blob: 3b1a0b548a75a5ee224fa51cb98f57d5a756572a [file] [log] [blame]
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001/*
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002 * ComboBoxEx control
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00003 *
4 * Copyright 1998, 1999 Eric Kohl
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00005 * Copyright 2000, 2001, 2002 Guy Albertelli <galberte@neo.lrun.com>
6 * Copyright 2002 Dimitrie O. Paun
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 *
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.
12 *
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.
17 *
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
21 *
Dimitrie O. Paunda9bac42002-10-16 18:57:14 +000022 * 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 *
Robert Shearman3c6956d2004-03-11 00:39:53 +000027 * Unless otherwise noted, we believe this code to be complete, as per
Dimitrie O. Paunda9bac42002-10-16 18:57:14 +000028 * the specification mentioned above.
29 * If you discover missing features, or bugs, please note them below.
30 *
Alexandre Julliarda0d77311998-09-13 16:32:00 +000031 */
32
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000033#include <stdarg.h>
Jeff Garzik9fd15a92001-03-22 19:33:57 +000034#include <string.h>
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000035#include "windef.h"
Marcus Meissner3480e4a1999-03-16 10:53:11 +000036#include "winbase.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000037#include "wingdi.h"
38#include "winuser.h"
39#include "winnls.h"
Alexandre Julliarda0d77311998-09-13 16:32:00 +000040#include "commctrl.h"
Alexandre Julliardf5cb3dd2003-09-17 20:15:21 +000041#include "comctl32.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000042#include "wine/debug.h"
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000043#include "wine/unicode.h"
Alexandre Julliarda0d77311998-09-13 16:32:00 +000044
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000045WINE_DEFAULT_DEBUG_CHANNEL(comboex);
Alexandre Julliard70c9e092000-08-09 00:41:17 +000046
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000047/* Item structure */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000048typedef struct
49{
Guy L. Albertellia2495952001-01-26 21:00:10 +000050 VOID *next;
51 UINT mask;
52 LPWSTR pszText;
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +000053 LPWSTR pszTemp;
Guy L. Albertellia2495952001-01-26 21:00:10 +000054 int cchTextMax;
55 int iImage;
56 int iSelectedImage;
57 int iOverlay;
58 int iIndent;
59 LPARAM lParam;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000060} CBE_ITEMDATA;
61
62/* ComboBoxEx structure */
63typedef struct
64{
65 HIMAGELIST himl;
Guy L. Albertellia2495952001-01-26 21:00:10 +000066 HWND hwndSelf; /* my own hwnd */
Dimitrie O. Paunc5940432003-11-20 22:04:13 +000067 HWND hwndNotify; /* my parent hwnd */
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000068 HWND hwndCombo;
Guy L. Albertellia2495952001-01-26 21:00:10 +000069 HWND hwndEdit;
70 WNDPROC prevEditWndProc; /* previous Edit WNDPROC value */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +000071 WNDPROC prevComboWndProc; /* previous Combo WNDPROC value */
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000072 DWORD dwExtStyle;
Guy L. Albertellibad75902001-04-20 18:27:19 +000073 INT selected; /* index of selected item */
Guy L. Albertellia2495952001-01-26 21:00:10 +000074 DWORD flags; /* WINE internal flags */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +000075 HFONT defaultFont;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000076 HFONT font;
77 INT nb_items; /* Number of items */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +000078 BOOL unicode; /* TRUE if this window is Unicode */
79 BOOL NtfUnicode; /* TRUE if parent wants notify in Unicode */
Guy L. Albertellia2495952001-01-26 21:00:10 +000080 CBE_ITEMDATA *edit; /* item data for edit item */
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +000081 CBE_ITEMDATA *items; /* Array of items */
Alexandre Julliard70c9e092000-08-09 00:41:17 +000082} COMBOEX_INFO;
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000083
Guy L. Albertellia2495952001-01-26 21:00:10 +000084/* internal flags in the COMBOEX_INFO structure */
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +000085#define WCBE_ACTEDIT 0x00000001 /* Edit active i.e.
Guy L. Albertellia2495952001-01-26 21:00:10 +000086 * CBEN_BEGINEDIT issued
87 * but CBEN_ENDEDIT{A|W}
88 * not yet issued. */
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +000089#define WCBE_EDITCHG 0x00000002 /* Edit issued EN_CHANGE */
Dimitrie O. Paun43230a22002-04-08 20:16:01 +000090#define WCBE_EDITHASCHANGED (WCBE_ACTEDIT | WCBE_EDITCHG)
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +000091#define WCBE_EDITFOCUSED 0x00000004 /* Edit control has focus */
92#define WCBE_MOUSECAPTURED 0x00000008 /* Combo has captured mouse */
93#define WCBE_MOUSEDRAGGED 0x00000010 /* User has dragged in combo */
Guy L. Albertellia2495952001-01-26 21:00:10 +000094
Dimitrie O. Paun43230a22002-04-08 20:16:01 +000095#define ID_CB_EDIT 1001
Alexandre Julliarda0d77311998-09-13 16:32:00 +000096
Guy L. Albertelli45e6f622001-02-20 01:53:43 +000097
98/*
99 * Special flag set in DRAWITEMSTRUCT itemState field. It is set by
Vincent Béron9a624912002-05-31 23:06:46 +0000100 * the ComboEx version of the Combo Window Proc so that when the
101 * WM_DRAWITEM message is then passed to ComboEx, we know that this
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000102 * particular WM_DRAWITEM message is for listbox only items. Any messasges
103 * without this flag is then for the Edit control field.
104 *
Vincent Béron9a624912002-05-31 23:06:46 +0000105 * We really cannot use the ODS_COMBOBOXEDIT flag because MSDN states that
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000106 * only version 4.0 applications will have ODS_COMBOBOXEDIT set.
107 */
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000108#define ODS_COMBOEXLBOX 0x4000
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000109
110
111
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000112/* Height in pixels of control over the amount of the selected font */
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000113#define CBE_EXTRA 3
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000114
115/* Indent amount per MS documentation */
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000116#define CBE_INDENT 10
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000117
118/* Offset in pixels from left side for start of image or text */
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000119#define CBE_STARTOFFSET 6
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000120
121/* Offset between image and text */
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000122#define CBE_SEP 4
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000123
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000124#define COMBOEX_SUBCLASS_PROP "CCComboEx32SubclassInfo"
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000125#define COMBOEX_GetInfoPtr(hwnd) ((COMBOEX_INFO *)GetWindowLongW (hwnd, 0))
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000126
127
Guy L. Albertellia2495952001-01-26 21:00:10 +0000128/* Things common to the entire DLL */
Guy L. Albertellia2495952001-01-26 21:00:10 +0000129static LRESULT WINAPI
130COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
131static LRESULT WINAPI
132COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Dimitrie O. Paunf14b5272002-08-27 18:16:48 +0000133static int CALLBACK
134COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code);
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000135static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr);
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000136typedef INT (WINAPI *cmp_func_t)(LPCWSTR, LPCWSTR);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000137
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000138inline static BOOL is_textW(LPCWSTR str)
139{
140 return str && str != LPSTR_TEXTCALLBACKW;
141}
142
143inline static BOOL is_textA(LPCSTR str)
144{
145 return str && str != LPSTR_TEXTCALLBACKA;
146}
147
148inline static LPCSTR debugstr_txt(LPCWSTR str)
149{
150 if (str == LPSTR_TEXTCALLBACKW) return "(callback)";
151 return debugstr_w(str);
152}
153
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000154static void COMBOEX_DumpItem (CBE_ITEMDATA *item)
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000155{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000156 TRACE("item %p - mask=%08x, pszText=%p, cchTM=%d, iImage=%d\n",
157 item, item->mask, item->pszText, item->cchTextMax, item->iImage);
158 TRACE("item %p - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
159 item, item->iSelectedImage, item->iOverlay, item->iIndent, item->lParam);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000160 if (item->mask & CBEIF_TEXT)
161 TRACE("item %p - pszText=%s\n", item, debugstr_txt(item->pszText));
Guy L. Albertellia2495952001-01-26 21:00:10 +0000162}
163
164
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000165static void COMBOEX_DumpInput (COMBOBOXEXITEMW *input)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000166{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000167 TRACE("input - mask=%08x, iItem=%d, pszText=%p, cchTM=%d, iImage=%d\n",
168 input->mask, input->iItem, input->pszText, input->cchTextMax,
169 input->iImage);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000170 if (input->mask & CBEIF_TEXT)
171 TRACE("input - pszText=<%s>\n", debugstr_txt(input->pszText));
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000172 TRACE("input - iSelectedImage=%d, iOverlay=%d, iIndent=%d, lParam=%08lx\n",
173 input->iSelectedImage, input->iOverlay, input->iIndent, input->lParam);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000174}
175
176
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000177inline static CBE_ITEMDATA *get_item_data(COMBOEX_INFO *infoPtr, INT index)
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000178{
Vincent Béron9a624912002-05-31 23:06:46 +0000179 return (CBE_ITEMDATA *)SendMessageW (infoPtr->hwndCombo, CB_GETITEMDATA,
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000180 (WPARAM)index, 0);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000181}
182
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000183inline static cmp_func_t get_cmp_func(COMBOEX_INFO *infoPtr)
184{
185 return infoPtr->dwExtStyle & CBES_EX_CASESENSITIVE ? lstrcmpW : lstrcmpiW;
186}
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000187
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000188static INT COMBOEX_Notify (COMBOEX_INFO *infoPtr, INT code, NMHDR *hdr)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000189{
Guy L. Albertellia2495952001-01-26 21:00:10 +0000190 hdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
191 hdr->hwndFrom = infoPtr->hwndSelf;
192 hdr->code = code;
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000193 if (infoPtr->NtfUnicode)
Dimitrie O. Paunc5940432003-11-20 22:04:13 +0000194 return SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000195 else
Dimitrie O. Paunc5940432003-11-20 22:04:13 +0000196 return SendMessageA (infoPtr->hwndNotify, WM_NOTIFY, 0, (LPARAM)hdr);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000197}
198
199
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000200static INT
201COMBOEX_NotifyItem (COMBOEX_INFO *infoPtr, INT code, NMCOMBOBOXEXW *hdr)
202{
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000203 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000204 if (infoPtr->NtfUnicode)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000205 return COMBOEX_Notify (infoPtr, code, &hdr->hdr);
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000206 else {
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000207 LPWSTR wstr = hdr->ceItem.pszText;
208 LPSTR astr = 0;
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000209 INT ret, len = 0;
210
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000211 if ((hdr->ceItem.mask & CBEIF_TEXT) && is_textW(wstr)) {
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000212 len = WideCharToMultiByte (CP_ACP, 0, wstr, -1, 0, 0, NULL, NULL);
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000213 if (len > 0) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000214 astr = (LPSTR)Alloc ((len + 1)*sizeof(CHAR));
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000215 if (!astr) return 0;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000216 WideCharToMultiByte (CP_ACP, 0, wstr, -1, astr, len, 0, 0);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000217 hdr->ceItem.pszText = (LPWSTR)astr;
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000218 }
219 }
220
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000221 if (code == CBEN_ENDEDITW) code = CBEN_ENDEDITA;
222 else if (code == CBEN_GETDISPINFOW) code = CBEN_GETDISPINFOA;
223 else if (code == CBEN_DRAGBEGINW) code = CBEN_DRAGBEGINA;
Vincent Béron9a624912002-05-31 23:06:46 +0000224
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000225 ret = COMBOEX_Notify (infoPtr, code, (NMHDR *)hdr);
226
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000227 if (astr && hdr->ceItem.pszText == (LPWSTR)astr)
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000228 hdr->ceItem.pszText = wstr;
Vincent Béron9a624912002-05-31 23:06:46 +0000229
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000230 if (astr) Free(astr);
Vincent Béron9a624912002-05-31 23:06:46 +0000231
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000232 return ret;
233 }
234}
235
236
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000237static INT COMBOEX_NotifyEndEdit (COMBOEX_INFO *infoPtr, NMCBEENDEDITW *neew, LPCWSTR wstr)
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000238{
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000239 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000240 if (infoPtr->NtfUnicode) {
241 lstrcpynW(neew->szText, wstr, CBEMAXSTRLEN);
242 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITW, &neew->hdr);
243 } else {
244 NMCBEENDEDITA neea;
Vincent Béron9a624912002-05-31 23:06:46 +0000245
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000246 memcpy (&neea.hdr, &neew->hdr, sizeof(NMHDR));
247 neea.fChanged = neew->fChanged;
248 neea.iNewSelection = neew->iNewSelection;
249 WideCharToMultiByte (CP_ACP, 0, wstr, -1, neea.szText, CBEMAXSTRLEN, 0, 0);
250 neea.iWhy = neew->iWhy;
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000251
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000252 return COMBOEX_Notify (infoPtr, CBEN_ENDEDITA, &neea.hdr);
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000253 }
254}
255
256
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +0000257static void COMBOEX_NotifyDragBegin(COMBOEX_INFO *infoPtr, LPCWSTR wstr)
258{
259 /* Change the Text item from Unicode to ANSI if necessary for NOTIFY */
260 if (infoPtr->NtfUnicode) {
261 NMCBEDRAGBEGINW ndbw;
262
263 ndbw.iItemid = -1;
264 lstrcpynW(ndbw.szText, wstr, CBEMAXSTRLEN);
265 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINW, &ndbw.hdr);
266 } else {
267 NMCBEDRAGBEGINA ndba;
268
269 ndba.iItemid = -1;
270 WideCharToMultiByte (CP_ACP, 0, wstr, -1, ndba.szText, CBEMAXSTRLEN, 0, 0);
271
272 COMBOEX_Notify (infoPtr, CBEN_DRAGBEGINA, &ndba.hdr);
273 }
274}
275
276
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000277static void COMBOEX_FreeText (CBE_ITEMDATA *item)
278{
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000279 if (is_textW(item->pszText)) Free(item->pszText);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000280 item->pszText = 0;
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000281 if (item->pszTemp) Free(item->pszTemp);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000282 item->pszTemp = 0;
283}
284
285
286static LPCWSTR COMBOEX_GetText(COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
287{
288 NMCOMBOBOXEXW nmce;
289 LPWSTR text, buf;
290 INT len;
Vincent Béron9a624912002-05-31 23:06:46 +0000291
292 if (item->pszText != LPSTR_TEXTCALLBACKW)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000293 return item->pszText;
Vincent Béron9a624912002-05-31 23:06:46 +0000294
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000295 ZeroMemory(&nmce, sizeof(nmce));
296 nmce.ceItem.mask = CBEIF_TEXT;
Carlos392defd2002-10-28 18:50:14 +0000297 nmce.ceItem.lParam = item->lParam;
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000298 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
299
300 if (is_textW(nmce.ceItem.pszText)) {
301 len = MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, NULL, 0);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000302 buf = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000303 if (buf)
304 MultiByteToWideChar (CP_ACP, 0, (LPSTR)nmce.ceItem.pszText, -1, buf, len);
305 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) {
306 COMBOEX_FreeText(item);
307 item->pszText = buf;
308 } else {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000309 if (item->pszTemp) Free(item->pszTemp);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000310 item->pszTemp = buf;
311 }
312 text = buf;
313 } else
314 text = nmce.ceItem.pszText;
Vincent Béron9a624912002-05-31 23:06:46 +0000315
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000316 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
317 item->pszText = text;
318 return text;
319}
320
321
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000322static void COMBOEX_GetComboFontSize (COMBOEX_INFO *infoPtr, SIZE *size)
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000323{
324 HFONT nfont, ofont;
325 HDC mydc;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000326
327 mydc = GetDC (0); /* why the entire screen???? */
Michael Stefaniucf3d18932002-10-23 20:19:22 +0000328 nfont = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000329 ofont = (HFONT) SelectObject (mydc, nfont);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000330 GetTextExtentPointA (mydc, "A", 1, size);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000331 SelectObject (mydc, ofont);
332 ReleaseDC (0, mydc);
Michael Stefaniuc353529b2002-10-23 22:19:10 +0000333 TRACE("selected font hwnd=%p, height=%ld\n", nfont, size->cy);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000334}
335
336
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000337static void COMBOEX_CopyItem (CBE_ITEMDATA *item, COMBOBOXEXITEMW *cit)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000338{
339 if (cit->mask & CBEIF_TEXT) {
Aric Stewart1282ef92002-02-08 17:10:49 +0000340 /*
341 * when given a text buffer actually use that buffer
342 */
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000343 if (cit->pszText) {
344 if (is_textW(item->pszText))
345 lstrcpynW(cit->pszText, item->pszText, cit->cchTextMax);
346 else
347 cit->pszText[0] = 0;
348 } else {
Aric Stewart1282ef92002-02-08 17:10:49 +0000349 cit->pszText = item->pszText;
350 cit->cchTextMax = item->cchTextMax;
351 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000352 }
353 if (cit->mask & CBEIF_IMAGE)
354 cit->iImage = item->iImage;
355 if (cit->mask & CBEIF_SELECTEDIMAGE)
356 cit->iSelectedImage = item->iSelectedImage;
357 if (cit->mask & CBEIF_OVERLAY)
358 cit->iOverlay = item->iOverlay;
359 if (cit->mask & CBEIF_INDENT)
360 cit->iIndent = item->iIndent;
361 if (cit->mask & CBEIF_LPARAM)
362 cit->lParam = item->lParam;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000363}
364
365
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000366static void COMBOEX_AdjustEditPos (COMBOEX_INFO *infoPtr)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000367{
368 SIZE mysize;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000369 INT x, y, w, h, xioff;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000370 RECT rect;
371
372 if (!infoPtr->hwndEdit) return;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000373
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000374 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
375 IMAGEINFO iinfo;
376 iinfo.rcImage.left = iinfo.rcImage.right = 0;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000377 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000378 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
379 } else xioff = 0;
380
Guy L. Albertellia2495952001-01-26 21:00:10 +0000381 GetClientRect (infoPtr->hwndCombo, &rect);
382 InflateRect (&rect, -2, -2);
383 InvalidateRect (infoPtr->hwndCombo, &rect, TRUE);
384
385 /* reposition the Edit control based on whether icon exists */
386 COMBOEX_GetComboFontSize (infoPtr, &mysize);
387 TRACE("Combo font x=%ld, y=%ld\n", mysize.cx, mysize.cy);
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000388 x = xioff + CBE_STARTOFFSET + 1;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000389 w = rect.right-rect.left - x - GetSystemMetrics(SM_CXVSCROLL) - 1;
390 h = mysize.cy + 1;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000391 y = rect.bottom - h - 1;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000392
Dan Kegel0fd521f2003-01-08 21:09:25 +0000393 TRACE("Combo client (%ld,%ld)-(%ld,%ld), setting Edit to (%d,%d)-(%d,%d)\n",
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000394 rect.left, rect.top, rect.right, rect.bottom, x, y, x + w, y + h);
395 SetWindowPos(infoPtr->hwndEdit, HWND_TOP, x, y, w, h,
Guy L. Albertellia2495952001-01-26 21:00:10 +0000396 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER);
397}
398
399
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000400static void COMBOEX_ReSize (COMBOEX_INFO *infoPtr)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000401{
402 SIZE mysize;
403 UINT cy;
404 IMAGEINFO iinfo;
405
406 COMBOEX_GetComboFontSize (infoPtr, &mysize);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000407 cy = mysize.cy + CBE_EXTRA;
Huw Davies8d74ef12002-11-13 19:39:09 +0000408 if (infoPtr->himl && ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo)) {
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000409 cy = max (iinfo.rcImage.bottom - iinfo.rcImage.top, cy);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000410 TRACE("upgraded height due to image: height=%d\n", cy);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000411 }
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000412 SendMessageW (infoPtr->hwndSelf, CB_SETITEMHEIGHT, (WPARAM)-1, (LPARAM)cy);
Dimitrie O. Paunca135642002-08-30 00:02:20 +0000413 if (infoPtr->hwndCombo) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000414 SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000415 (WPARAM) 0, (LPARAM) cy);
Dimitrie O. Paunca135642002-08-30 00:02:20 +0000416 if ( !(infoPtr->flags & CBES_EX_NOSIZELIMIT)) {
417 RECT comboRect;
418 if (GetWindowRect(infoPtr->hwndCombo, &comboRect)) {
419 RECT ourRect;
420 if (GetWindowRect(infoPtr->hwndSelf, &ourRect)) {
421 if (comboRect.bottom > ourRect.bottom) {
422 POINT pt = { ourRect.left, ourRect.top };
423 if (ScreenToClient(infoPtr->hwndSelf, &pt))
424 MoveWindow( infoPtr->hwndSelf, pt.x, pt.y, ourRect.right - ourRect.left,
425 comboRect.bottom - comboRect.top, FALSE);
426 }
427 }
428 }
429 }
430 }
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000431}
432
433
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000434static void COMBOEX_SetEditText (COMBOEX_INFO *infoPtr, CBE_ITEMDATA *item)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000435{
436 if (!infoPtr->hwndEdit) return;
437 /* native issues the following messages to the {Edit} control */
438 /* WM_SETTEXT (0,addr) */
439 /* EM_SETSEL32 (0,0) */
440 /* EM_SETSEL32 (0,-1) */
441 if (item->mask & CBEIF_TEXT) {
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000442 SendMessageW (infoPtr->hwndEdit, WM_SETTEXT, 0, (LPARAM)COMBOEX_GetText(infoPtr, item));
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000443 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
444 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000445 }
446}
447
Vincent Béron9a624912002-05-31 23:06:46 +0000448
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000449static CBE_ITEMDATA * COMBOEX_FindItem(COMBOEX_INFO *infoPtr, INT index)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000450{
451 CBE_ITEMDATA *item;
452 INT i;
453
454 if ((index > infoPtr->nb_items) || (index < -1))
455 return 0;
456 if (index == -1)
457 return infoPtr->edit;
458 item = infoPtr->items;
459 i = infoPtr->nb_items - 1;
460
461 /* find the item in the list */
462 while (item && (i > index)) {
463 item = (CBE_ITEMDATA *)item->next;
464 i--;
465 }
466 if (!item || (i != index)) {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000467 ERR("COMBOBOXEX item structures broken. Please report!\n");
Guy L. Albertellia2495952001-01-26 21:00:10 +0000468 return 0;
469 }
470 return item;
471}
472
473
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000474static inline BOOL COMBOEX_HasEdit(COMBOEX_INFO *infoPtr)
475{
Michael Stefaniuc025c0b72002-09-06 19:41:17 +0000476 return infoPtr->hwndEdit ? TRUE : FALSE;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000477}
Vincent Béron9a624912002-05-31 23:06:46 +0000478
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000479
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000480/* *** CBEM_xxx message support *** */
481
482
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000483static INT COMBOEX_DeleteItem (COMBOEX_INFO *infoPtr, INT index)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000484{
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000485 CBE_ITEMDATA *item;
486
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000487 TRACE("(index=%d)\n", index);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000488
489 /* if item number requested does not exist then return failure */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000490 if ((index > infoPtr->nb_items) || (index < 0)) return CB_ERR;
491 if (!(item = COMBOEX_FindItem(infoPtr, index))) return CB_ERR;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000492
493 /* doing this will result in WM_DELETEITEM being issued */
494 SendMessageW (infoPtr->hwndCombo, CB_DELETESTRING, (WPARAM)index, 0);
495
496 return infoPtr->nb_items;
497}
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000498
499
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000500static BOOL COMBOEX_GetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000501{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000502 INT index = cit->iItem;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000503 CBE_ITEMDATA *item;
504
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000505 TRACE("(...)\n");
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000506
507 /* if item number requested does not exist then return failure */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000508 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000509
510 /* if the item is the edit control and there is no edit control, skip */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000511 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000512
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000513 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000514
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000515 COMBOEX_CopyItem (item, cit);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000516
517 return TRUE;
518}
519
520
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000521static BOOL COMBOEX_GetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000522{
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000523 COMBOBOXEXITEMW tmpcit;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000524
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000525 TRACE("(...)\n");
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000526
527 tmpcit.mask = cit->mask;
528 tmpcit.iItem = cit->iItem;
Guy L. Albertelli683c00a2002-02-12 18:41:48 +0000529 tmpcit.pszText = 0;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000530 if(!COMBOEX_GetItemW (infoPtr, &tmpcit)) return FALSE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000531
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000532 if (is_textW(tmpcit.pszText) && cit->pszText)
Vincent Béron9a624912002-05-31 23:06:46 +0000533 WideCharToMultiByte (CP_ACP, 0, tmpcit.pszText, -1,
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000534 cit->pszText, cit->cchTextMax, NULL, NULL);
535 else if (cit->pszText) cit->pszText[0] = 0;
536 else cit->pszText = (LPSTR)tmpcit.pszText;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000537
538 cit->iImage = tmpcit.iImage;
539 cit->iSelectedImage = tmpcit.iSelectedImage;
540 cit->iOverlay = tmpcit.iOverlay;
541 cit->iIndent = tmpcit.iIndent;
542 cit->lParam = tmpcit.lParam;
543
544 return TRUE;
545}
546
547
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000548inline static BOOL COMBOEX_HasEditChanged (COMBOEX_INFO *infoPtr)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000549{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000550 return COMBOEX_HasEdit(infoPtr) &&
551 (infoPtr->flags & WCBE_EDITHASCHANGED) == WCBE_EDITHASCHANGED;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000552}
553
554
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000555static INT COMBOEX_InsertItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000556{
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000557 INT index;
558 CBE_ITEMDATA *item;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000559 NMCOMBOBOXEXW nmcit;
560
561 TRACE("\n");
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000562
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000563 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000564
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000565 /* get real index of item to insert */
566 index = cit->iItem;
567 if (index == -1) index = infoPtr->nb_items;
568 if (index > infoPtr->nb_items) index = infoPtr->nb_items;
569
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000570 /* get zero-filled space and chain it in */
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000571 if(!(item = (CBE_ITEMDATA *)Alloc (sizeof(*item)))) return -1;
Vincent Béron9a624912002-05-31 23:06:46 +0000572
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000573 /* locate position to insert new item in */
574 if (index == infoPtr->nb_items) {
575 /* fast path for iItem = -1 */
576 item->next = infoPtr->items;
577 infoPtr->items = item;
578 }
579 else {
580 INT i = infoPtr->nb_items-1;
581 CBE_ITEMDATA *moving = infoPtr->items;
582
583 while ((i > index) && moving) {
584 moving = (CBE_ITEMDATA *)moving->next;
585 i--;
586 }
587 if (!moving) {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000588 ERR("COMBOBOXEX item structures broken. Please report!\n");
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000589 Free(item);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000590 return -1;
591 }
592 item->next = moving->next;
593 moving->next = item;
594 }
595
596 /* fill in our hidden item structure */
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000597 item->mask = cit->mask;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000598 if (item->mask & CBEIF_TEXT) {
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000599 INT len = 0;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000600
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000601 if (is_textW(cit->pszText)) len = strlenW (cit->pszText);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000602 if (len > 0) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000603 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000604 if (!item->pszText) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000605 Free(item);
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000606 return -1;
607 }
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000608 strcpyW (item->pszText, cit->pszText);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000609 }
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000610 else if (cit->pszText == LPSTR_TEXTCALLBACKW)
611 item->pszText = LPSTR_TEXTCALLBACKW;
612 item->cchTextMax = cit->cchTextMax;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000613 }
614 if (item->mask & CBEIF_IMAGE)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000615 item->iImage = cit->iImage;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000616 if (item->mask & CBEIF_SELECTEDIMAGE)
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000617 item->iSelectedImage = cit->iSelectedImage;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000618 if (item->mask & CBEIF_OVERLAY)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000619 item->iOverlay = cit->iOverlay;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000620 if (item->mask & CBEIF_INDENT)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000621 item->iIndent = cit->iIndent;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000622 if (item->mask & CBEIF_LPARAM)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000623 item->lParam = cit->lParam;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000624 infoPtr->nb_items++;
625
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000626 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000627
Vincent Béron9a624912002-05-31 23:06:46 +0000628 SendMessageW (infoPtr->hwndCombo, CB_INSERTSTRING,
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000629 (WPARAM)cit->iItem, (LPARAM)item);
630
Guy L. Albertelli683c00a2002-02-12 18:41:48 +0000631 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000632 COMBOEX_CopyItem (item, &nmcit.ceItem);
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000633 COMBOEX_NotifyItem (infoPtr, CBEN_INSERTITEM, &nmcit);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000634
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000635 return index;
636
637}
638
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000639
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000640static INT COMBOEX_InsertItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000641{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000642 COMBOBOXEXITEMW citW;
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000643 LPWSTR wstr = NULL;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000644 INT ret;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000645
646 memcpy(&citW,cit,sizeof(COMBOBOXEXITEMA));
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000647 if (cit->mask & CBEIF_TEXT && is_textA(cit->pszText)) {
648 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000649 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000650 if (!wstr) return -1;
651 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
652 citW.pszText = wstr;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000653 }
Vincent Béron9a624912002-05-31 23:06:46 +0000654 ret = COMBOEX_InsertItemW(infoPtr, &citW);
655
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000656 if (wstr) Free(wstr);
Vincent Béron9a624912002-05-31 23:06:46 +0000657
Guy L. Albertellia2495952001-01-26 21:00:10 +0000658 return ret;
659}
660
661
Vincent Béron9a624912002-05-31 23:06:46 +0000662static DWORD
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000663COMBOEX_SetExtendedStyle (COMBOEX_INFO *infoPtr, DWORD mask, DWORD style)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000664{
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000665 DWORD dwTemp;
666
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000667 TRACE("(mask=x%08lx, style=0x%08lx)\n", mask, style);
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000668
669 dwTemp = infoPtr->dwExtStyle;
670
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000671 if (mask)
672 infoPtr->dwExtStyle = (infoPtr->dwExtStyle & ~mask) | style;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000673 else
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000674 infoPtr->dwExtStyle = style;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000675
Dimitrie O. Paunf14b5272002-08-27 18:16:48 +0000676 /* see if we need to change the word break proc on the edit */
677 if ((infoPtr->dwExtStyle ^ dwTemp) & CBES_EX_PATHWORDBREAKPROC) {
678 SendMessageW(infoPtr->hwndEdit, EM_SETWORDBREAKPROC, 0,
679 (infoPtr->dwExtStyle & CBES_EX_PATHWORDBREAKPROC) ?
680 (LPARAM)COMBOEX_PathWordBreakProc : 0);
681 }
682
Dimitrie O. Paun43230a22002-04-08 20:16:01 +0000683 /* test if the control's appearance has changed */
684 mask = CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT;
685 if ((infoPtr->dwExtStyle & mask) != (dwTemp & mask)) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000686 /* if state of EX_NOEDITIMAGE changes, invalidate all */
687 TRACE("EX_NOEDITIMAGE state changed to %ld\n",
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000688 infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGE);
689 InvalidateRect (infoPtr->hwndSelf, NULL, TRUE);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000690 COMBOEX_AdjustEditPos (infoPtr);
691 if (infoPtr->hwndEdit)
692 InvalidateRect (infoPtr->hwndEdit, NULL, TRUE);
693 }
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000694
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000695 return dwTemp;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000696}
697
698
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000699static HIMAGELIST COMBOEX_SetImageList (COMBOEX_INFO *infoPtr, HIMAGELIST himl)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000700{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000701 HIMAGELIST himlTemp = infoPtr->himl;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000702
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000703 TRACE("(...)\n");
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000704
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000705 infoPtr->himl = himl;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000706
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000707 COMBOEX_ReSize (infoPtr);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000708 InvalidateRect (infoPtr->hwndCombo, NULL, TRUE);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000709
Guy L. Albertellia2495952001-01-26 21:00:10 +0000710 /* reposition the Edit control based on whether icon exists */
711 COMBOEX_AdjustEditPos (infoPtr);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000712 return himlTemp;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000713}
714
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000715static BOOL COMBOEX_SetItemW (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMW *cit)
Eric Kohl66ef0111998-11-22 17:58:40 +0000716{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000717 INT index = cit->iItem;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000718 CBE_ITEMDATA *item;
Eric Kohl66ef0111998-11-22 17:58:40 +0000719
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000720 if (TRACE_ON(comboex)) COMBOEX_DumpInput (cit);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000721
722 /* if item number requested does not exist then return failure */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000723 if ((index > infoPtr->nb_items) || (index < -1)) return FALSE;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000724
Guy L. Albertellia2495952001-01-26 21:00:10 +0000725 /* if the item is the edit control and there is no edit control, skip */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000726 if ((index == -1) && !COMBOEX_HasEdit(infoPtr)) return FALSE;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000727
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000728 if (!(item = COMBOEX_FindItem(infoPtr, index))) return FALSE;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000729
Vincent Béron9a624912002-05-31 23:06:46 +0000730 /* add/change stuff to the internal item structure */
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000731 item->mask |= cit->mask;
732 if (cit->mask & CBEIF_TEXT) {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000733 INT len = 0;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000734
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000735 COMBOEX_FreeText(item);
736 if (is_textW(cit->pszText)) len = strlenW(cit->pszText);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000737 if (len > 0) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000738 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000739 if (!item->pszText) return FALSE;
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000740 strcpyW(item->pszText, cit->pszText);
741 } else if (cit->pszText == LPSTR_TEXTCALLBACKW)
742 item->pszText = LPSTR_TEXTCALLBACKW;
743 item->cchTextMax = cit->cchTextMax;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000744 }
745 if (cit->mask & CBEIF_IMAGE)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000746 item->iImage = cit->iImage;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000747 if (cit->mask & CBEIF_SELECTEDIMAGE)
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000748 item->iSelectedImage = cit->iSelectedImage;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000749 if (cit->mask & CBEIF_OVERLAY)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000750 item->iOverlay = cit->iOverlay;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000751 if (cit->mask & CBEIF_INDENT)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000752 item->iIndent = cit->iIndent;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000753 if (cit->mask & CBEIF_LPARAM)
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000754 cit->lParam = cit->lParam;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +0000755
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000756 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
Eric Kohl66ef0111998-11-22 17:58:40 +0000757
Guy L. Albertellia2495952001-01-26 21:00:10 +0000758 /* if original request was to update edit control, do some fast foot work */
759 if (cit->iItem == -1) {
760 COMBOEX_SetEditText (infoPtr, item);
761 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE | RDW_INVALIDATE);
762 }
Eric Kohl66ef0111998-11-22 17:58:40 +0000763 return TRUE;
764}
765
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000766static BOOL COMBOEX_SetItemA (COMBOEX_INFO *infoPtr, COMBOBOXEXITEMA *cit)
Marcus Meissner643fcff2000-11-06 20:22:06 +0000767{
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000768 COMBOBOXEXITEMW citW;
769 LPWSTR wstr = NULL;
770 BOOL ret;
Eric Kohl66ef0111998-11-22 17:58:40 +0000771
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000772 memcpy(&citW, cit, sizeof(COMBOBOXEXITEMA));
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000773 if ((cit->mask & CBEIF_TEXT) && is_textA(cit->pszText)) {
774 INT len = MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, NULL, 0);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000775 wstr = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000776 if (!wstr) return FALSE;
777 MultiByteToWideChar (CP_ACP, 0, cit->pszText, -1, wstr, len);
778 citW.pszText = wstr;
Marcus Meissner643fcff2000-11-06 20:22:06 +0000779 }
Vincent Béron9a624912002-05-31 23:06:46 +0000780 ret = COMBOEX_SetItemW(infoPtr, &citW);
Marcus Meissner643fcff2000-11-06 20:22:06 +0000781
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000782 if (wstr) Free(wstr);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000783
Marcus Meissner643fcff2000-11-06 20:22:06 +0000784 return ret;
785}
786
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000787
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000788static BOOL COMBOEX_SetUnicodeFormat (COMBOEX_INFO *infoPtr, BOOL value)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000789{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000790 BOOL bTemp = infoPtr->unicode;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000791
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000792 TRACE("to %s, was %s\n", value ? "TRUE":"FALSE", bTemp ? "TRUE":"FALSE");
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000793
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000794 infoPtr->unicode = value;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000795
796 return bTemp;
797}
798
Eric Kohl66ef0111998-11-22 17:58:40 +0000799
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000800/* *** CB_xxx message support *** */
801
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000802static INT
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000803COMBOEX_FindStringExact (COMBOEX_INFO *infoPtr, INT start, LPCWSTR str)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000804{
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000805 INT i;
806 cmp_func_t cmptext = get_cmp_func(infoPtr);
807 INT count = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000808
809 /* now search from after starting loc and wrapping back to start */
810 for(i=start+1; i<count; i++) {
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000811 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
812 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000813 }
814 for(i=0; i<=start; i++) {
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000815 CBE_ITEMDATA *item = get_item_data(infoPtr, i);
816 if (cmptext(COMBOEX_GetText(infoPtr, item), str) == 0) return i;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000817 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +0000818 return CB_ERR;
819}
820
821
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000822static DWORD COMBOEX_GetItemData (COMBOEX_INFO *infoPtr, INT index)
Guy L. Albertellibad75902001-04-20 18:27:19 +0000823{
Guy L. Albertellibad75902001-04-20 18:27:19 +0000824 CBE_ITEMDATA *item1, *item2;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000825 DWORD ret = 0;
Guy L. Albertellibad75902001-04-20 18:27:19 +0000826
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000827 item1 = get_item_data(infoPtr, index);
Guy L. Albertellibad75902001-04-20 18:27:19 +0000828 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
829 item2 = COMBOEX_FindItem (infoPtr, index);
830 if (item2 != item1) {
831 ERR("data structures damaged!\n");
832 return CB_ERR;
833 }
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000834 if (item1->mask & CBEIF_LPARAM) ret = item1->lParam;
835 TRACE("returning 0x%08lx\n", ret);
836 } else {
837 ret = (DWORD)item1;
838 TRACE("non-valid result from combo, returning 0x%08lx\n", ret);
Guy L. Albertellibad75902001-04-20 18:27:19 +0000839 }
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000840 return ret;
Guy L. Albertellibad75902001-04-20 18:27:19 +0000841}
842
843
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000844static INT COMBOEX_SetCursel (COMBOEX_INFO *infoPtr, INT index)
Guy L. Albertellia2495952001-01-26 21:00:10 +0000845{
Guy L. Albertellia2495952001-01-26 21:00:10 +0000846 CBE_ITEMDATA *item;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000847 INT sel;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000848
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000849 if (!(item = COMBOEX_FindItem(infoPtr, index)))
850 return SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000851
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000852 TRACE("selecting item %d text=%s\n", index, debugstr_txt(item->pszText));
Guy L. Albertellibad75902001-04-20 18:27:19 +0000853 infoPtr->selected = index;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000854
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000855 sel = (INT)SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL, index, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000856 COMBOEX_SetEditText (infoPtr, item);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000857 return sel;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000858}
859
860
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000861static DWORD COMBOEX_SetItemData (COMBOEX_INFO *infoPtr, INT index, DWORD data)
Guy L. Albertellibad75902001-04-20 18:27:19 +0000862{
Guy L. Albertellibad75902001-04-20 18:27:19 +0000863 CBE_ITEMDATA *item1, *item2;
864
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +0000865 item1 = get_item_data(infoPtr, index);
Guy L. Albertellibad75902001-04-20 18:27:19 +0000866 if ((item1 != NULL) && ((LRESULT)item1 != CB_ERR)) {
867 item2 = COMBOEX_FindItem (infoPtr, index);
868 if (item2 != item1) {
869 ERR("data structures damaged!\n");
870 return CB_ERR;
871 }
872 item1->mask |= CBEIF_LPARAM;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000873 item1->lParam = data;
874 TRACE("setting lparam to 0x%08lx\n", data);
Guy L. Albertellibad75902001-04-20 18:27:19 +0000875 return 0;
876 }
877 TRACE("non-valid result from combo 0x%08lx\n", (DWORD)item1);
878 return (LRESULT)item1;
879}
880
881
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000882static INT COMBOEX_SetItemHeight (COMBOEX_INFO *infoPtr, INT index, UINT height)
Eric Kohl66ef0111998-11-22 17:58:40 +0000883{
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000884 RECT cb_wrect, cbx_wrect, cbx_crect;
Eric Kohl66ef0111998-11-22 17:58:40 +0000885
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000886 /* First, lets forward the message to the normal combo control
887 just like Windows. */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000888 if (infoPtr->hwndCombo)
889 if (SendMessageW (infoPtr->hwndCombo, CB_SETITEMHEIGHT,
890 index, height) == CB_ERR) return CB_ERR;
Eric Kohl66ef0111998-11-22 17:58:40 +0000891
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000892 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000893 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
894 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
Vincent Béron9a624912002-05-31 23:06:46 +0000895 /* the height of comboex as height of the combo + comboex border */
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000896 height = cb_wrect.bottom-cb_wrect.top
897 + cbx_wrect.bottom-cbx_wrect.top
898 - (cbx_crect.bottom-cbx_crect.top);
Dan Kegel0fd521f2003-01-08 21:09:25 +0000899 TRACE("EX window=(%ld,%ld)-(%ld,%ld), client=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000900 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
901 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
Dan Kegel0fd521f2003-01-08 21:09:25 +0000902 TRACE("CB window=(%ld,%ld)-(%ld,%ld), EX setting=(0,0)-(%ld,%d)\n",
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000903 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
904 cbx_wrect.right-cbx_wrect.left, height);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000905 SetWindowPos (infoPtr->hwndSelf, HWND_TOP, 0, 0,
906 cbx_wrect.right-cbx_wrect.left, height,
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000907 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000908
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000909 return 0;
Eric Kohl66ef0111998-11-22 17:58:40 +0000910}
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000911
912
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000913/* *** WM_xxx message support *** */
914
915
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000916static LRESULT COMBOEX_Create (HWND hwnd, LPCREATESTRUCTA cs)
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000917{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000918 WCHAR COMBOBOX[] = { 'C', 'o', 'm', 'b', 'o', 'B', 'o', 'x', 0 };
919 WCHAR EDIT[] = { 'E', 'D', 'I', 'T', 0 };
920 WCHAR NIL[] = { 0 };
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000921 COMBOEX_INFO *infoPtr;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000922 LOGFONTW mylogfont;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000923 RECT wnrc1, clrc1, cmbwrc;
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000924 INT i;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000925
926 /* allocate memory for info structure */
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +0000927 infoPtr = (COMBOEX_INFO *)Alloc (sizeof(COMBOEX_INFO));
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000928 if (!infoPtr) return -1;
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000929
930 /* initialize info structure */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000931 /* note that infoPtr is allocated zero-filled */
Vincent Béron9a624912002-05-31 23:06:46 +0000932
Guy L. Albertellia2495952001-01-26 21:00:10 +0000933 infoPtr->hwndSelf = hwnd;
Guy L. Albertellibad75902001-04-20 18:27:19 +0000934 infoPtr->selected = -1;
Guy L. Albertellia2495952001-01-26 21:00:10 +0000935
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000936 infoPtr->unicode = IsWindowUnicode (hwnd);
Dimitrie O. Paunc5940432003-11-20 22:04:13 +0000937 infoPtr->hwndNotify = cs->hwndParent;
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000938
Dimitrie O. Paunc5940432003-11-20 22:04:13 +0000939 i = SendMessageW(infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000940 if ((i != NFR_ANSI) && (i != NFR_UNICODE)) {
941 WARN("wrong response to WM_NOTIFYFORMAT (%d), assuming ANSI\n", i);
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000942 i = NFR_ANSI;
943 }
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000944 infoPtr->NtfUnicode = (i == NFR_UNICODE);
Guy L. Albertellib2207c72001-06-24 00:22:20 +0000945
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000946 SetWindowLongW (hwnd, 0, (DWORD)infoPtr);
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000947
948 /* create combo box */
Guy L. Albertellibad75902001-04-20 18:27:19 +0000949 GetWindowRect(hwnd, &wnrc1);
950 GetClientRect(hwnd, &clrc1);
Dan Kegel0fd521f2003-01-08 21:09:25 +0000951 TRACE("EX window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellibad75902001-04-20 18:27:19 +0000952 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
953 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000954
955 /* Native version of ComboEx creates the ComboBox with DROPDOWNLIST */
956 /* specified. It then creates it's own version of the EDIT control */
957 /* and makes the ComboBox the parent. This is because a normal */
958 /* DROPDOWNLIST does not have a EDIT control, but we need one. */
959 /* We also need to place the edit control at the proper location */
960 /* (allow space for the icons). */
961
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000962 infoPtr->hwndCombo = CreateWindowW (COMBOBOX, NIL,
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000963 /* following line added to match native */
Guy L. Albertellia2495952001-01-26 21:00:10 +0000964 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VSCROLL |
Vincent Béron9a624912002-05-31 23:06:46 +0000965 CBS_NOINTEGRALHEIGHT | CBS_DROPDOWNLIST |
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +0000966 /* was base and is necessary */
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +0000967 WS_CHILD | WS_VISIBLE | CBS_OWNERDRAWFIXED |
968 GetWindowLongW (hwnd, GWL_STYLE),
Guy L. Albertellia2495952001-01-26 21:00:10 +0000969 cs->y, cs->x, cs->cx, cs->cy, hwnd,
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000970 (HMENU) GetWindowLongW (hwnd, GWL_ID),
Michael Stefaniucf3d18932002-10-23 20:19:22 +0000971 (HINSTANCE)GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
Alexandre Julliarda0d77311998-09-13 16:32:00 +0000972
Vincent Béron9a624912002-05-31 23:06:46 +0000973 /*
Guy L. Albertellia2495952001-01-26 21:00:10 +0000974 * native does the following at this point according to trace:
975 * GetWindowThreadProcessId(hwndCombo,0)
976 * GetCurrentThreadId()
977 * GetWindowThreadProcessId(hwndCombo, &???)
978 * GetCurrentProcessId()
979 */
980
981 /*
Vincent Béron9a624912002-05-31 23:06:46 +0000982 * Setup a property to hold the pointer to the COMBOBOXEX
Guy L. Albertellia2495952001-01-26 21:00:10 +0000983 * data structure.
984 */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000985 SetPropA(infoPtr->hwndCombo, COMBOEX_SUBCLASS_PROP, hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +0000986 infoPtr->prevComboWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndCombo,
Guy L. Albertellia2495952001-01-26 21:00:10 +0000987 GWL_WNDPROC, (LONG)COMBOEX_ComboWndProc);
Michael Stefaniucf3d18932002-10-23 20:19:22 +0000988 infoPtr->font = (HFONT)SendMessageW (infoPtr->hwndCombo, WM_GETFONT, 0, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +0000989
990
991 /*
992 * Now create our own EDIT control so we can position it.
993 * It is created only for CBS_DROPDOWN style
994 */
995 if ((cs->style & CBS_DROPDOWNLIST) == CBS_DROPDOWN) {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +0000996 infoPtr->hwndEdit = CreateWindowExW (0, EDIT, NIL,
Guy L. Albertellia2495952001-01-26 21:00:10 +0000997 WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | ES_AUTOHSCROLL,
998 0, 0, 0, 0, /* will set later */
Vincent Béron9a624912002-05-31 23:06:46 +0000999 infoPtr->hwndCombo,
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001000 (HMENU) GetWindowLongW (hwnd, GWL_ID),
Michael Stefaniucf3d18932002-10-23 20:19:22 +00001001 (HINSTANCE)GetWindowLongW (hwnd, GWL_HINSTANCE), NULL);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001002
1003 /* native does the following at this point according to trace:
1004 * GetWindowThreadProcessId(hwndEdit,0)
1005 * GetCurrentThreadId()
1006 * GetWindowThreadProcessId(hwndEdit, &???)
1007 * GetCurrentProcessId()
1008 */
1009
1010 /*
Vincent Béron9a624912002-05-31 23:06:46 +00001011 * Setup a property to hold the pointer to the COMBOBOXEX
Guy L. Albertellia2495952001-01-26 21:00:10 +00001012 * data structure.
1013 */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001014 SetPropA(infoPtr->hwndEdit, COMBOEX_SUBCLASS_PROP, hwnd);
Vincent Béron9a624912002-05-31 23:06:46 +00001015 infoPtr->prevEditWndProc = (WNDPROC)SetWindowLongW(infoPtr->hwndEdit,
Guy L. Albertellia2495952001-01-26 21:00:10 +00001016 GWL_WNDPROC, (LONG)COMBOEX_EditWndProc);
Michael Stefaniucf3d18932002-10-23 20:19:22 +00001017 infoPtr->font = (HFONT)SendMessageW(infoPtr->hwndCombo, WM_GETFONT, 0, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001018 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00001019
1020 /*
1021 * Locate the default font if necessary and then set it in
1022 * all associated controls
1023 */
1024 if (!infoPtr->font) {
Vincent Béron9a624912002-05-31 23:06:46 +00001025 SystemParametersInfoW (SPI_GETICONTITLELOGFONT, sizeof(mylogfont),
Guy L. Albertellia2495952001-01-26 21:00:10 +00001026 &mylogfont, 0);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001027 infoPtr->font = infoPtr->defaultFont = CreateFontIndirectW (&mylogfont);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001028 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001029 SendMessageW (infoPtr->hwndCombo, WM_SETFONT, (WPARAM)infoPtr->font, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001030 if (infoPtr->hwndEdit) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001031 SendMessageW (infoPtr->hwndEdit, WM_SETFONT, (WPARAM)infoPtr->font, 0);
1032 SendMessageW (infoPtr->hwndEdit, EM_SETMARGINS, (WPARAM)EC_USEFONTINFO, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001033 }
1034
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001035 COMBOEX_ReSize (infoPtr);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001036
1037 /* Above is fairly certain, below is much less certain. */
1038
1039 GetWindowRect(hwnd, &wnrc1);
1040 GetClientRect(hwnd, &clrc1);
1041 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001042 TRACE("EX window=(%ld,%ld)-(%ld,%ld) client=(%ld,%ld)-(%ld,%ld) CB wnd=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001043 wnrc1.left, wnrc1.top, wnrc1.right, wnrc1.bottom,
1044 clrc1.left, clrc1.top, clrc1.right, clrc1.bottom,
1045 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
Vincent Béron9a624912002-05-31 23:06:46 +00001046 SetWindowPos(infoPtr->hwndCombo, HWND_TOP,
Guy L. Albertellia2495952001-01-26 21:00:10 +00001047 0, 0, wnrc1.right-wnrc1.left, wnrc1.bottom-wnrc1.top,
1048 SWP_NOACTIVATE | SWP_NOREDRAW);
1049
1050 GetWindowRect(infoPtr->hwndCombo, &cmbwrc);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001051 TRACE("CB window=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001052 cmbwrc.left, cmbwrc.top, cmbwrc.right, cmbwrc.bottom);
Vincent Béron9a624912002-05-31 23:06:46 +00001053 SetWindowPos(hwnd, HWND_TOP,
Guy L. Albertellia2495952001-01-26 21:00:10 +00001054 0, 0, cmbwrc.right-cmbwrc.left, cmbwrc.bottom-cmbwrc.top,
1055 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
1056
1057 COMBOEX_AdjustEditPos (infoPtr);
1058
1059 /*
Vincent Béron9a624912002-05-31 23:06:46 +00001060 * Create an item structure to represent the data in the
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001061 * EDIT control. It is allocated zero-filled.
Guy L. Albertellia2495952001-01-26 21:00:10 +00001062 */
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001063 infoPtr->edit = (CBE_ITEMDATA *)Alloc (sizeof (CBE_ITEMDATA));
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001064 if (!infoPtr->edit) {
1065 COMBOEX_Destroy(infoPtr);
1066 return -1;
1067 }
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001068
1069 return 0;
1070}
1071
1072
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001073static LRESULT COMBOEX_Command (COMBOEX_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001074{
1075 LRESULT lret;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001076 INT command = HIWORD(wParam);
1077 CBE_ITEMDATA *item = 0;
1078 WCHAR wintext[520];
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001079 INT cursel, n, oldItem;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001080 NMCBEENDEDITW cbeend;
Guy L. Albertellibad75902001-04-20 18:27:19 +00001081 DWORD oldflags;
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00001082 HWND parent = infoPtr->hwndNotify;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001083
1084 TRACE("for command %d\n", command);
1085
1086 switch (command)
1087 {
1088 case CBN_DROPDOWN:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001089 SetFocus (infoPtr->hwndCombo);
1090 ShowWindow (infoPtr->hwndEdit, SW_HIDE);
1091 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
Vincent Béron9a624912002-05-31 23:06:46 +00001092
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001093 case CBN_CLOSEUP:
1094 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001095 /*
Vincent Béron9a624912002-05-31 23:06:46 +00001096 * from native trace of first dropdown after typing in URL in IE4
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001097 * CB_GETCURSEL(Combo)
1098 * GetWindowText(Edit)
1099 * CB_GETCURSEL(Combo)
1100 * CB_GETCOUNT(Combo)
1101 * CB_GETITEMDATA(Combo, n)
1102 * WM_NOTIFY(parent, CBEN_ENDEDITA|W)
1103 * CB_GETCURSEL(Combo)
1104 * CB_SETCURSEL(COMBOEX, n)
1105 * SetFocus(Combo)
Vincent Béron9a624912002-05-31 23:06:46 +00001106 * the rest is supposition
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001107 */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001108 ShowWindow (infoPtr->hwndEdit, SW_SHOW);
1109 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1110 InvalidateRect (infoPtr->hwndEdit, 0, TRUE);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001111 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1112 if (cursel == -1) {
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00001113 cmp_func_t cmptext = get_cmp_func(infoPtr);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001114 /* find match from edit against those in Combobox */
1115 GetWindowTextW (infoPtr->hwndEdit, wintext, 520);
1116 n = SendMessageW (infoPtr->hwndCombo, CB_GETCOUNT, 0, 0);
1117 for (cursel = 0; cursel < n; cursel++){
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001118 item = get_item_data(infoPtr, cursel);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001119 if ((INT)item == CB_ERR) break;
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00001120 if (!cmptext(COMBOEX_GetText(infoPtr, item), wintext)) break;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001121 }
1122 if ((cursel == n) || ((INT)item == CB_ERR)) {
1123 TRACE("failed to find match??? item=%p cursel=%d\n",
1124 item, cursel);
1125 if (infoPtr->hwndEdit)
1126 SetFocus(infoPtr->hwndEdit);
1127 return 0;
1128 }
1129 }
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001130 else {
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001131 item = get_item_data(infoPtr, cursel);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001132 if ((INT)item == CB_ERR) {
1133 TRACE("failed to find match??? item=%p cursel=%d\n",
1134 item, cursel);
1135 if (infoPtr->hwndEdit)
1136 SetFocus(infoPtr->hwndEdit);
1137 return 0;
1138 }
1139 }
Guy L. Albertellibad75902001-04-20 18:27:19 +00001140
1141 /* Save flags for testing and reset them */
1142 oldflags = infoPtr->flags;
1143 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1144
1145 if (oldflags & WCBE_ACTEDIT) {
Guy L. Albertellibad75902001-04-20 18:27:19 +00001146 cbeend.fChanged = (oldflags & WCBE_EDITCHG);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001147 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1148 CB_GETCURSEL, 0, 0);
1149 cbeend.iWhy = CBENF_DROPDOWN;
1150
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001151 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, COMBOEX_GetText(infoPtr, item))) return 0;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001152 }
Guy L. Albertellibad75902001-04-20 18:27:19 +00001153
1154 /* if selection has changed the set the new current selection */
1155 cursel = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1156 if ((oldflags & WCBE_EDITCHG) || (cursel != infoPtr->selected)) {
1157 infoPtr->selected = cursel;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001158 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, cursel, 0);
Guy L. Albertellibad75902001-04-20 18:27:19 +00001159 SetFocus(infoPtr->hwndCombo);
1160 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001161 return 0;
1162
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001163 case CBN_SELCHANGE:
1164 /*
1165 * CB_GETCURSEL(Combo)
1166 * CB_GETITEMDATA(Combo) < simulated by COMBOEX_FindItem
1167 * lstrlenA
1168 * WM_SETTEXT(Edit)
1169 * WM_GETTEXTLENGTH(Edit)
1170 * WM_GETTEXT(Edit)
1171 * EM_SETSEL(Edit, 0,0)
1172 * WM_GETTEXTLENGTH(Edit)
1173 * WM_GETTEXT(Edit)
1174 * EM_SETSEL(Edit, 0,len)
1175 * return WM_COMMAND to parent
1176 */
1177 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
1178 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1179 ERR("item %d not found. Problem!\n", oldItem);
1180 break;
Guy L. Albertellibad75902001-04-20 18:27:19 +00001181 }
1182 infoPtr->selected = oldItem;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001183 COMBOEX_SetEditText (infoPtr, item);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001184 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001185
1186 case CBN_SELENDOK:
Vincent Béron9a624912002-05-31 23:06:46 +00001187 /*
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001188 * We have to change the handle since we are the control
1189 * issuing the message. IE4 depends on this.
1190 */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001191 return SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001192
1193 case CBN_KILLFOCUS:
1194 /*
1195 * from native trace:
1196 *
1197 * pass to parent
1198 * WM_GETTEXT(Edit, 104)
1199 * CB_GETCURSEL(Combo) rets -1
1200 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1201 * CB_GETCURSEL(Combo)
1202 * InvalidateRect(Combo, 0, 0)
1203 * return 0
1204 */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001205 SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001206 if (infoPtr->flags & WCBE_ACTEDIT) {
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001207 GetWindowTextW (infoPtr->hwndEdit, wintext, 260);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001208 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
1209 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1210 CB_GETCURSEL, 0, 0);
1211 cbeend.iWhy = CBENF_KILLFOCUS;
1212
1213 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001214 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, wintext)) return 0;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001215 }
1216 /* possible CB_GETCURSEL */
1217 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1218 return 0;
1219
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001220 default:
Vincent Béron9a624912002-05-31 23:06:46 +00001221 /*
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001222 * We have to change the handle since we are the control
1223 * issuing the message. IE4 depends on this.
1224 * We also need to set the focus back to the Edit control
1225 * after passing the command to the parent of the ComboEx.
1226 */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001227 lret = SendMessageW (parent, WM_COMMAND, wParam, (LPARAM)infoPtr->hwndSelf);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001228 if (infoPtr->hwndEdit)
1229 SetFocus(infoPtr->hwndEdit);
1230 return lret;
1231 }
1232 return 0;
1233}
1234
1235
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001236static BOOL COMBOEX_WM_DeleteItem (COMBOEX_INFO *infoPtr, DELETEITEMSTRUCT *dis)
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001237{
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001238 CBE_ITEMDATA *item, *olditem;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001239 NMCOMBOBOXEXW nmcit;
Rolf Kalbermatter6c799302002-12-16 22:43:58 +00001240 UINT i;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001241
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001242 TRACE("CtlType=%08x, CtlID=%08x, itemID=%08x, hwnd=%p, data=%08lx\n",
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001243 dis->CtlType, dis->CtlID, dis->itemID, dis->hwndItem, dis->itemData);
1244
Jörg Mayere5b5af92001-08-10 22:49:35 +00001245 if (dis->itemID >= infoPtr->nb_items) return FALSE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001246
1247 olditem = infoPtr->items;
1248 i = infoPtr->nb_items - 1;
1249
1250 if (i == dis->itemID) {
1251 infoPtr->items = infoPtr->items->next;
1252 }
1253 else {
1254 item = olditem;
1255 i--;
1256
1257 /* find the prior item in the list */
1258 while (item->next && (i > dis->itemID)) {
1259 item = (CBE_ITEMDATA *)item->next;
1260 i--;
1261 }
1262 if (!item->next || (i != dis->itemID)) {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001263 ERR("COMBOBOXEX item structures broken. Please report!\n");
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001264 return FALSE;
1265 }
1266 olditem = item->next;
1267 item->next = (CBE_ITEMDATA *)((CBE_ITEMDATA *)item->next)->next;
1268 }
1269 infoPtr->nb_items--;
1270
Guy L. Albertelli683c00a2002-02-12 18:41:48 +00001271 memset (&nmcit.ceItem, 0, sizeof(nmcit.ceItem));
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001272 COMBOEX_CopyItem (olditem, &nmcit.ceItem);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001273 COMBOEX_NotifyItem (infoPtr, CBEN_DELETEITEM, &nmcit);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001274
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001275 COMBOEX_FreeText(olditem);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001276 Free(olditem);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001277
1278 return TRUE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001279}
1280
1281
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001282static LRESULT COMBOEX_DrawItem (COMBOEX_INFO *infoPtr, DRAWITEMSTRUCT *dis)
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001283{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001284 WCHAR nil[] = { 0 };
Guy L. Albertellia2495952001-01-26 21:00:10 +00001285 CBE_ITEMDATA *item = 0;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001286 SIZE txtsize;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001287 RECT rect;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001288 LPCWSTR str = nil;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001289 UINT xbase, x, y;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001290 INT len;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001291 COLORREF nbkc, ntxc, bkc, txc;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001292 int drawimage, drawstate, xioff;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001293
1294 if (!IsWindowEnabled(infoPtr->hwndCombo)) return 0;
1295
Vincent Béron9a624912002-05-31 23:06:46 +00001296 TRACE("DRAWITEMSTRUCT: CtlType=0x%08x CtlID=0x%08x\n",
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001297 dis->CtlType, dis->CtlID);
Vincent Béron9a624912002-05-31 23:06:46 +00001298 TRACE("itemID=0x%08x itemAction=0x%08x itemState=0x%08x\n",
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001299 dis->itemID, dis->itemAction, dis->itemState);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001300 TRACE("hWnd=%p hDC=%p (%ld,%ld)-(%ld,%ld) itemData=0x%08lx\n",
Vincent Béron9a624912002-05-31 23:06:46 +00001301 dis->hwndItem, dis->hDC, dis->rcItem.left,
1302 dis->rcItem.top, dis->rcItem.right, dis->rcItem.bottom,
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001303 dis->itemData);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001304
Guy L. Albertelli312beec2000-10-31 01:00:39 +00001305 /* MSDN says: */
1306 /* "itemID - Specifies the menu item identifier for a menu */
1307 /* item or the index of the item in a list box or combo box. */
1308 /* For an empty list box or combo box, this member can be -1. */
1309 /* This allows the application to draw only the focus */
1310 /* rectangle at the coordinates specified by the rcItem */
1311 /* member even though there are no items in the control. */
1312 /* This indicates to the user whether the list box or combo */
1313 /* box has the focus. How the bits are set in the itemAction */
1314 /* member determines whether the rectangle is to be drawn as */
1315 /* though the list box or combo box has the focus. */
1316 if (dis->itemID == 0xffffffff) {
Guy L. Albertellia2495952001-01-26 21:00:10 +00001317 if ( ( (dis->itemAction & ODA_FOCUS) && (dis->itemState & ODS_SELECTED)) ||
Vincent Béron9a624912002-05-31 23:06:46 +00001318 ( (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) && (dis->itemState & ODS_FOCUS) ) ) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001319
Dan Kegel0fd521f2003-01-08 21:09:25 +00001320 TRACE("drawing item -1 special focus, rect=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001321 dis->rcItem.left, dis->rcItem.top,
1322 dis->rcItem.right, dis->rcItem.bottom);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001323 }
Vincent Béron9a624912002-05-31 23:06:46 +00001324 else if ((dis->CtlType == ODT_COMBOBOX) &&
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001325 (dis->itemAction == ODA_DRAWENTIRE)) {
Guy L. Albertellia2495952001-01-26 21:00:10 +00001326 /* draw of edit control data */
Guy L. Albertellia2495952001-01-26 21:00:10 +00001327
1328 /* testing */
1329 {
1330 RECT exrc, cbrc, edrc;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001331 GetWindowRect (infoPtr->hwndSelf, &exrc);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001332 GetWindowRect (infoPtr->hwndCombo, &cbrc);
1333 edrc.left=edrc.top=edrc.right=edrc.bottom=-1;
1334 if (infoPtr->hwndEdit)
1335 GetWindowRect (infoPtr->hwndEdit, &edrc);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001336 TRACE("window rects ex=(%ld,%ld)-(%ld,%ld), cb=(%ld,%ld)-(%ld,%ld), ed=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001337 exrc.left, exrc.top, exrc.right, exrc.bottom,
1338 cbrc.left, cbrc.top, cbrc.right, cbrc.bottom,
1339 edrc.left, edrc.top, edrc.right, edrc.bottom);
1340 }
1341 }
1342 else {
Dan Kegel0fd521f2003-01-08 21:09:25 +00001343 ERR("NOT drawing item -1 special focus, rect=(%ld,%ld)-(%ld,%ld), action=%08x, state=%08x\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001344 dis->rcItem.left, dis->rcItem.top,
1345 dis->rcItem.right, dis->rcItem.bottom,
1346 dis->itemAction, dis->itemState);
1347 return 0;
1348 }
Guy L. Albertelli312beec2000-10-31 01:00:39 +00001349 }
1350
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001351 /* If draw item is -1 (edit control) setup the item pointer */
1352 if (dis->itemID == 0xffffffff) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001353 item = infoPtr->edit;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001354
1355 if (infoPtr->hwndEdit) {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001356 INT len;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001357
1358 /* free previous text of edit item */
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001359 COMBOEX_FreeText(item);
1360 item->mask &= ~CBEIF_TEXT;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001361 if( (len = GetWindowTextLengthW(infoPtr->hwndEdit)) ) {
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001362 item->mask |= CBEIF_TEXT;
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001363 item->pszText = (LPWSTR)Alloc ((len + 1)*sizeof(WCHAR));
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001364 if (item->pszText)
1365 GetWindowTextW(infoPtr->hwndEdit, item->pszText, len+1);
Vincent Béron9a624912002-05-31 23:06:46 +00001366
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001367 TRACE("edit control hwndEdit=%p, text len=%d str=%s\n",
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001368 infoPtr->hwndEdit, len, debugstr_txt(item->pszText));
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001369 }
1370 }
Uwe Bonnesa07258d2000-10-29 18:04:45 +00001371 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001372
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001373
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001374 /* if the item pointer is not set, then get the data and locate it */
1375 if (!item) {
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001376 item = get_item_data(infoPtr, dis->itemID);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001377 if (item == (CBE_ITEMDATA *)CB_ERR) {
1378 ERR("invalid item for id %d \n", dis->itemID);
1379 return 0;
1380 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001381 }
1382
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001383 if (TRACE_ON(comboex)) COMBOEX_DumpItem (item);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001384
1385 xbase = CBE_STARTOFFSET;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001386 if ((item->mask & CBEIF_INDENT) && (dis->itemState & ODS_COMBOEXLBOX)) {
1387 INT indent = item->iIndent;
1388 if (indent == I_INDENTCALLBACK) {
1389 NMCOMBOBOXEXW nmce;
1390 ZeroMemory(&nmce, sizeof(nmce));
1391 nmce.ceItem.mask = CBEIF_INDENT;
Carlos Lozano53472222002-10-31 22:02:47 +00001392 nmce.ceItem.lParam = item->lParam;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001393 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1394 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1395 item->iIndent = nmce.ceItem.iIndent;
1396 indent = nmce.ceItem.iIndent;
1397 }
1398 xbase += (indent * CBE_INDENT);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001399 }
1400
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001401 drawimage = -2;
1402 drawstate = ILD_NORMAL;
1403 if (item->mask & CBEIF_IMAGE)
1404 drawimage = item->iImage;
1405 if (dis->itemState & ODS_COMBOEXLBOX) {
1406 /* drawing listbox entry */
1407 if (dis->itemState & ODS_SELECTED) {
1408 if (item->mask & CBEIF_SELECTEDIMAGE)
1409 drawimage = item->iSelectedImage;
1410 drawstate = ILD_SELECTED;
1411 }
1412 } else {
1413 /* drawing combo/edit entry */
1414 if (IsWindowVisible(infoPtr->hwndEdit)) {
Vincent Béron9a624912002-05-31 23:06:46 +00001415 /* if we have an edit control, the slave the
1416 * selection state to the Edit focus state
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001417 */
1418 if (infoPtr->flags & WCBE_EDITFOCUSED) {
1419 if (item->mask & CBEIF_SELECTEDIMAGE)
1420 drawimage = item->iSelectedImage;
1421 drawstate = ILD_SELECTED;
1422 }
1423 } else {
Vincent Béron9a624912002-05-31 23:06:46 +00001424 /* if we don't have an edit control, use
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001425 * the requested state.
1426 */
1427 if (dis->itemState & ODS_SELECTED) {
1428 if (item->mask & CBEIF_SELECTEDIMAGE)
1429 drawimage = item->iSelectedImage;
1430 drawstate = ILD_SELECTED;
1431 }
1432 }
1433 }
1434
1435 if (infoPtr->himl && !(infoPtr->dwExtStyle & CBES_EX_NOEDITIMAGEINDENT)) {
1436 IMAGEINFO iinfo;
1437 iinfo.rcImage.left = iinfo.rcImage.right = 0;
1438 ImageList_GetImageInfo(infoPtr->himl, 0, &iinfo);
1439 xioff = iinfo.rcImage.right - iinfo.rcImage.left + CBE_SEP;
1440 } else xioff = 0;
1441
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001442 /* setup pointer to text to be drawn */
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001443 str = COMBOEX_GetText(infoPtr, item);
1444 if (!str) str = nil;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001445
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001446 len = strlenW (str);
1447 GetTextExtentPoint32W (dis->hDC, str, len, &txtsize);
Vincent Béron9a624912002-05-31 23:06:46 +00001448
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001449 if (dis->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)) {
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001450 int overlay = item->iOverlay;
Vincent Béron9a624912002-05-31 23:06:46 +00001451
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001452 if (drawimage == I_IMAGECALLBACK) {
1453 NMCOMBOBOXEXW nmce;
1454 ZeroMemory(&nmce, sizeof(nmce));
1455 nmce.ceItem.mask = (drawstate == ILD_NORMAL) ? CBEIF_IMAGE : CBEIF_SELECTEDIMAGE;
Carlos Lozano53472222002-10-31 22:02:47 +00001456 nmce.ceItem.lParam = item->lParam;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001457 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1458 if (drawstate == ILD_NORMAL) {
1459 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iImage = nmce.ceItem.iImage;
1460 drawimage = nmce.ceItem.iImage;
1461 } else if (drawstate == ILD_SELECTED) {
1462 if (nmce.ceItem.mask & CBEIF_DI_SETITEM) item->iSelectedImage = nmce.ceItem.iSelectedImage;
1463 drawimage = nmce.ceItem.iSelectedImage;
1464 } else ERR("Bad draw state = %d\n", drawstate);
1465 }
1466
1467 if (overlay == I_IMAGECALLBACK) {
1468 NMCOMBOBOXEXW nmce;
1469 ZeroMemory(&nmce, sizeof(nmce));
1470 nmce.ceItem.mask = CBEIF_OVERLAY;
Carlos Lozano53472222002-10-31 22:02:47 +00001471 nmce.ceItem.lParam = item->lParam;
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001472 COMBOEX_NotifyItem(infoPtr, CBEN_GETDISPINFOW, &nmce);
1473 if (nmce.ceItem.mask & CBEIF_DI_SETITEM)
1474 item->iOverlay = nmce.ceItem.iOverlay;
1475 overlay = nmce.ceItem.iOverlay;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001476 }
Vincent Béron9a624912002-05-31 23:06:46 +00001477
1478 if (drawimage >= 0 &&
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001479 !(infoPtr->dwExtStyle & (CBES_EX_NOEDITIMAGE | CBES_EX_NOEDITIMAGEINDENT))) {
1480 if (overlay > 0) ImageList_SetOverlayImage (infoPtr->himl, overlay, 1);
Vincent Béron9a624912002-05-31 23:06:46 +00001481 ImageList_Draw (infoPtr->himl, drawimage, dis->hDC, xbase, dis->rcItem.top,
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001482 drawstate | (overlay > 0 ? INDEXTOOVERLAYMASK(1) : 0));
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001483 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00001484
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001485 /* now draw the text */
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001486 if (!IsWindowVisible (infoPtr->hwndEdit)) {
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001487 nbkc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1488 COLOR_HIGHLIGHT : COLOR_WINDOW);
1489 bkc = SetBkColor (dis->hDC, nbkc);
1490 ntxc = GetSysColor ((dis->itemState & ODS_SELECTED) ?
1491 COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT);
1492 txc = SetTextColor (dis->hDC, ntxc);
1493 x = xbase + xioff;
1494 y = dis->rcItem.top +
1495 (dis->rcItem.bottom - dis->rcItem.top - txtsize.cy) / 2;
1496 rect.left = x;
1497 rect.right = x + txtsize.cx;
1498 rect.top = dis->rcItem.top + 1;
1499 rect.bottom = dis->rcItem.bottom - 1;
Dan Kegel0fd521f2003-01-08 21:09:25 +00001500 TRACE("drawing item %d text, rect=(%ld,%ld)-(%ld,%ld)\n",
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00001501 dis->itemID, rect.left, rect.top, rect.right, rect.bottom);
1502 ExtTextOutW (dis->hDC, x, y, ETO_OPAQUE | ETO_CLIPPED,
1503 &rect, str, len, 0);
1504 SetBkColor (dis->hDC, bkc);
1505 SetTextColor (dis->hDC, txc);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001506 }
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001507 }
Vincent Béron9a624912002-05-31 23:06:46 +00001508
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001509 if (dis->itemAction & ODA_FOCUS) {
1510 rect.left = xbase + xioff - 1;
1511 rect.right = rect.left + txtsize.cx + 2;
1512 rect.top = dis->rcItem.top;
1513 rect.bottom = dis->rcItem.bottom;
1514 DrawFocusRect(dis->hDC, &rect);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001515 }
1516
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001517 return 0;
1518}
1519
1520
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001521static LRESULT COMBOEX_Destroy (COMBOEX_INFO *infoPtr)
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001522{
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001523 if (infoPtr->hwndCombo)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001524 DestroyWindow (infoPtr->hwndCombo);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001525
Guy L. Albertellia2495952001-01-26 21:00:10 +00001526 if (infoPtr->edit) {
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001527 Free (infoPtr->edit);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001528 infoPtr->edit = 0;
1529 }
1530
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001531 if (infoPtr->items) {
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001532 CBE_ITEMDATA *item, *next;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001533
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001534 item = infoPtr->items;
1535 while (item) {
1536 next = (CBE_ITEMDATA *)item->next;
1537 COMBOEX_FreeText (item);
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001538 Free (item);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001539 item = next;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001540 }
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001541 infoPtr->items = 0;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001542 }
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001543
Vincent Béron9a624912002-05-31 23:06:46 +00001544 if (infoPtr->defaultFont)
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001545 DeleteObject (infoPtr->defaultFont);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001546
1547 /* free comboex info data */
Dimitrie O. Paun7de279a2003-09-22 21:32:33 +00001548 Free (infoPtr);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001549 SetWindowLongW (infoPtr->hwndSelf, 0, 0);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001550 return 0;
1551}
1552
1553
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001554static LRESULT COMBOEX_MeasureItem (COMBOEX_INFO *infoPtr, MEASUREITEMSTRUCT *mis)
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001555{
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001556 SIZE mysize;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001557 HDC hdc;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001558
1559 hdc = GetDC (0);
1560 GetTextExtentPointA (hdc, "W", 1, &mysize);
1561 ReleaseDC (0, hdc);
1562 mis->itemHeight = mysize.cy + CBE_EXTRA;
1563
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001564 TRACE("adjusted height hwnd=%p, height=%d\n",
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001565 infoPtr->hwndSelf, mis->itemHeight);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001566
1567 return 0;
1568}
1569
1570
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001571static LRESULT COMBOEX_NCCreate (HWND hwnd)
Guy L. Albertellibad75902001-04-20 18:27:19 +00001572{
1573 /* WARNING: The COMBOEX_INFO structure is not yet created */
1574 DWORD oldstyle, newstyle;
1575
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001576 oldstyle = (DWORD)GetWindowLongW (hwnd, GWL_STYLE);
Guy L. Albertellibad75902001-04-20 18:27:19 +00001577 newstyle = oldstyle & ~(WS_VSCROLL | WS_HSCROLL);
1578 if (newstyle != oldstyle) {
1579 TRACE("req style %08lx, reseting style %08lx\n",
1580 oldstyle, newstyle);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001581 SetWindowLongW (hwnd, GWL_STYLE, newstyle);
Guy L. Albertellibad75902001-04-20 18:27:19 +00001582 }
1583 return 1;
1584}
1585
1586
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001587static LRESULT COMBOEX_NotifyFormat (COMBOEX_INFO *infoPtr, LPARAM lParam)
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001588{
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001589 if (lParam == NF_REQUERY) {
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00001590 INT i = SendMessageW(infoPtr->hwndNotify,
Michael Stefaniuc025c0b72002-09-06 19:41:17 +00001591 WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001592 infoPtr->NtfUnicode = (i == NFR_UNICODE) ? 1 : 0;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001593 }
Dimitrie O. Paun55f9b752002-04-23 19:27:10 +00001594 return infoPtr->NtfUnicode ? NFR_UNICODE : NFR_ANSI;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001595}
1596
1597
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001598static LRESULT COMBOEX_Size (COMBOEX_INFO *infoPtr, INT width, INT height)
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001599{
Vincent Béron9a624912002-05-31 23:06:46 +00001600 TRACE("(width=%d, height=%d)\n", width, height);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001601
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001602 MoveWindow (infoPtr->hwndCombo, 0, 0, width, height, TRUE);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001603
Guy L. Albertellia2495952001-01-26 21:00:10 +00001604 COMBOEX_AdjustEditPos (infoPtr);
1605
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001606 return 0;
1607}
1608
1609
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001610static LRESULT COMBOEX_WindowPosChanging (COMBOEX_INFO *infoPtr, WINDOWPOS *wp)
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001611{
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001612 RECT cbx_wrect, cbx_crect, cb_wrect;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001613 UINT width, height;
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001614
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001615 GetWindowRect (infoPtr->hwndSelf, &cbx_wrect);
1616 GetClientRect (infoPtr->hwndSelf, &cbx_crect);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001617 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1618
1619 /* width is winpos value + border width of comboex */
1620 width = wp->cx
Vincent Béron9a624912002-05-31 23:06:46 +00001621 + (cbx_wrect.right-cbx_wrect.left)
1622 - (cbx_crect.right-cbx_crect.left);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001623
Guy L. Albertellibad75902001-04-20 18:27:19 +00001624 TRACE("winpos=(%d,%d %dx%d) flags=0x%08x\n",
1625 wp->x, wp->y, wp->cx, wp->cy, wp->flags);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001626 TRACE("EX window=(%ld,%ld)-(%ld,%ld), client=(%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001627 cbx_wrect.left, cbx_wrect.top, cbx_wrect.right, cbx_wrect.bottom,
1628 cbx_crect.left, cbx_crect.top, cbx_crect.right, cbx_crect.bottom);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001629 TRACE("CB window=(%ld,%ld)-(%ld,%ld), EX setting=(0,0)-(%d,%ld)\n",
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001630 cb_wrect.left, cb_wrect.top, cb_wrect.right, cb_wrect.bottom,
1631 width, cb_wrect.bottom-cb_wrect.top);
1632
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001633 if (width) SetWindowPos (infoPtr->hwndCombo, HWND_TOP, 0, 0,
1634 width,
1635 cb_wrect.bottom-cb_wrect.top,
1636 SWP_NOACTIVATE);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00001637
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001638 GetWindowRect (infoPtr->hwndCombo, &cb_wrect);
1639
1640 /* height is combo window height plus border width of comboex */
1641 height = (cb_wrect.bottom-cb_wrect.top)
1642 + (cbx_wrect.bottom-cbx_wrect.top)
1643 - (cbx_crect.bottom-cbx_crect.top);
1644 if (wp->cy < height) wp->cy = height;
1645 if (infoPtr->hwndEdit) {
1646 COMBOEX_AdjustEditPos (infoPtr);
1647 InvalidateRect (infoPtr->hwndCombo, 0, TRUE);
1648 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00001649
1650 return 0;
1651}
1652
Dimitrie O. Paunf14b5272002-08-27 18:16:48 +00001653static inline int is_delimiter(WCHAR c)
1654{
1655 switch(c) {
1656 case '/':
1657 case '\\':
1658 case '.':
1659 return TRUE;
1660 }
1661 return FALSE;
1662}
1663
1664static int CALLBACK
1665COMBOEX_PathWordBreakProc(LPWSTR lpch, int ichCurrent, int cch, int code)
1666{
1667 if (code == WB_ISDELIMITER) {
1668 return is_delimiter(lpch[ichCurrent]);
1669 } else {
1670 int dir = (code == WB_LEFT) ? -1 : 1;
1671 for(; 0 <= ichCurrent && ichCurrent < cch; ichCurrent += dir)
1672 if (is_delimiter(lpch[ichCurrent])) return ichCurrent;
1673 }
1674 return ichCurrent;
1675}
Guy L. Albertellia2495952001-01-26 21:00:10 +00001676
1677static LRESULT WINAPI
1678COMBOEX_EditWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1679{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001680 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1681 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001682 NMCBEENDEDITW cbeend;
1683 WCHAR edit_text[260];
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001684 COLORREF obkc;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001685 HDC hDC;
1686 RECT rect;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001687 LRESULT lret;
Guy L. Albertellia2495952001-01-26 21:00:10 +00001688
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001689 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001690 hwnd, uMsg, wParam, lParam, infoPtr);
1691
1692 if (!infoPtr) return 0;
1693
1694 switch (uMsg)
1695 {
1696
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001697 case WM_CHAR:
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001698 /* handle (ignore) the return character */
1699 if (wParam == VK_RETURN) return 0;
1700 /* all other characters pass into the real Edit */
Vincent Béron9a624912002-05-31 23:06:46 +00001701 return CallWindowProcW (infoPtr->prevEditWndProc,
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001702 hwnd, uMsg, wParam, lParam);
1703
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001704 case WM_ERASEBKGND:
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001705 /*
Vincent Béron9a624912002-05-31 23:06:46 +00001706 * The following was determined by traces of the native
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001707 */
1708 hDC = (HDC) wParam;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001709 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001710 GetClientRect (hwnd, &rect);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001711 TRACE("erasing (%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001712 rect.left, rect.top, rect.right, rect.bottom);
1713 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1714 SetBkColor (hDC, obkc);
Vincent Béron9a624912002-05-31 23:06:46 +00001715 return CallWindowProcW (infoPtr->prevEditWndProc,
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001716 hwnd, uMsg, wParam, lParam);
1717
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001718 case WM_KEYDOWN: {
1719 INT oldItem, selected, step = 1;
Guy L. Albertellia2495952001-01-26 21:00:10 +00001720 CBE_ITEMDATA *item;
1721
1722 switch ((INT)wParam)
1723 {
1724 case VK_ESCAPE:
1725 /* native version seems to do following for COMBOEX */
1726 /*
1727 * GetWindowTextA(Edit,&?, 0x104) x
1728 * CB_GETCURSEL to Combo rets -1 x
1729 * WM_NOTIFY to COMBOEX parent (rebar) x
Vincent Béron9a624912002-05-31 23:06:46 +00001730 * (CBEN_ENDEDIT{A|W}
Guy L. Albertellia2495952001-01-26 21:00:10 +00001731 * fChanged = FALSE x
1732 * inewSelection = -1 x
1733 * txt="www.hoho" x
1734 * iWhy = 3 x
1735 * CB_GETCURSEL to Combo rets -1 x
1736 * InvalidateRect(Combo, 0) x
1737 * WM_SETTEXT to Edit x
1738 * EM_SETSEL to Edit (0,0) x
1739 * EM_SETSEL to Edit (0,-1) x
1740 * RedrawWindow(Combo, 0, 0, 5) x
1741 */
1742 TRACE("special code for VK_ESCAPE\n");
1743
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001744 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001745
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001746 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001747 cbeend.fChanged = FALSE;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001748 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
Guy L. Albertellia2495952001-01-26 21:00:10 +00001749 CB_GETCURSEL, 0, 0);
1750 cbeend.iWhy = CBENF_ESCAPE;
1751
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001752 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001753 oldItem = SendMessageW (infoPtr->hwndCombo, CB_GETCURSEL, 0, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001754 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1755 if (!(item = COMBOEX_FindItem(infoPtr, oldItem))) {
1756 ERR("item %d not found. Problem!\n", oldItem);
1757 break;
1758 }
Vincent Béron9a624912002-05-31 23:06:46 +00001759 infoPtr->selected = oldItem;
Guy L. Albertellia2495952001-01-26 21:00:10 +00001760 COMBOEX_SetEditText (infoPtr, item);
Vincent Béron9a624912002-05-31 23:06:46 +00001761 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
Guy L. Albertellia2495952001-01-26 21:00:10 +00001762 RDW_INVALIDATE);
1763 break;
1764
1765 case VK_RETURN:
1766 /* native version seems to do following for COMBOEX */
1767 /*
1768 * GetWindowTextA(Edit,&?, 0x104) x
1769 * CB_GETCURSEL to Combo rets -1 x
1770 * CB_GETCOUNT to Combo rets 0
Vincent Béron9a624912002-05-31 23:06:46 +00001771 * if >0 loop
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001772 * CB_GETITEMDATA to match
Vincent Béron9a624912002-05-31 23:06:46 +00001773 * *** above 3 lines simulated by FindItem x
Guy L. Albertellia2495952001-01-26 21:00:10 +00001774 * WM_NOTIFY to COMBOEX parent (rebar) x
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001775 * (CBEN_ENDEDIT{A|W} x
Guy L. Albertellia2495952001-01-26 21:00:10 +00001776 * fChanged = TRUE (-1) x
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001777 * iNewSelection = -1 or selected x
Guy L. Albertellia2495952001-01-26 21:00:10 +00001778 * txt= x
1779 * iWhy = 2 (CBENF_RETURN) x
1780 * CB_GETCURSEL to Combo rets -1 x
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001781 * if -1 send CB_SETCURSEL to Combo -1 x
Guy L. Albertellia2495952001-01-26 21:00:10 +00001782 * InvalidateRect(Combo, 0, 0) x
1783 * SetFocus(Edit) x
1784 * CallWindowProc(406615a8, Edit, 0x100, 0xd, 0x1c0001)
1785 */
1786
1787 TRACE("special code for VK_RETURN\n");
1788
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001789 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001790
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001791 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
1792 selected = SendMessageW (infoPtr->hwndCombo,
1793 CB_GETCURSEL, 0, 0);
1794
1795 if (selected != -1) {
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00001796 cmp_func_t cmptext = get_cmp_func(infoPtr);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001797 item = COMBOEX_FindItem (infoPtr, selected);
1798 TRACE("handling VK_RETURN, selected = %d, selected_text=%s\n",
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00001799 selected, debugstr_txt(item->pszText));
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001800 TRACE("handling VK_RETURN, edittext=%s\n",
1801 debugstr_w(edit_text));
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00001802 if (cmptext (COMBOEX_GetText(infoPtr, item), edit_text)) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001803 /* strings not equal -- indicate edit has changed */
1804 selected = -1;
1805 }
1806 }
1807
1808 cbeend.iNewSelection = selected;
Vincent Béron9a624912002-05-31 23:06:46 +00001809 cbeend.fChanged = TRUE;
Guy L. Albertellia2495952001-01-26 21:00:10 +00001810 cbeend.iWhy = CBENF_RETURN;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001811 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001812 /* abort the change, restore previous */
1813 TRACE("Notify requested abort of change\n");
1814 COMBOEX_SetEditText (infoPtr, infoPtr->edit);
Vincent Béron9a624912002-05-31 23:06:46 +00001815 RedrawWindow (infoPtr->hwndCombo, 0, 0, RDW_ERASE |
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001816 RDW_INVALIDATE);
Guy L. Albertellia2495952001-01-26 21:00:10 +00001817 return 0;
1818 }
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001819 oldItem = SendMessageW (infoPtr->hwndCombo,CB_GETCURSEL, 0, 0);
1820 if (oldItem != -1) {
1821 /* if something is selected, then deselect it */
Vincent Béron9a624912002-05-31 23:06:46 +00001822 SendMessageW (infoPtr->hwndCombo, CB_SETCURSEL,
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001823 (WPARAM)-1, 0);
1824 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00001825 InvalidateRect (infoPtr->hwndCombo, 0, 0);
1826 SetFocus(infoPtr->hwndEdit);
1827 break;
1828
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001829 case VK_UP:
1830 step = -1;
1831 case VK_DOWN:
1832 /* by default, step is 1 */
1833 oldItem = SendMessageW (infoPtr->hwndSelf, CB_GETCURSEL, 0, 0);
1834 if (oldItem >= 0 && oldItem + step >= 0)
1835 SendMessageW (infoPtr->hwndSelf, CB_SETCURSEL, oldItem + step, 0);
1836 return 0;
Guy L. Albertellia2495952001-01-26 21:00:10 +00001837 default:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001838 return CallWindowProcW (infoPtr->prevEditWndProc,
Guy L. Albertellia2495952001-01-26 21:00:10 +00001839 hwnd, uMsg, wParam, lParam);
1840 }
1841 return 0;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001842 }
1843
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001844 case WM_SETFOCUS:
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001845 /* remember the focus to set state of icon */
Vincent Béron9a624912002-05-31 23:06:46 +00001846 lret = CallWindowProcW (infoPtr->prevEditWndProc,
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001847 hwnd, uMsg, wParam, lParam);
1848 infoPtr->flags |= WCBE_EDITFOCUSED;
1849 return lret;
1850
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001851 case WM_KILLFOCUS:
Vincent Béron9a624912002-05-31 23:06:46 +00001852 /*
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001853 * do NOTIFY CBEN_ENDEDIT with CBENF_KILLFOCUS
Guy L. Albertellia2495952001-01-26 21:00:10 +00001854 */
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001855 infoPtr->flags &= ~WCBE_EDITFOCUSED;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001856 if (infoPtr->flags & WCBE_ACTEDIT) {
1857 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001858
1859 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001860 cbeend.fChanged = FALSE;
1861 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
1862 CB_GETCURSEL, 0, 0);
1863 cbeend.iWhy = CBENF_KILLFOCUS;
Guy L. Albertellia2495952001-01-26 21:00:10 +00001864
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001865 COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001866 }
1867 /* fall through */
1868
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001869 default:
Vincent Béron9a624912002-05-31 23:06:46 +00001870 return CallWindowProcW (infoPtr->prevEditWndProc,
Guy L. Albertellia2495952001-01-26 21:00:10 +00001871 hwnd, uMsg, wParam, lParam);
1872 }
1873 return 0;
1874}
1875
1876
1877static LRESULT WINAPI
1878COMBOEX_ComboWndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1879{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001880 HWND hwndComboex = (HWND)GetPropA(hwnd, COMBOEX_SUBCLASS_PROP);
1881 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwndComboex);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001882 NMCBEENDEDITW cbeend;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001883 NMMOUSE nmmse;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001884 COLORREF obkc;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001885 HDC hDC;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001886 HWND focusedhwnd;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001887 RECT rect;
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +00001888 POINT pt;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001889 WCHAR edit_text[260];
Guy L. Albertellia2495952001-01-26 21:00:10 +00001890
Michael Stefaniuc353529b2002-10-23 22:19:10 +00001891 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx, info_ptr=%p\n",
Guy L. Albertellia2495952001-01-26 21:00:10 +00001892 hwnd, uMsg, wParam, lParam, infoPtr);
1893
1894 if (!infoPtr) return 0;
1895
1896 switch (uMsg)
1897 {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001898
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001899 case WM_DRAWITEM:
1900 /*
1901 * The only way this message should come is from the
1902 * child Listbox issuing the message. Flag this so
1903 * that ComboEx knows this is listbox.
1904 */
1905 ((DRAWITEMSTRUCT *)lParam)->itemState |= ODS_COMBOEXLBOX;
Vincent Béron9a624912002-05-31 23:06:46 +00001906 return CallWindowProcW (infoPtr->prevComboWndProc,
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001907 hwnd, uMsg, wParam, lParam);
1908
1909 case WM_ERASEBKGND:
1910 /*
Vincent Béron9a624912002-05-31 23:06:46 +00001911 * The following was determined by traces of the native
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001912 */
1913 hDC = (HDC) wParam;
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00001914 obkc = SetBkColor (hDC, GetSysColor (COLOR_WINDOW));
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001915 GetClientRect (hwnd, &rect);
Dan Kegel0fd521f2003-01-08 21:09:25 +00001916 TRACE("erasing (%ld,%ld)-(%ld,%ld)\n",
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001917 rect.left, rect.top, rect.right, rect.bottom);
1918 ExtTextOutW (hDC, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0);
1919 SetBkColor (hDC, obkc);
Vincent Béron9a624912002-05-31 23:06:46 +00001920 return CallWindowProcW (infoPtr->prevComboWndProc,
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001921 hwnd, uMsg, wParam, lParam);
1922
1923 case WM_SETCURSOR:
1924 /*
1925 * WM_NOTIFY to comboex parent (rebar)
1926 * with NM_SETCURSOR with extra words of 0,0,0,0,0x02010001
1927 * CallWindowProc (previous)
1928 */
1929 nmmse.dwItemSpec = 0;
1930 nmmse.dwItemData = 0;
1931 nmmse.pt.x = 0;
1932 nmmse.pt.y = 0;
1933 nmmse.dwHitInfo = lParam;
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001934 COMBOEX_Notify (infoPtr, NM_SETCURSOR, (NMHDR *)&nmmse);
Vincent Béron9a624912002-05-31 23:06:46 +00001935 return CallWindowProcW (infoPtr->prevComboWndProc,
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00001936 hwnd, uMsg, wParam, lParam);
1937
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +00001938 case WM_LBUTTONDOWN:
1939 GetClientRect (hwnd, &rect);
1940 rect.bottom = rect.top + SendMessageW(infoPtr->hwndSelf,
1941 CB_GETITEMHEIGHT, -1, 0);
1942 rect.left = rect.right - GetSystemMetrics(SM_CXVSCROLL);
Dimitrie O. Paun856a91b2002-09-09 19:21:30 +00001943 POINTSTOPOINT(pt, MAKEPOINTS(lParam));
Dimitrie O. Paun69c9c432002-08-28 22:21:46 +00001944 if (PtInRect(&rect, pt))
1945 return CallWindowProcW (infoPtr->prevComboWndProc,
1946 hwnd, uMsg, wParam, lParam);
1947 infoPtr->flags |= WCBE_MOUSECAPTURED;
1948 SetCapture(hwnd);
1949 break;
1950
1951 case WM_LBUTTONUP:
1952 if (!(infoPtr->flags & WCBE_MOUSECAPTURED))
1953 return CallWindowProcW (infoPtr->prevComboWndProc,
1954 hwnd, uMsg, wParam, lParam);
1955 ReleaseCapture();
1956 infoPtr->flags &= ~WCBE_MOUSECAPTURED;
1957 if (infoPtr->flags & WCBE_MOUSEDRAGGED) {
1958 infoPtr->flags &= ~WCBE_MOUSEDRAGGED;
1959 } else {
1960 SendMessageW(hwnd, CB_SHOWDROPDOWN, TRUE, 0);
1961 }
1962 break;
1963
1964 case WM_MOUSEMOVE:
1965 if ( (infoPtr->flags & WCBE_MOUSECAPTURED) &&
1966 !(infoPtr->flags & WCBE_MOUSEDRAGGED)) {
1967 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
1968 COMBOEX_NotifyDragBegin(infoPtr, edit_text);
1969 infoPtr->flags |= WCBE_MOUSEDRAGGED;
1970 }
1971 return CallWindowProcW (infoPtr->prevComboWndProc,
1972 hwnd, uMsg, wParam, lParam);
1973
Guy L. Albertellia2495952001-01-26 21:00:10 +00001974 case WM_COMMAND:
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001975 switch (HIWORD(wParam)) {
Guy L. Albertellia2495952001-01-26 21:00:10 +00001976
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001977 case EN_UPDATE:
1978 /* traces show that COMBOEX does not issue CBN_EDITUPDATE
1979 * on the EN_UPDATE
1980 */
1981 return 0;
1982
1983 case EN_KILLFOCUS:
1984 /*
1985 * Native does:
1986 *
1987 * GetFocus() retns AA
1988 * GetWindowTextA(Edit)
1989 * CB_GETCURSEL(Combo) (got -1)
1990 * WM_NOTIFY(CBEN_ENDEDITA) with CBENF_KILLFOCUS
1991 * CB_GETCURSEL(Combo) (got -1)
1992 * InvalidateRect(Combo, 0, 0)
1993 * WM_KILLFOCUS(Combo, AA)
1994 * return 0;
1995 */
1996 focusedhwnd = GetFocus();
1997 if (infoPtr->flags & WCBE_ACTEDIT) {
Guy L. Albertellib2207c72001-06-24 00:22:20 +00001998 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00001999 cbeend.fChanged = (infoPtr->flags & WCBE_EDITCHG);
2000 cbeend.iNewSelection = SendMessageW (infoPtr->hwndCombo,
2001 CB_GETCURSEL, 0, 0);
2002 cbeend.iWhy = CBENF_KILLFOCUS;
2003
2004 infoPtr->flags &= ~(WCBE_ACTEDIT | WCBE_EDITCHG);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00002005 if (COMBOEX_NotifyEndEdit (infoPtr, &cbeend, edit_text)) return 0;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002006 }
2007 /* possible CB_GETCURSEL */
2008 InvalidateRect (infoPtr->hwndCombo, 0, 0);
2009 if (focusedhwnd)
2010 SendMessageW (infoPtr->hwndCombo, WM_KILLFOCUS,
Vincent Béron9a624912002-05-31 23:06:46 +00002011 (WPARAM)focusedhwnd, 0);
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002012 return 0;
2013
2014 case EN_SETFOCUS: {
Vincent Béron9a624912002-05-31 23:06:46 +00002015 /*
Guy L. Albertellia2495952001-01-26 21:00:10 +00002016 * For EN_SETFOCUS this issues the same calls and messages
2017 * as the native seems to do.
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002018 *
2019 * for some cases however native does the following:
2020 * (noticed after SetFocus during LBUTTONDOWN on
2021 * on dropdown arrow)
2022 * WM_GETTEXTLENGTH (Edit);
2023 * WM_GETTEXT (Edit, len+1, str);
2024 * EM_SETSEL (Edit, 0, 0);
2025 * WM_GETTEXTLENGTH (Edit);
2026 * WM_GETTEXT (Edit, len+1, str);
2027 * EM_SETSEL (Edit, 0, len);
2028 * WM_NOTIFY (parent, CBEN_BEGINEDIT)
Guy L. Albertellia2495952001-01-26 21:00:10 +00002029 */
2030 NMHDR hdr;
2031
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002032 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, 0);
2033 SendMessageW (infoPtr->hwndEdit, EM_SETSEL, 0, -1);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00002034 COMBOEX_Notify (infoPtr, CBEN_BEGINEDIT, &hdr);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002035 infoPtr->flags |= WCBE_ACTEDIT;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002036 infoPtr->flags &= ~WCBE_EDITCHG; /* no change yet */
Guy L. Albertellia2495952001-01-26 21:00:10 +00002037 return 0;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002038 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00002039
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002040 case EN_CHANGE: {
Vincent Béron9a624912002-05-31 23:06:46 +00002041 /*
Guy L. Albertellia2495952001-01-26 21:00:10 +00002042 * For EN_CHANGE this issues the same calls and messages
2043 * as the native seems to do.
2044 */
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002045 WCHAR edit_text[260];
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00002046 LPCWSTR lastwrk;
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00002047 cmp_func_t cmptext = get_cmp_func(infoPtr);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002048
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00002049 INT selected = SendMessageW (infoPtr->hwndCombo,
2050 CB_GETCURSEL, 0, 0);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002051
2052 /* lstrlenA( lastworkingURL ) */
2053
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002054 GetWindowTextW (infoPtr->hwndEdit, edit_text, 260);
2055 if (selected == -1) {
2056 lastwrk = infoPtr->edit->pszText;
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002057 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00002058 else {
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00002059 CBE_ITEMDATA *item = COMBOEX_FindItem (infoPtr, selected);
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00002060 lastwrk = COMBOEX_GetText(infoPtr, item);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002061 }
2062
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002063 TRACE("handling EN_CHANGE, selected = %d, selected_text=%s\n",
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002064 selected, debugstr_w(lastwrk));
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002065 TRACE("handling EN_CHANGE, edittext=%s\n",
2066 debugstr_w(edit_text));
Guy L. Albertellia2495952001-01-26 21:00:10 +00002067
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00002068 /* cmptext is between lastworkingURL and GetWindowText */
2069 if (cmptext (lastwrk, edit_text)) {
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002070 /* strings not equal -- indicate edit has changed */
2071 infoPtr->flags |= WCBE_EDITCHG;
Guy L. Albertellia2495952001-01-26 21:00:10 +00002072 }
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00002073 SendMessageW ( infoPtr->hwndNotify, WM_COMMAND,
Guy L. Albertellia2495952001-01-26 21:00:10 +00002074 MAKEWPARAM(GetDlgCtrlID (infoPtr->hwndSelf),
2075 CBN_EDITCHANGE),
Michael Stefaniuc025c0b72002-09-06 19:41:17 +00002076 (LPARAM)infoPtr->hwndSelf);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002077 return 0;
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002078 }
Guy L. Albertellia2495952001-01-26 21:00:10 +00002079
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002080 case LBN_SELCHANGE:
2081 /*
2082 * Therefore from traces there is no additional code here
2083 */
Guy L. Albertellia2495952001-01-26 21:00:10 +00002084
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002085 /*
2086 * Using native COMCTL32 gets the following:
2087 * 1 == SHDOCVW.DLL issues call/message
2088 * 2 == COMCTL32.DLL issues call/message
2089 * 3 == WINE issues call/message
2090 *
2091 *
2092 * for LBN_SELCHANGE:
2093 * 1 CB_GETCURSEL(ComboEx)
2094 * 1 CB_GETDROPPEDSTATE(ComboEx)
2095 * 1 CallWindowProc( *2* for WM_COMMAND(LBN_SELCHANGE)
2096 * 2 CallWindowProc( *3* for WM_COMMAND(LBN_SELCHANGE)
2097 ** call CBRollUp( xxx, TRUE for LBN_SELCHANGE, TRUE)
2098 * 3 WM_COMMAND(ComboEx, CBN_SELENDOK)
2099 * WM_USER+49(ComboLB, 1,0) <=============!!!!!!!!!!!
2100 * 3 ShowWindow(ComboLB, SW_HIDE)
2101 * 3 RedrawWindow(Combo, RDW_UPDATENOW)
2102 * 3 WM_COMMAND(ComboEX, CBN_CLOSEUP)
2103 ** end of CBRollUp
2104 * 3 WM_COMMAND(ComboEx, CBN_SELCHANGE) (echo to parent)
2105 * ? LB_GETCURSEL <==|
2106 * ? LB_GETTEXTLEN |
2107 * ? LB_GETTEXT | Needs to be added to
2108 * ? WM_CTLCOLOREDIT(ComboEx) | Combo processing
2109 * ? LB_GETITEMDATA |
2110 * ? WM_DRAWITEM(ComboEx) <==|
2111 */
2112 default:
2113 break;
2114 }/* fall through */
Guy L. Albertellia2495952001-01-26 21:00:10 +00002115 default:
Vincent Béron9a624912002-05-31 23:06:46 +00002116 return CallWindowProcW (infoPtr->prevComboWndProc,
Guy L. Albertellia2495952001-01-26 21:00:10 +00002117 hwnd, uMsg, wParam, lParam);
2118 }
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002119 return 0;
2120}
2121
2122
Patrik Stridvall26ffb3c1999-07-31 14:41:43 +00002123static LRESULT WINAPI
Alexandre Julliarda3960291999-02-26 11:11:13 +00002124COMBOEX_WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002125{
Guy L. Albertellib2207c72001-06-24 00:22:20 +00002126 COMBOEX_INFO *infoPtr = COMBOEX_GetInfoPtr (hwnd);
2127
Michael Stefaniuc353529b2002-10-23 22:19:10 +00002128 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, uMsg, wParam, lParam);
Guy L. Albertellibad75902001-04-20 18:27:19 +00002129
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002130 if (!infoPtr) {
Guy L. Albertellibad75902001-04-20 18:27:19 +00002131 if (uMsg == WM_CREATE)
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002132 return COMBOEX_Create (hwnd, (LPCREATESTRUCTA)lParam);
Guy L. Albertellibad75902001-04-20 18:27:19 +00002133 if (uMsg == WM_NCCREATE)
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002134 COMBOEX_NCCreate (hwnd);
2135 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
Guy L. Albertellibad75902001-04-20 18:27:19 +00002136 }
Gerard Patela1b2fc22000-05-10 01:34:53 +00002137
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002138 switch (uMsg)
2139 {
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002140 case CBEM_DELETEITEM:
2141 return COMBOEX_DeleteItem (infoPtr, wParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002142
2143 case CBEM_GETCOMBOCONTROL:
Michael Stefaniuc025c0b72002-09-06 19:41:17 +00002144 return (LRESULT)infoPtr->hwndCombo;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002145
2146 case CBEM_GETEDITCONTROL:
Michael Stefaniuc025c0b72002-09-06 19:41:17 +00002147 return (LRESULT)infoPtr->hwndEdit;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002148
2149 case CBEM_GETEXTENDEDSTYLE:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002150 return infoPtr->dwExtStyle;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002151
2152 case CBEM_GETIMAGELIST:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002153 return (LRESULT)infoPtr->himl;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002154
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002155 case CBEM_GETITEMA:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002156 return (LRESULT)COMBOEX_GetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002157
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002158 case CBEM_GETITEMW:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002159 return (LRESULT)COMBOEX_GetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002160
Andreas Mohr7a6228d1998-12-11 09:16:48 +00002161 case CBEM_GETUNICODEFORMAT:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002162 return infoPtr->unicode;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002163
Guy L. Albertellia2495952001-01-26 21:00:10 +00002164 case CBEM_HASEDITCHANGED:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002165 return COMBOEX_HasEditChanged (infoPtr);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002166
Alexandre Julliarda3960291999-02-26 11:11:13 +00002167 case CBEM_INSERTITEMA:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002168 return COMBOEX_InsertItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002169
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002170 case CBEM_INSERTITEMW:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002171 return COMBOEX_InsertItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002172
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002173 case CBEM_SETEXSTYLE:
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002174 case CBEM_SETEXTENDEDSTYLE:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002175 return COMBOEX_SetExtendedStyle (infoPtr, (DWORD)wParam, (DWORD)lParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002176
2177 case CBEM_SETIMAGELIST:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002178 return (LRESULT)COMBOEX_SetImageList (infoPtr, (HIMAGELIST)lParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002179
Alexandre Julliarda3960291999-02-26 11:11:13 +00002180 case CBEM_SETITEMA:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002181 return COMBOEX_SetItemA (infoPtr, (COMBOBOXEXITEMA *)lParam);
Eric Kohl66ef0111998-11-22 17:58:40 +00002182
Marcus Meissner643fcff2000-11-06 20:22:06 +00002183 case CBEM_SETITEMW:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002184 return COMBOEX_SetItemW (infoPtr, (COMBOBOXEXITEMW *)lParam);
Marcus Meissner643fcff2000-11-06 20:22:06 +00002185
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002186 case CBEM_SETUNICODEFORMAT:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002187 return COMBOEX_SetUnicodeFormat (infoPtr, wParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002188
Dimitrie O. Paun43230a22002-04-08 20:16:01 +00002189 /*case CBEM_SETWINDOWTHEME:
2190 FIXME("CBEM_SETWINDOWTHEME: stub\n");*/
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002191
Dmitry Timoshkov2f2e4fa2002-08-13 18:07:02 +00002192 case WM_SETTEXT:
2193 case WM_GETTEXT:
2194 return SendMessageW(infoPtr->hwndEdit, uMsg, wParam, lParam);
2195
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002196/* Combo messages we are not sure if we need to process or just forward */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002197 case CB_GETDROPPEDCONTROLRECT:
Alexandre Julliarda3960291999-02-26 11:11:13 +00002198 case CB_GETITEMHEIGHT:
2199 case CB_GETLBTEXT:
2200 case CB_GETLBTEXTLEN:
2201 case CB_GETEXTENDEDUI:
2202 case CB_LIMITTEXT:
2203 case CB_RESETCONTENT:
2204 case CB_SELECTSTRING:
Eric Kohl66ef0111998-11-22 17:58:40 +00002205
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002206/* Combo messages OK to just forward to the regular COMBO */
Vincent Béron9a624912002-05-31 23:06:46 +00002207 case CB_GETCOUNT:
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002208 case CB_GETCURSEL:
Guy L. Albertellia7a006a2001-03-16 16:41:56 +00002209 case CB_GETDROPPEDSTATE:
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002210 case CB_SETDROPPEDWIDTH:
2211 case CB_SETEXTENDEDUI:
2212 case CB_SHOWDROPDOWN:
Dimitrie O. Paund5d431f2002-04-11 17:33:47 +00002213 return SendMessageW (infoPtr->hwndCombo, uMsg, wParam, lParam);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002214
2215/* Combo messages we need to process specially */
2216 case CB_FINDSTRINGEXACT:
Dimitrie O. Paun9ff6e772002-08-26 21:46:25 +00002217 return COMBOEX_FindStringExact (infoPtr, (INT)wParam, (LPCWSTR)lParam);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002218
Guy L. Albertellibad75902001-04-20 18:27:19 +00002219 case CB_GETITEMDATA:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002220 return COMBOEX_GetItemData (infoPtr, (INT)wParam);
Guy L. Albertellibad75902001-04-20 18:27:19 +00002221
Guy L. Albertellia2495952001-01-26 21:00:10 +00002222 case CB_SETCURSEL:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002223 return COMBOEX_SetCursel (infoPtr, (INT)wParam);
Guy L. Albertellia2495952001-01-26 21:00:10 +00002224
Guy L. Albertellibad75902001-04-20 18:27:19 +00002225 case CB_SETITEMDATA:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002226 return COMBOEX_SetItemData (infoPtr, (INT)wParam, (DWORD)lParam);
Guy L. Albertellibad75902001-04-20 18:27:19 +00002227
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002228 case CB_SETITEMHEIGHT:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002229 return COMBOEX_SetItemHeight (infoPtr, (INT)wParam, (UINT)lParam);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002230
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002231
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002232
2233/* Window messages passed to parent */
Guy L. Albertelli762ed032000-12-18 03:12:31 +00002234 case WM_COMMAND:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002235 return COMBOEX_Command (infoPtr, wParam, lParam);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002236
Guy L. Albertelli762ed032000-12-18 03:12:31 +00002237 case WM_NOTIFY:
Guy L. Albertellib2207c72001-06-24 00:22:20 +00002238 if (infoPtr->NtfUnicode)
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00002239 return SendMessageW (infoPtr->hwndNotify, uMsg, wParam, lParam);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00002240 else
Dimitrie O. Paunc5940432003-11-20 22:04:13 +00002241 return SendMessageA (infoPtr->hwndNotify, uMsg, wParam, lParam);
Guy L. Albertelli762ed032000-12-18 03:12:31 +00002242
2243
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002244/* Window messages we need to process */
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002245 case WM_DELETEITEM:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002246 return COMBOEX_WM_DeleteItem (infoPtr, (DELETEITEMSTRUCT *)lParam);
Guy L. Albertelli45e6f622001-02-20 01:53:43 +00002247
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002248 case WM_DRAWITEM:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002249 return COMBOEX_DrawItem (infoPtr, (DRAWITEMSTRUCT *)lParam);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002250
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002251 case WM_DESTROY:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002252 return COMBOEX_Destroy (infoPtr);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002253
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002254 case WM_MEASUREITEM:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002255 return COMBOEX_MeasureItem (infoPtr, (MEASUREITEMSTRUCT *)lParam);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002256
Guy L. Albertellib2207c72001-06-24 00:22:20 +00002257 case WM_NOTIFYFORMAT:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002258 return COMBOEX_NotifyFormat (infoPtr, lParam);
Guy L. Albertellib2207c72001-06-24 00:22:20 +00002259
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002260 case WM_SIZE:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002261 return COMBOEX_Size (infoPtr, LOWORD(lParam), HIWORD(lParam));
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002262
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002263 case WM_WINDOWPOSCHANGING:
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002264 return COMBOEX_WindowPosChanging (infoPtr, (WINDOWPOS *)lParam);
Guy L. Albertellic6c53cd2000-10-29 01:16:53 +00002265
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002266 default:
Guy L. Albertelli23739a32002-07-16 01:23:59 +00002267 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002268 ERR("unknown msg %04x wp=%08x lp=%08lx\n",uMsg,wParam,lParam);
2269 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002270 }
2271 return 0;
2272}
2273
2274
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002275void COMBOEX_Register (void)
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002276{
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002277 WNDCLASSW wndClass;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002278
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002279 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002280 wndClass.style = CS_GLOBALCLASS;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002281 wndClass.lpfnWndProc = (WNDPROC)COMBOEX_WindowProc;
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002282 wndClass.cbClsExtra = 0;
2283 wndClass.cbWndExtra = sizeof(COMBOEX_INFO *);
Alexandre Julliardcf526442003-09-10 03:56:47 +00002284 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
Alexandre Julliarda3960291999-02-26 11:11:13 +00002285 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002286 wndClass.lpszClassName = WC_COMBOBOXEXW;
Vincent Béron9a624912002-05-31 23:06:46 +00002287
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002288 RegisterClassW (&wndClass);
Alexandre Julliarda0d77311998-09-13 16:32:00 +00002289}
2290
Eric Kohl9d8e8641998-10-24 10:49:27 +00002291
Dimitrie O. Paun7c3fca12002-04-05 21:16:19 +00002292void COMBOEX_Unregister (void)
Eric Kohl9d8e8641998-10-24 10:49:27 +00002293{
Francois Gougetd2667a42002-12-02 18:10:57 +00002294 UnregisterClassW (WC_COMBOBOXEXW, NULL);
Eric Kohl9d8e8641998-10-24 10:49:27 +00002295}