2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
6 static char Copyright[] = "Copyright Alexandre Julliard, 1994";
20 /***********************************************************************
23 * Load a bitmap from a file. Used by SetDeskWallPaper().
25 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
27 BITMAPFILEHEADER
*fileHeader
;
28 BITMAPINFO
*bitmapInfo
;
31 const char *unixFileName
;
35 /* Read all the file into memory */
37 if (!(unixFileName
= DOSFS_GetUnixFileName( filename
, TRUE
))) 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
);
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
);
117 /***********************************************************************
120 * Window procedure for the desktop window.
122 LRESULT
DesktopWndProc ( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
124 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
125 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
127 /* Most messages are ignored (we DON'T call DefWindowProc) */
131 /* Warning: this message is sent directly by */
132 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
134 infoPtr
->hbrushPattern
= 0;
135 infoPtr
->hbitmapWallPaper
= 0;
137 SetDeskWallPaper( (LPSTR
)-1 );
141 if (rootWindow
== DefaultRootWindow(display
)) return 1;
142 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, infoPtr
);
149 /***********************************************************************
150 * SetDeskPattern (USER.279)
152 BOOL
SetDeskPattern(void)
155 GetProfileString( "desktop", "Pattern", "(None)", buffer
, 100 );
156 return DESKTOP_SetPattern( buffer
);
160 /***********************************************************************
161 * SetDeskWallPaper (USER.285)
163 BOOL
SetDeskWallPaper( LPCSTR filename
)
168 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
169 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
171 if (filename
== (LPSTR
)-1)
173 GetProfileString( "desktop", "WallPaper", "(None)", buffer
, 256 );
177 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
179 if (infoPtr
->hbitmapWallPaper
) DeleteObject( infoPtr
->hbitmapWallPaper
);
180 infoPtr
->hbitmapWallPaper
= hbitmap
;
181 infoPtr
->fTileWallPaper
= GetProfileInt( "desktop", "TileWallPaper", 0 );
185 GetObject( hbitmap
, sizeof(bmp
), (LPSTR
)&bmp
);
186 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
187 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
193 /***********************************************************************
196 * Set the desktop pattern.
198 BOOL
DESKTOP_SetPattern(char *pattern
)
200 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
201 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
204 if (infoPtr
->hbrushPattern
) DeleteObject( infoPtr
->hbrushPattern
);
205 memset( pat
, 0, sizeof(pat
) );
206 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
207 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
208 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
214 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
215 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
216 infoPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
217 DeleteObject( hbitmap
);
219 else infoPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );