24 #include <glib/gi18n.h>
49 { N_(
"70%"), 0.7071067811 },
50 { N_(
"85%"), 0.8408964152 },
52 { N_(
"125%"), 1.1892071149 },
53 { N_(
"150%"), 1.4142135623 },
54 { N_(
"175%"), 1.6817928304 },
56 { N_(
"300%"), 2.8284271247 },
59 { N_(
"1600%"), 16.0 },
60 { N_(
"3200%"), 32.0 },
79 #define EPSILON 0.000001
91 gtk_entry_set_text (GTK_ENTRY (zoom_action->
priv->
entry),
97 zoom_perc = zoom * 100.;
98 if (ABS ((gint)zoom_perc - zoom_perc) < 0.001)
99 zoom_str = g_strdup_printf (
"%d%%", (gint)zoom_perc);
101 zoom_str = g_strdup_printf (
"%.2f%%", zoom_perc);
102 gtk_entry_set_text (GTK_ENTRY (zoom_action->
priv->
entry), zoom_str);
110 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (zoom_action));
132 gtk_widget_set_sensitive (GTK_WIDGET (zoom_action),
FALSE);
145 gtk_entry_set_width_chars (GTK_ENTRY (zoom_action->
priv->
entry), width + 3 + 3);
168 item = g_menu_item_new (
zoom_levels[i].name, NULL);
169 g_menu_item_set_action_and_target (item,
"win.zoom",
172 g_object_unref (item);
184 g_clear_pointer (&zoom_action->
priv->
popup, (GDestroyNotify)gtk_widget_destroy);
195 const gchar *text = gtk_entry_get_text (entry);
196 gchar *end_ptr = NULL;
198 if (!text || text[0] ==
'\0') {
204 zoom_perc = g_strtod (text, &end_ptr);
205 if (end_ptr && end_ptr[0] !=
'\0' && end_ptr[0] !=
'%') {
211 screen = gtk_widget_get_screen (GTK_WIDGET (zoom_action));
212 zoom = zoom_perc / 100.;
246 zoom_action->
priv->
popup = gtk_popover_new_from_model (GTK_WIDGET (zoom_action),
247 G_MENU_MODEL (zoom_action->
priv->
menu));
248 g_signal_connect (zoom_action->
priv->
popup,
"closed",
251 gtk_entry_get_icon_area (GTK_ENTRY (zoom_action->
priv->
entry),
252 GTK_ENTRY_ICON_SECONDARY, &rect);
253 gtk_popover_set_pointing_to (GTK_POPOVER (zoom_action->
priv->
popup), &rect);
254 gtk_popover_set_position (GTK_POPOVER (zoom_action->
priv->
popup), GTK_POS_BOTTOM);
261 GtkEntryIconPosition icon_pos,
262 GdkEventButton *event,
265 if (event->button != GDK_BUTTON_PRIMARY)
268 gtk_widget_show (
get_popup (zoom_action));
278 g_object_remove_weak_pointer (G_OBJECT (zoom_action->
priv->
model),
282 g_clear_object (&zoom_action->
priv->
menu);
285 G_OBJECT_CLASS (ev_zoom_action_parent_class)->finalize (
object);
298 zoom_action->
priv->
model = g_value_get_object (value);
301 zoom_action->
priv->
menu = g_value_dup_object (value);
304 G_OBJECT_WARN_INVALID_PROPERTY_ID (
object, prop_id, pspec);
322 *minimum_width = *natural_width = 0;
324 GTK_WIDGET_CLASS (ev_zoom_action_parent_class)->get_preferred_width (widget, minimum_width, natural_width);
325 *natural_width = *minimum_width;
333 G_OBJECT_CLASS (ev_zoom_action_parent_class)->constructed (
object);
336 g_menu_model_get_item_link (G_MENU_MODEL (zoom_action->
priv->
menu),
340 g_object_add_weak_pointer (G_OBJECT (zoom_action->
priv->
model),
346 gtk_widget_set_sensitive (GTK_WIDGET (zoom_action),
FALSE);
349 g_signal_connect_object (zoom_action->
priv->
model,
"notify::document",
352 g_signal_connect_object (zoom_action->
priv->
model,
"notify::scale",
355 g_signal_connect_object (zoom_action->
priv->
model,
"notify::max-scale",
365 GObjectClass *object_class = G_OBJECT_CLASS (klass);
366 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
374 g_object_class_install_property (object_class,
376 g_param_spec_object (
"document-model",
378 "The document model",
381 G_PARAM_CONSTRUCT_ONLY |
382 G_PARAM_STATIC_STRINGS));
384 g_object_class_install_property (object_class,
386 g_param_spec_object (
"menu",
388 "The zoom popup menu",
391 G_PARAM_CONSTRUCT_ONLY |
392 G_PARAM_STATIC_STRINGS));
395 g_signal_new (
"activated",
396 G_OBJECT_CLASS_TYPE (object_class),
399 g_cclosure_marshal_VOID__VOID,
411 priv = zoom_action->
priv;
413 gtk_orientable_set_orientation (GTK_ORIENTABLE (zoom_action), GTK_ORIENTATION_VERTICAL);
415 priv->
entry = gtk_entry_new ();
416 gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->
entry),
417 GTK_ENTRY_ICON_SECONDARY,
419 gtk_box_pack_start (GTK_BOX (zoom_action), priv->
entry,
TRUE,
FALSE, 0);
420 gtk_widget_show (priv->
entry);
422 g_signal_connect (priv->
entry,
"icon-press",
425 g_signal_connect (priv->
entry,
"activate",
428 g_signal_connect_swapped (priv->
entry,
"focus-out-event",
438 g_return_val_if_fail (G_IS_MENU (menu), NULL);
441 "document-model", model,