dmime/tests: Test tempo track Play and DMUS_PMSGT_TEMPO messages.
[wine.git] / dlls / user32 / desktop.c
blobb0384b6d8c2514eb3e6591e6c7bbc4f1acbfc7b9
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_LoadBitmap
40 static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename )
42 HBITMAP hbitmap;
44 if (!filename[0]) return 0;
45 hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
46 if (!hbitmap)
48 WCHAR buffer[MAX_PATH];
49 UINT len = GetWindowsDirectoryW( buffer, MAX_PATH - 2 );
50 if (buffer[len - 1] != '\\') buffer[len++] = '\\';
51 lstrcpynW( buffer + len, filename, MAX_PATH - len );
52 hbitmap = LoadImageW( 0, buffer, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );
54 return hbitmap;
57 /***********************************************************************
58 * init_wallpaper
60 static void init_wallpaper( const WCHAR *wallpaper )
62 HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper );
64 if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper );
65 hbitmapWallPaper = hbitmap;
66 if (hbitmap)
68 BITMAP bmp;
69 GetObjectA( hbitmap, sizeof(bmp), &bmp );
70 bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
71 bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
72 fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
76 /***********************************************************************
77 * DesktopWndProc
79 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
81 switch (message)
83 case WM_NCCREATE:
84 case WM_NCCALCSIZE:
85 case WM_PARENTNOTIFY:
86 case WM_DISPLAYCHANGE:
87 return NtUserMessageCall( hwnd, message, wParam, lParam, 0, NtUserDesktopWindowProc, FALSE );
89 default:
90 if (message < WM_USER)
91 return DefWindowProcW( hwnd, message, wParam, lParam );
92 return NtUserMessageCall( hwnd, message, wParam, lParam, 0, NtUserDesktopWindowProc, FALSE );
96 /***********************************************************************
97 * PaintDesktop (USER32.@)
100 BOOL WINAPI PaintDesktop(HDC hdc)
102 HWND hwnd = GetDesktopWindow();
104 /* check for an owning thread; otherwise don't paint anything (non-desktop mode) */
105 if (GetWindowThreadProcessId( hwnd, NULL ))
107 RECT rect;
109 GetClientRect( hwnd, &rect );
111 /* Paint desktop pattern (only if wall paper does not cover everything) */
113 if (!hbitmapWallPaper ||
114 (!fTileWallPaper && ((bitmapSize.cx < rect.right) || (bitmapSize.cy < rect.bottom))))
116 HBRUSH brush = hbrushPattern;
117 if (!brush) brush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
118 /* Set colors in case pattern is a monochrome bitmap */
119 SetBkColor( hdc, RGB(0,0,0) );
120 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
121 FillRect( hdc, &rect, brush );
124 /* Paint wall paper */
126 if (hbitmapWallPaper)
128 INT x, y;
129 HDC hMemDC = CreateCompatibleDC( hdc );
131 SelectObject( hMemDC, hbitmapWallPaper );
133 if (fTileWallPaper)
135 for (y = 0; y < rect.bottom; y += bitmapSize.cy)
136 for (x = 0; x < rect.right; x += bitmapSize.cx)
137 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
139 else
141 x = (rect.left + rect.right - bitmapSize.cx) / 2;
142 y = (rect.top + rect.bottom - bitmapSize.cy) / 2;
143 if (x < 0) x = 0;
144 if (y < 0) y = 0;
145 BitBlt( hdc, x, y, bitmapSize.cx, bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
147 DeleteDC( hMemDC );
150 return TRUE;
153 /***********************************************************************
154 * SetDeskWallPaper (USER32.@)
156 * FIXME: is there a unicode version?
158 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
160 return SystemParametersInfoA( SPI_SETDESKWALLPAPER, MAX_PATH, (void *)filename, SPIF_UPDATEINIFILE );
164 /***********************************************************************
165 * update_wallpaper
167 BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern )
169 int pat[8];
171 if (hbrushPattern) DeleteObject( hbrushPattern );
172 hbrushPattern = 0;
173 memset( pat, 0, sizeof(pat) );
174 if (pattern)
176 char buffer[64];
177 WideCharToMultiByte( CP_ACP, 0, pattern, -1, buffer, sizeof(buffer), NULL, NULL );
178 if (sscanf( buffer, " %d %d %d %d %d %d %d %d",
179 &pat[0], &pat[1], &pat[2], &pat[3],
180 &pat[4], &pat[5], &pat[6], &pat[7] ))
182 WORD ptrn[8];
183 HBITMAP hbitmap;
184 int i;
186 for (i = 0; i < 8; i++) ptrn[i] = pat[i] & 0xffff;
187 hbitmap = CreateBitmap( 8, 8, 1, 1, ptrn );
188 hbrushPattern = CreatePatternBrush( hbitmap );
189 DeleteObject( hbitmap );
192 init_wallpaper( wallpaper );
193 NtUserRedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN );
194 return TRUE;