2 * Misc 16-bit USER functions
4 * Copyright 2002 Patrik Stridvall
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/winuser16.h"
27 /* handle to handle 16 conversions */
28 #define HANDLE_16(h32) (LOWORD(h32))
30 /* handle16 to handle conversions */
31 #define HANDLE_32(h16) ((HANDLE)(ULONG_PTR)(h16))
32 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
34 WORD WINAPI DestroyIcon32(HGLOBAL16, UINT16);
37 /***********************************************************************
40 HCURSOR16 WINAPI SetCursor16(HCURSOR16 hCursor)
42 return HCURSOR_16(SetCursor(HCURSOR_32(hCursor)));
45 /***********************************************************************
46 * ShowCursor (USER.71)
48 INT16 WINAPI ShowCursor16(BOOL16 bShow)
50 return ShowCursor(bShow);
53 /***********************************************************************
56 BOOL16 WINAPI DrawIcon16(HDC16 hdc, INT16 x, INT16 y, HICON16 hIcon)
58 return DrawIcon(HDC_32(hdc), x, y, HICON_32(hIcon));
61 /***********************************************************************
64 * See "Undocumented Windows". Used by W2.0 paint.exe.
66 DWORD WINAPI IconSize16(void)
68 return MAKELONG(GetSystemMetrics(SM_CYICON), GetSystemMetrics(SM_CXICON));
71 /***********************************************************************
72 * LoadCursor (USER.173)
74 HCURSOR16 WINAPI LoadCursor16(HINSTANCE16 hInstance, LPCSTR name)
76 return HCURSOR_16(LoadCursorA(HINSTANCE_32(hInstance), name));
80 /***********************************************************************
83 HICON16 WINAPI LoadIcon16(HINSTANCE16 hInstance, LPCSTR name)
85 return HICON_16(LoadIconA(HINSTANCE_32(hInstance), name));
88 /**********************************************************************
89 * LoadBitmap (USER.175)
91 HBITMAP16 WINAPI LoadBitmap16(HINSTANCE16 hInstance, LPCSTR name)
93 return HBITMAP_16(LoadBitmapA(HINSTANCE_32(hInstance), name));
96 /*************************************************************************
99 BOOL16 WINAPI ScrollDC16( HDC16 hdc, INT16 dx, INT16 dy, const RECT16 *rect,
100 const RECT16 *cliprc, HRGN16 hrgnUpdate,
103 RECT rect32, clipRect32, rcUpdate32;
106 if (rect) CONV_RECT16TO32( rect, &rect32 );
107 if (cliprc) CONV_RECT16TO32( cliprc, &clipRect32 );
108 ret = ScrollDC( HDC_32(hdc), dx, dy, rect ? &rect32 : NULL,
109 cliprc ? &clipRect32 : NULL, HRGN_32(hrgnUpdate),
111 if (rcUpdate) CONV_RECT32TO16( &rcUpdate32, rcUpdate );
115 /***********************************************************************
116 * GetCursor (USER.247)
118 HCURSOR16 WINAPI GetCursor16(void)
120 return HCURSOR_16(GetCursor());
123 /***********************************************************************
124 * GlobalAddAtom (USER.268)
126 ATOM WINAPI GlobalAddAtom16(LPCSTR lpString)
128 return GlobalAddAtomA(lpString);
131 /***********************************************************************
132 * GlobalDeleteAtom (USER.269)
134 ATOM WINAPI GlobalDeleteAtom16(ATOM nAtom)
136 return GlobalDeleteAtom(nAtom);
139 /***********************************************************************
140 * GlobalFindAtom (USER.270)
142 ATOM WINAPI GlobalFindAtom16(LPCSTR lpString)
144 return GlobalFindAtomA(lpString);
147 /***********************************************************************
148 * GlobalGetAtomName (USER.271)
150 UINT16 WINAPI GlobalGetAtomName16(ATOM nAtom, LPSTR lpBuffer, INT16 nSize)
152 return GlobalGetAtomNameA(nAtom, lpBuffer, nSize);
155 /***********************************************************************
156 * SelectPalette (USER.282)
158 HPALETTE16 WINAPI SelectPalette16( HDC16 hdc, HPALETTE16 hpal, BOOL16 bForceBackground )
160 return HPALETTE_16( SelectPalette( HDC_32(hdc), HPALETTE_32(hpal), bForceBackground ));
163 /***********************************************************************
164 * RealizePalette (USER.283)
166 UINT16 WINAPI RealizePalette16( HDC16 hdc )
168 return UserRealizePalette( HDC_32(hdc) );
171 /***********************************************************************
172 * LoadImage (USER.389)
175 HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type,
176 INT16 desiredx, INT16 desiredy, UINT16 loadflags)
178 return HANDLE_16(LoadImageA(HINSTANCE_32(hinst), name, type, desiredx,
179 desiredy, loadflags));
182 /******************************************************************************
183 * CopyImage (USER.390) Creates new image and copies attributes to it
186 HICON16 WINAPI CopyImage16(HANDLE16 hnd, UINT16 type, INT16 desiredx,
187 INT16 desiredy, UINT16 flags)
189 return HICON_16(CopyImage(HANDLE_32(hnd), (UINT)type, (INT)desiredx,
190 (INT)desiredy, (UINT)flags));
193 /**********************************************************************
194 * DrawIconEx (USER.394)
196 BOOL16 WINAPI DrawIconEx16(HDC16 hdc, INT16 xLeft, INT16 yTop, HICON16 hIcon,
197 INT16 cxWidth, INT16 cyWidth, UINT16 istep,
198 HBRUSH16 hbr, UINT16 flags)
200 return DrawIconEx(HDC_32(hdc), xLeft, yTop, HICON_32(hIcon), cxWidth, cyWidth,
201 istep, HBRUSH_32(hbr), flags);
204 /**********************************************************************
205 * GetIconInfo (USER.395)
207 BOOL16 WINAPI GetIconInfo16(HICON16 hIcon, LPICONINFO16 iconinfo)
210 BOOL16 ret = GetIconInfo(HICON_32(hIcon), &ii32);
212 iconinfo->fIcon = ii32.fIcon;
213 iconinfo->xHotspot = ii32.xHotspot;
214 iconinfo->yHotspot = ii32.yHotspot;
215 iconinfo->hbmMask = HBITMAP_16(ii32.hbmMask);
216 iconinfo->hbmColor = HBITMAP_16(ii32.hbmColor);
220 /***********************************************************************
221 * CreateCursor (USER.406)
223 HCURSOR16 WINAPI CreateCursor16(HINSTANCE16 hInstance,
224 INT16 xHotSpot, INT16 yHotSpot,
225 INT16 nWidth, INT16 nHeight,
226 LPCVOID lpANDbits, LPCVOID lpXORbits)
230 info.ptHotSpot.x = xHotSpot;
231 info.ptHotSpot.y = yHotSpot;
232 info.nWidth = nWidth;
233 info.nHeight = nHeight;
234 info.nWidthBytes = 0;
236 info.bBitsPerPixel = 1;
238 return CreateCursorIconIndirect16(hInstance, &info, lpANDbits, lpXORbits);
241 /**********************************************************************
242 * CreateIconFromResourceEx (USER.450)
244 * FIXME: not sure about exact parameter types
246 HICON16 WINAPI CreateIconFromResourceEx16(LPBYTE bits, UINT16 cbSize,
247 BOOL16 bIcon, DWORD dwVersion,
248 INT16 width, INT16 height,
251 return HICON_16(CreateIconFromResourceEx(bits, cbSize, bIcon, dwVersion,
252 width, height, cFlag));
255 /***********************************************************************
256 * DestroyIcon (USER.457)
258 BOOL16 WINAPI DestroyIcon16(HICON16 hIcon)
260 return DestroyIcon32(hIcon, 0);
263 /***********************************************************************
264 * DestroyCursor (USER.458)
266 BOOL16 WINAPI DestroyCursor16(HCURSOR16 hCursor)
268 return DestroyIcon32(hCursor, 0);
271 /*******************************************************************
274 * Recursively find a child that contains spDragInfo->pt point
275 * and send WM_QUERYDROPOBJECT. Helper for DragObject16.
277 static BOOL DRAG_QueryUpdate16( HWND hQueryWnd, SEGPTR spDragInfo )
282 LPDRAGINFO16 ptrDragInfo = MapSL(spDragInfo);
286 if (!IsWindowEnabled(hQueryWnd)) return FALSE;
288 old_pt.x = ptrDragInfo->pt.x;
289 old_pt.y = ptrDragInfo->pt.y;
291 ScreenToClient( hQueryWnd, &pt );
292 child = ChildWindowFromPointEx( hQueryWnd, pt, CWP_SKIPINVISIBLE );
293 if (!child) return FALSE;
295 if (child != hQueryWnd)
298 if (DRAG_QueryUpdate16( child, spDragInfo )) return TRUE;
302 GetClientRect( hQueryWnd, &tempRect );
303 wParam = !PtInRect( &tempRect, pt );
306 ptrDragInfo->pt.x = pt.x;
307 ptrDragInfo->pt.y = pt.y;
308 ptrDragInfo->hScope = HWND_16(hQueryWnd);
310 bResult = SendMessage16( HWND_16(hQueryWnd), WM_QUERYDROPOBJECT, wParam, spDragInfo );
314 ptrDragInfo->pt.x = old_pt.x;
315 ptrDragInfo->pt.y = old_pt.y;
321 /******************************************************************************
322 * DragObject (USER.464)
324 DWORD WINAPI DragObject16( HWND16 hwndScope, HWND16 hWnd, UINT16 wObj,
325 HANDLE16 hOfStruct, WORD szList, HCURSOR16 hCursor )
328 LPDRAGINFO16 lpDragInfo;
330 HCURSOR hOldCursor=0, hBummer=0;
331 HGLOBAL16 hDragInfo = GlobalAlloc16( GMEM_SHARE | GMEM_ZEROINIT, 2*sizeof(DRAGINFO16));
332 HCURSOR hCurrentCursor = 0;
333 HWND16 hCurrentWnd = 0;
335 lpDragInfo = (LPDRAGINFO16) GlobalLock16(hDragInfo);
336 spDragInfo = K32WOWGlobalLock16(hDragInfo);
338 if( !lpDragInfo || !spDragInfo ) return 0L;
340 if (!(hBummer = LoadCursorA(0, MAKEINTRESOURCEA(OCR_NO))))
342 GlobalFree16(hDragInfo);
346 if(hCursor) hOldCursor = SetCursor(HCURSOR_32(hCursor));
348 lpDragInfo->hWnd = hWnd;
349 lpDragInfo->hScope = 0;
350 lpDragInfo->wFlags = wObj;
351 lpDragInfo->hList = szList; /* near pointer! */
352 lpDragInfo->hOfStruct = hOfStruct;
355 SetCapture( HWND_32(hWnd) );
360 GetMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST );
362 *(lpDragInfo+1) = *lpDragInfo;
364 lpDragInfo->pt.x = msg.pt.x;
365 lpDragInfo->pt.y = msg.pt.y;
367 /* update DRAGINFO struct */
368 if( DRAG_QueryUpdate16(WIN_Handle32(hwndScope), spDragInfo) > 0 )
369 hCurrentCursor = HCURSOR_32(hCursor);
372 hCurrentCursor = hBummer;
373 lpDragInfo->hScope = 0;
376 SetCursor(hCurrentCursor);
378 /* send WM_DRAGLOOP */
379 SendMessage16( hWnd, WM_DRAGLOOP, (WPARAM16)(hCurrentCursor != hBummer),
380 (LPARAM) spDragInfo );
381 /* send WM_DRAGSELECT or WM_DRAGMOVE */
382 if( hCurrentWnd != lpDragInfo->hScope )
385 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 0,
386 (LPARAM)MAKELONG(LOWORD(spDragInfo)+sizeof(DRAGINFO16),
387 HIWORD(spDragInfo)) );
388 hCurrentWnd = lpDragInfo->hScope;
390 SendMessage16( hCurrentWnd, WM_DRAGSELECT, 1, (LPARAM)spDragInfo);
394 SendMessage16( hCurrentWnd, WM_DRAGMOVE, 0, (LPARAM)spDragInfo);
396 } while( msg.message != WM_LBUTTONUP && msg.message != WM_NCLBUTTONUP );
401 if( hCursor ) SetCursor(hOldCursor);
403 if( hCurrentCursor != hBummer )
404 msg.lParam = SendMessage16( lpDragInfo->hScope, WM_DROPOBJECT,
405 (WPARAM16)hWnd, (LPARAM)spDragInfo );
408 GlobalFree16(hDragInfo);
410 return (DWORD)(msg.lParam);
414 /**********************************************************************
415 * DrawFrameControl (USER.656)
417 BOOL16 WINAPI DrawFrameControl16( HDC16 hdc, LPRECT16 rc, UINT16 uType, UINT16 uState )
422 CONV_RECT16TO32( rc, &rect32 );
423 ret = DrawFrameControl( HDC_32(hdc), &rect32, uType, uState );
424 CONV_RECT32TO16( &rect32, rc );
428 /**********************************************************************
429 * DrawEdge (USER.659)
431 BOOL16 WINAPI DrawEdge16( HDC16 hdc, LPRECT16 rc, UINT16 edge, UINT16 flags )
436 CONV_RECT16TO32( rc, &rect32 );
437 ret = DrawEdge( HDC_32(hdc), &rect32, edge, flags );
438 CONV_RECT32TO16( &rect32, rc );
442 /**********************************************************************
445 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
451 /* We might call WinExec() */
452 ReleaseThunkLock(&mutex_count);
454 ret = WinHelpA(WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData));
456 RestoreThunkLock(mutex_count);