2 Copyright (C) 2001-2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <pbd/whitespace.h>
23 #include <ardour/audio_library.h>
24 #include <ardour/session.h>
25 #include <ardour/audioengine.h>
26 #include <ardour/configuration.h>
27 #include <ardour/auditioner.h>
28 #include <ardour/destructive_filesource.h>
29 #include <ardour/crossfade.h>
30 #include <midi++/manager.h>
31 #include <gtkmm2ext/stop_signal.h>
32 #include <gtkmm2ext/utils.h>
34 #include "public_editor.h"
36 #include "ardour_ui.h"
37 #include "io_selector.h"
38 #include "gain_meter.h"
42 #include "option_editor.h"
46 using namespace ARDOUR;
49 using namespace Editing;
50 using namespace Gtkmm2ext;
53 static vector<string> positional_sync_strings;
55 OptionEditor::OptionEditor (ARDOUR_UI& uip, PublicEditor& ed, Mixer_UI& mixui)
56 : Dialog ("option editor"),
67 short_xfade_adjustment (0, 1.0, 500.0, 5.0, 100.0),
68 short_xfade_slider (short_xfade_adjustment),
69 destructo_xfade_adjustment (1.0, 1.0, 500.0, 1.0, 100.0),
70 destructo_xfade_slider (destructo_xfade_adjustment),
74 smpte_offset_clock (X_("SMPTEOffsetClock"), true, true),
75 smpte_offset_negative_button (_("SMPTE offset is negative")),
82 click_browse_button (_("Browse")),
83 click_emphasis_browse_button (_("Browse")),
87 keyboard_mouse_table (3, 4),
88 delete_button_adjustment (3, 1, 5),
89 delete_button_spin (delete_button_adjustment),
90 edit_button_adjustment (3, 1, 5),
91 edit_button_spin (edit_button_adjustment)
94 using namespace Notebook_Helpers;
96 click_io_selector = 0;
97 auditioner_io_selector = 0;
100 set_default_size (300, 300);
101 set_title (_("ardour: options editor"));
102 set_wmclass (_("ardour_option_editor"), "Ardour");
104 set_name ("OptionsWindow");
105 add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
107 VBox *vbox = get_vbox();
108 set_border_width (3);
110 vbox->set_spacing (4);
111 vbox->pack_start(notebook);
113 signal_delete_event().connect (mem_fun(*this, &OptionEditor::wm_close));
115 notebook.set_show_tabs (true);
116 notebook.set_show_border (true);
117 notebook.set_name ("OptionsNotebook");
119 setup_sync_options();
120 setup_path_options();
121 setup_fade_options ();
122 setup_keyboard_options ();
123 setup_auditioner_editor ();
125 notebook.pages().push_back (TabElem (sync_packer, _("Sync")));
126 notebook.pages().push_back (TabElem (path_table, _("Paths/Files")));
127 notebook.pages().push_back (TabElem (keyboard_mouse_table, _("Kbd/Mouse")));
128 notebook.pages().push_back (TabElem (click_packer, _("Click")));
129 notebook.pages().push_back (TabElem (audition_packer, _("Audition")));
130 notebook.pages().push_back (TabElem (fade_packer, _("Layers & Fades")));
132 if (!MIDI::Manager::instance()->get_midi_ports().empty()) {
133 setup_midi_options ();
134 notebook.pages().push_back (TabElem (midi_packer, _("MIDI")));
142 OptionEditor::set_session (Session *s)
144 clear_click_editor ();
145 clear_auditioner_editor ();
147 click_path_entry.set_text ("");
148 click_emphasis_path_entry.set_text ("");
149 session_raid_entry.set_text ("");
151 click_path_entry.set_sensitive (false);
152 click_emphasis_path_entry.set_sensitive (false);
153 session_raid_entry.set_sensitive (false);
155 short_xfade_slider.set_sensitive (false);
156 smpte_offset_negative_button.set_sensitive (false);
158 smpte_offset_clock.set_session (s);
160 if ((session = s) == 0) {
164 click_path_entry.set_sensitive (true);
165 click_emphasis_path_entry.set_sensitive (true);
166 session_raid_entry.set_sensitive (true);
167 short_xfade_slider.set_sensitive (true);
168 smpte_offset_negative_button.set_sensitive (true);
170 smpte_offset_clock.set_session (s);
171 smpte_offset_clock.set (s->smpte_offset (), true);
173 smpte_offset_negative_button.set_active (session->smpte_offset_negative());
175 /* set up port assignments */
177 std::map<MIDI::Port*,vector<RadioButton*> >::iterator res;
179 if (session->mtc_port()) {
180 if ((res = port_toggle_buttons.find (session->mtc_port())) != port_toggle_buttons.end()) {
181 (*res).second[MtcIndex]->set_active (true);
185 if (session->mmc_port ()) {
186 if ((res = port_toggle_buttons.find (session->mmc_port())) != port_toggle_buttons.end()) {
187 (*res).second[MmcIndex]->set_active (true);
191 if (session->midi_port()) {
192 if ((res = port_toggle_buttons.find (session->midi_port())) != port_toggle_buttons.end()) {
193 (*res).second[MidiIndex]->set_active (true);
197 setup_click_editor ();
198 connect_audition_editor ();
200 short_xfade_adjustment.set_value ((Crossfade::short_xfade_length() / (float) session->frame_rate()) * 1000.0);
202 add_session_paths ();
205 OptionEditor::~OptionEditor ()
210 OptionEditor::setup_path_options()
214 path_table.set_homogeneous (false);
215 path_table.set_border_width (12);
216 path_table.set_row_spacings (5);
218 session_raid_entry.set_name ("OptionsEntry");
220 session_raid_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::raid_path_changed));
222 label = manage(new Label(_("session RAID path")));
223 label->set_name ("OptionsLabel");
224 path_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
225 path_table.attach (session_raid_entry, 1, 3, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
227 label = manage(new Label(_("Soundfile Search Paths")));
228 label->set_name("OptionsLabel");
229 path_table.attach(*label, 0, 1, 2, 3, FILL|EXPAND, FILL);
230 path_table.attach(sfdb_path_view, 1, 3, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
232 sfdb_path_view.set_paths(Library->get_paths());
233 sfdb_path_view.PathsUpdated.connect (mem_fun(*this, &OptionEditor::sfdb_paths_changed));
235 path_table.show_all();
239 OptionEditor::sfdb_paths_changed ()
241 Library->set_paths (sfdb_path_view.get_paths());
245 OptionEditor::add_session_paths ()
247 click_path_entry.set_sensitive (true);
248 click_emphasis_path_entry.set_sensitive (true);
249 session_raid_entry.set_sensitive (true);
251 if (Config->get_click_sound().empty()) {
252 click_path_entry.set_text (_("internal"));
254 click_path_entry.set_text (Config->get_click_sound());
257 if (Config->get_click_emphasis_sound().empty()) {
258 click_emphasis_path_entry.set_text (_("internal"));
260 click_emphasis_path_entry.set_text (Config->get_click_emphasis_sound());
263 session_raid_entry.set_text(session->raid_path());
267 OptionEditor::setup_fade_options ()
271 Label* label = manage (new Label (_("Short crossfade length (msecs)")));
272 label->set_name ("OptionsLabel");
274 hbox = manage (new HBox);
275 hbox->set_border_width (5);
276 hbox->set_spacing (10);
277 hbox->pack_start (*label, false, false);
278 hbox->pack_start (short_xfade_slider, true, true);
279 fade_packer.pack_start (*hbox, false, false);
281 short_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::short_xfade_adjustment_changed));
283 label = manage (new Label (_("Destructive crossfade length (msecs)")));
284 label->set_name ("OptionsLabel");
286 hbox = manage (new HBox);
287 hbox->set_border_width (5);
288 hbox->set_spacing (10);
289 hbox->pack_start (*label, false, false);
290 hbox->pack_start (destructo_xfade_slider, true, true);
291 fade_packer.pack_start (*hbox, false, false);
293 destructo_xfade_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::destructo_xfade_adjustment_changed));
295 short_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
296 destructo_xfade_slider.set_update_policy (UPDATE_DISCONTINUOUS);
298 destructo_xfade_adjustment.set_value (Config->get_destructive_xfade_msecs());
300 fade_packer.show_all ();
304 OptionEditor::short_xfade_adjustment_changed ()
307 float val = short_xfade_adjustment.get_value();
309 /* val is in msecs */
311 Crossfade::set_short_xfade_length ((nframes_t) floor (session->frame_rate() * (val / 1000.0)));
316 OptionEditor::destructo_xfade_adjustment_changed ()
318 float val = destructo_xfade_adjustment.get_value();
320 /* val is in msecs */
323 Config->set_destructive_xfade_msecs ((uint32_t) floor (val));
325 cerr << "set destructo fade to " << Config->get_destructive_xfade_msecs () << endl;
328 SndFileSource::setup_standard_crossfades (session->frame_rate());
333 OptionEditor::setup_sync_options ()
338 smpte_offset_clock.set_mode (AudioClock::SMPTE);
339 smpte_offset_clock.ValueChanged.connect (mem_fun(*this, &OptionEditor::smpte_offset_chosen));
341 smpte_offset_negative_button.set_name ("OptionEditorToggleButton");
343 smpte_offset_negative_button.unset_flags (Gtk::CAN_FOCUS);
345 Label *smpte_offset_label = manage (new Label (_("SMPTE Offset")));
346 smpte_offset_label->set_name("OptionsLabel");
348 hbox = manage (new HBox);
349 hbox->set_border_width (5);
350 hbox->set_spacing (10);
351 hbox->pack_start (*smpte_offset_label, false, false);
352 hbox->pack_start (smpte_offset_clock, false, false);
353 hbox->pack_start (smpte_offset_negative_button, false, false);
355 sync_packer.pack_start (*hbox, false, false);
357 smpte_offset_negative_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::smpte_offset_negative_clicked));
361 OptionEditor::smpte_offset_negative_clicked ()
364 session->set_smpte_offset_negative (smpte_offset_negative_button.get_active());
369 OptionEditor::smpte_offset_chosen()
372 nframes_t frames = smpte_offset_clock.current_duration();
373 session->set_smpte_offset (frames);
379 OptionEditor::setup_midi_options ()
382 MIDI::Manager::PortMap::const_iterator i;
383 const MIDI::Manager::PortMap& ports = MIDI::Manager::instance()->get_midi_ports();
388 Gtk::Table* table = manage (new Table (ports.size() + 4, 9));
390 table->set_row_spacings (6);
391 table->set_col_spacings (10);
393 table->attach (*(manage (new Label (X_("Port")))), 0, 1, 0, 1);
394 table->attach (*(manage (new Label (X_("Offline")))), 1, 2, 0, 1);
395 table->attach (*(manage (new Label (X_("Trace\nInput")))), 2, 3, 0, 1);
396 table->attach (*(manage (new Label (X_("Trace\nOutput")))), 3, 4, 0, 1);
397 table->attach (*(manage (new Label (X_("MTC")))), 4, 5, 0, 1);
398 table->attach (*(manage (new Label (X_("MMC")))), 6, 7, 0, 1);
399 table->attach (*(manage (new Label (X_("MIDI Parameter\nControl")))), 8, 9, 0, 1);
401 table->attach (*(manage (new HSeparator())), 0, 9, 1, 2);
402 table->attach (*(manage (new VSeparator())), 5, 6, 0, 8);
403 table->attach (*(manage (new VSeparator())), 7, 8, 0, 8);
405 for (n = 0, i = ports.begin(); i != ports.end(); ++n, ++i) {
407 pair<MIDI::Port*,vector<RadioButton*> > newpair;
409 newpair.first = i->second;
411 table->attach (*(manage (new Label (i->first))), 0, 1, n+2, n+3,FILL|EXPAND, FILL );
412 tb = manage (new ToggleButton (_("online")));
413 tb->set_name ("OptionEditorToggleButton");
415 /* remember, we have to handle the i18n case where the relative
416 lengths of the strings in language N is different than in english.
419 if (strlen (_("offline")) > strlen (_("online"))) {
420 set_size_request_to_display_given_text (*tb, _("offline"), 15, 12);
422 set_size_request_to_display_given_text (*tb, _("online"), 15, 12);
425 tb->set_active (!(*i).second->input()->offline());
426 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_online_toggled), (*i).second, tb));
427 (*i).second->input()->OfflineStatusChanged.connect (bind (mem_fun(*this, &OptionEditor::map_port_online), (*i).second, tb));
428 table->attach (*tb, 1, 2, n+2, n+3, FILL|EXPAND, FILL);
430 tb = manage (new ToggleButton ());
431 tb->set_name ("OptionEditorToggleButton");
432 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_trace_in_toggled), (*i).second, tb));
433 tb->set_size_request (10, 10);
434 table->attach (*tb, 2, 3, n+2, n+3, FILL|EXPAND, FILL);
436 tb = manage (new ToggleButton ());
437 tb->set_name ("OptionEditorToggleButton");
438 tb->signal_button_press_event().connect (bind (mem_fun(*this, &OptionEditor::port_trace_out_toggled), (*i).second, tb));
439 tb->set_size_request (10, 10);
440 table->attach (*tb, 3, 4, n+2, n+3, FILL|EXPAND, FILL);
442 rb = manage (new RadioButton ());
443 newpair.second.push_back (rb);
444 rb->set_name ("OptionEditorToggleButton");
446 mtc_button_group = rb->get_group();
448 rb->set_group (mtc_button_group);
451 table->attach (*rb, 4, 5, n+2, n+3, FILL|EXPAND, FILL);
452 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mtc_port_chosen), (*i).second, rb));
454 if (Config->get_mtc_port_name() == i->first) {
455 rb->set_active (true);
458 rb = manage (new RadioButton ());
459 newpair.second.push_back (rb);
460 rb->set_name ("OptionEditorToggleButton");
462 mmc_button_group = rb->get_group();
464 rb->set_group (mmc_button_group);
466 table->attach (*rb, 6, 7, n+2, n+3, FILL|EXPAND, FILL);
467 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::mmc_port_chosen), (*i).second, rb));
469 if (Config->get_mmc_port_name() == i->first) {
470 rb->set_active (true);
473 rb = manage (new RadioButton ());
474 newpair.second.push_back (rb);
475 rb->set_name ("OptionEditorToggleButton");
477 midi_button_group = rb->get_group();
479 rb->set_group (midi_button_group);
481 table->attach (*rb, 8, 9, n+2, n+3, FILL|EXPAND, FILL);
482 rb->signal_toggled().connect (bind (mem_fun(*this, &OptionEditor::midi_port_chosen), (*i).second, rb));
484 if (Config->get_midi_port_name() == i->first) {
485 rb->set_active (true);
488 port_toggle_buttons.insert (newpair);
493 hbox = manage (new HBox);
494 hbox->set_border_width (6);
495 hbox->pack_start (*table, true, false);
496 midi_packer.pack_start (*hbox, false, false);
500 OptionEditor::mtc_port_chosen (MIDI::Port *port, Gtk::RadioButton* rb)
503 if (rb->get_active()) {
504 cerr << "Activating MTC port " << port->name() << endl;
506 session->set_mtc_port (port->name());
507 Config->set_mtc_port_name (port->name());
509 session->set_mtc_port ("");
511 rb->set_active (true);
517 OptionEditor::mmc_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
520 if (rb->get_active()) {
521 cerr << "Activating MMC port " << port->name() << endl;
523 session->set_mmc_port (port->name());
524 Config->set_mtc_port_name (port->name());
526 session->set_mmc_port ("");
528 rb->set_active (true);
534 OptionEditor::midi_port_chosen (MIDI::Port* port, Gtk::RadioButton* rb)
537 if (rb->get_active()) {
538 cerr << "Activating MIDI port " << port->name() << endl;
540 session->set_midi_port (port->name());
541 Config->set_midi_port_name (port->name());
543 session->set_midi_port ("");
545 rb->set_active (true);
551 OptionEditor::port_online_toggled (GdkEventButton* ev, MIDI::Port* port, ToggleButton* tb)
553 bool wanted = tb->get_active(); /* it hasn't changed at this point */
555 if (wanted != port->input()->offline()) {
556 port->input()->set_offline (wanted);
558 return stop_signal (*tb, "button_press_event");
562 OptionEditor::map_port_online (MIDI::Port* port, ToggleButton* tb)
564 if (port->input()->offline()) {
565 tb->set_label (_("offline"));
566 tb->set_active (false);
568 tb->set_label (_("online"));
569 tb->set_active (true);
574 OptionEditor::port_trace_in_toggled (GdkEventButton* ev, MIDI::Port* port, ToggleButton* tb)
576 /* XXX not very good MVC style here */
578 port->input()->trace (!tb->get_active(), &cerr, string (port->name()) + string (" input: "));
579 tb->set_active (!tb->get_active());
580 return stop_signal (*tb, "button_press_event");
584 OptionEditor::port_trace_out_toggled (GdkEventButton* ev,MIDI::Port* port, ToggleButton* tb)
586 /* XXX not very good MVC style here */
588 port->output()->trace (!tb->get_active(), &cerr, string (port->name()) + string (" output: "));
589 tb->set_active (!tb->get_active());
590 return stop_signal (*tb, "button_press_event");
594 OptionEditor::save ()
596 /* XXX a bit odd that we save the entire session state here */
602 OptionEditor::wm_close (GdkEventAny *ev)
610 OptionEditor::raid_path_changed ()
613 Config->set_raid_path (session_raid_entry.get_text());
618 OptionEditor::click_browse_clicked ()
620 SoundFileChooser sfdb (_("Choose Click"), session);
622 int result = sfdb.run ();
624 if (result == Gtk::RESPONSE_OK) {
625 click_chosen(sfdb.get_filename());
630 OptionEditor::click_chosen (const string & path)
632 click_path_entry.set_text (path);
633 click_sound_changed ();
637 OptionEditor::click_emphasis_browse_clicked ()
639 SoundFileChooser sfdb (_("Choose Click Emphasis"), session);
641 int result = sfdb.run ();
643 if (result == Gtk::RESPONSE_OK) {
644 click_emphasis_chosen (sfdb.get_filename());
649 OptionEditor::click_emphasis_chosen (const string & path)
651 click_emphasis_path_entry.set_text (path);
652 click_emphasis_sound_changed ();
656 OptionEditor::click_sound_changed ()
659 string path = click_path_entry.get_text();
661 if (path == Config->get_click_sound()) {
667 Config->set_click_sound ("");
671 strip_whitespace_edges (path);
673 if (path == _("internal")) {
674 Config->set_click_sound ("");
676 Config->set_click_sound (path);
683 OptionEditor::click_emphasis_sound_changed ()
686 string path = click_emphasis_path_entry.get_text();
688 if (path == Config->get_click_emphasis_sound()) {
694 Config->set_click_emphasis_sound ("");
698 strip_whitespace_edges (path);
700 if (path == _("internal")) {
701 Config->set_click_emphasis_sound ("");
703 Config->set_click_emphasis_sound (path);
710 OptionEditor::clear_click_editor ()
712 if (click_io_selector) {
713 click_packer.remove (*click_io_selector);
714 click_packer.remove (*click_gpm);
715 delete click_io_selector;
717 click_io_selector = 0;
723 OptionEditor::setup_click_editor ()
726 HBox* hpacker = manage (new HBox);
728 click_path_entry.set_sensitive (true);
729 click_emphasis_path_entry.set_sensitive (true);
731 click_path_entry.set_name ("OptionsEntry");
732 click_emphasis_path_entry.set_name ("OptionsEntry");
734 click_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_sound_changed));
735 click_emphasis_path_entry.signal_activate().connect (mem_fun(*this, &OptionEditor::click_emphasis_sound_changed));
737 click_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_sound_changed));
738 click_emphasis_path_entry.signal_focus_out_event().connect (bind (mem_fun(*this, &OptionEditor::focus_out_event_handler), &OptionEditor::click_emphasis_sound_changed));
740 click_browse_button.set_name ("EditorGTKButton");
741 click_emphasis_browse_button.set_name ("EditorGTKButton");
742 click_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_browse_clicked));
743 click_emphasis_browse_button.signal_clicked().connect (mem_fun(*this, &OptionEditor::click_emphasis_browse_clicked));
745 click_packer.set_border_width (12);
746 click_packer.set_spacing (5);
748 click_io_selector = new IOSelector (*session, session->click_io(), false);
749 click_gpm = new GainMeter (session->click_io(), *session);
751 click_table.set_col_spacings (10);
753 label = manage(new Label(_("Click audio file")));
754 label->set_name ("OptionsLabel");
755 click_table.attach (*label, 0, 1, 0, 1, FILL|EXPAND, FILL);
756 click_table.attach (click_path_entry, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
757 click_table.attach (click_browse_button, 2, 3, 0, 1, FILL|EXPAND, FILL);
759 label = manage(new Label(_("Click emphasis audiofile")));
760 label->set_name ("OptionsLabel");
761 click_table.attach (*label, 0, 1, 1, 2, FILL|EXPAND, FILL);
762 click_table.attach (click_emphasis_path_entry, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
763 click_table.attach (click_emphasis_browse_button, 2, 3, 1, 2, FILL|EXPAND, FILL);
765 hpacker->set_spacing (10);
766 hpacker->pack_start (*click_io_selector, false, false);
767 hpacker->pack_start (*click_gpm, false, false);
769 click_packer.pack_start (click_table, false, false);
770 click_packer.pack_start (*hpacker, false, false);
772 click_packer.show_all ();
776 OptionEditor::clear_auditioner_editor ()
778 if (auditioner_io_selector) {
779 audition_hpacker.remove (*auditioner_io_selector);
780 audition_hpacker.remove (*auditioner_gpm);
781 delete auditioner_io_selector;
782 delete auditioner_gpm;
783 auditioner_io_selector = 0;
789 OptionEditor::setup_auditioner_editor ()
791 audition_packer.set_border_width (12);
792 audition_packer.set_spacing (5);
793 audition_hpacker.set_spacing (10);
795 audition_label.set_name ("OptionEditorAuditionerLabel");
796 audition_label.set_text (_("The auditioner is a dedicated mixer strip used\n"
797 "for listening to specific regions outside the context\n"
798 "of the overall mix. It can be connected just like any\n"
799 "other mixer strip."));
801 audition_packer.pack_start (audition_label, false, false, 10);
802 audition_packer.pack_start (audition_hpacker, false, false);
806 OptionEditor::connect_audition_editor ()
808 auditioner_io_selector = new IOSelector (*session, session->the_auditioner(), false);
809 auditioner_gpm = new GainMeter (session->the_auditioner(), *session);
811 audition_hpacker.pack_start (*auditioner_io_selector, false, false);
812 audition_hpacker.pack_start (*auditioner_gpm, false, false);
814 auditioner_io_selector->show_all ();
815 auditioner_gpm->show_all ();
819 OptionEditor::focus_out_event_handler (GdkEventFocus* ev, void (OptionEditor::*pmf)())
825 static const struct {
829 { "Shift", GDK_SHIFT_MASK },
830 { "Control", GDK_CONTROL_MASK },
831 { "Alt (Mod1)", GDK_MOD1_MASK },
832 { "Control-Shift", GDK_CONTROL_MASK|GDK_SHIFT_MASK },
833 { "Control-Alt", GDK_CONTROL_MASK|GDK_MOD1_MASK },
834 { "Shift-Alt", GDK_SHIFT_MASK|GDK_MOD1_MASK },
835 { "Control-Shift-Alt", GDK_CONTROL_MASK|GDK_SHIFT_MASK|GDK_MOD1_MASK },
836 { "Mod2", GDK_MOD2_MASK },
837 { "Mod3", GDK_MOD3_MASK },
838 { "Mod4", GDK_MOD4_MASK },
839 { "Mod5", GDK_MOD5_MASK },
844 OptionEditor::setup_keyboard_options ()
849 keyboard_mouse_table.set_border_width (12);
850 keyboard_mouse_table.set_row_spacings (5);
851 keyboard_mouse_table.set_col_spacings (5);
853 /* internationalize and prepare for use with combos */
855 for (int i = 0; modifiers[i].name; ++i) {
856 dumb.push_back (_(modifiers[i].name));
859 set_popdown_strings (edit_modifier_combo, dumb);
860 edit_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::edit_modifier_chosen));
862 for (int x = 0; modifiers[x].name; ++x) {
863 if (modifiers[x].modifier == Keyboard::edit_modifier ()) {
864 edit_modifier_combo.set_active_text (_(modifiers[x].name));
869 label = manage (new Label (_("Edit using")));
870 label->set_name ("OptionsLabel");
871 label->set_alignment (1.0, 0.5);
873 keyboard_mouse_table.attach (*label, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
874 keyboard_mouse_table.attach (edit_modifier_combo, 1, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
876 label = manage (new Label (_("+ button")));
877 label->set_name ("OptionsLabel");
879 keyboard_mouse_table.attach (*label, 3, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
880 keyboard_mouse_table.attach (edit_button_spin, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, FILL);
882 edit_button_spin.set_name ("OptionsEntry");
883 edit_button_adjustment.set_value (Keyboard::edit_button());
884 edit_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::edit_button_changed));
886 set_popdown_strings (delete_modifier_combo, dumb);
887 delete_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::delete_modifier_chosen));
889 for (int x = 0; modifiers[x].name; ++x) {
890 if (modifiers[x].modifier == Keyboard::delete_modifier ()) {
891 delete_modifier_combo.set_active_text (_(modifiers[x].name));
896 label = manage (new Label (_("Delete using")));
897 label->set_name ("OptionsLabel");
898 label->set_alignment (1.0, 0.5);
900 keyboard_mouse_table.attach (*label, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
901 keyboard_mouse_table.attach (delete_modifier_combo, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
903 label = manage (new Label (_("+ button")));
904 label->set_name ("OptionsLabel");
906 keyboard_mouse_table.attach (*label, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
907 keyboard_mouse_table.attach (delete_button_spin, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, FILL);
909 delete_button_spin.set_name ("OptionsEntry");
910 delete_button_adjustment.set_value (Keyboard::delete_button());
911 delete_button_adjustment.signal_value_changed().connect (mem_fun(*this, &OptionEditor::delete_button_changed));
913 set_popdown_strings (snap_modifier_combo, dumb);
914 snap_modifier_combo.signal_changed().connect (mem_fun(*this, &OptionEditor::snap_modifier_chosen));
916 for (int x = 0; modifiers[x].name; ++x) {
917 if (modifiers[x].modifier == (guint) Keyboard::snap_modifier ()) {
918 snap_modifier_combo.set_active_text (_(modifiers[x].name));
923 label = manage (new Label (_("Ignore snap using")));
924 label->set_name ("OptionsLabel");
925 label->set_alignment (1.0, 0.5);
927 keyboard_mouse_table.attach (*label, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
928 keyboard_mouse_table.attach (snap_modifier_combo, 1, 2, 2, 3, Gtk::FILL|Gtk::EXPAND, FILL);
932 OptionEditor::edit_modifier_chosen ()
936 txt = edit_modifier_combo.get_active_text();
938 for (int i = 0; modifiers[i].name; ++i) {
939 if (txt == _(modifiers[i].name)) {
940 Keyboard::set_edit_modifier (modifiers[i].modifier);
947 OptionEditor::delete_modifier_chosen ()
951 txt = delete_modifier_combo.get_active_text();
953 for (int i = 0; modifiers[i].name; ++i) {
954 if (txt == _(modifiers[i].name)) {
955 Keyboard::set_delete_modifier (modifiers[i].modifier);
962 OptionEditor::snap_modifier_chosen ()
966 txt = snap_modifier_combo.get_active_text();
968 for (int i = 0; modifiers[i].name; ++i) {
969 if (txt == _(modifiers[i].name)) {
970 Keyboard::set_snap_modifier (modifiers[i].modifier);
977 OptionEditor::delete_button_changed ()
979 Keyboard::set_delete_button ((guint) delete_button_adjustment.get_value());
983 OptionEditor::edit_button_changed ()
985 Keyboard::set_edit_button ((guint) edit_button_adjustment.get_value());
989 OptionEditor::fixup_combo_size (Gtk::ComboBoxText& combo, vector<string>& strings)
991 /* find the widest string */
993 string::size_type maxlen = 0;
996 for (vector<string>::iterator i = strings.begin(); i != strings.end(); ++i) {
999 if ((l = (*i).length()) > maxlen) {
1005 /* try to include ascenders and descenders */
1007 if (maxstring.length() > 2) {
1012 const guint32 FUDGE = 10; // Combo's are stupid - they steal space from the entry for the button
1014 set_size_request_to_display_given_text (combo, maxstring.c_str(), 10 + FUDGE, 10);