From afcb324eb181a9c6cb0b3c8e8589ed99391a63a0 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 --- libslab/Makefile.am | 21 +----- libslab/search-bar.c | 13 ++-- libslab/search-entry-watermark.svg | 58 --------------- libslab/search-entry.c | 148 ------------------------------------- libslab/search-entry.h | 54 -------------- libslab/slab.h | 1 - 6 files changed, 9 insertions(+), 286 deletions(-) delete mode 100644 libslab/search-entry-watermark.svg delete mode 100644 libslab/search-entry.c delete mode 100644 libslab/search-entry.h (limited to 'libslab') diff --git a/libslab/Makefile.am b/libslab/Makefile.am index e4f2ffdc..93a728d0 100644 --- a/libslab/Makefile.am +++ b/libslab/Makefile.am @@ -18,7 +18,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 \ @@ -39,8 +38,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 \ @@ -53,12 +50,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 @@ -72,16 +63,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 fd480f34..7645c0fa 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" @@ -31,7 +30,7 @@ typedef struct { GtkWidget *hbox; NldSearchContextPicker *context_picker; - GtkEntry *entry; + GtkSearchEntry *entry; GtkWidget *button; int search_timeout; @@ -92,10 +91,10 @@ nld_search_bar_init (NldSearchBar * search_bar) priv->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); gtk_box_pack_start (GTK_BOX (search_bar), priv->hbox, TRUE, FALSE, 0); - entry = nld_search_entry_new (); + entry = gtk_search_entry_new (); gtk_widget_set_halign (entry, GTK_ALIGN_START); gtk_widget_set_valign (entry, GTK_ALIGN_CENTER); - priv->entry = GTK_ENTRY (entry); + priv->entry = GTK_SEARCH_ENTRY (entry); gtk_widget_show (entry); gtk_box_pack_start (GTK_BOX (priv->hbox), entry, TRUE, TRUE, 0); @@ -151,7 +150,7 @@ nld_search_bar_clear (NldSearchBar * search_bar) NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar); priv->block_signal = TRUE; - gtk_entry_set_text (priv->entry, ""); + gtk_entry_set_text (GTK_ENTRY (priv->entry), ""); if (priv->context_picker) nld_search_context_picker_set_context (priv->context_picker, 0); priv->block_signal = FALSE; @@ -325,7 +324,7 @@ nld_search_bar_get_text (NldSearchBar * search_bar) { NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar); - return gtk_entry_get_text (priv->entry); + return gtk_entry_get_text (GTK_ENTRY (priv->entry)); } void @@ -333,7 +332,7 @@ nld_search_bar_set_text (NldSearchBar * search_bar, const char *text, gboolean a { NldSearchBarPrivate *priv = NLD_SEARCH_BAR_GET_PRIVATE (search_bar); - gtk_entry_set_text (priv->entry, text); + gtk_entry_set_text (GTK_ENTRY (priv->entry), text); if (activate) emit_search (search_bar); } 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 4e843ca4..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, 7, "%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); - g_object_unref (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 2e4b0575..a50dddf9 100644 --- a/libslab/slab.h +++ b/libslab/slab.h @@ -32,7 +32,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