/*
- Copyright (C) 1999 Paul Barton-Davis
+ Copyright (C) 1999 Paul Barton-Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
ClickBox::ClickBox (Gtk::Adjustment *adjp, const string &name, bool round_to_steps)
: AutoSpin (*adjp,0,round_to_steps)
{
- print_func = default_printer;
- print_arg = 0;
+ layout = create_pango_layout ("");
+ twidth = 0;
+ theight = 0;
+
- set_name (name);
add_events (Gdk::BUTTON_RELEASE_MASK|
Gdk::BUTTON_PRESS_MASK|
Gdk::ENTER_NOTIFY_MASK|
Gdk::LEAVE_NOTIFY_MASK);
- set_label ();
get_adjustment().signal_value_changed().connect (mem_fun (*this, &ClickBox::set_label));
-
+ signal_style_changed().connect (mem_fun (*this, &ClickBox::style_changed));
signal_button_press_event().connect (mem_fun (*this, &ClickBox::button_press_handler));
signal_button_release_event().connect (mem_fun (*this, &ClickBox::button_release_handler));
+ set_name (name);
+ set_label ();
}
ClickBox::~ClickBox ()
return true;
}
+bool
+ClickBox::on_scroll_event (GdkEventScroll* ev)
+{
+ AutoSpin::scroll_event (ev);
+ return true;
+}
+
bool
ClickBox::button_release_handler (GdkEventButton* ev)
{
}
void
-ClickBox::default_printer (char buf[32], Gtk::Adjustment &adj,
- void *ignored)
+ClickBox::set_label ()
{
- sprintf (buf, "%.2f", adj.get_value());
+ char buf[32];
+ int width, height;
+
+ bool const h = _printer (buf, get_adjustment());
+ if (!h) {
+ /* the printer didn't handle it, so use a default */
+ sprintf (buf, "%.2f", get_adjustment().get_value ());
+ }
+
+ layout->set_text (buf);
+ layout->get_pixel_size (width, height);
+
+ if (twidth < width && (width > 50)) {
+ /* override GenericPluginUI::build_control_ui()
+ * Gtkmm2ext::set_size_request_to_display_given_text ("g9999999")
+ * see http://tracker.ardour.org/view.php?id=6499
+ */
+ set_size_request (std::min (300, width + 6), height + 4);
+ }
+
+ twidth = width; theight = height;
+
+ queue_draw ();
}
void
-ClickBox::set_label ()
+ClickBox::style_changed (const Glib::RefPtr<Gtk::Style>&)
{
- queue_draw ();
+ layout->context_changed ();
+ layout->get_pixel_size (twidth, theight);
}
bool
Gtk::DrawingArea::on_expose_event (ev);
- if (print_func) {
+ Glib::RefPtr<Gtk::Style> style (get_style());
+ Glib::RefPtr<Gdk::GC> fg_gc (style->get_fg_gc (Gtk::STATE_NORMAL));
+ Glib::RefPtr<Gdk::GC> bg_gc (style->get_bg_gc (Gtk::STATE_NORMAL));
+ Glib::RefPtr<Gdk::Window> win (get_window());
- char buf[32];
+ GdkRectangle base_rect;
+ GdkRectangle draw_rect;
+ gint x, y, width, height, depth;
- Glib::RefPtr<Gtk::Style> style (get_style());
+ win->get_geometry (x, y, width, height, depth);
- print_func (buf, get_adjustment(), print_arg);
+ base_rect.width = width;
+ base_rect.height = height;
+ base_rect.x = 0;
+ base_rect.y = 0;
- Glib::RefPtr <Gdk::Window> win (get_window());
- win->draw_rectangle (style->get_bg_gc(get_state()),
- TRUE, 0, 0, -1, -1);
+ gdk_rectangle_intersect (&ev->area, &base_rect, &draw_rect);
+ win->draw_rectangle (bg_gc, true, draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
- {
- int width = 0;
- int height = 0;
- create_pango_layout(buf)->get_pixel_size(width, height);
- set_size_request(width, height);
- }
+ if (twidth && theight) {
+ win->draw_layout (fg_gc, (width - twidth) / 2, (height - theight) / 2, layout);
}
return true;
}
+
+void
+ClickBox::set_printer (sigc::slot<bool, char *, Gtk::Adjustment &> p)
+{
+ _printer = p;
+ set_label ();
+}
+