1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: David Webster
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #include "wx/window.h"
23 #include "wx/os2/private.h"
26 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
28 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
30 friend class WXDLLEXPORT wxAcceleratorTable
;
32 wxAcceleratorRefData();
33 virtual ~wxAcceleratorRefData();
35 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
41 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
43 wxAcceleratorRefData::wxAcceleratorRefData()
47 } // end of wxAcceleratorRefData::wxAcceleratorRefData
49 wxAcceleratorRefData::~wxAcceleratorRefData()
53 WinDestroyAccelTable((HACCEL
) m_hAccel
);
56 } // end of wxAcceleratorRefData::~wxAcceleratorRefData
58 wxAcceleratorTable::wxAcceleratorTable()
61 } // end of wxAcceleratorTable::wxAcceleratorTable
63 wxAcceleratorTable::~wxAcceleratorTable()
65 } // end of wxAcceleratorTable::~wxAcceleratorTable
67 // Load from .rc resource
68 wxAcceleratorTable::wxAcceleratorTable(
69 const wxString
& rResource
75 m_refData
= new wxAcceleratorRefData
;
77 ulId
= atol(rResource
.c_str());
78 hAccel
= ::WinLoadAccelTable( vHabmain
79 ,NULL
// resources always in .exe
82 if (wxTheApp
->GetTopWindow() != NULL
)
85 // If we have accelerators the top window is the frame
87 wxFrame
* pFrame
= (wxFrame
*)wxTheApp
->GetTopWindow();
89 ::WinSetAccelTable( vHabmain
91 ,(HWND
)pFrame
->GetFrame()
94 M_ACCELDATA
->m_hAccel
= hAccel
;
95 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
98 extern int wxCharCodeWXToOS2(
103 // Create from an array
104 wxAcceleratorTable::wxAcceleratorTable(
106 , const wxAcceleratorEntry vaEntries
[]
109 int nAccelLength
= ((sizeof(ACCEL
) * n
) + sizeof(ACCELTABLE
));
113 m_refData
= new wxAcceleratorRefData
;
114 pArr
= (PACCELTABLE
) new BYTE
[nAccelLength
];
116 for (i
= 0; i
< n
; i
++)
118 USHORT uVirt
= AF_CHAR
;
120 if (vaEntries
[i
].GetFlags() & wxACCEL_ALT
)
123 uVirt
|= AF_VIRTUALKEY
;
125 if (vaEntries
[i
].GetFlags() & wxACCEL_SHIFT
)
128 uVirt
|= AF_VIRTUALKEY
;
130 if (vaEntries
[i
].GetFlags() & wxACCEL_CTRL
)
133 uVirt
|= AF_VIRTUALKEY
;
137 USHORT uKey
= (USHORT
)wxCharCodeWXToOS2( vaEntries
[i
].GetKeyCode(),
140 uVirt
= AF_CHAR
| AF_VIRTUALKEY
;
142 USHORT uCmd
= (USHORT
)vaEntries
[i
].GetCommand();
144 pArr
->aaccel
[i
].fs
= uVirt
;
145 pArr
->aaccel
[i
].key
= uKey
;
146 pArr
->aaccel
[i
].cmd
= uCmd
;
148 pArr
->codepage
= (USHORT
)::WinQueryCp(wxTheApp
->m_hMq
);
149 pArr
->cAccel
= (USHORT
)n
;
150 M_ACCELDATA
->m_hAccel
= ::WinCreateAccelTable( vHabmain
153 if (wxTheApp
->GetTopWindow() != NULL
)
156 // If we have accelerators the top window is the frame
158 wxFrame
* pFrame
= (wxFrame
*)wxTheApp
->GetTopWindow();
160 ::WinSetAccelTable( vHabmain
161 ,M_ACCELDATA
->m_hAccel
162 ,(HWND
)pFrame
->GetFrame()
167 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
168 } // end of wxAcceleratorTable::wxAcceleratorTable
170 bool wxAcceleratorTable::IsOk() const
172 return(M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
173 } // end of wxAcceleratorTable::IsOk
175 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
178 m_refData
= new wxAcceleratorRefData
;
180 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
183 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
187 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
190 bool wxAcceleratorTable::Translate( WXHWND hWnd
,
191 WXMSG
* pWxmsg
) const
193 PQMSG pMsg
= (PQMSG
)pWxmsg
;
196 rc
= ::WinTranslateAccel( vHabmain
201 return (IsOk() && rc
);
202 } // end of wxAcceleratorTable::Translate
204 // ---------------------------------------------------------------------------
205 // function for translating labels
206 // ---------------------------------------------------------------------------
208 wxString
wxPMTextToLabel( const wxString
& rsTitle
)
216 for (zPc
= rsTitle
.c_str(); *zPc
!= wxT('\0'); zPc
++)
218 if (*zPc
== wxT('&'))
220 if (*(zPc
+ 1) == wxT('&'))
230 if ( *zPc
== wxT('~'))
233 // Tildes must be doubled to prevent them from being
234 // interpreted as accelerator character prefix by PM ???
242 } // end of wxPMTextToLabel