Re: [evolution-patches] seek review patch for bug 48095: week view jump button should be focusable (in the tab loop)



Hi Gilbert,

Can you help to review this patch.

JP Rosevear wrote:
On Wed, 2003-09-03 at 05:49, Bolian Yin wrote:
  
Hi,

Please review the patch.

This patch add the jump button in week view in the tab loop. When focus 
comes to a jump button,
press any printable key or Space/Enter, goto the day view.
    

Approved for HEAD pending Sun hacker review.

-JP
  
Index: art/jump.xpm
===================================================================
RCS file: /cvs/gnome/evolution/art/jump.xpm,v
retrieving revision 1.1
diff -u -r1.1 jump.xpm
--- art/jump.xpm	15 Mar 2001 03:46:48 -0000	1.1
+++ art/jump.xpm	3 Sep 2003 09:15:52 -0000
@@ -12,3 +12,19 @@
 ".++++++++++++++.",
 ".++++++++++++++.",
 "................"};
+
+static char * jump_xpm_focused[] = {
+"16 8 3 1",
+"       c None",
+".      c #0000FF",
+"+      c #FFFF00",
+"................",
+"................",
+"..++++++++++++..",
+"..+..++..++..+..",
+"..+..++..++..+..",
+"..++++++++++++..",
+"................",
+"................"};
+                                                                                                                
+
Index: calendar/gui/e-week-view.c
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-week-view.c,v
retrieving revision 1.183
diff -u -r1.183 e-week-view.c
--- calendar/gui/e-week-view.c	20 Aug 2003 10:16:59 -0000	1.183
+++ calendar/gui/e-week-view.c	3 Sep 2003 09:15:57 -0000
@@ -382,6 +382,8 @@
 		g_signal_connect (week_view->jump_buttons[i], "event",
 				  G_CALLBACK (e_week_view_on_jump_button_event), week_view);
 	}
+	week_view->focused_jump_button = -1;
+
 	gdk_pixbuf_unref (pixbuf);
 
 	/*
@@ -996,22 +998,25 @@
 	EWeekView *week_view;
 	gint new_event_num;
 	gint new_span_num;
-	gint current_event_num;
-	gint current_span_num;
 	gint event_loop;
 	gboolean editable = FALSE;
+	static gint last_focus_event_num = -1, last_focus_span_num = -1;
 
 	g_return_val_if_fail (widget != NULL, FALSE);
 	g_return_val_if_fail (E_IS_WEEK_VIEW (widget), FALSE);
 
 	week_view = E_WEEK_VIEW (widget);
-	current_event_num = week_view->editing_event_num;
-	current_span_num = week_view->editing_span_num;
+
+	if (week_view->focused_jump_button == -1) {
+		last_focus_event_num = week_view->editing_event_num;
+		last_focus_span_num = week_view->editing_span_num;
+	}
+
 	for (event_loop = 0; event_loop < week_view->events->len;
 	     ++event_loop) {
 		if (!e_week_view_get_next_tab_event (week_view, direction,
-						     current_event_num,
-						     current_span_num,
+						     last_focus_event_num,
+						     last_focus_span_num,
 						     &new_event_num,
 						     &new_span_num))
 			return FALSE;
@@ -1029,8 +1034,32 @@
 							    NULL);
 		if (editable)
 			break;
-		current_event_num = new_event_num;
-		current_span_num = new_span_num;
+		else {
+			/* check if we should go to the jump button */
+
+			EWeekViewEvent *event;
+			EWeekViewEventSpan *span;
+			gint current_day;
+
+			event = &g_array_index (week_view->events,
+						EWeekViewEvent,
+						new_event_num);
+			span = &g_array_index (week_view->spans,
+					       EWeekViewEventSpan,
+					       event->spans_index + new_span_num);
+			current_day = span->start_day;
+
+			if ((week_view->focused_jump_button != current_day) &&
+			    e_week_view_is_jump_button_visible(week_view, current_day)) {
+
+				/* focus go to the jump button */
+				e_week_view_stop_editing_event (week_view);
+				gnome_canvas_item_grab_focus (week_view->jump_buttons[current_day]);
+				return TRUE;
+			}
+		}
+		last_focus_event_num = new_event_num;
+		last_focus_span_num = new_span_num;
 	}
 	return editable;
 }
@@ -3571,6 +3600,25 @@
 	g_object_unref (new_comp);
 }
 
+void
+e_week_view_jump_to_button_item (EWeekView *week_view, GnomeCanvasItem *item)
+{
+	gint day;
+	GnomeCalendar *calendar;
+
+	for (day = 0; day < E_WEEK_VIEW_MAX_WEEKS * 7; ++day) {
+		if (item == week_view->jump_buttons[day]) {
+			calendar = e_cal_view_get_calendar (E_CAL_VIEW (week_view));
+			if (calendar)
+				gnome_calendar_dayjump
+					(calendar,
+					 week_view->day_starts[day]);
+			else
+				g_warning ("Calendar not set");
+			return;
+		}
+	}
+}
 
 static gboolean
 e_week_view_on_jump_button_event (GnomeCanvasItem *item,
@@ -3580,21 +3628,47 @@
 	gint day;
 
 	if (event->type == GDK_BUTTON_PRESS) {
-		for (day = 0; day < E_WEEK_VIEW_MAX_WEEKS * 7; day++) {
-			if (item == week_view->jump_buttons[day]) {
-				GnomeCalendar *calendar;
+		e_week_view_jump_to_button_item (week_view, item);
+		return TRUE;
+	}
+	else if (event->type == GDK_KEY_PRESS) {
+		/* return, if Tab, Control or Alt is pressed */
+		if ((event->key.keyval == GDK_Tab) ||
+		    (event->key.state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
+			return FALSE;
+		/* with a return key or a simple character, jump to the day */
+		if ((event->key.keyval == GDK_Return) ||
+		    ((event->key.keyval >= 0x20) &&
+		     (event->key.keyval <= 0xFF))) {
+			e_week_view_jump_to_button_item (week_view, item);
+			return TRUE;
+		}
+	}
+	else if (event->type == GDK_FOCUS_CHANGE) {
+		GdkEventFocus *focus_event = (GdkEventFocus *)event;
+		GdkPixbuf *pixbuf = NULL;
 
-				calendar = e_cal_view_get_calendar (E_CAL_VIEW (week_view));
-				if (calendar)
-					gnome_calendar_dayjump
-						(calendar,
-						 week_view->day_starts[day]);
-				else
-					g_warning ("Calendar not set");
-				return TRUE;
-			}
+		for (day = 0; day < E_WEEK_VIEW_MAX_WEEKS * 7; day++) {
+			if (item == week_view->jump_buttons[day])
+				break;
 		}
 
+		if (focus_event->in) {
+			week_view->focused_jump_button = day;
+			pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**) jump_xpm_focused);
+			gnome_canvas_item_set (week_view->jump_buttons[day],
+					       "GnomeCanvasPixbuf::pixbuf",
+					       pixbuf, NULL);
+		}
+		else {
+			week_view->focused_jump_button = -1;
+			pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**) jump_xpm);
+			gnome_canvas_item_set (week_view->jump_buttons[day],
+					       "GnomeCanvasPixbuf::pixbuf",
+					       pixbuf, NULL);
+		}
+		if (pixbuf)
+			gdk_pixbuf_unref (pixbuf);
 	}
 
 	return FALSE;
@@ -3695,4 +3769,12 @@
 	return (week_view->editing_event_num != -1) ? 1 : 0;
 }
 
+gboolean
+e_week_view_is_jump_button_visible (EWeekView *week_view, gint day)
+{
+	g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);
 
+	if ((day >= 0) && (day < E_WEEK_VIEW_MAX_WEEKS * 7))
+		return week_view->jump_buttons[day]->object.flags & GNOME_CANVAS_ITEM_VISIBLE;
+	return FALSE;
+}
Index: calendar/gui/e-week-view.h
===================================================================
RCS file: /cvs/gnome/evolution/calendar/gui/e-week-view.h,v
retrieving revision 1.46
diff -u -r1.46 e-week-view.h
--- calendar/gui/e-week-view.h	20 Aug 2003 10:17:00 -0000	1.46
+++ calendar/gui/e-week-view.h	3 Sep 2003 09:15:57 -0000
@@ -170,6 +170,7 @@
 	GnomeCanvasItem *main_canvas_item;
 
 	GnomeCanvasItem *jump_buttons[E_WEEK_VIEW_MAX_WEEKS * 7];
+	gint focused_jump_button;
 
 	GtkWidget *vscrollbar;
 
@@ -441,6 +442,11 @@
  					   GnomeCanvasItem *item,
  					   gint		  *event_num_return,
  					   gint		  *span_num_return);
+
+gboolean e_week_view_is_jump_button_visible (EWeekView *week_view,
+					     gint day);
+void e_week_view_jump_to_button_item (EWeekView *week_view, GnomeCanvasItem *item);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]