1 /*****************************************************************************
2 * prefs_widgets.m: Preferences controls
3 *****************************************************************************
4 * Copyright (C) 2002-2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 UPWARDS_WHITE_ARROW "\xE2\x87\xA7"
42 #define OPTION_KEY "\xE2\x8C\xA5"
43 #define UP_ARROWHEAD "\xE2\x8C\x83"
44 #define PLACE_OF_INTEREST_SIGN "\xE2\x8C\x98"
46 #define POPULATE_A_KEY( o_menu, string, value ) \
50 o_mi = [[NSMenuItem alloc] initWithTitle:string \
51 action:nil keyEquivalent:@""]; \
52 [o_mi setKeyEquivalentModifierMask: \
54 if( MACOS_VERSION >= 10.3 ) \
55 [o_mi setAlternate: NO]; \
58 [o_menu addItem: o_mi]; \
59 if( MACOS_VERSION >= 10.3 ) \
62 o_mi = [[NSMenuItem alloc] initWithTitle: \
63 [[NSString stringWithUTF8String: \
65 ] stringByAppendingString: string] \
66 action:nil keyEquivalent:@""]; \
67 [o_mi setKeyEquivalentModifierMask: \
69 [o_mi setAlternate: YES]; \
71 KEY_MODIFIER_CTRL | ( value )]; \
72 [o_menu addItem: o_mi]; \
74 o_mi = [[NSMenuItem alloc] initWithTitle: \
75 [[NSString stringWithUTF8String: \
76 UP_ARROWHEAD OPTION_KEY \
77 ] stringByAppendingString: string] \
78 action:nil keyEquivalent:@""]; \
79 [o_mi setKeyEquivalentModifierMask: \
80 NSControlKeyMask | NSAlternateKeyMask]; \
81 [o_mi setAlternate: YES]; \
83 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT) | ( value )]; \
84 [o_menu addItem: o_mi]; \
86 o_mi = [[NSMenuItem alloc] initWithTitle: \
87 [[NSString stringWithUTF8String: \
88 UP_ARROWHEAD UPWARDS_WHITE_ARROW \
89 ] stringByAppendingString: string] \
90 action:nil keyEquivalent:@""]; \
91 [o_mi setKeyEquivalentModifierMask: \
92 NSControlKeyMask | NSShiftKeyMask]; \
93 [o_mi setAlternate: YES]; \
95 (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT) | ( value )]; \
96 [o_menu addItem: o_mi]; \
98 o_mi = [[NSMenuItem alloc] initWithTitle: \
99 [[NSString stringWithUTF8String: \
100 UP_ARROWHEAD PLACE_OF_INTEREST_SIGN \
101 ] stringByAppendingString: string] \
102 action:nil keyEquivalent:@""]; \
103 [o_mi setKeyEquivalentModifierMask: \
104 NSControlKeyMask | NSCommandKeyMask]; \
105 [o_mi setAlternate: YES]; \
107 (KEY_MODIFIER_CTRL | KEY_MODIFIER_COMMAND) | ( value )]; \
108 [o_menu addItem: o_mi]; \
109 /* Ctrl+Alt+Shift */ \
110 o_mi = [[NSMenuItem alloc] initWithTitle: \
111 [[NSString stringWithUTF8String: \
112 UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW \
113 ] stringByAppendingString: string] \
114 action:nil keyEquivalent:@""]; \
115 [o_mi setKeyEquivalentModifierMask: \
116 NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask]; \
117 [o_mi setAlternate: YES]; \
119 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | \
121 [o_menu addItem: o_mi]; \
122 /* Ctrl+Alt+Apple */ \
123 o_mi = [[NSMenuItem alloc] initWithTitle: \
124 [[NSString stringWithUTF8String: \
125 UP_ARROWHEAD OPTION_KEY PLACE_OF_INTEREST_SIGN \
126 ] stringByAppendingString: string] \
127 action:nil keyEquivalent:@""]; \
128 [o_mi setKeyEquivalentModifierMask: \
129 NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask]; \
130 [o_mi setAlternate: YES]; \
132 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | \
134 [o_menu addItem: o_mi]; \
135 /* Ctrl+Shift+Apple */ \
136 o_mi = [[NSMenuItem alloc] initWithTitle: \
137 [[NSString stringWithUTF8String: \
138 UP_ARROWHEAD UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
139 ] stringByAppendingString: string] \
140 action:nil keyEquivalent:@""]; \
141 [o_mi setKeyEquivalentModifierMask: \
142 NSControlKeyMask | NSShiftKeyMask | NSCommandKeyMask]; \
143 [o_mi setAlternate: YES]; \
145 (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | \
147 [o_menu addItem: o_mi]; \
148 /* Ctrl+Alt+Shift+Apple */ \
149 o_mi = [[NSMenuItem alloc] initWithTitle: \
150 [[NSString stringWithUTF8String: \
151 UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW \
152 PLACE_OF_INTEREST_SIGN \
153 ] stringByAppendingString: string] \
154 action:nil keyEquivalent:@""]; \
155 [o_mi setKeyEquivalentModifierMask: \
156 NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask | \
158 [o_mi setAlternate: YES]; \
160 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | \
161 KEY_MODIFIER_COMMAND) | ( value )]; \
162 [o_menu addItem: o_mi]; \
164 o_mi = [[NSMenuItem alloc] initWithTitle: \
165 [[NSString stringWithUTF8String: \
167 ] stringByAppendingString: string] \
168 action:nil keyEquivalent:@""]; \
169 [o_mi setKeyEquivalentModifierMask: \
170 NSAlternateKeyMask]; \
171 [o_mi setAlternate: YES]; \
173 KEY_MODIFIER_ALT | ( value )]; \
174 [o_menu addItem: o_mi]; \
176 o_mi = [[NSMenuItem alloc] initWithTitle: \
177 [[NSString stringWithUTF8String: \
178 OPTION_KEY UPWARDS_WHITE_ARROW \
179 ] stringByAppendingString: string] \
180 action:nil keyEquivalent:@""]; \
181 [o_mi setKeyEquivalentModifierMask: \
182 NSAlternateKeyMask | NSShiftKeyMask]; \
183 [o_mi setAlternate: YES]; \
185 (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | ( value )]; \
186 [o_menu addItem: o_mi]; \
188 o_mi = [[NSMenuItem alloc] initWithTitle: \
189 [[NSString stringWithUTF8String: \
190 OPTION_KEY PLACE_OF_INTEREST_SIGN \
191 ] stringByAppendingString: string] \
192 action:nil keyEquivalent:@""]; \
193 [o_mi setKeyEquivalentModifierMask: \
194 NSAlternateKeyMask | NSCommandKeyMask]; \
195 [o_mi setAlternate: YES]; \
197 (KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | ( value )]; \
198 [o_menu addItem: o_mi]; \
199 /* Alt+Shift+Apple */ \
200 o_mi = [[NSMenuItem alloc] initWithTitle: \
201 [[NSString stringWithUTF8String: \
202 OPTION_KEY UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
203 ] stringByAppendingString: string] \
204 action:nil keyEquivalent:@""]; \
205 [o_mi setKeyEquivalentModifierMask: \
206 NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask]; \
207 [o_mi setAlternate: YES]; \
209 (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | \
211 [o_menu addItem: o_mi]; \
213 o_mi = [[NSMenuItem alloc] initWithTitle: \
214 [[NSString stringWithUTF8String: \
215 UPWARDS_WHITE_ARROW \
216 ] stringByAppendingString: string] \
217 action:nil keyEquivalent:@""]; \
218 [o_mi setKeyEquivalentModifierMask: \
220 [o_mi setAlternate: YES]; \
222 KEY_MODIFIER_SHIFT | ( value )]; \
223 [o_menu addItem: o_mi]; \
225 o_mi = [[NSMenuItem alloc] initWithTitle: \
226 [[NSString stringWithUTF8String: \
227 UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
228 ] stringByAppendingString: string] \
229 action:nil keyEquivalent:@""]; \
230 [o_mi setKeyEquivalentModifierMask: \
231 NSShiftKeyMask | NSCommandKeyMask]; \
232 [o_mi setAlternate: YES]; \
234 (KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | ( value )]; \
235 [o_menu addItem: o_mi]; \
237 o_mi = [[NSMenuItem alloc] initWithTitle: \
238 [[NSString stringWithUTF8String: \
239 PLACE_OF_INTEREST_SIGN \
240 ] stringByAppendingString: string] \
241 action:nil keyEquivalent:@""]; \
242 [o_mi setKeyEquivalentModifierMask: \
244 [o_mi setAlternate: YES]; \
246 KEY_MODIFIER_COMMAND | ( value )]; \
247 [o_menu addItem: o_mi]; \
251 #define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label ) \
253 NSRect s_rc = superFrame; \
254 s_rc.size.height = 17; \
255 s_rc.origin.x = x_offset - 3; \
256 s_rc.origin.y = superFrame.size.height - 17 + my_y_offset; \
257 o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain]; \
258 [o_label setDrawsBackground: NO]; \
259 [o_label setBordered: NO]; \
260 [o_label setEditable: NO]; \
261 [o_label setSelectable: NO]; \
262 [o_label setStringValue: label]; \
263 [o_label setFont:[NSFont systemFontOfSize:0]]; \
264 [o_label sizeToFit]; \
267 #define ADD_TEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset, \
268 my_width, tooltip, init_value ) \
270 NSRect s_rc = superFrame; \
271 s_rc.origin.x = x_offset; \
272 s_rc.origin.y = my_y_offset; \
273 s_rc.size.height = 22; \
274 s_rc.size.width = my_width; \
275 o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain]; \
276 [o_textfield setFont:[NSFont systemFontOfSize:0]]; \
277 [o_textfield setToolTip: tooltip]; \
278 [o_textfield setStringValue: init_value]; \
281 #define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset, \
284 NSRect s_rc = superFrame; \
285 s_rc.origin.x = x_offset + 2; \
286 s_rc.origin.y = my_y_offset; \
287 s_rc.size.height = 26; \
288 s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x - \
290 o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain]; \
291 [o_combo setFont:[NSFont systemFontOfSize:0]]; \
292 [o_combo setToolTip: tooltip]; \
293 [o_combo setUsesDataSource:TRUE]; \
294 [o_combo setDataSource:self]; \
295 [o_combo setNumberOfVisibleItems:10]; \
296 [o_combo setCompletes:YES]; \
299 #define ADD_RIGHT_BUTTON( o_button, superFrame, x_offset, my_y_offset, \
302 NSRect s_rc = superFrame; \
303 o_button = [[[NSButton alloc] initWithFrame: s_rc] retain]; \
304 [o_button setButtonType: NSMomentaryPushInButton]; \
305 [o_button setBezelStyle: NSRoundedBezelStyle]; \
306 [o_button setTitle: title]; \
307 [o_button setFont:[NSFont systemFontOfSize:0]]; \
308 [o_button sizeToFit]; \
309 s_rc = [o_button frame]; \
310 s_rc.origin.x = superFrame.size.width - [o_button frame].size.width - 6;\
311 s_rc.origin.y = my_y_offset - 6; \
312 s_rc.size.width += 12; \
313 [o_button setFrame: s_rc]; \
314 [o_button setToolTip: tooltip]; \
315 [o_button setTarget: self]; \
316 [o_button setAction: @selector(openFileDialog:)]; \
319 #define ADD_POPUP( o_popup, superFrame, x_offset, my_y_offset, x2_offset, \
322 NSRect s_rc = superFrame; \
323 s_rc.origin.x = x_offset - 1; \
324 s_rc.origin.y = my_y_offset; \
325 s_rc.size.height = 26; \
326 s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x - \
328 o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain]; \
329 [o_popup setFont:[NSFont systemFontOfSize:0]]; \
330 [o_popup setToolTip: tooltip]; \
333 #define ADD_STEPPER( o_stepper, superFrame, x_offset, my_y_offset, tooltip, \
336 NSRect s_rc = superFrame; \
337 s_rc.origin.x = x_offset; \
338 s_rc.origin.y = my_y_offset; \
339 s_rc.size.height = 23; \
340 s_rc.size.width = 23; \
341 o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain]; \
342 [o_stepper setFont:[NSFont systemFontOfSize:0]]; \
343 [o_stepper setToolTip: tooltip]; \
344 [o_stepper setMaxValue: higher]; \
345 [o_stepper setMinValue: lower]; \
346 [o_stepper setTarget: self]; \
347 [o_stepper setAction: @selector(stepperChanged:)]; \
348 [o_stepper sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask | \
349 NSLeftMouseDraggedMask]; \
352 #define ADD_SLIDER( o_slider, superFrame, x_offset, my_y_offset, my_width, \
353 tooltip, lower, higher ) \
355 NSRect s_rc = superFrame; \
356 s_rc.origin.x = x_offset; \
357 s_rc.origin.y = my_y_offset; \
358 s_rc.size.height = 21; \
359 s_rc.size.width = my_width; \
360 o_slider = [[[NSSlider alloc] initWithFrame: s_rc] retain]; \
361 [o_slider setFont:[NSFont systemFontOfSize:0]]; \
362 [o_slider setToolTip: tooltip]; \
363 [o_slider setMaxValue: higher]; \
364 [o_slider setMinValue: lower]; \
367 #define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, \
368 tooltip, init_value, position ) \
370 NSRect s_rc = superFrame; \
371 s_rc.size.height = 18; \
372 s_rc.origin.x = x_offset - 2; \
373 s_rc.origin.y = superFrame.size.height - 18 + my_y_offset; \
374 o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain]; \
375 [o_checkbox setFont:[NSFont systemFontOfSize:0]]; \
376 [o_checkbox setButtonType: NSSwitchButton]; \
377 [o_checkbox setImagePosition: position]; \
378 [o_checkbox setIntValue: init_value]; \
379 [o_checkbox setTitle: label]; \
380 [o_checkbox setToolTip: tooltip]; \
381 [o_checkbox sizeToFit]; \
384 @implementation VLCConfigControl
385 - (id)initWithFrame: (NSRect)frame
387 return [self initWithFrame: frame
391 - (id)initWithFrame: (NSRect)frame
392 item: (module_config_t *)_p_item
394 self = [super initWithFrame: frame];
399 psz_name = strdup( p_item->psz_name );
401 i_type = p_item->i_type;
403 b_advanced = p_item->b_advanced;
404 [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
409 - (void)setYPos:(int)i_yPos
411 NSRect frame = [self frame];
412 frame.origin.y = i_yPos;
413 [self setFrame:frame];
418 if( o_label ) [o_label release];
419 if( psz_name ) free( psz_name );
423 + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
428 case CONFIG_ITEM_STRING:
431 case CONFIG_ITEM_STRING:
434 case CONFIG_ITEM_STRING_LIST:
437 case CONFIG_ITEM_FILE:
440 case CONFIG_ITEM_MODULE:
443 case CONFIG_ITEM_INTEGER:
446 case CONFIG_ITEM_RANGED_INTEGER:
449 case CONFIG_ITEM_BOOL:
452 case CONFIG_ITEM_KEY_BEFORE_10_3:
455 case CONFIG_ITEM_KEY_AFTER_10_3:
458 case CONFIG_ITEM_MODULE_LIST:
466 case CONFIG_ITEM_STRING_LIST:
469 case CONFIG_ITEM_STRING:
472 case CONFIG_ITEM_STRING_LIST:
475 case CONFIG_ITEM_FILE:
478 case CONFIG_ITEM_MODULE:
481 case CONFIG_ITEM_INTEGER:
484 case CONFIG_ITEM_RANGED_INTEGER:
487 case CONFIG_ITEM_BOOL:
490 case CONFIG_ITEM_KEY_BEFORE_10_3:
493 case CONFIG_ITEM_KEY_AFTER_10_3:
496 case CONFIG_ITEM_MODULE_LIST:
504 case CONFIG_ITEM_FILE:
507 case CONFIG_ITEM_STRING:
510 case CONFIG_ITEM_STRING_LIST:
513 case CONFIG_ITEM_FILE:
516 case CONFIG_ITEM_MODULE:
519 case CONFIG_ITEM_INTEGER:
522 case CONFIG_ITEM_RANGED_INTEGER:
525 case CONFIG_ITEM_BOOL:
528 case CONFIG_ITEM_KEY_BEFORE_10_3:
531 case CONFIG_ITEM_KEY_AFTER_10_3:
534 case CONFIG_ITEM_MODULE_LIST:
542 case CONFIG_ITEM_MODULE:
545 case CONFIG_ITEM_STRING:
548 case CONFIG_ITEM_STRING_LIST:
551 case CONFIG_ITEM_FILE:
554 case CONFIG_ITEM_MODULE:
557 case CONFIG_ITEM_INTEGER:
560 case CONFIG_ITEM_RANGED_INTEGER:
563 case CONFIG_ITEM_BOOL:
566 case CONFIG_ITEM_KEY_BEFORE_10_3:
569 case CONFIG_ITEM_KEY_AFTER_10_3:
572 case CONFIG_ITEM_MODULE_LIST:
580 case CONFIG_ITEM_INTEGER:
583 case CONFIG_ITEM_STRING:
586 case CONFIG_ITEM_STRING_LIST:
589 case CONFIG_ITEM_FILE:
592 case CONFIG_ITEM_MODULE:
595 case CONFIG_ITEM_INTEGER:
598 case CONFIG_ITEM_RANGED_INTEGER:
601 case CONFIG_ITEM_BOOL:
604 case CONFIG_ITEM_KEY_BEFORE_10_3:
607 case CONFIG_ITEM_KEY_AFTER_10_3:
610 case CONFIG_ITEM_MODULE_LIST:
618 case CONFIG_ITEM_RANGED_INTEGER:
621 case CONFIG_ITEM_STRING:
624 case CONFIG_ITEM_STRING_LIST:
627 case CONFIG_ITEM_FILE:
630 case CONFIG_ITEM_MODULE:
633 case CONFIG_ITEM_INTEGER:
636 case CONFIG_ITEM_RANGED_INTEGER:
639 case CONFIG_ITEM_BOOL:
642 case CONFIG_ITEM_KEY_BEFORE_10_3:
645 case CONFIG_ITEM_KEY_AFTER_10_3:
648 case CONFIG_ITEM_MODULE_LIST:
656 case CONFIG_ITEM_BOOL:
659 case CONFIG_ITEM_STRING:
662 case CONFIG_ITEM_STRING_LIST:
665 case CONFIG_ITEM_FILE:
668 case CONFIG_ITEM_MODULE:
671 case CONFIG_ITEM_INTEGER:
674 case CONFIG_ITEM_RANGED_INTEGER:
677 case CONFIG_ITEM_BOOL:
680 case CONFIG_ITEM_KEY_BEFORE_10_3:
683 case CONFIG_ITEM_KEY_AFTER_10_3:
686 case CONFIG_ITEM_MODULE_LIST:
694 case CONFIG_ITEM_KEY_BEFORE_10_3:
697 case CONFIG_ITEM_STRING:
700 case CONFIG_ITEM_STRING_LIST:
703 case CONFIG_ITEM_FILE:
706 case CONFIG_ITEM_MODULE:
709 case CONFIG_ITEM_INTEGER:
712 case CONFIG_ITEM_RANGED_INTEGER:
715 case CONFIG_ITEM_BOOL:
718 case CONFIG_ITEM_KEY_BEFORE_10_3:
721 case CONFIG_ITEM_KEY_AFTER_10_3:
724 case CONFIG_ITEM_MODULE_LIST:
732 case CONFIG_ITEM_KEY_AFTER_10_3:
735 case CONFIG_ITEM_STRING:
738 case CONFIG_ITEM_STRING_LIST:
741 case CONFIG_ITEM_FILE:
744 case CONFIG_ITEM_MODULE:
747 case CONFIG_ITEM_INTEGER:
750 case CONFIG_ITEM_RANGED_INTEGER:
753 case CONFIG_ITEM_BOOL:
756 case CONFIG_ITEM_KEY_BEFORE_10_3:
759 case CONFIG_ITEM_KEY_AFTER_10_3:
762 case CONFIG_ITEM_MODULE_LIST:
770 case CONFIG_ITEM_MODULE_LIST:
773 case CONFIG_ITEM_STRING:
776 case CONFIG_ITEM_STRING_LIST:
779 case CONFIG_ITEM_FILE:
782 case CONFIG_ITEM_MODULE:
785 case CONFIG_ITEM_INTEGER:
788 case CONFIG_ITEM_RANGED_INTEGER:
791 case CONFIG_ITEM_BOOL:
794 case CONFIG_ITEM_KEY_BEFORE_10_3:
797 case CONFIG_ITEM_KEY_AFTER_10_3:
800 case CONFIG_ITEM_MODULE_LIST:
815 + (VLCConfigControl *)newControl: (module_config_t *)_p_item
816 withView: (NSView *)o_parent_view
818 VLCConfigControl *p_control = NULL;
819 /* Skip depracated options */
820 if( _p_item->psz_current )
825 switch( _p_item->i_type )
827 case CONFIG_ITEM_STRING:
828 if( !_p_item->i_list )
830 p_control = [[StringConfigControl alloc]
831 initWithItem: _p_item
832 withView: o_parent_view];
836 p_control = [[StringListConfigControl alloc]
837 initWithItem: _p_item
838 withView: o_parent_view];
841 case CONFIG_ITEM_FILE:
842 case CONFIG_ITEM_DIRECTORY:
843 p_control = [[FileConfigControl alloc]
844 initWithItem: _p_item
845 withView: o_parent_view];
847 case CONFIG_ITEM_MODULE:
848 case CONFIG_ITEM_MODULE_CAT:
849 p_control = [[ModuleConfigControl alloc]
850 initWithItem: _p_item
851 withView: o_parent_view];
853 case CONFIG_ITEM_INTEGER:
854 if( _p_item->i_list )
856 p_control = [[IntegerListConfigControl alloc]
857 initWithItem: _p_item
858 withView: o_parent_view];
860 else if( _p_item->min.i != 0 || _p_item->max.i != 0 )
862 p_control = [[RangedIntegerConfigControl alloc]
863 initWithItem: _p_item
864 withView: o_parent_view];
868 p_control = [[IntegerConfigControl alloc]
869 initWithItem: _p_item
870 withView: o_parent_view];
873 case CONFIG_ITEM_BOOL:
874 p_control = [[BoolConfigControl alloc]
875 initWithItem: _p_item
876 withView: o_parent_view];
878 case CONFIG_ITEM_FLOAT:
879 if( _p_item->min.f != 0 || _p_item->max.f != 0 )
881 p_control = [[RangedFloatConfigControl alloc]
882 initWithItem: _p_item
883 withView: o_parent_view];
887 p_control = [[FloatConfigControl alloc]
888 initWithItem: _p_item
889 withView: o_parent_view];
892 case CONFIG_ITEM_KEY:
893 if( MACOS_VERSION < 10.3 )
895 p_control = [[KeyConfigControlBefore103 alloc]
896 initWithItem: _p_item
897 withView: o_parent_view];
901 p_control = [[KeyConfigControlAfter103 alloc]
902 initWithItem: _p_item
903 withView: o_parent_view];
906 case CONFIG_ITEM_MODULE_LIST:
907 case CONFIG_ITEM_MODULE_LIST_CAT:
908 p_control = [[ModuleListConfigControl alloc]
909 initWithItem: _p_item
910 withView: o_parent_view];
918 - (NSString *)getName
920 return [[VLCMain sharedInstance] localizedString: psz_name];
948 - (char *)stringValue
956 switch( p_item->i_type )
958 case CONFIG_ITEM_STRING:
959 case CONFIG_ITEM_FILE:
960 case CONFIG_ITEM_DIRECTORY:
961 case CONFIG_ITEM_MODULE:
962 case CONFIG_ITEM_MODULE_LIST:
963 case CONFIG_ITEM_MODULE_LIST_CAT:
964 config_PutPsz( VLCIntf, psz_name, [self stringValue] );
966 case CONFIG_ITEM_KEY:
967 /* So you don't need to restart to have the changes take effect */
968 val.i_int = [self intValue];
969 var_Set( VLCIntf->p_libvlc, psz_name, val );
970 case CONFIG_ITEM_INTEGER:
971 case CONFIG_ITEM_BOOL:
972 config_PutInt( VLCIntf, psz_name, [self intValue] );
974 case CONFIG_ITEM_FLOAT:
975 config_PutFloat( VLCIntf, psz_name, [self floatValue] );
982 return [o_label frame].size.width;
985 - (void) alignWithXPosition:(int)i_xPos;
987 /* FIXME: not implemented atm, but created to shut up the warning
988 * about "method definition not found" -- FK @ 7/24/05 */
992 @implementation StringConfigControl
993 - (id) initWithItem: (module_config_t *)_p_item
994 withView: (NSView *)o_parent_view
996 NSRect mainFrame = [o_parent_view frame];
997 NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
998 mainFrame.size.height = 22;
999 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1000 mainFrame.origin.x = LEFTMARGIN;
1001 mainFrame.origin.y = 0;
1003 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1005 i_view_type = CONFIG_ITEM_STRING;
1007 if( p_item->psz_text )
1008 o_labelString = [[VLCMain sharedInstance]
1009 localizedString: (char *)p_item->psz_text];
1011 o_labelString = [NSString stringWithString:@""];
1012 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1013 [o_label setAutoresizingMask:NSViewNotSizable ];
1014 [self addSubview: o_label];
1016 /* build the textfield */
1017 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1018 [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext]
1019 toWidth: PREFS_WRAP];
1020 if( p_item->value.psz )
1021 o_textfieldString = [[VLCMain sharedInstance]
1022 localizedString: (char *)p_item->value.psz];
1024 o_textfieldString = [NSString stringWithString: @""];
1025 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1026 0, mainFrame.size.width - [o_label frame].size.width -
1027 2, o_textfieldTooltip, o_textfieldString )
1028 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1029 [self addSubview: o_textfield];
1034 - (void) alignWithXPosition:(int)i_xPos
1037 NSRect superFrame = [self frame];
1038 frame = [o_label frame];
1039 frame.origin.x = i_xPos - frame.size.width - 3;
1040 [o_label setFrame:frame];
1042 frame = [o_textfield frame];
1043 frame.origin.x = i_xPos + 2;
1044 frame.size.width = superFrame.size.width - frame.origin.x - 1;
1045 [o_textfield setFrame:frame];
1050 [o_textfield release];
1054 - (char *)stringValue
1056 return strdup( [[VLCMain sharedInstance] delocalizeString:
1057 [o_textfield stringValue]] );
1061 @implementation StringListConfigControl
1062 - (id) initWithItem: (module_config_t *)_p_item
1063 withView: (NSView *)o_parent_view
1065 NSRect mainFrame = [o_parent_view frame];
1066 NSString *o_labelString, *o_textfieldTooltip;
1067 mainFrame.size.height = 22;
1068 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1069 mainFrame.origin.x = LEFTMARGIN;
1070 mainFrame.origin.y = 0;
1072 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1075 i_view_type = CONFIG_ITEM_STRING_LIST;
1077 if( p_item->psz_text )
1078 o_labelString = [[VLCMain sharedInstance]
1079 localizedString: (char *)p_item->psz_text];
1081 o_labelString = [NSString stringWithString:@""];
1082 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1083 [o_label setAutoresizingMask:NSViewNotSizable ];
1084 [self addSubview: o_label];
1086 /* build the textfield */
1087 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1088 [[VLCMain sharedInstance]
1089 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1090 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1091 -2, 0, o_textfieldTooltip )
1092 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1093 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1094 if( p_item->value.psz &&
1095 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
1096 [o_combo selectItemAtIndex: i_index];
1097 [self addSubview: o_combo];
1102 - (void) alignWithXPosition:(int)i_xPos
1105 NSRect superFrame = [self frame];
1106 frame = [o_label frame];
1107 frame.origin.x = i_xPos - frame.size.width - 3;
1108 [o_label setFrame:frame];
1110 frame = [o_combo frame];
1111 frame.origin.x = i_xPos + 2;
1112 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1113 [o_combo setFrame:frame];
1122 - (char *)stringValue
1124 if( [o_combo indexOfSelectedItem] >= 0 )
1125 return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
1127 return strdup( [[VLCMain sharedInstance]
1128 delocalizeString: [o_combo stringValue]] );
1132 @implementation StringListConfigControl (NSComboBoxDataSource)
1133 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1135 return p_item->i_list;
1138 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1140 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1142 return [[VLCMain sharedInstance]
1143 localizedString: (char *)p_item->ppsz_list_text[i_index]];
1144 } else return [[VLCMain sharedInstance]
1145 localizedString: (char *)p_item->ppsz_list[i_index]];
1149 @implementation FileConfigControl
1150 - (id) initWithItem: (module_config_t *)_p_item
1151 withView: (NSView *)o_parent_view
1153 NSRect mainFrame = [o_parent_view frame];
1154 NSString *o_labelString, *o_buttonTooltip, *o_textfieldString;
1155 NSString *o_textfieldTooltip;
1156 mainFrame.size.height = 46;
1157 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1158 mainFrame.origin.x = LEFTMARGIN;
1159 mainFrame.origin.y = 0;
1161 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1163 i_view_type = CONFIG_ITEM_FILE;
1165 /* is it a directory */
1166 b_directory = ( [self getType] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1169 if( p_item->psz_text )
1170 o_labelString = [[VLCMain sharedInstance]
1171 localizedString: (char *)p_item->psz_text];
1173 o_labelString = [NSString stringWithString:@""];
1174 ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString )
1175 [o_label setAutoresizingMask:NSViewNotSizable ];
1176 [self addSubview: o_label];
1178 /* build the button */
1179 o_buttonTooltip = [[VLCMain sharedInstance]
1180 wrapString: [[VLCMain sharedInstance]
1181 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1182 ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_buttonTooltip,
1184 [o_button setAutoresizingMask:NSViewMinXMargin ];
1185 [self addSubview: o_button];
1187 /* build the textfield */
1188 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1189 [[VLCMain sharedInstance]
1190 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1191 if( p_item->value.psz )
1192 o_textfieldString = [[VLCMain sharedInstance]
1193 localizedString: (char *)p_item->value.psz];
1195 o_textfieldString = [NSString stringWithString: @""];
1196 ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1197 8 - [o_button frame].size.width,
1198 o_textfieldTooltip, o_textfieldString )
1199 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1200 [self addSubview: o_textfield];
1205 - (void) alignWithXPosition:(int)i_xPos
1212 [o_textfield release];
1217 - (IBAction)openFileDialog: (id)sender
1219 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1221 [o_open_panel setTitle: (b_directory)?
1222 _NS("Select a directory"):_NS("Select a file")];
1223 [o_open_panel setPrompt: _NS("Select")];
1224 [o_open_panel setAllowsMultipleSelection: NO];
1225 [o_open_panel setCanChooseFiles: !b_directory];
1226 [o_open_panel setCanChooseDirectories: b_directory];
1227 [o_open_panel beginSheetForDirectory:nil
1230 modalForWindow:[sender window]
1232 didEndSelector: @selector(pathChosenInPanel:
1238 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1239 withReturn:(int)i_return_code contextInfo:(void *)o_context_info
1241 if( i_return_code == NSOKButton )
1243 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
1244 [o_textfield setStringValue: o_path];
1248 - (char *)stringValue
1250 if( [[o_textfield stringValue] length] != 0)
1251 return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1257 @implementation ModuleConfigControl
1258 - (id) initWithItem: (module_config_t *)_p_item
1259 withView: (NSView *)o_parent_view
1261 NSRect mainFrame = [o_parent_view frame];
1262 NSString *o_labelString, *o_popupTooltip;
1263 mainFrame.size.height = 22;
1264 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1265 mainFrame.origin.x = LEFTMARGIN;
1266 mainFrame.origin.y = 0;
1268 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1273 module_config_t *p_end;
1274 i_view_type = CONFIG_ITEM_MODULE;
1277 if( p_item->psz_text )
1278 o_labelString = [[VLCMain sharedInstance]
1279 localizedString: (char *)p_item->psz_text];
1281 o_labelString = [NSString stringWithString:@""];
1282 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
1283 [o_label setAutoresizingMask:NSViewNotSizable ];
1284 [self addSubview: o_label];
1286 /* build the popup */
1287 o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1288 [[VLCMain sharedInstance]
1289 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1290 ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1291 -2, 0, o_popupTooltip )
1292 [o_popup setAutoresizingMask:NSViewWidthSizable ];
1293 [o_popup addItemWithTitle: _NS("Default")];
1294 [[o_popup lastItem] setTag: -1];
1295 [o_popup selectItem: [o_popup lastItem]];
1297 /* build a list of available modules */
1298 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1299 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1301 p_parser = (module_t *)p_list->p_values[i_index].p_object;
1302 p_end = p_item + p_parser->confsize;
1303 if( p_item->i_type == CONFIG_ITEM_MODULE )
1305 if( !strcmp( p_parser->psz_capability,
1306 p_item->psz_type ) )
1308 NSString *o_description = [[VLCMain sharedInstance]
1309 localizedString: (char *)p_parser->psz_longname];
1310 [o_popup addItemWithTitle: o_description];
1312 if( p_item->value.psz &&
1313 !strcmp( p_item->value.psz, p_parser->psz_object_name ) )
1314 [o_popup selectItem:[o_popup lastItem]];
1319 module_config_t *p_config;
1320 if( !strcmp( p_parser->psz_object_name, "main" ) )
1323 p_config = p_parser->p_config;
1326 /* Hack: required subcategory is stored in i_min */
1327 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1328 p_config->value.i == p_item->min.i )
1330 NSString *o_description = [[VLCMain sharedInstance]
1331 localizedString: (char *)p_parser->psz_longname];
1332 [o_popup addItemWithTitle: o_description];
1334 if( p_item->value.psz && !strcmp(p_item->value.psz,
1335 p_parser->psz_object_name) )
1336 [o_popup selectItem:[o_popup lastItem]];
1338 } while( p_item < p_end && p_config++ );
1341 vlc_list_release( p_list );
1342 [self addSubview: o_popup];
1347 - (void) alignWithXPosition:(int)i_xPos
1350 NSRect superFrame = [self frame];
1351 frame = [o_label frame];
1352 frame.origin.x = i_xPos - frame.size.width - 3;
1353 [o_label setFrame:frame];
1355 frame = [o_popup frame];
1356 frame.origin.x = i_xPos - 1;
1357 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1358 [o_popup setFrame:frame];
1367 - (char *)stringValue
1369 NSString *newval = [o_popup titleOfSelectedItem];
1370 char *returnval = NULL;
1374 module_config_t *p_end;
1376 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1377 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1379 p_parser = (module_t *)p_list->p_values[i_index].p_object;
1380 p_end = p_item + p_parser->confsize;
1381 if( p_item->i_type == CONFIG_ITEM_MODULE )
1383 if( !strcmp( p_parser->psz_capability,
1384 p_item->psz_type ) )
1386 NSString *o_description = [[VLCMain sharedInstance]
1387 localizedString: (char *)p_parser->psz_longname];
1388 if( [newval isEqualToString: o_description] )
1390 returnval = strdup(p_parser->psz_object_name);
1397 module_config_t *p_config;
1398 if( !strcmp( p_parser->psz_object_name, "main" ) )
1401 p_config = p_parser->p_config;
1404 /* Hack: required subcategory is stored in i_min */
1405 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1406 p_config->value.i == p_item->min.i )
1408 NSString *o_description = [[VLCMain sharedInstance]
1409 localizedString: (char *)p_parser->psz_longname];
1410 if( [newval isEqualToString: o_description] )
1412 returnval = strdup(p_parser->psz_object_name);
1416 } while( p_item < p_end && p_config++ );
1419 vlc_list_release( p_list );
1424 @implementation IntegerConfigControl
1425 - (id) initWithItem: (module_config_t *)_p_item
1426 withView: (NSView *)o_parent_view
1428 NSRect mainFrame = [o_parent_view frame];
1429 NSString *o_labelString, *o_tooltip, *o_textfieldString;
1430 mainFrame.size.height = 23;
1431 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1432 mainFrame.origin.x = LEFTMARGIN;
1433 mainFrame.origin.y = 0;
1435 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1437 i_view_type = CONFIG_ITEM_INTEGER;
1439 o_tooltip = [[VLCMain sharedInstance] wrapString:
1440 [[VLCMain sharedInstance]
1441 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1444 if( p_item->psz_text )
1445 o_labelString = [[VLCMain sharedInstance]
1446 localizedString: (char *)p_item->psz_text];
1448 o_labelString = [NSString stringWithString:@""];
1449 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1450 [o_label setAutoresizingMask:NSViewNotSizable ];
1451 [self addSubview: o_label];
1453 /* build the stepper */
1454 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1455 0, o_tooltip, -1600, 1600)
1456 [o_stepper setIntValue: p_item->value.i];
1457 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1458 [self addSubview: o_stepper];
1460 /* build the textfield */
1461 if( p_item->value.psz )
1462 o_textfieldString = [[VLCMain sharedInstance]
1463 localizedString: (char *)p_item->value.psz];
1465 o_textfieldString = [NSString stringWithString: @""];
1466 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1467 1, 49, o_tooltip, @"" )
1468 [o_textfield setIntValue: p_item->value.i];
1469 [o_textfield setDelegate: self];
1470 [[NSNotificationCenter defaultCenter] addObserver: self
1471 selector: @selector(textfieldChanged:)
1472 name: NSControlTextDidChangeNotification
1473 object: o_textfield];
1474 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1475 [self addSubview: o_textfield];
1480 - (void) alignWithXPosition:(int)i_xPos
1483 frame = [o_label frame];
1484 frame.origin.x = i_xPos - frame.size.width - 3;
1485 [o_label setFrame:frame];
1487 frame = [o_textfield frame];
1488 frame.origin.x = i_xPos + 2;
1489 [o_textfield setFrame:frame];
1491 frame = [o_stepper frame];
1492 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1493 [o_stepper setFrame:frame];
1498 [o_stepper release];
1499 [o_textfield release];
1503 - (IBAction)stepperChanged:(id)sender
1505 [o_textfield setIntValue: [o_stepper intValue]];
1508 - (void)textfieldChanged:(NSNotification *)o_notification
1510 [o_stepper setIntValue: [o_textfield intValue]];
1515 return [o_textfield intValue];
1520 @implementation IntegerListConfigControl
1522 - (id) initWithItem: (module_config_t *)_p_item
1523 withView: (NSView *)o_parent_view
1525 NSRect mainFrame = [o_parent_view frame];
1526 NSString *o_labelString, *o_textfieldTooltip;
1527 mainFrame.size.height = 22;
1528 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1529 mainFrame.origin.x = LEFTMARGIN;
1530 mainFrame.origin.y = 0;
1532 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1535 i_view_type = CONFIG_ITEM_STRING_LIST;
1538 if( p_item->psz_text )
1539 o_labelString = [[VLCMain sharedInstance]
1540 localizedString: (char *)p_item->psz_text];
1542 o_labelString = [NSString stringWithString:@""];
1543 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1544 [o_label setAutoresizingMask:NSViewNotSizable ];
1545 [self addSubview: o_label];
1547 /* build the textfield */
1548 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1549 [[VLCMain sharedInstance]
1550 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1551 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1552 -2, 0, o_textfieldTooltip )
1553 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1554 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1556 if( p_item->value.i == p_item->pi_list[i_index] )
1558 [o_combo selectItemAtIndex: i_index];
1561 [self addSubview: o_combo];
1566 - (void) alignWithXPosition:(int)i_xPos
1569 NSRect superFrame = [self frame];
1570 frame = [o_label frame];
1571 frame.origin.x = i_xPos - frame.size.width - 3;
1572 [o_label setFrame:frame];
1574 frame = [o_combo frame];
1575 frame.origin.x = i_xPos + 2;
1576 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1577 [o_combo setFrame:frame];
1588 if( [o_combo indexOfSelectedItem] >= 0 )
1589 return p_item->pi_list[[o_combo indexOfSelectedItem]];
1591 return [o_combo intValue];
1595 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1596 - (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1598 return p_item->i_list;
1601 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index
1603 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1604 return [[VLCMain sharedInstance]
1605 localizedString: (char *)p_item->ppsz_list_text[i_index]];
1607 return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1611 @implementation RangedIntegerConfigControl
1612 - (id) initWithItem: (module_config_t *)_p_item
1613 withView: (NSView *)o_parent_view
1615 NSRect mainFrame = [o_parent_view frame];
1616 NSString *o_labelString, *o_tooltip;
1617 mainFrame.size.height = 50;
1618 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1619 mainFrame.origin.x = LEFTMARGIN;
1620 mainFrame.origin.y = 0;
1622 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1624 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1627 if( p_item->psz_text )
1628 o_labelString = [[VLCMain sharedInstance]
1629 localizedString: (char *)p_item->psz_text];
1631 o_labelString = [NSString stringWithString:@""];
1632 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1633 [o_label setAutoresizingMask:NSViewNotSizable ];
1634 [self addSubview: o_label];
1636 /* build the textfield */
1637 o_tooltip = [[VLCMain sharedInstance] wrapString:
1638 [[VLCMain sharedInstance]
1639 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1640 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1641 28, 49, o_tooltip, @"" )
1642 [o_textfield setIntValue: p_item->value.i];
1643 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1644 [o_textfield setDelegate: self];
1645 [[NSNotificationCenter defaultCenter] addObserver: self
1646 selector: @selector(textfieldChanged:)
1647 name: NSControlTextDidChangeNotification
1648 object: o_textfield];
1649 [self addSubview: o_textfield];
1651 /* build the mintextfield */
1652 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1653 [o_textfield_min setIntValue: p_item->min.i];
1654 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1655 [o_textfield_min setAlignment:NSRightTextAlignment];
1656 [self addSubview: o_textfield_min];
1658 /* build the maxtextfield */
1659 ADD_LABEL( o_textfield_max, mainFrame,
1660 mainFrame.size.width - 31, -30, @"8888" )
1661 [o_textfield_max setIntValue: p_item->max.i];
1662 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1663 [self addSubview: o_textfield_max];
1665 /* build the slider */
1666 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1667 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1668 [o_textfield_max frame].size.width -
1669 [o_textfield_max frame].size.width - 14 -
1670 [o_textfield_min frame].origin.x, o_tooltip,
1671 p_item->min.i, p_item->max.i )
1672 [o_slider setIntValue: p_item->value.i];
1673 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1674 [o_slider setTarget: self];
1675 [o_slider setAction: @selector(sliderChanged:)];
1676 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1677 NSLeftMouseDraggedMask];
1678 [self addSubview: o_slider];
1684 - (void) alignWithXPosition:(int)i_xPos
1687 frame = [o_label frame];
1688 frame.origin.x = i_xPos - frame.size.width - 3;
1689 [o_label setFrame:frame];
1691 frame = [o_textfield frame];
1692 frame.origin.x = i_xPos + 2;
1693 [o_textfield setFrame:frame];
1698 [o_textfield release];
1699 [o_textfield_min release];
1700 [o_textfield_max release];
1705 - (IBAction)sliderChanged:(id)sender
1707 [o_textfield setIntValue: [o_slider intValue]];
1710 - (void)textfieldChanged:(NSNotification *)o_notification
1712 [o_slider setIntValue: [o_textfield intValue]];
1717 return [o_slider intValue];
1721 @implementation FloatConfigControl
1722 - (id) initWithItem: (module_config_t *)_p_item
1723 withView: (NSView *)o_parent_view
1725 NSRect mainFrame = [o_parent_view frame];
1726 NSString *o_labelString, *o_tooltip, *o_textfieldString;
1727 mainFrame.size.height = 23;
1728 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1729 mainFrame.origin.x = LEFTMARGIN;
1730 mainFrame.origin.y = 0;
1732 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1734 i_view_type = CONFIG_ITEM_INTEGER;
1736 o_tooltip = [[VLCMain sharedInstance] wrapString:
1737 [[VLCMain sharedInstance]
1738 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1741 if( p_item->psz_text )
1742 o_labelString = [[VLCMain sharedInstance]
1743 localizedString: (char *)p_item->psz_text];
1745 o_labelString = [NSString stringWithString:@""];
1746 ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString )
1747 [o_label setAutoresizingMask:NSViewNotSizable ];
1748 [self addSubview: o_label];
1750 /* build the stepper */
1751 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1752 0, o_tooltip, -1600, 1600)
1753 [o_stepper setFloatValue: p_item->value.f];
1754 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1755 [self addSubview: o_stepper];
1757 /* build the textfield */
1758 if( p_item->value.psz )
1759 o_textfieldString = [[VLCMain sharedInstance]
1760 localizedString: (char *)p_item->value.psz];
1762 o_textfieldString = [NSString stringWithString: @""];
1763 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1764 1, 49, o_tooltip, @"" )
1765 [o_textfield setFloatValue: p_item->value.f];
1766 [o_textfield setDelegate: self];
1767 [[NSNotificationCenter defaultCenter] addObserver: self
1768 selector: @selector(textfieldChanged:)
1769 name: NSControlTextDidChangeNotification
1770 object: o_textfield];
1771 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1772 [self addSubview: o_textfield];
1777 - (void) alignWithXPosition:(int)i_xPos
1780 frame = [o_label frame];
1781 frame.origin.x = i_xPos - frame.size.width - 3;
1782 [o_label setFrame:frame];
1784 frame = [o_textfield frame];
1785 frame.origin.x = i_xPos + 2;
1786 [o_textfield setFrame:frame];
1788 frame = [o_stepper frame];
1789 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1790 [o_stepper setFrame:frame];
1795 [o_stepper release];
1796 [o_textfield release];
1800 - (IBAction)stepperChanged:(id)sender
1802 [o_textfield setFloatValue: [o_stepper floatValue]];
1805 - (void)textfieldChanged:(NSNotification *)o_notification
1807 [o_stepper setFloatValue: [o_textfield floatValue]];
1812 return [o_stepper floatValue];
1816 @implementation RangedFloatConfigControl
1817 - (id) initWithItem: (module_config_t *)_p_item
1818 withView: (NSView *)o_parent_view
1820 NSRect mainFrame = [o_parent_view frame];
1821 NSString *o_labelString, *o_tooltip;
1822 mainFrame.size.height = 50;
1823 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1824 mainFrame.origin.x = LEFTMARGIN;
1825 mainFrame.origin.y = 0;
1827 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1829 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1832 if( p_item->psz_text )
1833 o_labelString = [[VLCMain sharedInstance]
1834 localizedString: (char *)p_item->psz_text];
1836 o_labelString = [NSString stringWithString:@""];
1837 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
1838 [o_label setAutoresizingMask:NSViewNotSizable ];
1839 [self addSubview: o_label];
1841 /* build the textfield */
1842 o_tooltip = [[VLCMain sharedInstance] wrapString:
1843 [[VLCMain sharedInstance]
1844 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1845 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1846 28, 49, o_tooltip, @"" )
1847 [o_textfield setFloatValue: p_item->value.f];
1848 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1849 [o_textfield setDelegate: self];
1850 [[NSNotificationCenter defaultCenter] addObserver: self
1851 selector: @selector(textfieldChanged:)
1852 name: NSControlTextDidChangeNotification
1853 object: o_textfield];
1854 [self addSubview: o_textfield];
1856 /* build the mintextfield */
1857 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888" )
1858 [o_textfield_min setFloatValue: p_item->min.f];
1859 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1860 [o_textfield_min setAlignment:NSRightTextAlignment];
1861 [self addSubview: o_textfield_min];
1863 /* build the maxtextfield */
1864 ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1866 [o_textfield_max setFloatValue: p_item->max.f];
1867 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1868 [self addSubview: o_textfield_max];
1870 /* build the slider */
1871 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1872 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1873 [o_textfield_max frame].size.width -
1874 [o_textfield_max frame].size.width - 14 -
1875 [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
1877 [o_slider setFloatValue: p_item->value.f];
1878 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1879 [o_slider setTarget: self];
1880 [o_slider setAction: @selector(sliderChanged:)];
1881 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1882 NSLeftMouseDraggedMask];
1883 [self addSubview: o_slider];
1889 - (void) alignWithXPosition:(int)i_xPos
1892 frame = [o_label frame];
1893 frame.origin.x = i_xPos - frame.size.width - 3;
1894 [o_label setFrame:frame];
1896 frame = [o_textfield frame];
1897 frame.origin.x = i_xPos + 2;
1898 [o_textfield setFrame:frame];
1903 [o_textfield release];
1904 [o_textfield_min release];
1905 [o_textfield_max release];
1910 - (IBAction)sliderChanged:(id)sender
1912 [o_textfield setFloatValue: [o_slider floatValue]];
1915 - (void)textfieldChanged:(NSNotification *)o_notification
1917 [o_slider setFloatValue: [o_textfield floatValue]];
1922 return [o_slider floatValue];
1927 @implementation BoolConfigControl
1929 - (id) initWithItem: (module_config_t *)_p_item
1930 withView: (NSView *)o_parent_view
1932 NSRect mainFrame = [o_parent_view frame];
1933 NSString *o_labelString, *o_tooltip;
1934 mainFrame.size.height = 17;
1935 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1936 mainFrame.origin.x = LEFTMARGIN;
1937 mainFrame.origin.y = 0;
1939 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1941 i_view_type = CONFIG_ITEM_BOOL;
1943 /* add the checkbox */
1944 o_tooltip = [[VLCMain sharedInstance]
1945 wrapString: [[VLCMain sharedInstance]
1946 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1947 ADD_CHECKBOX( o_checkbox, mainFrame, 0,
1948 0, @"", o_tooltip, p_item->value.i, NSImageLeft)
1949 [o_checkbox setAutoresizingMask:NSViewNotSizable ];
1950 [self addSubview: o_checkbox];
1952 if( p_item->psz_text )
1953 o_labelString = [[VLCMain sharedInstance]
1954 localizedString: (char *)p_item->psz_text];
1956 o_labelString = [NSString stringWithString:@""];
1957 ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString )
1958 [o_label setAutoresizingMask:NSViewNotSizable ];
1959 [self addSubview: o_label];
1966 [o_checkbox release];
1972 return [o_checkbox intValue];
1977 @implementation KeyConfigControlBefore103
1979 - (id) initWithItem: (module_config_t *)_p_item
1980 withView: (NSView *)o_parent_view
1982 NSRect mainFrame = [o_parent_view frame];
1983 NSString *o_labelString, *o_tooltip;
1984 mainFrame.size.height = 37;
1985 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1986 mainFrame.origin.x = LEFTMARGIN;
1987 mainFrame.origin.y = 0;
1989 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1991 i_view_type = CONFIG_ITEM_KEY_BEFORE_10_3;
1994 if( p_item->psz_text )
1995 o_labelString = [[VLCMain sharedInstance]
1996 localizedString: (char *)p_item->psz_text];
1998 o_labelString = [NSString stringWithString:@""];
1999 ADD_LABEL( o_label, mainFrame, 0, -10, o_labelString )
2000 [o_label setAutoresizingMask:NSViewNotSizable ];
2001 [self addSubview: o_label];
2003 /* add the checkboxes */
2004 o_tooltip = [[VLCMain sharedInstance] wrapString:
2005 [[VLCMain sharedInstance]
2006 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2007 ADD_CHECKBOX( o_cmd_checkbox, mainFrame,
2008 [o_label frame].size.width + 2, 0,
2009 [NSString stringWithUTF8String:PLACE_OF_INTEREST_SIGN], o_tooltip,
2010 ((((unsigned int)p_item->value.i) & KEY_MODIFIER_COMMAND)?YES:NO),
2012 [o_cmd_checkbox setState: p_item->value.i & KEY_MODIFIER_COMMAND];
2013 ADD_CHECKBOX( o_ctrl_checkbox, mainFrame,
2014 [o_cmd_checkbox frame].size.width +
2015 [o_cmd_checkbox frame].origin.x + 6, 0,
2016 [NSString stringWithUTF8String:UP_ARROWHEAD], o_tooltip,
2017 ((((unsigned int)p_item->value.i) & KEY_MODIFIER_CTRL)?YES:NO),
2019 [o_ctrl_checkbox setState: p_item->value.i & KEY_MODIFIER_CTRL];
2020 ADD_CHECKBOX( o_alt_checkbox, mainFrame, [o_label frame].size.width +
2021 2, -2 - [o_cmd_checkbox frame].size.height,
2022 [NSString stringWithUTF8String:OPTION_KEY], o_tooltip,
2023 ((((unsigned int)p_item->value.i) & KEY_MODIFIER_ALT)?YES:NO),
2025 [o_alt_checkbox setState: p_item->value.i & KEY_MODIFIER_ALT];
2026 ADD_CHECKBOX( o_shift_checkbox, mainFrame,
2027 [o_cmd_checkbox frame].size.width +
2028 [o_cmd_checkbox frame].origin.x + 6, -2 -
2029 [o_cmd_checkbox frame].size.height,
2030 [NSString stringWithUTF8String:UPWARDS_WHITE_ARROW], o_tooltip,
2031 ((((unsigned int)p_item->value.i) & KEY_MODIFIER_SHIFT)?YES:NO),
2033 [o_shift_checkbox setState: p_item->value.i & KEY_MODIFIER_SHIFT];
2034 [self addSubview: o_cmd_checkbox];
2035 [self addSubview: o_ctrl_checkbox];
2036 [self addSubview: o_alt_checkbox];
2037 [self addSubview: o_shift_checkbox];
2039 /* build the popup */
2040 ADD_POPUP( o_popup, mainFrame, [o_shift_checkbox frame].origin.x +
2041 [o_shift_checkbox frame].size.width + 4,
2043 [o_popup setAutoresizingMask:NSViewWidthSizable ];
2045 if( o_keys_menu == nil )
2048 o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2049 for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2050 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2051 POPULATE_A_KEY( o_keys_menu,
2052 [NSString stringWithCString:vlc_keys[i].psz_key_string]
2053 , vlc_keys[i].i_key_code)
2055 [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2056 [o_popup selectItemWithTitle: [[VLCMain sharedInstance]
2057 localizedString:(char *)KeyToString(
2058 (((unsigned int)p_item->value.i) & ~KEY_MODIFIER ))]];
2059 [self addSubview: o_popup];
2064 - (void) alignWithXPosition:(int)i_xPos
2067 NSRect superFrame = [self frame];
2068 frame = [o_label frame];
2069 frame.origin.x = i_xPos - frame.size.width - 3;
2070 [o_label setFrame:frame];
2072 frame = [o_cmd_checkbox frame];
2073 frame.origin.x = i_xPos;
2074 [o_cmd_checkbox setFrame:frame];
2076 frame = [o_ctrl_checkbox frame];
2077 frame.origin.x = [o_cmd_checkbox frame].size.width +
2078 [o_cmd_checkbox frame].origin.x + 4;
2079 [o_ctrl_checkbox setFrame:frame];
2081 frame = [o_alt_checkbox frame];
2082 frame.origin.x = i_xPos;
2083 [o_alt_checkbox setFrame:frame];
2085 frame = [o_shift_checkbox frame];
2086 frame.origin.x = [o_cmd_checkbox frame].size.width +
2087 [o_cmd_checkbox frame].origin.x + 4;
2088 [o_shift_checkbox setFrame:frame];
2090 frame = [o_popup frame];
2091 frame.origin.x = [o_shift_checkbox frame].origin.x +
2092 [o_shift_checkbox frame].size.width + 3;
2093 frame.size.width = superFrame.size.width - frame.origin.x + 2;
2094 [o_popup setFrame:frame];
2099 [o_cmd_checkbox release];
2100 [o_ctrl_checkbox release];
2101 [o_alt_checkbox release];
2102 [o_shift_checkbox release];
2109 unsigned int i_new_key = 0;
2111 i_new_key |= ([o_cmd_checkbox state] == NSOnState) ?
2112 KEY_MODIFIER_COMMAND : 0;
2113 i_new_key |= ([o_ctrl_checkbox state] == NSOnState) ?
2114 KEY_MODIFIER_CTRL : 0;
2115 i_new_key |= ([o_alt_checkbox state] == NSOnState) ?
2116 KEY_MODIFIER_ALT : 0;
2117 i_new_key |= ([o_shift_checkbox state] == NSOnState) ?
2118 KEY_MODIFIER_SHIFT : 0;
2120 i_new_key |= StringToKey((char *)[[[o_popup selectedItem] title] cString]);
2125 @implementation KeyConfigControlAfter103
2126 - (id) initWithItem: (module_config_t *)_p_item
2127 withView: (NSView *)o_parent_view
2129 NSRect mainFrame = [o_parent_view frame];
2130 NSString *o_labelString, *o_tooltip;
2131 mainFrame.size.height = 22;
2132 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
2133 mainFrame.origin.x = LEFTMARGIN;
2134 mainFrame.origin.y = 0;
2136 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2138 i_view_type = CONFIG_ITEM_KEY_AFTER_10_3;
2141 if( p_item->psz_text )
2142 o_labelString = [[VLCMain sharedInstance]
2143 localizedString: (char *)p_item->psz_text];
2145 o_labelString = [NSString stringWithString:@""];
2146 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString )
2147 [o_label setAutoresizingMask:NSViewNotSizable ];
2148 [self addSubview: o_label];
2150 /* build the popup */
2151 o_tooltip = [[VLCMain sharedInstance] wrapString:
2152 [[VLCMain sharedInstance]
2153 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2154 ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2155 [o_label frame].size.width + 3,
2157 [o_popup setAutoresizingMask:NSViewWidthSizable ];
2159 if( o_keys_menu == nil )
2162 o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2163 for ( i = 0; i < sizeof(vlc_keys) / sizeof(key_descriptor_t); i++)
2164 if( vlc_keys[i].psz_key_string && *vlc_keys[i].psz_key_string )
2165 POPULATE_A_KEY( o_keys_menu,
2166 [NSString stringWithCString:vlc_keys[i].psz_key_string]
2167 , vlc_keys[i].i_key_code)
2169 [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2170 [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
2171 [self addSubview: o_popup];
2177 - (void) alignWithXPosition:(int)i_xPos
2180 NSRect superFrame = [self frame];
2181 frame = [o_label frame];
2182 frame.origin.x = i_xPos - frame.size.width - 3;
2183 [o_label setFrame:frame];
2185 frame = [o_popup frame];
2186 frame.origin.x = i_xPos - 1;
2187 frame.size.width = superFrame.size.width - frame.origin.x + 2;
2188 [o_popup setFrame:frame];
2199 return [o_popup selectedTag];
2203 @implementation ModuleListConfigControl
2204 - (id) initWithItem: (module_config_t *)_p_item
2205 withView: (NSView *)o_parent_view
2207 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2211 //Fill our array to know how may items we have...
2214 module_config_t *p_end;
2216 NSRect mainFrame = [o_parent_view frame];
2217 NSString *o_labelString, *o_textfieldString, *o_tooltip;
2219 o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2220 /* build a list of available modules */
2221 p_list = vlc_list_find( VLCIntf, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2222 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2224 p_parser = (module_t *)p_list->p_values[i_index].p_object;
2225 p_end = p_item + p_parser->confsize;
2227 if( !strcmp( p_parser->psz_object_name, "main" ) )
2230 module_config_t *p_config = p_parser->p_config;
2233 NSString *o_modulelongname, *o_modulename;
2234 NSNumber *o_moduleenabled = nil;
2235 /* Hack: required subcategory is stored in i_min */
2236 if( p_config->i_type == CONFIG_SUBCATEGORY &&
2237 p_config->value.i == _p_item->min.i )
2239 o_modulelongname = [NSString stringWithUTF8String:
2240 p_parser->psz_longname];
2241 o_modulename = [NSString stringWithUTF8String:
2242 p_parser->psz_object_name];
2244 if( _p_item->value.psz &&
2245 strstr( _p_item->value.psz, p_parser->psz_object_name ) )
2246 o_moduleenabled = [NSNumber numberWithBool:YES];
2248 o_moduleenabled = [NSNumber numberWithBool:NO];
2250 [o_modulearray addObject:[NSMutableArray
2251 arrayWithObjects: o_modulename, o_modulelongname,
2252 o_moduleenabled, nil]];
2254 } while( p_item < p_end && p_config++ );
2256 vlc_list_release( p_list );
2258 mainFrame.size.height = 30 + 18 * [o_modulearray count];
2259 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2260 mainFrame.origin.x = LEFTMARGIN;
2261 mainFrame.origin.y = 0;
2262 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2264 i_view_type = CONFIG_ITEM_MODULE_LIST;
2267 if( p_item->psz_text )
2268 o_labelString = [[VLCMain sharedInstance]
2269 localizedString: (char *)p_item->psz_text];
2271 o_labelString = [NSString stringWithString:@""];
2272 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString )
2273 [o_label setAutoresizingMask:NSViewNotSizable ];
2274 [self addSubview: o_label];
2276 /* build the textfield */
2277 o_tooltip = [[VLCMain sharedInstance] wrapString:
2278 [[VLCMain sharedInstance]
2279 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2280 if( p_item->value.psz )
2281 o_textfieldString = [[VLCMain sharedInstance]
2282 localizedString: (char *)p_item->value.psz];
2284 o_textfieldString = [NSString stringWithString: @""];
2285 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2286 mainFrame.size.height - 22, mainFrame.size.width -
2287 [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2288 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2289 [self addSubview: o_textfield];
2293 NSRect s_rc = mainFrame;
2294 s_rc.size.height = mainFrame.size.height - 30;
2295 s_rc.size.width = mainFrame.size.width - 12;
2298 o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2299 [o_scrollview setDrawsBackground: NO];
2300 [o_scrollview setBorderType: NSBezelBorder];
2301 if( MACOS_VERSION >= 10.3 )
2302 [o_scrollview setAutohidesScrollers:YES];
2304 NSTableView *o_tableview;
2305 o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2306 if( MACOS_VERSION >= 10.3 )
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];