Back

1     //------------------------------------------------------------------------------
2     // Module: FMain.h                                                            //
3     //                                                                            //
4     //    Main program of Lore's Source to HTML Converter                         //
5     //                                                                            //
6     //    Copyright (c) 2000-2004 by Lars Haendel                                 //
7     //    Home: http://www.newty.de                                               //
8     //                                                                            //
9     //    This program is free software; you can redistribute it and/or modify    //
10    //    it under the terms of the GNU General Public License as published by    //
11    //    the Free Software Foundation as version 2 of the License.               //
12    //                                                                            //
13    //    This program is distributed in the hope that it will be useful,         //
14    //    but WITHOUT ANY WARRANTY; without even the implied warranty of          //
15    //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
16    //    GNU General Public License for more details.                            //
17    //                                                                            //
18    //    You should have received a copy of the GNU General Public License       //
19    //    along with this program; if not, write to the Free Software             //
20    //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.               //
21    //                                                                            //
22    //------------------------------------------------------------------------------
23
24
25    #ifndef FMainH
26    #define FMainH
27
28    #include <Classes.hpp>
29    #include <Controls.hpp>
30    #include <StdCtrls.hpp>
31    #include <Forms.hpp>
32    #include <Dialogs.hpp>
33    #include <Menus.hpp>
34
35    #include <Buttons.hpp>
36    #include <ExtCtrls.hpp>
37    #include <ComCtrls.hpp>
38    #include <AppEvnts.hpp>
39    #include <ImgList.hpp>
40    #include <ToolWin.hpp>
41    #include <Registry.hpp>       // due to:  TRegistry
42
43
44
45    //----------------------------------------------------------------------------------------------------------------------
46    #include <time>               // due to:  clock()
47
48    #include "ItemStyle.h"        //          TItemStyle
49    #include "StyleFile.h"        //          TStyleFile
50    #include "Options.h"          //          TOptions
51    #include "Project.h"          //          TProject
52    #include "Languages.h"        //          TLanguage
53    #include "FAbout.h"           //          TFAbout
54
55
56    char* GetCmdLine();
57
58
59    //----------------------------------------------------------------------------------------------------------------------
60    // main program
61    class TFMain : public TForm
62    {
63    __published:
64
65       //-------------------------------------------------------------------------------------------------------------------
66       // dialogs
67       TSaveDialog  *SaveDialog;
68       TOpenDialog  *OpenDialog;
69       TColorDialog *ColorDialog;
70
71
72       //-------------------------------------------------------------------------------------------------------------------
73       // misc.
74       TTimer *Timer;
75       TApplicationEvents *ApplicationEvents1;
76       TPageControl *PageControl;
77
78
79       //-------------------------------------------------------------------------------------------------------------------
80       // tab sheet 'Highlighting'
81       TTabSheet *TsHighlighting;
82
83       TGroupBox *GbCurrentStyle;
84       TLabel *LaBackground;
85       TLabel *LaCodeItem0;
86       TLabel *LaCodeItem1;
87       TLabel *LaCodeItem2;
88       TLabel *LaCodeItem3;
89       TLabel *LaCodeItem4;
90       TLabel *LaCodeItem5;
91       TLabel *LaCodeItem6;
92       TLabel *LaCodeItem7;
93       TLabel *LaCodeItem8;
94       TLabel *LaCodeItem9;
95       TLabel *LaCodeItemA;
96
97       TCheckBox *CbBold1;
98       TCheckBox *CbBold2;
99       TCheckBox *CbBold4;
100      TCheckBox *CbBold5;
101      TCheckBox *CbBold6;
102      TCheckBox *CbBold7;
103      TCheckBox *CbBold8;
104      TCheckBox *CbBold9;
105      TCheckBox *CbBoldA;
106      TCheckBox *CbBoldB;
107
108      TBitBtn *BtColor0;
109      TBitBtn *BtColor1;
110      TBitBtn *BtColor2;
111      TBitBtn *BtColor3;
112      TBitBtn *BtColor4;
113      TBitBtn *BtColor5;
114      TBitBtn *BtColor6;
115      TBitBtn *BtColor7;
116      TBitBtn *BtColor8;
117      TBitBtn *BtColor9;
118      TBitBtn *BtColorA;
119      TBitBtn *BtColorB;
120
121      TPanel *PaPreview;
122      TLabel *LaSample1;
123      TLabel *LaSample2;
124      TLabel *LaSample3;
125      TLabel *LaSample4;
126      TLabel *LaSample5;
127      TLabel *LaSample6;
128      TLabel *LaSample7;
129      TLabel *LaSample8;
130      TLabel *LaSample9;
131      TLabel *LaSampleA;
132
133      TCheckBox *CbItalic1;
134      TCheckBox *CbItalic2;
135      TCheckBox *CbItalic4;
136      TCheckBox *CbItalic5;
137      TCheckBox *CbItalic6;
138      TCheckBox *CbItalic7;
139      TCheckBox *CbItalic8;
140      TCheckBox *CbItalic9;
141      TCheckBox *CbItalicA;
142      TCheckBox *CbItalicB;
143
144      TGroupBox *GbStyleSpeedSettings;
145      TListBox *LbStyles;
146      TBitBtn *BtDeleteStyle;
147      TBitBtn *BtInsertStyle;
148
149
150      //-------------------------------------------------------------------------------------------------------------------
151      // tab sheet 'Options'
152      TTabSheet *TsOptions;
153      TGroupBox *GbOverviewFile;
154
155      TCheckBox *CbGenerateOverviewFile;
156      TCheckBox *CbOverwriteExistingFiles;
157      TBitBtn *BtSaveDefaults;
158      TBitBtn *BtRestoreFactoryDefaults;
159      TBitBtn *BtRestoreDefaults;
160
161
162      //-------------------------------------------------------------------------------------------------------------------
163      // tab sheet 'Convert'
164      TTabSheet *TsConvert;
165
166      // group box 'File selection'
167      TGroupBox *GbFileSelection;
168      TListView *LvFiles;
169      TBitBtn *BtAddFile;
170      TBitBtn *BtRename;
171      TBitBtn *BtDelete;
172      TBitBtn *BtClear;
173      TCheckBox *CbShowPath;
174      TBitBtn *BtSetOutputDir;
175      TCheckBox *CbEnforceOutputDir;
176      TLabel *LaOutputDir;
177
178      // group vox 'Messages'
179      TGroupBox *GbMessages;
180      TListBox *LbMessages;
181
182      // misc.
183      TBitBtn *BtViewInBrowser;
184      TBitBtn *BtCancel;
185      TBitBtn *BtStart;
186      TBevel *Bevel1;
187      TGroupBox *GbLanguage;
188      TComboBox *CbLanguage;
189
190
191      // group box 'Progress'
192      TGroupBox *GbProgress;
193      TLabel *LaProgress2;
194      TLabel *LaProgress1;
195      TProgressBar *ProgressBar1;
196      TProgressBar *ProgressBar2;
197
198
199      //-------------------------------------------------------------------------------------------------------------------
200      // menu
201      TMainMenu *MnMainMenu;
202      TMenuItem *File;
203      TMenuItem *Help;
204      TMenuItem *MnNewProject;
205      TMenuItem *MnOpenProject;
206      TMenuItem *MnSaveProject;
207      TMenuItem *MnSaveProjectAs;
208      TMenuItem *MnExit;
209      TMenuItem *MnOpenHelp;
210      TMenuItem *MnAbout;
211
212
213      //-------------------------------------------------------------------------------------------------------------------
214      // toolbar
215      TToolBar *ToolBar;
216      TToolButton *TbNewProject;
217      TToolButton *TbOpenProject;
218      TToolButton *TbSaveProject;
219      TToolButton *TbGap;
220      TToolButton *TbHelp;
221      TToolButton *TbAbout;
222      TImageList *ToolBarImageList;
223      TLabel *LaCodeItemB;
224      TLabel *LaCodeItemC;
225      TLabel *LaSampleB;
226      TLabel *LaSampleC;
227      TBitBtn *BtColorC;
228      TCheckBox *CbBoldC;
229      TCheckBox *CbItalicC;
230      TBitBtn *BtSetOverviewFileName;
231      TLabel *LaOverviewFileName;
232      TGroupBox *GbMisc;
233      TCheckBox *CbAddTopLinks;
234      TCheckBox *CbAddLineNumbers;
235      TCheckBox *CbAddLineAnchors;
236      TGroupBox *GbTab;
237      TLabel *LaTab;
238      TUpDown *UdTab;
239      TGroupBox *GbIndent;
240      TLabel *LaIndent;
241      TUpDown *UdIndent;
242      TGroupBox *GbBackLinks;
243      TLabel *LaBackLinkText;
244      TRadioButton *RbBackLink1;
245      TCheckBox *CbAddBackLink;
246      TRadioButton *RbBackLink2;
247      TBitBtn *BtBackLink;
248      TGroupBox *GbExpertSettings;
249      TLabel *LaExpert;
250      TLabel *LaEndlNo;
251      TCheckBox *CbTabClosingOnEndl;
252      TUpDown *UdEndlNo;
253      TCheckBox *CbTags;
254      TLabel *LaHint;
255
256
257
258      //-------------------------------------------------------------------------------------------------------------------
259      // TabSheet "Highlighting"
260      // response to checkboxes and color buttons
261      void __fastcall BtColor1Click(TObject *Sender);
262      void __fastcall BtColor2Click(TObject *Sender);
263      void __fastcall BtColor3Click(TObject *Sender);
264      void __fastcall BtColor4Click(TObject *Sender);
265      void __fastcall BtColor5Click(TObject *Sender);
266      void __fastcall BtColor6Click(TObject *Sender);
267      void __fastcall BtColor7Click(TObject *Sender);
268      void __fastcall BtColor8Click(TObject *Sender);
269      void __fastcall BtColor9Click(TObject *Sender);
270      void __fastcall BtColor0Click(TObject *Sender);
271      void __fastcall BtColorAClick(TObject *Sender);
272      void __fastcall BtColorBClick(TObject *Sender);
273      void __fastcall BtColorCClick(TObject *Sender);
274
275      void __fastcall CbBold1Click(TObject *Sender);
276      void __fastcall CbBold2Click(TObject *Sender);
277      void __fastcall CbBold4Click(TObject *Sender);
278      void __fastcall CbBold5Click(TObject *Sender);
279      void __fastcall CbBold6Click(TObject *Sender);
280      void __fastcall CbBold7Click(TObject *Sender);
281      void __fastcall CbBold8Click(TObject *Sender);
282      void __fastcall CbBold9Click(TObject *Sender);
283      void __fastcall CbBoldAClick(TObject *Sender);
284      void __fastcall CbBoldBClick(TObject *Sender);
285      void __fastcall CbBoldCClick(TObject *Sender);
286
287      void __fastcall CbItalic1Click(TObject *Sender);
288      void __fastcall CbItalic2Click(TObject *Sender);
289      void __fastcall CbItalic4Click(TObject *Sender);
290      void __fastcall CbItalic5Click(TObject *Sender);
291      void __fastcall CbItalic6Click(TObject *Sender);
292      void __fastcall CbItalic7Click(TObject *Sender);
293      void __fastcall CbItalic8Click(TObject *Sender);
294      void __fastcall CbItalic9Click(TObject *Sender);
295      void __fastcall CbItalicAClick(TObject *Sender);
296      void __fastcall CbItalicBClick(TObject *Sender);
297      void __fastcall CbItalicCClick(TObject *Sender);
298
299
300
301      // response to buttons
302      void __fastcall CmSaveStyle   (TObject *Sender);      // save unsaved style
303      void __fastcall CmDeleteStyle (TObject *Sender);      // delete saved style
304      void __fastcall CmStyleChange (TObject *Sender);
305
306
307      //-------------------------------------------------------------------------------------------------------------------
308      // tab sheet 'Options'
309      // response to checkboxes and updown controls
310      void __fastcall CmTabClosingOnEndl(TObject *Sender);
311      void __fastcall CmTags  (TObject *Sender);
312      void __fastcall CmTab   (TObject *Sender, TUDBtnType Button);
313      void __fastcall CmIndent(TObject *Sender, TUDBtnType Button);
314      void __fastcall CmEndlNo(TObject *Sender, TUDBtnType Button);
315
316      void __fastcall CbGenerateOverviewFileClick(TObject *Sender);
317      void __fastcall CbAddBackLinkClick(TObject *Sender);
318      void __fastcall CbAddTopLinksClick(TObject *Sender);
319      void __fastcall CbAddLineNumbersClick(TObject *Sender);
320
321      void __fastcall BtRestoreFactoryDefaultsClick(TObject *Sender);
322      void __fastcall BtRestoreDefaultsClick(TObject *Sender);
323      void __fastcall BtSaveDefaultsClick(TObject *Sender);
324
325
326      //-------------------------------------------------------------------------------------------------------------------
327      // TabSheet "Convert"
328      // response to buttons
329      void __fastcall CmAddFile  (TObject *Sender);
330      void __fastcall CmRename   (TObject *Sender);
331      void __fastcall CmDelete   (TObject *Sender);
332      void __fastcall CmClearList(TObject *Sender);
333      void __fastcall CmStart    (TObject *Sender);
334      void __fastcall CmCancel   (TObject *Sender);
335      void __fastcall CmViewInBrowser(TObject *Sender);
336      void __fastcall LvOnKeyDown(TObject *Sender, WORD &Key, TShiftState Shift);
337
338      // response to checkboxes and other actions
339      void __fastcall CmPath(TObject *Sender);
340      void __fastcall CmListView(TObject *Sender);
341      void __fastcall LvFilesResize(TObject *Sender);
342      void __fastcall DisableDeleteAndRename(TObject *Sender);
343      void __fastcall CbOverwriteExistingFilesClick(TObject *Sender);
344      void __fastcall CbEnforceOutputDirClick(TObject *Sender);
345      void __fastcall BtSetOutputDirClick(TObject *Sender);
346      void __fastcall CbLanguageChange(TObject *Sender);
347
348
349      //-------------------------------------------------------------------------------------------------------------------
350      // events main form
351      void __fastcall OnTimer(TObject *Sender);
352      void __fastcall OnShow(TObject *Sender);
353      void __fastcall OnClose(TObject *Sender, TCloseAction &Action);
354      void __fastcall OnCloseQuery(TObject *Sender, bool &CanClose);
355      void __fastcall CmOpenHelp(TWMKey &Msg, bool &Handled);
356
357      // events PageControl
358      void __fastcall PageControlChange  (TObject *Sender);
359      void __fastcall PageControlChanging(TObject *Sender, bool &AllowChange);
360
361      // menu
362      void __fastcall MnNewProjectClick(TObject *Sender);
363      void __fastcall MnOpenHelpClick(TObject *Sender);
364      void __fastcall MnAboutClick(TObject *Sender);
365      void __fastcall MnSaveProjectAsClick(TObject *Sender);
366      void __fastcall MnExitClick(TObject *Sender);
367
368      // toolbar
369      void __fastcall TbSaveProjectClick(TObject *Sender);
370      void __fastcall TbOpenProjectClick(TObject *Sender);
371      void __fastcall PageControlResize(TObject *Sender);
372      void __fastcall BtSetOverviewFileNameClick(TObject *Sender);
373      void __fastcall BtBackLinkClick(TObject *Sender);
374      void __fastcall RbBackLink1Click(TObject *Sender);
375      void __fastcall RbBackLink2Click(TObject *Sender);
376      void __fastcall CbAddLineAnchorsClick(TObject *Sender);
377
378
379   private:
380
381      //-------------------------------------------------------------------------------------------------------------------
382      // main variables
383      AnsiString szCmplPrgName;              // complete program name (name + version)
384      AnsiString szDir;                      // executable's directory
385
386      TOptions defaults;                     // default options
387      TProject project;                      // project settings
388      TLangs langs;                          // language definitions
389      const TLanguage* lang;                 // selected/active language
390      TStyleFile styles;                     // list with highlighting styles
391      TItemStyle* style;                     // selected/active style
392      TRegistry* registry;
393      int RegisterExtension();
394
395
396
397      //-------------------------------------------------------------------------------------------------------------------
398      // style control
399      void SetColor(char*const& szColor);    // open color-dialog and copy the choosen color to <color>
400      void StyleToPreview();                 // update preview sample text fields
401      void StyleToCheckboxes();              // set checkboxes according to current style
402
403      void InitializeStyle();                // get first style from style list or (if list is empty) create temporary one
404      void SaveStyles();                     // wrapper: save styles to file
405
406      bool f_StyleLoadError;                 // flag: causes a warning when styles are saved
407      bool f_ManipCtrls;
408
409
410      //-------------------------------------------------------------------------------------------------------------------
411      // tab sheet 'Options'
412      void EnableOptionsCtrls();             // enable/disable controls on tab sheet 'Options'
413
414      AnsiString szProjectFile;              // project's filename
415      AnsiString szProjectDir;               // last used project directory
416      AnsiString szSourceDir;                // last used source directory
417      AnsiString szOutputDir;                // last used output directory
418      AnsiString szIncludeDir;               // last used directory for include files like HTML header and footer
419
420
421      //-------------------------------------------------------------------------------------------------------------------
422      // project/options management
423      void ProjectToGUI();                   // set GUI according to project settings
424      void OptionsToGUI();                   // set GUI according to options (TOptions part of TProject)
425      void SaveDefaults();                   // Utility: Save default settings
426
427      void OpenProject(const char*const& szFileName);       // open project
428
429      // Actualize preview sample text fields according to currently active language definition
430      void PositionLanguageDropDownList();                  // Move language drop down list to correct position
431
432      bool f_Saved;                                         // project is saved
433      void ProjectSaved(const bool& _f_Saved);
434
435
436      //-------------------------------------------------------------------------------------------------------------------
437      // tab sheet 'Convert' (file selection)
438      void __fastcall EvDragDrop(TMessage& msg);
439
440      void AddName2Lists(const AnsiString& szName);   // add filename to source and(!) target filename lists
441      void AddMessage(const AnsiString& msg);         // wrapper: adds a message to the message listbox
442      AnsiString ModifyFileName(AnsiString szName, const bool& f_Destination=false);
443
444      // generate overview filename and store it in wrapper.szFileName
445      void IniOverviewFileName();
446
447      // return relative filename
448      static const char* MakeRelativeLink(const char*const& szBaseFile, const char*const& szFileName);
449
450      void EnableConvertCtrls();             // enable/disable controls on tab sheet convert
451      void RefreshFileSelectionListView();   // refresh file selection list view
452
453
454      //-------------------------------------------------------------------------------------------------------------------
455      // conversion process
456      float inv5Percent;                        // progress counters
457      int   toDo, done, progress, gaugePos;
458      bool  f_Converting, f_Stop;               // flags
459      clock_t startTime, endTime;
460
461      void Finish(const bool& f_AllOk=true);
462      friend class ThreadFunc;
463      void GenerateOverviewFile();              // generate overview file
464
465
466      //-------------------------------------------------------------------------------------------------------------------
467      // struct to wrap the window-handle to be able to pass it by pointer to a thread-function
468      // additionally contains the name of the generated overview file to be able to open it
469      struct THandleWrap
470      {
471         HWND hwnd;
472         char szFileName[STS];   // name overview file
473      } wrapper;
474      friend void ViewHtmlFile(void* _tmp);    // thread-function
475
476
477   public:
478
479      // constructor/destructor
480      __fastcall TFMain(TComponent* Owner);
481      __fastcall ~TFMain();
482
483
484      // message-map: respond to drag & drop of filenames
485      BEGIN_MESSAGE_MAP
486         MESSAGE_HANDLER(WM_DROPFILES, TMessage, EvDragDrop)
487      END_MESSAGE_MAP(TForm)
488   };
489   extern PACKAGE TFMain *FMain;
490   #endif

Top