]> Pileus Git - ~andy/gtk/blob - gtk/gtkfontchooser.c
GtkFontChooser: get_font_name did not return the font size
[~andy/gtk] / gtk / gtkfontchooser.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <stdlib.h>
23 #include <glib/gprintf.h>
24 #include <string.h>
25
26 #include <atk/atk.h>
27
28 #include "gtkfontchooser.h"
29 #include "gtkcellrenderertext.h"
30 #include "gtkentry.h"
31 #include "gtkframe.h"
32 #include "gtkhbbox.h"
33 #include "gtkhbox.h"
34 #include "gtklabel.h"
35 #include "gtkliststore.h"
36 #include "gtkstock.h"
37 #include "gtktextview.h"
38 #include "gtktreeselection.h"
39 #include "gtktreeview.h"
40 #include "gtkbox.h"
41 #include "gtkscrolledwindow.h"
42 #include "gtkintl.h"
43 #include "gtkaccessible.h"
44 #include "gtkbuildable.h"
45 #include "gtkprivate.h"
46 #include "gtkalignment.h"
47 #include "gtkscale.h"
48 #include "gtkbox.h"
49 #include "gtkspinbutton.h"
50 #include "gtkwidget.h"
51 #include "gtkgrid.h"
52
53 /**
54  * SECTION:gtkfontchooser
55  * @Short_description: A widget for selecting fonts
56  * @Title: GtkFontChooser
57  * @See_also: #GtkFontChooserDialog
58  *
59  * The #GtkFontChooser widget lists the available fonts, styles and sizes,
60  * allowing the user to select a font.
61  * It is used in the #GtkFontChooserDialog widget to provide a dialog box for
62  * selecting fonts.
63  *
64  * To set the font which is initially selected, use
65  * gtk_font_chooser_set_font_name().
66  *
67  * To get the selected font use gtk_font_chooser_get_font_name().
68  *
69  * To change the text which is shown in the preview area, use
70  * gtk_font_chooser_set_preview_text().
71  *
72  * Since: 3.2
73  */
74
75
76 struct _GtkFontChooserPrivate
77 {
78   GtkWidget    *search_entry;
79   GtkWidget    *family_face_list;
80   GtkWidget    *list_scrolled_window;
81   GtkWidget    *empty_list;
82   GtkListStore *model;  
83   GtkTreeModel *filter;
84
85   GtkWidget       *preview;
86   GtkWidget       *preview_scrolled_window;
87   gchar           *preview_text;
88   gboolean         show_preview_entry;
89
90   GtkWidget *size_spin;
91   GtkWidget *size_slider;
92
93   gint             size;
94   PangoFontFace   *face;
95   PangoFontFamily *family;
96 };
97
98 #define DEFAULT_FONT_NAME "Sans 10"
99 #define MAX_FONT_SIZE 999
100
101 /* This is the initial fixed height and the top padding of the preview entry */
102 #define PREVIEW_HEIGHT 72
103 #define PREVIEW_TOP_PADDING 6
104
105 /* These are the sizes of the font, style & size lists. */
106 #define FONT_LIST_HEIGHT  136
107 #define FONT_LIST_WIDTH   190
108 #define FONT_STYLE_LIST_WIDTH 170
109 #define FONT_SIZE_LIST_WIDTH  60
110
111 #define ROW_FORMAT_STRING "<span weight=\"bold\" size=\"small\">%s</span>\n<span size=\"x-large\" font_desc=\"%s\">%s</span>"
112
113 #define NO_FONT_MATCHED_SEARCH "No fonts matched your serach entry.You can revise your serach and try again."
114
115 /* These are what we use as the standard font sizes, for the size list.
116  */
117 static const gint font_sizes[] = {
118   6, 8, 9, 10, 11, 12, 13, 14, 16, 20, 24, 36, 48, 72
119 };
120
121 enum {
122    PROP_0,
123    PROP_FONT_NAME,
124    PROP_PREVIEW_TEXT,
125    PROP_SHOW_PREVIEW_ENTRY
126 };
127
128
129 enum {
130   FAMILY_COLUMN,
131   FACE_COLUMN,
132   PREVIEW_TEXT_COLUMN,
133   PREVIEW_TITLE_COLUMN
134 };
135
136 static void  gtk_font_chooser_set_property       (GObject         *object,
137                                                   guint            prop_id,
138                                                   const GValue    *value,
139                                                   GParamSpec      *pspec);
140 static void  gtk_font_chooser_get_property       (GObject         *object,
141                                                   guint            prop_id,
142                                                   GValue          *value,
143                                                   GParamSpec      *pspec);
144 static void  gtk_font_chooser_finalize           (GObject         *object);
145
146 static void  gtk_font_chooser_screen_changed     (GtkWidget       *widget,
147                                                   GdkScreen       *previous_screen);
148 static void  gtk_font_chooser_style_updated      (GtkWidget      *widget);
149
150 static void  gtk_font_chooser_ref_family         (GtkFontChooser *fontchooser,
151                                                   PangoFontFamily  *family);
152 static void  gtk_font_chooser_ref_face           (GtkFontChooser *fontchooser,
153                                                   PangoFontFace    *face);
154
155 static void gtk_font_chooser_bootstrap_fontlist (GtkFontChooser *fontchooser);
156
157 G_DEFINE_TYPE (GtkFontChooser, gtk_font_chooser, GTK_TYPE_BOX)
158
159 static void
160 gtk_font_chooser_class_init (GtkFontChooserClass *klass)
161 {
162   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
163   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
164
165   widget_class->screen_changed = gtk_font_chooser_screen_changed;
166   widget_class->style_updated = gtk_font_chooser_style_updated;
167
168   gobject_class->finalize = gtk_font_chooser_finalize;
169   gobject_class->set_property = gtk_font_chooser_set_property;
170   gobject_class->get_property = gtk_font_chooser_get_property;
171
172   g_object_class_install_property (gobject_class,
173                                    PROP_FONT_NAME,
174                                    g_param_spec_string ("font-name",
175                                                         P_("Font name"),
176                                                         P_("The string that represents this font"),
177                                                         DEFAULT_FONT_NAME,
178                                                         GTK_PARAM_READWRITE));
179   g_object_class_install_property (gobject_class,
180                                    PROP_PREVIEW_TEXT,
181                                    g_param_spec_string ("preview-text",
182                                                         P_("Preview text"),
183                                                         P_("The text to display in order to demonstrate the selected font"),
184                                                         pango_language_get_sample_string (NULL),
185                                                         GTK_PARAM_READWRITE));
186
187   g_object_class_install_property (gobject_class,
188                                    PROP_SHOW_PREVIEW_ENTRY,
189                                    g_param_spec_boolean ("show-preview-entry",
190                                                         P_("Show preview text entry"),
191                                                         P_("Whether the preview text entry is shown or not"),
192                                                         TRUE,
193                                                         GTK_PARAM_READWRITE));
194
195   g_type_class_add_private (klass, sizeof (GtkFontChooserPrivate));
196 }
197
198 static void 
199 gtk_font_chooser_set_property (GObject         *object,
200                                guint            prop_id,
201                                const GValue    *value,
202                                GParamSpec      *pspec)
203 {
204   GtkFontChooser *fontchooser;
205
206   fontchooser = GTK_FONT_CHOOSER (object);
207
208   switch (prop_id)
209     {
210     case PROP_FONT_NAME:
211       gtk_font_chooser_set_font_name (fontchooser, g_value_get_string (value));
212       break;
213     case PROP_PREVIEW_TEXT:
214       gtk_font_chooser_set_preview_text (fontchooser, g_value_get_string (value));
215       break;
216     case PROP_SHOW_PREVIEW_ENTRY:
217       gtk_font_chooser_set_show_preview_entry (fontchooser, g_value_get_boolean (value));
218       break;
219     default:
220       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221       break;
222     }
223 }
224
225 static void
226 gtk_font_chooser_get_property (GObject         *object,
227                                guint            prop_id,
228                                GValue          *value,
229                                GParamSpec      *pspec)
230 {
231   GtkFontChooser *fontchooser;
232
233   fontchooser = GTK_FONT_CHOOSER (object);
234
235   switch (prop_id)
236     {
237     case PROP_FONT_NAME:
238       g_value_take_string (value, gtk_font_chooser_get_font_name (fontchooser));
239       break;
240     case PROP_PREVIEW_TEXT:
241       g_value_set_string (value, gtk_font_chooser_get_preview_text (fontchooser));
242       break;
243     case PROP_SHOW_PREVIEW_ENTRY:
244       g_value_set_boolean (value, gtk_font_chooser_get_show_preview_entry (fontchooser));
245       break;
246     default:
247       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
248       break;
249     }
250 }
251 static void
252 deleted_text_cb (GtkEntryBuffer *buffer,
253                  guint           position,
254                  guint           n_chars,
255                  gpointer        user_data)
256 {
257   GtkFontChooser        *fc    = (GtkFontChooser*)user_data;
258   GtkFontChooserPrivate *priv  = fc->priv;
259   GtkWidget             *entry = priv->search_entry;
260   
261   if (gtk_entry_buffer_get_length (buffer) == 0)
262     {
263       GIcon *icon = g_themed_icon_new_with_default_fallbacks ("edit-find-symbolic");
264       gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry),
265                                      GTK_ENTRY_ICON_SECONDARY,
266                                      icon);
267       g_object_unref (icon);
268     }
269
270   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
271 }
272
273 static void
274 inserted_text_cb (GtkEntryBuffer *buffer,
275                   guint           position,
276                   gchar          *chars,
277                   guint           n_chars,
278                   gpointer        user_data) 
279 {
280   GtkFontChooser        *fc    = (GtkFontChooser*)user_data;
281   GtkFontChooserPrivate *priv  = fc->priv;
282   GtkWidget             *entry = priv->search_entry;
283
284   if (g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY),
285                  "edit-clear-symbolic") != 0 ||
286       g_strcmp0 (gtk_entry_get_icon_stock (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY),
287                  GTK_STOCK_CLEAR)       != 0)
288     {
289       GIcon *icon = g_themed_icon_new_with_default_fallbacks ("edit-clear-symbolic");
290       gtk_entry_set_icon_from_gicon (GTK_ENTRY (entry),
291                                      GTK_ENTRY_ICON_SECONDARY,
292                                      icon);
293       g_object_unref (icon);
294     }
295
296   gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
297 }
298
299 static void
300 icon_press_cb (GtkEntry             *entry,
301                GtkEntryIconPosition  pos,
302                GdkEvent             *event,
303                gpointer              user_data)
304 {
305   gtk_entry_buffer_delete_text (gtk_entry_get_buffer (entry), 0, -1);
306 }
307
308 static void
309 slider_change_cb (GtkAdjustment *adjustment,
310                   gpointer       user_data)
311 {
312   GtkFontChooser        *fc    = (GtkFontChooser*)user_data;
313   GtkFontChooserPrivate *priv  = fc->priv;
314   GtkAdjustment         *spin_adj     = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON (priv->size_spin));
315   gdouble                slider_value = gtk_adjustment_get_value (adjustment);
316   gdouble                spin_value   = gtk_adjustment_get_value (spin_adj);
317
318   if (slider_value != spin_value)
319     gtk_adjustment_set_value (spin_adj,
320                               gtk_adjustment_get_value (adjustment));
321 }
322
323 static void
324 spin_change_cb (GtkAdjustment *adjustment,
325                 gpointer       user_data)
326 {
327   PangoFontDescription    *desc;
328   GtkFontChooser          *fontchooser = (GtkFontChooser*)user_data;
329   GtkFontChooserPrivate   *priv        = fontchooser->priv;
330   GtkAdjustment           *slider_adj  = gtk_range_get_adjustment (GTK_RANGE (priv->size_slider));
331
332   gdouble size = gtk_adjustment_get_value (adjustment);
333   priv->size = ((gint)size) * PANGO_SCALE;
334
335   desc = pango_context_get_font_description (gtk_widget_get_pango_context (priv->preview));
336   pango_font_description_set_size (desc, priv->size);
337   gtk_widget_override_font (priv->preview, desc);
338
339   g_object_notify (G_OBJECT (fontchooser), "font-name");
340
341   /* If the new value is lower than the lower bound of the slider, we set
342    * the slider adjustment to the lower bound value if it is not already set
343    */
344   if (size < gtk_adjustment_get_lower (slider_adj) &&
345       gtk_adjustment_get_value (slider_adj) != gtk_adjustment_get_lower (slider_adj))
346     gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_lower (slider_adj));
347
348   /* If the new value is upper than the upper bound of the slider, we set
349    * the slider adjustment to the upper bound value if it is not already set
350    */
351   else if (size > gtk_adjustment_get_upper (slider_adj) &&
352            gtk_adjustment_get_value (slider_adj) != gtk_adjustment_get_upper (slider_adj))
353     gtk_adjustment_set_value (slider_adj, gtk_adjustment_get_upper (slider_adj));
354
355   /* If the new value is not already set on the slider we set it */
356   else if (size != gtk_adjustment_get_value (slider_adj))
357     gtk_adjustment_set_value (slider_adj, size);
358
359   gtk_widget_queue_draw (priv->preview);
360 }
361
362 static void
363 set_range_marks (GtkFontChooserPrivate *priv,
364                  GtkWidget             *size_slider,
365                  gint                  *sizes,
366                  gint                   length)
367 {
368   GtkAdjustment *adj;
369   gint i;
370   gdouble value;
371
372   if (length < 2)
373     {
374       sizes = (gint*)font_sizes;
375       length = G_N_ELEMENTS (font_sizes);
376     }
377   
378   gtk_scale_clear_marks (GTK_SCALE (size_slider));
379   
380   adj = gtk_range_get_adjustment(GTK_RANGE (size_slider));
381   
382   gtk_adjustment_set_lower (adj, (gdouble) sizes[0]);
383   gtk_adjustment_set_upper (adj, (gdouble) sizes[length-1]);
384
385   value = gtk_adjustment_get_value (adj);
386   if (value > (gdouble) sizes[length-1])
387     gtk_adjustment_set_value (adj, (gdouble) sizes[length-1]);
388   else if (value < (gdouble) sizes[0])
389     gtk_adjustment_set_value (adj, (gdouble) sizes[0]);
390   
391   for (i = 0; i < length; i++)
392     gtk_scale_add_mark (GTK_SCALE (size_slider),
393                         (gdouble) sizes[i],
394                         GTK_POS_BOTTOM, NULL);
395 }
396
397 static void
398 cursor_changed_cb (GtkTreeView *treeview,
399                    gpointer     user_data)
400 {
401   PangoFontFamily      *family;
402   PangoFontFace        *face;
403   PangoFontDescription *desc;
404   
405   gint *sizes;
406   gint  i, n_sizes;
407
408   GtkTreeIter  iter;
409   GtkTreePath *path = gtk_tree_path_new ();
410   
411   GtkFontChooser *fontchooser = (GtkFontChooser*)user_data;
412   
413   gtk_tree_view_get_cursor (treeview, &path, NULL);
414   
415   if (!path)
416     return;
417
418   if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (fontchooser->priv->filter), &iter, path))
419     {
420       gtk_tree_path_free (path);
421       return;
422     } 
423   
424   
425   gtk_tree_model_get (GTK_TREE_MODEL (fontchooser->priv->filter), &iter,
426                       FACE_COLUMN, &face,
427                       FAMILY_COLUMN, &family,
428                       -1);
429
430   gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
431
432   gtk_tree_path_free (path);
433   path = NULL;
434   
435   if (!face || !family)
436     {
437       g_object_unref (face);
438       g_object_unref (family);
439       return;
440     }
441
442   desc = pango_font_face_describe (face);
443   pango_font_description_set_size (desc, fontchooser->priv->size);
444   gtk_widget_override_font (fontchooser->priv->preview, desc);
445
446   pango_font_face_list_sizes (face, &sizes, &n_sizes);
447   /* It seems not many fonts actually have a sane set of sizes */
448   for (i = 0; i < n_sizes; i++)
449     sizes[i] = sizes[i] / PANGO_SCALE;
450   
451   set_range_marks (fontchooser->priv, fontchooser->priv->size_slider, sizes, n_sizes);
452
453   gtk_font_chooser_ref_family (fontchooser, family);
454   gtk_font_chooser_ref_face   (fontchooser, face);
455
456   /* Free resources */
457   g_object_unref ((gpointer)family);
458   g_object_unref ((gpointer)face);
459   pango_font_description_free(desc);
460
461   g_object_notify (G_OBJECT (fontchooser), "font-name");
462 }
463
464 static gboolean
465 zoom_preview_cb (GtkWidget      *scrolled_window,
466                  GdkEventScroll *event,
467                  gpointer        user_data)
468 {
469   GtkFontChooser        *fc    = (GtkFontChooser*)user_data;
470   GtkFontChooserPrivate *priv  = fc->priv;
471
472   GtkAdjustment *adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin));
473
474   if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_RIGHT)
475     gtk_adjustment_set_value (adj,
476                               gtk_adjustment_get_value (adj) +
477                               gtk_adjustment_get_step_increment (adj));
478   else if (event->direction == GDK_SCROLL_DOWN || event->direction == GDK_SCROLL_LEFT)
479     gtk_adjustment_set_value (adj,
480                               gtk_adjustment_get_value (adj) -
481                               gtk_adjustment_get_step_increment (adj));
482   return TRUE;
483 }
484
485 #if 0
486 static void
487 row_inserted_cb (GtkTreeModel *model,
488                  GtkTreePath  *path,
489                  GtkTreeIter  *iter,
490                  gpointer      user_data)
491 {
492   GtkFontChooser        *fontchooser = (GtkFontChooser*)user_data;
493   GtkFontChooserPrivate *priv        = fontchooser->priv;
494   
495   if (gtk_bin_get_child (GTK_BIN (priv->list_scrolled_window)) ==
496       priv->empty_list)
497     {
498       g_object_ref (priv->empty_list);
499       gtk_container_remove (GTK_CONTAINER (priv->list_scrolled_window),
500                             priv->empty_list);
501       gtk_container_add (GTK_CONTAINER (priv->list_scrolled_window),
502                          priv->family_face_list);
503     }
504 }
505
506 static void
507 row_deleted_cb  (GtkTreeModel *model,
508                  GtkTreePath  *path,
509                  gpointer      user_data)
510 {
511   GtkFontChooser        *fontchooser = (GtkFontChooser*)user_data;
512   GtkFontChooserPrivate *priv        = fontchooser->priv;
513
514   if (gtk_tree_model_iter_n_children (model, NULL) == 0)
515     {
516       if (gtk_bin_get_child (GTK_BIN (priv->list_scrolled_window)) ==
517           priv->family_face_list)
518         {
519           g_object_ref (priv->family_face_list);
520           gtk_container_remove (GTK_CONTAINER (priv->list_scrolled_window),
521                                 priv->family_face_list);
522           gtk_container_add (GTK_CONTAINER (priv->list_scrolled_window),
523                              priv->empty_list);
524         }
525       
526     }
527 }
528 #endif
529
530 static void
531 gtk_font_chooser_init (GtkFontChooser *fontchooser)
532 {
533   GIcon                   *icon;
534   GtkFontChooserPrivate   *priv;
535   PangoFontDescription    *font_desc;
536   GtkWidget               *scrolled_win;
537   GtkWidget               *grid;
538   GtkWidget               *sub_grid;
539
540   fontchooser->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooser,
541                                                    GTK_TYPE_FONT_CHOOSER,
542                                                    GtkFontChooserPrivate);
543
544   priv = fontchooser->priv;
545
546   /* Default preview string  */
547   priv->preview_text = g_strdup (pango_language_get_sample_string (NULL));
548   priv->show_preview_entry = TRUE;
549
550   /* Getting the default size */
551   font_desc  = pango_context_get_font_description (gtk_widget_get_pango_context (GTK_WIDGET (fontchooser)));
552   priv->size = pango_font_description_get_size (font_desc);
553   priv->face = NULL;
554   priv->family = NULL;
555
556   gtk_widget_push_composite_child ();
557
558   /* Creating fundamental widgets for the private struct */
559   priv->search_entry = gtk_entry_new ();
560   priv->family_face_list = gtk_tree_view_new ();
561   priv->preview = gtk_entry_new ();
562   priv->size_slider = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
563                                                 (gdouble) font_sizes[0],
564                                                 (gdouble) font_sizes[G_N_ELEMENTS (font_sizes) - 1],
565                                                 1.0);
566
567   priv->size_spin = gtk_spin_button_new_with_range (0.0, (gdouble)(G_MAXINT / PANGO_SCALE), 1.0);
568
569   /** Bootstrapping widget layout **/
570   gtk_box_set_spacing (GTK_BOX (fontchooser), 6);
571
572   /* Main font family/face view */
573   priv->list_scrolled_window = gtk_scrolled_window_new (NULL, NULL);
574   scrolled_win = priv->list_scrolled_window;
575   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_win),
576                                   GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
577   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win),
578                                        GTK_SHADOW_ETCHED_IN);
579   gtk_container_add (GTK_CONTAINER (scrolled_win),
580                      priv->family_face_list);
581
582   /* Text to display when list is empty */
583   priv->empty_list = gtk_text_view_new ();
584   gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->empty_list)),
585                             _(NO_FONT_MATCHED_SEARCH),
586                             -1);
587
588   /* Basic layout */
589   grid = gtk_grid_new ();
590   sub_grid = gtk_grid_new ();
591   
592   gtk_widget_set_margin_bottom (priv->search_entry, 6);
593   gtk_widget_set_margin_bottom (scrolled_win,       6);
594   gtk_widget_set_margin_bottom (priv->preview,      6);
595   gtk_widget_set_margin_right  (priv->size_slider,  6);
596
597   gtk_grid_attach (GTK_GRID (grid), priv->search_entry, 0, 0, 3, 1);
598   gtk_grid_attach (GTK_GRID (grid), scrolled_win,       0, 1, 3, 1);  
599   gtk_grid_attach (GTK_GRID (grid), priv->preview,      0, 2, 3, 1);
600   gtk_grid_attach (GTK_GRID (grid), sub_grid,           0, 4, 3, 1);
601   
602   gtk_widget_set_hexpand  (GTK_WIDGET (sub_grid),          TRUE);  
603   gtk_grid_attach (GTK_GRID (sub_grid), priv->size_slider,  0, 3, 2, 1);
604   gtk_grid_attach (GTK_GRID (sub_grid), priv->size_spin,    2, 3, 1, 1);
605
606   gtk_widget_set_hexpand  (GTK_WIDGET (scrolled_win),      TRUE);
607   gtk_widget_set_vexpand  (GTK_WIDGET (scrolled_win),      TRUE);
608   gtk_widget_set_hexpand  (GTK_WIDGET (priv->search_entry), TRUE);
609
610   gtk_widget_set_hexpand  (GTK_WIDGET (priv->size_slider), TRUE);
611   gtk_widget_set_hexpand  (GTK_WIDGET (priv->size_spin),   FALSE);
612
613   gtk_grid_set_column_homogeneous (GTK_GRID (sub_grid), FALSE);
614   gtk_box_pack_start (GTK_BOX (fontchooser), grid, TRUE, TRUE, 0);
615
616   /* Setting the adjustment values for the size slider */
617   gtk_adjustment_set_value (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider)),
618                             (gdouble)(priv->size / PANGO_SCALE));
619   gtk_adjustment_set_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin)),
620                             (gdouble)(priv->size / PANGO_SCALE));
621
622   gtk_widget_show_all (GTK_WIDGET (fontchooser));
623   gtk_widget_hide     (GTK_WIDGET (fontchooser));
624
625   /* Treeview column and model bootstrapping */
626   gtk_font_chooser_bootstrap_fontlist (fontchooser);
627
628   /* Set default preview text */
629   gtk_entry_set_text (GTK_ENTRY (priv->preview),
630                       pango_language_get_sample_string (NULL));
631
632   /* Set search icon and place holder text */
633   icon = g_themed_icon_new_with_default_fallbacks ("edit-find-symbolic");
634   gtk_entry_set_icon_from_gicon (GTK_ENTRY (priv->search_entry),
635                                  GTK_ENTRY_ICON_SECONDARY,
636                                  icon);
637   g_object_unref (icon);
638
639   gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), _("Search font name"));
640
641   /** Callback connections **/
642   /* Connect to callback for the live search text entry */
643   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
644                     "deleted-text", G_CALLBACK (deleted_text_cb), fontchooser);
645   g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
646                     "inserted-text", G_CALLBACK (inserted_text_cb), fontchooser);
647   g_signal_connect (G_OBJECT (priv->search_entry),
648                     "icon-press", G_CALLBACK (icon_press_cb), NULL);
649
650   /* Size controls callbacks */
651   g_signal_connect (G_OBJECT (gtk_range_get_adjustment (GTK_RANGE (priv->size_slider))),
652                     "value-changed", G_CALLBACK (slider_change_cb), fontchooser);
653   g_signal_connect (G_OBJECT (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (priv->size_spin))),
654                     "value-changed", G_CALLBACK (spin_change_cb), fontchooser);
655
656   /* Font selection callback */
657   g_signal_connect (G_OBJECT (priv->family_face_list), "cursor-changed",
658                     G_CALLBACK (cursor_changed_cb),    fontchooser);
659
660   /* Zoom on preview scroll*/
661   g_signal_connect (G_OBJECT (priv->preview), "scroll-event",
662                     G_CALLBACK (zoom_preview_cb),  fontchooser);
663
664   g_signal_connect (G_OBJECT (priv->size_slider), "scroll-event",
665                     G_CALLBACK (zoom_preview_cb), fontchooser);
666
667   set_range_marks (priv, priv->size_slider, (gint*)font_sizes, G_N_ELEMENTS (font_sizes));
668   
669   /* Font list empty hides the scrolledwindow */
670   /*
671   g_signal_connect (G_OBJECT (priv->filter), "row-deleted",
672                     G_CALLBACK (row_deleted_cb), fontchooser);
673   g_signal_connect (G_OBJECT (priv->filter), "row-inserted",
674                     G_CALLBACK (row_inserted_cb), fontchooser);
675   */
676
677   /* Set default focus */
678   gtk_widget_pop_composite_child();
679 }
680
681 /**
682  * gtk_font_chooser_new:
683  *
684  * Creates a new #GtkFontChooser.
685  *
686  * Return value: a new #GtkFontChooser
687  *
688  * Since: 3.2
689  */
690 GtkWidget *
691 gtk_font_chooser_new (void)
692 {
693   GtkFontChooser *fontchooser;
694
695   fontchooser = g_object_new (GTK_TYPE_FONT_CHOOSER, NULL);
696
697   return GTK_WIDGET (fontchooser);
698 }
699
700 static int
701 cmp_families (const void *a, 
702               const void *b)
703 {
704   const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
705   const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
706
707   return g_utf8_collate (a_name, b_name);
708 }
709
710 static void 
711 populate_list (GtkFontChooser *fontchooser,
712                GtkTreeView    *treeview,
713                GtkListStore   *model)
714 {
715   GtkStyleContext      *style_context;
716   PangoFontDescription *default_font;
717
718   GtkTreeIter   match_row;
719   GtkTreePath  *path;
720
721   gint n_families, i;  
722   PangoFontFamily **families;
723
724   GString     *tmp = g_string_new (NULL);
725   GString     *family_and_face = g_string_new (NULL);
726
727   pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (treeview)),
728                                &families,
729                                &n_families);
730
731   qsort (families, n_families, sizeof (PangoFontFamily *), cmp_families);
732
733   gtk_list_store_clear (model);
734
735   /* Get row header font color */
736   style_context = gtk_widget_get_style_context (GTK_WIDGET (treeview));
737
738   /* Get theme font */
739   default_font  = (PangoFontDescription*) gtk_style_context_get_font (style_context,
740                                                                       GTK_STATE_NORMAL);
741
742   /* Iterate over families and faces */
743   for (i = 0; i < n_families; i++)
744     {
745       GtkTreeIter     iter;
746       PangoFontFace **faces;
747       
748       int             j, n_faces;
749       const gchar    *fam_name = pango_font_family_get_name (families[i]);
750
751       pango_font_family_list_faces (families[i], &faces, &n_faces);
752       
753       for (j = 0; j < n_faces; j++)
754         {
755           PangoFontDescription *pango_desc = pango_font_face_describe (faces[j]);
756           const gchar *face_name = pango_font_face_get_face_name (faces[j]);
757           gchar       *font_desc = pango_font_description_to_string (pango_desc);
758           
759           /* foreground_color, family_name, face_name, desc, sample string */
760           g_string_printf (family_and_face, "%s %s",
761                                             fam_name,
762                                             face_name);
763           
764           g_string_printf (tmp, ROW_FORMAT_STRING,
765                            family_and_face->str,
766                            font_desc,
767                            fontchooser->priv->preview_text);
768
769           gtk_list_store_append (model, &iter);
770           gtk_list_store_set (model, &iter,
771                               FAMILY_COLUMN, families[i],
772                               FACE_COLUMN, faces[j],
773                               PREVIEW_TITLE_COLUMN, family_and_face->str,
774                               PREVIEW_TEXT_COLUMN, tmp->str,
775                               -1);
776
777           /* Select the first font or the default font/face from the style context */
778           if ((i == 0 && j == 0) ||
779               (!strcmp (fam_name, pango_font_description_get_family (default_font)) && j == 0))
780             match_row = iter;
781
782           pango_font_description_free(pango_desc);
783           g_free (font_desc);
784         }
785
786       g_free (faces);
787     }
788
789   path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), &match_row);
790
791   if (path)
792     {
793       gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
794       gtk_tree_view_scroll_to_cell (treeview, path, NULL, FALSE, 0.5, 0.5);
795       gtk_tree_path_free(path);
796     }
797
798   g_string_free (family_and_face, TRUE);
799   g_string_free (tmp, TRUE);
800   g_free (families);
801 }
802
803 static gboolean
804 visible_func (GtkTreeModel *model,
805               GtkTreeIter  *iter,
806               gpointer      user_data)
807 {
808   gboolean result = TRUE;
809   GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*)user_data;
810
811   const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
812   gchar       *font_name;
813   gchar       *term;
814   gchar      **split_terms;
815   gint         n_terms = 0;
816
817   /* If there's no filter string we show the item */
818   if (strlen (search_text) == 0)
819     return TRUE;
820
821   gtk_tree_model_get (model, iter,
822                       PREVIEW_TITLE_COLUMN, &font_name,
823                       -1);
824
825   if (font_name == NULL)
826        return FALSE;
827
828   split_terms = g_strsplit (search_text, " ", 0);
829   term = split_terms[0];
830
831   while (term && result)
832   {
833     gchar* font_name_casefold = g_utf8_casefold (font_name, -1);
834     gchar* term_casefold = g_utf8_casefold (term, -1);
835
836     if (g_strrstr (font_name_casefold, term_casefold))
837       result = result && TRUE;
838     else
839       result = FALSE;
840
841     n_terms++;
842     term = split_terms[n_terms];
843
844     g_free (term_casefold);
845     g_free (font_name_casefold);
846   }
847
848   g_free (font_name);
849   g_strfreev (split_terms);
850
851   return result;
852 }
853
854 static void
855 gtk_font_chooser_bootstrap_fontlist (GtkFontChooser* fontchooser)
856 {
857   GtkTreeView       *treeview = GTK_TREE_VIEW (fontchooser->priv->family_face_list);
858   GtkCellRenderer   *cell;
859   GtkTreeViewColumn *col;
860
861   fontchooser->priv->model = gtk_list_store_new (4,
862                                                  PANGO_TYPE_FONT_FAMILY,
863                                                  PANGO_TYPE_FONT_FACE,
864                                                  G_TYPE_STRING,
865                                                  G_TYPE_STRING);
866
867   fontchooser->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontchooser->priv->model),
868                                                          NULL);
869   g_object_unref (fontchooser->priv->model);
870
871   gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontchooser->priv->filter),
872                                           visible_func,
873                                           (gpointer)fontchooser->priv,
874                                           NULL);
875
876   gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontchooser->priv->filter));
877   g_object_unref (fontchooser->priv->filter);
878
879   gtk_tree_view_set_rules_hint      (treeview, TRUE);
880   gtk_tree_view_set_headers_visible (treeview, FALSE);
881
882   cell = gtk_cell_renderer_text_new ();
883   col = gtk_tree_view_column_new_with_attributes ("Family",
884                                                   cell,
885                                                   "markup", PREVIEW_TEXT_COLUMN,
886                                                   NULL);
887                                                   
888   g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
889
890   gtk_tree_view_append_column (treeview, col);
891
892   populate_list (fontchooser, treeview, fontchooser->priv->model);
893 }
894
895
896 static void
897 gtk_font_chooser_finalize (GObject *object)
898 {
899   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (object);
900
901   gtk_font_chooser_ref_family (fontchooser, NULL);
902   gtk_font_chooser_ref_face (fontchooser, NULL);
903
904   G_OBJECT_CLASS (gtk_font_chooser_parent_class)->finalize (object);
905 }
906
907
908 static void
909 gtk_font_chooser_screen_changed (GtkWidget *widget,
910                                  GdkScreen *previous_screen)
911 {
912   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
913
914   populate_list (fontchooser,
915                  GTK_TREE_VIEW (fontchooser->priv->family_face_list),
916                  fontchooser->priv->model);
917   return;
918 }
919
920 static void
921 gtk_font_chooser_style_updated (GtkWidget *widget)
922 {
923   GtkFontChooser *fontchooser = GTK_FONT_CHOOSER (widget);
924
925   GTK_WIDGET_CLASS (gtk_font_chooser_parent_class)->style_updated (widget);
926
927   populate_list (fontchooser,
928                  GTK_TREE_VIEW (fontchooser->priv->family_face_list),
929                  fontchooser->priv->model);
930   return;
931 }
932
933 static void
934 gtk_font_chooser_ref_family (GtkFontChooser   *fontchooser,
935                              PangoFontFamily  *family)
936 {
937   GtkFontChooserPrivate *priv = fontchooser->priv;
938
939   if (family)
940     family = g_object_ref (family);
941   if (priv->family)
942     g_object_unref (priv->family);
943   priv->family = family;
944 }
945
946 static void
947 gtk_font_chooser_ref_face (GtkFontChooser   *fontchooser,
948                            PangoFontFace    *face)
949 {
950   GtkFontChooserPrivate *priv = fontchooser->priv;
951
952   if (face)
953     face = g_object_ref (face);
954   if (priv->face)
955     g_object_unref (priv->face);
956   priv->face = face;
957 }
958
959
960 /*
961  * These functions are the main public interface for getting/setting the font.
962  */
963
964 /**
965  * gtk_font_chooser_get_family:
966  * @fontchooser: a #GtkFontChooser
967  *
968  * Gets the #PangoFontFamily representing the selected font family.
969  *
970  * Return value: (transfer none): A #PangoFontFamily representing the
971  *     selected font family. Font families are a collection of font
972  *     faces. The returned object is owned by @fontchooser and must not
973  *     be modified or freed.
974  *
975  * Since: 3.2
976  */
977 PangoFontFamily *
978 gtk_font_chooser_get_family (GtkFontChooser *fontchooser)
979 {
980   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
981
982   return fontchooser->priv->family;
983 }
984
985 /**
986  * gtk_font_chooser_get_face:
987  * @fontchooser: a #GtkFontChooser
988  *
989  * Gets the #PangoFontFace representing the selected font group
990  * details (i.e. family, slant, weight, width, etc).
991  *
992  * Return value: (transfer none): A #PangoFontFace representing the
993  *     selected font group details. The returned object is owned by
994  *     @fontchooser and must not be modified or freed.
995  *
996  * Since: 3.2
997  */
998 PangoFontFace *
999 gtk_font_chooser_get_face (GtkFontChooser *fontchooser)
1000 {
1001   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
1002
1003   return fontchooser->priv->face;
1004 }
1005
1006 /**
1007  * gtk_font_chooser_get_size:
1008  * @fontchooser: a #GtkFontChooser
1009  *
1010  * The selected font size.
1011  *
1012  * Return value: A n integer representing the selected font size,
1013  *     or -1 if no font size is selected.
1014  *
1015  * Since: 3.2
1016  **/
1017 gint
1018 gtk_font_chooser_get_size (GtkFontChooser *fontchooser)
1019 {
1020   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), -1);
1021
1022   return fontchooser->priv->size;
1023 }
1024
1025 /**
1026  * gtk_font_chooser_get_font_name:
1027  * @fontchooser: a #GtkFontChooser
1028  * 
1029  * Gets the currently-selected font name. 
1030  *
1031  * Note that this can be a different string than what you set with 
1032  * gtk_font_chooser_set_font_name(), as the font chooser widget may 
1033  * normalize font names and thus return a string with a different structure. 
1034  * For example, "Helvetica Italic Bold 12" could be normalized to 
1035  * "Helvetica Bold Italic 12". Use pango_font_description_equal()
1036  * if you want to compare two font descriptions.
1037  * 
1038  * Return value: (transfer full) (allow-none): A string with the name of the
1039  *     current font, or %NULL if  no font is selected. You must free this
1040  *     string with g_free().
1041  *
1042  * Since: 3.2
1043  */
1044 gchar *
1045 gtk_font_chooser_get_font_name (GtkFontChooser *fontchooser)
1046 {
1047   gchar                *font_name;
1048   gchar                *font_desc_name;
1049   PangoFontDescription *desc;
1050
1051   if (!fontchooser->priv->face)
1052     return NULL;
1053
1054
1055
1056   desc = pango_font_face_describe (fontchooser->priv->face);
1057   font_desc_name = pango_font_description_to_string (desc);
1058   pango_font_description_free (desc);
1059   
1060   font_name = g_strdup_printf ("%s %d", font_desc_name, fontchooser->priv->size / PANGO_SCALE);
1061   g_free (font_desc_name);
1062   return font_name;
1063 }
1064
1065 /* This sets the current font, then selecting the appropriate list rows. */
1066
1067 /**
1068  * gtk_font_chooser_set_font_name:
1069  * @fontchooser: a #GtkFontChooser
1070  * @fontname: a font name like "Helvetica 12" or "Times Bold 18"
1071  * 
1072  * Sets the currently-selected font. 
1073  *
1074  * Note that the @fontchooser needs to know the screen in which it will appear 
1075  * for this to work; this can be guaranteed by simply making sure that the 
1076  * @fontchooser is inserted in a toplevel window before you call this function.
1077  * 
1078  * Return value: %TRUE if the font could be set successfully; %FALSE if no 
1079  *     such font exists or if the @fontchooser doesn't belong to a particular 
1080  *     screen yet.
1081  *
1082  * Since: 3.2
1083  */
1084 gboolean
1085 gtk_font_chooser_set_font_name (GtkFontChooser *fontchooser,
1086                                 const gchar      *fontname)
1087 {
1088   GtkFontChooserPrivate *priv = fontchooser->priv;
1089   GtkTreeIter           iter;
1090   gboolean              valid;
1091   gchar                *family_name;
1092   PangoFontDescription *desc;
1093   gboolean              found = FALSE;
1094   
1095   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
1096   g_return_val_if_fail (fontname != NULL, FALSE);
1097
1098   if (!gtk_widget_has_screen (GTK_WIDGET (fontchooser)))
1099     return FALSE;
1100
1101   desc = pango_font_description_from_string (fontname);
1102   family_name = (gchar*)pango_font_description_get_family (desc);
1103
1104   if (!family_name)
1105   {
1106     pango_font_description_free (desc);
1107     return FALSE;
1108   }
1109
1110   /* We make sure the filter is clear */
1111   gtk_entry_set_text (GTK_ENTRY (priv->search_entry), "");
1112
1113   /* We find the matching family/face */
1114   for (valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->filter), &iter);
1115        valid;
1116        valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->filter), &iter))
1117     {
1118       PangoFontFace        *face;
1119       PangoFontDescription *tmp_desc;
1120
1121       gtk_tree_model_get (GTK_TREE_MODEL (priv->filter), &iter,
1122                           FACE_COLUMN,   &face,
1123                           -1);
1124
1125       tmp_desc = pango_font_face_describe (face);
1126       if (pango_font_description_get_size_is_absolute (desc))
1127         pango_font_description_set_absolute_size (tmp_desc,
1128                                                   pango_font_description_get_size (desc));
1129       else
1130         pango_font_description_set_size (tmp_desc,
1131                                          pango_font_description_get_size (desc));        
1132
1133
1134       if (pango_font_description_equal (desc, tmp_desc))
1135         {
1136           GtkTreePath *path;
1137           gint size = pango_font_description_get_size (desc);
1138
1139           if (size)
1140             {
1141               if (pango_font_description_get_size_is_absolute (desc))
1142                 size = size * PANGO_SCALE;
1143               gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->size_spin),
1144                                          size / PANGO_SCALE);
1145             }
1146
1147           path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->filter),
1148                                           &iter);
1149
1150           if (path)
1151             {
1152               gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->family_face_list),
1153                                         path,
1154                                         NULL,
1155                                         FALSE);
1156               gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->family_face_list),
1157                                             path,
1158                                             NULL,
1159                                             FALSE,
1160                                             0.5,
1161                                             0.5);
1162               gtk_tree_path_free (path);
1163             }
1164
1165           found = TRUE;
1166         }
1167
1168       g_object_unref (face);
1169       pango_font_description_free (tmp_desc);
1170
1171       if (found)
1172         break;
1173     }
1174
1175   pango_font_description_free (desc);
1176   g_object_notify (G_OBJECT (fontchooser), "font-name");
1177
1178   return found;
1179 }
1180
1181 /**
1182  * gtk_font_chooser_get_preview_text:
1183  * @fontchooser: a #GtkFontChooser
1184  *
1185  * Gets the text displayed in the preview area.
1186  * 
1187  * Return value: (transfer none): the text displayed in the
1188  *     preview area. This string is owned by the widget and
1189  *     should not be modified or freed
1190  *
1191  * Since: 3.2
1192  */
1193 const gchar*
1194 gtk_font_chooser_get_preview_text (GtkFontChooser *fontchooser)
1195 {
1196   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
1197   return (const gchar*)fontchooser->priv->preview_text;
1198 }
1199
1200
1201 /**
1202  * gtk_font_chooser_set_preview_text:
1203  * @fontchooser: a #GtkFontChooser
1204  * @text: (transfer none): the text to display in the preview area 
1205  *
1206  * Sets the text displayed in the preview area.
1207  * The @text is used to show how the selected font looks.
1208  *
1209  * Since: 3.2
1210  */
1211 void
1212 gtk_font_chooser_set_preview_text  (GtkFontChooser *fontchooser,
1213                                     const gchar    *text)
1214 {
1215   g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
1216   g_return_if_fail (text != NULL);
1217
1218   g_free (fontchooser->priv->preview_text);
1219   fontchooser->priv->preview_text = g_strdup (text);
1220
1221   populate_list (fontchooser,
1222                  GTK_TREE_VIEW (fontchooser->priv->family_face_list),
1223                  fontchooser->priv->model);
1224
1225   gtk_entry_set_text (GTK_ENTRY (fontchooser->priv->preview), text);
1226
1227   g_object_notify (G_OBJECT (fontchooser), "preview-text");
1228 }
1229
1230 /**
1231  * gtk_font_chooser_get_show_preview_entry:
1232  * @fontchooser: a #GtkFontChooser
1233  *
1234  * Return value: %TRUE if the preview entry is shown or %FALSE if
1235  *               it is hidden.
1236  * Since: 3.2
1237  */
1238 gboolean
1239 gtk_font_chooser_get_show_preview_entry (GtkFontChooser *fontchooser)
1240 {
1241   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), FALSE);
1242
1243   return fontchooser->priv->show_preview_entry;
1244 }
1245
1246 /**
1247  * gtk_font_chooser_set_show_preview_entry:
1248  * @fontchooser: a #GtkFontChooser
1249  * @show_preview_entry: whether to show the editable preview entry or not
1250  *
1251  * Shows or hides the editable preview entry.
1252  * Since: 3.2
1253  */
1254 void
1255 gtk_font_chooser_set_show_preview_entry (GtkFontChooser *fontchooser,
1256                                          gboolean        show_preview_entry)
1257 {
1258   g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
1259
1260   if (show_preview_entry)
1261     gtk_widget_show (fontchooser->priv->preview_scrolled_window);
1262   else
1263     gtk_widget_hide (fontchooser->priv->preview_scrolled_window);
1264
1265   fontchooser->priv->show_preview_entry = show_preview_entry;
1266   g_object_notify (G_OBJECT (fontchooser), "show-preview-entry");
1267 }