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()
27 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
28 return MONITOR_GetWidth(pDesktop
->pPrimaryMonitor
);
31 /***********************************************************************
32 * DESKTOP_GetScreenHeight
34 * Return the height of the screen associated to the current desktop.
36 int DESKTOP_GetScreenHeight()
38 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
39 return MONITOR_GetHeight(pDesktop
->pPrimaryMonitor
);
42 /***********************************************************************
43 * DESKTOP_GetScreenDepth
45 * Return the depth of the screen associated to the current desktop.
47 int DESKTOP_GetScreenDepth()
49 DESKTOP
*pDesktop
= (DESKTOP
*) WIN_GetDesktop()->wExtra
;
50 return MONITOR_GetDepth(pDesktop
->pPrimaryMonitor
);
53 /***********************************************************************
56 * Load a bitmap from a file. Used by SetDeskWallPaper().
58 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
60 BITMAPFILEHEADER
*fileHeader
;
61 BITMAPINFO
*bitmapInfo
;
67 /* Read all the file into memory */
69 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
71 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
72 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
73 len
+ strlen(filename
) + 2 )))
75 GetWindowsDirectoryA( buffer
, len
+ 1 );
76 strcat( buffer
, "\\" );
77 strcat( buffer
, filename
);
78 file
= _lopen( buffer
, OF_READ
);
79 HeapFree( GetProcessHeap(), 0, buffer
);
81 if (file
== HFILE_ERROR
) return 0;
82 size
= _llseek( file
, 0, 2 );
83 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
88 _llseek( file
, 0, 0 );
89 size
= _lread( file
, buffer
, size
);
91 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
92 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
94 /* Check header content */
95 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
97 HeapFree( GetProcessHeap(), 0, buffer
);
100 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
101 buffer
+ fileHeader
->bfOffBits
,
102 bitmapInfo
, DIB_RGB_COLORS
);
103 HeapFree( GetProcessHeap(), 0, buffer
);
108 /***********************************************************************
109 * DESKTOP_DoEraseBkgnd
111 * Handle the WM_ERASEBKGND message.
113 static LRESULT
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
,
114 DESKTOP
*desktopPtr
)
117 WND
* Wnd
= WIN_FindWndPtr( hwnd
);
119 if (Wnd
->hrgnUpdate
> 1) DeleteObject( Wnd
->hrgnUpdate
);
122 GetClientRect( hwnd
, &rect
);
124 /* Paint desktop pattern (only if wall paper does not cover everything) */
126 if (!desktopPtr
->hbitmapWallPaper
||
127 (!desktopPtr
->fTileWallPaper
&& ((desktopPtr
->bitmapSize
.cx
< rect
.right
) ||
128 (desktopPtr
->bitmapSize
.cy
< rect
.bottom
))))
130 /* Set colors in case pattern is a monochrome bitmap */
131 SetBkColor( hdc
, RGB(0,0,0) );
132 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
133 FillRect( hdc
, &rect
, desktopPtr
->hbrushPattern
);
136 /* Paint wall paper */
138 if (desktopPtr
->hbitmapWallPaper
)
141 HDC hMemDC
= CreateCompatibleDC( hdc
);
143 SelectObject( hMemDC
, desktopPtr
->hbitmapWallPaper
);
145 if (desktopPtr
->fTileWallPaper
)
147 for (y
= 0; y
< rect
.bottom
; y
+= desktopPtr
->bitmapSize
.cy
)
148 for (x
= 0; x
< rect
.right
; x
+= desktopPtr
->bitmapSize
.cx
)
149 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
150 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
154 x
= (rect
.left
+ rect
.right
- desktopPtr
->bitmapSize
.cx
) / 2;
155 y
= (rect
.top
+ rect
.bottom
- desktopPtr
->bitmapSize
.cy
) / 2;
158 BitBlt( hdc
, x
, y
, desktopPtr
->bitmapSize
.cx
,
159 desktopPtr
->bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
168 /***********************************************************************
171 * Window procedure for the desktop window.
173 LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
,
174 WPARAM wParam
, LPARAM lParam
)
176 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
177 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
179 /* Most messages are ignored (we DON'T call DefWindowProc) */
183 /* Warning: this message is sent directly by */
184 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
186 desktopPtr
->hbrushPattern
= 0;
187 desktopPtr
->hbitmapWallPaper
= 0;
189 SetDeskWallPaper( (LPSTR
)-1 );
193 if (X11DRV_WND_GetXRootWindow(wndPtr
) ==
194 DefaultRootWindow(display
))
196 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, desktopPtr
);
199 if ((wParam
& 0xfff0) != SC_CLOSE
) return 0;
200 ExitWindows16( 0, 0 );
203 return (LRESULT
)SetCursor16( LoadCursor16( 0, IDC_ARROW16
) );
209 /***********************************************************************
210 * PaintDesktop (USER32.415)
213 BOOL WINAPI
PaintDesktop(HDC hdc
)
215 HWND hwnd
= GetDesktopWindow();
216 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
217 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
219 return DESKTOP_DoEraseBkgnd( hwnd
, hdc
, desktopPtr
);
222 /***********************************************************************
223 * SetDeskPattern (USER.279)
225 BOOL16 WINAPI
SetDeskPattern(void)
228 GetProfileStringA( "desktop", "Pattern", "(None)", buffer
, 100 );
229 return DESKTOP_SetPattern( buffer
);
233 /***********************************************************************
234 * SetDeskWallPaper16 (USER.285)
236 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
238 return SetDeskWallPaper( filename
);
242 /***********************************************************************
243 * SetDeskWallPaper32 (USER32.475)
245 * FIXME: is there a unicode version?
247 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
252 WND
*wndPtr
= WIN_GetDesktop();
253 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
255 if (filename
== (LPSTR
)-1)
257 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
261 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
263 if (desktopPtr
->hbitmapWallPaper
) DeleteObject( desktopPtr
->hbitmapWallPaper
);
264 desktopPtr
->hbitmapWallPaper
= hbitmap
;
265 desktopPtr
->fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
269 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
270 desktopPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
271 desktopPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
277 /***********************************************************************
280 * Set the desktop pattern.
282 BOOL
DESKTOP_SetPattern( LPCSTR pattern
)
284 WND
*wndPtr
= WIN_GetDesktop();
285 DESKTOP
*desktopPtr
= (DESKTOP
*)wndPtr
->wExtra
;
288 if (desktopPtr
->hbrushPattern
) DeleteObject( desktopPtr
->hbrushPattern
);
289 memset( pat
, 0, sizeof(pat
) );
290 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
291 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
292 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
298 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
299 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
300 desktopPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
301 DeleteObject( hbitmap
);
303 else desktopPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );