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

Last change on this file since 7788 was 7726, checked in by sandervl, 24 years ago

minor updates

File size: 72.9 KB
Line 
1/*
2 * TODO <-------------
3 * 1. The following extended styles need to be implemented, use will
4 * result in a FIXME:
5 * CBES_EX_NOEDITIMAGEINDENT
6 * CBES_EX_PATHWORDBREAKPROC
7 * CBES_EX_NOSIZELIMIT
8 * CBES_EX_CASESENSITIVE
9 * 2. None of the following callback items are implemented. Therefor
10 * no CBEN_GETDISPINFO notifies are issued. Use in either CBEM_INSERTITEM
11 * or CBEM_SETITEM will result in a FIXME:
12 * LPSTR_TEXTCALLBACK
13 * I_IMAGECALLBACK
14 * I_INDENTCALLBACK
15 * 3. No use is made of the iOverlay image.
16 * 4. Notify CBEN_DRAGBEGIN is not implemented.
17 */
18
19
20/*
21 * ComboBoxEx control v2 (mod6)
22 *
23 * Copyright 1998, 1999 Eric Kohl
24 *
25 * NOTES
26 * This is just a dummy control. An author is needed! Any volunteers?
27 * I will only improve this control once in a while.
28 * Eric <ekohl@abo.rhein-zeitung.de>
29 *
30
31 * Changes Guy Albertelli <galberte@neo.lrun.com>
32 * v1 Implemented messages: CB_SETITEMHEIGHT, WM_WINDOWPOSCHANGING,
33 * WM_DRAWITEM, and WM_MEASUREITEM. Fixed WM_CREATE. Fixed height
34 * of window rect reported fixing rebar control.
35 * v2
36 * 1. Rewrite of WM_Create for own created EDIT control. Also try to
37 * generate message sequence similar to native DLL.
38 * 2. Handle case where CBEM_SETITEM is called to display data in EDIT
39 * Control.
40 * 3. Add override for WNDPROC for the EDIT control (reqed for VK_RETURN).
41 * 4. Dump input data for things using COMBOBOXEXITEM{A|W}.
42 * 5. Handle positioning EDIT control based on whether icon present.
43 * 6. Make InsertItemA use InsertItemW, and store all data in ..W form.
44 * 7. Implement CBEM_DELETEITEM, CBEM_GETITEM{A|W}, CB_SETCURSEL,
45 * CBEM_{GET|SET}UNICODEFORMAT.
46 * 8. Add override for WNDPROC for the COMBO control.
47 * 9. Support extended style CBES_EX_NOEDITIMAGE and warn others are not
48 * supported.
49 * 10. Implement CB_FINDSTRINGEXACT in both the Combo and ComboEx window
50 * procs to match the items. This eliminates dup entries in the listbox.
51 *
52 * mod 4
53 * 1. Implemented CBN_SELCHANGE, CBN_KILLFOCUS, and CBN_SELENDOK.
54 * 2. Fix putting text in CBEN_ENDEDIT notifys for CBN_DROPDOWN case.
55 * 3. Lock image selected status to focus state of edit control if
56 * edit control exists. Mimics native actions.
57 * 4. Implemented WM_SETFOCUS in EditWndProc to track status of
58 * focus for 3 above.
59 * 5. The LBN_SELCHANGE is just for documentation purposes.
60 *
61 * mod 5
62 * 1. Add support for CB_GETITEMDATA to a Comboex. Returns the LPARAM
63 * passed during insert of item.
64 * 2. Remember selected item and don't issue CB_SETCURSEL unless needed.
65 * 3. Add initial support for WM_NCCREATE to remove unwanted window styles
66 * (Currently just WS_VSCROLL and WS_HSCROLL, but probably should be
67 * more.)
68 * 4. Improve some traces.
69 * 5. Add support for CB_SETITEMDATA sets LPARAM value from item.
70 *
71 * mod 6
72 * 1. Add support for WM_NOTIFYFORMAT (both incoming and outgoing) and do
73 * WM_NOTIFY correctly based on results.
74 * 2. Fix memory leaks of text strings in COMBOEX_WM_DELETEITEM.
75 * 3. Add routines to handle special cases of NMCBEENDEDIT and NMCOMBOXEX
76 * so translation to ANSI is done correctly.
77 * 4. Fix some issues with COMBOEX_DrawItem.
78 *
79 * Test vehicals were the ControlSpy modules (rebar.exe and comboboxex.exe),
80 * WinRAR, and IE 4.0.
81 *
82 */
83
84#include <string.h>
85#include "winbase.h"
86#include "commctrl.h"
87#include "debugtools.h"
88#include "wine/unicode.h"
89#ifdef __WIN32OS2__
90#include "ccbase.h"
91#define inline
92#endif
93
94DEFAULT_DEBUG_CHANNEL(comboex);
95/*
96 * The following is necessary for the test done in COMBOEX_DrawItem
97 * to determine whether to dump out the DRAWITEM structure or not.
98 */
99DECLARE_DEBUG_CHANNEL(message);
100
101/* Item structure */
102typedef struct
103{
104 VOID *next;
105 UINT mask;
106 LPWSTR pszText;
107 int cchTextMax;
108 int iImage;
109 int iSelectedImage;
110 int iOverlay;
111 int iIndent;
112 LPARAM lParam;
113} CBE_ITEMDATA;
114
115/* ComboBoxEx structure */
116typedef struct
117{
118#ifdef __WIN32OS2__
119 COMCTL32_HEADER header;
120#endif
121 HIMAGELIST himl;
122 HWND hwndSelf; /* my own hwnd */
123 HWND hwndCombo;
124 HWND hwndEdit;
125 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
126 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
127 DWORD dwExtStyle;
128 INT selected; /* index of selected item */
129 DWORD flags; /* WINE internal flags */
130#ifdef __WIN32OS2__
131 HFONT hDefaultFont;
132#endif
133 HFONT font;
134
135 INT nb_items; /* Number of items */
136 BOOL bUnicode; /* TRUE if this window is Unicode */
137 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
138 CBE_ITEMDATA *edit; /* item data for edit item */
139 CBE_ITEMDATA *items; /* Array of items */
140} COMBOEX_INFO;
141
142/* internal flags in the COMBOEX_INFO structure */
143#define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
144 * CBEN_BEGINEDIT issued
145 * but CBEN_ENDEDIT{A|W}
146 * not yet issued. */
147#define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
148#define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
149
150
151#define ID_CB_EDIT 1001
152
153
154/*
155 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
156 * the ComboEx version of the Combo Window Proc so that when the
157 * WM_DRAWITEM message is then passed to ComboEx, we know that this
158 * particular WM_DRAWITEM message is for listbox only items. Any messasges
159 * without this flag is then for the Edit control field.
160 *
161 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
162 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
163 */
164#define ODS_COMBOEXLBOX 0x4000
165
166
167
168/* Height in pixels of control over the amount of the selected font */
169#define CBE_EXTRA 3
170
171/* Indent amount per MS documentation */
172#define CBE_INDENT 10
173
174/* Offset in pixels from left side for start of image or text */
175#define CBE_STARTOFFSET 6
176
177/* Offset between image and text */
178#define CBE_SEP 4
179
180#define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongA (hwnd, 0))
181
182
183/* Things common to the entire DLL */
184static ATOM ComboExInfo;
185static LRESULT WINAPI
186COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
187static LRESULT WINAPI
188COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
189
190static void
191COMBOEX_DumpItem (CBE_ITEMDATA *item)
192{
193 if (TRACE_ON(comboex)){
194 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
195 item, item->mask, item->pszText, item->cchTextMax,
196 item->iImage);
197 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
198 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
199 if ((item->mask & CBEIF_TEXT) && item->pszText)
200 TRACE("item %p - pszText=%s\n",
201 item, debugstr_w((const WCHAR *)item->pszText));
202 }
203}
204
205
206static void
207COMBOEX_DumpInput (COMBOBOXEXITEMA *input, BOOL true_for_w)
208{
209 if (TRACE_ON(comboex)){
210 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
211 input->mask, input->iItem, input->pszText, input->cchTextMax,
212 input->iImage);
213 if ((input->mask & CBEIF_TEXT) && input->pszText) {
214 if (true_for_w)
215 TRACE("input - pszText=<%s>\n",
216 debugstr_w((const WCHAR *)input->pszText));
217 else
218 TRACE("input - pszText=<%s>\n",
219 debugstr_a((const char *)input->pszText));
220 }
221 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
222 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
223 }
224}
225
226
227inline static LRESULT
228COMBOEX_Forward (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
229{
230 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
231
232 if (infoPtr->hwndCombo)
233 return SendMessageA (infoPtr->hwndCombo, uMsg, wParam, lParam);
234
235 return 0;
236}
237
238
239static INT
240COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
241{
242
243 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
244 hdr->hwndFrom = infoPtr->hwndSelf;
245 hdr->code = code;
246 if (infoPtr->NtfUnicode)
247 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
248 (LPARAM)hdr);
249 else
250 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
251 (LPARAM)hdr);
252}
253
254
255static INT
256COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
257{
258
259 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
260
261 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
262 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
263 hdr->hdr.code = code;
264 if (infoPtr->NtfUnicode)
265 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
266 (LPARAM)hdr);
267 else {
268 LPWSTR str, ostr = NULL;
269 INT ret, len = 0;
270
271 if (hdr->ceItem.mask & CBEIF_TEXT) {
272 ostr = hdr->ceItem.pszText;
273 str = ostr;
274 if (!str) str = (LPWSTR)L"";
275 len = WideCharToMultiByte (CP_ACP, 0, str, -1, 0, 0, NULL, NULL);
276 if (len > 0) {
277 hdr->ceItem.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(CHAR));
278 WideCharToMultiByte (CP_ACP, 0, str, -1, (LPSTR)hdr->ceItem.pszText,
279 len, NULL, NULL);
280 }
281 }
282
283 ret = SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
284 (LPARAM)hdr);
285 if (hdr->ceItem.mask & CBEIF_TEXT) {
286 if (len > 0)
287 COMCTL32_Free (hdr->ceItem.pszText);
288 hdr->ceItem.pszText = ostr;
289 }
290 return ret;
291 }
292}
293
294
295static INT
296COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *hdr, LPWSTR itemText)
297{
298
299 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
300
301 hdr->hdr.idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
302 hdr->hdr.hwndFrom = infoPtr->hwndSelf;
303 hdr->hdr.code = (infoPtr->NtfUnicode) ? CBEN_ENDEDITW : CBEN_ENDEDITA;
304 if (infoPtr->NtfUnicode)
305 return SendMessageW (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
306 (LPARAM)hdr);
307 else {
308 NMCBEENDEDITA ansi;
309
310 memcpy (&ansi.hdr, &hdr->hdr, sizeof(NMHDR));
311 ansi.fChanged = hdr->fChanged;
312 ansi.iNewSelection = hdr->iNewSelection;
313 WideCharToMultiByte (CP_ACP, 0, itemText, -1,
314 (LPSTR)&ansi.szText, CBEMAXSTRLEN, NULL, NULL);
315 ansi.iWhy = hdr->iWhy;
316 return SendMessageA (GetParent(infoPtr->hwndSelf), WM_NOTIFY, 0,
317 (LPARAM)&ansi);
318 }
319}
320
321
322static void
323COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
324{
325 HFONT nfont, ofont;
326 HDC mydc;
327
328 mydc = GetDC (0); /* why the entire screen???? */
329 nfont = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
330 ofont = (HFONT) SelectObject (mydc, nfont);
331 GetTextExtentPointA (mydc, "A", 1, size);
332 SelectObject (mydc, ofont);
333 ReleaseDC (0, mydc);
334 TRACE("selected font hwnd=%08x, height=%ld\n", nfont, size->cy);
335}
336
337
338static void
339COMBOEX_CopyItem (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
340{
341 if (cit->mask & CBEIF_TEXT) {
342 cit->pszText = item->pszText;
343 cit->cchTextMax = item->cchTextMax;
344 }
345 if (cit->mask & CBEIF_IMAGE)
346 cit->iImage = item->iImage;
347 if (cit->mask & CBEIF_SELECTEDIMAGE)
348 cit->iSelectedImage = item->iSelectedImage;
349 if (cit->mask & CBEIF_OVERLAY)
350 cit->iOverlay = item->iOverlay;
351 if (cit->mask & CBEIF_INDENT)
352 cit->iIndent = item->iIndent;
353 if (cit->mask & CBEIF_LPARAM)
354 cit->lParam = item->lParam;
355
356}
357
358
359static void
360COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
361{
362 SIZE mysize;
363 IMAGEINFO iinfo;
364 INT x, y, w, h, xoff = 0;
365 RECT rect;
366
367 if (!infoPtr->hwndEdit) return;
368 iinfo.rcImage.left = iinfo.rcImage.right = 0;
369 if (infoPtr->himl) {
370 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
371 xoff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
372 }
373 GetClientRect (infoPtr->hwndCombo, &rect);
374 InflateRect (&rect, -2, -2);
375 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
376
377 /* reposition the Edit control based on whether icon exists */
378 COMBOEX_GetComboFontSize (infoPtr, &mysize);
379 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
380 x = xoff + CBE_STARTOFFSET + 1;
381 y = CBE_EXTRA + 1;
382 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
383 h = mysize.cy + 1;
384
385 TRACE("Combo client (%d,%d)-(%d,%d), setting Edit to (%d,%d)-(%d,%d)\n",
386 rect.left, rect.top, rect.right, rect.bottom,
387 x, y, x + w, y + h);
388 SetWindowPos(infoPtr->hwndEdit, HWND_TOP,
389 x, y,
390 w, h,
391 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
392}
393
394
395static void
396COMBOEX_ReSize (HWND hwnd, COMBOEX_INFO *infoPtr)
397{
398 SIZE mysize;
399 UINT cy;
400 IMAGEINFO iinfo;
401
402 COMBOEX_GetComboFontSize (infoPtr, &mysize);
403 cy = mysize.cy + CBE_EXTRA;
404 if (infoPtr->himl) {
405 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
406 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
407 TRACE("upgraded height due to image: height=%d\n", cy);
408 }
409 SendMessageW (hwnd, CB_SETITEMHEIGHT, (WPARAM) -1, (LPARAM) cy);
410 if (infoPtr->hwndCombo)
411 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
412 (WPARAM) 0, (LPARAM) cy);
413}
414
415
416static void
417COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
418{
419 if (!infoPtr->hwndEdit) return;
420 /* native issues the following messages to the {Edit} control */
421 /* WM_SETTEXT (0,addr) */
422 /* EM_SETSEL32 (0,0) */
423 /* EM_SETSEL32 (0,-1) */
424 if (item->mask & CBEIF_TEXT) {
425 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)item->pszText);
426 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
427 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
428 }
429}
430
431
432static CBE_ITEMDATA *
433COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
434{
435 CBE_ITEMDATA *item;
436 INT i;
437
438 if ((index > infoPtr->nb_items) || (index < -1))
439 return 0;
440 if (index == -1)
441 return infoPtr->edit;
442 item = infoPtr->items;
443 i = infoPtr->nb_items - 1;
444
445 /* find the item in the list */
446 while (item && (i > index)) {
447 item = (CBE_ITEMDATA *)item->next;
448 i--;
449 }
450 if (!item || (i != index)) {
451 FIXME("COMBOBOXEX item structures broken. Please report!\n");
452 return 0;
453 }
454 return item;
455}
456
457
458static void
459COMBOEX_WarnCallBack (CBE_ITEMDATA *item)
460{
461 if (item->pszText == LPSTR_TEXTCALLBACKW)
462 FIXME("Callback not implemented yet for pszText\n");
463 if (item->iImage == I_IMAGECALLBACK)
464 FIXME("Callback not implemented yet for iImage\n");
465 if (item->iSelectedImage == I_IMAGECALLBACK)
466 FIXME("Callback not implemented yet for iSelectedImage\n");
467 if (item->iOverlay == I_IMAGECALLBACK)
468 FIXME("Callback not implemented yet for iOverlay\n");
469 if (item->iIndent == I_INDENTCALLBACK)
470 FIXME("Callback not implemented yet for iIndent\n");
471}
472
473
474/* *** CBEM_xxx message support *** */
475
476
477static LRESULT
478COMBOEX_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
479{
480 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
481 INT index = (INT) wParam;
482 CBE_ITEMDATA *item;
483
484 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
485
486 /* if item number requested does not exist then return failure */
487 if ((index > infoPtr->nb_items) || (index < 0)) {
488 ERR("attempt to delete item that does not exist\n");
489 return CB_ERR;
490 }
491
492 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
493 ERR("attempt to delete item that was not found!\n");
494 return CB_ERR;
495 }
496
497 /* doing this will result in WM_DELETEITEM being issued */
498 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
499
500 return infoPtr->nb_items;
501}
502
503
504inline static LRESULT
505COMBOEX_GetComboControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
506{
507 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
508
509 TRACE("\n");
510
511 return (LRESULT)infoPtr->hwndCombo;
512}
513
514
515inline static LRESULT
516COMBOEX_GetEditControl (HWND hwnd, WPARAM wParam, LPARAM lParam)
517{
518 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
519
520 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
521 return 0;
522
523 TRACE("-- 0x%x\n", infoPtr->hwndEdit);
524
525 return (LRESULT)infoPtr->hwndEdit;
526}
527
528
529inline static LRESULT
530COMBOEX_GetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
531{
532 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
533
534 TRACE("-- 0x%08lx\n", infoPtr->dwExtStyle);
535
536 return (LRESULT)infoPtr->dwExtStyle;
537}
538
539
540inline static LRESULT
541COMBOEX_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
542{
543 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
544
545 TRACE("-- 0x%p\n", infoPtr->himl);
546
547 return (LRESULT)infoPtr->himl;
548}
549
550
551static LRESULT
552COMBOEX_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
553{
554 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
555 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
556 INT index;
557 CBE_ITEMDATA *item;
558
559 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
560
561 /* get real index of item to insert */
562 index = cit->iItem;
563
564 /* if item number requested does not exist then return failure */
565 if ((index > infoPtr->nb_items) || (index < -1)) {
566 ERR("attempt to get item that does not exist\n");
567 return 0;
568 }
569
570 /* if the item is the edit control and there is no edit control, skip */
571 if ((index == -1) &&
572 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
573 return 0;
574
575 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
576 ERR("attempt to get item that was not found!\n");
577 return 0;
578 }
579
580 COMBOEX_CopyItem (infoPtr, item, cit);
581
582 return TRUE;
583}
584
585
586inline static LRESULT
587COMBOEX_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
588{
589 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
590 COMBOBOXEXITEMW tmpcit;
591 INT len;
592
593 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
594
595 tmpcit.mask = cit->mask;
596 tmpcit.iItem = cit->iItem;
597 COMBOEX_GetItemW (hwnd, wParam, (LPARAM) &tmpcit);
598
599 len = WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1, 0, 0, NULL, NULL);
600 if (len > 0)
601 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
602 cit->pszText, cit->cchTextMax, NULL, NULL);
603
604 cit->iImage = tmpcit.iImage;
605 cit->iSelectedImage = tmpcit.iSelectedImage;
606 cit->iOverlay = tmpcit.iOverlay;
607 cit->iIndent = tmpcit.iIndent;
608 cit->lParam = tmpcit.lParam;
609
610 return TRUE;
611}
612
613
614inline static LRESULT
615COMBOEX_GetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
616{
617 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
618
619 TRACE("%s hwnd=0x%x\n",
620 infoPtr->bUnicode ? "TRUE" : "FALSE", hwnd);
621
622 return infoPtr->bUnicode;
623}
624
625
626inline static LRESULT
627COMBOEX_HasEditChanged (HWND hwnd, WPARAM wParam, LPARAM lParam)
628{
629 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
630
631 if ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN)
632 return FALSE;
633 if ((infoPtr->flags & (WCBE_ACTEDIT | WCBE_EDITCHG)) ==
634 (WCBE_ACTEDIT | WCBE_EDITCHG))
635 return TRUE;
636 return FALSE;
637}
638
639
640static LRESULT
641COMBOEX_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
642{
643 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
644 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
645 INT index;
646 CBE_ITEMDATA *item;
647 NMCOMBOBOXEXW nmcit;
648
649 TRACE("\n");
650
651 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
652
653 /* get real index of item to insert */
654 index = cit->iItem;
655 if (index == -1) index = infoPtr->nb_items;
656 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
657
658 /* get space and chain it in */
659 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
660 item->next = NULL;
661 item->pszText = NULL;
662
663 /* locate position to insert new item in */
664 if (index == infoPtr->nb_items) {
665 /* fast path for iItem = -1 */
666 item->next = infoPtr->items;
667 infoPtr->items = item;
668 }
669 else {
670 INT i = infoPtr->nb_items-1;
671 CBE_ITEMDATA *moving = infoPtr->items;
672
673 while ((i > index) && moving) {
674 moving = (CBE_ITEMDATA *)moving->next;
675 i--;
676 }
677 if (!moving) {
678 FIXME("COMBOBOXEX item structures broken. Please report!\n");
679 COMCTL32_Free(item);
680 return -1;
681 }
682 item->next = moving->next;
683 moving->next = item;
684 }
685
686 /* fill in our hidden item structure */
687 item->mask = cit->mask;
688 if (item->mask & CBEIF_TEXT) {
689 LPWSTR str;
690 INT len;
691
692 str = cit->pszText;
693 if (!str) str = (LPWSTR) L"";
694 len = strlenW (str);
695 if (len > 0) {
696 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
697 strcpyW (item->pszText, str);
698 }
699 else
700 item->pszText = NULL;
701 item->cchTextMax = cit->cchTextMax;
702 }
703 if (item->mask & CBEIF_IMAGE)
704 item->iImage = cit->iImage;
705 if (item->mask & CBEIF_SELECTEDIMAGE)
706 item->iSelectedImage = cit->iSelectedImage;
707 if (item->mask & CBEIF_OVERLAY)
708 item->iOverlay = cit->iOverlay;
709 if (item->mask & CBEIF_INDENT)
710 item->iIndent = cit->iIndent;
711 if (item->mask & CBEIF_LPARAM)
712 item->lParam = cit->lParam;
713 infoPtr->nb_items++;
714
715 COMBOEX_WarnCallBack (item);
716
717 COMBOEX_DumpItem (item);
718
719 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
720 (WPARAM)cit->iItem, (LPARAM)item);
721
722 COMBOEX_CopyItem (infoPtr, item, &nmcit.ceItem);
723 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
724
725 return index;
726
727}
728
729
730static LRESULT
731COMBOEX_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
732{
733 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
734 COMBOBOXEXITEMW citW;
735 LRESULT ret;
736
737 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
738 if (cit->mask & CBEIF_TEXT) {
739 LPSTR str;
740 INT len;
741
742 str = cit->pszText;
743 if (!str) str="";
744 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
745 if (len > 0) {
746 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
747 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
748 }
749 }
750 ret = COMBOEX_InsertItemW(hwnd,wParam,(LPARAM)&citW);;
751
752 if (cit->mask & CBEIF_TEXT)
753 COMCTL32_Free(citW.pszText);
754 return ret;
755}
756
757
758static LRESULT
759COMBOEX_SetExtendedStyle (HWND hwnd, WPARAM wParam, LPARAM lParam)
760{
761 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
762 DWORD dwTemp;
763
764 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
765
766 dwTemp = infoPtr->dwExtStyle;
767
768 if (lParam & (CBES_EX_NOEDITIMAGEINDENT |
769 CBES_EX_PATHWORDBREAKPROC |
770 CBES_EX_NOSIZELIMIT |
771 CBES_EX_CASESENSITIVE))
772 FIXME("Extended style not implemented %08lx\n", lParam);
773
774 if ((DWORD)wParam) {
775 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~(DWORD)wParam) | (DWORD)lParam;
776 }
777 else
778 infoPtr->dwExtStyle = (DWORD)lParam;
779
780 /*
781 * native does this for CBES_EX_NOEDITIMAGE state change
782 */
783 if ((infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE) ^
784 (dwTemp & CBES_EX_NOEDITIMAGE)) {
785 /* if state of EX_NOEDITIMAGE changes, invalidate all */
786 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
787 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
788 InvalidateRect (hwnd, NULL, TRUE);
789 COMBOEX_AdjustEditPos (infoPtr);
790 if (infoPtr->hwndEdit)
791 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
792 }
793
794 return (LRESULT)dwTemp;
795}
796
797
798inline static LRESULT
799COMBOEX_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
800{
801 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
802 HIMAGELIST himlTemp;
803
804 TRACE("(0x%08x 0x%08lx)\n", wParam, lParam);
805
806 himlTemp = infoPtr->himl;
807 infoPtr->himl = (HIMAGELIST)lParam;
808
809 COMBOEX_ReSize (hwnd, infoPtr);
810 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
811
812 /* reposition the Edit control based on whether icon exists */
813 COMBOEX_AdjustEditPos (infoPtr);
814 return (LRESULT)himlTemp;
815}
816
817static LRESULT
818COMBOEX_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
819{
820 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
821 COMBOBOXEXITEMW *cit = (COMBOBOXEXITEMW *) lParam;
822 INT index;
823 CBE_ITEMDATA *item;
824
825 COMBOEX_DumpInput ((COMBOBOXEXITEMA *) cit, TRUE);
826
827 /* get real index of item to insert */
828 index = cit->iItem;
829
830 /* if item number requested does not exist then return failure */
831 if ((index > infoPtr->nb_items) || (index < -1)) {
832 ERR("attempt to set item that does not exist yet!\n");
833 return 0;
834 }
835
836 /* if the item is the edit control and there is no edit control, skip */
837 if ((index == -1) &&
838 ((GetWindowLongA (hwnd, GWL_STYLE) & CBS_DROPDOWNLIST) != CBS_DROPDOWN))
839 return 0;
840
841 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
842 ERR("attempt to set item that was not found!\n");
843 return 0;
844 }
845
846 /* add/change stuff to the internal item structure */
847 item->mask |= cit->mask;
848 if (cit->mask & CBEIF_TEXT) {
849 LPWSTR str;
850 INT len;
851 WCHAR emptystr[1] = {0};
852
853 str = cit->pszText;
854 if (!str) str=emptystr;
855 len = strlenW(str);
856 if (len > 0) {
857 item->pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
858 strcpyW(item->pszText,str);
859 }
860 item->cchTextMax = cit->cchTextMax;
861 }
862 if (cit->mask & CBEIF_IMAGE)
863 item->iImage = cit->iImage;
864 if (cit->mask & CBEIF_SELECTEDIMAGE)
865 item->iSelectedImage = cit->iSelectedImage;
866 if (cit->mask & CBEIF_OVERLAY)
867 item->iOverlay = cit->iOverlay;
868 if (cit->mask & CBEIF_INDENT)
869 item->iIndent = cit->iIndent;
870 if (cit->mask & CBEIF_LPARAM)
871 cit->lParam = cit->lParam;
872
873 COMBOEX_WarnCallBack (item);
874
875 COMBOEX_DumpItem (item);
876
877 /* if original request was to update edit control, do some fast foot work */
878 if (cit->iItem == -1) {
879 COMBOEX_SetEditText (infoPtr, item);
880 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
881 }
882 return TRUE;
883}
884
885static LRESULT
886COMBOEX_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
887{
888 COMBOBOXEXITEMA *cit = (COMBOBOXEXITEMA *) lParam;
889 COMBOBOXEXITEMW citW;
890 LRESULT ret;
891
892 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
893 if (cit->mask & CBEIF_TEXT) {
894 LPSTR str;
895 INT len;
896
897 str = cit->pszText;
898 if (!str) str="";
899 len = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
900 if (len > 0) {
901 citW.pszText = (LPWSTR)COMCTL32_Alloc ((len + 1)*sizeof(WCHAR));
902 MultiByteToWideChar (CP_ACP, 0, str, -1, citW.pszText, len);
903 }
904 }
905 ret = COMBOEX_SetItemW(hwnd,wParam,(LPARAM)&citW);;
906
907 if (cit->mask & CBEIF_TEXT)
908 COMCTL32_Free(citW.pszText);
909 return ret;
910}
911
912
913inline static LRESULT
914COMBOEX_SetUnicodeFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
915{
916 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
917 BOOL bTemp = infoPtr->bUnicode;
918
919 TRACE("to %s hwnd=0x%04x, was %s\n",
920 ((BOOL)wParam) ? "TRUE" : "FALSE", hwnd,
921 (bTemp) ? "TRUE" : "FALSE");
922
923 infoPtr->bUnicode = (BOOL)wParam;
924
925 return bTemp;
926}
927
928
929
930/* *** CB_xxx message support *** */
931
932
933static LRESULT
934COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
935{
936 INT i, count;
937 CBE_ITEMDATA *item;
938 LPWSTR desired = NULL;
939 INT start = (INT) wParam;
940
941 i = MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0);
942 if (i > 0) {
943 desired = (LPWSTR)COMCTL32_Alloc ((i + 1)*sizeof(WCHAR));
944 MultiByteToWideChar (CP_ACP, 0, (LPSTR)lParam, -1, desired, i);
945 }
946
947 count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0 , 0);
948
949 /* now search from after starting loc and wrapping back to start */
950 for(i=start+1; i<count; i++) {
951 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
952 CB_GETITEMDATA, (WPARAM)i, 0);
953 TRACE("desired=%s, item=%s\n",
954 debugstr_w(desired), debugstr_w(item->pszText));
955 if (lstrcmpiW(item->pszText, desired) == 0) {
956 COMCTL32_Free (desired);
957 return i;
958 }
959 }
960 for(i=0; i<=start; i++) {
961 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
962 CB_GETITEMDATA, (WPARAM)i, 0);
963 TRACE("desired=%s, item=%s\n",
964 debugstr_w(desired), debugstr_w(item->pszText));
965 if (lstrcmpiW(item->pszText, desired) == 0) {
966 COMCTL32_Free (desired);
967 return i;
968 }
969 }
970 COMCTL32_Free(desired);
971 return CB_ERR;
972}
973
974
975static LRESULT
976COMBOEX_GetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
977{
978 INT index = wParam;
979 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
980 CBE_ITEMDATA *item1, *item2;
981 LRESULT lret = 0;
982
983 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
984 wParam, lParam);
985 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
986 item2 = COMBOEX_FindItem (infoPtr, index);
987 if (item2 != item1) {
988 ERR("data structures damaged!\n");
989 return CB_ERR;
990 }
991 if (item1->mask & CBEIF_LPARAM)
992 lret = (LRESULT) item1->lParam;
993 TRACE("returning 0x%08lx\n", lret);
994 return lret;
995 }
996 lret = (LRESULT)item1;
997 TRACE("non-valid result from combo, returning 0x%08lx\n", lret);
998 return lret;
999}
1000
1001
1002static LRESULT
1003COMBOEX_SetCursel (HWND hwnd, WPARAM wParam, LPARAM lParam)
1004{
1005 INT index = wParam;
1006 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1007 CBE_ITEMDATA *item;
1008 LRESULT lret;
1009
1010 if (!(item = COMBOEX_FindItem(infoPtr, index))) {
1011 /* FIXME: need to clear selection */
1012 return CB_ERR;
1013 }
1014
1015 TRACE("selecting item %d text=%s\n", index, (item->pszText) ?
1016 debugstr_w(item->pszText) : "<null>");
1017 infoPtr->selected = index;
1018
1019 lret = SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, wParam, lParam);
1020 COMBOEX_SetEditText (infoPtr, item);
1021 return lret;
1022}
1023
1024
1025static LRESULT
1026COMBOEX_SetItemData (HWND hwnd, WPARAM wParam, LPARAM lParam)
1027{
1028 INT index = wParam;
1029 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1030 CBE_ITEMDATA *item1, *item2;
1031
1032 item1 = (CBE_ITEMDATA *)COMBOEX_Forward (hwnd, CB_GETITEMDATA,
1033 wParam, lParam);
1034 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
1035 item2 = COMBOEX_FindItem (infoPtr, index);
1036 if (item2 != item1) {
1037 ERR("data structures damaged!\n");
1038 return CB_ERR;
1039 }
1040 item1->mask |= CBEIF_LPARAM;
1041 item1->lParam = lParam;
1042 TRACE("setting lparam to 0x%08lx\n", lParam);
1043 return 0;
1044 }
1045 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
1046 return (LRESULT)item1;
1047}
1048
1049
1050static LRESULT
1051COMBOEX_SetItemHeight (HWND hwnd, WPARAM wParam, LPARAM lParam)
1052{
1053 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1054 RECT cb_wrect, cbx_wrect, cbx_crect;
1055 LRESULT ret = 0;
1056 UINT height;
1057
1058 /* First, lets forward the message to the normal combo control
1059 just like Windows. */
1060 if (infoPtr->hwndCombo)
1061 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT, wParam, lParam);
1062
1063 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1064 GetWindowRect (hwnd, &cbx_wrect);
1065 GetClientRect (hwnd, &cbx_crect);
1066 /* the height of comboex as height of the combo + comboex border */
1067 height = cb_wrect.bottom-cb_wrect.top
1068 + cbx_wrect.bottom-cbx_wrect.top
1069 - (cbx_crect.bottom-cbx_crect.top);
1070 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1071 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1072 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1073 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1074 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1075 cbx_wrect.right-cbx_wrect.left, height);
1076 SetWindowPos (hwnd, HWND_TOP, 0, 0,
1077 cbx_wrect.right-cbx_wrect.left,
1078 height,
1079 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1080
1081 return ret;
1082}
1083
1084
1085/* *** WM_xxx message support *** */
1086
1087
1088static LRESULT
1089COMBOEX_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1090{
1091 LPCREATESTRUCTA cs = (LPCREATESTRUCTA) lParam;
1092 COMBOEX_INFO *infoPtr;
1093 DWORD dwComboStyle;
1094 LOGFONTA mylogfont;
1095 CBE_ITEMDATA *item;
1096 RECT wnrc1, clrc1, cmbwrc;
1097 LONG test;
1098 INT i;
1099
1100 /* allocate memory for info structure */
1101#ifdef __WIN32OS2__
1102 infoPtr = (COMBOEX_INFO*)initControl(hwnd,sizeof(COMBOEX_INFO));
1103#else
1104 infoPtr = (COMBOEX_INFO *)COMCTL32_Alloc (sizeof(COMBOEX_INFO));
1105#endif
1106 if (infoPtr == NULL) {
1107 ERR("could not allocate info memory!\n");
1108 return 0;
1109 }
1110
1111 /* initialize info structure */
1112
1113 infoPtr->items = NULL;
1114 infoPtr->nb_items = 0;
1115 infoPtr->hwndSelf = hwnd;
1116 infoPtr->selected = -1;
1117
1118 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1119
1120 i = SendMessageA(GetParent (hwnd),
1121 WM_NOTIFYFORMAT, hwnd, NF_QUERY);
1122 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1123 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1124 i);
1125 i = NFR_ANSI;
1126 }
1127 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1128
1129 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1130
1131 /* create combo box */
1132 dwComboStyle = GetWindowLongA (hwnd, GWL_STYLE) &
1133 (CBS_SIMPLE|CBS_DROPDOWN|CBS_DROPDOWNLIST|WS_CHILD);
1134
1135 GetWindowRect(hwnd, &wnrc1);
1136 GetClientRect(hwnd, &clrc1);
1137 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d)\n",
1138 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1139 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
1140 TRACE("combo style=%08lx, adding style=%08lx\n", dwComboStyle,
1141 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1142 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1143 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED);
1144
1145 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
1146 /* specified. It then creates it's own version of the EDIT control */
1147 /* and makes the ComboBox the parent. This is because a normal */
1148 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
1149 /* We also need to place the edit control at the proper location */
1150 /* (allow space for the icons). */
1151
1152 infoPtr->hwndCombo = CreateWindowA ("ComboBox", "",
1153 /* following line added to match native */
1154 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
1155 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
1156 /* was base and is necessary */
1157 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED | dwComboStyle,
1158 cs->y, cs->x, cs->cx, cs->cy, hwnd,
1159 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1160 GetWindowLongA (hwnd, GWL_HINSTANCE), NULL);
1161
1162 /*
1163 * native does the following at this point according to trace:
1164 * GetWindowThreadProcessId(hwndCombo,0)
1165 * GetCurrentThreadId()
1166 * GetWindowThreadProcessId(hwndCombo, &???)
1167 * GetCurrentProcessId()
1168 */
1169
1170 /*
1171 * Setup a property to hold the pointer to the COMBOBOXEX
1172 * data structure.
1173 */
1174 test = GetPropA(infoPtr->hwndCombo, (LPCSTR)(LONG)ComboExInfo);
1175 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1176 SetPropA(infoPtr->hwndCombo, "CC32SubclassInfo", (LONG)infoPtr);
1177 }
1178 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndCombo,
1179 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
1180 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1181
1182
1183 /*
1184 * Now create our own EDIT control so we can position it.
1185 * It is created only for CBS_DROPDOWN style
1186 */
1187 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
1188 infoPtr->hwndEdit = CreateWindowExA (0, "EDIT", "",
1189 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
1190 0, 0, 0, 0, /* will set later */
1191 infoPtr->hwndCombo,
1192 (HMENU) GetWindowLongA (hwnd, GWL_ID),
1193 GetWindowLongA (hwnd, GWL_HINSTANCE),
1194 NULL);
1195
1196 /* native does the following at this point according to trace:
1197 * GetWindowThreadProcessId(hwndEdit,0)
1198 * GetCurrentThreadId()
1199 * GetWindowThreadProcessId(hwndEdit, &???)
1200 * GetCurrentProcessId()
1201 */
1202
1203 /*
1204 * Setup a property to hold the pointer to the COMBOBOXEX
1205 * data structure.
1206 */
1207 test = GetPropA(infoPtr->hwndEdit, (LPCSTR)(LONG)ComboExInfo);
1208 if (!test || ((COMBOEX_INFO *)test != infoPtr)) {
1209 SetPropA(infoPtr->hwndEdit, "CC32SubclassInfo", (LONG)infoPtr);
1210 }
1211 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongA(infoPtr->hwndEdit,
1212 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
1213 infoPtr->font = SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
1214 }
1215 else {
1216 infoPtr->hwndEdit = 0;
1217 infoPtr->font = 0;
1218 }
1219
1220 /*
1221 * Locate the default font if necessary and then set it in
1222 * all associated controls
1223 */
1224 if (!infoPtr->font) {
1225 SystemParametersInfoA (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
1226 &mylogfont, 0);
1227#ifdef __WIN32OS2__
1228 infoPtr->font = infoPtr->hDefaultFont = CreateFontIndirectA (&mylogfont);
1229#else
1230 infoPtr->font = CreateFontIndirectA (&mylogfont);
1231#endif
1232 }
1233 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1234 if (infoPtr->hwndEdit) {
1235 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1236 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
1237 }
1238
1239 COMBOEX_ReSize (hwnd, infoPtr);
1240
1241 /* Above is fairly certain, below is much less certain. */
1242
1243 GetWindowRect(hwnd, &wnrc1);
1244 GetClientRect(hwnd, &clrc1);
1245 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1246 TRACE("EX window=(%d,%d)-(%d,%d) client=(%d,%d)-(%d,%d) CB wnd=(%d,%d)-(%d,%d)\n",
1247 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1248 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1249 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1250 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
1251 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1252 SWP_NOACTIVATE | SWP_NOREDRAW);
1253
1254 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
1255 TRACE("CB window=(%d,%d)-(%d,%d)\n",
1256 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
1257 SetWindowPos(hwnd, HWND_TOP,
1258 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1259 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1260
1261 COMBOEX_AdjustEditPos (infoPtr);
1262
1263 /*
1264 * Create an item structure to represent the data in the
1265 * EDIT control.
1266 */
1267 item = (CBE_ITEMDATA *)COMCTL32_Alloc (sizeof (CBE_ITEMDATA));
1268 item->next = NULL;
1269 item->pszText = NULL;
1270 item->mask = 0;
1271 infoPtr->edit = item;
1272
1273 return 0;
1274}
1275
1276
1277inline static LRESULT
1278COMBOEX_Command (HWND hwnd, WPARAM wParam, LPARAM lParam)
1279{
1280 LRESULT lret;
1281 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1282 INT command = HIWORD(wParam);
1283 CBE_ITEMDATA *item = 0;
1284 WCHAR wintext[520];
1285 INT cursel, n, oldItem;
1286 NMCBEENDEDITW cbeend;
1287 DWORD oldflags;
1288
1289 TRACE("for command %d\n", command);
1290
1291 switch (command)
1292 {
1293 case CBN_DROPDOWN:
1294 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1295 (LPARAM)hwnd);
1296 /*
1297 * from native trace of first dropdown after typing in URL in IE4
1298 * CB_GETCURSEL(Combo)
1299 * GetWindowText(Edit)
1300 * CB_GETCURSEL(Combo)
1301 * CB_GETCOUNT(Combo)
1302 * CB_GETITEMDATA(Combo, n)
1303 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1304 * CB_GETCURSEL(Combo)
1305 * CB_SETCURSEL(COMBOEX, n)
1306 * SetFocus(Combo)
1307 * the rest is supposition
1308 */
1309 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1310 if (cursel == -1) {
1311 /* find match from edit against those in Combobox */
1312 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1313 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1314 for (cursel = 0; cursel < n; cursel++){
1315 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1316 CB_GETITEMDATA,
1317 cursel, 0);
1318 if ((INT)item == CB_ERR) break;
1319 if (lstrcmpiW(item->pszText, wintext) == 0) break;
1320 }
1321 if ((cursel == n) || ((INT)item == CB_ERR)) {
1322 TRACE("failed to find match??? item=%p cursel=%d\n",
1323 item, cursel);
1324 if (infoPtr->hwndEdit)
1325 SetFocus(infoPtr->hwndEdit);
1326 return 0;
1327 }
1328 }
1329 else {
1330 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1331 CB_GETITEMDATA,
1332 cursel, 0);
1333 if ((INT)item == CB_ERR) {
1334 TRACE("failed to find match??? item=%p cursel=%d\n",
1335 item, cursel);
1336 if (infoPtr->hwndEdit)
1337 SetFocus(infoPtr->hwndEdit);
1338 return 0;
1339 }
1340 }
1341
1342 /* Save flags for testing and reset them */
1343 oldflags = infoPtr->flags;
1344 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1345
1346 if (oldflags & WCBE_ACTEDIT) {
1347 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
1348 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1349 CB_GETCURSEL, 0, 0);
1350 cbeend.iWhy = CBENF_DROPDOWN;
1351
1352 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, item->pszText)) {
1353 /* abort the change */
1354 TRACE("Notify requested abort of change\n");
1355 return 0;
1356 }
1357 }
1358
1359 /* if selection has changed the set the new current selection */
1360 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1361 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1362 infoPtr->selected = cursel;
1363 SendMessageW (hwnd, CB_SETCURSEL, cursel, 0);
1364 SetFocus(infoPtr->hwndCombo);
1365 }
1366 return 0;
1367
1368 case CBN_SELCHANGE:
1369 /*
1370 * CB_GETCURSEL(Combo)
1371 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1372 * lstrlenA
1373 * WM_SETTEXT(Edit)
1374 * WM_GETTEXTLENGTH(Edit)
1375 * WM_GETTEXT(Edit)
1376 * EM_SETSEL(Edit, 0,0)
1377 * WM_GETTEXTLENGTH(Edit)
1378 * WM_GETTEXT(Edit)
1379 * EM_SETSEL(Edit, 0,len)
1380 * return WM_COMMAND to parent
1381 */
1382 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1383 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1384 ERR("item %d not found. Problem!\n", oldItem);
1385 break;
1386 }
1387 infoPtr->selected = oldItem;
1388 COMBOEX_SetEditText (infoPtr, item);
1389 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1390 (LPARAM)hwnd);
1391
1392 case CBN_SELENDOK:
1393 /*
1394 * We have to change the handle since we are the control
1395 * issuing the message. IE4 depends on this.
1396 */
1397 return SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1398 (LPARAM)hwnd);
1399
1400 case CBN_KILLFOCUS:
1401 /*
1402 * from native trace:
1403 *
1404 * pass to parent
1405 * WM_GETTEXT(Edit, 104)
1406 * CB_GETCURSEL(Combo) rets -1
1407 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1408 * CB_GETCURSEL(Combo)
1409 * InvalidateRect(Combo, 0, 0)
1410 * return 0
1411 */
1412 SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1413 (LPARAM)hwnd);
1414 if (infoPtr->flags & WCBE_ACTEDIT) {
1415 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
1416 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1417 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1418 CB_GETCURSEL, 0, 0);
1419 cbeend.iWhy = CBENF_KILLFOCUS;
1420
1421 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1422 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) {
1423 /* abort the change */
1424 TRACE("Notify requested abort of change\n");
1425 return 0;
1426 }
1427 }
1428 /* possible CB_GETCURSEL */
1429 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1430 return 0;
1431
1432 case CBN_CLOSEUP:
1433 default:
1434 /*
1435 * We have to change the handle since we are the control
1436 * issuing the message. IE4 depends on this.
1437 * We also need to set the focus back to the Edit control
1438 * after passing the command to the parent of the ComboEx.
1439 */
1440 lret = SendMessageW (GetParent (hwnd), WM_COMMAND, wParam,
1441 (LPARAM)hwnd);
1442 if (infoPtr->hwndEdit)
1443 SetFocus(infoPtr->hwndEdit);
1444 return lret;
1445 }
1446 return 0;
1447}
1448
1449
1450inline static LRESULT
1451COMBOEX_WM_DeleteItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1452{
1453 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1454 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)lParam;
1455 CBE_ITEMDATA *item, *olditem;
1456 INT i;
1457 NMCOMBOBOXEXW nmcit;
1458
1459 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%x, data=%08lx\n",
1460 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1461
1462 if ((dis->itemID >= infoPtr->nb_items) || (dis->itemID < 0)) return FALSE;
1463
1464 olditem = infoPtr->items;
1465 i = infoPtr->nb_items - 1;
1466
1467 if (i == dis->itemID) {
1468 infoPtr->items = infoPtr->items->next;
1469 }
1470 else {
1471 item = olditem;
1472 i--;
1473
1474 /* find the prior item in the list */
1475 while (item->next && (i > dis->itemID)) {
1476 item = (CBE_ITEMDATA *)item->next;
1477 i--;
1478 }
1479 if (!item->next || (i != dis->itemID)) {
1480 FIXME("COMBOBOXEX item structures broken. Please report!\n");
1481 return FALSE;
1482 }
1483 olditem = item->next;
1484 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1485 }
1486 infoPtr->nb_items--;
1487
1488 COMBOEX_CopyItem (infoPtr, olditem, &nmcit.ceItem);
1489 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
1490
1491 if (olditem->pszText)
1492 COMCTL32_Free(olditem->pszText);
1493 COMCTL32_Free(olditem);
1494
1495 return TRUE;
1496
1497}
1498
1499
1500inline static LRESULT
1501COMBOEX_DrawItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1502{
1503 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1504 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
1505 CBE_ITEMDATA *item = 0;
1506 SIZE txtsize;
1507 RECT rect;
1508 LPWSTR str;
1509 int drawimage, drawstate;
1510 UINT xbase, x, y;
1511 UINT xioff = 0; /* size and spacer of image if any */
1512 IMAGEINFO iinfo;
1513 INT len;
1514 COLORREF nbkc, ntxc;
1515
1516 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1517
1518 /* dump the DRAWITEMSTRUCT if tracing "comboex" but not "message" */
1519 if (!TRACE_ON(message)) {
1520 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
1521 dis->CtlType, dis->CtlID);
1522 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
1523 dis->itemID, dis->itemAction, dis->itemState);
1524 TRACE("hWnd=0x%04x hDC=0x%04x (%d,%d)-(%d,%d) itemData=0x%08lx\n",
1525 dis->hwndItem, dis->hDC, dis->rcItem.left,
1526 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
1527 dis->itemData);
1528 }
1529
1530 /* MSDN says: */
1531 /* "itemID - Specifies the menu item identifier for a menu */
1532 /* item or the index of the item in a list box or combo box. */
1533 /* For an empty list box or combo box, this member can be -1. */
1534 /* This allows the application to draw only the focus */
1535 /* rectangle at the coordinates specified by the rcItem */
1536 /* member even though there are no items in the control. */
1537 /* This indicates to the user whether the list box or combo */
1538 /* box has the focus. How the bits are set in the itemAction */
1539 /* member determines whether the rectangle is to be drawn as */
1540 /* though the list box or combo box has the focus. */
1541 if (dis->itemID == 0xffffffff) {
1542 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
1543 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
1544
1545 TRACE("drawing item -1 special focus, rect=(%d,%d)-(%d,%d)\n",
1546 dis->rcItem.left, dis->rcItem.top,
1547 dis->rcItem.right, dis->rcItem.bottom);
1548 }
1549 else if ((dis->CtlType == ODT_COMBOBOX) &&
1550 (dis->itemAction == ODA_DRAWENTIRE)) {
1551 /* draw of edit control data */
1552
1553 /* testing */
1554 {
1555 RECT exrc, cbrc, edrc;
1556 GetWindowRect (hwnd, &exrc);
1557 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1558 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1559 if (infoPtr->hwndEdit)
1560 GetWindowRect (infoPtr->hwndEdit, &edrc);
1561 TRACE("window rects ex=(%d,%d)-(%d,%d), cb=(%d,%d)-(%d,%d), ed=(%d,%d)-(%d,%d)\n",
1562 exrc.left, exrc.top, exrc.right, exrc.bottom,
1563 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1564 edrc.left, edrc.top, edrc.right, edrc.bottom);
1565 }
1566 }
1567 else {
1568 ERR("NOT drawing item -1 special focus, rect=(%d,%d)-(%d,%d), action=%08x, state=%08x\n",
1569 dis->rcItem.left, dis->rcItem.top,
1570 dis->rcItem.right, dis->rcItem.bottom,
1571 dis->itemAction, dis->itemState);
1572 return 0;
1573 }
1574 }
1575
1576 /* If draw item is -1 (edit control) setup the item pointer */
1577 if (dis->itemID == 0xffffffff) {
1578 CHAR str[260];
1579 INT wlen, alen;
1580
1581 item = infoPtr->edit;
1582
1583 if (infoPtr->hwndEdit) {
1584
1585 /* free previous text of edit item */
1586 if (item->pszText) {
1587 COMCTL32_Free(item->pszText);
1588 item->pszText = 0;
1589 item->mask &= ~CBEIF_TEXT;
1590 }
1591 alen = SendMessageA (infoPtr->hwndEdit, WM_GETTEXT, 260, (LPARAM)&str);
1592 TRACE("edit control hwndEdit=%0x, text len=%d str=<%s>\n",
1593 infoPtr->hwndEdit, alen, str);
1594 if (alen > 0) {
1595 item->mask |= CBEIF_TEXT;
1596 wlen = MultiByteToWideChar (CP_ACP, 0, str, -1, NULL, 0);
1597 if (wlen > 0) {
1598 item->pszText = (LPWSTR)COMCTL32_Alloc ((wlen + 1)*sizeof(WCHAR));
1599 MultiByteToWideChar (CP_ACP, 0, str, -1, item->pszText, wlen);
1600 }
1601 }
1602 }
1603 }
1604
1605 /* if the item pointer is not set, then get the data and locate it */
1606 if (!item) {
1607 item = (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo,
1608 CB_GETITEMDATA, (WPARAM)dis->itemID, 0);
1609 if (item == (CBE_ITEMDATA *)CB_ERR)
1610 {
1611 FIXME("invalid item for id %d \n",dis->itemID);
1612 return 0;
1613 }
1614 }
1615
1616 COMBOEX_DumpItem (item);
1617
1618 xbase = CBE_STARTOFFSET;
1619 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX))
1620 xbase += (item->iIndent * CBE_INDENT);
1621 if (item->mask & CBEIF_IMAGE) {
1622 ImageList_GetImageInfo(infoPtr->himl, item->iImage, &iinfo);
1623 xioff = (iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP);
1624 }
1625
1626 switch (dis->itemAction) {
1627 case ODA_FOCUS:
1628 if (dis->itemState & ODS_SELECTED /*1*/) {
1629 if ((item->mask & CBEIF_TEXT) && item->pszText) {
1630 RECT rect2;
1631
1632 len = strlenW (item->pszText);
1633 GetTextExtentPointW (dis->hDC, item->pszText, len, &txtsize);
1634 rect.left = xbase + xioff - 1;
1635 rect.right = rect.left + txtsize.cx + 2;
1636 rect.top = dis->rcItem.top;
1637 rect.bottom = dis->rcItem.bottom;
1638 GetClipBox (dis->hDC, &rect2);
1639 TRACE("drawing item %d focus, rect=(%d,%d)-(%d,%d)\n",
1640 dis->itemID, rect.left, rect.top,
1641 rect.right, rect.bottom);
1642 TRACE(" clip=(%d,%d)-(%d,%d)\n",
1643 rect2.left, rect2.top,
1644 rect2.right, rect2.bottom);
1645
1646 DrawFocusRect(dis->hDC, &rect);
1647 }
1648 else {
1649 FIXME("ODA_FOCUS and ODS_SELECTED but no text\n");
1650 }
1651 }
1652 else {
1653 FIXME("ODA_FOCUS but not ODS_SELECTED\n");
1654 }
1655 break;
1656 case ODA_SELECT:
1657 case ODA_DRAWENTIRE:
1658 drawimage = -1;
1659 drawstate = ILD_NORMAL;
1660 if (!(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE)) {
1661 if (item->mask & CBEIF_IMAGE)
1662 drawimage = item->iImage;
1663 if (dis->itemState & ODS_COMBOEXLBOX) {
1664 /* drawing listbox entry */
1665 if (dis->itemState & ODS_SELECTED) {
1666 if (item->mask & CBEIF_SELECTEDIMAGE)
1667 drawimage = item->iSelectedImage;
1668 drawstate = ILD_SELECTED;
1669 }
1670 }
1671 else {
1672 /* drawing combo/edit entry */
1673 if (infoPtr->hwndEdit) {
1674 /* if we have an edit control, the slave the
1675 * selection state to the Edit focus state
1676 */
1677 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1678 if (item->mask & CBEIF_SELECTEDIMAGE)
1679 drawimage = item->iSelectedImage;
1680 drawstate = ILD_SELECTED;
1681 }
1682 }
1683 else {
1684 /* if we don't have an edit control, use
1685 * the requested state.
1686 */
1687 if (dis->itemState & ODS_SELECTED) {
1688 if (item->mask & CBEIF_SELECTEDIMAGE)
1689 drawimage = item->iSelectedImage;
1690 drawstate = ILD_SELECTED;
1691 }
1692 }
1693 }
1694 }
1695 if (drawimage != -1) {
1696 TRACE("drawing image state=%d\n", dis->itemState & ODS_SELECTED);
1697 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC,
1698 xbase, dis->rcItem.top, drawstate);
1699 }
1700
1701 /* setup pointer to text to be drawn */
1702 if ((item->mask & CBEIF_TEXT) && item->pszText)
1703 str = item->pszText;
1704 else
1705 str = (LPWSTR) L"";
1706
1707 /* now draw the text */
1708 len = lstrlenW (str);
1709 GetTextExtentPointW (dis->hDC, str, len, &txtsize);
1710 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1711 COLOR_HIGHLIGHT : COLOR_WINDOW);
1712 SetBkColor (dis->hDC, nbkc);
1713 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1714 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1715 SetTextColor (dis->hDC, ntxc);
1716 x = xbase + xioff;
1717 y = dis->rcItem.top +
1718 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1719 rect.left = x;
1720 rect.right = x + txtsize.cx;
1721 rect.top = dis->rcItem.top + 1;
1722 rect.bottom = dis->rcItem.bottom - 1;
1723 TRACE("drawing item %d text, rect=(%d,%d)-(%d,%d)\n",
1724 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1725 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1726 &rect, str, len, 0);
1727 if (dis->itemState & ODS_FOCUS) {
1728 rect.top -= 1;
1729 rect.bottom += 1;
1730 rect.left -= 1;
1731 rect.right += 1;
1732 TRACE("drawing item %d focus after text, rect=(%d,%d)-(%d,%d)\n",
1733 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1734 DrawFocusRect (dis->hDC, &rect);
1735 }
1736 break;
1737 default:
1738 FIXME("unknown action hwnd=%08x, wparam=%08x, lparam=%08lx, action=%d\n",
1739 hwnd, wParam, lParam, dis->itemAction);
1740 }
1741
1742 return 0;
1743}
1744
1745
1746static LRESULT
1747COMBOEX_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1748{
1749 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1750
1751 if (infoPtr->hwndCombo)
1752 DestroyWindow (infoPtr->hwndCombo);
1753
1754 if (infoPtr->edit) {
1755 COMCTL32_Free (infoPtr->edit);
1756 infoPtr->edit = 0;
1757 }
1758
1759 if (infoPtr->items) {
1760 CBE_ITEMDATA *this, *next;
1761
1762 this = infoPtr->items;
1763 while (this) {
1764 next = (CBE_ITEMDATA *)this->next;
1765 if ((this->mask & CBEIF_TEXT) && this->pszText)
1766 COMCTL32_Free (this->pszText);
1767 COMCTL32_Free (this);
1768 this = next;
1769 }
1770 }
1771
1772#ifdef __WIN32OS2__
1773 //NEVER delete the font object received by WM_SETFONT!
1774 if (infoPtr->hDefaultFont) DeleteObject (infoPtr->hDefaultFont);
1775#else
1776 DeleteObject (infoPtr->font);
1777#endif
1778
1779 /* free comboex info data */
1780 COMCTL32_Free (infoPtr);
1781 SetWindowLongA (hwnd, 0, 0);
1782 return 0;
1783}
1784
1785
1786static LRESULT
1787COMBOEX_MeasureItem (HWND hwnd, WPARAM wParam, LPARAM lParam)
1788{
1789 /*COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);*/
1790 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *) lParam;
1791 HDC hdc;
1792 SIZE mysize;
1793
1794 hdc = GetDC (0);
1795 GetTextExtentPointA (hdc, "W", 1, &mysize);
1796 ReleaseDC (0, hdc);
1797 mis->itemHeight = mysize.cy + CBE_EXTRA;
1798
1799 TRACE("adjusted height hwnd=%08x, height=%d\n",
1800 hwnd, mis->itemHeight);
1801
1802 return 0;
1803}
1804
1805
1806static LRESULT
1807COMBOEX_NCCreate (HWND hwnd, WPARAM wParam, LPARAM lParam)
1808{
1809 /* WARNING: The COMBOEX_INFO structure is not yet created */
1810 DWORD oldstyle, newstyle;
1811
1812 oldstyle = (DWORD)GetWindowLongA (hwnd, GWL_STYLE);
1813 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1814 if (newstyle != oldstyle) {
1815 TRACE("req style %08lx, reseting style %08lx\n",
1816 oldstyle, newstyle);
1817 SetWindowLongA (hwnd, GWL_STYLE, newstyle);
1818 }
1819 return 1;
1820}
1821
1822
1823static LRESULT
1824COMBOEX_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1825{
1826 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1827 INT i;
1828
1829 if (lParam == NF_REQUERY) {
1830 i = SendMessageA(GetParent (hwnd),
1831 WM_NOTIFYFORMAT, infoPtr->hwndSelf, NF_QUERY);
1832 if ((i < NFR_ANSI) || (i > NFR_UNICODE)) {
1833 ERR("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n",
1834 i);
1835 i = NFR_ANSI;
1836 }
1837 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
1838 return (LRESULT)i;
1839 }
1840 return (LRESULT)((infoPtr->bUnicode) ? NFR_UNICODE : NFR_ANSI);
1841}
1842
1843
1844static LRESULT
1845COMBOEX_Size (HWND hwnd, WPARAM wParam, LPARAM lParam)
1846{
1847 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1848 RECT rect;
1849
1850 GetWindowRect (hwnd, &rect);
1851 TRACE("my rect (%d,%d)-(%d,%d)\n",
1852 rect.left, rect.top, rect.right, rect.bottom);
1853
1854 MoveWindow (infoPtr->hwndCombo, 0, 0, rect.right -rect.left,
1855 rect.bottom - rect.top, TRUE);
1856
1857 COMBOEX_AdjustEditPos (infoPtr);
1858
1859 return 0;
1860}
1861
1862
1863static LRESULT
1864COMBOEX_WindowPosChanging (HWND hwnd, WPARAM wParam, LPARAM lParam)
1865{
1866 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
1867 RECT cbx_wrect, cbx_crect, cb_wrect;
1868 UINT width, height;
1869 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1870
1871 GetWindowRect (hwnd, &cbx_wrect);
1872 GetClientRect (hwnd, &cbx_crect);
1873 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1874
1875 /* width is winpos value + border width of comboex */
1876 width = wp->cx
1877 + (cbx_wrect.right-cbx_wrect.left)
1878 - (cbx_crect.right-cbx_crect.left);
1879
1880 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1881 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
1882 TRACE("EX window=(%d,%d)-(%d,%d), client=(%d,%d)-(%d,%d)\n",
1883 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1884 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
1885 TRACE("CB window=(%d,%d)-(%d,%d), EX setting=(0,0)-(%d,%d)\n",
1886 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1887 width, cb_wrect.bottom-cb_wrect.top);
1888
1889 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1890 width,
1891 cb_wrect.bottom-cb_wrect.top,
1892 SWP_NOACTIVATE);
1893
1894 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1895
1896 /* height is combo window height plus border width of comboex */
1897 height = (cb_wrect.bottom-cb_wrect.top)
1898 + (cbx_wrect.bottom-cbx_wrect.top)
1899 - (cbx_crect.bottom-cbx_crect.top);
1900 if (wp->cy < height) wp->cy = height;
1901 if (infoPtr->hwndEdit) {
1902 COMBOEX_AdjustEditPos (infoPtr);
1903 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1904 }
1905
1906 return 0;
1907}
1908
1909
1910static LRESULT WINAPI
1911COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1912{
1913 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
1914 NMCBEENDEDITW cbeend;
1915 WCHAR edit_text[260];
1916 COLORREF nbkc, obkc;
1917 HDC hDC;
1918 RECT rect;
1919 LRESULT lret;
1920
1921 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
1922 hwnd, uMsg, wParam, lParam, infoPtr);
1923
1924 if (!infoPtr) return 0;
1925
1926 switch (uMsg)
1927 {
1928
1929 case WM_CHAR:
1930 /* handle (ignore) the return character */
1931 if (wParam == VK_RETURN) return 0;
1932 /* all other characters pass into the real Edit */
1933 return CallWindowProcA (infoPtr->prevEditWndProc,
1934 hwnd, uMsg, wParam, lParam);
1935
1936 case WM_ERASEBKGND:
1937 /*
1938 * The following was determined by traces of the native
1939 */
1940 hDC = (HDC) wParam;
1941 nbkc = GetSysColor (COLOR_WINDOW);
1942 obkc = SetBkColor (hDC, nbkc);
1943 GetClientRect (hwnd, &rect);
1944 TRACE("erasing (%d,%d)-(%d,%d)\n",
1945 rect.left, rect.top, rect.right, rect.bottom);
1946 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1947 SetBkColor (hDC, obkc);
1948 return CallWindowProcA (infoPtr->prevEditWndProc,
1949 hwnd, uMsg, wParam, lParam);
1950
1951 case WM_KEYDOWN: {
1952 INT oldItem, selected;
1953 CBE_ITEMDATA *item;
1954
1955 switch ((INT)wParam)
1956 {
1957 case VK_ESCAPE:
1958 /* native version seems to do following for COMBOEX */
1959 /*
1960 * GetWindowTextA(Edit,&?, 0x104) x
1961 * CB_GETCURSEL to Combo rets -1 x
1962 * WM_NOTIFY to COMBOEX parent (rebar) x
1963 * (CBEN_ENDEDIT{A|W}
1964 * fChanged = FALSE x
1965 * inewSelection = -1 x
1966 * txt="www.hoho" x
1967 * iWhy = 3 x
1968 * CB_GETCURSEL to Combo rets -1 x
1969 * InvalidateRect(Combo, 0) x
1970 * WM_SETTEXT to Edit x
1971 * EM_SETSEL to Edit (0,0) x
1972 * EM_SETSEL to Edit (0,-1) x
1973 * RedrawWindow(Combo, 0, 0, 5) x
1974 */
1975 TRACE("special code for VK_ESCAPE\n");
1976
1977 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1978
1979 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1980 cbeend.fChanged = FALSE;
1981 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1982 CB_GETCURSEL, 0, 0);
1983 cbeend.iWhy = CBENF_ESCAPE;
1984
1985 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
1986 /* abort the change */
1987 TRACE("Notify requested abort of change\n");
1988 return 0;
1989 }
1990 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1991 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1992 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1993 ERR("item %d not found. Problem!\n", oldItem);
1994 break;
1995 }
1996 infoPtr->selected = oldItem;
1997 COMBOEX_SetEditText (infoPtr, item);
1998 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
1999 RDW_INVALIDATE);
2000 break;
2001
2002 case VK_RETURN:
2003 /* native version seems to do following for COMBOEX */
2004 /*
2005 * GetWindowTextA(Edit,&?, 0x104) x
2006 * CB_GETCURSEL to Combo rets -1 x
2007 * CB_GETCOUNT to Combo rets 0
2008 * if >0 loop
2009 * CB_GETITEMDATA to match
2010 * *** above 3 lines simulated by FindItem x
2011 * WM_NOTIFY to COMBOEX parent (rebar) x
2012 * (CBEN_ENDEDIT{A|W} x
2013 * fChanged = TRUE (-1) x
2014 * iNewSelection = -1 or selected x
2015 * txt= x
2016 * iWhy = 2 (CBENF_RETURN) x
2017 * CB_GETCURSEL to Combo rets -1 x
2018 * if -1 send CB_SETCURSEL to Combo -1 x
2019 * InvalidateRect(Combo, 0, 0) x
2020 * SetFocus(Edit) x
2021 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
2022 */
2023
2024 TRACE("special code for VK_RETURN\n");
2025
2026 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2027
2028 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2029 selected = SendMessageW (infoPtr->hwndCombo,
2030 CB_GETCURSEL, 0, 0);
2031
2032 if (selected != -1) {
2033 item = COMBOEX_FindItem (infoPtr, selected);
2034 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
2035 selected, debugstr_w(item->pszText));
2036 TRACE("handling VK_RETURN, edittext=%s\n",
2037 debugstr_w(edit_text));
2038 if (lstrcmpiW (item->pszText, edit_text)) {
2039 /* strings not equal -- indicate edit has changed */
2040 selected = -1;
2041 }
2042 }
2043
2044 cbeend.iNewSelection = selected;
2045 cbeend.fChanged = TRUE;
2046 cbeend.iWhy = CBENF_RETURN;
2047 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2048 /* abort the change, restore previous */
2049 TRACE("Notify requested abort of change\n");
2050 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
2051 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
2052 RDW_INVALIDATE);
2053 return 0;
2054 }
2055 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
2056 if (oldItem != -1) {
2057 /* if something is selected, then deselect it */
2058 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
2059 (WPARAM)-1, 0);
2060 }
2061 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2062 SetFocus(infoPtr->hwndEdit);
2063 break;
2064
2065 default:
2066 return CallWindowProcA (infoPtr->prevEditWndProc,
2067 hwnd, uMsg, wParam, lParam);
2068 }
2069 return 0;
2070 }
2071
2072 case WM_SETFOCUS:
2073 /* remember the focus to set state of icon */
2074 lret = CallWindowProcA (infoPtr->prevEditWndProc,
2075 hwnd, uMsg, wParam, lParam);
2076 infoPtr->flags |= WCBE_EDITFOCUSED;
2077 return lret;
2078
2079 case WM_KILLFOCUS:
2080 /*
2081 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
2082 */
2083 infoPtr->flags &= ~WCBE_EDITFOCUSED;
2084 if (infoPtr->flags & WCBE_ACTEDIT) {
2085 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2086
2087 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2088 cbeend.fChanged = FALSE;
2089 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2090 CB_GETCURSEL, 0, 0);
2091 cbeend.iWhy = CBENF_KILLFOCUS;
2092
2093 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
2094 }
2095 /* fall through */
2096
2097 default:
2098 return CallWindowProcA (infoPtr->prevEditWndProc,
2099 hwnd, uMsg, wParam, lParam);
2100 }
2101 return 0;
2102}
2103
2104
2105static LRESULT WINAPI
2106COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2107{
2108 COMBOEX_INFO *infoPtr = (COMBOEX_INFO *)GetPropA (hwnd, (LPCSTR)(LONG) ComboExInfo);
2109 NMCBEENDEDITW cbeend;
2110 NMMOUSE nmmse;
2111 COLORREF nbkc, obkc;
2112 HDC hDC;
2113 HWND focusedhwnd;
2114 RECT rect;
2115 WCHAR edit_text[260];
2116
2117 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
2118 hwnd, uMsg, wParam, lParam, infoPtr);
2119
2120 if (!infoPtr) return 0;
2121
2122 switch (uMsg)
2123 {
2124
2125 case CB_FINDSTRINGEXACT:
2126 return COMBOEX_FindStringExact (infoPtr, wParam, lParam);
2127
2128 case WM_DRAWITEM:
2129 /*
2130 * The only way this message should come is from the
2131 * child Listbox issuing the message. Flag this so
2132 * that ComboEx knows this is listbox.
2133 */
2134 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
2135 return CallWindowProcA (infoPtr->prevComboWndProc,
2136 hwnd, uMsg, wParam, lParam);
2137
2138 case WM_ERASEBKGND:
2139 /*
2140 * The following was determined by traces of the native
2141 */
2142 hDC = (HDC) wParam;
2143 nbkc = GetSysColor (COLOR_WINDOW);
2144 obkc = SetBkColor (hDC, nbkc);
2145 GetClientRect (hwnd, &rect);
2146 TRACE("erasing (%d,%d)-(%d,%d)\n",
2147 rect.left, rect.top, rect.right, rect.bottom);
2148 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
2149 SetBkColor (hDC, obkc);
2150 return CallWindowProcA (infoPtr->prevComboWndProc,
2151 hwnd, uMsg, wParam, lParam);
2152
2153 case WM_SETCURSOR:
2154 /*
2155 * WM_NOTIFY to comboex parent (rebar)
2156 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
2157 * CallWindowProc (previous)
2158 */
2159 nmmse.dwItemSpec = 0;
2160 nmmse.dwItemData = 0;
2161 nmmse.pt.x = 0;
2162 nmmse.pt.y = 0;
2163 nmmse.dwHitInfo = lParam;
2164 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
2165 return CallWindowProcA (infoPtr->prevComboWndProc,
2166 hwnd, uMsg, wParam, lParam);
2167
2168 case WM_COMMAND:
2169 switch (HIWORD(wParam)) {
2170
2171 case EN_UPDATE:
2172 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
2173 * on the EN_UPDATE
2174 */
2175 return 0;
2176
2177 case EN_KILLFOCUS:
2178 /*
2179 * Native does:
2180 *
2181 * GetFocus() retns AA
2182 * GetWindowTextA(Edit)
2183 * CB_GETCURSEL(Combo) (got -1)
2184 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
2185 * CB_GETCURSEL(Combo) (got -1)
2186 * InvalidateRect(Combo, 0, 0)
2187 * WM_KILLFOCUS(Combo, AA)
2188 * return 0;
2189 */
2190 focusedhwnd = GetFocus();
2191 if (infoPtr->flags & WCBE_ACTEDIT) {
2192 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2193 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2194 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2195 CB_GETCURSEL, 0, 0);
2196 cbeend.iWhy = CBENF_KILLFOCUS;
2197
2198 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
2199 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
2200 /* abort the change */
2201 TRACE("Notify requested abort of change\n");
2202 return 0;
2203 }
2204 }
2205 /* possible CB_GETCURSEL */
2206 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2207 if (focusedhwnd)
2208 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
2209 (WPARAM)focusedhwnd, 0);
2210 return 0;
2211
2212 case EN_SETFOCUS: {
2213 /*
2214 * For EN_SETFOCUS this issues the same calls and messages
2215 * as the native seems to do.
2216 *
2217 * for some cases however native does the following:
2218 * (noticed after SetFocus during LBUTTONDOWN on
2219 * on dropdown arrow)
2220 * WM_GETTEXTLENGTH (Edit);
2221 * WM_GETTEXT (Edit, len+1, str);
2222 * EM_SETSEL (Edit, 0, 0);
2223 * WM_GETTEXTLENGTH (Edit);
2224 * WM_GETTEXT (Edit, len+1, str);
2225 * EM_SETSEL (Edit, 0, len);
2226 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
2227 */
2228 NMHDR hdr;
2229
2230 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2231 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
2232 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
2233 infoPtr->flags |= WCBE_ACTEDIT;
2234 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
2235 return 0;
2236 }
2237
2238 case EN_CHANGE: {
2239 /*
2240 * For EN_CHANGE this issues the same calls and messages
2241 * as the native seems to do.
2242 */
2243 WCHAR edit_text[260];
2244 WCHAR *lastwrk;
2245 INT selected, cnt;
2246 CBE_ITEMDATA *item;
2247
2248 selected = SendMessageW (infoPtr->hwndCombo,
2249 CB_GETCURSEL, 0, 0);
2250
2251 /* lstrlenA( lastworkingURL ) */
2252
2253 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2254 if (selected == -1) {
2255 lastwrk = infoPtr->edit->pszText;
2256 cnt = lstrlenW (lastwrk);
2257 if (cnt >= 259) cnt = 259;
2258 }
2259 else {
2260 item = COMBOEX_FindItem (infoPtr, selected);
2261 cnt = lstrlenW (item->pszText);
2262 lastwrk = item->pszText;
2263 if (cnt >= 259) cnt = 259;
2264 }
2265
2266 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
2267 selected, debugstr_w(lastwrk));
2268 TRACE("handling EN_CHANGE, edittext=%s\n",
2269 debugstr_w(edit_text));
2270
2271 /* lstrcmpiW is between lastworkingURL and GetWindowText */
2272
2273 if (lstrcmpiW (lastwrk, edit_text)) {
2274 /* strings not equal -- indicate edit has changed */
2275 infoPtr->flags |= WCBE_EDITCHG;
2276 }
2277 SendMessageW ( GetParent(infoPtr->hwndSelf), WM_COMMAND,
2278 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2279 CBN_EDITCHANGE),
2280 infoPtr->hwndSelf);
2281 return 0;
2282 }
2283
2284 case LBN_SELCHANGE:
2285 /*
2286 * Therefore from traces there is no additional code here
2287 */
2288
2289 /*
2290 * Using native COMCTL32 gets the following:
2291 * 1 == SHDOCVW.DLL issues call/message
2292 * 2 == COMCTL32.DLL issues call/message
2293 * 3 == WINE issues call/message
2294 *
2295 *
2296 * for LBN_SELCHANGE:
2297 * 1 CB_GETCURSEL(ComboEx)
2298 * 1 CB_GETDROPPEDSTATE(ComboEx)
2299 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2300 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2301 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2302 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2303 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2304 * 3 ShowWindow(ComboLB, SW_HIDE)
2305 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2306 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2307 ** end of CBRollUp
2308 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2309 * ? LB_GETCURSEL <==|
2310 * ? LB_GETTEXTLEN |
2311 * ? LB_GETTEXT | Needs to be added to
2312 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2313 * ? LB_GETITEMDATA |
2314 * ? WM_DRAWITEM(ComboEx) <==|
2315 */
2316 default:
2317 break;
2318 }/* fall through */
2319 default:
2320 return CallWindowProcA (infoPtr->prevComboWndProc,
2321 hwnd, uMsg, wParam, lParam);
2322 }
2323 return 0;
2324}
2325
2326
2327static LRESULT WINAPI
2328COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2329{
2330 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2331
2332 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
2333
2334 if (!COMBOEX_GetInfoPtr (hwnd)) {
2335 if (uMsg == WM_CREATE)
2336 return COMBOEX_Create (hwnd, wParam, lParam);
2337 if (uMsg == WM_NCCREATE)
2338 COMBOEX_NCCreate (hwnd, wParam, lParam);
2339 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2340 }
2341
2342 switch (uMsg)
2343 {
2344 case CBEM_DELETEITEM: /* maps to CB_DELETESTRING */
2345 return COMBOEX_DeleteItem (hwnd, wParam, lParam);
2346
2347 case CBEM_GETCOMBOCONTROL:
2348 return COMBOEX_GetComboControl (hwnd, wParam, lParam);
2349
2350 case CBEM_GETEDITCONTROL:
2351 return COMBOEX_GetEditControl (hwnd, wParam, lParam);
2352
2353 case CBEM_GETEXTENDEDSTYLE:
2354 return COMBOEX_GetExtendedStyle (hwnd, wParam, lParam);
2355
2356 case CBEM_GETIMAGELIST:
2357 return COMBOEX_GetImageList (hwnd, wParam, lParam);
2358
2359 case CBEM_GETITEMA:
2360 return COMBOEX_GetItemA (hwnd, wParam, lParam);
2361
2362 case CBEM_GETITEMW:
2363 return COMBOEX_GetItemW (hwnd, wParam, lParam);
2364
2365 case CBEM_GETUNICODEFORMAT:
2366 return COMBOEX_GetUnicodeFormat (hwnd, wParam, lParam);
2367
2368 case CBEM_HASEDITCHANGED:
2369 return COMBOEX_HasEditChanged (hwnd, wParam, lParam);
2370
2371 case CBEM_INSERTITEMA:
2372 return COMBOEX_InsertItemA (hwnd, wParam, lParam);
2373
2374 case CBEM_INSERTITEMW:
2375 return COMBOEX_InsertItemW (hwnd, wParam, lParam);
2376
2377 case CBEM_SETEXSTYLE: /* FIXME: obsoleted, should be the same as: */
2378 case CBEM_SETEXTENDEDSTYLE:
2379 return COMBOEX_SetExtendedStyle (hwnd, wParam, lParam);
2380
2381 case CBEM_SETIMAGELIST:
2382 return COMBOEX_SetImageList (hwnd, wParam, lParam);
2383
2384 case CBEM_SETITEMA:
2385 return COMBOEX_SetItemA (hwnd, wParam, lParam);
2386
2387 case CBEM_SETITEMW:
2388 return COMBOEX_SetItemW (hwnd, wParam, lParam);
2389
2390 case CBEM_SETUNICODEFORMAT:
2391 return COMBOEX_SetUnicodeFormat (hwnd, wParam, lParam);
2392
2393
2394/* Combo messages we are not sure if we need to process or just forward */
2395 case CB_GETDROPPEDCONTROLRECT:
2396 case CB_GETITEMHEIGHT:
2397 case CB_GETLBTEXT:
2398 case CB_GETLBTEXTLEN:
2399 case CB_GETEXTENDEDUI:
2400 case CB_LIMITTEXT:
2401 case CB_RESETCONTENT:
2402 case CB_SELECTSTRING:
2403 case WM_SETTEXT:
2404 case WM_GETTEXT:
2405 FIXME("(0x%x 0x%x 0x%lx): possibly missing function\n",
2406 uMsg, wParam, lParam);
2407 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2408
2409/* Combo messages OK to just forward to the regular COMBO */
2410 case CB_GETCOUNT:
2411 case CB_GETCURSEL:
2412 case CB_GETDROPPEDSTATE:
2413 case CB_SETDROPPEDWIDTH:
2414 case CB_SETEXTENDEDUI:
2415 case CB_SHOWDROPDOWN:
2416 return COMBOEX_Forward (hwnd, uMsg, wParam, lParam);
2417
2418/* Combo messages we need to process specially */
2419 case CB_FINDSTRINGEXACT:
2420 return COMBOEX_FindStringExact (COMBOEX_GetInfoPtr (hwnd),
2421 wParam, lParam);
2422
2423 case CB_GETITEMDATA:
2424 return COMBOEX_GetItemData (hwnd, wParam, lParam);
2425
2426 case CB_SETCURSEL:
2427 return COMBOEX_SetCursel (hwnd, wParam, lParam);
2428
2429 case CB_SETITEMDATA:
2430 return COMBOEX_SetItemData (hwnd, wParam, lParam);
2431
2432 case CB_SETITEMHEIGHT:
2433 return COMBOEX_SetItemHeight (hwnd, wParam, lParam);
2434
2435
2436
2437/* Window messages passed to parent */
2438 case WM_COMMAND:
2439 return COMBOEX_Command (hwnd, wParam, lParam);
2440
2441 case WM_NOTIFY:
2442 if (infoPtr->NtfUnicode)
2443 return SendMessageW (GetParent (hwnd),
2444 uMsg, wParam, lParam);
2445 else
2446 return SendMessageA (GetParent (hwnd),
2447 uMsg, wParam, lParam);
2448
2449
2450/* Window messages we need to process */
2451 case WM_DELETEITEM:
2452 return COMBOEX_WM_DeleteItem (hwnd, wParam, lParam);
2453
2454 case WM_DRAWITEM:
2455 return COMBOEX_DrawItem (hwnd, wParam, lParam);
2456
2457 case WM_DESTROY:
2458 return COMBOEX_Destroy (hwnd, wParam, lParam);
2459
2460 case WM_MEASUREITEM:
2461 return COMBOEX_MeasureItem (hwnd, wParam, lParam);
2462
2463 case WM_NOTIFYFORMAT:
2464 return COMBOEX_NotifyFormat (hwnd, wParam, lParam);
2465
2466 case WM_SIZE:
2467 return COMBOEX_Size (hwnd, wParam, lParam);
2468
2469 case WM_WINDOWPOSCHANGING:
2470 return COMBOEX_WindowPosChanging (hwnd, wParam, lParam);
2471
2472 default:
2473 if (uMsg >= WM_USER)
2474 ERR("unknown msg %04x wp=%08x lp=%08lx\n",
2475 uMsg, wParam, lParam);
2476#ifdef __WIN32OS2__
2477 return defComCtl32ProcA (hwnd, uMsg, wParam, lParam);
2478#else
2479 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2480#endif
2481 }
2482 return 0;
2483}
2484
2485
2486VOID
2487COMBOEX_Register (void)
2488{
2489 WNDCLASSA wndClass;
2490
2491 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
2492 wndClass.style = CS_GLOBALCLASS;
2493 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
2494 wndClass.cbClsExtra = 0;
2495 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
2496 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
2497 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
2498 wndClass.lpszClassName = WC_COMBOBOXEXA;
2499
2500 RegisterClassA (&wndClass);
2501
2502 ComboExInfo = GlobalAddAtomA("CC32SubclassInfo");
2503}
2504
2505
2506VOID
2507COMBOEX_Unregister (void)
2508{
2509 UnregisterClassA (WC_COMBOBOXEXA, (HINSTANCE)NULL);
2510}
2511
Note: See TracBrowser for help on using the repository browser.