From f184a1a48f0baf73bd74316d3d71566c626a6b5a Mon Sep 17 00:00:00 2001 From: Zhang Xianwei Date: Sun, 7 Jan 2018 16:07:12 +0800 Subject: libslab: fix search icon misaligned Make use GtkSearchEntry instead of builtin NldSearchEntry fixes #299 Signed-off-by: Zhang Xianwei (squashed afcb324eb181a9c6cb0b3c8e8589ed99391a63a0 + 172e05f957cfcf4b94c469f9b0933ce414faaf8a for 1.18 branch) --- libslab/Makefile.am | 21 +----- libslab/search-bar.c | 3 +- libslab/search-entry-watermark.svg | 58 --------------- libslab/search-entry.c | 148 ------------------------------------- libslab/search-entry.h | 54 -------------- libslab/slab.h | 1 - 6 files changed, 4 insertions(+), 281 deletions(-) delete mode 100644 libslab/search-entry-watermark.svg delete mode 100644 libslab/search-entry.c delete mode 100644 libslab/search-entry.h diff --git a/libslab/Makefile.am b/libslab/Makefile.am index 96bf3d9d..4bbb8316 100644 --- a/libslab/Makefile.am +++ b/libslab/Makefile.am @@ -20,7 +20,6 @@ HEADER_FILES= \ nameplate-tile.h \ search-bar.h \ search-context-picker.h \ - search-entry.h \ shell-window.h \ slab-mate-util.h \ slab-section.h \ @@ -44,8 +43,6 @@ libmate_slab_la_SOURCES = \ nameplate-tile.c \ search-bar.c \ search-context-picker.c \ - search-entry-watermark.h \ - search-entry.c \ shell-window.c \ slab-mate-util.c \ slab-section.c \ @@ -59,12 +56,6 @@ libmate_slab_includedir = $(includedir)/libmate-slab libmate_slab_include_HEADERS = $(HEADER_FILES) libmate_slab_la_LIBADD = $(LIBSLAB_LIBS) -search-entry-watermark.h: search-entry-watermark.svg - echo '#define SEARCH_ENTRY_WATERMARK_SVG "\' > $@; \ - sed -e 's/"/\\"/g' -e 's/$$/\\/' -e 's/#000000/#%s/g' $< >> $@; \ - echo '"' >> $@ - - MARSHAL_GENERATED = nld-marshal.c nld-marshal.h nld-marshal.h: nld-marshal.list @@ -78,16 +69,10 @@ nld-marshal.c: nld-marshal.h || ( rm -f nld-marshal.tmp && exit 1 ) -BUILT_SOURCES = \ - search-entry-watermark.h \ - $(MARSHAL_GENERATED) +BUILT_SOURCES = $(MARSHAL_GENERATED) -CLEANFILES = \ - search-entry-watermark.h \ - $(MARSHAL_GENERATED) +CLEANFILES = $(MARSHAL_GENERATED) -EXTRA_DIST= \ - search-entry-watermark.svg \ - nld-marshal.list +EXTRA_DIST = nld-marshal.list -include $(top_srcdir)/git.mk diff --git a/libslab/search-bar.c b/libslab/search-bar.c index f355fb01..d97847c1 100644 --- a/libslab/search-bar.c +++ b/libslab/search-bar.c @@ -21,7 +21,6 @@ #include "search-bar.h" #include "config.h" -#include "search-entry.h" #include "search-context-picker.h" #include "nld-marshal.h" @@ -96,7 +95,7 @@ nld_search_bar_init (NldSearchBar * search_bar) alignment = gtk_alignment_new (0.0, 0.5, 1.0, 0.0); gtk_box_pack_start (GTK_BOX (priv->hbox), alignment, TRUE, TRUE, 0); - entry = nld_search_entry_new (); + entry = gtk_search_entry_new (); priv->entry = GTK_ENTRY (entry); gtk_widget_show (entry); gtk_container_add (GTK_CONTAINER (alignment), entry); diff --git a/libslab/search-entry-watermark.svg b/libslab/search-entry-watermark.svg deleted file mode 100644 index f72efff1..00000000 --- a/libslab/search-entry-watermark.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - image/svg+xml - - - - - - - - diff --git a/libslab/search-entry.c b/libslab/search-entry.c deleted file mode 100644 index 26a54665..00000000 --- a/libslab/search-entry.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * This file is part of libslab. - * - * Copyright (c) 2006 Novell, Inc. - * - * Libslab is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Libslab is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libslab; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "search-entry.h" -#include "search-entry-watermark.h" - -#include -#include - -typedef struct -{ - GdkPixbuf *watermark; - int width, height; -} NldSearchEntryPrivate; - -#define NLD_SEARCH_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NLD_TYPE_SEARCH_ENTRY, NldSearchEntryPrivate)) - -static void nld_search_entry_class_init (NldSearchEntryClass *); -static void nld_search_entry_init (NldSearchEntry *); -static void nld_search_entry_finalize (GObject *); - -static void nld_search_entry_realize (GtkWidget * widget); -static gboolean nld_search_entry_draw (GtkWidget * widget, cairo_t * cr); - -G_DEFINE_TYPE (NldSearchEntry, nld_search_entry, GTK_TYPE_ENTRY) - -static void nld_search_entry_class_init (NldSearchEntryClass * nld_search_entry_class) -{ - GObjectClass *g_obj_class = G_OBJECT_CLASS (nld_search_entry_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (nld_search_entry_class); - - g_type_class_add_private (nld_search_entry_class, sizeof (NldSearchEntryPrivate)); - - widget_class->realize = nld_search_entry_realize; - widget_class->draw = nld_search_entry_draw; - - g_obj_class->finalize = nld_search_entry_finalize; -} - -static void -nld_search_entry_init (NldSearchEntry * entry) -{ -} - -static void -nld_search_entry_finalize (GObject * object) -{ - NldSearchEntryPrivate *priv = NLD_SEARCH_ENTRY_GET_PRIVATE (object); - - if (priv->watermark) - g_object_unref (priv->watermark); - - G_OBJECT_CLASS (nld_search_entry_parent_class)->finalize (object); -} - -static void -rsvg_size_callback (int *width, int *height, gpointer user_data) -{ - NldSearchEntryPrivate *priv = user_data; - - *width = priv->width = priv->height * (double) *width / (double) *height; - *height = priv->height; -} - -static void -nld_search_entry_realize (GtkWidget * widget) -{ - NldSearchEntryPrivate *priv = NLD_SEARCH_ENTRY_GET_PRIVATE (widget); - int height; - GdkColor *gdkcolor; - char *svg, color[7]; - RsvgHandle *rsvg; - GdkRectangle text_area; - - GTK_WIDGET_CLASS (nld_search_entry_parent_class)->realize (widget); - - gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); - height = text_area.height; - - if (height - 2 == priv->height) - return; - priv->height = height - 2; - - gdkcolor = >k_widget_get_style (widget)->fg[gtk_widget_get_state (widget)]; - snprintf (color, 6, "%02x%02x%02x", gdkcolor->red >> 8, gdkcolor->green >> 8, - gdkcolor->blue >> 8); - svg = g_strdup_printf (SEARCH_ENTRY_WATERMARK_SVG, color, color); - - rsvg = rsvg_handle_new (); - rsvg_handle_set_size_callback (rsvg, rsvg_size_callback, priv, NULL); - rsvg_handle_write (rsvg, (const guchar *) svg, strlen (svg), NULL); - rsvg_handle_close (rsvg, NULL); - g_free (svg); - - if (priv->watermark) - g_object_unref (priv->watermark); - priv->watermark = rsvg_handle_get_pixbuf (rsvg); - rsvg_handle_free (rsvg); -} - -static gboolean -nld_search_entry_draw (GtkWidget * widget, cairo_t * cr) -{ - NldSearchEntryPrivate *priv = NLD_SEARCH_ENTRY_GET_PRIVATE (widget); - GdkRectangle text_area; - - gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); - - GTK_WIDGET_CLASS (nld_search_entry_parent_class)->draw (widget, cr); - - int width, x; - - if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) - { - width = text_area.width; - x = width - priv->width - 1; - } - else - x = 1; - - gdk_cairo_set_source_pixbuf (cr, priv->watermark, x, 1); - cairo_paint (cr); - - return FALSE; -} - -GtkWidget * -nld_search_entry_new (void) -{ - return g_object_new (NLD_TYPE_SEARCH_ENTRY, NULL); -} diff --git a/libslab/search-entry.h b/libslab/search-entry.h deleted file mode 100644 index 0cb07db2..00000000 --- a/libslab/search-entry.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This file is part of libslab. - * - * Copyright (c) 2006 Novell, Inc. - * - * Libslab is free software; you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * Libslab is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for - * more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with libslab; if not, write to the Free Software Foundation, Inc., 51 - * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef __NLD_SEARCH_ENTRY_H__ -#define __NLD_SEARCH_ENTRY_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define NLD_TYPE_SEARCH_ENTRY (nld_search_entry_get_type ()) -#define NLD_SEARCH_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NLD_TYPE_SEARCH_ENTRY, NldSearchEntry)) -#define NLD_SEARCH_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NLD_TYPE_SEARCH_ENTRY, NldSearchEntryClass)) -#define NLD_IS_SEARCH_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NLD_TYPE_SEARCH_ENTRY)) -#define NLD_IS_SEARCH_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NLD_TYPE_SEARCH_ENTRY)) -#define NLD_SEARCH_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NLD_TYPE_SEARCH_ENTRY, NldSearchEntryClass)) - -typedef struct -{ - GtkEntry parent; -} NldSearchEntry; - -typedef struct -{ - GtkEntryClass parent_class; -} NldSearchEntryClass; - -GType nld_search_entry_get_type (void); - -GtkWidget *nld_search_entry_new (void); - -#ifdef __cplusplus -} -#endif -#endif /* __NLD_SEARCH_ENTRY_H__ */ diff --git a/libslab/slab.h b/libslab/slab.h index b4ecb87c..e35d2a40 100644 --- a/libslab/slab.h +++ b/libslab/slab.h @@ -34,7 +34,6 @@ #include "nameplate-tile.h" #include "search-bar.h" #include "search-context-picker.h" -#include "search-entry.h" #include "shell-window.h" #include "slab-mate-util.h" #include "slab-section.h" -- cgit v1.2.1