Search
lxdream.org :: lxdream :: r765:4cd066048203
lxdream 0.9.1
released Jun 29
Download Now
changeset765:4cd066048203
parent764:44f5670ada62
child766:336858fb0160
authornkeynes
dateWed Jul 23 11:11:30 2008 +0000 (11 years ago)
Cocoa preferences panel work-in-progress
src/Makefile.am
src/Makefile.in
src/cocoaui/cocoa_ctrl.c
src/cocoaui/cocoa_path.c
src/cocoaui/cocoa_prefs.c
src/cocoaui/cocoaui.c
src/cocoaui/cocoaui.h
1.1 --- a/src/Makefile.am Wed Jul 23 11:10:49 2008 +0000
1.2 +++ b/src/Makefile.am Wed Jul 23 11:11:30 2008 +0000
1.3 @@ -92,6 +92,7 @@
1.4 if GUI_COCOA
1.5 lxdream_SOURCES += cocoaui/cocoaui.c cocoaui/cocoaui.h \
1.6 cocoaui/cocoa_win.c cocoaui/cocoa_gd.c cocoaui/cocoa_prefs.c \
1.7 + cocoaui/cocoa_path.c cocoaui/cocoa_ctrl.c \
1.8 drivers/video_osx.c drivers/mac_keymap.h drivers/mac_keymap.txt
1.9 endif
1.10
2.1 --- a/src/Makefile.in Wed Jul 23 11:10:49 2008 +0000
2.2 +++ b/src/Makefile.in Wed Jul 23 11:11:30 2008 +0000
2.3 @@ -56,6 +56,7 @@
2.4
2.5 @GUI_COCOA_TRUE@am__append_4 = cocoaui/cocoaui.c cocoaui/cocoaui.h \
2.6 @GUI_COCOA_TRUE@ cocoaui/cocoa_win.c cocoaui/cocoa_gd.c cocoaui/cocoa_prefs.c \
2.7 +@GUI_COCOA_TRUE@ cocoaui/cocoa_path.c cocoaui/cocoa_ctrl.c \
2.8 @GUI_COCOA_TRUE@ drivers/video_osx.c drivers/mac_keymap.h drivers/mac_keymap.txt
2.9
2.10 @VIDEO_OSMESA_TRUE@am__append_5 = drivers/video_gdk.c
2.11 @@ -127,13 +128,14 @@
2.12 gtkui/gtk_ctrl.c gtkui/gtk_path.c gtkui/gtk_gd.c \
2.13 drivers/video_gtk.c cocoaui/cocoaui.c cocoaui/cocoaui.h \
2.14 cocoaui/cocoa_win.c cocoaui/cocoa_gd.c cocoaui/cocoa_prefs.c \
2.15 - drivers/video_osx.c drivers/mac_keymap.h \
2.16 - drivers/mac_keymap.txt drivers/video_gdk.c drivers/video_glx.c \
2.17 - drivers/video_glx.h drivers/video_nsgl.c drivers/video_nsgl.h \
2.18 - drivers/audio_osx.c drivers/audio_pulse.c drivers/audio_esd.c \
2.19 - drivers/audio_alsa.c drivers/cd_linux.c drivers/cd_osx.c \
2.20 - drivers/osx_iokit.c drivers/osx_iokit.h drivers/cd_none.c \
2.21 - drivers/joy_linux.c drivers/joy_linux.h
2.22 + cocoaui/cocoa_path.c cocoaui/cocoa_ctrl.c drivers/video_osx.c \
2.23 + drivers/mac_keymap.h drivers/mac_keymap.txt \
2.24 + drivers/video_gdk.c drivers/video_glx.c drivers/video_glx.h \
2.25 + drivers/video_nsgl.c drivers/video_nsgl.h drivers/audio_osx.c \
2.26 + drivers/audio_pulse.c drivers/audio_esd.c drivers/audio_alsa.c \
2.27 + drivers/cd_linux.c drivers/cd_osx.c drivers/osx_iokit.c \
2.28 + drivers/osx_iokit.h drivers/cd_none.c drivers/joy_linux.c \
2.29 + drivers/joy_linux.h
2.30 @BUILD_SH4X86_TRUE@am__objects_1 = sh4x86.$(OBJEXT) sh4trans.$(OBJEXT) \
2.31 @BUILD_SH4X86_TRUE@ x86dasm.$(OBJEXT) i386-dis.$(OBJEXT) \
2.32 @BUILD_SH4X86_TRUE@ dis-init.$(OBJEXT) dis-buf.$(OBJEXT)
2.33 @@ -144,6 +146,7 @@
2.34 @GUI_GTK_TRUE@ gtk_gd.$(OBJEXT) video_gtk.$(OBJEXT)
2.35 @GUI_COCOA_TRUE@am__objects_3 = cocoaui.$(OBJEXT) cocoa_win.$(OBJEXT) \
2.36 @GUI_COCOA_TRUE@ cocoa_gd.$(OBJEXT) cocoa_prefs.$(OBJEXT) \
2.37 +@GUI_COCOA_TRUE@ cocoa_path.$(OBJEXT) cocoa_ctrl.$(OBJEXT) \
2.38 @GUI_COCOA_TRUE@ video_osx.$(OBJEXT)
2.39 @VIDEO_OSMESA_TRUE@am__objects_4 = video_gdk.$(OBJEXT)
2.40 @VIDEO_GLX_TRUE@am__objects_5 = video_glx.$(OBJEXT)
2.41 @@ -543,7 +546,9 @@
2.42 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cd_none.Po@am__quote@
2.43 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cd_osx.Po@am__quote@
2.44 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi.Po@am__quote@
2.45 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_ctrl.Po@am__quote@
2.46 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_gd.Po@am__quote@
2.47 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_path.Po@am__quote@
2.48 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_prefs.Po@am__quote@
2.49 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_win.Po@am__quote@
2.50 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoaui.Po@am__quote@
2.51 @@ -1606,6 +1611,34 @@
2.52 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.53 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cocoa_prefs.obj `if test -f 'cocoaui/cocoa_prefs.c'; then $(CYGPATH_W) 'cocoaui/cocoa_prefs.c'; else $(CYGPATH_W) '$(srcdir)/cocoaui/cocoa_prefs.c'; fi`
2.54
2.55 +cocoa_path.o: cocoaui/cocoa_path.c
2.56 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cocoa_path.o -MD -MP -MF "$(DEPDIR)/cocoa_path.Tpo" -c -o cocoa_path.o `test -f 'cocoaui/cocoa_path.c' || echo '$(srcdir)/'`cocoaui/cocoa_path.c; \
2.57 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cocoa_path.Tpo" "$(DEPDIR)/cocoa_path.Po"; else rm -f "$(DEPDIR)/cocoa_path.Tpo"; exit 1; fi
2.58 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cocoaui/cocoa_path.c' object='cocoa_path.o' libtool=no @AMDEPBACKSLASH@
2.59 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.60 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cocoa_path.o `test -f 'cocoaui/cocoa_path.c' || echo '$(srcdir)/'`cocoaui/cocoa_path.c
2.61 +
2.62 +cocoa_path.obj: cocoaui/cocoa_path.c
2.63 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cocoa_path.obj -MD -MP -MF "$(DEPDIR)/cocoa_path.Tpo" -c -o cocoa_path.obj `if test -f 'cocoaui/cocoa_path.c'; then $(CYGPATH_W) 'cocoaui/cocoa_path.c'; else $(CYGPATH_W) '$(srcdir)/cocoaui/cocoa_path.c'; fi`; \
2.64 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cocoa_path.Tpo" "$(DEPDIR)/cocoa_path.Po"; else rm -f "$(DEPDIR)/cocoa_path.Tpo"; exit 1; fi
2.65 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cocoaui/cocoa_path.c' object='cocoa_path.obj' libtool=no @AMDEPBACKSLASH@
2.66 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.67 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cocoa_path.obj `if test -f 'cocoaui/cocoa_path.c'; then $(CYGPATH_W) 'cocoaui/cocoa_path.c'; else $(CYGPATH_W) '$(srcdir)/cocoaui/cocoa_path.c'; fi`
2.68 +
2.69 +cocoa_ctrl.o: cocoaui/cocoa_ctrl.c
2.70 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cocoa_ctrl.o -MD -MP -MF "$(DEPDIR)/cocoa_ctrl.Tpo" -c -o cocoa_ctrl.o `test -f 'cocoaui/cocoa_ctrl.c' || echo '$(srcdir)/'`cocoaui/cocoa_ctrl.c; \
2.71 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cocoa_ctrl.Tpo" "$(DEPDIR)/cocoa_ctrl.Po"; else rm -f "$(DEPDIR)/cocoa_ctrl.Tpo"; exit 1; fi
2.72 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cocoaui/cocoa_ctrl.c' object='cocoa_ctrl.o' libtool=no @AMDEPBACKSLASH@
2.73 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.74 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cocoa_ctrl.o `test -f 'cocoaui/cocoa_ctrl.c' || echo '$(srcdir)/'`cocoaui/cocoa_ctrl.c
2.75 +
2.76 +cocoa_ctrl.obj: cocoaui/cocoa_ctrl.c
2.77 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cocoa_ctrl.obj -MD -MP -MF "$(DEPDIR)/cocoa_ctrl.Tpo" -c -o cocoa_ctrl.obj `if test -f 'cocoaui/cocoa_ctrl.c'; then $(CYGPATH_W) 'cocoaui/cocoa_ctrl.c'; else $(CYGPATH_W) '$(srcdir)/cocoaui/cocoa_ctrl.c'; fi`; \
2.78 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cocoa_ctrl.Tpo" "$(DEPDIR)/cocoa_ctrl.Po"; else rm -f "$(DEPDIR)/cocoa_ctrl.Tpo"; exit 1; fi
2.79 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='cocoaui/cocoa_ctrl.c' object='cocoa_ctrl.obj' libtool=no @AMDEPBACKSLASH@
2.80 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
2.81 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cocoa_ctrl.obj `if test -f 'cocoaui/cocoa_ctrl.c'; then $(CYGPATH_W) 'cocoaui/cocoa_ctrl.c'; else $(CYGPATH_W) '$(srcdir)/cocoaui/cocoa_ctrl.c'; fi`
2.82 +
2.83 video_osx.o: drivers/video_osx.c
2.84 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT video_osx.o -MD -MP -MF "$(DEPDIR)/video_osx.Tpo" -c -o video_osx.o `test -f 'drivers/video_osx.c' || echo '$(srcdir)/'`drivers/video_osx.c; \
2.85 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/video_osx.Tpo" "$(DEPDIR)/video_osx.Po"; else rm -f "$(DEPDIR)/video_osx.Tpo"; exit 1; fi
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/src/cocoaui/cocoa_ctrl.c Wed Jul 23 11:11:30 2008 +0000
3.3 @@ -0,0 +1,101 @@
3.4 +/**
3.5 + * $Id$
3.6 + *
3.7 + * Construct and manage the controller configuration pane
3.8 + *
3.9 + * Copyright (c) 2008 Nathan Keynes.
3.10 + *
3.11 + * This program is free software; you can redistribute it and/or modify
3.12 + * it under the terms of the GNU General Public License as published by
3.13 + * the Free Software Foundation; either version 2 of the License, or
3.14 + * (at your option) any later version.
3.15 + *
3.16 + * This program is distributed in the hope that it will be useful,
3.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3.19 + * GNU General Public License for more details.
3.20 + */
3.21 +
3.22 +#include "cocoaui.h"
3.23 +#include "config.h"
3.24 +#include "maple/maple.h"
3.25 +
3.26 +#define MAX_DEVICES 4
3.27 +
3.28 +@implementation LxdreamPrefsControllerPane
3.29 ++ (LxdreamPrefsControllerPane *)new
3.30 +{
3.31 + return [[LxdreamPrefsControllerPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
3.32 +}
3.33 +- (id)initWithFrame: (NSRect)frameRect
3.34 +{
3.35 + if( [super initWithFrame: frameRect title: NS_("Controllers")] == nil ) {
3.36 + return nil;
3.37 + } else {
3.38 + const struct maple_device_class **devices = maple_get_device_classes();
3.39 + char buf[16];
3.40 + int i,j;
3.41 + int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
3.42 + for( i=0; i<MAX_DEVICES; i++ ) {
3.43 + save_controller[i] = NULL;
3.44 + maple_device_t device = maple_get_device(i,0);
3.45 + NSRect frame = NSMakeRect( TEXT_GAP, height -((TEXT_HEIGHT+TEXT_GAP)*i - 2),
3.46 + 50, LABEL_HEIGHT );
3.47 + snprintf( buf, sizeof(buf), _("Slot %d."), i );
3.48 + NSTextField *label = [self addLabel: [NSString stringWithUTF8String: buf]
3.49 + withFrame: frame ];
3.50 + [label setAlignment: NSRightTextAlignment];
3.51 + frame = NSMakeRect( 50 + (TEXT_GAP*2), height - ((TEXT_HEIGHT+TEXT_GAP)*i),
3.52 + 150, TEXT_HEIGHT );
3.53 + NSPopUpButton *popup = [[NSPopUpButton alloc] initWithFrame: frame pullsDown: NO];
3.54 + [popup addItemWithTitle: NS_("<empty>")];
3.55 + [popup setAutoresizingMask: (NSViewMinYMargin|NSViewMaxXMargin)];
3.56 + [[popup itemAtIndex: 0] setTag: 0];
3.57 + for( j=0; devices[j] != NULL; j++ ) {
3.58 + [popup addItemWithTitle: [NSString stringWithUTF8String: devices[j]->name]];
3.59 + if( device != NULL && device->device_class == devices[j] ) {
3.60 + [popup selectItemAtIndex: (j+1)];
3.61 + }
3.62 + [[popup itemAtIndex: (j+1)] setTag: (j+1)];
3.63 + }
3.64 + [popup setTarget: self];
3.65 + [popup setAction: @selector(deviceChanged:)];
3.66 + [popup setTag: i];
3.67 + [self addSubview: popup];
3.68 + }
3.69 + return self;
3.70 + }
3.71 +}
3.72 +- (void)deviceChanged: (id)sender
3.73 +{
3.74 + int slot = [sender tag];
3.75 + int new_device_idx = [sender indexOfSelectedItem] - 1;
3.76 + maple_device_class_t new_device_class = NULL;
3.77 +
3.78 + maple_device_t current = maple_get_device(slot,0);
3.79 + maple_device_t new_device = NULL;
3.80 + if( new_device_idx != -1 ) {
3.81 + new_device_class = maple_get_device_classes()[new_device_idx];
3.82 + }
3.83 + if( current == NULL ? new_device_class == NULL : current->device_class == new_device_class ) {
3.84 + // No change
3.85 + return;
3.86 + }
3.87 + if( current != NULL && current->device_class == &controller_class ) {
3.88 + save_controller[slot] = current->clone(current);
3.89 + }
3.90 + if( new_device_class == NULL ) {
3.91 + maple_detach_device(slot,0);
3.92 + } else {
3.93 + if( new_device_class == &controller_class && save_controller[slot] != NULL ) {
3.94 + new_device = save_controller[slot];
3.95 + save_controller[slot] = NULL;
3.96 + } else {
3.97 + new_device = maple_new_device( new_device_class->name );
3.98 + }
3.99 + maple_attach_device(new_device,slot,0);
3.100 + }
3.101 +
3.102 + lxdream_save_config();
3.103 +}
3.104 +@end
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/src/cocoaui/cocoa_path.c Wed Jul 23 11:11:30 2008 +0000
4.3 @@ -0,0 +1,72 @@
4.4 +/**
4.5 + * $Id$
4.6 + *
4.7 + * Construct and manage the paths configuration pane
4.8 + *
4.9 + * Copyright (c) 2008 Nathan Keynes.
4.10 + *
4.11 + * This program is free software; you can redistribute it and/or modify
4.12 + * it under the terms of the GNU General Public License as published by
4.13 + * the Free Software Foundation; either version 2 of the License, or
4.14 + * (at your option) any later version.
4.15 + *
4.16 + * This program is distributed in the hope that it will be useful,
4.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.19 + * GNU General Public License for more details.
4.20 + */
4.21 +
4.22 +#include "cocoaui.h"
4.23 +#include "config.h"
4.24 +
4.25 +
4.26 +
4.27 +@implementation LxdreamPrefsPathPane
4.28 ++ (LxdreamPrefsPathPane *)new
4.29 +{
4.30 + return [[LxdreamPrefsPathPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
4.31 +}
4.32 +- (id)initWithFrame: (NSRect)frameRect
4.33 +{
4.34 + if( [super initWithFrame: frameRect title: NS_("Paths")] == nil ) {
4.35 + return nil;
4.36 + } else {
4.37 + int i;
4.38 + int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
4.39 +
4.40 + for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
4.41 + const struct lxdream_config_entry *entry = lxdream_get_config_entry(i);
4.42 + if( entry->label != NULL ) {
4.43 + NSRect frame = NSMakeRect( TEXT_GAP, height -((TEXT_HEIGHT+TEXT_GAP)*i - 2),
4.44 + 150, LABEL_HEIGHT );
4.45 + NSTextField *label = [self addLabel: NS_(entry->label) withFrame: frame];
4.46 + [label setAlignment: NSRightTextAlignment];
4.47 +
4.48 + frame = NSMakeRect( 150 + (TEXT_GAP*2),
4.49 + height -((TEXT_HEIGHT+TEXT_GAP)*i),
4.50 + 360, TEXT_HEIGHT );
4.51 + NSTextField *field = [[NSTextField alloc] initWithFrame: frame];
4.52 + [field setTag: i];
4.53 + [field setStringValue: [NSString stringWithCString: entry->value]];
4.54 + [field setDelegate: self];
4.55 + [field setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];
4.56 + [self addSubview: label];
4.57 + [self addSubview: field];
4.58 + }
4.59 + }
4.60 + }
4.61 + return self;
4.62 +}
4.63 +- (void)controlTextDidEndEditing:(NSNotification *)notify
4.64 +{
4.65 + int tag = [[notify object] tag];
4.66 + const char *str = [[[notify object] stringValue] UTF8String];
4.67 + const char *oldval = lxdream_get_config_value(tag);
4.68 + if( str[0] == '\0' )
4.69 + str = NULL;
4.70 + if( oldval == NULL ? str != NULL : (str == NULL || strcmp(oldval,str) != 0 ) ) {
4.71 + lxdream_set_global_config_value(tag, str);
4.72 + lxdream_save_config();
4.73 + }
4.74 +}
4.75 +@end
5.1 --- a/src/cocoaui/cocoa_prefs.c Wed Jul 23 11:10:49 2008 +0000
5.2 +++ b/src/cocoaui/cocoa_prefs.c Wed Jul 23 11:11:30 2008 +0000
5.3 @@ -20,32 +20,123 @@
5.4 #include "lxdream.h"
5.5 #include "config.h"
5.6
5.7 -@interface LxdreamPrefsToolbarDelegate : NSObject {
5.8 - NSArray *identifiers;
5.9 - NSArray *defaults;
5.10 - NSDictionary *items;
5.11 +static LxdreamPrefsPanel *prefs_panel = NULL;
5.12 +
5.13 +@implementation LxdreamPrefsPane
5.14 +- (NSTextField *)addLabel: (NSString *)text withFrame: (NSRect)frame
5.15 +{
5.16 + NSTextField *label = [[NSTextField alloc] initWithFrame: frame];
5.17 + [label setStringValue: text];
5.18 + [label setBordered: NO];
5.19 + [label setDrawsBackground: NO];
5.20 + [label setEditable: NO];
5.21 + [label setAutoresizingMask: (NSViewMinYMargin|NSViewMaxXMargin)];
5.22 + [self addSubview: label];
5.23 + return label;
5.24 }
5.25 -- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
5.26 - tooltip: (NSString *)tooltip icon: (NSString *)icon
5.27 - action: (SEL) action;
5.28 +- (int)contentHeight
5.29 +{
5.30 + return [self frame].size.height - headerHeight;
5.31 +}
5.32 +
5.33 +- (id)initWithFrame: (NSRect)frameRect title:(NSString *)title
5.34 +{
5.35 + if( [super initWithFrame: frameRect ] == nil ) {
5.36 + return nil;
5.37 + } else {
5.38 + int height = frameRect.size.height - TEXT_GAP;
5.39 +
5.40 + NSFont *titleFont = [NSFont fontWithName: @"Helvetica-Bold" size: 16.0];
5.41 + NSRect fontRect = [titleFont boundingRectForFont];
5.42 + int titleHeight = fontRect.size.height + [titleFont descender];
5.43 + NSTextField *label = [self addLabel: title withFrame:
5.44 + NSMakeRect( TEXT_GAP, height-titleHeight,
5.45 + frameRect.size.width - (TEXT_GAP*2), titleHeight )];
5.46 + [label setFont: titleFont];
5.47 + height -= (titleHeight + TEXT_GAP);
5.48 +
5.49 + NSBox *rule = [[NSBox alloc] initWithFrame: NSMakeRect(1, height, frameRect.size.width-2, 1)];
5.50 + [rule setAutoresizingMask: (NSViewMinYMargin|NSViewWidthSizable)];
5.51 + [rule setBoxType: NSBoxSeparator];
5.52 + [self addSubview: rule];
5.53 + height -= TEXT_GAP;
5.54 +
5.55 + headerHeight = frameRect.size.height - height;
5.56 + return self;
5.57 + }
5.58 +}
5.59 @end
5.60
5.61 -@implementation LxdreamPrefsToolbarDelegate
5.62 -- (id) init
5.63 +
5.64 +@interface LxdreamPrefsPanel (Private)
5.65 +- (void) initToolbar;
5.66 +- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
5.67 +tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action;
5.68 +@end
5.69 +
5.70 +@implementation LxdreamPrefsPanel
5.71 +
5.72 +- (NSView *)createControlsPane
5.73 {
5.74 + NSView *pane = [[NSView alloc] initWithFrame: NSMakeRect(0,0,600,400)];
5.75 + return pane;
5.76 +}
5.77 +
5.78 +- (id)initWithContentRect:(NSRect)contentRect
5.79 +{
5.80 + if( [super initWithContentRect: contentRect
5.81 + styleMask: ( NSTitledWindowMask | NSClosableWindowMask |
5.82 + NSMiniaturizableWindowMask | NSResizableWindowMask |
5.83 + NSUnifiedTitleAndToolbarWindowMask )
5.84 + backing: NSBackingStoreBuffered defer: NO ] == nil ) {
5.85 + return nil;
5.86 + } else {
5.87 + [self setTitle: NS_("Preferences")];
5.88 + [self setDelegate: self];
5.89 + [self initToolbar];
5.90 + path_pane = [LxdreamPrefsPathPane new];
5.91 + ctrl_pane = [LxdreamPrefsControllerPane new];
5.92 +
5.93 + [self setContentView: path_pane];
5.94 + return self;
5.95 + }
5.96 +}
5.97 +- (void)windowWillClose: (NSNotification *)notice
5.98 +{
5.99 + prefs_panel = NULL;
5.100 +}
5.101 +- (void) initToolbar
5.102 +{
5.103 + NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
5.104 +
5.105 NSToolbarItem *paths = [self createToolbarItem: @"Paths" label: @"Paths"
5.106 tooltip: @"Configure system paths" icon: @"tb-paths"
5.107 action: @selector(paths_action:)];
5.108 NSToolbarItem *ctrls = [self createToolbarItem: @"Controllers" label: @"Controllers"
5.109 tooltip: @"Configure controllers" icon: @"tb-ctrls"
5.110 action: @selector(controllers_action:)];
5.111 - identifiers = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
5.112 - defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
5.113 + toolbar_ids = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
5.114 + toolbar_defaults = [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
5.115 NSArray *values = [NSArray arrayWithObjects: paths, ctrls, nil ];
5.116 - items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
5.117 - return self;
5.118 + toolbar_items = [NSDictionary dictionaryWithObjects: values forKeys: toolbar_ids];
5.119 +
5.120 + [toolbar setDelegate: self];
5.121 + [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
5.122 + [toolbar setSizeMode: NSToolbarSizeModeSmall];
5.123 + [toolbar setSelectedItemIdentifier: @"Paths"];
5.124 + [self setToolbar: toolbar];
5.125 }
5.126
5.127 +- (void)paths_action: (id)sender
5.128 +{
5.129 + [self setContentView: path_pane];
5.130 +}
5.131 +- (void)controllers_action: (id)sender
5.132 +{
5.133 + [self setContentView: ctrl_pane];
5.134 +}
5.135 +
5.136 +/***************************** Toolbar methods ***************************/
5.137 - (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
5.138 tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action
5.139 {
5.140 @@ -59,70 +150,32 @@
5.141 [item setAction: action];
5.142 return item;
5.143 }
5.144 -
5.145 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
5.146 {
5.147 - return identifiers;
5.148 + return toolbar_ids;
5.149 }
5.150
5.151 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
5.152 {
5.153 - return defaults;
5.154 + return toolbar_defaults;
5.155 }
5.156
5.157 - (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
5.158 {
5.159 - return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil];
5.160 + return [NSArray arrayWithObjects: @"Paths", @"Controllers", nil ];
5.161 }
5.162
5.163 - (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
5.164 willBeInsertedIntoToolbar:(BOOL)flag
5.165 {
5.166 - return [items objectForKey: itemIdentifier];
5.167 -}
5.168 -- (void)paths_action: (id)sender
5.169 -{
5.170 -}
5.171 -- (void)controllers_action: (id)sender
5.172 -{
5.173 + return [toolbar_items objectForKey: itemIdentifier];
5.174 }
5.175 @end
5.176
5.177 -@implementation LxdreamPrefsPanel
5.178 -- (NSView *)createPathsPane
5.179 +void cocoa_gui_show_preferences()
5.180 {
5.181 - NSView *pane = [NSView new];
5.182 - int i;
5.183 - for( i=0; i<=CONFIG_KEY_MAX; i++ ) {
5.184 - lxdream_config_entry_t entry = lxdream_get_config_entry(i);
5.185 - if( entry->label != NULL ) {
5.186 - }
5.187 + if( prefs_panel == NULL ) {
5.188 + prefs_panel = [[LxdreamPrefsPanel alloc] initWithContentRect: NSMakeRect(0,0,600,400)];
5.189 }
5.190 - return pane;
5.191 -}
5.192 -- (id)initWithContentRect:(NSRect)contentRect
5.193 -{
5.194 - if( [super initWithContentRect: contentRect
5.195 - styleMask: ( NSTitledWindowMask | NSClosableWindowMask |
5.196 - NSMiniaturizableWindowMask | NSResizableWindowMask |
5.197 - NSUnifiedTitleAndToolbarWindowMask )
5.198 - backing: NSBackingStoreBuffered defer: NO ] == nil ) {
5.199 - return nil;
5.200 - } else {
5.201 - [self setTitle: NS_("Preferences")];
5.202 - [self setDelegate: self];
5.203 - NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamPrefsToolbar"];
5.204 - [toolbar setDelegate: [[LxdreamPrefsToolbarDelegate alloc] init]];
5.205 - [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
5.206 - [toolbar setSizeMode: NSToolbarSizeModeSmall];
5.207 - [toolbar setSelectedItemIdentifier: @"Paths"];
5.208 - [self setToolbar: toolbar];
5.209 - [self setContentView: [self createPathsPane]];
5.210 - return self;
5.211 - }
5.212 -}
5.213 -- (void)windowWillClose: (NSNotification *)notice
5.214 -{
5.215 - [NSApp stopModal];
5.216 -}
5.217 -@end
5.218 + [prefs_panel makeKeyAndOrderFront: prefs_panel];
5.219 +}
5.220 \ No newline at end of file
6.1 --- a/src/cocoaui/cocoaui.c Wed Jul 23 11:10:49 2008 +0000
6.2 +++ b/src/cocoaui/cocoaui.c Wed Jul 23 11:11:30 2008 +0000
6.3 @@ -69,8 +69,8 @@
6.4 title = [@"About " stringByAppendingString:appName];
6.5 [appleMenu addItemWithTitle:title action:@selector(about_action:) keyEquivalent:@""];
6.6
6.7 - // [appleMenu addItem:[NSMenuItem separatorItem]];
6.8 - // [appleMenu addItemWithTitle: NS_("Preferences...") action:@selector(preferences_action:) keyEquivalent:@","];
6.9 + [appleMenu addItem:[NSMenuItem separatorItem]];
6.10 + [appleMenu addItemWithTitle: NS_("Preferences...") action:@selector(preferences_action:) keyEquivalent:@","];
6.11
6.12 // Services Menu
6.13 [appleMenu addItem:[NSMenuItem separatorItem]];
6.14 @@ -159,8 +159,7 @@
6.15 }
6.16 - (void) preferences_action: (id)sender
6.17 {
6.18 - LxdreamPrefsPanel *panel = [[LxdreamPrefsPanel alloc] initWithContentRect: NSMakeRect(0,0,600,400)];
6.19 - [NSApp runModalForWindow: panel];
6.20 + cocoa_gui_show_preferences();
6.21 }
6.22 - (void) load_action: (id)sender
6.23 {
7.1 --- a/src/cocoaui/cocoaui.h Wed Jul 23 11:10:49 2008 +0000
7.2 +++ b/src/cocoaui/cocoaui.h Wed Jul 23 11:11:30 2008 +0000
7.3 @@ -29,9 +29,15 @@
7.4
7.5 #define NS_(x) [NSString stringWithUTF8String: _(x)]
7.6
7.7 +/* Standard sizing */
7.8 +#define TEXT_HEIGHT 22
7.9 +#define LABEL_HEIGHT 17
7.10 +#define TEXT_GAP 10
7.11 +
7.12 NSWindow *cocoa_gui_create_main_window();
7.13 NSMenu *cocoa_gdrom_menu_new();
7.14 NSView *video_osx_create_drawable();
7.15 +void cocoa_gui_show_preferences();
7.16
7.17 @interface LxdreamMainWindow : NSWindow
7.18 {
7.19 @@ -46,12 +52,41 @@
7.20 - (void)setIsGrabbed:(BOOL)grab;
7.21 @end
7.22
7.23 +@interface LxdreamPrefsPane : NSView
7.24 +{
7.25 + int headerHeight;
7.26 +}
7.27 +- (id)initWithFrame: (NSRect)frameRect title:(NSString *)title;
7.28 +/**
7.29 + * Create a text label and add it to the pane
7.30 + */
7.31 +- (NSTextField *)addLabel: (NSString *)text withFrame: (NSRect)frame;
7.32 +- (int)contentHeight;
7.33 +@end
7.34 +
7.35 @interface LxdreamPrefsPanel : NSPanel
7.36 {
7.37 + NSArray *toolbar_ids;
7.38 + NSArray *toolbar_defaults;
7.39 + NSDictionary *toolbar_items;
7.40 + NSView *path_pane, *ctrl_pane;
7.41 }
7.42 - (id)initWithContentRect:(NSRect)contentRect;
7.43 @end
7.44
7.45 +@interface LxdreamPrefsPathPane: LxdreamPrefsPane
7.46 +{
7.47 +}
7.48 ++ (LxdreamPrefsPathPane *)new;
7.49 +@end
7.50 +
7.51 +@interface LxdreamPrefsControllerPane: LxdreamPrefsPane
7.52 +{
7.53 + struct maple_device *save_controller[4];
7.54 +}
7.55 ++ (LxdreamPrefsControllerPane *)new;
7.56 +@end
7.57 +
7.58 #ifdef __cplusplus
7.59 }
7.60 #endif
.