mshtml: Implement onprogress for XMLHttpRequest.
[wine.git] / dlls / user32 / desktop.c
blobca000972bc418a2d4efdf40ae258e72b0a0790eb
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 <stdarg.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winnls.h"
29 #include "controls.h"
31 static HBRUSH hbrushPattern;
32 static HBITMAP hbitmapWallPaper;
33 static SIZE bitmapSize;
34 static BOOL fTileWallPaper;
37 /*********************************************************************
38 * desktop class descriptor
40 const struct builtin_class_descr DESKTOP_builtin_class =
42 (LPCWSTR)DESKTOP_CLASS_ATOM, /* name */
43 CS_DBLCLKS, /* style */
44 WINPROC_DESKTOP, /* proc */
45 0, /* extra */
46 0, /* cursor */
47 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
51 /***********************************************************************
52 * DESKTOP_LoadBitmap
54 static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename )
56 HBITMAP hbitmap;
58 if (!filename[0]) return 0;
59 hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
60 if (!hbitmap)
62 WCHAR buffer[MAX_PATH];
63 UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
64 if (buffer[len - 1] != '\\') buffer[len++] = '\\';
65 lstrcpynW( buffer + len, filename, MAX_PATH - len );
66 hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
68 return hbitmap;
71 /***********************************************************************
72 * init_wallpaper
74 static void init_wallpaper( const WCHAR *wallpaper )
76 HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper );
78 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
79 hbitmapWallPaper = hbitmap;
80 if (hbitmap)
82 BITMAP bmp;
83 GetObjectA( hbitmap, sizeof(bmp), &bmp );
84 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
85 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
86 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
90 /***********************************************************************
91 * DesktopWndProc
93 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
95 switch (message)
97 case WM_NCCREATE:
98 case WM_NCCALCSIZE:
99 case WM_PARENTNOTIFY:
100 return NtUserMessageCall( hwnd, message, wParam, lParam, 0, NtUserDesktopWindowProc, FALSE );
102 default:
103 if (message < WM_USER)
104 return DefWindowProcW( hwnd, message, wParam, lParam );
105 return NtUserMessageCall( hwnd, message, wParam, lParam, 0, NtUserDesktopWindowProc, FALSE );
109 /***********************************************************************
110 * PaintDesktop (USER32.@)
113 BOOL WINAPI PaintDesktop(HDC hdc)
115 HWND hwnd = GetDesktopWindow();
117 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
118 if (GetWindowThreadProcessId( hwnd, NULL ))
120 RECT rect;
122 GetClientRect( hwnd, &rect );
124 /* Paint desktop pattern (only if wall paper does not cover everything) */
126 if (!hbitmapWallPaper ||
127 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
129 HBRUSH brush = hbrushPattern;
130 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
131 /* Set colors in case pattern is a monochrome bitmap */
132 SetBkColor( hdc, RGB(0,0,0) );
133 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
134 FillRect( hdc, &rect, brush );
137 /* Paint wall paper */
139 if (hbitmapWallPaper)
141 INT x, y;
142 HDC hMemDC = CreateCompatibleDC( hdc );
144 SelectObject( hMemDC, hbitmapWallPaper );
146 if (fTileWallPaper)
148 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
149 for (x = 0; x < rect.right; x += bitmapSize.cx)
150 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
152 else
154 x = (rect.left + rect.right - bitmapSize.cx) / 2;
155 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
156 if (x < 0) x = 0;
157 if (y < 0) y = 0;
158 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
160 DeleteDC( hMemDC );
163 return TRUE;
166 /***********************************************************************
167 * SetDeskWallPaper (USER32.@)
169 * FIXME: is there a unicode version?
171 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
173 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
177 /***********************************************************************
178 * update_wallpaper
180 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
182 int pat[8];
184 if (hbrushPattern) DeleteObject( hbrushPattern );
185 hbrushPattern = 0;
186 memset( pat, 0, sizeof(pat) );
187 if (pattern)
189 char buffer[64];
190 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
191 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
192 &pat[0], &pat[1], &pat[2], &pat[3],
193 &pat[4], &pat[5], &pat[6], &pat[7] ))
195 WORD ptrn[8];
196 HBITMAP hbitmap;
197 int i;
199 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
200 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
201 hbrushPattern = CreatePatternBrush( hbitmap );
202 DeleteObject( hbitmap );
205 init_wallpaper( wallpaper );
206 NtUserRedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
207 return TRUE;