accel.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: accel.h
  3. // Purpose: interface of wxAccelerator* classes
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /** wxAcceleratorEntry flags */
  8. enum wxAcceleratorEntryFlags
  9. {
  10. /** no modifiers */
  11. wxACCEL_NORMAL,
  12. /** hold Alt key down */
  13. wxACCEL_ALT,
  14. /** hold Ctrl key down, corresponds to Command key on OS X */
  15. wxACCEL_CTRL,
  16. /** hold Shift key down */
  17. wxACCEL_SHIFT,
  18. /** corresponds to real Ctrl key on OS X, identic to @c wxACCEL_CTRL on other platforms */
  19. wxACCEL_RAW_CTRL,
  20. /** deprecated, identic to @c wxACCEL_CTRL on all platforms. */
  21. wxACCEL_CMD
  22. };
  23. /**
  24. @class wxAcceleratorEntry
  25. An object used by an application wishing to create an accelerator table
  26. (see wxAcceleratorTable).
  27. @library{wxcore}
  28. @category{data}
  29. @see wxAcceleratorTable, wxWindow::SetAcceleratorTable
  30. */
  31. class wxAcceleratorEntry
  32. {
  33. public:
  34. /**
  35. Constructor.
  36. @param flags
  37. A combination of the ::wxAcceleratorEntryFlags values, which
  38. indicates which modifier keys are held down.
  39. @param keyCode
  40. The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
  41. @param cmd
  42. The menu or control command identifier (ID).
  43. @param item
  44. The menu item associated with this accelerator.
  45. */
  46. wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0,
  47. wxMenuItem *item = NULL);
  48. /**
  49. Copy ctor.
  50. */
  51. wxAcceleratorEntry(const wxAcceleratorEntry& entry);
  52. /**
  53. Returns the command identifier for the accelerator table entry.
  54. */
  55. int GetCommand() const;
  56. /**
  57. Returns the flags for the accelerator table entry.
  58. */
  59. int GetFlags() const;
  60. /**
  61. Returns the keycode for the accelerator table entry.
  62. */
  63. int GetKeyCode() const;
  64. /**
  65. Returns the menu item associated with this accelerator entry.
  66. */
  67. wxMenuItem *GetMenuItem() const;
  68. /**
  69. Sets the accelerator entry parameters.
  70. @param flags
  71. A combination of the ::wxAcceleratorEntryFlags values, which
  72. indicates which modifier keys are held down.
  73. @param keyCode
  74. The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
  75. @param cmd
  76. The menu or control command identifier (ID).
  77. @param item
  78. The menu item associated with this accelerator.
  79. */
  80. void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL);
  81. /**
  82. Returns @true if this object is correctly initialized.
  83. */
  84. bool IsOk() const;
  85. /**
  86. Returns a textual representation of this accelerator.
  87. The returned string is of the form <code>[Alt+][Ctrl+][RawCtrl+][Shift+]Key</code>
  88. where the modifier keys are present only if the corresponding flag is
  89. set.
  90. */
  91. wxString ToString() const;
  92. /**
  93. Returns a textual representation of this accelerator which is
  94. appropriate for saving in configuration files.
  95. Unlike the string returned by ToString(), this one is never translated
  96. so, while it's not suitable for showing to the user, it can be used to
  97. uniquely identify the accelerator independently of the user language.
  98. The returned string can still be parsed by FromString().
  99. @since 2.9.4
  100. */
  101. wxString ToRawString() const;
  102. /**
  103. Parses the given string and sets the accelerator accordingly.
  104. @param str
  105. This string may be either in the same format as returned by
  106. ToString(), i.e. contain the accelerator itself only, or have the
  107. format of a full menu item text with i.e. <code>Label TAB
  108. Accelerator</code>. In the latter case, the part of the string
  109. before the TAB is ignored. Notice that the latter format is only
  110. supported for the compatibility with the previous wxWidgets
  111. versions and the new code should pass only the accelerator string
  112. itself to this function.
  113. @return @true if the given string correctly initialized this object
  114. (i.e. if IsOk() returns true after this call)
  115. */
  116. bool FromString(const wxString& str);
  117. wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry);
  118. bool operator==(const wxAcceleratorEntry& entry) const;
  119. bool operator!=(const wxAcceleratorEntry& entry) const;
  120. };
  121. /**
  122. @class wxAcceleratorTable
  123. An accelerator table allows the application to specify a table of keyboard
  124. shortcuts for menu or button commands.
  125. The object ::wxNullAcceleratorTable is defined to be a table with no data, and
  126. is the initial accelerator table for a window.
  127. Example:
  128. @code
  129. wxAcceleratorEntry entries[4];
  130. entries[0].Set(wxACCEL_CTRL, (int) 'N', ID_NEW_WINDOW);
  131. entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);
  132. entries[2].Set(wxACCEL_SHIFT, (int) 'A', ID_ABOUT);
  133. entries[3].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CUT);
  134. wxAcceleratorTable accel(4, entries);
  135. frame->SetAcceleratorTable(accel);
  136. @endcode
  137. @remarks
  138. An accelerator takes precedence over normal processing and can be a convenient
  139. way to program some event handling. For example, you can use an accelerator table
  140. to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning
  141. 'OK'.
  142. @library{wxcore}
  143. @category{data}
  144. @stdobjects
  145. ::wxNullAcceleratorTable
  146. @see wxAcceleratorEntry, wxWindow::SetAcceleratorTable
  147. */
  148. class wxAcceleratorTable : public wxObject
  149. {
  150. public:
  151. /**
  152. Default ctor.
  153. */
  154. wxAcceleratorTable();
  155. /**
  156. Initializes the accelerator table from an array of wxAcceleratorEntry.
  157. @param n
  158. Number of accelerator entries.
  159. @param entries
  160. The array of entries.
  161. @beginWxPerlOnly
  162. The wxPerl constructor accepts a list of either
  163. Wx::AcceleratorEntry objects or references to 3-element arrays
  164. [flags, keyCode, cmd] , like the parameters of
  165. Wx::AcceleratorEntry::new.
  166. @endWxPerlOnly
  167. */
  168. wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]);
  169. /**
  170. Loads the accelerator table from a Windows resource (Windows only).
  171. @onlyfor{wxmsw}
  172. @param resource
  173. Name of a Windows accelerator.
  174. */
  175. wxAcceleratorTable(const wxString& resource);
  176. /**
  177. Destroys the wxAcceleratorTable object.
  178. See @ref overview_refcount_destruct for more info.
  179. */
  180. virtual ~wxAcceleratorTable();
  181. /**
  182. Returns @true if the accelerator table is valid.
  183. */
  184. bool IsOk() const;
  185. };
  186. // ============================================================================
  187. // Global functions/macros
  188. // ============================================================================
  189. /**
  190. An empty accelerator table.
  191. */
  192. wxAcceleratorTable wxNullAcceleratorTable;