2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
12 #include "directory.h"
18 /***********************************************************************
21 * Load a bitmap from a file. Used by SetDeskWallPaper().
23 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
25 BITMAPFILEHEADER
*fileHeader
;
26 BITMAPINFO
*bitmapInfo
;
32 /* Read all the file into memory */
34 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
36 UINT32 len
= GetWindowsDirectory( NULL
, 0 );
37 if (!(buffer
= HeapAlloc( SystemHeap
, 0, len
+ strlen(filename
) + 2 )))
39 GetWindowsDirectory( buffer
, len
+ 1 );
40 strcat( buffer
, "\\" );
41 strcat( buffer
, filename
);
42 file
= _lopen( buffer
, OF_READ
);
43 HeapFree( SystemHeap
, 0, buffer
);
45 if (file
== HFILE_ERROR
) return 0;
46 size
= _llseek( file
, 0, 2 );
47 if (!(buffer
= HeapAlloc( SystemHeap
, 0, size
)))
52 _llseek( file
, 0, 0 );
53 size
= FILE_Read( file
, buffer
, size
);
55 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
56 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
58 /* Check header content */
59 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
61 HeapFree( SystemHeap
, 0, buffer
);
64 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
65 buffer
+ fileHeader
->bfOffBits
,
66 bitmapInfo
, DIB_RGB_COLORS
);
67 HeapFree( SystemHeap
, 0, buffer
);
72 /***********************************************************************
73 * DESKTOP_DoEraseBkgnd
75 * Handle the WM_ERASEBKGND message.
77 static LONG
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
, DESKTOPINFO
*infoPtr
)
80 GetClientRect16( hwnd
, &rect
);
82 /* Paint desktop pattern (only if wall paper does not cover everything) */
84 if (!infoPtr
->hbitmapWallPaper
||
85 (!infoPtr
->fTileWallPaper
&& ((infoPtr
->bitmapSize
.cx
< rect
.right
) ||
86 (infoPtr
->bitmapSize
.cy
< rect
.bottom
))))
88 /* Set colors in case pattern is a monochrome bitmap */
89 SetBkColor( hdc
, RGB(0,0,0) );
90 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
91 FillRect16( hdc
, &rect
, infoPtr
->hbrushPattern
);
94 /* Paint wall paper */
96 if (infoPtr
->hbitmapWallPaper
)
100 if (infoPtr
->fTileWallPaper
)
102 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
103 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
104 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
,
106 infoPtr
->bitmapSize
.cx
,
107 infoPtr
->bitmapSize
.cy
);
111 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
112 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
115 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
, x
, y
, 0, 0,
116 infoPtr
->bitmapSize
.cx
, infoPtr
->bitmapSize
.cy
);
124 /***********************************************************************
127 * Window procedure for the desktop window.
129 LRESULT
DesktopWndProc( HWND32 hwnd
, UINT32 message
,
130 WPARAM32 wParam
, LPARAM lParam
)
132 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
133 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
135 /* Most messages are ignored (we DON'T call DefWindowProc) */
139 /* Warning: this message is sent directly by */
140 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
142 infoPtr
->hbrushPattern
= 0;
143 infoPtr
->hbitmapWallPaper
= 0;
145 SetDeskWallPaper( (LPSTR
)-1 );
149 if (rootWindow
== DefaultRootWindow(display
)) return 1;
150 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, infoPtr
);
153 if ((wParam
& 0xfff0) != SC_CLOSE
) return 0;
157 return (LRESULT
)SetCursor( LoadCursor16( 0, IDC_ARROW
) );
164 /***********************************************************************
165 * SetDeskPattern (USER.279)
167 BOOL
SetDeskPattern(void)
170 GetProfileString( "desktop", "Pattern", "(None)", buffer
, 100 );
171 return DESKTOP_SetPattern( buffer
);
175 /***********************************************************************
176 * SetDeskWallPaper (USER.285)
178 BOOL
SetDeskWallPaper( LPCSTR filename
)
183 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
184 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
186 if (filename
== (LPSTR
)-1)
188 GetProfileString( "desktop", "WallPaper", "(None)", buffer
, 256 );
192 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
194 if (infoPtr
->hbitmapWallPaper
) DeleteObject( infoPtr
->hbitmapWallPaper
);
195 infoPtr
->hbitmapWallPaper
= hbitmap
;
196 infoPtr
->fTileWallPaper
= GetProfileInt( "desktop", "TileWallPaper", 0 );
200 GetObject16( hbitmap
, sizeof(bmp
), &bmp
);
201 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
202 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
208 /***********************************************************************
211 * Set the desktop pattern.
213 BOOL
DESKTOP_SetPattern(char *pattern
)
215 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
216 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
219 if (infoPtr
->hbrushPattern
) DeleteObject( infoPtr
->hbrushPattern
);
220 memset( pat
, 0, sizeof(pat
) );
221 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
222 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
223 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
229 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
230 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
231 infoPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
232 DeleteObject( hbitmap
);
234 else infoPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );