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

Last change on this file since 6644 was 6644, checked in by bird, 24 years ago

Added $Id:$ keyword.

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