2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
7 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
13 #include "directory.h"
18 /***********************************************************************
21 * Load a bitmap from a file. Used by SetDeskWallPaper().
23 static HBITMAP32 DESKTOP_LoadBitmap( HDC32 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 = GetWindowsDirectory32A( NULL, 0 );
37 if (!(buffer = HeapAlloc( SystemHeap, 0, len + strlen(filename) + 2 )))
39 GetWindowsDirectory32A( 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 = _lread32( 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 LRESULT DESKTOP_DoEraseBkgnd( HWND32 hwnd, HDC32 hdc,
78 DESKTOPINFO *infoPtr )
81 WND* Wnd = WIN_FindWndPtr( hwnd );
83 if (Wnd->hrgnUpdate > 1) DeleteObject32( Wnd->hrgnUpdate );
86 GetClientRect32( hwnd, &rect );
88 /* Paint desktop pattern (only if wall paper does not cover everything) */
90 if (!infoPtr->hbitmapWallPaper ||
91 (!infoPtr->fTileWallPaper && ((infoPtr->bitmapSize.cx < rect.right) ||
92 (infoPtr->bitmapSize.cy < rect.bottom))))
94 /* Set colors in case pattern is a monochrome bitmap */
95 SetBkColor( hdc, RGB(0,0,0) );
96 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
97 FillRect32( hdc, &rect, infoPtr->hbrushPattern );
100 /* Paint wall paper */
102 if (infoPtr->hbitmapWallPaper)
106 if (infoPtr->fTileWallPaper)
108 for (y = 0; y < rect.bottom; y += infoPtr->bitmapSize.cy)
109 for (x = 0; x < rect.right; x += infoPtr->bitmapSize.cx)
110 GRAPH_DrawBitmap( hdc, infoPtr->hbitmapWallPaper,
112 infoPtr->bitmapSize.cx,
113 infoPtr->bitmapSize.cy );
117 x = (rect.left + rect.right - infoPtr->bitmapSize.cx) / 2;
118 y = (rect.top + rect.bottom - infoPtr->bitmapSize.cy) / 2;
121 GRAPH_DrawBitmap( hdc, infoPtr->hbitmapWallPaper, x, y, 0, 0,
122 infoPtr->bitmapSize.cx, infoPtr->bitmapSize.cy );
130 /***********************************************************************
133 * Window procedure for the desktop window.
135 LRESULT 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;
163 return (LRESULT)SetCursor( LoadCursor16( 0, IDC_ARROW ) );
170 /***********************************************************************
171 * SetDeskPattern (USER.279)
173 BOOL16 SetDeskPattern(void)
176 GetProfileString( "desktop", "Pattern", "(None)", buffer, 100 );
177 return DESKTOP_SetPattern( buffer );
181 /***********************************************************************
182 * SetDeskWallPaper16 (USER.285)
184 BOOL16 SetDeskWallPaper16( LPCSTR filename )
186 return SetDeskWallPaper32( filename );
190 /***********************************************************************
191 * SetDeskWallPaper32 (USER32.475)
193 * FIXME: is there a unicode version?
195 BOOL32 SetDeskWallPaper32( LPCSTR filename )
200 WND *wndPtr = WIN_GetDesktop();
201 DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
203 if (filename == (LPSTR)-1)
205 GetProfileString( "desktop", "WallPaper", "(None)", buffer, 256 );
209 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
210 ReleaseDC32( 0, hdc );
211 if (infoPtr->hbitmapWallPaper) DeleteObject32( infoPtr->hbitmapWallPaper );
212 infoPtr->hbitmapWallPaper = hbitmap;
213 infoPtr->fTileWallPaper = GetProfileInt( "desktop", "TileWallPaper", 0 );
217 GetObject32A( hbitmap, sizeof(bmp), &bmp );
218 infoPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
219 infoPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
225 /***********************************************************************
228 * Set the desktop pattern.
230 BOOL32 DESKTOP_SetPattern( LPCSTR pattern )
232 WND *wndPtr = WIN_GetDesktop();
233 DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
236 if (infoPtr->hbrushPattern) DeleteObject32( infoPtr->hbrushPattern );
237 memset( pat, 0, sizeof(pat) );
238 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
239 &pat[0], &pat[1], &pat[2], &pat[3],
240 &pat[4], &pat[5], &pat[6], &pat[7] ))
246 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
247 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
248 infoPtr->hbrushPattern = CreatePatternBrush32( hbitmap );
249 DeleteObject32( hbitmap );
251 else infoPtr->hbrushPattern = CreateSolidBrush32( GetSysColor(COLOR_BACKGROUND) );