gtk-engines r1330 - in trunk: . engines/clearlooks/src



Author: bberg
Date: Fri Mar  6 17:05:48 2009
New Revision: 1330
URL: http://svn.gnome.org/viewvc/gtk-engines?rev=1330&view=rev

Log:
2009-03-06  Benjamin Berg  <benjamin sipsolutions net>

	* engines/clearlooks/src/clearlooks_draw.c:
	(clearlooks_draw_entry_progress),
	(clearlooks_register_style_classic):
	* engines/clearlooks/src/clearlooks_style.c:
	(clearlooks_style_draw_box):
	* engines/clearlooks/src/clearlooks_types.h:
	Support for entry progress drawing.


Modified:
   trunk/ChangeLog
   trunk/engines/clearlooks/src/clearlooks_draw.c
   trunk/engines/clearlooks/src/clearlooks_style.c
   trunk/engines/clearlooks/src/clearlooks_types.h

Modified: trunk/engines/clearlooks/src/clearlooks_draw.c
==============================================================================
--- trunk/engines/clearlooks/src/clearlooks_draw.c	(original)
+++ trunk/engines/clearlooks/src/clearlooks_draw.c	Fri Mar  6 17:05:48 2009
@@ -466,6 +466,74 @@
 }
 
 static void
+clearlooks_draw_entry_progress (cairo_t *cr,
+                                const ClearlooksColors *colors,
+                                const WidgetParameters *params,
+                                const EntryProgressParameters *progress,
+                                int x, int y, int width, int height)
+{
+	CairoColor border;
+	CairoColor fill;
+	gint entry_width, entry_height;
+	double entry_radius;
+	double radius;
+
+	cairo_save (cr);
+
+	fill = colors->bg[params->state_type];
+	ge_shade_color (&fill, 0.9, &border);
+
+	if (progress->max_size_known) {
+		entry_width = progress->max_size.width + progress->border.left + progress->border.right;
+		entry_height = progress->max_size.height + progress->border.top + progress->border.bottom;
+		entry_radius = MIN (params->radius, MIN ((entry_width - 4.0) / 2.0, (entry_height - 4.0) / 2.0));
+	} else {
+		entry_radius = params->radius;
+	}
+
+	radius = MAX (0, entry_radius - MAX (MAX (progress->border.left, progress->border.right),
+	                                     MAX (progress->border.top, progress->border.bottom)));
+
+	if (progress->max_size_known) {
+		/* Clip to the max size, and then draw a (larger) rectangle ... */
+		ge_cairo_rounded_rectangle (cr, progress->max_size.x,
+		                                progress->max_size.y,
+		                                progress->max_size.width,
+		                                progress->max_size.height,
+		                                radius,
+		                                CR_CORNER_ALL);
+		cairo_clip (cr);
+
+		/* We just draw wider by one pixel ... */
+		ge_cairo_set_color (cr, &fill);
+		cairo_rectangle (cr, x, y + 1, width, height - 2);
+		cairo_fill (cr);
+
+		cairo_set_line_width (cr, 1.0);
+		ge_cairo_set_color (cr, &border);
+		ge_cairo_inner_rectangle (cr, x - 1, y, width + 2, height);
+		cairo_stroke (cr);
+	} else {
+		ge_cairo_rounded_rectangle (cr, x, y, width + 10, height + 10, radius, CR_CORNER_ALL);
+		cairo_clip (cr);
+		ge_cairo_rounded_rectangle (cr, x - 10, y - 10, width + 10, height + 10, radius, CR_CORNER_ALL);
+		cairo_clip (cr);
+
+
+		ge_cairo_set_color (cr, &fill);
+		ge_cairo_rounded_rectangle (cr, x + 1, y + 1, width - 2, height - 2, radius, CR_CORNER_ALL);
+		cairo_fill (cr);
+
+		cairo_set_line_width (cr, 1.0);
+		ge_cairo_set_color (cr, &border);
+		ge_cairo_rounded_rectangle (cr, x + 0.5, y + 0.5, width - 1.0, height - 1.0, radius, CR_CORNER_ALL);
+		cairo_stroke (cr);
+	}
+
+	cairo_restore (cr);
+}
+
+static void
 clearlooks_draw_spinbutton (cairo_t *cr,
                             const ClearlooksColors *colors,
                             const WidgetParameters *params,
@@ -2390,6 +2458,7 @@
 	functions->draw_progressbar_fill    = clearlooks_draw_progressbar_fill;
 	functions->draw_slider_button       = clearlooks_draw_slider_button;
 	functions->draw_entry               = clearlooks_draw_entry;
+	functions->draw_entry_progress      = clearlooks_draw_entry_progress;
 	functions->draw_spinbutton          = clearlooks_draw_spinbutton;
 	functions->draw_spinbutton_down     = clearlooks_draw_spinbutton_down;
 	functions->draw_optionmenu          = clearlooks_draw_optionmenu;
@@ -2414,7 +2483,7 @@
 	functions->draw_handle              = clearlooks_draw_handle;
 	functions->draw_resize_grip         = clearlooks_draw_resize_grip;
 	functions->draw_arrow               = clearlooks_draw_arrow;
-	functions->draw_focus                = clearlooks_draw_focus;
+	functions->draw_focus               = clearlooks_draw_focus;
 	functions->draw_checkbox            = clearlooks_draw_checkbox;
 	functions->draw_radiobutton         = clearlooks_draw_radiobutton;
 	functions->draw_shadow              = clearlooks_draw_shadow;

Modified: trunk/engines/clearlooks/src/clearlooks_style.c
==============================================================================
--- trunk/engines/clearlooks/src/clearlooks_style.c	(original)
+++ trunk/engines/clearlooks/src/clearlooks_style.c	Fri Mar  6 17:05:48 2009
@@ -848,6 +848,117 @@
 		                                       x, y, width, height,
 		                                       10 - (int)(elapsed * 10.0) % 10);
 	}
+	else if (DETAIL ("entry-progress"))
+	{
+		WidgetParameters params;
+		EntryProgressParameters progress;
+
+		clearlooks_set_widget_parameters (widget, style, state_type, &params);
+
+		progress.max_size_known = FALSE;
+		progress.max_size.x = 0;
+		progress.max_size.y = 0;
+		progress.max_size.width = 0;
+		progress.max_size.height = 0;
+		progress.border.left = style->xthickness;
+		progress.border.right = style->xthickness;
+		progress.border.top = style->ythickness;
+		progress.border.bottom = style->ythickness;
+
+		if (GE_IS_ENTRY (widget)) {
+			GtkBorder *border;
+			/* Try to retrieve the style property. */
+			gtk_widget_style_get (widget,
+			                      "progress-border", &border,
+			                      NULL);
+
+			if (border) {
+				progress.border = *border;
+				gtk_border_free (border);
+			}
+
+			/* We got an entry, but well, we may not be drawing to
+			 * this particular widget ... it may not even be realized.
+			 * Also, we need to be drawing on a window obviously ... */
+			if (GTK_WIDGET_REALIZED (widget) &&
+			    GDK_IS_WINDOW (window) &&
+			    gdk_window_is_visible (widget->window)) {
+				/* Assumptions done by this code:
+				 *  - GtkEntry has some nested windows.
+				 *  - widget->window is the entries window
+				 *  - widget->window is the size of the entry part
+				 *    (and not larger)
+				 *  - only one layer of subwindows
+				 * These should be true with any GTK+ 2.x version.
+				 */
+
+				if (widget->window == window) {
+					progress.max_size_known = TRUE;
+					gdk_drawable_get_size (widget->window,
+					                       &progress.max_size.width,
+					                       &progress.max_size.height);
+
+				} else {
+					GdkWindow *parent;
+					parent = gdk_window_get_parent (window);
+					if (widget->window == parent) {
+						gint pos_x, pos_y;
+						/* widget->window is the parent window
+						 * of the current one. This means we can
+						 * calculate the correct offsets. */
+						gdk_window_get_position (window, &pos_x, &pos_y);
+						progress.max_size.x = -pos_x;
+						progress.max_size.y = -pos_y;
+
+						progress.max_size_known = TRUE;
+						gdk_drawable_get_size (widget->window,
+						                       &progress.max_size.width,
+						                       &progress.max_size.height);
+					} /* Nothing we can do in this case ... */
+				}
+
+				/* Now, one more thing needs to be done. If interior-focus
+				 * is off, then the entry may be a bit smaller. */
+				if (progress.max_size_known && GTK_WIDGET_HAS_FOCUS (widget)) {
+					gboolean interior_focus = TRUE;
+					gint focus_line_width = 1;
+
+					gtk_widget_style_get (widget,
+					                      "interior-focus", &interior_focus,
+					                      "focus-line-width", &focus_line_width,
+					                      NULL);
+
+					if (!interior_focus) {
+						progress.max_size.x += focus_line_width;
+						progress.max_size.y += focus_line_width;
+						progress.max_size.width -= 2*focus_line_width;
+						progress.max_size.height -= 2*focus_line_width;
+					}
+				}
+				
+				if (progress.max_size_known) {
+					progress.max_size.x += progress.border.left;
+					progress.max_size.y += progress.border.top;
+					progress.max_size.width -= progress.border.left + progress.border.right;
+					progress.max_size.height -= progress.border.top + progress.border.bottom;
+
+					/* Now test that max_size.height == height, if that
+					 * fails, something has gone wrong ... so then throw away
+					 * the max_size information. */
+					if (progress.max_size.height != height) {
+						progress.max_size_known = FALSE;
+						progress.max_size.x = 0;
+						progress.max_size.y = 0;
+						progress.max_size.width = 0;
+						progress.max_size.height = 0;
+					}
+				}
+			}
+		}
+
+		STYLE_FUNCTION(draw_entry_progress) (cr, colors, &params, &progress,
+		                                     x, y, width, height);
+	}
 	else if (DETAIL ("optionmenu"))
 	{
 		WidgetParameters params;

Modified: trunk/engines/clearlooks/src/clearlooks_types.h
==============================================================================
--- trunk/engines/clearlooks/src/clearlooks_types.h	(original)
+++ trunk/engines/clearlooks/src/clearlooks_types.h	Fri Mar  6 17:05:48 2009
@@ -302,6 +302,18 @@
 
 typedef struct
 {
+	/* The maximum size of the fill. Calcualted from the entries allocation,
+	 * and other information. Relative to the drawn position.
+	 */
+	GdkRectangle max_size;
+	gboolean max_size_known;
+	/* The border around the bar. This can be used for radius calculations.
+	 */
+	GtkBorder border;
+} EntryProgressParameters;
+
+typedef struct
+{
 	ClearlooksArrowType type;
 	ClearlooksDirection direction;
 } ArrowParameters;
@@ -360,6 +372,12 @@
 	                               const WidgetParameters *widget,
 	                               int x, int y, int width, int height);
 
+	void (*draw_entry_progress)   (cairo_t *cr,
+	                               const ClearlooksColors *colors,
+	                               const WidgetParameters *widget,
+	                               const EntryProgressParameters *progress,
+	                               int x, int y, int width, int height);
+
 	void (*draw_spinbutton)       (cairo_t *cr,
 	                               const ClearlooksColors *colors,
 	                               const WidgetParameters *widget,



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