Use MsiDecomposeDescriptorW in MsiProvideQualifiedComponentExW.
[wine.git] / programs / view / view.c
blob147cc4503948883c47ed724fcb04bbf715578f3c
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 <windowsx.h>
21 #include "resource.h"
23 #include "globals.h"
24 #include <stdio.h>
26 BOOL FileIsPlaceable( LPCSTR szFileName );
27 HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName );
29 HMETAFILE hmf;
30 int deltax = 0, deltay = 0;
31 int width = 0, height = 0;
32 BOOL isAldus;
34 static BOOL FileOpen(HWND hWnd, char *fn, int fnsz)
36 OPENFILENAME ofn = { sizeof(OPENFILENAME),
37 0, 0, NULL, NULL, 0, 0, NULL,
38 fnsz, NULL, 0, NULL, NULL,
39 OFN_SHOWHELP, 0, 0, NULL, 0, NULL };
40 ofn.lpstrFilter = "Metafiles\0*.wmf\0";
41 ofn.hwndOwner = hWnd;
42 ofn.lpstrFile = fn;
43 if( fnsz < 1 )
44 return FALSE;
45 *fn = 0;
46 return GetOpenFileName(&ofn);
50 LRESULT CALLBACK WndProc(HWND hwnd,
51 UINT uMessage,
52 WPARAM wparam,
53 LPARAM lparam)
55 switch (uMessage)
57 case WM_PAINT:
59 PAINTSTRUCT ps;
60 BeginPaint(hwnd, &ps);
61 SetMapMode(ps.hdc, MM_ANISOTROPIC);
62 /* Set the window extent to a sane value in case the metafile doesn't */
63 SetWindowExtEx(ps.hdc, width, height, NULL);
64 SetViewportExtEx(ps.hdc, width, height, NULL);
65 SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
66 if(hmf) PlayMetaFile(ps.hdc, hmf);
67 EndPaint(hwnd, &ps);
69 break;
71 case WM_COMMAND: /* message: command from application menu */
72 switch (GET_WM_COMMAND_ID(wparam,lparam))
74 case IDM_HELLO:
75 MessageBox( hwnd , "Hello there world!", "Hello", MB_OK);
76 break;
78 case IDM_OPEN:
80 char filename[MAX_PATH];
81 if (FileOpen(hwnd, filename, sizeof(filename))) {
82 isAldus = FileIsPlaceable(filename);
83 if (isAldus) {
84 hmf = GetPlaceableMetaFile(hwnd, filename);
85 } else {
86 RECT r;
87 hmf = GetMetaFile(filename);
88 GetClientRect(hwnd, &r);
89 width = r.right - r.left;
90 height = r.bottom - r.top;
92 InvalidateRect( hwnd, NULL, TRUE );
95 break;
97 case IDM_SET_EXT_TO_WIN:
99 RECT r;
100 GetClientRect(hwnd, &r);
101 width = r.right - r.left;
102 height = r.bottom - r.top;
103 InvalidateRect( hwnd, NULL, TRUE );
105 break;
108 case IDM_LEFT:
109 deltax += 100;
110 InvalidateRect( hwnd, NULL, TRUE );
111 break;
112 case IDM_RIGHT:
113 deltax -= 100;
114 InvalidateRect( hwnd, NULL, TRUE );
115 break;
116 case IDM_UP:
117 deltay += 100;
118 InvalidateRect( hwnd, NULL, TRUE );
119 break;
120 case IDM_DOWN:
121 deltay -= 100;
122 InvalidateRect( hwnd, NULL, TRUE );
123 break;
125 case IDM_EXIT:
126 DestroyWindow(hwnd);
127 break;
129 default:
130 return DefWindowProc(hwnd, uMessage, wparam, lparam);
132 break;
134 case WM_DESTROY: /* message: window being destroyed */
135 PostQuitMessage(0);
136 break;
138 default: /* Passes it on if unprocessed */
139 return DefWindowProc(hwnd, uMessage, wparam, lparam);
141 return 0;
144 BOOL FileIsPlaceable( LPCSTR szFileName )
146 HFILE hInFile;
147 APMFILEHEADER apmh;
149 if( (hInFile = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR )
150 return FALSE;
152 if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
153 != sizeof(APMFILEHEADER) )
155 _lclose( hInFile );
156 return FALSE;
158 _lclose( hInFile );
160 /* Is it placeable? */
161 return (apmh.key == APMHEADER_KEY);
164 HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
166 LPBYTE lpData;
167 METAHEADER mfHeader;
168 APMFILEHEADER APMHeader;
169 HFILE fh;
170 HMETAFILE hmf;
171 WORD checksum, *p;
172 HDC hdc;
173 int i;
175 if( (fh = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR ) return 0;
176 _llseek(fh, 0, 0);
177 if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
178 _llseek(fh, sizeof(APMFILEHEADER), 0);
179 checksum = 0;
180 p = (WORD *) &APMHeader;
182 for(i=0; i<10; i++)
183 checksum ^= *p++;
184 if (checksum != APMHeader.checksum) {
185 char msg[128];
186 sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
187 checksum, APMHeader.checksum);
188 MessageBox(hwnd, msg, "Checksum failed", MB_OK);
189 return 0;
192 if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;
194 if (!(lpData = GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;
196 _llseek(fh, sizeof(APMFILEHEADER), 0);
197 if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
199 GlobalFree((HGLOBAL)lpData);
200 _lclose(fh);
201 return 0;
203 _lclose(fh);
205 if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
206 return 0;
209 width = APMHeader.bbox.Right - APMHeader.bbox.Left;
210 height = APMHeader.bbox.Bottom - APMHeader.bbox.Top;
212 /* printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch); */
213 hdc = GetDC(hwnd);
214 width = width * GetDeviceCaps(hdc, LOGPIXELSX)/APMHeader.inch;
215 height = height * GetDeviceCaps(hdc,LOGPIXELSY)/APMHeader.inch;
216 ReleaseDC(hwnd, hdc);
218 deltax = 0;
219 deltay = 0 ;
220 return hmf;