e7320102c64f9c1d6ae5b0c7fc69126fb1447f50
1 /** \file
2 * Gtkmm facade/wrapper around zoom_status code that formerly lived
3 * in desktop-widget.cpp
4 *
5 * Authors:
6 * Ralf Stephan <ralf@ark.in-berlin.de>
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * MenTaLguY <mental@rydia.net>
9 * bulia byak <buliabyak@users.sf.net>
10 *
11 * Copyright (C) 2005 Ralf Stephan
12 * Copyright (C) 2004 MenTaLguY
13 * Copyright (C) 1999-2002 Lauris Kaplinski
14 * Copyright (C) 2000-2001 Ximian, Inc.
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #include "ui/widget/zoom-status.h"
20 #include "desktop.h"
21 #include "desktop-handles.h"
22 #include "widgets/spw-utilities.h"
24 namespace Inkscape {
25 namespace UI {
26 namespace Widget {
28 ZoomStatus::ZoomStatus()
29 : _adj(0.0, -1.0, 1.0, 0.1, 0.1)
30 {
31 _dt = 0;
32 _upd_f = false;
34 property_numeric() = false;
35 property_update_policy() = Gtk::UPDATE_ALWAYS;
36 sp_set_font_size_smaller(static_cast<GtkWidget*>((void*)gobj()));
37 }
39 ZoomStatus::~ZoomStatus()
40 {
41 _dt = 0;
42 }
44 void
45 ZoomStatus::init(SPDesktop *dt)
46 {
47 _dt = dt;
48 property_digits() = 4;
49 _adj.set_value(0.0);
50 _adj.set_lower(log(SP_DESKTOP_ZOOM_MIN)/log(2.0));
51 _adj.set_upper(log(SP_DESKTOP_ZOOM_MAX)/log(2.0));
52 _adj.set_step_increment(0.1);
53 _adj.set_page_increment(0.1);
54 set_adjustment(_adj);
55 }
57 void
58 ZoomStatus::update()
59 {
60 if (!_dt) return;
61 _upd_f = true;
62 set_value(log(_dt->current_zoom())/log(2.0));
63 _upd_f = false;
64 }
66 inline double
67 value_to_display(double value)
68 {
69 return floor(pow(2, value) * 100.0 + 0.5);
70 }
72 inline double
73 display_to_value(double value)
74 {
75 return log(value / 100.0) / log(2.0);
76 }
78 int
79 ZoomStatus::on_input(double *new_val)
80 {
81 double new_scrolled = get_value();
82 double new_typed = atof(get_text().c_str());
84 if (value_to_display(new_scrolled) == new_typed)
85 { // the new value is set by scrolling
86 *new_val = new_scrolled;
87 } else { // the new value is typed in
88 *new_val = display_to_value(new_typed);
89 }
91 return true;
92 }
94 bool
95 ZoomStatus::on_output()
96 {
97 gchar b[64];
98 g_snprintf(b, 64, "%4.0f%%", value_to_display(get_value()));
99 set_text(b);
100 return true;
101 }
103 void
104 ZoomStatus::on_value_changed()
105 {
106 if (_upd_f) return;
107 _upd_f = true;
108 g_assert(_dt);
109 double zoom_factor = pow(2, get_value());
110 NR::Rect const d =_dt->get_display_area();
111 _dt->zoom_absolute(d.midpoint()[NR::X], d.midpoint()[NR::Y], zoom_factor);
112 gtk_widget_grab_focus(static_cast<GtkWidget*>((void*)_dt->canvas)); /// \todo this no love song
113 _upd_f = false;
114 }
116 }}}
118 /*
119 Local Variables:
120 mode:c++
121 c-file-style:"stroustrup"
122 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123 indent-tabs-mode:nil
124 fill-column:99
125 End:
126 */
127 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :