Main.cpp 28 KB

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