2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
17 #include "wine/winuser16.h"
22 HBITMAP hbitmapWallPaper;
27 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
30 /*********************************************************************
31 * desktop class descriptor
33 const struct builtin_class_descr DESKTOP_builtin_class =
35 DESKTOP_CLASS_ATOM, /* name */
36 CS_GLOBALCLASS, /* style */
37 NULL, /* procA (winproc is Unicode only) */
38 DesktopWndProc, /* procW */
39 sizeof(DESKTOP), /* extra */
40 IDC_ARROWA, /* cursor */
41 COLOR_BACKGROUND+1 /* brush */
45 /***********************************************************************
48 * Load a bitmap from a file. Used by SetDeskWallPaper().
50 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
52 BITMAPFILEHEADER *fileHeader;
53 BITMAPINFO *bitmapInfo;
59 /* Read all the file into memory */
61 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
63 UINT len = GetWindowsDirectoryA( NULL, 0 );
64 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
65 len + strlen(filename) + 2 )))
67 GetWindowsDirectoryA( buffer, len + 1 );
68 strcat( buffer, "\\" );
69 strcat( buffer, filename );
70 file = _lopen( buffer, OF_READ );
71 HeapFree( GetProcessHeap(), 0, buffer );
73 if (file == HFILE_ERROR) return 0;
74 size = _llseek( file, 0, 2 );
75 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
80 _llseek( file, 0, 0 );
81 size = _lread( file, buffer, size );
83 fileHeader = (BITMAPFILEHEADER *)buffer;
84 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
86 /* Check header content */
87 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
89 HeapFree( GetProcessHeap(), 0, buffer );
92 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
93 buffer + fileHeader->bfOffBits,
94 bitmapInfo, DIB_RGB_COLORS );
95 HeapFree( GetProcessHeap(), 0, buffer );
101 /***********************************************************************
104 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
106 LRESULT retvalue = 0;
107 WND *wndPtr = WIN_FindWndPtr( hwnd );
108 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
110 if (message == WM_NCCREATE)
112 desktopPtr->hbrushPattern = 0;
113 desktopPtr->hbitmapWallPaper = 0;
115 SetDeskWallPaper( (LPSTR)-1 );
118 /* all other messages are ignored */
120 WIN_ReleaseWndPtr(wndPtr);
124 /***********************************************************************
125 * PaintDesktop (USER32.@)
128 BOOL WINAPI PaintDesktop(HDC hdc)
130 HWND hwnd = GetDesktopWindow();
131 WND *wndPtr = WIN_FindWndPtr( hwnd );
132 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
134 /* check for a queue; otherwise don't paint anything (non-desktop mode) */
135 if (wndPtr->hmemTaskQ)
139 GetClientRect( hwnd, &rect );
141 /* Paint desktop pattern (only if wall paper does not cover everything) */
143 if (!desktopPtr->hbitmapWallPaper ||
144 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
145 (desktopPtr->bitmapSize.cy < rect.bottom))))
147 HBRUSH brush = desktopPtr->hbrushPattern;
148 if (!brush) brush = GetClassLongA( hwnd, GCL_HBRBACKGROUND );
149 /* Set colors in case pattern is a monochrome bitmap */
150 SetBkColor( hdc, RGB(0,0,0) );
151 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
152 FillRect( hdc, &rect, brush );
155 /* Paint wall paper */
157 if (desktopPtr->hbitmapWallPaper)
160 HDC hMemDC = CreateCompatibleDC( hdc );
162 SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
164 if (desktopPtr->fTileWallPaper)
166 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
167 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
168 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
169 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
173 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
174 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
177 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
178 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
183 WIN_ReleaseWndPtr(wndPtr);
187 /***********************************************************************
188 * OldSetDeskPattern (USER.279)
190 BOOL16 WINAPI SetDeskPattern(void)
193 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
194 return DESKTOP_SetPattern( buffer );
198 /***********************************************************************
199 * SetDeskWallPaper (USER.285)
201 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
203 return SetDeskWallPaper( filename );
207 /***********************************************************************
208 * SetDeskWallPaper (USER32.@)
210 * FIXME: is there a unicode version?
212 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
217 WND *wndPtr = WIN_GetDesktop();
218 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
220 if (filename == (LPSTR)-1)
222 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
226 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
228 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
229 desktopPtr->hbitmapWallPaper = hbitmap;
230 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
234 GetObjectA( hbitmap, sizeof(bmp), &bmp );
235 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
236 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
238 WIN_ReleaseDesktop();
243 /***********************************************************************
246 * Set the desktop pattern.
248 BOOL DESKTOP_SetPattern( LPCSTR pattern )
250 WND *wndPtr = WIN_GetDesktop();
251 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
254 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
255 memset( pat, 0, sizeof(pat) );
256 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
257 &pat[0], &pat[1], &pat[2], &pat[3],
258 &pat[4], &pat[5], &pat[6], &pat[7] ))
264 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
265 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
266 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
267 DeleteObject( hbitmap );
269 else desktopPtr->hbrushPattern = 0;
270 WIN_ReleaseDesktop();