1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2010 Ales Hvezda
4 * Copyright (C) 1998-2020 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 /*! \file x_grid_size_sb.c
22 * \brief Spinbox for grid size selection.
38 update_spin_button_internal (GtkSpinButton
*spin_button
, gdouble value
);
45 v
== 5 || v
== 10 || v
== 20 || v
== 40 || v
== 80 || v
== 160 ||
46 v
== 320 || v
== 640 || v
== 1280 || v
== 2560 || v
== 5120 ||
47 v
== 10240 || v
== 20480 || v
== 40960 || v
== 81920 ||
49 /* base 100 (default) */
50 v
== 25 || v
== 50 || v
== 100 || v
== 200 || v
== 400 || v
== 800 ||
51 v
== 1600 || v
== 3200 || v
== 6400 || v
== 12800 || v
== 25600 ||
55 v
== 125 || v
== 250 || v
== 500 || v
== 1000 || v
== 2000 ||
56 v
== 4000 || v
== 8000 || v
== 16000 || v
== 32000 || v
== 64000;
60 spin_button_value_changed (GtkSpinButton
*spin_button
,
61 GschemToplevel
*w_current
)
63 gint value
= gtk_spin_button_get_value_as_int (spin_button
);
64 gint prev_value
= gschem_options_get_snap_size (w_current
->options
);
66 /* Gtk doesn't allow handling the increment/decrement events
67 directly, so we have to observe the new value and guess whether
68 they are the result of pressing up/down on the previous value. */
69 if (!is_grid_step (value
) && is_grid_step (prev_value
)) {
70 if (value
== prev_value
- 1) {
71 if (prev_value
% 2 == 0 && is_grid_step (prev_value
/ 2))
72 value
= prev_value
/ 2;
75 } else if (value
== prev_value
+ 1) {
76 if (is_grid_step (prev_value
* 2))
77 value
= prev_value
* 2;
83 update_spin_button_internal (spin_button
, value
);
84 gschem_options_set_snap_size (w_current
->options
, value
);
88 update_spin_button (GschemOptions
*options
,
92 update_spin_button_internal (GTK_SPIN_BUTTON (user_data
),
93 gschem_options_get_snap_size (options
));
97 update_spin_button_internal (GtkSpinButton
*spin_button
,
100 g_signal_handlers_block_matched (
101 spin_button
, G_SIGNAL_MATCH_FUNC
, 0, 0, NULL
,
102 G_CALLBACK (spin_button_value_changed
), NULL
);
104 gtk_spin_button_set_value (spin_button
, value
);
106 g_signal_handlers_unblock_matched (
107 spin_button
, G_SIGNAL_MATCH_FUNC
, 0, 0, NULL
,
108 G_CALLBACK (spin_button_value_changed
), NULL
);
111 /*! \brief Create grid size spinbox.
114 x_grid_size_sb_new (GschemToplevel
*w_current
)
116 GtkObject
*adjustment
= gtk_adjustment_new (1, MINIMUM_SNAP_SIZE
,
117 MAXIMUM_SNAP_SIZE
, 1, 1, 0);
118 GtkWidget
*spin_button
= g_object_new (GTK_TYPE_SPIN_BUTTON
, NULL
);
119 gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (spin_button
),
120 GTK_ADJUSTMENT (adjustment
));
121 gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_button
),
122 gschem_options_get_snap_size (w_current
->options
));
123 gtk_entry_set_width_chars (GTK_ENTRY (spin_button
), 5);
125 g_signal_connect (spin_button
, "value-changed",
126 G_CALLBACK (spin_button_value_changed
), w_current
);
127 g_signal_connect (w_current
->options
, "notify::snap-size",
128 G_CALLBACK (update_spin_button
), spin_button
);