]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfontchooserwidget.c
Place the search icon in the primary slot of the entry
[~andy/gtk] / gtk / gtkfontchooserwidget.c
index 9a3f37cb1216152db421cede1365e556b437544c..7454a35186a98fa2db42f83a5161f329a69c5cbe 100644 (file)
@@ -12,9 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "config.h"
 #include <atk/atk.h>
 
 #include "gtkfontchooserwidget.h"
-#include "gtkfontchooser.h"
-#include "gtkfontchooserutils.h"
+
+#include "gtkadjustment.h"
+#include "gtkbuildable.h"
+#include "gtkbox.h"
 #include "gtkcellrenderertext.h"
 #include "gtkentry.h"
-#include "gtkframe.h"
-#include "gtkbbox.h"
-#include "gtkbox.h"
+#include "gtksearchentry.h"
+#include "gtkgrid.h"
+#include "gtkfontchooser.h"
+#include "gtkfontchooserutils.h"
+#include "gtkintl.h"
 #include "gtklabel.h"
 #include "gtkliststore.h"
-#include "gtkstock.h"
-#include "gtktextview.h"
-#include "gtktreeselection.h"
-#include "gtktreeview.h"
-#include "gtkscrolledwindow.h"
-#include "gtkintl.h"
-#include "gtkaccessible.h"
-#include "gtkbuildable.h"
+#include "gtknotebook.h"
 #include "gtkprivate.h"
 #include "gtkscale.h"
+#include "gtkscrolledwindow.h"
 #include "gtkspinbutton.h"
-#include "gtknotebook.h"
+#include "gtktextview.h"
+#include "gtktreeselection.h"
+#include "gtktreeview.h"
 #include "gtkwidget.h"
-#include "gtkgrid.h"
 
 /**
- * SECTION:gtkfontchooser
+ * SECTION:gtkfontchooserwidget
  * @Short_description: A widget for selecting fonts
  * @Title: GtkFontChooserWidget
  * @See_also: #GtkFontChooserDialog
@@ -246,55 +243,13 @@ gtk_font_chooser_widget_refilter_font_list (GtkFontChooserWidget *fontchooser)
 }
 
 static void
-text_changed_cb (GtkEntry       *entry,
-                 GParamSpec     *pspec,
+text_changed_cb (GtkEntry             *entry,
+                 GParamSpec           *pspec,
                  GtkFontChooserWidget *fc)
 {
-  GtkFontChooserWidgetPrivate *priv = fc->priv;
-  const gchar *text;
-
-  text = gtk_entry_get_text (entry);
-
-  if (text == NULL || text[0] == '\0')
-    {
-      GIcon *icon;
-
-      icon = g_themed_icon_new_with_default_fallbacks ("edit-find-symbolic");
-      g_object_set (G_OBJECT (priv->search_entry),
-                    "secondary-icon-gicon", icon,
-                    "secondary-icon-activatable", FALSE,
-                    "secondary-icon-sensitive", FALSE,
-                    NULL);
-      g_object_unref (icon);
-    }
-  else
-    {
-      if (!gtk_entry_get_icon_activatable (GTK_ENTRY (priv->search_entry), GTK_ENTRY_ICON_SECONDARY))
-        {
-          GIcon *icon;
-
-          icon = g_themed_icon_new_with_default_fallbacks ("edit-clear-symbolic");
-          g_object_set (G_OBJECT (priv->search_entry),
-                        "secondary-icon-gicon", icon,
-                        "secondary-icon-activatable", TRUE,
-                        "secondary-icon-sensitive", TRUE,
-                        NULL);
-          g_object_unref (icon);
-        }
-    }
-
   gtk_font_chooser_widget_refilter_font_list (fc);
 }
 
-static void
-icon_press_cb (GtkEntry             *entry,
-               GtkEntryIconPosition  pos,
-               GdkEvent             *event,
-               gpointer              user_data)
-{
-  gtk_entry_set_text (entry, "");
-}
-
 static void
 size_change_cb (GtkAdjustment *adjustment,
                 gpointer       user_data)
@@ -511,7 +466,6 @@ row_deleted_cb  (GtkTreeModel *model,
 static void
 gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
 {
-  GIcon *icon;
   GtkFontChooserWidgetPrivate *priv;
   GtkWidget *scrolled_win;
   GtkWidget *grid;
@@ -530,8 +484,9 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
   gtk_widget_push_composite_child ();
 
   /* Creating fundamental widgets for the private struct */
-  priv->search_entry = gtk_entry_new ();
+  priv->search_entry = gtk_search_entry_new ();
   priv->family_face_list = gtk_tree_view_new ();
+  gtk_tree_view_set_enable_search (GTK_TREE_VIEW (priv->family_face_list), FALSE);
   priv->preview = gtk_entry_new ();
   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
                                                 0.0,
@@ -599,22 +554,11 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
   gtk_entry_set_text (GTK_ENTRY (priv->preview),
                       pango_language_get_sample_string (NULL));
 
-  /* Set search icon and place holder text */
-  icon = g_themed_icon_new_with_default_fallbacks ("edit-find-symbolic");
-  g_object_set (G_OBJECT (priv->search_entry),
-                "secondary-icon-gicon", icon,
-                "secondary-icon-activatable", FALSE,
-                "secondary-icon-sensitive", FALSE,
-                NULL);
-  g_object_unref (icon);
-
   gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
 
-  /** Callback connections **/
+  /* Callback connections */
   g_signal_connect (priv->search_entry, "notify::text",
                     G_CALLBACK (text_changed_cb), fontchooser);
-  g_signal_connect (priv->search_entry,
-                    "icon-press", G_CALLBACK (icon_press_cb), NULL);
 
   g_signal_connect (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
                     "value-changed", G_CALLBACK (size_change_cb), fontchooser);
@@ -806,7 +750,7 @@ gtk_font_chooser_widget_get_preview_text_height (GtkFontChooserWidget *fontchoos
                          "font-size", &font_size,
                          NULL);
 
-  return dpi / 72.0 * PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
+  return (dpi < 0.0 ? 96.0 : dpi) / 72.0 * PANGO_SCALE_X_LARGE * font_size * PANGO_SCALE;
 }
 
 static PangoAttrList *
@@ -1118,7 +1062,13 @@ gtk_font_chooser_widget_ensure_selection (GtkFontChooserWidget *fontchooser)
                                                         &filter_iter,
                                                         &priv->font_iter))
     {
+      GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter_model),
+                                                   &filter_iter);
+
       gtk_tree_selection_select_iter (selection, &filter_iter);
+      gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
+                                    path, NULL, FALSE, 0.0, 0.0);
+      gtk_tree_path_free (path);
     }
   else
     {