1 /*****************************************************************************
2 * prefs_widgets.m: Preferences controls
3 *****************************************************************************
4 * Copyright (C) 2002-2011 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 <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_AFTER_10_3:
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_AFTER_10_3:
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_AFTER_10_3:
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_AFTER_10_3:
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_AFTER_10_3:
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_AFTER_10_3:
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_AFTER_10_3:
698 case CONFIG_ITEM_MODULE_LIST:
706 case CONFIG_ITEM_KEY_AFTER_10_3:
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_AFTER_10_3:
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_AFTER_10_3:
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 )
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.f != 0 || _p_item->max.f != 0 )
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 case CONFIG_ITEM_KEY:
862 p_control = [[KeyConfigControl alloc]
863 initWithItem: _p_item
864 withView: o_parent_view];
866 case CONFIG_ITEM_MODULE_LIST:
867 case CONFIG_ITEM_MODULE_LIST_CAT:
868 p_control = [[ModuleListConfigControl alloc]
869 initWithItem: _p_item
870 withView: o_parent_view];
880 return [[VLCMain sharedInstance] localizedString: psz_name];
908 - (char *)stringValue
916 switch( p_item->i_type )
918 case CONFIG_ITEM_STRING:
919 case CONFIG_ITEM_PASSWORD:
920 case CONFIG_ITEM_LOADFILE:
921 case CONFIG_ITEM_SAVEFILE:
922 case CONFIG_ITEM_DIRECTORY:
923 case CONFIG_ITEM_MODULE:
924 case CONFIG_ITEM_MODULE_LIST:
925 case CONFIG_ITEM_MODULE_LIST_CAT:
926 config_PutPsz( VLCIntf, psz_name, [self stringValue] );
928 case CONFIG_ITEM_KEY:
929 /* So you don't need to restart to have the changes take effect */
930 val.i_int = [self intValue];
931 var_Set( VLCIntf->p_libvlc, psz_name, val );
932 case CONFIG_ITEM_INTEGER:
933 case CONFIG_ITEM_BOOL:
934 config_PutInt( VLCIntf, psz_name, [self intValue] );
936 case CONFIG_ITEM_FLOAT:
937 config_PutFloat( VLCIntf, psz_name, [self floatValue] );
948 return [o_label frame].size.width;
951 - (void) alignWithXPosition:(int)i_xPos;
953 /* FIXME: not implemented atm, but created to shut up the warning
954 * about "method definition not found" -- FK @ 7/24/05 */
958 @implementation StringConfigControl
959 - (id) initWithItem: (module_config_t *)_p_item
960 withView: (NSView *)o_parent_view
962 NSRect mainFrame = [o_parent_view frame];
963 NSString *o_labelString, *o_textfieldString, *o_textfieldTooltip;
964 mainFrame.size.height = 22;
965 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
966 mainFrame.origin.x = LEFTMARGIN;
967 mainFrame.origin.y = 0;
969 if( [super initWithFrame: mainFrame item: _p_item] != nil )
971 if( p_item->i_type == CONFIG_ITEM_PASSWORD )
972 i_view_type = CONFIG_ITEM_PASSWORD;
974 i_view_type = CONFIG_ITEM_STRING;
976 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
977 [[VLCMain sharedInstance] localizedString: (char *)p_item->psz_longtext]
978 toWidth: PREFS_WRAP];
981 if( p_item->psz_text )
982 o_labelString = [[VLCMain sharedInstance]
983 localizedString: (char *)p_item->psz_text];
985 o_labelString = [NSString stringWithString:@""];
986 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
987 [o_label setAutoresizingMask:NSViewNotSizable ];
988 [self addSubview: o_label];
990 /* build the textfield */
991 if( p_item->value.psz )
992 o_textfieldString = [[VLCMain sharedInstance]
993 localizedString: (char *)p_item->value.psz];
995 o_textfieldString = [NSString stringWithString: @""];
996 if( p_item->i_type == CONFIG_ITEM_PASSWORD )
998 ADD_SECURETEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
999 0, mainFrame.size.width - [o_label frame].size.width -
1000 2, o_textfieldTooltip, o_textfieldString )
1004 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1005 0, mainFrame.size.width - [o_label frame].size.width -
1006 2, o_textfieldTooltip, o_textfieldString )
1008 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1010 [self addSubview: o_textfield];
1015 - (void) alignWithXPosition:(int)i_xPos
1018 NSRect superFrame = [self frame];
1019 frame = [o_label frame];
1020 frame.origin.x = i_xPos - frame.size.width - 3;
1021 [o_label setFrame:frame];
1023 frame = [o_textfield frame];
1024 frame.origin.x = i_xPos + 2;
1025 frame.size.width = superFrame.size.width - frame.origin.x - 1;
1026 [o_textfield setFrame:frame];
1031 [o_textfield release];
1035 - (char *)stringValue
1037 return [[VLCMain sharedInstance] delocalizeString:
1038 [o_textfield stringValue]];
1043 NSString *o_textfieldString;
1044 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1046 o_textfieldString = [[VLCMain sharedInstance]
1047 localizedString: psz_value];
1049 o_textfieldString = [NSString stringWithString: @""];
1051 [super resetValues];
1055 @implementation StringListConfigControl
1056 - (id) initWithItem: (module_config_t *)_p_item
1057 withView: (NSView *)o_parent_view
1059 NSRect mainFrame = [o_parent_view frame];
1060 NSString *o_labelString, *o_textfieldTooltip;
1061 mainFrame.size.height = 22;
1062 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1063 mainFrame.origin.x = LEFTMARGIN;
1064 mainFrame.origin.y = 0;
1066 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1069 i_view_type = CONFIG_ITEM_STRING_LIST;
1071 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1072 [[VLCMain sharedInstance]
1073 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1076 if( p_item->psz_text )
1077 o_labelString = [[VLCMain sharedInstance]
1078 localizedString: (char *)p_item->psz_text];
1080 o_labelString = [NSString stringWithString:@""];
1081 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1082 [o_label setAutoresizingMask:NSViewNotSizable ];
1083 [self addSubview: o_label];
1085 /* build the textfield */
1086 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1087 -2, 0, o_textfieldTooltip )
1088 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1089 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1091 if( !p_item->value.psz && !p_item->ppsz_list[i_index] )
1092 [o_combo selectItemAtIndex: i_index];
1093 else if( p_item->value.psz && p_item->ppsz_list[i_index] &&
1094 !strcmp( p_item->value.psz, p_item->ppsz_list[i_index] ) )
1095 [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]] );
1134 [o_combo reloadData];
1135 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1137 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1139 if( !psz_value && !p_item->ppsz_list[i_index] )
1140 [o_combo selectItemAtIndex: i_index];
1141 else if( psz_value && p_item->ppsz_list[i_index] &&
1142 !strcmp( psz_value, p_item->ppsz_list[i_index] ) )
1143 [o_combo selectItemAtIndex: i_index];
1147 [super resetValues];
1151 @implementation StringListConfigControl (NSComboBoxDataSource)
1152 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1154 return p_item->i_list;
1157 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1159 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1161 return [[VLCMain sharedInstance]
1162 localizedString: (char *)p_item->ppsz_list_text[i_index]];
1163 } else return [[VLCMain sharedInstance]
1164 localizedString: (char *)p_item->ppsz_list[i_index]];
1168 @implementation FileConfigControl
1169 - (id) initWithItem: (module_config_t *)_p_item
1170 withView: (NSView *)o_parent_view
1172 NSRect mainFrame = [o_parent_view frame];
1173 NSString *o_labelString, *o_itemTooltip, *o_textfieldString;
1174 mainFrame.size.height = 46;
1175 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1176 mainFrame.origin.x = LEFTMARGIN;
1177 mainFrame.origin.y = 0;
1179 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1181 i_view_type = CONFIG_ITEM_LOADFILE;
1183 o_itemTooltip = [[VLCMain sharedInstance]
1184 wrapString: [[VLCMain sharedInstance]
1185 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1187 /* is it a directory */
1188 b_directory = ( [self type] == CONFIG_ITEM_DIRECTORY ) ? YES : NO;
1191 if( p_item->psz_text )
1192 o_labelString = [[VLCMain sharedInstance]
1193 localizedString: (char *)p_item->psz_text];
1195 o_labelString = [NSString stringWithString:@""];
1196 ADD_LABEL( o_label, mainFrame, 0, 3, o_labelString, o_itemTooltip )
1197 [o_label setAutoresizingMask:NSViewNotSizable ];
1198 [self addSubview: o_label];
1200 /* build the button */
1201 ADD_RIGHT_BUTTON( o_button, mainFrame, 0, 0, o_itemTooltip,
1203 [o_button setAutoresizingMask:NSViewMinXMargin ];
1204 [self addSubview: o_button];
1206 /* build the textfield */
1207 if( p_item->value.psz )
1208 o_textfieldString = [NSString stringWithFormat: @"%s", (char *)p_item->value.psz];
1210 o_textfieldString = [NSString stringWithString: @""];
1211 ADD_TEXTFIELD( o_textfield, mainFrame, 12, 2, mainFrame.size.width -
1212 8 - [o_button frame].size.width,
1213 o_itemTooltip, o_textfieldString )
1214 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
1215 [self addSubview: o_textfield];
1220 - (void) alignWithXPosition:(int)i_xPos
1227 [o_textfield release];
1232 - (IBAction)openFileDialog: (id)sender
1234 NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
1236 [o_open_panel setTitle: (b_directory)?
1237 _NS("Select a directory"):_NS("Select a file")];
1238 [o_open_panel setPrompt: _NS("Select")];
1239 [o_open_panel setAllowsMultipleSelection: NO];
1240 [o_open_panel setCanChooseFiles: !b_directory];
1241 [o_open_panel setCanChooseDirectories: b_directory];
1242 [o_open_panel beginSheetForDirectory:nil
1245 modalForWindow:[sender window]
1247 didEndSelector: @selector(pathChosenInPanel:
1253 - (void)pathChosenInPanel:(NSOpenPanel *)o_sheet
1254 withReturn:(int)i_return_code contextInfo:(void *)o_context_info
1256 if( i_return_code == NSOKButton )
1258 NSString *o_path = [[o_sheet filenames] objectAtIndex: 0];
1259 [o_textfield setStringValue: o_path];
1263 - (char *)stringValue
1265 if( [[o_textfield stringValue] length] != 0)
1266 return strdup( [[o_textfield stringValue] fileSystemRepresentation] );
1273 NSString *o_textfieldString;
1274 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1276 o_textfieldString = [NSString stringWithFormat: @"%s", psz_value];
1278 o_textfieldString = [NSString stringWithString: @""];
1281 [super resetValues];
1285 @implementation ModuleConfigControl
1286 - (id) initWithItem: (module_config_t *)_p_item
1287 withView: (NSView *)o_parent_view
1289 NSRect mainFrame = [o_parent_view frame];
1290 NSString *o_labelString, *o_popupTooltip;
1291 mainFrame.size.height = 22;
1292 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1293 mainFrame.origin.x = LEFTMARGIN;
1294 mainFrame.origin.y = 0;
1296 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1298 i_view_type = CONFIG_ITEM_MODULE;
1300 o_popupTooltip = [[VLCMain sharedInstance] wrapString:
1301 [[VLCMain sharedInstance]
1302 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1305 if( p_item->psz_text )
1306 o_labelString = [[VLCMain sharedInstance]
1307 localizedString: (char *)p_item->psz_text];
1309 o_labelString = [NSString stringWithString:@""];
1310 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_popupTooltip )
1311 [o_label setAutoresizingMask:NSViewNotSizable ];
1312 [self addSubview: o_label];
1314 /* build the popup */
1315 ADD_POPUP( o_popup, mainFrame, [o_label frame].size.width,
1316 -2, 0, o_popupTooltip )
1317 [o_popup setAutoresizingMask:NSViewWidthSizable ];
1318 [o_popup addItemWithTitle: _NS("Default")];
1319 [[o_popup lastItem] setTag: -1];
1320 [o_popup selectItem: [o_popup lastItem]];
1323 [self addSubview: o_popup];
1328 - (void) alignWithXPosition:(int)i_xPos
1331 NSRect superFrame = [self frame];
1332 frame = [o_label frame];
1333 frame.origin.x = i_xPos - frame.size.width - 3;
1334 [o_label setFrame:frame];
1336 frame = [o_popup frame];
1337 frame.origin.x = i_xPos - 1;
1338 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1339 [o_popup setFrame:frame];
1348 - (char *)stringValue
1350 NSString *newval = [o_popup titleOfSelectedItem];
1351 char *returnval = NULL;
1352 size_t i_module_index;
1353 module_t *p_parser, **p_list;
1355 p_list = module_list_get( NULL );
1356 for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
1358 p_parser = p_list[i_module_index];
1360 if( p_item->i_type == CONFIG_ITEM_MODULE )
1362 if( module_provides( p_parser, p_item->psz_type ) )
1364 NSString *o_description = [[VLCMain sharedInstance]
1365 localizedString: module_get_name( p_parser, TRUE )];
1366 if( [newval isEqualToString: o_description] )
1368 returnval = strdup( module_get_object( p_parser ));
1377 if( module_is_main( p_parser) )
1379 unsigned int confsize, unused;
1380 module_config_get( p_parser, &confsize );
1381 for ( i = 0; i < confsize; i++ )
1383 module_config_t *p_config = module_config_get( p_parser, &unused ) + i;
1384 /* Hack: required subcategory is stored in i_min */
1385 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1386 p_config->value.i == p_item->min.i )
1388 NSString *o_description = [[VLCMain sharedInstance]
1389 localizedString: module_get_name( p_parser, TRUE )];
1390 if( [newval isEqualToString: o_description] )
1392 returnval = strdup(module_get_object( p_parser ));
1399 module_list_free( p_list );
1405 /* build a list of available modules */
1407 module_t *p_parser, **p_list;
1409 p_list = module_list_get( NULL );
1410 for( i_index = 0; p_list[i_index]; i_index++ )
1412 p_parser = p_list[i_index];
1414 if( p_item->i_type == CONFIG_ITEM_MODULE )
1416 if( module_provides( p_parser, p_item->psz_type ) )
1418 NSString *o_description = [[VLCMain sharedInstance]
1419 localizedString: module_get_name( p_parser, TRUE )];
1420 [o_popup addItemWithTitle: o_description];
1421 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1424 !strcmp( psz_value, module_get_object( p_parser ) ) )
1425 [o_popup selectItem:[o_popup lastItem]];
1434 if( module_is_main( p_parser ) )
1436 unsigned int confsize;
1437 unsigned int unused;
1438 module_config_t *p_configlist = module_config_get( p_parser, &confsize );
1439 for ( i = 0; i < confsize; i++ )
1441 module_config_t *p_config = &p_configlist[i];
1442 /* Hack: required subcategory is stored in i_min */
1443 if( p_config->i_type == CONFIG_SUBCATEGORY &&
1444 config_GetInt( VLCIntf, p_item->psz_name) == p_item->min.i )
1446 NSString *o_description = [[VLCMain sharedInstance]
1447 localizedString: module_get_name( p_parser, TRUE )];
1448 [o_popup addItemWithTitle: o_description];
1449 char *psz_value = config_GetPsz( VLCIntf, p_item->psz_name );
1451 if( psz_value && !strcmp(psz_value,
1452 module_get_object( p_parser )) )
1453 [o_popup selectItem:[o_popup lastItem]];
1458 module_config_free( p_configlist );
1461 module_list_free( p_list );
1462 [super resetValues];
1466 @implementation IntegerConfigControl
1467 - (id) initWithItem: (module_config_t *)_p_item
1468 withView: (NSView *)o_parent_view
1470 NSRect mainFrame = [o_parent_view frame];
1471 NSString *o_labelString, *o_tooltip;
1472 mainFrame.size.height = 23;
1473 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1474 mainFrame.origin.x = LEFTMARGIN;
1475 mainFrame.origin.y = 0;
1477 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1479 i_view_type = CONFIG_ITEM_INTEGER;
1481 o_tooltip = [[VLCMain sharedInstance] wrapString:
1482 [[VLCMain sharedInstance]
1483 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1486 if( p_item->psz_text )
1487 o_labelString = [[VLCMain sharedInstance]
1488 localizedString: (char *)p_item->psz_text];
1490 o_labelString = [NSString stringWithString:@""];
1491 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1492 [o_label setAutoresizingMask:NSViewNotSizable ];
1493 [self addSubview: o_label];
1495 /* build the stepper */
1496 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1497 0, o_tooltip, -100000, 100000)
1498 [o_stepper setIntValue: p_item->value.i];
1499 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1500 [self addSubview: o_stepper];
1502 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1503 1, 49, o_tooltip, @"" )
1504 [o_textfield setIntValue: p_item->value.i];
1505 [o_textfield setDelegate: self];
1506 [[NSNotificationCenter defaultCenter] addObserver: self
1507 selector: @selector(textfieldChanged:)
1508 name: NSControlTextDidChangeNotification
1509 object: o_textfield];
1510 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1511 [self addSubview: o_textfield];
1516 - (void) alignWithXPosition:(int)i_xPos
1519 frame = [o_label frame];
1520 frame.origin.x = i_xPos - frame.size.width - 3;
1521 [o_label setFrame:frame];
1523 frame = [o_textfield frame];
1524 frame.origin.x = i_xPos + 2;
1525 [o_textfield setFrame:frame];
1527 frame = [o_stepper frame];
1528 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1529 [o_stepper setFrame:frame];
1534 [o_stepper release];
1535 [o_textfield release];
1539 - (IBAction)stepperChanged:(id)sender
1541 [o_textfield setIntValue: [o_stepper intValue]];
1544 - (void)textfieldChanged:(NSNotification *)o_notification
1546 [o_stepper setIntValue: [o_textfield intValue]];
1551 return [o_textfield intValue];
1556 [o_textfield setIntValue: config_GetInt(VLCIntf, p_item->psz_name)];
1557 [super resetValues];
1562 @implementation IntegerListConfigControl
1564 - (id) initWithItem: (module_config_t *)_p_item
1565 withView: (NSView *)o_parent_view
1567 NSRect mainFrame = [o_parent_view frame];
1568 NSString *o_labelString, *o_textfieldTooltip;
1569 mainFrame.size.height = 22;
1570 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1571 mainFrame.origin.x = LEFTMARGIN;
1572 mainFrame.origin.y = 0;
1574 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1577 i_view_type = CONFIG_ITEM_STRING_LIST;
1579 o_textfieldTooltip = [[VLCMain sharedInstance] wrapString:
1580 [[VLCMain sharedInstance]
1581 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1584 if( p_item->psz_text )
1585 o_labelString = [[VLCMain sharedInstance]
1586 localizedString: (char *)p_item->psz_text];
1588 o_labelString = [NSString stringWithString:@""];
1589 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_textfieldTooltip )
1590 [o_label setAutoresizingMask:NSViewNotSizable ];
1591 [self addSubview: o_label];
1593 /* build the textfield */
1594 ADD_COMBO( o_combo, mainFrame, [o_label frame].size.width,
1595 -2, 0, o_textfieldTooltip )
1596 [o_combo setAutoresizingMask:NSViewWidthSizable ];
1597 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1599 if( p_item->value.i == p_item->pi_list[i_index] )
1601 [o_combo selectItemAtIndex: i_index];
1604 [self addSubview: o_combo];
1609 - (void) alignWithXPosition:(int)i_xPos
1612 NSRect superFrame = [self frame];
1613 frame = [o_label frame];
1614 frame.origin.x = i_xPos - frame.size.width - 3;
1615 [o_label setFrame:frame];
1617 frame = [o_combo frame];
1618 frame.origin.x = i_xPos + 2;
1619 frame.size.width = superFrame.size.width - frame.origin.x + 2;
1620 [o_combo setFrame:frame];
1631 if( [o_combo indexOfSelectedItem] >= 0 )
1632 return p_item->pi_list[[o_combo indexOfSelectedItem]];
1634 return [o_combo intValue];
1640 [o_combo reloadData];
1641 for( i_index = 0; i_index < p_item->i_list; i_index++ )
1643 if( config_GetInt( VLCIntf, p_item->psz_name) == p_item->pi_list[i_index] )
1645 [o_combo selectItemAtIndex: i_index];
1652 @implementation IntegerListConfigControl (NSComboBoxDataSource)
1653 - (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
1655 return p_item->i_list;
1658 - (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)i_index
1660 if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] )
1661 return [[VLCMain sharedInstance]
1662 localizedString: (char *)p_item->ppsz_list_text[i_index]];
1664 return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];
1668 @implementation RangedIntegerConfigControl
1669 - (id) initWithItem: (module_config_t *)_p_item
1670 withView: (NSView *)o_parent_view
1672 NSRect mainFrame = [o_parent_view frame];
1673 NSString *o_labelString, *o_tooltip;
1674 mainFrame.size.height = 50;
1675 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1676 mainFrame.origin.x = LEFTMARGIN;
1677 mainFrame.origin.y = 0;
1679 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1681 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1683 o_tooltip = [[VLCMain sharedInstance] wrapString:
1684 [[VLCMain sharedInstance]
1685 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1688 if( p_item->psz_text )
1689 o_labelString = [[VLCMain sharedInstance]
1690 localizedString: (char *)p_item->psz_text];
1692 o_labelString = [NSString stringWithString:@""];
1693 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1694 [o_label setAutoresizingMask:NSViewNotSizable ];
1695 [self addSubview: o_label];
1697 /* build the textfield */
1698 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1699 28, 49, o_tooltip, @"" )
1700 [o_textfield setIntValue: p_item->value.i];
1701 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1702 [o_textfield setDelegate: self];
1703 [[NSNotificationCenter defaultCenter] addObserver: self
1704 selector: @selector(textfieldChanged:)
1705 name: NSControlTextDidChangeNotification
1706 object: o_textfield];
1707 [self addSubview: o_textfield];
1709 /* build the mintextfield */
1710 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1711 [o_textfield_min setIntValue: p_item->min.i];
1712 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1713 [o_textfield_min setAlignment:NSRightTextAlignment];
1714 [self addSubview: o_textfield_min];
1716 /* build the maxtextfield */
1717 ADD_LABEL( o_textfield_max, mainFrame,
1718 mainFrame.size.width - 31, -30, @"8888", @"" )
1719 [o_textfield_max setIntValue: p_item->max.i];
1720 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1721 [self addSubview: o_textfield_max];
1723 /* build the slider */
1724 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1725 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1726 [o_textfield_max frame].size.width -
1727 [o_textfield_max frame].size.width - 14 -
1728 [o_textfield_min frame].origin.x, o_tooltip,
1729 p_item->min.i, p_item->max.i )
1730 [o_slider setIntValue: p_item->value.i];
1731 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1732 [o_slider setTarget: self];
1733 [o_slider setAction: @selector(sliderChanged:)];
1734 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1735 NSLeftMouseDraggedMask];
1736 [self addSubview: o_slider];
1742 - (void) alignWithXPosition:(int)i_xPos
1745 frame = [o_label frame];
1746 frame.origin.x = i_xPos - frame.size.width - 3;
1747 [o_label setFrame:frame];
1749 frame = [o_textfield frame];
1750 frame.origin.x = i_xPos + 2;
1751 [o_textfield setFrame:frame];
1756 [o_textfield release];
1757 [o_textfield_min release];
1758 [o_textfield_max release];
1763 - (IBAction)sliderChanged:(id)sender
1765 [o_textfield setIntValue: [o_slider intValue]];
1768 - (void)textfieldChanged:(NSNotification *)o_notification
1770 [o_slider setIntValue: [o_textfield intValue]];
1775 return [o_slider intValue];
1780 int value = config_GetInt( VLCIntf, p_item->psz_name );
1781 [o_textfield setIntValue:value];
1782 [o_slider setIntValue:value];
1783 [super resetValues];
1787 @implementation FloatConfigControl
1788 - (id) initWithItem: (module_config_t *)_p_item
1789 withView: (NSView *)o_parent_view
1791 NSRect mainFrame = [o_parent_view frame];
1792 NSString *o_labelString, *o_tooltip;
1793 mainFrame.size.height = 23;
1794 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
1795 mainFrame.origin.x = LEFTMARGIN;
1796 mainFrame.origin.y = 0;
1798 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1800 i_view_type = CONFIG_ITEM_INTEGER;
1802 o_tooltip = [[VLCMain sharedInstance] wrapString:
1803 [[VLCMain sharedInstance]
1804 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1807 if( p_item->psz_text )
1808 o_labelString = [[VLCMain sharedInstance]
1809 localizedString: (char *)p_item->psz_text];
1811 o_labelString = [NSString stringWithString:@""];
1812 ADD_LABEL( o_label, mainFrame, 0, -2, o_labelString, o_tooltip )
1813 [o_label setAutoresizingMask:NSViewNotSizable ];
1814 [self addSubview: o_label];
1816 /* build the stepper */
1817 ADD_STEPPER( o_stepper, mainFrame, mainFrame.size.width - 19,
1818 0, o_tooltip, -100000, 100000)
1819 [o_stepper setFloatValue: p_item->value.f];
1820 [o_stepper setAutoresizingMask:NSViewMaxXMargin ];
1821 [self addSubview: o_stepper];
1823 /* build the textfield */
1824 ADD_TEXTFIELD( o_textfield, mainFrame, mainFrame.size.width - 19 - 52,
1825 1, 49, o_tooltip, @"" )
1826 [o_textfield setFloatValue: p_item->value.f];
1827 [o_textfield setDelegate: self];
1828 [[NSNotificationCenter defaultCenter] addObserver: self
1829 selector: @selector(textfieldChanged:)
1830 name: NSControlTextDidChangeNotification
1831 object: o_textfield];
1832 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1833 [self addSubview: o_textfield];
1838 - (void) alignWithXPosition:(int)i_xPos
1841 frame = [o_label frame];
1842 frame.origin.x = i_xPos - frame.size.width - 3;
1843 [o_label setFrame:frame];
1845 frame = [o_textfield frame];
1846 frame.origin.x = i_xPos + 2;
1847 [o_textfield setFrame:frame];
1849 frame = [o_stepper frame];
1850 frame.origin.x = i_xPos + [o_textfield frame].size.width + 5;
1851 [o_stepper setFrame:frame];
1856 [o_stepper release];
1857 [o_textfield release];
1861 - (IBAction)stepperChanged:(id)sender
1863 [o_textfield setFloatValue: [o_stepper floatValue]];
1866 - (void)textfieldChanged:(NSNotification *)o_notification
1868 [o_stepper setFloatValue: [o_textfield floatValue]];
1873 return [o_stepper floatValue];
1878 [o_textfield setFloatValue: config_GetFloat( VLCIntf, p_item->psz_name)];
1879 [super resetValues];
1883 @implementation RangedFloatConfigControl
1884 - (id) initWithItem: (module_config_t *)_p_item
1885 withView: (NSView *)o_parent_view
1887 NSRect mainFrame = [o_parent_view frame];
1888 NSString *o_labelString, *o_tooltip;
1889 mainFrame.size.height = 50;
1890 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
1891 mainFrame.origin.x = LEFTMARGIN;
1892 mainFrame.origin.y = 0;
1894 if( [super initWithFrame: mainFrame item: _p_item] != nil )
1896 i_view_type = CONFIG_ITEM_RANGED_INTEGER;
1898 o_tooltip = [[VLCMain sharedInstance] wrapString:
1899 [[VLCMain sharedInstance]
1900 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
1903 if( p_item->psz_text )
1904 o_labelString = [[VLCMain sharedInstance]
1905 localizedString: (char *)p_item->psz_text];
1907 o_labelString = [NSString stringWithString:@""];
1908 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
1909 [o_label setAutoresizingMask:NSViewNotSizable ];
1910 [self addSubview: o_label];
1912 /* build the textfield */
1913 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
1914 28, 49, o_tooltip, @"" )
1915 [o_textfield setFloatValue: p_item->value.f];
1916 [o_textfield setAutoresizingMask:NSViewMaxXMargin ];
1917 [o_textfield setDelegate: self];
1918 [[NSNotificationCenter defaultCenter] addObserver: self
1919 selector: @selector(textfieldChanged:)
1920 name: NSControlTextDidChangeNotification
1921 object: o_textfield];
1922 [self addSubview: o_textfield];
1924 /* build the mintextfield */
1925 ADD_LABEL( o_textfield_min, mainFrame, 12, -30, @"-8888", @"" )
1926 [o_textfield_min setFloatValue: p_item->min.f];
1927 [o_textfield_min setAutoresizingMask:NSViewMaxXMargin ];
1928 [o_textfield_min setAlignment:NSRightTextAlignment];
1929 [self addSubview: o_textfield_min];
1931 /* build the maxtextfield */
1932 ADD_LABEL( o_textfield_max, mainFrame, mainFrame.size.width - 31,
1934 [o_textfield_max setFloatValue: p_item->max.f];
1935 [o_textfield_max setAutoresizingMask:NSViewMinXMargin ];
1936 [self addSubview: o_textfield_max];
1938 /* build the slider */
1939 ADD_SLIDER( o_slider, mainFrame, [o_textfield_min frame].origin.x +
1940 [o_textfield_min frame].size.width + 6, -1, mainFrame.size.width -
1941 [o_textfield_max frame].size.width -
1942 [o_textfield_max frame].size.width - 14 -
1943 [o_textfield_min frame].origin.x, o_tooltip, p_item->min.f,
1945 [o_slider setFloatValue: p_item->value.f];
1946 [o_slider setAutoresizingMask:NSViewWidthSizable ];
1947 [o_slider setTarget: self];
1948 [o_slider setAction: @selector(sliderChanged:)];
1949 [o_slider sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
1950 NSLeftMouseDraggedMask];
1951 [self addSubview: o_slider];
1957 - (void) alignWithXPosition:(int)i_xPos
1960 frame = [o_label frame];
1961 frame.origin.x = i_xPos - frame.size.width - 3;
1962 [o_label setFrame:frame];
1964 frame = [o_textfield frame];
1965 frame.origin.x = i_xPos + 2;
1966 [o_textfield setFrame:frame];
1971 [o_textfield release];
1972 [o_textfield_min release];
1973 [o_textfield_max release];
1978 - (IBAction)sliderChanged:(id)sender
1980 [o_textfield setFloatValue: [o_slider floatValue]];
1983 - (void)textfieldChanged:(NSNotification *)o_notification
1985 [o_slider setFloatValue: [o_textfield floatValue]];
1990 return [o_slider floatValue];
1995 [o_textfield setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
1996 [o_slider setFloatValue: config_GetFloat(VLCIntf, p_item->psz_name)];
1997 [super resetValues];
2001 @implementation BoolConfigControl
2003 - (id) initWithItem: (module_config_t *)_p_item
2004 withView: (NSView *)o_parent_view
2006 NSRect mainFrame = [o_parent_view frame];
2007 NSString *o_labelString, *o_tooltip;
2008 mainFrame.size.height = 17;
2009 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2010 mainFrame.origin.x = LEFTMARGIN;
2011 mainFrame.origin.y = 0;
2013 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2015 i_view_type = CONFIG_ITEM_BOOL;
2017 /* add the checkbox */
2018 o_tooltip = [[VLCMain sharedInstance]
2019 wrapString: [[VLCMain sharedInstance]
2020 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2021 ADD_CHECKBOX( o_checkbox, mainFrame, 0,
2022 0, @"", o_tooltip, p_item->value.i, NSImageLeft)
2023 [o_checkbox setAutoresizingMask:NSViewNotSizable ];
2024 [self addSubview: o_checkbox];
2026 if( p_item->psz_text )
2027 o_labelString = [[VLCMain sharedInstance]
2028 localizedString: (char *)p_item->psz_text];
2030 o_labelString = [NSString stringWithString:@""];
2031 ADD_LABEL( o_label, mainFrame, [o_checkbox frame].size.width, 0, o_labelString, o_tooltip )
2032 [o_label setAutoresizingMask:NSViewNotSizable ];
2033 [self addSubview: o_label];
2040 [o_checkbox release];
2046 return [o_checkbox intValue];
2051 [o_checkbox setState: config_GetInt( VLCIntf, p_item->psz_name)];
2052 [super resetValues];
2056 @implementation KeyConfigControl
2057 - (id) initWithItem: (module_config_t *)_p_item
2058 withView: (NSView *)o_parent_view
2060 NSRect mainFrame = [o_parent_view frame];
2061 NSString *o_labelString, *o_tooltip;
2062 mainFrame.size.height = 22;
2063 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN + 1;
2064 mainFrame.origin.x = LEFTMARGIN;
2065 mainFrame.origin.y = 0;
2067 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2069 i_view_type = CONFIG_ITEM_KEY_AFTER_10_3;
2071 o_tooltip = [[VLCMain sharedInstance] wrapString:
2072 [[VLCMain sharedInstance]
2073 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2076 if( p_item->psz_text )
2077 o_labelString = [[VLCMain sharedInstance]
2078 localizedString: (char *)p_item->psz_text];
2080 o_labelString = [NSString stringWithString:@""];
2081 ADD_LABEL( o_label, mainFrame, 0, -1, o_labelString, o_tooltip )
2082 [o_label setAutoresizingMask:NSViewNotSizable ];
2083 [self addSubview: o_label];
2085 /* build the popup */
2086 ADD_POPUP( o_popup, mainFrame, [o_label frame].origin.x +
2087 [o_label frame].size.width + 3,
2089 [o_popup setAutoresizingMask:NSViewWidthSizable ];
2091 if( o_keys_menu == nil )
2094 o_keys_menu = [[NSMenu alloc] initWithTitle: @"Keys Menu"];
2095 #warning This does not work anymore. FIXME.
2097 for ( i = 0; i < sizeof(vlc_key) / sizeof(key_descriptor_t); i++)
2098 if( vlc_key[i].psz_key_string )
2099 POPULATE_A_KEY( o_keys_menu,
2100 [NSString stringWithUTF8String:vlc_key[i].psz_key_string]
2101 , vlc_key[i].i_key_code)
2104 [o_popup setMenu:[o_keys_menu copyWithZone:nil]];
2105 [o_popup selectItem:[[o_popup menu] itemWithTag:p_item->value.i]];
2106 [self addSubview: o_popup];
2112 - (void) alignWithXPosition:(int)i_xPos
2115 NSRect superFrame = [self frame];
2116 frame = [o_label frame];
2117 frame.origin.x = i_xPos - frame.size.width - 3;
2118 [o_label setFrame:frame];
2120 frame = [o_popup frame];
2121 frame.origin.x = i_xPos - 1;
2122 frame.size.width = superFrame.size.width - frame.origin.x + 2;
2123 [o_popup setFrame:frame];
2134 return [o_popup selectedTag];
2139 [o_popup selectItem:[[o_popup menu] itemWithTag:config_GetInt( VLCIntf, p_item->psz_name )]];
2140 [super resetValues];
2144 @implementation ModuleListConfigControl
2145 - (id) initWithItem: (module_config_t *)_p_item
2146 withView: (NSView *)o_parent_view
2148 if( _p_item->i_type == CONFIG_ITEM_MODULE_LIST )
2152 //Fill our array to know how may items we have...
2153 module_t *p_parser, **p_list;
2154 size_t i_module_index;
2155 NSRect mainFrame = [o_parent_view frame];
2156 NSString *o_labelString, *o_textfieldString, *o_tooltip;
2158 o_modulearray = [[NSMutableArray alloc] initWithCapacity:10];
2159 /* build a list of available modules */
2160 p_list = module_list_get( NULL );
2161 for( i_module_index = 0; p_list[i_module_index]; i_module_index++ )
2164 p_parser = p_list[i_module_index];
2166 if( module_is_main( p_parser ) )
2169 unsigned int confsize;
2170 module_config_t *p_configlist = module_config_get( p_parser, &confsize );
2172 for ( i = 0; i < confsize; i++ )
2174 unsigned int unused;
2175 module_config_t *p_config = &p_configlist[i];
2176 NSString *o_modulelongname, *o_modulename;
2177 NSNumber *o_moduleenabled = nil;
2179 /* Hack: required subcategory is stored in i_min */
2180 if( p_config->i_type == CONFIG_SUBCATEGORY &&
2181 p_config->value.i == _p_item->min.i )
2183 o_modulelongname = [NSString stringWithUTF8String:
2184 module_get_name( p_parser, TRUE )];
2185 o_modulename = [NSString stringWithUTF8String:
2186 module_get_object( p_parser )];
2188 if( _p_item->value.psz &&
2189 strstr( _p_item->value.psz, module_get_object( p_parser ) ) )
2190 o_moduleenabled = [NSNumber numberWithBool:YES];
2192 o_moduleenabled = [NSNumber numberWithBool:NO];
2194 [o_modulearray addObject:[NSMutableArray
2195 arrayWithObjects: o_modulename, o_modulelongname,
2196 o_moduleenabled, nil]];
2199 module_config_free( p_configlist );
2201 module_list_free( p_list );
2203 mainFrame.size.height = 30 + 20 * [o_modulearray count];
2204 mainFrame.size.width = mainFrame.size.width - LEFTMARGIN - RIGHTMARGIN;
2205 mainFrame.origin.x = LEFTMARGIN;
2206 mainFrame.origin.y = 0;
2207 if( [super initWithFrame: mainFrame item: _p_item] != nil )
2209 i_view_type = CONFIG_ITEM_MODULE_LIST;
2211 o_tooltip = [[VLCMain sharedInstance] wrapString:
2212 [[VLCMain sharedInstance]
2213 localizedString: (char *)p_item->psz_longtext ] toWidth: PREFS_WRAP];
2216 if( p_item->psz_text )
2217 o_labelString = [[VLCMain sharedInstance]
2218 localizedString: (char *)p_item->psz_text];
2220 o_labelString = [NSString stringWithString:@""];
2221 ADD_LABEL( o_label, mainFrame, 0, -3, o_labelString, o_tooltip )
2222 [o_label setAutoresizingMask:NSViewNotSizable ];
2223 [self addSubview: o_label];
2225 /* build the textfield */
2226 if( p_item->value.psz )
2227 o_textfieldString = [[VLCMain sharedInstance]
2228 localizedString: (char *)p_item->value.psz];
2230 o_textfieldString = [NSString stringWithString: @""];
2231 ADD_TEXTFIELD( o_textfield, mainFrame, [o_label frame].size.width + 2,
2232 mainFrame.size.height - 22, mainFrame.size.width -
2233 [o_label frame].size.width - 2, o_tooltip, o_textfieldString )
2234 [o_textfield setAutoresizingMask:NSViewWidthSizable ];
2235 [self addSubview: o_textfield];
2239 NSRect s_rc = mainFrame;
2240 s_rc.size.height = mainFrame.size.height - 30;
2241 s_rc.size.width = mainFrame.size.width - 12;
2244 o_scrollview = [[[NSScrollView alloc] initWithFrame: s_rc] retain];
2245 [o_scrollview setDrawsBackground: NO];
2246 [o_scrollview setBorderType: NSBezelBorder];
2247 [o_scrollview setAutohidesScrollers:YES];
2249 NSTableView *o_tableview;
2250 o_tableview = [[NSTableView alloc] initWithFrame : s_rc];
2251 [o_tableview setUsesAlternatingRowBackgroundColors:YES];
2252 [o_tableview setHeaderView:nil];
2253 /* TODO: find a good way to fix the row height and text size*/
2254 /* FIXME: support for multiple selection... */
2255 // [o_tableview setAllowsMultipleSelection:YES];
2257 NSCell *o_headerCell = [[NSCell alloc] initTextCell:@"Enabled"];
2258 NSCell *o_dataCell = [[NSButtonCell alloc] init];
2259 [(NSButtonCell*)o_dataCell setButtonType:NSSwitchButton];
2260 [o_dataCell setTitle:@""];
2261 [o_dataCell setFont:[NSFont systemFontOfSize:0]];
2262 NSTableColumn *o_tableColumn = [[NSTableColumn alloc]
2263 initWithIdentifier:@"Enabled"];
2264 [o_tableColumn setHeaderCell: o_headerCell];
2265 [o_tableColumn setDataCell: o_dataCell];
2266 [o_tableColumn setWidth:17];
2267 [o_tableview addTableColumn: o_tableColumn];
2269 o_headerCell = [[NSCell alloc] initTextCell:@"Module Name"];
2270 o_dataCell = [[NSTextFieldCell alloc] init];
2271 [o_dataCell setFont:[NSFont systemFontOfSize:12]];
2272 o_tableColumn = [[NSTableColumn alloc]
2273 initWithIdentifier:@"Module"];
2274 [o_tableColumn setHeaderCell: o_headerCell];
2275 [o_tableColumn setDataCell: o_dataCell];
2276 [o_tableColumn setWidth:s_rc.size.width - 34];
2277 [o_tableview addTableColumn: o_tableColumn];
2278 [o_tableview registerForDraggedTypes:[NSArray arrayWithObjects:
2279 @"VLC media player module", nil]];
2281 [o_tableview setDataSource:self];
2282 [o_tableview setTarget: self];
2283 [o_tableview setAction: @selector(tableChanged:)];
2284 [o_tableview sendActionOn:NSLeftMouseUpMask | NSLeftMouseDownMask |
2285 NSLeftMouseDraggedMask];
2286 [o_scrollview setDocumentView: o_tableview];
2288 [o_scrollview setAutoresizingMask:NSViewWidthSizable ];
2289 [o_scrollview setAutohidesScrollers:YES];
2290 [self addSubview: o_scrollview];
2296 - (void) alignWithXPosition:(int)i_xPos
2301 - (IBAction)tableChanged:(id)sender
2303 NSString *o_newstring = @"";
2305 for( i = 0 ; i < [o_modulearray count] ; i++ )
2306 if( [[[o_modulearray objectAtIndex:i] objectAtIndex:2]
2309 o_newstring = [o_newstring stringByAppendingString:
2310 [[o_modulearray objectAtIndex:i] objectAtIndex:0]];
2311 o_newstring = [o_newstring stringByAppendingString:@":"];
2314 [o_textfield setStringValue: [o_newstring
2315 substringToIndex: ([o_newstring length])?[o_newstring length] - 1:0]];
2320 [o_scrollview release];
2325 - (char *)stringValue
2327 return strdup( [[o_textfield stringValue] UTF8String] );
2332 #warning Reset prefs of the module selector is broken atm.
2333 NSLog( @"don't forget about modulelistconfig" );
2334 [super resetValues];
2339 @implementation ModuleListConfigControl (NSTableDataSource)
2341 - (BOOL)tableView:(NSTableView*)table writeRows:(NSArray*)rows
2342 toPasteboard:(NSPasteboard*)pb
2344 // We only want to allow dragging of selected rows.
2345 NSEnumerator *iter = [rows objectEnumerator];
2347 while ((row = [iter nextObject]) != nil)
2349 if (![table isRowSelected:[row intValue]])
2353 [pb declareTypes:[NSArray
2354 arrayWithObject:@"VLC media player module"] owner:nil];
2355 [pb setPropertyList:rows forType:@"VLC media player module"];
2359 - (NSDragOperation)tableView:(NSTableView*)table
2360 validateDrop:(id <NSDraggingInfo>)info proposedRow:(NSInteger)row
2361 proposedDropOperation:(NSTableViewDropOperation)op
2363 // Make drops at the end of the table go to the end.
2366 row = [table numberOfRows];
2367 op = NSTableViewDropAbove;
2368 [table setDropRow:row dropOperation:op];
2371 // We don't ever want to drop onto a row, only between rows.
2372 if (op == NSTableViewDropOn)
2373 [table setDropRow:(row+1) dropOperation:NSTableViewDropAbove];
2374 return NSTableViewDropAbove;
2377 - (BOOL)tableView:(NSTableView*)table acceptDrop:(id <NSDraggingInfo>)info
2378 row:(NSInteger)dropRow dropOperation:(NSTableViewDropOperation)op;
2380 NSPasteboard *pb = [info draggingPasteboard];
2381 NSDragOperation srcMask = [info draggingSourceOperationMask];
2388 // Intra-table drag - data is the array of rows.
2389 if (!accepted && (array =
2390 [pb propertyListForType:@"VLC media player module"]) != NULL)
2392 NSEnumerator *iter = nil;
2394 BOOL isCopy = (srcMask & NSDragOperationMove) ? NO:YES;
2396 iter = [array objectEnumerator];
2397 while ((val = [iter nextObject]) != NULL)
2399 NSArray *o_tmp = [[o_modulearray objectAtIndex:
2400 [val intValue]] mutableCopyWithZone:nil];
2401 [o_modulearray removeObject:o_tmp];
2402 [o_modulearray insertObject:o_tmp
2403 atIndex:(dropRow>[val intValue]) ? dropRow - 1 : dropRow];
2407 // Select the newly-dragged items.
2408 iter = [array objectEnumerator];
2410 [table deselectAll:self];
2412 [self tableChanged:self];
2413 [table setNeedsDisplay:YES];
2414 // Indicate that we finished the drag.
2418 [table setNeedsDisplay:YES];
2422 // An exception occurred. Uh-oh. Update the track table so that
2423 // it stays consistent, and re-raise the exception.
2425 [localException raise];
2426 [table setNeedsDisplay:YES];
2432 - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
2434 return [o_modulearray count];
2437 - (id)tableView:(NSTableView *)aTableView
2438 objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2440 if( [[aTableColumn identifier] isEqualToString: @"Enabled"] )
2441 return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:2];
2442 if( [[aTableColumn identifier] isEqualToString: @"Module"] )
2443 return [[o_modulearray objectAtIndex:rowIndex] objectAtIndex:1];
2448 - (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject
2449 forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
2451 [[o_modulearray objectAtIndex:rowIndex] replaceObjectAtIndex:2
2452 withObject: anObject];