uxtheme: Remove unused variable.
[wine] / dlls / user32 / desktop.c
1 /*
2  * Desktop window class.
3  *
4  * Copyright 1994 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winnls.h"
34 #include "controls.h"
35
36 static HBRUSH hbrushPattern;
37 static HBITMAP hbitmapWallPaper;
38 static SIZE bitmapSize;
39 static BOOL fTileWallPaper;
40
41
42 /*********************************************************************
43  * desktop class descriptor
44  */
45 const struct builtin_class_descr DESKTOP_builtin_class =
46 {
47     (LPCWSTR)DESKTOP_CLASS_ATOM, /* name */
48     CS_DBLCLKS,           /* style */
49     WINPROC_DESKTOP,      /* proc */
50     0,                    /* extra */
51     IDC_ARROW,            /* cursor */
52     (HBRUSH)(COLOR_BACKGROUND+1)    /* brush */
53 };
54
55
56 /***********************************************************************
57  *           DESKTOP_LoadBitmap
58  */
59 static HBITMAP DESKTOP_LoadBitmap(void)
60 {
61     HBITMAP hbitmap;
62     WCHAR filename[MAX_PATH];
63
64     if (!SystemParametersInfoW( SPI_GETDESKWALLPAPER, MAX_PATH, filename, 0 )) return 0;
65     if (!filename[0]) return 0;
66     hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
67     if (!hbitmap)
68     {
69         WCHAR buffer[MAX_PATH];
70         UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
71         if (buffer[len - 1] != '\\') buffer[len++] = '\\';
72         lstrcpynW( buffer + len, filename, MAX_PATH - len );
73         hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
74     }
75     return hbitmap;
76 }
77
78 /***********************************************************************
79  *           init_wallpaper
80  */
81 static void init_wallpaper(void)
82 {
83     HBITMAP hbitmap = DESKTOP_LoadBitmap();
84
85     if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
86     hbitmapWallPaper = hbitmap;
87     if (hbitmap)
88     {
89         BITMAP bmp;
90         GetObjectA( hbitmap, sizeof(bmp), &bmp );
91         bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
92         bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
93         fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
94     }
95 }
96
97 /***********************************************************************
98  *           DesktopWndProc
99  */
100 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
101 {
102     if (message == WM_NCCREATE) return TRUE;
103     return 0;  /* all other messages are ignored */
104 }
105
106 /***********************************************************************
107  *           PaintDesktop   (USER32.@)
108  *
109  */
110 BOOL WINAPI PaintDesktop(HDC hdc)
111 {
112     HWND hwnd = GetDesktopWindow();
113
114     /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
115     if (GetWindowThreadProcessId( hwnd, NULL ))
116     {
117         RECT rect;
118
119         GetClientRect( hwnd, &rect );
120
121         /* Paint desktop pattern (only if wall paper does not cover everything) */
122
123         if (!hbitmapWallPaper ||
124             (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
125         {
126             HBRUSH brush = hbrushPattern;
127             if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
128             /* Set colors in case pattern is a monochrome bitmap */
129             SetBkColor( hdc, RGB(0,0,0) );
130             SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
131             FillRect( hdc, &rect, brush );
132         }
133
134         /* Paint wall paper */
135
136         if (hbitmapWallPaper)
137         {
138             INT x, y;
139             HDC hMemDC = CreateCompatibleDC( hdc );
140
141             SelectObject( hMemDC, hbitmapWallPaper );
142
143             if (fTileWallPaper)
144             {
145                 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
146                     for (x = 0; x < rect.right; x += bitmapSize.cx)
147                         BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
148             }
149             else
150             {
151                 x = (rect.left + rect.right - bitmapSize.cx) / 2;
152                 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
153                 if (x < 0) x = 0;
154                 if (y < 0) y = 0;
155                 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
156             }
157             DeleteDC( hMemDC );
158         }
159     }
160     return TRUE;
161 }
162
163 /***********************************************************************
164  *           SetDeskWallPaper   (USER32.@)
165  *
166  * FIXME: is there a unicode version?
167  */
168 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
169 {
170     return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
171 }
172
173
174 /***********************************************************************
175  *           DESKTOP_SetPattern
176  *
177  * Set the desktop pattern.
178  */
179 BOOL DESKTOP_SetPattern( LPCWSTR pattern )
180 {
181     int pat[8];
182
183     if (hbrushPattern) DeleteObject( hbrushPattern );
184     hbrushPattern = 0;
185     memset( pat, 0, sizeof(pat) );
186     if (pattern)
187     {
188         char buffer[64];
189         WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
190         if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
191                     &pat[0], &pat[1], &pat[2], &pat[3],
192                     &pat[4], &pat[5], &pat[6], &pat[7] ))
193         {
194             WORD ptrn[8];
195             HBITMAP hbitmap;
196             int i;
197
198             for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
199             hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
200             hbrushPattern = CreatePatternBrush( hbitmap );
201             DeleteObject( hbitmap );
202         }
203     }
204     init_wallpaper();
205     return TRUE;
206 }