From f9df032da7a5cc01f4ab1a20cd204c135a7145a9 Mon Sep 17 00:00:00 2001 From: Claudio Rodrigo Pereyra Diaz Date: Sun, 8 Mar 2015 21:59:36 -0300 Subject: [PATCH] Add Calendar Widget Add Calendar Sample Implement CalendarBackend for Gtk Signed-off-by: Claudio Rodrigo Pereyra Diaz --- README.markdown | 1 + TestApps/Samples/MainWindow.cs | 1 + TestApps/Samples/Samples.csproj | 1 + TestApps/Samples/Samples/CalendarSample.cs | 94 ++++++++++++++ Xwt.Gtk/Xwt.Gtk.csproj | 1 + Xwt.Gtk/Xwt.Gtk3.csproj | 1 + Xwt.Gtk/Xwt.GtkBackend/CalendarBackend.cs | 135 +++++++++++++++++++++ Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs | 1 + Xwt/Xwt.Backends/ICalendarBackend.cs | 52 ++++++++ Xwt/Xwt.csproj | 2 + Xwt/Xwt/Calendar.cs | 131 ++++++++++++++++++++ 11 files changed, 420 insertions(+) create mode 100644 TestApps/Samples/Samples/CalendarSample.cs create mode 100644 Xwt.Gtk/Xwt.GtkBackend/CalendarBackend.cs create mode 100644 Xwt/Xwt.Backends/ICalendarBackend.cs create mode 100644 Xwt/Xwt/Calendar.cs diff --git a/README.markdown b/README.markdown index 9afcbc41..5f499e58 100644 --- a/README.markdown +++ b/README.markdown @@ -130,6 +130,7 @@ based on the contents of the childrens on it. * Button * MenuButton * ToggleButton + * Calendar * Canvas (Container) * Checkbox * ComboBox diff --git a/TestApps/Samples/MainWindow.cs b/TestApps/Samples/MainWindow.cs index fde4178a..df69b6c7 100644 --- a/TestApps/Samples/MainWindow.cs +++ b/TestApps/Samples/MainWindow.cs @@ -69,6 +69,7 @@ namespace Samples var w = AddSample (null, "Widgets", null); AddSample (w, "Boxes", typeof(Boxes)); AddSample (w, "Buttons", typeof(ButtonSample)); + AddSample (w, "Calendar", typeof(CalendarSample)); AddSample (w, "CheckBox", typeof(Checkboxes)); AddSample (w, "Clipboard", typeof(ClipboardSample)); AddSample (w, "ColorSelector", typeof(ColorSelectorSample)); diff --git a/TestApps/Samples/Samples.csproj b/TestApps/Samples/Samples.csproj index bedc2091..4040443b 100644 --- a/TestApps/Samples/Samples.csproj +++ b/TestApps/Samples/Samples.csproj @@ -109,6 +109,7 @@ + diff --git a/TestApps/Samples/Samples/CalendarSample.cs b/TestApps/Samples/Samples/CalendarSample.cs new file mode 100644 index 00000000..f86ca155 --- /dev/null +++ b/TestApps/Samples/Samples/CalendarSample.cs @@ -0,0 +1,94 @@ +// +// Calendar.cs +// +// Author: +// Claudio Rodrigo Pereyra Diaz +// +// Copyright (c) 2015 Hamekoz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using Xwt; + +namespace Samples +{ + public class CalendarSample : VBox + { + public CalendarSample () + { + var label = new Label (); + var calendar = new Calendar () { + NoMonthChange = false, + ShowDayNames = true, + ShowHeading = true, + ShowWeekNumbers = false, + ExpandHorizontal = false, + }; + var entry = new TextEntry () { + PlaceholderText = "Enter a date to change calendar", + }; + calendar.ValueChanged += delegate { + label.Text = string.Format ("Selected date: {0}", calendar.Date.ToShortDateString ()); + entry.Text = calendar.Date.ToShortDateString (); + }; + label.Text = string.Format ("Selected date: {0} (Event not working, help to fix it)", calendar.Date.ToShortDateString ()); + + entry.Activated += delegate { + var date = DateTime.Parse (entry.Text); + calendar.Date = date; + }; + var showDayNames = new CheckBox () { + Label = "Show day names", + Active = calendar.ShowDayNames, + }; + showDayNames.Clicked += delegate { + calendar.ShowDayNames = showDayNames.Active; + }; + var showHeading = new CheckBox () { + Label = "Show heading", + Active = calendar.ShowHeading, + }; + showHeading.Clicked += delegate { + calendar.ShowHeading = showHeading.Active; + }; + var showWeekNumbers = new CheckBox () { + Label = "Show Week Numbers", + Active = calendar.ShowWeekNumbers, + }; + showWeekNumbers.Clicked += delegate { + calendar.ShowWeekNumbers = showWeekNumbers.Active; + }; + var noMonthChange = new CheckBox () { + Label = "Disable month change", + Active = calendar.NoMonthChange, + }; + noMonthChange.Clicked += delegate { + calendar.NoMonthChange = noMonthChange.Active; + }; + PackStart (calendar); + PackStart (noMonthChange); + PackStart (showDayNames); + PackStart (showWeekNumbers); + PackStart (showHeading); + PackStart (entry); + PackStart (label); + } + } +} + diff --git a/Xwt.Gtk/Xwt.Gtk.csproj b/Xwt.Gtk/Xwt.Gtk.csproj index b8a4891a..485d071f 100644 --- a/Xwt.Gtk/Xwt.Gtk.csproj +++ b/Xwt.Gtk/Xwt.Gtk.csproj @@ -150,6 +150,7 @@ + diff --git a/Xwt.Gtk/Xwt.Gtk3.csproj b/Xwt.Gtk/Xwt.Gtk3.csproj index 20f39721..9f6a4e6c 100644 --- a/Xwt.Gtk/Xwt.Gtk3.csproj +++ b/Xwt.Gtk/Xwt.Gtk3.csproj @@ -153,6 +153,7 @@ + diff --git a/Xwt.Gtk/Xwt.GtkBackend/CalendarBackend.cs b/Xwt.Gtk/Xwt.GtkBackend/CalendarBackend.cs new file mode 100644 index 00000000..c929ff44 --- /dev/null +++ b/Xwt.Gtk/Xwt.GtkBackend/CalendarBackend.cs @@ -0,0 +1,135 @@ +// +// CalendarBackend.cs +// +// Author: +// Claudio Rodrigo Pereyra Diaz +// +// Copyright (c) 2015 Hamekoz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using Xwt.Backends; + + +namespace Xwt.GtkBackend +{ + public partial class CalendarBackend: WidgetBackend, ICalendarBackend + { + public override void Initialize () + { + Widget = new Gtk.Calendar (); + Widget.Show (); + } + + protected virtual Gtk.Calendar Calendar { + get { return (Gtk.Calendar)base.Widget; } + } + + protected new Gtk.Calendar Widget { + get { return Calendar; } + set { base.Widget = value; } + } + + protected new ICalendarEventSink EventSink { + get { return (ICalendarEventSink)base.EventSink; } + } + + public DateTime Date { + get { + return Widget.Date; + } + set { + Widget.Date = value; + } + } + + public bool NoMonthChange { + get { + return Widget.NoMonthChange; + } + set { + Widget.NoMonthChange = value; + } + } + + public bool ShowDayNames { + get { + return Widget.ShowDayNames; + } + set { + Widget.ShowDayNames = value; + } + } + + public bool ShowHeading { + get { + return Widget.ShowHeading; + } + set { + Widget.ShowHeading = value; + } + } + + public bool ShowWeekNumbers { + get { + return Widget.ShowWeekNumbers; + } + set { + Widget.ShowWeekNumbers = value; + } + } + + public override void EnableEvent (object eventId) + { + base.EnableEvent (eventId); + if (eventId is CalendarEvent) { + switch ((CalendarEvent)eventId) { + case CalendarEvent.ValueChanged: + Widget.DaySelected += HandleValueChanged; + Widget.DaySelectedDoubleClick += HandleValueChanged; + Widget.MonthChanged += HandleValueChanged; + break; + } + } + } + + public override void DisableEvent (object eventId) + { + base.DisableEvent (eventId); + if (eventId is CalendarEvent) { + switch ((CalendarEvent)eventId) { + case CalendarEvent.ValueChanged: + Widget.DaySelected -= HandleValueChanged; + Widget.DaySelectedDoubleClick -= HandleValueChanged; + Widget.MonthChanged -= HandleValueChanged; + break; + } + } + } + + void HandleValueChanged (object sender, EventArgs e) + { + ApplicationContext.InvokeUserCode (delegate { + EventSink.OnValueChanged (); + }); + } + } +} + diff --git a/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs b/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs index fae14d79..0957ecbf 100755 --- a/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs +++ b/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs @@ -111,6 +111,7 @@ namespace Xwt.GtkBackend RegisterBackend (); RegisterBackend (); RegisterBackend (); + RegisterBackend (); string typeName = null; string asmName = null; diff --git a/Xwt/Xwt.Backends/ICalendarBackend.cs b/Xwt/Xwt.Backends/ICalendarBackend.cs new file mode 100644 index 00000000..6d6dae23 --- /dev/null +++ b/Xwt/Xwt.Backends/ICalendarBackend.cs @@ -0,0 +1,52 @@ +// +// ICalendarBackend.cs +// +// Author: +// Claudio Rodrigo Pereyra Diaz +// +// Copyright (c) 2015 Hamekoz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; + +namespace Xwt.Backends +{ + public interface ICalendarBackend : IWidgetBackend + { + DateTime Date { get; set; } + + bool NoMonthChange { get; set; } + + bool ShowDayNames { get; set; } + + bool ShowHeading { get; set; } + + bool ShowWeekNumbers { get; set; } + } + + public interface ICalendarEventSink: IWidgetEventSink + { + void OnValueChanged (); + } + + public enum CalendarEvent + { + ValueChanged, + } +} diff --git a/Xwt/Xwt.csproj b/Xwt/Xwt.csproj index c4aa025a..38d4dcb9 100644 --- a/Xwt/Xwt.csproj +++ b/Xwt/Xwt.csproj @@ -325,6 +325,8 @@ + + diff --git a/Xwt/Xwt/Calendar.cs b/Xwt/Xwt/Calendar.cs new file mode 100644 index 00000000..4be236eb --- /dev/null +++ b/Xwt/Xwt/Calendar.cs @@ -0,0 +1,131 @@ +// +// Calendar.cs +// +// Author: +// Claudio Rodrigo Pereyra Diaz +// +// Copyright (c) 2015 Hamekoz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using Xwt.Backends; +using System.ComponentModel; + +namespace Xwt +{ + [BackendType (typeof(ICalendarBackend))] + public class Calendar : Widget + { + EventHandler valueChanged; + + static Calendar () + { + MapEvent (CalendarEvent.ValueChanged, typeof(Calendar), "OnValueChanged"); + } + + protected new class WidgetBackendHost: Widget.WidgetBackendHost + { + public void OnValueChanged () + { + ((Calendar)Parent).OnValueChanged (EventArgs.Empty); + } + } + + public Calendar () + { + } + + ICalendarBackend Backend { + get { return (ICalendarBackend)BackendHost.Backend; } + } + + protected override BackendHost CreateBackendHost () + { + return new WidgetBackendHost (); + } + + public DateTime Date { + get { + return Backend.Date; + } + set { + Backend.Date = value; + } + } + + [DefaultValue (false)] + public bool NoMonthChange { + get { + return Backend.NoMonthChange; + } + set { + Backend.NoMonthChange = value; + } + } + + [DefaultValue (false)] + public bool ShowDayNames { + get { + return Backend.ShowDayNames; + } + set { + Backend.ShowDayNames = value; + } + } + + [DefaultValue (true)] + public bool ShowHeading { + get { + return Backend.ShowHeading; + } + set { + Backend.ShowHeading = value; + } + } + + [DefaultValue (false)] + public bool ShowWeekNumbers { + get { + return Backend.ShowWeekNumbers; + } + set { + Backend.ShowWeekNumbers = value; + } + } + + protected virtual void OnValueChanged (EventArgs e) + { + if (valueChanged != null) + valueChanged (this, e); + } + + public event EventHandler ValueChanged { + add { + BackendHost.OnBeforeEventAdd (CalendarEvent.ValueChanged, valueChanged); + valueChanged += value; + } + remove { + valueChanged -= value; + BackendHost.OnAfterEventRemove (CalendarEvent.ValueChanged, valueChanged); + } + } + } +} +