1 |
/* -*- c++ -*- |
/* -*- c++ -*- |
2 |
* Copyright (C) 2006-2011 Andreas Persson |
* Copyright (C) 2006-2013 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 |
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/table.h> |
37 |
#include <gtkmm/textview.h> |
#include <gtkmm/textview.h> |
38 |
|
|
39 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2 |
#if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 12) || GTKMM_MAJOR_VERSION < 2 |
304 |
}; |
}; |
305 |
|
|
306 |
|
|
307 |
|
/** |
308 |
|
* Container widget for LabelWidgets. |
309 |
|
*/ |
310 |
|
class Table : public Gtk::Table |
311 |
|
{ |
312 |
|
public: |
313 |
|
Table(int x, int y); |
314 |
|
void add(BoolEntry& boolentry); |
315 |
|
void add(BoolEntryPlus6& boolentry); |
316 |
|
void add(LabelWidget& labelwidget); |
317 |
|
private: |
318 |
|
int rowno; |
319 |
|
}; |
320 |
|
|
321 |
|
|
322 |
|
/** |
323 |
|
* Base class for editor components that use LabelWidgets to edit |
324 |
|
* member variables of the same class. By connecting the widgets to |
325 |
|
* members of the model class, the model is automatically kept |
326 |
|
* updated. |
327 |
|
*/ |
328 |
|
template<class M> |
329 |
|
class PropEditor { |
330 |
|
public: |
331 |
|
sigc::signal<void>& signal_changed() { |
332 |
|
return sig_changed; |
333 |
|
} |
334 |
|
protected: |
335 |
|
M* m; |
336 |
|
int update_model; // to prevent infinite update loops |
337 |
|
PropEditor() : update_model(0) { } |
338 |
|
sigc::signal<void> sig_changed; |
339 |
|
|
340 |
|
template<class C, typename T> |
341 |
|
void connect(C& widget, T M::* member) { |
342 |
|
// gcc 4.1.2 needs this temporary variable to resolve the |
343 |
|
// address |
344 |
|
void (PropEditor::*f)(const C* w, T M::* member) = |
345 |
|
&PropEditor::set_member; |
346 |
|
widget.signal_value_changed().connect( |
347 |
|
sigc::bind(sigc::mem_fun(*this, f), &widget, member)); |
348 |
|
|
349 |
|
void (PropEditor::*g)(C* w, T M::* member) = |
350 |
|
&PropEditor::get_member; |
351 |
|
sig.connect( |
352 |
|
sigc::bind(sigc::mem_fun(*this, g), &widget, member)); |
353 |
|
} |
354 |
|
|
355 |
|
template<class C, class S, typename T> |
356 |
|
void connect(C& widget, void (S::*setter)(T)) { |
357 |
|
void (PropEditor::*f)(const C* w, void (S::*setter)(T)) = |
358 |
|
&PropEditor<M>::call_setter; |
359 |
|
widget.signal_value_changed().connect( |
360 |
|
sigc::bind(sigc::mem_fun(*this, f), &widget, setter)); |
361 |
|
} |
362 |
|
|
363 |
|
void connect(NoteEntry& eKeyRangeLow, NoteEntry& eKeyRangeHigh, |
364 |
|
gig::range_t M::* range) { |
365 |
|
eKeyRangeLow.signal_value_changed().connect( |
366 |
|
sigc::bind( |
367 |
|
sigc::mem_fun(*this, &PropEditor::key_range_low_changed), |
368 |
|
&eKeyRangeLow, &eKeyRangeHigh, range)); |
369 |
|
eKeyRangeHigh.signal_value_changed().connect( |
370 |
|
sigc::bind( |
371 |
|
sigc::mem_fun(*this, &PropEditor::key_range_high_changed), |
372 |
|
&eKeyRangeLow, &eKeyRangeHigh, range)); |
373 |
|
sig.connect( |
374 |
|
sigc::bind(sigc::mem_fun(*this, &PropEditor::get_key_range), |
375 |
|
&eKeyRangeLow, &eKeyRangeHigh, range)); |
376 |
|
} |
377 |
|
|
378 |
|
void update(M* m) { |
379 |
|
update_model++; |
380 |
|
this->m = m; |
381 |
|
sig.emit(); |
382 |
|
update_model--; |
383 |
|
} |
384 |
|
|
385 |
|
private: |
386 |
|
sigc::signal<void> sig; |
387 |
|
|
388 |
|
void key_range_low_changed(NoteEntry* eKeyRangeLow, |
389 |
|
NoteEntry* eKeyRangeHigh, |
390 |
|
gig::range_t M::* range) { |
391 |
|
if (update_model == 0) { |
392 |
|
uint8_t value = eKeyRangeLow->get_value(); |
393 |
|
(m->*range).low = value; |
394 |
|
if (value > (m->*range).high) { |
395 |
|
eKeyRangeHigh->set_value(value); |
396 |
|
} |
397 |
|
sig_changed(); |
398 |
|
} |
399 |
|
} |
400 |
|
|
401 |
|
void key_range_high_changed(NoteEntry* eKeyRangeLow, |
402 |
|
NoteEntry* eKeyRangeHigh, |
403 |
|
gig::range_t M::* range) { |
404 |
|
if (update_model == 0) { |
405 |
|
uint8_t value = eKeyRangeHigh->get_value(); |
406 |
|
(m->*range).high = value; |
407 |
|
if (value < (m->*range).low) { |
408 |
|
eKeyRangeLow->set_value(value); |
409 |
|
} |
410 |
|
sig_changed(); |
411 |
|
} |
412 |
|
} |
413 |
|
|
414 |
|
template<class C, typename T> |
415 |
|
void set_member(const C* w, T M::* member) { |
416 |
|
if (update_model == 0) { |
417 |
|
m->*member = w->get_value(); |
418 |
|
sig_changed(); |
419 |
|
} |
420 |
|
} |
421 |
|
|
422 |
|
template<class C, typename T> |
423 |
|
void get_member(C* w, T M::* member) { |
424 |
|
w->set_value(m->*member); |
425 |
|
} |
426 |
|
|
427 |
|
void get_key_range(NoteEntry* eKeyRangeLow, |
428 |
|
NoteEntry* eKeyRangeHigh, |
429 |
|
gig::range_t M::* range) { |
430 |
|
eKeyRangeLow->set_value((m->*range).low); |
431 |
|
eKeyRangeHigh->set_value((m->*range).high); |
432 |
|
} |
433 |
|
|
434 |
|
template<class C, class S, typename T> |
435 |
|
void call_setter(const C* w, void (S::*setter)(T)) { |
436 |
|
if (update_model == 0) { |
437 |
|
(static_cast<S*>(this)->*setter)(w->get_value()); |
438 |
|
sig_changed(); |
439 |
|
} |
440 |
|
} |
441 |
|
}; |
442 |
|
|
443 |
#endif |
#endif |