[banshee/gtk3] DateButton: Re-format the code, no real code change
- From: Bertrand Lorentz <blorentz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee/gtk3] DateButton: Re-format the code, no real code change
- Date: Mon, 1 Aug 2011 16:57:40 +0000 (UTC)
commit 8d23f7361379ca64d025d529cf8869af974bafc5
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date: Mon Aug 1 18:40:09 2011 +0200
DateButton: Re-format the code, no real code change
.../Banshee.Widgets/Banshee.Widgets/DateButton.cs | 318 ++++++++++----------
1 files changed, 155 insertions(+), 163 deletions(-)
---
diff --git a/src/Core/Banshee.Widgets/Banshee.Widgets/DateButton.cs b/src/Core/Banshee.Widgets/Banshee.Widgets/DateButton.cs
index ba5d031..ae3f3e2 100644
--- a/src/Core/Banshee.Widgets/Banshee.Widgets/DateButton.cs
+++ b/src/Core/Banshee.Widgets/Banshee.Widgets/DateButton.cs
@@ -33,167 +33,159 @@ using Gtk;
namespace Banshee.Widgets
{
- public class DateButton : ToggleButton
- {
- private Window popup;
- private DateTime date;
- private Calendar cal;
- private string displayFormat;
-
- private const uint CURRENT_TIME = 0;
-
- public DateButton(string text) : base(text)
- {
- Toggled += OnToggled;
- popup = null;
- date = DateTime.Now;
- displayFormat = "yyyy/MM/dd";
- }
-
- private void ShowCalendar()
- {
- popup = new Window(WindowType.Popup);
- popup.Screen = this.Screen;
-
- Frame frame = new Frame();
- frame.ShadowType = ShadowType.Out;
- frame.Show();
-
- popup.Add(frame);
-
- VBox box = new VBox(false, 0);
- box.Show();
- frame.Add(box);
-
- cal = new Calendar();
- cal.DisplayOptions = CalendarDisplayOptions.ShowHeading
- | CalendarDisplayOptions.ShowDayNames
- | CalendarDisplayOptions.ShowWeekNumbers;
-
- cal.KeyPressEvent += OnCalendarKeyPressed;
- popup.ButtonPressEvent += OnButtonPressed;
-
- cal.Show();
-
- Alignment calAlignment = new Alignment(0.0f, 0.0f, 1.0f, 1.0f);
- calAlignment.Show();
- calAlignment.SetPadding(4, 4, 4, 4);
- calAlignment.Add(cal);
-
- box.PackStart(calAlignment, false, false, 0);
-
- int minimum_height, natural_height;
- GetPreferredHeight (out minimum_height, out natural_height);
- int x = 0, y = 0;
- Window.GetOrigin(out x, out y);
- popup.Move(x + Allocation.X, y + Allocation.Y + natural_height + 3);
- popup.Show();
- popup.GrabFocus();
-
- Grab.Add(popup);
-
- Gdk.GrabStatus grabbed = Gdk.Pointer.Grab(popup.Window, true,
- Gdk.EventMask.ButtonPressMask
- | Gdk.EventMask.ButtonReleaseMask
- | Gdk.EventMask.PointerMotionMask, null, null, CURRENT_TIME);
-
- if(grabbed == Gdk.GrabStatus.Success) {
- grabbed = Gdk.Keyboard.Grab(popup.Window,
- true, CURRENT_TIME);
-
- if(grabbed != Gdk.GrabStatus.Success) {
- Grab.Remove(popup);
- popup.Destroy();
- popup = null;
- }
- } else {
- Grab.Remove(popup);
- popup.Destroy();
- popup = null;
- }
-
- cal.DaySelectedDoubleClick += OnCalendarDaySelected;
- cal.ButtonPressEvent += OnCalendarButtonPressed;
-
- cal.Date = date;
- }
-
- public void HideCalendar(bool update)
- {
- if(popup != null) {
- Grab.Remove(popup);
- Gdk.Pointer.Ungrab(CURRENT_TIME);
- Gdk.Keyboard.Ungrab(CURRENT_TIME);
-
- popup.Destroy();
- popup = null;
- }
-
- if(update) {
- date = cal.GetDate();
- Label = date.ToString(displayFormat);
- }
-
- Active = false;
- }
-
- private void OnToggled(object o, EventArgs args)
- {
- if(Active) {
- ShowCalendar();
- } else {
- HideCalendar(false);
- }
- }
-
- private void OnButtonPressed(object o, ButtonPressEventArgs args)
- {
- if(popup != null)
- HideCalendar(false);
- }
-
- private void OnCalendarDaySelected(object o, EventArgs args)
- {
- HideCalendar(true);
- }
-
- private void OnCalendarButtonPressed(object o,
- ButtonPressEventArgs args)
- {
- args.RetVal = true;
- }
-
- private void OnCalendarKeyPressed(object o, KeyPressEventArgs args)
- {
- switch(args.Event.Key) {
- case Gdk.Key.Escape:
- HideCalendar(false);
- break;
- case Gdk.Key.KP_Enter:
- case Gdk.Key.ISO_Enter:
- case Gdk.Key.Key_3270_Enter:
- case Gdk.Key.Return:
- case Gdk.Key.space:
- case Gdk.Key.KP_Space:
- HideCalendar(true);
- break;
- default:
- break;
- }
- }
-
- public string DisplayFormat
- {
- set {
- displayFormat = value;
- }
- }
-
- public DateTime Date
- {
- get {
- return date;
- }
- }
- }
+ public class DateButton : ToggleButton
+ {
+ private Window popup;
+ private DateTime date;
+ private Calendar cal;
+ private string displayFormat;
+
+ private const uint CURRENT_TIME = 0;
+
+ public DateButton (string text) : base (text)
+ {
+ Toggled += OnToggled;
+ popup = null;
+ date = DateTime.Now;
+ displayFormat = "yyyy/MM/dd";
+ }
+
+ private void ShowCalendar ()
+ {
+ popup = new Window (WindowType.Popup);
+ popup.Screen = this.Screen;
+
+ Frame frame = new Frame ();
+ frame.ShadowType = ShadowType.Out;
+ frame.Show ();
+
+ popup.Add (frame);
+
+ VBox box = new VBox (false, 0);
+ box.Show ();
+ frame.Add (box);
+
+ cal = new Calendar ();
+ cal.DisplayOptions = CalendarDisplayOptions.ShowHeading
+ | CalendarDisplayOptions.ShowDayNames
+ | CalendarDisplayOptions.ShowWeekNumbers;
+
+ cal.KeyPressEvent += OnCalendarKeyPressed;
+ popup.ButtonPressEvent += OnButtonPressed;
+
+ cal.Show ();
+
+ Alignment calAlignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
+ calAlignment.Show ();
+ calAlignment.SetPadding (4, 4, 4, 4);
+ calAlignment.Add (cal);
+
+ box.PackStart (calAlignment, false, false, 0);
+
+ int minimum_height, natural_height;
+ GetPreferredHeight (out minimum_height, out natural_height);
+ int x = 0, y = 0;
+ Window.GetOrigin (out x, out y);
+ popup.Move (x + Allocation.X, y + Allocation.Y + natural_height + 3);
+ popup.Show ();
+ popup.GrabFocus ();
+
+ Grab.Add (popup);
+
+ Gdk.GrabStatus grabbed = Gdk.Pointer.Grab (popup.Window, true,
+ Gdk.EventMask.ButtonPressMask
+ | Gdk.EventMask.ButtonReleaseMask
+ | Gdk.EventMask.PointerMotionMask, null, null, CURRENT_TIME);
+
+ if (grabbed == Gdk.GrabStatus.Success) {
+ grabbed = Gdk.Keyboard.Grab (popup.Window, true, CURRENT_TIME);
+
+ if (grabbed != Gdk.GrabStatus.Success) {
+ Grab.Remove (popup);
+ popup.Destroy ();
+ popup = null;
+ }
+ } else {
+ Grab.Remove (popup);
+ popup.Destroy ();
+ popup = null;
+ }
+
+ cal.DaySelectedDoubleClick += OnCalendarDaySelected;
+ cal.ButtonPressEvent += OnCalendarButtonPressed;
+
+ cal.Date = date;
+ }
+
+ public void HideCalendar (bool update)
+ {
+ if (popup != null) {
+ Grab.Remove (popup);
+ Gdk.Pointer.Ungrab (CURRENT_TIME);
+ Gdk.Keyboard.Ungrab (CURRENT_TIME);
+
+ popup.Destroy ();
+ popup = null;
+ }
+
+ if (update) {
+ date = cal.GetDate ();
+ Label = date.ToString (displayFormat);
+ }
+
+ Active = false;
+ }
+
+ private void OnToggled (object o, EventArgs args)
+ {
+ if (Active) {
+ ShowCalendar ();
+ } else {
+ HideCalendar (false);
+ }
+ }
+
+ private void OnButtonPressed (object o, ButtonPressEventArgs args)
+ {
+ if (popup != null)
+ HideCalendar (false);
+ }
+
+ private void OnCalendarDaySelected (object o, EventArgs args)
+ {
+ HideCalendar (true);
+ }
+
+ private void OnCalendarButtonPressed (object o, ButtonPressEventArgs args)
+ {
+ args.RetVal = true;
+ }
+
+ private void OnCalendarKeyPressed (object o, KeyPressEventArgs args)
+ {
+ switch (args.Event.Key) {
+ case Gdk.Key.Escape:
+ HideCalendar (false);
+ break;
+ case Gdk.Key.KP_Enter:
+ case Gdk.Key.ISO_Enter:
+ case Gdk.Key.Key_3270_Enter:
+ case Gdk.Key.Return:
+ case Gdk.Key.space:
+ case Gdk.Key.KP_Space:
+ HideCalendar (true);
+ break;
+ default:
+ break;
+ }
+ }
+
+ public string DisplayFormat {
+ set { displayFormat = value; }
+ }
+
+ public DateTime Date {
+ get { return date; }
+ }
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]