}
-static void integer_printer (char buf[32], Adjustment &adj, void */*arg*/)
+static bool
+integer_printer (char buf[32], Adjustment &adj)
{
snprintf (buf, 32, "%.0f", adj.get_value());
+ return true;
}
void
if (desc.integer_step) {
control_ui->clickbox = new ClickBox (adj, "PluginUIClickBox");
Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2);
- control_ui->clickbox->set_print_func (integer_printer, 0);
+ control_ui->clickbox->set_printer (sigc::ptr_fun (integer_printer));
} else {
//sigc::slot<void,char*,uint32_t> pslot = sigc::bind (sigc::mem_fun(*this, &GenericPluginUI::print_parameter), (uint32_t) port_index);
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;
return true;
}
-void
-ClickBox::default_printer (char buf[32], Gtk::Adjustment &adj,
- void *)
-{
- sprintf (buf, "%.2f", adj.get_value());
-}
-
void
ClickBox::set_label ()
{
- if (!print_func) {
- return;
- }
-
char buf[32];
- print_func (buf, get_adjustment(), print_arg);
+ 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 (twidth, theight);
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());
-
- GdkRectangle base_rect;
- GdkRectangle draw_rect;
- gint x, y, width, height, depth;
-
- win->get_geometry (x, y, width, height, depth);
-
- base_rect.width = width;
- base_rect.height = height;
- base_rect.x = 0;
- base_rect.y = 0;
-
- 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);
-
- if (twidth && theight) {
- win->draw_layout (fg_gc, (width - twidth) / 2, (height - theight) / 2, layout);
- }
+ 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());
+
+ GdkRectangle base_rect;
+ GdkRectangle draw_rect;
+ gint x, y, width, height, depth;
+
+ win->get_geometry (x, y, width, height, depth);
+
+ base_rect.width = width;
+ base_rect.height = height;
+ base_rect.x = 0;
+ base_rect.y = 0;
+
+ 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);
+
+ 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 ();
+}
+
ClickBox (Gtk::Adjustment *adj, const std::string &name, bool round_to_steps = false);
~ClickBox ();
- void set_print_func(void (*pf)(char buf[32], Gtk::Adjustment &, void *),
- void *arg) {
- print_func = pf;
- print_arg = arg;
- set_label ();
- }
-
+ /** Set a slot to `print' the value to put in the box.
+ * The slot should write the value of the Gtk::Adjustment
+ * into the char array, and should return true if it has done the printing,
+ * or false to use the ClickBox's default printing method.
+ */
+ void set_printer (sigc::slot<bool, char *, Gtk::Adjustment &>);
protected:
bool on_expose_event (GdkEventExpose*);
private:
- void (*print_func) (char buf[32], Gtk::Adjustment &, void *);
- void *print_arg;
-
Glib::RefPtr<Pango::Layout> layout;
int twidth;
int theight;
bool button_press_handler (GdkEventButton *);
bool button_release_handler (GdkEventButton *);
- static void default_printer (char buf[32], Gtk::Adjustment &, void *);
+ sigc::slot<bool, char *, Gtk::Adjustment &> _printer;
};
} /* namespace */