source: trunk/src/comctl32/comboex.c

Last change on this file was 10097, checked in by sandervl, 22 years ago

Wine resync

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