source: trunk/src/user32/winaccel.cpp@ 2469

Last change on this file since 2469 was 2469, checked in by sandervl, 26 years ago

* empty log message *

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