Remove NoMonthChange and DoubleClick from Calendar
Move CalendarBackend from Xwt.Mac to Xwt.Xam.Mac Override Enable/Disable Event in CalendarBackends Signed-off-by: Claudio Rodrigo Pereyra Diaz <claudiorodrigo@pereyradiaz.com.ar>
This commit is contained in:
Родитель
79acd79109
Коммит
7bd9fd9c05
|
@ -34,7 +34,6 @@ namespace Samples
|
|||
{
|
||||
var label = new Label ();
|
||||
var calendar = new Calendar () {
|
||||
NoMonthChange = false,
|
||||
ExpandHorizontal = false,
|
||||
};
|
||||
var entry = new TextEntry () {
|
||||
|
@ -42,56 +41,42 @@ namespace Samples
|
|||
};
|
||||
var minDate = new TextEntry () {
|
||||
PlaceholderText = "Enter the min date of calendar",
|
||||
Text = calendar.MinDate.ToShortDateString (),
|
||||
};
|
||||
var maxDate = new TextEntry () {
|
||||
PlaceholderText = "Enter the max date of calendar",
|
||||
Text = calendar.MaxDate.ToShortDateString (),
|
||||
};
|
||||
var noMonthChange = new CheckBox () {
|
||||
Label = "Disable month change",
|
||||
Active = calendar.NoMonthChange,
|
||||
};
|
||||
|
||||
calendar.ValueChanged += delegate {
|
||||
label.Text = string.Format ("Selected date: {0}", calendar.Date.ToShortDateString ());
|
||||
if (entry.Text != string.Empty) {
|
||||
entry.Text = calendar.Date.ToShortDateString ();
|
||||
minDate.Text = calendar.MinDate.ToShortDateString ();
|
||||
maxDate.Text = calendar.MaxDate.ToShortDateString ();
|
||||
}
|
||||
|
||||
};
|
||||
label.Text = string.Format ("Selected date: {0}", calendar.Date.ToShortDateString ());
|
||||
|
||||
var button = new Button () {
|
||||
Label = "Change value",
|
||||
Label = "Change values",
|
||||
};
|
||||
|
||||
button.Clicked += delegate {
|
||||
DateTime date;
|
||||
if (DateTime.TryParse (entry.Text, out date))
|
||||
calendar.Date = date;
|
||||
|
||||
DateTime dateMin;
|
||||
if (DateTime.TryParse (minDate.Text, out dateMin))
|
||||
calendar.MinDate = dateMin.Date;
|
||||
|
||||
DateTime dateMax;
|
||||
if (DateTime.TryParse (maxDate.Text, out dateMax))
|
||||
calendar.MaxDate = dateMax.Date;
|
||||
DateTime date;
|
||||
if (DateTime.TryParse (entry.Text, out date))
|
||||
calendar.Date = date;
|
||||
};
|
||||
|
||||
|
||||
|
||||
noMonthChange.Clicked += delegate {
|
||||
calendar.NoMonthChange = noMonthChange.Active;
|
||||
};
|
||||
PackStart (calendar);
|
||||
PackStart (noMonthChange);
|
||||
PackStart (entry);
|
||||
PackStart (minDate);
|
||||
PackStart (maxDate);
|
||||
PackStart (button);
|
||||
PackStart (label);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,18 @@ namespace Xwt.GtkBackend
|
|||
public override void Initialize ()
|
||||
{
|
||||
Widget = new Gtk.Calendar ();
|
||||
Widget.DaySelected += HandleValueChanged;
|
||||
Widget.DaySelectedDoubleClick += HandleDoubleClick;
|
||||
Widget.DaySelected += CheckBetweenMinMax;
|
||||
Widget.Show ();
|
||||
}
|
||||
|
||||
void CheckBetweenMinMax (object sender, EventArgs e)
|
||||
{
|
||||
if (Date < MinDate)
|
||||
Date = MinDate;
|
||||
if (Date > MaxDate)
|
||||
Date = MaxDate;
|
||||
}
|
||||
|
||||
protected new Gtk.Calendar Widget {
|
||||
get { return (Gtk.Calendar)base.Widget; }
|
||||
set { base.Widget = value; }
|
||||
|
@ -49,6 +56,20 @@ namespace Xwt.GtkBackend
|
|||
get { return (ICalendarEventSink)base.EventSink; }
|
||||
}
|
||||
|
||||
public override void EnableEvent (object eventId)
|
||||
{
|
||||
base.EnableEvent (eventId);
|
||||
if (eventId is CalendarEvent)
|
||||
Widget.DaySelected += HandleValueChanged;
|
||||
}
|
||||
|
||||
public override void DisableEvent (object eventId)
|
||||
{
|
||||
base.DisableEvent (eventId);
|
||||
if (eventId is CalendarEvent)
|
||||
Widget.DaySelected -= HandleValueChanged;
|
||||
}
|
||||
|
||||
public DateTime Date {
|
||||
get {
|
||||
return Widget.Date;
|
||||
|
@ -80,34 +101,12 @@ namespace Xwt.GtkBackend
|
|||
}
|
||||
}
|
||||
|
||||
public bool NoMonthChange {
|
||||
get {
|
||||
return Widget.NoMonthChange;
|
||||
}
|
||||
set {
|
||||
Widget.NoMonthChange = value;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleValueChanged (object sender, EventArgs e)
|
||||
{
|
||||
if (Date < MinDate) {
|
||||
Date = MinDate;
|
||||
}
|
||||
if (Date > MaxDate) {
|
||||
Date = MaxDate;
|
||||
}
|
||||
ApplicationContext.InvokeUserCode (delegate {
|
||||
EventSink.OnValueChanged ();
|
||||
});
|
||||
}
|
||||
|
||||
void HandleDoubleClick (object sender, EventArgs e)
|
||||
{
|
||||
ApplicationContext.InvokeUserCode (delegate {
|
||||
EventSink.OnDoubleClick ();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -284,7 +284,9 @@
|
|||
<Compile Include="..\Xwt.XamMac\Xwt.Mac.CellViews\TextTableCell.cs">
|
||||
<Link>Xwt.Mac.CellViews\TextTableCell.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Xwt.Mac\CalendarBackend.cs" />
|
||||
<Compile Include="..\Xwt.XamMac\Xwt.Mac\CalendarBackend.cs">
|
||||
<Link>Xwt.Mac\CalendarBackend.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
|
|
|
@ -36,7 +36,6 @@ namespace Xwt.WPFBackend
|
|||
public CalendarBackend ()
|
||||
{
|
||||
Widget = new WindowsCalendar ();
|
||||
Widget.SelectedDatesChanged += (object sender, SelectionChangedEventArgs e) => HandleValueChanged(sender, e);
|
||||
Widget.DisplayMode = CalendarMode.Month;
|
||||
Widget.IsTodayHighlighted = true;
|
||||
Widget.SelectionMode = CalendarSelectionMode.SingleDate;
|
||||
|
@ -56,6 +55,20 @@ namespace Xwt.WPFBackend
|
|||
get { return (ICalendarEventSink)base.EventSink; }
|
||||
}
|
||||
|
||||
public override void EnableEvent (object eventId)
|
||||
{
|
||||
base.EnableEvent (eventId);
|
||||
if (eventId is CalendarEvent)
|
||||
Widget.SelectedDatesChanged += HandleValueChanged;
|
||||
}
|
||||
|
||||
public override void DisableEvent (object eventId)
|
||||
{
|
||||
base.DisableEvent (eventId);
|
||||
if (eventId is CalendarEvent)
|
||||
Widget.SelectedDatesChanged -= HandleValueChanged;
|
||||
}
|
||||
|
||||
public DateTime Date {
|
||||
get {
|
||||
return Calendar.SelectedDate ?? Calendar.DisplayDate;
|
||||
|
@ -66,67 +79,26 @@ namespace Xwt.WPFBackend
|
|||
}
|
||||
}
|
||||
|
||||
DateTime minDate;
|
||||
public DateTime MinDate {
|
||||
get {
|
||||
return minDate;
|
||||
return Widget.DisplayDateStart;
|
||||
}
|
||||
set {
|
||||
minDate = value;
|
||||
if (!NoMonthChange)
|
||||
Widget.DisplayDateStart = minDate;
|
||||
Widget.DisplayDateStart = value;
|
||||
}
|
||||
}
|
||||
|
||||
DateTime maxDate;
|
||||
public DateTime MaxDate {
|
||||
get {
|
||||
return maxDate;
|
||||
return Widget.DisplayDateEnd;
|
||||
}
|
||||
set {
|
||||
maxDate = value;
|
||||
if (!NoMonthChange)
|
||||
Widget.DisplayDateEnd = maxDate;
|
||||
}
|
||||
}
|
||||
|
||||
bool noMonthChange;
|
||||
public bool NoMonthChange {
|
||||
get {
|
||||
return noMonthChange;
|
||||
}
|
||||
set {
|
||||
noMonthChange = value;
|
||||
if (noMonthChange) {
|
||||
var dateStart = new DateTime (Calendar.DisplayDate.Year, Calendar.DisplayDate.Month, 1);
|
||||
var dateEnd = new DateTime (Calendar.DisplayDate.Year, Calendar.DisplayDate.Month, 1).AddMonths (1).AddDays (-1);
|
||||
if (dateStart < MinDate)
|
||||
dateStart = MinDate;
|
||||
if (dateEnd > MaxDate)
|
||||
dateEnd = MaxDate;
|
||||
if (Calendar.SelectedDate < dateStart)
|
||||
Calendar.SelectedDate = dateStart;
|
||||
if (Calendar.SelectedDate > dateEnd)
|
||||
Calendar.SelectedDate = dateEnd;
|
||||
Calendar.DisplayDateStart = dateStart;
|
||||
Calendar.DisplayDateEnd = dateEnd ;
|
||||
} else {
|
||||
Calendar.DisplayDateStart = MinDate;
|
||||
Calendar.DisplayDateEnd = MaxDate;
|
||||
}
|
||||
Widget.DisplayDateEnd = value;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleValueChanged (object sender, EventArgs e)
|
||||
{
|
||||
if (Date < MinDate) {
|
||||
Date = MinDate;
|
||||
return;
|
||||
}
|
||||
if (Date > MaxDate) {
|
||||
Date = MaxDate;
|
||||
return;
|
||||
}
|
||||
Context.InvokeUserCode (delegate {
|
||||
EventSink.OnValueChanged ();
|
||||
});
|
||||
|
|
|
@ -33,6 +33,8 @@ using nint = System.Int32;
|
|||
using nfloat = System.Single;
|
||||
using MonoMac.Foundation;
|
||||
using MonoMac.AppKit;
|
||||
|
||||
|
||||
#else
|
||||
using Foundation;
|
||||
using AppKit;
|
||||
|
@ -71,7 +73,6 @@ namespace Xwt.Mac
|
|||
ApplicationContext.InvokeUserCode (((ICalendarEventSink)EventSink).OnValueChanged);
|
||||
}
|
||||
|
||||
|
||||
public DateTime Date {
|
||||
get {
|
||||
return (DateTime)Widget.DateValue;
|
||||
|
@ -81,68 +82,39 @@ namespace Xwt.Mac
|
|||
Widget.DateValue = currentDate;
|
||||
}
|
||||
}
|
||||
|
||||
DateTime minDate;
|
||||
|
||||
public DateTime MinDate {
|
||||
get {
|
||||
return minDate;
|
||||
}
|
||||
set {
|
||||
minDate = value;
|
||||
if (!NoMonthChange) {
|
||||
var date = (NSDate)minDate;
|
||||
Widget.MinDate = date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DateTime maxDate;
|
||||
|
||||
public DateTime MaxDate {
|
||||
get {
|
||||
return maxDate;
|
||||
}
|
||||
set {
|
||||
maxDate = value;
|
||||
if (!NoMonthChange) {
|
||||
var date = (NSDate)maxDate;
|
||||
Widget.MaxDate = date;
|
||||
}
|
||||
}
|
||||
}
|
||||
bool noMonthChange;
|
||||
public bool NoMonthChange {
|
||||
get {
|
||||
return noMonthChange;
|
||||
}
|
||||
set {
|
||||
noMonthChange = value;
|
||||
if (noMonthChange) {
|
||||
var dateStart = new DateTime (Date.Year, Date.Month, 1);
|
||||
var dateEnd = new DateTime (Date.Year, Date.Month, 1).AddMonths (1).AddDays (-1);
|
||||
if (dateStart < MinDate)
|
||||
dateStart = MinDate;
|
||||
if (dateEnd > MaxDate)
|
||||
dateEnd = MaxDate;
|
||||
Widget.MinDate = (NSDate)dateStart;
|
||||
Widget.MaxDate = (NSDate)dateEnd ;
|
||||
} else {
|
||||
Widget.MinDate = (NSDate)MinDate;
|
||||
Widget.MaxDate = (NSDate)MaxDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleValueChanged (object sender, EventArgs e)
|
||||
{
|
||||
if (Date < MinDate) {
|
||||
Date = MinDate;
|
||||
}
|
||||
if (Date > MaxDate) {
|
||||
Date = MaxDate;
|
||||
}
|
||||
ApplicationContext.InvokeUserCode (delegate {
|
||||
EventSink.OnValueChanged ();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MacCalendar: NSDatePicker, IViewObject
|
||||
|
@ -159,9 +131,7 @@ namespace Xwt.Mac
|
|||
Bordered = true;
|
||||
DatePickerElements = NSDatePickerElementFlags.YearMonthDateDay;
|
||||
DrawsBackground = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -120,6 +120,7 @@
|
|||
<Compile Include="Xwt.Mac\SaveFileDialogBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\ColorPickerBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\OutlineViewBackend.cs" />
|
||||
<Compile Include="Xwt.Mac\CalendarBackend.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\BuildHelpers.targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
|
|
@ -34,20 +34,15 @@ namespace Xwt.Backends
|
|||
DateTime MinDate { get; set; }
|
||||
|
||||
DateTime MaxDate { get; set; }
|
||||
|
||||
bool NoMonthChange { get; set; }
|
||||
}
|
||||
|
||||
public interface ICalendarEventSink: IWidgetEventSink
|
||||
{
|
||||
void OnValueChanged ();
|
||||
|
||||
void OnDoubleClick ();
|
||||
}
|
||||
|
||||
public enum CalendarEvent
|
||||
{
|
||||
ValueChanged,
|
||||
DoubleClick,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,6 @@ namespace Xwt
|
|||
static Calendar ()
|
||||
{
|
||||
MapEvent (CalendarEvent.ValueChanged, typeof(Calendar), "OnValueChanged");
|
||||
MapEvent (CalendarEvent.DoubleClick, typeof(Calendar), "OnDoubleClick");
|
||||
}
|
||||
|
||||
protected new class WidgetBackendHost: Widget.WidgetBackendHost, ICalendarEventSink
|
||||
|
@ -47,11 +46,6 @@ namespace Xwt
|
|||
{
|
||||
((Calendar)Parent).OnValueChanged (EventArgs.Empty);
|
||||
}
|
||||
|
||||
public void OnDoubleClick ()
|
||||
{
|
||||
((Calendar)Parent).OnDoubleClick (EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public Calendar ()
|
||||
|
@ -105,16 +99,6 @@ namespace Xwt
|
|||
}
|
||||
}
|
||||
|
||||
[DefaultValue (false)]
|
||||
public bool NoMonthChange {
|
||||
get {
|
||||
return Backend.NoMonthChange;
|
||||
}
|
||||
set {
|
||||
Backend.NoMonthChange = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnValueChanged (EventArgs e)
|
||||
{
|
||||
if (valueChanged != null)
|
||||
|
@ -131,23 +115,6 @@ namespace Xwt
|
|||
BackendHost.OnAfterEventRemove (CalendarEvent.ValueChanged, valueChanged);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnDoubleClick (EventArgs e)
|
||||
{
|
||||
if (doubleClick != null)
|
||||
doubleClick (this, e);
|
||||
}
|
||||
|
||||
public event EventHandler DoubleClick {
|
||||
add {
|
||||
BackendHost.OnBeforeEventAdd (CalendarEvent.DoubleClick, doubleClick);
|
||||
doubleClick += value;
|
||||
}
|
||||
remove {
|
||||
doubleClick -= value;
|
||||
BackendHost.OnAfterEventRemove (CalendarEvent.DoubleClick, doubleClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче