GtkCalendar focus patch



Hi:

Attached is a patch for gtkcalendar which corrects problems with focus
drawing for wide focus lines and accessibility.

It:  
(1) adjusts size requests for calendars to account for the wider focus
line requirements;
(2) removes assumption that focus line is 1 pixel wide;
(3) uses gtk_paint_focus to do the focus line;
(4) paints the focus line in the FG color for the current cell state,
according to whether 
    the focussed cell is selected or not (otherwise the focus line will
be invisible for
    high contrast settings when drawn against the "SELECTED" date
background).

This makes calendar date focus drawing consistent with the rest of GTK.

OK to commit (with appropriate ChangeLog entry?)

-Bill
Index: gtk/gtkcalendar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcalendar.c,v
retrieving revision 1.38
diff -u -p -r1.38 gtkcalendar.c
--- gtk/gtkcalendar.c	2001/12/03 15:24:25	1.38
+++ gtk/gtkcalendar.c	2002/01/24 14:53:34
@@ -1152,9 +1152,12 @@ gtk_calendar_size_request (GtkWidget	  *
   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 @@ gtk_calendar_size_request (GtkWidget	  *
 						 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 @@ gtk_calendar_size_request (GtkWidget	  *
     {
       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 @@ gtk_calendar_size_request (GtkWidget	  *
   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 @@ gtk_calendar_size_request (GtkWidget	  *
 				  (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 @@ gtk_calendar_paint_day (GtkWidget *widge
   gint y_top;
   gint y_loc;
   gint day_xspace;
+  gint focus_width;
+
   GtkCalendarPrivateData *private_data;
   PangoLayout *layout;
   PangoRectangle logical_rect;
@@ -1762,6 +1768,8 @@ gtk_calendar_paint_day (GtkWidget *widge
       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 @@ gtk_calendar_paint_day (GtkWidget *widge
   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 @@ gtk_calendar_paint_day (GtkWidget *widge
   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]