Merged older cs.po file with newest pot file.
[gliv/czech_localization.git] / src / scrollbars.c
blobe9c6ba79cad2e1c1f32dacceeb164e18609e22a8
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /******************************************
22 * The vertical and horizontal scrollbars *
23 ******************************************/
25 #include "gliv.h"
26 #include "scrollbars.h"
27 #include "options.h"
28 #include "gliv-image.h"
29 #include "windows.h"
30 #include "matrix.h"
31 #include "params.h"
32 #include "rendering.h"
34 extern rt_struct *rt;
35 extern options_struct *options;
36 extern GlivImage *current_image;
38 /* Horizontal Scrollbar. */
39 static GtkHScrollbar *hscroll;
41 /* Vertical Scrollbar. */
42 static GtkVScrollbar *vscroll;
44 gboolean toggle_scrollbars(void)
46 GtkWidget *widgets[2];
48 widgets[0] = GTK_WIDGET(hscroll);
49 widgets[1] = GTK_WIDGET(vscroll);
51 if (toggle_widgets(widgets, 2, &options->scrollbars) && options->scrollbars)
52 update_scrollbars();
54 return FALSE;
57 /* Update a given scrollbar. */
58 static void update_scroll(GtkScrollbar * scroll, gfloat min, gfloat max,
59 gfloat dim)
61 GtkAdjustment *adj;
62 gboolean update_needed = FALSE;
63 gfloat previous;
65 adj = gtk_range_get_adjustment(GTK_RANGE(scroll));
67 /* Smallest length containing the image and the window = window U image. */
68 previous = adj->lower;
69 adj->lower = MIN(min, 0.0);
70 update_needed = update_needed || !float_equal(previous, adj->lower);
72 previous = adj->upper;
73 adj->upper = MAX(max, dim);
74 update_needed = update_needed || !float_equal(previous, adj->upper);
76 /* Window size. */
77 adj->page_size = dim;
79 adj->step_increment = MOVE_OFFSET;
80 adj->page_increment = dim;
82 /* The offset is actually computed with adj->lower and adj->upper. */
83 adj->value = 0.0;
85 if (update_needed) {
86 gtk_adjustment_changed(adj);
87 gdk_window_process_updates(GTK_WIDGET(scroll)->window, FALSE);
91 /* Update both scrollbars. */
92 void update_scrollbars(void)
94 gfloat min_x, max_x, min_y, max_y;
96 if (current_image == NULL || options->scrollbars == FALSE)
97 return;
99 get_matrix_bounding_box(&min_x, &max_x, &min_y, &max_y);
101 update_scroll(GTK_SCROLLBAR(hscroll), min_x, max_x,
102 (gfloat) rt->wid_size->width);
104 update_scroll(GTK_SCROLLBAR(vscroll), min_y, max_y,
105 (gfloat) rt->wid_size->height);
108 static gboolean scroll_val(GtkRange * range)
110 gfloat offset;
112 offset = -1.0 * gtk_range_get_value(range);
114 if (range == GTK_RANGE(hscroll))
115 matrix_move(offset, 0.0);
116 else
117 /* range == GTK_RANGE(vscroll) */
118 matrix_move(0.0, offset);
120 refresh(REFRESH_BURST | APPEND_HISTORY);
121 update_scrollbars();
122 return FALSE;
125 /* Called during the initialization to build the two scrollbars. */
126 GtkWidget *get_new_scrollbar(gboolean horizontal)
128 GtkRange *range;
130 if (horizontal) {
131 range = GTK_RANGE(gtk_hscrollbar_new(NULL));
132 hscroll = GTK_HSCROLLBAR(range);
133 } else {
134 range = GTK_RANGE(gtk_vscrollbar_new(NULL));
135 vscroll = GTK_VSCROLLBAR(range);
138 gtk_range_set_update_policy(range, GTK_UPDATE_CONTINUOUS);
140 g_signal_connect(range, "value-changed", G_CALLBACK(scroll_val), NULL);
142 return GTK_WIDGET(range);
145 void hide_scrollbars(void)
147 gtk_widget_hide(GTK_WIDGET(hscroll));
148 gtk_widget_hide(GTK_WIDGET(vscroll));