user32: Register classes once the graphics driver has been loaded, except for the...
[wine.git] / dlls / user32 / desktop.c
blob563a214d7b1f9cebb7f3ac32267aead1f272fb75
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"
36 static HBRUSH hbrushPattern;
37 static HBITMAP hbitmapWallPaper;
38 static SIZE bitmapSize;
39 static BOOL fTileWallPaper;
42 /*********************************************************************
43 * desktop class descriptor
45 const struct builtin_class_descr DESKTOP_builtin_class =
47 (LPCWSTR)DESKTOP_CLASS_ATOM, /* name */
48 CS_DBLCLKS, /* style */
49 WINPROC_DESKTOP, /* proc */
50 0, /* extra */
51 0, /* cursor */
52 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
56 /***********************************************************************
57 * DESKTOP_LoadBitmap
59 static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename )
61 HBITMAP hbitmap;
63 if (!filename[0]) return 0;
64 hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
65 if (!hbitmap)
67 WCHAR buffer[MAX_PATH];
68 UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
69 if (buffer[len - 1] != '\\') buffer[len++] = '\\';
70 lstrcpynW( buffer + len, filename, MAX_PATH - len );
71 hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
73 return hbitmap;
76 /***********************************************************************
77 * init_wallpaper
79 static void init_wallpaper( const WCHAR *wallpaper )
81 HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper );
83 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
84 hbitmapWallPaper = hbitmap;
85 if (hbitmap)
87 BITMAP bmp;
88 GetObjectA( hbitmap, sizeof(bmp), &bmp );
89 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
90 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
91 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
95 /***********************************************************************
96 * DesktopWndProc
98 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
100 if (message == WM_NCCREATE) return TRUE;
101 return 0; /* all other messages are ignored */
104 /***********************************************************************
105 * PaintDesktop (USER32.@)
108 BOOL WINAPI PaintDesktop(HDC hdc)
110 HWND hwnd = GetDesktopWindow();
112 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
113 if (GetWindowThreadProcessId( hwnd, NULL ))
115 RECT rect;
117 GetClientRect( hwnd, &rect );
119 /* Paint desktop pattern (only if wall paper does not cover everything) */
121 if (!hbitmapWallPaper ||
122 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
124 HBRUSH brush = hbrushPattern;
125 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
126 /* Set colors in case pattern is a monochrome bitmap */
127 SetBkColor( hdc, RGB(0,0,0) );
128 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
129 FillRect( hdc, &rect, brush );
132 /* Paint wall paper */
134 if (hbitmapWallPaper)
136 INT x, y;
137 HDC hMemDC = CreateCompatibleDC( hdc );
139 SelectObject( hMemDC, hbitmapWallPaper );
141 if (fTileWallPaper)
143 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
144 for (x = 0; x < rect.right; x += bitmapSize.cx)
145 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
147 else
149 x = (rect.left + rect.right - bitmapSize.cx) / 2;
150 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
151 if (x < 0) x = 0;
152 if (y < 0) y = 0;
153 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
155 DeleteDC( hMemDC );
158 return TRUE;
161 /***********************************************************************
162 * SetDeskWallPaper (USER32.@)
164 * FIXME: is there a unicode version?
166 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
168 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
172 /***********************************************************************
173 * update_wallpaper
175 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
177 int pat[8];
179 if (hbrushPattern) DeleteObject( hbrushPattern );
180 hbrushPattern = 0;
181 memset( pat, 0, sizeof(pat) );
182 if (pattern)
184 char buffer[64];
185 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
186 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
187 &pat[0], &pat[1], &pat[2], &pat[3],
188 &pat[4], &pat[5], &pat[6], &pat[7] ))
190 WORD ptrn[8];
191 HBITMAP hbitmap;
192 int i;
194 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
195 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
196 hbrushPattern = CreatePatternBrush( hbitmap );
197 DeleteObject( hbitmap );
200 init_wallpaper( wallpaper );
201 RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
202 return TRUE;