Release 960506
[wine/multimedia.git] / win32 / user32.c
blob1a6fa92415dc0f2c3e58ad1240b2ed07038b23c6
1 /*
2 * Win32 user functions
4 * Copyright 1995 Martin von Loewis
5 */
7 /* This file contains only wrappers to existing Wine functions or trivial
8 stubs. 'Real' implementations go into context specific files */
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <stdarg.h>
13 #include "windows.h"
14 #include "winerror.h"
15 #include "relay32.h"
16 #include "alias.h"
17 #include "stackframe.h"
18 #include "xmalloc.h"
19 #include "handle32.h"
20 #include "struct32.h"
21 #include "resource32.h"
22 #include "string32.h"
23 #include "dialog.h"
24 #include "win.h"
25 #include "debug.h"
26 #include "stddebug.h"
28 /***********************************************************************
29 * GetMessageA (USER32.269)
31 BOOL USER32_GetMessageA(MSG32* lpmsg,DWORD hwnd,DWORD min,DWORD max)
33 BOOL ret;
34 MSG msg;
35 ret=GetMessage(MAKE_SEGPTR(&msg),(HWND)hwnd,min,max);
36 STRUCT32_MSG16to32(&msg,lpmsg);
37 return ret;
40 /***********************************************************************
41 * BeginPaint (USER32.9)
43 HDC USER32_BeginPaint(DWORD hwnd,PAINTSTRUCT32 *lpps)
45 PAINTSTRUCT ps;
46 HDC ret;
47 ret=BeginPaint((HWND)hwnd,&ps);
48 lpps->hdc=(DWORD)ps.hdc;
49 lpps->fErase=ps.fErase;
50 lpps->rcPaint.top=ps.rcPaint.top;
51 lpps->rcPaint.left=ps.rcPaint.left;
52 lpps->rcPaint.right=ps.rcPaint.right;
53 lpps->rcPaint.bottom=ps.rcPaint.bottom;
54 lpps->fRestore=ps.fRestore;
55 lpps->fIncUpdate=ps.fIncUpdate;
56 return ret;
59 /***********************************************************************
60 * EndPaint (USER32.175)
62 BOOL USER32_EndPaint(DWORD hwnd,PAINTSTRUCT32 *lpps)
64 PAINTSTRUCT ps;
65 ps.hdc=(HDC)lpps->hdc;
66 ps.fErase=lpps->fErase;
67 ps.rcPaint.top=lpps->rcPaint.top;
68 ps.rcPaint.left=lpps->rcPaint.left;
69 ps.rcPaint.right=lpps->rcPaint.right;
70 ps.rcPaint.bottom=lpps->rcPaint.bottom;
71 ps.fRestore=lpps->fRestore;
72 ps.fIncUpdate=lpps->fIncUpdate;
73 EndPaint((HWND)hwnd,&ps);
74 return TRUE;
77 /***********************************************************************
78 * DispatchMessageA (USER32.140)
80 LONG USER32_DispatchMessageA(MSG32* lpmsg)
82 MSG msg;
83 LONG ret;
84 STRUCT32_MSG32to16(lpmsg,&msg);
85 ret=DispatchMessage(&msg);
86 STRUCT32_MSG16to32(&msg,lpmsg);
87 return ret;
90 /***********************************************************************
91 * TranslateMessage (USER32.555)
93 BOOL USER32_TranslateMessage(MSG32* lpmsg)
95 MSG msg;
96 STRUCT32_MSG32to16(lpmsg,&msg);
97 return TranslateMessage(&msg);
100 /***********************************************************************
101 * CreateWindowEx32A (USER32.82)
103 HWND32 CreateWindowEx32A( DWORD flags, LPCSTR class, LPCSTR title,
104 DWORD style, INT32 x, INT32 y, INT32 width,
105 INT32 height, HWND32 parent, HMENU32 menu,
106 HINSTANCE32 instance, LPVOID param )
108 HWND32 retval;
109 HANDLE classh=0, titleh=0;
110 SEGPTR classsegp=0, titlesegp=0;
111 char *classbuf, *titlebuf;
112 int usec,uset;
114 /*Have to translate CW_USEDEFAULT */
115 if(x==CW_USEDEFAULT32)x=CW_USEDEFAULT16;
116 if(y==CW_USEDEFAULT32)y=CW_USEDEFAULT16;
117 if(width==CW_USEDEFAULT32)width=CW_USEDEFAULT16;
118 if(height==CW_USEDEFAULT32)height=CW_USEDEFAULT16;
120 /* FIXME: There has to be a better way of doing this - but neither
121 malloc nor alloca will work */
122 usec = HIWORD(class);
123 uset = HIWORD(title);
125 if(usec){
126 classh = GlobalAlloc16(0, strlen(class)+1);
127 classsegp = WIN16_GlobalLock16(classh);
128 classbuf = PTR_SEG_TO_LIN(classsegp);
129 strcpy( classbuf, class );
131 if(uset){
132 titleh = GlobalAlloc16(0, strlen(title)+1);
133 titlesegp = WIN16_GlobalLock16(titleh);
134 titlebuf = PTR_SEG_TO_LIN(titlesegp);
135 strcpy( titlebuf, title );
138 retval = (HWND32)CreateWindowEx16(flags,(usec ? classsegp : (SEGPTR)class),
139 (uset ? titlesegp : (SEGPTR)title),style,x,y,width,height,
140 (HWND)parent,(HMENU)menu,(HINSTANCE)instance,
141 (DWORD)param);
142 if(usec)GlobalFree16(classh);
143 if(uset)GlobalFree16(titleh);
144 return retval;
147 HWND32 CreateWindowEx32W( DWORD flags, LPCWSTR class, LPCWSTR title,
148 DWORD style, INT32 x, INT32 y, INT32 width,
149 INT32 height, HWND32 parent, HMENU32 menu,
150 HINSTANCE32 instance, LPVOID param )
152 HWND32 hwnd;
153 LPSTR c,t;
154 int usec,uset;
155 usec=HIWORD(class);
156 uset=HIWORD(title);
157 c = usec ? STRING32_DupUniToAnsi(class) : (LPSTR)class;
158 t = uset ? STRING32_DupUniToAnsi(title) : (LPSTR)title;
159 hwnd=CreateWindowEx32A(flags,c,t,style,x,y,width,height,parent,menu,
160 instance,param);
161 if(usec)free(c);
162 if(uset)free(t);
163 return hwnd;
166 /***********************************************************************
167 * InvalidateRect (USER32.327)
169 BOOL USER32_InvalidateRect(HWND hWnd,const RECT32 *lpRect,BOOL bErase)
171 RECT r;
173 if (lpRect == NULL)
174 InvalidateRect(hWnd, (RECT *)NULL, bErase);
175 else {
176 STRUCT32_RECT32to16(lpRect,&r);
177 InvalidateRect(hWnd,&r,bErase);
179 /* FIXME: Return meaningful value */
180 return TRUE;
183 /***********************************************************************
184 * DrawTextA (USER32.163)
186 int USER32_DrawTextA(HDC hdc,LPCSTR lpStr,int count,RECT32* r32,UINT uFormat)
188 RECT r;
189 STRUCT32_RECT32to16(r32,&r);
190 return DrawText(hdc,lpStr,count,&r,uFormat);
193 /***********************************************************************
194 * GetClientRect (USER32.219)
196 BOOL USER32_GetClientRect(HWND hwnd,RECT32 *r32)
198 RECT r;
199 GetClientRect(hwnd,&r);
200 STRUCT32_RECT16to32(&r,r32);
201 /* FIXME: return value */
202 return 0;
205 UINT USER32_SetTimer(HWND hwnd, UINT id, UINT timeout, void *proc)
208 dprintf_win32(stddeb, "USER32_SetTimer: %d %d %d %08lx\n", hwnd, id, timeout,
209 (LONG)proc );
210 return SetTimer( hwnd, id, timeout, MAKE_SEGPTR(proc));
213 /* WARNING: It has not been verified that the signature or semantics
214 of the corresponding NT function is the same */
216 HWND USER32_CreateDialogIndirectParamAorW(HINSTANCE hInst,LPVOID templ,
217 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam,int A)
219 DLGTEMPLATE32 *dlgTempl=templ;
220 DLGITEMTEMPLATE32 *dlgitem;
221 WORD *ptr;
222 DWORD MenuName=0;
223 DWORD ClassName=0;
224 DWORD szFontName=0;
225 WORD wPointSize;
226 HFONT hFont=0;
227 HMENU hMenu=0;
228 DWORD exStyle;
229 DWORD szCaption;
230 RECT rect;
231 DIALOGINFO *dlgInfo;
232 WND *wndPtr;
233 WORD xUnit = xBaseUnit;
234 WORD yUnit = yBaseUnit;
235 int i;
236 DWORD ClassId;
237 DWORD Text;
238 HWND hwnd,hwndCtrl;
239 HWND hwndDefButton=0;
240 WCHAR buffer[200];
242 /* parse the dialog template header*/
243 exStyle = dlgTempl->dwExtendedStyle;
244 ptr = (WORD*)(dlgTempl+1);
245 switch(*ptr){
246 case 0: MenuName=0;ptr++;break;
247 case 0xFFFF: MenuName=*(ptr+1);ptr+=2;break;
248 default: MenuName = (DWORD)ptr;
249 ptr += STRING32_lstrlenW(ptr)+1;
251 switch(*ptr){
252 case 0: ClassName = DIALOG_CLASS_ATOM;ptr++;break;
253 case 0xFFFF: ClassName = *(ptr+1);ptr+=2;break;
254 default: ClassName = (DWORD)ptr;
255 ptr += STRING32_lstrlenW(ptr)+1;
257 szCaption=(DWORD)ptr;
258 ptr+=STRING32_lstrlenW(ptr)+1;
259 if(dlgTempl->style & DS_SETFONT)
261 wPointSize = *ptr;
262 ptr++;
263 szFontName = (DWORD)ptr;
264 ptr+=STRING32_lstrlenW(ptr)+1;
267 if(MenuName) hMenu=WIN32_LoadMenuW(hInst,(LPWSTR)MenuName);
268 if(dlgTempl->style & DS_SETFONT)
270 fprintf(stderr,"Win32: dialog fonts not supported yet\n");
273 /* Create dialog main window */
274 rect.left = rect.top = 0;
275 rect.right = dlgTempl->cx * xUnit / 4;
276 rect.bottom = dlgTempl->cy * yUnit / 8;
278 /* FIXME: proper modalframe handling ??*/
279 if (dlgTempl->style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
281 AdjustWindowRectEx( &rect, dlgTempl->style,
282 hMenu ? TRUE : FALSE , exStyle );
283 rect.right -= rect.left;
284 rect.bottom -= rect.top;
286 if(dlgTempl->x == CW_USEDEFAULT16)
287 rect.left = rect.top = CW_USEDEFAULT16;
288 else{
289 rect.left += dlgTempl->x * xUnit / 4;
290 rect.top += dlgTempl->y * yUnit / 8;
291 if (!(dlgTempl->style & DS_ABSALIGN))
292 ClientToScreen(hWndParent, (POINT *)&rect );
295 /* FIXME: Here is the place to consider A */
296 hwnd = CreateWindowEx32W(exStyle, (LPWSTR)ClassName, (LPWSTR)szCaption,
297 dlgTempl->style & ~WS_VISIBLE,
298 rect.left, rect.top, rect.right, rect.bottom,
299 hWndParent, hMenu, hInst, 0);
301 if(!hwnd)
303 if(hFont)DeleteObject(hFont);
304 if(hMenu)DeleteObject(hMenu);
305 return 0;
308 wndPtr = WIN_FindWndPtr(hwnd);
310 /* FIXME: should purge junk from system menu, but windows/dialog.c
311 says this does not belong here */
313 /* Create control windows */
314 dprintf_dialog(stddeb, " BEGIN\n" );
315 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
316 dlgInfo->msgResult = 0; /* This is used to store the default button id */
317 dlgInfo->hDialogHeap = 0;
319 for (i = 0; i < dlgTempl->noOfItems; i++)
321 if((int)ptr&3)
323 fprintf(stddeb,"DWORD aligning\n");
324 ptr++;
326 dlgitem = (DLGITEMTEMPLATE32*)ptr;
327 ptr = (WORD*)(dlgitem+1);
328 if(*ptr == 0xFFFF) {
329 /* FIXME: ignore HIBYTE? */
330 ClassId = *(ptr+1);
331 ptr+=2;
332 }else{
333 ClassId = (DWORD)ptr;
334 ptr += STRING32_lstrlenW(ptr)+1;
336 if(*ptr == 0xFFFF) {
337 Text = *(ptr+1);
338 ptr+=2;
339 }else{
340 Text = (DWORD)ptr;
341 ptr += STRING32_lstrlenW(ptr)+1;
343 if(!HIWORD(ClassId))
345 switch(LOWORD(ClassId))
347 case 0x80: STRING32_AnsiToUni(buffer,"BUTTON" ); break;
348 case 0x81: STRING32_AnsiToUni( buffer, "EDIT" ); break;
349 case 0x82: STRING32_AnsiToUni( buffer, "STATIC" ); break;
350 case 0x83: STRING32_AnsiToUni( buffer, "LISTBOX" ); break;
351 case 0x84: STRING32_AnsiToUni( buffer, "SCROLLBAR" ); break;
352 case 0x85: STRING32_AnsiToUni( buffer, "COMBOBOX" ); break;
353 default: buffer[0] = '\0'; break;
355 ClassId = (DWORD)buffer;
357 /*FIXME: debugging output*/
358 /*FIXME: local edit ?*/
359 exStyle = dlgitem->dwExtendedStyle|WS_EX_NOPARENTNOTIFY;
360 if(*ptr)
362 fprintf(stderr,"having data\n");
364 ptr++;
365 hwndCtrl = CreateWindowEx32W(WS_EX_NOPARENTNOTIFY,
366 (LPWSTR)ClassId, (LPWSTR)Text,
367 dlgitem->style | WS_CHILD,
368 dlgitem->x * xUnit / 4,
369 dlgitem->y * yUnit / 8,
370 dlgitem->cx * xUnit / 4,
371 dlgitem->cy * yUnit / 8,
372 hwnd, (HMENU)((DWORD)dlgitem->id),
373 hInst, (SEGPTR)0 );
374 SetWindowPos( hwndCtrl, HWND_BOTTOM, 0, 0, 0, 0,
375 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
376 /* Send initialisation messages to the control */
377 if (hFont) SendMessage( hwndCtrl, WM_SETFONT, (WPARAM)hFont, 0 );
378 if (SendMessage( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
380 /* If there's already a default push-button, set it back */
381 /* to normal and use this one instead. */
382 if (hwndDefButton)
383 SendMessage( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE);
384 hwndDefButton = hwndCtrl;
385 dlgInfo->msgResult = GetWindowWord( hwndCtrl, GWW_ID );
388 dprintf_dialog(stddeb, " END\n" );
390 /* Initialise dialog extra data */
391 ALIAS_RegisterAlias(0,0,lpDialogFunc);
392 dlgInfo->dlgProc = lpDialogFunc;
393 dlgInfo->hUserFont = hFont;
394 dlgInfo->hMenu = hMenu;
395 dlgInfo->xBaseUnit = xUnit;
396 dlgInfo->yBaseUnit = yUnit;
397 dlgInfo->hwndFocus = DIALOG_GetFirstTabItem( hwnd );
399 /* Send initialisation messages and set focus */
400 if (dlgInfo->hUserFont)
401 SendMessage( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
402 if (SendMessage( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, dwInitParam ))
403 SetFocus( dlgInfo->hwndFocus );
404 if (dlgTempl->style & WS_VISIBLE) ShowWindow(hwnd, SW_SHOW);
405 return hwnd;
408 HWND USER32_CreateDialogIndirectParamW(HINSTANCE hInst,LPVOID dlgTempl,
409 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
411 return USER32_CreateDialogIndirectParamAorW(hInst,dlgTempl,hWndParent,
412 lpDialogFunc,dwInitParam,0);
415 HWND USER32_CreateDialogIndirectParamA(HINSTANCE hInst,LPVOID dlgTempl,
416 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
418 return USER32_CreateDialogIndirectParamAorW(hInst,dlgTempl,hWndParent,
419 lpDialogFunc,dwInitParam,1);
422 HWND USER32_CreateDialogParamW(HINSTANCE hInst,LPCWSTR lpszName,
423 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
425 HANDLE32 hrsrc;
426 hrsrc=FindResource32(hInst,lpszName,(LPWSTR)RT_DIALOG);
427 if(!hrsrc)return 0;
428 return USER32_CreateDialogIndirectParamW(hInst,
429 LoadResource32(hInst, hrsrc),hWndParent,lpDialogFunc,dwInitParam);
432 HWND USER32_CreateDialogParamA(HINSTANCE hInst,LPCSTR lpszName,
433 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
435 HWND res;
436 if(!HIWORD(lpszName))
437 res = USER32_CreateDialogParamW(hInst,(LPCWSTR)lpszName,hWndParent,
438 lpDialogFunc,dwInitParam);
439 else{
440 LPWSTR uni=STRING32_DupAnsiToUni(lpszName);
441 res=USER32_CreateDialogParamW(hInst,uni,hWndParent,
442 lpDialogFunc,dwInitParam);
444 return res;
447 int USER32_DialogBoxIndirectParamW(HINSTANCE hInstance,LPVOID dlgTempl,
448 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
450 HWND hwnd;
451 hwnd = USER32_CreateDialogIndirectParamW(hInstance,dlgTempl,
452 hWndParent,lpDialogFunc,dwInitParam);
453 if(hwnd)return DIALOG_DoDialogBox(hwnd,hWndParent);
454 return -1;
457 int USER32_DialogBoxIndirectParamA(HINSTANCE hInstance,LPVOID dlgTempl,
458 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
460 HWND hwnd;
461 hwnd = USER32_CreateDialogIndirectParamA(hInstance,dlgTempl,
462 hWndParent,lpDialogFunc,dwInitParam);
463 if(hwnd)return DIALOG_DoDialogBox(hwnd,hWndParent);
464 return -1;
467 int USER32_DialogBoxParamW(HINSTANCE hInstance,LPCWSTR lpszName,
468 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
470 HWND hwnd;
471 hwnd = USER32_CreateDialogParamW(hInstance,lpszName,
472 hWndParent,lpDialogFunc,dwInitParam);
473 if(hwnd)return DIALOG_DoDialogBox(hwnd,hWndParent);
474 return -1;
477 int USER32_DialogBoxParamA(HINSTANCE hInstance,LPCSTR lpszName,
478 HWND hWndParent,DLGPROC lpDialogFunc,LPARAM dwInitParam)
480 HWND hwnd;
481 hwnd = USER32_CreateDialogParamA(hInstance,lpszName,
482 hWndParent,lpDialogFunc,dwInitParam);
483 if(hwnd)return DIALOG_DoDialogBox(hwnd,hWndParent);
484 return -1;
487 int USER32_wsprintfA( int *args )
489 return vsprintf( (char *)args[0], (char *)args[1], (va_list)&args[2] );