Change notification fixes.
[wine/hacks.git] / controls / desktop.c
blob9dd5423ad0e5d44c112ff01048892ff9052e4112
1 /*
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
21 #include "config.h"
23 #include <stdio.h>
24 #include <string.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
29 #include "windef.h"
30 #include "wingdi.h"
31 #include "user.h"
32 #include "controls.h"
33 #include "wine/winuser16.h"
35 static HBRUSH hbrushPattern;
36 static HBITMAP hbitmapWallPaper;
37 static SIZE bitmapSize;
38 static BOOL fTileWallPaper;
40 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
43 /*********************************************************************
44 * desktop class descriptor
46 const struct builtin_class_descr DESKTOP_builtin_class =
48 DESKTOP_CLASS_ATOM, /* name */
49 CS_GLOBALCLASS, /* style */
50 NULL, /* procA (winproc is Unicode only) */
51 DesktopWndProc, /* procW */
52 0, /* extra */
53 IDC_ARROWA, /* cursor */
54 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
58 /***********************************************************************
59 * DESKTOP_LoadBitmap
61 * Load a bitmap from a file. Used by SetDeskWallPaper().
63 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
65 BITMAPFILEHEADER *fileHeader;
66 BITMAPINFO *bitmapInfo;
67 HBITMAP hbitmap;
68 HFILE file;
69 LPSTR buffer;
70 LONG size;
72 /* Read all the file into memory */
74 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
76 UINT len = GetWindowsDirectoryA( NULL, 0 );
77 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
78 len + strlen(filename) + 2 )))
79 return 0;
80 GetWindowsDirectoryA( buffer, len + 1 );
81 strcat( buffer, "\\" );
82 strcat( buffer, filename );
83 file = _lopen( buffer, OF_READ );
84 HeapFree( GetProcessHeap(), 0, buffer );
86 if (file == HFILE_ERROR) return 0;
87 size = _llseek( file, 0, 2 );
88 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
90 _lclose( file );
91 return 0;
93 _llseek( file, 0, 0 );
94 size = _lread( file, buffer, size );
95 _lclose( file );
96 fileHeader = (BITMAPFILEHEADER *)buffer;
97 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
99 /* Check header content */
100 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
102 HeapFree( GetProcessHeap(), 0, buffer );
103 return 0;
105 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
106 buffer + fileHeader->bfOffBits,
107 bitmapInfo, DIB_RGB_COLORS );
108 HeapFree( GetProcessHeap(), 0, buffer );
109 return hbitmap;
114 /***********************************************************************
115 * DesktopWndProc
117 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
119 /* all messages are ignored */
120 return 0;
123 /***********************************************************************
124 * PaintDesktop (USER32.@)
127 BOOL WINAPI PaintDesktop(HDC hdc)
129 HWND hwnd = GetDesktopWindow();
131 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
132 if (GetWindowThreadProcessId( hwnd, NULL ))
134 RECT rect;
136 GetClientRect( hwnd, &rect );
138 /* Paint desktop pattern (only if wall paper does not cover everything) */
140 if (!hbitmapWallPaper ||
141 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
143 HBRUSH brush = hbrushPattern;
144 if (!brush) brush = (HBRUSH)GetClassLongA( hwnd, GCL_HBRBACKGROUND );
145 /* Set colors in case pattern is a monochrome bitmap */
146 SetBkColor( hdc, RGB(0,0,0) );
147 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
148 FillRect( hdc, &rect, brush );
151 /* Paint wall paper */
153 if (hbitmapWallPaper)
155 INT x, y;
156 HDC hMemDC = CreateCompatibleDC( hdc );
158 SelectObject( hMemDC, hbitmapWallPaper );
160 if (fTileWallPaper)
162 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
163 for (x = 0; x < rect.right; x += bitmapSize.cx)
164 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
166 else
168 x = (rect.left + rect.right - bitmapSize.cx) / 2;
169 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
170 if (x < 0) x = 0;
171 if (y < 0) y = 0;
172 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
174 DeleteDC( hMemDC );
177 return TRUE;
180 /***********************************************************************
181 * OldSetDeskPattern (USER.279)
183 BOOL16 WINAPI SetDeskPattern(void)
185 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
189 /***********************************************************************
190 * SetDeskWallPaper (USER.285)
192 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
194 return SetDeskWallPaper( filename );
198 /***********************************************************************
199 * SetDeskWallPaper (USER32.@)
201 * FIXME: is there a unicode version?
203 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
205 HBITMAP hbitmap;
206 HDC hdc;
207 char buffer[256];
209 if (filename == (LPSTR)-1)
211 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
212 filename = buffer;
214 hdc = GetDC( 0 );
215 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
216 ReleaseDC( 0, hdc );
217 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
218 hbitmapWallPaper = hbitmap;
219 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
220 if (hbitmap)
222 BITMAP bmp;
223 GetObjectA( hbitmap, sizeof(bmp), &bmp );
224 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
225 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
227 return TRUE;
231 /***********************************************************************
232 * DESKTOP_SetPattern
234 * Set the desktop pattern.
236 BOOL DESKTOP_SetPattern( LPCSTR pattern )
238 int pat[8];
240 if (hbrushPattern) DeleteObject( hbrushPattern );
241 memset( pat, 0, sizeof(pat) );
242 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
243 &pat[0], &pat[1], &pat[2], &pat[3],
244 &pat[4], &pat[5], &pat[6], &pat[7] ))
246 WORD pattern[8];
247 HBITMAP hbitmap;
248 int i;
250 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
251 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
252 hbrushPattern = CreatePatternBrush( hbitmap );
253 DeleteObject( hbitmap );
255 else hbrushPattern = 0;
256 return TRUE;