Search
lxdream.org :: lxdream/src/cocoaui/cocoa_gd.m
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_gd.m
changeset 964:f2f3c7612d06
next1040:9e3e41eab2db
author nkeynes
date Mon Feb 09 00:13:46 2009 +0000 (15 years ago)
permissions -rw-r--r--
last change Fail cleanly if the display doesn't actually support GLX, rather than crashing horribly
view annotate diff log raw
     1 /**
     2  * $Id$
     3  *
     4  * Management of the GDRom menu under cocoa
     5  * 
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     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.
    12  *
    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.
    17  */
    20 #include <AppKit/AppKit.h>
    21 #include <stdio.h>
    22 #include <stdlib.h>
    23 #include <string.h>
    24 #include <sys/time.h>
    25 #include "lxdream.h"
    26 #include "dreamcast.h"
    27 #include "dream.h"
    28 #include "gdlist.h"
    29 #include "cocoaui/cocoaui.h"
    31 void cocoa_gdrom_menu_build( NSMenu *menu )
    32 {
    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]];
    38         } else {
    39             [[menu addItemWithTitle: [NSString stringWithCString: entry] 
    40                                       action: @selector(gdrom_list_action:) keyEquivalent: @""]
    41                                       setTag: i];
    42         }
    43     }
    44     [menu addItem: [NSMenuItem separatorItem]];
    45     [menu addItemWithTitle: NS_("Open image file...") action: @selector(mount_action:)
    46      keyEquivalent: @"i"];
    47 }
    49 void cocoa_gdrom_menu_rebuild( NSMenu *menu )
    50 {
    51     while( [menu numberOfItems] > 0  ) {
    52         [ menu removeItemAtIndex: 0 ];
    53     }
    55     cocoa_gdrom_menu_build( menu );
    56 }
    58 gboolean cocoa_gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
    59 {
    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;
    63     int i;
    65     if( list_changed ) {
    66         cocoa_gdrom_menu_rebuild(menu);
    67     }
    69     for( i=0; i< [menu numberOfItems]; i++ ) {
    70         if( i == selection ) {
    71             [[menu itemAtIndex: i] setState: NSOnState];
    72         } else {
    73             [[menu itemAtIndex: i] setState: NSOffState];
    74         }
    75     }
    76     [pool release];
    77     return TRUE;
    78 }
    80 NSMenu *cocoa_gdrom_menu_new()
    81 {
    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 );    
    87     return menu;
    88 }
.