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