source: trunk/savebmp.cpp@ 2

Last change on this file since 2 was 2, checked in by Gregg Young, 7 years ago

Gotcha 1.78 source from Hobbes

  • Property svn:eol-style set to native
File size: 20.9 KB
RevLine 
[2]1/***
2 This file belongs to the Gotcha! distribution.
3 Copyright (C) 1998-2002 Thorsten Thielen <thth@c2226.de>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***/
19
20#include <time.h>
21
22// ** SaveBitmap ********************************************************** /*fold00*/
23
24VOID SaveBitmap (HBITMAP hbm, HPS hps)
25{
26#ifdef _DOLOGMEM_
27 LogMem("SaveBitmap", TRUE);
28#endif
29
30 if( pset->QueryFileSaveStyle () == FSS_FORCEFILE )
31 {
32 PSZ psz = pset->QueryForceSaveFile();
33 psz = AddExtensionToFilename( psz );
34 SaveBitmapToFile( hbm, psz, hps );
35#ifdef _DOLOGMEM_
36 LogMem( "SaveBitmap-1", FALSE );
37#endif
38 return;
39 }
40
41 if (pset->DoSound ())
42 {
43 DosBeep ( 500, 100);
44 DosBeep (1000, 100);
45 DosBeep (1500, 100);
46 }
47
48 switch (pset->QuerySaveStyle ())
49 {
50 case SAVESTYLE_CLIPBOARD:
51 SaveBitmapToClipboard (hbm);
52 break;
53
54 default:
55#ifdef _DOLOGDEBUG_
56 LogDebug( "SaveBitmap()" );
57#endif
58 if (SelectSaveFile ()) {
59#ifdef _DOLOGDEBUG_
60 LogDebug( "Before call to SaveBitmapToFile()" );
61#endif
62 SaveBitmapToFile (hbm, pset->QuerySaveFile (), hps);
63#ifdef _DOLOGDEBUG_
64 LogDebug( "After call to SaveBitmapToFile()" );
65#endif
66 }
67 break;
68 }
69
70#ifdef _DOLOGMEM_
71 LogMem("SaveBitmap-2", FALSE);
72#endif
73}
74
75// ** SaveBitmapToClipboard *********************************************** /*FOLD00*/
76
77VOID SaveBitmapToClipboard (HBITMAP hbm)
78{
79#ifdef _DOLOGMEM_
80 LogMem("SaveBitmapToClipboard", TRUE);
81#endif
82 // copy the thing to the clipboard
83 WinOpenClipbrd (hab);
84 WinEmptyClipbrd (hab);
85 WinSetClipbrdData (hab, ULONG (hbm), CF_BITMAP, CFI_HANDLE);
86 WinCloseClipbrd (hab);
87#ifdef _DOLOGMEM_
88 LogMem("SaveBitmapToClipboard", FALSE);
89#endif
90}
91
92// ** SaveBitmapToFile **************************************************** /*FOLD00*/
93
94#define CB_12HEADER sizeof (BITMAPINFOHEADER) // == 12
95#define CB_16HEADER (sizeof (BITMAPINFOHEADER2)-24)
96#define CB_20HEADER sizeof (BITMAPINFOHEADER2) // == 64
97
98VOID SaveBitmapToFile (HBITMAP hbm, PSZ psz, HPS hps)
99{
100 ULONG rc;
101
102#ifdef _DOLOGMEM_
103 LogMem("SaveBitmapToFile", TRUE);
104#endif
105#ifdef _DOLOGDEBUG_
106 LogDebug( "Start of SaveBitmapToFile()" );
107#endif
108 // get the fullsized bitmap info header from the bitmap
109 BITMAPINFOHEADER2 bih2;
110
111 bih2.cbFix = sizeof (BITMAPINFOHEADER2);
112 if (! GpiQueryBitmapInfoHeader (hbm, &bih2))
113 {
114#ifdef _DOLOGDEBUG_
115 LogDebug( "SaveBitmapToFile(): Exit GpiQueryBitmapInfoHeader" );
116#endif
117 DisplayError (RSTR(IDS_HEADER_ERROR),
118 RSTR(IDS_ERROR_COULDNOTRETRIEVEHEADER),
119 WinGetLastError (hab));
120 return;
121 }
122#ifdef _DOLOGDEBUG_
123 LogDebug( "SaveBitmapToFile(): GpiQueryBitmapInfoHeader ok." );
124#endif
125
126 // get the size of the colortable
127 ULONG cbColtab = 0L, cColors = 0L;
128
129 if (bih2.cBitCount == 8)
130 cColors = 256L;
131 else if (bih2.cBitCount == 4)
132 cColors = 16L;
133 else if (bih2.cBitCount == 1)
134 cColors = 2L;
135
136 cbColtab = cColors * sizeof( RGB2 );
137
138 // get size of bits buffer and allocate it
139 ULONG cbBits =
140 (bih2.cBitCount * bih2.cx + 31L)/32L * bih2.cPlanes * 4L * bih2.cy;
141 PBYTE pb =
142 PBYTE (malloc (cbBits));
143
144 // allocate and init the file info header
145 PBITMAPFILEHEADER2 pbfh2 =
146 PBITMAPFILEHEADER2 (malloc (sizeof (BITMAPFILEHEADER2)+cbColtab));
147#ifdef _DOLOGDEBUG_
148 LogDebug( "SaveBitmapToFile(): Filling header." );
149#endif
150
151 // fill the bitmap header with the bitmap data
152 memcpy (&(pbfh2->bmp2), &bih2, sizeof (BITMAPINFOHEADER2));
153 pbfh2->bmp2.cbImage = cbBits;
154
155#ifdef _DOLOGDEBUG_
156 LogDebug( "SaveBitmapToFile(): Before GpiQueryBitmapBits." );
157#endif
158 // grab the bits!! ;-) - and the colortable
159 if (GpiQueryBitmapBits (hps, 0, bih2.cy, pb, PBITMAPINFO2 (&(pbfh2->bmp2)))
160 == GPI_ALTERROR)
161 {
162#ifdef _DOLOGDEBUG_
163 LogDebug( "SaveBitmapToFile(): Exit GpiQueryBitmapBits" );
164#endif
165 DisplayError (RSTR(IDS_HEADER_ERROR),
166 RSTR(IDS_ERROR_COULDNOTGETBITMAPBITS),
167 WinGetLastError (hab));
168 free (pb);
169 return;
170 }
171#ifdef _DOLOGDEBUG_
172 LogDebug( "SaveBitmapToFile(): GpiQueryBitmapBits ok." );
173#endif
174
175 pbfh2->usType = BFT_BMAP;
176 pbfh2->offBits = sizeof (BITMAPFILEHEADER2)-sizeof (BITMAPINFOHEADER2);
177
178 switch (pset->QueryFileFormat ())
179 {
180 case BMF_12:
181 pbfh2->offBits += CB_12HEADER + cColors*sizeof (RGB);
182 break;
183
184 case BMF_20:
185 pbfh2->offBits += CB_20HEADER + cColors*sizeof (RGB2);
186 break;
187
188 default:
189 pbfh2->offBits += CB_16HEADER + cColors*sizeof (RGB2);
190 break;
191 }
192
193 pbfh2->cbSize = pbfh2->offBits+cbBits;
194 pbfh2->xHotspot = pbfh2->yHotspot = 0;
195
196#ifdef _DOLOGDEBUG_
197 LogDebug( "SaveBitmapToFile(): Before if." );
198#endif
199 if( ( pset->QueryFileFormat() == BMF_12 ) ||
200 ( pset->QueryFileFormat() == BMF_16 ) ||
201 ( pset->QueryFileFormat() == BMF_20 ) )
202 {
203 // open out file
204 FILE *pf = fopen (psz, "wb");
205 if (! pf)
206 {
207 DisplayError (RSTR(IDS_HEADER_ERROR), RSTR(IDS_ERROR_COULDNOTOPENFILE),
208 psz);
209 free (pb);
210 return;
211 }
212
213 // write file info header
214 fwrite (pbfh2, sizeof (BITMAPFILEHEADER2)-sizeof (BITMAPINFOHEADER2),
215 1, pf);
216
217 // write bitmap info header
218 switch (pset->QueryFileFormat ())
219 {
220 case BMF_12:
221 {
222 BITMAPINFOHEADER bih;
223
224 bih.cbFix = CB_12HEADER;
225 bih.cx = USHORT (bih2.cx);
226 bih.cy = USHORT (bih2.cy);
227 bih.cPlanes = bih2.cPlanes;
228 bih.cBitCount = bih2.cBitCount;
229
230 fwrite (&bih, CB_12HEADER, 1, pf);
231 }
232 break;
233
234 case BMF_20:
235 pbfh2->bmp2.cbFix = CB_20HEADER;
236 fwrite (&(pbfh2->bmp2), CB_20HEADER, 1, pf);
237 break;
238
239 default:
240 pbfh2->bmp2.cbFix = CB_16HEADER;
241 fwrite (&(pbfh2->bmp2), CB_16HEADER, 1, pf);
242 break;
243 }
244
245 // write colortable if present
246 if (cbColtab)
247 {
248 switch (pset->QueryFileFormat ())
249 {
250 case BMF_12:
251 {
252 RGB rgb;
253 for (USHORT i = 0; i < cColors; i++)
254 {
255 rgb.bRed = PBITMAPINFO2 (&(pbfh2->bmp2))
256 ->argbColor[i].bRed;
257 rgb.bGreen = PBITMAPINFO2 (&(pbfh2->bmp2))
258 ->argbColor[i].bGreen;
259 rgb.bBlue = PBITMAPINFO2 (&(pbfh2->bmp2))
260 ->argbColor[i].bBlue;
261 fwrite (&rgb, sizeof (rgb), 1, pf);
262 }
263 }
264 break;
265
266 default:
267 fwrite (PBYTE (&(pbfh2->bmp2))+sizeof (BITMAPINFOHEADER2),
268 cbColtab, 1, pf);
269 break;
270 }
271 }
272
273 // write the actual bitmap data bits
274 fwrite (pb, cbBits, 1, pf);
275 fclose (pf);
276 } else {
277#ifdef _DOLOGDEBUG_
278 LogDebug( "SaveBitmapToFile(): Starting 'else' path." );
279#endif
280 PFN xmmioClose = pset->GetMMIO()->pfmmioClose;
281// PFN xmmioOpen = pset->GetMMIO()->pfmmioOpen;
282 PFN xmmioWrite = pset->GetMMIO()->pfmmioWrite;
283 PFN xmmioQueryHeaderLength = pset->GetMMIO()->pfmmioQueryHeaderLength;
284 PFN xmmioSetHeader = pset->GetMMIO()->pfmmioSetHeader;
285
286#ifdef _DOLOGDEBUG_
287 LogDebug( "SaveBitmapToFile(): Before GetFOURCC." );
288#endif
289 // ********* WRITE TARGET
290 FOURCC fccTargetIOProc = pset->GetFOURCC();
291
292 // Initialize our info MMIOINFO structure.
293 MMIOINFO mmioinfoTarget;
294#ifdef _DOLOGDEBUG_
295 LogDebug( "SaveBitmapToFile(): Before memset." );
296#endif
297 memset( &mmioinfoTarget, 0L, sizeof( MMIOINFO ) );
298 mmioinfoTarget.fccIOProc = fccTargetIOProc;
299 mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
300
301#ifdef _DOLOGDEBUG_
302 LogDebug( "SaveBitmapToFile(): Trying to open file." );
303#endif
304 // Open target file.
305 HMMIO hmmioTarget;
306 if( ! ( hmmioTarget = pset->GetMMIO()->pfmmioOpen( psz,
307 &mmioinfoTarget,
308 MMIO_CREATE | MMIO_WRITE |
309 MMIO_DENYWRITE | MMIO_NOIDENTIFY ) ) ) {
310 DisplayError ("mmioOpen()-Error",
311 "mmioOpen()-Error %ld", mmioinfoTarget.ulErrorRet );
312 return;
313 }
314#ifdef _DOLOGDEBUG_
315 LogDebug( "SaveBitmapToFile(): Open file ok." );
316#endif
317
318 // Set the target header.
319 ULONG ulImageHeaderLength;
320
321 xmmioQueryHeaderLength( hmmioTarget, (PLONG)&ulImageHeaderLength, 0L, 0L );
322 if( ulImageHeaderLength != sizeof( MMIMAGEHEADER ) )
323 {
324 // We have a problem.....possibly incompatible versions.
325 xmmioClose( hmmioTarget, 0L );
326 DisplayError ("mmioQueryHeaderLength()-Error",
327 "mmioQueryHeaderLength()-Error",
328 WinGetLastError (hab));
329 return;
330 }
331#ifdef _DOLOGDEBUG_
332 LogDebug( "SaveBitmapToFile(): xmmioQueryHeaderLength ok." );
333#endif
334
335 MMIMAGEHEADER mmImgHdr;
336 mmImgHdr.ulHeaderLength = ulImageHeaderLength;
337 mmImgHdr.ulContentType = MMIO_IMAGE_UNKNOWN;
338 mmImgHdr.ulMediaType = MMIO_MEDIATYPE_IMAGE;
339
340#ifdef _DOLOGDEBUG_
341 LogDebug( "SaveBitmapToFile(): Before memcpy (colors)." );
342#endif
343 memcpy( mmImgHdr.bmiColors,
344 PBYTE( &( pbfh2->bmp2 ) ) + sizeof( BITMAPINFOHEADER2 ),
345 cbColtab );
346
347 mmImgHdr.mmXDIBHeader.XDIBHeaderPrefix.ulMemSize = cbBits; // FIXME;
348 mmImgHdr.mmXDIBHeader.XDIBHeaderPrefix.ulPelFormat = 0; // FIXME;
349 mmImgHdr.mmXDIBHeader.XDIBHeaderPrefix.usTransType = 0; // FIXME
350 mmImgHdr.mmXDIBHeader.XDIBHeaderPrefix.ulTransVal = 0; // FIXME
351 memcpy( &(mmImgHdr.mmXDIBHeader.BMPInfoHeader2), &bih2, sizeof (BITMAPINFOHEADER2));
352
353#ifdef _DOLOGDEBUG_
354 LogDebug( "SaveBitmapToFile(): Before xmmioSetHeader." );
355#endif
356 ULONG ulBytesRead;
357 if( ( rc = (LONG)xmmioSetHeader( hmmioTarget, (MMIMAGEHEADER*)&mmImgHdr,
358 (LONG)sizeof( MMIMAGEHEADER ), (PLONG)&ulBytesRead,
359 0L, 0L ) ) != MMIO_SUCCESS )
360 {
361 // Header unavailable.
362 xmmioClose( hmmioTarget, 0L );
363 DisplayError ("mmioSetHeader()-Error",
364 "mmioSetHeader()-Error %ld", rc );
365 return;
366 }
367#ifdef _DOLOGDEBUG_
368 LogDebug( "SaveBitmapToFile(): xmmioSetHeader ok." );
369#endif
370
371 // write the actual bitmap data bits
372 if( ( rc = xmmioWrite( hmmioTarget, pb, cbBits ) ) == MMIO_ERROR )
373 DisplayError ("mmioWrite()-Error",
374 "mmioWrite()-Error %ld", rc );
375#ifdef _DOLOGDEBUG_
376 LogDebug( "SaveBitmapToFile(): xmmioWrite ok." );
377#endif
378
379 if( ( rc = xmmioClose( hmmioTarget, 0 ) ) != MMIO_SUCCESS )
380 DisplayError ("mmioClose()-Error",
381 "mmioClose()-Error %ld", rc );
382#ifdef _DOLOGDEBUG_
383 LogDebug( "SaveBitmapToFile(): xmmioClose ok." );
384#endif
385 }
386
387#ifdef _DOLOGDEBUG_
388 LogDebug( "SaveBitmapToFile(): Everything done, closed file" );
389#endif
390
391 // set BITMAP file type ea
392 SetEAs( psz );
393
394 // cleanup and return
395 free (pbfh2);
396 free (pb);
397#ifdef _DOLOGMEM_
398 LogMem("SaveBitmapToFile", FALSE);
399#endif
400}
401
402// ** SetEAs ************************************************************** /*FOLD00*/
403
404BOOL SetEAs (PSZ psz)
405{
406#ifdef _DOLOGMEM_
407 LogMem("SetEAs", TRUE);
408#endif
409 // alloc memory for EA data
410 CHAR achComment[ 100 ];
411 time_t tim = time_t( time( NULL ) );
412 sprintf( achComment, "Captured by %s on %s", PSZ_NAMEVERSION, ctime( &tim ) );
413 PSZ pszName = ".TYPE", pszName2 = ".COMMENT";
414 PSZ pszValue = pset->GetFileEAType();
415 USHORT cbName = strlen (pszName)+1, cbName2 = strlen( pszName2 )+1;
416 USHORT cbValue = strlen (pszValue)+1, cbValue2 = strlen( achComment )+1;
417 USHORT usMemNeeded = sizeof (FEA2LIST) + cbName + cbValue +cbName2 + cbValue2;
418 PBYTE pb = PBYTE (malloc (usMemNeeded));
419
420 EAOP2 eaop2;
421
422 eaop2.fpFEA2List = (FEA2LIST FAR *) pb;
423 eaop2.fpFEA2List->cbList = usMemNeeded;
424
425 eaop2.fpFEA2List->list[0].fEA = 0; // EA is no "must have"
426 eaop2.fpFEA2List->list[0].cbName = cbName-1;
427 eaop2.fpFEA2List->list[0].cbValue = cbValue;
428 eaop2.fpFEA2List->list[1].fEA = 0; // EA is no "must have"
429 eaop2.fpFEA2List->list[1].cbName = cbName2-1;
430 eaop2.fpFEA2List->list[1].cbValue = cbValue2;
431
432 strcpy (eaop2.fpFEA2List->list[0].szName, pszName);
433 memcpy (eaop2.fpFEA2List->list[0].szName+cbName, pszValue, cbValue);
434 strcpy (eaop2.fpFEA2List->list[1].szName, pszName2);
435 memcpy (eaop2.fpFEA2List->list[1].szName+cbName2, achComment, cbValue2);
436
437 if (DosSetPathInfo (psz, FIL_QUERYEASIZE, PVOID (&eaop2),
438 sizeof (EAOP2), DSPI_WRTTHRU))
439 {
440 DisplayError (RSTR(IDS_HEADER_ERROR),
441 RSTR(IDS_ERROR_COULDNOTWRITEFILETYPEEA));
442 free (pb);
443#ifdef _DOLOGMEM_
444 LogMem("SetEAs-1", FALSE);
445#endif
446 return FALSE;
447 }
448
449 free (pb);
450#ifdef _DOLOGMEM_
451 LogMem("SetEAs-2", FALSE);
452#endif
453 return TRUE;
454}
455
456// ** SelectSaveFile ****************************************************** /*FOLD00*/
457
458BOOL SelectSaveFile (VOID)
459{
460#ifdef _DOLOGMEM_
461 LogMem("SelectSaveFile", TRUE);
462#endif
463 // if FSS_NUMFILES, create and return a new name
464 if (pset->QueryFileSaveStyle () == FSS_NUMFILES)
465 {
466 CHAR ach[_MAX_PATH];
467 for (USHORT i = 0; i < 10000; i++)
468 {
469 sprintf( ach, "%s\\got%05d.%s", pset->QueryNumSaveDir(), i,
470 pset->GetFileExtension() );
471 if (access (ach, 0) != 0)
472 {
473 pset->SetSaveFile (ach);
474 return TRUE;
475 }
476 }
477 return FALSE;
478 }
479
480 // ... else do a file dlg
481 FILEDLG fdlg;
482
483 memset (&fdlg, 0, sizeof (fdlg));
484
485 fdlg.hMod = GETMODULE;
486 fdlg.usDlgId = ID_DLG_FILE;
487 fdlg.pfnDlgProc = FileDLGProcedure;
488 fdlg.cbSize = sizeof (fdlg);
489 fdlg.fl = FDS_SAVEAS_DIALOG | FDS_CENTER | FDS_CUSTOM;
490 fdlg.pszTitle = RSTR(IDS_SAVESCREENSHOTTO);
491 strcpy (fdlg.szFullFile, pset->QuerySaveFile ());
492
493 if (WinFileDlg (HWND_DESKTOP, HWND_DESKTOP, &fdlg))
494 {
495 if (fdlg.lReturn != DID_OK)
496 return FALSE;
497
498 PSZ pszOut = fdlg.szFullFile;
499
500 // Add bmp extension if not already present.
501 if( pset->AutoaddExtension() )
502 pszOut = AddExtensionToFilename( pszOut );
503
504 // if file exists and user wants it, confirm overwriting
505 if (pset->ConfirmOverwrite ())
506 if (access (pszOut, 0) == 0)
507 // let user confirm operation
508 if (WinMessageBox (HWND_DESKTOP, HWND_DESKTOP,
509 RSTR(IDS_FILEEXISTSOVERWRITE),
510 RSTR(IDS_HEADER_WARNING), 0L,
511 MB_OKCANCEL | MB_QUERY | MB_DEFBUTTON2 |
512 MB_MOVEABLE)
513 != MBID_OK)
514 return FALSE;
515
516 pset->SetSaveFile (pszOut);
517 return TRUE;
518 }
519 return FALSE;
520#ifdef _DOLOGMEM_
521 LogMem("SelectSaveFile", FALSE);
522#endif
523}
524
525// ** FileDLGProcedure **************************************************** /*fold00*/
526
527MRESULT EXPENTRY FileDLGProcedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
528{
529#ifdef _DOFNCOMPLETION_
530 static HDIR hdir = NULLHANDLE;
531 static BOOL fCompletion = FALSE;
532#endif
533
534 switch (msg)
535 {
536 case WM_INITDLG:
537 WinSendDlgItemMsg (hwnd, WID_CB_AUTOADDEXTENSION, BM_SETCHECK,
538 MPFROMLONG (pset->AutoaddExtension ()),
539 MPFROMLONG (0));
540 WinSendDlgItemMsg (hwnd, WID_CB_CONFIRMOVERWRITE, BM_SETCHECK,
541 MPFROMLONG (pset->ConfirmOverwrite ()),
542 MPFROMLONG (0));
543/* FIXME neither work ... WinSendDlgItemMsg (hwnd, DID_FILES_LB, WM_ENABLE,
544 MPFROMLONG (TRUE),
545 MPFROMLONG (0));
546 //WinEnableWindow( WinWindowFromID( hwnd, DID_FILES_LB ), TRUE ); */
547 break;
548
549#ifdef _DOFNCOMPLETION_
550 case WM_CHAR: {
551 HWND hwndFNE = WinWindowFromID (hwnd, DID_FILENAME_ED);
552 if (WinQueryFocus (HWND_DESKTOP) == hwndFNE)
553 {
554 // tab key, downpress
555 if ((CHARMSG (&msg)->chr == 9) && !
556 (CHARMSG (&msg)->fs & KC_KEYUP))
557 {
558 ULONG c = 1, fl;
559 FILEFINDBUF3 findbuf;
560 APIRET rc;
561 CHAR ach[_MAX_PATH];
562
563 if (! hdir)
564 {
565 WinQueryWindowText (hwndFNE, _MAX_PATH-1, ach);
566 strcat (ach, "*");
567 fl = FILE_NORMAL;
568 hdir = HDIR_CREATE;
569 rc = DosFindFirst (ach, &hdir, fl, &findbuf,
570 sizeof (findbuf), &c,
571 FIL_STANDARD);
572 }
573 else
574 {
575 rc = DosFindNext (hdir, &findbuf,
576 sizeof (findbuf), &c);
577 }
578
579 if (! rc)
580 {
581 fCompletion = TRUE;
582 WinSetWindowText (hwndFNE, findbuf.achName);
583 fCompletion = FALSE;
584 }
585 else
586 DosBeep (1000, 10);
587 return MRESULT (FALSE);
588 }
589 } } break;
590
591 case WM_CONTROL:
592 switch (SHORT1FROMMP (mp1))
593 {
594 case DID_FILENAME_ED:
595 if ((SHORT2FROMMP (mp1) == EN_CHANGE) ||
596 (SHORT2FROMMP (mp1) == EN_KILLFOCUS))
597 if (hdir && !fCompletion)
598 {
599 // FIXME maybe do this to when closing dialog?
600 DosFindClose (hdir);
601 hdir = NULLHANDLE;
602 }
603 break;
604 }
605 break;
606#endif
607
608 case WM_COMMAND:
609 case WM_CLOSE:
610 pset->AutoaddExtension
611 (BOOL (WinSendDlgItemMsg (hwnd, WID_CB_AUTOADDEXTENSION,
612 BM_QUERYCHECK, 0, 0)));
613 pset->ConfirmOverwrite
614 (BOOL (WinSendDlgItemMsg (hwnd, WID_CB_CONFIRMOVERWRITE,
615 BM_QUERYCHECK, 0, 0)));
616 break;
617 }
618
619 return WinDefFileDlgProc (hwnd, msg, mp1, mp2);
620}
621
622// ** AddExtensionToFilename ********************************************** /*fold00*/
623
624PSZ AddExtensionToFilename( PSZ psz )
625{
626 // Using a static buffer here is not really good, but good enough
627 // currently as we know there will be no concurrent access.
628 static CHAR ach[_MAX_PATH];
629 PSZ pszExtension;
630
631 PSZ apszValidExtensions[10] =
632 { "bmp", "tif", "tiff", "tga", "targa", "pcx", "gif", "jpg", "jpeg", "dib" };
633
634 if( ! ( pszExtension = strrchr( psz, '.' ) ) ) {
635 // No extension at all - add the appropriate one.
636 sprintf( ach, "%s.%s", psz, pset->GetFileExtension() );
637 } else if( stricmp ( pszExtension+1, pset->GetFileExtension() ) == 0 ) {
638 // Correct extension already - just return unchanged filename.
639 strcpy( ach, psz );
640 } else {
641 // Some extension, but not the correct one - change or append.
642 BOOL fValidExtension = FALSE;
643 for( int i = 0; i < 10; i++ ) {
644 if( stricmp( pszExtension+1, apszValidExtensions[i] ) == 0 ) {
645 fValidExtension = TRUE;
646 break;
647 }
648 }
649 if( fValidExtension ) {
650 // Valid extension, but not right for current format - replace.
651 *pszExtension = '\0';
652 sprintf( ach, "%s.%s", psz, pset->GetFileExtension() );
653 } else {
654 // Some extension but not a valid image file format extension - add.
655 sprintf( ach, "%s.%s", psz, pset->GetFileExtension() );
656 }
657 }
658 return ach;
659}
660
661// ************************************************************************
Note: See TracBrowser for help on using the repository browser.