1 /* -*-C-*-
2 
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts
6     Institute of Technology
7 
8 This file is part of MIT/GNU Scheme.
9 
10 MIT/GNU Scheme is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or (at
13 your option) any later version.
14 
15 MIT/GNU Scheme is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with MIT/GNU Scheme; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
23 USA.
24 
25 */
26 
27 
28 /* This software was derived from the following:  */
29 
30 /******************************************************************************\
31 *       This is a part of the Microsoft Source Code Samples.
32 *       Copyright (C) 1993 Microsoft Corporation.
33 *       All rights reserved.
34 *       This source code is only intended as a supplement to
35 *       Microsoft Development Tools and/or WinHelp documentation.
36 *       See these sources for detailed information regarding the
37 *       Microsoft samples programs.
38 \******************************************************************************/
39 
40 #include <stdio.h>
41 /****************************************************************************
42  *                                                                          *
43  *  FILE        : SHOWDIB.H                                                 *
44  *                                                                          *
45  *  DESCRIPTION : Header/include file for ShowDIB example.                  *
46  *                                                                          *
47  ****************************************************************************/
48 
49 typedef    POINTS       MPOINT         ;
50 
51 #ifdef WIN32
52 #define GET_WM_ACTIVATE_STATE(wp, lp)   LOWORD(wp)
53 #define GET_WM_VSCROLL_CODE(wp, lp)     LOWORD(wp)
54 #define GET_WM_VSCROLL_POS(wp, lp)      HIWORD(wp)
55 #define GET_WM_HSCROLL_CODE(wp, lp)     LOWORD(wp)
56 #define GET_WM_HSCROLL_POS(wp, lp)      HIWORD(wp)
57 #define GET_EM_SETSEL_MPS(iStart, iEnd) (UINT)(iStart), (LONG)(iEnd)
58 #define GET_WM_COMMAND_CMD(wp, lp)      HIWORD(wp)
59 #define MAKEMPOINT(l)                   (*((MPOINT *)&(l)))
60 #define HUGE_T
61 #else
62 #define GET_WM_ACTIVATE_STATE(wp, lp)               (wp)
63 #define GET_WM_HSCROLL_CODE(wp, lp)                 (wp)
64 #define GET_WM_HSCROLL_POS(wp, lp)                  LOWORD(lp)
65 #define GET_WM_VSCROLL_CODE(wp, lp)                 (wp)
66 #define GET_WM_VSCROLL_POS(wp, lp)                  LOWORD(lp)
67 #define GET_EM_SETSEL_MPS(iStart, iEnd) 0, MAKELONG(iStart, iEnd)
68 #define GET_WM_COMMAND_CMD(wp, lp)      HIWORD(lp)
69 #define MAKEMPOINT(l)                   (*((MPOINT FAR *)&(l)))
70 #define HUGE_T         huge
71 #endif
72 
73 /* Macro to restrict a given value to an upper or lower boundary value */
74 #define BOUND(x,min,max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
75 
76 /* Macro to swap two values */
77 #define SWAP(x,y)   ((x)^=(y)^=(x)^=(y))
78 
79 /* Macro to find the minimum of two values */
80 #define MIN(x,y) (((x) <= (y)) : x ? y)
81 
82 /* Macros to display/remove hourglass cursor for lengthy operations */
83 #define StartWait() hcurSave = SetCursor(LoadCursor(NULL,IDC_WAIT))
84 #define EndWait()   SetCursor(hcurSave)
85 
86 /* WinFlags, __WinFlags is a ABS external, thus the need for the & */
87 #define WinFlags    ((WORD)(&_WinFlags))
88 
89 #define MINBAND         50     /* Minimum band size used by the program */
90 #define BANDINCREMENT   20     /* Decrement for band size while trying  */
91                                /* to determine optimum band size.       */
92 
93 /* Bit values for the DIB attributes flag (fFileOptions). Also used as control
94  * IDs for the radiobuttons for DIB bitcount in the File/Open dialog
95  */
96 #define F_1BPP      DLGOPEN_1BPP
97 #define F_4BPP      DLGOPEN_4BPP
98 #define F_8BPP      DLGOPEN_8BPP
99 #define F_24BPP     DLGOPEN_24BPP
100 
101 /* Bit values for the DIB attributes flag (fFileOptions), also used as control
102  * IDs for the radiobuttons for DIB compression type in the File/Open dialog
103  */
104 #define F_RLE4      DLGOPEN_RLE4
105 #define F_RLE8      DLGOPEN_RLE8
106 #define F_RGB       DLGOPEN_RGB
107 
108 #ifdef NOT_IN_STDIO
109 /* flags for _lseek */
110 #define  SEEK_CUR 1
111 #define  SEEK_END 2
112 #define  SEEK_SET 0
113 #endif
114 
115 /* struct to be passed in for the SETDIBSCALING printer escape */
116 typedef struct {
117         SHORT ScaleMode;
118         SHORT dx, dy;
119 } DIBPARAMS;
120 
121 /* Menu IDs */
122 
123 #define IDM_UPDATECOL   1000
124 #define IDM_ANIMATE0    1001
125 #define IDM_ANIMATE5    5
126 #define IDM_ANIMATE20   20
127 #define IDM_ANIMATE50   50
128 #define IDM_ANIMATE100  100
129 #define IDM_ANIMATE200  200
130 #define IDM_ANIMATE201  32000
131 
132 #define IDM_OPEN        1002
133 #define IDM_EXIT        1003
134 #define IDM_ABOUT       1004
135 #define IDM_DIBSCREEN   1005
136 #define IDM_NOUGLY      1006
137 #define IDM_STEALCOL    1009
138 #define IDM_PRINT       1010
139 #define IDM_COPY        1012
140 #define IDM_MEMORYDIB   1014
141 #define IDM_SAVE        1015
142 #define IDM_TRANSPARENT 1016
143 
144 #define IDM_PASTEDIB    1020
145 #define IDM_PASTEDDB    1021
146 #define IDM_PASTEPAL    1022
147 
148 #define IDI_APP         2000
149 
150 #define ABOUTBOX        100
151 
152 extern HWND hWndApp;                   /* The handle to the app. window     */
153 
154 #define MAXREAD  32768                 /* Number of bytes to be read during */
155                                        /* each read operation.              */
156 
157 /* Header signatutes for various resources */
158 #define BFT_ICON   0x4349   /* 'IC' */
159 #define BFT_BITMAP 0x4d42   /* 'BM' */
160 #define BFT_CURSOR 0x5450   /* 'PT' */
161 
162 /* macro to determine if resource is a DIB */
163 #define ISDIB(bft) ((bft) == BFT_BITMAP)
164 
165 /* Macro to align given value to the closest DWORD (unsigned long ) */
166 #define ALIGNULONG(i)   ((i+3)/4*4)
167 
168 /* Macro to determine to round off the given value to the closest byte */
169 #define WIDTHBYTES(i)   ((i+31)/32*4)
170 
171 #define PALVERSION      0x300
172 #define MAXPALETTE      256       /* max. # supported palette entries */
173 
174 /********** THE FOLLOWING ARE USED IN DLGOPEN.C  ************************/
175 
176 /* IDs for controls in the DlgOpen dialog */
177 #define DLGOPEN_EDIT            101
178 #define DLGOPEN_FILE_LISTBOX    102
179 #define DLGOPEN_DIR_LISTBOX     103
180 #define DLGOPEN_PATH            104
181 #define DLGOPEN_TEXT            105
182 #define DLGOPEN_FOLDOUT         106
183 #define DLGOPEN_BIG             107
184 #define DLGOPEN_SMALL           108
185 
186 #define DLGOPEN_OPTION          0xF000
187 #define DLGOPEN_1BPP            0x0001
188 #define DLGOPEN_4BPP            0x0002
189 #define DLGOPEN_8BPP            0x0004
190 #define DLGOPEN_24BPP           0x0008
191 #define DLGOPEN_RLE4            0x0010
192 #define DLGOPEN_RLE8            0x0020
193 #define DLGOPEN_RGB             0x0040
194 
195 #define DLGOPEN_OPTION8         0x0080
196 
197 /*  flags:
198  *     The LOWORD is the standard FileOpen() flags (OF_*)
199  *     the HIWORD can be any of the following:
200  */
201 #define OF_MUSTEXIST    0x00010000  /* file must exist if the user hits Ok    */
202 #define OF_NOSHOWSPEC   0x00020000  /* DO NOT Show search spec in the edit box*/
203 #define OF_SHOWSPEC     0x00000000  /* Show the search spec in the edit box   */
204 #define OF_SAVE         0x00040000  /* Ok button will say "Save"              */
205 #define OF_OPEN         0x00080000  /* Ok button will say "Open"              */
206 #define OF_NOOPTIONS    0x00100000  /* Disable the options fold out           */
207 
208 /* Attributes for DlgDirLst() */
209 #define ATTRFILELIST    0x0000        /* include files only          */
210 #define ATTRDIRLIST     0xC010        /* directories and drives ONLY */
211 #define CBEXTMAX        6             /* Number of bytes in "\*.txt" */
212 
213 
214 #define IDF(id)     ((id) & ~DLGOPEN_OPTION)  /* extracts flag from control ID */
215 #define FID(f)      ((f)  |  DLGOPEN_OPTION)  /* extracts control ID from flag */
216 
217 /***************** GLOBAL VARIABLES *************************/
218 
219 extern CHAR           achFileName[128]; /* File pathname                       */
220 extern DWORD          dwOffset;     /* Current position if DIB file pointer    */
221 extern RECT           rcClip;       /* Current clip rectangle.                 */
222 extern BOOL           fPalColors;   /* TRUE if the current DIB's color table   */
223                                     /* contains palette indexes not rgb values */
224 extern BOOL           bDIBToDevice; /* Use SetDIBitsToDevice() to BLT data.    */
225 extern BOOL           bLegitDraw;   /* We have a valid bitmap to draw          */
226 extern WORD           wTransparent; /* Mode of DC                              */
227 extern CHAR           szAppName[];  /* App. name                               */
228 extern HPALETTE       hpalCurrent;  /* Handle to current palette               */
229 extern HANDLE         hdibCurrent;  /* Handle to current memory DIB            */
230 extern HBITMAP        hbmCurrent;   /* Handle to current memory BITMAP         */
231 extern HANDLE         hbiCurrent;   /* Handle to current bitmap info struct    */
232 extern DWORD          dwStyle;      /* Style bits of the App. window           */
233 
234 /***************** FUNCTION DECLARATIONS *******************/
235 
236 DWORD PASCAL lread(INT fh, VOID FAR *pv, DWORD ul);
237 DWORD PASCAL lwrite(INT fh, VOID FAR *pv, DWORD ul);
238 
239 /***********************************************************/
240 /* Declarations of functions used in showdib.c module      */
241 /***********************************************************/
242 
243 LONG     APIENTRY WndProc  (HWND, UINT, UINT, LONG) ;
244 BOOL               MenuCommand (HWND hWnd, UINT wParam);
245 INT                InitDIB (HWND);
246 VOID               FreeDib (VOID);
247 
248 /***********************************************************/
249 /* Declarations of functions used in dib.c module          */
250 /***********************************************************/
251 
252 HANDLE FAR WINAPI      OpenDIB (LPSTR szFile);
253 BOOL FAR WINAPI        WriteDIB (LPSTR szFile,HANDLE hdib);
254 WORD        PaletteSize (VOID FAR * pv);
255 WORD        DibNumColors (VOID FAR * pv);
256 HPALETTE    CreateDibPalette (HANDLE hdib);
257 HPALETTE    CreateBIPalette (LPBITMAPINFOHEADER lpbi);
258 HANDLE FAR WINAPI      DibFromBitmap (HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal);
259 HBITMAP FAR WINAPI     BitmapFromDib (HANDLE hdib, HPALETTE hpal);
260 BOOL FAR WINAPI        DibBlt (HDC hdc, INT x0, INT y0, INT dx, INT dy, HANDLE hdib, INT x1, INT y1, LONG rop);
261 BOOL        StretchDibBlt (HDC hdc, INT x0, INT y0, INT dx, INT dy, HANDLE hdib, INT x1, INT y1, INT dx1, INT dy1, LONG rop);
262 BOOL        DibInfo (HANDLE hdib,LPBITMAPINFOHEADER lpbi);
263 HANDLE      ReadDibBitmapInfo (INT fh);
264 BOOL        DrawBitmap (HDC hdc, INT x, INT y, HBITMAP hbm, DWORD rop);
265 VOID            ReadBitMapFileHeaderandConvertToDwordAlign(HFILE fh, LPBITMAPFILEHEADER pbf, LPDWORD lpdwoff);
266 VOID    WriteMapFileHeaderandConvertFromDwordAlignToPacked(HFILE fh, LPBITMAPFILEHEADER pbf);
267 
268 /***********************************************************/
269 /* Declarations of functions used in drawdib. c module     */
270 /***********************************************************/
271 
272 VOID               PrintDIB (HWND hWnd, HDC hDC, INT x, INT y, INT dx, INT dy);
273 VOID               AppPaint (HWND hWnd, HDC hDC, INT x, INT y);
274 INT                ErrMsg (PSTR sz,...);
275 BOOL               fDialog (INT id, HWND hwnd, FARPROC fpfn);
276 VOID               BandDIB (HWND hWnd, HDC hDC, INT x, INT y);
277 BOOL     APIENTRY AppAbout (HWND, UINT, UINT, LONG) ;
278 HANDLE             CopyHandle (HANDLE h);
279 VOID               SizeWindow (HWND hWnd);
280 VOID               GetRealClientRect (HWND hwnd, PRECT lprc);
281 VOID               SetScrollRanges (HWND hwnd);
282 VOID               DrawSelect (HDC hdc, BOOL fDraw);
283 VOID        PASCAL NormalizeRect (RECT *prc);
284 VOID               TrackMouse (HWND hwnd, MPOINT pt);
285 HBITMAP FAR WINAPI            CopyBitmap (HBITMAP hbm);
286 HPALETTE           CopyPalette (HPALETTE hpal);
287 HBITMAP FAR WINAPI            CropBitmap (HBITMAP hbm, int,int,int,int);
288 HANDLE             RenderFormat (INT cf);
289 HANDLE             RealizeDibFormat (DWORD biStyle, WORD biBits);
290 
291 /***********************************************************/
292 /* Declarations of functions used in the print.c module    */
293 /***********************************************************/
294 
295 BOOL    PASCAL InitPrinting (HDC hDC, HWND hWnd, HANDLE hInst, LPSTR msg);
296 VOID    PASCAL TermPrinting (HDC hDC);
297 HDC     PASCAL GetPrinterDC (VOID);
298 HDC     PASCAL GetPrinterDC1 (VOID);
299 
300 /***********************************************************/
301 /* Declarations of functions used in the dlgopen.c module  */
302 /***********************************************************/
303 
304 LONG APIENTRY DlgfnOpen(
305         HWND hwnd,
306     UINT msg,
307     UINT wParam,
308     LONG lParam
309 );
310 HFILE APIENTRY DlgOpenFile (
311         HWND            hwndParent,
312         CHAR            *szTitleIn,
313         DWORD           flags,
314         CHAR            *szExtIn,
315     CHAR        *szFileNameIn,
316     WORD                *pfOpt
317 );
318 
319 /*****************************************************/
320 /* make new sizeof structs to cover dword alignment  */
321 /*****************************************************/
322 
323 #define SIZEOF_BITMAPFILEHEADER_PACKED  (   \
324     sizeof(WORD) +      /* bfType      */   \
325     sizeof(DWORD) +     /* bfSize      */   \
326     sizeof(WORD) +      /* bfReserved1 */   \
327     sizeof(WORD) +      /* bfReserved2 */   \
328     sizeof(DWORD))      /* bfOffBits   */
329