Merge the non-obsolete bits from wine.texinfo into the Wine Developers
[wine/multimedia.git] / controls / desktop.c
blob10fc475241cf5321d4a9e2b271eddf1fadd20a8f
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "user.h"
34 #include "controls.h"
35 #include "wine/winuser16.h"
37 static HBRUSH hbrushPattern;
38 static HBITMAP hbitmapWallPaper;
39 static SIZE bitmapSize;
40 static BOOL fTileWallPaper;
42 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
45 /*********************************************************************
46 * desktop class descriptor
48 const struct builtin_class_descr DESKTOP_builtin_class =
50 DESKTOP_CLASS_ATOM, /* name */
51 CS_GLOBALCLASS, /* style */
52 NULL, /* procA (winproc is Unicode only) */
53 DesktopWndProc, /* procW */
54 0, /* extra */
55 IDC_ARROW, /* cursor */
56 (HBRUSH)(COLOR_BACKGROUND+1) /* brush */
60 /***********************************************************************
61 * DESKTOP_LoadBitmap
63 * Load a bitmap from a file. Used by SetDeskWallPaper().
65 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
67 BITMAPFILEHEADER *fileHeader;
68 BITMAPINFO *bitmapInfo;
69 HBITMAP hbitmap;
70 HFILE file;
71 LPSTR buffer;
72 LONG size;
74 /* Read all the file into memory */
76 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
78 UINT len = GetWindowsDirectoryA( NULL, 0 );
79 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
80 len + strlen(filename) + 2 )))
81 return 0;
82 GetWindowsDirectoryA( buffer, len + 1 );
83 strcat( buffer, "\\" );
84 strcat( buffer, filename );
85 file = _lopen( buffer, OF_READ );
86 HeapFree( GetProcessHeap(), 0, buffer );
88 if (file == HFILE_ERROR) return 0;
89 size = _llseek( file, 0, 2 );
90 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
92 _lclose( file );
93 return 0;
95 _llseek( file, 0, 0 );
96 size = _lread( file, buffer, size );
97 _lclose( file );
98 fileHeader = (BITMAPFILEHEADER *)buffer;
99 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
101 /* Check header content */
102 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
104 HeapFree( GetProcessHeap(), 0, buffer );
105 return 0;
107 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
108 buffer + fileHeader->bfOffBits,
109 bitmapInfo, DIB_RGB_COLORS );
110 HeapFree( GetProcessHeap(), 0, buffer );
111 return hbitmap;
116 /***********************************************************************
117 * DesktopWndProc
119 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
121 /* all messages are ignored */
122 return 0;
125 /***********************************************************************
126 * PaintDesktop (USER32.@)
129 BOOL WINAPI PaintDesktop(HDC hdc)
131 HWND hwnd = GetDesktopWindow();
133 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
134 if (GetWindowThreadProcessId( hwnd, NULL ))
136 RECT rect;
138 GetClientRect( hwnd, &rect );
140 /* Paint desktop pattern (only if wall paper does not cover everything) */
142 if (!hbitmapWallPaper ||
143 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
145 HBRUSH brush = hbrushPattern;
146 if (!brush) brush = (HBRUSH)GetClassLongA( hwnd, GCL_HBRBACKGROUND );
147 /* Set colors in case pattern is a monochrome bitmap */
148 SetBkColor( hdc, RGB(0,0,0) );
149 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
150 FillRect( hdc, &rect, brush );
153 /* Paint wall paper */
155 if (hbitmapWallPaper)
157 INT x, y;
158 HDC hMemDC = CreateCompatibleDC( hdc );
160 SelectObject( hMemDC, hbitmapWallPaper );
162 if (fTileWallPaper)
164 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
165 for (x = 0; x < rect.right; x += bitmapSize.cx)
166 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
168 else
170 x = (rect.left + rect.right - bitmapSize.cx) / 2;
171 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
172 if (x < 0) x = 0;
173 if (y < 0) y = 0;
174 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
176 DeleteDC( hMemDC );
179 return TRUE;
182 /***********************************************************************
183 * OldSetDeskPattern (USER.279)
185 BOOL16 WINAPI SetDeskPattern(void)
187 return SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE );
191 /***********************************************************************
192 * SetDeskWallPaper (USER.285)
194 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
196 return SetDeskWallPaper( filename );
200 /***********************************************************************
201 * SetDeskWallPaper (USER32.@)
203 * FIXME: is there a unicode version?
205 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
207 HBITMAP hbitmap;
208 HDC hdc;
209 char buffer[256];
211 if (filename == (LPSTR)-1)
213 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
214 filename = buffer;
216 hdc = GetDC( 0 );
217 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
218 ReleaseDC( 0, hdc );
219 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
220 hbitmapWallPaper = hbitmap;
221 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
222 if (hbitmap)
224 BITMAP bmp;
225 GetObjectA( hbitmap, sizeof(bmp), &bmp );
226 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
227 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
229 return TRUE;
233 /***********************************************************************
234 * DESKTOP_SetPattern
236 * Set the desktop pattern.
238 BOOL DESKTOP_SetPattern( LPCSTR pattern )
240 int pat[8];
242 if (hbrushPattern) DeleteObject( hbrushPattern );
243 memset( pat, 0, sizeof(pat) );
244 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
245 &pat[0], &pat[1], &pat[2], &pat[3],
246 &pat[4], &pat[5], &pat[6], &pat[7] ))
248 WORD pattern[8];
249 HBITMAP hbitmap;
250 int i;
252 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
253 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
254 hbrushPattern = CreatePatternBrush( hbitmap );
255 DeleteObject( hbitmap );
257 else hbrushPattern = 0;
258 return TRUE;