In Window SetWindowPos with SWP_HIDEWINDOW does not remove
[wine.git] / controls / desktop.c
blobbb6b64d2ae5b2cb9587ee2ea1597d86595f63187
1 /*
2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include "win.h"
11 #include "desktop.h"
12 #include "heap.h"
13 #include "wine/winuser16.h"
16 /***********************************************************************
17 * DESKTOP_LoadBitmap
19 * Load a bitmap from a file. Used by SetDeskWallPaper().
21 static HBITMAP32 DESKTOP_LoadBitmap( HDC32 hdc, const char *filename )
23 BITMAPFILEHEADER *fileHeader;
24 BITMAPINFO *bitmapInfo;
25 HBITMAP32 hbitmap;
26 HFILE32 file;
27 LPSTR buffer;
28 LONG size;
30 /* Read all the file into memory */
32 if ((file = _lopen32( filename, OF_READ )) == HFILE_ERROR32)
34 UINT32 len = GetWindowsDirectory32A( NULL, 0 );
35 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
36 len + strlen(filename) + 2 )))
37 return 0;
38 GetWindowsDirectory32A( buffer, len + 1 );
39 strcat( buffer, "\\" );
40 strcat( buffer, filename );
41 file = _lopen32( buffer, OF_READ );
42 HeapFree( GetProcessHeap(), 0, buffer );
44 if (file == HFILE_ERROR32) return 0;
45 size = _llseek32( file, 0, 2 );
46 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
48 _lclose32( file );
49 return 0;
51 _llseek32( file, 0, 0 );
52 size = _lread32( file, buffer, size );
53 _lclose32( file );
54 fileHeader = (BITMAPFILEHEADER *)buffer;
55 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
57 /* Check header content */
58 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
60 HeapFree( GetProcessHeap(), 0, buffer );
61 return 0;
63 hbitmap = CreateDIBitmap32( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
64 buffer + fileHeader->bfOffBits,
65 bitmapInfo, DIB_RGB_COLORS );
66 HeapFree( GetProcessHeap(), 0, buffer );
67 return hbitmap;
71 /***********************************************************************
72 * DESKTOP_DoEraseBkgnd
74 * Handle the WM_ERASEBKGND message.
76 static LRESULT DESKTOP_DoEraseBkgnd( HWND32 hwnd, HDC32 hdc,
77 DESKTOPINFO *infoPtr )
79 RECT32 rect;
80 WND* Wnd = WIN_FindWndPtr( hwnd );
82 if (Wnd->hrgnUpdate > 1) DeleteObject32( Wnd->hrgnUpdate );
83 Wnd->hrgnUpdate = 0;
85 GetClientRect32( hwnd, &rect );
87 /* Paint desktop pattern (only if wall paper does not cover everything) */
89 if (!infoPtr->hbitmapWallPaper ||
90 (!infoPtr->fTileWallPaper && ((infoPtr->bitmapSize.cx < rect.right) ||
91 (infoPtr->bitmapSize.cy < rect.bottom))))
93 /* Set colors in case pattern is a monochrome bitmap */
94 SetBkColor32( hdc, RGB(0,0,0) );
95 SetTextColor32( hdc, GetSysColor32(COLOR_BACKGROUND) );
96 FillRect32( hdc, &rect, infoPtr->hbrushPattern );
99 /* Paint wall paper */
101 if (infoPtr->hbitmapWallPaper)
103 INT32 x, y;
104 HDC32 hMemDC = CreateCompatibleDC32( hdc );
106 SelectObject32( hMemDC, infoPtr->hbitmapWallPaper );
108 if (infoPtr->fTileWallPaper)
110 for (y = 0; y < rect.bottom; y += infoPtr->bitmapSize.cy)
111 for (x = 0; x < rect.right; x += infoPtr->bitmapSize.cx)
112 BitBlt32( hdc, x, y, infoPtr->bitmapSize.cx,
113 infoPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
115 else
117 x = (rect.left + rect.right - infoPtr->bitmapSize.cx) / 2;
118 y = (rect.top + rect.bottom - infoPtr->bitmapSize.cy) / 2;
119 if (x < 0) x = 0;
120 if (y < 0) y = 0;
121 BitBlt32( hdc, x, y, infoPtr->bitmapSize.cx,
122 infoPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
124 DeleteDC32( hMemDC );
127 return 1;
131 /***********************************************************************
132 * DesktopWndProc
134 * Window procedure for the desktop window.
136 LRESULT WINAPI DesktopWndProc( HWND32 hwnd, UINT32 message,
137 WPARAM32 wParam, LPARAM lParam )
139 WND *wndPtr = WIN_FindWndPtr( hwnd );
140 DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
142 /* Most messages are ignored (we DON'T call DefWindowProc) */
144 switch(message)
146 /* Warning: this message is sent directly by */
147 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
148 case WM_NCCREATE:
149 infoPtr->hbrushPattern = 0;
150 infoPtr->hbitmapWallPaper = 0;
151 SetDeskPattern();
152 SetDeskWallPaper32( (LPSTR)-1 );
153 return 1;
155 case WM_ERASEBKGND:
156 if (rootWindow == DefaultRootWindow(display)) return 1;
157 return DESKTOP_DoEraseBkgnd( hwnd, (HDC32)wParam, infoPtr );
159 case WM_SYSCOMMAND:
160 if ((wParam & 0xfff0) != SC_CLOSE) return 0;
161 ExitWindows16( 0, 0 );
163 case WM_SETCURSOR:
164 return (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
167 return 0;
170 /***********************************************************************
171 * PaintDesktop (USER32.415)
174 BOOL32 WINAPI PaintDesktop(HDC32 hdc)
176 HWND32 hwnd = GetDesktopWindow32();
177 WND *wndPtr = WIN_FindWndPtr( hwnd );
178 DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
180 return DESKTOP_DoEraseBkgnd( hwnd, hdc, infoPtr );
183 /***********************************************************************
184 * SetDeskPattern (USER.279)
186 BOOL16 WINAPI SetDeskPattern(void)
188 char buffer[100];
189 GetProfileString32A( "desktop", "Pattern", "(None)", buffer, 100 );
190 return DESKTOP_SetPattern( buffer );
194 /***********************************************************************
195 * SetDeskWallPaper16 (USER.285)
197 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
199 return SetDeskWallPaper32( filename );
203 /***********************************************************************
204 * SetDeskWallPaper32 (USER32.475)
206 * FIXME: is there a unicode version?
208 BOOL32 WINAPI SetDeskWallPaper32( LPCSTR filename )
210 HBITMAP32 hbitmap;
211 HDC32 hdc;
212 char buffer[256];
213 WND *wndPtr = WIN_GetDesktop();
214 DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
216 if (filename == (LPSTR)-1)
218 GetProfileString32A( "desktop", "WallPaper", "(None)", buffer, 256 );
219 filename = buffer;
221 hdc = GetDC32( 0 );
222 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
223 ReleaseDC32( 0, hdc );
224 if (infoPtr->hbitmapWallPaper) DeleteObject32( infoPtr->hbitmapWallPaper );
225 infoPtr->hbitmapWallPaper = hbitmap;
226 infoPtr->fTileWallPaper = GetProfileInt32A( "desktop", "TileWallPaper", 0 );
227 if (hbitmap)
229 BITMAP32 bmp;
230 GetObject32A( hbitmap, sizeof(bmp), &bmp );
231 infoPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
232 infoPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
234 return TRUE;
238 /***********************************************************************
239 * DESKTOP_SetPattern
241 * Set the desktop pattern.
243 BOOL32 DESKTOP_SetPattern( LPCSTR pattern )
245 WND *wndPtr = WIN_GetDesktop();
246 DESKTOPINFO *infoPtr = (DESKTOPINFO *)wndPtr->wExtra;
247 int pat[8];
249 if (infoPtr->hbrushPattern) DeleteObject32( infoPtr->hbrushPattern );
250 memset( pat, 0, sizeof(pat) );
251 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
252 &pat[0], &pat[1], &pat[2], &pat[3],
253 &pat[4], &pat[5], &pat[6], &pat[7] ))
255 WORD pattern[8];
256 HBITMAP32 hbitmap;
257 int i;
259 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
260 hbitmap = CreateBitmap32( 8, 8, 1, 1, (LPSTR)pattern );
261 infoPtr->hbrushPattern = CreatePatternBrush32( hbitmap );
262 DeleteObject32( hbitmap );
264 else infoPtr->hbrushPattern = CreateSolidBrush32( GetSysColor32(COLOR_BACKGROUND) );
265 return TRUE;