GtkCalendar focus patch



Hi:

Attached is a GtkCalendar patch for bug 63075, 
"GtkCalendar does not use standard focus drawing mechanism"

http://bugzilla.gnome.org/show_bug.cgi?id=63075

What it does:

(1) increases size allocation when using larger-than-default 
    focus line widths;
(2) uses gtk_paint_focus to draw the focus line;
(3) passes a GtkStateType to gtk_paint_focus such that the 
    focus line is drawn in the foreground color of the focussed 
    date's state (prevents black-on-black drawing);
(3) maintains size compatibility with previous calendar when using 
    default focus width.

Note that this means that calendar focus is drawn with a dashed line
in the default theme now, which is consistent with the rest of GTK+.
However this behavior can readily be changed by changing the 
focus-line-pattern for GtkCalendar in an rc-file.  Likewise the default
theme's foregroung SELECTED color gives low contrast against the 
background (the focus line is drawn as white instead of black) - note
that the dates are drawn with the 'text' gc rather than the fg_gc.
Again, this can be changed by setting the fg_gc[SELECTED] to black
for GtkCalendar in the default rc file.

OK to commit?

-Bill
Index: gtk/gtkcalendar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcalendar.c,v
retrieving revision 1.38
diff -u -r1.38 gtkcalendar.c
--- gtk/gtkcalendar.c	2001/12/03 15:24:25	1.38
+++ gtk/gtkcalendar.c	2002/01/25 15:00:38
@@ -1152,9 +1152,12 @@
   gint calendar_margin = CALENDAR_MARGIN;
   gint header_width, main_width;
   gint max_header_height = 0;
+  gint focus_width;
   
   calendar = GTK_CALENDAR (widget);
   private_data = GTK_CALENDAR_PRIVATE_DATA (widget);
+  gtk_widget_style_get (GTK_WIDGET (widget), "focus-line-width", 
+			&focus_width, NULL);
 
   layout = gtk_widget_create_pango_layout (widget, NULL);
   
@@ -1245,7 +1248,7 @@
 						 logical_rect.width / 2);
       }
   
-  main_width = (7 * (private_data->min_day_width + DAY_XPAD * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
+  main_width = (7 * (private_data->min_day_width + DAY_XPAD * 2 + focus_width * 2 - 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
 		+ (private_data->max_week_char_width
 		   ? private_data->max_week_char_width * 2 + DAY_XPAD * 2 + CALENDAR_XSEP * 2
 		   : 0));
@@ -1270,7 +1273,8 @@
     {
       private_data->day_name_h = (private_data->max_label_char_ascent
 				  + private_data->max_label_char_descent
-				  + 2 * DAY_YPAD + calendar_margin);
+				  + 2 * DAY_YPAD + calendar_margin 
+				  + 2 * focus_width - 1);
       calendar_margin = CALENDAR_YSEP;
     } 
   else
@@ -1281,7 +1285,7 @@
   private_data->main_h = (CALENDAR_MARGIN + calendar_margin
 			  + 6 * (private_data->max_day_char_ascent
 				 + private_data->max_day_char_descent 
-				 + DAY_YPAD * 2)
+				 + DAY_YPAD * 2 + (focus_width - 1) * 2)
 			  + DAY_YSEP * 5);
   
   /* 
@@ -1294,7 +1298,7 @@
 				  (CALENDAR_MARGIN + calendar_margin
 				   + 6 * (private_data->max_day_char_ascent 
 					  + private_data->max_day_char_descent 
-					  + DAY_YPAD * 2)
+					  + DAY_YPAD * 2 + focus_width - 1)
 				   + DAY_YSEP * 5));
     }
   
@@ -1742,6 +1746,8 @@
   gint y_top;
   gint y_loc;
   gint day_xspace;
+  gint focus_width;
+
   GtkCalendarPrivateData *private_data;
   PangoLayout *layout;
   PangoRectangle logical_rect;
@@ -1762,6 +1768,8 @@
       return;
     }
   
+  gtk_widget_style_get (widget, "focus-line-width", &focus_width, NULL);
+
   day_height = row_height (calendar);
   
   day_xspace = private_data->day_width - private_data->max_day_char_width*2;
@@ -1769,7 +1777,7 @@
   day = calendar->day[row][col];
   
   x_left = left_x_for_column (calendar, col);
-  x_loc = x_left + private_data->day_width / 2 + private_data->max_day_char_width;
+  x_loc = x_left + private_data->day_width / 2 + private_data->max_day_char_width;;
   
   y_top = top_y_for_row (calendar, row);
   
@@ -1832,9 +1840,20 @@
   if (GTK_WIDGET_HAS_FOCUS (calendar) 
       && calendar->focus_row == row && calendar->focus_col == col)
     {
-      gdk_draw_rectangle (private_data->main_win, calendar->xor_gc, 
-			  FALSE, x_left, y_top,
-			  private_data->day_width-1, day_height-1);
+      GdkRectangle area;
+      area.x = x_left;
+      area.y = y_top;
+      area.width = private_data->day_width + focus_width;
+      area.height = day_height + focus_width;
+
+      gtk_paint_focus (widget->style, 
+		       private_data->main_win,
+		       (calendar->selected_day == day) 
+		          ? GTK_STATE_SELECTED : GTK_STATE_NORMAL, 
+		       &area, widget, "calendar-day",
+		       x_left, y_top, 
+		       private_data->day_width, 
+		       day_height);
     }
 
   g_object_unref (G_OBJECT (layout));


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