2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
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
)
105 if (infoPtr
->fTileWallPaper
)
107 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
108 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
109 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
,
111 infoPtr
->bitmapSize
.cx
,
112 infoPtr
->bitmapSize
.cy
, FALSE
);
116 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
117 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
120 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
,
121 x
, y
, 0, 0, infoPtr
->bitmapSize
.cx
,
122 infoPtr
->bitmapSize
.cy
, FALSE
);
130 /***********************************************************************
133 * Window procedure for the desktop window.
135 LRESULT WINAPI
DesktopWndProc( HWND32 hwnd
, UINT32 message
,
136 WPARAM32 wParam
, LPARAM lParam
)
138 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
139 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
141 /* Most messages are ignored (we DON'T call DefWindowProc) */
145 /* Warning: this message is sent directly by */
146 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
148 infoPtr
->hbrushPattern
= 0;
149 infoPtr
->hbitmapWallPaper
= 0;
151 SetDeskWallPaper32( (LPSTR
)-1 );
155 if (rootWindow
== DefaultRootWindow(display
)) return 1;
156 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC32
)wParam
, infoPtr
);
159 if ((wParam
& 0xfff0) != SC_CLOSE
) return 0;
160 ExitWindows16( 0, 0 );
163 return (LRESULT
)SetCursor16( LoadCursor16( 0, IDC_ARROW16
) );
169 /***********************************************************************
170 * PaintDesktop (USER32.415)
173 BOOL32 WINAPI
PaintDesktop(HDC32 hdc
)
175 HWND32 hwnd
= GetDesktopWindow32();
176 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
177 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
179 return DESKTOP_DoEraseBkgnd( hwnd
, hdc
, infoPtr
);
182 /***********************************************************************
183 * SetDeskPattern (USER.279)
185 BOOL16 WINAPI
SetDeskPattern(void)
188 GetProfileString32A( "desktop", "Pattern", "(None)", buffer
, 100 );
189 return DESKTOP_SetPattern( buffer
);
193 /***********************************************************************
194 * SetDeskWallPaper16 (USER.285)
196 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
198 return SetDeskWallPaper32( filename
);
202 /***********************************************************************
203 * SetDeskWallPaper32 (USER32.475)
205 * FIXME: is there a unicode version?
207 BOOL32 WINAPI
SetDeskWallPaper32( LPCSTR filename
)
212 WND
*wndPtr
= WIN_GetDesktop();
213 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
215 if (filename
== (LPSTR
)-1)
217 GetProfileString32A( "desktop", "WallPaper", "(None)", buffer
, 256 );
221 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
222 ReleaseDC32( 0, hdc
);
223 if (infoPtr
->hbitmapWallPaper
) DeleteObject32( infoPtr
->hbitmapWallPaper
);
224 infoPtr
->hbitmapWallPaper
= hbitmap
;
225 infoPtr
->fTileWallPaper
= GetProfileInt32A( "desktop", "TileWallPaper", 0 );
229 GetObject32A( hbitmap
, sizeof(bmp
), &bmp
);
230 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
231 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
237 /***********************************************************************
240 * Set the desktop pattern.
242 BOOL32
DESKTOP_SetPattern( LPCSTR pattern
)
244 WND
*wndPtr
= WIN_GetDesktop();
245 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
248 if (infoPtr
->hbrushPattern
) DeleteObject32( infoPtr
->hbrushPattern
);
249 memset( pat
, 0, sizeof(pat
) );
250 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
251 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
252 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
258 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
259 hbitmap
= CreateBitmap32( 8, 8, 1, 1, (LPSTR
)pattern
);
260 infoPtr
->hbrushPattern
= CreatePatternBrush32( hbitmap
);
261 DeleteObject32( hbitmap
);
263 else infoPtr
->hbrushPattern
= CreateSolidBrush32( GetSysColor32(COLOR_BACKGROUND
) );