]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/keyboard/keyboard.cpp
Use TAbs in debian/rules, not spaces, as it's a makefile.
[wxWidgets.git] / samples / keyboard / keyboard.cpp
index eb45da0907d290ea5aca364c7f1e66cf70159810..f218f6bbaf9cfb1bf218f2ed18424ad65a30ac56 100644 (file)
@@ -32,8 +32,17 @@ private:
     // event handlers
     void OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(true); }
     void OnAbout(wxCommandEvent& event);
+
+    void OnTestAccelA(wxCommandEvent& WXUNUSED(event))
+        { m_logText->AppendText("Test accelerator \"A\" used.\n"); }
+    void OnTestAccelCtrlA(wxCommandEvent& WXUNUSED(event))
+        { m_logText->AppendText("Test accelerator \"Ctrl-A\" used.\n"); }
+    void OnTestAccelEsc(wxCommandEvent& WXUNUSED(event))
+        { m_logText->AppendText("Test accelerator \"Esc\" used.\n"); }
+
     void OnClear(wxCommandEvent& WXUNUSED(event)) { m_logText->Clear(); }
     void OnSkip(wxCommandEvent& event) { m_skip = event.IsChecked(); }
+
     void OnKeyDown(wxKeyEvent& event) { LogEvent("KeyDown", event); }
     void OnKeyUp(wxKeyEvent& event) { LogEvent("KeyUp", event); }
     void OnChar(wxKeyEvent& event) { LogEvent("Char", event); }
@@ -88,6 +97,9 @@ MyFrame::MyFrame(const wxString& title)
         QuitID = wxID_EXIT,
         ClearID = wxID_CLEAR,
         SkipID = 100,
+        TestAccelA,
+        TestAccelCtrlA,
+        TestAccelEsc
     };
 
     // create a menu bar
@@ -96,6 +108,11 @@ MyFrame::MyFrame(const wxString& title)
     menuFile->Append(ClearID, "&Clear log\tCtrl-L");
     menuFile->AppendSeparator();
 
+    menuFile->Append(TestAccelA, "Test accelerator &1\tA");
+    menuFile->Append(TestAccelCtrlA, "Test accelerator &2\tCtrl-A");
+    menuFile->Append(TestAccelEsc, "Test accelerator &3\tEsc");
+    menuFile->AppendSeparator();
+
     menuFile->AppendCheckItem(SkipID, "Call event.&Skip()\tCtrl-S");
     menuFile->Check(SkipID, true);
     menuFile->AppendSeparator();
@@ -161,6 +178,15 @@ MyFrame::MyFrame(const wxString& title)
     Connect(SkipID, wxEVT_COMMAND_MENU_SELECTED,
             wxCommandEventHandler(MyFrame::OnSkip));
 
+    Connect(TestAccelA, wxEVT_COMMAND_MENU_SELECTED,
+            wxCommandEventHandler(MyFrame::OnTestAccelA));
+
+    Connect(TestAccelCtrlA, wxEVT_COMMAND_MENU_SELECTED,
+            wxCommandEventHandler(MyFrame::OnTestAccelCtrlA));
+
+    Connect(TestAccelEsc, wxEVT_COMMAND_MENU_SELECTED,
+            wxCommandEventHandler(MyFrame::OnTestAccelEsc));
+
     // connect event handlers for the blue input window
     m_inputWin->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MyFrame::OnKeyDown),
                         NULL, this);
@@ -309,7 +335,12 @@ const char* GetVirtualKeyCodeName(int keycode)
         WXK_(NUMPAD_SUBTRACT)
         WXK_(NUMPAD_DECIMAL)
         WXK_(NUMPAD_DIVIDE)
+
+        WXK_(WINDOWS_LEFT)
+        WXK_(WINDOWS_RIGHT)
+        WXK_(COMMAND)
 #undef WXK_
+
     default:
         return NULL;
     }
@@ -322,15 +353,18 @@ wxString GetKeyName(const wxKeyEvent &event)
     const char* virt = GetVirtualKeyCodeName(keycode);
     if ( virt )
         return virt;
-    if ( keycode > 0 && keycode < 27 )
+    if ( keycode > 0 && keycode < 32 )
         return wxString::Format("Ctrl-%c", (unsigned char)('A' + keycode - 1));
-    if ( keycode >= 27 && keycode < 128 )
+    if ( keycode >= 32 && keycode < 128 )
         return wxString::Format("'%c'", (unsigned char)keycode);
+
 #if wxUSE_UNICODE
-    return wxString::Format("'%c'", event.GetUnicodeKey());
-#else
-    return "unknown";
+    int uc = event.GetUnicodeKey();
+    if ( uc != WXK_NONE )
+        return wxString::Format("'%c'", uc);
 #endif
+
+    return "unknown";
 }
 
 
@@ -345,7 +379,7 @@ void MyFrame::LogEvent(const wxString& name, wxKeyEvent& event)
                    "    none   "
 #endif
 #ifdef wxHAS_RAW_KEY_CODES
-                   "  %7lu    0x%lx"
+                   "  %7lu    0x%08lx"
 #else
                    "  not-set    not-set"
 #endif