blob: 809e78d236de6512dced598659815ce4fea7636b [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
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000011#include "desktop.h"
Marcus Meissner317af321999-02-17 13:51:06 +000012#include "windef.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000013#include "wingdi.h"
Alexandre Julliard3051b641996-07-05 17:14:13 +000014#include "heap.h"
Alexandre Julliard7f3418f2000-03-25 17:30:13 +000015#include "user.h"
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000016#include "win.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000017#include "wine/winuser16.h"
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000018
Patrik Stridvallb87fe2e1999-04-01 08:16:08 +000019
20/***********************************************************************
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000021 * DESKTOP_LoadBitmap
22 *
23 * Load a bitmap from a file. Used by SetDeskWallPaper().
24 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000025static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000026{
27 BITMAPFILEHEADER *fileHeader;
28 BITMAPINFO *bitmapInfo;
Alexandre Julliarda3960291999-02-26 11:11:13 +000029 HBITMAP hbitmap;
30 HFILE file;
Alexandre Julliard3051b641996-07-05 17:14:13 +000031 LPSTR buffer;
32 LONG size;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000033
Alexandre Julliard3051b641996-07-05 17:14:13 +000034 /* Read all the file into memory */
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000035
Alexandre Julliarda3960291999-02-26 11:11:13 +000036 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
Alexandre Julliard0c126c71996-02-18 18:44:41 +000037 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000038 UINT len = GetWindowsDirectoryA( NULL, 0 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000039 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
40 len + strlen(filename) + 2 )))
Alexandre Julliard3051b641996-07-05 17:14:13 +000041 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +000042 GetWindowsDirectoryA( buffer, len + 1 );
Alexandre Julliard3051b641996-07-05 17:14:13 +000043 strcat( buffer, "\\" );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000044 strcat( buffer, filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +000045 file = _lopen( buffer, OF_READ );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000046 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard0c126c71996-02-18 18:44:41 +000047 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000048 if (file == HFILE_ERROR) return 0;
49 size = _llseek( file, 0, 2 );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000050 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000051 {
Alexandre Julliarda3960291999-02-26 11:11:13 +000052 _lclose( file );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000053 return 0;
54 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000055 _llseek( file, 0, 0 );
56 size = _lread( file, buffer, size );
57 _lclose( file );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000058 fileHeader = (BITMAPFILEHEADER *)buffer;
59 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
60
61 /* Check header content */
62 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
63 {
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000064 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000065 return 0;
66 }
Alexandre Julliarda3960291999-02-26 11:11:13 +000067 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000068 buffer + fileHeader->bfOffBits,
69 bitmapInfo, DIB_RGB_COLORS );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +000070 HeapFree( GetProcessHeap(), 0, buffer );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000071 return hbitmap;
72}
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000073
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000074
75/***********************************************************************
76 * DESKTOP_DoEraseBkgnd
77 *
78 * Handle the WM_ERASEBKGND message.
79 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000080static LRESULT DESKTOP_DoEraseBkgnd( HWND hwnd, HDC hdc,
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000081 DESKTOP *desktopPtr )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000082{
Alexandre Julliarda3960291999-02-26 11:11:13 +000083 RECT rect;
Alexandre Julliard1e37a181996-08-18 16:21:52 +000084 WND* Wnd = WIN_FindWndPtr( hwnd );
85
Alexandre Julliarda3960291999-02-26 11:11:13 +000086 if (Wnd->hrgnUpdate > 1) DeleteObject( Wnd->hrgnUpdate );
Alexandre Julliard1e37a181996-08-18 16:21:52 +000087 Wnd->hrgnUpdate = 0;
88
Francois Boisvert6b1b41c1999-03-14 17:25:32 +000089 WIN_ReleaseWndPtr(Wnd);
90
Alexandre Julliarda3960291999-02-26 11:11:13 +000091 GetClientRect( hwnd, &rect );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000092
93 /* Paint desktop pattern (only if wall paper does not cover everything) */
94
Patrik Stridvall8d8703c1999-02-04 14:05:38 +000095 if (!desktopPtr->hbitmapWallPaper ||
96 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
97 (desktopPtr->bitmapSize.cy < rect.bottom))))
Alexandre Julliard2d159fb1994-07-15 16:04:31 +000098 {
99 /* Set colors in case pattern is a monochrome bitmap */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000100 SetBkColor( hdc, RGB(0,0,0) );
101 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
102 FillRect( hdc, &rect, desktopPtr->hbrushPattern );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000103 }
104
105 /* Paint wall paper */
106
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000107 if (desktopPtr->hbitmapWallPaper)
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000108 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000109 INT x, y;
110 HDC hMemDC = CreateCompatibleDC( hdc );
Huw D M Davies2d617be1998-12-08 09:14:09 +0000111
Alexandre Julliarda3960291999-02-26 11:11:13 +0000112 SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000113
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000114 if (desktopPtr->fTileWallPaper)
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000115 {
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000116 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
117 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000118 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000119 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000120 }
121 else
122 {
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000123 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
124 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000125 if (x < 0) x = 0;
126 if (y < 0) y = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000127 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000128 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000129 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000130 DeleteDC( hMemDC );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000131 }
132
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000133 return 1;
134}
135
136
137/***********************************************************************
Marcus Meissner9aded511999-05-01 10:23:45 +0000138 * DesktopWndProc_locked
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000139 *
140 * Window procedure for the desktop window.
141 */
Marcus Meissner9aded511999-05-01 10:23:45 +0000142static inline LRESULT WINAPI DesktopWndProc_locked( WND *wndPtr, UINT message,
Alexandre Julliarda3960291999-02-26 11:11:13 +0000143 WPARAM wParam, LPARAM lParam )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000144{
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000145 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Marcus Meissner9aded511999-05-01 10:23:45 +0000146 HWND hwnd = wndPtr->hwndSelf;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000147
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000148 /* Most messages are ignored (we DON'T call DefWindowProc) */
149
150 switch(message)
151 {
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000152 /* Warning: this message is sent directly by */
153 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
154 case WM_NCCREATE:
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000155 desktopPtr->hbrushPattern = 0;
156 desktopPtr->hbitmapWallPaper = 0;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000157 SetDeskPattern();
Alexandre Julliarda3960291999-02-26 11:11:13 +0000158 SetDeskWallPaper( (LPSTR)-1 );
Marcus Meissner9aded511999-05-01 10:23:45 +0000159 return 1;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000160
161 case WM_ERASEBKGND:
Alexandre Julliard7f3418f2000-03-25 17:30:13 +0000162 if(!USER_Driver->pIsSingleWindow())
Marcus Meissner9aded511999-05-01 10:23:45 +0000163 return 1;
164 return DESKTOP_DoEraseBkgnd( hwnd, (HDC)wParam, desktopPtr );
Alexandre Julliard02ed4c21996-03-02 19:34:10 +0000165
166 case WM_SYSCOMMAND:
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000167 if ((wParam & 0xfff0) != SC_CLOSE)
Marcus Meissner9aded511999-05-01 10:23:45 +0000168 return 0;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000169 ExitWindows16( 0, 0 );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000170
171 case WM_SETCURSOR:
Marcus Meissner9aded511999-05-01 10:23:45 +0000172 return (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000173 }
174
Marcus Meissner9aded511999-05-01 10:23:45 +0000175 return 0;
176}
177
178/***********************************************************************
179 * DesktopWndProc
180 *
181 * This is just a wrapper for the DesktopWndProc which does windows
182 * locking and unlocking.
183 */
184LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message,
185 WPARAM wParam, LPARAM lParam )
186{
187 WND *wndPtr = WIN_FindWndPtr( hwnd );
188 LRESULT retvalue = DesktopWndProc_locked(wndPtr,message,wParam,lParam);
189
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000190 WIN_ReleaseWndPtr(wndPtr);
191 return retvalue;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000192}
193
Alexandre Julliarda845b881998-06-01 10:44:35 +0000194/***********************************************************************
195 * PaintDesktop (USER32.415)
196 *
197 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000198BOOL WINAPI PaintDesktop(HDC hdc)
Alexandre Julliarda845b881998-06-01 10:44:35 +0000199{
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000200 BOOL retvalue;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000201 HWND hwnd = GetDesktopWindow();
Alexandre Julliarda845b881998-06-01 10:44:35 +0000202 WND *wndPtr = WIN_FindWndPtr( hwnd );
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000203 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000204 retvalue = DESKTOP_DoEraseBkgnd( hwnd, hdc, desktopPtr );
205 WIN_ReleaseWndPtr(wndPtr);
206 return retvalue;
Alexandre Julliarda845b881998-06-01 10:44:35 +0000207
Alexandre Julliarda845b881998-06-01 10:44:35 +0000208}
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000209
210/***********************************************************************
211 * SetDeskPattern (USER.279)
212 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000213BOOL16 WINAPI SetDeskPattern(void)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000214{
215 char buffer[100];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000216 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000217 return DESKTOP_SetPattern( buffer );
218}
219
220
221/***********************************************************************
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000222 * SetDeskWallPaper16 (USER.285)
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000223 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000224BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000225{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000226 return SetDeskWallPaper( filename );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000227}
228
229
230/***********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000231 * SetDeskWallPaper (USER32.475)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000232 *
233 * FIXME: is there a unicode version?
234 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000235BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000236{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000237 HBITMAP hbitmap;
238 HDC hdc;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000239 char buffer[256];
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000240 WND *wndPtr = WIN_GetDesktop();
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000241 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000242
243 if (filename == (LPSTR)-1)
244 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000245 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000246 filename = buffer;
247 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000248 hdc = GetDC( 0 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000249 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000250 ReleaseDC( 0, hdc );
251 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000252 desktopPtr->hbitmapWallPaper = hbitmap;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000253 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000254 if (hbitmap)
255 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000256 BITMAP bmp;
257 GetObjectA( hbitmap, sizeof(bmp), &bmp );
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000258 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
259 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
Alexandre Julliard2d159fb1994-07-15 16:04:31 +0000260 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000261 WIN_ReleaseDesktop();
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000262 return TRUE;
263}
264
265
266/***********************************************************************
267 * DESKTOP_SetPattern
268 *
269 * Set the desktop pattern.
270 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000271BOOL DESKTOP_SetPattern( LPCSTR pattern )
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000272{
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000273 WND *wndPtr = WIN_GetDesktop();
Patrik Stridvall8d8703c1999-02-04 14:05:38 +0000274 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000275 int pat[8];
276
Alexandre Julliarda3960291999-02-26 11:11:13 +0000277 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000278 memset( pat, 0, sizeof(pat) );
279 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
280 &pat[0], &pat[1], &pat[2], &pat[3],
281 &pat[4], &pat[5], &pat[6], &pat[7] ))
282 {
283 WORD pattern[8];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000284 HBITMAP hbitmap;
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000285 int i;
286
287 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000288 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
289 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
290 DeleteObject( hbitmap );
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000291 }
Alexandre Julliarda3960291999-02-26 11:11:13 +0000292 else desktopPtr->hbrushPattern = CreateSolidBrush( GetSysColor(COLOR_BACKGROUND) );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000293 WIN_ReleaseDesktop();
Alexandre Julliard8d24ae61994-04-05 21:42:43 +0000294 return TRUE;
295}
296