| 1 | /* $Id: comboex.c,v 1.3 1999-06-10 16:21:57 achimha Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * ComboBoxEx control | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1998, 1999 Eric Kohl | 
|---|
| 6 | * Copyright 1999 Achim Hasenmueller | 
|---|
| 7 | * | 
|---|
| 8 | * NOTES | 
|---|
| 9 | *   This is just a dummy control. An author is needed! Any volunteers? | 
|---|
| 10 | *   I will only improve this control once in a while. | 
|---|
| 11 | *     Eric <ekohl@abo.rhein-zeitung.de> | 
|---|
| 12 | * | 
|---|
| 13 | * TODO: | 
|---|
| 14 | *   - All messages. | 
|---|
| 15 | *   - All notifications. | 
|---|
| 16 | * | 
|---|
| 17 | * FIXME: | 
|---|
| 18 | *   - should include "combo.h" | 
|---|
| 19 | */ | 
|---|
| 20 |  | 
|---|
| 21 | #include "winbase.h" | 
|---|
| 22 | #include "commctrl.h" | 
|---|
| 23 | #include "comctl32.h" | 
|---|
| 24 | #include "comboex.h" | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 | #define ID_CB_EDIT    1001 | 
|---|
| 28 |  | 
|---|
| 29 | #define COMBOEX_GetInfoPtr(wndPtr) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0)) | 
|---|
| 30 |  | 
|---|
| 31 |  | 
|---|
| 32 | /* << COMBOEX_DeleteItem >> */ | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | static LRESULT | 
|---|
| 36 | COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 37 | { | 
|---|
| 38 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 39 |  | 
|---|
| 40 | //    TRACE (comboex, "\n"); | 
|---|
| 41 |  | 
|---|
| 42 | return (LRESULT)infoPtr->hwndCombo; | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 |  | 
|---|
| 46 | static LRESULT | 
|---|
| 47 | COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 48 | { | 
|---|
| 49 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 50 |  | 
|---|
| 51 | if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN) | 
|---|
| 52 | return 0; | 
|---|
| 53 |  | 
|---|
| 54 | //    TRACE (comboex, "-- 0x%x\n", GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT)); | 
|---|
| 55 |  | 
|---|
| 56 | return (LRESULT)GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|
| 60 | static LRESULT | 
|---|
| 61 | COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 62 | { | 
|---|
| 63 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 64 |  | 
|---|
| 65 | return (LRESULT)infoPtr->dwExtStyle; | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | static LRESULT | 
|---|
| 70 | COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 71 | { | 
|---|
| 72 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 73 |  | 
|---|
| 74 | //    TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam); | 
|---|
| 75 |  | 
|---|
| 76 | return (LRESULT)infoPtr->himl; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 |  | 
|---|
| 81 |  | 
|---|
| 82 | static LRESULT | 
|---|
| 83 | COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 84 | { | 
|---|
| 85 | /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); */ | 
|---|
| 86 |  | 
|---|
| 87 | //    FIXME (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam); | 
|---|
| 88 |  | 
|---|
| 89 | return -1; | 
|---|
| 90 | } | 
|---|
| 91 |  | 
|---|
| 92 |  | 
|---|
| 93 |  | 
|---|
| 94 | static LRESULT | 
|---|
| 95 | COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 96 | { | 
|---|
| 97 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 98 | DWORD dwTemp; | 
|---|
| 99 |  | 
|---|
| 100 | //    TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam); | 
|---|
| 101 |  | 
|---|
| 102 | dwTemp = infoPtr->dwExtStyle; | 
|---|
| 103 |  | 
|---|
| 104 | if ((DWORD)wParam) { | 
|---|
| 105 | infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam; | 
|---|
| 106 | } | 
|---|
| 107 | else | 
|---|
| 108 | infoPtr->dwExtStyle = (DWORD)lParam; | 
|---|
| 109 |  | 
|---|
| 110 | /* FIXME: repaint?? */ | 
|---|
| 111 |  | 
|---|
| 112 | return (LRESULT)dwTemp; | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 |  | 
|---|
| 116 | static LRESULT | 
|---|
| 117 | COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 118 | { | 
|---|
| 119 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 120 | HIMAGELIST himlTemp; | 
|---|
| 121 |  | 
|---|
| 122 | //    TRACE (comboex, "(0x%08x 0x%08lx)\n", wParam, lParam); | 
|---|
| 123 |  | 
|---|
| 124 | himlTemp = infoPtr->himl; | 
|---|
| 125 | infoPtr->himl = (HIMAGELIST)lParam; | 
|---|
| 126 |  | 
|---|
| 127 | return (LRESULT)himlTemp; | 
|---|
| 128 | } | 
|---|
| 129 |  | 
|---|
| 130 |  | 
|---|
| 131 | static LRESULT | 
|---|
| 132 | COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 133 | { | 
|---|
| 134 | /* COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); */ | 
|---|
| 135 |  | 
|---|
| 136 | //    FIXME (comboex, "(%p): stub\n", (LPVOID)lParam); | 
|---|
| 137 |  | 
|---|
| 138 | return TRUE; | 
|---|
| 139 | } | 
|---|
| 140 |  | 
|---|
| 141 |  | 
|---|
| 142 | /* << COMBOEX_SetItem32W >> */ | 
|---|
| 143 |  | 
|---|
| 144 |  | 
|---|
| 145 | static LRESULT | 
|---|
| 146 | COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 147 | { | 
|---|
| 148 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 149 |  | 
|---|
| 150 | //    FIXME (comboex, "(0x%x 0x%x 0x%lx): stub\n", uMsg, wParam, lParam); | 
|---|
| 151 |  | 
|---|
| 152 | if (infoPtr->hwndCombo) | 
|---|
| 153 | return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam); | 
|---|
| 154 |  | 
|---|
| 155 | return 0; | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 |  | 
|---|
| 159 | static LRESULT | 
|---|
| 160 | COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 161 | { | 
|---|
| 162 | COMBOEX_INFO *infoPtr; | 
|---|
| 163 | DWORD dwComboStyle; | 
|---|
| 164 |  | 
|---|
| 165 | /* allocate memory for info structure */ | 
|---|
| 166 | infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO)); | 
|---|
| 167 | if (infoPtr == NULL) { | 
|---|
| 168 | //      ERR (comboex, "could not allocate info memory!\n"); | 
|---|
| 169 | return 0; | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr); | 
|---|
| 173 |  | 
|---|
| 174 |  | 
|---|
| 175 | /* initialize info structure */ | 
|---|
| 176 |  | 
|---|
| 177 |  | 
|---|
| 178 | /* create combo box */ | 
|---|
| 179 | dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) & | 
|---|
| 180 | (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD); | 
|---|
| 181 |  | 
|---|
| 182 | infoPtr->hwndCombo = CreateWindowA ("ComboBox", "", | 
|---|
| 183 | WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle, | 
|---|
| 184 | 0, 0, 0, 0, hwnd, (HMENU)1, | 
|---|
| 185 | GetWindowLongA (hwnd, GWL_HINSTANCE), NULL); | 
|---|
| 186 |  | 
|---|
| 187 | return 0; | 
|---|
| 188 | } | 
|---|
| 189 |  | 
|---|
| 190 |  | 
|---|
| 191 | static LRESULT | 
|---|
| 192 | COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 193 | { | 
|---|
| 194 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 195 |  | 
|---|
| 196 |  | 
|---|
| 197 | if (infoPtr->hwndCombo) | 
|---|
| 198 | DestroyWindow (infoPtr->hwndCombo); | 
|---|
| 199 |  | 
|---|
| 200 |  | 
|---|
| 201 |  | 
|---|
| 202 |  | 
|---|
| 203 | /* free comboex info data */ | 
|---|
| 204 | COMCTL32_Free (infoPtr); | 
|---|
| 205 |  | 
|---|
| 206 | return 0; | 
|---|
| 207 | } | 
|---|
| 208 |  | 
|---|
| 209 |  | 
|---|
| 210 | static LRESULT | 
|---|
| 211 | COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam) | 
|---|
| 212 | { | 
|---|
| 213 | COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd); | 
|---|
| 214 | RECT rect; | 
|---|
| 215 |  | 
|---|
| 216 | GetClientRect (hwnd, &rect); | 
|---|
| 217 |  | 
|---|
| 218 | MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left, | 
|---|
| 219 | rect.bottom - rect.top, TRUE); | 
|---|
| 220 |  | 
|---|
| 221 | return 0; | 
|---|
| 222 | } | 
|---|
| 223 |  | 
|---|
| 224 |  | 
|---|
| 225 | LRESULT WINAPI | 
|---|
| 226 | COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) | 
|---|
| 227 | { | 
|---|
| 228 | switch (uMsg) | 
|---|
| 229 | { | 
|---|
| 230 | /*      case CBEM_DELETEITEM: */ | 
|---|
| 231 |  | 
|---|
| 232 | case CBEM_GETCOMBOCONTROL: | 
|---|
| 233 | return COMBOEX_GetComboControl (hwnd, wParam, lParam); | 
|---|
| 234 |  | 
|---|
| 235 | case CBEM_GETEDITCONTROL: | 
|---|
| 236 | return COMBOEX_GetEditControl (hwnd, wParam, lParam); | 
|---|
| 237 |  | 
|---|
| 238 | case CBEM_GETEXTENDEDSTYLE: | 
|---|
| 239 | return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam); | 
|---|
| 240 |  | 
|---|
| 241 | case CBEM_GETIMAGELIST: | 
|---|
| 242 | return COMBOEX_GetImageList (hwnd, wParam, lParam); | 
|---|
| 243 |  | 
|---|
| 244 | /*      case CBEM_GETITEM32A: | 
|---|
| 245 | case CBEM_GETITEM32W: | 
|---|
| 246 | case CBEM_GETUNICODEFORMAT: | 
|---|
| 247 | case CBEM_HASEDITCHANGED: | 
|---|
| 248 | */ | 
|---|
| 249 |  | 
|---|
| 250 | case CBEM_INSERTITEMA: | 
|---|
| 251 | return COMBOEX_InsertItemA (hwnd, wParam, lParam); | 
|---|
| 252 |  | 
|---|
| 253 | /*      case CBEM_INSERTITEM32W: */ | 
|---|
| 254 |  | 
|---|
| 255 | case CBEM_SETEXTENDEDSTYLE: | 
|---|
| 256 | return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam); | 
|---|
| 257 |  | 
|---|
| 258 | case CBEM_SETIMAGELIST: | 
|---|
| 259 | return COMBOEX_SetImageList (hwnd, wParam, lParam); | 
|---|
| 260 |  | 
|---|
| 261 | case CBEM_SETITEMA: | 
|---|
| 262 | return COMBOEX_SetItemA (hwnd, wParam, lParam); | 
|---|
| 263 |  | 
|---|
| 264 | /*      case CBEM_SETITEM32W: | 
|---|
| 265 | case CBEM_SETUNICODEFORMAT: | 
|---|
| 266 | */ | 
|---|
| 267 |  | 
|---|
| 268 | case CB_DELETESTRING: | 
|---|
| 269 | case CB_FINDSTRINGEXACT: | 
|---|
| 270 | case CB_GETCOUNT: | 
|---|
| 271 | case CB_GETCURSEL: | 
|---|
| 272 | case CB_GETDROPPEDCONTROLRECT: | 
|---|
| 273 | case CB_GETDROPPEDSTATE: | 
|---|
| 274 | case CB_GETITEMDATA: | 
|---|
| 275 | case CB_GETITEMHEIGHT: | 
|---|
| 276 | case CB_GETLBTEXT: | 
|---|
| 277 | case CB_GETLBTEXTLEN: | 
|---|
| 278 | case CB_GETEXTENDEDUI: | 
|---|
| 279 | case CB_LIMITTEXT: | 
|---|
| 280 | case CB_RESETCONTENT: | 
|---|
| 281 | case CB_SELECTSTRING: | 
|---|
| 282 | case CB_SETCURSEL: | 
|---|
| 283 | case CB_SETDROPPEDWIDTH: | 
|---|
| 284 | case CB_SETEXTENDEDUI: | 
|---|
| 285 | case CB_SETITEMDATA: | 
|---|
| 286 | case CB_SETITEMHEIGHT: | 
|---|
| 287 | case CB_SHOWDROPDOWN: | 
|---|
| 288 | return COMBOEX_Forward (hwnd, uMsg, wParam, lParam); | 
|---|
| 289 |  | 
|---|
| 290 |  | 
|---|
| 291 | case WM_CREATE: | 
|---|
| 292 | return COMBOEX_Create (hwnd, wParam, lParam); | 
|---|
| 293 |  | 
|---|
| 294 | case WM_DESTROY: | 
|---|
| 295 | return COMBOEX_Destroy (hwnd, wParam, lParam); | 
|---|
| 296 |  | 
|---|
| 297 | case WM_SIZE: | 
|---|
| 298 | return COMBOEX_Size (hwnd, wParam, lParam); | 
|---|
| 299 |  | 
|---|
| 300 | default: | 
|---|
| 301 | //          if (uMsg >= WM_USER) | 
|---|
| 302 | //              ERR (comboex, "unknown msg %04x wp=%08x lp=%08lx\n", | 
|---|
| 303 | //                   uMsg, wParam, lParam); | 
|---|
| 304 | return DefWindowProcA (hwnd, uMsg, wParam, lParam); | 
|---|
| 305 | } | 
|---|
| 306 | return 0; | 
|---|
| 307 | } | 
|---|
| 308 |  | 
|---|
| 309 |  | 
|---|
| 310 | VOID | 
|---|
| 311 | COMBOEX_Register (VOID) | 
|---|
| 312 | { | 
|---|
| 313 | WNDCLASSA wndClass; | 
|---|
| 314 |  | 
|---|
| 315 | if (GlobalFindAtomA (WC_COMBOBOXEXA)) return; | 
|---|
| 316 |  | 
|---|
| 317 | ZeroMemory (&wndClass, sizeof(WNDCLASSA)); | 
|---|
| 318 | wndClass.style         = CS_GLOBALCLASS; | 
|---|
| 319 | wndClass.lpfnWndProc   = (WNDPROC)COMBOEX_WindowProc; | 
|---|
| 320 | wndClass.cbClsExtra    = 0; | 
|---|
| 321 | wndClass.cbWndExtra    = sizeof(COMBOEX_INFO *); | 
|---|
| 322 | wndClass.hCursor       = LoadCursorA (0, IDC_ARROWA); | 
|---|
| 323 | wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); | 
|---|
| 324 | wndClass.lpszClassName = WC_COMBOBOXEXA; | 
|---|
| 325 |  | 
|---|
| 326 | RegisterClassA (&wndClass); | 
|---|
| 327 | } | 
|---|
| 328 |  | 
|---|
| 329 |  | 
|---|
| 330 | VOID | 
|---|
| 331 | COMBOEX_Unregister (VOID) | 
|---|
| 332 | { | 
|---|
| 333 | if (GlobalFindAtomA (WC_COMBOBOXEXA)) | 
|---|
| 334 | UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL); | 
|---|
| 335 | } | 
|---|
| 336 |  | 
|---|