1 /*****************************************************************************
2 * prefs_widgets.m: Preferences controls
3 *****************************************************************************
4 * Copyright (C) 2002-2003 VideoLAN
7 * Authors: Derk-Jan Hartman <hartman at videolan.org>
8 * Jérôme Decoodt <djc at videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
35 #include "prefs_widgets.h"
37 #define PREFS_WRAP 300
38 #define OFFSET_RIGHT 20
39 #define OFFSET_BETWEEN 2
41 #define MACOS_VERSION [[[NSDictionary dictionaryWithContentsOfFile: \
42 @"/System/Library/CoreServices/SystemVersion.plist"] \
43 objectForKey: @"ProductVersion"] floatValue]
45 #define UPWARDS_WHITE_ARROW "\xE2\x87\xA7"
46 #define OPTION_KEY "\xE2\x8C\xA5"
47 #define UP_ARROWHEAD "\xE2\x8C\x83"
48 #define PLACE_OF_INTEREST_SIGN "\xE2\x8C\x98"
50 #define POPULATE_A_KEY( o_menu, string, value ) \
54 o_mi = [[NSMenuItem alloc] initWithTitle:string \
55 action:nil keyEquivalent:@""]; \
56 [o_mi setKeyEquivalentModifierMask: \
58 if( MACOS_VERSION >= 10.3 ) \
59 [o_mi setAlternate: NO]; \
62 [o_menu addItem: o_mi]; \
63 if( MACOS_VERSION >= 10.3 ) \
66 o_mi = [[NSMenuItem alloc] initWithTitle: \
67 [[NSString stringWithUTF8String: \
69 ] stringByAppendingString: string] \
70 action:nil keyEquivalent:@""]; \
71 [o_mi setKeyEquivalentModifierMask: \
73 [o_mi setAlternate: YES]; \
75 KEY_MODIFIER_CTRL | ( value )]; \
76 [o_menu addItem: o_mi]; \
78 o_mi = [[NSMenuItem alloc] initWithTitle: \
79 [[NSString stringWithUTF8String: \
80 UP_ARROWHEAD OPTION_KEY \
81 ] stringByAppendingString: string] \
82 action:nil keyEquivalent:@""]; \
83 [o_mi setKeyEquivalentModifierMask: \
84 NSControlKeyMask | NSAlternateKeyMask]; \
85 [o_mi setAlternate: YES]; \
87 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT) | ( value )]; \
88 [o_menu addItem: o_mi]; \
90 o_mi = [[NSMenuItem alloc] initWithTitle: \
91 [[NSString stringWithUTF8String: \
92 UP_ARROWHEAD UPWARDS_WHITE_ARROW \
93 ] stringByAppendingString: string] \
94 action:nil keyEquivalent:@""]; \
95 [o_mi setKeyEquivalentModifierMask: \
96 NSControlKeyMask | NSShiftKeyMask]; \
97 [o_mi setAlternate: YES]; \
99 (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT) | ( value )]; \
100 [o_menu addItem: o_mi]; \
102 o_mi = [[NSMenuItem alloc] initWithTitle: \
103 [[NSString stringWithUTF8String: \
104 UP_ARROWHEAD PLACE_OF_INTEREST_SIGN \
105 ] stringByAppendingString: string] \
106 action:nil keyEquivalent:@""]; \
107 [o_mi setKeyEquivalentModifierMask: \
108 NSControlKeyMask | NSCommandKeyMask]; \
109 [o_mi setAlternate: YES]; \
111 (KEY_MODIFIER_CTRL | KEY_MODIFIER_COMMAND) | ( value )]; \
112 [o_menu addItem: o_mi]; \
113 /* Ctrl+Alt+Shift */ \
114 o_mi = [[NSMenuItem alloc] initWithTitle: \
115 [[NSString stringWithUTF8String: \
116 UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW \
117 ] stringByAppendingString: string] \
118 action:nil keyEquivalent:@""]; \
119 [o_mi setKeyEquivalentModifierMask: \
120 NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask]; \
121 [o_mi setAlternate: YES]; \
123 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | \
125 [o_menu addItem: o_mi]; \
126 /* Ctrl+Alt+Apple */ \
127 o_mi = [[NSMenuItem alloc] initWithTitle: \
128 [[NSString stringWithUTF8String: \
129 UP_ARROWHEAD OPTION_KEY PLACE_OF_INTEREST_SIGN \
130 ] stringByAppendingString: string] \
131 action:nil keyEquivalent:@""]; \
132 [o_mi setKeyEquivalentModifierMask: \
133 NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask]; \
134 [o_mi setAlternate: YES]; \
136 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | \
138 [o_menu addItem: o_mi]; \
139 /* Ctrl+Shift+Apple */ \
140 o_mi = [[NSMenuItem alloc] initWithTitle: \
141 [[NSString stringWithUTF8String: \
142 UP_ARROWHEAD UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
143 ] stringByAppendingString: string] \
144 action:nil keyEquivalent:@""]; \
145 [o_mi setKeyEquivalentModifierMask: \
146 NSControlKeyMask | NSShiftKeyMask | NSCommandKeyMask]; \
147 [o_mi setAlternate: YES]; \
149 (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | \
151 [o_menu addItem: o_mi]; \
152 /* Ctrl+Alt+Shift+Apple */ \
153 o_mi = [[NSMenuItem alloc] initWithTitle: \
154 [[NSString stringWithUTF8String: \
155 UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW \
156 PLACE_OF_INTEREST_SIGN \
157 ] stringByAppendingString: string] \
158 action:nil keyEquivalent:@""]; \
159 [o_mi setKeyEquivalentModifierMask: \
160 NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask | \
162 [o_mi setAlternate: YES]; \
164 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | \
165 KEY_MODIFIER_COMMAND) | ( value )]; \
166 [o_menu addItem: o_mi]; \
168 o_mi = [[NSMenuItem alloc] initWithTitle: \
169 [[NSString stringWithUTF8String: \
171 ] stringByAppendingString: string] \
172 action:nil keyEquivalent:@""]; \
173 [o_mi setKeyEquivalentModifierMask: \
174 NSAlternateKeyMask]; \
175 [o_mi setAlternate: YES]; \
177 KEY_MODIFIER_ALT | ( value )]; \
178 [o_menu addItem: o_mi]; \
180 o_mi = [[NSMenuItem alloc] initWithTitle: \
181 [[NSString stringWithUTF8String: \
182 OPTION_KEY UPWARDS_WHITE_ARROW \
183 ] stringByAppendingString: string] \
184 action:nil keyEquivalent:@""]; \
185 [o_mi setKeyEquivalentModifierMask: \
186 NSAlternateKeyMask | NSShiftKeyMask]; \
187 [o_mi setAlternate: YES]; \
189 (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | ( value )]; \
190 [o_menu addItem: o_mi]; \
192 o_mi = [[NSMenuItem alloc] initWithTitle: \
193 [[NSString stringWithUTF8String: \
194 OPTION_KEY PLACE_OF_INTEREST_SIGN \
195 ] stringByAppendingString: string] \
196 action:nil keyEquivalent:@""]; \
197 [o_mi setKeyEquivalentModifierMask: \
198 NSAlternateKeyMask | NSCommandKeyMask]; \
199 [o_mi setAlternate: YES]; \
201 (KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | ( value )]; \
202 [o_menu addItem: o_mi]; \
203 /* Alt+Shift+Apple */ \
204 o_mi = [[NSMenuItem alloc] initWithTitle: \
205 [[NSString stringWithUTF8String: \
206 OPTION_KEY UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
207 ] stringByAppendingString: string] \
208 action:nil keyEquivalent:@""]; \
209 [o_mi setKeyEquivalentModifierMask: \
210 NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask]; \
211 [o_mi setAlternate: YES]; \
213 (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | \
215 [o_menu addItem: o_mi]; \
217 o_mi = [[NSMenuItem alloc] initWithTitle: \
218 [[NSString stringWithUTF8String: \
219 UPWARDS_WHITE_ARROW \
220 ] stringByAppendingString: string] \
221 action:nil keyEquivalent:@""]; \
222 [o_mi setKeyEquivalentModifierMask: \
224 [o_mi setAlternate: YES]; \
226 KEY_MODIFIER_SHIFT | ( value )]; \
227 [o_menu addItem: o_mi]; \
229 o_mi = [[NSMenuItem alloc] initWithTitle: \
230 [[NSString stringWithUTF8String: \
231 UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
232 ] stringByAppendingString: string] \
233 action:nil keyEquivalent:@""]; \
234 [o_mi setKeyEquivalentModifierMask: \
235 NSShiftKeyMask | NSCommandKeyMask]; \
236 [o_mi setAlternate: YES]; \
238 (KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | ( value )]; \
239 [o_menu addItem: o_mi]; \
241 o_mi = [[NSMenuItem alloc] initWithTitle: \
242 [[NSString stringWithUTF8String: \
243 PLACE_OF_INTEREST_SIGN \
244 ] stringByAppendingString: string] \
245 action:nil keyEquivalent:@""]; \
246 [o_mi setKeyEquivalentModifierMask: \
248 [o_mi setAlternate: YES]; \
250 KEY_MODIFIER_COMMAND | ( value )]; \
251 [o_menu addItem: o_mi]; \
255 #define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label ) \
257 NSRect s_rc = superFrame; \
258 s_rc.size.height = 17; \
259 s_rc.origin.x = x_offset - 3; \
260 s_rc.origin.y = superFrame.size.height - 17 + my_y_offset; \
261 o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain]; \
262 [o_label setDrawsBackground: NO]; \
263 [o_label setBordered: NO]; \
264 [o_label setEditable: NO]; \
265 [o_label setSelectable: NO]; \
266 [o_label setStringValue: label]; \
267 [o_label setFont:[NSFont systemFontOfSize:0]]; \
268 [o_label sizeToFit]; \
271 #define ADD_TEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset, \
272 my_width, tooltip, init_value ) \
274 NSRect s_rc = superFrame; \
275 s_rc.origin.x = x_offset; \
276 s_rc.origin.y = my_y_offset; \
277 s_rc.size.height = 22; \
278 s_rc.size.width = my_width; \
279 o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain]; \
280 [o_textfield setFont:[NSFont systemFontOfSize:0]]; \
281 [o_textfield setToolTip: tooltip]; \
282 [o_textfield setStringValue: init_value]; \
285 #define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset, \
288 NSRect s_rc = superFrame; \
289 s_rc.origin.x = x_offset + 2; \
290 s_rc.origin.y = my_y_offset; \
291 s_rc.size.height = 26; \
292 s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x - \
294 o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain]; \
295 [o_combo setFont:[NSFont systemFontOfSize:0]]; \
296 [o_combo setToolTip: tooltip]; \
297 [o_combo setUsesDataSource:TRUE]; \
298 [o_combo setDataSource:self]; \
299 [o_combo setNumberOfVisibleItems:10]; \
300 [o_combo setCompletes:YES]; \
303 #define ADD_RIGHT_BUTTON( o_button, superFrame, x_offset, my_y_offset, \
306 NSRect s_rc = superFrame; \
307 o_button = [[[NSButton alloc] initWithFrame: s_rc] retain]; \
308 [o_button setButtonType: NSMomentaryPushInButton]; \
309 [o_button setBezelStyle: NSRoundedBezelStyle]; \
310 [o_button setTitle: title]; \
311 [o_button setFont:[NSFont systemFontOfSize:0]]; \
312 [o_button sizeToFit]; \
313 s_rc = [o_button frame]; \
314 s_rc.origin.x = superFrame.size.width - [o_button frame].size.width - 6;\
315 s_rc.origin.y = my_y_offset - 6; \
316 s_rc.size.width += 12; \
317 [o_button setFrame: s_rc]; \
318 [o_button setToolTip: tooltip]; \
319 [o_button setTarget: self]; \
320 [o_button setAction: @selector(openFileDialog:)]; \
323 #define ADD_POPUP( o_popup, superFrame, x_offset, my_y_offset, x2_offset, \
326 NSRect s_rc = superFrame; \
327 s_rc.origin.x = x_offset - 1; \
328 s_rc.origin.y = my_y_offset; \
329 s_rc.size.height = 26; \
330 s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x - \
332 o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain]; \
333 [o_popup setFont:[NSFont systemFontOfSize:0]]; \
334 [o_popup setToolTip: tooltip]; \
337 #define ADD_STEPPER( o_stepper, superFrame, x_offset, my_y_offset, tooltip, \
340 NSRect s_rc = superFrame; \
341 s_rc.origin.x = x_offset; \
342 s_rc.origin.y = my_y_offset; \
343 s_rc.size.height = 23; \
344 s_rc.size.width = 23; \
345 o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain]; \
346 [o_stepper setFont:[NSFont systemFontOfSize:0]]; \
347 [o_stepper setToolTip: tooltip]; \
348 [o_stepper setMaxValue: higher]; \
349 [o_stepper setMinValue: lower]; \
350 [o_stepper setTarget: self]; \
351 [o_stepper setAction: @selector(stepperChanged:)]; \
352 [o_stepper sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask | \
353 NSLeftMouseDraggedMask]; \
356 #define ADD_SLIDER( o_slider, superFrame, x_offset, my_y_offset, my_width, \
357 tooltip, lower, higher ) \
359 NSRect s_rc = superFrame; \
360 s_rc.origin.x = x_offset; \
361 s_rc.origin.y = my_y_offset; \
362 s_rc.size.height = 21; \
363 s_rc.size.width = my_width; \
364 o_slider = [[[NSSlider alloc] initWithFrame: s_rc] retain]; \
365 [o_slider setFont:[NSFont systemFontOfSize:0]]; \
366 [o_slider setToolTip: tooltip]; \
367 [o_slider setMaxValue: higher]; \
368 [o_slider setMinValue: lower]; \
371 #define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, \
372 tooltip, init_value, position ) \
374 NSRect s_rc = superFrame; \
375 s_rc.size.height = 18; \
376 s_rc.origin.x = x_offset - 2; \
377 s_rc.origin.y = superFrame.size.height - 18 + my_y_offset; \
378 o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain]; \
379 [o_checkbox setFont:[NSFont systemFontOfSize:0]]; \
380 [o_checkbox setButtonType: NSSwitchButton]; \
381 [o_checkbox setImagePosition: position]; \
382 [o_checkbox setIntValue: init_value]; \
383 [o_checkbox setTitle: label]; \
384 [o_checkbox setToolTip: tooltip]; \
385 [o_checkbox sizeToFit]; \
388 @implementation VLCConfigControl
389 - (id)initWithFrame: (NSRect)frame
391 return [self initWithFrame: frame
395 - (id)initWithFrame: (NSRect)frame
396 item: (module_config_t *)_p_item
398 self = [super initWithFrame: frame];
403 psz_name = strdup( p_item->psz_name );
405 i_type = p_item->i_type;
407 b_advanced = p_item->b_advanced;
408 [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
413 - (void)setYPos:(int)i_yPos
415 NSRect frame = [self frame];
416 frame.origin.y = i_yPos;
417 [self setFrame:frame];
422 if( o_label ) [o_label release];
423 if( psz_name ) free( psz_name );
427 + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
432 case CONFIG_ITEM_STRING:
435 case CONFIG_ITEM_STRING:
438 case CONFIG_ITEM_STRING_LIST:
441 case CONFIG_ITEM_FILE:
444 case CONFIG_ITEM_MODULE:
447 case CONFIG_ITEM_INTEGER:
450 case CONFIG_ITEM_RANGED_INTEGER:
453 case CONFIG_ITEM_BOOL:
456 case CONFIG_ITEM_KEY_BEFORE_10_3:
459 case CONFIG_ITEM_KEY_AFTER_10_3:
462 case CONFIG_ITEM_MODULE_LIST:
470 case CONFIG_ITEM_STRING_LIST:
473 case CONFIG_ITEM_STRING:
476 case CONFIG_ITEM_STRING_LIST:
479 case CONFIG_ITEM_FILE:
482 case CONFIG_ITEM_MODULE:
485 case CONFIG_ITEM_INTEGER:
488 case CONFIG_ITEM_RANGED_INTEGER:
491 case CONFIG_ITEM_BOOL:
494 case CONFIG_ITEM_KEY_BEFORE_10_3:
497 case CONFIG_ITEM_KEY_AFTER_10_3:
500 case CONFIG_ITEM_MODULE_LIST:
508 case CONFIG_ITEM_FILE:
511 case CONFIG_ITEM_STRING:
514 case CONFIG_ITEM_STRING_LIST:
517 case CONFIG_ITEM_FILE:
520 case CONFIG_ITEM_MODULE:
523 case CONFIG_ITEM_INTEGER:
526 case CONFIG_ITEM_RANGED_INTEGER:
529 case CONFIG_ITEM_BOOL:
532 case CONFIG_ITEM_KEY_BEFORE_10_3:
535 case CONFIG_ITEM_KEY_AFTER_10_3:
538 case CONFIG_ITEM_MODULE_LIST:
546 case CONFIG_ITEM_MODULE:
549 case CONFIG_ITEM_STRING:
552 case CONFIG_ITEM_STRING_LIST:
555 case CONFIG_ITEM_FILE:
558 case CONFIG_ITEM_MODULE:
561 case CONFIG_ITEM_INTEGER:
564 case CONFIG_ITEM_RANGED_INTEGER:
567 case CONFIG_ITEM_BOOL:
570 case CONFIG_ITEM_KEY_BEFORE_10_3:
573 case CONFIG_ITEM_KEY_AFTER_10_3:
576 case CONFIG_ITEM_MODULE_LIST:
584 case CONFIG_ITEM_INTEGER:
587 case CONFIG_ITEM_STRING:
590 case CONFIG_ITEM_STRING_LIST:
593 case CONFIG_ITEM_FILE:
596 case CONFIG_ITEM_MODULE:
599 case CONFIG_ITEM_INTEGER:
602 case CONFIG_ITEM_RANGED_INTEGER:
605 case CONFIG_ITEM_BOOL:
608 case CONFIG_ITEM_KEY_BEFORE_10_3:
611 case CONFIG_ITEM_KEY_AFTER_10_3:
614 case CONFIG_ITEM_MODULE_LIST:
622 case CONFIG_ITEM_RANGED_INTEGER:
625 case CONFIG_ITEM_STRING:
628 case CONFIG_ITEM_STRING_LIST:
631 case CONFIG_ITEM_FILE:
634 case CONFIG_ITEM_MODULE:
637 case CONFIG_ITEM_INTEGER:
640 case CONFIG_ITEM_RANGED_INTEGER:
643 case CONFIG_ITEM_BOOL:
646 case CONFIG_ITEM_KEY_BEFORE_10_3:
649 case CONFIG_ITEM_KEY_AFTER_10_3:
652 case CONFIG_ITEM_MODULE_LIST:
660 case CONFIG_ITEM_BOOL:
663 case CONFIG_ITEM_STRING:
666 case CONFIG_ITEM_STRING_LIST:
669 case CONFIG_ITEM_FILE:
672 case CONFIG_ITEM_MODULE:
675 case CONFIG_ITEM_INTEGER:
678 case CONFIG_ITEM_RANGED_INTEGER:
681 case CONFIG_ITEM_BOOL:
684 case CONFIG_ITEM_KEY_BEFORE_10_3:
687 case CONFIG_ITEM_KEY_AFTER_10_3:
690 case CONFIG_ITEM_MODULE_LIST:
698 case CONFIG_ITEM_KEY_BEFORE_10_3:
701 case CONFIG_ITEM_STRING:
704 case CONFIG_ITEM_STRING_LIST:
707 case CONFIG_ITEM_FILE:
710 case CONFIG_ITEM_MODULE:
713 case CONFIG_ITEM_INTEGER:
716 case CONFIG_ITEM_RANGED_INTEGER:
719 case CONFIG_ITEM_BOOL:
722 case CONFIG_ITEM_KEY_BEFORE_10_3:
725 case CONFIG_ITEM_KEY_AFTER_10_3:
728 case CONFIG_ITEM_MODULE_LIST:
736 case CONFIG_ITEM_KEY_AFTER_10_3:
739 case CONFIG_ITEM_STRING:
742 case CONFIG_ITEM_STRING_LIST:
745 case CONFIG_ITEM_FILE:
748 case CONFIG_ITEM_MODULE:
751 case CONFIG_ITEM_INTEGER:
754 case CONFIG_ITEM_RANGED_INTEGER:
757 case CONFIG_ITEM_BOOL:
760 case CONFIG_ITEM_KEY_BEFORE_10_3:
763 case CONFIG_ITEM_KEY_AFTER_10_3:
766 case CONFIG_ITEM_MODULE_LIST:
774 case CONFIG_ITEM_MODULE_LIST:
777 case CONFIG_ITEM_STRING:
780 case CONFIG_ITEM_STRING_LIST:
783 case CONFIG_ITEM_FILE:
786 case CONFIG_ITEM_MODULE:
789 case CONFIG_ITEM_INTEGER:
792 case CONFIG_ITEM_RANGED_INTEGER:
795 case CONFIG_ITEM_BOOL:
798 case CONFIG_ITEM_KEY_BEFORE_10_3:
801 case CONFIG_ITEM_KEY_AFTER_10_3:
804 case CONFIG_ITEM_MODULE_LIST:
819 + (VLCConfigControl *)newControl: (module_config_t *)_p_item
820 withView: (NSView *)o_parent_view
822 VLCConfigControl *p_control = NULL;
823 switch( _p_item->i_type )
825 case CONFIG_ITEM_STRING:
826 if( !_p_item->i_list )
828 p_control = [[StringConfigControl alloc]
829 initWithItem: _p_item
830 withView: o_parent_view];
834 p_control = [[StringListConfigControl alloc]
835 initWithItem: _p_item
836 withView: o_parent_view];
839 case CONFIG_ITEM_FILE:
840 case CONFIG_ITEM_DIRECTORY:
841 p_control = [[FileConfigControl alloc]
842 initWithItem: _p_item
843 withView: o_parent_view];
845 case CONFIG_ITEM_MODULE:
846 case CONFIG_ITEM_MODULE_CAT:
847 p_control = [[ModuleConfigControl alloc]
848 initWithItem: _p_item
849 withView: o_parent_view];
851 case CONFIG_ITEM_INTEGER:
852 if( _p_item->i_list )
854 p_control = [[IntegerListConfigControl alloc]
855 initWithItem: _p_item
856 withView: o_parent_view];
858 else if( _p_item->i_min != 0 || _p_item->i_max != 0 )
860 p_control = [[RangedIntegerConfigControl alloc]
861 initWithItem: _p_item
862 withView: o_parent_view];
866 p_control = [[IntegerConfigControl alloc]
867 initWithItem: _p_item
868 withView: o_parent_view];
871 case CONFIG_ITEM_BOOL:
872 p_control = [[BoolConfigControl alloc]
873 initWithItem: _p_item
874 withView: o_parent_view];
876 case CONFIG_ITEM_FLOAT:
877 if( _p_item->f_min != 0 || _p_item->f_max != 0 )
879 p_control = [[RangedFloatConfigControl alloc]
880 initWithItem: _p_item
881 withView: o_parent_view];
885 p_control = [[FloatConfigControl alloc]
886 initWithItem: _p_item
887 withView: o_parent_view];
890 case CONFIG_ITEM_KEY:
891 if( MACOS_VERSION < 10.3 )
893 p_control = [[KeyConfigControlBefore103 alloc]
894 initWithItem: _p_item
895 withView: o_parent_view];
899 p_control = [[KeyConfigControlAfter103 alloc]
900 initWithItem: _p_item
901 withView: o_parent_view];
904 case CONFIG_ITEM_MODULE_LIST:
905 case CONFIG_ITEM_MODULE_LIST_CAT:
906 p_control = [[ModuleListConfigControl alloc]
907 initWithItem: _p_item
908 withView: o_parent_view];
916 - (NSString *)getName
918 return [[VLCMain sharedInstance] localizedString: psz_name];
946 - (char *)stringValue
954 switch( p_item->i_type )
956 case CONFIG_ITEM_STRING:
957 case CONFIG_ITEM_FILE:
958 case CONFIG_ITEM_DIRECTORY:
959 case CONFIG_ITEM_MODULE:
960 case CONFIG_ITEM_MODULE_LIST:
961 case CONFIG_ITEM_MODULE_LIST_CAT:
962 fprintf( stderr, "Applying %s to %s\n" , [self stringValue], psz_name );
963 config_PutPsz( VLCIntf, psz_name, [self stringValue] );
965 case CONFIG_ITEM_KEY:
966 /* So you don't need to restart to have the changes take effect */
967 fprintf( stderr, "Applying %d to %s\n" , [self intValue], psz_name );
968 val.i_int = [self intValue];
969 var_Set( VLCIntf->p_vlc, psz_name, val );
970 case CONFIG_ITEM_INTEGER:
971 case CONFIG_ITEM_BOOL:
972 fprintf( stderr, "Applying %d to %s\n" , [self intValue], psz_name );
973 config_PutInt( VLCIntf, psz_name, [self intValue] );
975 case CONFIG_ITEM_FLOAT:
976 fprintf( stderr, "Applying %f to %s\n" , [self floatValue], psz_name );
977 config_PutFloat( VLCIntf, psz_name, [self floatValue] );
984 return [o_label frame].size.width;
988 @implementation StringConfigControl
989 - (id) initWithItem: (module_config_t *)_p_item
990 withView: (NSView *)o_parent_view
992 NSRect mainFrame = [o_parent_view frame];
993 NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
994 mainFrame.size.height = 22;
995 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
996 mainFrame.origin.x = LEFTMARGIN;
997 mainFrame.origin.y = 0;
999 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1001 i_view_type = CONFIG_ITEM_STRING;
1003 if( p_item->psz_text )
1004 o_labelString = [[VLCMain sharedInstance]
1005 localizedString: p_item->psz_text];
1007 o_labelString = [NSString stringWithString:@""];
1008 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1009 [o_label setAutoresizingMask:NSViewNotSizable ];
1010 [self addSubview: o_label];
1012 /* build the textfield */
1013 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1014 [[VLCMain sharedInstance] localizedString: p_item->psz_longtext]
1015 toWidth: PREFS_WRAP];
1016 if( p_item->psz_value )
1017 o_textfieldString = [[VLCMain sharedInstance]
1018 localizedString: p_item->psz_value];
1020 o_textfieldString = [NSString stringWithString: @""];
1021 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1022 0, mainFrame.size.width - [o_label frame].size.width -
1023 2, o_textfieldTooltip, o_textfieldString )
1024 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1025 [self addSubview: o_textfield];
1030 - (void) alignWithXPosition:(int)i_xPos
1033 NSRect superFrame = [self frame];
1034 frame = [o_label frame];
1035 frame.origin.x = i_xPos - frame.size.width - 3;
1036 [o_label setFrame:frame];
1038 frame = [o_textfield frame];
1039 frame.origin.x = i_xPos + 2;
1040 frame.size.width = superFrame.size.width - frame.origin.x - 1;
1041 [o_textfield setFrame:frame];
1046 [o_textfield release];
1050 - (char *)stringValue
1052 return strdup( [[VLCMain sharedInstance] delocalizeString:
1053 [o_textfield stringValue]] );
1057 @implementation StringListConfigControl
1058 - (id) initWithItem: (module_config_t *)_p_item
1059 withView: (NSView *)o_parent_view
1061 NSRect mainFrame = [o_parent_view frame];
1062 NSString *o_labelString, *o_textfieldTooltip;
1063 mainFrame.size.height = 22;
1064 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1065 mainFrame.origin.x = LEFTMARGIN;
1066 mainFrame.origin.y = 0;
1068 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1071 i_view_type = CONFIG_ITEM_STRING_LIST;
1073 if( p_item->psz_text )
1074 o_labelString = [[VLCMain sharedInstance]
1075 localizedString: p_item->psz_text];
1077 o_labelString = [NSString stringWithString:@""];
1078 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1079 [o_label setAutoresizingMask:NSViewNotSizable ];
1080 [self addSubview: o_label];
1082 /* build the textfield */
1083 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1084 [[VLCMain sharedInstance]
1085 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1086 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1087 -2, 0, o_textfieldTooltip )
1088 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1089 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1090 if( p_item->psz_value &&
1091 !strcmp( p_item->psz_value, p_item->ppsz_list[i_index] ) )
1092 [o_combo selectItemAtIndex: i_index];
1093 [self addSubview: o_combo];
1098 - (void) alignWithXPosition:(int)i_xPos
1101 NSRect superFrame = [self frame];
1102 frame = [o_label frame];
1103 frame.origin.x = i_xPos - frame.size.width - 3;
1104 [o_label setFrame:frame];
1106 frame = [o_combo frame];
1107 frame.origin.x = i_xPos + 2;
1108 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1109 [o_combo setFrame:frame];
1118 - (char *)stringValue
1120 if( [o_combo indexOfSelectedItem] >= 0 )
1121 return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
1123 return strdup( [[VLCMain sharedInstance]
1124 delocalizeString: [o_combo stringValue]] );
1128 @implementation StringListConfigControl (NSComboBoxDataSource)
1129 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1131 return p_item->i_list;
1134 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1136 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1138 return [[VLCMain sharedInstance]
1139 localizedString: p_item->ppsz_list_text[i_index]];
1140 } else return [[VLCMain sharedInstance]
1141 localizedString: p_item->ppsz_list[i_index]];
1145 @implementation FileConfigControl
1146 - (id) initWithItem: (module_config_t *)_p_item
1147 withView: (NSView *)o_parent_view
1149 NSRect mainFrame = [o_parent_view frame];
1150 NSString *o_labelString, *o_buttonTooltip, *o_textfieldString;
1151 NSString *o_textfieldTooltip;
1152 mainFrame.size.height = 46;
1153 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1154 mainFrame.origin.x = LEFTMARGIN;
1155 mainFrame.origin.y = 0;
1157 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1159 i_view_type = CONFIG_ITEM_FILE;
1161 /* is it a directory */
1162 b_directory = ( [self getType] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1165 if( p_item->psz_text )
1166 o_labelString = [[VLCMain sharedInstance]
1167 localizedString: p_item->psz_text];
1169 o_labelString = [NSString stringWithString:@""];
1170 ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString )
1171 [o_label setAutoresizingMask:NSViewNotSizable ];
1172 [self addSubview: o_label];
1174 /* build the button */
1175 o_buttonTooltip = [[VLCMain sharedInstance]
1176 wrapString: [[VLCMain sharedInstance]
1177 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1178 ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_buttonTooltip,
1180 [o_button setAutoresizingMask:NSViewMinXMargin ];
1181 [self addSubview: o_button];
1183 /* build the textfield */
1184 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1185 [[VLCMain sharedInstance]
1186 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1187 if( p_item->psz_value )
1188 o_textfieldString = [[VLCMain sharedInstance]
1189 localizedString: p_item->psz_value];
1191 o_textfieldString = [NSString stringWithString: @""];
1192 ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1193 8 - [o_button frame].size.width,
1194 o_textfieldTooltip, o_textfieldString )
1195 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1196 [self addSubview: o_textfield];
1201 - (void) alignWithXPosition:(int)i_xPos
1208 [o_textfield release];
1213 - (IBAction)openFileDialog: (id)sender
1215 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1217 [o_open_panel setTitle: (b_directory)?
1218 _NS("Select a directory"):_NS("Select a file")];
1219 [o_open_panel setPrompt: _NS("Select")];
1220 [o_open_panel setAllowsMultipleSelection: NO];
1221 [o_open_panel setCanChooseFiles: !b_directory];
1222 [o_open_panel setCanChooseDirectories: b_directory];
1223 [o_open_panel beginSheetForDirectory:nil
1226 modalForWindow:[sender window]
1228 didEndSelector: @selector(pathChosenInPanel:
1234 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1235 withReturn:(int)i_return_code contextInfo:(void *)o_context_info
1237 if( i_return_code == NSOKButton )
1239 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
1240 [o_textfield setStringValue: o_path];
1244 - (char *)stringValue
1246 if( [[o_textfield stringValue] length] != 0)
1247 return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1253 @implementation ModuleConfigControl
1254 - (id) initWithItem: (module_config_t *)_p_item
1255 withView: (NSView *)o_parent_view
1257 NSRect mainFrame = [o_parent_view frame];
1258 NSString *o_labelString, *o_popupTooltip;
1259 mainFrame.size.height = 22;
1260 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1261 mainFrame.origin.x = LEFTMARGIN;
1262 mainFrame.origin.y = 0;
1264 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1269 i_view_type = CONFIG_ITEM_MODULE;
1272 if( p_item->psz_text )
1273 o_labelString = [[VLCMain sharedInstance]
1274 localizedString: p_item->psz_text];
1276 o_labelString = [NSString stringWithString:@""];
1277 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
1278 [o_label setAutoresizingMask:NSViewNotSizable ];
1279 [self addSubview: o_label];
1281 /* build the popup */
1282 o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1283 [[VLCMain sharedInstance]
1284 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1285 ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1286 -2, 0, o_popupTooltip )
1287 [o_popup setAutoresizingMask:NSViewWidthSizable ];
1288 [o_popup addItemWithTitle: _NS("Default")];
1289 [[o_popup lastItem] setTag: -1];
1290 [o_popup selectItem: [o_popup lastItem]];
1292 /* build a list of available modules */
1293 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1294 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1296 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1297 if( p_item->i_type == CONFIG_ITEM_MODULE )
1299 if( !strcmp( p_parser->psz_capability,
1300 p_item->psz_type ) )
1302 NSString *o_description = [[VLCMain sharedInstance]
1303 localizedString: p_parser->psz_longname];
1304 [o_popup addItemWithTitle: o_description];
1306 if( p_item->psz_value &&
1307 !strcmp( p_item->psz_value, p_parser->psz_object_name ) )
1308 [o_popup selectItem:[o_popup lastItem]];
1313 module_config_t *p_config;
1314 if( !strcmp( p_parser->psz_object_name, "main" ) )
1317 p_config = p_parser->p_config;
1320 /* Hack: required subcategory is stored in i_min */
1321 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1322 p_config->i_value == p_item->i_min )
1324 NSString *o_description = [[VLCMain sharedInstance]
1325 localizedString: p_parser->psz_longname];
1326 [o_popup addItemWithTitle: o_description];
1328 if( p_item->psz_value && !strcmp(p_item->psz_value,
1329 p_parser->psz_object_name) )
1330 [o_popup selectItem:[o_popup lastItem]];
1332 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
1335 vlc_list_release( p_list );
1336 [self addSubview: o_popup];
1341 - (void) alignWithXPosition:(int)i_xPos
1344 NSRect superFrame = [self frame];
1345 frame = [o_label frame];
1346 frame.origin.x = i_xPos - frame.size.width - 3;
1347 [o_label setFrame:frame];
1349 frame = [o_popup frame];
1350 frame.origin.x = i_xPos - 1;
1351 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1352 [o_popup setFrame:frame];
1361 - (char *)stringValue
1363 NSString *newval = [o_popup titleOfSelectedItem];
1364 char *returnval = NULL;
1369 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1370 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1372 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1373 if( p_item->i_type == CONFIG_ITEM_MODULE )
1375 if( !strcmp( p_parser->psz_capability,
1376 p_item->psz_type ) )
1378 NSString *o_description = [[VLCMain sharedInstance]
1379 localizedString: p_parser->psz_longname];
1380 if( [newval isEqualToString: o_description] )
1382 returnval = strdup(p_parser->psz_object_name);
1389 module_config_t *p_config;
1390 if( !strcmp( p_parser->psz_object_name, "main" ) )
1393 p_config = p_parser->p_config;
1396 /* Hack: required subcategory is stored in i_min */
1397 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1398 p_config->i_value == p_item->i_min )
1400 NSString *o_description = [[VLCMain sharedInstance]
1401 localizedString: p_parser->psz_longname];
1402 if( [newval isEqualToString: o_description] )
1404 returnval = strdup(p_parser->psz_object_name);
1408 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
1411 vlc_list_release( p_list );
1416 @implementation IntegerConfigControl
1417 - (id) initWithItem: (module_config_t *)_p_item
1418 withView: (NSView *)o_parent_view
1420 NSRect mainFrame = [o_parent_view frame];
1421 NSString *o_labelString, *o_tooltip, *o_textfieldString;
1422 mainFrame.size.height = 23;
1423 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1424 mainFrame.origin.x = LEFTMARGIN;
1425 mainFrame.origin.y = 0;
1427 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1429 i_view_type = CONFIG_ITEM_INTEGER;
1431 o_tooltip = [[VLCMain sharedInstance] wrapString:
1432 [[VLCMain sharedInstance]
1433 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1436 if( p_item->psz_text )
1437 o_labelString = [[VLCMain sharedInstance]
1438 localizedString: p_item->psz_text];
1440 o_labelString = [NSString stringWithString:@""];
1441 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1442 [o_label setAutoresizingMask:NSViewNotSizable ];
1443 [self addSubview: o_label];
1445 /* build the stepper */
1446 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1447 0, o_tooltip, -1600, 1600)
1448 [o_stepper setIntValue: p_item->i_value];
1449 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1450 [self addSubview: o_stepper];
1452 /* build the textfield */
1453 if( p_item->psz_value )
1454 o_textfieldString = [[VLCMain sharedInstance]
1455 localizedString: p_item->psz_value];
1457 o_textfieldString = [NSString stringWithString: @""];
1458 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1459 1, 49, o_tooltip, @"" )
1460 [o_textfield setIntValue: p_item->i_value];
1461 [o_textfield setDelegate: self];
1462 [[NSNotificationCenter defaultCenter] addObserver: self
1463 selector: @selector(textfieldChanged:)
1464 name: NSControlTextDidChangeNotification
1465 object: o_textfield];
1466 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1467 [self addSubview: o_textfield];
1472 - (void) alignWithXPosition:(int)i_xPos
1475 frame = [o_label frame];
1476 frame.origin.x = i_xPos - frame.size.width - 3;
1477 [o_label setFrame:frame];
1479 frame = [o_textfield frame];
1480 frame.origin.x = i_xPos + 2;
1481 [o_textfield setFrame:frame];
1483 frame = [o_stepper frame];
1484 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1485 [o_stepper setFrame:frame];
1490 [o_stepper release];
1491 [o_textfield release];
1495 - (IBAction)stepperChanged:(id)sender
1497 [o_textfield setIntValue: [o_stepper intValue]];
1500 - (void)textfieldChanged:(NSNotification *)o_notification
1502 [o_stepper setIntValue: [o_textfield intValue]];
1507 return [o_textfield intValue];
1512 @implementation IntegerListConfigControl
1514 - (id) initWithItem: (module_config_t *)_p_item
1515 withView: (NSView *)o_parent_view
1517 NSRect mainFrame = [o_parent_view frame];
1518 NSString *o_labelString, *o_textfieldTooltip;
1519 mainFrame.size.height = 22;
1520 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1521 mainFrame.origin.x = LEFTMARGIN;
1522 mainFrame.origin.y = 0;
1524 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1527 i_view_type = CONFIG_ITEM_STRING_LIST;
1530 if( p_item->psz_text )
1531 o_labelString = [[VLCMain sharedInstance]
1532 localizedString: p_item->psz_text];
1534 o_labelString = [NSString stringWithString:@""];
1535 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1536 [o_label setAutoresizingMask:NSViewNotSizable ];
1537 [self addSubview: o_label];
1539 /* build the textfield */
1540 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1541 [[VLCMain sharedInstance]
1542 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1543 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1544 -2, 0, o_textfieldTooltip )
1545 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1546 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1548 if( p_item->i_value == p_item->pi_list[i_index] )
1550 [o_combo selectItemAtIndex: i_index];
1553 [self addSubview: o_combo];
1558 - (void) alignWithXPosition:(int)i_xPos
1561 NSRect superFrame = [self frame];
1562 frame = [o_label frame];
1563 frame.origin.x = i_xPos - frame.size.width - 3;
1564 [o_label setFrame:frame];
1566 frame = [o_combo frame];
1567 frame.origin.x = i_xPos + 2;
1568 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1569 [o_combo setFrame:frame];
1580 if( [o_combo indexOfSelectedItem] >= 0 )
1581 return p_item->pi_list[[o_combo indexOfSelectedItem]];
1583 return [o_combo intValue];
1587 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1588 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1590 return p_item->i_list;
1593 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1595 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1596 return [[VLCMain sharedInstance]
1597 localizedString: p_item->ppsz_list_text[i_index]];
1599 return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1603 @implementation RangedIntegerConfigControl
1604 - (id) initWithItem: (module_config_t *)_p_item
1605 withView: (NSView *)o_parent_view
1607 NSRect mainFrame = [o_parent_view frame];
1608 NSString *o_labelString, *o_tooltip;
1609 mainFrame.size.height = 50;
1610 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1611 mainFrame.origin.x = LEFTMARGIN;
1612 mainFrame.origin.y = 0;
1614 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1616 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1619 if( p_item->psz_text )
1620 o_labelString = [[VLCMain sharedInstance]
1621 localizedString: p_item->psz_text];
1623 o_labelString = [NSString stringWithString:@""];
1624 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1625 [o_label setAutoresizingMask:NSViewNotSizable ];
1626 [self addSubview: o_label];
1628 /* build the textfield */
1629 o_tooltip = [[VLCMain sharedInstance] wrapString:
1630 [[VLCMain sharedInstance]
1631 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1632 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1633 28, 49, o_tooltip, @"" )
1634 [o_textfield setIntValue: p_item->i_value];
1635 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1636 [o_textfield setDelegate: self];
1637 [[NSNotificationCenter defaultCenter] addObserver: self
1638 selector: @selector(textfieldChanged:)
1639 name: NSControlTextDidChangeNotification
1640 object: o_textfield];
1641 [self addSubview: o_textfield];
1643 /* build the mintextfield */
1644 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1645 [o_textfield_min setIntValue: p_item->i_min];
1646 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1647 [o_textfield_min setAlignment:NSRightTextAlignment];
1648 [self addSubview: o_textfield_min];
1650 /* build the maxtextfield */
1651 ADD_LABEL( o_textfield_max, mainFrame,
1652 mainFrame.size.width - 31, -30, @"8888" )
1653 [o_textfield_max setIntValue: p_item->i_max];
1654 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1655 [self addSubview: o_textfield_max];
1657 /* build the slider */
1658 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1659 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1660 [o_textfield_max frame].size.width -
1661 [o_textfield_max frame].size.width - 14 -
1662 [o_textfield_min frame].origin.x, o_tooltip,
1663 p_item->i_min, p_item->i_max )
1664 [o_slider setIntValue: p_item->i_value];
1665 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1666 [o_slider setTarget: self];
1667 [o_slider setAction: @selector(sliderChanged:)];
1668 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1669 NSLeftMouseDraggedMask];
1670 [self addSubview: o_slider];
1676 - (void) alignWithXPosition:(int)i_xPos
1679 frame = [o_label frame];
1680 frame.origin.x = i_xPos - frame.size.width - 3;
1681 [o_label setFrame:frame];
1683 frame = [o_textfield frame];
1684 frame.origin.x = i_xPos + 2;
1685 [o_textfield setFrame:frame];
1690 [o_textfield release];
1691 [o_textfield_min release];
1692 [o_textfield_max release];
1697 - (IBAction)sliderChanged:(id)sender
1699 [o_textfield setIntValue: [o_slider intValue]];
1702 - (void)textfieldChanged:(NSNotification *)o_notification
1704 [o_slider setIntValue: [o_textfield intValue]];
1709 return [o_slider intValue];
1713 @implementation FloatConfigControl
1714 - (id) initWithItem: (module_config_t *)_p_item
1715 withView: (NSView *)o_parent_view
1717 NSRect mainFrame = [o_parent_view frame];
1718 NSString *o_labelString, *o_tooltip, *o_textfieldString;
1719 mainFrame.size.height = 23;
1720 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1721 mainFrame.origin.x = LEFTMARGIN;
1722 mainFrame.origin.y = 0;
1724 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1726 i_view_type = CONFIG_ITEM_INTEGER;
1728 o_tooltip = [[VLCMain sharedInstance] wrapString:
1729 [[VLCMain sharedInstance]
1730 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1733 if( p_item->psz_text )
1734 o_labelString = [[VLCMain sharedInstance]
1735 localizedString: p_item->psz_text];
1737 o_labelString = [NSString stringWithString:@""];
1738 ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1739 [o_label setAutoresizingMask:NSViewNotSizable ];
1740 [self addSubview: o_label];
1742 /* build the stepper */
1743 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1744 0, o_tooltip, -1600, 1600)
1745 [o_stepper setFloatValue: p_item->f_value];
1746 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1747 [self addSubview: o_stepper];
1749 /* build the textfield */
1750 if( p_item->psz_value )
1751 o_textfieldString = [[VLCMain sharedInstance]
1752 localizedString: p_item->psz_value];
1754 o_textfieldString = [NSString stringWithString: @""];
1755 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1756 1, 49, o_tooltip, @"" )
1757 [o_textfield setFloatValue: p_item->f_value];
1758 [o_textfield setDelegate: self];
1759 [[NSNotificationCenter defaultCenter] addObserver: self
1760 selector: @selector(textfieldChanged:)
1761 name: NSControlTextDidChangeNotification
1762 object: o_textfield];
1763 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1764 [self addSubview: o_textfield];
1769 - (void) alignWithXPosition:(int)i_xPos
1772 frame = [o_label frame];
1773 frame.origin.x = i_xPos - frame.size.width - 3;
1774 [o_label setFrame:frame];
1776 frame = [o_textfield frame];
1777 frame.origin.x = i_xPos + 2;
1778 [o_textfield setFrame:frame];
1780 frame = [o_stepper frame];
1781 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1782 [o_stepper setFrame:frame];
1787 [o_stepper release];
1788 [o_textfield release];
1792 - (IBAction)stepperChanged:(id)sender
1794 [o_textfield setFloatValue: [o_stepper floatValue]];
1797 - (void)textfieldChanged:(NSNotification *)o_notification
1799 [o_stepper setFloatValue: [o_textfield floatValue]];
1804 return [o_stepper floatValue];
1808 @implementation RangedFloatConfigControl
1809 - (id) initWithItem: (module_config_t *)_p_item
1810 withView: (NSView *)o_parent_view
1812 NSRect mainFrame = [o_parent_view frame];
1813 NSString *o_labelString, *o_tooltip;
1814 mainFrame.size.height = 50;
1815 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1816 mainFrame.origin.x = LEFTMARGIN;
1817 mainFrame.origin.y = 0;
1819 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1821 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1824 if( p_item->psz_text )
1825 o_labelString = [[VLCMain sharedInstance]
1826 localizedString: p_item->psz_text];
1828 o_labelString = [NSString stringWithString:@""];
1829 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1830 [o_label setAutoresizingMask:NSViewNotSizable ];
1831 [self addSubview: o_label];
1833 /* build the textfield */
1834 o_tooltip = [[VLCMain sharedInstance] wrapString:
1835 [[VLCMain sharedInstance]
1836 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1837 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1838 28, 49, o_tooltip, @"" )
1839 [o_textfield setFloatValue: p_item->f_value];
1840 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1841 [o_textfield setDelegate: self];
1842 [[NSNotificationCenter defaultCenter] addObserver: self
1843 selector: @selector(textfieldChanged:)
1844 name: NSControlTextDidChangeNotification
1845 object: o_textfield];
1846 [self addSubview: o_textfield];
1848 /* build the mintextfield */
1849 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1850 [o_textfield_min setFloatValue: p_item->f_min];
1851 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1852 [o_textfield_min setAlignment:NSRightTextAlignment];
1853 [self addSubview: o_textfield_min];
1855 /* build the maxtextfield */
1856 ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1858 [o_textfield_max setFloatValue: p_item->f_max];
1859 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1860 [self addSubview: o_textfield_max];
1862 /* build the slider */
1863 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1864 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1865 [o_textfield_max frame].size.width -
1866 [o_textfield_max frame].size.width - 14 -
1867 [o_textfield_min frame].origin.x, o_tooltip, p_item->f_min,
1869 [o_slider setFloatValue: p_item->f_value];
1870 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1871 [o_slider setTarget: self];
1872 [o_slider setAction: @selector(sliderChanged:)];
1873 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1874 NSLeftMouseDraggedMask];
1875 [self addSubview: o_slider];
1881 - (void) alignWithXPosition:(int)i_xPos
1884 frame = [o_label frame];
1885 frame.origin.x = i_xPos - frame.size.width - 3;
1886 [o_label setFrame:frame];
1888 frame = [o_textfield frame];
1889 frame.origin.x = i_xPos + 2;
1890 [o_textfield setFrame:frame];
1895 [o_textfield release];
1896 [o_textfield_min release];
1897 [o_textfield_max release];
1902 - (IBAction)sliderChanged:(id)sender
1904 [o_textfield setFloatValue: [o_slider floatValue]];
1907 - (void)textfieldChanged:(NSNotification *)o_notification
1909 [o_slider setFloatValue: [o_textfield floatValue]];
1914 return [o_slider floatValue];
1919 @implementation BoolConfigControl
1921 - (id) initWithItem: (module_config_t *)_p_item
1922 withView: (NSView *)o_parent_view
1924 NSRect mainFrame = [o_parent_view frame];
1925 NSString *o_labelString, *o_tooltip;
1926 mainFrame.size.height = 17;
1927 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1928 mainFrame.origin.x = LEFTMARGIN;
1929 mainFrame.origin.y = 0;
1931 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1933 i_view_type = CONFIG_ITEM_BOOL;
1936 if( p_item->psz_text )
1937 o_labelString = [[VLCMain sharedInstance]
1938 localizedString: p_item->psz_text];
1940 o_labelString = [NSString stringWithString:@""];
1941 ADD_LABEL( o_label, mainFrame, 0, 0, o_labelString )
1942 [o_label setAutoresizingMask:NSViewNotSizable ];
1943 [self addSubview: o_label];
1944 /* add the checkbox */
1945 o_tooltip = [[VLCMain sharedInstance]
1946 wrapString: [[VLCMain sharedInstance]
1947 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
1948 ADD_CHECKBOX( o_checkbox, mainFrame, [o_label frame].size.width,
1949 0, @"", o_tooltip, p_item->i_value, NSImageLeft)
1950 [o_checkbox setAutoresizingMask:NSViewNotSizable ];
1951 [self addSubview: o_checkbox];
1956 - (void) alignWithXPosition:(int)i_xPos
1959 frame = [o_label frame];
1960 frame.origin.x = i_xPos - frame.size.width - 3;
1961 [o_label setFrame:frame];
1963 frame = [o_checkbox frame];
1964 frame.origin.x = i_xPos;
1965 [o_checkbox setFrame:frame];
1970 [o_checkbox release];
1976 return [o_checkbox intValue];
1981 @implementation KeyConfigControlBefore103
1983 - (id) initWithItem: (module_config_t *)_p_item
1984 withView: (NSView *)o_parent_view
1986 NSRect mainFrame = [o_parent_view frame];
1987 NSString *o_labelString, *o_tooltip;
1988 mainFrame.size.height = 37;
1989 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1990 mainFrame.origin.x = LEFTMARGIN;
1991 mainFrame.origin.y = 0;
1993 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1995 i_view_type = CONFIG_ITEM_KEY_BEFORE_10_3;
1998 if( p_item->psz_text )
1999 o_labelString = [[VLCMain sharedInstance]
2000 localizedString: p_item->psz_text];
2002 o_labelString = [NSString stringWithString:@""];
2003 ADD_LABEL( o_label, mainFrame, 0, -10, o_labelString )
2004 [o_label setAutoresizingMask:NSViewNotSizable ];
2005 [self addSubview: o_label];
2007 /* add the checkboxes */
2008 o_tooltip = [[VLCMain sharedInstance] wrapString:
2009 [[VLCMain sharedInstance]
2010 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2011 ADD_CHECKBOX( o_cmd_checkbox, mainFrame,
2012 [o_label frame].size.width + 2, 0,
2013 [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN], o_tooltip,
2014 ((((unsigned int)p_item->i_value) & KEY_MODIFIER_COMMAND)?YES:NO),
2016 [o_cmd_checkbox setState: p_item->i_value & KEY_MODIFIER_COMMAND];
2017 ADD_CHECKBOX( o_ctrl_checkbox, mainFrame,
2018 [o_cmd_checkbox frame].size.width +
2019 [o_cmd_checkbox frame].origin.x + 6, 0,
2020 [NSString stringWithUTF8String:UP_ARROWHEAD], o_tooltip,
2021 ((((unsigned int)p_item->i_value) & KEY_MODIFIER_CTRL)?YES:NO),
2023 [o_ctrl_checkbox setState: p_item->i_value & KEY_MODIFIER_CTRL];
2024 ADD_CHECKBOX( o_alt_checkbox, mainFrame, [o_label frame].size.width +
2025 2, -2 - [o_cmd_checkbox frame].size.height,
2026 [NSString stringWithUTF8String:OPTION_KEY], o_tooltip,
2027 ((((unsigned int)p_item->i_value) & KEY_MODIFIER_ALT)?YES:NO),
2029 [o_alt_checkbox setState: p_item->i_value & KEY_MODIFIER_ALT];
2030 ADD_CHECKBOX( o_shift_checkbox, mainFrame,
2031 [o_cmd_checkbox frame].size.width +
2032 [o_cmd_checkbox frame].origin.x + 6, -2 -
2033 [o_cmd_checkbox frame].size.height,
2034 [NSString stringWithUTF8String:UPWARDS_WHITE_ARROW], o_tooltip,
2035 ((((unsigned int)p_item->i_value) & KEY_MODIFIER_SHIFT)?YES:NO),
2037 [o_shift_checkbox setState: p_item->i_value & KEY_MODIFIER_SHIFT];
2038 [self addSubview: o_cmd_checkbox];
2039 [self addSubview: o_ctrl_checkbox];
2040 [self addSubview: o_alt_checkbox];
2041 [self addSubview: o_shift_checkbox];
2043 /* build the popup */
2044 ADD_POPUP( o_popup, mainFrame, [o_shift_checkbox frame].origin.x +
2045 [o_shift_checkbox frame].size.width + 4,
2047 [o_popup setAutoresizingMask:NSViewWidthSizable ];
2049 if( o_keys_menu == nil )
2052 o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2053 for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2054 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2055 POPULATE_A_KEY( o_keys_menu,
2056 [NSString stringWithCString:vlc_keys[i].psz_key_string]
2057 , vlc_keys[i].i_key_code)
2059 [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2060 [o_popup selectItemWithTitle: [[VLCMain sharedInstance]
2061 localizedString:KeyToString(
2062 (((unsigned int)p_item->i_value) & ~KEY_MODIFIER ))]];
2063 [self addSubview: o_popup];
2068 - (void) alignWithXPosition:(int)i_xPos
2071 NSRect superFrame = [self frame];
2072 frame = [o_label frame];
2073 frame.origin.x = i_xPos - frame.size.width - 3;
2074 [o_label setFrame:frame];
2076 frame = [o_cmd_checkbox frame];
2077 frame.origin.x = i_xPos;
2078 [o_cmd_checkbox setFrame:frame];
2080 frame = [o_ctrl_checkbox frame];
2081 frame.origin.x = [o_cmd_checkbox frame].size.width +
2082 [o_cmd_checkbox frame].origin.x + 4;
2083 [o_ctrl_checkbox setFrame:frame];
2085 frame = [o_alt_checkbox frame];
2086 frame.origin.x = i_xPos;
2087 [o_alt_checkbox setFrame:frame];
2089 frame = [o_shift_checkbox frame];
2090 frame.origin.x = [o_cmd_checkbox frame].size.width +
2091 [o_cmd_checkbox frame].origin.x + 4;
2092 [o_shift_checkbox setFrame:frame];
2094 frame = [o_popup frame];
2095 frame.origin.x = [o_shift_checkbox frame].origin.x +
2096 [o_shift_checkbox frame].size.width + 3;
2097 frame.size.width = superFrame.size.width - frame.origin.x + 2;
2098 [o_popup setFrame:frame];
2103 [o_cmd_checkbox release];
2104 [o_ctrl_checkbox release];
2105 [o_alt_checkbox release];
2106 [o_shift_checkbox release];
2113 unsigned int i_new_key = 0;
2115 i_new_key |= ([o_cmd_checkbox state] == NSOnState) ?
2116 KEY_MODIFIER_COMMAND : 0;
2117 i_new_key |= ([o_ctrl_checkbox state] == NSOnState) ?
2118 KEY_MODIFIER_CTRL : 0;
2119 i_new_key |= ([o_alt_checkbox state] == NSOnState) ?
2120 KEY_MODIFIER_ALT : 0;
2121 i_new_key |= ([o_shift_checkbox state] == NSOnState) ?
2122 KEY_MODIFIER_SHIFT : 0;
2124 i_new_key |= StringToKey([[[o_popup selectedItem] title] cString]);
2129 @implementation KeyConfigControlAfter103
2130 - (id) initWithItem: (module_config_t *)_p_item
2131 withView: (NSView *)o_parent_view
2133 NSRect mainFrame = [o_parent_view frame];
2134 NSString *o_labelString, *o_tooltip;
2135 mainFrame.size.height = 22;
2136 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
2137 mainFrame.origin.x = LEFTMARGIN;
2138 mainFrame.origin.y = 0;
2140 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2142 i_view_type = CONFIG_ITEM_KEY_AFTER_10_3;
2145 if( p_item->psz_text )
2146 o_labelString = [[VLCMain sharedInstance]
2147 localizedString: p_item->psz_text];
2149 o_labelString = [NSString stringWithString:@""];
2150 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
2151 [o_label setAutoresizingMask:NSViewNotSizable ];
2152 [self addSubview: o_label];
2154 /* build the popup */
2155 o_tooltip = [[VLCMain sharedInstance] wrapString:
2156 [[VLCMain sharedInstance]
2157 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2158 ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2159 [o_label frame].size.width + 3,
2161 [o_popup setAutoresizingMask:NSViewWidthSizable ];
2163 if( o_keys_menu == nil )
2166 o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2167 for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2168 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2169 POPULATE_A_KEY( o_keys_menu,
2170 [NSString stringWithCString:vlc_keys[i].psz_key_string]
2171 , vlc_keys[i].i_key_code)
2173 [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2174 [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->i_value]];
2175 [self addSubview: o_popup];
2181 - (void) alignWithXPosition:(int)i_xPos
2184 NSRect superFrame = [self frame];
2185 frame = [o_label frame];
2186 frame.origin.x = i_xPos - frame.size.width - 3;
2187 [o_label setFrame:frame];
2189 frame = [o_popup frame];
2190 frame.origin.x = i_xPos - 1;
2191 frame.size.width = superFrame.size.width - frame.origin.x + 2;
2192 [o_popup setFrame:frame];
2203 return [o_popup selectedTag];
2207 @implementation ModuleListConfigControl
2208 - (id) initWithItem: (module_config_t *)_p_item
2209 withView: (NSView *)o_parent_view
2211 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2215 //Fill our array to know how may items we have...
2219 NSRect mainFrame = [o_parent_view frame];
2220 NSString *o_labelString, *o_textfieldString, *o_tooltip;
2222 o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2223 /* build a list of available modules */
2224 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2225 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2227 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2229 if( !strcmp( p_parser->psz_object_name, "main" ) )
2232 module_config_t *p_config = p_parser->p_config;
2235 NSString *o_modulelongname, *o_modulename;
2236 NSNumber *o_moduleenabled = nil;
2237 /* Hack: required subcategory is stored in i_min */
2238 if( p_config->i_type == CONFIG_SUBCATEGORY &&
2239 p_config->i_value == _p_item->i_min )
2241 o_modulelongname = [NSString stringWithUTF8String:
2242 p_parser->psz_longname];
2243 o_modulename = [NSString stringWithUTF8String:
2244 p_parser->psz_object_name];
2246 if( _p_item->psz_value &&
2247 strstr( _p_item->psz_value, p_parser->psz_object_name ) )
2248 o_moduleenabled = [NSNumber numberWithBool:YES];
2250 o_moduleenabled = [NSNumber numberWithBool:NO];
2252 [o_modulearray addObject:[NSMutableArray
2253 arrayWithObjects: o_modulename, o_modulelongname,
2254 o_moduleenabled, nil]];
2256 } while( p_config->i_type != CONFIG_HINT_END && p_config++ );
2258 vlc_list_release( p_list );
2260 mainFrame.size.height = 30 + 18 * [o_modulearray count];
2261 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2262 mainFrame.origin.x = LEFTMARGIN;
2263 mainFrame.origin.y = 0;
2264 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2266 i_view_type = CONFIG_ITEM_MODULE_LIST;
2269 if( p_item->psz_text )
2270 o_labelString = [[VLCMain sharedInstance]
2271 localizedString: p_item->psz_text];
2273 o_labelString = [NSString stringWithString:@""];
2274 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
2275 [o_label setAutoresizingMask:NSViewNotSizable ];
2276 [self addSubview: o_label];
2278 /* build the textfield */
2279 o_tooltip = [[VLCMain sharedInstance] wrapString:
2280 [[VLCMain sharedInstance]
2281 localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP];
2282 if( p_item->psz_value )
2283 o_textfieldString = [[VLCMain sharedInstance]
2284 localizedString: p_item->psz_value];
2286 o_textfieldString = [NSString stringWithString: @""];
2287 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2288 mainFrame.size.height - 22, mainFrame.size.width -
2289 [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2290 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2291 [self addSubview: o_textfield];
2295 NSRect s_rc = mainFrame;
2296 s_rc.size.height = mainFrame.size.height - 30;
2297 s_rc.size.width = mainFrame.size.width - 12;
2300 o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2301 [o_scrollview setDrawsBackground: NO];
2302 [o_scrollview setBorderType: NSBezelBorder];
2303 [o_scrollview setAutohidesScrollers:YES];
2305 NSTableView *o_tableview;
2306 o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2307 [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2308 [o_tableview setHeaderView:nil];
2309 /* TODO: find a good way to fix the row height and text size*/
2310 /* FIXME: support for multiple selection... */
2311 // [o_tableview setAllowsMultipleSelection:YES];
2313 NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2314 NSCell *o_dataCell = [[NSButtonCell alloc] init];
2315 [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2316 [o_dataCell setTitle:@""];
2317 [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2318 NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2319 initWithIdentifier:[NSString stringWithCString: "Enabled"]];
2320 [o_tableColumn setHeaderCell: o_headerCell];
2321 [o_tableColumn setDataCell: o_dataCell];
2322 [o_tableColumn setWidth:17];
2323 [o_tableview addTableColumn: o_tableColumn];
2325 o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2326 o_dataCell = [[NSTextFieldCell alloc] init];
2327 [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2328 o_tableColumn = [[NSTableColumn alloc]
2329 initWithIdentifier:[NSString stringWithCString: "Module"]];
2330 [o_tableColumn setHeaderCell: o_headerCell];
2331 [o_tableColumn setDataCell: o_dataCell];
2332 [o_tableColumn setWidth:388 - 17];
2333 [o_tableview addTableColumn: o_tableColumn];
2334 [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2335 @"VLC media player module", nil]];
2337 [o_tableview setDataSource:self];
2338 [o_tableview setTarget: self];
2339 [o_tableview setAction: @selector(tableChanged:)];
2340 [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2341 NSLeftMouseDraggedMask];
2342 [o_scrollview setDocumentView: o_tableview];
2344 [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2345 [self addSubview: o_scrollview];
2352 - (void) alignWithXPosition:(int)i_xPos
2357 - (IBAction)tableChanged:(id)sender
2359 NSString *o_newstring = @"";
2361 for( i = 0 ; i < [o_modulearray count] ; i++ )
2362 if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2365 o_newstring = [o_newstring stringByAppendingString:
2366 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2367 o_newstring = [o_newstring stringByAppendingString:@","];
2370 [o_textfield setStringValue: [o_newstring
2371 substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2376 [o_scrollview release];
2381 - (char *)stringValue
2383 return strdup( [[o_textfield stringValue] cString] );
2388 @implementation ModuleListConfigControl (NSTableDataSource)
2390 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2391 toPasteboard:(NSPasteboard*)pb
2393 // We only want to allow dragging of selected rows.
2394 NSEnumerator *iter = [rows objectEnumerator];
2396 while ((row = [iter nextObject]) != nil)
2398 if (![table isRowSelected:[row intValue]])
2402 [pb declareTypes:[NSArray
2403 arrayWithObject:@"VLC media player module"] owner:nil];
2404 [pb setPropertyList:rows forType:@"VLC media player module"];
2408 - (NSDragOperation)tableView:(NSTableView*)table
2409 validateDrop:(id <NSDraggingInfo>)info proposedRow:(int)row
2410 proposedDropOperation:(NSTableViewDropOperation)op
2412 // Make drops at the end of the table go to the end.
2415 row = [table numberOfRows];
2416 op = NSTableViewDropAbove;
2417 [table setDropRow:row dropOperation:op];
2420 // We don't ever want to drop onto a row, only between rows.
2421 if (op == NSTableViewDropOn)
2422 [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2423 return NSTableViewDropAbove;
2426 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2427 row:(int)dropRow dropOperation:(NSTableViewDropOperation)op;
2429 NSPasteboard *pb = [info draggingPasteboard];
2430 NSDragOperation srcMask = [info draggingSourceOperationMask];
2437 // Intra-table drag - data is the array of rows.
2438 if (!accepted && (array =
2439 [pb propertyListForType:@"VLC media player module"]) != NULL)
2441 NSEnumerator *iter = nil;
2443 BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2445 iter = [array objectEnumerator];
2446 while ((val = [iter nextObject]) != NULL)
2448 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2449 [val intValue]] mutableCopyWithZone:nil];
2450 [o_modulearray removeObject:o_tmp];
2451 [o_modulearray insertObject:o_tmp
2452 atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2456 // Select the newly-dragged items.
2457 iter = [array objectEnumerator];
2459 [table deselectAll:self];
2461 [self tableChanged:self];
2462 [table setNeedsDisplay:YES];
2463 // Indicate that we finished the drag.
2467 [table setNeedsDisplay:YES];
2471 // An exception occurred. Uh-oh. Update the track table so that
2472 // it stays consistent, and re-raise the exception.
2474 [localException raise];
2475 [table setNeedsDisplay:YES];
2481 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
2483 return [o_modulearray count];
2486 - (id)tableView:(NSTableView *)aTableView
2487 objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2489 if( [[aTableColumn identifier] isEqualToString:
2490 [NSString stringWithCString:"Enabled"]] )
2491 return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2492 if( [[aTableColumn identifier] isEqualToString:
2493 [NSString stringWithCString:"Module"]] )
2494 return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2499 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2500 forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
2502 [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2503 withObject: anObject];