wow64: Add thunks for the I/O completion syscalls.
[wine.git] / dlls / user32 / desktop.c
blobf7ab99a38bf358b01a73dbf996e5e710d08a3962
1 /*
2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winnls.h"
29 #include "controls.h"
31 static HBRUSH hbrushPattern;
32 static HBITMAP hbitmapWallPaper;
33 static SIZE bitmapSize;
34 static BOOL fTileWallPaper;
37 /*********************************************************************
38 * desktop class descriptor
40 const struct builtin_class_descr DESKTOP_builtin_class =
42 (LPCWSTR)DESKTOP_CLASS_ATOM, /* name */
43 CS_DBLCLKS, /* style */
44 WINPROC_DESKTOP, /* proc */
45 0, /* extra */
46 0, /* cursor */
47 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
51 /***********************************************************************
52 * DESKTOP_LoadBitmap
54 static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename )
56 HBITMAP hbitmap;
58 if (!filename[0]) return 0;
59 hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
60 if (!hbitmap)
62 WCHAR buffer[MAX_PATH];
63 UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
64 if (buffer[len - 1] != '\\') buffer[len++] = '\\';
65 lstrcpynW( buffer + len, filename, MAX_PATH - len );
66 hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
68 return hbitmap;
71 /***********************************************************************
72 * init_wallpaper
74 static void init_wallpaper( const WCHAR *wallpaper )
76 HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper );
78 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
79 hbitmapWallPaper = hbitmap;
80 if (hbitmap)
82 BITMAP bmp;
83 GetObjectA( hbitmap, sizeof(bmp), &bmp );
84 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
85 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
86 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
90 /***********************************************************************
91 * DesktopWndProc
93 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
95 switch (message)
97 case WM_NCCREATE:
99 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
100 const GUID *guid = cs->lpCreateParams;
102 if (guid)
104 ATOM atom;
105 WCHAR buffer[37];
107 if (GetAncestor( hwnd, GA_PARENT )) return FALSE; /* refuse to create non-desktop window */
109 swprintf( buffer, ARRAY_SIZE(buffer), L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
110 guid->Data1, guid->Data2, guid->Data3,
111 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
112 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
113 atom = GlobalAddAtomW( buffer );
114 SetPropW( hwnd, L"__wine_display_device_guid", ULongToHandle( atom ) );
116 return TRUE;
118 case WM_NCCALCSIZE:
119 return 0;
120 default:
121 return DefWindowProcW( hwnd, message, wParam, lParam );
125 /***********************************************************************
126 * PaintDesktop (USER32.@)
129 BOOL WINAPI PaintDesktop(HDC hdc)
131 HWND hwnd = GetDesktopWindow();
133 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
134 if (GetWindowThreadProcessId( hwnd, NULL ))
136 RECT rect;
138 GetClientRect( hwnd, &rect );
140 /* Paint desktop pattern (only if wall paper does not cover everything) */
142 if (!hbitmapWallPaper ||
143 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
145 HBRUSH brush = hbrushPattern;
146 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
147 /* Set colors in case pattern is a monochrome bitmap */
148 SetBkColor( hdc, RGB(0,0,0) );
149 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
150 FillRect( hdc, &rect, brush );
153 /* Paint wall paper */
155 if (hbitmapWallPaper)
157 INT x, y;
158 HDC hMemDC = CreateCompatibleDC( hdc );
160 SelectObject( hMemDC, hbitmapWallPaper );
162 if (fTileWallPaper)
164 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
165 for (x = 0; x < rect.right; x += bitmapSize.cx)
166 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
168 else
170 x = (rect.left + rect.right - bitmapSize.cx) / 2;
171 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
172 if (x < 0) x = 0;
173 if (y < 0) y = 0;
174 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
176 DeleteDC( hMemDC );
179 return TRUE;
182 /***********************************************************************
183 * SetDeskWallPaper (USER32.@)
185 * FIXME: is there a unicode version?
187 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
189 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
193 /***********************************************************************
194 * update_wallpaper
196 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
198 int pat[8];
200 if (hbrushPattern) DeleteObject( hbrushPattern );
201 hbrushPattern = 0;
202 memset( pat, 0, sizeof(pat) );
203 if (pattern)
205 char buffer[64];
206 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
207 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
208 &pat[0], &pat[1], &pat[2], &pat[3],
209 &pat[4], &pat[5], &pat[6], &pat[7] ))
211 WORD ptrn[8];
212 HBITMAP hbitmap;
213 int i;
215 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
216 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
217 hbrushPattern = CreatePatternBrush( hbitmap );
218 DeleteObject( hbitmap );
221 init_wallpaper( wallpaper );
222 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
223 return TRUE;