Search
lxdream.org :: lxdream/src/cocoaui/cocoa_prefs.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_prefs.c
changeset 725:4d4018e8eeb8
next729:4cc913eabd3d
author nkeynes
date Sun Jul 06 03:18:55 2008 +0000 (14 years ago)
permissions -rw-r--r--
last change Add slightly more detailed about dialog
Add (currently empty) preferences dialog (WIP)
view annotate diff log raw
     1 /**
     2  * $Id: cocoa_win.c 723 2008-06-25 00:39:02Z nkeynes $
     3  *
     4  * Construct and manage the preferences panel under cocoa.
     5  *
     6  * Copyright (c) 2008 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  */
    19 #include "cocoaui/cocoaui.h"
    20 #include "lxdream.h"
    21 #include "config.h"
    23 @interface LxdreamPrefsToolbarDelegate : NSObject {
    24     NSArray *identifiers;
    25     NSArray *defaults;
    26     NSDictionary *items;
    27 }
    28 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label 
    29     tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action; 
    30 @end
    32 @implementation LxdreamPrefsToolbarDelegate
    33 - (id) init
    34 {
    35     NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths" 
    36                             tooltip: @"Configure system paths" icon: @"tb-paths" 
    37                             action: @selector(paths_action:)];
    38     NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"
    39                             tooltip: @"Configure controllers" icon: @"tb-ctrls"
    40                             action: @selector(controllers_action:)];
    41     identifiers = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
    42     defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ]; 
    43     NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];
    44     items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
    45     return self;
    46 }
    48 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label 
    49     tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action 
    50 {
    51     NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: id];
    52     [item setLabel: label];
    53     [item setToolTip: tooltip];
    54     [item setTarget: self];
    55     NSString *iconFile = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"];
    56     NSImage *image = [[NSImage alloc] initWithContentsOfFile: iconFile];
    57     [item setImage: image];
    58     [item setAction: action];
    59     return item;
    60 }
    62 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar 
    63 {
    64     return identifiers;
    65 }
    67 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
    68 {
    69     return defaults;
    70 }
    72 - (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
    73 {
    74     return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil];
    75 }
    77 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
    78      willBeInsertedIntoToolbar:(BOOL)flag 
    79 {
    80      return [items objectForKey: itemIdentifier];
    81 }
    82 - (void)paths_action: (id)sender
    83 {
    84 }
    85 - (void)controllers_action: (id)sender
    86 {
    87 }
    88 @end
    90 @implementation LxdreamPrefsPanel
    91 - (NSView *)createPathsPane
    92 {
    93     NSView *pane = [NSView new];
    94     int i;
    95     for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
    96         lxdream_config_entry_t entry = lxdream_get_config_entry(i);
    97         if( entry->label != NULL ) {
    98         }
    99     }
   100     return pane;
   101 }
   102 - (id)initWithContentRect:(NSRect)contentRect 
   103 {
   104     if( [super initWithContentRect: contentRect
   105            styleMask: ( NSTitledWindowMask | NSClosableWindowMask | 
   106                NSMiniaturizableWindowMask | NSResizableWindowMask |
   107                NSUnifiedTitleAndToolbarWindowMask )
   108            backing: NSBackingStoreBuffered defer: NO ] == nil ) {
   109         return nil;
   110     } else {
   111         [self setTitle: NS_("Preferences")];
   112         [self setDelegate: self];
   113         NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
   114         [toolbar setDelegate: [[LxdreamPrefsToolbarDelegate alloc] init]];
   115         [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
   116         [toolbar setSizeMode: NSToolbarSizeModeSmall];
   117         [toolbar setSelectedItemIdentifier: @"Paths"];
   118         [self setToolbar: toolbar];
   119         [self setContentView: [self createPathsPane]];
   120         return self;
   121     }
   122 }
   123 - (void)windowWillClose: (NSNotification *)notice
   124 {
   125     [NSApp stopModal];
   126 }
   127 @end
.