// @(#)root/html:$Id$
// Author: Axel Naumann 2007-01-25

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TDocDirective
#define ROOT_TDocDirective

////////////////////////////////////////////////////////////////////////////
//                                                                        //
// TDocDirective                                                          //
//                                                                        //
// Special treatment of comments, like HTML source, a macro, or latex.    //
//                                                                        //
////////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TNamed
#include "TNamed.h"
#endif


class TClass;
class TDocParser;
class TDocOutput;
class THtml;
class TLatex;
class TMacro;
class TVirtualPad;

class TDocDirective: public TNamed {
protected:
   TDocParser* fDocParser;  // parser invoking this handler
   THtml*      fHtml;       // parser's THtml object
   TDocOutput* fDocOutput;  // parser invoking this handler
   TString     fParameters; // parameters to the directive
   Int_t       fCounter;    // counter to generate unique names, -1 to ignore

   virtual void AddParameter(const TString& /*name*/, const char* /*value*/ = 0) {}

   TDocDirective() {}
   TDocDirective(const char* name):
      TNamed(name, ""), fDocParser(0), fHtml(0), fDocOutput(0), fCounter(-1) {};
   virtual ~TDocDirective() {}

   const char* GetName() const { return TNamed::GetName(); }
   void GetName(TString& name) const;
   TDocParser* GetDocParser() const { return fDocParser; }
   TDocOutput* GetDocOutput() const { return fDocOutput; }
   THtml*      GetHtml() const { return fHtml; }
   const char* GetOutputDir() const;

   void SetParser(TDocParser* parser);
   void SetParameters(const char* params);
   void SetTag(const char* tag) { SetTitle(tag); }
   void SetCounter(Int_t count) { fCounter = count; }
   virtual void DeleteOutputFiles(const char* ext) const;

public:
   // get the tag ending this directive
   virtual const char* GetEndTag() const = 0;

   // add a line to the directive's text
   virtual void AddLine(const TSubString& line) = 0;

   // retrieve the result (replacement) of the directive; return false if invalid
   virtual Bool_t GetResult(TString& result) = 0;

   // Delete output for the parser's current class or module.
   virtual void DeleteOutput() const {}

   friend class TDocParser;

   ClassDef(TDocDirective, 0); // THtml directive handler
};

class TDocHtmlDirective: public TDocDirective {
private:
   TString fText;     // HTML text to be kept
   Bool_t  fVerbatim; // whether we are in a <pre></pre> block
public:
   TDocHtmlDirective(): TDocDirective("HTML"), fVerbatim(kFALSE) {}
   virtual ~TDocHtmlDirective() {}

   virtual void AddLine(const TSubString& line);
   virtual const char* GetEndTag() const { return "end_html"; }
   virtual Bool_t GetResult(TString& result);

   ClassDef(TDocHtmlDirective, 0); // Handler for "Begin_Html"/"End_Html" for raw HTML in documentation comments
};

class TDocMacroDirective: public TDocDirective {
private:
   TMacro* fMacro;         // macro to be executed
   Bool_t  fNeedGraphics;  // if set, we cannot switch to batch mode
   Bool_t  fShowSource;    // whether a source tab should be created
   Bool_t  fIsFilename;    // whether the directive is a failename to be executed

   virtual void AddParameter(const TString& name, const char* value = 0);
   TString CreateSubprocessInputFile();

public:
   TDocMacroDirective():
      TDocDirective("MACRO"), fMacro(0), fNeedGraphics(kFALSE),
      fShowSource(kFALSE), fIsFilename(kTRUE) {};
   virtual ~TDocMacroDirective();

   virtual void AddLine(const TSubString& line);
   virtual const char* GetEndTag() const { return "end_macro"; }
   virtual Bool_t GetResult(TString& result);
   // Delete output for the parser's current class or module.
   virtual void DeleteOutput() const { DeleteOutputFiles(".gif"); }

   static void SubProcess(const TString& what, const TString& out);

   ClassDef(TDocMacroDirective, 0); // Handler for "Begin_Macro"/"End_Macro" for code that is executed and that can generate an image for documentation
};

class TDocLatexDirective: public TDocDirective {
protected:
   TMacro*      fLatex;       // collection of lines
   Int_t        fFontSize;    // fontsize for current latex block, in pixels
   TString      fSeparator;   // column separator, often "="
   Bool_t       fSepIsRegexp; // whether fSeparator is a regexp expression
   TString      fAlignment;   // column alignment: 'l' for justify left, 'c' for center, 'r' for right
   TVirtualPad* fBBCanvas;    // canvas for bounding box determination

   virtual void    CreateLatex(const char* filename);
   virtual void    AddParameter(const TString& name, const char* value = 0);
   virtual void GetBoundingBox(TLatex& latex, const char* text, Float_t& width, Float_t& height);

public:
   TDocLatexDirective():
      TDocDirective("LATEX"), fLatex(0), fFontSize(16),
      fSepIsRegexp(kFALSE), fBBCanvas(0) {};
   virtual ~TDocLatexDirective();

   virtual void AddLine(const TSubString& line);
   virtual const char* GetEndTag() const {return "end_latex";}

   const char* GetAlignment() const {return fAlignment;}
   const char* GetSeparator() const {return fSeparator;}
   Bool_t SeparatorIsRegexp() const {return fSepIsRegexp;}
   Int_t  GetFontSize() const {return fFontSize;}
   TList* GetListOfLines() const;

   virtual Bool_t GetResult(TString& result);
   // Delete output for the parser's current class or module.
   virtual void DeleteOutput() const { DeleteOutputFiles(".gif"); }

   ClassDef(TDocLatexDirective, 0); // Handler for "Begin_Latex"/"End_Latex" to generate an image from latex
};

#endif // ROOT_TDocDirective
 TDocDirective.h:1
 TDocDirective.h:2
 TDocDirective.h:3
 TDocDirective.h:4
 TDocDirective.h:5
 TDocDirective.h:6
 TDocDirective.h:7
 TDocDirective.h:8
 TDocDirective.h:9
 TDocDirective.h:10
 TDocDirective.h:11
 TDocDirective.h:12
 TDocDirective.h:13
 TDocDirective.h:14
 TDocDirective.h:15
 TDocDirective.h:16
 TDocDirective.h:17
 TDocDirective.h:18
 TDocDirective.h:19
 TDocDirective.h:20
 TDocDirective.h:21
 TDocDirective.h:22
 TDocDirective.h:23
 TDocDirective.h:24
 TDocDirective.h:25
 TDocDirective.h:26
 TDocDirective.h:27
 TDocDirective.h:28
 TDocDirective.h:29
 TDocDirective.h:30
 TDocDirective.h:31
 TDocDirective.h:32
 TDocDirective.h:33
 TDocDirective.h:34
 TDocDirective.h:35
 TDocDirective.h:36
 TDocDirective.h:37
 TDocDirective.h:38
 TDocDirective.h:39
 TDocDirective.h:40
 TDocDirective.h:41
 TDocDirective.h:42
 TDocDirective.h:43
 TDocDirective.h:44
 TDocDirective.h:45
 TDocDirective.h:46
 TDocDirective.h:47
 TDocDirective.h:48
 TDocDirective.h:49
 TDocDirective.h:50
 TDocDirective.h:51
 TDocDirective.h:52
 TDocDirective.h:53
 TDocDirective.h:54
 TDocDirective.h:55
 TDocDirective.h:56
 TDocDirective.h:57
 TDocDirective.h:58
 TDocDirective.h:59
 TDocDirective.h:60
 TDocDirective.h:61
 TDocDirective.h:62
 TDocDirective.h:63
 TDocDirective.h:64
 TDocDirective.h:65
 TDocDirective.h:66
 TDocDirective.h:67
 TDocDirective.h:68
 TDocDirective.h:69
 TDocDirective.h:70
 TDocDirective.h:71
 TDocDirective.h:72
 TDocDirective.h:73
 TDocDirective.h:74
 TDocDirective.h:75
 TDocDirective.h:76
 TDocDirective.h:77
 TDocDirective.h:78
 TDocDirective.h:79
 TDocDirective.h:80
 TDocDirective.h:81
 TDocDirective.h:82
 TDocDirective.h:83
 TDocDirective.h:84
 TDocDirective.h:85
 TDocDirective.h:86
 TDocDirective.h:87
 TDocDirective.h:88
 TDocDirective.h:89
 TDocDirective.h:90
 TDocDirective.h:91
 TDocDirective.h:92
 TDocDirective.h:93
 TDocDirective.h:94
 TDocDirective.h:95
 TDocDirective.h:96
 TDocDirective.h:97
 TDocDirective.h:98
 TDocDirective.h:99
 TDocDirective.h:100
 TDocDirective.h:101
 TDocDirective.h:102
 TDocDirective.h:103
 TDocDirective.h:104
 TDocDirective.h:105
 TDocDirective.h:106
 TDocDirective.h:107
 TDocDirective.h:108
 TDocDirective.h:109
 TDocDirective.h:110
 TDocDirective.h:111
 TDocDirective.h:112
 TDocDirective.h:113
 TDocDirective.h:114
 TDocDirective.h:115
 TDocDirective.h:116
 TDocDirective.h:117
 TDocDirective.h:118
 TDocDirective.h:119
 TDocDirective.h:120
 TDocDirective.h:121
 TDocDirective.h:122
 TDocDirective.h:123
 TDocDirective.h:124
 TDocDirective.h:125
 TDocDirective.h:126
 TDocDirective.h:127
 TDocDirective.h:128
 TDocDirective.h:129
 TDocDirective.h:130
 TDocDirective.h:131
 TDocDirective.h:132
 TDocDirective.h:133
 TDocDirective.h:134
 TDocDirective.h:135
 TDocDirective.h:136
 TDocDirective.h:137
 TDocDirective.h:138
 TDocDirective.h:139
 TDocDirective.h:140
 TDocDirective.h:141
 TDocDirective.h:142
 TDocDirective.h:143
 TDocDirective.h:144
 TDocDirective.h:145
 TDocDirective.h:146
 TDocDirective.h:147
 TDocDirective.h:148
 TDocDirective.h:149
 TDocDirective.h:150
 TDocDirective.h:151
 TDocDirective.h:152
 TDocDirective.h:153
 TDocDirective.h:154
 TDocDirective.h:155
 TDocDirective.h:156
 TDocDirective.h:157
 TDocDirective.h:158
 TDocDirective.h:159