Main.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. //---------------------------------------------------------------------------
  2. #ifndef MainH
  3. #define MainH
  4. //---------------------------------------------------------------------------
  5. #include <Classes.hpp>
  6. #include <Controls.hpp>
  7. #include <StdCtrls.hpp>
  8. #include <Forms.hpp>
  9. #include <Buttons.hpp>
  10. #include <ComCtrls.hpp>
  11. #include <Dialogs.hpp>
  12. #include <ExtCtrls.hpp>
  13. #include <Menus.hpp>
  14. #include <stdio.h>
  15. //---------------------------------------------------------------------------
  16. // These MUST be defined before we include "Libmng.h
  17. //# define MNG_SUPPORT_READ
  18. //# define MNG_ACCESS_CHUNKS
  19. //# define MNG_STORE_CHUNKS
  20. //# define MNG_NO_CMS
  21. # define MNG_USE_DLL
  22. # define MNG_SKIP_ZLIB
  23. # define MNG_SKIP_LCMS
  24. # define MNG_SKIP_IJG6B
  25. #include "../../../libmng.h"
  26. //---------------------------------------------------------------------------
  27. class TMainForm : public TForm
  28. {
  29. __published: // IDE-managed Components
  30. TMainMenu *MainMenu1;
  31. TMenuItem *mnuFile;
  32. TMenuItem *mnuOpen;
  33. TMenuItem *mnuReload;
  34. TMenuItem *mnuSave;
  35. TMenuItem *N1;
  36. TMenuItem *mnuPrint;
  37. TMenuItem *mnuPrintSetup;
  38. TMenuItem *N2;
  39. TMenuItem *mnuExit;
  40. TMenuItem *mnuEdit;
  41. TMenuItem *mnuUndo;
  42. TMenuItem *N3;
  43. TMenuItem *mnuCut;
  44. TMenuItem *mnuCopy;
  45. TMenuItem *mnuPaste;
  46. TMenuItem *N4;
  47. TMenuItem *mnuSelectAll;
  48. TMenuItem *N5;
  49. TMenuItem *mnuSetFont;
  50. TMenuItem *mnuWordWrap;
  51. TMenuItem *mnuSearch;
  52. TMenuItem *mnuFind;
  53. TMenuItem *mnuFindNext;
  54. TPanel *Panel1;
  55. TSpeedButton *sbtnOpen;
  56. TSpeedButton *sbtnReload;
  57. TSpeedButton *sbtnSave;
  58. TSpeedButton *sbtnPrint;
  59. TSpeedButton *sbtnPrintSetup;
  60. TSpeedButton *sbtnUndo;
  61. TSpeedButton *sbtnCut;
  62. TSpeedButton *sbtnCopy;
  63. TSpeedButton *sbtnPaste;
  64. TOpenDialog *OpenDialog1;
  65. TSaveDialog *SaveDialog1;
  66. TPrintDialog *PrintDialog;
  67. TPrinterSetupDialog *PrinterSetupDialog;
  68. TFontDialog *FontDialog1;
  69. TFindDialog *FindDialog;
  70. TPageControl *PageControl1;
  71. TTabSheet *tsChunks;
  72. TTabSheet *tsReport;
  73. TPanel *pnlChunks;
  74. TListBox *ListBoxChunks;
  75. TSpeedButton *sbtnCopyChunk;
  76. TRichEdit *RichEditChunks;
  77. TRichEdit *RichEditReport;
  78. TPanel *PanelStatusBar;
  79. TProgressBar *ProgressBar1;
  80. TTabSheet *tsOptions;
  81. TTabSheet *tsAbout;
  82. TLabel *LabelAbout;
  83. TTabSheet *tsHelp;
  84. TLabel *LabelHelp;
  85. TCheckBox *cbBool;
  86. TCheckBox *cbMacroIdentifier;
  87. TCheckBox *cbRawData;
  88. TCheckBox *cbRGBOrder;
  89. TCheckBox *cbPaletteEntries;
  90. TCheckBox *cbComments;
  91. TRadioGroup *RadioGroupTabSize;
  92. TStaticText *StaticTextStatus;
  93. TStaticText *StaticText1;
  94. void __fastcall mnuFileOpenClick(TObject *Sender);
  95. void __fastcall FormCreate(TObject *Sender);
  96. void __fastcall ListBoxChunksClick(TObject *Sender);
  97. void __fastcall mnuReloadClick(TObject *Sender);
  98. void __fastcall mnuExitClick(TObject *Sender);
  99. void __fastcall FormDestroy(TObject *Sender);
  100. void __fastcall mnuUndoClick(TObject *Sender);
  101. void __fastcall mnuCutClick(TObject *Sender);
  102. void __fastcall mnuCopyClick(TObject *Sender);
  103. void __fastcall mnuPasteClick(TObject *Sender);
  104. void __fastcall mnuSelectAllClick(TObject *Sender);
  105. void __fastcall mnuWordWrapClick(TObject *Sender);
  106. void __fastcall mnuSetFontClick(TObject *Sender);
  107. void __fastcall FontDialog1Apply(TObject *Sender, HWND Wnd);
  108. void __fastcall mnuFindClick(TObject *Sender);
  109. void __fastcall FindDialogFind(TObject *Sender);
  110. void __fastcall mnuFindNextClick(TObject *Sender);
  111. void __fastcall sbtnCopyChunkClick(TObject *Sender);
  112. void __fastcall mnuPrintClick(TObject *Sender);
  113. void __fastcall mnuPrintSetupClick(TObject *Sender);
  114. void __fastcall mnuSaveClick(TObject *Sender);
  115. void __fastcall EventShowPage(TObject *Sender);
  116. void __fastcall RadioGroupTabSizeClick(TObject *Sender);
  117. protected :
  118. void virtual __fastcall OnMinMax(TMessage& Msg);
  119. BEGIN_MESSAGE_MAP // to limit minimum form size for about/help panes
  120. MESSAGE_HANDLER( WM_GETMINMAXINFO, TMessage, OnMinMax )
  121. END_MESSAGE_MAP(TForm)
  122. private: // User declarations
  123. FILE *fd;
  124. int iChunkCount; // To link stringList to listbox
  125. String asTab; // Number of spaces to use as tab stop
  126. public: // User declarations
  127. // Constructor
  128. __fastcall TMainForm(TComponent* Owner);
  129. // Destructor
  130. __fastcall ~TMainForm( void );
  131. // ------------------------------------------------------------------
  132. // Callbacks ... as static member functions
  133. // ------------------------------------------------------------------
  134. static mng_ptr __stdcall Alloc( mng_size_t iSize );
  135. static void __stdcall Free( mng_ptr pPtr, mng_size_t iSize );
  136. static mng_bool __stdcall FileReadData( mng_handle hMNG,
  137. mng_ptr pBuf,
  138. mng_uint32 iSize,
  139. mng_uint32 *iRead );
  140. static mng_bool __stdcall ProcessHeader( mng_handle hHandle,
  141. mng_uint32 iWidth,
  142. mng_uint32 iHeight );
  143. static mng_bool __stdcall OpenStream( mng_handle hMNG );
  144. static mng_bool __stdcall CloseStream( mng_handle hMNG );
  145. static mng_bool __stdcall IterateChunks( mng_handle hMNG,
  146. mng_handle hChunk,
  147. mng_chunkid iChunktype,
  148. mng_uint32 iChunkseq );
  149. // ------------------------------------------------------------------
  150. //public data members
  151. // ------------------------------------------------------------------
  152. // Associates a string, strList[n], with a chunk in the listbox[N]
  153. TStringList *strList;
  154. String asAppName; // pinch Application->Title at startup
  155. // ------------------------------------------------------------------
  156. // MessageBox functions
  157. // ------------------------------------------------------------------
  158. int __fastcall MessageBox( String &as, UINT flags );
  159. void __fastcall MsgBoxOk( String as );
  160. int __fastcall MsgBoxYN( String as );
  161. int __fastcall MsgBoxYNC( String as );
  162. void __fastcall MsgBoxStop( String as );
  163. void __fastcall MsgBoxInfo( String as );
  164. void __fastcall MsgBoxWarn( String as );
  165. // ------------------------------------------------------------------
  166. // Just to isolate teh "FILE *fd" variable from possible change.
  167. inline FILE* __fastcall GetFd( void )
  168. { return fd; };
  169. // ------------------------------------------------------------------
  170. // Options
  171. // ------------------------------------------------------------------
  172. inline bool _fastcall WantsComments( void )
  173. { return cbComments->Checked; };
  174. inline bool _fastcall WantsPaletteEntries( void )
  175. { return cbPaletteEntries->Checked; };
  176. inline bool _fastcall WantsRgbOrder( void )
  177. { return cbRGBOrder->Checked; };
  178. inline bool _fastcall WantsRawData( void )
  179. { return cbRawData->Checked; };
  180. inline bool _fastcall WantsMacroIds( void )
  181. { return cbMacroIdentifier->Checked; };
  182. inline bool _fastcall WantsBool( void )
  183. { return cbBool->Checked; };
  184. // ------------------------------------------------------------------
  185. // Chunk count stuff
  186. // ------------------------------------------------------------------
  187. inline int __fastcall IncChunkCount( void )
  188. { return iChunkCount += 1; };
  189. inline int __fastcall SetChunkCount( int anInt )
  190. { iChunkCount = anInt; };
  191. inline int __fastcall GetChunkCount( void )
  192. { return iChunkCount; };
  193. // ------------------------------------------------------------------
  194. // Open a file, initialise things, and then calls "Dumptree(...)"
  195. void __fastcall LoadFile( void );
  196. // All LibMng calls involving the library handle are made from here :
  197. // Initialize the library
  198. // Setup callbacks
  199. // Read the file into memory
  200. // Run through the chunk list (mng_iterate_chunks)
  201. // Cleanup the library
  202. // Show Report page, all done. (then explode into the starry heavens!)
  203. bool __fastcall DumpTree( void );
  204. // Handle library errors gracefully.
  205. void __fastcall MNGError( mng_handle hMNG, String SHMsg );
  206. // Uesd with Palette entries - to right align int's to N chars width
  207. String __fastcall PadInt( int iInt, int iWidth = 3 ); // default = 3
  208. // A long switch that calls Info_XXXX's to assemble the chunks string
  209. mng_bool __fastcall ShowChunk( mng_handle hMNG,
  210. mng_handle hChunk,
  211. mng_chunkid iChunktype );
  212. // ------------------------------------------------------------------
  213. // The following functions are to assemble a string for each chunk.
  214. // The function name "Info_????" denotes which chunk it handles
  215. // Definitions can be found in "Chunks.cpp"
  216. // ------------------------------------------------------------------
  217. bool __fastcall Info_BACK( mng_handle hMNG, mng_handle hChunk, String &as );
  218. bool __fastcall Info_BASI( mng_handle hMNG, mng_handle hChunk, String &as );
  219. bool __fastcall Info_CLIP( mng_handle hMNG, mng_handle hChunk, String &as );
  220. bool __fastcall Info_CLON( mng_handle hMNG, mng_handle hChunk, String &as );
  221. bool __fastcall Info_DBYK( mng_handle hMNG, mng_handle hChunk, String &as );
  222. bool __fastcall Info_DEFI( mng_handle hMNG, mng_handle hChunk, String &as );
  223. bool __fastcall Info_DHDR( mng_handle hMNG, mng_handle hChunk, String &as );
  224. bool __fastcall Info_DISC( mng_handle hMNG, mng_handle hChunk, String &as );
  225. bool __fastcall Info_DROP( mng_handle hMNG, mng_handle hChunk, String &as );
  226. bool __fastcall Info_ENDL( mng_handle hMNG, mng_handle hChunk, String &as );
  227. bool __fastcall Info_FRAM( mng_handle hMNG, mng_handle hChunk, String &as );
  228. bool __fastcall Info_IDAT( mng_handle hMNG, mng_handle hChunk, String &as );
  229. bool __fastcall Info_IEND( mng_handle hMNG, mng_handle hChunk, String &as );
  230. bool __fastcall Info_IHDR( mng_handle hMNG, mng_handle hChunk, String &as );
  231. // MNG_UINT_IJNG - Function missing @ap@
  232. // MNG_UINT_IPNG - Function missing @ap@
  233. bool __fastcall Info_JDAT( mng_handle hMNG, mng_handle hChunk, String &as );
  234. bool __fastcall Info_JHDR( mng_handle hMNG, mng_handle hChunk, String &as );
  235. // MNG_UINT_JSEP - Function missing @ap@
  236. bool __fastcall Info_LOOP( mng_handle hMNG, mng_handle hChunk, String &as );
  237. // MAGN ? MNG_UINT_MAGN @ap@
  238. bool __fastcall Info_MEND( mng_handle hMNG, mng_handle hChunk, String &as );
  239. bool __fastcall Info_MHDR( mng_handle hMNG, mng_handle hChunk, String &as );
  240. bool __fastcall Info_MOVE( mng_handle hMNG, mng_handle hChunk, String &as );
  241. // MaGN ? MNG_UINT_MaGN @ap@
  242. bool __fastcall Info_ORDR( mng_handle hMNG, mng_handle hChunk, String &as );
  243. bool __fastcall Info_PAST( mng_handle hMNG, mng_handle hChunk, String &as );
  244. bool __fastcall Info_PLTE( mng_handle hMNG, mng_handle hChunk, String &as );
  245. bool __fastcall Info_PPLT( mng_handle hMNG, mng_handle hChunk, String &as );
  246. bool __fastcall Info_PROM( mng_handle hMNG, mng_handle hChunk, String &as );
  247. bool __fastcall Info_SAVE( mng_handle hMNG, mng_handle hChunk, String &as );
  248. bool __fastcall Info_SEEK( mng_handle hMNG, mng_handle hChunk, String &as );
  249. bool __fastcall Info_SHOW( mng_handle hMNG, mng_handle hChunk, String &as );
  250. bool __fastcall Info_TERM( mng_handle hMNG, mng_handle hChunk, String &as );
  251. bool __fastcall Info_bKGD( mng_handle hMNG, mng_handle hChunk, String &as );
  252. bool __fastcall Info_cHRM( mng_handle hMNG, mng_handle hChunk, String &as );
  253. bool __fastcall Info_eXPI( mng_handle hMNG, mng_handle hChunk, String &as );
  254. bool __fastcall Info_fPRI( mng_handle hMNG, mng_handle hChunk, String &as );
  255. bool __fastcall Info_gAMA( mng_handle hMNG, mng_handle hChunk, String &as );
  256. bool __fastcall Info_hIST( mng_handle hMNG, mng_handle hChunk, String &as );
  257. bool __fastcall Info_iCCP( mng_handle hMNG, mng_handle hChunk, String &as );
  258. bool __fastcall Info_iTXt( mng_handle hMNG, mng_handle hChunk, String &as );
  259. bool __fastcall Info_nEED( mng_handle hMNG, mng_handle hChunk, String &as );
  260. // MNG_UINT_oFFs - Function missing @ap@
  261. // MNG_UINT_pCAL - Function missing @ap@
  262. bool __fastcall Info_pHYg( mng_handle hMNG, mng_handle hChunk, String &as );
  263. bool __fastcall Info_pHYs( mng_handle hMNG, mng_handle hChunk, String &as );
  264. bool __fastcall Info_sBIT( mng_handle hMNG, mng_handle hChunk, String &as );
  265. // MNG_UINT_sCAL - Function missing @ap@
  266. bool __fastcall Info_sPLT( mng_handle hMNG, mng_handle hChunk, String &as );
  267. bool __fastcall Info_sRGB( mng_handle hMNG, mng_handle hChunk, String &as );
  268. bool __fastcall Info_tEXt( mng_handle hMNG, mng_handle hChunk, String &as );
  269. bool __fastcall Info_tIME( mng_handle hMNG, mng_handle hChunk, String &as );
  270. bool __fastcall Info_tRNS( mng_handle hMNG, mng_handle hChunk, String &as );
  271. bool __fastcall Info_zTXt( mng_handle hMNG, mng_handle hChunk, String &as );
  272. bool __fastcall Info_Unknown( mng_handle hMNG, mng_handle hChunk, String &as );
  273. };
  274. //---------------------------------------------------------------------------
  275. extern PACKAGE TMainForm *MainForm;
  276. //---------------------------------------------------------------------------
  277. #endif