1 /*****************************************************************************
2 * prefs_widgets.m: Preferences controls
3 *****************************************************************************
4 * Copyright (C) 2002-2011 VLC authors and 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
35 #include <vlc_common.h>
36 #include <vlc_modules.h>
40 #include "prefs_widgets.h"
42 #define PREFS_WRAP 300
43 #define OFFSET_RIGHT 20
44 #define OFFSET_BETWEEN 2
46 #define UPWARDS_WHITE_ARROW "\xE2\x87\xA7"
47 #define OPTION_KEY "\xE2\x8C\xA5"
48 #define UP_ARROWHEAD "\xE2\x8C\x83"
49 #define PLACE_OF_INTEREST_SIGN "\xE2\x8C\x98"
51 #define POPULATE_A_KEY( o_menu, string, value ) \
55 o_mi = [[NSMenuItem alloc] initWithTitle:string \
56 action:nil keyEquivalent:@""]; \
57 [o_mi setKeyEquivalentModifierMask: \
59 [o_mi setAlternate: NO]; \
62 [o_menu addItem: o_mi]; \
64 o_mi = [[NSMenuItem alloc] initWithTitle: \
65 [[NSString stringWithUTF8String: \
67 ] stringByAppendingString: string] \
68 action:nil keyEquivalent:@""]; \
69 [o_mi setKeyEquivalentModifierMask: \
71 [o_mi setAlternate: YES]; \
73 KEY_MODIFIER_CTRL | ( value )]; \
74 [o_menu addItem: o_mi]; \
76 o_mi = [[NSMenuItem alloc] initWithTitle: \
77 [[NSString stringWithUTF8String: \
78 UP_ARROWHEAD OPTION_KEY \
79 ] stringByAppendingString: string] \
80 action:nil keyEquivalent:@""]; \
81 [o_mi setKeyEquivalentModifierMask: \
82 NSControlKeyMask | NSAlternateKeyMask]; \
83 [o_mi setAlternate: YES]; \
85 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT) | ( value )]; \
86 [o_menu addItem: o_mi]; \
88 o_mi = [[NSMenuItem alloc] initWithTitle: \
89 [[NSString stringWithUTF8String: \
90 UP_ARROWHEAD UPWARDS_WHITE_ARROW \
91 ] stringByAppendingString: string] \
92 action:nil keyEquivalent:@""]; \
93 [o_mi setKeyEquivalentModifierMask: \
94 NSControlKeyMask | NSShiftKeyMask]; \
95 [o_mi setAlternate: YES]; \
97 (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT) | ( value )]; \
98 [o_menu addItem: o_mi]; \
100 o_mi = [[NSMenuItem alloc] initWithTitle: \
101 [[NSString stringWithUTF8String: \
102 UP_ARROWHEAD PLACE_OF_INTEREST_SIGN \
103 ] stringByAppendingString: string] \
104 action:nil keyEquivalent:@""]; \
105 [o_mi setKeyEquivalentModifierMask: \
106 NSControlKeyMask | NSCommandKeyMask]; \
107 [o_mi setAlternate: YES]; \
109 (KEY_MODIFIER_CTRL | KEY_MODIFIER_COMMAND) | ( value )]; \
110 [o_menu addItem: o_mi]; \
111 /* Ctrl+Alt+Shift */ \
112 o_mi = [[NSMenuItem alloc] initWithTitle: \
113 [[NSString stringWithUTF8String: \
114 UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW \
115 ] stringByAppendingString: string] \
116 action:nil keyEquivalent:@""]; \
117 [o_mi setKeyEquivalentModifierMask: \
118 NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask]; \
119 [o_mi setAlternate: YES]; \
121 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | \
123 [o_menu addItem: o_mi]; \
124 /* Ctrl+Alt+Apple */ \
125 o_mi = [[NSMenuItem alloc] initWithTitle: \
126 [[NSString stringWithUTF8String: \
127 UP_ARROWHEAD OPTION_KEY PLACE_OF_INTEREST_SIGN \
128 ] stringByAppendingString: string] \
129 action:nil keyEquivalent:@""]; \
130 [o_mi setKeyEquivalentModifierMask: \
131 NSControlKeyMask | NSAlternateKeyMask | NSCommandKeyMask]; \
132 [o_mi setAlternate: YES]; \
134 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | \
136 [o_menu addItem: o_mi]; \
137 /* Ctrl+Shift+Apple */ \
138 o_mi = [[NSMenuItem alloc] initWithTitle: \
139 [[NSString stringWithUTF8String: \
140 UP_ARROWHEAD UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
141 ] stringByAppendingString: string] \
142 action:nil keyEquivalent:@""]; \
143 [o_mi setKeyEquivalentModifierMask: \
144 NSControlKeyMask | NSShiftKeyMask | NSCommandKeyMask]; \
145 [o_mi setAlternate: YES]; \
147 (KEY_MODIFIER_CTRL | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | \
149 [o_menu addItem: o_mi]; \
150 /* Ctrl+Alt+Shift+Apple */ \
151 o_mi = [[NSMenuItem alloc] initWithTitle: \
152 [[NSString stringWithUTF8String: \
153 UP_ARROWHEAD OPTION_KEY UPWARDS_WHITE_ARROW \
154 PLACE_OF_INTEREST_SIGN \
155 ] stringByAppendingString: string] \
156 action:nil keyEquivalent:@""]; \
157 [o_mi setKeyEquivalentModifierMask: \
158 NSControlKeyMask | NSAlternateKeyMask | NSShiftKeyMask | \
160 [o_mi setAlternate: YES]; \
162 (KEY_MODIFIER_CTRL | KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | \
163 KEY_MODIFIER_COMMAND) | ( value )]; \
164 [o_menu addItem: o_mi]; \
166 o_mi = [[NSMenuItem alloc] initWithTitle: \
167 [[NSString stringWithUTF8String: \
169 ] stringByAppendingString: string] \
170 action:nil keyEquivalent:@""]; \
171 [o_mi setKeyEquivalentModifierMask: \
172 NSAlternateKeyMask]; \
173 [o_mi setAlternate: YES]; \
175 KEY_MODIFIER_ALT | ( value )]; \
176 [o_menu addItem: o_mi]; \
178 o_mi = [[NSMenuItem alloc] initWithTitle: \
179 [[NSString stringWithUTF8String: \
180 OPTION_KEY UPWARDS_WHITE_ARROW \
181 ] stringByAppendingString: string] \
182 action:nil keyEquivalent:@""]; \
183 [o_mi setKeyEquivalentModifierMask: \
184 NSAlternateKeyMask | NSShiftKeyMask]; \
185 [o_mi setAlternate: YES]; \
187 (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT) | ( value )]; \
188 [o_menu addItem: o_mi]; \
190 o_mi = [[NSMenuItem alloc] initWithTitle: \
191 [[NSString stringWithUTF8String: \
192 OPTION_KEY PLACE_OF_INTEREST_SIGN \
193 ] stringByAppendingString: string] \
194 action:nil keyEquivalent:@""]; \
195 [o_mi setKeyEquivalentModifierMask: \
196 NSAlternateKeyMask | NSCommandKeyMask]; \
197 [o_mi setAlternate: YES]; \
199 (KEY_MODIFIER_ALT | KEY_MODIFIER_COMMAND) | ( value )]; \
200 [o_menu addItem: o_mi]; \
201 /* Alt+Shift+Apple */ \
202 o_mi = [[NSMenuItem alloc] initWithTitle: \
203 [[NSString stringWithUTF8String: \
204 OPTION_KEY UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
205 ] stringByAppendingString: string] \
206 action:nil keyEquivalent:@""]; \
207 [o_mi setKeyEquivalentModifierMask: \
208 NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask]; \
209 [o_mi setAlternate: YES]; \
211 (KEY_MODIFIER_ALT | KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | \
213 [o_menu addItem: o_mi]; \
215 o_mi = [[NSMenuItem alloc] initWithTitle: \
216 [[NSString stringWithUTF8String: \
217 UPWARDS_WHITE_ARROW \
218 ] stringByAppendingString: string] \
219 action:nil keyEquivalent:@""]; \
220 [o_mi setKeyEquivalentModifierMask: \
222 [o_mi setAlternate: YES]; \
224 KEY_MODIFIER_SHIFT | ( value )]; \
225 [o_menu addItem: o_mi]; \
227 o_mi = [[NSMenuItem alloc] initWithTitle: \
228 [[NSString stringWithUTF8String: \
229 UPWARDS_WHITE_ARROW PLACE_OF_INTEREST_SIGN \
230 ] stringByAppendingString: string] \
231 action:nil keyEquivalent:@""]; \
232 [o_mi setKeyEquivalentModifierMask: \
233 NSShiftKeyMask | NSCommandKeyMask]; \
234 [o_mi setAlternate: YES]; \
236 (KEY_MODIFIER_SHIFT | KEY_MODIFIER_COMMAND) | ( value )]; \
237 [o_menu addItem: o_mi]; \
239 o_mi = [[NSMenuItem alloc] initWithTitle: \
240 [[NSString stringWithUTF8String: \
241 PLACE_OF_INTEREST_SIGN \
242 ] stringByAppendingString: string] \
243 action:nil keyEquivalent:@""]; \
244 [o_mi setKeyEquivalentModifierMask: \
246 [o_mi setAlternate: YES]; \
248 KEY_MODIFIER_COMMAND | ( value )]; \
249 [o_menu addItem: o_mi]; \
252 #define ADD_LABEL( o_label, superFrame, x_offset, my_y_offset, label, \
255 NSRect s_rc = superFrame; \
256 s_rc.size.height = 17; \
257 s_rc.origin.x = x_offset - 3; \
258 s_rc.origin.y = superFrame.size.height - 17 + my_y_offset; \
259 o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain]; \
260 [o_label setDrawsBackground: NO]; \
261 [o_label setBordered: NO]; \
262 [o_label setEditable: NO]; \
263 [o_label setSelectable: NO]; \
264 [o_label setStringValue: label]; \
265 [o_label setToolTip: tooltip]; \
266 [o_label setFont:[NSFont systemFontOfSize:0]]; \
267 [o_label sizeToFit]; \
270 #define ADD_TEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset, \
271 my_width, tooltip, init_value ) \
273 NSRect s_rc = superFrame; \
274 s_rc.origin.x = x_offset; \
275 s_rc.origin.y = my_y_offset; \
276 s_rc.size.height = 22; \
277 s_rc.size.width = my_width; \
278 o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain]; \
279 [o_textfield setFont:[NSFont systemFontOfSize:0]]; \
280 [o_textfield setToolTip: tooltip]; \
281 [o_textfield setStringValue: init_value]; \
284 #define ADD_SECURETEXTFIELD( o_textfield, superFrame, x_offset, my_y_offset, \
285 my_width, tooltip, init_value ) \
287 NSRect s_rc = superFrame; \
288 s_rc.origin.x = x_offset; \
289 s_rc.origin.y = my_y_offset; \
290 s_rc.size.height = 22; \
291 s_rc.size.width = my_width; \
292 o_textfield = [[[NSSecureTextField alloc] initWithFrame: s_rc] retain]; \
293 [o_textfield setFont:[NSFont systemFontOfSize:0]]; \
294 [o_textfield setToolTip: tooltip]; \
295 [o_textfield setStringValue: init_value]; \
298 #define ADD_COMBO( o_combo, superFrame, x_offset, my_y_offset, x2_offset, \
301 NSRect s_rc = superFrame; \
302 s_rc.origin.x = x_offset + 2; \
303 s_rc.origin.y = my_y_offset; \
304 s_rc.size.height = 26; \
305 s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x - \
307 o_combo = [[[NSComboBox alloc] initWithFrame: s_rc] retain]; \
308 [o_combo setFont:[NSFont systemFontOfSize:0]]; \
309 [o_combo setToolTip: tooltip]; \
310 [o_combo setUsesDataSource:TRUE]; \
311 [o_combo setDataSource:self]; \
312 [o_combo setNumberOfVisibleItems:10]; \
313 [o_combo setCompletes:YES]; \
316 #define ADD_RIGHT_BUTTON( o_button, superFrame, x_offset, my_y_offset, \
319 NSRect s_rc = superFrame; \
320 o_button = [[[NSButton alloc] initWithFrame: s_rc] retain]; \
321 [o_button setButtonType: NSMomentaryPushInButton]; \
322 [o_button setBezelStyle: NSRoundedBezelStyle]; \
323 [o_button setTitle: title]; \
324 [o_button setFont:[NSFont systemFontOfSize:0]]; \
325 [o_button sizeToFit]; \
326 s_rc = [o_button frame]; \
327 s_rc.origin.x = superFrame.size.width - [o_button frame].size.width - 6;\
328 s_rc.origin.y = my_y_offset - 6; \
329 s_rc.size.width += 12; \
330 [o_button setFrame: s_rc]; \
331 [o_button setToolTip: tooltip]; \
332 [o_button setTarget: self]; \
333 [o_button setAction: @selector(openFileDialog:)]; \
336 #define ADD_POPUP( o_popup, superFrame, x_offset, my_y_offset, x2_offset, \
339 NSRect s_rc = superFrame; \
340 s_rc.origin.x = x_offset - 1; \
341 s_rc.origin.y = my_y_offset; \
342 s_rc.size.height = 26; \
343 s_rc.size.width = superFrame.size.width + 2 - s_rc.origin.x - \
345 o_popup = [[[NSPopUpButton alloc] initWithFrame: s_rc] retain]; \
346 [o_popup setFont:[NSFont systemFontOfSize:0]]; \
347 [o_popup setToolTip: tooltip]; \
350 #define ADD_STEPPER( o_stepper, superFrame, x_offset, my_y_offset, tooltip, \
353 NSRect s_rc = superFrame; \
354 s_rc.origin.x = x_offset; \
355 s_rc.origin.y = my_y_offset; \
356 s_rc.size.height = 23; \
357 s_rc.size.width = 23; \
358 o_stepper = [[[NSStepper alloc] initWithFrame: s_rc] retain]; \
359 [o_stepper setFont:[NSFont systemFontOfSize:0]]; \
360 [o_stepper setToolTip: tooltip]; \
361 [o_stepper setMaxValue: higher]; \
362 [o_stepper setMinValue: lower]; \
363 [o_stepper setTarget: self]; \
364 [o_stepper setAction: @selector(stepperChanged:)]; \
365 [o_stepper sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask | \
366 NSLeftMouseDraggedMask]; \
369 #define ADD_SLIDER( o_slider, superFrame, x_offset, my_y_offset, my_width, \
370 tooltip, lower, higher ) \
372 NSRect s_rc = superFrame; \
373 s_rc.origin.x = x_offset; \
374 s_rc.origin.y = my_y_offset; \
375 s_rc.size.height = 21; \
376 s_rc.size.width = my_width; \
377 o_slider = [[[NSSlider alloc] initWithFrame: s_rc] retain]; \
378 [o_slider setFont:[NSFont systemFontOfSize:0]]; \
379 [o_slider setToolTip: tooltip]; \
380 [o_slider setMaxValue: higher]; \
381 [o_slider setMinValue: lower]; \
384 #define ADD_CHECKBOX( o_checkbox, superFrame, x_offset, my_y_offset, label, \
385 tooltip, init_value, position ) \
387 NSRect s_rc = superFrame; \
388 s_rc.size.height = 18; \
389 s_rc.origin.x = x_offset - 2; \
390 s_rc.origin.y = superFrame.size.height - 18 + my_y_offset; \
391 o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain]; \
392 [o_checkbox setFont:[NSFont systemFontOfSize:0]]; \
393 [o_checkbox setButtonType: NSSwitchButton]; \
394 [o_checkbox setImagePosition: position]; \
395 [o_checkbox setIntValue: init_value]; \
396 [o_checkbox setTitle: label]; \
397 [o_checkbox setToolTip: tooltip]; \
398 [o_checkbox sizeToFit]; \
401 @implementation VLCConfigControl
402 - (id)initWithFrame: (NSRect)frame
404 return [self initWithFrame: frame
408 - (id)initWithFrame: (NSRect)frame
409 item: (module_config_t *)_p_item
411 self = [super initWithFrame: frame];
416 psz_name = p_item->psz_name;
418 i_type = p_item->i_type;
420 b_advanced = p_item->b_advanced;
421 [self setAutoresizingMask:NSViewWidthSizable | NSViewMinYMargin ];
426 - (void)setYPos:(int)i_yPos
428 NSRect frame = [self frame];
429 frame.origin.y = i_yPos;
430 [self setFrame:frame];
435 if( o_label ) [o_label release];
440 + (int)calcVerticalMargin: (int)i_curItem lastItem: (int)i_lastItem
445 case CONFIG_ITEM_STRING:
446 case CONFIG_ITEM_PASSWORD:
449 case CONFIG_ITEM_STRING:
450 case CONFIG_ITEM_PASSWORD:
453 case CONFIG_ITEM_STRING_LIST:
456 case CONFIG_ITEM_LOADFILE:
457 case CONFIG_ITEM_SAVEFILE:
460 case CONFIG_ITEM_MODULE:
463 case CONFIG_ITEM_INTEGER:
466 case CONFIG_ITEM_RANGED_INTEGER:
469 case CONFIG_ITEM_BOOL:
472 case CONFIG_ITEM_KEY:
475 case CONFIG_ITEM_MODULE_LIST:
483 case CONFIG_ITEM_STRING_LIST:
486 case CONFIG_ITEM_STRING:
487 case CONFIG_ITEM_PASSWORD:
490 case CONFIG_ITEM_STRING_LIST:
493 case CONFIG_ITEM_LOADFILE:
494 case CONFIG_ITEM_SAVEFILE:
497 case CONFIG_ITEM_MODULE:
500 case CONFIG_ITEM_INTEGER:
503 case CONFIG_ITEM_RANGED_INTEGER:
506 case CONFIG_ITEM_BOOL:
509 case CONFIG_ITEM_KEY:
512 case CONFIG_ITEM_MODULE_LIST:
520 case CONFIG_ITEM_LOADFILE:
521 case CONFIG_ITEM_SAVEFILE:
524 case CONFIG_ITEM_STRING:
525 case CONFIG_ITEM_PASSWORD:
528 case CONFIG_ITEM_STRING_LIST:
531 case CONFIG_ITEM_LOADFILE:
532 case CONFIG_ITEM_SAVEFILE:
535 case CONFIG_ITEM_MODULE:
538 case CONFIG_ITEM_INTEGER:
541 case CONFIG_ITEM_RANGED_INTEGER:
544 case CONFIG_ITEM_BOOL:
547 case CONFIG_ITEM_KEY:
550 case CONFIG_ITEM_MODULE_LIST:
558 case CONFIG_ITEM_MODULE:
561 case CONFIG_ITEM_STRING:
562 case CONFIG_ITEM_PASSWORD:
565 case CONFIG_ITEM_STRING_LIST:
568 case CONFIG_ITEM_LOADFILE:
569 case CONFIG_ITEM_SAVEFILE:
572 case CONFIG_ITEM_MODULE:
575 case CONFIG_ITEM_INTEGER:
578 case CONFIG_ITEM_RANGED_INTEGER:
581 case CONFIG_ITEM_BOOL:
584 case CONFIG_ITEM_KEY:
587 case CONFIG_ITEM_MODULE_LIST:
595 case CONFIG_ITEM_INTEGER:
598 case CONFIG_ITEM_STRING:
599 case CONFIG_ITEM_PASSWORD:
602 case CONFIG_ITEM_STRING_LIST:
605 case CONFIG_ITEM_LOADFILE:
606 case CONFIG_ITEM_SAVEFILE:
609 case CONFIG_ITEM_MODULE:
612 case CONFIG_ITEM_INTEGER:
615 case CONFIG_ITEM_RANGED_INTEGER:
618 case CONFIG_ITEM_BOOL:
621 case CONFIG_ITEM_KEY:
624 case CONFIG_ITEM_MODULE_LIST:
632 case CONFIG_ITEM_RANGED_INTEGER:
635 case CONFIG_ITEM_STRING:
636 case CONFIG_ITEM_PASSWORD:
639 case CONFIG_ITEM_STRING_LIST:
642 case CONFIG_ITEM_LOADFILE:
643 case CONFIG_ITEM_SAVEFILE:
646 case CONFIG_ITEM_MODULE:
649 case CONFIG_ITEM_INTEGER:
652 case CONFIG_ITEM_RANGED_INTEGER:
655 case CONFIG_ITEM_BOOL:
658 case CONFIG_ITEM_KEY:
661 case CONFIG_ITEM_MODULE_LIST:
669 case CONFIG_ITEM_BOOL:
672 case CONFIG_ITEM_STRING:
673 case CONFIG_ITEM_PASSWORD:
676 case CONFIG_ITEM_STRING_LIST:
679 case CONFIG_ITEM_LOADFILE:
680 case CONFIG_ITEM_SAVEFILE:
683 case CONFIG_ITEM_MODULE:
686 case CONFIG_ITEM_INTEGER:
689 case CONFIG_ITEM_RANGED_INTEGER:
692 case CONFIG_ITEM_BOOL:
695 case CONFIG_ITEM_KEY:
698 case CONFIG_ITEM_MODULE_LIST:
706 case CONFIG_ITEM_KEY:
709 case CONFIG_ITEM_STRING:
710 case CONFIG_ITEM_PASSWORD:
713 case CONFIG_ITEM_STRING_LIST:
716 case CONFIG_ITEM_LOADFILE:
717 case CONFIG_ITEM_SAVEFILE:
720 case CONFIG_ITEM_MODULE:
723 case CONFIG_ITEM_INTEGER:
726 case CONFIG_ITEM_RANGED_INTEGER:
729 case CONFIG_ITEM_BOOL:
732 case CONFIG_ITEM_KEY:
735 case CONFIG_ITEM_MODULE_LIST:
743 case CONFIG_ITEM_MODULE_LIST:
746 case CONFIG_ITEM_STRING:
747 case CONFIG_ITEM_PASSWORD:
750 case CONFIG_ITEM_STRING_LIST:
753 case CONFIG_ITEM_LOADFILE:
754 case CONFIG_ITEM_SAVEFILE:
757 case CONFIG_ITEM_MODULE:
760 case CONFIG_ITEM_INTEGER:
763 case CONFIG_ITEM_RANGED_INTEGER:
766 case CONFIG_ITEM_BOOL:
769 case CONFIG_ITEM_KEY:
772 case CONFIG_ITEM_MODULE_LIST:
787 + (VLCConfigControl *)newControl: (module_config_t *)_p_item
788 withView: (NSView *)o_parent_view
790 VLCConfigControl *p_control = NULL;
792 switch( _p_item->i_type )
794 case CONFIG_ITEM_STRING:
795 case CONFIG_ITEM_PASSWORD:
796 if( !_p_item->i_list )
798 p_control = [[StringConfigControl alloc]
799 initWithItem: _p_item
800 withView: o_parent_view];
804 p_control = [[StringListConfigControl alloc]
805 initWithItem: _p_item
806 withView: o_parent_view];
809 case CONFIG_ITEM_LOADFILE:
810 case CONFIG_ITEM_SAVEFILE:
811 case CONFIG_ITEM_DIRECTORY:
812 p_control = [[FileConfigControl alloc]
813 initWithItem: _p_item
814 withView: o_parent_view];
816 case CONFIG_ITEM_MODULE:
817 case CONFIG_ITEM_MODULE_CAT:
818 p_control = [[ModuleConfigControl alloc]
819 initWithItem: _p_item
820 withView: o_parent_view];
822 case CONFIG_ITEM_INTEGER:
823 if( _p_item->i_list )
825 p_control = [[IntegerListConfigControl alloc]
826 initWithItem: _p_item
827 withView: o_parent_view];
829 else if( (_p_item->min.i != 0 || _p_item->max.i != 0) && (_p_item->min.i != INT_MIN || _p_item->max.i != INT_MAX) )
831 p_control = [[RangedIntegerConfigControl alloc]
832 initWithItem: _p_item
833 withView: o_parent_view];
837 p_control = [[IntegerConfigControl alloc]
838 initWithItem: _p_item
839 withView: o_parent_view];
842 case CONFIG_ITEM_BOOL:
843 p_control = [[BoolConfigControl alloc]
844 initWithItem: _p_item
845 withView: o_parent_view];
847 case CONFIG_ITEM_FLOAT:
848 if( (_p_item->min.i != 0 || _p_item->max.i != 0) && (_p_item->min.i != INT_MIN || _p_item->max.i != INT_MAX) )
850 p_control = [[RangedFloatConfigControl alloc]
851 initWithItem: _p_item
852 withView: o_parent_view];
856 p_control = [[FloatConfigControl alloc]
857 initWithItem: _p_item
858 withView: o_parent_view];
861 /* don't display keys in the advanced settings, since the current controls
862 are broken by design. The user is required to change hotkeys in the sprefs
863 and can only change really advanced stuff here..
864 case CONFIG_ITEM_KEY:
865 p_control = [[KeyConfigControl alloc]
866 initWithItem: _p_item
867 withView: o_parent_view];
869 case CONFIG_ITEM_MODULE_LIST:
870 case CONFIG_ITEM_MODULE_LIST_CAT:
871 p_control = [[ModuleListConfigControl alloc]
872 initWithItem: _p_item
873 withView: o_parent_view];
883 return [[VLCMain sharedInstance] localizedString: psz_name];
911 - (char *)stringValue
919 switch( p_item->i_type )
921 case CONFIG_ITEM_STRING:
922 case CONFIG_ITEM_PASSWORD:
923 case CONFIG_ITEM_LOADFILE:
924 case CONFIG_ITEM_SAVEFILE:
925 case CONFIG_ITEM_DIRECTORY:
926 case CONFIG_ITEM_MODULE:
927 case CONFIG_ITEM_MODULE_LIST:
928 case CONFIG_ITEM_MODULE_LIST_CAT:
929 config_PutPsz( VLCIntf, psz_name, [self stringValue] );
931 case CONFIG_ITEM_KEY:
932 /* So you don't need to restart to have the changes take effect */
933 val.i_int = [self intValue];
934 var_Set( VLCIntf->p_libvlc, psz_name, val );
935 case CONFIG_ITEM_INTEGER:
936 case CONFIG_ITEM_BOOL:
937 config_PutInt( VLCIntf, psz_name, [self intValue] );
939 case CONFIG_ITEM_FLOAT:
940 config_PutFloat( VLCIntf, psz_name, [self floatValue] );
951 return [o_label frame].size.width;
954 - (void) alignWithXPosition:(int)i_xPos;
956 /* FIXME: not implemented atm, but created to shut up the warning
957 * about "method definition not found" -- FK @ 7/24/05 */
961 @implementation StringConfigControl
962 - (id) initWithItem: (module_config_t *)_p_item
963 withView: (NSView *)o_parent_view
965 NSRect mainFrame = [o_parent_view frame];
966 NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
967 mainFrame.size.height = 22;
968 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
969 mainFrame.origin.x = LEFTMARGIN;
970 mainFrame.origin.y = 0;
972 if( [super initWithFrame: mainFrame item: _p_item] != nil )
974 if( p_item->i_type == CONFIG_ITEM_PASSWORD )
975 i_view_type = CONFIG_ITEM_PASSWORD;
977 i_view_type = CONFIG_ITEM_STRING;
979 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
980 [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext]
981 toWidth: PREFS_WRAP];
984 if( p_item->psz_text )
985 o_labelString = [[VLCMain sharedInstance]
986 localizedString: (char *)p_item->psz_text];
988 o_labelString = [NSString stringWithString:@""];
989 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
990 [o_label setAutoresizingMask:NSViewNotSizable ];
991 [self addSubview: o_label];
993 /* build the textfield */
994 if( p_item->value.psz )
995 o_textfieldString = [[VLCMain sharedInstance]
996 localizedString: (char *)p_item->value.psz];
998 o_textfieldString = [NSString stringWithString: @""];
999 if( p_item->i_type == CONFIG_ITEM_PASSWORD )
1001 ADD_SECURETEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1002 0, mainFrame.size.width - [o_label frame].size.width -
1003 2, o_textfieldTooltip, o_textfieldString )
1007 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1008 0, mainFrame.size.width - [o_label frame].size.width -
1009 2, o_textfieldTooltip, o_textfieldString )
1011 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1013 [self addSubview: o_textfield];
1018 - (void) alignWithXPosition:(int)i_xPos
1021 NSRect superFrame = [self frame];
1022 frame = [o_label frame];
1023 frame.origin.x = i_xPos - frame.size.width - 3;
1024 [o_label setFrame:frame];
1026 frame = [o_textfield frame];
1027 frame.origin.x = i_xPos + 2;
1028 frame.size.width = superFrame.size.width - frame.origin.x - 1;
1029 [o_textfield setFrame:frame];
1034 [o_textfield release];
1038 - (char *)stringValue
1040 return [[VLCMain sharedInstance] delocalizeString:
1041 [o_textfield stringValue]];
1046 NSString *o_textfieldString;
1047 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1049 o_textfieldString = [[VLCMain sharedInstance]
1050 localizedString: psz_value];
1052 o_textfieldString = [NSString stringWithString: @""];
1054 [super resetValues];
1058 @implementation StringListConfigControl
1059 - (id) initWithItem: (module_config_t *)_p_item
1060 withView: (NSView *)o_parent_view
1062 NSRect mainFrame = [o_parent_view frame];
1063 NSString *o_labelString, *o_textfieldTooltip;
1064 mainFrame.size.height = 22;
1065 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1066 mainFrame.origin.x = LEFTMARGIN;
1067 mainFrame.origin.y = 0;
1069 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1072 i_view_type = CONFIG_ITEM_STRING_LIST;
1074 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1075 [[VLCMain sharedInstance]
1076 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1079 if( p_item->psz_text )
1080 o_labelString = [[VLCMain sharedInstance]
1081 localizedString: (char *)p_item->psz_text];
1083 o_labelString = [NSString stringWithString:@""];
1084 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1085 [o_label setAutoresizingMask:NSViewNotSizable ];
1086 [self addSubview: o_label];
1088 /* build the textfield */
1089 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1090 -2, 0, o_textfieldTooltip )
1091 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1092 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1094 if( !p_item->value.psz && !p_item->ppsz_list[i_index] )
1095 [o_combo selectItemAtIndex: i_index];
1096 else if( p_item->value.psz && p_item->ppsz_list[i_index] &&
1097 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
1098 [o_combo selectItemAtIndex: i_index];
1100 [self addSubview: o_combo];
1105 - (void) alignWithXPosition:(int)i_xPos
1108 NSRect superFrame = [self frame];
1109 frame = [o_label frame];
1110 frame.origin.x = i_xPos - frame.size.width - 3;
1111 [o_label setFrame:frame];
1113 frame = [o_combo frame];
1114 frame.origin.x = i_xPos + 2;
1115 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1116 [o_combo setFrame:frame];
1125 - (char *)stringValue
1127 if( [o_combo indexOfSelectedItem] >= 0 ) {
1128 if( p_item->ppsz_list[[o_combo indexOfSelectedItem]] != NULL )
1129 return strdup( p_item->ppsz_list[[o_combo indexOfSelectedItem]] );
1131 if( [[VLCMain sharedInstance] delocalizeString: [o_combo stringValue]] != NULL )
1132 return strdup( [[VLCMain sharedInstance] delocalizeString: [o_combo stringValue]] );
1140 [o_combo reloadData];
1141 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1143 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1145 if( !psz_value && !p_item->ppsz_list[i_index] )
1146 [o_combo selectItemAtIndex: i_index];
1147 else if( psz_value && p_item->ppsz_list[i_index] &&
1148 !strcmp( psz_value, p_item->ppsz_list[i_index] ) )
1149 [o_combo selectItemAtIndex: i_index];
1153 [super resetValues];
1157 @implementation StringListConfigControl (NSComboBoxDataSource)
1158 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1160 return p_item->i_list;
1163 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1165 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1167 return [[VLCMain sharedInstance]
1168 localizedString: (char *)p_item->ppsz_list_text[i_index]];
1169 } else return [[VLCMain sharedInstance]
1170 localizedString: (char *)p_item->ppsz_list[i_index]];
1174 @implementation FileConfigControl
1175 - (id) initWithItem: (module_config_t *)_p_item
1176 withView: (NSView *)o_parent_view
1178 NSRect mainFrame = [o_parent_view frame];
1179 NSString *o_labelString, *o_itemTooltip, *o_textfieldString;
1180 mainFrame.size.height = 46;
1181 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1182 mainFrame.origin.x = LEFTMARGIN;
1183 mainFrame.origin.y = 0;
1185 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1187 i_view_type = CONFIG_ITEM_LOADFILE;
1189 o_itemTooltip = [[VLCMain sharedInstance]
1190 wrapString: [[VLCMain sharedInstance]
1191 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1193 /* is it a directory */
1194 b_directory = ( [self type] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1197 if( p_item->psz_text )
1198 o_labelString = [[VLCMain sharedInstance]
1199 localizedString: (char *)p_item->psz_text];
1201 o_labelString = [NSString stringWithString:@""];
1202 ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString, o_itemTooltip )
1203 [o_label setAutoresizingMask:NSViewNotSizable ];
1204 [self addSubview: o_label];
1206 /* build the button */
1207 ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_itemTooltip,
1209 [o_button setAutoresizingMask:NSViewMinXMargin ];
1210 [self addSubview: o_button];
1212 /* build the textfield */
1213 if( p_item->value.psz )
1214 o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
1216 o_textfieldString = [NSString stringWithString: @""];
1217 ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1218 8 - [o_button frame].size.width,
1219 o_itemTooltip, o_textfieldString )
1220 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1221 [self addSubview: o_textfield];
1226 - (void) alignWithXPosition:(int)i_xPos
1233 [o_textfield release];
1238 - (IBAction)openFileDialog: (id)sender
1240 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1242 [o_open_panel setTitle: (b_directory)?
1243 _NS("Select a directory"):_NS("Select a file")];
1244 [o_open_panel setPrompt: _NS("Select")];
1245 [o_open_panel setAllowsMultipleSelection: NO];
1246 [o_open_panel setCanChooseFiles: !b_directory];
1247 [o_open_panel setCanChooseDirectories: b_directory];
1248 [o_open_panel beginSheetForDirectory:nil
1251 modalForWindow:[sender window]
1253 didEndSelector: @selector(pathChosenInPanel:
1259 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1260 withReturn:(int)i_return_code contextInfo:(void *)o_context_info
1262 if( i_return_code == NSOKButton )
1264 NSString *o_path = [[[o_sheet URLs] objectAtIndex: 0] path];
1265 [o_textfield setStringValue: o_path];
1269 - (char *)stringValue
1271 if( [[o_textfield stringValue] length] != 0)
1272 return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1279 NSString *o_textfieldString;
1280 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1282 o_textfieldString = [NSString stringWithFormat: @"%s", psz_value];
1284 o_textfieldString = [NSString stringWithString: @""];
1287 [super resetValues];
1291 @implementation ModuleConfigControl
1292 - (id) initWithItem: (module_config_t *)_p_item
1293 withView: (NSView *)o_parent_view
1295 NSRect mainFrame = [o_parent_view frame];
1296 NSString *o_labelString, *o_popupTooltip;
1297 mainFrame.size.height = 22;
1298 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1299 mainFrame.origin.x = LEFTMARGIN;
1300 mainFrame.origin.y = 0;
1302 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1304 i_view_type = CONFIG_ITEM_MODULE;
1306 o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1307 [[VLCMain sharedInstance]
1308 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1311 if( p_item->psz_text )
1312 o_labelString = [[VLCMain sharedInstance]
1313 localizedString: (char *)p_item->psz_text];
1315 o_labelString = [NSString stringWithString:@""];
1317 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_popupTooltip )
1318 [o_label setAutoresizingMask:NSViewNotSizable ];
1319 [self addSubview: o_label];
1321 /* build the popup */
1322 ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1323 -2, 0, o_popupTooltip )
1324 [o_popup setAutoresizingMask:NSViewWidthSizable ];
1325 [o_popup addItemWithTitle: _NS("Default")];
1326 [[o_popup lastItem] setTag: -1];
1327 [o_popup selectItem: [o_popup lastItem]];
1330 [self addSubview: o_popup];
1335 - (void) alignWithXPosition:(int)i_xPos
1338 NSRect superFrame = [self frame];
1339 frame = [o_label frame];
1340 frame.origin.x = i_xPos - frame.size.width - 3;
1341 [o_label setFrame:frame];
1343 frame = [o_popup frame];
1344 frame.origin.x = i_xPos - 1;
1345 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1346 [o_popup setFrame:frame];
1355 - (char *)stringValue
1357 NSString *newval = [o_popup titleOfSelectedItem];
1358 char *returnval = NULL;
1359 size_t i_module_index;
1360 module_t *p_parser, **p_list;
1362 p_list = module_list_get( NULL );
1363 for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
1365 p_parser = p_list[i_module_index];
1367 if( p_item->i_type == CONFIG_ITEM_MODULE )
1369 if( module_provides( p_parser, p_item->psz_type ) )
1371 NSString *o_description = [[VLCMain sharedInstance]
1372 localizedString: module_get_name( p_parser, TRUE )];
1373 if( [newval isEqualToString: o_description] )
1375 returnval = strdup( module_get_object( p_parser ));
1382 if( module_is_main( p_parser) )
1385 unsigned int confsize;
1386 module_config_t *p_config = module_config_get( p_parser, &confsize );
1387 for ( size_t i = 0; i < confsize; i++ )
1389 module_config_t *p_cfg = p_config + i;
1390 /* Hack: required subcategory is stored in i_min */
1391 if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
1392 p_cfg->value.i == p_cfg->min.i )
1394 NSString *o_description = [[VLCMain sharedInstance]
1395 localizedString: module_get_name( p_parser, TRUE )];
1396 if( [newval isEqualToString: o_description] )
1398 returnval = strdup(module_get_object( p_parser ));
1403 module_config_free( p_config );
1406 module_list_free( p_list );
1412 /* build a list of available modules */
1414 module_t *p_parser, **p_list;
1416 p_list = module_list_get( NULL );
1417 for( i_index = 0; p_list[i_index]; i_index++ )
1419 p_parser = p_list[i_index];
1421 if( p_item->i_type == CONFIG_ITEM_MODULE )
1423 if( module_provides( p_parser, p_item->psz_type ) )
1425 NSString *o_description = [[VLCMain sharedInstance]
1426 localizedString: module_get_name( p_parser, TRUE )];
1427 [o_popup addItemWithTitle: o_description];
1428 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1431 !strcmp( psz_value, module_get_object( p_parser ) ) )
1432 [o_popup selectItem:[o_popup lastItem]];
1439 if( module_is_main( p_parser ) )
1441 unsigned int confsize;
1443 module_config_t *p_configlist = module_config_get( p_parser, &confsize );
1444 for ( size_t i = 0; i < confsize; i++ )
1446 module_config_t *p_config = &p_configlist[i];
1447 /* Hack: required subcategory is stored in i_min */
1448 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1449 p_config->value.i == p_item->min.i )
1451 NSString *o_description = [[VLCMain sharedInstance]
1452 localizedString: module_get_name( p_parser, TRUE )];
1453 [o_popup addItemWithTitle: o_description];
1455 if( p_item->value.psz && !strcmp(p_item->value.psz,
1456 module_get_object( p_parser )) )
1457 [o_popup selectItem:[o_popup lastItem]];
1460 module_config_free( p_configlist );
1463 module_list_free( p_list );
1464 [super resetValues];
1468 @implementation IntegerConfigControl
1469 - (id) initWithItem: (module_config_t *)_p_item
1470 withView: (NSView *)o_parent_view
1472 NSRect mainFrame = [o_parent_view frame];
1473 NSString *o_labelString, *o_tooltip;
1474 mainFrame.size.height = 23;
1475 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1476 mainFrame.origin.x = LEFTMARGIN;
1477 mainFrame.origin.y = 0;
1479 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1481 i_view_type = CONFIG_ITEM_INTEGER;
1483 o_tooltip = [[VLCMain sharedInstance] wrapString:
1484 [[VLCMain sharedInstance]
1485 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1488 if( p_item->psz_text )
1489 o_labelString = [[VLCMain sharedInstance]
1490 localizedString: (char *)p_item->psz_text];
1492 o_labelString = [NSString stringWithString:@""];
1493 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1494 [o_label setAutoresizingMask:NSViewNotSizable ];
1495 [self addSubview: o_label];
1497 /* build the stepper */
1498 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1499 0, o_tooltip, -100000, 100000)
1500 [o_stepper setIntValue: p_item->value.i];
1501 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1502 [self addSubview: o_stepper];
1504 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1505 1, 49, o_tooltip, @"" )
1506 [o_textfield setIntValue: p_item->value.i];
1507 [o_textfield setDelegate: self];
1508 [[NSNotificationCenter defaultCenter] addObserver: self
1509 selector: @selector(textfieldChanged:)
1510 name: NSControlTextDidChangeNotification
1511 object: o_textfield];
1512 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1513 [self addSubview: o_textfield];
1518 - (void) alignWithXPosition:(int)i_xPos
1521 frame = [o_label frame];
1522 frame.origin.x = i_xPos - frame.size.width - 3;
1523 [o_label setFrame:frame];
1525 frame = [o_textfield frame];
1526 frame.origin.x = i_xPos + 2;
1527 [o_textfield setFrame:frame];
1529 frame = [o_stepper frame];
1530 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1531 [o_stepper setFrame:frame];
1536 [o_stepper release];
1537 [o_textfield release];
1541 - (IBAction)stepperChanged:(id)sender
1543 [o_textfield setIntValue: [o_stepper intValue]];
1546 - (void)textfieldChanged:(NSNotification *)o_notification
1548 [o_stepper setIntValue: [o_textfield intValue]];
1553 return [o_textfield intValue];
1558 [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)];
1559 [super resetValues];
1564 @implementation IntegerListConfigControl
1566 - (id) initWithItem: (module_config_t *)_p_item
1567 withView: (NSView *)o_parent_view
1569 NSRect mainFrame = [o_parent_view frame];
1570 NSString *o_labelString, *o_textfieldTooltip;
1571 mainFrame.size.height = 22;
1572 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1573 mainFrame.origin.x = LEFTMARGIN;
1574 mainFrame.origin.y = 0;
1576 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1579 i_view_type = CONFIG_ITEM_STRING_LIST;
1581 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1582 [[VLCMain sharedInstance]
1583 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1586 if( p_item->psz_text )
1587 o_labelString = [[VLCMain sharedInstance]
1588 localizedString: (char *)p_item->psz_text];
1590 o_labelString = [NSString stringWithString:@""];
1591 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1592 [o_label setAutoresizingMask:NSViewNotSizable ];
1593 [self addSubview: o_label];
1595 /* build the textfield */
1596 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1597 -2, 0, o_textfieldTooltip )
1598 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1599 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1601 if( p_item->value.i == p_item->pi_list[i_index] )
1603 [o_combo selectItemAtIndex: i_index];
1606 [self addSubview: o_combo];
1611 - (void) alignWithXPosition:(int)i_xPos
1614 NSRect superFrame = [self frame];
1615 frame = [o_label frame];
1616 frame.origin.x = i_xPos - frame.size.width - 3;
1617 [o_label setFrame:frame];
1619 frame = [o_combo frame];
1620 frame.origin.x = i_xPos + 2;
1621 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1622 [o_combo setFrame:frame];
1633 if( [o_combo indexOfSelectedItem] >= 0 )
1634 return p_item->pi_list[[o_combo indexOfSelectedItem]];
1636 return [o_combo intValue];
1642 [o_combo reloadData];
1643 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1645 if( config_GetInt( VLCIntf, p_item->psz_name) == p_item->pi_list[i_index] )
1647 [o_combo selectItemAtIndex: i_index];
1654 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1655 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1657 return p_item->i_list;
1660 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1662 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1663 return [[VLCMain sharedInstance]
1664 localizedString: (char *)p_item->ppsz_list_text[i_index]];
1666 return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1670 @implementation RangedIntegerConfigControl
1671 - (id) initWithItem: (module_config_t *)_p_item
1672 withView: (NSView *)o_parent_view
1674 NSRect mainFrame = [o_parent_view frame];
1675 NSString *o_labelString, *o_tooltip;
1676 mainFrame.size.height = 50;
1677 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1678 mainFrame.origin.x = LEFTMARGIN;
1679 mainFrame.origin.y = 0;
1681 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1683 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1685 o_tooltip = [[VLCMain sharedInstance] wrapString:
1686 [[VLCMain sharedInstance]
1687 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1690 if( p_item->psz_text )
1691 o_labelString = [[VLCMain sharedInstance]
1692 localizedString: (char *)p_item->psz_text];
1694 o_labelString = [NSString stringWithString:@""];
1695 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1696 [o_label setAutoresizingMask:NSViewNotSizable ];
1697 [self addSubview: o_label];
1699 /* build the textfield */
1700 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1701 28, 49, o_tooltip, @"" )
1702 [o_textfield setIntValue: p_item->value.i];
1703 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1704 [o_textfield setDelegate: self];
1705 [[NSNotificationCenter defaultCenter] addObserver: self
1706 selector: @selector(textfieldChanged:)
1707 name: NSControlTextDidChangeNotification
1708 object: o_textfield];
1709 [self addSubview: o_textfield];
1711 /* build the mintextfield */
1712 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1713 [o_textfield_min setIntValue: p_item->min.i];
1714 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1715 [o_textfield_min setAlignment:NSRightTextAlignment];
1716 [self addSubview: o_textfield_min];
1718 /* build the maxtextfield */
1719 ADD_LABEL( o_textfield_max, mainFrame,
1720 mainFrame.size.width - 31, -30, @"8888", @"" )
1721 [o_textfield_max setIntValue: p_item->max.i];
1722 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1723 [self addSubview: o_textfield_max];
1725 /* build the slider */
1726 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1727 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1728 [o_textfield_max frame].size.width -
1729 [o_textfield_max frame].size.width - 14 -
1730 [o_textfield_min frame].origin.x, o_tooltip,
1731 p_item->min.i, p_item->max.i )
1732 [o_slider setIntValue: p_item->value.i];
1733 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1734 [o_slider setTarget: self];
1735 [o_slider setAction: @selector(sliderChanged:)];
1736 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1737 NSLeftMouseDraggedMask];
1738 [self addSubview: o_slider];
1744 - (void) alignWithXPosition:(int)i_xPos
1747 frame = [o_label frame];
1748 frame.origin.x = i_xPos - frame.size.width - 3;
1749 [o_label setFrame:frame];
1751 frame = [o_textfield frame];
1752 frame.origin.x = i_xPos + 2;
1753 [o_textfield setFrame:frame];
1758 [o_textfield release];
1759 [o_textfield_min release];
1760 [o_textfield_max release];
1765 - (IBAction)sliderChanged:(id)sender
1767 [o_textfield setIntValue: [o_slider intValue]];
1770 - (void)textfieldChanged:(NSNotification *)o_notification
1772 [o_slider setIntValue: [o_textfield intValue]];
1777 return [o_slider intValue];
1782 int value = config_GetInt( VLCIntf, p_item->psz_name );
1783 [o_textfield setIntValue:value];
1784 [o_slider setIntValue:value];
1785 [super resetValues];
1789 @implementation FloatConfigControl
1790 - (id) initWithItem: (module_config_t *)_p_item
1791 withView: (NSView *)o_parent_view
1793 NSRect mainFrame = [o_parent_view frame];
1794 NSString *o_labelString, *o_tooltip;
1795 mainFrame.size.height = 23;
1796 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1797 mainFrame.origin.x = LEFTMARGIN;
1798 mainFrame.origin.y = 0;
1800 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1802 i_view_type = CONFIG_ITEM_INTEGER;
1804 o_tooltip = [[VLCMain sharedInstance] wrapString:
1805 [[VLCMain sharedInstance]
1806 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1809 if( p_item->psz_text )
1810 o_labelString = [[VLCMain sharedInstance]
1811 localizedString: (char *)p_item->psz_text];
1813 o_labelString = [NSString stringWithString:@""];
1814 ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString, o_tooltip )
1815 [o_label setAutoresizingMask:NSViewNotSizable ];
1816 [self addSubview: o_label];
1818 /* build the stepper */
1819 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1820 0, o_tooltip, -100000, 100000)
1821 [o_stepper setFloatValue: p_item->value.f];
1822 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1823 [self addSubview: o_stepper];
1825 /* build the textfield */
1826 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1827 1, 49, o_tooltip, @"" )
1828 [o_textfield setFloatValue: p_item->value.f];
1829 [o_textfield setDelegate: self];
1830 [[NSNotificationCenter defaultCenter] addObserver: self
1831 selector: @selector(textfieldChanged:)
1832 name: NSControlTextDidChangeNotification
1833 object: o_textfield];
1834 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1835 [self addSubview: o_textfield];
1840 - (void) alignWithXPosition:(int)i_xPos
1843 frame = [o_label frame];
1844 frame.origin.x = i_xPos - frame.size.width - 3;
1845 [o_label setFrame:frame];
1847 frame = [o_textfield frame];
1848 frame.origin.x = i_xPos + 2;
1849 [o_textfield setFrame:frame];
1851 frame = [o_stepper frame];
1852 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1853 [o_stepper setFrame:frame];
1858 [o_stepper release];
1859 [o_textfield release];
1863 - (IBAction)stepperChanged:(id)sender
1865 [o_textfield setFloatValue: [o_stepper floatValue]];
1868 - (void)textfieldChanged:(NSNotification *)o_notification
1870 [o_stepper setFloatValue: [o_textfield floatValue]];
1875 return [o_stepper floatValue];
1880 [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)];
1881 [super resetValues];
1885 @implementation RangedFloatConfigControl
1886 - (id) initWithItem: (module_config_t *)_p_item
1887 withView: (NSView *)o_parent_view
1889 NSRect mainFrame = [o_parent_view frame];
1890 NSString *o_labelString, *o_tooltip;
1891 mainFrame.size.height = 50;
1892 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1893 mainFrame.origin.x = LEFTMARGIN;
1894 mainFrame.origin.y = 0;
1896 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1898 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1900 o_tooltip = [[VLCMain sharedInstance] wrapString:
1901 [[VLCMain sharedInstance]
1902 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1905 if( p_item->psz_text )
1906 o_labelString = [[VLCMain sharedInstance]
1907 localizedString: (char *)p_item->psz_text];
1909 o_labelString = [NSString stringWithString:@""];
1910 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1911 [o_label setAutoresizingMask:NSViewNotSizable ];
1912 [self addSubview: o_label];
1914 /* build the textfield */
1915 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1916 28, 49, o_tooltip, @"" )
1917 [o_textfield setFloatValue: p_item->value.f];
1918 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1919 [o_textfield setDelegate: self];
1920 [[NSNotificationCenter defaultCenter] addObserver: self
1921 selector: @selector(textfieldChanged:)
1922 name: NSControlTextDidChangeNotification
1923 object: o_textfield];
1924 [self addSubview: o_textfield];
1926 /* build the mintextfield */
1927 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1928 [o_textfield_min setFloatValue: p_item->min.f];
1929 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1930 [o_textfield_min setAlignment:NSRightTextAlignment];
1931 [self addSubview: o_textfield_min];
1933 /* build the maxtextfield */
1934 ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1936 [o_textfield_max setFloatValue: p_item->max.f];
1937 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1938 [self addSubview: o_textfield_max];
1940 /* build the slider */
1941 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1942 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1943 [o_textfield_max frame].size.width -
1944 [o_textfield_max frame].size.width - 14 -
1945 [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
1947 [o_slider setFloatValue: p_item->value.f];
1948 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1949 [o_slider setTarget: self];
1950 [o_slider setAction: @selector(sliderChanged:)];
1951 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1952 NSLeftMouseDraggedMask];
1953 [self addSubview: o_slider];
1959 - (void) alignWithXPosition:(int)i_xPos
1962 frame = [o_label frame];
1963 frame.origin.x = i_xPos - frame.size.width - 3;
1964 [o_label setFrame:frame];
1966 frame = [o_textfield frame];
1967 frame.origin.x = i_xPos + 2;
1968 [o_textfield setFrame:frame];
1973 [o_textfield release];
1974 [o_textfield_min release];
1975 [o_textfield_max release];
1980 - (IBAction)sliderChanged:(id)sender
1982 [o_textfield setFloatValue: [o_slider floatValue]];
1985 - (void)textfieldChanged:(NSNotification *)o_notification
1987 [o_slider setFloatValue: [o_textfield floatValue]];
1992 return [o_slider floatValue];
1997 [o_textfield setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
1998 [o_slider setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
1999 [super resetValues];
2003 @implementation BoolConfigControl
2005 - (id) initWithItem: (module_config_t *)_p_item
2006 withView: (NSView *)o_parent_view
2008 NSRect mainFrame = [o_parent_view frame];
2009 NSString *o_labelString, *o_tooltip;
2010 mainFrame.size.height = 17;
2011 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2012 mainFrame.origin.x = LEFTMARGIN;
2013 mainFrame.origin.y = 0;
2015 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2017 i_view_type = CONFIG_ITEM_BOOL;
2019 /* add the checkbox */
2020 o_tooltip = [[VLCMain sharedInstance]
2021 wrapString: [[VLCMain sharedInstance]
2022 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2023 ADD_CHECKBOX( o_checkbox, mainFrame, 0,
2024 0, @"", o_tooltip, p_item->value.i, NSImageLeft)
2025 [o_checkbox setAutoresizingMask:NSViewNotSizable ];
2026 [self addSubview: o_checkbox];
2028 if( p_item->psz_text )
2029 o_labelString = [[VLCMain sharedInstance]
2030 localizedString: (char *)p_item->psz_text];
2032 o_labelString = [NSString stringWithString:@""];
2033 ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString, o_tooltip )
2034 [o_label setAutoresizingMask:NSViewNotSizable ];
2035 [self addSubview: o_label];
2042 [o_checkbox release];
2048 return [o_checkbox intValue];
2053 [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)];
2054 [super resetValues];
2058 @implementation KeyConfigControl
2059 - (id) initWithItem: (module_config_t *)_p_item
2060 withView: (NSView *)o_parent_view
2062 NSRect mainFrame = [o_parent_view frame];
2063 NSString *o_labelString, *o_tooltip;
2064 mainFrame.size.height = 22;
2065 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
2066 mainFrame.origin.x = LEFTMARGIN;
2067 mainFrame.origin.y = 0;
2069 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2071 i_view_type = CONFIG_ITEM_KEY;
2073 o_tooltip = [[VLCMain sharedInstance] wrapString:
2074 [[VLCMain sharedInstance]
2075 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2078 if( p_item->psz_text )
2079 o_labelString = [[VLCMain sharedInstance]
2080 localizedString: (char *)p_item->psz_text];
2082 o_labelString = [NSString stringWithString:@""];
2083 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_tooltip )
2084 [o_label setAutoresizingMask:NSViewNotSizable ];
2085 [self addSubview: o_label];
2087 /* build the popup */
2088 ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2089 [o_label frame].size.width + 3,
2091 [o_popup setAutoresizingMask:NSViewWidthSizable ];
2093 if( o_keys_menu == nil )
2096 o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2097 #warning This does not work anymore. FIXME.
2099 for ( i = 0; i < sizeof(vlc_key) / sizeof(key_descriptor_t); i++)
2100 if( vlc_key[i].psz_key_string )
2101 POPULATE_A_KEY( o_keys_menu,
2102 [NSString stringWithUTF8String:vlc_key[i].psz_key_string]
2103 , vlc_key[i].i_key_code)
2106 [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2107 [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
2108 [self addSubview: o_popup];
2114 - (void) alignWithXPosition:(int)i_xPos
2117 NSRect superFrame = [self frame];
2118 frame = [o_label frame];
2119 frame.origin.x = i_xPos - frame.size.width - 3;
2120 [o_label setFrame:frame];
2122 frame = [o_popup frame];
2123 frame.origin.x = i_xPos - 1;
2124 frame.size.width = superFrame.size.width - frame.origin.x + 2;
2125 [o_popup setFrame:frame];
2136 return [o_popup selectedTag];
2141 [o_popup selectItem:[[o_popup menu] itemWithTag:config_GetInt( VLCIntf, p_item->psz_name )]];
2142 [super resetValues];
2146 @implementation ModuleListConfigControl
2147 - (id) initWithItem: (module_config_t *)_p_item
2148 withView: (NSView *)o_parent_view
2150 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2154 //Fill our array to know how may items we have...
2155 module_t *p_parser, **p_list;
2156 size_t i_module_index;
2157 NSRect mainFrame = [o_parent_view frame];
2158 NSString *o_labelString, *o_textfieldString, *o_tooltip;
2160 o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2161 /* build a list of available modules */
2162 p_list = module_list_get( NULL );
2163 for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
2166 p_parser = p_list[i_module_index];
2168 if( module_is_main( p_parser ) )
2171 unsigned int confsize;
2172 module_config_t *p_configlist = module_config_get( p_parser, &confsize );
2174 for ( i = 0; i < confsize; i++ )
2176 unsigned int unused;
2177 module_config_t *p_config = &p_configlist[i];
2178 NSString *o_modulelongname, *o_modulename;
2179 NSNumber *o_moduleenabled = nil;
2181 /* Hack: required subcategory is stored in i_min */
2182 if( p_config->i_type == CONFIG_SUBCATEGORY &&
2183 p_config->value.i == _p_item->min.i )
2185 o_modulelongname = [NSString stringWithUTF8String:
2186 module_get_name( p_parser, TRUE )];
2187 o_modulename = [NSString stringWithUTF8String:
2188 module_get_object( p_parser )];
2190 if( _p_item->value.psz &&
2191 strstr( _p_item->value.psz, module_get_object( p_parser ) ) )
2192 o_moduleenabled = [NSNumber numberWithBool:YES];
2194 o_moduleenabled = [NSNumber numberWithBool:NO];
2196 [o_modulearray addObject:[NSMutableArray
2197 arrayWithObjects: o_modulename, o_modulelongname,
2198 o_moduleenabled, nil]];
2201 module_config_free( p_configlist );
2203 module_list_free( p_list );
2205 mainFrame.size.height = 30 + 20 * [o_modulearray count];
2206 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2207 mainFrame.origin.x = LEFTMARGIN;
2208 mainFrame.origin.y = 0;
2209 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2211 i_view_type = CONFIG_ITEM_MODULE_LIST;
2213 o_tooltip = [[VLCMain sharedInstance] wrapString:
2214 [[VLCMain sharedInstance]
2215 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2218 if( p_item->psz_text )
2219 o_labelString = [[VLCMain sharedInstance]
2220 localizedString: (char *)p_item->psz_text];
2222 o_labelString = [NSString stringWithString:@""];
2223 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
2224 [o_label setAutoresizingMask:NSViewNotSizable ];
2225 [self addSubview: o_label];
2227 /* build the textfield */
2228 if( p_item->value.psz )
2229 o_textfieldString = [[VLCMain sharedInstance]
2230 localizedString: (char *)p_item->value.psz];
2232 o_textfieldString = [NSString stringWithString: @""];
2233 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2234 mainFrame.size.height - 22, mainFrame.size.width -
2235 [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2236 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2237 [self addSubview: o_textfield];
2241 NSRect s_rc = mainFrame;
2242 s_rc.size.height = mainFrame.size.height - 30;
2243 s_rc.size.width = mainFrame.size.width - 12;
2246 o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2247 [o_scrollview setDrawsBackground: NO];
2248 [o_scrollview setBorderType: NSBezelBorder];
2249 [o_scrollview setAutohidesScrollers:YES];
2251 NSTableView *o_tableview;
2252 o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2253 [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2254 [o_tableview setHeaderView:nil];
2255 /* TODO: find a good way to fix the row height and text size*/
2256 /* FIXME: support for multiple selection... */
2257 // [o_tableview setAllowsMultipleSelection:YES];
2259 NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2260 NSCell *o_dataCell = [[NSButtonCell alloc] init];
2261 [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2262 [o_dataCell setTitle:@""];
2263 [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2264 NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2265 initWithIdentifier:@"Enabled"];
2266 [o_tableColumn setHeaderCell: o_headerCell];
2267 [o_tableColumn setDataCell: o_dataCell];
2268 [o_tableColumn setWidth:17];
2269 [o_tableview addTableColumn: o_tableColumn];
2271 o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2272 o_dataCell = [[NSTextFieldCell alloc] init];
2273 [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2274 o_tableColumn = [[NSTableColumn alloc]
2275 initWithIdentifier:@"Module"];
2276 [o_tableColumn setHeaderCell: o_headerCell];
2277 [o_tableColumn setDataCell: o_dataCell];
2278 [o_tableColumn setWidth:s_rc.size.width - 34];
2279 [o_tableview addTableColumn: o_tableColumn];
2280 [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2281 @"VLC media player module", nil]];
2283 [o_tableview setDataSource:self];
2284 [o_tableview setTarget: self];
2285 [o_tableview setAction: @selector(tableChanged:)];
2286 [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2287 NSLeftMouseDraggedMask];
2288 [o_scrollview setDocumentView: o_tableview];
2290 [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2291 [o_scrollview setAutohidesScrollers:YES];
2292 [self addSubview: o_scrollview];
2298 - (void) alignWithXPosition:(int)i_xPos
2303 - (IBAction)tableChanged:(id)sender
2305 NSString *o_newstring = @"";
2306 NSUInteger count = [o_modulearray count];
2307 for( NSUInteger i = 0 ; i < count ; i++ )
2308 if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2311 o_newstring = [o_newstring stringByAppendingString:
2312 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2313 o_newstring = [o_newstring stringByAppendingString:@":"];
2316 [o_textfield setStringValue: [o_newstring
2317 substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2322 [o_scrollview release];
2327 - (char *)stringValue
2329 return strdup( [[o_textfield stringValue] UTF8String] );
2334 #warning Reset prefs of the module selector is broken atm.
2335 NSLog( @"don't forget about modulelistconfig" );
2336 [super resetValues];
2341 @implementation ModuleListConfigControl (NSTableDataSource)
2343 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2344 toPasteboard:(NSPasteboard*)pb
2346 // We only want to allow dragging of selected rows.
2347 NSEnumerator *iter = [rows objectEnumerator];
2349 while ((row = [iter nextObject]) != nil)
2351 if (![table isRowSelected:[row intValue]])
2355 [pb declareTypes:[NSArray
2356 arrayWithObject:@"VLC media player module"] owner:nil];
2357 [pb setPropertyList:rows forType:@"VLC media player module"];
2361 - (NSDragOperation)tableView:(NSTableView*)table
2362 validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
2363 proposedDropOperation:(NSTableViewDropOperation)op
2365 // Make drops at the end of the table go to the end.
2368 row = [table numberOfRows];
2369 op = NSTableViewDropAbove;
2370 [table setDropRow:row dropOperation:op];
2373 // We don't ever want to drop onto a row, only between rows.
2374 if (op == NSTableViewDropOn)
2375 [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2376 return NSTableViewDropAbove;
2379 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2380 row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
2382 NSPasteboard *pb = [info draggingPasteboard];
2383 NSDragOperation srcMask = [info draggingSourceOperationMask];
2390 // Intra-table drag - data is the array of rows.
2391 if (!accepted && (array =
2392 [pb propertyListForType:@"VLC media player module"]) != NULL)
2394 NSEnumerator *iter = nil;
2396 BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2398 iter = [array objectEnumerator];
2399 while ((val = [iter nextObject]) != NULL)
2401 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2402 [val intValue]] mutableCopyWithZone:nil];
2403 [o_modulearray removeObject:o_tmp];
2404 [o_modulearray insertObject:o_tmp
2405 atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2409 // Select the newly-dragged items.
2410 iter = [array objectEnumerator];
2412 [table deselectAll:self];
2414 [self tableChanged:self];
2415 [table setNeedsDisplay:YES];
2416 // Indicate that we finished the drag.
2420 [table setNeedsDisplay:YES];
2424 // An exception occurred. Uh-oh. Update the track table so that
2425 // it stays consistent, and re-raise the exception.
2427 [localException raise];
2428 [table setNeedsDisplay:YES];
2434 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
2436 return [o_modulearray count];
2439 - (id)tableView:(NSTableView *)aTableView
2440 objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2442 if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
2443 return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2444 if( [[aTableColumn identifier] isEqualToString: @"Module"] )
2445 return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2450 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2451 forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2453 [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2454 withObject: anObject];