[california/wip/month-connectors] Move View.Month to ButtonConnector, although propagation isn't handled properly yet.
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/month-connectors] Move View.Month to ButtonConnector, although propagation isn't handled properly yet.
- Date: Fri, 23 May 2014 01:44:53 +0000 (UTC)
commit ca98436bae64ae8a251c3b60d8f0ebd70e5f9917
Author: Jim Nelson <jim yorba org>
Date: Thu May 22 18:44:10 2014 -0700
Move View.Month to ButtonConnector, although propagation isn't
handled properly yet.
src/toolkit/toolkit-button-connector.vala | 4 +-
src/view/month/month-grid.vala | 162 +++++++++++++----------------
src/view/month/month.vala | 2 +
3 files changed, 75 insertions(+), 93 deletions(-)
---
diff --git a/src/toolkit/toolkit-button-connector.vala b/src/toolkit/toolkit-button-connector.vala
index 915134d..d13679a 100644
--- a/src/toolkit/toolkit-button-connector.vala
+++ b/src/toolkit/toolkit-button-connector.vala
@@ -280,6 +280,8 @@ public class ButtonConnector : EventConnector {
if (button_states != null) {
InternalButtonEvent? details = button_states.get(widget);
if (details != null) {
+ details.update_release(widget, event);
+
// fire "unguaranteed" clicked signals now (with button release) rather than
// wait for timeout using the current value of press_type before the details
// are updated
@@ -296,8 +298,6 @@ public class ButtonConnector : EventConnector {
notify_triple_clicked(details, false);
break;
}
-
- details.update_release(widget, event);
}
}
break;
diff --git a/src/view/month/month-grid.vala b/src/view/month/month-grid.vala
index 80ec831..b6da372 100644
--- a/src/view/month/month-grid.vala
+++ b/src/view/month/month-grid.vala
@@ -54,8 +54,7 @@ private class Grid : Gtk.Grid {
private Gee.HashMap<Calendar.Date, Cell> date_to_cell = new Gee.HashMap<Calendar.Date, Cell>();
private Backing.CalendarSubscriptionManager? subscriptions = null;
- private Gdk.EventType button_press_type = Gdk.EventType.NOTHING;
- private Gdk.Point button_press_point = Gdk.Point();
+ private Toolkit.ButtonConnector cell_button_connector = new Toolkit.ButtonConnector();
public Grid(Controller owner, Calendar.MonthOfYear month_of_year) {
this.owner = owner;
@@ -67,6 +66,9 @@ private class Grid : Gtk.Grid {
row_homogeneous = true;
row_spacing = 0;
+ cell_button_connector.clicked.connect(on_cell_single_click);
+ cell_button_connector.double_clicked.connect(on_cell_double_click);
+
// prep the grid with a fixed number of rows and columns
for (int row = 0; row < ROWS; row++)
insert_row(0);
@@ -81,9 +83,7 @@ private class Grid : Gtk.Grid {
// TODO: try to avoid this on first pass
Cell cell = new Cell(this, Calendar.System.today, row, col);
cell.expand = true;
- cell.events |= Gdk.EventMask.BUTTON_PRESS_MASK & Gdk.EventMask.BUTTON1_MOTION_MASK;
- cell.button_press_event.connect(on_cell_button_event);
- cell.button_release_event.connect(on_cell_button_event);
+ cell_button_connector.connect_to(cell);
cell.motion_notify_event.connect(on_cell_motion_event);
attach(cell, col, row, 1, 1);
@@ -301,112 +301,92 @@ private class Grid : Gtk.Grid {
});
}
- private bool on_cell_button_event(Gtk.Widget widget, Gdk.EventButton event) {
- // only interested in left-clicks
- if (event.button != 1)
- return false;
+ // A button event returns all coordinates in the coordinate system of the pressed widget ...
+ // this determines which widget the button was released over and returns the point of release
+ // in that widget's coordinate system
+ private Cell? get_released_cell(Toolkit.ButtonEvent details, ref Gdk.Point release_cell_point) {
+ // The GDK coordinates are relative to the pressed Cell, so translate to the GtkGrid
+ int grid_x, grid_y;
+ if (!details.widget.translate_coordinates(this, details.release_point.x, details.release_point.y,
+ out grid_x, out grid_y)) {
+ return null;
+ }
- // NOTE: widget is the *pressed* widget, even for "release" events, no matter where the release
- // occurs
- Cell press_cell = (Cell) widget;
+ // Now translate the released coordinates back to the right Cell, if it is a Cell
+ Cell? release_cell = translate_to_cell(grid_x, grid_y);
+ if (release_cell == null)
+ return null;
- switch (event.type) {
- case Gdk.EventType.BUTTON_PRESS:
- case Gdk.EventType.2BUTTON_PRESS:
- case Gdk.EventType.3BUTTON_PRESS:
- button_press_type = event.type;
- button_press_point.x = (int) event.x;
- button_press_point.y = (int) event.y;
- break;
-
- case Gdk.EventType.BUTTON_RELEASE:
- // The GDK coordinates are relative to the pressed Cell, so translate to the GtkGrid
- int grid_x, grid_y;
- if (!press_cell.translate_coordinates(this, (int) event.x, (int) event.y, out grid_x,
- out grid_y)) {
- return false;
- }
-
- // Now translate the released coordinates back to the right Cell, if it is a Cell
- Cell? release_cell = translate_to_cell(grid_x, grid_y);
-
- // if released on a non-Cell, reset state and exit
- if (release_cell == null) {
- unselect_all();
- button_press_type = Gdk.EventType.NOTHING;
- button_press_point = {};
-
- return false;
- }
-
- // translate release point coordinates into the coordinates of the released cell
- Gdk.Point button_release_point = Gdk.Point();
- if (!press_cell.translate_coordinates(release_cell, (int) event.x, (int) event.y,
- out button_release_point.x, out button_release_point.y)) {
- return false;
- }
-
- bool stop_propagation = false;
- switch (button_press_type) {
- case Gdk.EventType.BUTTON_PRESS:
- stop_propagation = on_cell_single_click((Cell) widget, button_press_point,
- release_cell, button_release_point);
- break;
-
- case Gdk.EventType.2BUTTON_PRESS:
- stop_propagation = on_cell_double_click((Cell) widget, button_press_point,
- release_cell, button_release_point);
- break;
- }
-
- // reset, but don't de-select the view controller might be in charge of that
- button_press_type = Gdk.EventType.NOTHING;
- button_press_point = {};
-
- return stop_propagation;
+ // translate release point coordinates into the coordinates of the released cell
+ if (!details.widget.translate_coordinates(release_cell, details.release_point.x,
details.release_point.y,
+ out release_cell_point.x, out release_cell_point.y)) {
+ return null;
}
- return false;
+ return release_cell;
}
- private bool on_cell_single_click(Cell press_cell, Gdk.Point press_point,
- Cell release_cell, Gdk.Point release_point) {
- bool stop_propagation = false;
+ private void on_cell_single_click(Toolkit.ButtonEvent details, bool guaranteed) {
+ // only want unguaranteed primary button clicks
+ if (details.button != Toolkit.Button.PRIMARY || guaranteed)
+ return;
+
+ // get the Cell the button was released on (if it's a Cell at all)
+ Gdk.Point release_cell_point = Gdk.Point();
+ Cell? release_cell = get_released_cell(details, ref release_cell_point);
+ if (release_cell == null) {
+ // reset state and exit
+ unselect_all();
+
+ return;
+ }
+
+ //bool stop_propagation = false;
+
+ Cell press_cell = (Cell) details.widget;
// if pressed and released on the same cell, display the event at the released location
if (press_cell == release_cell) {
- Component.Event? event = release_cell.get_event_at(release_point);
+ Component.Event? event = release_cell.get_event_at(details.release_point);
if (event != null) {
- owner.request_display_event(event, release_cell, release_point);
- stop_propagation = true;
+ owner.request_display_event(event, release_cell, release_cell_point);
+ //stop_propagation = true;
}
- } else if (press_cell.date != null && release_cell.date != null) {
+ } else {
// create multi-day event
owner.request_create_all_day_event(new Calendar.DateSpan(press_cell.date, release_cell.date),
- release_cell, release_point);
- stop_propagation = true;
- } else {
- // make sure to clear selections if no action is taken
- unselect_all();
+ release_cell, release_cell_point);
+ //stop_propagation = true;
}
- return stop_propagation;
+ //return stop_propagation;
}
- private bool on_cell_double_click(Cell press_cell, Gdk.Point press_point, Cell release_cell,
- Gdk.Point release_point) {
+ private void on_cell_double_click(Toolkit.ButtonEvent details, bool guaranteed) {
+ // only interested in unguaranteed primary button clicks
+ if (details.button != Toolkit.Button.PRIMARY || guaranteed)
+ return;
+
+ // get the Cell the button was released on (if it's a Cell at all)
+ Gdk.Point release_cell_point = Gdk.Point();
+ Cell? release_cell = get_released_cell(details, ref release_cell_point);
+ if (release_cell == null) {
+ // reset state and exit
+ unselect_all();
+
+ return;
+ }
+
+ Cell press_cell = (Cell) details.widget;
+
// only interested in double-clicking on the same cell
if (press_cell != release_cell)
- return false;
+ return; //false;
// if an existing event is double-clicked, ignore, as the single click handler is displaying
// it (but stop propagation)
- if (release_cell.get_event_at(release_point) != null)
- return true;
-
- // if no date, still avoid propagating event
- if (release_cell.date == null)
- return true;
+ if (release_cell.get_event_at(release_cell_point) != null)
+ return; // true;
// TODO: Define default time better
Calendar.ExactTime start;
@@ -419,10 +399,10 @@ private class Grid : Gtk.Grid {
Calendar.ExactTime end = start.adjust_time(1, Calendar.TimeUnit.HOUR);
- owner.request_create_timed_event(new Calendar.ExactTimeSpan(start, end), release_cell,
release_point);
+ owner.request_create_timed_event(new Calendar.ExactTimeSpan(start, end), release_cell,
release_cell_point);
// stop propagation
- return true;
+ //return true;
}
private bool on_cell_motion_event(Gtk.Widget widget, Gdk.EventMotion event) {
diff --git a/src/view/month/month.vala b/src/view/month/month.vala
index 45096e3..d51d0d6 100644
--- a/src/view/month/month.vala
+++ b/src/view/month/month.vala
@@ -21,12 +21,14 @@ public void init() throws Error {
Calendar.init();
Component.init();
Backing.init();
+ Toolkit.init();
}
public void terminate() {
if (!Unit.do_terminate(ref init_count))
return;
+ Toolkit.terminate();
Backing.terminate();
Component.terminate();
Calendar.terminate();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]