From b6527471707ad53fb1dcf0d3c75c988b7e61d2e8 Mon Sep 17 00:00:00 2001 From: Alex Corrado Date: Tue, 5 Feb 2013 14:25:29 -0500 Subject: [PATCH] Require backends to actually implement the interface they are registered for --- Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs | 118 ++++++++++---------- Xwt.Mac/Xwt.Mac/SeparatorMenuItemBackend.cs | 3 +- Xwt.Mac/Xwt.Mac/ToggleButtonBackend.cs | 9 +- Xwt.WPF/Xwt.WPFBackend/WPFEngine.cs | 96 ++++++++-------- Xwt/Xwt.Backends/ToolkitEngineBackend.cs | 11 +- 5 files changed, 120 insertions(+), 117 deletions(-) diff --git a/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs b/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs index 6471cce7..ebcb293f 100755 --- a/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs +++ b/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs @@ -42,68 +42,68 @@ namespace Xwt.GtkBackend public override void InitializeBackends () { - RegisterBackend (typeof(ICustomWidgetBackend), typeof(CustomWidgetBackend)); - RegisterBackend (typeof(IWindowBackend), typeof(WindowBackend)); - RegisterBackend (typeof(ILabelBackend), typeof(LabelBackend)); - RegisterBackend (typeof(IBoxBackend), typeof(BoxBackend)); - RegisterBackend (typeof(IButtonBackend), typeof(ButtonBackend)); - RegisterBackend (typeof(INotebookBackend), typeof(NotebookBackend)); - RegisterBackend (typeof(ITreeViewBackend), typeof(TreeViewBackend)); - RegisterBackend (typeof(ITreeStoreBackend), typeof(TreeStoreBackend)); - RegisterBackend (typeof(IListViewBackend), typeof(ListViewBackend)); - RegisterBackend (typeof(IListStoreBackend), typeof(ListStoreBackend)); - RegisterBackend (typeof(ICanvasBackend), typeof(CanvasBackend)); - RegisterBackend (typeof(ImageBackendHandler), typeof(ImageHandler)); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); #if USE_PANGO - RegisterBackend (typeof(Xwt.Backends.ContextBackendHandler), typeof(ContextBackendHandlerWithPango)); - RegisterBackend (typeof(TextLayoutBackendHandler), typeof(GtkTextLayoutBackendHandler)); + RegisterBackend (); + RegisterBackend (); #else - WidgetRegistry.RegisterBackend (typeof(ContextBackendHandler), typeof(ContextBackendHandler)); - WidgetRegistry.RegisterBackend (typeof(TextLayoutBackendHandler), typeof(CairoTextLayoutBackendHandler)); + WidgetRegistry.RegisterBackend (); + WidgetRegistry.RegisterBackend (); #endif - RegisterBackend (typeof(DrawingPathBackendHandler), typeof(CairoContextBackendHandler)); - RegisterBackend (typeof(GradientBackendHandler), typeof(CairoGradientBackendHandler)); - RegisterBackend (typeof(FontBackendHandler), typeof(GtkFontBackendHandler)); - RegisterBackend (typeof(IMenuBackend), typeof(MenuBackend)); - RegisterBackend (typeof(IMenuItemBackend), typeof(MenuItemBackend)); - RegisterBackend (typeof(ICheckBoxMenuItemBackend), typeof(CheckBoxMenuItemBackend)); - RegisterBackend (typeof(IRadioButtonMenuItemBackend), typeof(RadioButtonMenuItemBackend)); - RegisterBackend (typeof(ISeparatorMenuItemBackend), typeof(SeparatorMenuItemBackend)); - RegisterBackend (typeof(IScrollViewBackend), typeof(ScrollViewBackend)); - RegisterBackend (typeof(IComboBoxBackend), typeof(ComboBoxBackend)); - RegisterBackend (typeof(IDesignerSurfaceBackend), typeof(DesignerSurfaceBackend)); - RegisterBackend (typeof(IMenuButtonBackend), typeof(MenuButtonBackend)); - RegisterBackend (typeof(ITextEntryBackend), typeof(TextEntryBackend)); - RegisterBackend (typeof(IToggleButtonBackend), typeof(ToggleButtonBackend)); - RegisterBackend (typeof(IImageViewBackend), typeof(ImageViewBackend)); - RegisterBackend (typeof(IAlertDialogBackend), typeof(AlertDialogBackend)); - RegisterBackend (typeof(ICheckBoxBackend), typeof(CheckBoxBackend)); - RegisterBackend (typeof(IFrameBackend), typeof(FrameBackend)); - RegisterBackend (typeof(ISeparatorBackend), typeof(SeparatorBackend)); - RegisterBackend (typeof(IDialogBackend), typeof(DialogBackend)); - RegisterBackend (typeof(IComboBoxEntryBackend), typeof(ComboBoxEntryBackend)); - RegisterBackend (typeof(ClipboardBackend), typeof(GtkClipboardBackend)); - RegisterBackend (typeof(ImagePatternBackendHandler), typeof(GtkImagePatternBackendHandler)); - RegisterBackend (typeof(ImageBuilderBackendHandler), typeof(ImageBuilderBackend)); - RegisterBackend (typeof(IScrollAdjustmentBackend), typeof(ScrollAdjustmentBackend)); - RegisterBackend (typeof(IOpenFileDialogBackend), typeof(OpenFileDialogBackend)); - RegisterBackend (typeof(ISaveFileDialogBackend), typeof(SaveFileDialogBackend)); - RegisterBackend (typeof(ISelectFolderDialogBackend), typeof(SelectFolderDialogBackend)); - RegisterBackend (typeof(IPanedBackend), typeof(PanedBackend)); - RegisterBackend (typeof(ISelectColorDialogBackend), typeof(SelectColorDialogBackend)); - RegisterBackend (typeof(IListBoxBackend), typeof(ListBoxBackend)); - RegisterBackend (typeof(IStatusIconBackend), typeof(StatusIconBackend)); - RegisterBackend (typeof(IProgressBarBackend), typeof(ProgressBarBackend)); - RegisterBackend (typeof(IPopoverBackend), typeof (PopoverBackend)); - RegisterBackend (typeof(ISpinButtonBackend), typeof (SpinButtonBackend)); - RegisterBackend (typeof(IDatePickerBackend), typeof (DatePickerBackend)); - RegisterBackend (typeof(ILinkLabelBackend), typeof (LinkLabelBackend)); - RegisterBackend (typeof(ISpinnerBackend), typeof (SpinnerBackend)); - RegisterBackend (typeof(IRichTextViewBackend), typeof (RichTextViewBackend)); - RegisterBackend (typeof(IExpanderBackend), typeof (ExpanderBackend)); - RegisterBackend (typeof(DesktopBackend), typeof(GtkDesktopBackend)); - RegisterBackend (typeof(IEmbeddedWidgetBackend), typeof(EmbeddedWidgetBackend)); - RegisterBackend (typeof(ISegmentedButtonBackend), typeof(SegmentedButtonBackend)); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); } public override void RunApplication () diff --git a/Xwt.Mac/Xwt.Mac/SeparatorMenuItemBackend.cs b/Xwt.Mac/Xwt.Mac/SeparatorMenuItemBackend.cs index d2696b10..48b2ced4 100644 --- a/Xwt.Mac/Xwt.Mac/SeparatorMenuItemBackend.cs +++ b/Xwt.Mac/Xwt.Mac/SeparatorMenuItemBackend.cs @@ -24,11 +24,12 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using Xwt.Backends; using MonoMac.AppKit; namespace Xwt.Mac { - public class SeparatorMenuItemBackend: MenuItemBackend + public class SeparatorMenuItemBackend: MenuItemBackend, ISeparatorMenuItemBackend { public SeparatorMenuItemBackend (): base (NSMenuItem.SeparatorItem) { diff --git a/Xwt.Mac/Xwt.Mac/ToggleButtonBackend.cs b/Xwt.Mac/Xwt.Mac/ToggleButtonBackend.cs index 5aa5bf80..3dd27b1b 100644 --- a/Xwt.Mac/Xwt.Mac/ToggleButtonBackend.cs +++ b/Xwt.Mac/Xwt.Mac/ToggleButtonBackend.cs @@ -24,11 +24,18 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using MonoMac.AppKit; +using Xwt.Backends; namespace Xwt.Mac { - public class ToggleButtonBackend: ButtonBackend + public class ToggleButtonBackend: ButtonBackend, IToggleButtonBackend { + public bool Active { + get { return Widget.State == NSCellStateValue.On; } + set { Widget.State = value? NSCellStateValue.On : NSCellStateValue.Off; } + } + public ToggleButtonBackend () { } diff --git a/Xwt.WPF/Xwt.WPFBackend/WPFEngine.cs b/Xwt.WPF/Xwt.WPFBackend/WPFEngine.cs index 384b8a5d..0872da7c 100755 --- a/Xwt.WPF/Xwt.WPFBackend/WPFEngine.cs +++ b/Xwt.WPF/Xwt.WPFBackend/WPFEngine.cs @@ -49,54 +49,54 @@ namespace Xwt.WPFBackend if (application == null) application = new System.Windows.Application (); - RegisterBackend (typeof (IWindowBackend), typeof (WindowBackend)); - RegisterBackend (typeof (IDialogBackend), typeof (DialogBackend)); - RegisterBackend (typeof (INotebookBackend), typeof (NotebookBackend)); - RegisterBackend (typeof (IMenuBackend), typeof (MenuBackend)); - RegisterBackend (typeof (IMenuItemBackend), typeof (MenuItemBackend)); - RegisterBackend (typeof (ICheckBoxMenuItemBackend), typeof (CheckboxMenuItemBackend)); - RegisterBackend (typeof (IRadioButtonMenuItemBackend), typeof (RadioButtonMenuItemBackend)); - RegisterBackend (typeof (ISeparatorMenuItemBackend), typeof (SeparatorMenuItemBackend)); - RegisterBackend (typeof (IBoxBackend), typeof (BoxBackend)); - RegisterBackend (typeof (ILabelBackend), typeof (LabelBackend)); - RegisterBackend (typeof (ITextEntryBackend), typeof (TextEntryBackend)); - RegisterBackend (typeof (IButtonBackend), typeof (ButtonBackend)); - RegisterBackend (typeof (IToggleButtonBackend), typeof (ToggleButtonBackend)); - RegisterBackend (typeof (IMenuButtonBackend), typeof (MenuButtonBackend)); - RegisterBackend (typeof (ICheckBoxBackend), typeof (CheckBoxBackend)); - RegisterBackend (typeof (ITreeViewBackend), typeof (TreeViewBackend)); - RegisterBackend (typeof (ITreeStoreBackend), typeof (TreeStoreBackend)); - RegisterBackend (typeof (IImageViewBackend), typeof (ImageViewBackend)); - RegisterBackend (typeof (ISeparatorBackend), typeof (SeparatorBackend)); - RegisterBackend (typeof (ImageBackendHandler), typeof (ImageHandler)); - RegisterBackend (typeof (FontBackendHandler), typeof (WpfFontBackendHandler)); - RegisterBackend (typeof (ClipboardBackend), typeof (WpfClipboardBackend)); - RegisterBackend (typeof (IComboBoxBackend), typeof (ComboBoxBackend)); - RegisterBackend (typeof (IComboBoxEntryBackend), typeof (ComboBoxEntryBackend)); - RegisterBackend (typeof (IScrollViewBackend), typeof (ScrollViewBackend)); - RegisterBackend (typeof (IFrameBackend), typeof (FrameBackend)); - RegisterBackend (typeof (ICanvasBackend), typeof (CanvasBackend)); - RegisterBackend (typeof (ContextBackendHandler), typeof (WpfContextBackendHandler)); - RegisterBackend (typeof (DrawingPathBackendHandler), typeof (WpfContextBackendHandler)); - RegisterBackend (typeof (GradientBackendHandler), typeof (WpfGradientBackendHandler)); - RegisterBackend (typeof (TextLayoutBackendHandler), typeof (WpfTextLayoutBackendHandler)); - RegisterBackend (typeof (ICustomWidgetBackend), typeof (CustomWidgetBackend)); - RegisterBackend (typeof (IPanedBackend), typeof (PanedBackend)); - RegisterBackend (typeof (IScrollAdjustmentBackend), typeof (ScrollAdjustmentBackend)); - RegisterBackend (typeof (IOpenFileDialogBackend), typeof (OpenFileDialogBackend)); - RegisterBackend (typeof (ISelectFolderDialogBackend), typeof (SelectFolderDialogBackend)); - RegisterBackend (typeof (IAlertDialogBackend), typeof (AlertDialogBackend)); - RegisterBackend (typeof (ImageBuilderBackendHandler), typeof (WpfImageBuilderBackendHandler)); - RegisterBackend (typeof (ImagePatternBackendHandler), typeof (WpfImagePatternBackendHandler)); - RegisterBackend (typeof (IListViewBackend), typeof (ListViewBackend)); - RegisterBackend (typeof (IListStoreBackend), typeof (ListDataSource)); - RegisterBackend (typeof (IListBoxBackend), typeof (ListBoxBackend)); - RegisterBackend (typeof (IPopoverBackend), typeof (PopoverBackend)); - RegisterBackend (typeof (IProgressBarBackend), typeof (ProgressBarBackend)); - RegisterBackend (typeof (IRichTextViewBackend), typeof (RichTextViewBackend)); - RegisterBackend (typeof (ILinkLabelBackend), typeof (LinkLabelBackend)); - RegisterBackend (typeof (ISpinnerBackend), typeof (SpinnerBackend)); - RegisterBackend (typeof (DesktopBackend), typeof (WpfDesktopBackend)); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); + RegisterBackend (); } public override void DispatchPendingEvents() diff --git a/Xwt/Xwt.Backends/ToolkitEngineBackend.cs b/Xwt/Xwt.Backends/ToolkitEngineBackend.cs index b2af4247..04a56887 100755 --- a/Xwt/Xwt.Backends/ToolkitEngineBackend.cs +++ b/Xwt/Xwt.Backends/ToolkitEngineBackend.cs @@ -247,17 +247,12 @@ namespace Xwt.Backends return (T) CreateBackend (typeof(T)); } - public void RegisterBackend () - { - RegisterBackend (typeof(Backend), typeof(Implementation)); - } - - public void RegisterBackend (Type backendType, Type implementationType) + public void RegisterBackend () where Implementation: Backend { CheckInitialized (); - backendTypes [backendType] = implementationType; + backendTypes [typeof(Backend)] = typeof(Implementation); } - + public T CreateFrontend (object backend) { return (T) Activator.CreateInstance (typeof(T), backend);