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 736:a02d1475ccfd
prev729:4cc913eabd3d
next765:4cd066048203
author nkeynes
date Sat Jul 19 02:48:50 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Add debian control files to the dist
view annotate diff log raw
     1 /**
     2  * $Id$
     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 
    30                                action: (SEL) action; 
    31 @end
    33 @implementation LxdreamPrefsToolbarDelegate
    34 - (id) init
    35 {
    36     NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths" 
    37                             tooltip: @"Configure system paths" icon: @"tb-paths" 
    38                             action: @selector(paths_action:)];
    39     NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"
    40                             tooltip: @"Configure controllers" icon: @"tb-ctrls"
    41                             action: @selector(controllers_action:)];
    42     identifiers = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
    43     defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ]; 
    44     NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];
    45     items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
    46     return self;
    47 }
    49 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label 
    50 tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action 
    51 {
    52     NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: id];
    53     [item setLabel: label];
    54     [item setToolTip: tooltip];
    55     [item setTarget: self];
    56     NSString *iconFile = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"];
    57     NSImage *image = [[NSImage alloc] initWithContentsOfFile: iconFile];
    58     [item setImage: image];
    59     [item setAction: action];
    60     return item;
    61 }
    63 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar 
    64 {
    65     return identifiers;
    66 }
    68 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
    69 {
    70     return defaults;
    71 }
    73 - (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
    74 {
    75     return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil];
    76 }
    78 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
    79 willBeInsertedIntoToolbar:(BOOL)flag 
    80 {
    81     return [items objectForKey: itemIdentifier];
    82 }
    83 - (void)paths_action: (id)sender
    84 {
    85 }
    86 - (void)controllers_action: (id)sender
    87 {
    88 }
    89 @end
    91 @implementation LxdreamPrefsPanel
    92 - (NSView *)createPathsPane
    93 {
    94     NSView *pane = [NSView new];
    95     int i;
    96     for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
    97         lxdream_config_entry_t entry = lxdream_get_config_entry(i);
    98         if( entry->label != NULL ) {
    99         }
   100     }
   101     return pane;
   102 }
   103 - (id)initWithContentRect:(NSRect)contentRect 
   104 {
   105     if( [super initWithContentRect: contentRect
   106          styleMask: ( NSTitledWindowMask | NSClosableWindowMask | 
   107                  NSMiniaturizableWindowMask | NSResizableWindowMask |
   108                  NSUnifiedTitleAndToolbarWindowMask )
   109                  backing: NSBackingStoreBuffered defer: NO ] == nil ) {
   110         return nil;
   111     } else {
   112         [self setTitle: NS_("Preferences")];
   113         [self setDelegate: self];
   114         NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
   115         [toolbar setDelegate: [[LxdreamPrefsToolbarDelegate alloc] init]];
   116         [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
   117         [toolbar setSizeMode: NSToolbarSizeModeSmall];
   118         [toolbar setSelectedItemIdentifier: @"Paths"];
   119         [self setToolbar: toolbar];
   120         [self setContentView: [self createPathsPane]];
   121         return self;
   122     }
   123 }
   124 - (void)windowWillClose: (NSNotification *)notice
   125 {
   126     [NSApp stopModal];
   127 }
   128 @end
.