[gedit] Use css for the search popup



commit a3b806adde12ee2a5fcc725d6ff962d294df4109
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Aug 18 19:52:23 2011 +0200

    Use css for the search popup

 gedit/Makefile.am             |    2 -
 gedit/gedit-floating-slider.c |  155 ++++++++++++++++++-----
 gedit/gedit-floating-slider.h |    3 +
 gedit/gedit-rounded-frame.c   |  283 -----------------------------------------
 gedit/gedit-rounded-frame.h   |   61 ---------
 gedit/gedit-view-frame.c      |   18 +--
 tests/Makefile.am             |    6 +-
 tests/test-overlay.c          |    9 +-
 tests/test-rounded-frame.c    |   29 ----
 9 files changed, 134 insertions(+), 432 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index 7748d3d..b5d730c 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -123,7 +123,6 @@ NOINST_H_FILES =			\
 	gedit-plugins-engine.h		\
 	gedit-print-job.h		\
 	gedit-print-preview.h		\
-	gedit-rounded-frame.h		\
 	gedit-session.h			\
 	gedit-settings.h		\
 	gedit-status-combo-box.h	\
@@ -207,7 +206,6 @@ libgedit_c_files =			\
 	gedit-print-job.c		\
 	gedit-print-preview.c		\
 	gedit-progress-info-bar.c	\
-	gedit-rounded-frame.c		\
 	gedit-session.c			\
 	gedit-settings.c		\
 	gedit-statusbar.c		\
diff --git a/gedit/gedit-floating-slider.c b/gedit/gedit-floating-slider.c
index 974b0f4..1ab37d7 100644
--- a/gedit/gedit-floating-slider.c
+++ b/gedit/gedit-floating-slider.c
@@ -28,6 +28,7 @@
 struct _GeditFloatingSliderPrivate
 {
 	GtkAllocation widget_alloc;
+	GtkAllocation child_alloc;
 	GeditTheatricsChoreographerEasing easing;
 	GeditTheatricsChoreographerBlocking blocking;
 	GeditTheatricsAnimationState animation_state;
@@ -37,6 +38,11 @@ struct _GeditFloatingSliderPrivate
 	gdouble percent;
 };
 
+struct _GeditFloatingSliderClassPrivate
+{
+	GtkCssProvider *css;
+};
+
 enum
 {
 	PROP_0,
@@ -49,12 +55,12 @@ enum
 	PROP_ORIENTATION
 };
 
-G_DEFINE_TYPE_EXTENDED (GeditFloatingSlider, gedit_floating_slider, GTK_TYPE_BIN,
-			0,
-			G_IMPLEMENT_INTERFACE (GEDIT_TYPE_ANIMATABLE,
-			                       NULL)
-			G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
-			                       NULL))
+G_DEFINE_TYPE_WITH_CODE (GeditFloatingSlider, gedit_floating_slider, GTK_TYPE_BIN,
+                         g_type_add_class_private (g_define_type_id, sizeof (GeditFloatingSliderClassPrivate));
+                         G_IMPLEMENT_INTERFACE (GEDIT_TYPE_ANIMATABLE,
+                                                NULL)
+                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
+                                                NULL))
 
 static void
 gedit_floating_slider_finalize (GObject *object)
@@ -160,12 +166,22 @@ gedit_floating_slider_get_preferred_width (GtkWidget *widget,
 
 	if (child != NULL)
 	{
+		GtkStyleContext *context;
+		GtkBorder padding;
 		gint child_min, child_nat;
 
 		gtk_widget_get_preferred_width (child, &child_min, &child_nat);
-		priv->widget_alloc.width = child_min;
+
+		priv->child_alloc.width = child_min;
+
+		context = gtk_widget_get_style_context (widget);
+		gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL,
+		                               &padding);
+
+		priv->widget_alloc.width = child_min + padding.left + padding.right;
 	}
 
+
 	if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
 	{
 		width = gedit_theatrics_choreographer_pixel_compose (priv->percent,
@@ -193,10 +209,19 @@ gedit_floating_slider_get_preferred_height (GtkWidget *widget,
 
 	if (child != NULL)
 	{
+		GtkStyleContext *context;
+		GtkBorder padding;
 		gint child_min, child_nat;
 
 		gtk_widget_get_preferred_height (child, &child_min, &child_nat);
-		priv->widget_alloc.height = child_min;
+
+		priv->child_alloc.height = child_min;
+
+		context = gtk_widget_get_style_context (widget);
+		gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL,
+		                               &padding);
+
+		priv->widget_alloc.height = child_min + padding.top + padding.bottom;
 	}
 
 	if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
@@ -226,40 +251,101 @@ gedit_floating_slider_size_allocate (GtkWidget     *widget,
 
 	if (child != NULL)
 	{
+		GtkStyleContext *context;
+		GtkBorder padding;
+		GtkAllocation child_alloc;
+
+		context = gtk_widget_get_style_context (widget);
+		gtk_style_context_get_padding (context, GTK_STATE_FLAG_NORMAL,
+		                               &padding);
+
+		child_alloc = priv->child_alloc;
+
 		if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
 		{
-			priv->widget_alloc.height = allocation->height;
-			priv->widget_alloc.x = 0;
+			child_alloc.y = padding.top;
+			child_alloc.x = padding.left;
 
 			if (priv->blocking == GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE)
 			{
-				priv->widget_alloc.x = allocation->width - priv->widget_alloc.width;
+				child_alloc.x = allocation->width - priv->child_alloc.width - padding.right;
 			}
 		}
 		else
 		{
-			priv->widget_alloc.width = allocation->width;
-			priv->widget_alloc.y = 0;
+			child_alloc.y = padding.top;
+			child_alloc.x = padding.left;
 
 			if (priv->blocking == GEDIT_THEATRICS_CHOREOGRAPHER_BLOCKING_DOWNSTAGE)
 			{
-				priv->widget_alloc.y = allocation->height - priv->widget_alloc.height;
+				child_alloc.y = allocation->height - priv->child_alloc.height - padding.bottom;
 			}
 		}
 
-		if (priv->widget_alloc.height > 0 && priv->widget_alloc.width > 0)
+		if (child_alloc.height > 0 && child_alloc.width > 0)
 		{
-			gtk_widget_size_allocate (child, &priv->widget_alloc);
+			gtk_widget_size_allocate (child, &child_alloc);
 		}
 	}
 }
 
+static gboolean
+gedit_floating_slider_draw (GtkWidget *widget,
+                            cairo_t   *cr)
+{
+	GtkStyleContext *context;
+
+	context = gtk_widget_get_style_context (widget);
+
+	gtk_style_context_save (context);
+	gtk_style_context_set_state (context,
+	                             gtk_widget_get_state_flags (widget));
+
+	gtk_render_background (context, cr, 0, 0,
+	                       gtk_widget_get_allocated_width (widget),
+	                       gtk_widget_get_allocated_height (widget));
+
+	gtk_render_frame (context, cr, 0, 0,
+	                  gtk_widget_get_allocated_width (widget),
+	                  gtk_widget_get_allocated_height (widget));
+
+	gtk_style_context_restore (context);
+
+	return GTK_WIDGET_CLASS (gedit_floating_slider_parent_class)->draw (widget, cr);
+}
+
 static void
 gedit_floating_slider_class_init (GeditFloatingSliderClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-	
+	static const gchar style[] =
+	"* {"
+	  "background-image: -gtk-gradient (linear,\n"
+	                                    "left top, left bottom,\n"
+	                                    "from (shade (@notebook_tab_gradient_a, 0.97)),\n"
+	                                    "to (shade (@notebook_tab_gradient_b, 0.90)));\n"
+
+	  "padding: 6;\n"
+	  "border-color: shade (@notebook_tab_gradient_b, 0.80);\n"
+
+	  "border-radius: 0 0 3 3;\n"
+	  "border-width: 1;\n"
+	  "border-style: solid;\n"
+	"}\n"
+
+	".button {"
+	  "background-color: alpha (@theme_base_color, 0.0);"
+	  "background-image: none;"
+
+	  "padding: 0;\n"
+	  "border-style: none;"
+	  "border-image: none;"
+
+	  "-GtkButton-image-spacing: 0;"
+	  "-GtkButton-inner-border: 0;"
+	"}";
+
 	object_class->finalize = gedit_floating_slider_finalize;
 	object_class->get_property = gedit_floating_slider_get_property;
 	object_class->set_property = gedit_floating_slider_set_property;
@@ -267,46 +353,53 @@ gedit_floating_slider_class_init (GeditFloatingSliderClass *klass)
 	widget_class->get_preferred_width = gedit_floating_slider_get_preferred_width;
 	widget_class->get_preferred_height = gedit_floating_slider_get_preferred_height;
 	widget_class->size_allocate = gedit_floating_slider_size_allocate;
+	widget_class->draw = gedit_floating_slider_draw;
 
-	g_object_class_override_property (object_class,
-	                                  PROP_EASING,
+	g_object_class_override_property (object_class, PROP_EASING,
 	                                  "easing");
 
-	g_object_class_override_property (object_class,
-	                                  PROP_BLOCKING,
+	g_object_class_override_property (object_class, PROP_BLOCKING,
 	                                  "blocking");
 
-	g_object_class_override_property (object_class,
-	                                  PROP_ANIMATION_STATE,
+	g_object_class_override_property (object_class, PROP_ANIMATION_STATE,
 	                                  "animation-state");
 
-	g_object_class_override_property (object_class,
-	                                  PROP_DURATION,
+	g_object_class_override_property (object_class, PROP_DURATION,
 	                                  "duration");
 
-	g_object_class_override_property (object_class,
-	                                  PROP_PERCENT,
+	g_object_class_override_property (object_class, PROP_PERCENT,
 	                                  "percent");
 
-	g_object_class_override_property (object_class,
-	                                  PROP_BIAS,
+	g_object_class_override_property (object_class, PROP_BIAS,
 	                                  "bias");
 
-	g_object_class_override_property (object_class,
-	                                  PROP_ORIENTATION,
+	g_object_class_override_property (object_class, PROP_ORIENTATION,
 	                                  "orientation");
 
 	g_type_class_add_private (object_class, sizeof (GeditFloatingSliderPrivate));
+
+	klass->priv = G_TYPE_CLASS_GET_PRIVATE (klass, GEDIT_TYPE_FLOATING_SLIDER,
+	                                        GeditFloatingSliderClassPrivate);
+
+	klass->priv->css = gtk_css_provider_new ();
+	gtk_css_provider_load_from_data (klass->priv->css, style, -1, NULL);
 }
 
 static void
 gedit_floating_slider_init (GeditFloatingSlider *slider)
 {
+	GtkStyleContext *context;
+
 	slider->priv = G_TYPE_INSTANCE_GET_PRIVATE (slider,
 	                                            GEDIT_TYPE_FLOATING_SLIDER,
 	                                            GeditFloatingSliderPrivate);
 
 	slider->priv->orientation = GTK_ORIENTATION_VERTICAL;
+
+	context = gtk_widget_get_style_context (GTK_WIDGET (slider));
+	gtk_style_context_add_provider (context,
+	                                GTK_STYLE_PROVIDER (GEDIT_FLOATING_SLIDER_GET_CLASS (slider)->priv->css),
+	                                GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
 }
 
 GtkWidget *
diff --git a/gedit/gedit-floating-slider.h b/gedit/gedit-floating-slider.h
index 7576439..3da4e65 100644
--- a/gedit/gedit-floating-slider.h
+++ b/gedit/gedit-floating-slider.h
@@ -42,6 +42,7 @@ G_BEGIN_DECLS
 typedef struct _GeditFloatingSlider		GeditFloatingSlider;
 typedef struct _GeditFloatingSliderClass	GeditFloatingSliderClass;
 typedef struct _GeditFloatingSliderPrivate	GeditFloatingSliderPrivate;
+typedef struct _GeditFloatingSliderClassPrivate	GeditFloatingSliderClassPrivate;
 
 struct _GeditFloatingSlider
 {
@@ -53,6 +54,8 @@ struct _GeditFloatingSlider
 struct _GeditFloatingSliderClass
 {
 	GtkBinClass parent_class;
+
+	GeditFloatingSliderClassPrivate *priv;
 };
 
 GType		 gedit_floating_slider_get_type	(void) G_GNUC_CONST;
diff --git a/gedit/gedit-view-frame.c b/gedit/gedit-view-frame.c
index 09b7191..9bdd719 100644
--- a/gedit/gedit-view-frame.c
+++ b/gedit/gedit-view-frame.c
@@ -30,7 +30,6 @@
 #include "gedit-utils.h"
 #include "gedit-animated-overlay.h"
 #include "gedit-floating-slider.h"
-#include "gedit-rounded-frame.h"
 
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
@@ -1065,11 +1064,10 @@ static GtkWidget *
 create_search_widget (GeditViewFrame *frame)
 {
 	GtkWidget          *search_widget;
-	GtkWidget          *hbox;
 	GtkWidget          *button;
 	GtkEntryCompletion *completion;
 
-	search_widget = gedit_rounded_frame_new ();
+	search_widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 	gtk_widget_show (search_widget);
 
 	g_signal_connect (search_widget, "key-press-event",
@@ -1079,12 +1077,6 @@ create_search_widget (GeditViewFrame *frame)
 	                  G_CALLBACK (search_widget_scroll_event),
 	                  frame);
 
-	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
-	gtk_widget_show (hbox);
-
-	gtk_container_add (GTK_CONTAINER (search_widget), hbox);
-	gtk_container_set_border_width (GTK_CONTAINER (hbox), 3);
-
 	/* add entry */
 	frame->priv->search_entry = gtk_entry_new ();
 	gtk_widget_show (frame->priv->search_entry);
@@ -1112,7 +1104,7 @@ create_search_widget (GeditViewFrame *frame)
 		                  G_CALLBACK (search_entry_focus_out_event),
 		                  frame);
 
-	gtk_container_add (GTK_CONTAINER (hbox),
+	gtk_container_add (GTK_CONTAINER (search_widget),
 	                   frame->priv->search_entry);
 
 	if (search_completion_model == NULL)
@@ -1151,7 +1143,7 @@ create_search_widget (GeditViewFrame *frame)
 	button = create_button_from_stock (GTK_STOCK_GO_UP);
 	gtk_widget_show (button);
 
-	gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (search_widget), button, FALSE, FALSE, 0);
 
 	g_signal_connect (button,
 	                  "clicked",
@@ -1161,7 +1153,7 @@ create_search_widget (GeditViewFrame *frame)
 	button = create_button_from_stock (GTK_STOCK_GO_DOWN);
 	gtk_widget_show (button);
 
-	gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (search_widget), button, FALSE, FALSE, 0);
 
 	g_signal_connect (button,
 	                  "clicked",
@@ -1286,7 +1278,7 @@ start_interactive_search_real (GeditViewFrame *frame)
 	if (gtk_bin_get_child (GTK_BIN (frame->priv->slider)) == NULL)
 	{
 		gtk_container_add (GTK_CONTAINER (frame->priv->slider),
-			           create_search_widget (frame));
+		                   create_search_widget (frame));
 	}
 
 	if (gtk_widget_get_visible (frame->priv->slider))
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 27c5db8..58d452e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -19,11 +19,7 @@ TEST_PROGS			+= document-saver
 document_saver_SOURCES		= document-saver.c
 document_saver_LDADD		= $(progs_ldadd)
 
-TEST_GTK_PROGS			= test-rounded-frame
-test_rounded_frame_SOURCES	= test-rounded-frame.c
-test_rounded_frame_LDADD	= $(progs_ldadd)
-
-TEST_GTK_PROGS			+= test-overlay
+TEST_GTK_PROGS			= test-overlay
 test_overlay_SOURCES		= test-overlay.c
 test_overlay_LDADD		= $(progs_ldadd)
 
diff --git a/tests/test-overlay.c b/tests/test-overlay.c
index a094872..c3e73e1 100644
--- a/tests/test-overlay.c
+++ b/tests/test-overlay.c
@@ -1,7 +1,6 @@
 #include <gtk/gtk.h>
 #include <glib.h>
 #include "gedit-animated-overlay.h"
-#include "gedit-rounded-frame.h"
 #include "gedit-floating-slider.h"
 
 static GtkWidget *overlay;
@@ -20,7 +19,6 @@ main ()
 {
 	GtkWidget *window;
 	GtkWidget *textview;
-	GtkWidget *frame;
 	GtkWidget *entry;
 	GtkWidget *vbox;
 	GtkWidget *button;
@@ -39,15 +37,10 @@ main ()
 
 	gtk_box_pack_start (GTK_BOX (vbox), overlay, TRUE, TRUE, 0);
 
-	frame = gedit_rounded_frame_new ();
-	gtk_widget_show (frame);
-
 	entry = gtk_entry_new ();
 
-	gtk_container_add (GTK_CONTAINER (frame), entry);
-
 	slider = gedit_floating_slider_new ();
-	gtk_container_add (GTK_CONTAINER (slider), frame);
+	gtk_container_add (GTK_CONTAINER (slider), entry);
 	gtk_widget_set_halign (slider, GTK_ALIGN_START);
 	gtk_widget_set_valign (slider, GTK_ALIGN_START);
 



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