2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1994";
16 #include "prototypes.h"
18 extern BOOL
GRAPH_DrawBitmap( HDC hdc
, HBITMAP hbitmap
, int xdest
, int ydest
,
19 int xsrc
, int ysrc
, int width
, int height
,
20 int rop
); /* graphics.c */
22 /***********************************************************************
25 * Load a bitmap from a file. Used by SetDeskWallPaper().
27 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, char *filename
)
29 BITMAPFILEHEADER
*fileHeader
;
30 BITMAPINFO
*bitmapInfo
;
32 char *unixFileName
, *buffer
;
36 /* Read all the file into memory */
38 if (!(unixFileName
= GetUnixFileName( filename
))) return 0;
39 if ((file
= open( unixFileName
, O_RDONLY
)) == -1) return 0;
40 size
= lseek( file
, 0, SEEK_END
);
41 if (!(buffer
= (char *)malloc( size
)))
46 lseek( file
, 0, SEEK_SET
);
47 size
= read( file
, buffer
, size
);
49 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
50 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
52 /* Check header content */
53 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
58 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
59 buffer
+ fileHeader
->bfOffBits
,
60 bitmapInfo
, DIB_RGB_COLORS
);
66 /***********************************************************************
67 * DESKTOP_DoEraseBkgnd
69 * Handle the WM_ERASEBKGND message.
71 static LONG
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
, DESKTOPINFO
*infoPtr
)
74 GetClientRect( hwnd
, &rect
);
76 /* Paint desktop pattern (only if wall paper does not cover everything) */
78 if (!infoPtr
->hbitmapWallPaper
||
79 (!infoPtr
->fTileWallPaper
&& (infoPtr
->bitmapSize
.cx
< rect
.right
) &&
80 (infoPtr
->bitmapSize
.cy
< rect
.bottom
)))
82 /* Set colors in case pattern is a monochrome bitmap */
83 SetBkColor( hdc
, RGB(0,0,0) );
84 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
85 FillRect( hdc
, &rect
, infoPtr
->hbrushPattern
);
88 /* Paint wall paper */
90 if (infoPtr
->hbitmapWallPaper
)
94 if (infoPtr
->fTileWallPaper
)
96 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
97 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
98 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
,
100 infoPtr
->bitmapSize
.cx
,
101 infoPtr
->bitmapSize
.cy
, SRCCOPY
);
105 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
106 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
109 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
, x
, y
, 0, 0,
110 infoPtr
->bitmapSize
.cx
, infoPtr
->bitmapSize
.cy
,
119 /***********************************************************************
122 * Window procedure for the desktop window.
124 LONG
DesktopWndProc ( HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
126 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
127 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
129 /* Most messages are ignored (we DON'T call DefWindowProc) */
133 /* Warning: this message is sent directly by */
134 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
136 infoPtr
->hbrushPattern
= 0;
137 infoPtr
->hbitmapWallPaper
= 0;
139 SetDeskWallPaper( (LPSTR
)-1 );
143 if (rootWindow
== DefaultRootWindow(display
)) return 1;
144 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, infoPtr
);
151 /***********************************************************************
152 * SetDeskPattern (USER.279)
154 BOOL
SetDeskPattern()
157 GetProfileString( "desktop", "Pattern", "(None)", buffer
, 100 );
158 return DESKTOP_SetPattern( buffer
);
162 /***********************************************************************
163 * SetDeskWallPaper (USER.285)
165 BOOL
SetDeskWallPaper( LPSTR filename
)
170 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
171 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
173 if (filename
== (LPSTR
)-1)
175 GetProfileString( "desktop", "WallPaper", "(None)", buffer
, 256 );
179 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
181 if (infoPtr
->hbitmapWallPaper
) DeleteObject( infoPtr
->hbitmapWallPaper
);
182 infoPtr
->hbitmapWallPaper
= hbitmap
;
183 infoPtr
->fTileWallPaper
= GetProfileInt( "desktop", "TileWallPaper", 0 );
187 GetObject( hbitmap
, sizeof(bmp
), (LPSTR
)&bmp
);
188 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
189 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
195 /***********************************************************************
198 * Set the desktop pattern.
200 BOOL
DESKTOP_SetPattern(char *pattern
)
202 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
203 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
206 if (infoPtr
->hbrushPattern
) DeleteObject( infoPtr
->hbrushPattern
);
207 memset( pat
, 0, sizeof(pat
) );
208 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
209 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
210 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
216 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
217 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
218 infoPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
219 DeleteObject( hbitmap
);
221 else infoPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );