blob: 9d07dc6e763122bccef6ae0eed9575f80c930b91 [file] [log] [blame]
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001/*
2 * Desktop window class.
3 *
4 * Copyright 1994 Alexandre Julliard
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00005 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard0c126c71996-02-18 18:44:41 +000019 */
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000020
Patrik Stridvalld016f812002-08-17 00:43:16 +000021#include "config.h"
22
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000023#include <stdarg.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000024#include <stdio.h>
25#include <string.h>
Patrik Stridvalld016f812002-08-17 00:43:16 +000026#ifdef HAVE_UNISTD_H
27# include <unistd.h>
28#endif
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000029
Marcus Meissner317af321999-02-17 13:51:06 +000030#include "windef.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000031#include "winbase.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000032#include "wingdi.h"
Alexandre Julliard7f3418f2000-03-25 17:30:13 +000033#include "user.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000034#include "controls.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000035#include "wine/winuser16.h"
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000036
Alexandre Julliardde424282001-08-10 22:51:42 +000037static HBRUSH hbrushPattern;
38static HBITMAP hbitmapWallPaper;
39static SIZE bitmapSize;
40static BOOL fTileWallPaper;
Alexandre Julliard91222da2000-12-10 23:01:33 +000041
42static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
43
44
45/*********************************************************************
46 * desktop class descriptor
47 */
48const struct builtin_class_descr DESKTOP_builtin_class =
49{
50 DESKTOP_CLASS_ATOM, /* name */
Alexandre Julliardb0622102003-12-10 04:14:35 +000051 CS_DBLCLKS, /* style */
Alexandre Julliard91222da2000-12-10 23:01:33 +000052 NULL, /* procA (winproc is Unicode only) */
53 DesktopWndProc, /* procW */
Alexandre Julliardde424282001-08-10 22:51:42 +000054 0, /* extra */
Alexandre Julliardcf526442003-09-10 03:56:47 +000055 IDC_ARROW, /* cursor */
Michael Stefaniucec5612e2002-10-30 23:45:38 +000056 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
Alexandre Julliard91222da2000-12-10 23:01:33 +000057};
58
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000059
60/***********************************************************************
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000061 * DESKTOP_LoadBitmap
62 *
63 * Load a bitmap from a file. Used by SetDeskWallPaper().
64 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000065static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000066{
67 BITMAPFILEHEADER *fileHeader;
68 BITMAPINFO *bitmapInfo;
Alexandre Julliarda3960291999-02-26 11:11:13 +000069 HBITMAP hbitmap;
70 HFILE file;
Alexandre Julliard3051b641996-07-05 17:14:13 +000071 LPSTR buffer;
72 LONG size;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000073
Alexandre Julliard3051b641996-07-05 17:14:13 +000074 /* Read all the file into memory */
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000075
Alexandre Julliarda3960291999-02-26 11:11:13 +000076 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
Alexandre Julliard0c126c71996-02-18 18:44:41 +000077 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000078 UINT len = GetWindowsDirectoryA( NULL, 0 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000079 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
80 len + strlen(filename) + 2 )))
Alexandre Julliard3051b641996-07-05 17:14:13 +000081 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +000082 GetWindowsDirectoryA( buffer, len + 1 );
Alexandre Julliard3051b641996-07-05 17:14:13 +000083 strcat( buffer, "\\" );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000084 strcat( buffer, filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +000085 file = _lopen( buffer, OF_READ );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000086 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000087 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000088 if (file == HFILE_ERROR) return 0;
89 size = _llseek( file, 0, 2 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000090 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000091 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000092 _lclose( file );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000093 return 0;
94 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000095 _llseek( file, 0, 0 );
96 size = _lread( file, buffer, size );
97 _lclose( file );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000098 fileHeader = (BITMAPFILEHEADER *)buffer;
99 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
Vincent BĂ©ron9a624912002-05-31 23:06:46 +0000100
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000101 /* Check header content */
102 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
103 {
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000104 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000105 return 0;
106 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000107 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000108 buffer + fileHeader->bfOffBits,
109 bitmapInfo, DIB_RGB_COLORS );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +0000110 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000111 return hbitmap;
112}
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000113
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000114
Marcus Meissner9aded511999-05-01 10:23:45 +0000115
116/***********************************************************************
117 * DesktopWndProc
Marcus Meissner9aded511999-05-01 10:23:45 +0000118 */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000119static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
Marcus Meissner9aded511999-05-01 10:23:45 +0000120{
Alexandre Julliardb6503722003-04-19 21:27:19 +0000121 /* all messages are ignored */
122 return 0;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000123}
124
Alexandre Julliarda845b881998-06-01 10:44:35 +0000125/***********************************************************************
Patrik Stridvall0c610282001-01-25 22:22:21 +0000126 * PaintDesktop (USER32.@)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000127 *
128 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000129BOOL WINAPI PaintDesktop(HDC hdc)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000130{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000131 HWND hwnd = GetDesktopWindow();
Alexandre Julliarda845b881998-06-01 10:44:35 +0000132
Alexandre Julliardde424282001-08-10 22:51:42 +0000133 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
134 if (GetWindowThreadProcessId( hwnd, NULL ))
Alexandre Julliard43230042001-05-16 19:52:29 +0000135 {
136 RECT rect;
137
138 GetClientRect( hwnd, &rect );
139
140 /* Paint desktop pattern (only if wall paper does not cover everything) */
141
Alexandre Julliardde424282001-08-10 22:51:42 +0000142 if (!hbitmapWallPaper ||
143 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
Alexandre Julliard43230042001-05-16 19:52:29 +0000144 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000145 HBRUSH brush = hbrushPattern;
Michael Stefaniucec5612e2002-10-30 23:45:38 +0000146 if (!brush) brush = (HBRUSH)GetClassLongA( hwnd, GCL_HBRBACKGROUND );
Alexandre Julliard43230042001-05-16 19:52:29 +0000147 /* 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 );
151 }
152
153 /* Paint wall paper */
154
Alexandre Julliardde424282001-08-10 22:51:42 +0000155 if (hbitmapWallPaper)
Alexandre Julliard43230042001-05-16 19:52:29 +0000156 {
157 INT x, y;
158 HDC hMemDC = CreateCompatibleDC( hdc );
159
Alexandre Julliardde424282001-08-10 22:51:42 +0000160 SelectObject( hMemDC, hbitmapWallPaper );
Alexandre Julliard43230042001-05-16 19:52:29 +0000161
Alexandre Julliardde424282001-08-10 22:51:42 +0000162 if (fTileWallPaper)
Alexandre Julliard43230042001-05-16 19:52:29 +0000163 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000164 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 );
Alexandre Julliard43230042001-05-16 19:52:29 +0000167 }
168 else
169 {
Alexandre Julliardde424282001-08-10 22:51:42 +0000170 x = (rect.left + rect.right - bitmapSize.cx) / 2;
171 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
Alexandre Julliard43230042001-05-16 19:52:29 +0000172 if (x < 0) x = 0;
173 if (y < 0) y = 0;
Alexandre Julliardde424282001-08-10 22:51:42 +0000174 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
Alexandre Julliard43230042001-05-16 19:52:29 +0000175 }
176 DeleteDC( hMemDC );
177 }
178 }
Alexandre Julliard43230042001-05-16 19:52:29 +0000179 return TRUE;
Alexandre Julliarda845b881998-06-01 10:44:35 +0000180}
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000181
182/***********************************************************************
Patrik Stridvall15a3b742001-04-27 18:03:51 +0000183 * OldSetDeskPattern (USER.279)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000184 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000185BOOL16 WINAPI SetDeskPattern(void)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000186{
Alexandre Julliardb6503722003-04-19 21:27:19 +0000187 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000188}
189
190
191/***********************************************************************
Patrik Stridvall15a3b742001-04-27 18:03:51 +0000192 * SetDeskWallPaper (USER.285)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000193 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000194BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000195{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000196 return SetDeskWallPaper( filename );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000197}
198
199
200/***********************************************************************
Patrik Stridvall0c610282001-01-25 22:22:21 +0000201 * SetDeskWallPaper (USER32.@)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000202 *
203 * FIXME: is there a unicode version?
204 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000205BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000206{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000207 HBITMAP hbitmap;
208 HDC hdc;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000209 char buffer[256];
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000210
211 if (filename == (LPSTR)-1)
212 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000213 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000214 filename = buffer;
215 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000216 hdc = GetDC( 0 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000217 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000218 ReleaseDC( 0, hdc );
Alexandre Julliardde424282001-08-10 22:51:42 +0000219 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
220 hbitmapWallPaper = hbitmap;
221 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000222 if (hbitmap)
223 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000224 BITMAP bmp;
225 GetObjectA( hbitmap, sizeof(bmp), &bmp );
Alexandre Julliardde424282001-08-10 22:51:42 +0000226 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
227 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000228 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000229 return TRUE;
230}
231
232
233/***********************************************************************
234 * DESKTOP_SetPattern
235 *
236 * Set the desktop pattern.
237 */
Justin Chevrier0a25dd42004-03-04 01:41:11 +0000238BOOL DESKTOP_SetPattern( LPCWSTR pattern )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000239{
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000240 int pat[8];
241
Alexandre Julliardde424282001-08-10 22:51:42 +0000242 if (hbrushPattern) DeleteObject( hbrushPattern );
Justin Chevrier0a25dd42004-03-04 01:41:11 +0000243 hbrushPattern = 0;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000244 memset( pat, 0, sizeof(pat) );
Justin Chevrier0a25dd42004-03-04 01:41:11 +0000245 if (pattern)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000246 {
Justin Chevrier0a25dd42004-03-04 01:41:11 +0000247 char buffer[64];
248 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
249 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
250 &pat[0], &pat[1], &pat[2], &pat[3],
251 &pat[4], &pat[5], &pat[6], &pat[7] ))
252 {
253 WORD pattern[8];
254 HBITMAP hbitmap;
255 int i;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000256
Justin Chevrier0a25dd42004-03-04 01:41:11 +0000257 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
258 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
259 hbrushPattern = CreatePatternBrush( hbitmap );
260 DeleteObject( hbitmap );
261 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000262 }
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000263 return TRUE;
264}