Search
lxdream.org :: lxdream/src/cocoaui/cocoa_path.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_path.c
changeset 881:10b67e485aa4
prev770:429ff505c450
next888:9892c970b95a
author nkeynes
date Sun Oct 19 10:55:53 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Refresh DC config when path properties change
file annotate diff log raw
nkeynes@765
     1
/**
nkeynes@765
     2
 * $Id$
nkeynes@765
     3
 *
nkeynes@765
     4
 * Construct and manage the paths configuration pane
nkeynes@765
     5
 *
nkeynes@765
     6
 * Copyright (c) 2008 Nathan Keynes.
nkeynes@765
     7
 *
nkeynes@765
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@765
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@765
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@765
    11
 * (at your option) any later version.
nkeynes@765
    12
 *
nkeynes@765
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@765
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@765
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@765
    16
 * GNU General Public License for more details.
nkeynes@765
    17
 */
nkeynes@765
    18
nkeynes@765
    19
#include "cocoaui.h"
nkeynes@765
    20
#include "config.h"
nkeynes@765
    21
nkeynes@770
    22
@interface LxdreamPrefsPathPane: LxdreamPrefsPane 
nkeynes@770
    23
{
nkeynes@770
    24
}
nkeynes@770
    25
+ (LxdreamPrefsPathPane *)new;
nkeynes@770
    26
@end
nkeynes@765
    27
nkeynes@765
    28
@implementation LxdreamPrefsPathPane
nkeynes@765
    29
+ (LxdreamPrefsPathPane *)new
nkeynes@765
    30
{
nkeynes@765
    31
    return [[LxdreamPrefsPathPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
nkeynes@765
    32
}
nkeynes@765
    33
- (id)initWithFrame: (NSRect)frameRect
nkeynes@765
    34
{
nkeynes@765
    35
    if( [super initWithFrame: frameRect title: NS_("Paths")] == nil ) {
nkeynes@765
    36
        return nil;
nkeynes@765
    37
    } else {
nkeynes@765
    38
        int i;
nkeynes@765
    39
        int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
nkeynes@765
    40
        
nkeynes@765
    41
        for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
nkeynes@765
    42
            const struct lxdream_config_entry *entry = lxdream_get_config_entry(i);
nkeynes@765
    43
            if( entry->label != NULL ) {
nkeynes@765
    44
                NSRect frame = NSMakeRect( TEXT_GAP, height -((TEXT_HEIGHT+TEXT_GAP)*i - 2), 
nkeynes@765
    45
                                           150, LABEL_HEIGHT );
nkeynes@770
    46
                NSTextField *label = cocoa_gui_add_label(self, NS_(entry->label), frame);
nkeynes@765
    47
                [label setAlignment: NSRightTextAlignment];
nkeynes@765
    48
nkeynes@765
    49
                frame = NSMakeRect( 150 + (TEXT_GAP*2), 
nkeynes@765
    50
                                    height -((TEXT_HEIGHT+TEXT_GAP)*i), 
nkeynes@765
    51
                                    360, TEXT_HEIGHT ); 
nkeynes@765
    52
                NSTextField *field = [[NSTextField alloc] initWithFrame: frame];
nkeynes@765
    53
                [field setTag: i];
nkeynes@765
    54
                [field setStringValue: [NSString stringWithCString: entry->value]]; 
nkeynes@765
    55
                [field setDelegate: self];
nkeynes@765
    56
                [field setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];
nkeynes@765
    57
                [self addSubview: label];
nkeynes@765
    58
                [self addSubview: field];
nkeynes@765
    59
            }
nkeynes@765
    60
        }
nkeynes@765
    61
    }
nkeynes@765
    62
    return self;
nkeynes@765
    63
}
nkeynes@765
    64
- (void)controlTextDidEndEditing:(NSNotification *)notify
nkeynes@765
    65
{
nkeynes@765
    66
    int tag = [[notify object] tag];
nkeynes@765
    67
    const char *str = [[[notify object] stringValue] UTF8String];
nkeynes@765
    68
    const char *oldval = lxdream_get_config_value(tag);
nkeynes@765
    69
    if( str[0] == '\0' )
nkeynes@765
    70
        str = NULL;
nkeynes@765
    71
    if( oldval == NULL ? str != NULL : (str == NULL || strcmp(oldval,str) != 0 ) ) {   
nkeynes@765
    72
        lxdream_set_global_config_value(tag, str);
nkeynes@765
    73
        lxdream_save_config();
nkeynes@881
    74
        dreamcast_config_changed();
nkeynes@765
    75
    }
nkeynes@765
    76
}
nkeynes@765
    77
@end
nkeynes@770
    78
nkeynes@770
    79
nkeynes@770
    80
NSView *cocoa_gui_create_prefs_path_pane()
nkeynes@770
    81
{
nkeynes@770
    82
    return [LxdreamPrefsPathPane new];
nkeynes@770
    83
}
.