[california/wip/731635-hotspot] First stab
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/731635-hotspot] First stab
- Date: Fri, 19 Sep 2014 22:42:33 +0000 (UTC)
commit 49f66a27dc2d5cedb4634625be55de496ecde8ec
Author: Jim Nelson <jim yorba org>
Date: Fri Sep 19 15:42:04 2014 -0700
First stab
Moved Month.Grid to using Toolkit.MotionConnector
src/toolkit/toolkit.vala | 37 +++++++++++++++++++++++++------------
src/view/month/month-grid.vala | 36 ++++++++++++++++++++++++++++--------
2 files changed, 53 insertions(+), 20 deletions(-)
---
diff --git a/src/toolkit/toolkit.vala b/src/toolkit/toolkit.vala
index ca38290..f407356 100644
--- a/src/toolkit/toolkit.vala
+++ b/src/toolkit/toolkit.vala
@@ -72,18 +72,7 @@ public void spin_event_loop() {
* { link set_window_unbusy}.
*/
public Gdk.Cursor? set_busy(Gtk.Widget widget) {
- Gtk.Widget toplevel = widget.get_toplevel();
- if (!toplevel.is_toplevel()) {
- debug("Unable to set busy: widget has no toplevel window");
-
- return null;
- }
-
- Gdk.Window gdk_window = toplevel.get_window();
- Gdk.Cursor? unbusy_cursor = gdk_window.get_cursor();
- gdk_window.set_cursor(new Gdk.Cursor.for_display(toplevel.get_display(), Gdk.CursorType.WATCH));
-
- return unbusy_cursor;
+ return set_toplevel_cursor(widget, Gdk.CursorType.WATCH);
}
/**
@@ -104,6 +93,30 @@ public void set_unbusy(Gtk.Widget widget, Gdk.Cursor? unbusy_cursor) {
}
/**
+ * Sets the Gtk.Widget's toplevel's cursor.
+ *
+ * @returns The toplevel's current cursor. This can be saved to restore later or simply dropped.
+ */
+public Gdk.Cursor? set_toplevel_cursor(Gtk.Widget widget, Gdk.CursorType? cursor_type) {
+ Gtk.Widget toplevel = widget.get_toplevel();
+ if (!toplevel.is_toplevel()) {
+ debug("Unable to set cursor: widget has no toplevel window");
+
+ return null;
+ }
+
+ Gdk.Window gdk_window = toplevel.get_window();
+ Gdk.Cursor? old_cursor = gdk_window.get_cursor();
+
+ if (cursor_type != null)
+ gdk_window.set_cursor(new Gdk.Cursor.for_display(toplevel.get_display(), cursor_type));
+ else
+ gdk_window.set_cursor(null);
+
+ return old_cursor;
+}
+
+/**
* Destroy a Gtk.Widget when the event loop is idle.
*/
public void destroy_later(Gtk.Widget widget) {
diff --git a/src/view/month/month-grid.vala b/src/view/month/month-grid.vala
index f124f94..d7afbe7 100644
--- a/src/view/month/month-grid.vala
+++ b/src/view/month/month-grid.vala
@@ -52,6 +52,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 Toolkit.ButtonConnector cell_button_connector = new Toolkit.ButtonConnector();
+ private Toolkit.MotionConnector cell_motion_connector = new Toolkit.MotionConnector();
private Scheduled? scheduled_subscription_update = null;
public Grid(Controller owner, Calendar.MonthOfYear month_of_year) {
@@ -65,6 +66,8 @@ private class Grid : Gtk.Grid {
cell_button_connector.clicked.connect(on_cell_single_click);
cell_button_connector.double_clicked.connect(on_cell_double_click);
+ cell_motion_connector.motion.connect(on_cell_motion);
+ cell_motion_connector.button_motion.connect(on_cell_button_motion);
// create a WeekSpan for the first week of the month to the last week of the month
Calendar.WeekSpan span = new Calendar.WeekSpan.from_span(month_of_year,
Calendar.System.first_of_week);
@@ -87,7 +90,7 @@ private class Grid : Gtk.Grid {
Cell cell = new Cell(this, date, rows, col);
cell.expand = true;
cell_button_connector.connect_to(cell);
- cell.motion_notify_event.connect(on_cell_motion_event);
+ cell_motion_connector.connect_to(cell);
attach(cell, col, rows, 1, 1);
@@ -300,6 +303,8 @@ private class Grid : Gtk.Grid {
Cell press_cell = (Cell) details.widget;
+ Toolkit.set_toplevel_cursor(this, null);
+
// 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(details.release_point);
@@ -343,27 +348,44 @@ private class Grid : Gtk.Grid {
if (release_cell.get_event_at(release_cell_point) != null)
return Toolkit.STOP;
+ Toolkit.set_toplevel_cursor(this, null);
+
owner.request_create_all_day_event(new Calendar.DateSpan(press_cell.date, release_cell.date),
release_cell, release_cell_point);
return Toolkit.STOP;
}
- private bool on_cell_motion_event(Gtk.Widget widget, Gdk.EventMotion event) {
+ private void on_cell_motion(Toolkit.MotionEvent details) {
+ Cell cell = (Cell) details.widget;
+
+ Component.Event? event = cell.get_event_at(details.point);
+
+ Gdk.CursorType? cursor_type = null;
+ if (event != null)
+ cursor_type = Gdk.CursorType.HAND1;
+
+ Toolkit.set_toplevel_cursor(cell, cursor_type);
+ }
+
+ private void on_cell_button_motion(Toolkit.MotionEvent event) {
+ if (!event.is_button_pressed(Toolkit.Button.PRIMARY))
+ return;
+
// Because using button 1 motion mask, widget is always the original cell the button-pressed
// event originated at
- Cell press_cell = (Cell) widget;
+ Cell press_cell = (Cell) event.widget;
// turn Cell coordinates into GtkGrid coordinates
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;
+ if (!press_cell.translate_coordinates(this, event.point.x, event.point.y, out grid_x, out grid_y))
+ return;
// get the cell the pointer is currently over ... if not found or the same as the original,
// do nothing
Cell? hover_cell = translate_to_cell(grid_x, grid_y);
if (hover_cell == null || hover_cell == press_cell)
- return false;
+ return;
// mark two cells and all in-between as selected, being sure to mark any previous selected
// as unselected
@@ -373,8 +395,6 @@ private class Grid : Gtk.Grid {
return true;
});
-
- return true;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]