Opened 4 years ago

Closed 2 years ago

#12917 closed defect (fixed)

[wxOSX_COCOA] Key&board accelerators for button labels

Reported by: joostn Owned by:
Priority: low Milestone:
Component: wxOSX-Cocoa Version: stable-latest
Keywords: wxbutton button shortcut accelerator Cc: joost@…
Blocked By: Blocking:
Patch: yes

Description

Sample app:

#include "wx/wx.h"

class MyFrame : public wxFrame
{
    DECLARE_CLASS( MyFrame )
    DECLARE_EVENT_TABLE()
public:
    MyFrame()  
      : wxFrame(NULL,wxID_ANY,wxT("Frame"))
    {
      wxButton *btn1=new wxButton(this,1100,wxT("Button &A"),wxPoint(0,10));
      wxButton *btn2=new wxButton(this,1101,wxT("Button &B"),wxPoint(0,100));
    }
    void OnButtonAClick(wxCommandEvent &event)
    {
      wxMessageBox(wxT("A"));
    }
    void OnButtonBClick(wxCommandEvent &event)
    {
      wxMessageBox(wxT("B"));
    }
};


IMPLEMENT_CLASS( MyFrame, wxFrame )
BEGIN_EVENT_TABLE( MyFrame, wxFrame )
    EVT_BUTTON( 1100, MyFrame::OnButtonAClick )
    EVT_BUTTON( 1101, MyFrame::OnButtonBClick )
END_EVENT_TABLE()


class MyApp : public wxApp
{
public:
    bool OnInit()
    {
      wxApp::OnInit();
      MyFrame *frame=new MyFrame();
      frame->Show();
      return true;
    }
};

DECLARE_APP(MyApp)
IMPLEMENT_APP(MyApp)

Pressing Cmd+A should invoke button A and Cmd+B should invoke button B, just like the Alt shortcuts under windows. This is accomplished by the attached patch.

Keyboard shortcut is ignored if the button is the default button, since I haven't found a way to attach two keys to the same button.

Attachments (1)

button_shortcut.patch download (3.7 KB) - added by joostn 4 years ago.
The patch

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by joostn

The patch

comment:1 Changed 3 years ago by vadz

  • Priority changed from normal to low
  • Status changed from new to confirmed

Looks reasonable to me. Stefan, any objections to applying this?

comment:2 Changed 3 years ago by csomor

apart from the fact that it should be #if and not #ifdef for wxOSX_USE_COCOA and that it should have the same brace around the call for MacSetAcceleratorFromLabel in _osx.cpp it looks fine to me

comment:3 Changed 2 years ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [72809]) Implement support for button mnemonics in wxOSX/Cocoa.

Set the mnemonic as "key equivalent".

Closes #12917.

Note: See TracTickets for help on using tickets.