- mostly cleanup after the renaming
[wine/wine64.git] / controls / desktop.c
blob96f5a34882a457ea891dfbe953b47dba07b9605d
1 /*
2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include "x11drv.h"
9 #include <stdio.h>
10 #include <string.h>
11 #include <unistd.h>
13 #include "desktop.h"
14 #include "windef.h"
15 #include "heap.h"
16 #include "monitor.h"
17 #include "win.h"
18 #include "wine/winuser16.h"
20 /***********************************************************************
21 * DESKTOP_GetScreenWidth
23 * Return the width of the screen associated to the current desktop.
25 int DESKTOP_GetScreenWidth()
27 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
28 return MONITOR_GetWidth(pDesktop->pPrimaryMonitor);
31 /***********************************************************************
32 * DESKTOP_GetScreenHeight
34 * Return the height of the screen associated to the current desktop.
36 int DESKTOP_GetScreenHeight()
38 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
39 return MONITOR_GetHeight(pDesktop->pPrimaryMonitor);
42 /***********************************************************************
43 * DESKTOP_GetScreenDepth
45 * Return the depth of the screen associated to the current desktop.
47 int DESKTOP_GetScreenDepth()
49 DESKTOP *pDesktop = (DESKTOP *) WIN_GetDesktop()->wExtra;
50 return MONITOR_GetDepth(pDesktop->pPrimaryMonitor);
53 /***********************************************************************
54 * DESKTOP_LoadBitmap
56 * Load a bitmap from a file. Used by SetDeskWallPaper().
58 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
60 BITMAPFILEHEADER *fileHeader;
61 BITMAPINFO *bitmapInfo;
62 HBITMAP hbitmap;
63 HFILE file;
64 LPSTR buffer;
65 LONG size;
67 /* Read all the file into memory */
69 if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
71 UINT len = GetWindowsDirectoryA( NULL, 0 );
72 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
73 len + strlen(filename) + 2 )))
74 return 0;
75 GetWindowsDirectoryA( buffer, len + 1 );
76 strcat( buffer, "\\" );
77 strcat( buffer, filename );
78 file = _lopen( buffer, OF_READ );
79 HeapFree( GetProcessHeap(), 0, buffer );
81 if (file == HFILE_ERROR) return 0;
82 size = _llseek( file, 0, 2 );
83 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
85 _lclose( file );
86 return 0;
88 _llseek( file, 0, 0 );
89 size = _lread( file, buffer, size );
90 _lclose( file );
91 fileHeader = (BITMAPFILEHEADER *)buffer;
92 bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
94 /* Check header content */
95 if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
97 HeapFree( GetProcessHeap(), 0, buffer );
98 return 0;
100 hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
101 buffer + fileHeader->bfOffBits,
102 bitmapInfo, DIB_RGB_COLORS );
103 HeapFree( GetProcessHeap(), 0, buffer );
104 return hbitmap;
108 /***********************************************************************
109 * DESKTOP_DoEraseBkgnd
111 * Handle the WM_ERASEBKGND message.
113 static LRESULT DESKTOP_DoEraseBkgnd( HWND hwnd, HDC hdc,
114 DESKTOP *desktopPtr )
116 RECT rect;
117 WND* Wnd = WIN_FindWndPtr( hwnd );
119 if (Wnd->hrgnUpdate > 1) DeleteObject( Wnd->hrgnUpdate );
120 Wnd->hrgnUpdate = 0;
122 GetClientRect( hwnd, &rect );
124 /* Paint desktop pattern (only if wall paper does not cover everything) */
126 if (!desktopPtr->hbitmapWallPaper ||
127 (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
128 (desktopPtr->bitmapSize.cy < rect.bottom))))
130 /* Set colors in case pattern is a monochrome bitmap */
131 SetBkColor( hdc, RGB(0,0,0) );
132 SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
133 FillRect( hdc, &rect, desktopPtr->hbrushPattern );
136 /* Paint wall paper */
138 if (desktopPtr->hbitmapWallPaper)
140 INT x, y;
141 HDC hMemDC = CreateCompatibleDC( hdc );
143 SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
145 if (desktopPtr->fTileWallPaper)
147 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
148 for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
149 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
150 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
152 else
154 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
155 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
156 if (x < 0) x = 0;
157 if (y < 0) y = 0;
158 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
159 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
161 DeleteDC( hMemDC );
164 return 1;
168 /***********************************************************************
169 * DesktopWndProc
171 * Window procedure for the desktop window.
173 LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message,
174 WPARAM wParam, LPARAM lParam )
176 WND *wndPtr = WIN_FindWndPtr( hwnd );
177 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
179 /* Most messages are ignored (we DON'T call DefWindowProc) */
181 switch(message)
183 /* Warning: this message is sent directly by */
184 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
185 case WM_NCCREATE:
186 desktopPtr->hbrushPattern = 0;
187 desktopPtr->hbitmapWallPaper = 0;
188 SetDeskPattern();
189 SetDeskWallPaper( (LPSTR)-1 );
190 return 1;
192 case WM_ERASEBKGND:
193 if (X11DRV_WND_GetXRootWindow(wndPtr) ==
194 DefaultRootWindow(display))
195 return 1;
196 return DESKTOP_DoEraseBkgnd( hwnd, (HDC)wParam, desktopPtr );
198 case WM_SYSCOMMAND:
199 if ((wParam & 0xfff0) != SC_CLOSE) return 0;
200 ExitWindows16( 0, 0 );
202 case WM_SETCURSOR:
203 return (LRESULT)SetCursor16( LoadCursor16( 0, IDC_ARROW16 ) );
206 return 0;
209 /***********************************************************************
210 * PaintDesktop (USER32.415)
213 BOOL WINAPI PaintDesktop(HDC hdc)
215 HWND hwnd = GetDesktopWindow();
216 WND *wndPtr = WIN_FindWndPtr( hwnd );
217 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
219 return DESKTOP_DoEraseBkgnd( hwnd, hdc, desktopPtr );
222 /***********************************************************************
223 * SetDeskPattern (USER.279)
225 BOOL16 WINAPI SetDeskPattern(void)
227 char buffer[100];
228 GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
229 return DESKTOP_SetPattern( buffer );
233 /***********************************************************************
234 * SetDeskWallPaper16 (USER.285)
236 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
238 return SetDeskWallPaper( filename );
242 /***********************************************************************
243 * SetDeskWallPaper32 (USER32.475)
245 * FIXME: is there a unicode version?
247 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
249 HBITMAP hbitmap;
250 HDC hdc;
251 char buffer[256];
252 WND *wndPtr = WIN_GetDesktop();
253 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
255 if (filename == (LPSTR)-1)
257 GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
258 filename = buffer;
260 hdc = GetDC( 0 );
261 hbitmap = DESKTOP_LoadBitmap( hdc, filename );
262 ReleaseDC( 0, hdc );
263 if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
264 desktopPtr->hbitmapWallPaper = hbitmap;
265 desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
266 if (hbitmap)
268 BITMAP bmp;
269 GetObjectA( hbitmap, sizeof(bmp), &bmp );
270 desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
271 desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
273 return TRUE;
277 /***********************************************************************
278 * DESKTOP_SetPattern
280 * Set the desktop pattern.
282 BOOL DESKTOP_SetPattern( LPCSTR pattern )
284 WND *wndPtr = WIN_GetDesktop();
285 DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
286 int pat[8];
288 if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
289 memset( pat, 0, sizeof(pat) );
290 if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
291 &pat[0], &pat[1], &pat[2], &pat[3],
292 &pat[4], &pat[5], &pat[6], &pat[7] ))
294 WORD pattern[8];
295 HBITMAP hbitmap;
296 int i;
298 for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
299 hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
300 desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
301 DeleteObject( hbitmap );
303 else desktopPtr->hbrushPattern = CreateSolidBrush( GetSysColor(COLOR_BACKGROUND) );
304 return TRUE;