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(void)
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 /***********************************************************************
197 * DesktopWndProc_locked
199 * Window procedure for the desktop window.
201 static inline LRESULT WINAPI DesktopWndProc_locked( WND *wndPtr, UINT message,
202 WPARAM wParam, LPARAM lParam )
204 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
205 HWND hwnd = wndPtr->hwndSelf;
207 /* Most messages are ignored (we DON'T call DefWindowProc) */
211 /* Warning: this message is sent directly by */
212 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
214 desktopPtr->hbrushPattern = 0;
215 desktopPtr->hbitmapWallPaper = 0;
217 SetDeskWallPaper( (LPSTR)-1 );
221 if(!DESKTOP_IsSingleWindow())
223 return DESKTOP_DoEraseBkgnd( hwnd, (HDC)wParam, desktopPtr );
226 if ((wParam & 0xfff0) != SC_CLOSE)
228 ExitWindows16( 0, 0 );
231 return (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
237 /***********************************************************************
240 * This is just a wrapper for the DesktopWndProc which does windows
241 * locking and unlocking.
243 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message,
244 WPARAM wParam, LPARAM lParam )
246 WND *wndPtr = WIN_FindWndPtr( hwnd );
247 LRESULT retvalue = DesktopWndProc_locked(wndPtr,message,wParam,lParam);
249 WIN_ReleaseWndPtr(wndPtr);
253 /***********************************************************************
254 * PaintDesktop (USER32.415)
257 BOOL WINAPI PaintDesktop(HDC hdc)
260 HWND hwnd = GetDesktopWindow();
261 WND *wndPtr = WIN_FindWndPtr( hwnd );
262 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
263 retvalue = DESKTOP_DoEraseBkgnd( hwnd, hdc, desktopPtr );
264 WIN_ReleaseWndPtr(wndPtr);
269 /***********************************************************************
270 * SetDeskPattern (USER.279)
272 BOOL16 WINAPI SetDeskPattern(void)
275 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
276 return DESKTOP_SetPattern( buffer );
280 /***********************************************************************
281 * SetDeskWallPaper16 (USER.285)
283 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
285 return SetDeskWallPaper( filename );
289 /***********************************************************************
290 * SetDeskWallPaper32 (USER32.475)
292 * FIXME: is there a unicode version?
294 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
299 WND *wndPtr = WIN_GetDesktop();
300 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
302 if (filename == (LPSTR)-1)
304 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
308 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
310 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
311 desktopPtr->hbitmapWallPaper = hbitmap;
312 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
316 GetObjectA( hbitmap, sizeof(bmp), &bmp );
317 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
318 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
320 WIN_ReleaseDesktop();
325 /***********************************************************************
328 * Set the desktop pattern.
330 BOOL DESKTOP_SetPattern( LPCSTR pattern )
332 WND *wndPtr = WIN_GetDesktop();
333 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
336 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
337 memset( pat, 0, sizeof(pat) );
338 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
339 &pat[0], &pat[1], &pat[2], &pat[3],
340 &pat[4], &pat[5], &pat[6], &pat[7] ))
346 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
347 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
348 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
349 DeleteObject( hbitmap );
351 else desktopPtr->hbrushPattern = CreateSolidBrush( GetSysColor(COLOR_BACKGROUND) );
352 WIN_ReleaseDesktop();