[gtk+] Change GtkCalendar's inner border and separator values from hard-coded ones to using style propertie



commit cd3510ce1fe6273073ba717b190aa3d327a011c7
Author: Cody Russell <bratsche gnome org>
Date:   Tue Aug 3 10:45:14 2010 -0500

    Change GtkCalendar's inner border and separator values from hard-coded
    ones to using style properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=624779

 gtk/gtkcalendar.c |  189 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 135 insertions(+), 54 deletions(-)
---
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index 1bac951..9d111f5 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -195,12 +195,6 @@ dates_difference(guint year1, guint mm1, guint dd1,
 
 /* Spacing around day/week headers and main area, inside those windows */
 #define CALENDAR_MARGIN		 0
-/* Spacing around day/week headers and main area, outside those windows */
-#define INNER_BORDER		 4
-/* Separation between day headers and main area */
-#define CALENDAR_YSEP		 4
-/* Separation between week headers and main area */
-#define CALENDAR_XSEP		 4
 
 #define DAY_XSEP		 0 /* not really good for small calendar */
 #define DAY_YSEP		 0 /* not really good for small calendar */
@@ -403,7 +397,9 @@ static void calendar_invalidate_arrow   (GtkCalendar *widget,
 					 guint      arrow);
 
 static void calendar_compute_days      (GtkCalendar *calendar);
-     
+static gint calendar_get_xsep          (GtkCalendar *calendar);
+static gint calendar_get_ysep          (GtkCalendar *calendar);
+
 static char    *default_abbreviated_dayname[7];
 static char    *default_monthname[12];
 
@@ -601,6 +597,43 @@ gtk_calendar_class_init (GtkCalendarClass *class)
 							 TRUE,
 							 GTK_PARAM_READWRITE));
 
+
+  /**
+   * GtkCalendar:inner-border
+   *
+   * The spacing around the day/week headers and main area.
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("inner-border",
+                                                             P_("Inner border"),
+                                                             P_("Inner border space"),
+                                                             0, G_MAXINT, 4,
+                                                             GTK_PARAM_READABLE));
+
+  /**
+   * GtkCalndar:vertical-separation
+   *
+   * Separation between day headers and main area.
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("vertical-separation",
+                                                             P_("Vertical separation"),
+                                                             P_("Space between day headers and main area"),
+                                                             0, G_MAXINT, 4,
+                                                             GTK_PARAM_READABLE));
+
+  /**
+   * GtkCalendar:horizontal-separation
+   *
+   * Separation between week headers and main area.
+   */
+  gtk_widget_class_install_style_property (widget_class,
+                                           g_param_spec_int ("horizontal-separation",
+                                                             P_("Horizontal separation"),
+                                                             P_("Space between week headers and main area"),
+                                                             0, G_MAXINT, 4,
+                                                             GTK_PARAM_READABLE));
+
   /**
    * GtkCalendar::month-changed:
    * @calendar: the object which received the signal.
@@ -1097,7 +1130,7 @@ calendar_row_height (GtkCalendar *calendar)
 {
   return (GTK_CALENDAR_GET_PRIVATE (calendar)->main_h - CALENDAR_MARGIN
 	  - ((calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
-	     ? CALENDAR_YSEP : CALENDAR_MARGIN)) / 6;
+	     ? calendar_get_ysep (calendar) : CALENDAR_MARGIN)) / 6;
 }
 
 
@@ -1109,13 +1142,14 @@ calendar_left_x_for_column (GtkCalendar *calendar,
 {
   gint width;
   gint x_left;
-  
+  gint calendar_xsep = calendar_get_xsep (calendar);
+
   if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
     column = 6 - column;
 
   width = GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
   if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
-    x_left = CALENDAR_XSEP + (width + DAY_XSEP) * column;
+    x_left = calendar_xsep + (width + DAY_XSEP) * column;
   else
     x_left = CALENDAR_MARGIN + (width + DAY_XSEP) * column;
   
@@ -1558,6 +1592,42 @@ calendar_realize_header (GtkCalendar *calendar)
   calendar_realize_arrows (calendar);
 }
 
+static gint
+calendar_get_inner_border (GtkCalendar *calendar)
+{
+  gint inner_border;
+
+  gtk_widget_style_get (GTK_WIDGET (calendar),
+                        "inner-border", &inner_border,
+                        NULL);
+
+  return inner_border;
+}
+
+static gint
+calendar_get_xsep (GtkCalendar *calendar)
+{
+  gint xsep;
+
+  gtk_widget_style_get (GTK_WIDGET (calendar),
+                        "horizontal-separation", &xsep,
+                        NULL);
+
+  return xsep;
+}
+
+static gint
+calendar_get_ysep (GtkCalendar *calendar)
+{
+  gint ysep;
+
+  gtk_widget_style_get (GTK_WIDGET (calendar),
+                        "vertical-separation", &ysep,
+                        NULL);
+
+  return ysep;
+}
+
 static void
 calendar_realize_day_names (GtkCalendar *calendar)
 {
@@ -1565,7 +1635,8 @@ calendar_realize_day_names (GtkCalendar *calendar)
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   GdkWindowAttr attributes;
   gint attributes_mask;
-  
+  gint inner_border = calendar_get_inner_border (calendar);
+
   /* Day names	window --------------------------------- */
   if ( calendar->display_flags & GTK_CALENDAR_SHOW_DAY_NAMES)
     {
@@ -1575,11 +1646,11 @@ calendar_realize_day_names (GtkCalendar *calendar)
       attributes.colormap = gtk_widget_get_colormap (widget);
       attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
       attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-      attributes.x = (widget->style->xthickness + INNER_BORDER);
+      attributes.x = (widget->style->xthickness + inner_border);
       attributes.y = priv->header_h + (widget->style->ythickness 
-					   + INNER_BORDER);
+					   + inner_border);
       attributes.width = (widget->allocation.width 
-			  - (widget->style->xthickness + INNER_BORDER) 
+			  - (widget->style->xthickness + inner_border) 
 			  * 2);
       attributes.height = priv->day_name_h;
       priv->day_name_win = gdk_window_new (widget->window,
@@ -1603,7 +1674,8 @@ calendar_realize_week_numbers (GtkCalendar *calendar)
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (calendar);
   GdkWindowAttr attributes;
   gint attributes_mask;
-  
+  gint inner_border = calendar_get_inner_border (calendar);
+
   /* Week number window -------------------------------- */
   if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
     {
@@ -1615,11 +1687,11 @@ calendar_realize_week_numbers (GtkCalendar *calendar)
       
       attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
-	attributes.x = widget->style->xthickness + INNER_BORDER;
+	attributes.x = widget->style->xthickness + inner_border;
       else 
-	attributes.x = widget->allocation.width - priv->week_width - (widget->style->xthickness + INNER_BORDER);
+	attributes.x = widget->allocation.width - priv->week_width - (widget->style->xthickness + inner_border);
       attributes.y = (priv->header_h + priv->day_name_h 
-		      + (widget->style->ythickness + INNER_BORDER));
+		      + (widget->style->ythickness + inner_border));
       attributes.width = priv->week_width;
       attributes.height = priv->main_h;
       priv->week_win = gdk_window_new (widget->window,
@@ -1642,6 +1714,7 @@ gtk_calendar_realize (GtkWidget *widget)
   GtkCalendarPrivate *priv = GTK_CALENDAR_GET_PRIVATE (widget);
   GdkWindowAttr attributes;
   gint attributes_mask;
+  gint inner_border = calendar_get_inner_border (calendar);
 
   gtk_widget_set_realized (widget, TRUE);
   
@@ -1674,14 +1747,14 @@ gtk_calendar_realize (GtkWidget *widget)
 			    | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
   
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
-    attributes.x = priv->week_width + (widget->style->ythickness + INNER_BORDER);
+    attributes.x = priv->week_width + (widget->style->ythickness + inner_border);
   else
-    attributes.x = widget->style->ythickness + INNER_BORDER;
+    attributes.x = widget->style->ythickness + inner_border;
 
   attributes.y = (priv->header_h + priv->day_name_h 
-		  + (widget->style->ythickness + INNER_BORDER));
+		  + (widget->style->ythickness + inner_border));
   attributes.width = (widget->allocation.width - attributes.x 
-		      - (widget->style->xthickness + INNER_BORDER));
+		      - (widget->style->xthickness + inner_border));
   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
     attributes.width -= priv->week_width;
 
@@ -1843,6 +1916,9 @@ gtk_calendar_size_request (GtkWidget	  *widget,
   gint focus_width;
   gint focus_padding;
   gint max_detail_height;
+  gint inner_border = calendar_get_inner_border (calendar);
+  gint calendar_ysep = calendar_get_ysep (calendar);
+  gint calendar_xsep = calendar_get_xsep (calendar);
 
   gtk_widget_style_get (GTK_WIDGET (widget),
 			"focus-line-width", &focus_width,
@@ -2018,11 +2094,11 @@ gtk_calendar_size_request (GtkWidget	  *widget,
 
   main_width = (7 * (priv->min_day_width + (focus_padding + focus_width) * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
 		+ (priv->max_week_char_width
-		   ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + CALENDAR_XSEP * 2
+		   ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + calendar_xsep * 2
 		   : 0));
   
   
-  requisition->width = MAX (header_width, main_width + INNER_BORDER * 2) + widget->style->xthickness * 2;
+  requisition->width = MAX (header_width, main_width + inner_border * 2) + widget->style->xthickness * 2;
   
   /*
    * Calculate the requisition height for the widget.
@@ -2030,7 +2106,7 @@ gtk_calendar_size_request (GtkWidget	  *widget,
   
   if (calendar->display_flags & GTK_CALENDAR_SHOW_HEADING)
     {
-      priv->header_h = (max_header_height + CALENDAR_YSEP * 2);
+      priv->header_h = (max_header_height + calendar_ysep * 2);
     }
   else
     {
@@ -2042,7 +2118,7 @@ gtk_calendar_size_request (GtkWidget	  *widget,
       priv->day_name_h = (priv->max_label_char_ascent
 				  + priv->max_label_char_descent
 				  + 2 * (focus_padding + focus_width) + calendar_margin);
-      calendar_margin = CALENDAR_YSEP;
+      calendar_margin = calendar_ysep;
     } 
   else
     {
@@ -2059,7 +2135,7 @@ gtk_calendar_size_request (GtkWidget	  *widget,
   height = (priv->header_h + priv->day_name_h 
 	    + priv->main_h);
   
-  requisition->height = height + (widget->style->ythickness + INNER_BORDER) * 2;
+  requisition->height = height + (widget->style->ythickness + inner_border) * 2;
 
   g_object_unref (layout);
 }
@@ -2073,23 +2149,25 @@ gtk_calendar_size_allocate (GtkWidget	  *widget,
   gint xthickness = widget->style->xthickness;
   gint ythickness = widget->style->xthickness;
   guint i;
-  
+  gint inner_border = calendar_get_inner_border (calendar);
+  gint calendar_xsep = calendar_get_xsep (calendar);
+
   widget->allocation = *allocation;
     
   if (calendar->display_flags & GTK_CALENDAR_SHOW_WEEK_NUMBERS)
     {
       priv->day_width = (priv->min_day_width
-			 * ((allocation->width - (xthickness + INNER_BORDER) * 2
-			     - (CALENDAR_MARGIN * 2) -  (DAY_XSEP * 6) - CALENDAR_XSEP * 2))
+			 * ((allocation->width - (xthickness + inner_border) * 2
+			     - (CALENDAR_MARGIN * 2) -  (DAY_XSEP * 6) - calendar_xsep * 2))
 			 / (7 * priv->min_day_width + priv->max_week_char_width * 2));
-      priv->week_width = ((allocation->width - (xthickness + INNER_BORDER) * 2
-			   - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2 )
-			  - priv->day_width * 7 + CALENDAR_MARGIN + CALENDAR_XSEP);
+      priv->week_width = ((allocation->width - (xthickness + inner_border) * 2
+			   - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - calendar_xsep * 2 )
+			  - priv->day_width * 7 + CALENDAR_MARGIN + calendar_xsep);
     } 
   else 
     {
       priv->day_width = (allocation->width
-			 - (xthickness + INNER_BORDER) * 2
+			 - (xthickness + inner_border) * 2
 			 - (CALENDAR_MARGIN * 2)
 			 - (DAY_XSEP * 6))/7;
       priv->week_width = 0;
@@ -2119,45 +2197,45 @@ gtk_calendar_size_allocate (GtkWidget	  *widget,
       
       if (priv->day_name_win)
 	gdk_window_move_resize (priv->day_name_win,
-				xthickness + INNER_BORDER,
-				priv->header_h + (widget->style->ythickness + INNER_BORDER),
-				allocation->width - (xthickness + INNER_BORDER) * 2,
+				xthickness + inner_border,
+				priv->header_h + (widget->style->ythickness + inner_border),
+				allocation->width - (xthickness + inner_border) * 2,
 				priv->day_name_h);
       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
 	{
 	  if (priv->week_win)
 	    gdk_window_move_resize (priv->week_win,
-				    (xthickness + INNER_BORDER),
+				    (xthickness + inner_border),
 				    priv->header_h + priv->day_name_h
-				    + (widget->style->ythickness + INNER_BORDER),
+				    + (widget->style->ythickness + inner_border),
 				    priv->week_width,
 				    priv->main_h);
 	  gdk_window_move_resize (priv->main_win,
-				  priv->week_width + (xthickness + INNER_BORDER),
+				  priv->week_width + (xthickness + inner_border),
 				  priv->header_h + priv->day_name_h
-				  + (widget->style->ythickness + INNER_BORDER),
+				  + (widget->style->ythickness + inner_border),
 				  allocation->width 
 				  - priv->week_width 
-				  - (xthickness + INNER_BORDER) * 2,
+				  - (xthickness + inner_border) * 2,
 				  priv->main_h);
 	}
       else 
 	{
 	  gdk_window_move_resize (priv->main_win,
-				  (xthickness + INNER_BORDER),
+				  (xthickness + inner_border),
 				  priv->header_h + priv->day_name_h
-				  + (widget->style->ythickness + INNER_BORDER),
+				  + (widget->style->ythickness + inner_border),
 				  allocation->width 
 				  - priv->week_width 
-				  - (xthickness + INNER_BORDER) * 2,
+				  - (xthickness + inner_border) * 2,
 				  priv->main_h);
 	  if (priv->week_win)
 	    gdk_window_move_resize (priv->week_win,
 				    allocation->width 
 				    - priv->week_width 
-				    - (xthickness + INNER_BORDER),
+				    - (xthickness + inner_border),
 				    priv->header_h + priv->day_name_h
-				    + (widget->style->ythickness + INNER_BORDER),
+				    + (widget->style->ythickness + inner_border),
 				    priv->week_width,
 				    priv->main_h);
 	}
@@ -2287,7 +2365,9 @@ calendar_paint_day_names (GtkCalendar *calendar)
   PangoRectangle logical_rect;
   gint focus_padding;
   gint focus_width;
-  
+  gint calendar_ysep = calendar_get_ysep (calendar);
+  gint calendar_xsep = calendar_get_xsep (calendar);
+
   cr = gdk_cairo_create (priv->day_name_win);
   
   gtk_widget_style_get (GTK_WIDGET (widget),
@@ -2314,9 +2394,9 @@ calendar_paint_day_names (GtkCalendar *calendar)
     {
       cairo_rectangle (cr, 
 		       CALENDAR_MARGIN,
-		       priv->day_name_h - CALENDAR_YSEP,
-		       priv->week_width - CALENDAR_YSEP - CALENDAR_MARGIN,
-		       CALENDAR_YSEP);
+		       priv->day_name_h - calendar_ysep,
+		       priv->week_width - calendar_ysep - CALENDAR_MARGIN,
+		       calendar_ysep);
       cairo_fill (cr);
     }
   
@@ -2342,7 +2422,7 @@ calendar_paint_day_names (GtkCalendar *calendar)
       cairo_move_to (cr, 
 		     (CALENDAR_MARGIN +
 		      + (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
-			 (priv->week_width + (priv->week_width ? CALENDAR_XSEP : 0))
+			 (priv->week_width + (priv->week_width ? calendar_xsep : 0))
 			 : 0)
 		      + day_wid_sep * i
 		      + (day_width - logical_rect.width)/2),
@@ -2369,7 +2449,8 @@ calendar_paint_week_numbers (GtkCalendar *calendar)
   PangoRectangle logical_rect;
   gint focus_padding;
   gint focus_width;
-  
+  gint calendar_xsep = calendar_get_xsep (calendar);
+
   cr = gdk_cairo_create (priv->week_win);
   
   gtk_widget_style_get (GTK_WIDGET (widget),
@@ -2435,7 +2516,7 @@ calendar_paint_week_numbers (GtkCalendar *calendar)
 
       x_loc = (priv->week_width
 	       - logical_rect.width
-	       - CALENDAR_XSEP - focus_padding - focus_width);
+	       - calendar_xsep - focus_padding - focus_width);
 
       cairo_move_to (cr, x_loc, y_loc);
       pango_cairo_show_layout (cr, layout);



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