blob: 01e1706cacfe3d7d32a4cc72a14ea9c59dbc1cfe [file] [log] [blame]
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001/*
2 * Desktop window class.
3 *
4 * Copyright 1994 Alexandre Julliard
Alexandre Julliard0c126c71996-02-18 18:44:41 +00005 */
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00006
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00007#include <stdio.h>
8#include <string.h>
Alexandre Julliardaca05781994-10-17 18:12:41 +00009#include <unistd.h>
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000010
Marcus Meissner317af321999-02-17 13:51:06 +000011#include "windef.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000012#include "wingdi.h"
Alexandre Julliard3051b641996-07-05 17:14:13 +000013#include "heap.h"
Alexandre Julliard7f3418f2000-03-25 17:30:13 +000014#include "user.h"
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000015#include "win.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000016#include "controls.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000017#include "wine/winuser16.h"
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000018
Alexandre Julliard91222da2000-12-10 23:01:33 +000019typedef struct
20{
21 HBRUSH hbrushPattern;
22 HBITMAP hbitmapWallPaper;
23 SIZE bitmapSize;
24 BOOL fTileWallPaper;
25} DESKTOP;
26
27static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
28
29
30/*********************************************************************
31 * desktop class descriptor
32 */
33const struct builtin_class_descr DESKTOP_builtin_class =
34{
35 DESKTOP_CLASS_ATOM, /* name */
36 CS_GLOBALCLASS, /* style */
37 NULL, /* procA (winproc is Unicode only) */
38 DesktopWndProc, /* procW */
39 sizeof(DESKTOP), /* extra */
40 IDC_ARROWA, /* cursor */
41 COLOR_BACKGROUND+1 /* brush */
42};
43
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000044
45/***********************************************************************
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000046 * DESKTOP_LoadBitmap
47 *
48 * Load a bitmap from a file. Used by SetDeskWallPaper().
49 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000050static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000051{
52 BITMAPFILEHEADER *fileHeader;
53 BITMAPINFO *bitmapInfo;
Alexandre Julliarda3960291999-02-26 11:11:13 +000054 HBITMAP hbitmap;
55 HFILE file;
Alexandre Julliard3051b641996-07-05 17:14:13 +000056 LPSTR buffer;
57 LONG size;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000058
Alexandre Julliard3051b641996-07-05 17:14:13 +000059 /* Read all the file into memory */
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000060
Alexandre Julliarda3960291999-02-26 11:11:13 +000061 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
Alexandre Julliard0c126c71996-02-18 18:44:41 +000062 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000063 UINT len = GetWindowsDirectoryA( NULL, 0 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000064 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
65 len + strlen(filename) + 2 )))
Alexandre Julliard3051b641996-07-05 17:14:13 +000066 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +000067 GetWindowsDirectoryA( buffer, len + 1 );
Alexandre Julliard3051b641996-07-05 17:14:13 +000068 strcat( buffer, "\\" );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000069 strcat( buffer, filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +000070 file = _lopen( buffer, OF_READ );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000071 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000072 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000073 if (file == HFILE_ERROR) return 0;
74 size = _llseek( file, 0, 2 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000075 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000076 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000077 _lclose( file );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000078 return 0;
79 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000080 _llseek( file, 0, 0 );
81 size = _lread( file, buffer, size );
82 _lclose( file );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000083 fileHeader = (BITMAPFILEHEADER *)buffer;
84 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
85
86 /* Check header content */
87 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
88 {
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000089 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000090 return 0;
91 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000092 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000093 buffer + fileHeader->bfOffBits,
94 bitmapInfo, DIB_RGB_COLORS );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000095 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000096 return hbitmap;
97}
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000098
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000099
Marcus Meissner9aded511999-05-01 10:23:45 +0000100
101/***********************************************************************
102 * DesktopWndProc
Marcus Meissner9aded511999-05-01 10:23:45 +0000103 */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000104static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
Marcus Meissner9aded511999-05-01 10:23:45 +0000105{
Alexandre Julliard43230042001-05-16 19:52:29 +0000106 LRESULT retvalue = 0;
Marcus Meissner9aded511999-05-01 10:23:45 +0000107 WND *wndPtr = WIN_FindWndPtr( hwnd );
Alexandre Julliard43230042001-05-16 19:52:29 +0000108 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
109
110 if (message == WM_NCCREATE)
111 {
112 desktopPtr->hbrushPattern = 0;
113 desktopPtr->hbitmapWallPaper = 0;
114 SetDeskPattern();
115 SetDeskWallPaper( (LPSTR)-1 );
116 retvalue = 1;
117 }
118 /* all other messages are ignored */
Marcus Meissner9aded511999-05-01 10:23:45 +0000119
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000120 WIN_ReleaseWndPtr(wndPtr);
121 return retvalue;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000122}
123
Alexandre Julliarda845b881998-06-01 10:44:35 +0000124/***********************************************************************
Patrik Stridvall0c610282001-01-25 22:22:21 +0000125 * PaintDesktop (USER32.@)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000126 *
127 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000128BOOL WINAPI PaintDesktop(HDC hdc)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000129{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000130 HWND hwnd = GetDesktopWindow();
Alexandre Julliarda845b881998-06-01 10:44:35 +0000131 WND *wndPtr = WIN_FindWndPtr( hwnd );
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000132 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Alexandre Julliarda845b881998-06-01 10:44:35 +0000133
Alexandre Julliard43230042001-05-16 19:52:29 +0000134 /* check for a queue; otherwise don't paint anything (non-desktop mode) */
135 if (wndPtr->hmemTaskQ)
136 {
137 RECT rect;
138
139 GetClientRect( hwnd, &rect );
140
141 /* Paint desktop pattern (only if wall paper does not cover everything) */
142
143 if (!desktopPtr->hbitmapWallPaper ||
144 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
145 (desktopPtr->bitmapSize.cy < rect.bottom))))
146 {
147 HBRUSH brush = desktopPtr->hbrushPattern;
148 if (!brush) brush = GetClassLongA( hwnd, GCL_HBRBACKGROUND );
149 /* Set colors in case pattern is a monochrome bitmap */
150 SetBkColor( hdc, RGB(0,0,0) );
151 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
152 FillRect( hdc, &rect, brush );
153 }
154
155 /* Paint wall paper */
156
157 if (desktopPtr->hbitmapWallPaper)
158 {
159 INT x, y;
160 HDC hMemDC = CreateCompatibleDC( hdc );
161
162 SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
163
164 if (desktopPtr->fTileWallPaper)
165 {
166 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
167 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
168 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
169 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
170 }
171 else
172 {
173 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
174 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
175 if (x < 0) x = 0;
176 if (y < 0) y = 0;
177 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
178 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
179 }
180 DeleteDC( hMemDC );
181 }
182 }
183 WIN_ReleaseWndPtr(wndPtr);
184 return TRUE;
Alexandre Julliarda845b881998-06-01 10:44:35 +0000185}
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000186
187/***********************************************************************
Patrik Stridvall15a3b742001-04-27 18:03:51 +0000188 * OldSetDeskPattern (USER.279)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000189 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000190BOOL16 WINAPI SetDeskPattern(void)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000191{
192 char buffer[100];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000193 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000194 return DESKTOP_SetPattern( buffer );
195}
196
197
198/***********************************************************************
Patrik Stridvall15a3b742001-04-27 18:03:51 +0000199 * SetDeskWallPaper (USER.285)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000200 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000201BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000202{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000203 return SetDeskWallPaper( filename );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000204}
205
206
207/***********************************************************************
Patrik Stridvall0c610282001-01-25 22:22:21 +0000208 * SetDeskWallPaper (USER32.@)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000209 *
210 * FIXME: is there a unicode version?
211 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000212BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000213{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000214 HBITMAP hbitmap;
215 HDC hdc;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000216 char buffer[256];
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000217 WND *wndPtr = WIN_GetDesktop();
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000218 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000219
220 if (filename == (LPSTR)-1)
221 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000222 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000223 filename = buffer;
224 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000225 hdc = GetDC( 0 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000226 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000227 ReleaseDC( 0, hdc );
228 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000229 desktopPtr->hbitmapWallPaper = hbitmap;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000230 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000231 if (hbitmap)
232 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000233 BITMAP bmp;
234 GetObjectA( hbitmap, sizeof(bmp), &bmp );
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000235 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
236 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000237 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000238 WIN_ReleaseDesktop();
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000239 return TRUE;
240}
241
242
243/***********************************************************************
244 * DESKTOP_SetPattern
245 *
246 * Set the desktop pattern.
247 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000248BOOL DESKTOP_SetPattern( LPCSTR pattern )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000249{
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000250 WND *wndPtr = WIN_GetDesktop();
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000251 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000252 int pat[8];
253
Alexandre Julliarda3960291999-02-26 11:11:13 +0000254 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000255 memset( pat, 0, sizeof(pat) );
256 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
257 &pat[0], &pat[1], &pat[2], &pat[3],
258 &pat[4], &pat[5], &pat[6], &pat[7] ))
259 {
260 WORD pattern[8];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000261 HBITMAP hbitmap;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000262 int i;
263
264 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000265 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
266 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
267 DeleteObject( hbitmap );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000268 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000269 else desktopPtr->hbrushPattern = 0;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000270 WIN_ReleaseDesktop();
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000271 return TRUE;
272}
273