msvcp90: Return last index in string::find_last_not_of_cstr_substr if input is empty.
[wine.git] / dlls / user32 / desktop.c
blobbc9125235b9db34e557cdcd8016b8e91972fcdd7
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 sprintfW( buffer, guid_formatW, guid->Data1, guid->Data2, guid->Data3,
121 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
122 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
123 atom = GlobalAddAtomW( buffer );
124 SetPropW( hwnd, display_device_guid_propW, ULongToHandle( atom ) );
126 return TRUE;
128 default:
129 return 0; /* all other messages are ignored */
133 /***********************************************************************
134 * PaintDesktop (USER32.@)
137 BOOL WINAPI PaintDesktop(HDC hdc)
139 HWND hwnd = GetDesktopWindow();
141 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
142 if (GetWindowThreadProcessId( hwnd, NULL ))
144 RECT rect;
146 GetClientRect( hwnd, &rect );
148 /* Paint desktop pattern (only if wall paper does not cover everything) */
150 if (!hbitmapWallPaper ||
151 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
153 HBRUSH brush = hbrushPattern;
154 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
155 /* Set colors in case pattern is a monochrome bitmap */
156 SetBkColor( hdc, RGB(0,0,0) );
157 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
158 FillRect( hdc, &rect, brush );
161 /* Paint wall paper */
163 if (hbitmapWallPaper)
165 INT x, y;
166 HDC hMemDC = CreateCompatibleDC( hdc );
168 SelectObject( hMemDC, hbitmapWallPaper );
170 if (fTileWallPaper)
172 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
173 for (x = 0; x < rect.right; x += bitmapSize.cx)
174 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
176 else
178 x = (rect.left + rect.right - bitmapSize.cx) / 2;
179 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
180 if (x < 0) x = 0;
181 if (y < 0) y = 0;
182 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
184 DeleteDC( hMemDC );
187 return TRUE;
190 /***********************************************************************
191 * SetDeskWallPaper (USER32.@)
193 * FIXME: is there a unicode version?
195 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
197 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
201 /***********************************************************************
202 * update_wallpaper
204 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
206 int pat[8];
208 if (hbrushPattern) DeleteObject( hbrushPattern );
209 hbrushPattern = 0;
210 memset( pat, 0, sizeof(pat) );
211 if (pattern)
213 char buffer[64];
214 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
215 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
216 &pat[0], &pat[1], &pat[2], &pat[3],
217 &pat[4], &pat[5], &pat[6], &pat[7] ))
219 WORD ptrn[8];
220 HBITMAP hbitmap;
221 int i;
223 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
224 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
225 hbrushPattern = CreatePatternBrush( hbitmap );
226 DeleteObject( hbitmap );
229 init_wallpaper( wallpaper );
230 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
231 return TRUE;