2 Copyright (C) 1999 Paul Barton-Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <cstdio> /* for sprintf, sigh ... */
24 #include <gtkmm2ext/utils.h>
25 #include <gtkmm2ext/click_box.h>
29 using namespace Gtkmm2ext;
32 ClickBox::ClickBox (Gtk::Adjustment *adjp, const string &name, bool round_to_steps)
33 : AutoSpin (*adjp,0,round_to_steps)
35 layout = create_pango_layout ("");
40 add_events (Gdk::BUTTON_RELEASE_MASK|
41 Gdk::BUTTON_PRESS_MASK|
42 Gdk::ENTER_NOTIFY_MASK|
43 Gdk::LEAVE_NOTIFY_MASK);
45 get_adjustment().signal_value_changed().connect (mem_fun (*this, &ClickBox::set_label));
46 signal_style_changed().connect (mem_fun (*this, &ClickBox::style_changed));
47 signal_button_press_event().connect (mem_fun (*this, &ClickBox::button_press_handler));
48 signal_button_release_event().connect (mem_fun (*this, &ClickBox::button_release_handler));
53 ClickBox::~ClickBox ()
58 ClickBox::button_press_handler (GdkEventButton* ev)
61 AutoSpin::button_press (ev);
66 ClickBox::on_scroll_event (GdkEventScroll* ev)
68 AutoSpin::scroll_event (ev);
73 ClickBox::button_release_handler (GdkEventButton* ev)
88 ClickBox::set_label ()
93 bool const h = _printer (buf, get_adjustment());
95 /* the printer didn't handle it, so use a default */
96 sprintf (buf, "%.2f", get_adjustment().get_value ());
99 layout->set_text (buf);
100 layout->get_pixel_size (width, height);
102 if (twidth < width && (width > 50)) {
103 /* override GenericPluginUI::build_control_ui()
104 * Gtkmm2ext::set_size_request_to_display_given_text ("g9999999")
105 * see http://tracker.ardour.org/view.php?id=6499
107 set_size_request (std::min (300, width + 6), height + 4);
110 twidth = width; theight = height;
116 ClickBox::style_changed (const Glib::RefPtr<Gtk::Style>&)
118 layout->context_changed ();
119 layout->get_pixel_size (twidth, theight);
123 ClickBox::on_expose_event (GdkEventExpose *ev)
125 /* Why do we do things like this rather than use a Gtk::Label?
126 Because whenever Gtk::Label::set_label() is called, it
127 triggers a recomputation of its own size, along with that
128 of its container and on up the tree. That's intended
129 to be unnecessary here.
132 Gtk::DrawingArea::on_expose_event (ev);
134 Glib::RefPtr<Gtk::Style> style (get_style());
135 Glib::RefPtr<Gdk::GC> fg_gc (style->get_fg_gc (Gtk::STATE_NORMAL));
136 Glib::RefPtr<Gdk::GC> bg_gc (style->get_bg_gc (Gtk::STATE_NORMAL));
137 Glib::RefPtr<Gdk::Window> win (get_window());
139 GdkRectangle base_rect;
140 GdkRectangle draw_rect;
141 gint x, y, width, height, depth;
143 win->get_geometry (x, y, width, height, depth);
145 base_rect.width = width;
146 base_rect.height = height;
150 gdk_rectangle_intersect (&ev->area, &base_rect, &draw_rect);
151 win->draw_rectangle (bg_gc, true, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
153 if (twidth && theight) {
154 win->draw_layout (fg_gc, (width - twidth) / 2, (height - theight) / 2, layout);
161 ClickBox::set_printer (sigc::slot<bool, char *, Gtk::Adjustment &> p)