[maemo-commits] [maemo-commits] r9307 - in projects/haf/trunk/sapwood: . src

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Jan 24 17:12:36 EET 2007
Author: tko
Date: 2007-01-24 17:12:33 +0200 (Wed, 24 Jan 2007)
New Revision: 9307

Modified:
   projects/haf/trunk/sapwood/ChangeLog
   projects/haf/trunk/sapwood/src/sapwood-draw.c
Log:
Special theming for dialog buttons

2007-01-24  Tommi Komulainen  <tommi.komulainen at nokia.com>

	Adjust the detail for buttons in button boxes depending on the button
	position inside the button box for enhanced theming (special rounding
	for outmost button edges.) For horizontal button box we use the
	following details to work with existing themes:
	- osso_button_nesw
	- osso_button_nsw
	- osso_button_nes
	- osso_button_ns

	vertical:
	- osso_button_nesw
	- osso_button_new
	- osso_button_esw
	- osso_button_ew

	NOTE: this loses the ability to theme the 'default' response button
	differently from the others. We could use 'osso_buttondefault_nesw' or
	similar but that would then require duplicate theme declarations or
	risk really bad looking theming when the 'default' style is used
	without matching graphics. Some way to handle fallbacks
	(buttondefault-shaped - button-shaped - buttondefault - button) could
	be useful.

	* src/sapwood-draw.c (maybe_set_dialog_button_details,
	draw_simple_image): When painting GtkButtons check if it's contained
	in a button box, and if so figure out the position
	(solitary,left,right,middle - similarly for vertical) and replace the
	detail with specific ones matching the position.


Modified: projects/haf/trunk/sapwood/ChangeLog
===================================================================
--- projects/haf/trunk/sapwood/ChangeLog	2007-01-24 15:10:42 UTC (rev 9306)
+++ projects/haf/trunk/sapwood/ChangeLog	2007-01-24 15:12:33 UTC (rev 9307)
@@ -1,5 +1,36 @@
 2007-01-24  Tommi Komulainen  <tommi.komulainen at nokia.com>
 
+	Adjust the detail for buttons in button boxes depending on the button
+	position inside the button box for enhanced theming (special rounding
+	for outmost button edges.) For horizontal button box we use the
+	following details to work with existing themes:
+	- osso_button_nesw
+	- osso_button_nsw
+	- osso_button_nes
+	- osso_button_ns
+
+	vertical:
+	- osso_button_nesw
+	- osso_button_new
+	- osso_button_esw
+	- osso_button_ew
+
+	NOTE: this loses the ability to theme the 'default' response button
+	differently from the others. We could use 'osso_buttondefault_nesw' or
+	similar but that would then require duplicate theme declarations or
+	risk really bad looking theming when the 'default' style is used
+	without matching graphics. Some way to handle fallbacks
+	(buttondefault-shaped - button-shaped - buttondefault - button) could
+	be useful.
+
+	* src/sapwood-draw.c (maybe_set_dialog_button_details,
+	draw_simple_image): When painting GtkButtons check if it's contained
+	in a button box, and if so figure out the position
+	(solitary,left,right,middle - similarly for vertical) and replace the
+	detail with specific ones matching the position.
+
+2007-01-24  Tommi Komulainen  <tommi.komulainen at nokia.com>
+
 	* src/sapwood-pixmap.c (sapwood_pixmap_get_pixmap): Switch x/y indices
 	the right way around.
 

Modified: projects/haf/trunk/sapwood/src/sapwood-draw.c
===================================================================
--- projects/haf/trunk/sapwood/src/sapwood-draw.c	2007-01-24 15:10:42 UTC (rev 9306)
+++ projects/haf/trunk/sapwood/src/sapwood-draw.c	2007-01-24 15:12:33 UTC (rev 9307)
@@ -102,6 +102,79 @@
   return NULL;
 }
 
+static void
+maybe_set_dialog_button_details (GtkWidget *button, ThemeMatchData *match_data)
+{
+  GtkWidget *bbox;
+  gboolean secondary;
+  gboolean horizontal;
+  GtkWidget *first = NULL;
+  GtkWidget *last = NULL;
+  GList *list;
+
+  if (!match_data->detail ||
+      (strcmp (match_data->detail, "button") != 0 &&
+       strcmp (match_data->detail, "buttondefault") != 0))
+    return;
+
+  bbox = gtk_widget_get_ancestor (button, GTK_TYPE_BUTTON_BOX);
+  if (!bbox)
+    return;
+
+  horizontal = GTK_IS_HBUTTON_BOX (bbox);
+
+  secondary = gtk_button_box_get_child_secondary (GTK_BUTTON_BOX (bbox),
+						  button);
+
+  for (list = GTK_BOX (bbox)->children; list != NULL; list = list->next)
+    {
+      GtkBoxChild *child_info = list->data;
+      GtkWidget   *widget = child_info->widget;
+
+      if (child_info->is_secondary != secondary ||
+	  !GTK_WIDGET_VISIBLE (widget))
+	continue;
+
+      if (horizontal)
+	{
+	  if (first == NULL || first->allocation.x > widget->allocation.x)
+	    first = widget;
+	  if (last == NULL || last->allocation.x < widget->allocation.x)
+	    last = widget;
+	}
+      else
+	{
+	  if (first == NULL || first->allocation.y > widget->allocation.y)
+	    first = widget;
+	  if (last == NULL || last->allocation.y < widget->allocation.y)
+	    last = widget;
+	}
+    }
+
+  if (horizontal)
+    {
+      if (first == button && button == last)		/* solitary */
+	match_data->detail = "osso_button_nesw";
+      else if (first == button)				/* left */
+	match_data->detail = "osso_button_nsw";
+      else if (last == button)				/* right */
+	match_data->detail = "osso_button_nes";
+      else						/* middle */
+	match_data->detail = "osso_button_ns";
+    }
+  else
+    {
+      if (first == button && button == last)		/* solitary */
+	match_data->detail = "osso_button_nesw";
+      else if (first == button)				/* top */
+	match_data->detail = "osso_button_new";
+      else if (last == button)				/* bottom */
+	match_data->detail = "osso_button_esw";
+      else						/* middle */
+	match_data->detail = "osso_button_ew";
+    }
+}
+
 static gboolean
 draw_simple_image(GtkStyle       *style,
 		  GdkWindow      *window,
@@ -132,6 +205,10 @@
       else
 	match_data->orientation = GTK_ORIENTATION_HORIZONTAL;
     }
+
+  /* Special handling for buttons in dialogs */
+  if (GTK_IS_BUTTON (widget))
+    maybe_set_dialog_button_details (widget, match_data);
     
   image = match_theme_image (style, match_data);
   if (image)


More information about the maemo-commits mailing list