Ardour  9.0-pre0-1048-gdef69dd383
bindings.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __libgtkmm2ext_bindings_h__
21 #define __libgtkmm2ext_bindings_h__
22 
23 #include <map>
24 #include <vector>
25 #include <list>
26 
27 #include <stdint.h>
28 
29 #include <ydk/gdkkeysyms.h>
30 #include <ytkmm/action.h>
31 #include <ytkmm/radioaction.h>
32 #include <ytkmm/toggleaction.h>
33 
34 #include "pbd/signals.h"
35 
36 #include "gtkmm2ext/visibility.h"
37 
38 class XMLNode;
39 class XMLProperty;
40 
41 namespace Gtkmm2ext {
42 
44 {
45  public:
47  _val = GDK_VoidSymbol;
48  }
49 
50  KeyboardKey (uint32_t state, uint32_t keycode);
51 
52  static KeyboardKey null_key() { return KeyboardKey (0, 0); }
53 
54  uint32_t state() const { return _val >> 32; }
55  uint32_t key() const { return _val & 0xffffffff; }
56 
57  bool operator<(const KeyboardKey& other) const {
58  return _val < other._val;
59  }
60 
61  bool operator==(const KeyboardKey& other) const {
62  return _val == other._val;
63  }
64 
65  std::string name() const;
66  std::string native_name() const;
67  std::string native_short_name() const;
68  static bool make_key (const std::string&, KeyboardKey&);
69 
70  std::string display_label() const;
71 
72  private:
73  uint64_t _val;
74 };
75 
77  public:
79  _val = ~0ULL;
80  }
81 
82  MouseButton (uint32_t state, uint32_t button_number);
83  uint32_t state() const { return _val >> 32; }
84  uint32_t button() const { return _val & 0xffff; }
85 
86  bool operator<(const MouseButton& other) const {
87  return _val < other._val;
88  }
89 
90  bool operator==(const MouseButton& other) const {
91  return _val == other._val;
92  }
93 
94  std::string name() const;
95  static bool make_button (const std::string&, MouseButton&);
96 
97  private:
98  uint64_t _val;
99 };
100 
102 
104  public:
105  enum Operation {
107  Release
108  };
109 
110  struct ActionInfo {
111  ActionInfo (std::string const& name) : action_name (name) {}
112  ActionInfo (std::string const& name, std::string const& grp) : action_name (name), group_name (grp) {}
113 
114  std::string action_name;
115  std::string group_name; /* may be empty */
116  mutable Glib::RefPtr<Gtk::Action> action;
117  };
118  typedef std::map<KeyboardKey,ActionInfo> KeybindingMap;
119 
120  Bindings (std::string const& name);
121  Bindings (std::string const & name, Bindings & other);
123 
124  std::string const& name() const { return _name; }
125  Bindings const * parent() const { return _parent; }
126 
127  void associate (bool force = false);
128  void dissociate ();
129  void reassociate ();
130 
131  bool empty() const;
132  bool empty_keys () const;
133  bool empty_mouse () const;
134 
135  bool add (KeyboardKey, Operation, std::string const&, XMLProperty const*, bool can_save = false);
136  bool replace (KeyboardKey, Operation, std::string const& action_name, bool can_save = true);
137  bool remove (Operation, std::string const& action_name, bool can_save = false);
138 
140 
141  void add (MouseButton, Operation, std::string const&, XMLProperty const*);
144 
145  bool is_bound (KeyboardKey const&, Operation, std::string* path = 0) const;
146  std::string bound_name (KeyboardKey const&, Operation) const;
147  bool is_registered (Operation op, std::string const& action_name) const;
148 
149  KeyboardKey get_binding_for_action (Glib::RefPtr<Gtk::Action>, Operation& op);
150 
151  bool load (XMLNode const& node);
152  void load_operation (XMLNode const& node);
153  void save (XMLNode& root);
154  void save_as_html (std::ostream&, bool) const;
155 
156  /* used for editing bindings */
157  void get_all_actions (std::vector<std::string>& paths,
158  std::vector<std::string>& labels,
159  std::vector<std::string>& tooltips,
160  std::vector<std::string>& keys,
161  std::vector<Glib::RefPtr<Gtk::Action> >& actions);
162 
163  /* all bindings currently in existence, as grouped into Bindings */
164  static void reset_bindings () { bindings.clear (); }
165  static std::list<Bindings*> bindings;
166  static Bindings* get_bindings (std::string const & name);
167  static void associate_all ();
168  static void save_all_bindings_as_html (std::ostream&);
169 
171 
177  }
178  }
179  };
180 
181  private:
183  std::string _name;
186 
187  typedef std::map<MouseButton,ActionInfo> MouseButtonBindingMap;
190 
191  void push_to_gtk (KeyboardKey, Glib::RefPtr<Gtk::Action>);
192 
194  const KeybindingMap& get_keymap (Operation op) const;
196 
197  void relativize ();
198  void clone_press (KeybindingMap&) const;
201  void copy_from_parent (bool associate);
204 
205  /* GTK has the following position a Gtk::Action:
206  *
207  * accel_path: <Actions>/GroupName/ActionName
208  * name: ActionName
209  *
210  * We want proper namespacing and we're not interested in
211  * the silly <Actions> "extra" namespace. So in Ardour:
212  *
213  * accel_path: <Actions>/GroupName/ActionName
214  * name: GroupName/ActionName
215  *
216  * This (static) method returns the "ardour" name for the action.
217  */
218  static std::string ardour_action_name (Glib::RefPtr<Gtk::Action>);
219 
220  static int _drag_active;
221  friend struct DragsBlockBindings;
222 };
223 
224 typedef std::vector<Bindings*> BindingSet;
225 
228 
229 static char const * const ARDOUR_BINDING_KEY = "ardour-bindings";
230 
231 } // namespace
232 
233 std::ostream& operator<<(std::ostream& out, Gtkmm2ext::KeyboardKey const & k);
234 
235 #endif /* __libgtkmm2ext_bindings_h__ */
std::ostream & operator<<(std::ostream &out, Gtkmm2ext::KeyboardKey const &k)
MouseButtonBindingMap button_release_bindings
Definition: bindings.h:189
void clone_kbd_bindings(KeybindingMap const &, KeybindingMap &) const
void add(MouseButton, Operation, std::string const &, XMLProperty const *)
static std::string ardour_action_name(Glib::RefPtr< Gtk::Action >)
MouseButtonBindingMap button_press_bindings
Definition: bindings.h:188
void copy_from_parent(bool associate)
bool activate(KeyboardKey, Operation)
const KeybindingMap & get_keymap(Operation op) const
PBD::ScopedConnection bc
Definition: bindings.h:203
void save(XMLNode &root)
KeyboardKey get_binding_for_action(Glib::RefPtr< Gtk::Action >, Operation &op)
void save_as_html(std::ostream &, bool) const
static std::list< Bindings * > bindings
Definition: bindings.h:165
bool activate(MouseButton, Operation)
Bindings(std::string const &name, Bindings &other)
KeybindingMap release_bindings
Definition: bindings.h:185
void push_to_gtk(KeyboardKey, Glib::RefPtr< Gtk::Action >)
void associate(bool force=false)
bool load(XMLNode const &node)
void load_operation(XMLNode const &node)
static Bindings * get_bindings(std::string const &name)
void get_all_actions(std::vector< std::string > &paths, std::vector< std::string > &labels, std::vector< std::string > &tooltips, std::vector< std::string > &keys, std::vector< Glib::RefPtr< Gtk::Action > > &actions)
Bindings * _parent
Definition: bindings.h:182
void remove(MouseButton, Operation)
bool empty() const
std::string bound_name(KeyboardKey const &, Operation) const
static void associate_all()
void clone_release(KeybindingMap &) const
Bindings(std::string const &name)
std::map< MouseButton, ActionInfo > MouseButtonBindingMap
Definition: bindings.h:187
bool add(KeyboardKey, Operation, std::string const &, XMLProperty const *, bool can_save=false)
static PBD::Signal< void(Bindings *)> BindingsChanged
Definition: bindings.h:170
std::string const & name() const
Definition: bindings.h:124
static void reset_bindings()
Definition: bindings.h:164
void parent_changed(Bindings *)
void clone_press(KeybindingMap &) const
static void save_all_bindings_as_html(std::ostream &)
MouseButtonBindingMap & get_mousemap(Operation op)
Bindings const * parent() const
Definition: bindings.h:125
bool replace(KeyboardKey, Operation, std::string const &action_name, bool can_save=true)
bool empty_mouse() const
KeybindingMap press_bindings
Definition: bindings.h:184
bool is_registered(Operation op, std::string const &action_name) const
bool remove(Operation, std::string const &action_name, bool can_save=false)
bool empty_keys() const
std::string _name
Definition: bindings.h:183
bool is_bound(KeyboardKey const &, Operation, std::string *path=0) const
KeybindingMap & get_keymap(Operation op)
static int _drag_active
Definition: bindings.h:220
std::map< KeyboardKey, ActionInfo > KeybindingMap
Definition: bindings.h:118
bool operator<(const KeyboardKey &other) const
Definition: bindings.h:57
std::string display_label() const
uint32_t state() const
Definition: bindings.h:54
static KeyboardKey null_key()
Definition: bindings.h:52
std::string native_name() const
std::string native_short_name() const
bool operator==(const KeyboardKey &other) const
Definition: bindings.h:61
std::string name() const
uint32_t key() const
Definition: bindings.h:55
KeyboardKey(uint32_t state, uint32_t keycode)
static bool make_key(const std::string &, KeyboardKey &)
MouseButton(uint32_t state, uint32_t button_number)
bool operator==(const MouseButton &other) const
Definition: bindings.h:90
bool operator<(const MouseButton &other) const
Definition: bindings.h:86
static bool make_button(const std::string &, MouseButton &)
uint32_t button() const
Definition: bindings.h:84
std::string name() const
uint32_t state() const
Definition: bindings.h:83
Definition: xml++.h:114
#define GDK_VoidSymbol
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBGTKMM2EXT_API
static char const *const ARDOUR_BINDING_KEY
Definition: bindings.h:229
std::vector< Bindings * > BindingSet
Definition: bindings.h:224
void set_widget_bindings(Gtk::Widget &, Bindings &, char const *const name)
ActionInfo(std::string const &name, std::string const &grp)
Definition: bindings.h:112
Glib::RefPtr< Gtk::Action > action
Definition: bindings.h:116
ActionInfo(std::string const &name)
Definition: bindings.h:111