[vlc-devel] [PATCH 1/2] macosx: Lua extensions infrastructure
Brendon Justin
brendonjustin at gmail.com
Thu Jan 12 22:36:01 CET 2012
Code for launching Lua extensions on Mac OS X. Much of the code is from the
macosx_dialog_provider.
---
modules/gui/macosx/ExtensionsDialogProvider.h | 64 +++
modules/gui/macosx/ExtensionsDialogProvider.m | 611 +++++++++++++++++++++++++
modules/gui/macosx/ExtensionsManager.h | 75 +++
modules/gui/macosx/ExtensionsManager.m | 372 +++++++++++++++
modules/gui/macosx/Modules.am | 10 +
modules/gui/macosx/VLCLoginPanel.h | 48 ++
modules/gui/macosx/VLCLoginPanel.m | 183 ++++++++
modules/gui/macosx/VLCProgressPanel.h | 46 ++
modules/gui/macosx/VLCProgressPanel.m | 142 ++++++
modules/gui/macosx/VLCUIWidgets.h | 72 +++
modules/gui/macosx/VLCUIWidgets.m | 395 ++++++++++++++++
11 files changed, 2018 insertions(+), 0 deletions(-)
create mode 100644 modules/gui/macosx/ExtensionsDialogProvider.h
create mode 100644 modules/gui/macosx/ExtensionsDialogProvider.m
create mode 100644 modules/gui/macosx/ExtensionsManager.h
create mode 100644 modules/gui/macosx/ExtensionsManager.m
create mode 100644 modules/gui/macosx/VLCLoginPanel.h
create mode 100644 modules/gui/macosx/VLCLoginPanel.m
create mode 100644 modules/gui/macosx/VLCProgressPanel.h
create mode 100644 modules/gui/macosx/VLCProgressPanel.m
create mode 100644 modules/gui/macosx/VLCUIWidgets.h
create mode 100644 modules/gui/macosx/VLCUIWidgets.m
diff --git a/modules/gui/macosx/ExtensionsDialogProvider.h b/modules/gui/macosx/ExtensionsDialogProvider.h
new file mode 100644
index 0000000..f1d839a
--- /dev/null
+++ b/modules/gui/macosx/ExtensionsDialogProvider.h
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * ExtensionsDialogProvider.h: Mac OS X Extensions Dialogs
+ *****************************************************************************
+ * Copyright (C) 2005-2012 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Brendon Justin <brendonjustin at gmail.com>,
+ * Derk-Jan Hartman <hartman at videolan dot org>,
+ * Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "coredialogs.h"
+#import "intf.h"
+#import "VLCUIWidgets.h"
+
+#import <vlc_common.h>
+#import <vlc_dialog.h>
+#import <vlc_extensions.h>
+
+#import <Cocoa/Cocoa.h>
+
+/*****************************************************************************
+ * ExtensionsDialogProvider interface
+ *****************************************************************************/
+ at interface ExtensionsDialogProvider : NSObject <NSWindowDelegate>
+{
+ intf_thread_t *p_intf;
+}
+
++ (ExtensionsDialogProvider *)sharedInstance:(intf_thread_t *)_p_intf;
++ (void)killInstance;
+
+- (id)initWithIntf:(intf_thread_t *)_p_intf;
+
+- (void)performEventWithObject: (NSValue *)o_value ofType:(const char*)type;
+
+- (void)triggerClick:(id)sender;
+- (void)syncTextField:(NSNotification *)notifcation;
+- (void)tableViewSelectionDidChange:(NSNotification *)notifcation;
+- (void)popUpSelectionChanged:(id)sender;
+- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;
+- (BOOL)windowShouldClose:(id)sender;
+- (void)updateWidgets:(extension_dialog_t *)dialog;
+
+- (VLCDialogWindow *)createExtensionDialog:(extension_dialog_t *)p_dialog;
+- (int)destroyExtensionDialog:(extension_dialog_t *)o_value;
+- (VLCDialogWindow *)updateExtensionDialog:(NSValue *)o_value;
+- (void)manageDialog:(extension_dialog_t *)p_dialog;
+
+ at end
diff --git a/modules/gui/macosx/ExtensionsDialogProvider.m b/modules/gui/macosx/ExtensionsDialogProvider.m
new file mode 100644
index 0000000..872861b
--- /dev/null
+++ b/modules/gui/macosx/ExtensionsDialogProvider.m
@@ -0,0 +1,611 @@
+/*****************************************************************************
+ * ExtensionsDialogProvider.m: Mac OS X Extensions Dialogs
+ *****************************************************************************
+ * Copyright (C) 2005-2012 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Brendon Justin <brendonjustin at gmail.com>,
+ * Derk-Jan Hartman <hartman at videolan dot org>,
+ * Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "ExtensionsDialogProvider.h"
+
+#import "intf.h"
+#import "ExtensionsManager.h"
+#import "misc.h"
+#import "VLCUIWidgets.h"
+
+#import <stdlib.h>
+
+/*****************************************************************************
+ * VLCExtensionsDialogProvider implementation
+ *****************************************************************************/
+
+static int dialogCallback( vlc_object_t *p_this, const char *psz_variable,
+ vlc_value_t old_val, vlc_value_t new_val,
+ void *param );
+
+static NSView *createControlFromWidget(extension_widget_t *widget, id self)
+{
+ assert(!widget->p_sys_intf);
+ switch (widget->type)
+ {
+ case EXTENSION_WIDGET_HTML:
+ {
+// NSScrollView *scrollView = [[NSScrollView alloc] init];
+// [scrollView setHasVerticalScroller:YES];
+// NSTextView *field = [[NSTextView alloc] init];
+// [scrollView setDocumentView:field];
+// [scrollView setAutoresizesSubviews:YES];
+// [scrollView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+// [field release];
+// return scrollView;
+ NSTextView *field = [[NSTextView alloc] init];
+ [field setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+ [field setDrawsBackground:NO];
+ return field;
+ }
+ case EXTENSION_WIDGET_LABEL:
+ {
+ NSTextField *field = [[NSTextField alloc] init];
+ [field setEditable:NO];
+ [field setBordered:NO];
+ [field setDrawsBackground:NO];
+ [field setFont:[NSFont systemFontOfSize:0]];
+ [[field cell] setControlSize:NSRegularControlSize];
+ [field setAutoresizingMask:NSViewNotSizable];
+ return field;
+ }
+ case EXTENSION_WIDGET_TEXT_FIELD:
+ {
+ VLCDialogTextField *field = [[VLCDialogTextField alloc] init];
+ [field setWidget:widget];
+ [field setAutoresizingMask:NSViewWidthSizable];
+ [field setFont:[NSFont systemFontOfSize:0]];
+ [[field cell] setControlSize:NSRegularControlSize];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(syncTextField:) name:NSControlTextDidChangeNotification object:field];
+ return field;
+ }
+ case EXTENSION_WIDGET_BUTTON:
+ {
+ VLCDialogButton *button = [[VLCDialogButton alloc] init];
+ [button setBezelStyle:NSRoundedBezelStyle];
+ [button setWidget:widget];
+ [button setAction:@selector(triggerClick:)];
+ [button setTarget:self];
+ [[button cell] setControlSize:NSRegularControlSize];
+ [button setAutoresizingMask:NSViewNotSizable];
+ return button;
+ }
+ case EXTENSION_WIDGET_DROPDOWN:
+ {
+ VLCDialogPopUpButton *popup = [[VLCDialogPopUpButton alloc] init];
+ [popup setAction:@selector(popUpSelectionChanged:)];
+ [popup setTarget:self];
+ [popup setWidget:widget];
+ return popup;
+ }
+ case EXTENSION_WIDGET_LIST:
+ {
+ NSScrollView *scrollView = [[NSScrollView alloc] init];
+ [scrollView setHasVerticalScroller:YES];
+ VLCDialogList *list = [[VLCDialogList alloc] init];
+ [list setUsesAlternatingRowBackgroundColors:YES];
+ [list setHeaderView:nil];
+ [scrollView setDocumentView:list];
+ [scrollView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+
+ NSTableColumn *column = [[NSTableColumn alloc] init];
+ [list addTableColumn:column];
+ [column release];
+ [list setDataSource:list];
+ [list setDelegate:self];
+ [list setWidget:widget];
+ [list release];
+ return scrollView;
+ }
+ case EXTENSION_WIDGET_IMAGE:
+ {
+ NSImageView *imageView = [[NSImageView alloc] init];
+ [imageView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+ [imageView setImageFrameStyle:NSImageFramePhoto];
+ [imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
+ return imageView;
+ }
+ case EXTENSION_WIDGET_SPIN_ICON:
+ {
+ NSProgressIndicator *spinner = [[NSProgressIndicator alloc] init];
+ [spinner setUsesThreadedAnimation:YES];
+ [spinner setStyle:NSProgressIndicatorSpinningStyle];
+ [spinner setDisplayedWhenStopped:YES];
+ [spinner startAnimation:self];
+ return spinner;
+ }
+ default:
+ return nil;
+ }
+
+}
+
+static void updateControlFromWidget(NSView *control, extension_widget_t *widget, id self)
+{
+ switch (widget->type)
+ {
+ case EXTENSION_WIDGET_HTML:
+// {
+// // Get the scroll view
+// assert([control isKindOfClass:[NSScrollView class]]);
+// NSScrollView *scrollView = (NSScrollView *)control;
+// control = [scrollView documentView];
+//
+// assert([control isKindOfClass:[NSTextView class]]);
+// NSTextView *textView = (NSTextView *)control;
+// NSString *string = [NSString stringWithUTF8String:widget->psz_text];
+// NSAttributedString *attrString = [[NSAttributedString alloc] initWithHTML:[string dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:NULL];
+// [[textView textStorage] setAttributedString:[[NSAttributedString alloc] initWithString:@"Hello"]];
+// [textView setNeedsDisplay:YES];
+// [textView scrollRangeToVisible:NSMakeRange(0, 0)];
+// [attrString release];
+// break;
+//
+// }
+ {
+ assert([control isKindOfClass:[NSTextView class]]);
+ NSTextView *textView = (NSTextView *)control;
+ NSString *string = [NSString stringWithUTF8String:widget->psz_text];
+ NSAttributedString *attrString = [[NSAttributedString alloc] initWithHTML:[string dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:NULL];
+ [[textView textStorage] setAttributedString:attrString];
+ [textView setNeedsDisplay:YES];
+ [textView scrollRangeToVisible:NSMakeRange(0, 0)];
+ [attrString release];
+ break;
+
+ }
+ case EXTENSION_WIDGET_LABEL:
+ case EXTENSION_WIDGET_PASSWORD:
+ case EXTENSION_WIDGET_TEXT_FIELD:
+ {
+ if (!widget->psz_text)
+ break;
+ assert([control isKindOfClass:[NSControl class]]);
+ NSControl *field = (NSControl *)control;
+ NSString *string = [NSString stringWithUTF8String:widget->psz_text];
+ NSAttributedString *attrString = [[NSAttributedString alloc] initWithHTML:[string dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:NULL];
+ [field setAttributedStringValue:attrString];
+ [attrString release];
+ break;
+ }
+ case EXTENSION_WIDGET_CHECK_BOX:
+ case EXTENSION_WIDGET_BUTTON:
+ {
+ assert([control isKindOfClass:[NSButton class]]);
+ NSButton *button = (NSButton *)control;
+ if (!widget->psz_text)
+ break;
+ [button setTitle:[NSString stringWithUTF8String:widget->psz_text]];
+ break;
+ }
+ case EXTENSION_WIDGET_DROPDOWN:
+ {
+ assert([control isKindOfClass:[NSPopUpButton class]]);
+ NSPopUpButton *popup = (NSPopUpButton *)control;
+ [popup removeAllItems];
+ struct extension_widget_value_t *value;
+ for(value = widget->p_values; value != NULL; value = value->p_next)
+ {
+ [popup addItemWithTitle:[NSString stringWithUTF8String:value->psz_text]];
+ }
+ [popup synchronizeTitleAndSelectedItem];
+ [self popUpSelectionChanged:popup];
+ break;
+ }
+
+ case EXTENSION_WIDGET_LIST:
+ {
+ assert([control isKindOfClass:[NSScrollView class]]);
+ NSScrollView *scrollView = (NSScrollView *)control;
+ assert([[scrollView documentView] isKindOfClass:[VLCDialogList class]]);
+ VLCDialogList *list = (VLCDialogList *)[scrollView documentView];
+
+ NSMutableArray *contentArray = [NSMutableArray array];
+ struct extension_widget_value_t *value;
+ for(value = widget->p_values; value != NULL; value = value->p_next)
+ {
+ NSDictionary *entry = [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithInt:value->i_id], @"id",
+ [NSString stringWithUTF8String:value->psz_text], @"text",
+ nil];
+ [contentArray addObject:entry];
+ }
+ list.contentArray = contentArray;
+ [list reloadData];
+ break;
+ }
+ case EXTENSION_WIDGET_IMAGE:
+ {
+ assert([control isKindOfClass:[NSImageView class]]);
+ NSImageView *imageView = (NSImageView *)control;
+ NSString *string = widget->psz_text ? [NSString stringWithUTF8String:widget->psz_text] : nil;
+ NSImage *image = nil;
+ if (string)
+ image = [[NSImage alloc] initWithContentsOfURL:[NSURL fileURLWithPath:string]];
+ [imageView setImage:image];
+ [image release];
+ break;
+ }
+ case EXTENSION_WIDGET_SPIN_ICON:
+ {
+ assert([control isKindOfClass:[NSProgressIndicator class]]);
+ NSProgressIndicator *progressIndicator = (NSProgressIndicator *)control;
+ if( widget->i_spin_loops != 0 )
+ [progressIndicator startAnimation:self];
+ else
+ [progressIndicator stopAnimation:self];
+ break;
+ }
+ }
+
+}
+
+/**
+ * Ask the dialogs provider to create a new dialog
+ **/
+static int dialogCallback( vlc_object_t *p_this, const char *psz_variable,
+ vlc_value_t old_val, vlc_value_t new_val,
+ void *param )
+{
+ (void) p_this;
+ (void) psz_variable;
+ (void) old_val;
+ (void) param;
+
+ ExtensionsDialogProvider *p_edp = [ExtensionsDialogProvider sharedInstance:(intf_thread_t *)p_this];
+ if( !p_edp )
+ return VLC_EGENERIC;
+ if( !new_val.p_address )
+ return VLC_EGENERIC;
+
+ extension_dialog_t *p_dialog = ( extension_dialog_t* ) new_val.p_address;
+ [p_edp manageDialog:p_dialog];
+ return VLC_SUCCESS;
+}
+
+ at implementation ExtensionsDialogProvider
+
+static ExtensionsDialogProvider *_o_sharedInstance = nil;
+
++ (ExtensionsDialogProvider *)sharedInstance:(intf_thread_t *)_p_intf
+{
+ return _o_sharedInstance ? _o_sharedInstance : [[self alloc] initWithIntf:_p_intf];
+}
+
++ (void)killInstance
+{
+ if (_o_sharedInstance)
+ {
+ [_o_sharedInstance release];
+ }
+}
+
+- (id)initWithIntf:(intf_thread_t *)_p_intf
+{
+ if( _o_sharedInstance )
+ [self dealloc];
+
+ if ((self = [super init]))
+ {
+ _o_sharedInstance = self;
+ p_intf = _p_intf;
+
+ // The Cocoa interface already called dialog_Register()
+ var_Create( p_intf, "dialog-extension", VLC_VAR_ADDRESS );
+ var_AddCallback( p_intf, "dialog-extension", dialogCallback, NULL );
+ }
+
+ return _o_sharedInstance;
+}
+
+- (void)dealloc
+{
+ msg_Dbg( p_intf, "ExtensionsDialogProvider is quitting..." );
+ var_DelCallback( p_intf, "dialog-extension", dialogCallback, NULL );
+
+ [super dealloc];
+}
+
+- (void)performEventWithObject: (NSValue *)o_value ofType: (const char*)type
+{
+ NSString *o_type = [NSString stringWithUTF8String:type];
+
+ if( [o_type isEqualToString: @"dialog-extension"] )
+ {
+ [self performSelectorOnMainThread:@selector(updateExtensionDialog:)
+ withObject:o_value
+ waitUntilDone:YES];
+
+ }
+ else
+ msg_Err( VLCIntf, "unhandled dialog type: '%s'", type );
+}
+
+- (void)triggerClick:(id)sender
+{
+ assert([sender isKindOfClass:[VLCDialogButton class]]);
+ VLCDialogButton *button = sender;
+ extension_widget_t *widget = [button widget];
+
+ vlc_mutex_lock(&widget->p_dialog->lock);
+ extension_WidgetClicked(widget->p_dialog, widget);
+ vlc_mutex_unlock(&widget->p_dialog->lock);
+}
+
+- (void)syncTextField:(NSNotification *)notifcation
+{
+ id sender = [notifcation object];
+ assert([sender isKindOfClass:[VLCDialogTextField class]]);
+ VLCDialogTextField *field = sender;
+ extension_widget_t *widget = [field widget];
+
+ vlc_mutex_lock(&widget->p_dialog->lock);
+ free(widget->psz_text);
+ widget->psz_text = strdup([[field stringValue] UTF8String]);
+ vlc_mutex_unlock(&widget->p_dialog->lock);
+}
+
+- (void)tableViewSelectionDidChange:(NSNotification *)notifcation
+{
+ id sender = [notifcation object];
+ assert(sender && [sender isKindOfClass:[VLCDialogList class]]);
+ VLCDialogList *list = sender;
+
+ struct extension_widget_value_t *value;
+ unsigned i = 0;
+ for(value = [list widget]->p_values; value != NULL; value = value->p_next, i++)
+ value->b_selected = (i == [list selectedRow]);
+}
+
+- (void)popUpSelectionChanged:(id)sender
+{
+ assert([sender isKindOfClass:[VLCDialogPopUpButton class]]);
+ VLCDialogPopUpButton *popup = sender;
+ struct extension_widget_value_t *value;
+ unsigned i = 0;
+ for(value = [popup widget]->p_values; value != NULL; value = value->p_next, i++)
+ value->b_selected = (i == [popup indexOfSelectedItem]);
+
+}
+
+- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
+{
+ NSView *contentView = [sender contentView];
+ assert([contentView isKindOfClass:[VLCDialogGridView class]]);
+ VLCDialogGridView *gridView = (VLCDialogGridView *)contentView;
+
+ NSRect rect = NSMakeRect(0, 0, 0, 0);
+ rect.size = frameSize;
+ rect = [sender contentRectForFrameRect:rect];
+ rect.size = [gridView flexSize:rect.size];
+ rect = [sender frameRectForContentRect:rect];
+ return rect.size;
+}
+
+- (BOOL)windowShouldClose:(id)sender
+{
+ assert([sender isKindOfClass:[VLCDialogWindow class]]);
+ VLCDialogWindow *window = sender;
+ extension_dialog_t *dialog = [window dialog];
+ extension_DialogClosed(dialog);
+ dialog->p_sys_intf = NULL;
+ return YES;
+}
+
+- (void)updateWidgets:(extension_dialog_t *)dialog
+{
+ extension_widget_t *widget;
+ VLCDialogWindow *dialogWindow = dialog->p_sys_intf;
+
+ FOREACH_ARRAY(widget, dialog->widgets)
+ {
+ if (!widget)
+ continue; /* Some widgets may be NULL at this point */
+
+ BOOL shouldDestroy = widget->b_kill;
+ NSView *control = widget->p_sys_intf;
+ BOOL update = widget->b_update;
+
+ if (!control && !shouldDestroy)
+ {
+ control = createControlFromWidget(widget, self);
+ updateControlFromWidget(control, widget, self);
+ widget->p_sys_intf = control;
+ update = YES; // Force update and repositionning
+ [control setHidden:widget->b_hide];
+ }
+
+ if (update && !shouldDestroy)
+ {
+ updateControlFromWidget(control, widget, self);
+ [control setHidden:widget->b_hide];
+
+ int row = widget->i_row - 1;
+ int col = widget->i_column - 1;
+ int hsp = __MAX( 1, widget->i_horiz_span );
+ int vsp = __MAX( 1, widget->i_vert_span );
+ if( row < 0 )
+ {
+ row = 4;
+ col = 0;
+ }
+
+ VLCDialogGridView *gridView = (VLCDialogGridView *)[dialogWindow contentView];
+ [gridView addSubview:control atRow:row column:col rowSpan:vsp colSpan:hsp];
+
+ widget->b_update = false;
+ }
+
+ if (shouldDestroy)
+ {
+ VLCDialogGridView *gridView = (VLCDialogGridView *)[dialogWindow contentView];
+ [gridView removeSubview:control];
+ [control release];
+ widget->p_sys_intf = NULL;
+ }
+ }
+ FOREACH_END()
+}
+
+/** Create a dialog
+ * Note: Lock on p_dialog->lock must be held. */
+- (VLCDialogWindow *)createExtensionDialog:(extension_dialog_t *)p_dialog
+{
+ VLCDialogWindow *dialogWindow = nil;
+
+ BOOL shouldDestroy = p_dialog->b_kill;
+ if (!shouldDestroy)
+ {
+ NSRect content = NSMakeRect(0, 0, 1, 1);
+ dialogWindow = [[VLCDialogWindow alloc] initWithContentRect:content
+ styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ [dialogWindow setDelegate:self];
+ [dialogWindow setDialog:p_dialog];
+ [dialogWindow setTitle:[NSString stringWithUTF8String:p_dialog->psz_title]];
+
+ VLCDialogGridView *gridView = [[VLCDialogGridView alloc] init];
+ [gridView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+ [dialogWindow setContentView:gridView];
+ [gridView release];
+
+ p_dialog->p_sys_intf = (void *)dialogWindow;
+ }
+
+ [self updateWidgets:p_dialog];
+
+ if (shouldDestroy)
+ {
+ [dialogWindow setDelegate:nil];
+ [dialogWindow close];
+ p_dialog->p_sys_intf = NULL;
+ dialogWindow = nil;
+ }
+
+ return dialogWindow;
+}
+
+/** Destroy a dialog
+ * Note: Lock on p_dialog->lock must be held. */
+- (int)destroyExtensionDialog:(extension_dialog_t *)p_dialog
+{
+ assert( p_dialog );
+
+ VLCDialogWindow *dialogWindow = ( VLCDialogWindow* ) p_dialog->p_sys_intf;
+ if( !dialogWindow )
+ return VLC_EGENERIC;
+
+ [VLCDialogWindow release];
+
+ p_dialog->p_sys_intf = NULL;
+ vlc_cond_signal( &p_dialog->cond );
+ return VLC_SUCCESS;
+}
+
+/**
+ * Update/Create/Destroy a dialog
+ **/
+- (VLCDialogWindow *)updateExtensionDialog:(NSValue *)o_value
+{
+ extension_dialog_t *p_dialog = [o_value pointerValue];
+
+ VLCDialogWindow *dialogWindow = ( VLCDialogWindow* ) p_dialog->p_sys_intf;
+ if( p_dialog->b_kill && !dialogWindow )
+ {
+ /* This extension could not be activated properly but tried
+ to create a dialog. We must ignore it. */
+ return NULL;
+ }
+
+ vlc_mutex_lock(&p_dialog->lock);
+ if( !p_dialog->b_kill && !dialogWindow )
+ {
+ dialogWindow = [self createExtensionDialog:p_dialog];
+
+ BOOL visible = !p_dialog->b_hide;
+ if (visible)
+ {
+ [dialogWindow center];
+ [dialogWindow makeKeyAndOrderFront:self];
+ }
+ else
+ {
+ [dialogWindow orderOut:nil];
+ }
+
+ [dialogWindow setHas_lock:NO];
+ }
+ else if( !p_dialog->b_kill && dialogWindow )
+ {
+ [dialogWindow setHas_lock:YES];
+ [self updateWidgets:p_dialog];
+ if( strcmp( [[dialogWindow title] UTF8String],
+ p_dialog->psz_title ) != 0 )
+ {
+ NSString *titleString = [NSString stringWithCString:p_dialog->psz_title
+ encoding:NSASCIIStringEncoding];
+
+ [dialogWindow setTitle:titleString];
+ }
+
+ [dialogWindow setHas_lock:NO];
+
+ BOOL visible = !p_dialog->b_hide;
+ if (visible)
+ {
+ [dialogWindow center];
+ [dialogWindow makeKeyAndOrderFront:self];
+ }
+ else
+ {
+ [dialogWindow orderOut:nil];
+ }
+ }
+ else if( p_dialog->b_kill )
+ {
+ [self destroyExtensionDialog:p_dialog];
+ }
+ vlc_cond_signal( &p_dialog->cond );
+ vlc_mutex_unlock( &p_dialog->lock );
+ return dialogWindow;
+}
+
+/**
+ * Ask the dialog manager to create/update/kill the dialog. Thread-safe.
+ **/
+- (void)manageDialog:( extension_dialog_t *)p_dialog
+{
+ assert( p_dialog );
+ ExtensionsManager *extMgr = [ExtensionsManager getInstance:p_intf];
+ assert( extMgr != NULL );
+
+ NSValue *o_value = [NSValue valueWithPointer:p_dialog];
+ [self performSelectorOnMainThread:@selector(updateExtensionDialog:)
+ withObject:o_value
+ waitUntilDone:YES];
+}
+
+ at end
diff --git a/modules/gui/macosx/ExtensionsManager.h b/modules/gui/macosx/ExtensionsManager.h
new file mode 100644
index 0000000..a6c97a7
--- /dev/null
+++ b/modules/gui/macosx/ExtensionsManager.h
@@ -0,0 +1,75 @@
+/*****************************************************************************
+ * extensions_manager.h: Extensions manager for Cocoa
+ ****************************************************************************
+ * Copyright (C) 2012 VideoLAN and authors
+ * $Id$
+ *
+ * Authors: Brendon Justin <brendonjustin at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#import "ExtensionsDialogProvider.h"
+#import "intf.h"
+
+#import <vlc_extensions.h>
+
+#import <Cocoa/Cocoa.h>
+
+ at class ExtensionsDialogProvider;
+
+ at protocol ExtensionsDelegate <NSObject>
+- (void)extensionsUpdated;
+ at end
+
+ at interface ExtensionsManager : NSObject
+{
+ intf_thread_t *p_intf;
+ extensions_manager_t *p_extensions_manager;
+ ExtensionsDialogProvider *p_edp;
+
+ NSMutableDictionary *p_extDict;
+
+ BOOL b_unloading; ///< Work around threads + emit issues, see isUnloading
+ BOOL b_failed; ///< Flag set to true if we could not load the module
+
+ id <ExtensionsDelegate> delegate;
+};
+
++ (ExtensionsManager *)getInstance:(intf_thread_t *)_p_intf;
+
+- (id)initWithIntf:(intf_thread_t *)_p_intf;
+- (void)buildMenu:(NSMenu *)extMenu;
+- (extensions_manager_t *)getManager;
+
+- (BOOL)loadExtensions;
+- (void)unloadExtensions;
+- (void)reloadExtensions;
+
+- (void)triggerMenu:(id)sender;
+- (void)inputChanged:(input_thread_t *)p_input;
+- (void)playingChanged:(int)state;
+- (void)metaChanged:(input_item_t *)p_input;
+
+- (BOOL)isLoaded;
+- (BOOL)cannotLoad;
+
+ at property (readonly) BOOL isUnloading;
+
+ at end
diff --git a/modules/gui/macosx/ExtensionsManager.m b/modules/gui/macosx/ExtensionsManager.m
new file mode 100644
index 0000000..2380806
--- /dev/null
+++ b/modules/gui/macosx/ExtensionsManager.m
@@ -0,0 +1,372 @@
+/*****************************************************************************
+ * extensions_manager.cpp: Extensions manager for Cocoa
+ ****************************************************************************
+ * Copyright (C) 2012 VideoLAN and authors
+ * $Id$
+ *
+ * Authors: Brendon Justin <brendonjustin at gmail.com>,
+ * Jean-Philippe André < jpeg # videolan.org >
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "ExtensionsManager.h"
+
+#import "ExtensionsDialogProvider.h"
+
+#import <vlc_modules.h>
+#import "assert.h"
+
+#define MENU_MAP(a,e) ((uint32_t)( (((uint16_t)a) << 16) | ((uint16_t)e) ))
+#define MENU_GET_ACTION(a) ( (uint16_t)( ((uint32_t)a) >> 16 ) )
+#define MENU_GET_EXTENSION(a) ( (uint16_t)( ((uint32_t)a) & 0xFFFF ) )
+
+ at implementation ExtensionsManager
+
+static ExtensionsManager* instance = nil;
+
+ at synthesize isUnloading = b_unloading;
+
++ (ExtensionsManager *)getInstance:( intf_thread_t *)_p_intf
+{
+ if( !instance )
+ instance = [[[ExtensionsManager alloc] initWithIntf:_p_intf] autorelease];
+ return instance;
+}
+
+- (id)initWithIntf:(intf_thread_t *)_p_intf
+{
+ if ((self = [super init]))
+ {
+ p_intf = _p_intf;
+ p_extensions_manager = NULL;
+ p_edp = NULL;
+
+ p_extDict = [[NSMutableDictionary alloc] init];
+
+ b_unloading = false;
+ b_failed = false;
+
+ delegate = nil;
+ }
+
+ return self;
+}
+
+/** Get the extensions_manager_t if it is loaded and hold the object */
+- (extensions_manager_t *)getManager
+{
+ if( !p_extensions_manager )
+ return NULL;
+
+ vlc_object_hold( p_extensions_manager );
+ return p_extensions_manager;
+}
+
+- (void)buildMenu:(NSMenu *)extMenu
+{
+ assert( extMenu != nil );
+ if( ![self isLoaded] )
+ {
+ // This case can happen: do nothing
+ return;
+ }
+
+ vlc_mutex_lock( &p_extensions_manager->lock );
+
+ extension_t *p_ext = NULL;
+ int i_ext = 0;
+ FOREACH_ARRAY( p_ext, p_extensions_manager->extensions )
+ {
+ bool b_Active = extension_IsActivated( p_extensions_manager, p_ext );
+
+ NSString *titleString = [NSString stringWithCString:p_ext->psz_title
+ encoding:NSASCIIStringEncoding];
+
+ if( b_Active && extension_HasMenu( p_extensions_manager, p_ext ) )
+ {
+ NSMenu *submenu = [[NSMenu alloc] initWithTitle:titleString];
+ NSMenuItem *submenuItem = [extMenu addItemWithTitle:titleString
+ action:nil
+ keyEquivalent:@""];
+
+ [extMenu setSubmenu:submenu forItem:submenuItem];
+ [submenu release];
+
+ char **ppsz_titles = NULL;
+ uint16_t *pi_ids = NULL;
+ size_t i_num = 0;
+
+ if( extension_GetMenu( p_extensions_manager, p_ext,
+ &ppsz_titles, &pi_ids ) == VLC_SUCCESS )
+ {
+ for( int i = 0; ppsz_titles[i] != NULL; ++i )
+ {
+ ++i_num;
+ titleString = [NSString stringWithCString:ppsz_titles[i]
+ encoding:NSASCIIStringEncoding];
+ NSMenuItem *menuItem = [submenu addItemWithTitle:titleString
+ action:@selector(triggerMenu:)
+ keyEquivalent:@""];
+ [menuItem setTarget:self];
+ menuItem.tag = MENU_MAP(pi_ids[i], i_ext);
+
+ free( ppsz_titles[i] );
+ }
+ if( !i_num )
+ {
+ NSMenuItem *menuItem = [submenu addItemWithTitle:@"Empty"
+ action:@selector(triggerMenu:)
+ keyEquivalent:@""];
+ [menuItem setEnabled:NO];
+ }
+ free( ppsz_titles );
+ free( pi_ids );
+ }
+ else
+ {
+ msg_Warn( p_intf, "Could not get menu for extension '%s'",
+ p_ext->psz_title );
+ NSMenuItem *menuItem = [submenu addItemWithTitle:@"Empty"
+ action:@selector(triggerMenu:)
+ keyEquivalent:@""];
+ [menuItem setEnabled:NO];
+ }
+
+ [submenu addItem:[NSMenuItem separatorItem]];
+
+ NSMenuItem *deactivateItem = [submenu addItemWithTitle:@"Deactivate"
+ action:@selector(triggerMenu:)
+ keyEquivalent:@""];
+ [deactivateItem setTarget:self];
+ deactivateItem.tag = MENU_MAP(0, i_ext);
+ }
+ else
+ {
+ NSMenuItem *menuItem = [extMenu addItemWithTitle:titleString
+ action:@selector(triggerMenu:)
+ keyEquivalent:@""];
+ [menuItem setTarget:self];
+
+ if( !extension_TriggerOnly( p_extensions_manager, p_ext ) )
+ {
+ if ( b_Active )
+ [menuItem setState:NSOnState];
+ }
+ menuItem.tag = MENU_MAP(0, i_ext);
+ }
+ i_ext++;
+ }
+ FOREACH_END()
+
+ vlc_mutex_unlock( &p_extensions_manager->lock );
+}
+
+- (BOOL)loadExtensions
+{
+ if( !p_extensions_manager )
+ {
+ p_extensions_manager = ( extensions_manager_t* )
+ vlc_object_create( p_intf, sizeof( extensions_manager_t ) );
+ if( !p_extensions_manager )
+ {
+ b_failed = true;
+ [delegate extensionsUpdated];
+ return false;
+ }
+
+ p_extensions_manager->p_module =
+ module_need( p_extensions_manager, "extension", NULL, false );
+
+ if( !p_extensions_manager->p_module )
+ {
+ msg_Err( p_intf, "Unable to load extensions module" );
+ vlc_object_release( p_extensions_manager );
+ p_extensions_manager = NULL;
+ b_failed = true;
+ [delegate extensionsUpdated];
+ return false;
+ }
+
+ /* Initialize dialog provider */
+ p_edp = [ExtensionsDialogProvider sharedInstance:p_intf];
+ [p_edp retain];
+
+ if( !p_edp )
+ {
+ msg_Err( p_intf, "Unable to create dialogs provider for extensions" );
+ module_unneed( p_extensions_manager,
+ p_extensions_manager->p_module );
+ vlc_object_release( p_extensions_manager );
+ p_extensions_manager = NULL;
+ b_failed = true;
+ [delegate extensionsUpdated];
+ return false;
+ }
+ b_unloading = false;
+ }
+ b_failed = false;
+ [delegate extensionsUpdated];
+ return true;
+}
+
+- (void)unloadExtensions
+{
+ if( !p_extensions_manager )
+ return;
+ b_unloading = true;
+ [p_edp release];
+ module_unneed( p_extensions_manager, p_extensions_manager->p_module );
+ vlc_object_release( p_extensions_manager );
+ p_extensions_manager = NULL;
+}
+
+- (void)reloadExtensions
+{
+ [self unloadExtensions];
+ [self loadExtensions];
+
+ if (delegate)
+ [delegate extensionsUpdated];
+}
+
+- (void)triggerMenu:(id)sender
+{
+ uint32_t identifier = [(NSMenuItem *)sender tag];
+
+ uint16_t i_ext = MENU_GET_EXTENSION( identifier );
+ uint16_t i_action = MENU_GET_ACTION( identifier );
+
+ vlc_mutex_lock( &p_extensions_manager->lock );
+
+ if( (int) i_ext > p_extensions_manager->extensions.i_size )
+ {
+ msg_Dbg( p_intf, "can't trigger extension with wrong id %d",
+ (int) i_ext );
+ return;
+ }
+
+ extension_t *p_ext = ARRAY_VAL( p_extensions_manager->extensions, i_ext );
+ assert( p_ext != NULL);
+
+ vlc_mutex_unlock( &p_extensions_manager->lock );
+
+ if( i_action == 0 )
+ {
+ msg_Dbg( p_intf, "activating or triggering extension '%s', id %d",
+ p_ext->psz_title, i_ext );
+
+ if( extension_TriggerOnly( p_extensions_manager, p_ext ) )
+ {
+ extension_Trigger( p_extensions_manager, p_ext );
+ }
+ else
+ {
+ if( !extension_IsActivated( p_extensions_manager, p_ext ) )
+ extension_Activate( p_extensions_manager, p_ext );
+ else
+ extension_Deactivate( p_extensions_manager, p_ext );
+ }
+ }
+ else
+ {
+ msg_Dbg( p_intf, "triggering extension '%s', on menu with id = 0x%x",
+ p_ext->psz_title, i_action );
+
+ extension_TriggerMenu( p_extensions_manager, p_ext, i_action );
+ }
+}
+
+- (void)inputChanged:(input_thread_t *)p_input
+{
+ //This is unlikely, but can happen if no extension modules can be loaded.
+ if ( p_extensions_manager == NULL )
+ return ;
+ vlc_mutex_lock( &p_extensions_manager->lock );
+
+ extension_t *p_ext;
+ FOREACH_ARRAY( p_ext, p_extensions_manager->extensions )
+ {
+ if( extension_IsActivated( p_extensions_manager, p_ext ) )
+ {
+ extension_SetInput( p_extensions_manager, p_ext, p_input );
+ }
+ }
+ FOREACH_END()
+
+ vlc_mutex_unlock( &p_extensions_manager->lock );
+}
+
+- (void)playingChanged:(int)state
+{
+ //This is unlikely, but can happen if no extension modules can be loaded.
+ if ( p_extensions_manager == NULL )
+ return ;
+ vlc_mutex_lock( &p_extensions_manager->lock );
+
+ extension_t *p_ext;
+ FOREACH_ARRAY( p_ext, p_extensions_manager->extensions )
+ {
+ if( extension_IsActivated( p_extensions_manager, p_ext ) )
+ {
+ extension_PlayingChanged( p_extensions_manager, p_ext, state );
+ }
+ }
+ FOREACH_END()
+
+ vlc_mutex_unlock( &p_extensions_manager->lock );
+}
+
+- (void)metaChanged:(input_item_t *)p_input
+{
+ //This is unlikely, but can happen if no extension modules can be loaded.
+ if ( p_extensions_manager == NULL )
+ return ;
+ vlc_mutex_lock( &p_extensions_manager->lock );
+ extension_t *p_ext;
+ FOREACH_ARRAY( p_ext, p_extensions_manager->extensions )
+ {
+ if( extension_IsActivated( p_extensions_manager, p_ext ) )
+ {
+ extension_MetaChanged( p_extensions_manager, p_ext );
+ }
+ }
+ FOREACH_END()
+ vlc_mutex_unlock( &p_extensions_manager->lock );
+}
+
+- (void)dealloc
+{
+ msg_Dbg( p_intf, "Killing extension dialog provider" );
+ [ExtensionsDialogProvider killInstance];
+
+ vlc_object_release( p_extensions_manager );
+
+ [p_extDict release];
+
+ [super dealloc];
+}
+
+- (BOOL)isLoaded
+{
+ return p_extensions_manager != NULL;
+}
+
+- (BOOL)cannotLoad
+{
+ return b_unloading || b_failed;
+}
+
+ at end
diff --git a/modules/gui/macosx/Modules.am b/modules/gui/macosx/Modules.am
index 5749490..41dfc67 100644
--- a/modules/gui/macosx/Modules.am
+++ b/modules/gui/macosx/Modules.am
@@ -17,6 +17,16 @@ SOURCES_macosx = \
MainWindow.m \
CoreInteraction.h \
CoreInteraction.m \
+ ExtensionsManager.h \
+ ExtensionsManager.m \
+ ExtensionsDialogProvider.h \
+ ExtensionsDialogProvider.m \
+ VLCLoginPanel.h \
+ VLCLoginPanel.m \
+ VLCProgressPanel.h \
+ VLCProgressPanel.m \
+ VLCUIWidgets.h \
+ VLCUIWidgets.m \
about.h \
about.m \
applescript.h \
diff --git a/modules/gui/macosx/VLCLoginPanel.h b/modules/gui/macosx/VLCLoginPanel.h
new file mode 100644
index 0000000..8b93835
--- /dev/null
+++ b/modules/gui/macosx/VLCLoginPanel.h
@@ -0,0 +1,48 @@
+/*****************************************************************************
+ * VLCLoginPanel.h: A Generic Login Panel created for VLC
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface VLCLoginPanel : NSPanel {
+ IBOutlet NSButton * _cancelButton;
+ IBOutlet NSButton * _okayButton;
+ IBOutlet NSTextField * _userNameLabel;
+ IBOutlet NSTextField * _userNameField;
+ IBOutlet NSTextField * _passwordLabel;
+ IBOutlet NSSecureTextField * _passwordField;
+ IBOutlet NSTextField * _titleField;
+ IBOutlet NSTextField * _informativeTextField;
+ IBOutlet NSImageView * _iconView;
+}
+
+- (IBAction)buttonAction:(id)sender;
+- (void)createContentView;
+
+- (void)setDialogTitle:(NSString *)title;
+- (void)setDialogMessage:(NSString *)message;
+
+- (NSString *)userName;
+- (NSString *)password;
+
+ at end
diff --git a/modules/gui/macosx/VLCLoginPanel.m b/modules/gui/macosx/VLCLoginPanel.m
new file mode 100644
index 0000000..3658665
--- /dev/null
+++ b/modules/gui/macosx/VLCLoginPanel.m
@@ -0,0 +1,183 @@
+/*****************************************************************************
+ * VLCLoginPanel.m: A Generic Login Panel created for VLC
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCLoginPanel.h"
+
+
+ at implementation VLCLoginPanel
+
+- (id)init
+{
+ NSRect windowRect;
+ windowRect.size.height = 278;
+ windowRect.size.width = 505;
+ windowRect.origin.x = windowRect.origin.y = 0;
+
+ return [super initWithContentRect:windowRect
+ styleMask:NSTitledWindowMask
+ backing:NSBackingStoreBuffered
+ defer:YES];
+}
+
+- (void)createContentView
+{
+ NSRect s_rc = [self frame];
+ id ourContentView = [self contentView];
+
+ s_rc.origin.x = 275;
+ s_rc.origin.y = 44;
+ s_rc.size.height = 32;
+ s_rc.size.width = 108;
+ _cancelButton = [[NSButton alloc] initWithFrame:s_rc];
+ [_cancelButton setButtonType:NSMomentaryLightButton];
+ [_cancelButton setTitle:@"Cancel"];
+ [_cancelButton setBezelStyle:NSRoundedBezelStyle];
+ [_cancelButton setBordered:YES];
+ [_cancelButton setTarget:self];
+ [_cancelButton setAction:@selector(buttonAction:)];
+ [_cancelButton setKeyEquivalent:@"\e"] ; // escape key
+ [ourContentView addSubview:_cancelButton];
+
+ s_rc.origin.x = 383;
+ s_rc.origin.y = 44;
+ s_rc.size.height = 32;
+ s_rc.size.width = 108;
+ _okayButton = [[NSButton alloc] initWithFrame:s_rc];
+ [_okayButton setButtonType:NSMomentaryLightButton];
+ [_okayButton setTitle:@"OK"];
+ [_okayButton setBezelStyle:NSRoundedBezelStyle];
+ [_okayButton setBordered:YES];
+ [_okayButton setTarget:self];
+ [_okayButton setAction:@selector(buttonAction:)];
+ [_okayButton setKeyEquivalent:@"\r"] ; // enter key
+ [ourContentView addSubview:_okayButton];
+
+ s_rc.origin.x = 94;
+ s_rc.origin.y = 170;
+ s_rc.size.height = 14;
+ s_rc.size.width = 129;
+ _userNameLabel = [[NSTextField alloc] initWithFrame:s_rc];
+ [_userNameLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ [_userNameLabel setStringValue:@"User Name"];
+ [_userNameLabel setBezeled:NO];
+ [_userNameLabel setEditable:NO];
+ [_userNameLabel setSelectable:NO];
+ [_userNameLabel setDrawsBackground:NO];
+ [ourContentView addSubview:_userNameLabel];
+
+ s_rc.origin.x = 97;
+ s_rc.origin.y = 148;
+ s_rc.size.height = 22;
+ s_rc.size.width = 310;
+ _userNameField = [[NSTextField alloc] initWithFrame:s_rc];
+ [_userNameField setBezeled:YES];
+ [_userNameField setEditable:YES];
+ [_userNameField setImportsGraphics:NO];
+ [ourContentView addSubview:_userNameField];
+
+ s_rc.origin.x = 94;
+ s_rc.origin.y = 116;
+ s_rc.size.height = 14;
+ s_rc.size.width = 129;
+ _passwordLabel = [[NSTextField alloc] initWithFrame:s_rc];
+ [_passwordLabel setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ [_passwordLabel setStringValue:@"Password"];
+ [_passwordLabel setBezeled:NO];
+ [_passwordLabel setEditable:NO];
+ [_passwordLabel setSelectable:NO];
+ [_passwordLabel setDrawsBackground:NO];
+ [ourContentView addSubview:_passwordLabel];
+
+ s_rc.origin.x = 97;
+ s_rc.origin.y = 94;
+ s_rc.size.height = 22;
+ s_rc.size.width = 310;
+ _passwordField = [[NSSecureTextField alloc] initWithFrame:s_rc];
+ [_passwordField setBezeled:YES];
+ [_passwordField setEditable:YES];
+ [_passwordField setImportsGraphics:NO];
+ [ourContentView addSubview:_passwordField];
+
+ s_rc.origin.x = 94;
+ s_rc.origin.y = 238;
+ s_rc.size.height = 17;
+ s_rc.size.width = 316;
+ _titleField = [[NSTextField alloc] initWithFrame:s_rc];
+ [_titleField setFont:[NSFont boldSystemFontOfSize:0]];
+ [_titleField setBezeled:NO];
+ [_titleField setEditable:NO];
+ [_titleField setSelectable:YES];
+ [_titleField setDrawsBackground:NO];
+ [ourContentView addSubview:_titleField];
+
+ s_rc.origin.x = 94;
+ s_rc.origin.y = 183;
+ s_rc.size.height = 44;
+ s_rc.size.width = 394;
+ _informativeTextField = [[NSTextField alloc] initWithFrame:s_rc];
+ [_informativeTextField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ [_informativeTextField setBezeled:NO];
+ [_informativeTextField setEditable:NO];
+ [_informativeTextField setSelectable:YES];
+ [_informativeTextField setDrawsBackground:NO];
+ [ourContentView addSubview:_informativeTextField];
+
+ s_rc.origin.x = 20;
+ s_rc.origin.y = 188;
+ s_rc.size.height = s_rc.size.width = 64;
+ _iconView = [[NSImageView alloc] initWithFrame:s_rc];
+ [_iconView setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
+ [_iconView setEditable:NO];
+ [_iconView setAllowsCutCopyPaste:NO];
+ [ourContentView addSubview:_iconView];
+}
+
+- (IBAction)buttonAction:(id)sender
+{
+ if (sender == _okayButton)
+ [NSApp stopModalWithCode: 1];
+ else
+ [NSApp stopModalWithCode: 0];
+}
+
+- (void)setDialogTitle:(NSString *)title
+{
+ [_titleField setStringValue:title];
+ [self setTitle:title];
+}
+- (void)setDialogMessage:(NSString *)message
+{
+ [_informativeTextField setStringValue:message];
+}
+
+- (NSString *)userName
+{
+ return [_userNameField stringValue];
+}
+
+- (NSString *)password
+{
+ return [_passwordField stringValue];
+}
+
+ at end
diff --git a/modules/gui/macosx/VLCProgressPanel.h b/modules/gui/macosx/VLCProgressPanel.h
new file mode 100644
index 0000000..0c1dde4
--- /dev/null
+++ b/modules/gui/macosx/VLCProgressPanel.h
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * VLCProgressPanel.h: A Generic Progress Indicator Panel created for VLC
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+
+
+ at interface VLCProgressPanel : NSPanel {
+ BOOL _isCancelled;
+
+ IBOutlet NSProgressIndicator * _progressBar;
+ IBOutlet NSTextField *_titleField;
+ IBOutlet NSTextField *_messageField;
+ IBOutlet NSButton *_cancelButton;
+ IBOutlet NSImageView *_iconView;
+}
+- (void)createContentView;
+
+- (void)setDialogTitle:(NSString *)title;
+- (void)setDialogMessage:(NSString *)message;
+- (void)setCancelButtonLabel:(NSString *)cancelLabel;
+- (void)setProgressAsDouble:(double)value;
+- (BOOL)isCancelled;
+
+- (IBAction)cancelDialog:(id)sender;
+
+ at end
diff --git a/modules/gui/macosx/VLCProgressPanel.m b/modules/gui/macosx/VLCProgressPanel.m
new file mode 100644
index 0000000..d06dbc7
--- /dev/null
+++ b/modules/gui/macosx/VLCProgressPanel.m
@@ -0,0 +1,142 @@
+/*****************************************************************************
+ * VLCProgressPanel.m: A Generic Progress Indicator Panel created for VLC
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne at videolan dot org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCProgressPanel.h"
+
+
+ at implementation VLCProgressPanel
+
+- (id)init
+{
+ NSRect windowRect;
+ windowRect.size.height = 182;
+ windowRect.size.width = 520;
+ windowRect.origin.x = windowRect.origin.y = 0;
+
+ return [super initWithContentRect:windowRect
+ styleMask:NSTitledWindowMask
+ backing:NSBackingStoreBuffered
+ defer:YES];
+}
+
+- (void)createContentView
+{
+ NSRect s_rc = [self frame];
+ id ourContentView = [self contentView];
+
+ s_rc.origin.x = 398;
+ s_rc.origin.y = 28;
+ s_rc.size.height = 32;
+ s_rc.size.width = 108;
+ _cancelButton = [[NSButton alloc] initWithFrame:s_rc];
+ [_cancelButton setButtonType:NSMomentaryLightButton];
+ [_cancelButton setTitle:@"Cancel"];
+ [_cancelButton setBezelStyle:NSRoundedBezelStyle];
+ [_cancelButton setBordered:YES];
+ [_cancelButton setTarget:self];
+ [_cancelButton setAction:@selector(cancelDialog:)];
+ [_cancelButton setKeyEquivalent:@"\e"] ; // escape key
+ [ourContentView addSubview:_cancelButton];
+
+ s_rc.origin.x = 89;
+ s_rc.origin.y = 153;
+ s_rc.size.height = 17;
+ s_rc.size.width = 414;
+ _titleField = [[NSTextField alloc] initWithFrame:s_rc];
+ [_titleField setFont:[NSFont boldSystemFontOfSize:0]];
+ [_titleField setBezeled:NO];
+ [_titleField setEditable:NO];
+ [_titleField setSelectable:YES];
+ [_titleField setDrawsBackground:NO];
+ [ourContentView addSubview:_titleField];
+
+ s_rc.origin.x = 89;
+ s_rc.origin.y = 116;
+ s_rc.size.height = 42;
+ s_rc.size.width = 414;
+ _messageField = [[NSTextField alloc] initWithFrame:s_rc];
+ [_messageField setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ [_messageField setBezeled:NO];
+ [_messageField setEditable:NO];
+ [_messageField setSelectable:YES];
+ [_messageField setDrawsBackground:NO];
+ [ourContentView addSubview:_messageField];
+
+ s_rc.origin.x = 90;
+ s_rc.origin.y = 66;
+ s_rc.size.height = 20;
+ s_rc.size.width = 412;
+ _progressBar = [[NSProgressIndicator alloc] initWithFrame:s_rc];
+ [_progressBar setMaxValue:1000.0];
+ [_progressBar setUsesThreadedAnimation:YES];
+ [_progressBar setStyle:NSProgressIndicatorBarStyle];
+ [_progressBar setDisplayedWhenStopped:YES];
+ [_progressBar setControlSize:NSRegularControlSize];
+ [_progressBar setIndeterminate:NO];
+ [ourContentView addSubview:_progressBar];
+ [_progressBar startAnimation:nil];
+
+ s_rc.origin.x = 20;
+ s_rc.origin.y = 110;
+ s_rc.size.height = s_rc.size.width = 64;
+ _iconView = [[NSImageView alloc] initWithFrame:s_rc];
+ [_iconView setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
+ [_iconView setEditable:NO];
+ [_iconView setAllowsCutCopyPaste:NO];
+ [ourContentView addSubview:_iconView];
+}
+
+- (void)setDialogTitle:(NSString *)title
+{
+ [_titleField setStringValue:title];
+ [self setTitle:title];
+}
+
+- (void)setDialogMessage:(NSString *)message
+{
+ [_messageField setStringValue:message];
+}
+
+- (void)setCancelButtonLabel:(NSString *)cancelLabel
+{
+ [_cancelButton setTitle:cancelLabel];
+}
+
+- (void)setProgressAsDouble:(double)value
+{
+ [_progressBar setDoubleValue:value];
+}
+
+- (BOOL)isCancelled
+{
+ return _isCancelled;
+}
+
+- (IBAction)cancelDialog:(id)sender
+{
+ _isCancelled = YES;
+ [_progressBar setIndeterminate:YES];
+ [_progressBar startAnimation:self];
+}
+
+ at end
diff --git a/modules/gui/macosx/VLCUIWidgets.h b/modules/gui/macosx/VLCUIWidgets.h
new file mode 100644
index 0000000..d19e18e
--- /dev/null
+++ b/modules/gui/macosx/VLCUIWidgets.h
@@ -0,0 +1,72 @@
+/*****************************************************************************
+ * VLCUIWidgets.h: Widgets for VLC's Minimal Dialog Provider for Mac OS X
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Pierre d'Herbemont <pdherbemont # videolan dot>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import <Cocoa/Cocoa.h>
+#import <vlc_extensions.h>
+
+ at class VLCDialogGridView;
+
+ at interface VLCDialogButton : NSButton
+
+ at property (readwrite) extension_widget_t *widget;
+ at end
+
+
+ at interface VLCDialogPopUpButton : NSPopUpButton
+
+ at property (readwrite) extension_widget_t *widget;
+ at end
+
+
+ at interface VLCDialogTextField : NSTextField
+
+ at property (readwrite) extension_widget_t *widget;
+ at end
+
+
+ at interface VLCDialogWindow : NSWindow
+
+ at property (readwrite) extension_dialog_t *dialog;
+ at property (readwrite) BOOL has_lock;
+ at end
+
+
+ at interface VLCDialogList : NSTableView <NSTableViewDataSource>
+
+ at property (readwrite) extension_widget_t *widget;
+ at property (readwrite, retain) NSMutableArray *contentArray;
+ at end
+
+
+ at interface VLCDialogGridView : NSView {
+ NSUInteger _rowCount, _colCount;
+ NSMutableArray *_griddedViews;
+}
+
+- (void)addSubview:(NSView *)view atRow:(NSUInteger)row column:(NSUInteger)column rowSpan:(NSUInteger)rowSpan colSpan:(NSUInteger)colSpan;
+- (NSSize)flexSize:(NSSize)size;
+- (void)removeSubview:(NSView *)view;
+
+ at property (readonly) NSUInteger numViews;
+
+ at end
\ No newline at end of file
diff --git a/modules/gui/macosx/VLCUIWidgets.m b/modules/gui/macosx/VLCUIWidgets.m
new file mode 100644
index 0000000..b89d5d4
--- /dev/null
+++ b/modules/gui/macosx/VLCUIWidgets.m
@@ -0,0 +1,395 @@
+/*****************************************************************************
+ * VLCUIWidgets.m: Widgets for VLC's Minimal Dialog Provider for Mac OS X
+ *****************************************************************************
+ * Copyright (C) 2009-2010 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Pierre d'Herbemont <pdherbemont # videolan dot>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "VLCUIWidgets.h"
+
+#import <stdlib.h>
+
+ at implementation VLCDialogButton
+ at synthesize widget;
+ at end
+
+
+ at implementation VLCDialogPopUpButton
+ at synthesize widget;
+ at end
+
+
+ at implementation VLCDialogTextField
+ at synthesize widget;
+ at end
+
+
+ at implementation VLCDialogWindow
+ at synthesize dialog;
+ at synthesize has_lock;
+ at end
+
+
+ at implementation VLCDialogList
+ at synthesize widget;
+ at synthesize contentArray;
+
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
+{
+ return [contentArray count];
+}
+
+- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex
+{
+ return [[contentArray objectAtIndex:rowIndex] objectForKey:@"text"];
+}
+ at end
+
+
+ at implementation VLCDialogGridView
+
+- (NSUInteger)numViews
+{
+ return [_griddedViews count];
+}
+
+- (id)init
+{
+ if ((self = [super init]))
+ {
+ _colCount = 0;
+ _rowCount = 0;
+ _griddedViews = [[NSMutableArray alloc] init];
+ }
+
+ return self;
+}
+- (void)dealloc
+{
+ [_griddedViews release];
+ [super dealloc];
+}
+
+- (void)recomputeCount
+{
+ _colCount = 0;
+ _rowCount = 0;
+ for (NSDictionary *obj in _griddedViews)
+ {
+ NSUInteger row = [[obj objectForKey:@"row"] intValue];
+ NSUInteger col = [[obj objectForKey:@"col"] intValue];
+ if (col + 1 > _colCount)
+ _colCount = col + 1;
+ if (row + 1 > _rowCount)
+ _rowCount = row + 1;
+ }
+}
+
+- (void)recomputeWindowSize
+{
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(recomputeWindowSize) object:nil];
+
+ NSWindow *window = [self window];
+ NSRect frame = [window frame];
+ NSRect contentRect = [window contentRectForFrameRect:frame];
+ contentRect.size = [self flexSize:frame.size];
+ NSRect newFrame = [window frameRectForContentRect:contentRect];
+ newFrame.origin.y -= newFrame.size.height - frame.size.height;
+ newFrame.origin.x -= (newFrame.size.width - frame.size.width) / 2;
+ [window setFrame:newFrame display:YES animate:YES];
+}
+
+- (NSSize)objectSizeToFit:(NSView *)view
+{
+ if ([view isKindOfClass:[NSControl class]]) {
+ NSControl *control = (NSControl *)view;
+ return [[control cell] cellSize];
+ }
+ return [view frame].size;
+}
+
+- (CGFloat)marginX
+{
+ return 16;
+}
+- (CGFloat)marginY
+{
+ return 8;
+}
+
+- (CGFloat)constrainedHeightOfRow:(NSUInteger)targetRow
+{
+ CGFloat height = 0;
+ for(NSDictionary *obj in _griddedViews) {
+ NSUInteger row = [[obj objectForKey:@"row"] intValue];
+ if (row != targetRow)
+ continue;
+ NSUInteger rowSpan = [[obj objectForKey:@"rowSpan"] intValue];
+ if (rowSpan != 1)
+ continue;
+ NSView *view = [obj objectForKey:@"view"];
+ if ([view autoresizingMask] & NSViewHeightSizable)
+ continue;
+ NSSize sizeToFit = [self objectSizeToFit:view];
+ if (height < sizeToFit.height)
+ height = sizeToFit.height;
+ }
+ return height;
+}
+
+- (CGFloat)remainingRowsHeight
+{
+ NSUInteger height = [self marginY];
+ if (!_rowCount)
+ return 0;
+ NSUInteger autosizedRows = 0;
+ for (NSUInteger i = 0; i < _rowCount; i++) {
+ CGFloat constrainedHeight = [self constrainedHeightOfRow:i];
+ if (!constrainedHeight)
+ autosizedRows++;
+ height += constrainedHeight + [self marginY];
+ }
+ CGFloat remaining = 0;
+ if (height < self.bounds.size.height && autosizedRows)
+ remaining = (self.bounds.size.height - height) / autosizedRows;
+ if (remaining < 0)
+ remaining = 0;
+
+ return remaining;
+}
+
+- (CGFloat)heightOfRow:(NSUInteger)targetRow
+{
+ NSAssert(targetRow < _rowCount, @"accessing a non existing row");
+ CGFloat height = [self constrainedHeightOfRow:targetRow];
+ if (!height)
+ height = [self remainingRowsHeight];
+ return height;
+}
+
+
+- (CGFloat)topOfRow:(NSUInteger)targetRow
+{
+ CGFloat top = [self marginY];
+ for (NSUInteger i = 1; i < _rowCount - targetRow; i++)
+ {
+ top += [self heightOfRow:_rowCount - i] + [self marginY];
+ }
+ return top;
+}
+
+- (CGFloat)constrainedWidthOfColumn:(NSUInteger)targetColumn
+{
+ CGFloat width = 0;
+ for(NSDictionary *obj in _griddedViews) {
+ NSUInteger col = [[obj objectForKey:@"col"] intValue];
+ if (col != targetColumn)
+ continue;
+ NSUInteger colSpan = [[obj objectForKey:@"colSpan"] intValue];
+ if (colSpan != 1)
+ continue;
+ NSView *view = [obj objectForKey:@"view"];
+ if ([view autoresizingMask] & NSViewWidthSizable)
+ return 0;
+ NSSize sizeToFit = [self objectSizeToFit:view];
+ if (width < sizeToFit.width)
+ width = sizeToFit.width;
+ }
+ return width;
+}
+
+- (CGFloat)remainingColumnWidth
+{
+ NSUInteger width = [self marginX];
+ if (!_colCount)
+ return 0;
+ NSUInteger autosizedCol = 0;
+ for (NSUInteger i = 0; i < _colCount; i++) {
+ CGFloat constrainedWidth = [self constrainedWidthOfColumn:i];
+ if (!constrainedWidth)
+ autosizedCol++;
+ width += constrainedWidth + [self marginX];
+
+ }
+ CGFloat remaining = 0;
+ if (width < self.bounds.size.width && autosizedCol)
+ remaining = (self.bounds.size.width - width) / autosizedCol;
+ if (remaining < 0)
+ remaining = 0;
+ return remaining;
+}
+
+- (CGFloat)widthOfColumn:(NSUInteger)targetColumn
+{
+ CGFloat width = [self constrainedWidthOfColumn:targetColumn];
+ if (!width)
+ width = [self remainingColumnWidth];
+ return width;
+}
+
+
+- (CGFloat)leftOfColumn:(NSUInteger)targetColumn
+{
+ CGFloat left = [self marginX];
+ for (NSUInteger i = 0; i < targetColumn; i++)
+ {
+ left += [self widthOfColumn:i] + [self marginX];
+
+ }
+ return left;
+}
+
+- (void)relayout
+{
+ for(NSDictionary *obj in _griddedViews) {
+ NSUInteger row = [[obj objectForKey:@"row"] intValue];
+ NSUInteger col = [[obj objectForKey:@"col"] intValue];
+ NSUInteger rowSpan = [[obj objectForKey:@"rowSpan"] intValue];
+ NSUInteger colSpan = [[obj objectForKey:@"colSpan"] intValue];
+ NSView *view = [obj objectForKey:@"view"];
+ NSRect rect;
+
+ // Get the height
+ if ([view autoresizingMask] & NSViewHeightSizable || rowSpan > 1) {
+ CGFloat height = 0;
+ for (NSUInteger r = 0; r < rowSpan; r++) {
+ if (row + r >= _rowCount)
+ break;
+ height += [self heightOfRow:row + r] + [self marginY];
+ }
+ rect.size.height = height - [self marginY];
+ }
+ else
+ rect.size.height = [self objectSizeToFit:view].height;
+
+ // Get the width
+ if ([view autoresizingMask] & NSViewWidthSizable) {
+ CGFloat width = 0;
+ for (NSUInteger c = 0; c < colSpan; c++)
+ width += [self widthOfColumn:col + c] + [self marginX];
+ rect.size.width = width - [self marginX];
+ }
+ else
+ rect.size.width = [self objectSizeToFit:view].width;
+
+ // Top corner
+ rect.origin.y = [self topOfRow:row] + ([self heightOfRow:row] - rect.size.height) / 2;
+ rect.origin.x = [self leftOfColumn:col];
+
+ [view setFrame:rect];
+ [view setNeedsDisplay:YES];
+ }
+}
+
+- (NSMutableDictionary *)objectForView:(NSView *)view
+{
+ for (NSMutableDictionary *dict in _griddedViews)
+ {
+ if ([dict objectForKey:@"view"] == view)
+ return dict;
+ }
+ return nil;
+}
+
+- (void)addSubview:(NSView *)view atRow:(NSUInteger)row column:(NSUInteger)column
+ rowSpan:(NSUInteger)rowSpan
+ colSpan:(NSUInteger)colSpan
+{
+ if (row + 1 > _rowCount)
+ _rowCount = row + 1;
+ if (column + 1 > _colCount)
+ _colCount = column + 1;
+
+ NSMutableDictionary *dict = [self objectForView:view];
+ if (!dict) {
+ dict = [NSMutableDictionary dictionary];
+ [dict setObject:view forKey:@"view"];
+ [_griddedViews addObject:dict];
+ }
+ [dict setObject:[NSNumber numberWithInt:rowSpan] forKey:@"rowSpan"];
+ [dict setObject:[NSNumber numberWithInt:colSpan] forKey:@"colSpan"];
+ [dict setObject:[NSNumber numberWithInt:row] forKey:@"row"];
+ [dict setObject:[NSNumber numberWithInt:column] forKey:@"col"];
+
+ [self addSubview:view];
+ [self relayout];
+
+ // Recompute the size of the window after making sure we won't see anymore update
+ [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(recomputeWindowSize) object:nil];
+ [self performSelector:@selector(recomputeWindowSize) withObject:nil afterDelay:0.1];
+}
+
+- (void)removeSubview:(NSView *)view
+{
+ NSDictionary *dict = [self objectForView:view];
+ if (dict)
+ [_griddedViews removeObject:dict];
+ [view removeFromSuperview];
+
+ [self recomputeCount];
+ [self recomputeWindowSize];
+
+ [self relayout];
+ [self setNeedsDisplay:YES];
+}
+
+- (void)setFrame:(NSRect)frameRect
+{
+ [super setFrame:frameRect];
+ [self relayout];
+}
+
+- (NSSize)flexSize:(NSSize)size
+{
+ if (!_rowCount || !_colCount)
+ return size;
+
+ CGFloat minHeight = [self marginY];
+ BOOL canFlexHeight = NO;
+ for (NSUInteger i = 0; i < _rowCount; i++) {
+ CGFloat constrained = [self constrainedHeightOfRow:i];
+ if (!constrained) {
+ canFlexHeight = YES;
+ constrained = 128;
+ }
+ minHeight += constrained + [self marginY];
+ }
+
+ CGFloat minWidth = [self marginX];
+ BOOL canFlexWidth = NO;
+ for (NSUInteger i = 0; i < _colCount; i++) {
+ CGFloat constrained = [self constrainedWidthOfColumn:i];
+ if (!constrained) {
+ canFlexWidth = YES;
+ constrained = 128;
+ }
+ minWidth += constrained + [self marginX];
+ }
+ if (size.width < minWidth)
+ size.width = minWidth;
+ if (size.height < minHeight)
+ size.height = minHeight;
+ if (!canFlexHeight)
+ size.height = minHeight;
+ if (!canFlexWidth)
+ size.width = minWidth;
+ return size;
+}
+
+ at end
--
1.7.5.4
More information about the vlc-devel
mailing list