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
35 #include "wine/winuser16.h"
37 static HBRUSH hbrushPattern
;
38 static HBITMAP hbitmapWallPaper
;
39 static SIZE bitmapSize
;
40 static BOOL fTileWallPaper
;
42 static LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
45 /*********************************************************************
46 * desktop class descriptor
48 const struct builtin_class_descr DESKTOP_builtin_class
=
50 DESKTOP_CLASS_ATOM
, /* name */
51 CS_DBLCLKS
, /* style */
52 NULL
, /* procA (winproc is Unicode only) */
53 DesktopWndProc
, /* procW */
55 IDC_ARROW
, /* cursor */
56 (HBRUSH
)(COLOR_BACKGROUND
+1) /* brush */
60 /***********************************************************************
63 * Load a bitmap from a file. Used by SetDeskWallPaper().
65 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
67 BITMAPFILEHEADER
*fileHeader
;
68 BITMAPINFO
*bitmapInfo
;
74 /* Read all the file into memory */
76 if ((file
= _lopen( filename
, OF_READ
)) == HFILE_ERROR
)
78 UINT len
= GetWindowsDirectoryA( NULL
, 0 );
79 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0,
80 len
+ strlen(filename
) + 2 )))
82 GetWindowsDirectoryA( buffer
, len
+ 1 );
83 strcat( buffer
, "\\" );
84 strcat( buffer
, filename
);
85 file
= _lopen( buffer
, OF_READ
);
86 HeapFree( GetProcessHeap(), 0, buffer
);
88 if (file
== HFILE_ERROR
) return 0;
89 size
= _llseek( file
, 0, 2 );
90 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
95 _llseek( file
, 0, 0 );
96 size
= _lread( file
, buffer
, size
);
98 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
99 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
101 /* Check header content */
102 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
104 HeapFree( GetProcessHeap(), 0, buffer
);
107 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
108 buffer
+ fileHeader
->bfOffBits
,
109 bitmapInfo
, DIB_RGB_COLORS
);
110 HeapFree( GetProcessHeap(), 0, buffer
);
116 /***********************************************************************
119 static LRESULT WINAPI
DesktopWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
121 /* all messages are ignored */
125 /***********************************************************************
126 * PaintDesktop (USER32.@)
129 BOOL WINAPI
PaintDesktop(HDC hdc
)
131 HWND hwnd
= GetDesktopWindow();
133 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
134 if (GetWindowThreadProcessId( hwnd
, NULL
))
138 GetClientRect( hwnd
, &rect
);
140 /* Paint desktop pattern (only if wall paper does not cover everything) */
142 if (!hbitmapWallPaper
||
143 (!fTileWallPaper
&& ((bitmapSize
.cx
< rect
.right
) || (bitmapSize
.cy
< rect
.bottom
))))
145 HBRUSH brush
= hbrushPattern
;
146 if (!brush
) brush
= (HBRUSH
)GetClassLongA( hwnd
, GCL_HBRBACKGROUND
);
147 /* Set colors in case pattern is a monochrome bitmap */
148 SetBkColor( hdc
, RGB(0,0,0) );
149 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
150 FillRect( hdc
, &rect
, brush
);
153 /* Paint wall paper */
155 if (hbitmapWallPaper
)
158 HDC hMemDC
= CreateCompatibleDC( hdc
);
160 SelectObject( hMemDC
, hbitmapWallPaper
);
164 for (y
= 0; y
< rect
.bottom
; y
+= bitmapSize
.cy
)
165 for (x
= 0; x
< rect
.right
; x
+= bitmapSize
.cx
)
166 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
170 x
= (rect
.left
+ rect
.right
- bitmapSize
.cx
) / 2;
171 y
= (rect
.top
+ rect
.bottom
- bitmapSize
.cy
) / 2;
174 BitBlt( hdc
, x
, y
, bitmapSize
.cx
, bitmapSize
.cy
, hMemDC
, 0, 0, SRCCOPY
);
182 /***********************************************************************
183 * OldSetDeskPattern (USER.279)
185 BOOL16 WINAPI
SetDeskPattern(void)
187 return SystemParametersInfoA( SPI_SETDESKPATTERN
, -1, NULL
, FALSE
);
191 /***********************************************************************
192 * SetDeskWallPaper (USER.285)
194 BOOL16 WINAPI
SetDeskWallPaper16( LPCSTR filename
)
196 return SetDeskWallPaper( filename
);
200 /***********************************************************************
201 * SetDeskWallPaper (USER32.@)
203 * FIXME: is there a unicode version?
205 BOOL WINAPI
SetDeskWallPaper( LPCSTR filename
)
211 if (filename
== (LPSTR
)-1)
213 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer
, 256 );
217 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
219 if (hbitmapWallPaper
) DeleteObject( hbitmapWallPaper
);
220 hbitmapWallPaper
= hbitmap
;
221 fTileWallPaper
= GetProfileIntA( "desktop", "TileWallPaper", 0 );
225 GetObjectA( hbitmap
, sizeof(bmp
), &bmp
);
226 bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
227 bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
233 /***********************************************************************
236 * Set the desktop pattern.
238 BOOL
DESKTOP_SetPattern( LPCWSTR pattern
)
242 if (hbrushPattern
) DeleteObject( hbrushPattern
);
244 memset( pat
, 0, sizeof(pat
) );
248 WideCharToMultiByte( CP_ACP
, 0, pattern
, -1, buffer
, sizeof(buffer
), NULL
, NULL
);
249 if (sscanf( buffer
, " %d %d %d %d %d %d %d %d",
250 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
251 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
257 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
258 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
259 hbrushPattern
= CreatePatternBrush( hbitmap
);
260 DeleteObject( hbitmap
);