2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
16 #include "wine/winuser16.h"
21 HBITMAP hbitmapWallPaper
;
26 static LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
29 /*********************************************************************
30 * desktop class descriptor
32 const struct builtin_class_descr DESKTOP_builtin_class
=
34 DESKTOP_CLASS_ATOM
, /* name */
35 CS_GLOBALCLASS
, /* style */
36 NULL
, /* procA (winproc is Unicode only) */
37 DesktopWndProc
, /* procW */
38 sizeof(DESKTOP
), /* extra */
39 IDC_ARROWA
, /* cursor */
40 COLOR_BACKGROUND
+1 /* brush */
44 /***********************************************************************
47 * Load a bitmap from a file. Used by SetDeskWallPaper().
49 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
51 BITMAPFILEHEADER
*fileHeader
;
52 BITMAPINFO
*bitmapInfo
;
58 /* Read all the file into memory */
60 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
62 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
63 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
64 len
+ strlen(filename
) + 2 )))
66 GetWindowsDirectoryA( buffer
, len
+ 1 );
67 strcat( buffer
, "\\" );
68 strcat( buffer
, filename
);
69 file
= _lopen( buffer
, OF_READ
);
70 HeapFree( GetProcessHeap(), 0, buffer
);
72 if (file
== HFILE_ERROR
) return 0;
73 size
= _llseek( file
, 0, 2 );
74 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
79 _llseek( file
, 0, 0 );
80 size
= _lread( file
, buffer
, size
);
82 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
83 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
85 /* Check header content */
86 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
88 HeapFree( GetProcessHeap(), 0, buffer
);
91 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
92 buffer
+ fileHeader
->bfOffBits
,
93 bitmapInfo
, DIB_RGB_COLORS
);
94 HeapFree( GetProcessHeap(), 0, buffer
);
100 /***********************************************************************
103 static LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
105 LRESULT retvalue
= 0;
106 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
107 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
109 if (message
== WM_NCCREATE
)
111 desktopPtr
->hbrushPattern
= 0;
112 desktopPtr
->hbitmapWallPaper
= 0;
114 SetDeskWallPaper( (LPSTR
)-1 );
117 /* all other messages are ignored */
119 WIN_ReleaseWndPtr(wndPtr
);
123 /***********************************************************************
124 * PaintDesktop (USER32.@)
127 BOOL WINAPI
PaintDesktop(HDC hdc
)
129 HWND hwnd
= GetDesktopWindow();
130 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
131 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
133 /* check for a queue; otherwise don't paint anything (non-desktop mode) */
134 if (wndPtr
->hmemTaskQ
)
138 GetClientRect( hwnd
, &rect
);
140 /* Paint desktop pattern (only if wall paper does not cover everything) */
142 if (!desktopPtr
->hbitmapWallPaper
||
143 (!desktopPtr
->fTileWallPaper
&& ((desktopPtr
->bitmapSize
.cx
< rect
.right
) ||
144 (desktopPtr
->bitmapSize
.cy
< rect
.bottom
))))
146 HBRUSH brush
= desktopPtr
->hbrushPattern
;
147 if (!brush
) brush
= GetClassLongA( hwnd
, GCL_HBRBACKGROUND
);
148 /* Set colors in case pattern is a monochrome bitmap */
149 SetBkColor( hdc
, RGB(0,0,0) );
150 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
151 FillRect( hdc
, &rect
, brush
);
154 /* Paint wall paper */
156 if (desktopPtr
->hbitmapWallPaper
)
159 HDC hMemDC
= CreateCompatibleDC( hdc
);
161 SelectObject( hMemDC
, desktopPtr
->hbitmapWallPaper
);
163 if (desktopPtr
->fTileWallPaper
)
165 for (y
= 0; y
< rect
.bottom
; y
+= desktopPtr
->bitmapSize
.cy
)
166 for (x
= 0; x
< rect
.right
; x
+= desktopPtr
->bitmapSize
.cx
)
167 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
168 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
172 x
= (rect
.left
+ rect
.right
- desktopPtr
->bitmapSize
.cx
) / 2;
173 y
= (rect
.top
+ rect
.bottom
- desktopPtr
->bitmapSize
.cy
) / 2;
176 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
177 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
182 WIN_ReleaseWndPtr(wndPtr
);
186 /***********************************************************************
187 * OldSetDeskPattern (USER.279)
189 BOOL16 WINAPI
SetDeskPattern(void)
192 GetProfileStringA( "desktop", "Pattern", "(None)", buffer
, 100 );
193 return DESKTOP_SetPattern( buffer
);
197 /***********************************************************************
198 * SetDeskWallPaper (USER.285)
200 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
202 return SetDeskWallPaper( filename
);
206 /***********************************************************************
207 * SetDeskWallPaper (USER32.@)
209 * FIXME: is there a unicode version?
211 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
216 WND
*wndPtr
= WIN_GetDesktop();
217 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
219 if (filename
== (LPSTR
)-1)
221 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
225 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
227 if (desktopPtr
->hbitmapWallPaper
) DeleteObject( desktopPtr
->hbitmapWallPaper
);
228 desktopPtr
->hbitmapWallPaper
= hbitmap
;
229 desktopPtr
->fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
233 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
234 desktopPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
235 desktopPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
237 WIN_ReleaseDesktop();
242 /***********************************************************************
245 * Set the desktop pattern.
247 BOOL
DESKTOP_SetPattern( LPCSTR pattern
)
249 WND
*wndPtr
= WIN_GetDesktop();
250 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
253 if (desktopPtr
->hbrushPattern
) DeleteObject( desktopPtr
->hbrushPattern
);
254 memset( pat
, 0, sizeof(pat
) );
255 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
256 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
257 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
263 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
264 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
265 desktopPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
266 DeleteObject( hbitmap
);
268 else desktopPtr
->hbrushPattern
= 0;
269 WIN_ReleaseDesktop();