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