| 1 | #ifndef _GTKMM_ACCELMAP_H |
| 2 | #define _GTKMM_ACCELMAP_H |
| 3 | /* accelmap.h |
| 4 | * |
| 5 | * Copyright (C) 2002 The Gtkmm Development Team |
| 6 | * |
| 7 | * This library is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU Lesser General Public |
| 9 | * License as published by the Free Software Foundation; either |
| 10 | * version 2.1 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This library is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * Lesser General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Lesser General Public |
| 18 | * License along with this library; if not, see <https://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include <string> |
| 22 | |
| 23 | #include <gdkmm/types.h> |
| 24 | #include <gtkmm/accelkey.h> |
| 25 | |
| 26 | namespace Gtk |
| 27 | { |
| 28 | |
| 29 | namespace AccelMap |
| 30 | { |
| 31 | |
| 32 | //TODO: Why is the accel_path a std::string, instead of a Glib::ustring? murrayc. |
| 33 | |
| 34 | /** Registers a new accelerator with the global accelerator map. |
| 35 | * This function should only be called once per accel_path |
| 36 | * with the canonical accel_key and accel_mods for this path. |
| 37 | * To change the accelerator during runtime programatically, use |
| 38 | * change_entry(). |
| 39 | * The accelerator path must consist of "<WINDOWTYPE>/Category1/Category2/.../Action", |
| 40 | * where \<WINDOWTYPE\> should be a unique application-specific identifier, that |
| 41 | * corresponds to the kind of window the accelerator is being used in, e.g. "Gimp-Image", |
| 42 | * "Abiword-Document" or "Gnumeric-Settings". |
| 43 | * The Category1/.../Action portion is most appropriately chosen by the action the |
| 44 | * accelerator triggers, i.e. for accelerators on menu items, choose the item's menu path, |
| 45 | * e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All". |
| 46 | * So a full valid accelerator path may look like: |
| 47 | * "<Gimp-Toolbox>/File/Dialogs/Tool Options...". |
| 48 | * |
| 49 | * @param accel_path valid accelerator path |
| 50 | * @param accel_key the accelerator key |
| 51 | * @param accel_mods the accelerator modifiers |
| 52 | * |
| 53 | */ |
| 54 | GTKMM_API |
| 55 | void add_entry(const std::string& accel_path, |
| 56 | guint accel_key, |
| 57 | Gdk::ModifierType accel_mods); |
| 58 | |
| 59 | /** Changes the accel_key and accel_mods currently associated with accel_path. |
| 60 | * Due to conflicts with other accelerators, a change may not always be possible, |
| 61 | * replace indicates whether other accelerators may be deleted to resolve such |
| 62 | * conflicts. A change will only occur if all conflicts could be resolved (which |
| 63 | * might not be the case if conflicting accelerators are locked). Successful |
| 64 | * changes are indicated by a true return value. |
| 65 | * |
| 66 | * @param accel_path a valid accelerator path |
| 67 | * @param accel_key the new accelerator key |
| 68 | * @param accel_mods the new accelerator modifiers |
| 69 | * @param replace true if other accelerators may be deleted upon conflicts |
| 70 | * @result true if the accelerator could be changed, false otherwise |
| 71 | */ |
| 72 | GTKMM_API |
| 73 | bool change_entry(const std::string& accel_path, |
| 74 | guint accel_key, |
| 75 | Gdk::ModifierType accel_mods, |
| 76 | bool replace); |
| 77 | |
| 78 | /** Parses a file previously saved with save() for |
| 79 | * accelerator specifications, and propagates them accordingly. |
| 80 | * |
| 81 | * @param filename a file containing accelerator specifications |
| 82 | */ |
| 83 | GTKMM_API |
| 84 | void load(const std::string& filename); |
| 85 | |
| 86 | /** Saves current accelerator specifications (accelerator path, key |
| 87 | * and modifiers) to filename. |
| 88 | * The file is written in a format suitable to be read back in by |
| 89 | * load(). |
| 90 | * |
| 91 | * @param filename the file to contain accelerator specifications |
| 92 | */ |
| 93 | GTKMM_API |
| 94 | void save(const std::string& filename); |
| 95 | |
| 96 | /** Locks the given accelerator path. |
| 97 | * |
| 98 | * Locking an accelerator path prevents its accelerator from being changed |
| 99 | * during runtime. A locked accelerator path can be unlocked by |
| 100 | * unlock_path(). Refer to change_entry() |
| 101 | * about runtime accelerator changes. |
| 102 | * |
| 103 | * Note that locking of individual accelerator paths is independent from |
| 104 | * locking the AccelGroup containing them. For runtime accelerator |
| 105 | * changes to be possible both the accelerator path and its AccelGroup |
| 106 | * have to be unlocked. |
| 107 | * |
| 108 | * @param accel_path a valid accelerator path |
| 109 | * |
| 110 | * @newin{2,4} |
| 111 | */ |
| 112 | GTKMM_API |
| 113 | void lock_path(const std::string& accel_path); |
| 114 | |
| 115 | /** Unlocks the given accelerator path. Refer to gtk_accel_map_lock_path() |
| 116 | * about accelerator path locking. |
| 117 | * |
| 118 | * @param accel_path a valid accelerator path |
| 119 | * |
| 120 | * @newin{2,4} |
| 121 | */ |
| 122 | GTKMM_API |
| 123 | void unlock_path(const std::string& accel_path); |
| 124 | |
| 125 | /** Looks up the accelerator entry for accel_path. |
| 126 | * @param accel_path A valid accelerator path. |
| 127 | * @result true if accel_path is known, false otherwise |
| 128 | * |
| 129 | * @newin{2,10} |
| 130 | */ |
| 131 | GTKMM_API |
| 132 | bool lookup_entry (const Glib::ustring& accel_path); |
| 133 | |
| 134 | /** Looks up the accelerator entry for accel_path and fills in key. |
| 135 | * @param accel_path A valid accelerator path. |
| 136 | * @param key The accelerator key to be filled in. |
| 137 | * @result true if accel_path is known, false otherwise |
| 138 | * |
| 139 | * @newin{2,10} |
| 140 | */ |
| 141 | GTKMM_API |
| 142 | bool lookup_entry (const Glib::ustring& accel_path, Gtk::AccelKey& key); |
| 143 | |
| 144 | } // namespace AccelMap |
| 145 | |
| 146 | } // namespace Gtk |
| 147 | |
| 148 | #endif /* _GTKMM_ACCELMAP_H */ |