comctl32: Fix a typo in comment.
[wine.git] / dlls / user32 / desktop.c
blobd22e732fd5b95b64529ef268bace134f885e0881
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 "config.h"
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winnls.h"
34 #include "controls.h"
35 #include "wine/unicode.h"
37 static HBRUSH hbrushPattern;
38 static HBITMAP hbitmapWallPaper;
39 static SIZE bitmapSize;
40 static BOOL fTileWallPaper;
43 /*********************************************************************
44 * desktop class descriptor
46 const struct builtin_class_descr DESKTOP_builtin_class =
48 (LPCWSTR)DESKTOP_CLASS_ATOM, /* name */
49 CS_DBLCLKS, /* style */
50 WINPROC_DESKTOP, /* proc */
51 0, /* extra */
52 0, /* cursor */
53 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
57 /***********************************************************************
58 * DESKTOP_LoadBitmap
60 static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename )
62 HBITMAP hbitmap;
64 if (!filename[0]) return 0;
65 hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
66 if (!hbitmap)
68 WCHAR buffer[MAX_PATH];
69 UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
70 if (buffer[len - 1] != '\\') buffer[len++] = '\\';
71 lstrcpynW( buffer + len, filename, MAX_PATH - len );
72 hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
74 return hbitmap;
77 /***********************************************************************
78 * init_wallpaper
80 static void init_wallpaper( const WCHAR *wallpaper )
82 HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper );
84 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
85 hbitmapWallPaper = hbitmap;
86 if (hbitmap)
88 BITMAP bmp;
89 GetObjectA( hbitmap, sizeof(bmp), &bmp );
90 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
91 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
92 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
96 /***********************************************************************
97 * DesktopWndProc
99 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
101 static const WCHAR display_device_guid_propW[] = {
102 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
103 'd','e','v','i','c','e','_','g','u','i','d',0 };
104 static const WCHAR guid_formatW[] = {
105 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%','0','2','x','%','0','2','x','-',
106 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',0};
108 switch (message)
110 case WM_NCCREATE:
112 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
113 const GUID *guid = cs->lpCreateParams;
115 if (guid)
117 ATOM atom;
118 WCHAR buffer[37];
120 if (GetAncestor( hwnd, GA_PARENT )) return FALSE; /* refuse to create non-desktop window */
122 sprintfW( buffer, guid_formatW, guid->Data1, guid->Data2, guid->Data3,
123 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
124 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
125 atom = GlobalAddAtomW( buffer );
126 SetPropW( hwnd, display_device_guid_propW, ULongToHandle( atom ) );
128 return TRUE;
130 default:
131 return 0; /* all other messages are ignored */
135 /***********************************************************************
136 * PaintDesktop (USER32.@)
139 BOOL WINAPI PaintDesktop(HDC hdc)
141 HWND hwnd = GetDesktopWindow();
143 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
144 if (GetWindowThreadProcessId( hwnd, NULL ))
146 RECT rect;
148 GetClientRect( hwnd, &rect );
150 /* Paint desktop pattern (only if wall paper does not cover everything) */
152 if (!hbitmapWallPaper ||
153 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
155 HBRUSH brush = hbrushPattern;
156 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
157 /* Set colors in case pattern is a monochrome bitmap */
158 SetBkColor( hdc, RGB(0,0,0) );
159 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
160 FillRect( hdc, &rect, brush );
163 /* Paint wall paper */
165 if (hbitmapWallPaper)
167 INT x, y;
168 HDC hMemDC = CreateCompatibleDC( hdc );
170 SelectObject( hMemDC, hbitmapWallPaper );
172 if (fTileWallPaper)
174 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
175 for (x = 0; x < rect.right; x += bitmapSize.cx)
176 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
178 else
180 x = (rect.left + rect.right - bitmapSize.cx) / 2;
181 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
182 if (x < 0) x = 0;
183 if (y < 0) y = 0;
184 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
186 DeleteDC( hMemDC );
189 return TRUE;
192 /***********************************************************************
193 * SetDeskWallPaper (USER32.@)
195 * FIXME: is there a unicode version?
197 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
199 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
203 /***********************************************************************
204 * update_wallpaper
206 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
208 int pat[8];
210 if (hbrushPattern) DeleteObject( hbrushPattern );
211 hbrushPattern = 0;
212 memset( pat, 0, sizeof(pat) );
213 if (pattern)
215 char buffer[64];
216 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
217 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
218 &pat[0], &pat[1], &pat[2], &pat[3],
219 &pat[4], &pat[5], &pat[6], &pat[7] ))
221 WORD ptrn[8];
222 HBITMAP hbitmap;
223 int i;
225 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
226 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
227 hbrushPattern = CreatePatternBrush( hbitmap );
228 DeleteObject( hbitmap );
231 init_wallpaper( wallpaper );
232 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
233 return TRUE;