ntdll: Add support for rep;ret instruction in function epilogs.
[wine/multimedia.git] / dlls / user32 / desktop.c
blob92ee21ac53310d5eb5d389884b5fe0fc5f8c20af
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 IDC_ARROW, /* cursor */
52 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
56 /***********************************************************************
57 * DESKTOP_LoadBitmap
59 * Load a bitmap from a file. Used by SetDeskWallPaper().
61 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
63 BITMAPFILEHEADER *fileHeader;
64 BITMAPINFO *bitmapInfo;
65 HBITMAP hbitmap;
66 HFILE file;
67 LPSTR buffer;
68 LONG size;
70 /* Read all the file into memory */
72 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
74 UINT len = GetWindowsDirectoryA( NULL, 0 );
75 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
76 len + strlen(filename) + 2 )))
77 return 0;
78 GetWindowsDirectoryA( buffer, len + 1 );
79 strcat( buffer, "\\" );
80 strcat( buffer, filename );
81 file = _lopen( buffer, OF_READ );
82 HeapFree( GetProcessHeap(), 0, buffer );
84 if (file == HFILE_ERROR) return 0;
85 size = _llseek( file, 0, 2 );
86 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
88 _lclose( file );
89 return 0;
91 _llseek( file, 0, 0 );
92 size = _lread( file, buffer, size );
93 _lclose( file );
94 fileHeader = (BITMAPFILEHEADER *)buffer;
95 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
97 /* Check header content */
98 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
100 HeapFree( GetProcessHeap(), 0, buffer );
101 return 0;
103 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
104 buffer + fileHeader->bfOffBits,
105 bitmapInfo, DIB_RGB_COLORS );
106 HeapFree( GetProcessHeap(), 0, buffer );
107 return hbitmap;
112 /***********************************************************************
113 * DesktopWndProc
115 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
117 if (message == WM_NCCREATE) return TRUE;
118 return 0; /* all other messages are ignored */
121 /***********************************************************************
122 * PaintDesktop (USER32.@)
125 BOOL WINAPI PaintDesktop(HDC hdc)
127 HWND hwnd = GetDesktopWindow();
129 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
130 if (GetWindowThreadProcessId( hwnd, NULL ))
132 RECT rect;
134 GetClientRect( hwnd, &rect );
136 /* Paint desktop pattern (only if wall paper does not cover everything) */
138 if (!hbitmapWallPaper ||
139 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
141 HBRUSH brush = hbrushPattern;
142 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
143 /* Set colors in case pattern is a monochrome bitmap */
144 SetBkColor( hdc, RGB(0,0,0) );
145 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
146 FillRect( hdc, &rect, brush );
149 /* Paint wall paper */
151 if (hbitmapWallPaper)
153 INT x, y;
154 HDC hMemDC = CreateCompatibleDC( hdc );
156 SelectObject( hMemDC, hbitmapWallPaper );
158 if (fTileWallPaper)
160 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
161 for (x = 0; x < rect.right; x += bitmapSize.cx)
162 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
164 else
166 x = (rect.left + rect.right - bitmapSize.cx) / 2;
167 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
168 if (x < 0) x = 0;
169 if (y < 0) y = 0;
170 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
172 DeleteDC( hMemDC );
175 return TRUE;
178 /***********************************************************************
179 * SetDeskWallPaper (USER32.@)
181 * FIXME: is there a unicode version?
183 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
185 HBITMAP hbitmap;
186 HDC hdc;
187 char buffer[256];
189 if (filename == (LPSTR)-1)
191 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
192 filename = buffer;
194 hdc = GetDC( 0 );
195 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
196 ReleaseDC( 0, hdc );
197 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
198 hbitmapWallPaper = hbitmap;
199 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
200 if (hbitmap)
202 BITMAP bmp;
203 GetObjectA( hbitmap, sizeof(bmp), &bmp );
204 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
205 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
207 return TRUE;
211 /***********************************************************************
212 * DESKTOP_SetPattern
214 * Set the desktop pattern.
216 BOOL DESKTOP_SetPattern( LPCWSTR pattern )
218 int pat[8];
220 if (hbrushPattern) DeleteObject( hbrushPattern );
221 hbrushPattern = 0;
222 memset( pat, 0, sizeof(pat) );
223 if (pattern)
225 char buffer[64];
226 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
227 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
228 &pat[0], &pat[1], &pat[2], &pat[3],
229 &pat[4], &pat[5], &pat[6], &pat[7] ))
231 WORD ptrn[8];
232 HBITMAP hbitmap;
233 int i;
235 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
236 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
237 hbrushPattern = CreatePatternBrush( hbitmap );
238 DeleteObject( hbitmap );
241 return TRUE;