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()
27 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
28 return MONITOR_IsSingleWindow(pDesktop->pPrimaryMonitor);
31 /***********************************************************************
32 * DESKTOP_GetScreenWidth
34 * Return the width of the screen associated to the current desktop.
36 int DESKTOP_GetScreenWidth()
39 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
40 retvalue = MONITOR_GetWidth(pDesktop->pPrimaryMonitor);
46 /***********************************************************************
47 * DESKTOP_GetScreenHeight
49 * Return the height of the screen associated to the current desktop.
51 int DESKTOP_GetScreenHeight()
54 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
55 retvalue = MONITOR_GetHeight(pDesktop->pPrimaryMonitor);
61 /***********************************************************************
62 * DESKTOP_GetScreenDepth
64 * Return the depth of the screen associated to the current desktop.
66 int DESKTOP_GetScreenDepth()
69 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
70 retvalue = MONITOR_GetDepth(pDesktop->pPrimaryMonitor);
76 /***********************************************************************
79 * Load a bitmap from a file. Used by SetDeskWallPaper().
81 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
83 BITMAPFILEHEADER *fileHeader;
84 BITMAPINFO *bitmapInfo;
90 /* Read all the file into memory */
92 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
94 UINT len = GetWindowsDirectoryA( NULL, 0 );
95 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
96 len + strlen(filename) + 2 )))
98 GetWindowsDirectoryA( buffer, len + 1 );
99 strcat( buffer, "\\" );
100 strcat( buffer, filename );
101 file = _lopen( buffer, OF_READ );
102 HeapFree( GetProcessHeap(), 0, buffer );
104 if (file == HFILE_ERROR) return 0;
105 size = _llseek( file, 0, 2 );
106 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
111 _llseek( file, 0, 0 );
112 size = _lread( file, buffer, size );
114 fileHeader = (BITMAPFILEHEADER *)buffer;
115 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
117 /* Check header content */
118 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
120 HeapFree( GetProcessHeap(), 0, buffer );
123 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
124 buffer + fileHeader->bfOffBits,
125 bitmapInfo, DIB_RGB_COLORS );
126 HeapFree( GetProcessHeap(), 0, buffer );
131 /***********************************************************************
132 * DESKTOP_DoEraseBkgnd
134 * Handle the WM_ERASEBKGND message.
136 static LRESULT DESKTOP_DoEraseBkgnd( HWND hwnd, HDC hdc,
137 DESKTOP *desktopPtr )
140 WND* Wnd = WIN_FindWndPtr( hwnd );
142 if (Wnd->hrgnUpdate > 1) DeleteObject( Wnd->hrgnUpdate );
145 WIN_ReleaseWndPtr(Wnd);
147 GetClientRect( hwnd, &rect );
149 /* Paint desktop pattern (only if wall paper does not cover everything) */
151 if (!desktopPtr->hbitmapWallPaper ||
152 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
153 (desktopPtr->bitmapSize.cy < rect.bottom))))
155 /* Set colors in case pattern is a monochrome bitmap */
156 SetBkColor( hdc, RGB(0,0,0) );
157 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
158 FillRect( hdc, &rect, desktopPtr->hbrushPattern );
161 /* Paint wall paper */
163 if (desktopPtr->hbitmapWallPaper)
166 HDC hMemDC = CreateCompatibleDC( hdc );
168 SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
170 if (desktopPtr->fTileWallPaper)
172 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
173 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
174 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
175 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
179 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
180 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
183 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
184 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
193 /***********************************************************************
196 * Window procedure for the desktop window.
198 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message,
199 WPARAM wParam, LPARAM lParam )
202 WND *wndPtr = WIN_FindWndPtr( hwnd );
203 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
205 /* Most messages are ignored (we DON'T call DefWindowProc) */
209 /* Warning: this message is sent directly by */
210 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
212 desktopPtr->hbrushPattern = 0;
213 desktopPtr->hbitmapWallPaper = 0;
215 SetDeskWallPaper( (LPSTR)-1 );
220 if(!DESKTOP_IsSingleWindow())
225 retvalue = DESKTOP_DoEraseBkgnd( hwnd, (HDC)wParam, desktopPtr );
229 if ((wParam & 0xfff0) != SC_CLOSE)
234 ExitWindows16( 0, 0 );
237 retvalue = (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
243 WIN_ReleaseWndPtr(wndPtr);
247 /***********************************************************************
248 * PaintDesktop (USER32.415)
251 BOOL WINAPI PaintDesktop(HDC hdc)
254 HWND hwnd = GetDesktopWindow();
255 WND *wndPtr = WIN_FindWndPtr( hwnd );
256 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
257 retvalue = DESKTOP_DoEraseBkgnd( hwnd, hdc, desktopPtr );
258 WIN_ReleaseWndPtr(wndPtr);
263 /***********************************************************************
264 * SetDeskPattern (USER.279)
266 BOOL16 WINAPI SetDeskPattern(void)
269 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
270 return DESKTOP_SetPattern( buffer );
274 /***********************************************************************
275 * SetDeskWallPaper16 (USER.285)
277 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
279 return SetDeskWallPaper( filename );
283 /***********************************************************************
284 * SetDeskWallPaper32 (USER32.475)
286 * FIXME: is there a unicode version?
288 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
293 WND *wndPtr = WIN_GetDesktop();
294 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
296 if (filename == (LPSTR)-1)
298 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
302 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
304 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
305 desktopPtr->hbitmapWallPaper = hbitmap;
306 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
310 GetObjectA( hbitmap, sizeof(bmp), &bmp );
311 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
312 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
314 WIN_ReleaseDesktop();
319 /***********************************************************************
322 * Set the desktop pattern.
324 BOOL DESKTOP_SetPattern( LPCSTR pattern )
326 WND *wndPtr = WIN_GetDesktop();
327 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
330 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
331 memset( pat, 0, sizeof(pat) );
332 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
333 &pat[0], &pat[1], &pat[2], &pat[3],
334 &pat[4], &pat[5], &pat[6], &pat[7] ))
340 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
341 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
342 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
343 DeleteObject( hbitmap );
345 else desktopPtr->hbrushPattern = CreateSolidBrush( GetSysColor(COLOR_BACKGROUND) );
346 WIN_ReleaseDesktop();