2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "wine/winuser16.h"
31 static HBRUSH hbrushPattern
;
32 static HBITMAP hbitmapWallPaper
;
33 static SIZE bitmapSize
;
34 static BOOL fTileWallPaper
;
36 static LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
39 /*********************************************************************
40 * desktop class descriptor
42 const struct builtin_class_descr DESKTOP_builtin_class
=
44 DESKTOP_CLASS_ATOM
, /* name */
45 CS_GLOBALCLASS
, /* style */
46 NULL
, /* procA (winproc is Unicode only) */
47 DesktopWndProc
, /* procW */
49 IDC_ARROWA
, /* cursor */
50 COLOR_BACKGROUND
+1 /* brush */
54 /***********************************************************************
57 * Load a bitmap from a file. Used by SetDeskWallPaper().
59 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
61 BITMAPFILEHEADER
*fileHeader
;
62 BITMAPINFO
*bitmapInfo
;
68 /* Read all the file into memory */
70 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
72 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
73 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
74 len
+ strlen(filename
) + 2 )))
76 GetWindowsDirectoryA( buffer
, len
+ 1 );
77 strcat( buffer
, "\\" );
78 strcat( buffer
, filename
);
79 file
= _lopen( buffer
, OF_READ
);
80 HeapFree( GetProcessHeap(), 0, buffer
);
82 if (file
== HFILE_ERROR
) return 0;
83 size
= _llseek( file
, 0, 2 );
84 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
89 _llseek( file
, 0, 0 );
90 size
= _lread( file
, buffer
, size
);
92 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
93 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
95 /* Check header content */
96 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
98 HeapFree( GetProcessHeap(), 0, buffer
);
101 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
102 buffer
+ fileHeader
->bfOffBits
,
103 bitmapInfo
, DIB_RGB_COLORS
);
104 HeapFree( GetProcessHeap(), 0, buffer
);
110 /***********************************************************************
113 static LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
115 LRESULT retvalue
= 0;
117 if (message
== WM_NCCREATE
)
120 hbitmapWallPaper
= 0;
122 SetDeskWallPaper( (LPSTR
)-1 );
125 /* all other messages are ignored */
129 /***********************************************************************
130 * PaintDesktop (USER32.@)
133 BOOL WINAPI
PaintDesktop(HDC hdc
)
135 HWND hwnd
= GetDesktopWindow();
137 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
138 if (GetWindowThreadProcessId( hwnd
, NULL
))
142 GetClientRect( hwnd
, &rect
);
144 /* Paint desktop pattern (only if wall paper does not cover everything) */
146 if (!hbitmapWallPaper
||
147 (!fTileWallPaper
&& ((bitmapSize
.cx
< rect
.right
) || (bitmapSize
.cy
< rect
.bottom
))))
149 HBRUSH brush
= hbrushPattern
;
150 if (!brush
) brush
= GetClassLongA( hwnd
, GCL_HBRBACKGROUND
);
151 /* Set colors in case pattern is a monochrome bitmap */
152 SetBkColor( hdc
, RGB(0,0,0) );
153 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
154 FillRect( hdc
, &rect
, brush
);
157 /* Paint wall paper */
159 if (hbitmapWallPaper
)
162 HDC hMemDC
= CreateCompatibleDC( hdc
);
164 SelectObject( hMemDC
, hbitmapWallPaper
);
168 for (y
= 0; y
< rect
.bottom
; y
+= bitmapSize
.cy
)
169 for (x
= 0; x
< rect
.right
; x
+= bitmapSize
.cx
)
170 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
174 x
= (rect
.left
+ rect
.right
- bitmapSize
.cx
) / 2;
175 y
= (rect
.top
+ rect
.bottom
- bitmapSize
.cy
) / 2;
178 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
186 /***********************************************************************
187 * OldSetDeskPattern (USER.279)
189 BOOL16 WINAPI
SetDeskPattern(void)
192 GetProfileStringA( "desktop", "Pattern", "(None)", buffer
, 100 );
193 return DESKTOP_SetPattern( buffer
);
197 /***********************************************************************
198 * SetDeskWallPaper (USER.285)
200 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
202 return SetDeskWallPaper( filename
);
206 /***********************************************************************
207 * SetDeskWallPaper (USER32.@)
209 * FIXME: is there a unicode version?
211 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
217 if (filename
== (LPSTR
)-1)
219 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
223 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
225 if (hbitmapWallPaper
) DeleteObject( hbitmapWallPaper
);
226 hbitmapWallPaper
= hbitmap
;
227 fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
231 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
232 bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
233 bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
239 /***********************************************************************
242 * Set the desktop pattern.
244 BOOL
DESKTOP_SetPattern( LPCSTR pattern
)
248 if (hbrushPattern
) DeleteObject( hbrushPattern
);
249 memset( pat
, 0, sizeof(pat
) );
250 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
251 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
252 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
258 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
259 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
260 hbrushPattern
= CreatePatternBrush( hbitmap
);
261 DeleteObject( hbitmap
);
263 else hbrushPattern
= 0;