1 | /* $Id: winaccel.cpp,v 1.6 2000-02-16 14:28:25 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 accelerator key functions for OS/2
|
---|
4 | *
|
---|
5 | * Copyright 1999 Bart van Leeuwen
|
---|
6 | *
|
---|
7 | *
|
---|
8 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
9 | *
|
---|
10 | */
|
---|
11 | #include <os2win.h>
|
---|
12 | #include <misc.h>
|
---|
13 | #include <win32wbase.h>
|
---|
14 | #include <winaccel.h>
|
---|
15 |
|
---|
16 | #define DBG_LOCALLOG DBG_winaccel
|
---|
17 | #include "dbglocal.h"
|
---|
18 |
|
---|
19 | /*****************************************************************************
|
---|
20 | * Name : HACCEL WIN32API LoadAcceleratorsA
|
---|
21 | * Purpose : Load accelerator resource and return handle to it
|
---|
22 | * Parameters: HINSTANCE hinst, LPCSTR lpszAcc
|
---|
23 | * Variables :
|
---|
24 | * Result : Global Handle of resource
|
---|
25 | * Remark : see code
|
---|
26 | * Status : OK
|
---|
27 | *
|
---|
28 | * Author : Bart van Leeuwen [Sun, 1998/12/26 17:01]
|
---|
29 | *****************************************************************************/
|
---|
30 | HACCEL WIN32API LoadAcceleratorsA(HINSTANCE hinst, LPCSTR lpszAcc)
|
---|
31 | {
|
---|
32 | HACCEL rc;
|
---|
33 |
|
---|
34 | rc = (HACCEL)FindResourceA(hinst, lpszAcc, RT_ACCELERATORA);
|
---|
35 |
|
---|
36 | dprintf(("LoadAcceleratorsA returned %d\n", rc));
|
---|
37 | return(rc);
|
---|
38 | }
|
---|
39 | /*****************************************************************************
|
---|
40 | * Name : HACCEL WIN32API LoadAcceleratorsW
|
---|
41 | * Purpose : Load accelerator resource and return handle to it
|
---|
42 | * Parameters: HINSTANCE hinst, LPCSTR lpszAcc
|
---|
43 | * Variables :
|
---|
44 | * Result : Global Handle of resource
|
---|
45 | * Remark : see code
|
---|
46 | * Status : OK
|
---|
47 | *
|
---|
48 | * Author : Bart van Leeuwen [Sun, 1998/12/26 17:01]
|
---|
49 | *****************************************************************************/
|
---|
50 |
|
---|
51 | HACCEL WIN32API LoadAcceleratorsW(HINSTANCE hinst, LPCWSTR lpszAccel)
|
---|
52 | {
|
---|
53 | HACCEL rc;
|
---|
54 |
|
---|
55 | rc = (HACCEL)FindResourceW(hinst, lpszAccel, RT_ACCELERATORW);
|
---|
56 |
|
---|
57 |
|
---|
58 | dprintf(("LoadAcceleratorsW returned %d\n", rc));
|
---|
59 | return(rc);
|
---|
60 | }
|
---|
61 | //******************************************************************************
|
---|
62 | //******************************************************************************
|
---|
63 | BOOL WIN32API DestroyAcceleratorTable( HACCEL haccel)
|
---|
64 | {
|
---|
65 | Win32Resource *winres;
|
---|
66 |
|
---|
67 | dprintf(("DestroyAcceleratorTable %x\n", haccel));
|
---|
68 | winres = (Win32Resource *)haccel;
|
---|
69 | delete winres;
|
---|
70 | return TRUE;
|
---|
71 | }
|
---|
72 | /*****************************************************************************
|
---|
73 | * Name : int WIN32API TranslateAcceleratorA
|
---|
74 | * Purpose : Translate WM_*KEYDOWN messages to WM_COMMAND messages
|
---|
75 | * according to Accelerator table
|
---|
76 | * Parameters: HWND hwnd, HACCEL haccel, LPMSG lpmsg
|
---|
77 | * Variables :
|
---|
78 | * Result : int FALSE (no accelerator found) TRUE (accelerator found)
|
---|
79 | * Remark : if a accelerator is found it is not neccesarely executed
|
---|
80 | * depends on window stat
|
---|
81 | * Status : finished but not fully tested
|
---|
82 | *
|
---|
83 | * Author : Bart van Leeuwen [Sun, 1998/12/26 17:01]
|
---|
84 | *****************************************************************************/
|
---|
85 | int WIN32API TranslateAcceleratorA(HWND hwnd, HACCEL haccel, LPMSG lpmsg)
|
---|
86 | {
|
---|
87 | Win32BaseWindow *window,*parentWindow,*childWindow;
|
---|
88 | LPWINACCEL lpAccelTbl;
|
---|
89 | WINACCEL tmpAccel;
|
---|
90 | HACCEL temp2;
|
---|
91 | HGLOBAL GlobHandle;
|
---|
92 | HWND hwndMenu,parent,child,msgHwnd;
|
---|
93 | int i,keyMask;
|
---|
94 | INT16 menuStat;
|
---|
95 | BOOL sendMessage;
|
---|
96 |
|
---|
97 |
|
---|
98 | //bvl: check if messages come from keyboard
|
---|
99 | if ((lpmsg->message != WM_KEYDOWN &&
|
---|
100 | lpmsg->message != WM_SYSKEYDOWN))
|
---|
101 | {
|
---|
102 | //dprintf(("TranslateAcceleratorA called by invalid message"));
|
---|
103 | SetLastError(ERROR_SUCCESS);
|
---|
104 | return FALSE;
|
---|
105 | }
|
---|
106 |
|
---|
107 | window = Win32BaseWindow::GetWindowFromHandle(lpmsg->hwnd);
|
---|
108 |
|
---|
109 | if(!window)
|
---|
110 | {
|
---|
111 | dprintf(("TranslateAcceleratorA, window %x not found", hwnd));
|
---|
112 | SetLastError(ERROR_INVALID_WINDOW_HANDLE);
|
---|
113 | return FALSE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | //bvl: Get memory pointer here
|
---|
117 | GlobHandle = LoadResource(NULL,haccel);
|
---|
118 | lpAccelTbl = (LPWINACCEL) LockResource(GlobHandle);
|
---|
119 |
|
---|
120 | keyMask=0;
|
---|
121 | if(GetKeyState(VK_SHIFT) & 0x8000) keyMask |= FSHIFT;
|
---|
122 | if(GetKeyState(VK_CONTROL) & 0x8000) keyMask |= FCONTROL;
|
---|
123 | if(GetKeyState(VK_MENU) & 0x8000) keyMask |= FALT;
|
---|
124 |
|
---|
125 | i=0;
|
---|
126 | do
|
---|
127 | {
|
---|
128 | if ((lpAccelTbl[i].key == lpmsg->wParam)&&(keyMask == (lpAccelTbl[i].fVirt &
|
---|
129 | (FSHIFT | FCONTROL | FALT))))
|
---|
130 | {
|
---|
131 | //bvl: Accelerator found
|
---|
132 | dprintf(("Accelerator found for command: %X",lpAccelTbl[i].cmd));
|
---|
133 | //bvl: this is not right, check control and win stat
|
---|
134 | // SendMessageA(hwnd,WM_COMMAND,lpAccelTbl[i].cmd,0x00010000L);
|
---|
135 |
|
---|
136 | sendMessage = FALSE;
|
---|
137 |
|
---|
138 | if (window->isFrameWindow())
|
---|
139 | {
|
---|
140 | if ( !window->IsIconic() )
|
---|
141 | {
|
---|
142 | //bvl: this is a frame window so just use that menuhandle
|
---|
143 | hwndMenu = window->GetMenu();
|
---|
144 | if ( hwndMenu == NULL )
|
---|
145 | {
|
---|
146 | //bvl: window does not have a menu so command isn't a menu
|
---|
147 | dprintf(("framenomenu"));
|
---|
148 | sendMessage = TRUE;
|
---|
149 | }
|
---|
150 | else
|
---|
151 | {
|
---|
152 | //bvl: get menuitem status
|
---|
153 | menuStat = GetMenuState(hwndMenu,lpAccelTbl[i++].cmd,MF_BYCOMMAND);
|
---|
154 | //bvl: -1 means no menu Item
|
---|
155 | if( !menuStat == -1)
|
---|
156 | {
|
---|
157 | if( menuStat & !(MF_DISABLED|MF_GRAYED) )
|
---|
158 | {
|
---|
159 | //bvl: its a menu item and its enabled
|
---|
160 | dprintf(("framemenu"));
|
---|
161 | sendMessage = TRUE;
|
---|
162 | }
|
---|
163 | else
|
---|
164 | {
|
---|
165 | //bvl: its a menu Item but disabled
|
---|
166 | sendMessage = FALSE;
|
---|
167 | }
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {
|
---|
171 | //bvl: the message is probably not a menu msg so process it
|
---|
172 | dprintf(("framemenunoitem"));
|
---|
173 | sendMessage = TRUE;
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 | }
|
---|
178 | else
|
---|
179 | {
|
---|
180 | //bvl: the message is probably not a menu msg so process it
|
---|
181 | dprintf(("noframe"));
|
---|
182 | sendMessage = TRUE;
|
---|
183 | }
|
---|
184 |
|
---|
185 | if ( sendMessage )
|
---|
186 | {
|
---|
187 | //bvl: previous checks indicated that command can be send.
|
---|
188 | SendMessageA(hwnd,WM_COMMAND,lpAccelTbl[i].cmd,0x00010000L);
|
---|
189 | return TRUE;
|
---|
190 |
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | } while ((lpAccelTbl[i++].fVirt & 0x80) == 0);
|
---|
195 |
|
---|
196 | SetLastError(ERROR_SUCCESS);
|
---|
197 | return FALSE;
|
---|
198 | }
|
---|
199 | /*****************************************************************************
|
---|
200 | * Name : int WIN32API TranslateAcceleratorA
|
---|
201 | * Remark : See TranslateAcceleratorA
|
---|
202 | * Status : finished but not fully tested
|
---|
203 | *
|
---|
204 | * Author : Bart van Leeuwen [Sun, 1998/12/26 17:01]
|
---|
205 | *****************************************************************************/
|
---|
206 |
|
---|
207 | int WIN32API TranslateAcceleratorW( HWND hwnd, HACCEL hAccel, LPMSG lpMsg)
|
---|
208 | {
|
---|
209 | return TranslateAcceleratorA(hwnd, hAccel, lpMsg);
|
---|
210 | }
|
---|
211 | //******************************************************************************
|
---|
212 | //******************************************************************************
|
---|
213 | BOOL WIN32API TranslateMDISysAccel( HWND arg1, LPMSG arg2)
|
---|
214 | {
|
---|
215 | #ifdef DEBUG
|
---|
216 | //// WriteLog("USER32: TranslateMDISysAccel\n");
|
---|
217 | #endif
|
---|
218 | return O32_TranslateMDISysAccel(arg1, arg2);
|
---|
219 | }
|
---|
220 | //******************************************************************************
|
---|
221 | //******************************************************************************
|
---|
222 | HACCEL WIN32API CreateAcceleratorTableA( LPACCEL arg1, int arg2)
|
---|
223 | {
|
---|
224 | #ifdef DEBUG
|
---|
225 | WriteLog("USER32: CreateAcceleratorTableA\n");
|
---|
226 | #endif
|
---|
227 | return O32_CreateAcceleratorTable(arg1, arg2);
|
---|
228 | }
|
---|
229 | //******************************************************************************
|
---|
230 | //******************************************************************************
|
---|
231 | HACCEL WIN32API CreateAcceleratorTableW( LPACCEL arg1, int arg2)
|
---|
232 | {
|
---|
233 | #ifdef DEBUG
|
---|
234 | WriteLog("USER32: CreateAcceleratorTableW\n");
|
---|
235 | #endif
|
---|
236 | // NOTE: This will not work as is (needs UNICODE support)
|
---|
237 | return O32_CreateAcceleratorTable(arg1, arg2);
|
---|
238 | }
|
---|
239 | //******************************************************************************
|
---|
240 | //******************************************************************************
|
---|
241 | int WIN32API CopyAcceleratorTableA(HACCEL hAccelSrc, LPACCEL lpAccelDest,
|
---|
242 | int cAccelEntries)
|
---|
243 | {
|
---|
244 | #ifdef DEBUG
|
---|
245 | WriteLog("USER32: CopyAcceleratorTableA, not implemented\n");
|
---|
246 | #endif
|
---|
247 | return(0);
|
---|
248 | }
|
---|
249 | //******************************************************************************
|
---|
250 | //TODO:
|
---|
251 | //******************************************************************************
|
---|
252 | int WIN32API CopyAcceleratorTableW(HACCEL hAccelSrc, LPACCEL lpAccelDest,
|
---|
253 | int cAccelEntries)
|
---|
254 | {
|
---|
255 | #ifdef DEBUG
|
---|
256 | WriteLog("USER32: CopyAcceleratorTableW, not implemented\n");
|
---|
257 | #endif
|
---|
258 | return(0);
|
---|
259 | }
|
---|
260 | //******************************************************************************
|
---|
261 | //******************************************************************************
|
---|