Add Calendar Sample
Implement CalendarBackend for Gtk

Signed-off-by: Claudio Rodrigo Pereyra Diaz <claudiorodrigo@pereyradiaz.com.ar>
This commit is contained in:
Claudio Rodrigo Pereyra Diaz 2015-03-08 21:59:36 -03:00 коммит произвёл Vsevolod Kukol
Родитель 92a3975d63
Коммит f9df032da7
11 изменённых файлов: 420 добавлений и 0 удалений

Просмотреть файл

@ -130,6 +130,7 @@ based on the contents of the childrens on it.
* Button
* MenuButton
* ToggleButton
* Calendar
* Canvas (Container)
* Checkbox
* ComboBox

Просмотреть файл

@ -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));

Просмотреть файл

@ -109,6 +109,7 @@
<Compile Include="Samples\WidgetFocus.cs" />
<Compile Include="Samples\ListViewCellBounds.cs" />
<Compile Include="Samples\TreeViewCellBounds.cs" />
<Compile Include="Samples\CalendarSample.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

Просмотреть файл

@ -0,0 +1,94 @@
//
// Calendar.cs
//
// Author:
// Claudio Rodrigo Pereyra Diaz <claudiorodrigo@pereyradiaz.com.ar>
//
// 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);
}
}
}

Просмотреть файл

@ -150,6 +150,7 @@
<Compile Include="Xwt.GtkBackend\Gtk2PopoverWindow.cs" />
<Compile Include="Xwt.GtkBackend\ColorSelectorBackend.cs" />
<Compile Include="Xwt.GtkBackend\ColorPickerBackend.cs" />
<Compile Include="Xwt.GtkBackend\CalendarBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

Просмотреть файл

@ -153,6 +153,7 @@
<Compile Include="Xwt.GtkBackend\PanedBackendGtk3.cs" />
<Compile Include="Xwt.GtkBackend\ColorSelectorBackend.cs" />
<Compile Include="Xwt.GtkBackend\ColorPickerBackend.cs" />
<Compile Include="Xwt.GtkBackend\CalendarBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

Просмотреть файл

@ -0,0 +1,135 @@
//
// CalendarBackend.cs
//
// Author:
// Claudio Rodrigo Pereyra Diaz <claudiorodrigo@pereyradiaz.com.ar>
//
// 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 ();
});
}
}
}

Просмотреть файл

@ -111,6 +111,7 @@ namespace Xwt.GtkBackend
RegisterBackend<IWebViewBackend, WebViewBackend> ();
RegisterBackend<IColorSelectorBackend, ColorSelectorBackend> ();
RegisterBackend<IColorPickerBackend, ColorPickerBackend> ();
RegisterBackend<ICalendarBackend, CalendarBackend> ();
string typeName = null;
string asmName = null;

Просмотреть файл

@ -0,0 +1,52 @@
//
// ICalendarBackend.cs
//
// Author:
// Claudio Rodrigo Pereyra Diaz <claudiorodrigo@pereyradiaz.com.ar>
//
// 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,
}
}

Просмотреть файл

@ -325,6 +325,8 @@
<Compile Include="Xwt\ColorPicker.cs" />
<Compile Include="Xwt.Backends\IColorPickerBackend.cs" />
<Compile Include="Xwt\XwtSynchronizationContext.cs" />
<Compile Include="Xwt\Calendar.cs" />
<Compile Include="Xwt.Backends\ICalendarBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />

131
Xwt/Xwt/Calendar.cs Normal file
Просмотреть файл

@ -0,0 +1,131 @@
//
// Calendar.cs
//
// Author:
// Claudio Rodrigo Pereyra Diaz <claudiorodrigo@pereyradiaz.com.ar>
//
// 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);
}
}
}
}