shell32/autocomplete: Reset the contents of the AutoComplete listbox when hiding it.
[wine.git] / dlls / user32 / desktop.c
blobfe6649446ee180b5fbe57aa7139e0cb99c3ca316
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <string.h>
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winnls.h"
34 #include "controls.h"
35 #include "wine/unicode.h"
37 static HBRUSH hbrushPattern;
38 static HBITMAP hbitmapWallPaper;
39 static SIZE bitmapSize;
40 static BOOL fTileWallPaper;
43 /*********************************************************************
44 * desktop class descriptor
46 const struct builtin_class_descr DESKTOP_builtin_class =
48 (LPCWSTR)DESKTOP_CLASS_ATOM, /* name */
49 CS_DBLCLKS, /* style */
50 WINPROC_DESKTOP, /* proc */
51 0, /* extra */
52 0, /* cursor */
53 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
57 /***********************************************************************
58 * DESKTOP_LoadBitmap
60 static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename )
62 HBITMAP hbitmap;
64 if (!filename[0]) return 0;
65 hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
66 if (!hbitmap)
68 WCHAR buffer[MAX_PATH];
69 UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
70 if (buffer[len - 1] != '\\') buffer[len++] = '\\';
71 lstrcpynW( buffer + len, filename, MAX_PATH - len );
72 hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
74 return hbitmap;
77 /***********************************************************************
78 * init_wallpaper
80 static void init_wallpaper( const WCHAR *wallpaper )
82 HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper );
84 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
85 hbitmapWallPaper = hbitmap;
86 if (hbitmap)
88 BITMAP bmp;
89 GetObjectA( hbitmap, sizeof(bmp), &bmp );
90 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
91 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
92 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
96 /***********************************************************************
97 * DesktopWndProc
99 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
101 static const WCHAR display_device_guid_propW[] = {
102 '_','_','w','i','n','e','_','d','i','s','p','l','a','y','_',
103 'd','e','v','i','c','e','_','g','u','i','d',0 };
104 static const WCHAR guid_formatW[] = {
105 '%','0','8','x','-','%','0','4','x','-','%','0','4','x','-','%','0','2','x','%','0','2','x','-',
106 '%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',0};
108 switch (message)
110 case WM_NCCREATE:
112 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
113 const GUID *guid = cs->lpCreateParams;
115 if (guid)
117 ATOM atom;
118 WCHAR buffer[37];
120 if (GetAncestor( hwnd, GA_PARENT )) return FALSE; /* refuse to create non-desktop window */
122 sprintfW( buffer, guid_formatW, guid->Data1, guid->Data2, guid->Data3,
123 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
124 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
125 atom = GlobalAddAtomW( buffer );
126 SetPropW( hwnd, display_device_guid_propW, ULongToHandle( atom ) );
128 return TRUE;
130 case WM_NCCALCSIZE:
131 return 0;
132 default:
133 return DefWindowProcW( hwnd, message, wParam, lParam );
137 /***********************************************************************
138 * PaintDesktop (USER32.@)
141 BOOL WINAPI PaintDesktop(HDC hdc)
143 HWND hwnd = GetDesktopWindow();
145 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
146 if (GetWindowThreadProcessId( hwnd, NULL ))
148 RECT rect;
150 GetClientRect( hwnd, &rect );
152 /* Paint desktop pattern (only if wall paper does not cover everything) */
154 if (!hbitmapWallPaper ||
155 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
157 HBRUSH brush = hbrushPattern;
158 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
159 /* Set colors in case pattern is a monochrome bitmap */
160 SetBkColor( hdc, RGB(0,0,0) );
161 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
162 FillRect( hdc, &rect, brush );
165 /* Paint wall paper */
167 if (hbitmapWallPaper)
169 INT x, y;
170 HDC hMemDC = CreateCompatibleDC( hdc );
172 SelectObject( hMemDC, hbitmapWallPaper );
174 if (fTileWallPaper)
176 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
177 for (x = 0; x < rect.right; x += bitmapSize.cx)
178 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
180 else
182 x = (rect.left + rect.right - bitmapSize.cx) / 2;
183 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
184 if (x < 0) x = 0;
185 if (y < 0) y = 0;
186 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
188 DeleteDC( hMemDC );
191 return TRUE;
194 /***********************************************************************
195 * SetDeskWallPaper (USER32.@)
197 * FIXME: is there a unicode version?
199 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
201 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
205 /***********************************************************************
206 * update_wallpaper
208 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
210 int pat[8];
212 if (hbrushPattern) DeleteObject( hbrushPattern );
213 hbrushPattern = 0;
214 memset( pat, 0, sizeof(pat) );
215 if (pattern)
217 char buffer[64];
218 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
219 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
220 &pat[0], &pat[1], &pat[2], &pat[3],
221 &pat[4], &pat[5], &pat[6], &pat[7] ))
223 WORD ptrn[8];
224 HBITMAP hbitmap;
225 int i;
227 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
228 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
229 hbrushPattern = CreatePatternBrush( hbitmap );
230 DeleteObject( hbitmap );
233 init_wallpaper( wallpaper );
234 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
235 return TRUE;