Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

winhtky.c

Go to the documentation of this file.
00001 /****************************** Module Header ******************************\ 00002 * Module Name: whotkeys.c 00003 * 00004 * Copyright (c) 1985 - 1999, Microsoft Corporation 00005 * 00006 * This module contains the core functions of 3.1 window hotkey processing. 00007 * 00008 * History: 00009 * 16-Apr-1992 JimA Created. 00010 \***************************************************************************/ 00011 00012 #include "precomp.h" 00013 #pragma hdrstop 00014 00015 /***************************************************************************\ 00016 * HotKeyToWindow 00017 * 00018 * Scans the hotkey table and returns the pwnd corresponding to the 00019 * given hot key. Returns NULL if no such hot key in the list. Looks at the 00020 * current key state array. 00021 * 00022 * History: 00023 * 04-15-92 JimA Ported from Win3.1 sources. 00024 \***************************************************************************/ 00025 00026 PWND HotKeyToWindow( 00027 DWORD key) 00028 { 00029 PHOTKEYSTRUCT phk; 00030 int ckeys; 00031 00032 ckeys = gcHotKey; 00033 00034 if (ckeys == 0) 00035 return 0; 00036 00037 phk = gpHotKeyList; 00038 00039 while (ckeys) { 00040 if (phk->key == key) 00041 return TestWF(phk->spwnd, WFVISIBLE) ? phk->spwnd : NULL; 00042 phk++; 00043 ckeys--; 00044 } 00045 00046 return 0; 00047 } 00048 00049 00050 /***************************************************************************\ 00051 * HotKeyHelper 00052 * 00053 * Scans the hot key list and returns a pointer to the entry for the 00054 * window. 00055 * 00056 * History: 00057 * 04-15-92 JimA Ported from Win3.1 sources. 00058 \***************************************************************************/ 00059 00060 PHOTKEYSTRUCT HotKeyHelper( 00061 PWND pwnd) 00062 { 00063 PHOTKEYSTRUCT phk; 00064 int count; 00065 00066 count = gcHotKey; 00067 00068 if (gpHotKeyList == NULL) 00069 return 0; 00070 00071 phk = gpHotKeyList; 00072 00073 while (count) { 00074 if (phk->spwnd == pwnd) 00075 return phk; 00076 phk++; 00077 count--; 00078 } 00079 00080 return 0; 00081 } 00082 00083 00084 /***************************************************************************\ 00085 * DWP_SetHotKey 00086 * 00087 * Set the hot key for this window. Replace existing hot key, or if new 00088 * key is NULL, delete the entry. Return 2 if key already existed and 00089 * was replaced, 1 if key did not exist and was set, 0 for 00090 * failure, and -1 for invalid hot key. 00091 * 00092 * History: 00093 * 15-Apr-1992 JimA Ported from Win3.1 sources. 00094 \***************************************************************************/ 00095 00096 UINT DWP_SetHotKey( 00097 PWND pwnd, 00098 DWORD dwKey) 00099 { 00100 PHOTKEYSTRUCT phk; 00101 BOOL fKeyExists = FALSE; 00102 PWND pwndTemp; 00103 00104 /* 00105 * Filter out invalid hotkeys 00106 */ 00107 if (LOBYTE(dwKey) == VK_ESCAPE || 00108 LOBYTE(dwKey) == VK_SPACE || 00109 LOBYTE(dwKey) == VK_TAB || 00110 LOBYTE(dwKey) == VK_PACKET) { 00111 00112 return (UINT)-1; 00113 } 00114 00115 /* 00116 * Don't allow hotkeys for children 00117 */ 00118 if (TestWF(pwnd, WFCHILD)) 00119 return 0; 00120 00121 /* 00122 * Check if the hot key exists and is assigned to a different pwnd 00123 */ 00124 if (dwKey != 0) { 00125 00126 pwndTemp = HotKeyToWindow(dwKey); 00127 00128 if ((pwndTemp != NULL) && (pwndTemp != pwnd)) 00129 fKeyExists = TRUE; 00130 } 00131 00132 /* 00133 * Get the hotkey assigned to the window, if any 00134 */ 00135 if ((phk = HotKeyHelper(pwnd)) == NULL) { 00136 00137 /* 00138 * Window doesn't exist in the hotkey list and key is being set 00139 * to zero, so just return. 00140 */ 00141 if (dwKey == 0) 00142 return 1; 00143 00144 /* 00145 * Allocate and point to a spot for the new hotkey 00146 */ 00147 if (gcHotKey >= gcHotKeyAlloc) { 00148 00149 if (gcHotKeyAlloc) { 00150 00151 phk = (PHOTKEYSTRUCT)UserReAllocPool( 00152 (HANDLE)gpHotKeyList, 00153 gcHotKeyAlloc * sizeof(HOTKEYSTRUCT), 00154 (gcHotKey + 1) * sizeof(HOTKEYSTRUCT), TAG_HOTKEY); 00155 00156 if (phk != NULL) { 00157 00158 gpHotKeyList = phk; 00159 phk = &gpHotKeyList[gcHotKey++]; 00160 gcHotKeyAlloc = gcHotKey; 00161 00162 } else { 00163 00164 return 0; 00165 } 00166 00167 } else { 00168 00169 UserAssert(gpHotKeyList == NULL); 00170 UserAssert(gcHotKey == 0); 00171 00172 phk = (PHOTKEYSTRUCT)UserAllocPool(sizeof(HOTKEYSTRUCT), 00173 TAG_HOTKEY); 00174 00175 if (phk != NULL) { 00176 00177 gpHotKeyList = phk; 00178 gcHotKey = 1; 00179 gcHotKeyAlloc = 1; 00180 00181 } else { 00182 00183 return 0; 00184 } 00185 } 00186 00187 } else { 00188 phk = &gpHotKeyList[gcHotKey++]; 00189 } 00190 } 00191 00192 if (dwKey == 0) { 00193 00194 /* 00195 * The hotkey for this window is being deleted. Copy the last item 00196 * on the list on top of the one being deleted. 00197 */ 00198 if (--gcHotKey) { 00199 00200 Lock(&phk->spwnd, gpHotKeyList[gcHotKey].spwnd); 00201 Unlock(&gpHotKeyList[gcHotKey].spwnd); 00202 00203 phk->key = gpHotKeyList[gcHotKey].key; 00204 phk = (PHOTKEYSTRUCT)UserReAllocPool((HANDLE)gpHotKeyList, 00205 gcHotKeyAlloc * sizeof(HOTKEYSTRUCT), 00206 gcHotKey * sizeof(HOTKEYSTRUCT), TAG_HOTKEY); 00207 00208 if (phk != NULL) { 00209 gpHotKeyList = phk; 00210 gcHotKeyAlloc = gcHotKey; 00211 } 00212 00213 } else { 00214 00215 Unlock(&gpHotKeyList[gcHotKey].spwnd); 00216 UserFreePool((HANDLE)gpHotKeyList); 00217 gpHotKeyList = NULL; 00218 gcHotKeyAlloc = 0; 00219 } 00220 00221 } else { 00222 00223 /* 00224 * Add the window and key to the list 00225 */ 00226 phk->spwnd = NULL; 00227 Lock(&phk->spwnd, pwnd); 00228 phk->key = dwKey; 00229 } 00230 00231 return fKeyExists ? 2 : 1; 00232 } 00233 00234 /***************************************************************************\ 00235 * DWP_GetHotKey 00236 * 00237 * 00238 * History: 00239 * 15-Apr-1992 JimA Created. 00240 \***************************************************************************/ 00241 00242 UINT DWP_GetHotKey( 00243 PWND pwnd) 00244 { 00245 PHOTKEYSTRUCT phk; 00246 00247 if ((phk = HotKeyHelper(pwnd)) == NULL) 00248 return 0; 00249 00250 return phk->key; 00251 }

Generated on Sat May 15 19:42:25 2004 for test by doxygen 1.3.7