Skip to content

Commit

Permalink
Implement Spinner control for desktop platforms. Issue #131
Browse files Browse the repository at this point in the history
  • Loading branch information
cwensley committed Nov 20, 2013
1 parent 47cd438 commit f3394bc
Show file tree
Hide file tree
Showing 17 changed files with 840 additions and 345 deletions.
1 change: 1 addition & 0 deletions Source/Eto.Platform.Gtk/Eto.Platform.Gtk3.csproj
Expand Up @@ -276,6 +276,7 @@
<Compile Include="EtoWebView.cs" />
<Compile Include="Forms\GtkDockContainer.cs" />
<Compile Include="Forms\Controls\SearchBoxHandler.cs" />
<Compile Include="Forms\Controls\SpinnerHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<PropertyGroup>
Expand Down
48 changes: 48 additions & 0 deletions Source/Eto.Platform.Gtk/Forms/Controls/SpinnerHandler.cs
@@ -0,0 +1,48 @@
using System;
using Eto.Forms;

namespace Eto.Platform.GtkSharp.Forms.Controls
{
public class SpinnerHandler : GtkControl<Gtk.Spinner, Spinner>, ISpinner
{
bool enabled;
public SpinnerHandler()
{
Control = new Gtk.Spinner();
}

public override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
if (enabled)
Control.Start();
}

public override void OnUnLoad(EventArgs e)
{
base.OnUnLoad(e);
if (enabled)
Control.Stop();
}

public override bool Enabled
{
get { return enabled; }
set
{
if (enabled != value)
{
enabled = value;
if (Widget.Loaded)
{
if (enabled)
Control.Start();
else
Control.Stop();
}
}
}
}
}
}

175 changes: 90 additions & 85 deletions Source/Eto.Platform.Gtk/Generator.cs
Expand Up @@ -8,12 +8,13 @@
using Eto.Platform.GtkSharp.Forms.Printing;
using Eto.Platform.GtkSharp.Forms;
using Eto.Platform.GtkSharp.IO;
using Eto.Forms.ThemedControls;

namespace Eto.Platform.GtkSharp
{
static class Helper
{
public static void Init ()
public static void Init()
{
var args = new string[0];
if (Gtk.Application.InitCheck(string.Empty, ref args))
Expand All @@ -24,117 +25,121 @@ public static void Init ()
}

public class Generator : Eto.Generator
{
#if GTK2
{
#if GTK2
public override string ID { get { return Generators.Gtk; } }
#else
#else
public override string ID { get { return Generators.Gtk3; } }
#endif

public Generator ()
#endif
public Generator()
{
if (EtoEnvironment.Platform.IsWindows && Environment.Is64BitProcess)
throw new NotSupportedException("Please compile/run GTK in x86 mode (32-bit) on windows");
Helper.Init ();
Helper.Init();

AddTo (this);
AddTo(this);
}

public static void AddTo(Eto.Generator g)
{
// Drawing
g.Add <IBitmap> (() => new BitmapHandler ());
g.Add <IFontFamily> (() => new FontFamilyHandler ());
g.Add <IFont> (() => new FontHandler ());
g.Add <IFonts> (() => new FontsHandler ());
g.Add <IGraphics> (() => new GraphicsHandler ());
g.Add <IGraphicsPathHandler> (() => new GraphicsPathHandler ());
g.Add <IIcon> (() => new IconHandler ());
g.Add <IIndexedBitmap> (() => new IndexedBitmapHandler ());
g.Add <IMatrixHandler> (() => new MatrixHandler ());
g.Add <IPen> (() => new PenHandler ());
g.Add <ISolidBrush> (() => new SolidBrushHandler ());
g.Add <ITextureBrush> (() => new TextureBrushHandler ());
g.Add <ILinearGradientBrush> (() => new LinearGradientBrushHandler ());
g.Add<IBitmap>(() => new BitmapHandler());
g.Add<IFontFamily>(() => new FontFamilyHandler());
g.Add<IFont>(() => new FontHandler());
g.Add<IFonts>(() => new FontsHandler());
g.Add<IGraphics>(() => new GraphicsHandler());
g.Add<IGraphicsPathHandler>(() => new GraphicsPathHandler());
g.Add<IIcon>(() => new IconHandler());
g.Add<IIndexedBitmap>(() => new IndexedBitmapHandler());
g.Add<IMatrixHandler>(() => new MatrixHandler());
g.Add<IPen>(() => new PenHandler());
g.Add<ISolidBrush>(() => new SolidBrushHandler());
g.Add<ITextureBrush>(() => new TextureBrushHandler());
g.Add<ILinearGradientBrush>(() => new LinearGradientBrushHandler());

// Forms.Cells
g.Add <ICheckBoxCell> (() => new CheckBoxCellHandler ());
g.Add <IComboBoxCell> (() => new ComboBoxCellHandler ());
g.Add <IImageTextCell> (() => new ImageTextCellHandler ());
g.Add <IImageViewCell> (() => new ImageViewCellHandler ());
g.Add <ITextBoxCell> (() => new TextBoxCellHandler ());
g.Add<ICheckBoxCell>(() => new CheckBoxCellHandler());
g.Add<IComboBoxCell>(() => new ComboBoxCellHandler());
g.Add<IImageTextCell>(() => new ImageTextCellHandler());
g.Add<IImageViewCell>(() => new ImageViewCellHandler());
g.Add<ITextBoxCell>(() => new TextBoxCellHandler());

// Forms.Controls
g.Add <IButton> (() => new ButtonHandler ());
g.Add <ICheckBox> (() => new CheckBoxHandler ());
g.Add <IComboBox> (() => new ComboBoxHandler ());
g.Add <IDateTimePicker> (() => new DateTimePickerHandler ());
g.Add <IDrawable> (() => new DrawableHandler ());
g.Add <IGridColumn> (() => new GridColumnHandler ());
g.Add <IGridView> (() => new GridViewHandler ());
g.Add <IGroupBox> (() => new GroupBoxHandler ());
g.Add <IImageView> (() => new ImageViewHandler ());
g.Add <ILabel> (() => new LabelHandler ());
g.Add <IListBox> (() => new ListBoxHandler ());
g.Add <INumericUpDown> (() => new NumericUpDownHandler ());
g.Add <IPanel> (() => new PanelHandler ());
g.Add <IPasswordBox> (() => new PasswordBoxHandler ());
g.Add <IProgressBar> (() => new ProgressBarHandler ());
g.Add <IRadioButton> (() => new RadioButtonHandler ());
g.Add <IScrollable> (() => new ScrollableHandler ());
g.Add <ISearchBox> (() => new SearchBoxHandler ());
g.Add <ISlider> (() => new SliderHandler ());
g.Add <ISplitter> (() => new SplitterHandler ());
g.Add <ITabControl> (() => new TabControlHandler ());
g.Add <ITabPage> (() => new TabPageHandler ());
g.Add <ITextArea> (() => new TextAreaHandler ());
g.Add <ITextBox> (() => new TextBoxHandler ());
g.Add <ITreeGridView> (() => new TreeGridViewHandler ());
g.Add <ITreeView> (() => new TreeViewHandler ());
g.Add <IWebView> (() => new WebViewHandler ());
g.Add <IScreens> (() => new ScreensHandler ());
g.Add<IButton>(() => new ButtonHandler());
g.Add<ICheckBox>(() => new CheckBoxHandler());
g.Add<IComboBox>(() => new ComboBoxHandler());
g.Add<IDateTimePicker>(() => new DateTimePickerHandler());
g.Add<IDrawable>(() => new DrawableHandler());
g.Add<IGridColumn>(() => new GridColumnHandler());
g.Add<IGridView>(() => new GridViewHandler());
g.Add<IGroupBox>(() => new GroupBoxHandler());
g.Add<IImageView>(() => new ImageViewHandler());
g.Add<ILabel>(() => new LabelHandler());
g.Add<IListBox>(() => new ListBoxHandler());
g.Add<INumericUpDown>(() => new NumericUpDownHandler());
g.Add<IPanel>(() => new PanelHandler());
g.Add<IPasswordBox>(() => new PasswordBoxHandler());
g.Add<IProgressBar>(() => new ProgressBarHandler());
g.Add<IRadioButton>(() => new RadioButtonHandler());
g.Add<IScrollable>(() => new ScrollableHandler());
g.Add<ISearchBox>(() => new SearchBoxHandler());
g.Add<ISlider>(() => new SliderHandler());
#if GTK3
g.Add<ISpinner>(() => new SpinnerHandler());
#else
g.Add<ISpinner>(() => new ThemedSpinnerHandler());
#endif
g.Add<ISplitter>(() => new SplitterHandler());
g.Add<ITabControl>(() => new TabControlHandler());
g.Add<ITabPage>(() => new TabPageHandler());
g.Add<ITextArea>(() => new TextAreaHandler());
g.Add<ITextBox>(() => new TextBoxHandler());
g.Add<ITreeGridView>(() => new TreeGridViewHandler());
g.Add<ITreeView>(() => new TreeViewHandler());
g.Add<IWebView>(() => new WebViewHandler());
g.Add<IScreens>(() => new ScreensHandler());

// Forms.Menu
g.Add <ICheckMenuItem> (() => new CheckMenuItemHandler ());
g.Add <IContextMenu> (() => new ContextMenuHandler ());
g.Add <IImageMenuItem> (() => new ImageMenuItemHandler ());
g.Add <IMenuBar> (() => new MenuBarHandler ());
g.Add <IRadioMenuItem> (() => new RadioMenuItemHandler ());
g.Add <ISeparatorMenuItem> (() => new SeparatorMenuItemHandler ());
g.Add<ICheckMenuItem>(() => new CheckMenuItemHandler());
g.Add<IContextMenu>(() => new ContextMenuHandler());
g.Add<IImageMenuItem>(() => new ImageMenuItemHandler());
g.Add<IMenuBar>(() => new MenuBarHandler());
g.Add<IRadioMenuItem>(() => new RadioMenuItemHandler());
g.Add<ISeparatorMenuItem>(() => new SeparatorMenuItemHandler());

// Forms.Printing
g.Add <IPrintDialog> (() => new PrintDialogHandler ());
g.Add <IPrintDocument> (() => new PrintDocumentHandler ());
g.Add <IPrintSettings> (() => new PrintSettingsHandler ());
g.Add<IPrintDialog>(() => new PrintDialogHandler());
g.Add<IPrintDocument>(() => new PrintDocumentHandler());
g.Add<IPrintSettings>(() => new PrintSettingsHandler());

// Forms.ToolBar
g.Add <ICheckToolBarButton> (() => new CheckToolBarButtonHandler ());
g.Add <ISeparatorToolBarItem> (() => new SeparatorToolBarItemHandler ());
g.Add <IToolBarButton> (() => new ToolBarButtonHandler ());
g.Add <IToolBar> (() => new ToolBarHandler ());
g.Add<ICheckToolBarButton>(() => new CheckToolBarButtonHandler());
g.Add<ISeparatorToolBarItem>(() => new SeparatorToolBarItemHandler());
g.Add<IToolBarButton>(() => new ToolBarButtonHandler());
g.Add<IToolBar>(() => new ToolBarHandler());

// Forms
g.Add <IApplication> (() => new ApplicationHandler ());
g.Add <IClipboard> (() => new ClipboardHandler ());
g.Add <IColorDialog> (() => new ColorDialogHandler ());
g.Add <ICursor> (() => new CursorHandler ());
g.Add <IDialog> (() => new DialogHandler ());
g.Add <IFontDialog> (() => new FontDialogHandler ());
g.Add <IForm> (() => new FormHandler ());
g.Add <IMessageBox> (() => new MessageBoxHandler ());
g.Add <IOpenFileDialog> (() => new OpenFileDialogHandler ());
g.Add <IPixelLayout> (() => new PixelLayoutHandler ());
g.Add <ISaveFileDialog> (() => new SaveFileDialogHandler ());
g.Add <ISelectFolderDialog> (() => new SelectFolderDialogHandler ());
g.Add <ITableLayout> (() => new TableLayoutHandler ());
g.Add <IUITimer> (() => new UITimerHandler ());
g.Add <IMouse> (() => new MouseHandler ());
g.Add<IApplication>(() => new ApplicationHandler());
g.Add<IClipboard>(() => new ClipboardHandler());
g.Add<IColorDialog>(() => new ColorDialogHandler());
g.Add<ICursor>(() => new CursorHandler());
g.Add<IDialog>(() => new DialogHandler());
g.Add<IFontDialog>(() => new FontDialogHandler());
g.Add<IForm>(() => new FormHandler());
g.Add<IMessageBox>(() => new MessageBoxHandler());
g.Add<IOpenFileDialog>(() => new OpenFileDialogHandler());
g.Add<IPixelLayout>(() => new PixelLayoutHandler());
g.Add<ISaveFileDialog>(() => new SaveFileDialogHandler());
g.Add<ISelectFolderDialog>(() => new SelectFolderDialogHandler());
g.Add<ITableLayout>(() => new TableLayoutHandler());
g.Add<IUITimer>(() => new UITimerHandler());
g.Add<IMouse>(() => new MouseHandler());

// IO
g.Add <ISystemIcons> (() => new SystemIconsHandler ());
g.Add<ISystemIcons>(() => new SystemIconsHandler());

// General
g.Add <IEtoEnvironment> (() => new EtoEnvironmentHandler ());
g.Add<IEtoEnvironment>(() => new EtoEnvironmentHandler());
}
}
}
1 change: 1 addition & 0 deletions Source/Eto.Platform.Mac/Eto.Platform.Mac.csproj
Expand Up @@ -190,6 +190,7 @@
<Compile Include="Forms\iosCompatibility.cs" />
<Compile Include="Drawing\FontExtensions.cs" />
<Compile Include="MacExtensions.cs" />
<Compile Include="Forms\Controls\SpinnerHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />
Expand Down
1 change: 1 addition & 0 deletions Source/Eto.Platform.Mac/Eto.Platform.XamMac.csproj
Expand Up @@ -195,6 +195,7 @@
<Compile Include="Forms\iosCompatibility.cs" />
<Compile Include="Drawing\FontExtensions.cs" />
<Compile Include="MacExtensions.cs" />
<Compile Include="Forms\Controls\SpinnerHandler.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />
Expand Down
84 changes: 84 additions & 0 deletions Source/Eto.Platform.Mac/Forms/Controls/SpinnerHandler.cs
@@ -0,0 +1,84 @@
using System;
using MonoMac.AppKit;
using Eto.Forms;
using Eto.Drawing;

namespace Eto.Platform.Mac.Forms.Controls
{
public class SpinnerHandler : MacView<NSProgressIndicator, Spinner>, ISpinner
{
bool enabled;
readonly NSView view;

public override NSView ContainerControl { get { return view; } }

protected override SizeF GetNaturalSize(SizeF availableSize)
{
return new SizeF(16, 16);
}

public SpinnerHandler()
{
Control = new NSProgressIndicator
{
Style = NSProgressIndicatorStyle.Spinning,
ControlSize = NSControlSize.Regular
};
view = new MacEventView { Handler = this };
view.AddSubview(Control);
}
protected override void Initialize()
{
base.Initialize();
HandleEvent(Eto.Forms.Control.SizeChangedEvent);
}

public override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
var size = Math.Max(Size.Width, Size.Height);
if (size <= 8)
Control.ControlSize = NSControlSize.Mini;
else if (size <= 20)
Control.ControlSize = NSControlSize.Small;
else if (size <= 30)
Control.ControlSize = NSControlSize.Regular;
Control.SizeToFit();
Control.CenterInParent();
}

public override void OnLoadComplete(EventArgs e)
{
base.OnLoadComplete(e);
if (enabled)
Control.StartAnimation(Control);
}

public override void OnUnLoad(EventArgs e)
{
base.OnUnLoad(e);
if (enabled)
Control.StopAnimation(Control);
}

public override bool Enabled
{
get { return enabled; }
set
{
if (enabled != value)
{
enabled = value;
if (Widget.Loaded)
{
if (enabled)
Control.StartAnimation(Control);
else
Control.StopAnimation(Control);
}
}
}
}
}
}

0 comments on commit f3394bc

Please sign in to comment.