2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: accel.h
|
2008-03-09 17:42:34 +00:00
|
|
|
// Purpose: interface of wxAccelerator* classes
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-03-09 17:42:34 +00:00
|
|
|
|
|
|
|
/** wxAcceleratorEntry flags */
|
|
|
|
enum wxAcceleratorEntryFlags
|
|
|
|
{
|
|
|
|
/** no modifiers */
|
|
|
|
wxACCEL_NORMAL,
|
|
|
|
|
|
|
|
/** hold Alt key down */
|
|
|
|
wxACCEL_ALT,
|
|
|
|
|
2011-08-16 13:36:24 +00:00
|
|
|
/** hold Ctrl key down, corresponds to Command key on OS X */
|
2008-03-09 17:42:34 +00:00
|
|
|
wxACCEL_CTRL,
|
|
|
|
|
|
|
|
/** hold Shift key down */
|
|
|
|
wxACCEL_SHIFT,
|
|
|
|
|
2011-08-16 13:36:24 +00:00
|
|
|
/** corresponds to real Ctrl key on OS X, identic to @c wxACCEL_CTRL on other platforms */
|
|
|
|
wxACCEL_RAW_CTRL,
|
|
|
|
|
|
|
|
/** deprecated, identic to @c wxACCEL_CTRL on all platforms. */
|
2008-03-09 17:42:34 +00:00
|
|
|
wxACCEL_CMD
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxAcceleratorEntry
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-09 17:42:34 +00:00
|
|
|
An object used by an application wishing to create an accelerator table
|
|
|
|
(see wxAcceleratorTable).
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
2009-02-20 11:34:52 +00:00
|
|
|
@category{data}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:19:31 +00:00
|
|
|
@see wxAcceleratorTable, wxWindow::SetAcceleratorTable
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxAcceleratorEntry
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
2008-03-09 17:42:34 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2009-01-28 00:51:55 +00:00
|
|
|
A combination of the ::wxAcceleratorEntryFlags values, which
|
2008-03-09 17:42:34 +00:00
|
|
|
indicates which modifier keys are held down.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param keyCode
|
2009-01-28 00:51:55 +00:00
|
|
|
The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param cmd
|
2008-03-20 22:32:46 +00:00
|
|
|
The menu or control command identifier (ID).
|
|
|
|
@param item
|
|
|
|
The menu item associated with this accelerator.
|
|
|
|
*/
|
|
|
|
wxAcceleratorEntry(int flags = 0, int keyCode = 0, int cmd = 0,
|
|
|
|
wxMenuItem *item = NULL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Copy ctor.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-20 22:32:46 +00:00
|
|
|
wxAcceleratorEntry(const wxAcceleratorEntry& entry);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the command identifier for the accelerator table entry.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
int GetCommand() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the flags for the accelerator table entry.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
int GetFlags() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the keycode for the accelerator table entry.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
int GetKeyCode() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
2008-03-20 22:32:46 +00:00
|
|
|
/**
|
|
|
|
Returns the menu item associated with this accelerator entry.
|
|
|
|
*/
|
|
|
|
wxMenuItem *GetMenuItem() const;
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
Sets the accelerator entry parameters.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param flags
|
2009-01-28 00:51:55 +00:00
|
|
|
A combination of the ::wxAcceleratorEntryFlags values, which
|
2008-03-09 17:42:34 +00:00
|
|
|
indicates which modifier keys are held down.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param keyCode
|
2009-01-28 00:51:55 +00:00
|
|
|
The keycode to be detected. See ::wxKeyCode for a full list of keycodes.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param cmd
|
2008-03-20 22:32:46 +00:00
|
|
|
The menu or control command identifier (ID).
|
|
|
|
@param item
|
|
|
|
The menu item associated with this accelerator.
|
|
|
|
*/
|
|
|
|
void Set(int flags, int keyCode, int cmd, wxMenuItem *item = NULL);
|
2008-03-09 17:42:34 +00:00
|
|
|
|
2008-03-20 22:32:46 +00:00
|
|
|
/**
|
|
|
|
Returns @true if this object is correctly initialized.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-20 22:32:46 +00:00
|
|
|
bool IsOk() const;
|
|
|
|
|
|
|
|
/**
|
2010-12-03 12:39:57 +00:00
|
|
|
Returns a textual representation of this accelerator.
|
2009-01-28 00:51:55 +00:00
|
|
|
|
2012-05-23 21:16:28 +00:00
|
|
|
The returned string is of the form <code>[Alt+][Ctrl+][RawCtrl+][Shift+]Key</code>
|
2010-12-03 12:39:57 +00:00
|
|
|
where the modifier keys are present only if the corresponding flag is
|
|
|
|
set.
|
2008-03-20 22:32:46 +00:00
|
|
|
*/
|
|
|
|
wxString ToString() const;
|
|
|
|
|
2012-04-16 12:12:19 +00:00
|
|
|
/**
|
|
|
|
Returns a textual representation of this accelerator which is
|
|
|
|
appropriate for saving in configuration files.
|
|
|
|
|
|
|
|
Unlike the string returned by ToString(), this one is never translated
|
|
|
|
so, while it's not suitable for showing to the user, it can be used to
|
|
|
|
uniquely identify the accelerator independently of the user language.
|
|
|
|
|
|
|
|
The returned string can still be parsed by FromString().
|
|
|
|
|
|
|
|
@since 2.9.4
|
|
|
|
*/
|
|
|
|
wxString ToRawString() const;
|
|
|
|
|
2008-03-20 22:32:46 +00:00
|
|
|
/**
|
|
|
|
Parses the given string and sets the accelerator accordingly.
|
|
|
|
|
|
|
|
@param str
|
2010-12-03 12:39:57 +00:00
|
|
|
This string may be either in the same format as returned by
|
|
|
|
ToString(), i.e. contain the accelerator itself only, or have the
|
|
|
|
format of a full menu item text with i.e. <code>Label TAB
|
|
|
|
Accelerator</code>. In the latter case, the part of the string
|
2010-12-15 11:18:42 +00:00
|
|
|
before the TAB is ignored. Notice that the latter format is only
|
|
|
|
supported for the compatibility with the previous wxWidgets
|
|
|
|
versions and the new code should pass only the accelerator string
|
|
|
|
itself to this function.
|
2008-03-20 22:32:46 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @true if the given string correctly initialized this object
|
|
|
|
(i.e. if IsOk() returns true after this call)
|
2008-03-20 22:32:46 +00:00
|
|
|
*/
|
|
|
|
bool FromString(const wxString& str);
|
|
|
|
|
|
|
|
|
|
|
|
wxAcceleratorEntry& operator=(const wxAcceleratorEntry& entry);
|
|
|
|
bool operator==(const wxAcceleratorEntry& entry) const;
|
|
|
|
bool operator!=(const wxAcceleratorEntry& entry) const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxAcceleratorTable
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
An accelerator table allows the application to specify a table of keyboard
|
2008-03-18 16:21:15 +00:00
|
|
|
shortcuts for menu or button commands.
|
2008-03-09 17:42:34 +00:00
|
|
|
|
2008-03-10 15:19:31 +00:00
|
|
|
The object ::wxNullAcceleratorTable is defined to be a table with no data, and
|
2008-03-09 17:42:34 +00:00
|
|
|
is the initial accelerator table for a window.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
@code
|
|
|
|
wxAcceleratorEntry entries[4];
|
|
|
|
entries[0].Set(wxACCEL_CTRL, (int) 'N', ID_NEW_WINDOW);
|
|
|
|
entries[1].Set(wxACCEL_CTRL, (int) 'X', wxID_EXIT);
|
|
|
|
entries[2].Set(wxACCEL_SHIFT, (int) 'A', ID_ABOUT);
|
|
|
|
entries[3].Set(wxACCEL_NORMAL, WXK_DELETE, wxID_CUT);
|
|
|
|
|
|
|
|
wxAcceleratorTable accel(4, entries);
|
|
|
|
frame->SetAcceleratorTable(accel);
|
|
|
|
@endcode
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-09 17:42:34 +00:00
|
|
|
@remarks
|
|
|
|
An accelerator takes precedence over normal processing and can be a convenient
|
|
|
|
way to program some event handling. For example, you can use an accelerator table
|
|
|
|
to enable a dialog with a multi-line text control to accept CTRL-Enter as meaning
|
2008-03-20 13:19:55 +00:00
|
|
|
'OK'.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
2009-02-20 11:34:52 +00:00
|
|
|
@category{data}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@stdobjects
|
2008-03-10 15:19:31 +00:00
|
|
|
::wxNullAcceleratorTable
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-10 15:19:31 +00:00
|
|
|
@see wxAcceleratorEntry, wxWindow::SetAcceleratorTable
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxAcceleratorTable : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2008-03-09 17:42:34 +00:00
|
|
|
Default ctor.
|
|
|
|
*/
|
|
|
|
wxAcceleratorTable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes the accelerator table from an array of wxAcceleratorEntry.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param n
|
2008-03-09 12:33:59 +00:00
|
|
|
Number of accelerator entries.
|
2008-03-08 14:43:31 +00:00
|
|
|
@param entries
|
2008-03-09 12:33:59 +00:00
|
|
|
The array of entries.
|
2009-10-18 17:47:01 +00:00
|
|
|
|
|
|
|
@beginWxPerlOnly
|
|
|
|
The wxPerl constructor accepts a list of either
|
|
|
|
Wx::AcceleratorEntry objects or references to 3-element arrays
|
|
|
|
[flags, keyCode, cmd] , like the parameters of
|
|
|
|
Wx::AcceleratorEntry::new.
|
|
|
|
@endWxPerlOnly
|
2008-03-09 17:42:34 +00:00
|
|
|
*/
|
2008-03-20 22:32:46 +00:00
|
|
|
wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]);
|
2008-03-09 17:42:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Loads the accelerator table from a Windows resource (Windows only).
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-27 20:54:47 +00:00
|
|
|
@onlyfor{wxmsw}
|
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param resource
|
2008-03-09 12:33:59 +00:00
|
|
|
Name of a Windows accelerator.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
wxAcceleratorTable(const wxString& resource);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destroys the wxAcceleratorTable object.
|
2008-03-09 17:42:34 +00:00
|
|
|
See @ref overview_refcount_destruct for more info.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-24 01:02:55 +00:00
|
|
|
virtual ~wxAcceleratorTable();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the accelerator table is valid.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
bool IsOk() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
2008-03-09 17:42:34 +00:00
|
|
|
|
2008-03-14 15:35:10 +00:00
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2008-03-09 17:42:34 +00:00
|
|
|
/**
|
|
|
|
An empty accelerator table.
|
|
|
|
*/
|
|
|
|
wxAcceleratorTable wxNullAcceleratorTable;
|