Search
lxdream.org :: lxdream/src/cocoaui/cocoa_gd.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_gd.c
changeset 691:ad3356543392
next736:a02d1475ccfd
author nkeynes
date Mon Jun 30 04:58:26 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Use the configured paths for the dialog boxes by default
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/cocoaui/cocoa_gd.c Mon Jun 30 04:58:26 2008 +0000
1.3 @@ -0,0 +1,87 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Management of the GDRom menu under cocoa
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +
1.23 +#include <AppKit/AppKit.h>
1.24 +#include <stdio.h>
1.25 +#include <stdlib.h>
1.26 +#include <string.h>
1.27 +#include <sys/time.h>
1.28 +#include "lxdream.h"
1.29 +#include "dreamcast.h"
1.30 +#include "dream.h"
1.31 +#include "gdlist.h"
1.32 +#include "cocoaui/cocoaui.h"
1.33 +
1.34 +void cocoa_gdrom_menu_build( NSMenu *menu )
1.35 +{
1.36 + int i,len = gdrom_list_size();
1.37 + for( i=0; i<len; i++ ) {
1.38 + const gchar *entry = gdrom_list_get_display_name(i);
1.39 + if( entry[0] == '\0' ) {
1.40 + [menu addItem: [NSMenuItem separatorItem]];
1.41 + } else {
1.42 + [[menu addItemWithTitle: [NSString stringWithCString: entry]
1.43 + action: @selector(gdrom_list_action:) keyEquivalent: @""]
1.44 + setTag: i];
1.45 + }
1.46 + }
1.47 + [menu addItem: [NSMenuItem separatorItem]];
1.48 + [menu addItemWithTitle: NS_("Open image file...") action: @selector(mount_action:)
1.49 + keyEquivalent: @"i"];
1.50 +}
1.51 +
1.52 +void cocoa_gdrom_menu_rebuild( NSMenu *menu )
1.53 +{
1.54 + while( [menu numberOfItems] > 0 ) {
1.55 + [ menu removeItemAtIndex: 0 ];
1.56 + }
1.57 +
1.58 + cocoa_gdrom_menu_build( menu );
1.59 +}
1.60 +
1.61 +void cocoa_gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
1.62 +{
1.63 + // Create an auto-release pool - we may be called outside of the GUI main loop
1.64 + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1.65 + NSMenu *menu = (NSMenu *)user_data;
1.66 + int i;
1.67 +
1.68 + if( list_changed ) {
1.69 + cocoa_gdrom_menu_rebuild(menu);
1.70 + }
1.71 +
1.72 + for( i=0; i< [menu numberOfItems]; i++ ) {
1.73 + if( i == selection ) {
1.74 + [[menu itemAtIndex: i] setState: NSOnState];
1.75 + } else {
1.76 + [[menu itemAtIndex: i] setState: NSOffState];
1.77 + }
1.78 + }
1.79 + [pool release];
1.80 +}
1.81 +
1.82 +NSMenu *cocoa_gdrom_menu_new()
1.83 +{
1.84 + NSMenu *menu = [[NSMenu alloc] initWithTitle: @"GD-Rom Settings"];
1.85 + cocoa_gdrom_menu_build(menu);
1.86 +
1.87 + register_gdrom_list_change_hook(cocoa_gdrom_menu_update, menu);
1.88 + cocoa_gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );
1.89 + return menu;
1.90 +}
.