1 //---------------------------------------------------------------------------
2 #include <vcl.h>
3 #include <stdlib.h>
4 #include <dir.h>
5 #pragma hdrstop
6 //---------------------------------------------------------------------------
7 #pragma package(smart_init)
8 #pragma resource "*.dfm"
9 #include "Main.h"
10 TMainForm *MainForm;
11 //---------------------------------------------------------------------------
12 #include "About.h"
13 #include "Help.h"
14 
15 # define PAGE_CHUNKS    1
16 # define PAGE_REPORT    2
17 # define PAGE_OPTIONS   3
18 # define PAGE_ABOUT     4
19 # define PAGE_HELP      5
20 
21 /* ************************************************************************** */
22 /* *                                                                        * */
23 /* *          MngDump is based on Gerard Juyn's MngTree                     * */
24 /* *                                                                        * */
25 /* * COPYRIGHT NOTICE:                                                      * */
26 /* *                                                                        * */
27 /* * Copyright (c) 2000 Andy Protano                                        * */
28 /* *                    Gerard Juyn (gerard@libmng.com)                     * */
29 /* * [You may insert additional notices after this sentence if you modify   * */
30 /* *  this source]                                                          * */
31 /* *                                                                        * */
32 /* * For the purposes of this copyright and license, "Contributing Authors" * */
33 /* * is defined as the following set of individuals:                        * */
34 /* *                                                                        * */
35 /* *    Gerard Juyn (gerard@libmng.com)                                     * */
36 /* *    Andy Protano (a.a.protano@care4free.net)                            * */
37 /* *                                                                        * */
38 /* * This program is supplied "AS IS".  The Contributing Authors            * */
39 /* * disclaim all warranties, expressed or implied, including, without      * */
40 /* * limitation, the warranties of merchantability and of fitness for any   * */
41 /* * purpose.  The Contributing Authors assume no liability for direct,     * */
42 /* * indirect, incidental, special, exemplary, or consequential damages,    * */
43 /* * which may result from the use of the MNG Library, even if advised of   * */
44 /* * the possibility of such damage.                                        * */
45 /* *                                                                        * */
46 /* * Permission is hereby granted to use, copy, modify, and distribute this * */
47 /* * source code, or portions hereof, for any purpose, without fee, subject * */
48 /* * to the following restrictions:                                         * */
49 /* *                                                                        * */
50 /* * 1. The origin of this source code must not be misrepresented;          * */
51 /* *    you must not claim that you wrote the original software.            * */
52 /* *                                                                        * */
53 /* * 2. Altered versions must be plainly marked as such and must not be     * */
54 /* *    misrepresented as being the original source.                        * */
55 /* *                                                                        * */
56 /* * 3. This Copyright notice may not be removed or altered from any source * */
57 /* *    or altered source distribution.                                     * */
58 /* *                                                                        * */
59 /* * The Contributing Authors specifically permit, without fee, and         * */
60 /* * encourage the use of this source code as a component to supporting     * */
61 /* * the MNG and JNG file format in commercial products.  If you use this   * */
62 /* * source code in a product, acknowledgment would be highly appreciated.  * */
63 /* *                                                                        * */
64 /* ************************************************************************** */
65 
66 //---------------------------------------------------------------------------
67 //---------------------------------------------------------------------------
TMainForm(TComponent * Owner)68 __fastcall TMainForm::TMainForm(TComponent* Owner)
69   : TForm(Owner)
70 {
71 }
72 //---------------------------------------------------------------------------
~TMainForm(void)73 __fastcall TMainForm::~TMainForm( void )
74 {
75 }
76 //---------------------------------------------------------------------------
OnMinMax(TMessage & Msg)77 void __fastcall TMainForm::OnMinMax(TMessage& Msg)
78 {
79   ((POINT far *)Msg.LParam)[3].x = 500;
80   ((POINT far *)Msg.LParam)[3].y = 450;
81 
82   TForm::Dispatch(&Msg);
83 }
84 //---------------------------------------------------------------------------
85 //								MessageBox Methods
86 // ----------------------------------------------------------------------
MessageBox(String & as,UINT flags)87 int __fastcall TMainForm::MessageBox( String &as, UINT flags )
88 {
89   return ::MessageBox( Handle, as.c_str(), Application->Title.c_str(), flags );
90 }
91 // ----------------------------------------------------------------------
MsgBoxOk(String as)92 void __fastcall  TMainForm::MsgBoxOk( String as )
93 {
94   (void)MessageBox( as, MB_ICONINFORMATION );
95 }
96 //-------------------------------------------------------------------------
MsgBoxYN(String as)97 int __fastcall  TMainForm::MsgBoxYN( String as )
98 {
99   return MessageBox( as, MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON1 );
100 }
101 //-------------------------------------------------------------------------
MsgBoxYNC(String as)102 int __fastcall  TMainForm::MsgBoxYNC( String as )
103 {
104   return MessageBox( as, MB_YESNOCANCEL | MB_ICONQUESTION );
105 }
106 //-------------------------------------------------------------------------
MsgBoxStop(String as)107 void __fastcall  TMainForm::MsgBoxStop( String as )
108 {
109   (void)MessageBox( as, MB_ICONSTOP );
110 }
111 //-------------------------------------------------------------------------
MsgBoxInfo(String as)112 void __fastcall  TMainForm::MsgBoxInfo( String as )
113 {
114   (void)MessageBox( as, MB_OK | MB_ICONINFORMATION );
115 }
116 //-------------------------------------------------------------------------
MsgBoxWarn(String as)117 void __fastcall  TMainForm::MsgBoxWarn( String as )
118 {
119   (void)MessageBox( as, MB_OK | MB_ICONWARNING );
120 }
121 //-------------------------------------------------------------------------
FormCreate(TObject * Sender)122 void __fastcall TMainForm::FormCreate(TObject *Sender)
123 {
124   // For when the application name changes - coz i'll forget !
125   asAppName = Application->Title;
126   // And while we've got it set the caption
127   Caption = Application->Title;
128 
129   // Load About Screen
130   LabelAbout->Caption = _szAbout;
131   // Load Help Screen
132   LabelHelp->Caption  = _szHelp;
133 
134   fd = NULL;
135   strList = new TStringList();
136 
137   asTab = "  ";// default tab size 2
138   RadioGroupTabSize->ItemIndex = 1; // range is zero based
139 
140   // Start with the help pane
141   PageControl1->ActivePage = tsHelp;
142 
143   mnuWordWrap->Checked = false;
144   // This call will TOGGLE and set word wrap for all the applicables
145   // editors and enable/disable the Horz scroll bar.
146   mnuWordWrapClick( this ); // So start with false to get to true;
147 
148   // Clear things from design time settings
149   StaticTextStatus->Caption = "";
150   //strList->Clear(); constructor dodid that
151   pnlChunks->Caption = "";
152   ListBoxChunks->Clear();
153   RichEditChunks->Clear();
154   RichEditReport->Clear();
155   ProgressBar1->Min = 0;
156   ProgressBar1->Position = 0;
157   SetChunkCount( 0 );
158 
159   // Set default states for switches
160   cbPaletteEntries->Checked   = false;
161   cbRGBOrder->Checked         = true;
162   cbRawData->Checked          = true;
163   cbComments->Checked         = true;
164   cbMacroIdentifier->Checked  = true;
165   cbBool->Checked             = true;
166 }
167 //---------------------------------------------------------------------------
FormDestroy(TObject * Sender)168 void __fastcall TMainForm::FormDestroy(TObject *Sender)
169 {
170   delete strList;
171 }
172 //---------------------------------------------------------------------------
mnuExitClick(TObject * Sender)173 void __fastcall TMainForm::mnuExitClick(TObject *Sender)
174 {
175   Close();
176 }
177 //---------------------------------------------------------------------------
mnuFileOpenClick(TObject * Sender)178 void __fastcall TMainForm::mnuFileOpenClick(TObject *Sender)
179 {
180   if( !OpenDialog1->Execute() )
181     return;
182 
183   Application->ProcessMessages(); // Refresh the screen
184   LoadFile();
185 
186 }
187 //---------------------------------------------------------------------------
mnuReloadClick(TObject * Sender)188 void __fastcall TMainForm::mnuReloadClick(TObject *Sender)
189 {
190   // Only reload - if we have something to reload
191   if( OpenDialog1->FileName.Length() )
192     LoadFile();
193   else
194     MsgBoxStop( "Nothing to reload yet !" );
195 }
196 //---------------------------------------------------------------------------
mnuUndoClick(TObject * Sender)197 void __fastcall TMainForm::mnuUndoClick(TObject *Sender)
198 {
199   if( RichEditReport->Lines->Count )  // Do we have something in there ?
200     RichEditReport->Undo();
201 }
202 //---------------------------------------------------------------------------
mnuCutClick(TObject * Sender)203 void __fastcall TMainForm::mnuCutClick(TObject *Sender)
204 {
205   if( RichEditReport->Lines->Count )  // Do we have something in there ?
206     RichEditReport->CutToClipboard();
207 }
208 //---------------------------------------------------------------------------
mnuCopyClick(TObject * Sender)209 void __fastcall TMainForm::mnuCopyClick(TObject *Sender)
210 {
211   if( RichEditReport->Lines->Count )  // Do we have something in there ?
212     RichEditReport->CopyToClipboard();
213 }
214 //-------------------------------------------------------------------------
sbtnCopyChunkClick(TObject * Sender)215 void __fastcall TMainForm::sbtnCopyChunkClick(TObject *Sender)
216 {
217   if( RichEditChunks->Lines->Count )  // Do we have something in there ?
218   {
219     // Copy chunk data from Chunks pane to clipboard
220     RichEditChunks->SelectAll();
221     RichEditChunks->CopyToClipboard();
222     RichEditChunks->SelLength = 0;
223   }
224 }
225 //---------------------------------------------------------------------------
mnuPasteClick(TObject * Sender)226 void __fastcall TMainForm::mnuPasteClick(TObject *Sender)
227 {
228   if( RichEditReport->Lines->Count )  // Do we have something in there ?
229     RichEditReport->PasteFromClipboard();
230 }
231 //---------------------------------------------------------------------------
mnuSelectAllClick(TObject * Sender)232 void __fastcall TMainForm::mnuSelectAllClick(TObject *Sender)
233 {
234   if( RichEditReport->Lines->Count )  // Do we have something in there ?
235     RichEditReport->SelectAll();
236 }
237 //---------------------------------------------------------------------------
mnuWordWrapClick(TObject * Sender)238 void __fastcall TMainForm::mnuWordWrapClick(TObject *Sender)
239 {
240 bool  bWrap;
241 
242   mnuWordWrap->Checked = !mnuWordWrap->Checked;
243   bWrap = mnuWordWrap->Checked;
244 
245   RichEditChunks->WordWrap = bWrap;
246   RichEditReport->WordWrap = bWrap;
247 
248   if( bWrap ) { // if Word wrap on then no need for horizontal scrollbar
249     RichEditChunks->ScrollBars = ssVertical;
250     RichEditReport->ScrollBars = ssVertical;
251   } else { // Horizontal scrollbar required (auto)
252     RichEditChunks->ScrollBars = ssBoth;
253     RichEditReport->ScrollBars = ssBoth;
254   }
255 }
256 //---------------------------------------------------------------------------
mnuSetFontClick(TObject * Sender)257 void __fastcall TMainForm::mnuSetFontClick(TObject *Sender)
258 {
259   if( FontDialog1->Execute() )
260   {
261     RichEditChunks->Font = FontDialog1->Font;
262     RichEditReport->Font = FontDialog1->Font;
263   }
264 }
265 //---------------------------------------------------------------------------
FontDialog1Apply(TObject * Sender,HWND Wnd)266 void __fastcall TMainForm::FontDialog1Apply(TObject *Sender, HWND Wnd)
267 {
268   RichEditChunks->Font = FontDialog1->Font;
269   RichEditReport->Font = FontDialog1->Font;
270 }
271 //---------------------------------------------------------------------------
mnuFindClick(TObject * Sender)272 void __fastcall TMainForm::mnuFindClick(TObject *Sender)
273 {
274   if( RichEditReport->Lines->Count == 0 )
275   {
276     MsgBoxStop( "Find what ?.");
277     return;
278   }
279 
280   FindDialog->Execute();
281 }
282 //---------------------------------------------------------------------------
FindDialogFind(TObject * Sender)283 void __fastcall TMainForm::FindDialogFind(TObject *Sender)
284 {
285 TSearchTypes st;
286 TFindDialog *fd;
287 int newpos;
288 
289   if( RichEditReport->Lines->Count == 0 )
290   {
291     MsgBoxStop( "Find what ?.");
292     return;
293   }
294 
295   fd = dynamic_cast<TFindDialog *>( Sender );
296 
297   if( fd->Options.Contains( frMatchCase ) )
298       st << stMatchCase;
299   if( fd->Options.Contains( frWholeWord ) )
300       st << stWholeWord;
301 
302   if( RichEditReport->SelLength )
303       RichEditReport->SelStart += 1;
304 
305   newpos = RichEditReport->FindText( fd->FindText,
306         RichEditReport->SelStart, RichEditReport->Text.Length(), st );
307 
308   if( newpos != -1 ) {
309     RichEditReport->SelStart = newpos;
310     RichEditReport->SelLength = fd->FindText.Length();
311   } else {
312     MsgBoxInfo( "End of document reached." );
313     RichEditReport->SelStart = 0;
314   }
315 }
316 //---------------------------------------------------------------------------
mnuFindNextClick(TObject * Sender)317 void __fastcall TMainForm::mnuFindNextClick(TObject *Sender)
318 {
319   if( RichEditReport->Lines->Count == 0 )
320   {
321     MsgBoxStop( "Find what ?.");
322     return;
323   }
324 
325   FindDialogFind( FindDialog );
326 }
327 //---------------------------------------------------------------------------
mnuPrintClick(TObject * Sender)328 void __fastcall TMainForm::mnuPrintClick(TObject *Sender)
329 {
330   if( RichEditReport->Lines->Count == 0 )
331   {
332     MsgBoxStop( "I can't find anything to print !.");
333     return;
334   }
335 
336   RichEditReport->Print( ExtractFileName( OpenDialog1->FileName ) );
337 
338 }
339 //---------------------------------------------------------------------------
mnuPrintSetupClick(TObject * Sender)340 void __fastcall TMainForm::mnuPrintSetupClick(TObject *Sender)
341 {
342   PrinterSetupDialog->Execute();
343 }
344 //---------------------------------------------------------------------------
mnuSaveClick(TObject * Sender)345 void __fastcall TMainForm::mnuSaveClick(TObject *Sender)
346 {
347   if( RichEditReport->Lines->Count == 0 )
348   {
349     MsgBoxStop( "I can't find anything to save !.");
350     return;
351   }
352 
353   // Grab the graphic's filename and change to "txt" extension
354   {
355   char    szFile[ MAXFILE ];
356   char    szExt[ MAXEXT ];
357   char    szDest[ MAXPATH ];
358   String  as;
359 
360     fnsplit( OpenDialog1->FileName.c_str(), NULL, NULL, szFile, szExt );
361 
362     memset( szDest, 0, MAXPATH );
363     strcat( szDest, szFile );
364     strcat( szDest, "\." );
365     strcat( szDest, "txt" );
366     as = szDest;
367 
368     // Initially create a text file of the same name as the graphic
369     // but with "txt" extension
370     SaveDialog1->FileName = as;
371   }
372 
373   if( !SaveDialog1->Execute() )
374     return; // Given up hey ?
375 
376   RichEditReport->Lines->SaveToFile( SaveDialog1->FileName );
377 }
378 //---------------------------------------------------------------------------
379 //---------------------------------------------------------------------------
380 //---------------------------------------------------------------------------
LoadFile(void)381 void __fastcall TMainForm::LoadFile( void )
382 {
383 int     bStatus;
384 
385   // Can we open the file ?
386   if( (fd = fopen( OpenDialog1->FileName.c_str(), "rb") ) == NULL )
387   {
388     MsgBoxStop( "Cannot open input file\n\n" + OpenDialog1->FileName );
389     return;
390   }
391 
392   pnlChunks->Caption = "";
393   strList->Clear();
394   ListBoxChunks->Clear();
395   RichEditChunks->Clear();
396   RichEditReport->Clear();
397 
398   ProgressBar1->Min = 0;
399   ProgressBar1->Position = 0;
400   SetChunkCount( 0 );
401 
402   RichEditReport->Lines->Add( "" );
403   RichEditReport->Lines->Add( "Chunk contents of file :" );
404   RichEditReport->Lines->Add( OpenDialog1->FileName );
405   RichEditReport->Lines->Add( "" );
406 
407   // Make report pane visible - prove we are working and not locked up
408   PageControl1->ActivePage = tsReport;
409 
410 try {
411     StaticTextStatus->Caption = "Working ... please wait";
412     StaticTextStatus->Update();
413     bStatus = DumpTree(); // true indicates success
414 }
415 __finally {
416     ProgressBar1->Position = 0;
417     StaticTextStatus->Caption = "Ok";
418     fclose( fd );
419     fd = NULL;
420 }
421 
422   if( !bStatus ) // We have an error
423   {
424     pnlChunks->Caption = "";
425     strList->Clear();
426     ListBoxChunks->Clear();
427     RichEditChunks->Clear();
428 
429     RichEditReport->Lines->Add("");
430     RichEditReport->Lines->Add("An error occurred while reading the file.");
431 
432   } else {  // Read file and chunks without any problems
433 
434     // Set Report Panels caption
435     pnlChunks->Caption = "Chunk 1 of " + String( ListBoxChunks->Items->Count );
436 
437     // Set Listbox to first item
438     ListBoxChunks->ItemIndex = 0;
439 
440     // Put gleeful message in report pane
441     RichEditChunks->Lines->Add( "" );
442     RichEditChunks->Lines->Add(
443       "No error's found when reading file ... " );
444     RichEditChunks->Lines->Add(
445       "Click the list box to display the data for each chunk.");
446 
447     // Place cursor at top of editor
448     RichEditChunks->SelStart = 0;
449     RichEditChunks->SelLength = 0;
450 
451     // Place cursor at top of editor
452     RichEditReport->SelStart = 0;
453     RichEditReport->SelLength = 0;
454 
455     // Lock richedits - so an immediate undo does not make data vanish !
456     RichEditReport->Modified = false;
457     // @ap@ Borland should fix this ! (it don't work)
458   }
459 
460 }
461 //---------------------------------------------------------------------------
DumpTree(void)462 bool __fastcall TMainForm::DumpTree( void )
463 {
464 mng_handle  hMNG;
465 
466   // let's initialize the library
467   hMNG = mng_initialize( (mng_ptr)this, Alloc, Free, NULL );
468 
469   if( !hMNG )                           // did that work out ?
470   {
471     MNGError( hMNG, "Cannot initialize libmng." );
472     mng_cleanup( &hMNG ); // Always cleanup the library
473     MsgBoxStop( "Bye!" );
474     Application->Terminate(); // Exit now
475   }
476 
477   // setup callbacks
478   if( (mng_setcb_openstream   ( hMNG, OpenStream    ) != 0) ||
479       (mng_setcb_closestream  ( hMNG, CloseStream   ) != 0) ||
480       (mng_setcb_processheader( hMNG,ProcessHeader  ) != 0) ||
481       (mng_setcb_readdata     ( hMNG, FileReadData  ) != 0)
482     )
483   {
484     MNGError( hMNG, "Cannot set callbacks for libmng.");
485     mng_cleanup( &hMNG ); // Always cleanup the library
486     MsgBoxStop( "Bye!" );
487     Application->Terminate(); // Exit now
488   }
489   else
490   {
491     // read the file into memory
492     if( mng_read( hMNG ) != 0 )
493     {
494       // Because we read the whole file in first,
495       // here is where bad input files first choke !
496       MNGError( hMNG, "Cannot read the file." );
497       mng_cleanup( &hMNG ); // Always cleanup the library
498       return false;
499     }
500     else
501     {
502       // run through the chunk list
503       if( mng_iterate_chunks( hMNG, 0, IterateChunks ) != 0 )
504       {
505         MNGError( hMNG, "Error Getting Chunk info!" );
506         mng_cleanup( &hMNG ); // Always cleanup the library
507         return false;     // Errors may occur with bad chunk data
508       }
509     }
510   }
511 
512   mng_cleanup( &hMNG ); // Always cleanup the library
513 
514   return true;
515 }
516 //---------------------------------------------------------------------------
MNGError(mng_handle hMNG,String SHMsg)517 void  __fastcall TMainForm::MNGError( mng_handle hMNG, String SHMsg )
518 {
519 // get extended info
520 mng_uint32  iErrorcode;
521 mng_uint8   iSeverity;
522 mng_chunkid iChunkname;
523 mng_uint32  iChunkseq;
524 mng_int32   iExtra1;
525 mng_int32   iExtra2;
526 mng_pchar   zErrortext;
527 char        szFormatStr[ 256 ];
528 
529   iErrorcode = mng_getlasterror( hMNG, &iSeverity, &iChunkname,
530                           &iChunkseq, &iExtra1, &iExtra2,
531                           &zErrortext);
532 
533   wsprintf( szFormatStr,
534     "Error = %d; Severity = %d; Chunknr = %d; Extra1 = %d",
535     (int)iErrorcode, (int)iSeverity, (int)iChunkseq, (int)iExtra1
536   );
537 
538   MsgBoxStop( SHMsg + "\n\n" +  String( zErrortext ) + "\n\n" + String( szFormatStr ) );
539 }
540 //---------------------------------------------------------------------------
ListBoxChunksClick(TObject * Sender)541 void __fastcall TMainForm::ListBoxChunksClick(TObject *Sender)
542 {
543 // When the Chunks listbox is clicked ...
544 // display strings from strlist in the RichEditChunks window.
545 int iIndex = ListBoxChunks->ItemIndex;
546 
547   if( !ListBoxChunks->Items->Count )
548     return;
549 
550   // Update panel to reflect the selection : "Chunk N of NChunks"
551   pnlChunks->Caption  = "Chunk " + String( iIndex + 1) +
552     " of " + String( ListBoxChunks->Items->Count );
553 
554   // Reset Chunks windows ...
555   RichEditChunks->Clear();
556   RichEditChunks->Lines->Add( "" );
557   // ... Chunks header string : "Chunk N : XXXX" (XXXX == Chunk name)
558   RichEditChunks->Lines->Add( "Chunk " + String( iIndex + 1 ) + " : " +
559                             ListBoxChunks->Items->Strings[ iIndex ] );
560   // ... Seperator line
561   //RichEditChunks->Lines->Add("");
562 
563   // ... add the data from the stringlist
564   {
565   String as = strList->Strings[ iIndex ] + 1;
566   String z;
567     int n =1;
568     do{
569       if( as[n] == '\n' )
570       {
571         RichEditChunks->Lines->Add( z );
572         z = "";
573       }
574       else
575         z = z + as[n];
576       n+=1;
577     } while( n < as.Length() );
578     RichEditChunks->Lines->Add( z );
579   }
580 
581   // ... Seperator line
582   RichEditChunks->Lines->Add("");
583 
584   // Place cursor at top of editor
585   RichEditChunks->SelStart = 0;
586   RichEditChunks->SelLength = 0;
587 
588 }
589 //---------------------------------------------------------------------------
EventShowPage(TObject * Sender)590 void __fastcall TMainForm::EventShowPage(TObject *Sender)
591 {
592 
593   switch( ((TTabSheet *)Sender)->Tag ) {
594   case PAGE_REPORT  :
595     mnuPrint->Enabled = true;
596     mnuEdit->Enabled = true;
597     mnuUndo->Enabled = true;
598     mnuSave->Enabled = true;
599     sbtnSave->Enabled = true;
600     sbtnUndo->Enabled = true;
601     mnuCut->Enabled = true;
602     sbtnCut->Enabled = true;
603     mnuCopy->Enabled = true;
604     sbtnCopy->Enabled = true;
605     mnuPaste->Enabled = true;
606     sbtnPaste->Enabled = true;
607     mnuSearch->Enabled = true;
608     sbtnPrint->Enabled = true;
609     break;
610   //case PAGE_CHUNKS  :
611   //case PAGE_OPTIONS :
612   ///case PAGE_ABOUT   :
613   //case PAGE_HELP    :
614   default :
615     mnuPrint->Enabled = false;
616     mnuEdit->Enabled = false;
617     // no need to enable/disable menu commands as none will be available
618     mnuSave->Enabled = false;
619     sbtnSave->Enabled = false;
620     sbtnUndo->Enabled = false;
621     sbtnCut->Enabled = false;
622     sbtnCopy->Enabled = false;
623     sbtnPaste->Enabled = false;
624     mnuSearch->Enabled = false;
625     sbtnPrint->Enabled = false;
626   }
627 
628 }
629 //---------------------------------------------------------------------------
RadioGroupTabSizeClick(TObject * Sender)630 void __fastcall TMainForm::RadioGroupTabSizeClick(TObject *Sender)
631 {
632   switch( RadioGroupTabSize->ItemIndex ) {
633   case 0  : asTab = " ";      break;
634   case 1  : asTab = "  ";     break;
635   case 2  : asTab = "   ";    break;
636   case 3  : asTab = "    ";   break;
637   case 4  : asTab = "     ";  break;
638   case 5  : asTab = "      "; break;
639   }
640 }
641 //---------------------------------------------------------------------------
PadInt(int iInt,int iWidth)642 String __fastcall TMainForm::PadInt( int iInt, int iWidth )
643 {
644 
645 char  szFmtStr[ 24 ];
646 char  szInt[ 24 ];    // Should be wide enough !
647 String as;
648   wsprintf( szFmtStr,"%%%d\d\0",iWidth ); //"%[iWidth]d"
649   as = szFmtStr;
650   wsprintf( szInt, szFmtStr, iInt );
651 
652   return String( szInt );
653 }
654 //---------------------------------------------------------------------------
ShowChunk(mng_handle hMNG,mng_handle hChunk,mng_chunkid iChunktype)655 mng_bool __fastcall TMainForm::ShowChunk(
656   mng_handle hMNG, mng_handle hChunk, mng_chunkid iChunktype )
657 {
658 String  asDataText;
659 
660   // Fill asDataText with string data including newline's ...
661   // this is added to string list for each chunk
662   // and also added to the tail end of "Report"
663 
664   // NOTE :
665   // Return True to continue processing.
666   // If mng_getchunk_xxxx fails just return false to the
667   // caller "(bool) myiterchunk" which inturn will then return false
668   // to "(mng_retcode) mng_iterate_chunks(...)" which will then
669   // give us the correct error code.
670   // In other words DON'T check for errors in "(bool) myiterchunk" !
671 
672   switch( iChunktype ) {
673   case  MNG_UINT_BACK :
674     if( !Info_BACK( hMNG, hChunk, asDataText ) )  return false; break;
675   case  MNG_UINT_BASI :
676     if( !Info_BASI( hMNG, hChunk, asDataText ) )  return false; break;
677   case  MNG_UINT_CLIP :
678     if( !Info_CLIP( hMNG, hChunk, asDataText ) )  return false; break;
679   case  MNG_UINT_CLON :
680     if( !Info_CLON( hMNG, hChunk, asDataText ) )  return false; break;
681   case  MNG_UINT_DBYK : // untested @ap@
682     if( !Info_DBYK( hMNG, hChunk, asDataText ) )  return false; break;
683   case  MNG_UINT_DEFI :
684     if( !Info_DEFI( hMNG, hChunk, asDataText ) )  return false; break;
685   case  MNG_UINT_DHDR :
686     if( !Info_DHDR( hMNG, hChunk, asDataText ) )  return false; break;
687   case  MNG_UINT_DISC : // untested @ap@
688     if( !Info_DISC( hMNG, hChunk, asDataText ) )  return false; break;
689   case  MNG_UINT_DROP : // untested @ap@
690     if( !Info_DROP( hMNG, hChunk, asDataText ) )  return false; break;
691   case  MNG_UINT_ENDL :
692     if( !Info_ENDL( hMNG, hChunk, asDataText ) )  return false; break;
693   case  MNG_UINT_FRAM :
694     if( !Info_FRAM( hMNG, hChunk, asDataText ) )  return false; break;
695   case  MNG_UINT_IDAT :
696     if( !Info_IDAT( hMNG, hChunk, asDataText ) )  return false; break;
697   case  MNG_UINT_IEND :
698     if( !Info_IEND( hMNG, hChunk, asDataText ) )  return false; break;
699   case  MNG_UINT_IHDR :
700     if( !Info_IHDR( hMNG, hChunk, asDataText ) )  return false; break;
701 #define MNG_UINT_IJNG 0x494a4e47L // Function AWOL @ap@
702 #define MNG_UINT_IPNG 0x49504e47L // Function AWOL @ap@
703   case  MNG_UINT_JDAT :
704     if( !Info_JDAT( hMNG, hChunk, asDataText ) )  return false; break;
705   case  MNG_UINT_JHDR :
706     if( !Info_JHDR( hMNG, hChunk, asDataText ) )  return false; break;
707 #define MNG_UINT_JSEP 0x4a534550L // Function AWOL @ap@
708   case  MNG_UINT_LOOP :
709     if( !Info_LOOP( hMNG, hChunk, asDataText ) )  return false; break;
710 #define MNG_UINT_MaGN 0x4d61474eL // which one "mng_getchunk_magn" ?
711   case  MNG_UINT_MEND :
712     if( !Info_MEND( hMNG, hChunk, asDataText ) )  return false; break;
713   case  MNG_UINT_MHDR :
714     if( !Info_MHDR( hMNG, hChunk, asDataText ) )  return false; break;
715   case  MNG_UINT_MOVE :
716     if( !Info_MOVE( hMNG, hChunk, asDataText ) )  return false; break;
717 #define MNG_UINT_MaGN 0x4d61474eL // which one "mng_getchunk_magn" ?
718   case  MNG_UINT_ORDR :
719     if( !Info_ORDR( hMNG, hChunk, asDataText ) )  return false; break;
720   case  MNG_UINT_PAST :
721     if( !Info_PAST( hMNG, hChunk, asDataText ) )  return false; break;
722   case  MNG_UINT_PLTE :
723     if( !Info_PLTE( hMNG, hChunk, asDataText ) )  return false; break;
724   case  MNG_UINT_PPLT :
725     if( !Info_PPLT( hMNG, hChunk, asDataText ) )  return false; break;
726   case  MNG_UINT_PROM :
727     if( !Info_PROM( hMNG, hChunk, asDataText ) )  return false; break;
728   case  MNG_UINT_SAVE :
729     if( !Info_SAVE( hMNG, hChunk, asDataText ) )  return false; break;
730   case  MNG_UINT_SEEK :
731     if( !Info_SEEK( hMNG, hChunk, asDataText ) )  return false; break;
732   case  MNG_UINT_SHOW :
733     if( !Info_SHOW( hMNG, hChunk, asDataText ) )  return false; break;
734   case  MNG_UINT_TERM :
735     if( !Info_TERM( hMNG, hChunk, asDataText ) )  return false; break;
736   case  MNG_UINT_bKGD :
737     if( !Info_bKGD( hMNG, hChunk, asDataText ) )  return false; break;
738   case  MNG_UINT_cHRM :
739     if( !Info_cHRM( hMNG, hChunk, asDataText ) )  return false; break;
740   case  MNG_UINT_eXPI :
741     if( !Info_eXPI( hMNG, hChunk, asDataText ) )  return false; break;
742   case  MNG_UINT_fPRI :
743     if( !Info_fPRI( hMNG, hChunk, asDataText ) )  return false; break;
744   case  MNG_UINT_gAMA :
745     if( !Info_gAMA( hMNG, hChunk, asDataText ) )  return false; break;
746   case  MNG_UINT_hIST :
747     if( !Info_hIST( hMNG, hChunk, asDataText ) )  return false; break;
748   case  MNG_UINT_iCCP :
749     if( !Info_iCCP( hMNG, hChunk, asDataText ) )  return false; break;
750   case  MNG_UINT_iTXt : // untested @ap@
751     if( !Info_iTXt( hMNG, hChunk, asDataText ) )  return false; break;
752   case  MNG_UINT_nEED :
753     if( !Info_nEED( hMNG, hChunk, asDataText ) )  return false; break;
754 #define MNG_UINT_oFFs 0x6f464673L // Function AWOL @ap@
755 #define MNG_UINT_pCAL 0x7043414cL // Function AWOL @ap@
756   case  MNG_UINT_pHYg : // untested @ap@
757     if( !Info_pHYg( hMNG, hChunk, asDataText ) )  return false; break;
758   case  MNG_UINT_pHYs :
759     if( !Info_pHYs( hMNG, hChunk, asDataText ) )  return false; break;
760   case  MNG_UINT_sBIT :
761     if( !Info_sBIT( hMNG, hChunk, asDataText ) )  return false; break;
762 #define MNG_UINT_sCAL 0x7343414cL // Function AWOL @ap@
763   case  MNG_UINT_sPLT : // untested @ap@
764     if( !Info_sPLT( hMNG, hChunk, asDataText ) )  return false; break;
765   case  MNG_UINT_sRGB :
766     if( !Info_sRGB( hMNG, hChunk, asDataText ) )  return false; break;
767   case  MNG_UINT_tEXt :
768     if( !Info_tEXt( hMNG, hChunk, asDataText ) )  return false; break;
769   case  MNG_UINT_tIME :
770     if( !Info_tIME( hMNG, hChunk, asDataText ) )  return false; break;
771   case  MNG_UINT_tRNS :
772     if( !Info_tRNS( hMNG, hChunk, asDataText ) )  return false; break;
773   case  MNG_UINT_zTXt :
774     if( !Info_zTXt( hMNG, hChunk, asDataText ) )  return false; break;
775   case  MNG_UINT_HUH :
776   default :           // this will catch unknown chunks - Huh !
777     if( !Info_Unknown( hMNG, hChunk, asDataText ) )  return false; break;
778   } // end of switch
779   //-------------------------------------------------
780 
781   // Add this chunk's string to our string list
782   strList->Insert( GetChunkCount(), asDataText );
783 
784   // Now's the time to bump chunk count
785   IncChunkCount();
786 
787   // Add this chunk's string to the Report
788   MainForm->RichEditReport->Lines->Add( asDataText );
789 
790   return true;
791 }
792 //---------------------------------------------------------------------------
793 
794