2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
18 #include "wine/winuser16.h"
20 /***********************************************************************
21 * DESKTOP_GetScreenWidth
23 * Return the width of the screen associated to the current desktop.
25 int DESKTOP_GetScreenWidth()
27 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
28 return MONITOR_GetWidth(pDesktop->pPrimaryMonitor);
31 /***********************************************************************
32 * DESKTOP_GetScreenHeight
34 * Return the height of the screen associated to the current desktop.
36 int DESKTOP_GetScreenHeight()
38 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
39 return MONITOR_GetHeight(pDesktop->pPrimaryMonitor);
42 /***********************************************************************
43 * DESKTOP_GetScreenDepth
45 * Return the depth of the screen associated to the current desktop.
47 int DESKTOP_GetScreenDepth()
49 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
50 return MONITOR_GetDepth(pDesktop->pPrimaryMonitor);
53 /***********************************************************************
56 * Load a bitmap from a file. Used by SetDeskWallPaper().
58 static HBITMAP32 DESKTOP_LoadBitmap( HDC32 hdc, const char *filename )
60 BITMAPFILEHEADER *fileHeader;
61 BITMAPINFO *bitmapInfo;
67 /* Read all the file into memory */
69 if ((file = _lopen32( filename, OF_READ )) == HFILE_ERROR32)
71 UINT32 len = GetWindowsDirectory32A( NULL, 0 );
72 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
73 len + strlen(filename) + 2 )))
75 GetWindowsDirectory32A( buffer, len + 1 );
76 strcat( buffer, "\\" );
77 strcat( buffer, filename );
78 file = _lopen32( buffer, OF_READ );
79 HeapFree( GetProcessHeap(), 0, buffer );
81 if (file == HFILE_ERROR32) return 0;
82 size = _llseek32( file, 0, 2 );
83 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
88 _llseek32( file, 0, 0 );
89 size = _lread32( file, buffer, size );
91 fileHeader = (BITMAPFILEHEADER *)buffer;
92 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
94 /* Check header content */
95 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
97 HeapFree( GetProcessHeap(), 0, buffer );
100 hbitmap = CreateDIBitmap32( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
101 buffer + fileHeader->bfOffBits,
102 bitmapInfo, DIB_RGB_COLORS );
103 HeapFree( GetProcessHeap(), 0, buffer );
108 /***********************************************************************
109 * DESKTOP_DoEraseBkgnd
111 * Handle the WM_ERASEBKGND message.
113 static LRESULT DESKTOP_DoEraseBkgnd( HWND32 hwnd, HDC32 hdc,
114 DESKTOP *desktopPtr )
117 WND* Wnd = WIN_FindWndPtr( hwnd );
119 if (Wnd->hrgnUpdate > 1) DeleteObject32( Wnd->hrgnUpdate );
122 GetClientRect32( hwnd, &rect );
124 /* Paint desktop pattern (only if wall paper does not cover everything) */
126 if (!desktopPtr->hbitmapWallPaper ||
127 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
128 (desktopPtr->bitmapSize.cy < rect.bottom))))
130 /* Set colors in case pattern is a monochrome bitmap */
131 SetBkColor32( hdc, RGB(0,0,0) );
132 SetTextColor32( hdc, GetSysColor32(COLOR_BACKGROUND) );
133 FillRect32( hdc, &rect, desktopPtr->hbrushPattern );
136 /* Paint wall paper */
138 if (desktopPtr->hbitmapWallPaper)
141 HDC32 hMemDC = CreateCompatibleDC32( hdc );
143 SelectObject32( hMemDC, desktopPtr->hbitmapWallPaper );
145 if (desktopPtr->fTileWallPaper)
147 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
148 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
149 BitBlt32( hdc, x, y, desktopPtr->bitmapSize.cx,
150 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
154 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
155 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
158 BitBlt32( hdc, x, y, desktopPtr->bitmapSize.cx,
159 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
161 DeleteDC32( hMemDC );
168 /***********************************************************************
171 * Window procedure for the desktop window.
173 LRESULT WINAPI DesktopWndProc( HWND32 hwnd, UINT32 message,
174 WPARAM32 wParam, LPARAM lParam )
176 WND *wndPtr = WIN_FindWndPtr( hwnd );
177 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
179 /* Most messages are ignored (we DON'T call DefWindowProc) */
183 /* Warning: this message is sent directly by */
184 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
186 desktopPtr->hbrushPattern = 0;
187 desktopPtr->hbitmapWallPaper = 0;
189 SetDeskWallPaper32( (LPSTR)-1 );
193 if (X11DRV_WND_GetXRootWindow(wndPtr) ==
194 DefaultRootWindow(display))
196 return DESKTOP_DoEraseBkgnd( hwnd, (HDC32)wParam, desktopPtr );
199 if ((wParam & 0xfff0) != SC_CLOSE) return 0;
200 ExitWindows16( 0, 0 );
203 return (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
209 /***********************************************************************
210 * PaintDesktop (USER32.415)
213 BOOL32 WINAPI PaintDesktop(HDC32 hdc)
215 HWND32 hwnd = GetDesktopWindow32();
216 WND *wndPtr = WIN_FindWndPtr( hwnd );
217 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
219 return DESKTOP_DoEraseBkgnd( hwnd, hdc, desktopPtr );
222 /***********************************************************************
223 * SetDeskPattern (USER.279)
225 BOOL16 WINAPI SetDeskPattern(void)
228 GetProfileString32A( "desktop", "Pattern", "(None)", buffer, 100 );
229 return DESKTOP_SetPattern( buffer );
233 /***********************************************************************
234 * SetDeskWallPaper16 (USER.285)
236 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
238 return SetDeskWallPaper32( filename );
242 /***********************************************************************
243 * SetDeskWallPaper32 (USER32.475)
245 * FIXME: is there a unicode version?
247 BOOL32 WINAPI SetDeskWallPaper32( LPCSTR filename )
252 WND *wndPtr = WIN_GetDesktop();
253 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
255 if (filename == (LPSTR)-1)
257 GetProfileString32A( "desktop", "WallPaper", "(None)", buffer, 256 );
261 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
262 ReleaseDC32( 0, hdc );
263 if (desktopPtr->hbitmapWallPaper) DeleteObject32( desktopPtr->hbitmapWallPaper );
264 desktopPtr->hbitmapWallPaper = hbitmap;
265 desktopPtr->fTileWallPaper = GetProfileInt32A( "desktop", "TileWallPaper", 0 );
269 GetObject32A( hbitmap, sizeof(bmp), &bmp );
270 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
271 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
277 /***********************************************************************
280 * Set the desktop pattern.
282 BOOL32 DESKTOP_SetPattern( LPCSTR pattern )
284 WND *wndPtr = WIN_GetDesktop();
285 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
288 if (desktopPtr->hbrushPattern) DeleteObject32( desktopPtr->hbrushPattern );
289 memset( pat, 0, sizeof(pat) );
290 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
291 &pat[0], &pat[1], &pat[2], &pat[3],
292 &pat[4], &pat[5], &pat[6], &pat[7] ))
298 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
299 hbitmap = CreateBitmap32( 8, 8, 1, 1, (LPSTR)pattern );
300 desktopPtr->hbrushPattern = CreatePatternBrush32( hbitmap );
301 DeleteObject32( hbitmap );
303 else desktopPtr->hbrushPattern = CreateSolidBrush32( GetSysColor32(COLOR_BACKGROUND) );