source: trunk/dll/defview.c@ 1783

Last change on this file since 1783 was 1783, checked in by Gregg Young, 11 years ago

Fix shift click on windows bitmap opens fm2play because MMOS2 identifies it as an audio file. Ticket [541]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1
2/***********************************************************************
3
4 $Id: defview.c 1783 2014-07-19 20:39:26Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2003, 2012 Steven H.Levine
8
9 Default file viewer
10
11 20 Nov 03 SHL ShowMultimedia: try to convince fmplay to not play exes (Gregg Young)
12 14 Jul 06 SHL Use Runtime_Error
13 18 Mar 07 GKY Fixed misindentifycation of nonmultimedia files by ShowMultiMedia
14 18 Mar 07 GKY Open mp3, ogg & flac files with OS2 object default since fm2play fails
15 21 Apr 07 GKY Find FM2Utils by path or utils directory
16 09 Jun 07 SHL ShowMultimedia: Initialize hwnd so that OpenObject might work
17 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
18 20 Dec 07 GKY Open jpg files with OS2 object default since image.exe fails
19 29 Feb 08 GKY Refactor global command line variables to notebook.h
20 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
21 less than 10 KiB (It hangs and can't be closed)
22 05 Jan 09 GKY Use TestBinary so that text viewer isn't used for hex files by default
23 08 Mar 09 GKY Additional strings move to PCSZs
24 15 Nov 09 GKY Add check for attempt to open zero byte file and reorder file type checks
25 to place exes before MMPM check (avoids MMPM trying to play them)
26 15 Nov 09 GKY Work around MMIO's falure to identify MPG files as media
27 12 Dec 09 GKY Remove code that opened files to check if they were media types
28 It was redundant.
29 12 Dec 09 GKY Pass .WPI files to PM for default handling.
30 02 Jan 12 GKY Completely rework ShowMultimedia to only test and try to open files with known multimedia extensions
31 This fixes some traps in GBM.DLL and PMCTLS.DLL; mmioIdentifyFile appears to pretty much be broken.
32 28 Jun 14 GKY Fix errors identified with CPPCheck
33 19 Jul 14 GKY MMOS2 misids all kinds of things including window bitmaps as audio files
34 Removed FM2play from code since the misid leads to a failure to open the
35 bitmaps.
36
37***********************************************************************/
38
39#include <string.h>
40#include <ctype.h>
41
42#define INCL_DOS
43#define INCL_WIN
44#define INCL_GPI
45#define INCL_MMIOOS2
46#define INCL_LONGLONG // dircnrs.h
47#include <os2.h>
48#include <os2me.h>
49
50#include "fm3dll.h"
51#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
52#include "mainwnd2.h" // Data declaration(s)
53#include "init.h" // Data declaration(s)
54#include "fm3dlg.h"
55#include "arccnrs.h" // StartArcCnr
56#include "errutil.h" // Dos_Error...
57#include "notebook.h" // external viewers
58#include "defview.h"
59#include "info.h" // DrvInfoProc
60#include "assoc.h" // ExecAssociation
61#include "info.h" // FileInfoProc
62#include "valid.h" // IsExecutable
63#include "srchpath.h" // RunFM2Util
64#include "inis.h" // StartIniEditor
65#include "systemf.h" // ExecOnList
66#include "shadow.h" // OpenObject
67#include "viewer.h" // StartMLEEditor
68#include "newview.h" // StartViewer
69#include "mainwnd.h" // Data declaration(s)
70#include "misc.h" // ExecFile, ViewHelp
71
72// Data definitions
73static PSZ pszSrcFile = __FILE__;
74
75#pragma data_seg(GLOBAL2)
76PCSZ Default = "DEFAULT";
77
78/**
79 * ShowMultimedia uses MMOS2 if available to check if files are media types
80 * It will play them as media if they are. There are several work arounds
81 * to handle newer media types which are misidentified or which don't play
82 * in our default player/viewer
83 */
84
85BOOL ShowMultimedia(CHAR * filename)
86{
87
88 static BOOL no_mmos2 = FALSE;
89 BOOL played = FALSE;
90 CHAR loaderror[CCHMAXPATH];
91 HMODULE MMIOModHandle = NULLHANDLE;
92 PMMIOIDENTIFYFILE pMMIOIdentifyFile = NULL;
93 FOURCC fccStorageSystem = 0;
94 MMFORMATINFO mmFormatInfo;
95 APIRET rc;
96 HWND hwnd = HWND_DESKTOP;
97 char *p;
98
99 if (no_mmos2 || !filename || !*filename)
100 return played;
101
102 //load MMPM/2, if available.
103 *loaderror = 0;
104 rc = DosLoadModule(loaderror, sizeof(loaderror), "MMIO", &MMIOModHandle);
105 if (rc) {
106 no_mmos2 = TRUE;
107 return played;
108 }
109 else {
110 ULONG cmp;
111 CHAR cmps[6];
112
113 p = strrchr(filename, '.');
114 if (p) {
115 cmps[0] = '.';
116 cmps[1] = toupper(p[1]);
117 cmps[2] = toupper(p[2]);
118 cmps[3] = toupper(p[3]);
119 if (p[4]) {
120 cmps[4] = toupper(p[4]);
121 cmps[5] = 0;
122 }
123 else
124 cmps[4] = 0;
125
126 cmp = *(ULONG *) cmps;
127 if (cmp == *(ULONG *) PCSZ_DOTBMP || cmp == *(ULONG *) PCSZ_DOTJPEG ||
128 cmp == *(ULONG *) PCSZ_DOTMP3 || cmp == *(ULONG *) PCSZ_DOTJPG ||
129 cmp == *(ULONG *) PCSZ_DOTMPEG || cmp == *(ULONG *) PCSZ_DOTFLAC ||
130 cmp == *(ULONG *) ".TIF" || cmp == *(ULONG *) ".PCX" ||
131 cmp == *(ULONG *) ".TGA" || cmp == *(ULONG *) ".MOV" ||
132 cmp == *(ULONG *) ".PNG" || cmp == *(ULONG *) ".AVI" ||
133 cmp == *(ULONG *) ".OGG" || cmp == *(ULONG *) ".MID" ||
134 cmp == *(ULONG *) ".PCD" || cmp == *(ULONG *) ".FLC" ||
135 cmp == *(ULONG *) ".GIF" || cmp == *(ULONG *) ".FLA" ||
136 cmp == *(ULONG *) ".IFF" || cmp == *(ULONG *) ".SND" ||
137 cmp == *(ULONG *) "._AU" || cmp == *(ULONG *) ".AIF" ||
138 cmp == *(ULONG *) ".VID" || cmp == *(ULONG *) ".WAV" ||
139 cmp == *(ULONG *) "._IM" || cmp == *(ULONG *) ".RDI" ||
140 cmp == *(ULONG *) PCSZ_DOTMPG) {
141 if (DosQueryProcAddr(MMIOModHandle, 0,
142 "mmioIdentifyFile", (PFN *) &pMMIOIdentifyFile)) {
143 DosFreeModule(MMIOModHandle);
144 no_mmos2 = TRUE;
145 return played;
146 }
147 }
148 else
149 return played;
150 }
151 else
152 return played;
153 }
154 memset(&mmFormatInfo, 0, sizeof(MMFORMATINFO));
155 mmFormatInfo.ulStructLen = sizeof(MMFORMATINFO);
156 rc = pMMIOIdentifyFile(filename, 0L, &mmFormatInfo,
157 &fccStorageSystem, 0L,
158 MMIO_FORCE_IDENTIFY_FF);
159 DosFreeModule(MMIOModHandle);
160
161 // if identified and not FOURCC_DOS MPEGs are misidentified as DOS
162 //DbgMsg(pszSrcFile, __LINE__, "FOUCC %x %s %i", mmFormatInfo.fccIOProc,
163 // mmFormatInfo.szDefaultFormatExt, mmFormatInfo.ulMediaType);
164 if (!rc && (mmFormatInfo.fccIOProc != FOURCC_DOS ||
165 !stricmp(p, PCSZ_DOTMPG) || !stricmp(p, PCSZ_DOTMPEG))) {
166 if ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED)) {
167 OpenObject(filename, Default, hwnd);
168 played = TRUE;
169 }
170 }
171
172 return played;
173}
174
175VOID DefaultViewKeys(HWND hwnd, HWND hwndFrame, HWND hwndParent,
176 SWP * swp, CHAR * filename)
177{
178 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
179 DefaultView(hwnd, hwndFrame, hwndParent, swp, 4, filename);
180 else if (shiftstate & KC_CTRL)
181 DefaultView(hwnd, hwndFrame, hwndParent, swp, 2, filename);
182 else if (shiftstate & KC_SHIFT)
183 DefaultView(hwnd, hwndFrame, hwndParent, swp, 1, filename);
184 else
185 DefaultView(hwnd, hwndFrame, hwndParent, swp, 0, filename);
186}
187
188/**
189 * DefaultView runs multiple checks for opening files including checking
190 * for associations, archives, executables, help, ini, warpin, multimedia and
191 * viewing as binary or text.
192 */
193
194VOID DefaultView(HWND hwnd, HWND hwndFrame, HWND hwndParent, SWP * swp,
195 ULONG flags, CHAR * filename)
196{
197 /**
198 * bitmapped flags:
199 * ---------------
200 * 1 = View directly
201 * 2 = Open WPS default view
202 * 4 = Open WPS settings view
203 * 8 = Edit
204 * 16 = Info
205 * 32 = No view info
206 */
207
208 HWND hwndArc = (HWND) 0;
209 char *p, *dummy[3];
210
211 if (!hwndParent)
212 hwndParent = HWND_DESKTOP;
213
214 if (flags & 32) {
215 flags &= (~16);
216 if (!IsFile(filename)) {
217 Runtime_Error(pszSrcFile, __LINE__, "%s not found", filename);
218 return;
219 }
220 }
221
222 if (flags & 1) // directly view the file
223 goto ViewIt;
224
225 if (flags & 2) { // open default WPS view of file
226 OpenObject(filename, Default, hwnd);
227 return;
228 }
229
230 if (flags & 4) { // open WPS settings notebook for file
231 OpenObject(filename, Settings, hwnd);
232 return;
233 }
234
235 if ((flags & 16) || !IsFile(filename)) { // open info for directories
236
237 char fullname[CCHMAXPATH];
238
239 if (!IsFullName(filename)) {
240 if (!DosQueryPathInfo(filename,
241 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
242 filename = fullname;
243 }
244 if (IsFullName(filename) &&
245 !(driveflags[toupper(*filename) - 'A'] & DRIVE_INVALID)) {
246 if (!IsRoot(filename)) {
247 dummy[0] = filename;
248 dummy[1] = NULL;
249 WinDlgBox(HWND_DESKTOP,
250 HWND_DESKTOP,
251 FileInfoProc, FM3ModHandle, FLE_FRAME, (PVOID) dummy);
252 }
253 else
254 WinDlgBox(HWND_DESKTOP,
255 HWND_DESKTOP,
256 DrvInfoProc, FM3ModHandle, INFO_FRAME, (PVOID) filename);
257 }
258 return;
259 }
260
261 if (flags & 8) { // edit file
262
263 ULONG type = IDM_EDITTEXT;
264
265 dummy[0] = filename;
266 dummy[1] = NULL;
267 if (TestBinary(filename))
268 type = IDM_EDITBINARY;
269 switch (type) {
270 case IDM_EDITBINARY:
271 if (*bined) {
272 ExecOnList((HWND) 0, bined, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
273 pszSrcFile, __LINE__);
274 break;
275 }
276 // else intentional fallthru
277 case IDM_EDITTEXT:
278 if (*editor)
279 ExecOnList((HWND) 0, editor, WINDOWED | SEPARATE, NULL, NULL, dummy, NULL,
280 pszSrcFile, __LINE__);
281 else {
282 type = (type == IDM_EDITTEXT) ? 8 : (type == IDM_EDITBINARY) ? 16 : 0;
283 type |= 4;
284 StartMLEEditor(hwndParent, type, filename, hwndFrame);
285 }
286 break;
287 }
288 return;
289 }
290
291 if (ExecAssociation(hwnd, filename) == -1 &&
292 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
293 hwndArc = StartArcCnr((fExternalArcboxes || !swp ||
294 strcmp(realappname, FM3Str)) ?
295 HWND_DESKTOP :
296 hwndParent, hwndFrame, filename, 4, NULL);
297 if (!hwndArc) {
298 if (!IsExecutable(filename) || !ExecFile(hwnd, filename)) {
299 p = strrchr(filename, '.');
300 if (!p)
301 p = ".";
302 if (!stricmp(p, ".WPI")) {
303 OpenObject(filename, Default, hwnd);
304 return;
305 }
306 if (stricmp(p, ".INI") || !StartIniEditor(hwndParent, filename, 4)) {
307 if (stricmp(p, PCSZ_DOTHLP) || !ViewHelp(filename)) {
308 ViewIt:
309 if (TestBinary(filename)) {
310 if (!fCheckMM || !ShowMultimedia(filename)) {
311 if (*binview) {
312 dummy[0] = filename;
313 dummy[1] = NULL;
314 ExecOnList(hwnd,
315 binview,
316 WINDOWED | SEPARATE |
317 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
318 pszSrcFile, __LINE__);
319 }
320 else if (fUseNewViewer) {
321 if (fExternalViewer || strcmp(realappname, FM3Str))
322 hwndParent = HWND_DESKTOP;
323 StartViewer(hwndParent, 5, filename, hwndFrame);
324 }
325 else
326 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
327 }
328 }
329 else {
330 if (*viewer) {
331 dummy[0] = filename;
332 dummy[1] = NULL;
333 ExecOnList(hwnd,
334 viewer,
335 WINDOWED | SEPARATE |
336 ((fViewChild) ? CHILD : 0), NULL, NULL, dummy, NULL,
337 pszSrcFile, __LINE__);
338 }
339 else if (fUseNewViewer) {
340 if (fExternalViewer || strcmp(realappname, FM3Str))
341 hwndParent = HWND_DESKTOP;
342 StartViewer(hwndParent, 5, filename, hwndFrame);
343 }
344 else
345 StartMLEEditor(hwndParent, 5, filename, hwndFrame);
346 }
347 }
348 }
349 }
350 }
351 else {
352 if ((swp &&
353 !fExternalArcboxes &&
354 !strcmp(realappname, FM3Str)) &&
355 !ParentIsDesktop(hwnd, hwndParent))
356 WinSetWindowPos(hwndArc,
357 HWND_TOP,
358 swp->x,
359 swp->y,
360 swp->cx,
361 swp->cy,
362 SWP_MOVE | SWP_SIZE | SWP_SHOW |
363 SWP_ZORDER | SWP_ACTIVATE);
364 }
365 }
366}
367
368#pragma alloc_text(DEFVIEW,DefaultView,ShowMultimedia,DefaultViewKeys)
Note: See TracBrowser for help on using the repository browser.