2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
16 #include "wine/winuser16.h"
18 /**********************************************************************/
20 DESKTOP_DRIVER *DESKTOP_Driver = NULL;
22 /***********************************************************************
23 * DESKTOP_IsSingleWindow
25 BOOL DESKTOP_IsSingleWindow()
28 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
29 retvalue = MONITOR_IsSingleWindow(pDesktop->pPrimaryMonitor);
34 /***********************************************************************
35 * DESKTOP_GetScreenWidth
37 * Return the width of the screen associated to the current desktop.
39 int DESKTOP_GetScreenWidth()
42 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
43 retvalue = MONITOR_GetWidth(pDesktop->pPrimaryMonitor);
49 /***********************************************************************
50 * DESKTOP_GetScreenHeight
52 * Return the height of the screen associated to the current desktop.
54 int DESKTOP_GetScreenHeight()
57 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
58 retvalue = MONITOR_GetHeight(pDesktop->pPrimaryMonitor);
64 /***********************************************************************
65 * DESKTOP_GetScreenDepth
67 * Return the depth of the screen associated to the current desktop.
69 int DESKTOP_GetScreenDepth()
72 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
73 retvalue = MONITOR_GetDepth(pDesktop->pPrimaryMonitor);
79 /***********************************************************************
82 * Load a bitmap from a file. Used by SetDeskWallPaper().
84 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
86 BITMAPFILEHEADER *fileHeader;
87 BITMAPINFO *bitmapInfo;
93 /* Read all the file into memory */
95 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
97 UINT len = GetWindowsDirectoryA( NULL, 0 );
98 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
99 len + strlen(filename) + 2 )))
101 GetWindowsDirectoryA( buffer, len + 1 );
102 strcat( buffer, "\\" );
103 strcat( buffer, filename );
104 file = _lopen( buffer, OF_READ );
105 HeapFree( GetProcessHeap(), 0, buffer );
107 if (file == HFILE_ERROR) return 0;
108 size = _llseek( file, 0, 2 );
109 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
114 _llseek( file, 0, 0 );
115 size = _lread( file, buffer, size );
117 fileHeader = (BITMAPFILEHEADER *)buffer;
118 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
120 /* Check header content */
121 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
123 HeapFree( GetProcessHeap(), 0, buffer );
126 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
127 buffer + fileHeader->bfOffBits,
128 bitmapInfo, DIB_RGB_COLORS );
129 HeapFree( GetProcessHeap(), 0, buffer );
134 /***********************************************************************
135 * DESKTOP_DoEraseBkgnd
137 * Handle the WM_ERASEBKGND message.
139 static LRESULT DESKTOP_DoEraseBkgnd( HWND hwnd, HDC hdc,
140 DESKTOP *desktopPtr )
143 WND* Wnd = WIN_FindWndPtr( hwnd );
145 if (Wnd->hrgnUpdate > 1) DeleteObject( Wnd->hrgnUpdate );
148 WIN_ReleaseWndPtr(Wnd);
150 GetClientRect( hwnd, &rect );
152 /* Paint desktop pattern (only if wall paper does not cover everything) */
154 if (!desktopPtr->hbitmapWallPaper ||
155 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
156 (desktopPtr->bitmapSize.cy < rect.bottom))))
158 /* Set colors in case pattern is a monochrome bitmap */
159 SetBkColor( hdc, RGB(0,0,0) );
160 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
161 FillRect( hdc, &rect, desktopPtr->hbrushPattern );
164 /* Paint wall paper */
166 if (desktopPtr->hbitmapWallPaper)
169 HDC hMemDC = CreateCompatibleDC( hdc );
171 SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
173 if (desktopPtr->fTileWallPaper)
175 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
176 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
177 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
178 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
182 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
183 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
186 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
187 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
196 /***********************************************************************
199 * Window procedure for the desktop window.
201 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message,
202 WPARAM wParam, LPARAM lParam )
205 WND *wndPtr = WIN_FindWndPtr( hwnd );
206 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
208 /* Most messages are ignored (we DON'T call DefWindowProc) */
212 /* Warning: this message is sent directly by */
213 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
215 desktopPtr->hbrushPattern = 0;
216 desktopPtr->hbitmapWallPaper = 0;
218 SetDeskWallPaper( (LPSTR)-1 );
223 if(!DESKTOP_IsSingleWindow())
228 retvalue = DESKTOP_DoEraseBkgnd( hwnd, (HDC)wParam, desktopPtr );
232 if ((wParam & 0xfff0) != SC_CLOSE)
237 ExitWindows16( 0, 0 );
240 retvalue = (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
246 WIN_ReleaseWndPtr(wndPtr);
250 /***********************************************************************
251 * PaintDesktop (USER32.415)
254 BOOL WINAPI PaintDesktop(HDC hdc)
257 HWND hwnd = GetDesktopWindow();
258 WND *wndPtr = WIN_FindWndPtr( hwnd );
259 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
260 retvalue = DESKTOP_DoEraseBkgnd( hwnd, hdc, desktopPtr );
261 WIN_ReleaseWndPtr(wndPtr);
266 /***********************************************************************
267 * SetDeskPattern (USER.279)
269 BOOL16 WINAPI SetDeskPattern(void)
272 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
273 return DESKTOP_SetPattern( buffer );
277 /***********************************************************************
278 * SetDeskWallPaper16 (USER.285)
280 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
282 return SetDeskWallPaper( filename );
286 /***********************************************************************
287 * SetDeskWallPaper32 (USER32.475)
289 * FIXME: is there a unicode version?
291 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
296 WND *wndPtr = WIN_GetDesktop();
297 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
299 if (filename == (LPSTR)-1)
301 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
305 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
307 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
308 desktopPtr->hbitmapWallPaper = hbitmap;
309 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
313 GetObjectA( hbitmap, sizeof(bmp), &bmp );
314 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
315 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
317 WIN_ReleaseDesktop();
322 /***********************************************************************
325 * Set the desktop pattern.
327 BOOL DESKTOP_SetPattern( LPCSTR pattern )
329 WND *wndPtr = WIN_GetDesktop();
330 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
333 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
334 memset( pat, 0, sizeof(pat) );
335 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
336 &pat[0], &pat[1], &pat[2], &pat[3],
337 &pat[4], &pat[5], &pat[6], &pat[7] ))
343 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
344 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
345 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
346 DeleteObject( hbitmap );
348 else desktopPtr->hbrushPattern = CreateSolidBrush( GetSysColor(COLOR_BACKGROUND) );
349 WIN_ReleaseDesktop();