2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
15 #include "wine/winuser16.h"
17 static HBRUSH hbrushPattern;
18 static HBITMAP hbitmapWallPaper;
19 static SIZE bitmapSize;
20 static BOOL fTileWallPaper;
22 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
25 /*********************************************************************
26 * desktop class descriptor
28 const struct builtin_class_descr DESKTOP_builtin_class =
30 DESKTOP_CLASS_ATOM, /* name */
31 CS_GLOBALCLASS, /* style */
32 NULL, /* procA (winproc is Unicode only) */
33 DesktopWndProc, /* procW */
35 IDC_ARROWA, /* cursor */
36 COLOR_BACKGROUND+1 /* brush */
40 /***********************************************************************
43 * Load a bitmap from a file. Used by SetDeskWallPaper().
45 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
47 BITMAPFILEHEADER *fileHeader;
48 BITMAPINFO *bitmapInfo;
54 /* Read all the file into memory */
56 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
58 UINT len = GetWindowsDirectoryA( NULL, 0 );
59 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
60 len + strlen(filename) + 2 )))
62 GetWindowsDirectoryA( buffer, len + 1 );
63 strcat( buffer, "\\" );
64 strcat( buffer, filename );
65 file = _lopen( buffer, OF_READ );
66 HeapFree( GetProcessHeap(), 0, buffer );
68 if (file == HFILE_ERROR) return 0;
69 size = _llseek( file, 0, 2 );
70 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
75 _llseek( file, 0, 0 );
76 size = _lread( file, buffer, size );
78 fileHeader = (BITMAPFILEHEADER *)buffer;
79 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
81 /* Check header content */
82 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
84 HeapFree( GetProcessHeap(), 0, buffer );
87 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
88 buffer + fileHeader->bfOffBits,
89 bitmapInfo, DIB_RGB_COLORS );
90 HeapFree( GetProcessHeap(), 0, buffer );
96 /***********************************************************************
99 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
101 LRESULT retvalue = 0;
103 if (message == WM_NCCREATE)
106 hbitmapWallPaper = 0;
108 SetDeskWallPaper( (LPSTR)-1 );
111 /* all other messages are ignored */
115 /***********************************************************************
116 * PaintDesktop (USER32.@)
119 BOOL WINAPI PaintDesktop(HDC hdc)
121 HWND hwnd = GetDesktopWindow();
123 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
124 if (GetWindowThreadProcessId( hwnd, NULL ))
128 GetClientRect( hwnd, &rect );
130 /* Paint desktop pattern (only if wall paper does not cover everything) */
132 if (!hbitmapWallPaper ||
133 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
135 HBRUSH brush = hbrushPattern;
136 if (!brush) brush = GetClassLongA( hwnd, GCL_HBRBACKGROUND );
137 /* Set colors in case pattern is a monochrome bitmap */
138 SetBkColor( hdc, RGB(0,0,0) );
139 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
140 FillRect( hdc, &rect, brush );
143 /* Paint wall paper */
145 if (hbitmapWallPaper)
148 HDC hMemDC = CreateCompatibleDC( hdc );
150 SelectObject( hMemDC, hbitmapWallPaper );
154 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
155 for (x = 0; x < rect.right; x += bitmapSize.cx)
156 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
160 x = (rect.left + rect.right - bitmapSize.cx) / 2;
161 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
164 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
172 /***********************************************************************
173 * OldSetDeskPattern (USER.279)
175 BOOL16 WINAPI SetDeskPattern(void)
178 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
179 return DESKTOP_SetPattern( buffer );
183 /***********************************************************************
184 * SetDeskWallPaper (USER.285)
186 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
188 return SetDeskWallPaper( filename );
192 /***********************************************************************
193 * SetDeskWallPaper (USER32.@)
195 * FIXME: is there a unicode version?
197 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
203 if (filename == (LPSTR)-1)
205 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
209 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
211 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
212 hbitmapWallPaper = hbitmap;
213 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
217 GetObjectA( hbitmap, sizeof(bmp), &bmp );
218 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
219 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
225 /***********************************************************************
228 * Set the desktop pattern.
230 BOOL DESKTOP_SetPattern( LPCSTR pattern )
234 if (hbrushPattern) DeleteObject( hbrushPattern );
235 memset( pat, 0, sizeof(pat) );
236 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
237 &pat[0], &pat[1], &pat[2], &pat[3],
238 &pat[4], &pat[5], &pat[6], &pat[7] ))
244 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
245 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
246 hbrushPattern = CreatePatternBrush( hbitmap );
247 DeleteObject( hbitmap );
249 else hbrushPattern = 0;