Search
lxdream.org :: lxdream/src/cocoaui/cocoa_gd.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_gd.c
changeset 736:a02d1475ccfd
prev691:ad3356543392
next758:99ae000d4e09
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@691
     1
/**
nkeynes@691
     2
 * $Id$
nkeynes@691
     3
 *
nkeynes@691
     4
 * Management of the GDRom menu under cocoa
nkeynes@691
     5
 * 
nkeynes@691
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@691
     7
 *
nkeynes@691
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@691
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@691
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@691
    11
 * (at your option) any later version.
nkeynes@691
    12
 *
nkeynes@691
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@691
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@691
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@691
    16
 * GNU General Public License for more details.
nkeynes@691
    17
 */
nkeynes@691
    18
nkeynes@691
    19
nkeynes@691
    20
#include <AppKit/AppKit.h>
nkeynes@691
    21
#include <stdio.h>
nkeynes@691
    22
#include <stdlib.h>
nkeynes@691
    23
#include <string.h>
nkeynes@691
    24
#include <sys/time.h>
nkeynes@691
    25
#include "lxdream.h"
nkeynes@691
    26
#include "dreamcast.h"
nkeynes@691
    27
#include "dream.h"
nkeynes@691
    28
#include "gdlist.h"
nkeynes@691
    29
#include "cocoaui/cocoaui.h"
nkeynes@691
    30
nkeynes@691
    31
void cocoa_gdrom_menu_build( NSMenu *menu )
nkeynes@691
    32
{
nkeynes@691
    33
    int i,len = gdrom_list_size();
nkeynes@691
    34
    for( i=0; i<len; i++ ) {
nkeynes@691
    35
        const gchar *entry = gdrom_list_get_display_name(i);
nkeynes@691
    36
        if( entry[0] == '\0' ) {
nkeynes@691
    37
            [menu addItem: [NSMenuItem separatorItem]];
nkeynes@691
    38
        } else {
nkeynes@691
    39
            [[menu addItemWithTitle: [NSString stringWithCString: entry] 
nkeynes@736
    40
                                      action: @selector(gdrom_list_action:) keyEquivalent: @""]
nkeynes@736
    41
                                      setTag: i];
nkeynes@691
    42
        }
nkeynes@691
    43
    }
nkeynes@691
    44
    [menu addItem: [NSMenuItem separatorItem]];
nkeynes@691
    45
    [menu addItemWithTitle: NS_("Open image file...") action: @selector(mount_action:)
nkeynes@736
    46
     keyEquivalent: @"i"];
nkeynes@691
    47
}
nkeynes@736
    48
nkeynes@691
    49
void cocoa_gdrom_menu_rebuild( NSMenu *menu )
nkeynes@691
    50
{
nkeynes@691
    51
    while( [menu numberOfItems] > 0  ) {
nkeynes@691
    52
        [ menu removeItemAtIndex: 0 ];
nkeynes@691
    53
    }
nkeynes@736
    54
nkeynes@691
    55
    cocoa_gdrom_menu_build( menu );
nkeynes@691
    56
}
nkeynes@691
    57
nkeynes@691
    58
void cocoa_gdrom_menu_update( gboolean list_changed, int selection, void *user_data )
nkeynes@691
    59
{
nkeynes@691
    60
    // Create an auto-release pool - we may be called outside of the GUI main loop
nkeynes@691
    61
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
nkeynes@691
    62
    NSMenu *menu = (NSMenu *)user_data;
nkeynes@691
    63
    int i;
nkeynes@736
    64
nkeynes@691
    65
    if( list_changed ) {
nkeynes@691
    66
        cocoa_gdrom_menu_rebuild(menu);
nkeynes@691
    67
    }
nkeynes@736
    68
nkeynes@691
    69
    for( i=0; i< [menu numberOfItems]; i++ ) {
nkeynes@691
    70
        if( i == selection ) {
nkeynes@691
    71
            [[menu itemAtIndex: i] setState: NSOnState];
nkeynes@691
    72
        } else {
nkeynes@691
    73
            [[menu itemAtIndex: i] setState: NSOffState];
nkeynes@691
    74
        }
nkeynes@691
    75
    }
nkeynes@691
    76
    [pool release];
nkeynes@691
    77
}
nkeynes@691
    78
nkeynes@691
    79
NSMenu *cocoa_gdrom_menu_new()
nkeynes@691
    80
{
nkeynes@691
    81
    NSMenu *menu = [[NSMenu alloc] initWithTitle: @"GD-Rom Settings"];
nkeynes@691
    82
    cocoa_gdrom_menu_build(menu);
nkeynes@736
    83
nkeynes@691
    84
    register_gdrom_list_change_hook(cocoa_gdrom_menu_update, menu);
nkeynes@691
    85
    cocoa_gdrom_menu_update( FALSE, gdrom_list_get_selection(), menu );    
nkeynes@691
    86
    return menu;
nkeynes@691
    87
}
.