prefs_widgets.m
来自「VLC媒体播放程序」· M 代码 · 共 1,164 行 · 第 1/3 页
M
1,164 行
{ if( p_item->i_value == p_item->pi_list[i_index] ) { [o_combo selectItemAtIndex: i_index]; } } [o_combo setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_combo]; } return self;}- (void)dealloc{ [o_combo release]; [super dealloc];}- (int)intValue{ module_config_t *p_item; p_item = config_FindConfig( p_this, psz_name ); if( [o_combo indexOfSelectedItem] >= 0 ) return p_item->pi_list[[o_combo indexOfSelectedItem]]; else return [o_combo intValue];}@end@implementation IntegerListConfigControl (NSComboBoxDataSource)- (int)numberOfItemsInComboBox:(NSComboBox *)aComboBox{ module_config_t *p_item; p_item = config_FindConfig( p_this, psz_name ); return p_item->i_list;}- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(int)i_index{ module_config_t *p_item; p_item = config_FindConfig( p_this, psz_name ); if( p_item->ppsz_list_text && p_item->ppsz_list_text[i_index] ) { return [NSApp localizedString: p_item->ppsz_list_text[i_index]]; } else return [NSString stringWithFormat: @"%i", p_item->pi_list[i_index]];}@end@implementation RangedIntegerConfigControl- (id)initWithFrame: (NSRect)frame item: (module_config_t *)p_item withObject: (vlc_object_t *)_p_this{ frame.size.height = 50; if( self = [super initWithFrame: frame item: p_item withObject: _p_this] ) { NSRect s_rc = frame; s_rc.size.height = 20; s_rc.origin.y = 30; /* add the label */ o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_label setDrawsBackground: NO]; [o_label setBordered: NO]; [o_label setEditable: NO]; [o_label setSelectable: NO]; if( p_item->psz_text ) [o_label setStringValue: [NSApp localizedString: p_item->psz_text]]; [o_label sizeToFit]; [[self contentView] addSubview: o_label]; [o_label setAutoresizingMask:NSViewMaxXMargin ]; /* build the slider */ /* min value textfield */ s_rc.origin.y = 0; s_rc.origin.x = 0; s_rc.size.width = 40; o_textfield_min = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield_min setAutoresizingMask:NSViewMaxXMargin]; [o_textfield_min setDrawsBackground: NO]; [o_textfield_min setBordered: NO]; [o_textfield_min setEditable: NO]; [o_textfield_min setSelectable: NO]; [o_textfield_min setIntValue: p_item->i_min]; [o_textfield_min setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_textfield_min]; /* the slider */ s_rc.size.width = [[self contentView] bounds].size.width - OFFSET_RIGHT - 2*OFFSET_BETWEEN - 3*40; s_rc.origin.x = 40 + OFFSET_BETWEEN; o_slider = [[[NSStepper alloc] initWithFrame: s_rc] retain]; [o_slider setAutoresizingMask:NSViewWidthSizable]; [o_slider setMaxValue: p_item->i_max]; [o_slider setMinValue: p_item->i_min]; [o_slider setIntValue: p_item->i_value]; [o_slider setTarget: self]; [o_slider setAction: @selector(sliderChanged:)]; [o_slider sendActionOn:NSLeftMouseUpMask|NSLeftMouseDownMask|NSLeftMouseDraggedMask]; [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_slider]; /* max value textfield */ s_rc.size.width = 40; s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - OFFSET_BETWEEN - 2*40; o_textfield_max = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield_max setAutoresizingMask:NSViewMinXMargin ]; [o_textfield_max setDrawsBackground: NO]; [o_textfield_max setBordered: NO]; [o_textfield_max setEditable: NO]; [o_textfield_max setSelectable: NO]; [o_textfield_max setIntValue: p_item->i_max]; [o_textfield_max setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_textfield_max]; /* current value textfield */ s_rc.size.width = 40; s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - 40; o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield setAutoresizingMask:NSViewMinXMargin]; [o_textfield setIntValue: p_item->i_value]; [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [o_textfield setDelegate: self]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(textfieldChanged:) name: NSControlTextDidChangeNotification object: o_textfield]; [[self contentView] addSubview: o_textfield]; } return self;}- (void)dealloc{ [o_textfield release]; [o_textfield_min release]; [o_textfield_max release]; [o_slider release]; [super dealloc];}- (IBAction)sliderChanged:(id)sender{ [o_textfield setIntValue: [o_slider intValue]];}- (void)textfieldChanged:(NSNotification *)o_notification{ [o_slider setIntValue: [o_textfield intValue]];}- (int)intValue{ return [o_slider intValue];}@end@implementation FloatConfigControl- (id)initWithFrame: (NSRect)frame item: (module_config_t *)p_item withObject: (vlc_object_t *)_p_this{ frame.size.height = 20; if( self = [super initWithFrame: frame item: p_item withObject: _p_this] ) { NSRect s_rc = frame; /* add the label */ o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_label setDrawsBackground: NO]; [o_label setBordered: NO]; [o_label setEditable: NO]; [o_label setSelectable: NO]; if( p_item->psz_text ) [o_label setStringValue: [NSApp localizedString: p_item->psz_text]]; [o_label sizeToFit]; [[self contentView] addSubview: o_label]; [o_label setAutoresizingMask:NSViewMaxXMargin ]; /* build the textfield */ s_rc.origin.x = s_rc.size.width - 60 - OFFSET_RIGHT; s_rc.size.width = 60; o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield setAutoresizingMask:NSViewMinXMargin | NSViewWidthSizable ]; [o_textfield setFloatValue: p_item->f_value]; [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_textfield]; } return self;}- (void)dealloc{ [o_textfield release]; [super dealloc];}- (float)floatValue{ return [o_textfield floatValue];}@end@implementation RangedFloatConfigControl- (id)initWithFrame: (NSRect)frame item: (module_config_t *)p_item withObject: (vlc_object_t *)_p_this{ frame.size.height = 50; if( self = [super initWithFrame: frame item: p_item withObject: _p_this] ) { NSRect s_rc = frame; s_rc.size.height = 20; s_rc.origin.y = 30; /* add the label */ o_label = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_label setDrawsBackground: NO]; [o_label setBordered: NO]; [o_label setEditable: NO]; [o_label setSelectable: NO]; if( p_item->psz_text ) [o_label setStringValue: [NSApp localizedString: p_item->psz_text]]; [o_label sizeToFit]; [[self contentView] addSubview: o_label]; [o_label setAutoresizingMask:NSViewMaxXMargin ]; /* build the slider */ /* min value textfield */ s_rc.origin.y = 0; s_rc.origin.x = 0; s_rc.size.width = 40; o_textfield_min = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield_min setAutoresizingMask:NSViewMaxXMargin]; [o_textfield_min setDrawsBackground: NO]; [o_textfield_min setBordered: NO]; [o_textfield_min setEditable: NO]; [o_textfield_min setSelectable: NO]; [o_textfield_min setFloatValue: p_item->f_min]; [o_textfield_min setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_textfield_min]; /* the slider */ s_rc.size.width = [[self contentView] bounds].size.width - OFFSET_RIGHT - 2*OFFSET_BETWEEN - 3*40; s_rc.origin.x = 40 + OFFSET_BETWEEN; o_slider = [[[NSStepper alloc] initWithFrame: s_rc] retain]; [o_slider setAutoresizingMask:NSViewWidthSizable]; [o_slider setMaxValue: p_item->f_max]; [o_slider setMinValue: p_item->f_min]; [o_slider setFloatValue: p_item->f_value]; [o_slider setTarget: self]; [o_slider setAction: @selector(sliderChanged:)]; [o_slider sendActionOn:NSLeftMouseUpMask|NSLeftMouseDownMask|NSLeftMouseDraggedMask]; [o_slider setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_slider]; /* max value textfield */ s_rc.size.width = 40; s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - OFFSET_BETWEEN - 2*40; o_textfield_max = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield_max setAutoresizingMask:NSViewMinXMargin ]; [o_textfield_max setDrawsBackground: NO]; [o_textfield_max setBordered: NO]; [o_textfield_max setEditable: NO]; [o_textfield_max setSelectable: NO]; [o_textfield_max setFloatValue: p_item->f_max]; [o_textfield_max setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_textfield_max]; /* current value textfield */ s_rc.size.width = 40; s_rc.origin.x = [[self contentView] bounds].size.width - OFFSET_RIGHT - 40; o_textfield = [[[NSTextField alloc] initWithFrame: s_rc] retain]; [o_textfield setAutoresizingMask:NSViewMinXMargin]; [o_textfield setFloatValue: p_item->f_value]; [o_textfield setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [o_textfield setDelegate: self]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(textfieldChanged:) name: NSControlTextDidChangeNotification object: o_textfield]; [[self contentView] addSubview: o_textfield]; } return self;}- (void)dealloc{ [o_textfield release]; [o_textfield_min release]; [o_textfield_max release]; [o_slider release]; [super dealloc];}- (IBAction)sliderChanged:(id)sender{ [o_textfield setFloatValue: [o_slider floatValue]];}- (void)textfieldChanged:(NSNotification *)o_notification{ [o_slider setFloatValue: [o_textfield floatValue]];}- (float)floatValue{ return [o_slider floatValue];}@end@implementation BoolConfigControl- (id)initWithFrame: (NSRect)frame item: (module_config_t *)p_item withObject: (vlc_object_t *)_p_this{ frame.size.height = 20; if( self = [super initWithFrame: frame item: p_item withObject: _p_this] ) { NSRect s_rc = frame; s_rc.size.height = 20; o_checkbox = [[[NSButton alloc] initWithFrame: s_rc] retain]; [o_checkbox setButtonType: NSSwitchButton]; [o_checkbox setIntValue: p_item->i_value]; [o_checkbox setTitle: [NSApp localizedString: p_item->psz_text]]; [o_checkbox setToolTip: [NSApp wrapString: [NSApp localizedString: p_item->psz_longtext ] toWidth: PREFS_WRAP]]; [[self contentView] addSubview: o_checkbox]; } return self;}- (void)dealloc{ [o_checkbox release]; [super dealloc];}- (int)intValue{ [o_checkbox intValue];}@end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?