2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1994";
15 #include "prototypes.h"
17 extern BOOL
GRAPH_DrawBitmap( HDC hdc
, HBITMAP hbitmap
, int xdest
, int ydest
,
18 int xsrc
, int ysrc
, int width
, int height
,
19 int rop
); /* graphics.c */
21 /***********************************************************************
24 * Load a bitmap from a file. Used by SetDeskWallPaper().
26 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, char *filename
)
28 BITMAPFILEHEADER
*fileHeader
;
29 BITMAPINFO
*bitmapInfo
;
31 char *unixFileName
, *buffer
;
35 /* Read all the file into memory */
37 if (!(unixFileName
= GetUnixFileName( filename
))) return 0;
38 if ((file
= open( unixFileName
, O_RDONLY
)) == -1) return 0;
39 size
= lseek( file
, 0, SEEK_END
);
40 if (!(buffer
= (char *)malloc( size
)))
45 lseek( file
, 0, SEEK_SET
);
46 size
= read( file
, buffer
, size
);
48 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
49 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
51 /* Check header content */
52 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
57 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
58 buffer
+ fileHeader
->bfOffBits
,
59 bitmapInfo
, DIB_RGB_COLORS
);
65 /***********************************************************************
66 * DESKTOP_DoEraseBkgnd
68 * Handle the WM_ERASEBKGND message.
70 static LONG
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
, DESKTOPINFO
*infoPtr
)
73 GetClientRect( hwnd
, &rect
);
75 /* Paint desktop pattern (only if wall paper does not cover everything) */
77 if (!infoPtr
->hbitmapWallPaper
||
78 (!infoPtr
->fTileWallPaper
&& (infoPtr
->bitmapSize
.cx
< rect
.right
) &&
79 (infoPtr
->bitmapSize
.cy
< rect
.bottom
)))
81 /* Set colors in case pattern is a monochrome bitmap */
82 SetBkColor( hdc
, RGB(0,0,0) );
83 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
84 FillRect( hdc
, &rect
, infoPtr
->hbrushPattern
);
87 /* Paint wall paper */
89 if (infoPtr
->hbitmapWallPaper
)
93 if (infoPtr
->fTileWallPaper
)
95 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
96 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
97 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
,
99 infoPtr
->bitmapSize
.cx
,
100 infoPtr
->bitmapSize
.cy
, SRCCOPY
);
104 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
105 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
108 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
, x
, y
, 0, 0,
109 infoPtr
->bitmapSize
.cx
, infoPtr
->bitmapSize
.cy
,
118 /***********************************************************************
121 * Window procedure for the desktop window.
123 LONG
DesktopWndProc ( HWND hwnd
, WORD message
, WORD wParam
, LONG lParam
)
125 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
126 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
128 /* Most messages are ignored (we DON'T call DefWindowProc) */
132 /* Warning: this message is sent directly by */
133 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
135 infoPtr
->hbrushPattern
= 0;
136 infoPtr
->hbitmapWallPaper
= 0;
138 SetDeskWallPaper( (LPSTR
)-1 );
142 if (rootWindow
== DefaultRootWindow(display
)) return 1;
143 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, infoPtr
);
150 /***********************************************************************
151 * SetDeskPattern (USER.279)
153 BOOL
SetDeskPattern()
156 GetProfileString( "desktop", "Pattern", "(None)", buffer
, 100 );
157 return DESKTOP_SetPattern( buffer
);
161 /***********************************************************************
162 * SetDeskWallPaper (USER.285)
164 BOOL
SetDeskWallPaper( LPSTR filename
)
169 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
170 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
172 if (filename
== (LPSTR
)-1)
174 GetProfileString( "desktop", "WallPaper", "(None)", buffer
, 256 );
178 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
180 if (infoPtr
->hbitmapWallPaper
) DeleteObject( infoPtr
->hbitmapWallPaper
);
181 infoPtr
->hbitmapWallPaper
= hbitmap
;
182 infoPtr
->fTileWallPaper
= GetProfileInt( "desktop", "TileWallPaper", 0 );
186 GetObject( hbitmap
, sizeof(bmp
), (LPSTR
)&bmp
);
187 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
188 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
194 /***********************************************************************
197 * Set the desktop pattern.
199 BOOL
DESKTOP_SetPattern(char *pattern
)
201 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
202 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
205 if (infoPtr
->hbrushPattern
) DeleteObject( infoPtr
->hbrushPattern
);
206 memset( pat
, 0, sizeof(pat
) );
207 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
208 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
209 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
215 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
216 hbitmap
= CreateBitmap( 8, 8, 1, 1, pattern
);
217 infoPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
218 DeleteObject( hbitmap
);
220 else infoPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );