From f27ff4c8b882444a569e73e4b21aded280ee748f Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 25 Sep 2017 05:21:53 +0200 Subject: [PATCH] Retire ClickBox + AutoSpin After over 17 years of honorable service to the Ardour Codebase. ClickBox and AutoSpin are retiring into the git nirvana. We're glad for the duty, decency, reliability, dignity, respect which these classes brought to Arodur and look back in gratitude on their years of service. PS. First one to say "cruft" will be fired. --- libs/widgets/auto_spin.cc | 298 ------------------------------- libs/widgets/click_box.cc | 188 ------------------- libs/widgets/widgets/auto_spin.h | 76 -------- libs/widgets/widgets/click_box.h | 82 --------- libs/widgets/wscript | 2 - 5 files changed, 646 deletions(-) delete mode 100644 libs/widgets/auto_spin.cc delete mode 100644 libs/widgets/click_box.cc delete mode 100644 libs/widgets/widgets/auto_spin.h delete mode 100644 libs/widgets/widgets/click_box.h diff --git a/libs/widgets/auto_spin.cc b/libs/widgets/auto_spin.cc deleted file mode 100644 index 9d86eb50ac..0000000000 --- a/libs/widgets/auto_spin.cc +++ /dev/null @@ -1,298 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id$ -*/ - -#include -#include "gtkmm2ext/keyboard.h" -#include "widgets/auto_spin.h" - -using namespace Gtkmm2ext; -using namespace ArdourWidgets; -using namespace std; - -#define upper adjustment.get_upper() -#define lower adjustment.get_lower() -#define step_increment adjustment.get_step_increment() -#define page_increment adjustment.get_page_increment() - -const unsigned int AutoSpin::initial_timer_interval = 500; /* msecs */ -const unsigned int AutoSpin::timer_interval = 20; /* msecs */ -const unsigned int AutoSpin::climb_timer_calls = 5; /* between climbing */ - -AutoSpin::AutoSpin (Gtk::Adjustment &adjr, gfloat cr, bool round_to_steps_yn) - : adjustment (adjr), - climb_rate (cr) - -{ - initial = adjustment.get_value (); - left_is_decrement = true; - wrap = false; - have_timer = false; - need_timer = false; - timer_calls = 0; - round_to_steps = round_to_steps_yn; -} - -void -AutoSpin::stop_timer () -{ - if (have_timer) { - g_source_remove (timeout_tag); - have_timer = false; - } -} - -gint -AutoSpin::stop_spinning (GdkEventButton */*ev*/) -{ - need_timer = false; - stop_timer (); - return FALSE; -} - -gint -AutoSpin::button_press (GdkEventButton *ev) -{ - bool shifted = false; - bool control = false; - bool with_decrement = false; - - stop_spinning (0); - - if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) { - return true; - } - - if (ev->state & Keyboard::TertiaryModifier) { - /* use page shift */ - - shifted = true; - } - - if (ev->state & Keyboard::PrimaryModifier) { - /* go to upper/lower bound on button1/button2 */ - - control = true; - } - - /* XXX should figure out which button is left/right */ - - switch (ev->button) { - case 1: - if (control) { - set_value (left_is_decrement ? lower : upper); - return TRUE; - } else { - if (left_is_decrement) { - with_decrement = true; - } else { - with_decrement = false; - } - } - break; - - case 2: - if (!control) { - set_value (initial); - } - return TRUE; - break; - - case 3: - if (control) { - set_value (left_is_decrement ? upper : lower); - return TRUE; - } - break; - - case 4: - if (!control) { - adjust_value (shifted ? page_increment : step_increment); - } else { - set_value (upper); - } - return TRUE; - break; - - case 5: - if (!control) { - adjust_value (shifted ? -page_increment : -step_increment); - } else { - set_value (lower); - } - return TRUE; - break; - } - - start_spinning (with_decrement, shifted); - return TRUE; -} - -gint -AutoSpin::scroll_event (GdkEventScroll *ev) -{ - stop_spinning (0); - - gfloat increment = step_increment; - - if (ev->state & Keyboard::TertiaryModifier) { - increment = page_increment; - } - - switch (ev->direction) { - case GDK_SCROLL_DOWN: - case GDK_SCROLL_LEFT: - adjust_value (-increment); - break; - case GDK_SCROLL_RIGHT: - case GDK_SCROLL_UP: - adjust_value (increment); - break; - } - return TRUE; -} - -void -AutoSpin::start_spinning (bool decrement, bool page) -{ - timer_increment = page ? page_increment : step_increment; - - if (decrement) { - timer_increment = -timer_increment; - } - - adjust_value (timer_increment); - - have_timer = true; - timer_calls = 0; - timeout_tag = g_timeout_add (initial_timer_interval, - AutoSpin::_timer, - this); -} - -gint -AutoSpin::_timer (void *arg) -{ - return ((AutoSpin *) arg)->timer (); -} - -void -AutoSpin::set_value (gfloat value) -{ - if (round_to_steps) - adjustment.set_value (floor((value / step_increment) + 0.5f) * step_increment); - else - adjustment.set_value (value); -} - -bool -AutoSpin::adjust_value (gfloat increment) -{ - gfloat val; - bool done = false; - - val = adjustment.get_value (); - - val += increment; - - if (val > upper) { - if (wrap) { - val = lower; - } else { - val = upper; - done = true; - } - } else if (val < lower) { - if (wrap) { - val = upper; - } else { - val = lower; - done = true; - } - } - - set_value (val); - return done; -} - -gint -AutoSpin::timer () -{ - bool done; - int retval = FALSE; - - done = adjust_value (timer_increment); - - if (need_timer) { - - /* we're in the initial call, which happened - after initial_timer_interval msecs. Now - request a much more frequent update. - */ - - timeout_tag = g_timeout_add (timer_interval, - _timer, - this); - have_timer = true; - need_timer = false; - - /* cancel this initial timeout */ - - retval = FALSE; - - } else { - /* this is the regular "fast" call after each - timer_interval msecs. - */ - - if (timer_calls < climb_timer_calls) { - timer_calls++; - } else { - if (climb_rate > 0.0) { - if (timer_increment > 0) { - timer_increment += climb_rate; - } else { - timer_increment -= climb_rate; - } - } - timer_calls = 0; - } - - if (!done) { - retval = TRUE; - } - } - - return retval; -} - -void -AutoSpin::set_bounds (gfloat init, gfloat up, gfloat down, bool with_reset) -{ - adjustment.set_upper (up); - adjustment.set_lower (down); - - initial = init; - - adjustment.changed (); - - if (with_reset) { - adjustment.set_value (init); - } -} diff --git a/libs/widgets/click_box.cc b/libs/widgets/click_box.cc deleted file mode 100644 index b3271a0cc4..0000000000 --- a/libs/widgets/click_box.cc +++ /dev/null @@ -1,188 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - $Id$ -*/ - -#include -#include /* for sprintf, sigh ... */ - -#include "pbd/controllable.h" -#include "gtkmm2ext/utils.h" -#include "widgets/click_box.h" - -using namespace std; -using namespace Gtk; -using namespace ArdourWidgets; -using namespace sigc; - -ClickBox::ClickBox (Gtk::Adjustment *adjp, const string &name, bool round_to_steps) - : AutoSpin (*adjp,0,round_to_steps) -{ - layout = create_pango_layout (""); - twidth = 0; - theight = 0; - - - add_events (Gdk::BUTTON_RELEASE_MASK| - Gdk::BUTTON_PRESS_MASK| - Gdk::ENTER_NOTIFY_MASK| - Gdk::LEAVE_NOTIFY_MASK); - - 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 () -{ -} - -bool -ClickBox::button_press_handler (GdkEventButton* ev) -{ - if (_binding_proxy.button_press_handler (ev)) { - return true; - } - add_modal_grab(); - AutoSpin::button_press (ev); - return true; -} - -bool -ClickBox::on_scroll_event (GdkEventScroll* ev) -{ - AutoSpin::scroll_event (ev); - return true; -} - -bool -ClickBox::button_release_handler (GdkEventButton* ev) -{ - switch (ev->button) { - case 1: - case 2: - case 3: - stop_spinning (0); - default: - remove_modal_grab(); - break; - } - return true; -} - -void -ClickBox::set_label () -{ - 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::style_changed (const Glib::RefPtr&) -{ - layout->context_changed (); - layout->get_pixel_size (twidth, theight); -} - -bool -ClickBox::on_expose_event (GdkEventExpose *ev) -{ - /* Why do we do things like this rather than use a Gtk::Label? - Because whenever Gtk::Label::set_label() is called, it - triggers a recomputation of its own size, along with that - of its container and on up the tree. That's intended - to be unnecessary here. - */ - - Gtk::DrawingArea::on_expose_event (ev); - - Glib::RefPtr style (get_style()); - Glib::RefPtr fg_gc (style->get_fg_gc (Gtk::STATE_NORMAL)); - Glib::RefPtr bg_gc (style->get_bg_gc (Gtk::STATE_NORMAL)); - Glib::RefPtr 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 p) -{ - _printer = p; - set_label (); -} - -bool -ClickBox::on_enter_notify_event (GdkEventCrossing* ev) -{ - boost::shared_ptr c (_binding_proxy.get_controllable ()); - if (c) { - PBD::Controllable::GUIFocusChanged (boost::weak_ptr (c)); - } - return false; -} - -bool -ClickBox::on_leave_notify_event (GdkEventCrossing* ev) -{ - if (_binding_proxy.get_controllable()) { - PBD::Controllable::GUIFocusChanged (boost::weak_ptr ()); - } - return false; -} diff --git a/libs/widgets/widgets/auto_spin.h b/libs/widgets/widgets/auto_spin.h deleted file mode 100644 index 099976f4db..0000000000 --- a/libs/widgets/widgets/auto_spin.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - Copyright (C) 2000 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef _WIDGETS_AUTO_SPIN_H_ -#define _WIDGETS_AUTO_SPIN_H_ - -#ifdef interface -#undef interface -#endif - -#include - -#include "widgets/visibility.h" - -namespace ArdourWidgets { - -class LIBWIDGETS_API AutoSpin -{ -public: - AutoSpin (Gtk::Adjustment &adj, gfloat cr = 0, bool round_to_steps_yn = false); - - Gtk::Adjustment &get_adjustment() { return adjustment; } - - void use_left_as_decrement (bool yn) { left_is_decrement = yn; } - void set_wrap (bool yn) { wrap = yn; } - void set_climb_rate (gfloat cr) { climb_rate = cr; } - void set_bounds (gfloat initial, gfloat low, gfloat high, bool with_reset = true); - - gint button_press (GdkEventButton *); - gint stop_spinning (GdkEventButton *ignored_but_here_for_clicked); - void start_spinning (bool decrementing, bool use_page); - gint scroll_event (GdkEventScroll *); - -private: - Gtk::Adjustment &adjustment; - gfloat climb_rate; - gfloat timer_increment; - gfloat initial; - unsigned int timer_calls; - bool have_timer; - bool need_timer; - bool wrap; - gint timeout_tag; - bool left_is_decrement; - bool round_to_steps; - - static const unsigned int initial_timer_interval; - static const unsigned int timer_interval; - static const unsigned int climb_timer_calls; - - void stop_timer (); - static gint _timer (void *arg); - gint timer (); - bool adjust_value (gfloat increment); - void set_value (gfloat value); -}; - -} /* namespace */ - -#endif diff --git a/libs/widgets/widgets/click_box.h b/libs/widgets/widgets/click_box.h deleted file mode 100644 index ae4ee8961a..0000000000 --- a/libs/widgets/widgets/click_box.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef _WIDGETS_CLICK_BOX_H_ -#define _WIDGETS_CLICK_BOX_H_ - -#ifdef interface -#undef interface -#endif - -#include - -#include -#include - -#include "widgets/auto_spin.h" -#include "widgets/binding_proxy.h" -#include "widgets/visibility.h" - -namespace PBD { - class Controllable; -} - -namespace ArdourWidgets { - -class LIBWIDGETS_API ClickBox : public Gtk::DrawingArea, public AutoSpin -{ - public: - ClickBox (Gtk::Adjustment *adj, const std::string &name, bool round_to_steps = false); - ~ClickBox (); - - /** 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); - - void set_controllable (boost::shared_ptr c) { - _binding_proxy.set_controllable (c); - } - - protected: - bool on_expose_event (GdkEventExpose*); - bool on_enter_notify_event (GdkEventCrossing* ev); - bool on_leave_notify_event (GdkEventCrossing* ev); - - BindingProxy _binding_proxy; - - private: - Glib::RefPtr layout; - int twidth; - int theight; - - void set_label (); - void style_changed (const Glib::RefPtr &); - bool button_press_handler (GdkEventButton *); - bool button_release_handler (GdkEventButton *); - bool on_scroll_event (GdkEventScroll*); - - sigc::slot _printer; -}; - -} /* namespace */ - -#endif diff --git a/libs/widgets/wscript b/libs/widgets/wscript index 0559abe4dc..4a31086c10 100644 --- a/libs/widgets/wscript +++ b/libs/widgets/wscript @@ -34,12 +34,10 @@ widgets_sources = [ 'ardour_knob.cc', 'ardour_spacer.cc', 'ardour_spinner.cc', - 'auto_spin.cc', 'barcontroller.cc', 'binding_proxy.cc', 'eventboxext.cc', 'choice.cc', - 'click_box.cc', 'fastmeter.cc', 'focus_entry.cc', 'pane.cc',