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)
file annotate diff log raw
nkeynes@725
     1
/**
nkeynes@725
     2
 * $Id: cocoa_win.c 723 2008-06-25 00:39:02Z nkeynes $
nkeynes@725
     3
 *
nkeynes@725
     4
 * Construct and manage the preferences panel under cocoa.
nkeynes@725
     5
 *
nkeynes@725
     6
 * Copyright (c) 2008 Nathan Keynes.
nkeynes@725
     7
 *
nkeynes@725
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@725
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@725
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@725
    11
 * (at your option) any later version.
nkeynes@725
    12
 *
nkeynes@725
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@725
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@725
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@725
    16
 * GNU General Public License for more details.
nkeynes@725
    17
 */
nkeynes@725
    18
nkeynes@725
    19
#include "cocoaui/cocoaui.h"
nkeynes@725
    20
#include "lxdream.h"
nkeynes@725
    21
#include "config.h"
nkeynes@725
    22
nkeynes@725
    23
@interface LxdreamPrefsToolbarDelegate : NSObject {
nkeynes@725
    24
    NSArray *identifiers;
nkeynes@725
    25
    NSArray *defaults;
nkeynes@725
    26
    NSDictionary *items;
nkeynes@725
    27
}
nkeynes@725
    28
- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label 
nkeynes@725
    29
    tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action; 
nkeynes@725
    30
@end
nkeynes@725
    31
nkeynes@725
    32
@implementation LxdreamPrefsToolbarDelegate
nkeynes@725
    33
- (id) init
nkeynes@725
    34
{
nkeynes@725
    35
    NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths" 
nkeynes@725
    36
                            tooltip: @"Configure system paths" icon: @"tb-paths" 
nkeynes@725
    37
                            action: @selector(paths_action:)];
nkeynes@725
    38
    NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"
nkeynes@725
    39
                            tooltip: @"Configure controllers" icon: @"tb-ctrls"
nkeynes@725
    40
                            action: @selector(controllers_action:)];
nkeynes@725
    41
    identifiers = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
nkeynes@725
    42
    defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ]; 
nkeynes@725
    43
    NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];
nkeynes@725
    44
    items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
nkeynes@725
    45
    return self;
nkeynes@725
    46
}
nkeynes@725
    47
nkeynes@725
    48
- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label 
nkeynes@725
    49
    tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action 
nkeynes@725
    50
{
nkeynes@725
    51
    NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: id];
nkeynes@725
    52
    [item setLabel: label];
nkeynes@725
    53
    [item setToolTip: tooltip];
nkeynes@725
    54
    [item setTarget: self];
nkeynes@725
    55
    NSString *iconFile = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"];
nkeynes@725
    56
    NSImage *image = [[NSImage alloc] initWithContentsOfFile: iconFile];
nkeynes@725
    57
    [item setImage: image];
nkeynes@725
    58
    [item setAction: action];
nkeynes@725
    59
    return item;
nkeynes@725
    60
}
nkeynes@725
    61
nkeynes@725
    62
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar 
nkeynes@725
    63
{
nkeynes@725
    64
    return identifiers;
nkeynes@725
    65
}
nkeynes@725
    66
nkeynes@725
    67
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
nkeynes@725
    68
{
nkeynes@725
    69
    return defaults;
nkeynes@725
    70
}
nkeynes@725
    71
nkeynes@725
    72
- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
nkeynes@725
    73
{
nkeynes@725
    74
    return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil];
nkeynes@725
    75
}
nkeynes@725
    76
nkeynes@725
    77
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
nkeynes@725
    78
     willBeInsertedIntoToolbar:(BOOL)flag 
nkeynes@725
    79
{
nkeynes@725
    80
     return [items objectForKey: itemIdentifier];
nkeynes@725
    81
}
nkeynes@725
    82
- (void)paths_action: (id)sender
nkeynes@725
    83
{
nkeynes@725
    84
}
nkeynes@725
    85
- (void)controllers_action: (id)sender
nkeynes@725
    86
{
nkeynes@725
    87
}
nkeynes@725
    88
@end
nkeynes@725
    89
nkeynes@725
    90
@implementation LxdreamPrefsPanel
nkeynes@725
    91
- (NSView *)createPathsPane
nkeynes@725
    92
{
nkeynes@725
    93
    NSView *pane = [NSView new];
nkeynes@725
    94
    int i;
nkeynes@725
    95
    for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
nkeynes@725
    96
        lxdream_config_entry_t entry = lxdream_get_config_entry(i);
nkeynes@725
    97
        if( entry->label != NULL ) {
nkeynes@725
    98
        }
nkeynes@725
    99
    }
nkeynes@725
   100
    return pane;
nkeynes@725
   101
}
nkeynes@725
   102
- (id)initWithContentRect:(NSRect)contentRect 
nkeynes@725
   103
{
nkeynes@725
   104
    if( [super initWithContentRect: contentRect
nkeynes@725
   105
           styleMask: ( NSTitledWindowMask | NSClosableWindowMask | 
nkeynes@725
   106
               NSMiniaturizableWindowMask | NSResizableWindowMask |
nkeynes@725
   107
               NSUnifiedTitleAndToolbarWindowMask )
nkeynes@725
   108
           backing: NSBackingStoreBuffered defer: NO ] == nil ) {
nkeynes@725
   109
        return nil;
nkeynes@725
   110
    } else {
nkeynes@725
   111
        [self setTitle: NS_("Preferences")];
nkeynes@725
   112
        [self setDelegate: self];
nkeynes@725
   113
        NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
nkeynes@725
   114
        [toolbar setDelegate: [[LxdreamPrefsToolbarDelegate alloc] init]];
nkeynes@725
   115
        [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
nkeynes@725
   116
        [toolbar setSizeMode: NSToolbarSizeModeSmall];
nkeynes@725
   117
        [toolbar setSelectedItemIdentifier: @"Paths"];
nkeynes@725
   118
        [self setToolbar: toolbar];
nkeynes@725
   119
        [self setContentView: [self createPathsPane]];
nkeynes@725
   120
        return self;
nkeynes@725
   121
    }
nkeynes@725
   122
}
nkeynes@725
   123
- (void)windowWillClose: (NSNotification *)notice
nkeynes@725
   124
{
nkeynes@725
   125
    [NSApp stopModal];
nkeynes@725
   126
}
nkeynes@725
   127
@end
.