1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006, 2007 Andreas Persson |
* Copyright (C) 2006-2011 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
22 |
|
|
23 |
#include <gig.h> |
#include <gig.h> |
24 |
|
|
25 |
#include <math.h> |
#include <cmath> |
26 |
|
|
27 |
#include <gtkmm/adjustment.h> |
#include <gtkmm/adjustment.h> |
28 |
#include <gtkmm/alignment.h> |
#include <gtkmm/alignment.h> |
29 |
#include <gtkmm/box.h> |
#include <gtkmm/box.h> |
30 |
|
#include <gtkmm/checkbutton.h> |
31 |
#include <gtkmm/comboboxtext.h> |
#include <gtkmm/comboboxtext.h> |
32 |
|
#include <gtkmm/frame.h> |
33 |
#include <gtkmm/label.h> |
#include <gtkmm/label.h> |
34 |
#include <gtkmm/scale.h> |
#include <gtkmm/scale.h> |
35 |
#include <gtkmm/spinbutton.h> |
#include <gtkmm/spinbutton.h> |
36 |
|
#include <gtkmm/textview.h> |
37 |
|
|
38 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2 |
39 |
|
#define OLD_TOOLTIPS |
40 |
#include <gtkmm/tooltips.h> |
#include <gtkmm/tooltips.h> |
41 |
|
#endif |
42 |
|
|
43 |
class LabelWidget { |
class LabelWidget { |
44 |
public: |
public: |
51 |
return sig_changed; |
return sig_changed; |
52 |
} |
} |
53 |
protected: |
protected: |
54 |
|
#ifdef OLD_TOOLTIPS |
55 |
Gtk::Tooltips tooltips; |
Gtk::Tooltips tooltips; |
56 |
|
#endif |
57 |
sigc::signal<void> sig_changed; |
sigc::signal<void> sig_changed; |
58 |
}; |
}; |
59 |
|
|
60 |
class NumEntry : public LabelWidget { |
class NumEntry : public LabelWidget { |
61 |
protected: |
protected: |
62 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
63 |
Gtk::Adjustment adjust; |
Gtk::Adjustment adjust; |
64 |
|
#else |
65 |
|
Glib::RefPtr<Gtk::Adjustment> adjust; |
66 |
|
#endif |
67 |
Gtk::HScale scale; |
Gtk::HScale scale; |
68 |
Gtk::SpinButton spinbutton; |
Gtk::SpinButton spinbutton; |
69 |
Gtk::HBox box; |
Gtk::HBox box; |
75 |
NumEntry(const char* labelText, double lower = 0, double upper = 127, |
NumEntry(const char* labelText, double lower = 0, double upper = 127, |
76 |
int decimals = 0); |
int decimals = 0); |
77 |
void set_tip(const Glib::ustring& tip_text) { |
void set_tip(const Glib::ustring& tip_text) { |
78 |
|
#ifdef OLD_TOOLTIPS |
79 |
tooltips.set_tip(spinbutton, tip_text); |
tooltips.set_tip(spinbutton, tip_text); |
80 |
|
#else |
81 |
|
spinbutton.set_tooltip_text(tip_text); |
82 |
|
#endif |
83 |
} |
} |
84 |
void set_upper(double upper) { |
void set_upper(double upper) { |
85 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
86 |
adjust.set_upper(upper); |
adjust.set_upper(upper); |
87 |
|
#else |
88 |
|
adjust->set_upper(upper); |
89 |
|
#endif |
90 |
} |
} |
91 |
}; |
}; |
92 |
|
|
139 |
template<typename T> |
template<typename T> |
140 |
void NumEntryTemp<T>::set_value(T value) |
void NumEntryTemp<T>::set_value(T value) |
141 |
{ |
{ |
142 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
143 |
if (value > adjust.get_upper()) value = T(adjust.get_upper()); |
if (value > adjust.get_upper()) value = T(adjust.get_upper()); |
144 |
|
#else |
145 |
|
if (value > adjust->get_upper()) value = T(adjust->get_upper()); |
146 |
|
#endif |
147 |
if (this->value != value) { |
if (this->value != value) { |
148 |
this->value = value; |
this->value = value; |
149 |
const double f = pow(10, spinbutton.get_digits()); |
const double f = pow(10, spinbutton.get_digits()); |
189 |
void set_choices(const char** texts, const T* values); |
void set_choices(const char** texts, const T* values); |
190 |
|
|
191 |
void set_tip(const Glib::ustring& tip_text) { |
void set_tip(const Glib::ustring& tip_text) { |
192 |
tooltips.set_tip(combobox, tip_text); //FIXME: don't Gtk::ComboBoxes support tooltips ??? |
#ifdef OLD_TOOLTIPS |
193 |
|
tooltips.set_tip(combobox, tip_text); |
194 |
|
#else |
195 |
|
combobox.set_tooltip_text(tip_text); |
196 |
|
#endif |
197 |
} |
} |
198 |
}; |
}; |
199 |
|
|
200 |
template<typename T> |
template<typename T> |
201 |
ChoiceEntry<T>::ChoiceEntry(const char* labelText) : |
ChoiceEntry<T>::ChoiceEntry(const char* labelText) : |
202 |
align(0, 0, 0, 0), |
LabelWidget(labelText, align), |
203 |
LabelWidget(labelText, align) |
align(0, 0, 0, 0) |
204 |
{ |
{ |
205 |
combobox.signal_changed().connect(sig_changed.make_slot()); |
combobox.signal_changed().connect(sig_changed.make_slot()); |
206 |
align.add(combobox); |
align.add(combobox); |
210 |
void ChoiceEntry<T>::set_choices(const char** texts, const T* values) |
void ChoiceEntry<T>::set_choices(const char** texts, const T* values) |
211 |
{ |
{ |
212 |
for (int i = 0 ; texts[i] ; i++) { |
for (int i = 0 ; texts[i] ; i++) { |
213 |
|
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2 |
214 |
combobox.append_text(texts[i]); |
combobox.append_text(texts[i]); |
215 |
|
#else |
216 |
|
combobox.append(texts[i]); |
217 |
|
#endif |
218 |
} |
} |
219 |
this->values = values; |
this->values = values; |
220 |
} |
} |
260 |
void set_value(bool value) { checkbutton.set_active(value); } |
void set_value(bool value) { checkbutton.set_active(value); } |
261 |
|
|
262 |
void set_tip(const Glib::ustring& tip_text) { |
void set_tip(const Glib::ustring& tip_text) { |
263 |
|
#ifdef OLD_TOOLTIPS |
264 |
tooltips.set_tip(checkbutton, tip_text); |
tooltips.set_tip(checkbutton, tip_text); |
265 |
|
#else |
266 |
|
checkbutton.set_tooltip_text(tip_text); |
267 |
|
#endif |
268 |
} |
} |
269 |
}; |
}; |
270 |
|
|
284 |
class StringEntry : public LabelWidget { |
class StringEntry : public LabelWidget { |
285 |
private: |
private: |
286 |
Gtk::Entry entry; |
Gtk::Entry entry; |
|
gig::String* ptr; |
|
|
void value_changed(); |
|
287 |
public: |
public: |
288 |
StringEntry(const char* labelText); |
StringEntry(const char* labelText); |
289 |
void set_ptr(gig::String* ptr); |
gig::String get_value() const { return entry.get_text(); } |
290 |
|
void set_value(gig::String value) { entry.set_text(value); } |
291 |
|
void set_width_chars(int n_chars) { entry.set_width_chars(n_chars); } |
292 |
|
}; |
293 |
|
|
294 |
|
class StringEntryMultiLine : public LabelWidget { |
295 |
|
private: |
296 |
|
Gtk::TextView text_view; |
297 |
|
Glib::RefPtr<Gtk::TextBuffer> text_buffer; |
298 |
|
Gtk::Frame frame; |
299 |
|
public: |
300 |
|
StringEntryMultiLine(const char* labelText); |
301 |
|
gig::String get_value() const; |
302 |
|
void set_value(gig::String value); |
303 |
}; |
}; |
304 |
|
|
305 |
|
|