OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
KeyboardShortcutDialog Class Reference

#include <KeyboardShortcutDialog.hh>

Inheritance diagram for KeyboardShortcutDialog:
Inheritance graph
Collaboration diagram for KeyboardShortcutDialog:
Collaboration graph

Public Member Functions

 KeyboardShortcutDialog (wxWindow *parent, KeyboardShortcut *shortcut)
 
virtual ~KeyboardShortcutDialog ()
 

Private Types

enum  { ID_SHORTCUT = 10000 }
 enumerated IDs for dialog widgets More...
 

Private Member Functions

virtual bool TransferDataToWindow ()
 
wxSizer * createContents (wxWindow *parent, bool callFit, bool set_sizer)
 
void onCharEvent (wxKeyEvent &event)
 

Private Attributes

KeyboardShortcutshortcut_
 modified shortcut
 
wxStaticText * shortcutField_
 shortcut text field widget
 

Detailed Description

Dialog for defining keyboard shortcuts.

Definition at line 44 of file KeyboardShortcutDialog.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

enumerated IDs for dialog widgets

Enumerator
ID_SHORTCUT 

Definition at line 60 of file KeyboardShortcutDialog.hh.

Constructor & Destructor Documentation

◆ KeyboardShortcutDialog()

KeyboardShortcutDialog::KeyboardShortcutDialog ( wxWindow *  parent,
KeyboardShortcut shortcut 
)

The constructor.

Parameters
parentParent window of the dialog.
shortcutShortcut to modify.

Definition at line 56 of file KeyboardShortcutDialog.cc.

57 :
58 wxDialog(parent, -1, _T("Edit keyboard shortcut"), wxDefaultPosition),
59 shortcut_(shortcut) {
60
61 assert(shortcut != NULL);
62
63 wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
64 wxPanel* panel = new wxPanel(this, -1);
65 createContents(panel, true, true);
66 sizer->Add(panel);
67 SetSizer(sizer);
68 sizer->Fit(this);
69 FindWindow(wxID_OK)->Enable(false);
70 panel->SetFocus();
71}
#define assert(condition)
KeyboardShortcut * shortcut_
modified shortcut
wxSizer * createContents(wxWindow *parent, bool callFit, bool set_sizer)

References assert.

◆ ~KeyboardShortcutDialog()

KeyboardShortcutDialog::~KeyboardShortcutDialog ( )
virtual

The Destructor.

Definition at line 77 of file KeyboardShortcutDialog.cc.

77 {
78}

Member Function Documentation

◆ createContents()

wxSizer * KeyboardShortcutDialog::createContents ( wxWindow *  parent,
bool  call_fit,
bool  set_sizer 
)
private

Creates the dialog contents.

This function was initially generated by wxDesigner.

Returns
Main sizer of the created contents.
Parameters
parentThe dialog window.
call_fitIf true, fits the contents inside the dialog.
set_sizerIf true, sets the main sizer as dialog contents.

Definition at line 178 of file KeyboardShortcutDialog.cc.

179 {
180
181 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
182 wxStaticText *item1 = new wxStaticText( parent, -1,
183 wxT("Redefine the shortcut by pressing\n"
184 "keys for the new key combination."),
185 wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
186 item0->Add( item1, 0, wxALIGN_CENTER|wxALL, 10 );
187 wxStaticBox *item3 = new wxStaticBox( parent, -1, wxT("Shortcut:") );
188 wxStaticBoxSizer *item2 = new wxStaticBoxSizer( item3, wxHORIZONTAL );
189
191 new wxStaticText(parent, ID_SHORTCUT, wxT(""), wxDefaultPosition,
192 wxDefaultSize, 0);
193 item2->Add(shortcutField_, 0, wxALIGN_CENTER|wxALL, 5 );
194 item0->Add( item2, 0, wxGROW|wxALL, 5 );
195 wxStaticLine *item5 =
196 new wxStaticLine(parent, -1, wxDefaultPosition, wxSize(20,-1),
197 wxLI_HORIZONTAL );
198 item0->Add( item5, 0, wxGROW|wxALL, 5 );
199 wxBoxSizer *item6 = new wxBoxSizer( wxHORIZONTAL );
200 wxButton *item7 =
201 new wxButton(parent, wxID_OK, wxT("OK"), wxDefaultPosition,
202 wxDefaultSize, 0);
203 item6->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );
204 wxButton *item8 =
205 new wxButton(parent, wxID_CANCEL, wxT("Cancel"), wxDefaultPosition,
206 wxDefaultSize, 0);
207 item6->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );
208 item0->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );
209
210 if (set_sizer) {
211 parent->SetAutoLayout( TRUE );
212 parent->SetSizer( item0 );
213 if (call_fit)
214 {
215 item0->Fit( parent );
216 item0->SetSizeHints( parent );
217 }
218 }
219
220 return item0;
221}
const string TRUE
Value used for true in attribute and element values.
wxStaticText * shortcutField_
shortcut text field widget

References ID_SHORTCUT, shortcutField_, and TRUE.

◆ onCharEvent()

void KeyboardShortcutDialog::onCharEvent ( wxKeyEvent &  event)
private

Sets a new shortcut for the command.

Parameters
eventKeyevent of the new shortcut.

Definition at line 126 of file KeyboardShortcutDialog.cc.

126 {
127
128 int keycode = event.GetKeyCode();
129
130 PRINT_VAR(keycode);
131 // check that key code is valid
132 if (!((keycode >= int('0') && keycode <= int('9')) ||
133 (keycode >= int('A') && keycode <= int('Z')) ||
134 (keycode == 127) ||
135 (keycode >= WXK_F1 && keycode <= WXK_F12))) {
136
137 return;
138 }
139
140 // Check that character key shortcut has at least control
141 // or alt modifier.
142 if (keycode < 256 &&
143 !(event.AltDown() || event.ControlDown())) {
144 return;
145 }
146
147 shortcut_->setAlt(event.AltDown());
148 shortcut_->setCtrl(event.ControlDown());
149
150 if (keycode < 256) {
151 // character key shortcut
152 shortcut_->setFKey(0);
153 shortcut_->setKey(keycode);
154 } else if(keycode >= WXK_F1 && keycode <= WXK_F12) {
155 // function key shortcut
156 shortcut_->setKey(0);
157 shortcut_->setFKey(keycode - WXK_F1 + 1);
158 } else {
159 // invalid shortcut
160 assert(false);
161 }
162
163 FindWindow(wxID_OK)->Enable(true);
165}
#define PRINT_VAR(VARIABLE__)
void setFKey(int fKey)
void setAlt(bool alt)
void setCtrl(bool ctrl)
void setKey(char key)

References assert, PRINT_VAR, KeyboardShortcut::setAlt(), KeyboardShortcut::setCtrl(), KeyboardShortcut::setFKey(), KeyboardShortcut::setKey(), shortcut_, and TransferDataToWindow().

Here is the call graph for this function:

◆ TransferDataToWindow()

bool KeyboardShortcutDialog::TransferDataToWindow ( )
privatevirtual

Transfers data from dialog attributes to dialog widgets.

Returns
True, if the data was succesfully transfered, false othwerwise.

Definition at line 87 of file KeyboardShortcutDialog.cc.

87 {
88
89 string keyName = "";
90
91 // set the name of the key
92 if (shortcut_->key() > 32 && shortcut_->key() < 127) {
93 // character key
95 } else if (shortcut_->key() == 127) {
96 // delete key
97 keyName = "DEL";
98 } else if (shortcut_->fKey() != 0) {
99 // function key
100 keyName = "F"+Conversion::toString(shortcut_->fKey());
101 }
102
103 wxString key = WxConversion::toWxString(keyName);
104
105 // prepend key modifiers
106 if (shortcut_->alt()) {
107 key.Prepend(_T("ALT - "));
108 }
109 if (shortcut_->ctrl()) {
110 key.Prepend(_T("CTRL - "));
111 }
112
113 shortcutField_->SetLabel(key);
114
115 return true;
116}
static std::string toString(const T &source)
static wxString toWxString(const std::string &source)

References KeyboardShortcut::alt(), KeyboardShortcut::ctrl(), KeyboardShortcut::fKey(), KeyboardShortcut::key(), shortcut_, shortcutField_, Conversion::toString(), and WxConversion::toWxString().

Referenced by onCharEvent().

Here is the call graph for this function:

Member Data Documentation

◆ shortcut_

KeyboardShortcut* KeyboardShortcutDialog::shortcut_
private

modified shortcut

Definition at line 55 of file KeyboardShortcutDialog.hh.

Referenced by onCharEvent(), and TransferDataToWindow().

◆ shortcutField_

wxStaticText* KeyboardShortcutDialog::shortcutField_
private

shortcut text field widget

Definition at line 57 of file KeyboardShortcutDialog.hh.

Referenced by createContents(), and TransferDataToWindow().


The documentation for this class was generated from the following files: