2 * Common controls functions
4 * Copyright 1997 Dimitrie O. Paun
5 * 1998 Juergen Schmied <j.schmied@metronet.de>
6 * Copyright 1998,2000 Eric Kohl
7 * Copyright 2014-2015 Michael Müller
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * This code was audited for completeness against the documented features
26 * of Comctl32.dll version 6.0 on Oct. 21, 2002, by Christian Neumair.
28 * Unless otherwise noted, we believe this code to be complete, as per
29 * the specification mentioned above.
30 * If you discover missing features, or bugs, please note them below.
33 * -- implement GetMUILanguage + InitMUILanguage
34 * -- finish NOTES for MenuHelp, GetEffectiveClientRect and GetStatusTextW
35 * -- FIXMEs + BUGS (search for them)
38 * -- ICC_ANIMATE_CLASS
43 * -- ICC_INTERNET_CLASSES
45 * -- ICC_LISTVIEW_CLASSES
46 * -- ICC_NATIVEFNTCTL_CLASS
47 * -- ICC_PAGESCROLLER_CLASS
48 * -- ICC_PROGRESS_CLASS
49 * -- ICC_STANDARD_CLASSES (not yet implemented)
51 * -- ICC_TREEVIEW_CLASSES
53 * -- ICC_USEREX_CLASSES
54 * -- ICC_WIN95_CLASSES
62 #define NONAMELESSUNION
72 #define NO_SHLWAPI_STREAM
75 #include "wine/debug.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(commctrl
);
80 static LRESULT WINAPI
COMCTL32_SubclassProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
82 static LPWSTR COMCTL32_wSubclass
= NULL
;
83 HMODULE COMCTL32_hModule
= 0;
84 static LANGID COMCTL32_uiLang
= MAKELANGID(LANG_NEUTRAL
, SUBLANG_NEUTRAL
);
85 HBRUSH COMCTL32_hPattern55AABrush
= NULL
;
86 COMCTL32_SysColor comctl32_color
;
88 static HBITMAP COMCTL32_hPattern55AABitmap
= NULL
;
90 static const WORD wPattern55AA
[] =
92 0x5555, 0xaaaa, 0x5555, 0xaaaa,
93 0x5555, 0xaaaa, 0x5555, 0xaaaa
96 static const WCHAR strCC32SubclassInfo
[] = L
"CC32SubclassInfo";
98 static void unregister_versioned_classes(void)
100 #define VERSION "6.0.2600.2982!"
101 static const char *classes
[] =
104 VERSION WC_COMBOBOXA
,
112 for (i
= 0; i
< ARRAY_SIZE(classes
); i
++)
113 UnregisterClassA(classes
[i
], NULL
);
118 BOOL WINAPI
RegisterClassNameW(const WCHAR
*class)
122 const WCHAR nameW
[16];
123 void (*fn_register
)(void);
127 { L
"Button", BUTTON_Register
},
128 { L
"ComboBox", COMBO_Register
},
129 { L
"ComboLBox", COMBOLBOX_Register
},
130 { L
"Edit", EDIT_Register
},
131 { L
"ListBox", LISTBOX_Register
},
132 { L
"Static", STATIC_Register
},
135 int min
= 0, max
= ARRAY_SIZE(classes
) - 1;
139 int res
, pos
= (min
+ max
) / 2;
140 if (!(res
= wcsicmp(class, classes
[pos
].nameW
)))
142 classes
[pos
].fn_register();
145 if (res
< 0) max
= pos
- 1;
152 /***********************************************************************
155 * Initializes the internal 'COMCTL32.DLL'.
158 * hinstDLL [I] handle to the 'dlls' instance
160 * lpvReserved [I] reserved, must be NULL
167 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
169 TRACE("%p,%x,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
172 case DLL_PROCESS_ATTACH
:
173 DisableThreadLibraryCalls(hinstDLL
);
175 COMCTL32_hModule
= hinstDLL
;
177 /* add global subclassing atom (used by 'tooltip' and 'updown') */
178 COMCTL32_wSubclass
= (LPWSTR
)(DWORD_PTR
)GlobalAddAtomW (strCC32SubclassInfo
);
179 TRACE("Subclassing atom added: %p\n", COMCTL32_wSubclass
);
181 /* create local pattern brush */
182 COMCTL32_hPattern55AABitmap
= CreateBitmap (8, 8, 1, 1, wPattern55AA
);
183 COMCTL32_hPattern55AABrush
= CreatePatternBrush (COMCTL32_hPattern55AABitmap
);
185 /* Get all the colors at DLL load */
186 COMCTL32_RefreshSysColors();
188 /* like comctl32 5.82+ register all the common control classes */
191 DATETIME_Register ();
195 IPADDRESS_Register ();
196 LISTVIEW_Register ();
197 MONTHCAL_Register ();
198 NATIVEFONT_Register ();
200 PROGRESS_Register ();
206 TOOLTIPS_Register ();
207 TRACKBAR_Register ();
208 TREEVIEW_Register ();
211 /* subclass user32 controls */
212 THEMING_Initialize ();
215 case DLL_PROCESS_DETACH
:
216 if (lpvReserved
) break;
217 /* clean up subclassing */
218 THEMING_Uninitialize();
220 /* unregister all common control classes */
221 ANIMATE_Unregister ();
222 COMBOEX_Unregister ();
223 DATETIME_Unregister ();
224 FLATSB_Unregister ();
225 HEADER_Unregister ();
226 HOTKEY_Unregister ();
227 IPADDRESS_Unregister ();
228 LISTVIEW_Unregister ();
229 MONTHCAL_Unregister ();
230 NATIVEFONT_Unregister ();
232 PROGRESS_Unregister ();
234 STATUS_Unregister ();
235 SYSLINK_Unregister ();
237 TOOLBAR_Unregister ();
238 TOOLTIPS_Unregister ();
239 TRACKBAR_Unregister ();
240 TREEVIEW_Unregister ();
241 UPDOWN_Unregister ();
243 unregister_versioned_classes ();
245 /* delete local pattern brush */
246 DeleteObject (COMCTL32_hPattern55AABrush
);
247 DeleteObject (COMCTL32_hPattern55AABitmap
);
249 /* delete global subclassing atom */
250 GlobalDeleteAtom (LOWORD(COMCTL32_wSubclass
));
251 TRACE("Subclassing atom deleted: %p\n", COMCTL32_wSubclass
);
259 /***********************************************************************
260 * MenuHelp [COMCTL32.2]
262 * Handles the setting of status bar help messages when the user
263 * selects menu items.
266 * uMsg [I] message (WM_MENUSELECT) (see NOTES)
267 * wParam [I] wParam of the message uMsg
268 * lParam [I] lParam of the message uMsg
269 * hMainMenu [I] handle to the application's main menu
270 * hInst [I] handle to the module that contains string resources
271 * hwndStatus [I] handle to the status bar window
272 * lpwIDs [I] pointer to an array of integers (see NOTES)
278 * The official documentation is incomplete!
279 * This is the correct documentation:
282 * MenuHelp() does NOT handle WM_COMMAND messages! It only handles
283 * WM_MENUSELECT messages.
286 * (will be written ...)
290 MenuHelp (UINT uMsg
, WPARAM wParam
, LPARAM lParam
, HMENU hMainMenu
,
291 HINSTANCE hInst
, HWND hwndStatus
, UINT
* lpwIDs
)
295 if (!IsWindow (hwndStatus
))
300 TRACE("WM_MENUSELECT wParam=0x%lX lParam=0x%lX\n",
303 if ((HIWORD(wParam
) == 0xFFFF) && (lParam
== 0)) {
304 /* menu was closed */
305 TRACE("menu was closed!\n");
306 SendMessageW (hwndStatus
, SB_SIMPLE
, FALSE
, 0);
309 /* menu item was selected */
310 if (HIWORD(wParam
) & MF_POPUP
)
311 uMenuID
= *(lpwIDs
+1);
313 uMenuID
= (UINT
)LOWORD(wParam
);
314 TRACE("uMenuID = %u\n", uMenuID
);
319 if (!LoadStringW (hInst
, uMenuID
, szText
, ARRAY_SIZE(szText
)))
322 SendMessageW (hwndStatus
, SB_SETTEXTW
,
323 255 | SBT_NOBORDERS
, (LPARAM
)szText
);
324 SendMessageW (hwndStatus
, SB_SIMPLE
, TRUE
, 0);
330 TRACE("WM_COMMAND wParam=0x%lX lParam=0x%lX\n",
332 /* WM_COMMAND is not invalid since it is documented
333 * in the windows api reference. So don't output
334 * any FIXME for WM_COMMAND
336 WARN("We don't care about the WM_COMMAND\n");
340 FIXME("Invalid Message 0x%x!\n", uMsg
);
346 /***********************************************************************
347 * ShowHideMenuCtl [COMCTL32.3]
349 * Shows or hides controls and updates the corresponding menu item.
352 * hwnd [I] handle to the client window.
353 * uFlags [I] menu command id.
354 * lpInfo [I] pointer to an array of integers. (See NOTES.)
361 * The official documentation is incomplete!
362 * This is the correct documentation:
365 * Handle to the window that contains the menu and controls.
368 * Identifier of the menu item to receive or lose a check mark.
371 * The array of integers contains pairs of values. BOTH values of
372 * the first pair must be the handles to the application's main menu.
373 * Each subsequent pair consists of a menu id and control id.
377 ShowHideMenuCtl (HWND hwnd
, UINT_PTR uFlags
, LPINT lpInfo
)
381 TRACE("%p, %lx, %p\n", hwnd
, uFlags
, lpInfo
);
386 if (!(lpInfo
[0]) || !(lpInfo
[1]))
389 /* search for control */
390 lpMenuId
= &lpInfo
[2];
391 while (*lpMenuId
!= uFlags
)
394 if (GetMenuState ((HMENU
)(DWORD_PTR
)lpInfo
[1], uFlags
, MF_BYCOMMAND
) & MFS_CHECKED
) {
395 /* uncheck menu item */
396 CheckMenuItem ((HMENU
)(DWORD_PTR
)lpInfo
[0], *lpMenuId
, MF_BYCOMMAND
| MF_UNCHECKED
);
400 SetWindowPos (GetDlgItem (hwnd
, *lpMenuId
), 0, 0, 0, 0, 0,
404 /* check menu item */
405 CheckMenuItem ((HMENU
)(DWORD_PTR
)lpInfo
[0], *lpMenuId
, MF_BYCOMMAND
| MF_CHECKED
);
409 SetWindowPos (GetDlgItem (hwnd
, *lpMenuId
), 0, 0, 0, 0, 0,
417 /***********************************************************************
418 * GetEffectiveClientRect [COMCTL32.4]
420 * Calculates the coordinates of a rectangle in the client area.
423 * hwnd [I] handle to the client window.
424 * lpRect [O] pointer to the rectangle of the client window
425 * lpInfo [I] pointer to an array of integers (see NOTES)
431 * The official documentation is incomplete!
432 * This is the correct documentation:
435 * (will be written ...)
439 GetEffectiveClientRect (HWND hwnd
, LPRECT lpRect
, const INT
*lpInfo
)
445 TRACE("(%p %p %p)\n",
446 hwnd
, lpRect
, lpInfo
);
448 GetClientRect (hwnd
, lpRect
);
456 hwndCtrl
= GetDlgItem (hwnd
, *lpRun
);
457 if (GetWindowLongW (hwndCtrl
, GWL_STYLE
) & WS_VISIBLE
) {
458 TRACE("control id 0x%x\n", *lpRun
);
459 GetWindowRect (hwndCtrl
, &rcCtrl
);
460 MapWindowPoints (NULL
, hwnd
, (LPPOINT
)&rcCtrl
, 2);
461 SubtractRect (lpRect
, lpRect
, &rcCtrl
);
468 /***********************************************************************
469 * DrawStatusTextW [COMCTL32.@]
471 * Draws text with borders, like in a status bar.
474 * hdc [I] handle to the window's display context
475 * lprc [I] pointer to a rectangle
476 * text [I] pointer to the text
477 * style [I] drawing style
483 * The style variable can have one of the following values:
484 * (will be written ...)
487 void WINAPI
DrawStatusTextW (HDC hdc
, LPCRECT lprc
, LPCWSTR text
, UINT style
)
490 UINT border
= BDR_SUNKENOUTER
;
493 if (style
& SBT_POPOUT
)
494 border
= BDR_RAISEDOUTER
;
495 else if (style
& SBT_NOBORDERS
)
498 oldbkcolor
= SetBkColor (hdc
, comctl32_color
.clrBtnFace
);
499 DrawEdge (hdc
, &r
, border
, BF_MIDDLE
|BF_RECT
|BF_ADJUST
);
503 int oldbkmode
= SetBkMode (hdc
, TRANSPARENT
);
504 COLORREF oldtextcolor
;
505 UINT align
= DT_LEFT
;
508 oldtextcolor
= SetTextColor (hdc
, comctl32_color
.clrBtnText
);
509 if (style
& SBT_RTLREADING
)
510 FIXME("Unsupported RTL style!\n");
515 DrawTextW (hdc
, text
- strCnt
, strCnt
, &r
, align
|DT_VCENTER
|DT_SINGLELINE
|DT_NOPREFIX
);
518 if (align
==DT_RIGHT
) {
521 align
= (align
==DT_LEFT
? DT_CENTER
: DT_RIGHT
);
527 if (strCnt
) DrawTextW (hdc
, text
- strCnt
, -1, &r
, align
|DT_VCENTER
|DT_SINGLELINE
|DT_NOPREFIX
);
528 SetBkMode (hdc
, oldbkmode
);
529 SetTextColor (hdc
, oldtextcolor
);
532 SetBkColor (hdc
, oldbkcolor
);
536 /***********************************************************************
537 * DrawStatusText [COMCTL32.@]
538 * DrawStatusTextA [COMCTL32.5]
540 * Draws text with borders, like in a status bar.
543 * hdc [I] handle to the window's display context
544 * lprc [I] pointer to a rectangle
545 * text [I] pointer to the text
546 * style [I] drawing style
552 void WINAPI
DrawStatusTextA (HDC hdc
, LPCRECT lprc
, LPCSTR text
, UINT style
)
558 if ( (len
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 )) ) {
559 if ( (textW
= Alloc( len
* sizeof(WCHAR
) )) )
560 MultiByteToWideChar( CP_ACP
, 0, text
, -1, textW
, len
);
563 DrawStatusTextW( hdc
, lprc
, textW
, style
);
568 /***********************************************************************
569 * CreateStatusWindow [COMCTL32.@]
570 * CreateStatusWindowA [COMCTL32.6]
572 * Creates a status bar
575 * style [I] window style
576 * text [I] pointer to the window text
577 * parent [I] handle to the parent window
578 * wid [I] control id of the status bar
581 * Success: handle to the status window
586 CreateStatusWindowA (LONG style
, LPCSTR text
, HWND parent
, UINT wid
)
588 return CreateWindowA(STATUSCLASSNAMEA
, text
, style
,
589 CW_USEDEFAULT
, CW_USEDEFAULT
,
590 CW_USEDEFAULT
, CW_USEDEFAULT
,
591 parent
, (HMENU
)(DWORD_PTR
)wid
, 0, 0);
595 /***********************************************************************
596 * CreateStatusWindowW [COMCTL32.@]
598 * Creates a status bar control
601 * style [I] window style
602 * text [I] pointer to the window text
603 * parent [I] handle to the parent window
604 * wid [I] control id of the status bar
607 * Success: handle to the status window
612 CreateStatusWindowW (LONG style
, LPCWSTR text
, HWND parent
, UINT wid
)
614 return CreateWindowW(STATUSCLASSNAMEW
, text
, style
,
615 CW_USEDEFAULT
, CW_USEDEFAULT
,
616 CW_USEDEFAULT
, CW_USEDEFAULT
,
617 parent
, (HMENU
)(DWORD_PTR
)wid
, 0, 0);
621 /***********************************************************************
622 * CreateUpDownControl [COMCTL32.16]
624 * Creates an up-down control
627 * style [I] window styles
628 * x [I] horizontal position of the control
629 * y [I] vertical position of the control
630 * cx [I] with of the control
631 * cy [I] height of the control
632 * parent [I] handle to the parent window
633 * id [I] the control's identifier
634 * inst [I] handle to the application's module instance
635 * buddy [I] handle to the buddy window, can be NULL
636 * maxVal [I] upper limit of the control
637 * minVal [I] lower limit of the control
638 * curVal [I] current value of the control
641 * Success: handle to the updown control
646 CreateUpDownControl (DWORD style
, INT x
, INT y
, INT cx
, INT cy
,
647 HWND parent
, INT id
, HINSTANCE inst
,
648 HWND buddy
, INT maxVal
, INT minVal
, INT curVal
)
651 CreateWindowW (UPDOWN_CLASSW
, 0, style
, x
, y
, cx
, cy
,
652 parent
, (HMENU
)(DWORD_PTR
)id
, inst
, 0);
654 SendMessageW (hUD
, UDM_SETBUDDY
, (WPARAM
)buddy
, 0);
655 SendMessageW (hUD
, UDM_SETRANGE
, 0, MAKELONG(maxVal
, minVal
));
656 SendMessageW (hUD
, UDM_SETPOS
, 0, MAKELONG(curVal
, 0));
663 /***********************************************************************
664 * InitCommonControls [COMCTL32.17]
666 * Registers the common controls.
675 * This function is just a dummy - all the controls are registered at
676 * the DLL initialization time. See InitCommonControlsEx for details.
680 InitCommonControls (void)
685 /***********************************************************************
686 * InitCommonControlsEx [COMCTL32.@]
688 * Registers the common controls.
691 * lpInitCtrls [I] pointer to an INITCOMMONCONTROLS structure.
698 * Probably all versions of comctl32 initializes the Win95 controls in DllMain
699 * during DLL initialization. Starting from comctl32 v5.82 all the controls
700 * are initialized there. We follow this behaviour and this function is just
703 * Note: when writing programs under Windows, if you don't call any function
704 * from comctl32 the linker may not link this DLL. If InitCommonControlsEx
705 * was the only comctl32 function you were calling and you remove it you may
706 * have a false impression that InitCommonControlsEx actually did something.
710 InitCommonControlsEx (const INITCOMMONCONTROLSEX
*lpInitCtrls
)
712 if (!lpInitCtrls
|| lpInitCtrls
->dwSize
!= sizeof(INITCOMMONCONTROLSEX
))
715 TRACE("(0x%08x)\n", lpInitCtrls
->dwICC
);
720 /***********************************************************************
721 * CreateToolbarEx [COMCTL32.@]
723 * Creates a toolbar window.
741 * Success: handle to the tool bar control
746 CreateToolbarEx (HWND hwnd
, DWORD style
, UINT wID
, INT nBitmaps
,
747 HINSTANCE hBMInst
, UINT_PTR wBMID
, LPCTBBUTTON lpButtons
,
748 INT iNumButtons
, INT dxButton
, INT dyButton
,
749 INT dxBitmap
, INT dyBitmap
, UINT uStructSize
)
754 CreateWindowExW(0, TOOLBARCLASSNAMEW
, NULL
, style
|WS_CHILD
, 0,0,100,30,
755 hwnd
, (HMENU
)(DWORD_PTR
)wID
, COMCTL32_hModule
, NULL
);
759 SendMessageW (hwndTB
, TB_BUTTONSTRUCTSIZE
, uStructSize
, 0);
761 /* set bitmap and button size */
762 /*If CreateToolbarEx receives 0, windows sets default values*/
767 if (dxBitmap
== 0 || dyBitmap
== 0)
768 dxBitmap
= dyBitmap
= 16;
769 SendMessageW(hwndTB
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(dxBitmap
, dyBitmap
));
775 /* TB_SETBUTTONSIZE -> TB_SETBITMAPSIZE bug introduced for Windows compatibility */
776 if (dxButton
!= 0 && dyButton
!= 0)
777 SendMessageW(hwndTB
, TB_SETBITMAPSIZE
, 0, MAKELPARAM(dxButton
, dyButton
));
781 if (nBitmaps
> 0 || hBMInst
== HINST_COMMCTRL
)
783 tbab
.hInst
= hBMInst
;
786 SendMessageW (hwndTB
, TB_ADDBITMAP
, nBitmaps
, (LPARAM
)&tbab
);
790 SendMessageW (hwndTB
, TB_ADDBUTTONSW
, iNumButtons
, (LPARAM
)lpButtons
);
797 /***********************************************************************
798 * CreateMappedBitmap [COMCTL32.8]
800 * Loads a bitmap resource using a colour map.
803 * hInstance [I] Handle to the module containing the bitmap.
804 * idBitmap [I] The bitmap resource ID.
805 * wFlags [I] CMB_MASKED for using bitmap as a mask or 0 for normal.
806 * lpColorMap [I] Colour information needed for the bitmap or NULL (uses system colours).
807 * iNumMaps [I] Number of COLORMAP's pointed to by lpColorMap.
810 * Success: handle to the new bitmap
815 CreateMappedBitmap (HINSTANCE hInstance
, INT_PTR idBitmap
, UINT wFlags
,
816 LPCOLORMAP lpColorMap
, INT iNumMaps
)
820 const BITMAPINFOHEADER
*lpBitmap
;
821 LPBITMAPINFOHEADER lpBitmapInfo
;
822 UINT nSize
, nColorTableSize
, iColor
;
823 RGBQUAD
*pColorTable
;
824 INT i
, iMaps
, nWidth
, nHeight
;
827 LPCOLORMAP sysColorMap
;
829 COLORMAP internalColorMap
[4] =
830 {{0x000000, 0}, {0x808080, 0}, {0xC0C0C0, 0}, {0xFFFFFF, 0}};
832 /* initialize pointer to colortable and default color table */
835 sysColorMap
= lpColorMap
;
838 internalColorMap
[0].to
= GetSysColor (COLOR_BTNTEXT
);
839 internalColorMap
[1].to
= GetSysColor (COLOR_BTNSHADOW
);
840 internalColorMap
[2].to
= GetSysColor (COLOR_BTNFACE
);
841 internalColorMap
[3].to
= GetSysColor (COLOR_BTNHIGHLIGHT
);
843 sysColorMap
= internalColorMap
;
846 hRsrc
= FindResourceW (hInstance
, (LPWSTR
)idBitmap
, (LPWSTR
)RT_BITMAP
);
849 hglb
= LoadResource (hInstance
, hRsrc
);
852 lpBitmap
= LockResource (hglb
);
853 if (lpBitmap
== NULL
)
856 if (lpBitmap
->biSize
>= sizeof(BITMAPINFOHEADER
) && lpBitmap
->biClrUsed
)
857 nColorTableSize
= lpBitmap
->biClrUsed
;
858 else if (lpBitmap
->biBitCount
<= 8)
859 nColorTableSize
= (1 << lpBitmap
->biBitCount
);
862 nSize
= lpBitmap
->biSize
;
863 if (nSize
== sizeof(BITMAPINFOHEADER
) && lpBitmap
->biCompression
== BI_BITFIELDS
)
864 nSize
+= 3 * sizeof(DWORD
);
865 nSize
+= nColorTableSize
* sizeof(RGBQUAD
);
866 lpBitmapInfo
= GlobalAlloc (GMEM_FIXED
, nSize
);
867 if (lpBitmapInfo
== NULL
)
869 RtlMoveMemory (lpBitmapInfo
, lpBitmap
, nSize
);
871 pColorTable
= (RGBQUAD
*)(((LPBYTE
)lpBitmapInfo
) + lpBitmapInfo
->biSize
);
873 for (iColor
= 0; iColor
< nColorTableSize
; iColor
++) {
874 for (i
= 0; i
< iMaps
; i
++) {
875 cRef
= RGB(pColorTable
[iColor
].rgbRed
,
876 pColorTable
[iColor
].rgbGreen
,
877 pColorTable
[iColor
].rgbBlue
);
878 if ( cRef
== sysColorMap
[i
].from
) {
880 if (wFlags
& CBS_MASKED
) {
881 if (sysColorMap
[i
].to
!= COLOR_BTNTEXT
)
882 pColorTable
[iColor
] = RGB(255, 255, 255);
886 pColorTable
[iColor
].rgbBlue
= GetBValue(sysColorMap
[i
].to
);
887 pColorTable
[iColor
].rgbGreen
= GetGValue(sysColorMap
[i
].to
);
888 pColorTable
[iColor
].rgbRed
= GetRValue(sysColorMap
[i
].to
);
893 nWidth
= lpBitmapInfo
->biWidth
;
894 nHeight
= lpBitmapInfo
->biHeight
;
895 hdcScreen
= GetDC (NULL
);
896 hbm
= CreateCompatibleBitmap (hdcScreen
, nWidth
, nHeight
);
898 HDC hdcDst
= CreateCompatibleDC (hdcScreen
);
899 HBITMAP hbmOld
= SelectObject (hdcDst
, hbm
);
900 const BYTE
*lpBits
= (const BYTE
*)lpBitmap
+ nSize
;
901 StretchDIBits (hdcDst
, 0, 0, nWidth
, nHeight
, 0, 0, nWidth
, nHeight
,
902 lpBits
, (LPBITMAPINFO
)lpBitmapInfo
, DIB_RGB_COLORS
,
904 SelectObject (hdcDst
, hbmOld
);
907 ReleaseDC (NULL
, hdcScreen
);
908 GlobalFree (lpBitmapInfo
);
915 /***********************************************************************
916 * CreateToolbar [COMCTL32.7]
918 * Creates a toolbar control.
931 * Success: handle to the tool bar control
935 * Do not use this function anymore. Use CreateToolbarEx instead.
939 CreateToolbar (HWND hwnd
, DWORD style
, UINT wID
, INT nBitmaps
,
940 HINSTANCE hBMInst
, UINT wBMID
,
941 LPCTBBUTTON lpButtons
,INT iNumButtons
)
943 return CreateToolbarEx (hwnd
, style
| CCS_NODIVIDER
, wID
, nBitmaps
,
944 hBMInst
, wBMID
, lpButtons
,
945 iNumButtons
, 0, 0, 0, 0, CCSIZEOF_STRUCT(TBBUTTON
, dwData
));
949 /***********************************************************************
950 * DllGetVersion [COMCTL32.@]
952 * Retrieves version information of the 'COMCTL32.DLL'
955 * pdvi [O] pointer to version information structure.
959 * Failure: E_INVALIDARG
962 * Returns version of a comctl32.dll from IE4.01 SP1.
965 HRESULT WINAPI
DllGetVersion (DLLVERSIONINFO
*pdvi
)
967 if (pdvi
->cbSize
!= sizeof(DLLVERSIONINFO
)) {
968 WARN("wrong DLLVERSIONINFO size from app\n");
972 pdvi
->dwMajorVersion
= COMCTL32_VERSION
;
973 pdvi
->dwMinorVersion
= COMCTL32_VERSION_MINOR
;
974 pdvi
->dwBuildNumber
= 2919;
975 pdvi
->dwPlatformID
= 6304;
977 TRACE("%u.%u.%u.%u\n",
978 pdvi
->dwMajorVersion
, pdvi
->dwMinorVersion
,
979 pdvi
->dwBuildNumber
, pdvi
->dwPlatformID
);
984 /***********************************************************************
985 * DllInstall (COMCTL32.@)
987 * Installs the ComCtl32 DLL.
991 * Failure: A HRESULT error
993 HRESULT WINAPI
DllInstall(BOOL bInstall
, LPCWSTR cmdline
)
995 TRACE("(%u, %s): stub\n", bInstall
, debugstr_w(cmdline
));
999 /***********************************************************************
1000 * _TrackMouseEvent [COMCTL32.@]
1002 * Requests notification of mouse events
1004 * During mouse tracking WM_MOUSEHOVER or WM_MOUSELEAVE events are posted
1005 * to the hwnd specified in the ptme structure. After the event message
1006 * is posted to the hwnd, the entry in the queue is removed.
1008 * If the current hwnd isn't ptme->hwndTrack the TME_HOVER flag is completely
1009 * ignored. The TME_LEAVE flag results in a WM_MOUSELEAVE message being posted
1010 * immediately and the TME_LEAVE flag being ignored.
1013 * ptme [I,O] pointer to TRACKMOUSEEVENT information structure.
1019 * IMPLEMENTATION moved to USER32.TrackMouseEvent
1024 _TrackMouseEvent (TRACKMOUSEEVENT
*ptme
)
1026 return TrackMouseEvent (ptme
);
1029 /*************************************************************************
1030 * GetMUILanguage [COMCTL32.@]
1032 * Returns the user interface language in use by the current process.
1035 * Language ID in use by the current process.
1037 LANGID WINAPI
GetMUILanguage (VOID
)
1039 return COMCTL32_uiLang
;
1043 /*************************************************************************
1044 * InitMUILanguage [COMCTL32.@]
1046 * Sets the user interface language to be used by the current process.
1051 VOID WINAPI
InitMUILanguage (LANGID uiLang
)
1053 COMCTL32_uiLang
= uiLang
;
1057 /***********************************************************************
1058 * SetWindowSubclass [COMCTL32.410]
1060 * Starts a window subclass
1063 * hWnd [in] handle to window subclass.
1064 * pfnSubclass [in] Pointer to new window procedure.
1065 * uIDSubclass [in] Unique identifier of subclass together with pfnSubclass.
1066 * dwRef [in] Reference data to pass to window procedure.
1073 * If an application manually subclasses a window after subclassing it with
1074 * this API and then with this API again, then none of the previous
1075 * subclasses get called or the original window procedure.
1078 BOOL WINAPI
SetWindowSubclass (HWND hWnd
, SUBCLASSPROC pfnSubclass
,
1079 UINT_PTR uIDSubclass
, DWORD_PTR dwRef
)
1081 LPSUBCLASS_INFO stack
;
1082 LPSUBCLASSPROCS proc
;
1084 TRACE ("(%p, %p, %lx, %lx)\n", hWnd
, pfnSubclass
, uIDSubclass
, dwRef
);
1086 if (!hWnd
|| !pfnSubclass
)
1089 /* Since the window procedure that we set here has two additional arguments,
1090 * we can't simply set it as the new window procedure of the window. So we
1091 * set our own window procedure and then calculate the other two arguments
1094 /* See if we have been called for this window */
1095 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1097 /* allocate stack */
1098 stack
= Alloc (sizeof(SUBCLASS_INFO
));
1100 ERR ("Failed to allocate our Subclassing stack\n");
1103 SetPropW (hWnd
, COMCTL32_wSubclass
, stack
);
1105 /* set window procedure to our own and save the current one */
1106 if (IsWindowUnicode (hWnd
))
1107 stack
->origproc
= (WNDPROC
)SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
,
1108 (DWORD_PTR
)COMCTL32_SubclassProc
);
1110 stack
->origproc
= (WNDPROC
)SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
,
1111 (DWORD_PTR
)COMCTL32_SubclassProc
);
1114 /* Check to see if we have called this function with the same uIDSubClass
1115 * and pfnSubclass */
1116 proc
= stack
->SubclassProcs
;
1118 if ((proc
->id
== uIDSubclass
) &&
1119 (proc
->subproc
== pfnSubclass
)) {
1127 proc
= Alloc(sizeof(SUBCLASSPROCS
));
1129 ERR ("Failed to allocate subclass entry in stack\n");
1130 if (IsWindowUnicode (hWnd
))
1131 SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1133 SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1135 RemovePropW( hWnd
, COMCTL32_wSubclass
);
1139 proc
->subproc
= pfnSubclass
;
1141 proc
->id
= uIDSubclass
;
1142 proc
->next
= stack
->SubclassProcs
;
1143 stack
->SubclassProcs
= proc
;
1149 /***********************************************************************
1150 * GetWindowSubclass [COMCTL32.411]
1152 * Gets the Reference data from a subclass.
1155 * hWnd [in] Handle to the window which we are subclassing
1156 * pfnSubclass [in] Pointer to the subclass procedure
1157 * uID [in] Unique identifier of the subclassing procedure
1158 * pdwRef [out] Pointer to the reference data
1165 BOOL WINAPI
GetWindowSubclass (HWND hWnd
, SUBCLASSPROC pfnSubclass
,
1166 UINT_PTR uID
, DWORD_PTR
*pdwRef
)
1168 const SUBCLASS_INFO
*stack
;
1169 const SUBCLASSPROCS
*proc
;
1171 TRACE ("(%p, %p, %lx, %p)\n", hWnd
, pfnSubclass
, uID
, pdwRef
);
1173 /* See if we have been called for this window */
1174 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1178 proc
= stack
->SubclassProcs
;
1180 if ((proc
->id
== uID
) &&
1181 (proc
->subproc
== pfnSubclass
)) {
1182 *pdwRef
= proc
->ref
;
1192 /***********************************************************************
1193 * RemoveWindowSubclass [COMCTL32.412]
1195 * Removes a window subclass.
1198 * hWnd [in] Handle to the window which we are subclassing
1199 * pfnSubclass [in] Pointer to the subclass procedure
1200 * uID [in] Unique identifier of this subclass
1207 BOOL WINAPI
RemoveWindowSubclass(HWND hWnd
, SUBCLASSPROC pfnSubclass
, UINT_PTR uID
)
1209 LPSUBCLASS_INFO stack
;
1210 LPSUBCLASSPROCS prevproc
= NULL
;
1211 LPSUBCLASSPROCS proc
;
1214 TRACE ("(%p, %p, %lx)\n", hWnd
, pfnSubclass
, uID
);
1216 /* Find the Subclass to remove */
1217 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1221 proc
= stack
->SubclassProcs
;
1223 if ((proc
->id
== uID
) &&
1224 (proc
->subproc
== pfnSubclass
)) {
1227 stack
->SubclassProcs
= proc
->next
;
1229 prevproc
->next
= proc
->next
;
1231 if (stack
->stackpos
== proc
)
1232 stack
->stackpos
= stack
->stackpos
->next
;
1242 if (!stack
->SubclassProcs
&& !stack
->running
) {
1243 TRACE("Last Subclass removed, cleaning up\n");
1244 /* clean up our heap and reset the original window procedure */
1245 if (IsWindowUnicode (hWnd
))
1246 SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1248 SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1250 RemovePropW( hWnd
, COMCTL32_wSubclass
);
1256 /***********************************************************************
1257 * COMCTL32_SubclassProc (internal)
1259 * Window procedure for all subclassed windows.
1260 * Saves the current subclassing stack position to support nested messages
1262 static LRESULT WINAPI
COMCTL32_SubclassProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1264 LPSUBCLASS_INFO stack
;
1265 LPSUBCLASSPROCS proc
;
1268 TRACE ("(%p, 0x%08x, 0x%08lx, 0x%08lx)\n", hWnd
, uMsg
, wParam
, lParam
);
1270 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1272 ERR ("Our sub classing stack got erased for %p!! Nothing we can do\n", hWnd
);
1276 /* Save our old stackpos to properly handle nested messages */
1277 proc
= stack
->stackpos
;
1278 stack
->stackpos
= stack
->SubclassProcs
;
1280 ret
= DefSubclassProc(hWnd
, uMsg
, wParam
, lParam
);
1282 stack
->stackpos
= proc
;
1284 if (!stack
->SubclassProcs
&& !stack
->running
) {
1285 TRACE("Last Subclass removed, cleaning up\n");
1286 /* clean up our heap and reset the original window procedure */
1287 if (IsWindowUnicode (hWnd
))
1288 SetWindowLongPtrW (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1290 SetWindowLongPtrA (hWnd
, GWLP_WNDPROC
, (DWORD_PTR
)stack
->origproc
);
1292 RemovePropW( hWnd
, COMCTL32_wSubclass
);
1297 /***********************************************************************
1298 * DefSubclassProc [COMCTL32.413]
1300 * Calls the next window procedure (i.e. the one before this subclass)
1303 * hWnd [in] The window that we're subclassing
1305 * wParam [in] WPARAM
1306 * lParam [in] LPARAM
1313 LRESULT WINAPI
DefSubclassProc (HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1315 LPSUBCLASS_INFO stack
;
1318 TRACE ("(%p, 0x%08x, 0x%08lx, 0x%08lx)\n", hWnd
, uMsg
, wParam
, lParam
);
1320 /* retrieve our little stack from the Properties */
1321 stack
= GetPropW (hWnd
, COMCTL32_wSubclass
);
1323 ERR ("Our sub classing stack got erased for %p!! Nothing we can do\n", hWnd
);
1327 /* If we are at the end of stack then we have to call the original
1328 * window procedure */
1329 if (!stack
->stackpos
) {
1330 if (IsWindowUnicode (hWnd
))
1331 ret
= CallWindowProcW (stack
->origproc
, hWnd
, uMsg
, wParam
, lParam
);
1333 ret
= CallWindowProcA (stack
->origproc
, hWnd
, uMsg
, wParam
, lParam
);
1335 const SUBCLASSPROCS
*proc
= stack
->stackpos
;
1336 stack
->stackpos
= stack
->stackpos
->next
;
1337 /* call the Subclass procedure from the stack */
1338 ret
= proc
->subproc (hWnd
, uMsg
, wParam
, lParam
,
1339 proc
->id
, proc
->ref
);
1346 /***********************************************************************
1347 * COMCTL32_CreateToolTip [NOT AN API]
1349 * Creates a tooltip for the control specified in hwnd and does all
1350 * necessary setup and notifications.
1353 * hwndOwner [I] Handle to the window that will own the tool tip.
1356 * Success: Handle of tool tip window.
1361 COMCTL32_CreateToolTip(HWND hwndOwner
)
1365 hwndToolTip
= CreateWindowExW(0, TOOLTIPS_CLASSW
, NULL
, WS_POPUP
,
1366 CW_USEDEFAULT
, CW_USEDEFAULT
,
1367 CW_USEDEFAULT
, CW_USEDEFAULT
, hwndOwner
,
1370 /* Send NM_TOOLTIPSCREATED notification */
1373 NMTOOLTIPSCREATED nmttc
;
1374 /* true owner can be different if hwndOwner is a child window */
1375 HWND hwndTrueOwner
= GetWindow(hwndToolTip
, GW_OWNER
);
1376 nmttc
.hdr
.hwndFrom
= hwndTrueOwner
;
1377 nmttc
.hdr
.idFrom
= GetWindowLongPtrW(hwndTrueOwner
, GWLP_ID
);
1378 nmttc
.hdr
.code
= NM_TOOLTIPSCREATED
;
1379 nmttc
.hwndToolTips
= hwndToolTip
;
1381 SendMessageW(GetParent(hwndTrueOwner
), WM_NOTIFY
,
1382 GetWindowLongPtrW(hwndTrueOwner
, GWLP_ID
), (LPARAM
)&nmttc
);
1389 /***********************************************************************
1390 * COMCTL32_RefreshSysColors [NOT AN API]
1392 * Invoked on any control recognizing a WM_SYSCOLORCHANGE message to
1393 * refresh the color values in the color structure
1403 COMCTL32_RefreshSysColors(void)
1405 comctl32_color
.clrBtnHighlight
= GetSysColor (COLOR_BTNHIGHLIGHT
);
1406 comctl32_color
.clrBtnShadow
= GetSysColor (COLOR_BTNSHADOW
);
1407 comctl32_color
.clrBtnText
= GetSysColor (COLOR_BTNTEXT
);
1408 comctl32_color
.clrBtnFace
= GetSysColor (COLOR_BTNFACE
);
1409 comctl32_color
.clrHighlight
= GetSysColor (COLOR_HIGHLIGHT
);
1410 comctl32_color
.clrHighlightText
= GetSysColor (COLOR_HIGHLIGHTTEXT
);
1411 comctl32_color
.clrHotTrackingColor
= GetSysColor (COLOR_HOTLIGHT
);
1412 comctl32_color
.clr3dHilight
= GetSysColor (COLOR_3DHILIGHT
);
1413 comctl32_color
.clr3dShadow
= GetSysColor (COLOR_3DSHADOW
);
1414 comctl32_color
.clr3dDkShadow
= GetSysColor (COLOR_3DDKSHADOW
);
1415 comctl32_color
.clr3dFace
= GetSysColor (COLOR_3DFACE
);
1416 comctl32_color
.clrWindow
= GetSysColor (COLOR_WINDOW
);
1417 comctl32_color
.clrWindowText
= GetSysColor (COLOR_WINDOWTEXT
);
1418 comctl32_color
.clrGrayText
= GetSysColor (COLOR_GRAYTEXT
);
1419 comctl32_color
.clrActiveCaption
= GetSysColor (COLOR_ACTIVECAPTION
);
1420 comctl32_color
.clrInfoBk
= GetSysColor (COLOR_INFOBK
);
1421 comctl32_color
.clrInfoText
= GetSysColor (COLOR_INFOTEXT
);
1424 /***********************************************************************
1425 * COMCTL32_DrawInsertMark [NOT AN API]
1427 * Draws an insertion mark (which looks similar to an 'I').
1430 * hDC [I] Device context to draw onto.
1431 * lpRect [I] Co-ordinates of insertion mark.
1432 * clrInsertMark [I] Colour of the insertion mark.
1433 * bHorizontal [I] True if insert mark should be drawn horizontally,
1434 * vertical otherwise.
1440 * Draws up to but not including the bottom co-ordinate when drawing
1441 * vertically or the right co-ordinate when horizontal.
1443 void COMCTL32_DrawInsertMark(HDC hDC
, const RECT
*lpRect
, COLORREF clrInsertMark
, BOOL bHorizontal
)
1445 HPEN hPen
= CreatePen(PS_SOLID
, 1, clrInsertMark
);
1447 static const DWORD adwPolyPoints
[] = {4,4,4};
1448 LONG lCentre
= (bHorizontal
?
1449 lpRect
->top
+ (lpRect
->bottom
- lpRect
->top
)/2 :
1450 lpRect
->left
+ (lpRect
->right
- lpRect
->left
)/2);
1451 LONG l1
= (bHorizontal
? lpRect
->left
: lpRect
->top
);
1452 LONG l2
= (bHorizontal
? lpRect
->right
: lpRect
->bottom
);
1453 const POINT aptInsertMark
[] =
1455 /* top (V) or left (H) arrow */
1459 {lCentre
+ 1, l1
+ 2},
1463 {lCentre
+ 1, l1
- 1},
1464 {lCentre
+ 1, l2
- 2},
1465 /* bottom (V) or right (H) arrow */
1467 {lCentre
- 2, l2
- 1},
1468 {lCentre
+ 3, l2
- 1},
1469 {lCentre
+ 1, l2
- 3},
1471 hOldPen
= SelectObject(hDC
, hPen
);
1472 PolyPolyline(hDC
, aptInsertMark
, adwPolyPoints
, ARRAY_SIZE(adwPolyPoints
));
1473 SelectObject(hDC
, hOldPen
);
1477 /***********************************************************************
1478 * COMCTL32_EnsureBitmapSize [internal]
1480 * If needed, enlarge the bitmap so that the width is at least cxMinWidth and
1481 * the height is at least cyMinHeight. If the bitmap already has these
1482 * dimensions nothing changes.
1485 * hBitmap [I/O] Bitmap to modify. The handle may change
1486 * cxMinWidth [I] If the width of the bitmap is smaller, then it will
1487 * be enlarged to this value
1488 * cyMinHeight [I] If the height of the bitmap is smaller, then it will
1489 * be enlarged to this value
1490 * cyBackground [I] The color with which the new area will be filled
1495 void COMCTL32_EnsureBitmapSize(HBITMAP
*pBitmap
, int cxMinWidth
, int cyMinHeight
, COLORREF crBackground
)
1500 HBITMAP hNewDCBitmap
, hOldDCBitmap
;
1504 if (!GetObjectW(*pBitmap
, sizeof(BITMAP
), &bmp
))
1506 cxNew
= (cxMinWidth
> bmp
.bmWidth
? cxMinWidth
: bmp
.bmWidth
);
1507 cyNew
= (cyMinHeight
> bmp
.bmHeight
? cyMinHeight
: bmp
.bmHeight
);
1508 if (cxNew
== bmp
.bmWidth
&& cyNew
== bmp
.bmHeight
)
1511 hdcNew
= CreateCompatibleDC(NULL
);
1512 hNewBitmap
= CreateBitmap(cxNew
, cyNew
, bmp
.bmPlanes
, bmp
.bmBitsPixel
, NULL
);
1513 hNewDCBitmap
= SelectObject(hdcNew
, hNewBitmap
);
1514 hNewDCBrush
= SelectObject(hdcNew
, CreateSolidBrush(crBackground
));
1516 hdcOld
= CreateCompatibleDC(NULL
);
1517 hOldDCBitmap
= SelectObject(hdcOld
, *pBitmap
);
1519 BitBlt(hdcNew
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, hdcOld
, 0, 0, SRCCOPY
);
1520 if (bmp
.bmWidth
< cxMinWidth
)
1521 PatBlt(hdcNew
, bmp
.bmWidth
, 0, cxNew
, bmp
.bmHeight
, PATCOPY
);
1522 if (bmp
.bmHeight
< cyMinHeight
)
1523 PatBlt(hdcNew
, 0, bmp
.bmHeight
, bmp
.bmWidth
, cyNew
, PATCOPY
);
1524 if (bmp
.bmWidth
< cxMinWidth
&& bmp
.bmHeight
< cyMinHeight
)
1525 PatBlt(hdcNew
, bmp
.bmWidth
, bmp
.bmHeight
, cxNew
, cyNew
, PATCOPY
);
1527 SelectObject(hdcNew
, hNewDCBitmap
);
1528 DeleteObject(SelectObject(hdcNew
, hNewDCBrush
));
1530 SelectObject(hdcOld
, hOldDCBitmap
);
1533 DeleteObject(*pBitmap
);
1534 *pBitmap
= hNewBitmap
;
1538 void COMCTL32_GetFontMetrics(HFONT hFont
, TEXTMETRICW
*ptm
)
1540 HDC hdc
= GetDC(NULL
);
1543 hOldFont
= SelectObject(hdc
, hFont
);
1544 GetTextMetricsW(hdc
, ptm
);
1545 SelectObject(hdc
, hOldFont
);
1546 ReleaseDC(NULL
, hdc
);
1549 #ifndef OCM__BASE /* avoid including olectl.h */
1550 #define OCM__BASE (WM_USER+0x1c00)
1553 /***********************************************************************
1554 * COMCTL32_IsReflectedMessage [internal]
1556 * Some parents reflect notify messages - for some messages sent by the child,
1557 * they send it back with the message code increased by OCM__BASE (0x2000).
1558 * This allows better subclassing of controls. We don't need to handle such
1559 * messages but we don't want to print ERRs for them, so this helper function
1562 * Some of the codes are in the CCM_FIRST..CCM_LAST range, but there is no
1563 * collision with defined CCM_ codes.
1565 BOOL
COMCTL32_IsReflectedMessage(UINT uMsg
)
1569 case OCM__BASE
+ WM_COMMAND
:
1570 case OCM__BASE
+ WM_CTLCOLORBTN
:
1571 case OCM__BASE
+ WM_CTLCOLOREDIT
:
1572 case OCM__BASE
+ WM_CTLCOLORDLG
:
1573 case OCM__BASE
+ WM_CTLCOLORLISTBOX
:
1574 case OCM__BASE
+ WM_CTLCOLORMSGBOX
:
1575 case OCM__BASE
+ WM_CTLCOLORSCROLLBAR
:
1576 case OCM__BASE
+ WM_CTLCOLORSTATIC
:
1577 case OCM__BASE
+ WM_DRAWITEM
:
1578 case OCM__BASE
+ WM_MEASUREITEM
:
1579 case OCM__BASE
+ WM_DELETEITEM
:
1580 case OCM__BASE
+ WM_VKEYTOITEM
:
1581 case OCM__BASE
+ WM_CHARTOITEM
:
1582 case OCM__BASE
+ WM_COMPAREITEM
:
1583 case OCM__BASE
+ WM_HSCROLL
:
1584 case OCM__BASE
+ WM_VSCROLL
:
1585 case OCM__BASE
+ WM_PARENTNOTIFY
:
1586 case OCM__BASE
+ WM_NOTIFY
:
1593 /***********************************************************************
1594 * MirrorIcon [COMCTL32.414]
1596 * Mirrors an icon so that it will appear correctly on a mirrored DC.
1599 * phicon1 [I/O] Icon.
1600 * phicon2 [I/O] Icon.
1606 BOOL WINAPI
MirrorIcon(HICON
*phicon1
, HICON
*phicon2
)
1608 FIXME("(%p, %p): stub\n", phicon1
, phicon2
);
1612 static inline BOOL
IsDelimiter(WCHAR c
)
1625 static int CALLBACK
PathWordBreakProc(LPCWSTR lpch
, int ichCurrent
, int cch
, int code
)
1627 if (code
== WB_ISDELIMITER
)
1628 return IsDelimiter(lpch
[ichCurrent
]);
1631 int dir
= (code
== WB_LEFT
) ? -1 : 1;
1632 for(; 0 <= ichCurrent
&& ichCurrent
< cch
; ichCurrent
+= dir
)
1633 if (IsDelimiter(lpch
[ichCurrent
])) return ichCurrent
;
1638 /***********************************************************************
1639 * SetPathWordBreakProc [COMCTL32.384]
1641 * Sets the word break procedure for an edit control to one that understands
1642 * paths so that the user can jump over directories.
1645 * hwnd [I] Handle to edit control.
1646 * bSet [I] If this is TRUE then the word break proc is set, otherwise it is removed.
1649 * Result from EM_SETWORDBREAKPROC message.
1651 LRESULT WINAPI
SetPathWordBreakProc(HWND hwnd
, BOOL bSet
)
1653 return SendMessageW(hwnd
, EM_SETWORDBREAKPROC
, 0,
1654 (LPARAM
)(bSet
? PathWordBreakProc
: NULL
));
1657 /***********************************************************************
1658 * DrawShadowText [COMCTL32.@]
1660 * Draw text with shadow.
1662 int WINAPI
DrawShadowText(HDC hdc
, LPCWSTR text
, UINT length
, RECT
*rect
, DWORD flags
,
1663 COLORREF crText
, COLORREF crShadow
, int offset_x
, int offset_y
)
1669 FIXME("(%p, %s, %d, %p, 0x%08x, 0x%08x, 0x%08x, %d, %d): semi-stub\n", hdc
, debugstr_w(text
),
1670 length
, rect
, flags
, crText
, crShadow
, offset_x
, offset_y
);
1672 bkmode
= SetBkMode(hdc
, TRANSPARENT
);
1673 clr
= SetTextColor(hdc
, crShadow
);
1675 /* FIXME: for shadow we need to render normally, blur it, and blend with current background. */
1677 OffsetRect(&r
, 1, 1);
1678 DrawTextW(hdc
, text
, length
, &r
, flags
);
1680 SetTextColor(hdc
, crText
);
1682 /* with text color on top of a shadow */
1683 ret
= DrawTextW(hdc
, text
, length
, rect
, flags
);
1685 SetTextColor(hdc
, clr
);
1686 SetBkMode(hdc
, bkmode
);
1691 /***********************************************************************
1692 * LoadIconWithScaleDown [COMCTL32.@]
1694 HRESULT WINAPI
LoadIconWithScaleDown(HINSTANCE hinst
, const WCHAR
*name
, int cx
, int cy
, HICON
*icon
)
1696 TRACE("(%p, %s, %d, %d, %p)\n", hinst
, debugstr_w(name
), cx
, cy
, icon
);
1701 return E_INVALIDARG
;
1703 *icon
= LoadImageW(hinst
, name
, IMAGE_ICON
, cx
, cy
,
1704 (hinst
|| IS_INTRESOURCE(name
)) ? 0 : LR_LOADFROMFILE
);
1706 return HRESULT_FROM_WIN32(GetLastError());
1711 /***********************************************************************
1712 * LoadIconMetric [COMCTL32.@]
1714 HRESULT WINAPI
LoadIconMetric(HINSTANCE hinst
, const WCHAR
*name
, int size
, HICON
*icon
)
1718 TRACE("(%p, %s, %d, %p)\n", hinst
, debugstr_w(name
), size
, icon
);
1720 if (size
== LIM_SMALL
)
1722 cx
= GetSystemMetrics(SM_CXSMICON
);
1723 cy
= GetSystemMetrics(SM_CYSMICON
);
1725 else if (size
== LIM_LARGE
)
1727 cx
= GetSystemMetrics(SM_CXICON
);
1728 cy
= GetSystemMetrics(SM_CYICON
);
1733 return E_INVALIDARG
;
1736 return LoadIconWithScaleDown(hinst
, name
, cx
, cy
, icon
);
1739 static const WCHAR strMRUList
[] = L
"MRUList";
1741 /**************************************************************************
1742 * Alloc [COMCTL32.71]
1744 * Allocates memory block from the dll's private heap
1746 void * WINAPI
Alloc(DWORD size
)
1748 return LocalAlloc(LMEM_ZEROINIT
, size
);
1751 /**************************************************************************
1752 * ReAlloc [COMCTL32.72]
1754 * Changes the size of an allocated memory block or allocates a memory
1755 * block using the dll's private heap.
1758 void * WINAPI
ReAlloc(void *src
, DWORD size
)
1761 return LocalReAlloc(src
, size
, LMEM_ZEROINIT
| LMEM_MOVEABLE
);
1763 return LocalAlloc(LMEM_ZEROINIT
, size
);
1766 /**************************************************************************
1767 * Free [COMCTL32.73]
1769 * Frees an allocated memory block from the dll's private heap.
1771 BOOL WINAPI
Free(void *mem
)
1773 return !LocalFree(mem
);
1776 /**************************************************************************
1777 * GetSize [COMCTL32.74]
1779 DWORD WINAPI
GetSize(void *mem
)
1781 return LocalSize(mem
);
1784 /**************************************************************************
1785 * MRU-Functions {COMCTL32}
1788 * The MRU-API is a set of functions to manipulate lists of M.R.U. (Most Recently
1789 * Used) items. It is an undocumented API that is used (at least) by the shell
1790 * and explorer to implement their recent documents feature.
1792 * Since these functions are undocumented, they are unsupported by MS and
1793 * may change at any time.
1795 * Internally, the list is implemented as a last in, last out list of items
1796 * persisted into the system registry under a caller chosen key. Each list
1797 * item is given a one character identifier in the Ascii range from 'a' to
1798 * '}'. A list of the identifiers in order from newest to oldest is stored
1799 * under the same key in a value named "MRUList".
1801 * Items are re-ordered by changing the order of the values in the MRUList
1802 * value. When a new item is added, it becomes the new value of the oldest
1803 * identifier, and that identifier is moved to the front of the MRUList value.
1805 * Wine stores MRU-lists in the same registry format as Windows, so when
1806 * switching between the builtin and native comctl32.dll no problems or
1807 * incompatibilities should occur.
1809 * The following undocumented structure is used to create an MRU-list:
1810 *|typedef INT (CALLBACK *MRUStringCmpFn)(LPCTSTR lhs, LPCTSTR rhs);
1811 *|typedef INT (CALLBACK *MRUBinaryCmpFn)(LPCVOID lhs, LPCVOID rhs, DWORD length);
1813 *|typedef struct tagMRUINFO
1819 *| LPTSTR lpszSubKey;
1820 *| PROC lpfnCompare;
1821 *|} MRUINFO, *LPMRUINFO;
1824 * cbSize [I] The size of the MRUINFO structure. This must be set
1825 * to sizeof(MRUINFO) by the caller.
1826 * uMax [I] The maximum number of items allowed in the list. Because
1827 * of the limited number of identifiers, this should be set to
1828 * a value from 1 to 30 by the caller.
1829 * fFlags [I] If bit 0 is set, the list will be used to store binary
1830 * data, otherwise it is assumed to store strings. If bit 1
1831 * is set, every change made to the list will be reflected in
1832 * the registry immediately, otherwise changes will only be
1833 * written when the list is closed.
1834 * hKey [I] The registry key that the list should be written under.
1835 * This must be supplied by the caller.
1836 * lpszSubKey [I] A caller supplied name of a subkey under hKey to write
1837 * the list to. This may not be blank.
1838 * lpfnCompare [I] A caller supplied comparison function, which may be either
1839 * an MRUStringCmpFn if dwFlags does not have bit 0 set, or a
1840 * MRUBinaryCmpFn otherwise.
1843 * - Create an MRU-list with CreateMRUList() or CreateMRUListLazy().
1844 * - Add items to an MRU-list with AddMRUString() or AddMRUData().
1845 * - Remove items from an MRU-list with DelMRUString().
1846 * - Find data in an MRU-list with FindMRUString() or FindMRUData().
1847 * - Iterate through an MRU-list with EnumMRUList().
1848 * - Free an MRU-list with FreeMRUList().
1851 typedef INT (CALLBACK
*MRUStringCmpFnA
)(LPCSTR lhs
, LPCSTR rhs
);
1852 typedef INT (CALLBACK
*MRUStringCmpFnW
)(LPCWSTR lhs
, LPCWSTR rhs
);
1853 typedef INT (CALLBACK
*MRUBinaryCmpFn
)(LPCVOID lhs
, LPCVOID rhs
, DWORD length
);
1864 MRUStringCmpFnA string_cmpfn
;
1865 MRUBinaryCmpFn binary_cmpfn
;
1878 MRUStringCmpFnW string_cmpfn
;
1879 MRUBinaryCmpFn binary_cmpfn
;
1883 /* MRUINFO.fFlags */
1884 #define MRU_STRING 0 /* list will contain strings */
1885 #define MRU_BINARY 1 /* list will contain binary data */
1886 #define MRU_CACHEWRITE 2 /* only save list order to reg. is FreeMRUList */
1888 /* If list is a string list lpfnCompare has the following prototype
1889 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
1890 * for binary lists the prototype is
1891 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
1892 * where cbData is the no. of bytes to compare.
1893 * Need to check what return value means identical - 0?
1896 typedef struct tagWINEMRUITEM
1898 DWORD size
; /* size of data stored */
1899 DWORD itemFlag
; /* flags */
1901 } WINEMRUITEM
, *LPWINEMRUITEM
;
1904 #define WMRUIF_CHANGED 0x0001 /* this dataitem changed */
1906 typedef struct tagWINEMRULIST
1908 struct MRUINFOW extview
; /* original create information */
1909 BOOL isUnicode
; /* is compare fn Unicode */
1910 DWORD wineFlags
; /* internal flags */
1911 DWORD cursize
; /* current size of realMRU */
1912 LPWSTR realMRU
; /* pointer to string of index names */
1913 LPWINEMRUITEM
*array
; /* array of pointers to data */
1914 /* in 'a' to 'z' order */
1915 } WINEMRULIST
, *LPWINEMRULIST
;
1918 #define WMRUF_CHANGED 0x0001 /* MRU list has changed */
1920 /**************************************************************************
1921 * MRU_SaveChanged (internal)
1923 * Local MRU saving code
1925 static void MRU_SaveChanged(WINEMRULIST
*mp
)
1932 /* or should we do the following instead of RegOpenKeyEx:
1935 /* open the sub key */
1936 if ((err
= RegOpenKeyExW(mp
->extview
.hKey
, mp
->extview
.lpszSubKey
, 0, KEY_WRITE
, &newkey
)))
1938 /* not present - what to do ??? */
1939 ERR("Could not open key, error=%d, attempting to create\n", err
);
1940 if ((err
= RegCreateKeyExW( mp
->extview
.hKey
, mp
->extview
.lpszSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
1941 KEY_READ
| KEY_WRITE
, 0, &newkey
, 0)))
1943 ERR("failed to create key /%s/, err=%d\n", debugstr_w(mp
->extview
.lpszSubKey
), err
);
1948 if (mp
->wineFlags
& WMRUF_CHANGED
)
1950 mp
->wineFlags
&= ~WMRUF_CHANGED
;
1951 if ((err
= RegSetValueExW(newkey
, strMRUList
, 0, REG_SZ
, (BYTE
*)mp
->realMRU
,
1952 (lstrlenW(mp
->realMRU
) + 1)*sizeof(WCHAR
))))
1954 ERR("error saving MRUList, err=%d\n", err
);
1956 TRACE("saving MRUList=/%s/\n", debugstr_w(mp
->realMRU
));
1960 for (i
= 0; i
< mp
->cursize
; ++i
)
1962 witem
= mp
->array
[i
];
1963 if (witem
->itemFlag
& WMRUIF_CHANGED
)
1965 witem
->itemFlag
&= ~WMRUIF_CHANGED
;
1966 realname
[0] = 'a' + i
;
1967 if ((err
= RegSetValueExW(newkey
, realname
, 0, (mp
->extview
.fFlags
& MRU_BINARY
) ?
1968 REG_BINARY
: REG_SZ
, &witem
->datastart
, witem
->size
)))
1970 ERR("error saving /%s/, err=%d\n", debugstr_w(realname
), err
);
1972 TRACE("saving value for name /%s/ size=%d\n", debugstr_w(realname
), witem
->size
);
1975 RegCloseKey(newkey
);
1978 /**************************************************************************
1979 * FreeMRUList [COMCTL32.152]
1981 * Frees a most-recently-used items list.
1983 void WINAPI
FreeMRUList(HANDLE hMRUList
)
1985 WINEMRULIST
*mp
= hMRUList
;
1988 TRACE("%p.\n", hMRUList
);
1993 if (mp
->wineFlags
& WMRUF_CHANGED
)
1995 /* need to open key and then save the info */
1996 MRU_SaveChanged(mp
);
1999 for (i
= 0; i
< mp
->extview
.uMax
; ++i
)
2004 Free(mp
->extview
.lpszSubKey
);
2008 /**************************************************************************
2009 * FindMRUData [COMCTL32.169]
2011 * Searches binary list for item that matches data of given length.
2012 * Returns position in list order 0 -> MRU and value corresponding to item's reg.
2013 * name will be stored in it ('a' -> 0).
2016 INT WINAPI
FindMRUData(HANDLE hList
, const void *data
, DWORD cbData
, int *pos
)
2018 const WINEMRULIST
*mp
= hList
;
2023 if (!mp
|| !mp
->extview
.u
.string_cmpfn
)
2026 if (!(mp
->extview
.fFlags
& MRU_BINARY
) && !mp
->isUnicode
)
2028 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, data
, -1, NULL
, 0, NULL
, NULL
);
2030 WideCharToMultiByte(CP_ACP
, 0, data
, -1, dataA
, len
, NULL
, NULL
);
2033 for (i
= 0; i
< mp
->cursize
; ++i
)
2035 if (mp
->extview
.fFlags
& MRU_BINARY
)
2037 if (!mp
->extview
.u
.binary_cmpfn(data
, &mp
->array
[i
]->datastart
, cbData
))
2044 if (!mp
->extview
.u
.string_cmpfn(data
, (LPWSTR
)&mp
->array
[i
]->datastart
))
2049 DWORD len
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1,
2050 NULL
, 0, NULL
, NULL
);
2051 LPSTR itemA
= Alloc(len
);
2053 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&mp
->array
[i
]->datastart
, -1, itemA
, len
, NULL
, NULL
);
2055 cmp
= mp
->extview
.u
.string_cmpfn((LPWSTR
)dataA
, (LPWSTR
)itemA
);
2064 if (i
< mp
->cursize
)
2068 if (pos
&& (ret
!= -1))
2071 TRACE("%p, %p, %d, %p, returning %d.\n", hList
, data
, cbData
, pos
, ret
);
2076 /**************************************************************************
2077 * AddMRUData [COMCTL32.167]
2079 * Add item to MRU binary list. If item already exists in list then it is
2080 * simply moved up to the top of the list and not added again. If list is
2081 * full then the least recently used item is removed to make room.
2084 INT WINAPI
AddMRUData(HANDLE hList
, const void *data
, DWORD cbData
)
2086 WINEMRULIST
*mp
= hList
;
2090 if ((replace
= FindMRUData(hList
, data
, cbData
, NULL
)) >= 0)
2092 /* Item exists, just move it to the front */
2093 LPWSTR pos
= wcschr(mp
->realMRU
, replace
+ 'a');
2094 while (pos
> mp
->realMRU
)
2102 /* either add a new entry or replace oldest */
2103 if (mp
->cursize
< mp
->extview
.uMax
)
2105 /* Add in a new item */
2106 replace
= mp
->cursize
;
2111 /* get the oldest entry and replace data */
2112 replace
= mp
->realMRU
[mp
->cursize
- 1] - 'a';
2113 Free(mp
->array
[replace
]);
2116 /* Allocate space for new item and move in the data */
2117 mp
->array
[replace
] = witem
= Alloc(cbData
+ sizeof(WINEMRUITEM
));
2118 witem
->itemFlag
|= WMRUIF_CHANGED
;
2119 witem
->size
= cbData
;
2120 memcpy( &witem
->datastart
, data
, cbData
);
2122 /* now rotate MRU list */
2123 for (i
= mp
->cursize
- 1; i
>= 1; --i
)
2124 mp
->realMRU
[i
] = mp
->realMRU
[i
-1];
2127 /* The new item gets the front spot */
2128 mp
->wineFlags
|= WMRUF_CHANGED
;
2129 mp
->realMRU
[0] = replace
+ 'a';
2131 TRACE("(%p, %p, %d) adding data, /%c/ now most current\n", hList
, data
, cbData
, replace
+'a');
2133 if (!(mp
->extview
.fFlags
& MRU_CACHEWRITE
))
2135 /* save changed stuff right now */
2136 MRU_SaveChanged(mp
);
2142 /**************************************************************************
2143 * AddMRUStringW [COMCTL32.401]
2145 * Add an item to an MRU string list.
2148 INT WINAPI
AddMRUStringW(HANDLE hList
, const WCHAR
*str
)
2150 TRACE("%p, %s.\n", hList
, debugstr_w(str
));
2155 if (!str
|| IsBadStringPtrW(str
, -1))
2157 SetLastError(ERROR_INVALID_PARAMETER
);
2161 return AddMRUData(hList
, str
, (lstrlenW(str
) + 1) * sizeof(WCHAR
));
2164 /**************************************************************************
2165 * AddMRUStringA [COMCTL32.153]
2167 INT WINAPI
AddMRUStringA(HANDLE hList
, const char *str
)
2173 TRACE("%p, %s.\n", hList
, debugstr_a(str
));
2178 if (IsBadStringPtrA(str
, -1))
2180 SetLastError(ERROR_INVALID_PARAMETER
);
2184 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0) * sizeof(WCHAR
);
2189 MultiByteToWideChar(CP_ACP
, 0, str
, -1, strW
, len
/sizeof(WCHAR
));
2190 ret
= AddMRUData(hList
, strW
, len
);
2195 /**************************************************************************
2196 * DelMRUString [COMCTL32.156]
2198 * Removes item from either string or binary list (despite its name)
2201 * hList [I] list handle
2202 * nItemPos [I] item position to remove 0 -> MRU
2205 * TRUE if successful, FALSE if nItemPos is out of range.
2207 BOOL WINAPI
DelMRUString(HANDLE hList
, INT nItemPos
)
2209 FIXME("(%p, %d): stub\n", hList
, nItemPos
);
2213 /**************************************************************************
2214 * FindMRUStringW [COMCTL32.402]
2216 INT WINAPI
FindMRUStringW(HANDLE hList
, const WCHAR
*str
, int *pos
)
2218 return FindMRUData(hList
, str
, (lstrlenW(str
) + 1) * sizeof(WCHAR
), pos
);
2221 /**************************************************************************
2222 * FindMRUStringA [COMCTL32.155]
2224 * Searches string list for item that matches given string.
2227 * Position in list 0 -> MRU. -1 if item not found.
2229 INT WINAPI
FindMRUStringA(HANDLE hList
, const char *str
, int *pos
)
2231 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
2232 WCHAR
*strW
= Alloc(len
* sizeof(*strW
));
2235 MultiByteToWideChar(CP_ACP
, 0, str
, -1, strW
, len
);
2236 ret
= FindMRUData(hList
, strW
, len
* sizeof(WCHAR
), pos
);
2241 /*************************************************************************
2242 * create_mru_list (internal)
2244 static HANDLE
create_mru_list(WINEMRULIST
*mp
)
2248 DWORD datasize
, dwdisp
;
2253 /* get space to save indices that will turn into names
2254 * but in order of most to least recently used
2256 mp
->realMRU
= Alloc((mp
->extview
.uMax
+ 2) * sizeof(WCHAR
));
2258 /* get space to save pointers to actual data in order of
2259 * 'a' to 'z' (0 to n).
2261 mp
->array
= Alloc(mp
->extview
.uMax
* sizeof(LPVOID
));
2263 /* open the sub key */
2264 if ((err
= RegCreateKeyExW(mp
->extview
.hKey
, mp
->extview
.lpszSubKey
, 0, NULL
, REG_OPTION_NON_VOLATILE
,
2265 KEY_READ
| KEY_WRITE
, 0, &newkey
, &dwdisp
)))
2267 /* error - what to do ??? */
2268 ERR("(%u %u %x %p %s %p): Could not open key, error=%d\n", mp
->extview
.cbSize
, mp
->extview
.uMax
, mp
->extview
.fFlags
,
2269 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
), mp
->extview
.u
.string_cmpfn
, err
);
2273 /* get values from key 'MRUList' */
2276 datasize
= (mp
->extview
.uMax
+ 1) * sizeof(WCHAR
);
2277 if (RegQueryValueExW( newkey
, strMRUList
, 0, &type
, (BYTE
*)mp
->realMRU
, &datasize
))
2279 /* not present - set size to 1 (will become 0 later) */
2284 datasize
/= sizeof(WCHAR
);
2286 TRACE("MRU list = %s, datasize = %d\n", debugstr_w(mp
->realMRU
), datasize
);
2288 mp
->cursize
= datasize
- 1;
2289 /* datasize now has number of items in the MRUList */
2291 /* get actual values for each entry */
2293 for (i
= 0; i
< mp
->cursize
; ++i
)
2295 realname
[0] = 'a' + i
;
2296 if (RegQueryValueExW(newkey
, realname
, 0, &type
, 0, &datasize
))
2298 /* not present - what to do ??? */
2299 ERR("Key %s not found 1\n", debugstr_w(realname
));
2301 mp
->array
[i
] = witem
= Alloc(datasize
+ sizeof(WINEMRUITEM
));
2302 witem
->size
= datasize
;
2303 if (RegQueryValueExW(newkey
, realname
, 0, &type
, &witem
->datastart
, &datasize
))
2305 /* not present - what to do ??? */
2306 ERR("Key %s not found 2\n", debugstr_w(realname
));
2309 RegCloseKey( newkey
);
2314 TRACE("(%u %u %x %p %s %p): Current Size = %d\n", mp
->extview
.cbSize
, mp
->extview
.uMax
, mp
->extview
.fFlags
,
2315 mp
->extview
.hKey
, debugstr_w(mp
->extview
.lpszSubKey
), mp
->extview
.u
.string_cmpfn
, mp
->cursize
);
2319 /**************************************************************************
2320 * CreateMRUListLazyW [COMCTL32.404]
2322 HANDLE WINAPI
CreateMRUListLazyW(const struct MRUINFOW
*info
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
2326 /* Native does not check for a NULL. */
2327 if (!info
->hKey
|| IsBadStringPtrW(info
->lpszSubKey
, -1))
2330 mp
= Alloc(sizeof(*mp
));
2331 memcpy(&mp
->extview
, info
, sizeof(*info
));
2332 mp
->extview
.lpszSubKey
= Alloc((lstrlenW(info
->lpszSubKey
) + 1) * sizeof(WCHAR
));
2333 lstrcpyW(mp
->extview
.lpszSubKey
, info
->lpszSubKey
);
2334 mp
->isUnicode
= TRUE
;
2336 return create_mru_list(mp
);
2339 /**************************************************************************
2340 * CreateMRUListLazyA [COMCTL32.157]
2342 * Creates a most-recently-used list.
2344 HANDLE WINAPI
CreateMRUListLazyA(const struct MRUINFOA
*info
, DWORD dwParam2
, DWORD dwParam3
, DWORD dwParam4
)
2349 /* Native does not check for a NULL lpcml */
2351 if (!info
->hKey
|| IsBadStringPtrA(info
->lpszSubKey
, -1))
2354 mp
= Alloc(sizeof(*mp
));
2355 memcpy(&mp
->extview
, info
, sizeof(*info
));
2356 len
= MultiByteToWideChar(CP_ACP
, 0, info
->lpszSubKey
, -1, NULL
, 0);
2357 mp
->extview
.lpszSubKey
= Alloc(len
* sizeof(WCHAR
));
2358 MultiByteToWideChar(CP_ACP
, 0, info
->lpszSubKey
, -1, mp
->extview
.lpszSubKey
, len
);
2359 mp
->isUnicode
= FALSE
;
2360 return create_mru_list(mp
);
2363 /**************************************************************************
2364 * CreateMRUListW [COMCTL32.400]
2366 HANDLE WINAPI
CreateMRUListW(const struct MRUINFOW
*info
)
2368 return CreateMRUListLazyW(info
, 0, 0, 0);
2371 /**************************************************************************
2372 * CreateMRUListA [COMCTL32.151]
2374 HANDLE WINAPI
CreateMRUListA(const struct MRUINFOA
*info
)
2376 return CreateMRUListLazyA(info
, 0, 0, 0);
2379 /**************************************************************************
2380 * EnumMRUListW [COMCTL32.403]
2382 * Enumerate item in a most-recently-used list
2385 * hList [I] list handle
2386 * nItemPos [I] item position to enumerate
2387 * lpBuffer [O] buffer to receive item
2388 * nBufferSize [I] size of buffer
2391 * For binary lists specifies how many bytes were copied to buffer, for
2392 * string lists specifies full length of string. Enumerating past the end
2393 * of list returns -1.
2394 * If lpBuffer == NULL or nItemPos is -ve return value is no. of items in
2397 INT WINAPI
EnumMRUListW(HANDLE hList
, INT nItemPos
, void *buffer
, DWORD nBufferSize
)
2399 const WINEMRULIST
*mp
= hList
;
2400 const WINEMRUITEM
*witem
;
2401 INT desired
, datasize
;
2404 if ((nItemPos
< 0) || !buffer
) return mp
->cursize
;
2405 if (nItemPos
>= mp
->cursize
) return -1;
2406 desired
= mp
->realMRU
[nItemPos
];
2408 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
2409 witem
= mp
->array
[desired
];
2410 datasize
= min(witem
->size
, nBufferSize
);
2411 memcpy(buffer
, &witem
->datastart
, datasize
);
2412 TRACE("(%p, %d, %p, %d): returning len=%d\n", hList
, nItemPos
, buffer
, nBufferSize
, datasize
);
2416 /**************************************************************************
2417 * EnumMRUListA [COMCTL32.154]
2419 INT WINAPI
EnumMRUListA(HANDLE hList
, INT nItemPos
, void *buffer
, DWORD nBufferSize
)
2421 const WINEMRULIST
*mp
= hList
;
2423 INT desired
, datasize
;
2427 if ((nItemPos
< 0) || !buffer
) return mp
->cursize
;
2428 if (nItemPos
>= mp
->cursize
) return -1;
2429 desired
= mp
->realMRU
[nItemPos
];
2431 TRACE("nItemPos=%d, desired=%d\n", nItemPos
, desired
);
2432 witem
= mp
->array
[desired
];
2433 if (mp
->extview
.fFlags
& MRU_BINARY
)
2435 datasize
= min(witem
->size
, nBufferSize
);
2436 memcpy(buffer
, &witem
->datastart
, datasize
);
2440 lenA
= WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1, NULL
, 0, NULL
, NULL
);
2441 datasize
= min(lenA
, nBufferSize
);
2442 WideCharToMultiByte(CP_ACP
, 0, (LPWSTR
)&witem
->datastart
, -1, buffer
, datasize
, NULL
, NULL
);
2443 ((char *)buffer
)[ datasize
- 1 ] = '\0';
2444 datasize
= lenA
- 1;
2446 TRACE("(%p, %d, %p, %d): returning len=%d\n", hList
, nItemPos
, buffer
, nBufferSize
, datasize
);
2450 /**************************************************************************
2451 * Str_GetPtrWtoA [internal]
2453 * Converts a unicode string into a multi byte string
2457 INT
Str_GetPtrWtoA(const WCHAR
*src
, char *dst
, INT nMaxLen
)
2461 TRACE("%s, %p, %d.\n", debugstr_w(src
), dst
, nMaxLen
);
2464 return WideCharToMultiByte(CP_ACP
, 0, src
, -1, 0, 0, NULL
, NULL
);
2475 len
= WideCharToMultiByte(CP_ACP
, 0, src
, -1, 0, 0, NULL
, NULL
);
2479 WideCharToMultiByte(CP_ACP
, 0, src
, -1, dst
, len
, NULL
, NULL
);
2485 /**************************************************************************
2486 * Str_GetPtrAtoW [internal]
2488 * Converts a multibyte string into a unicode string
2491 INT
Str_GetPtrAtoW(const char *src
, WCHAR
*dst
, INT nMaxLen
)
2495 TRACE("%s, %p, %d.\n", debugstr_a(src
), dst
, nMaxLen
);
2498 return MultiByteToWideChar(CP_ACP
, 0, src
, -1, 0, 0);
2509 len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, 0, 0);
2513 MultiByteToWideChar(CP_ACP
, 0, src
, -1, dst
, len
);
2519 /**************************************************************************
2520 * Str_SetPtrAtoW [internal]
2522 * Converts a multi byte string to a unicode string.
2523 * If the pointer to the destination buffer is NULL a buffer is allocated.
2524 * If the destination buffer is too small to keep the converted multi byte
2525 * string the destination buffer is reallocated. If the source pointer is
2527 BOOL
Str_SetPtrAtoW(WCHAR
**dst
, const char *src
)
2529 TRACE("%p, %s.\n", dst
, debugstr_a(src
));
2533 INT len
= MultiByteToWideChar(CP_ACP
, 0, src
, -1, NULL
, 0);
2534 LPWSTR ptr
= ReAlloc(*dst
, len
* sizeof(**dst
));
2538 MultiByteToWideChar(CP_ACP
, 0, src
, -1, ptr
, len
);
2550 /**************************************************************************
2551 * Str_SetPtrWtoA [internal]
2553 * Converts a unicode string to a multi byte string.
2554 * If the pointer to the destination buffer is NULL a buffer is allocated.
2555 * If the destination buffer is too small to keep the converted wide
2556 * string the destination buffer is reallocated. If the source pointer is
2557 * NULL, the destination buffer is freed.
2559 BOOL
Str_SetPtrWtoA(char **dst
, const WCHAR
*src
)
2561 TRACE("%p, %s.\n", dst
, debugstr_w(src
));
2565 INT len
= WideCharToMultiByte(CP_ACP
, 0, src
, -1, NULL
, 0, NULL
, FALSE
);
2566 LPSTR ptr
= ReAlloc(*dst
, len
* sizeof(**dst
));
2570 WideCharToMultiByte(CP_ACP
, 0, src
, -1, ptr
, len
, NULL
, FALSE
);
2582 /**************************************************************************
2583 * Notification functions
2596 /**************************************************************************
2597 * DoNotify [Internal]
2600 static LRESULT
DoNotify(const struct NOTIFYDATA
*notify
, UINT code
, NMHDR
*hdr
)
2603 NMHDR
*lpNmh
= NULL
;
2606 TRACE("%p, %p, %d, %p, %#x.\n", notify
->hwndFrom
, notify
->hwndTo
, code
, hdr
, notify
->dwParam5
);
2608 if (!notify
->hwndTo
)
2611 if (notify
->hwndFrom
== (HWND
)-1)
2614 idFrom
= hdr
->idFrom
;
2618 if (notify
->hwndFrom
)
2619 idFrom
= GetDlgCtrlID(notify
->hwndFrom
);
2621 lpNmh
= hdr
? hdr
: &nmhdr
;
2622 lpNmh
->hwndFrom
= notify
->hwndFrom
;
2623 lpNmh
->idFrom
= idFrom
;
2627 return SendMessageW(notify
->hwndTo
, WM_NOTIFY
, idFrom
, (LPARAM
)lpNmh
);
2630 /**************************************************************************
2631 * SendNotify [COMCTL32.341]
2633 * Sends a WM_NOTIFY message to the specified window.
2636 LRESULT WINAPI
SendNotify(HWND hwndTo
, HWND hwndFrom
, UINT code
, NMHDR
*hdr
)
2638 struct NOTIFYDATA notify
;
2640 TRACE("%p, %p, %d, %p.\n", hwndTo
, hwndFrom
, code
, hdr
);
2642 notify
.hwndFrom
= hwndFrom
;
2643 notify
.hwndTo
= hwndTo
;
2644 notify
.dwParam5
= 0;
2645 notify
.dwParam6
= 0;
2647 return DoNotify(¬ify
, code
, hdr
);
2650 /**************************************************************************
2651 * SendNotifyEx [COMCTL32.342]
2653 * Sends a WM_NOTIFY message to the specified window.
2656 * hwndFrom [I] Window to receive the message
2657 * hwndTo [I] Window that the message is from
2658 * code [I] Notification code
2659 * hdr [I] The NMHDR and any additional information to send or NULL
2660 * dwParam5 [I] Unknown
2663 * Success: return value from notification
2667 * If hwndFrom is -1 then the identifier of the control sending the
2668 * message is taken from the NMHDR structure.
2669 * If hwndFrom is not -1 then lpHdr can be NULL.
2671 LRESULT WINAPI
SendNotifyEx(HWND hwndTo
, HWND hwndFrom
, UINT code
, NMHDR
*hdr
, DWORD dwParam5
)
2673 struct NOTIFYDATA notify
;
2676 TRACE("(%p %p %d %p %#x)\n", hwndFrom
, hwndTo
, code
, hdr
, dwParam5
);
2678 hwndNotify
= hwndTo
;
2681 if (IsWindow(hwndFrom
))
2683 hwndNotify
= GetParent(hwndFrom
);
2689 notify
.hwndFrom
= hwndFrom
;
2690 notify
.hwndTo
= hwndNotify
;
2691 notify
.dwParam5
= dwParam5
;
2692 notify
.dwParam6
= 0;
2694 return DoNotify(¬ify
, code
, hdr
);