Fixes to French translation of common dialog messages.
[wine] / controls / desktop.c
1 /*
2  * Desktop window class.
3  *
4  * Copyright 1994 Alexandre Julliard
5  */
6
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10
11 #include "windef.h"
12 #include "wingdi.h"
13 #include "heap.h"
14 #include "user.h"
15 #include "win.h"
16 #include "controls.h"
17 #include "wine/winuser16.h"
18
19 typedef struct
20 {
21     HBRUSH        hbrushPattern;
22     HBITMAP       hbitmapWallPaper;
23     SIZE          bitmapSize;
24     BOOL          fTileWallPaper;
25 } DESKTOP;
26
27 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam );
28
29
30 /*********************************************************************
31  * desktop class descriptor
32  */
33 const struct builtin_class_descr DESKTOP_builtin_class =
34 {
35     DESKTOP_CLASS_ATOM,   /* name */
36     CS_GLOBALCLASS,       /* style */
37     NULL,                 /* procA (winproc is Unicode only) */
38     DesktopWndProc,       /* procW */
39     sizeof(DESKTOP),      /* extra */
40     IDC_ARROWA,           /* cursor */
41     COLOR_BACKGROUND+1    /* brush */
42 };
43
44
45 /***********************************************************************
46  *           DESKTOP_LoadBitmap
47  *
48  * Load a bitmap from a file. Used by SetDeskWallPaper().
49  */
50 static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
51 {
52     BITMAPFILEHEADER *fileHeader;
53     BITMAPINFO *bitmapInfo;
54     HBITMAP hbitmap;
55     HFILE file;
56     LPSTR buffer;
57     LONG size;
58
59     /* Read all the file into memory */
60
61     if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
62     {
63         UINT len = GetWindowsDirectoryA( NULL, 0 );
64         if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
65                                   len + strlen(filename) + 2 )))
66             return 0;
67         GetWindowsDirectoryA( buffer, len + 1 );
68         strcat( buffer, "\\" );
69         strcat( buffer, filename );
70         file = _lopen( buffer, OF_READ );
71         HeapFree( GetProcessHeap(), 0, buffer );
72     }
73     if (file == HFILE_ERROR) return 0;
74     size = _llseek( file, 0, 2 );
75     if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
76     {
77         _lclose( file );
78         return 0;
79     }
80     _llseek( file, 0, 0 );
81     size = _lread( file, buffer, size );
82     _lclose( file );
83     fileHeader = (BITMAPFILEHEADER *)buffer;
84     bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));
85     
86       /* Check header content */
87     if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
88     {
89         HeapFree( GetProcessHeap(), 0, buffer );
90         return 0;
91     }
92     hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
93                                 buffer + fileHeader->bfOffBits,
94                                 bitmapInfo, DIB_RGB_COLORS );
95     HeapFree( GetProcessHeap(), 0, buffer );
96     return hbitmap;
97 }
98
99
100
101 /***********************************************************************
102  *           DesktopWndProc
103  */
104 static LRESULT WINAPI DesktopWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
105 {
106     LRESULT retvalue = 0;
107     WND *wndPtr = WIN_FindWndPtr( hwnd );
108     DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
109
110     if (message == WM_NCCREATE)
111     {
112         desktopPtr->hbrushPattern = 0;
113         desktopPtr->hbitmapWallPaper = 0;
114         SetDeskPattern();
115         SetDeskWallPaper( (LPSTR)-1 );
116         retvalue = 1;
117     }
118     /* all other messages are ignored */
119
120     WIN_ReleaseWndPtr(wndPtr);
121     return retvalue;
122 }
123
124 /***********************************************************************
125  *           PaintDesktop   (USER32.@)
126  *
127  */
128 BOOL WINAPI PaintDesktop(HDC hdc)
129 {
130     HWND hwnd = GetDesktopWindow();
131     WND *wndPtr = WIN_FindWndPtr( hwnd );
132     DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
133
134     /* check for a queue; otherwise don't paint anything (non-desktop mode) */
135     if (wndPtr->hmemTaskQ)
136     {
137         RECT rect;
138
139         GetClientRect( hwnd, &rect );
140
141         /* Paint desktop pattern (only if wall paper does not cover everything) */
142
143         if (!desktopPtr->hbitmapWallPaper ||
144             (!desktopPtr->fTileWallPaper && ((desktopPtr->bitmapSize.cx < rect.right) ||
145                                              (desktopPtr->bitmapSize.cy < rect.bottom))))
146         {
147             HBRUSH brush = desktopPtr->hbrushPattern;
148             if (!brush) brush = GetClassLongA( hwnd, GCL_HBRBACKGROUND );
149             /* Set colors in case pattern is a monochrome bitmap */
150             SetBkColor( hdc, RGB(0,0,0) );
151             SetTextColor( hdc, GetSysColor(COLOR_BACKGROUND) );
152             FillRect( hdc, &rect, brush );
153         }
154
155         /* Paint wall paper */
156
157         if (desktopPtr->hbitmapWallPaper)
158         {
159             INT x, y;
160             HDC hMemDC = CreateCompatibleDC( hdc );
161
162             SelectObject( hMemDC, desktopPtr->hbitmapWallPaper );
163
164             if (desktopPtr->fTileWallPaper)
165             {
166                 for (y = 0; y < rect.bottom; y += desktopPtr->bitmapSize.cy)
167                     for (x = 0; x < rect.right; x += desktopPtr->bitmapSize.cx)
168                         BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
169                                 desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
170             }
171             else
172             {
173                 x = (rect.left + rect.right - desktopPtr->bitmapSize.cx) / 2;
174                 y = (rect.top + rect.bottom - desktopPtr->bitmapSize.cy) / 2;
175                 if (x < 0) x = 0;
176                 if (y < 0) y = 0;
177                 BitBlt( hdc, x, y, desktopPtr->bitmapSize.cx,
178                         desktopPtr->bitmapSize.cy, hMemDC, 0, 0, SRCCOPY );
179             }
180             DeleteDC( hMemDC );
181         }
182     }
183     WIN_ReleaseWndPtr(wndPtr);
184     return TRUE;
185 }
186
187 /***********************************************************************
188  *           OldSetDeskPattern   (USER.279)
189  */
190 BOOL16 WINAPI SetDeskPattern(void)
191 {
192     char buffer[100];
193     GetProfileStringA( "desktop", "Pattern", "(None)", buffer, 100 );
194     return DESKTOP_SetPattern( buffer );
195 }
196
197
198 /***********************************************************************
199  *           SetDeskWallPaper   (USER.285)
200  */
201 BOOL16 WINAPI SetDeskWallPaper16( LPCSTR filename )
202 {
203     return SetDeskWallPaper( filename );
204 }
205
206
207 /***********************************************************************
208  *           SetDeskWallPaper   (USER32.@)
209  *
210  * FIXME: is there a unicode version?
211  */
212 BOOL WINAPI SetDeskWallPaper( LPCSTR filename )
213 {
214     HBITMAP hbitmap;
215     HDC hdc;
216     char buffer[256];
217     WND *wndPtr = WIN_GetDesktop();
218     DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
219
220     if (filename == (LPSTR)-1)
221     {
222         GetProfileStringA( "desktop", "WallPaper", "(None)", buffer, 256 );
223         filename = buffer;
224     }
225     hdc = GetDC( 0 );
226     hbitmap = DESKTOP_LoadBitmap( hdc, filename );
227     ReleaseDC( 0, hdc );
228     if (desktopPtr->hbitmapWallPaper) DeleteObject( desktopPtr->hbitmapWallPaper );
229     desktopPtr->hbitmapWallPaper = hbitmap;
230     desktopPtr->fTileWallPaper = GetProfileIntA( "desktop", "TileWallPaper", 0 );
231     if (hbitmap)
232     {
233         BITMAP bmp;
234         GetObjectA( hbitmap, sizeof(bmp), &bmp );
235         desktopPtr->bitmapSize.cx = (bmp.bmWidth != 0) ? bmp.bmWidth : 1;
236         desktopPtr->bitmapSize.cy = (bmp.bmHeight != 0) ? bmp.bmHeight : 1;
237     }
238     WIN_ReleaseDesktop();
239     return TRUE;
240 }
241
242
243 /***********************************************************************
244  *           DESKTOP_SetPattern
245  *
246  * Set the desktop pattern.
247  */
248 BOOL DESKTOP_SetPattern( LPCSTR pattern )
249 {
250     WND *wndPtr = WIN_GetDesktop();
251     DESKTOP *desktopPtr = (DESKTOP *)wndPtr->wExtra;
252     int pat[8];
253
254     if (desktopPtr->hbrushPattern) DeleteObject( desktopPtr->hbrushPattern );
255     memset( pat, 0, sizeof(pat) );
256     if (pattern && sscanf( pattern, " %d %d %d %d %d %d %d %d",
257                            &pat[0], &pat[1], &pat[2], &pat[3],
258                            &pat[4], &pat[5], &pat[6], &pat[7] ))
259     {
260         WORD pattern[8];
261         HBITMAP hbitmap;
262         int i;
263
264         for (i = 0; i < 8; i++) pattern[i] = pat[i] & 0xffff;
265         hbitmap = CreateBitmap( 8, 8, 1, 1, (LPSTR)pattern );
266         desktopPtr->hbrushPattern = CreatePatternBrush( hbitmap );
267         DeleteObject( hbitmap );
268     }
269     else desktopPtr->hbrushPattern = 0;
270     WIN_ReleaseDesktop();
271     return TRUE;
272 }
273