1 /* 2 khdoc.h Hypertext Document Classes Header 3 Copyright (c) 1996-8,2000,2001,2002 Kriang Lerdsuwanakij 4 email: lerdsuwa@users.sourceforge.net 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef __K_KHDOC_H 22 #define __K_KHDOC_H 23 24 #include "config.h" 25 26 #include "setupcurses.h" 27 28 #ifdef ZLIBAC_NEED_EXTERN_C 29 extern "C" { 30 # include <zlib.h> 31 } 32 #else 33 # include <zlib.h> 34 #endif 35 36 #include "list.h" 37 #include "miscobj.h" 38 39 const int TYPE_GOTO = 0; // Jump to other document 40 const int TYPE_SECTION = 1; // Jump to other section in with doc 41 const int TYPE_EXEC = 2; // Exec command 42 const int TYPE_CALL = 3; // Call ProcessCall(...) 43 const int TYPE_EXIT = 4; // Exit immediately 44 const int TYPE_NULL = -1; // Uninitialized type 45 const int TYPE_GOTO_OR_EXEC = -2; // Temporary undecided between GOTO, EXEC 46 47 extern ATTR_TYPE normalA, // Normal text 48 linkA, // Hypertext link (normal) 49 highlightA, // Highlighted linkA 50 barA, // Status bar 51 urlA, // URL bar 52 headerA, // <Hx>...</Hx> header 53 boldA, // Bold text 54 italicA, // Italic text 55 markA, // '+' bar 56 linkBoldA, // Hypertext link (bold) 57 linkItalicA, // Hypertext link (italic) 58 highlightBoldA, // Highlighted linkBoldA 59 highlightItalicA; // Highlighted linkItalicA 60 61 size_t GetSourceLine(char *buffer, size_t index); 62 63 #define NUM_COLUMN 1000 64 #define NUM_INDENT 10 65 const int IND_UL = 0; /* UL */ 66 const int IND_OL = 1; /* OL */ 67 const int IND_BLOCK = 2; /* BLOCKQUOTE */ 68 const int IND_DL = 3; /* DL */ 69 70 class HyperDocument; 71 class HyperDraw { 72 public: 73 virtual void Draw(HyperDocument &, WINDOW *) = 0; 74 virtual ~HyperDraw(); 75 }; 76 77 class HyperDocument { 78 private: 79 static const size_t ALLOCSIZE = 40960; 80 static const size_t ALLOCINC = 40960; 81 82 int isInA; /* Inside <A HREF=...>...</A> ? */ 83 int isInPre; /* Inside <PRE>...</PRE> ? (Possibly > 1) */ 84 Anchor *procA; /* Current processed <A HREF=...> */ 85 int curRow, curColumn; /* Current position */ 86 87 char lineBuffer[NUM_COLUMN]; /* Should be enough */ 88 89 // For text indent 90 91 int indentPos[NUM_INDENT]; /* Indent positions */ 92 int indentVal[NUM_INDENT]; /* Ordered-list counters */ 93 int indentType[NUM_INDENT]; /* Indent type */ 94 int numIndent; /* Current indent level */ 95 96 // Handle nesting of <A ...>, <B>, <I> 97 int numNestA; // Nested link 98 int numNestB; // Nested tags with bold appearance 99 int numNestI; // Nested tags with italic appearance 100 101 int numNestBTag; 102 int numNestITag; 103 int numNestStrongTag; 104 int numNestEmTag; 105 int numNestCiteTag; 106 107 // Physical screen size 108 109 int scrRow, scrColumn; /* Size of screen used by 110 HyperDocument */ 111 112 // HTML tags processing 113 114 attr_t GetNestedAttr(); 115 116 void IndentLine(WINDOW *pad); 117 int IndentColumn(); 118 void NextLine(WINDOW *pad); 119 120 void ProcessLI(char *buffer, size_t length, WINDOW *pad, size_t from); 121 void ProcessA(char *buffer, size_t length, WINDOW *pad, size_t from, 122 int curRow, int curColumn); 123 void ProcessHypertext(char *buffer, size_t length, 124 WINDOW *pad = NULL); 125 126 int ReadATag(); 127 128 // Buffer containing HTML document 129 130 char *buffer; 131 size_t bufferSize; 132 bool isMyBuffer; // Determine whether buffer 133 // should be freed by the 134 // destructor 135 HyperDraw *drawObj; 136 // Document created by 137 // calling HyperDocument 138 // Draw functions 139 140 void Init(); 141 void ReInit(); 142 void ReInitFormat(); 143 144 // Used by constructors 145 void InternalLoadDocument(char *buffer_, size_t bufferSize_); 146 147 #ifndef TRIM_NO_DOC_FILE 148 void InternalLoadDocument(const string &fileName); 149 #endif 150 #ifndef TRIM_NO_DOC_STREAM 151 void InternalLoadDocument(FILE *file); 152 #endif 153 #if ! (defined(TRIM_NO_DOC_STREAM) && defined(TRIM_NO_DOC_FILE)) 154 void ReadFile(gzFile file); // Used by LoadDocument(...) 155 #endif 156 157 string titleText; 158 sptr_list<Anchor> anchorList; 159 sptr_list<Anchor> sectionList; 160 int numRow, numColumn; 161 162 public: 163 short *numChar; 164 GetTitle()165 const string &GetTitle() const { return titleText; } GetAnchorList()166 const sptr_list<Anchor> &GetAnchorList() const { return anchorList; } GetSectionList()167 const sptr_list<Anchor> &GetSectionList() const { return sectionList; } GetNumRow()168 int GetNumRow() const { return numRow; } GetNumColumn()169 int GetNumColumn() const { return numColumn; } 170 171 HyperDocument(char *buffer_, size_t bufferSize_); 172 HyperDocument(HyperDraw *drawObj_); 173 #ifndef TRIM_NO_DOC_FILE 174 explicit HyperDocument(const string &fileName); 175 #endif 176 #ifndef TRIM_NO_DOC_STREAM 177 explicit HyperDocument(FILE *file); 178 #endif 179 ~HyperDocument(); 180 181 void LoadDocument(char *buffer_, size_t bufferSize_); 182 #ifndef TRIM_NO_DOC_FILE 183 void LoadDocument(const string &fileName); 184 #endif 185 #ifndef TRIM_NO_DOC_STREAM 186 void LoadDocument(FILE *file); 187 #endif 188 189 void FormatDocument(WINDOW *pad, int row, int col); 190 void SetDocumentSize(int docRow, int docSize, int row, int col); 191 192 Anchor *FindLink(const string &startSection, const string &findLink); 193 Anchor *FindNextLink(const string &startSection, const string &findLink); 194 195 private: 196 // No definition for these 197 198 HyperDocument(const HyperDocument &); 199 HyperDocument& operator=(const HyperDocument &); 200 201 protected: 202 void DrawCharSub(WINDOW *pad, chtype c); 203 #ifdef USE_UTF8_MODE 204 void DrawWCharSub(WINDOW *pad, wchar_t c); 205 #endif 206 public: 207 void DrawSetSize(int row, int col); 208 void DrawBegin(WINDOW *pad); 209 void DrawSetTitle(const char *s); 210 void DrawSetTitle(const string &s); 211 void DrawSetItalic(WINDOW *pad); 212 void DrawClearItalic(WINDOW *pad); 213 void DrawSetBold(WINDOW *pad); 214 void DrawClearBold(WINDOW *pad); 215 void DrawChar(WINDOW *pad, chtype c); 216 void DrawEntityChar(WINDOW *pad, entity_id id); 217 void DrawString(WINDOW *pad, const char *s); 218 void DrawString(WINDOW *pad, const string &s); 219 void DrawAName(WINDOW *pad, const char *s); 220 void DrawAName(WINDOW *pad, const string &s); 221 void DrawACallBegin(WINDOW *pad, const char *s); 222 void DrawACallBegin(WINDOW *pad, const string &s); 223 void DrawAHrefBegin(WINDOW *pad, const char *s); 224 void DrawAHrefBegin(WINDOW *pad, const string &s); 225 void DrawAEnd(WINDOW *pad); 226 }; 227 228 #endif /* __K_KHDOC_H */ 229