Search
lxdream.org :: lxdream/src/cocoaui/cocoa_prefs.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_prefs.c
changeset 765:4cd066048203
prev736:a02d1475ccfd
next770:429ff505c450
author nkeynes
date Wed Jul 23 11:11:30 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Cocoa preferences panel work-in-progress
file annotate diff log raw
1.1 --- a/src/cocoaui/cocoa_prefs.c Mon Jul 14 07:44:42 2008 +0000
1.2 +++ b/src/cocoaui/cocoa_prefs.c Wed Jul 23 11:11:30 2008 +0000
1.3 @@ -20,32 +20,123 @@
1.4 #include "lxdream.h"
1.5 #include "config.h"
1.6
1.7 -@interface LxdreamPrefsToolbarDelegate : NSObject {
1.8 - NSArray *identifiers;
1.9 - NSArray *defaults;
1.10 - NSDictionary *items;
1.11 +static LxdreamPrefsPanel *prefs_panel = NULL;
1.12 +
1.13 +@implementation LxdreamPrefsPane
1.14 +- (NSTextField *)addLabel: (NSString *)text withFrame: (NSRect)frame
1.15 +{
1.16 + NSTextField *label = [[NSTextField alloc] initWithFrame: frame];
1.17 + [label setStringValue: text];
1.18 + [label setBordered: NO];
1.19 + [label setDrawsBackground: NO];
1.20 + [label setEditable: NO];
1.21 + [label setAutoresizingMask: (NSViewMinYMargin|NSViewMaxXMargin)];
1.22 + [self addSubview: label];
1.23 + return label;
1.24 }
1.25 -- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
1.26 - tooltip: (NSString *)tooltip icon: (NSString *)icon
1.27 - action: (SEL) action;
1.28 +- (int)contentHeight
1.29 +{
1.30 + return [self frame].size.height - headerHeight;
1.31 +}
1.32 +
1.33 +- (id)initWithFrame: (NSRect)frameRect title:(NSString *)title
1.34 +{
1.35 + if( [super initWithFrame: frameRect ] == nil ) {
1.36 + return nil;
1.37 + } else {
1.38 + int height = frameRect.size.height - TEXT_GAP;
1.39 +
1.40 + NSFont *titleFont = [NSFont fontWithName: @"Helvetica-Bold" size: 16.0];
1.41 + NSRect fontRect = [titleFont boundingRectForFont];
1.42 + int titleHeight = fontRect.size.height + [titleFont descender];
1.43 + NSTextField *label = [self addLabel: title withFrame:
1.44 + NSMakeRect( TEXT_GAP, height-titleHeight,
1.45 + frameRect.size.width - (TEXT_GAP*2), titleHeight )];
1.46 + [label setFont: titleFont];
1.47 + height -= (titleHeight + TEXT_GAP);
1.48 +
1.49 + NSBox *rule = [[NSBox alloc] initWithFrame: NSMakeRect(1, height, frameRect.size.width-2, 1)];
1.50 + [rule setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];
1.51 + [rule setBoxType: NSBoxSeparator];
1.52 + [self addSubview: rule];
1.53 + height -= TEXT_GAP;
1.54 +
1.55 + headerHeight = frameRect.size.height - height;
1.56 + return self;
1.57 + }
1.58 +}
1.59 @end
1.60
1.61 -@implementation LxdreamPrefsToolbarDelegate
1.62 -- (id) init
1.63 +
1.64 +@interface LxdreamPrefsPanel (Private)
1.65 +- (void) initToolbar;
1.66 +- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
1.67 +tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action;
1.68 +@end
1.69 +
1.70 +@implementation LxdreamPrefsPanel
1.71 +
1.72 +- (NSView *)createControlsPane
1.73 {
1.74 + NSView *pane = [[NSView alloc] initWithFrame: NSMakeRect(0,0,600,400)];
1.75 + return pane;
1.76 +}
1.77 +
1.78 +- (id)initWithContentRect:(NSRect)contentRect
1.79 +{
1.80 + if( [super initWithContentRect: contentRect
1.81 + styleMask: ( NSTitledWindowMask | NSClosableWindowMask |
1.82 + NSMiniaturizableWindowMask | NSResizableWindowMask |
1.83 + NSUnifiedTitleAndToolbarWindowMask )
1.84 + backing: NSBackingStoreBuffered defer: NO ] == nil ) {
1.85 + return nil;
1.86 + } else {
1.87 + [self setTitle: NS_("Preferences")];
1.88 + [self setDelegate: self];
1.89 + [self initToolbar];
1.90 + path_pane = [LxdreamPrefsPathPane new];
1.91 + ctrl_pane = [LxdreamPrefsControllerPane new];
1.92 +
1.93 + [self setContentView: path_pane];
1.94 + return self;
1.95 + }
1.96 +}
1.97 +- (void)windowWillClose: (NSNotification *)notice
1.98 +{
1.99 + prefs_panel = NULL;
1.100 +}
1.101 +- (void) initToolbar
1.102 +{
1.103 + NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
1.104 +
1.105 NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths"
1.106 tooltip: @"Configure system paths" icon: @"tb-paths"
1.107 action: @selector(paths_action:)];
1.108 NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"
1.109 tooltip: @"Configure controllers" icon: @"tb-ctrls"
1.110 action: @selector(controllers_action:)];
1.111 - identifiers = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
1.112 - defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
1.113 + toolbar_ids = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
1.114 + toolbar_defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
1.115 NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];
1.116 - items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
1.117 - return self;
1.118 + toolbar_items = [NSDictionary dictionaryWithObjects: values forKeys: toolbar_ids];
1.119 +
1.120 + [toolbar setDelegate: self];
1.121 + [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
1.122 + [toolbar setSizeMode: NSToolbarSizeModeSmall];
1.123 + [toolbar setSelectedItemIdentifier: @"Paths"];
1.124 + [self setToolbar: toolbar];
1.125 }
1.126
1.127 +- (void)paths_action: (id)sender
1.128 +{
1.129 + [self setContentView: path_pane];
1.130 +}
1.131 +- (void)controllers_action: (id)sender
1.132 +{
1.133 + [self setContentView: ctrl_pane];
1.134 +}
1.135 +
1.136 +/***************************** Toolbar methods ***************************/
1.137 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
1.138 tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action
1.139 {
1.140 @@ -59,70 +150,32 @@
1.141 [item setAction: action];
1.142 return item;
1.143 }
1.144 -
1.145 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
1.146 {
1.147 - return identifiers;
1.148 + return toolbar_ids;
1.149 }
1.150
1.151 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
1.152 {
1.153 - return defaults;
1.154 + return toolbar_defaults;
1.155 }
1.156
1.157 - (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
1.158 {
1.159 - return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil];
1.160 + return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
1.161 }
1.162
1.163 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
1.164 willBeInsertedIntoToolbar:(BOOL)flag
1.165 {
1.166 - return [items objectForKey: itemIdentifier];
1.167 -}
1.168 -- (void)paths_action: (id)sender
1.169 -{
1.170 -}
1.171 -- (void)controllers_action: (id)sender
1.172 -{
1.173 + return [toolbar_items objectForKey: itemIdentifier];
1.174 }
1.175 @end
1.176
1.177 -@implementation LxdreamPrefsPanel
1.178 -- (NSView *)createPathsPane
1.179 +void cocoa_gui_show_preferences()
1.180 {
1.181 - NSView *pane = [NSView new];
1.182 - int i;
1.183 - for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
1.184 - lxdream_config_entry_t entry = lxdream_get_config_entry(i);
1.185 - if( entry->label != NULL ) {
1.186 - }
1.187 + if( prefs_panel == NULL ) {
1.188 + prefs_panel = [[LxdreamPrefsPanel alloc] initWithContentRect: NSMakeRect(0,0,600,400)];
1.189 }
1.190 - return pane;
1.191 -}
1.192 -- (id)initWithContentRect:(NSRect)contentRect
1.193 -{
1.194 - if( [super initWithContentRect: contentRect
1.195 - styleMask: ( NSTitledWindowMask | NSClosableWindowMask |
1.196 - NSMiniaturizableWindowMask | NSResizableWindowMask |
1.197 - NSUnifiedTitleAndToolbarWindowMask )
1.198 - backing: NSBackingStoreBuffered defer: NO ] == nil ) {
1.199 - return nil;
1.200 - } else {
1.201 - [self setTitle: NS_("Preferences")];
1.202 - [self setDelegate: self];
1.203 - NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
1.204 - [toolbar setDelegate: [[LxdreamPrefsToolbarDelegate alloc] init]];
1.205 - [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
1.206 - [toolbar setSizeMode: NSToolbarSizeModeSmall];
1.207 - [toolbar setSelectedItemIdentifier: @"Paths"];
1.208 - [self setToolbar: toolbar];
1.209 - [self setContentView: [self createPathsPane]];
1.210 - return self;
1.211 - }
1.212 -}
1.213 -- (void)windowWillClose: (NSNotification *)notice
1.214 -{
1.215 - [NSApp stopModal];
1.216 -}
1.217 -@end
1.218 + [prefs_panel makeKeyAndOrderFront: prefs_panel];
1.219 +}
1.220 \ No newline at end of file
.