Added ability to turn on/off debug channels.
[wine.git] / programs / view / view.c
blobb42bceead12b029bd595c91b3df8306f02c6d9ec
1 /*
2 * Copyright 1998 Douglas Ridgway
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <windows.h>
20 #include "resource.h"
23 #include <windowsx.h>
24 Wine doesn't have windowsx.h, so we use this
26 #define GET_WM_COMMAND_ID(wp,lp) LOWORD(wp)
28 /* Wine seems to need this */
29 #include <commdlg.h>
31 #include "globals.h"
32 #include <stdio.h>
34 BOOL FileIsPlaceable( LPCSTR szFileName );
35 HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName );
37 #define FN_LENGTH 80
39 HMETAFILE hmf;
40 int deltax = 0, deltay = 0;
41 int width = 0, height = 0;
42 BOOL isAldus;
44 BOOL FileOpen(HWND hWnd, char *fn)
46 OPENFILENAME ofn = { sizeof(OPENFILENAME),
47 0, 0, NULL, NULL, 0, 0, NULL,
48 FN_LENGTH, NULL, 0, NULL, NULL, OFN_CREATEPROMPT |
49 OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
50 ofn.lpstrFilter = "Metafiles\0*.wmf\0";
51 ofn.hwndOwner = hWnd;
52 ofn.lpstrFile = fn;
53 return GetOpenFileName(&ofn);
57 LRESULT CALLBACK WndProc(HWND hwnd,
58 UINT uMessage,
59 WPARAM wparam,
60 LPARAM lparam)
62 switch (uMessage)
64 case WM_PAINT:
66 PAINTSTRUCT ps;
67 BeginPaint(hwnd, &ps);
68 SetMapMode(ps.hdc, MM_ANISOTROPIC);
69 SetViewportExtEx(ps.hdc, width, height, NULL);
70 SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
71 if(hmf) PlayMetaFile(ps.hdc, hmf);
72 EndPaint(hwnd, &ps);
75 break;
77 case WM_COMMAND: /* message: command from application menu */
78 switch (GET_WM_COMMAND_ID(wparam,lparam))
80 case IDM_HELLO:
81 MessageBox( hwnd , "Hello there world!", "Hello", MB_OK);
82 break;
84 case IDM_OPEN:
86 char filename[FN_LENGTH];
87 if (FileOpen(hwnd, filename)) {
88 isAldus = FileIsPlaceable(filename);
89 if (isAldus) {
90 hmf = GetPlaceableMetaFile(hwnd, filename);
91 } else {
92 RECT r;
93 hmf = GetMetaFile(filename);
94 GetClientRect(hwnd, &r);
95 width = r.right - r.left;
96 height = r.bottom - r.top;
98 InvalidateRect( hwnd, NULL, TRUE );
101 break;
103 case IDM_SET_EXT_TO_WIN:
105 RECT r;
106 GetClientRect(hwnd, &r);
107 width = r.right - r.left;
108 height = r.bottom - r.top;
109 InvalidateRect( hwnd, NULL, TRUE );
111 break;
114 case IDM_LEFT:
115 deltax += 100;
116 InvalidateRect( hwnd, NULL, TRUE );
117 break;
118 case IDM_RIGHT:
119 deltax -= 100;
120 InvalidateRect( hwnd, NULL, TRUE );
121 break;
122 case IDM_UP:
123 deltay += 100;
124 InvalidateRect( hwnd, NULL, TRUE );
125 break;
126 case IDM_DOWN:
127 deltay -= 100;
128 InvalidateRect( hwnd, NULL, TRUE );
129 break;
131 case IDM_EXIT:
132 DestroyWindow(hwnd);
133 break;
135 default:
136 return DefWindowProc(hwnd, uMessage, wparam, lparam);
138 break;
140 case WM_DESTROY: /* message: window being destroyed */
141 PostQuitMessage(0);
142 break;
144 default: /* Passes it on if unproccessed */
145 return DefWindowProc(hwnd, uMessage, wparam, lparam);
147 return 0;
150 BOOL FileIsPlaceable( LPCSTR szFileName )
152 HFILE hInFile;
153 APMFILEHEADER apmh;
155 if( (hInFile = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR )
156 return FALSE;
158 if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
159 != sizeof(APMFILEHEADER) )
161 _lclose( hInFile );
162 return FALSE;
164 _lclose( hInFile );
166 /* Is it placeable? */
167 return (apmh.key == APMHEADER_KEY);
170 HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
172 LPSTR lpData;
173 METAHEADER mfHeader;
174 APMFILEHEADER APMHeader;
175 HFILE fh;
176 HMETAFILE hmf;
177 WORD checksum, *p;
178 int i;
180 if( (fh = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR ) return 0;
181 _llseek(fh, 0, 0);
182 if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
183 _llseek(fh, sizeof(APMFILEHEADER), 0);
184 checksum = 0;
185 p = (WORD *) &APMHeader;
187 for(i=0; i<10; i++)
188 checksum ^= *p++;
189 if (checksum != APMHeader.checksum) {
190 char msg[128];
191 sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
192 checksum, APMHeader.checksum);
193 MessageBox(hwnd, msg, "Checksum failed", MB_OK);
194 return 0;
197 if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;
199 if (!(lpData = (LPSTR) GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;
201 _llseek(fh, sizeof(APMFILEHEADER), 0);
202 if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
204 GlobalFree((HGLOBAL)lpData);
205 _lclose(fh);
206 return 0;
208 _lclose(fh);
210 if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
211 return 0;
214 width = APMHeader.bbox.Right - APMHeader.bbox.Left;
215 height = APMHeader.bbox.Bottom - APMHeader.bbox.Top;
217 /* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
218 width = width*96/APMHeader.inch;
219 height = height*96/APMHeader.inch;
221 deltax = 0;
222 deltay = 0 ;
223 return hmf;