2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
13 #include "wine/winuser16.h"
16 /***********************************************************************
19 * Load a bitmap from a file. Used by SetDeskWallPaper().
21 static HBITMAP32
DESKTOP_LoadBitmap( HDC32 hdc
, const char *filename
)
23 BITMAPFILEHEADER
*fileHeader
;
24 BITMAPINFO
*bitmapInfo
;
30 /* Read all the file into memory */
32 if ((file
= _lopen32( filename
, OF_READ
)) == HFILE_ERROR32
)
34 UINT32 len
= GetWindowsDirectory32A( NULL
, 0 );
35 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
36 len
+ strlen(filename
) + 2 )))
38 GetWindowsDirectory32A( buffer
, len
+ 1 );
39 strcat( buffer
, "\\" );
40 strcat( buffer
, filename
);
41 file
= _lopen32( buffer
, OF_READ
);
42 HeapFree( GetProcessHeap(), 0, buffer
);
44 if (file
== HFILE_ERROR32
) return 0;
45 size
= _llseek32( file
, 0, 2 );
46 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
51 _llseek32( file
, 0, 0 );
52 size
= _lread32( file
, buffer
, size
);
54 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
55 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
57 /* Check header content */
58 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
60 HeapFree( GetProcessHeap(), 0, buffer
);
63 hbitmap
= CreateDIBitmap32( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
64 buffer
+ fileHeader
->bfOffBits
,
65 bitmapInfo
, DIB_RGB_COLORS
);
66 HeapFree( GetProcessHeap(), 0, buffer
);
71 /***********************************************************************
72 * DESKTOP_DoEraseBkgnd
74 * Handle the WM_ERASEBKGND message.
76 static LRESULT
DESKTOP_DoEraseBkgnd( HWND32 hwnd
, HDC32 hdc
,
77 DESKTOPINFO
*infoPtr
)
80 WND
* Wnd
= WIN_FindWndPtr( hwnd
);
82 if (Wnd
->hrgnUpdate
> 1) DeleteObject32( Wnd
->hrgnUpdate
);
85 GetClientRect32( hwnd
, &rect
);
87 /* Paint desktop pattern (only if wall paper does not cover everything) */
89 if (!infoPtr
->hbitmapWallPaper
||
90 (!infoPtr
->fTileWallPaper
&& ((infoPtr
->bitmapSize
.cx
< rect
.right
) ||
91 (infoPtr
->bitmapSize
.cy
< rect
.bottom
))))
93 /* Set colors in case pattern is a monochrome bitmap */
94 SetBkColor32( hdc
, RGB(0,0,0) );
95 SetTextColor32( hdc
, GetSysColor32(COLOR_BACKGROUND
) );
96 FillRect32( hdc
, &rect
, infoPtr
->hbrushPattern
);
99 /* Paint wall paper */
101 if (infoPtr
->hbitmapWallPaper
)
104 HDC32 hMemDC
= CreateCompatibleDC32( hdc
);
106 SelectObject32( hMemDC
, infoPtr
->hbitmapWallPaper
);
108 if (infoPtr
->fTileWallPaper
)
110 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
111 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
112 BitBlt32( hdc
, x
, y
, infoPtr
->bitmapSize
.cx
,
113 infoPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
117 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
118 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
121 BitBlt32( hdc
, x
, y
, infoPtr
->bitmapSize
.cx
,
122 infoPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
124 DeleteDC32( hMemDC
);
131 /***********************************************************************
134 * Window procedure for the desktop window.
136 LRESULT WINAPI
DesktopWndProc( HWND32 hwnd
, UINT32 message
,
137 WPARAM32 wParam
, LPARAM lParam
)
139 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
140 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
142 /* Most messages are ignored (we DON'T call DefWindowProc) */
146 /* Warning: this message is sent directly by */
147 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
149 infoPtr
->hbrushPattern
= 0;
150 infoPtr
->hbitmapWallPaper
= 0;
152 SetDeskWallPaper32( (LPSTR
)-1 );
156 if (rootWindow
== DefaultRootWindow(display
)) return 1;
157 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC32
)wParam
, infoPtr
);
160 if ((wParam
& 0xfff0) != SC_CLOSE
) return 0;
161 ExitWindows16( 0, 0 );
164 return (LRESULT
)SetCursor16( LoadCursor16( 0, IDC_ARROW16
) );
170 /***********************************************************************
171 * PaintDesktop (USER32.415)
174 BOOL32 WINAPI
PaintDesktop(HDC32 hdc
)
176 HWND32 hwnd
= GetDesktopWindow32();
177 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
178 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
180 return DESKTOP_DoEraseBkgnd( hwnd
, hdc
, infoPtr
);
183 /***********************************************************************
184 * SetDeskPattern (USER.279)
186 BOOL16 WINAPI
SetDeskPattern(void)
189 GetProfileString32A( "desktop", "Pattern", "(None)", buffer
, 100 );
190 return DESKTOP_SetPattern( buffer
);
194 /***********************************************************************
195 * SetDeskWallPaper16 (USER.285)
197 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
199 return SetDeskWallPaper32( filename
);
203 /***********************************************************************
204 * SetDeskWallPaper32 (USER32.475)
206 * FIXME: is there a unicode version?
208 BOOL32 WINAPI
SetDeskWallPaper32( LPCSTR filename
)
213 WND
*wndPtr
= WIN_GetDesktop();
214 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
216 if (filename
== (LPSTR
)-1)
218 GetProfileString32A( "desktop", "WallPaper", "(None)", buffer
, 256 );
222 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
223 ReleaseDC32( 0, hdc
);
224 if (infoPtr
->hbitmapWallPaper
) DeleteObject32( infoPtr
->hbitmapWallPaper
);
225 infoPtr
->hbitmapWallPaper
= hbitmap
;
226 infoPtr
->fTileWallPaper
= GetProfileInt32A( "desktop", "TileWallPaper", 0 );
230 GetObject32A( hbitmap
, sizeof(bmp
), &bmp
);
231 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
232 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
238 /***********************************************************************
241 * Set the desktop pattern.
243 BOOL32
DESKTOP_SetPattern( LPCSTR pattern
)
245 WND
*wndPtr
= WIN_GetDesktop();
246 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
249 if (infoPtr
->hbrushPattern
) DeleteObject32( infoPtr
->hbrushPattern
);
250 memset( pat
, 0, sizeof(pat
) );
251 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
252 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
253 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
259 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
260 hbitmap
= CreateBitmap32( 8, 8, 1, 1, (LPSTR
)pattern
);
261 infoPtr
->hbrushPattern
= CreatePatternBrush32( hbitmap
);
262 DeleteObject32( hbitmap
);
264 else infoPtr
->hbrushPattern
= CreateSolidBrush32( GetSysColor32(COLOR_BACKGROUND
) );