diff options
Diffstat (limited to 'libs/gtkmm2ext')
27 files changed, 245 insertions, 141 deletions
diff --git a/libs/gtkmm2ext/SConscript b/libs/gtkmm2ext/SConscript index 429836080a..286587e869 100644 --- a/libs/gtkmm2ext/SConscript +++ b/libs/gtkmm2ext/SConscript @@ -60,6 +60,7 @@ tearoff.cc textviewer.cc utils.cc version.cc +window_title.cc """) gtkmm2ext.VersionBuild(['version.cc','gtkmm2ext/version.h'], []) diff --git a/libs/gtkmm2ext/barcontroller.cc b/libs/gtkmm2ext/barcontroller.cc index f59d192ff1..c3c15b4281 100644 --- a/libs/gtkmm2ext/barcontroller.cc +++ b/libs/gtkmm2ext/barcontroller.cc @@ -267,14 +267,12 @@ BarController::expose (GdkEventExpose* event) gint w, h; double fract; - w = darea.get_width() - 2; - h = darea.get_height() - 2; - fract = ((adjustment.get_value() - adjustment.get_lower()) / (adjustment.get_upper() - adjustment.get_lower())); switch (_style) { case Line: + w = darea.get_width() - 1; h = darea.get_height(); x1 = (gint) floor (w * fract); x2 = x1; @@ -304,6 +302,10 @@ BarController::expose (GdkEventExpose* event) break; case LeftToRight: + + w = darea.get_width() - 2; + h = darea.get_height() - 2; + x1 = 0; x2 = (gint) floor (w * fract); y1 = 0; diff --git a/libs/gtkmm2ext/bindable_button.cc b/libs/gtkmm2ext/bindable_button.cc index 76b89deb02..3c3cad6e46 100644 --- a/libs/gtkmm2ext/bindable_button.cc +++ b/libs/gtkmm2ext/bindable_button.cc @@ -42,7 +42,7 @@ BindableToggleButton::BindableToggleButton (MIDI::Controllable *mc) } BindableToggleButton::BindableToggleButton(MIDI::Controllable *mc, const string &label) - : ToggleButton (label), + : StatefulButton (label), prompter (Gtk::WIN_POS_MOUSE, 30000, false), midi_control (mc), bind_button (2), @@ -90,17 +90,6 @@ BindableToggleButton::midi_learn() } bool -BindableToggleButton::on_button_press_event (GdkEventButton *ev) -{ - if ((ev->state & bind_statemask) && ev->button == bind_button) { - midi_learn (); - return true; - } - - return false; -} - -bool BindableToggleButton::prompter_hiding (GdkEventAny *ev) { if (unprompting) { diff --git a/libs/gtkmm2ext/fastmeter.cc b/libs/gtkmm2ext/fastmeter.cc index 3c489e08ff..ab1e1472b3 100644 --- a/libs/gtkmm2ext/fastmeter.cc +++ b/libs/gtkmm2ext/fastmeter.cc @@ -50,18 +50,16 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o) hold_state = 0; current_peak = 0; current_level = 0; - current_user_level = -100.0f; set_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK); pixrect.x = 0; pixrect.y = 0; - if (orientation == Vertical) { - pixbuf = request_vertical_meter(250); + pixbuf = request_vertical_meter(dimen, 250); } else { - pixbuf = request_horizontal_meter(186); + pixbuf = request_horizontal_meter(186, dimen); } pixheight = pixbuf->get_height(); @@ -79,14 +77,14 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o) request_height= pixrect.height; } -Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_vertical_meter(int length) +Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_vertical_meter(int width, int height) { - if (length < min_v_pixbuf_size) - length = min_v_pixbuf_size; - if (length > max_v_pixbuf_size) - length = max_v_pixbuf_size; + if (height < min_v_pixbuf_size) + height = min_v_pixbuf_size; + if (height > max_v_pixbuf_size) + height = max_v_pixbuf_size; - int index = length - 1; + int index = height - 1; if (v_pixbuf_cache == 0) { v_pixbuf_cache = (Glib::RefPtr<Gdk::Pixbuf>*) malloc(sizeof(Glib::RefPtr<Gdk::Pixbuf>) * max_v_pixbuf_size); @@ -97,8 +95,6 @@ Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_vertical_meter(int length) return ret; guint8* data; - int width = 5; - int height = length; data = (guint8*) malloc(width*height * 3); @@ -155,15 +151,15 @@ Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_vertical_meter(int length) return ret; } -Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_horizontal_meter(int length) +Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_horizontal_meter(int width, int height) { - if (length < min_h_pixbuf_size) - length = min_h_pixbuf_size; - if (length > max_h_pixbuf_size) - length = max_h_pixbuf_size; + if (width < min_h_pixbuf_size) + width = min_h_pixbuf_size; + if (width > max_h_pixbuf_size) + width = max_h_pixbuf_size; + + int index = width - 1; - int index = length - 1; - if (h_pixbuf_cache == 0) { h_pixbuf_cache = (Glib::RefPtr<Gdk::Pixbuf>*) malloc(sizeof(Glib::RefPtr<Gdk::Pixbuf>) * max_h_pixbuf_size); memset(h_pixbuf_cache,0,sizeof(Glib::RefPtr<Gdk::Pixbuf>) * max_h_pixbuf_size); @@ -173,8 +169,6 @@ Glib::RefPtr<Gdk::Pixbuf> FastMeter::request_horizontal_meter(int length) return ret; guint8* data; - int width = length; - int height = 5; data = (guint8*) malloc(width*height * 3); @@ -253,19 +247,20 @@ void FastMeter::on_size_request (GtkRequisition* req) { if (orientation == Vertical) { + req->height = request_height; - req->height = max(req->height, min_v_pixbuf_size); req->height = min(req->height, max_v_pixbuf_size); - req->width = 5; - } else { req->width = request_width; + } else { + + req->width = request_width; req->width = max(req->width, min_h_pixbuf_size); req->width = min(req->width, max_h_pixbuf_size); - req->height = 5; + req->height = request_height; } } @@ -274,8 +269,9 @@ void FastMeter::on_size_allocate (Gtk::Allocation &alloc) { if (orientation == Vertical) { - if (alloc.get_width() != 5) { - alloc.set_width(5); + + if (alloc.get_width() != request_width) { + alloc.set_width (request_width); } int h = alloc.get_height(); @@ -286,11 +282,13 @@ FastMeter::on_size_allocate (Gtk::Allocation &alloc) alloc.set_height(h); if (pixheight != h) { - pixbuf = request_vertical_meter(h); + pixbuf = request_vertical_meter(request_width, h); } + } else { - if (alloc.get_height() != 5) { - alloc.set_height(5); + + if (alloc.get_height() != request_height) { + alloc.set_height(request_height); } int w = alloc.get_width(); @@ -301,7 +299,7 @@ FastMeter::on_size_allocate (Gtk::Allocation &alloc) alloc.set_width(w); if (pixwidth != w) { - pixbuf = request_horizontal_meter(w); + pixbuf = request_horizontal_meter(w, request_height); } } @@ -414,10 +412,9 @@ FastMeter::horizontal_expose (GdkEventExpose* ev) } void -FastMeter::set (float lvl, float usrlvl) +FastMeter::set (float lvl) { current_level = lvl; - current_user_level = usrlvl; if (lvl > current_peak) { current_peak = lvl; diff --git a/libs/gtkmm2ext/gtk_ui.cc b/libs/gtkmm2ext/gtk_ui.cc index 177e4f3dbb..903f56ba6f 100644 --- a/libs/gtkmm2ext/gtk_ui.cc +++ b/libs/gtkmm2ext/gtk_ui.cc @@ -37,6 +37,7 @@ #include <gtkmm2ext/textviewer.h> #include <gtkmm2ext/popup.h> #include <gtkmm2ext/utils.h> +#include <gtkmm2ext/window_title.h> #include "i18n.h" @@ -87,10 +88,11 @@ UI::UI (string namestr, int *argc, char ***argv, string rcfile) errors->text().set_editable (false); errors->text().set_name ("ErrorText"); - string title; - title = namestr; - title += ": Log"; - errors->set_title (title); + Glib::set_application_name(namestr); + + WindowTitle title(Glib::get_application_name()); + title += _("Log"); + errors->set_title (title.get_string()); errors->dismiss_button().set_name ("ErrorLogCloseButton"); errors->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), (Window *) errors)); diff --git a/libs/gtkmm2ext/gtkmm2ext/auto_spin.h b/libs/gtkmm2ext/gtkmm2ext/auto_spin.h index 68da2249a0..b692a7ccdc 100644 --- a/libs/gtkmm2ext/gtkmm2ext/auto_spin.h +++ b/libs/gtkmm2ext/gtkmm2ext/auto_spin.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_auto_spin_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/barcontroller.h b/libs/gtkmm2ext/gtkmm2ext/barcontroller.h index e5b8e31b58..c91f4c8a06 100644 --- a/libs/gtkmm2ext/gtkmm2ext/barcontroller.h +++ b/libs/gtkmm2ext/gtkmm2ext/barcontroller.h @@ -14,7 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_bar_controller_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/bindable_button.h b/libs/gtkmm2ext/gtkmm2ext/bindable_button.h index 1936125405..2ddd3628fc 100644 --- a/libs/gtkmm2ext/gtkmm2ext/bindable_button.h +++ b/libs/gtkmm2ext/gtkmm2ext/bindable_button.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __bindable_button_h__ @@ -30,15 +29,46 @@ namespace PBD { class Controllable; } -class BindableToggleButton : public Gtk::ToggleButton +class BindableToggleButton : public Gtkmm2ext::StatefulToggleButton { public: BindableToggleButton (PBD::Controllable& c) : binding_proxy (c) {} - explicit BindableToggleButton (PBD::Controllable& c, const std::string &label) : Gtk::ToggleButton (label), binding_proxy (c) {} + + explicit BindableToggleButton (PBD::Controllable& c, const std::string &label) + : Gtkmm2ext::StatefulToggleButton (label), binding_proxy (c) {} + virtual ~BindableToggleButton() {} bool on_button_press_event (GdkEventButton *ev) { - return binding_proxy.button_press_handler (ev); + if (!binding_proxy.button_press_handler (ev)) { + StatefulToggleButton::on_button_press_event (ev); + return false; + } else { + return true; + } + } + + private: + BindingProxy binding_proxy; +}; + +class BindableButton : public Gtkmm2ext::StatefulButton +{ + public: + BindableButton (PBD::Controllable& c) : binding_proxy (c) {} + + explicit BindableButton (PBD::Controllable& c, const std::string &label) + : Gtkmm2ext::StatefulButton (label), binding_proxy (c) {} + + ~BindableButton() {} + + bool on_button_press_event (GdkEventButton *ev) { + if (!binding_proxy.button_press_handler (ev)) { + StatefulButton::on_button_press_event (ev); + return false; + } else { + return true; + } } private: diff --git a/libs/gtkmm2ext/gtkmm2ext/click_box.h b/libs/gtkmm2ext/gtkmm2ext/click_box.h index e4aee36ebe..8f9fb55717 100644 --- a/libs/gtkmm2ext/gtkmm2ext/click_box.h +++ b/libs/gtkmm2ext/gtkmm2ext/click_box.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_click_box_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/doi.h b/libs/gtkmm2ext/gtkmm2ext/doi.h index 16a9a6549c..6ad1f7dd94 100644 --- a/libs/gtkmm2ext/gtkmm2ext/doi.h +++ b/libs/gtkmm2ext/gtkmm2ext/doi.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __ardour_gtk_doi_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h index d624f29afb..48bed3d150 100644 --- a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h +++ b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_fastmeter_h__ @@ -36,7 +35,7 @@ class FastMeter : public Gtk::DrawingArea { FastMeter (long hold_cnt, unsigned long width, Orientation); virtual ~FastMeter (); - void set (float level, float user_level=0.0f); + void set (float level); void clear (); float get_level() { return current_level; } @@ -70,13 +69,13 @@ class FastMeter : public Gtk::DrawingArea { bool vertical_expose (GdkEventExpose*); bool horizontal_expose (GdkEventExpose*); - static Glib::RefPtr<Gdk::Pixbuf> request_vertical_meter(int); + static Glib::RefPtr<Gdk::Pixbuf> request_vertical_meter(int w, int h); static Glib::RefPtr<Gdk::Pixbuf> *v_pixbuf_cache; static int min_v_pixbuf_size; static int max_v_pixbuf_size; - static Glib::RefPtr<Gdk::Pixbuf> request_horizontal_meter(int); + static Glib::RefPtr<Gdk::Pixbuf> request_horizontal_meter(int w, int h); static Glib::RefPtr<Gdk::Pixbuf> *h_pixbuf_cache; static int min_h_pixbuf_size; diff --git a/libs/gtkmm2ext/gtkmm2ext/grouped_buttons.h b/libs/gtkmm2ext/gtkmm2ext/grouped_buttons.h index 2bb067fcd0..99d9f8ffc4 100644 --- a/libs/gtkmm2ext/gtkmm2ext/grouped_buttons.h +++ b/libs/gtkmm2ext/gtkmm2ext/grouped_buttons.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_grouped_buttons_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h b/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h index a692e64c9c..b6a52c6c0c 100644 --- a/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h +++ b/libs/gtkmm2ext/gtkmm2ext/gtk_ui.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __pbd_gtk_ui_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/gtkutils.h b/libs/gtkmm2ext/gtkmm2ext/gtkutils.h index 1841040560..832423f31d 100644 --- a/libs/gtkmm2ext/gtkmm2ext/gtkutils.h +++ b/libs/gtkmm2ext/gtkmm2ext/gtkutils.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkutils_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/hexentry.h b/libs/gtkmm2ext/gtkmm2ext/hexentry.h index 785d6eef36..410f54274e 100644 --- a/libs/gtkmm2ext/gtkmm2ext/hexentry.h +++ b/libs/gtkmm2ext/gtkmm2ext/hexentry.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_hexentry_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/pixfader.h b/libs/gtkmm2ext/gtkmm2ext/pixfader.h index bb4176240a..d974f5d5bc 100644 --- a/libs/gtkmm2ext/gtkmm2ext/pixfader.h +++ b/libs/gtkmm2ext/gtkmm2ext/pixfader.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: fastmeter.h 570 2006-06-07 21:21:21Z sampo $ */ #ifndef __gtkmm2ext_pixfader_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/popup.h b/libs/gtkmm2ext/gtkmm2ext/popup.h index 89f14b4c50..1db357341d 100644 --- a/libs/gtkmm2ext/gtkmm2ext/popup.h +++ b/libs/gtkmm2ext/gtkmm2ext/popup.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __qui_popup_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/prompter.h b/libs/gtkmm2ext/gtkmm2ext/prompter.h index 9847e73661..10870ee752 100644 --- a/libs/gtkmm2ext/gtkmm2ext/prompter.h +++ b/libs/gtkmm2ext/gtkmm2ext/prompter.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_prompter_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/selector.h b/libs/gtkmm2ext/gtkmm2ext/selector.h index 9eb07cfbfe..841742db03 100644 --- a/libs/gtkmm2ext/gtkmm2ext/selector.h +++ b/libs/gtkmm2ext/gtkmm2ext/selector.h @@ -14,7 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkselector_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/slider_controller.h b/libs/gtkmm2ext/gtkmm2ext/slider_controller.h index c137dbabf5..74ff36816b 100644 --- a/libs/gtkmm2ext/gtkmm2ext/slider_controller.h +++ b/libs/gtkmm2ext/gtkmm2ext/slider_controller.h @@ -14,7 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_slider_controller_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h index f684903836..c86402e54e 100644 --- a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h +++ b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __pbd_gtkmm_abutton_h__ @@ -27,28 +26,56 @@ namespace Gtkmm2ext { -class StatefulButton : public Gtk::Button +class StateButton { public: - StatefulButton(); - explicit StatefulButton(const std::string &label); - virtual ~StatefulButton() {} + StateButton(); + virtual ~StateButton() {} + + void set_visual_state (int); + int get_visual_state () { return visual_state; } + void set_self_managed (bool yn) { _self_managed = yn; } - void set_colors (const std::vector<Gdk::Color>& colors); - void set_state (int); - int get_state () { return current_state; } - void set_active (bool yn) { - set_state (yn ? 1 : 0); - } - + protected: + int visual_state; + bool _self_managed; + bool _is_realized; + + virtual std::string get_widget_name() const = 0; + virtual void set_widget_name (std::string) = 0; + virtual int get_widget_state() = 0; +}; + + +class StatefulToggleButton : public StateButton, public Gtk::ToggleButton +{ + public: + StatefulToggleButton() {} + explicit StatefulToggleButton(const std::string &label) : Gtk::ToggleButton (label) {} + ~StatefulToggleButton() {} protected: - std::vector<Gdk::Color> colors; - int current_state; - Gdk::Color saved_bg; - bool have_saved_bg; + void on_realize (); + void on_toggled (); + + std::string get_widget_name() const { return get_name(); } + void set_widget_name (std::string name) { set_name (name); get_child()->set_name (name); } + int get_widget_state() { return get_state(); } +}; +class StatefulButton : public StateButton, public Gtk::Button +{ + public: + StatefulButton() {} + explicit StatefulButton(const std::string &label) : Gtk::Button (label) {} + virtual ~StatefulButton() {} + + protected: void on_realize (); + + std::string get_widget_name() const { return get_name(); } + void set_widget_name (std::string name) { set_name (name); get_child()->set_name (name); } + int get_widget_state() { return get_state(); } }; }; diff --git a/libs/gtkmm2ext/gtkmm2ext/tearoff.h b/libs/gtkmm2ext/gtkmm2ext/tearoff.h index fd36cb6416..5e80892b98 100644 --- a/libs/gtkmm2ext/gtkmm2ext/tearoff.h +++ b/libs/gtkmm2ext/gtkmm2ext/tearoff.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_tearoff_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/textviewer.h b/libs/gtkmm2ext/gtkmm2ext/textviewer.h index 280eb4437d..9cc639cd75 100644 --- a/libs/gtkmm2ext/gtkmm2ext/textviewer.h +++ b/libs/gtkmm2ext/gtkmm2ext/textviewer.h @@ -14,7 +14,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __pbd_gtkmm_textviewer_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/utils.h b/libs/gtkmm2ext/gtkmm2ext/utils.h index 97dab523aa..ca1b88abba 100644 --- a/libs/gtkmm2ext/gtkmm2ext/utils.h +++ b/libs/gtkmm2ext/gtkmm2ext/utils.h @@ -15,7 +15,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id$ */ #ifndef __gtkmm2ext_utils_h__ diff --git a/libs/gtkmm2ext/gtkmm2ext/window_title.h b/libs/gtkmm2ext/gtkmm2ext/window_title.h new file mode 100644 index 0000000000..1ce7d64b92 --- /dev/null +++ b/libs/gtkmm2ext/gtkmm2ext/window_title.h @@ -0,0 +1,44 @@ +#ifndef WINDOW_TITLE_INCLUDED +#define WINDOW_TITLE_INCLUDED + +#include <string> + +namespace Gtkmm2ext { + +using std::string; + +/** + * \class The WindowTitle class can be used to maintain the + * consistancy of window titles between windows and dialogs. + * + * Each string element that is added to the window title will + * be separated by a hyphen. + */ +class WindowTitle +{ +public: + + /** + * \param title The first string/element of the window title + * which will may be the application name or the document + * name in a document based application. + */ + WindowTitle(const string& title); + + /** + * Add an string element to the window title. + */ + void operator+= (const string&); + + /// @return The window title string. + const string& get_string () { return m_title;} + +private: + + string m_title; + +}; + +} // Gtkmm2ext + +#endif // WINDOW_TITLE_INCLUDED diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc index 074d086651..ffcafab123 100644 --- a/libs/gtkmm2ext/stateful_button.cc +++ b/libs/gtkmm2ext/stateful_button.cc @@ -1,31 +1,63 @@ #include <string> #include <iostream> -#include "gtkmm2ext/stateful_button.h" + +#include <gtkmm/main.h> + +#include <gtkmm2ext/stateful_button.h> using namespace Gtk; using namespace Glib; using namespace Gtkmm2ext; using namespace std; -StatefulButton::StatefulButton () +StateButton::StateButton () { - current_state = 0; - have_saved_bg = false; + _is_realized = false; + visual_state = 0; } -StatefulButton::StatefulButton (const string& label) - : Button (label) +void +StateButton::set_visual_state (int n) { - current_state = 0; - have_saved_bg = false; + if (!_is_realized) { + /* not yet realized */ + visual_state = n; + return; + } + + if (n == visual_state) { + return; + } + + string name = get_widget_name (); + name = name.substr (0, name.find_last_of ('-')); + + switch (n) { + case 0: + /* relax */ + break; + case 1: + name += "-active"; + break; + case 2: + name += "-alternate"; + break; + } + + set_widget_name (name); + visual_state = n; } +/* ----------------------------------------------------------------- */ + void -StatefulButton::set_colors (const vector<Gdk::Color>& c) +StatefulToggleButton::on_realize () { - colors = c; - current_state++; // to force transition - set_state (current_state - 1); + ToggleButton::on_realize (); + + _is_realized = true; + visual_state++; // to force transition + set_visual_state (visual_state - 1); } void @@ -33,48 +65,19 @@ StatefulButton::on_realize () { Button::on_realize (); - if (!have_saved_bg) { - saved_bg = get_style()->get_bg (STATE_NORMAL); - have_saved_bg = true; - } - - current_state++; // to force transition - set_state (current_state - 1); + _is_realized = true; + visual_state++; // to force transition + set_visual_state (visual_state - 1); } void -StatefulButton::set_state (int n) +StatefulToggleButton::on_toggled () { - if (is_realized()) { - - if (n == current_state) { - return; - } - - if (n == 0) { - - /* back to the default color */ - - if (have_saved_bg) { - modify_bg (STATE_NORMAL, saved_bg); - modify_bg (STATE_ACTIVE, saved_bg); - modify_bg (STATE_SELECTED, saved_bg); - modify_bg (STATE_PRELIGHT, saved_bg); - } - - + if (!_self_managed) { + if (get_active()) { + set_visual_state (1); } else { - - int index = (n-1) % colors.size (); - - modify_bg (STATE_NORMAL, colors[index]); - modify_bg (STATE_ACTIVE, colors[index]); - modify_bg (STATE_SELECTED, colors[index]); - modify_bg (STATE_PRELIGHT, colors[index]); + set_visual_state (0); } - - /* leave insensitive alone */ } - - current_state = n; } diff --git a/libs/gtkmm2ext/window_title.cc b/libs/gtkmm2ext/window_title.cc new file mode 100644 index 0000000000..237be1ff0f --- /dev/null +++ b/libs/gtkmm2ext/window_title.cc @@ -0,0 +1,26 @@ +#include "gtkmm2ext/window_title.h" + +#include "i18n.h" + +namespace { + +// I don't know if this should be translated. +const char* const title_separator = X_(" - "); + +} // anonymous namespace + +namespace Gtkmm2ext { + +WindowTitle::WindowTitle(const string& title) + : m_title(title) +{ + +} + +void +WindowTitle::operator+= (const string& element) +{ + m_title = m_title + title_separator + element; +} + +} |