source: trunk/src/comctl32/comboex.c@ 5280

Last change on this file since 5280 was 4627, checked in by sandervl, 25 years ago

Resynched with Christoph's changes for unicode handling

File size: 27.2 KB
Line 
1/*
2 * ComboBoxEx control
3 *
4 * Copyright 1998, 1999 Eric Kohl
5 *
6 * NOTES
7 * This is just a dummy control. An author is needed! Any volunteers?
8 * I will only improve this control once in a while.
9 * Eric <ekohl@abo.rhein-zeitung.de>
10 *
11 * TODO:
12 * - All messages.
13 * - All notifications.
14 *
15 * FIXME:
16 * - should include "combo.h"
17
18 * Changes Guy Albertelli <galberte@neo.lrun.com>
19 * 1. Implemented message CB_SETITEMHEIGHT
20 * 2. Implemented message WM_WINDOWPOSCHANGING
21 * 3. Implemented message WM_MEASUREITEM
22 * 4. Add code to WM_CREATE processing to set font of COMBOBOX and
23 * issue the CB_SETITEMHEIGHT to start the correct sizing process.
24 * The above 4 changes allow the window rect for the comboboxex
25 * to be set properly, which in turn allows the height of the
26 * rebar control it *may* be imbeded in to be correct.
27 * 5. Rewrite CBEM_INSERTITEMA to save the information.
28 * 6. Implemented message WM_DRAWITEM. The code will handle images
29 * but not "overlays" yet.
30 * 7. Fixed code in CBEM_SETIMAGELIST to resize control.
31 * 8. Add debugging code.
32 *
33 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe)
34 *
35 */
36
37#ifdef __WIN32OS2__
38#include <odin.h>
39#include <string.h>
40#define inline
41#endif
42
43#include "winbase.h"
44#include "wine/winestring.h"
45#include "commctrl.h"
46#include "debugtools.h"
47#include "wine/unicode.h"
48
49DEFAULT_DEBUG_CHANNEL(comboex);
50DECLARE_DEBUG_CHANNEL(message);
51
52/* Item structure */
53typedef struct
54{
55 VOID *next;
56 UINT mask;
57 LPWSTR pszText;
58 int cchTextMax;
59 int iImage;
60 int iSelectedImage;
61 int iOverlay;
62 int iIndent;
63 LPARAM lParam;
64} CBE_ITEMDATA;
65
66/* ComboBoxEx structure */
67typedef struct
68{
69 HIMAGELIST himl;
70 HWND hwndCombo;
71 DWORD dwExtStyle;
72 HFONT font;
73 INT nb_items; /* Number of items */
74 CBE_ITEMDATA *items; /* Array of items */
75} COMBOEX_INFO;
76
77#define ID_CB_EDIT 1001
78
79/* Height in pixels of control over the amount of the selected font */
80#define CBE_EXTRA 3
81
82/* Indent amount per MS documentation */
83#define CBE_INDENT 10
84
85/* Offset in pixels from left side for start of image or text */
86#define CBE_STARTOFFSET 6
87
88/* Offset between image and text */
89#define CBE_SEP 4
90
91#define COMBOEX_GetInfoPtr(wndPtr) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
92
93
94static void
95COMBOEX_DumpItem (CBE_ITEMDATA *item)
96{
97 if (TRACE_ON(comboex)){
98 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
99 item, item->mask, item->pszText, item->cchTextMax,
100 item->iImage);
101 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
102 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
103 }
104}
105
106
107inline static LRESULT
108COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
109{
110 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
111
112 FIXME("(0x%x 0x%x 0x%lx): stub\n", uMsg, wParam, lParam);
113
114 if (infoPtr->hwndCombo)
115 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
116
117 return 0;
118}
119
120
121static void
122COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
123{
124 HFONT nfont, ofont;
125 HDC mydc;
126 SIZE mysize;
127 UINT cy;
128 IMAGEINFO iinfo;
129
130 mydc = GetDC (0); /* why the entire screen???? */
131 nfont = SendMessageA (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
132 ofont = (HFONT) SelectObject (mydc, nfont);
133 GetTextExtentPointA (mydc, "A", 1, &mysize);
134 SelectObject (mydc, ofont);
135 ReleaseDC (0, mydc);
136 cy = mysize.cy + CBE_EXTRA;
137 if (infoPtr->himl) {
138 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
139 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
140 }
141 TRACE("selected font hwnd=%08x, height=%d\n", nfont, cy);
142 SendMessageA (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
143 if (infoPtr->hwndCombo)
144 SendMessageA (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
145 (WPARAM) 0, (LPARAM) cy);
146}
147
148
149/* *** CBEM_xxx message support *** */
150
151
152/* << COMBOEX_DeleteItem >> */
153
154
155inline static LRESULT
156COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
157{
158 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
159
160 TRACE("\n");
161
162 return (LRESULT)infoPtr->hwndCombo;
163}
164
165
166inline static LRESULT
167COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
168{
169 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
170
171 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
172 return 0;
173
174 TRACE("-- 0x%x\n", GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT));
175
176 return (LRESULT)GetDlgItem (infoPtr->hwndCombo, ID_CB_EDIT);
177}
178
179
180inline static LRESULT
181COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
182{
183 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
184
185 return (LRESULT)infoPtr->dwExtStyle;
186}
187
188
189inline static LRESULT
190COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
191{
192 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
193
194 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
195
196 return (LRESULT)infoPtr->himl;
197}
198
199
200/* << COMBOEX_GetItemA >> */
201
202/* << COMBOEX_GetItemW >> */
203
204/* << COMBOEX_GetUniCodeFormat >> */
205
206/* << COMBOEX_HasEditChanged >> */
207
208
209static LRESULT
210COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
211{
212 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
213 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
214 INT index;
215 CBE_ITEMDATA *item;
216
217
218 /* get real index of item to insert */
219 index = cit->iItem;
220 if (index == -1) index = infoPtr->nb_items;
221 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
222
223 /* get space and chain it in */
224 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
225 item->next = NULL;
226 item->pszText = NULL;
227
228 /* locate position to insert new item in */
229 if (index == infoPtr->nb_items) {
230 /* fast path for iItem = -1 */
231 item->next = infoPtr->items;
232 infoPtr->items = item;
233 }
234 else {
235 int i = infoPtr->nb_items-1;
236 CBE_ITEMDATA *moving = infoPtr->items;
237
238 while (i > index && moving) {
239 moving = (CBE_ITEMDATA *)moving->next;
240 }
241 if (!moving) {
242 FIXME("COMBOBOXEX item structures broken. Please report!\n");
243 COMCTL32_Free(item);
244 return -1;
245 }
246 item->next = moving->next;
247 moving->next = item;
248 }
249
250 /* fill in our hidden item structure */
251 item->mask = cit->mask;
252 if (item->mask & CBEIF_TEXT) {
253 LPSTR str;
254 INT len;
255
256 str = cit->pszText;
257 if (!str) str="";
258 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
259 if (len > 0) {
260 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
261 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, len);
262 }
263 item->cchTextMax = cit->cchTextMax;
264 }
265 if (item->mask & CBEIF_IMAGE)
266 item->iImage = cit->iImage;
267 if (item->mask & CBEIF_SELECTEDIMAGE)
268 item->iSelectedImage = cit->iSelectedImage;
269 if (item->mask & CBEIF_OVERLAY)
270 item->iOverlay = cit->iOverlay;
271 if (item->mask & CBEIF_INDENT)
272 item->iIndent = cit->iIndent;
273 if (item->mask & CBEIF_LPARAM)
274 item->lParam = cit->lParam;
275 infoPtr->nb_items++;
276
277 COMBOEX_DumpItem (item);
278
279 SendMessageA (infoPtr->hwndCombo, CB_INSERTSTRING,
280 (WPARAM)cit->iItem, (LPARAM)item);
281
282 return index;
283
284}
285
286
287static LRESULT
288COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
289{
290 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
291 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
292 INT index;
293 CBE_ITEMDATA *item;
294
295 /* get real index of item to insert */
296 index = cit->iItem;
297 if (index == -1) index = infoPtr->nb_items;
298 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
299
300 /* get space and chain it in */
301 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
302 item->next = NULL;
303 item->pszText = NULL;
304
305 /* locate position to insert new item in */
306 if (index == infoPtr->nb_items) {
307 /* fast path for iItem = -1 */
308 item->next = infoPtr->items;
309 infoPtr->items = item;
310 }
311 else {
312 INT i = infoPtr->nb_items-1;
313 CBE_ITEMDATA *moving = infoPtr->items;
314
315 while ((i > index) && moving) {
316 moving = (CBE_ITEMDATA *)moving->next;
317 i--;
318 }
319 if (!moving) {
320 FIXME("COMBOBOXEX item structures broken. Please report!\n");
321 COMCTL32_Free(item);
322 return -1;
323 }
324 item->next = moving->next;
325 moving->next = item;
326 }
327
328 /* fill in our hidden item structure */
329 item->mask = cit->mask;
330 if (item->mask & CBEIF_TEXT) {
331 LPWSTR str;
332 INT len;
333
334 str = cit->pszText;
335 if (!str) str = (LPWSTR) L"";
336 len = strlenW (str);
337 if (len > 0) {
338 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
339 strcpyW (item->pszText, str);
340 }
341 item->cchTextMax = cit->cchTextMax;
342 }
343 if (item->mask & CBEIF_IMAGE)
344 item->iImage = cit->iImage;
345 if (item->mask & CBEIF_SELECTEDIMAGE)
346 item->iSelectedImage = cit->iSelectedImage;
347 if (item->mask & CBEIF_OVERLAY)
348 item->iOverlay = cit->iOverlay;
349 if (item->mask & CBEIF_INDENT)
350 item->iIndent = cit->iIndent;
351 if (item->mask & CBEIF_LPARAM)
352 item->lParam = cit->lParam;
353 infoPtr->nb_items++;
354
355 COMBOEX_DumpItem (item);
356
357 SendMessageA (infoPtr->hwndCombo, CB_INSERTSTRING,
358 (WPARAM)cit->iItem, (LPARAM)item);
359
360 return index;
361
362}
363
364
365static LRESULT
366COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
367{
368 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
369 DWORD dwTemp;
370
371 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
372
373 dwTemp = infoPtr->dwExtStyle;
374
375 if ((DWORD)wParam) {
376 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
377 }
378 else
379 infoPtr->dwExtStyle = (DWORD)lParam;
380
381 /* FIXME: repaint?? */
382
383 return (LRESULT)dwTemp;
384}
385
386
387inline static LRESULT
388COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
389{
390 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
391 HIMAGELIST himlTemp;
392
393 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
394
395 himlTemp = infoPtr->himl;
396 infoPtr->himl = (HIMAGELIST)lParam;
397
398 COMBOEX_ReSize (hwnd, infoPtr);
399 InvalidateRect (hwnd, NULL, TRUE);
400
401 return (LRESULT)himlTemp;
402}
403
404static LRESULT
405COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
406{
407 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
408 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
409 INT index;
410 INT i;
411 CBE_ITEMDATA *item;
412
413 /* get real index of item to insert */
414 index = cit->iItem;
415 if (index == -1) {
416 FIXME("NYI setting data for item in edit control\n");
417 return 0;
418 }
419
420 /* if item number requested does not exist then return failure */
421 if ((index > infoPtr->nb_items) || (index < 0)) return 0;
422
423 /* find the item in the list */
424 item = infoPtr->items;
425 i = infoPtr->nb_items - 1;
426 while (item && (i > index)) {
427 item = (CBE_ITEMDATA *)item->next;
428 i--;
429 }
430 if (!item || (i != index)) {
431 FIXME("COMBOBOXEX item structures broken. Please report!\n");
432 return 0;
433 }
434
435 /* add/change stuff to the internal item structure */
436 item->mask |= cit->mask;
437 if (cit->mask & CBEIF_TEXT) {
438 LPWSTR str;
439 INT len;
440 WCHAR emptystr[1] = {0};
441
442 str = cit->pszText;
443 if (!str) str=emptystr;
444 len = strlenW(str);
445 if (len > 0) {
446 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
447 strcpyW(item->pszText,str);
448 }
449 item->cchTextMax = cit->cchTextMax;
450 }
451 if (cit->mask & CBEIF_IMAGE)
452 item->iImage = cit->iImage;
453 if (cit->mask & CBEIF_SELECTEDIMAGE)
454 item->iSelectedImage = cit->iSelectedImage;
455 if (cit->mask & CBEIF_OVERLAY)
456 item->iOverlay = cit->iOverlay;
457 if (cit->mask & CBEIF_INDENT)
458 item->iIndent = cit->iIndent;
459 if (cit->mask & CBEIF_LPARAM)
460 cit->lParam = cit->lParam;
461
462 COMBOEX_DumpItem (item);
463
464 return TRUE;
465}
466
467static LRESULT
468COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
469{
470 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
471 COMBOBOXEXITEMW citW;
472 LRESULT ret;
473
474 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
475 if (cit->mask & CBEIF_TEXT) {
476 LPSTR str;
477 INT len;
478
479 str = cit->pszText;
480 if (!str) str="";
481 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
482 if (len > 0) {
483 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
484 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
485 }
486 }
487 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
488
489 if (cit->mask & CBEIF_TEXT)
490 COMCTL32_Free(citW.pszText);
491 return ret;
492}
493
494
495/* << COMBOEX_SetUniCodeFormat >> */
496
497
498/* *** CB_xxx message support *** */
499
500
501static LRESULT
502COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
503{
504 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
505 RECT cb_wrect, cbx_wrect, cbx_crect;
506 LRESULT ret = 0;
507 UINT height;
508
509 /* First, lets forward the message to the normal combo control
510 just like Windows. */
511 if (infoPtr->hwndCombo)
512 SendMessageA (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
513
514 /* *** new *** */
515 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
516 GetWindowRect (hwnd, &cbx_wrect);
517 GetClientRect (hwnd, &cbx_crect);
518 /* the height of comboex as height of the combo + comboex border */
519 height = cb_wrect.bottom-cb_wrect.top
520 + cbx_wrect.bottom-cbx_wrect.top
521 - (cbx_crect.bottom-cbx_crect.top);
522 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
523 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
524 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
525 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
526 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
527 cbx_wrect.right-cbx_wrect.left, height);
528 SetWindowPos (hwnd, HWND_TOP, 0, 0,
529 cbx_wrect.right-cbx_wrect.left,
530 height,
531 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
532 /* *** end new *** */
533
534 return ret;
535}
536
537
538/* *** WM_xxx message support *** */
539
540
541static LRESULT
542COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
543{
544 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
545 COMBOEX_INFO *infoPtr;
546 DWORD dwComboStyle;
547 LOGFONTA mylogfont;
548
549 /* allocate memory for info structure */
550 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
551 if (infoPtr == NULL) {
552 ERR("could not allocate info memory!\n");
553 return 0;
554 }
555 infoPtr->items = NULL;
556 infoPtr->nb_items = 0;
557
558 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
559
560
561 /* initialize info structure */
562
563
564 /* create combo box */
565 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
566 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
567
568 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
569 /* following line added to match native */
570 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL | CBS_NOINTEGRALHEIGHT |
571 /* was base and is necessary */
572 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
573 cs->y, cs->x, cs->cx, cs->cy, hwnd, (HMENU)0,
574 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
575
576 /* *** new *** */
577 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont), &mylogfont, 0);
578 infoPtr->font = CreateFontIndirectA (&mylogfont);
579 SendMessageA (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
580 COMBOEX_ReSize (hwnd, infoPtr);
581 /* *** end new *** */
582
583 return 0;
584}
585
586
587inline static LRESULT
588COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
589{
590 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
591 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
592 CBE_ITEMDATA *item;
593 SIZE txtsize;
594 COLORREF nbkc, ntxc;
595 RECT rect;
596 int drawimage;
597 UINT x, xbase, y;
598 UINT xioff = 0; /* size and spacer of image if any */
599 IMAGEINFO iinfo;
600 INT len;
601
602 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
603
604 /* MSDN says: */
605 /* "itemID - Specifies the menu item identifier for a menu */
606 /* item or the index of the item in a list box or combo box. */
607 /* For an empty list box or combo box, this member can be -1. */
608 /* This allows the application to draw only the focus */
609 /* rectangle at the coordinates specified by the rcItem */
610 /* member even though there are no items in the control. */
611 /* This indicates to the user whether the list box or combo */
612 /* box has the focus. How the bits are set in the itemAction */
613 /* member determines whether the rectangle is to be drawn as */
614 /* though the list box or combo box has the focus. */
615 if (dis->itemID == 0xffffffff) {
616 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
617 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
618 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
619 dis->rcItem.left, dis->rcItem.top,
620 dis->rcItem.right, dis->rcItem.bottom);
621 DrawFocusRect(dis->hDC, &dis->rcItem);
622 return 0;
623 }
624 else {
625 TRACE("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
626 dis->rcItem.left, dis->rcItem.top,
627 dis->rcItem.right, dis->rcItem.bottom,
628 dis->itemAction, dis->itemState);
629 return 0;
630 }
631 }
632
633 item = (CBE_ITEMDATA *)SendMessageA (infoPtr->hwndCombo, CB_GETITEMDATA,
634 (WPARAM)dis->itemID, 0);
635 if (item == (CBE_ITEMDATA *)CB_ERR)
636 {
637 FIXME("invalid item for id %d \n",dis->itemID);
638 return 0;
639 }
640 if (!TRACE_ON(message)) {
641 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
642 dis->CtlType, dis->CtlID);
643 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
644 dis->itemID, dis->itemAction, dis->itemState);
645 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
646 dis->hwndItem, dis->hDC, dis->rcItem.left,
647 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
648 dis->itemData);
649 }
650 COMBOEX_DumpItem (item);
651
652 xbase = CBE_STARTOFFSET;
653 if (item->mask & CBEIF_INDENT)
654 xbase += (item->iIndent * CBE_INDENT);
655 if (item->mask & CBEIF_IMAGE) {
656 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
657 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
658 }
659
660 switch (dis->itemAction) {
661 case ODA_FOCUS:
662 if (dis->itemState & ODS_SELECTED /*1*/) {
663 if ((item->mask & CBEIF_TEXT) && item->pszText) {
664 len = strlenW (item->pszText);
665 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
666 rect.left = xbase + xioff - 1;
667 rect.top = dis->rcItem.top - 1 +
668 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
669 rect.right = rect.left + txtsize.cx + 2;
670 rect.bottom = rect.top + txtsize.cy + 2;
671 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
672 dis->itemID, rect.left, rect.top,
673 rect.right, rect.bottom);
674 DrawFocusRect(dis->hDC, &rect);
675 }
676 }
677 break;
678 case ODA_SELECT:
679 case ODA_DRAWENTIRE:
680 drawimage = -1;
681 if (item->mask & CBEIF_IMAGE) drawimage = item->iImage;
682 if ((dis->itemState & ODS_SELECTED) &&
683 (item->mask & CBEIF_SELECTEDIMAGE))
684 drawimage = item->iSelectedImage;
685 if (drawimage != -1) {
686 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
687 xbase, dis->rcItem.top,
688 (dis->itemState & ODS_SELECTED) ?
689 ILD_SELECTED : ILD_NORMAL);
690 }
691 if ((item->mask & CBEIF_TEXT) && item->pszText) {
692 len = strlenW (item->pszText);
693 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
694 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
695 COLOR_HIGHLIGHT : COLOR_WINDOW);
696 SetBkColor (dis->hDC, nbkc);
697 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
698 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
699 SetTextColor (dis->hDC, ntxc);
700 x = xbase + xioff;
701 y = dis->rcItem.top +
702 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
703 rect.left = x;
704 rect.right = x + txtsize.cx;
705 rect.top = y;
706 rect.bottom = y + txtsize.cy;
707 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
708 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
709 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
710 &rect, item->pszText, len, 0);
711 if (dis->itemState & ODS_FOCUS) {
712 rect.top -= 1;
713 rect.bottom += 1;
714 rect.left -= 1;
715 rect.right += 2;
716 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
717 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
718 DrawFocusRect (dis->hDC, &rect);
719 }
720 }
721 break;
722 default:
723 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
724 hwnd, wParam, lParam, dis->itemAction);
725 }
726
727 return 0;
728}
729
730
731static LRESULT
732COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
733{
734 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
735
736 if (infoPtr->hwndCombo)
737 DestroyWindow (infoPtr->hwndCombo);
738
739 if (infoPtr->items) {
740 CBE_ITEMDATA *this, *next;
741
742 this = infoPtr->items;
743 while (this) {
744 next = (CBE_ITEMDATA *)this->next;
745 if ((this->mask & CBEIF_TEXT) && this->pszText)
746 COMCTL32_Free (this->pszText);
747 COMCTL32_Free (this);
748 this = next;
749 }
750 }
751
752 DeleteObject (infoPtr->font);
753
754 /* free comboex info data */
755 COMCTL32_Free (infoPtr);
756 SetWindowLongA (hwnd, 0, 0);
757 return 0;
758}
759
760
761static LRESULT
762COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
763{
764 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
765 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
766 HDC hdc;
767 SIZE mysize;
768
769 hdc = GetDC (0);
770 GetTextExtentPointA (hdc, "W", 1, &mysize);
771 ReleaseDC (0, hdc);
772 mis->itemHeight = mysize.cy + CBE_EXTRA;
773
774 TRACE("adjusted height hwnd=%08x, height=%d\n",
775 hwnd, mis->itemHeight);
776
777 return 0;
778}
779
780
781static LRESULT
782COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
783{
784 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
785 RECT rect;
786
787 GetClientRect (hwnd, &rect);
788
789 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
790 rect.bottom - rect.top, TRUE);
791
792 return 0;
793}
794
795
796static LRESULT
797COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
798{
799 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
800 LRESULT ret;
801 RECT cbx_wrect, cbx_crect, cb_wrect;
802 UINT width;
803 WINDOWPOS *wp = (WINDOWPOS *)lParam;
804
805 ret = DefWindowProcA (hwnd, WM_WINDOWPOSCHANGING, wParam, lParam);
806 GetWindowRect (hwnd, &cbx_wrect);
807 GetClientRect (hwnd, &cbx_crect);
808 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
809
810 /* width is winpos value + border width of comboex */
811 width = wp->cx
812 + cbx_wrect.right-cbx_wrect.left
813 - (cbx_crect.right - cbx_crect.left);
814
815 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
816 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
817 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
818 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
819 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
820 width, cb_wrect.bottom-cb_wrect.top);
821
822 SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
823 width,
824 cb_wrect.bottom-cb_wrect.top,
825 SWP_NOACTIVATE);
826
827 return 0;
828}
829
830
831static LRESULT WINAPI
832COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
833{
834 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
835 if (!COMBOEX_GetInfoPtr (hwnd) && (uMsg != WM_CREATE))
836 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
837
838 switch (uMsg)
839 {
840/* case CBEM_DELETEITEM: */
841
842 case CBEM_GETCOMBOCONTROL:
843 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
844
845 case CBEM_GETEDITCONTROL:
846 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
847
848 case CBEM_GETEXTENDEDSTYLE:
849 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
850
851 case CBEM_GETIMAGELIST:
852 return COMBOEX_GetImageList (hwnd, wParam, lParam);
853
854/* case CBEM_GETITEMA:
855 case CBEM_GETITEMW:
856 case CBEM_GETUNICODEFORMAT:
857 case CBEM_HASEDITCHANGED:
858*/
859
860 case CBEM_INSERTITEMA:
861 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
862
863 case CBEM_INSERTITEMW:
864 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
865
866 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
867 case CBEM_SETEXTENDEDSTYLE:
868 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
869
870 case CBEM_SETIMAGELIST:
871 return COMBOEX_SetImageList (hwnd, wParam, lParam);
872
873 case CBEM_SETITEMA:
874 return COMBOEX_SetItemA (hwnd, wParam, lParam);
875
876 case CBEM_SETITEMW:
877 return COMBOEX_SetItemW (hwnd, wParam, lParam);
878
879/* case CBEM_SETUNICODEFORMAT:
880*/
881
882 case CB_DELETESTRING:
883 case CB_FINDSTRINGEXACT:
884 case CB_GETCOUNT:
885 case CB_GETCURSEL:
886 case CB_GETDROPPEDCONTROLRECT:
887 case CB_GETDROPPEDSTATE:
888 case CB_GETITEMDATA:
889 case CB_GETITEMHEIGHT:
890 case CB_GETLBTEXT:
891 case CB_GETLBTEXTLEN:
892 case CB_GETEXTENDEDUI:
893 case CB_LIMITTEXT:
894 case CB_RESETCONTENT:
895 case CB_SELECTSTRING:
896 case CB_SETCURSEL:
897 case CB_SETDROPPEDWIDTH:
898 case CB_SETEXTENDEDUI:
899 case CB_SETITEMDATA:
900 case CB_SHOWDROPDOWN:
901 case WM_SETTEXT:
902 case WM_GETTEXT:
903 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
904
905 case CB_SETITEMHEIGHT:
906 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
907
908
909 case WM_CREATE:
910 return COMBOEX_Create (hwnd, wParam, lParam);
911
912 case WM_DRAWITEM:
913 return COMBOEX_DrawItem (hwnd, wParam, lParam);
914
915 case WM_DESTROY:
916 return COMBOEX_Destroy (hwnd, wParam, lParam);
917
918 case WM_MEASUREITEM:
919 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
920
921 case WM_SIZE:
922 return COMBOEX_Size (hwnd, wParam, lParam);
923
924 case WM_WINDOWPOSCHANGING:
925 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
926
927 default:
928 if (uMsg >= WM_USER)
929 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
930 uMsg, wParam, lParam);
931#ifdef __WIN32OS2__
932 return defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
933#else
934 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
935#endif
936 }
937 return 0;
938}
939
940
941VOID
942COMBOEX_Register (void)
943{
944 WNDCLASSA wndClass;
945
946 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
947 wndClass.style = CS_GLOBALCLASS;
948 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
949 wndClass.cbClsExtra = 0;
950 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
951 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
952 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
953 wndClass.lpszClassName = WC_COMBOBOXEXA;
954
955 RegisterClassA (&wndClass);
956}
957
958
959VOID
960COMBOEX_Unregister (void)
961{
962 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);
963}
964
Note: See TracBrowser for help on using the repository browser.