filename | src/cocoaui/cocoa_prefs.m |
changeset | 964:f2f3c7612d06 |
next | 1034:7044e01148f0 |
author | nkeynes |
date | Thu Jan 15 04:15:11 2009 +0000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Add support for the Intel ICC compiler (C only, icc doesn't support Obj-C) - Rename Obj-C source to .m - Separate paths.c into paths_unix.c and paths_osx.m - Add configuration detection of ICC, along with specific opt flags |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/cocoaui/cocoa_prefs.m Thu Jan 15 04:15:11 2009 +00001.3 @@ -0,0 +1,190 @@1.4 +/**1.5 + * $Id$1.6 + *1.7 + * Construct and manage the preferences panel under cocoa.1.8 + *1.9 + * Copyright (c) 2008 Nathan Keynes.1.10 + *1.11 + * This program is free software; you can redistribute it and/or modify1.12 + * it under the terms of the GNU General Public License as published by1.13 + * the Free Software Foundation; either version 2 of the License, or1.14 + * (at your option) any later version.1.15 + *1.16 + * This program is distributed in the hope that it will be useful,1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.19 + * GNU General Public License for more details.1.20 + */1.21 +1.22 +#include "cocoaui/cocoaui.h"1.23 +#include "lxdream.h"1.24 +#include "config.h"1.25 +1.26 +static LxdreamPrefsPanel *prefs_panel = NULL;1.27 +1.28 +@implementation LxdreamPrefsPane1.29 +- (int)contentHeight1.30 +{1.31 + return [self frame].size.height - headerHeight;1.32 +}1.33 +1.34 +- (id)initWithFrame: (NSRect)frameRect title:(NSString *)title1.35 +{1.36 + if( [super initWithFrame: frameRect ] == nil ) {1.37 + return nil;1.38 + } else {1.39 + int height = frameRect.size.height - TEXT_GAP;1.40 +1.41 + NSFont *titleFont = [NSFont fontWithName: @"Helvetica-Bold" size: 16.0];1.42 + NSRect fontRect = [titleFont boundingRectForFont];1.43 + int titleHeight = fontRect.size.height + [titleFont descender];1.44 + NSTextField *label = cocoa_gui_add_label(self, title,1.45 + NSMakeRect( TEXT_GAP, height-titleHeight,1.46 + frameRect.size.width - (TEXT_GAP*2), titleHeight ));1.47 + [label setFont: titleFont];1.48 + height -= (titleHeight + TEXT_GAP);1.49 +1.50 + NSBox *rule = [[NSBox alloc] initWithFrame: NSMakeRect(1, height, frameRect.size.width-2, 1)];1.51 + [rule setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];1.52 + [rule setBoxType: NSBoxSeparator];1.53 + [self addSubview: rule];1.54 + height -= TEXT_GAP;1.55 +1.56 + headerHeight = frameRect.size.height - height;1.57 + return self;1.58 + }1.59 +}1.60 +@end1.61 +1.62 +/**************************** Main preferences window ************************/1.63 +1.64 +@interface LxdreamPrefsPanel (Private)1.65 +- (void) initToolbar;1.66 +- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label1.67 +tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action;1.68 +@end1.69 +1.70 +@implementation LxdreamPrefsPanel1.71 +1.72 +- (NSView *)createControlsPane1.73 +{1.74 + NSView *pane = [[NSView alloc] initWithFrame: NSMakeRect(0,0,640,400)];1.75 + return pane;1.76 +}1.77 +1.78 +- (id)initWithContentRect:(NSRect)contentRect1.79 +{1.80 + if( [super initWithContentRect: contentRect1.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 setMinSize: NSMakeSize(400,300)];1.90 + [self initToolbar];1.91 + path_pane = cocoa_gui_create_prefs_path_pane();1.92 + ctrl_pane = cocoa_gui_create_prefs_controller_pane();1.93 + binding_editor = nil;1.94 + [self setContentView: path_pane];1.95 + return self;1.96 + }1.97 +}1.98 +- (void)dealloc1.99 +{1.100 + if( binding_editor != nil ) {1.101 + [binding_editor release];1.102 + binding_editor = nil;1.103 + }1.104 + [super dealloc];1.105 +}1.106 +- (void)windowWillClose: (NSNotification *)notice1.107 +{1.108 + prefs_panel = NULL;1.109 +}1.110 +- (id)windowWillReturnFieldEditor:(NSWindow *)sender toObject:(id)view1.111 +{1.112 + if( [view isKindOfClass: [KeyBindingField class]] ) {1.113 + if( binding_editor == nil ) {1.114 + binding_editor = [[[KeyBindingEditor alloc] init] retain];1.115 + }1.116 + return binding_editor;1.117 + }1.118 + return nil;1.119 +}1.120 +- (void) initToolbar1.121 +{1.122 + NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];1.123 +1.124 + NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths"1.125 + tooltip: @"Configure system paths" icon: @"tb-paths"1.126 + action: @selector(paths_action:)];1.127 + NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"1.128 + tooltip: @"Configure controllers" icon: @"tb-ctrls"1.129 + action: @selector(controllers_action:)];1.130 + toolbar_ids = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];1.131 + toolbar_defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];1.132 + NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];1.133 + toolbar_items = [NSDictionary dictionaryWithObjects: values forKeys: toolbar_ids];1.134 +1.135 + [toolbar setDelegate: self];1.136 + [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];1.137 + [toolbar setSizeMode: NSToolbarSizeModeSmall];1.138 + [toolbar setSelectedItemIdentifier: @"Paths"];1.139 + [self setToolbar: toolbar];1.140 +}1.141 +1.142 +- (void)paths_action: (id)sender1.143 +{1.144 + [self setContentView: path_pane];1.145 +}1.146 +- (void)controllers_action: (id)sender1.147 +{1.148 + [self setContentView: ctrl_pane];1.149 +}1.150 +1.151 +/***************************** Toolbar methods ***************************/1.152 +- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label1.153 +tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action1.154 +{1.155 + NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: id];1.156 + [item setLabel: label];1.157 + [item setToolTip: tooltip];1.158 + [item setTarget: self];1.159 + NSString *iconFile = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"];1.160 + NSImage *image = [[NSImage alloc] initWithContentsOfFile: iconFile];1.161 + [item setImage: image];1.162 + [item setAction: action];1.163 + return item;1.164 +}1.165 +- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar1.166 +{1.167 + return toolbar_ids;1.168 +}1.169 +1.170 +- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar1.171 +{1.172 + return toolbar_defaults;1.173 +}1.174 +1.175 +- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar1.176 +{1.177 + return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];1.178 +}1.179 +1.180 +- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier1.181 +willBeInsertedIntoToolbar:(BOOL)flag1.182 +{1.183 + return [toolbar_items objectForKey: itemIdentifier];1.184 +}1.185 +@end1.186 +1.187 +void cocoa_gui_show_preferences()1.188 +{1.189 + if( prefs_panel == NULL ) {1.190 + prefs_panel = [[LxdreamPrefsPanel alloc] initWithContentRect: NSMakeRect(0,0,640,400)];1.191 + }1.192 + [prefs_panel makeKeyAndOrderFront: prefs_panel];1.193 +}1.194 \ No newline at end of file
.