2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
17 #include "wine/winuser16.h"
19 /**********************************************************************/
21 DESKTOP_DRIVER
*DESKTOP_Driver
= NULL
;
23 /***********************************************************************
24 * DESKTOP_IsSingleWindow
26 BOOL
DESKTOP_IsSingleWindow(void)
29 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
30 retvalue
= MONITOR_IsSingleWindow(pDesktop
->pPrimaryMonitor
);
35 /***********************************************************************
36 * DESKTOP_GetScreenWidth
38 * Return the width of the screen associated to the current desktop.
40 int DESKTOP_GetScreenWidth()
43 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
44 retvalue
= MONITOR_GetWidth(pDesktop
->pPrimaryMonitor
);
50 /***********************************************************************
51 * DESKTOP_GetScreenHeight
53 * Return the height of the screen associated to the current desktop.
55 int DESKTOP_GetScreenHeight()
58 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
59 retvalue
= MONITOR_GetHeight(pDesktop
->pPrimaryMonitor
);
65 /***********************************************************************
66 * DESKTOP_GetScreenDepth
68 * Return the depth of the screen associated to the current desktop.
70 int DESKTOP_GetScreenDepth()
73 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
74 retvalue
= MONITOR_GetDepth(pDesktop
->pPrimaryMonitor
);
80 /***********************************************************************
83 * Load a bitmap from a file. Used by SetDeskWallPaper().
85 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
87 BITMAPFILEHEADER
*fileHeader
;
88 BITMAPINFO
*bitmapInfo
;
94 /* Read all the file into memory */
96 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
98 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
99 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
100 len
+ strlen(filename
) + 2 )))
102 GetWindowsDirectoryA( buffer
, len
+ 1 );
103 strcat( buffer
, "\\" );
104 strcat( buffer
, filename
);
105 file
= _lopen( buffer
, OF_READ
);
106 HeapFree( GetProcessHeap(), 0, buffer
);
108 if (file
== HFILE_ERROR
) return 0;
109 size
= _llseek( file
, 0, 2 );
110 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
115 _llseek( file
, 0, 0 );
116 size
= _lread( file
, buffer
, size
);
118 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
119 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
121 /* Check header content */
122 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
124 HeapFree( GetProcessHeap(), 0, buffer
);
127 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
128 buffer
+ fileHeader
->bfOffBits
,
129 bitmapInfo
, DIB_RGB_COLORS
);
130 HeapFree( GetProcessHeap(), 0, buffer
);
135 /***********************************************************************
136 * DESKTOP_DoEraseBkgnd
138 * Handle the WM_ERASEBKGND message.
140 static LRESULT
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
,
141 DESKTOP
*desktopPtr
)
144 WND
* Wnd
= WIN_FindWndPtr( hwnd
);
146 if (Wnd
->hrgnUpdate
> 1) DeleteObject( Wnd
->hrgnUpdate
);
149 WIN_ReleaseWndPtr(Wnd
);
151 GetClientRect( hwnd
, &rect
);
153 /* Paint desktop pattern (only if wall paper does not cover everything) */
155 if (!desktopPtr
->hbitmapWallPaper
||
156 (!desktopPtr
->fTileWallPaper
&& ((desktopPtr
->bitmapSize
.cx
< rect
.right
) ||
157 (desktopPtr
->bitmapSize
.cy
< rect
.bottom
))))
159 /* Set colors in case pattern is a monochrome bitmap */
160 SetBkColor( hdc
, RGB(0,0,0) );
161 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
162 FillRect( hdc
, &rect
, desktopPtr
->hbrushPattern
);
165 /* Paint wall paper */
167 if (desktopPtr
->hbitmapWallPaper
)
170 HDC hMemDC
= CreateCompatibleDC( hdc
);
172 SelectObject( hMemDC
, desktopPtr
->hbitmapWallPaper
);
174 if (desktopPtr
->fTileWallPaper
)
176 for (y
= 0; y
< rect
.bottom
; y
+= desktopPtr
->bitmapSize
.cy
)
177 for (x
= 0; x
< rect
.right
; x
+= desktopPtr
->bitmapSize
.cx
)
178 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
179 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
183 x
= (rect
.left
+ rect
.right
- desktopPtr
->bitmapSize
.cx
) / 2;
184 y
= (rect
.top
+ rect
.bottom
- desktopPtr
->bitmapSize
.cy
) / 2;
187 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
188 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
197 /***********************************************************************
198 * DesktopWndProc_locked
200 * Window procedure for the desktop window.
202 static inline LRESULT WINAPI
DesktopWndProc_locked( WND
*wndPtr
, UINT message
,
203 WPARAM wParam
, LPARAM lParam
)
205 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
206 HWND hwnd
= wndPtr
->hwndSelf
;
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 );
222 if(!DESKTOP_IsSingleWindow())
224 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, desktopPtr
);
227 if ((wParam
& 0xfff0) != SC_CLOSE
)
229 ExitWindows16( 0, 0 );
232 return (LRESULT
)SetCursor16( LoadCursor16( 0, IDC_ARROW16
) );
238 /***********************************************************************
241 * This is just a wrapper for the DesktopWndProc which does windows
242 * locking and unlocking.
244 LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
,
245 WPARAM wParam
, LPARAM lParam
)
247 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
248 LRESULT retvalue
= DesktopWndProc_locked(wndPtr
,message
,wParam
,lParam
);
250 WIN_ReleaseWndPtr(wndPtr
);
254 /***********************************************************************
255 * PaintDesktop (USER32.415)
258 BOOL WINAPI
PaintDesktop(HDC hdc
)
261 HWND hwnd
= GetDesktopWindow();
262 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
263 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
264 retvalue
= DESKTOP_DoEraseBkgnd( hwnd
, hdc
, desktopPtr
);
265 WIN_ReleaseWndPtr(wndPtr
);
270 /***********************************************************************
271 * SetDeskPattern (USER.279)
273 BOOL16 WINAPI
SetDeskPattern(void)
276 GetProfileStringA( "desktop", "Pattern", "(None)", buffer
, 100 );
277 return DESKTOP_SetPattern( buffer
);
281 /***********************************************************************
282 * SetDeskWallPaper16 (USER.285)
284 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
286 return SetDeskWallPaper( filename
);
290 /***********************************************************************
291 * SetDeskWallPaper32 (USER32.475)
293 * FIXME: is there a unicode version?
295 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
300 WND
*wndPtr
= WIN_GetDesktop();
301 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
303 if (filename
== (LPSTR
)-1)
305 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
309 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
311 if (desktopPtr
->hbitmapWallPaper
) DeleteObject( desktopPtr
->hbitmapWallPaper
);
312 desktopPtr
->hbitmapWallPaper
= hbitmap
;
313 desktopPtr
->fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
317 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
318 desktopPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
319 desktopPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
321 WIN_ReleaseDesktop();
326 /***********************************************************************
329 * Set the desktop pattern.
331 BOOL
DESKTOP_SetPattern( LPCSTR pattern
)
333 WND
*wndPtr
= WIN_GetDesktop();
334 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
337 if (desktopPtr
->hbrushPattern
) DeleteObject( desktopPtr
->hbrushPattern
);
338 memset( pat
, 0, sizeof(pat
) );
339 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
340 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
341 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
347 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
348 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
349 desktopPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
350 DeleteObject( hbitmap
);
352 else desktopPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );
353 WIN_ReleaseDesktop();