4 * Management of the GDRom menu under cocoa
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
20 #include <AppKit/AppKit.h>
26 #include "dreamcast.h"
29 #include "cocoaui/cocoaui.h"
31 void cocoa_gdrom_menu_build( NSMenu *menu )
33 int i,len = gdrom_list_size();
34 for( i=0; i<len; i++ ) {
35 const gchar *entry = gdrom_list_get_display_name(i);
36 if( entry[0] == '\0' ) {
37 [menu addItem: [NSMenuItem separatorItem]];
39 [[menu addItemWithTitle: [NSString stringWithCString: entry]
40 action: @selector(gdrom_list_action:) keyEquivalent: @""]
44 [menu addItem: [NSMenuItem separatorItem]];
45 [menu addItemWithTitle: NS_("Open image file...") action: @selector(mount_action:)
49 void cocoa_gdrom_menu_rebuild( NSMenu *menu )
51 while( [menu numberOfItems] > 0 ) {
52 [ menu removeItemAtIndex: 0 ];
55 cocoa_gdrom_menu_build( menu );
58 gboolean cocoa_gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
60 // Create an auto-release pool - we may be called outside of the GUI main loop
61 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
62 NSMenu *menu = (NSMenu *)user_data;
66 cocoa_gdrom_menu_rebuild(menu);
69 for( i=0; i< [menu numberOfItems]; i++ ) {
70 if( i == selection ) {
71 [[menu itemAtIndex: i] setState: NSOnState];
73 [[menu itemAtIndex: i] setState: NSOffState];
80 NSMenu *cocoa_gdrom_menu_new()
82 NSMenu *menu = [[NSMenu alloc] initWithTitle: @"GD-Rom Settings"];
83 cocoa_gdrom_menu_build(menu);
85 register_gdrom_list_change_hook(cocoa_gdrom_menu_update, menu);
86 cocoa_gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );
.