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()
28 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
29 retvalue
= MONITOR_GetWidth(pDesktop
->pPrimaryMonitor
);
35 /***********************************************************************
36 * DESKTOP_GetScreenHeight
38 * Return the height of the screen associated to the current desktop.
40 int DESKTOP_GetScreenHeight()
43 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
44 retvalue
= MONITOR_GetHeight(pDesktop
->pPrimaryMonitor
);
50 /***********************************************************************
51 * DESKTOP_GetScreenDepth
53 * Return the depth of the screen associated to the current desktop.
55 int DESKTOP_GetScreenDepth()
58 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
59 retvalue
= MONITOR_GetDepth(pDesktop
->pPrimaryMonitor
);
65 /***********************************************************************
68 * Load a bitmap from a file. Used by SetDeskWallPaper().
70 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
72 BITMAPFILEHEADER
*fileHeader
;
73 BITMAPINFO
*bitmapInfo
;
79 /* Read all the file into memory */
81 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
83 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
84 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
85 len
+ strlen(filename
) + 2 )))
87 GetWindowsDirectoryA( buffer
, len
+ 1 );
88 strcat( buffer
, "\\" );
89 strcat( buffer
, filename
);
90 file
= _lopen( buffer
, OF_READ
);
91 HeapFree( GetProcessHeap(), 0, buffer
);
93 if (file
== HFILE_ERROR
) return 0;
94 size
= _llseek( file
, 0, 2 );
95 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
100 _llseek( file
, 0, 0 );
101 size
= _lread( file
, buffer
, size
);
103 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
104 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
106 /* Check header content */
107 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
109 HeapFree( GetProcessHeap(), 0, buffer
);
112 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
113 buffer
+ fileHeader
->bfOffBits
,
114 bitmapInfo
, DIB_RGB_COLORS
);
115 HeapFree( GetProcessHeap(), 0, buffer
);
120 /***********************************************************************
121 * DESKTOP_DoEraseBkgnd
123 * Handle the WM_ERASEBKGND message.
125 static LRESULT
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
,
126 DESKTOP
*desktopPtr
)
129 WND
* Wnd
= WIN_FindWndPtr( hwnd
);
131 if (Wnd
->hrgnUpdate
> 1) DeleteObject( Wnd
->hrgnUpdate
);
134 WIN_ReleaseWndPtr(Wnd
);
136 GetClientRect( hwnd
, &rect
);
138 /* Paint desktop pattern (only if wall paper does not cover everything) */
140 if (!desktopPtr
->hbitmapWallPaper
||
141 (!desktopPtr
->fTileWallPaper
&& ((desktopPtr
->bitmapSize
.cx
< rect
.right
) ||
142 (desktopPtr
->bitmapSize
.cy
< rect
.bottom
))))
144 /* Set colors in case pattern is a monochrome bitmap */
145 SetBkColor( hdc
, RGB(0,0,0) );
146 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
147 FillRect( hdc
, &rect
, desktopPtr
->hbrushPattern
);
150 /* Paint wall paper */
152 if (desktopPtr
->hbitmapWallPaper
)
155 HDC hMemDC
= CreateCompatibleDC( hdc
);
157 SelectObject( hMemDC
, desktopPtr
->hbitmapWallPaper
);
159 if (desktopPtr
->fTileWallPaper
)
161 for (y
= 0; y
< rect
.bottom
; y
+= desktopPtr
->bitmapSize
.cy
)
162 for (x
= 0; x
< rect
.right
; x
+= desktopPtr
->bitmapSize
.cx
)
163 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
164 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
168 x
= (rect
.left
+ rect
.right
- desktopPtr
->bitmapSize
.cx
) / 2;
169 y
= (rect
.top
+ rect
.bottom
- desktopPtr
->bitmapSize
.cy
) / 2;
172 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
173 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
182 /***********************************************************************
185 * Window procedure for the desktop window.
187 LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
,
188 WPARAM wParam
, LPARAM lParam
)
191 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
192 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
194 /* Most messages are ignored (we DON'T call DefWindowProc) */
198 /* Warning: this message is sent directly by */
199 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
201 desktopPtr
->hbrushPattern
= 0;
202 desktopPtr
->hbitmapWallPaper
= 0;
204 SetDeskWallPaper( (LPSTR
)-1 );
209 if (X11DRV_WND_GetXRootWindow(wndPtr
) ==
210 DefaultRootWindow(display
))
215 retvalue
= DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, desktopPtr
);
219 if ((wParam
& 0xfff0) != SC_CLOSE
)
224 ExitWindows16( 0, 0 );
227 retvalue
= (LRESULT
)SetCursor16( LoadCursor16( 0, IDC_ARROW16
) );
233 WIN_ReleaseWndPtr(wndPtr
);
237 /***********************************************************************
238 * PaintDesktop (USER32.415)
241 BOOL WINAPI
PaintDesktop(HDC hdc
)
244 HWND hwnd
= GetDesktopWindow();
245 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
246 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
247 retvalue
= DESKTOP_DoEraseBkgnd( hwnd
, hdc
, desktopPtr
);
248 WIN_ReleaseWndPtr(wndPtr
);
253 /***********************************************************************
254 * SetDeskPattern (USER.279)
256 BOOL16 WINAPI
SetDeskPattern(void)
259 GetProfileStringA( "desktop", "Pattern", "(None)", buffer
, 100 );
260 return DESKTOP_SetPattern( buffer
);
264 /***********************************************************************
265 * SetDeskWallPaper16 (USER.285)
267 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
269 return SetDeskWallPaper( filename
);
273 /***********************************************************************
274 * SetDeskWallPaper32 (USER32.475)
276 * FIXME: is there a unicode version?
278 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
283 WND
*wndPtr
= WIN_GetDesktop();
284 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
286 if (filename
== (LPSTR
)-1)
288 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
292 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
294 if (desktopPtr
->hbitmapWallPaper
) DeleteObject( desktopPtr
->hbitmapWallPaper
);
295 desktopPtr
->hbitmapWallPaper
= hbitmap
;
296 desktopPtr
->fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
300 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
301 desktopPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
302 desktopPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
304 WIN_ReleaseDesktop();
309 /***********************************************************************
312 * Set the desktop pattern.
314 BOOL
DESKTOP_SetPattern( LPCSTR pattern
)
316 WND
*wndPtr
= WIN_GetDesktop();
317 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
320 if (desktopPtr
->hbrushPattern
) DeleteObject( desktopPtr
->hbrushPattern
);
321 memset( pat
, 0, sizeof(pat
) );
322 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
323 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
324 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
330 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
331 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
332 desktopPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
333 DeleteObject( hbitmap
);
335 else desktopPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );
336 WIN_ReleaseDesktop();