2 * Desktop window class.
4 * Copyright 1994 Alexandre Julliard
14 #include "directory.h"
19 /***********************************************************************
22 * Load a bitmap from a file. Used by SetDeskWallPaper().
24 static HBITMAP
DESKTOP_LoadBitmap( HDC hdc
, const char *filename
)
26 BITMAPFILEHEADER
*fileHeader
;
27 BITMAPINFO
*bitmapInfo
;
30 const char *unixFileName
;
34 /* Read all the file into memory */
36 if (!(unixFileName
= DOSFS_GetUnixFileName( filename
, TRUE
)))
38 int len
= DIR_GetWindowsUnixDir( NULL
, 0 );
39 if (!(buffer
= malloc( len
+ strlen(filename
) + 2 ))) return 0;
40 DIR_GetWindowsUnixDir( buffer
, len
+ 1 );
41 strcat( buffer
, "/" );
42 strcat( buffer
, filename
);
43 unixFileName
= DOSFS_GetUnixFileName( buffer
, TRUE
);
45 if (!unixFileName
) return 0;
47 if ((file
= open( unixFileName
, O_RDONLY
)) == -1) return 0;
48 size
= lseek( file
, 0, SEEK_END
);
49 if (!(buffer
= (char *)malloc( size
)))
54 lseek( file
, 0, SEEK_SET
);
55 size
= read( file
, buffer
, size
);
57 fileHeader
= (BITMAPFILEHEADER
*)buffer
;
58 bitmapInfo
= (BITMAPINFO
*)(buffer
+ sizeof(BITMAPFILEHEADER
));
60 /* Check header content */
61 if ((fileHeader
->bfType
!= 0x4d42) || (size
< fileHeader
->bfSize
))
66 hbitmap
= CreateDIBitmap( hdc
, &bitmapInfo
->bmiHeader
, CBM_INIT
,
67 buffer
+ fileHeader
->bfOffBits
,
68 bitmapInfo
, DIB_RGB_COLORS
);
74 /***********************************************************************
75 * DESKTOP_DoEraseBkgnd
77 * Handle the WM_ERASEBKGND message.
79 static LONG
DESKTOP_DoEraseBkgnd( HWND hwnd
, HDC hdc
, DESKTOPINFO
*infoPtr
)
82 GetClientRect16( hwnd
, &rect
);
84 /* Paint desktop pattern (only if wall paper does not cover everything) */
86 if (!infoPtr
->hbitmapWallPaper
||
87 (!infoPtr
->fTileWallPaper
&& ((infoPtr
->bitmapSize
.cx
< rect
.right
) ||
88 (infoPtr
->bitmapSize
.cy
< rect
.bottom
))))
90 /* Set colors in case pattern is a monochrome bitmap */
91 SetBkColor( hdc
, RGB(0,0,0) );
92 SetTextColor( hdc
, GetSysColor(COLOR_BACKGROUND
) );
93 FillRect16( hdc
, &rect
, infoPtr
->hbrushPattern
);
96 /* Paint wall paper */
98 if (infoPtr
->hbitmapWallPaper
)
102 if (infoPtr
->fTileWallPaper
)
104 for (y
= 0; y
< rect
.bottom
; y
+= infoPtr
->bitmapSize
.cy
)
105 for (x
= 0; x
< rect
.right
; x
+= infoPtr
->bitmapSize
.cx
)
106 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
,
108 infoPtr
->bitmapSize
.cx
,
109 infoPtr
->bitmapSize
.cy
);
113 x
= (rect
.left
+ rect
.right
- infoPtr
->bitmapSize
.cx
) / 2;
114 y
= (rect
.top
+ rect
.bottom
- infoPtr
->bitmapSize
.cy
) / 2;
117 GRAPH_DrawBitmap( hdc
, infoPtr
->hbitmapWallPaper
, x
, y
, 0, 0,
118 infoPtr
->bitmapSize
.cx
, infoPtr
->bitmapSize
.cy
);
126 /***********************************************************************
129 * Window procedure for the desktop window.
131 LRESULT
DesktopWndProc( HWND32 hwnd
, UINT32 message
,
132 WPARAM32 wParam
, LPARAM lParam
)
134 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
135 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
137 /* Most messages are ignored (we DON'T call DefWindowProc) */
141 /* Warning: this message is sent directly by */
142 /* WIN_CreateDesktopWindow() and does not contain a valid lParam */
144 infoPtr
->hbrushPattern
= 0;
145 infoPtr
->hbitmapWallPaper
= 0;
147 SetDeskWallPaper( (LPSTR
)-1 );
151 if (rootWindow
== DefaultRootWindow(display
)) return 1;
152 return DESKTOP_DoEraseBkgnd( hwnd
, (HDC
)wParam
, infoPtr
);
155 if ((wParam
& 0xfff0) != SC_CLOSE
) return 0;
159 return (LRESULT
)SetCursor( LoadCursor( 0, IDC_ARROW
) );
166 /***********************************************************************
167 * SetDeskPattern (USER.279)
169 BOOL
SetDeskPattern(void)
172 GetProfileString( "desktop", "Pattern", "(None)", buffer
, 100 );
173 return DESKTOP_SetPattern( buffer
);
177 /***********************************************************************
178 * SetDeskWallPaper (USER.285)
180 BOOL
SetDeskWallPaper( LPCSTR filename
)
185 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
186 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
188 if (filename
== (LPSTR
)-1)
190 GetProfileString( "desktop", "WallPaper", "(None)", buffer
, 256 );
194 hbitmap
= DESKTOP_LoadBitmap( hdc
, filename
);
196 if (infoPtr
->hbitmapWallPaper
) DeleteObject( infoPtr
->hbitmapWallPaper
);
197 infoPtr
->hbitmapWallPaper
= hbitmap
;
198 infoPtr
->fTileWallPaper
= GetProfileInt( "desktop", "TileWallPaper", 0 );
202 GetObject( hbitmap
, sizeof(bmp
), (LPSTR
)&bmp
);
203 infoPtr
->bitmapSize
.cx
= (bmp
.bmWidth
!= 0) ? bmp
.bmWidth
: 1;
204 infoPtr
->bitmapSize
.cy
= (bmp
.bmHeight
!= 0) ? bmp
.bmHeight
: 1;
210 /***********************************************************************
213 * Set the desktop pattern.
215 BOOL
DESKTOP_SetPattern(char *pattern
)
217 WND
*wndPtr
= WIN_FindWndPtr( GetDesktopWindow() );
218 DESKTOPINFO
*infoPtr
= (DESKTOPINFO
*)wndPtr
->wExtra
;
221 if (infoPtr
->hbrushPattern
) DeleteObject( infoPtr
->hbrushPattern
);
222 memset( pat
, 0, sizeof(pat
) );
223 if (pattern
&& sscanf( pattern
, " %d %d %d %d %d %d %d %d",
224 &pat
[0], &pat
[1], &pat
[2], &pat
[3],
225 &pat
[4], &pat
[5], &pat
[6], &pat
[7] ))
231 for (i
= 0; i
< 8; i
++) pattern
[i
] = pat
[i
] & 0xffff;
232 hbitmap
= CreateBitmap( 8, 8, 1, 1, (LPSTR
)pattern
);
233 infoPtr
->hbrushPattern
= CreatePatternBrush( hbitmap
);
234 DeleteObject( hbitmap
);
236 else infoPtr
->hbrushPattern
= CreateSolidBrush( GetSysColor(COLOR_BACKGROUND
) );