1 /* 2 khwin.h Hypertext Window Header 3 Copyright (c) 1996-8,2000,2001,2003,2007 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_KHWIN_H 22 #define __K_KHWIN_H 23 24 #include "config.h" 25 26 #include CXX__HEADER_climits 27 USING_NAMESPACE_STD; 28 29 #include "khdoc.h" 30 #include "editbox.h" 31 #include "scrnman.h" 32 #include "statwin.h" 33 #include "miscobj.h" 34 #include "scroll.h" 35 #include "gzfileio.h" 36 #include "confobj.h" 37 38 const int idHyperWindow = 1; 39 const int idStatWindow = 2; 40 const int idURLWindow = 3; 41 const int idHScrollBar = 4; 42 const int idVScrollBar = 5; 43 const int idScrollBox = 6; 44 const int idMoreBar = 7; 45 46 const int modeNoScroll = 0; 47 const int modeHScroll = 1; 48 const int modeVScroll = 2; 49 const int modeHVScroll = 3; 50 51 52 class khGeometryManager : public NCGeometryManagerBase { 53 public: 54 static bool disableScrollBar; 55 khGeometryManager(int mode_)56 khGeometryManager(int mode_) : NCGeometryManagerBase(mode_) {} 57 void SetWinRect(int id, NCRect &rect); 58 }; 59 60 class khScreenManager : public NCScreenManager { 61 protected: 62 bool lockScreen; 63 64 virtual void RequestResize(); 65 66 void InitAttr(int id, const AttrConfig &cfg, ATTR_TYPE& attr); 67 68 public: 69 virtual int ReadKeyboard(); 70 71 khScreenManager(NCGeometryManagerBase &geoMan_); ~khScreenManager()72 virtual ~khScreenManager() {} 73 }; 74 75 class HyperWindow : public NCWindowBase { 76 protected: 77 khMarkerBar marker; 78 HyperDocument &html; // Our document, parser 79 StatusWindowBase &status, &url; 80 ScrollBarBase &hscroll, &vscroll; 81 82 WINDOW *blankWin; 83 int numRealColumn; 84 85 typedef sptr_list<Anchor>::const_iterator iterType; 86 87 Anchor newSelected; // Save new anchor generated by 88 // ProcessCall(...) for processing 89 90 const Anchor *anchorSelected; // Selected anchor (by pressing 91 // spacebar) 92 const Anchor *prevHighlight; // Store previously highlighted 93 // anchor to restore char 94 // attributes to normal ones 95 iterType curAnchorIter; // Current (highlighted) or closest 96 // (not highlighted) anchor 97 int curRow, curColumn; // Cursor position 98 int padRow, padColumn; // Current upper-left pad 99 // position displayed 100 101 int initSize; // User-supplied size ? 102 int initRow, initColumn; // User-supplied size 103 104 string startSection; 105 int lockKey; 106 107 // For vi key binding 108 bool viFoundG; // g prefix 109 bool viFoundZ; // Z prefix 110 bool viFoundCount; // count prefix 111 size_t viCount; // count prefix 112 113 bool emacsFoundAlt; 114 115 void InitObject(); // Document variables 116 117 /* 118 void InitFileIn(const char *fileName); // Read file to `buffer' 119 void InitFileIn(FILE *file); // Read stream to `buffer' 120 void ReadFile(gzFile file); // Used by InitFileIn(...) 121 */ 122 123 int isInitScreen; // Screen initialized ? 124 125 // Prepare document for display 126 void PrepareDisplay(bool sameDocument = false); 127 128 bool MatchSubString(iterType &curA, const string &findText); 129 130 void Highlight(); 131 132 void FitHighlightHorizontal(iterType &newA); 133 void FitHighlightTop(iterType &newA); 134 void FitHighlightMiddle(iterType &newA); 135 void FitHighlightBottom(iterType &newA); 136 137 void CenterPad(iterType &newA); 138 void CenterRowPad(iterType &newA); 139 void CenterRowPadIfScroll(iterType &newA); 140 141 virtual void ProcessKey(int key); 142 #ifdef NCURSES_MOUSE_VERSION 143 virtual void ProcessMouse(MEVENT & /*event*/); 144 #endif 145 virtual Anchor ProcessCall(Anchor *p); 146 147 void ProcessKeySelect(); 148 void ProcessKeyCenter(); 149 void ProcessKeyNextStatus(); 150 void ProcessKeyExit(); 151 void ProcessKeyPanLeft(); 152 void ProcessKeyPanRight(); 153 void ProcessKeyUp(); 154 void ProcessKeyDown(); 155 void ProcessKeyFirstLine(); 156 void ProcessKeyLastLine(); 157 void ProcessKeyScrollUpLines(size_t); 158 void ProcessKeyScrollDownLines(size_t); ProcessKeyPrevPage()159 void ProcessKeyPrevPage() { ProcessKeyScrollUpLines(GetRow()-1); } ProcessKeyNextPage()160 void ProcessKeyNextPage() { ProcessKeyScrollDownLines(GetRow()-1); } 161 void ProcessKeyFirstPage(); 162 void ProcessKeyLastPage(); 163 void ProcessKeyPrev(); 164 void ProcessKeyNext(); 165 void ProcessKeyBeginLine(); 166 void ProcessKeyEndLine(); 167 168 bool PosBeforeAnchor(iterType &p, int x, int y); 169 bool PosAfterAnchor(iterType &p, int x, int y); 170 bool PosAtAnchor(iterType &p, int x, int y); 171 172 int GetDocRow(); 173 int GetDocColumn(); 174 int GetNumChar(int y); 175 176 public: 177 virtual void DoResize(); 178 virtual void DoUpdate(); 179 virtual void DoRestCursor(); 180 181 // For all constructors 182 // row <= 0 && col <= 0 for full-screen plus specified 183 // row, col 184 185 HyperWindow(NCScreenManager &scrn_, int id_, HyperDocument &html_, 186 StatusWindowBase &status_, 187 StatusWindowBase &url_, 188 ScrollBarBase &hscroll_, 189 ScrollBarBase &vscroll_, 190 const string &startSection_, 191 int lockKey_ = 0, int row = 0, int col = 0); 192 193 virtual ~HyperWindow(); 194 virtual void Init(); // Alloc and setup pad 195 virtual void KeyboardLoop(); 196 }; 197 198 class SomethingWithFind { // Provide FindText interface for 199 // khStatusWindowWithFind 200 public: 201 // CursorMode: 202 // return: nonzero if cursor must be turned on before find 203 // and turned off after find 204 virtual int CursorMode() = 0; 205 206 virtual void FindText(const string & /*text*/, bool find_backward = false) = 0; 207 virtual void FindPrev(const string & /*text*/) = 0; 208 virtual void FindNext(const string & /*text*/) = 0; 209 virtual void SelectText(const string & /*text*/) = 0; 210 virtual void FindProcessKey(int ch) = 0; ~SomethingWithFind()211 virtual ~SomethingWithFind() {} 212 }; 213 214 215 class khHyperWindowWithFind : public HyperWindow, public SomethingWithFind { 216 public: 217 virtual int CursorMode(); 218 virtual void FindText(const string &text, bool find_backward = false); 219 virtual void FindPrev(const string &text); 220 virtual void FindNext(const string &text); 221 virtual void SelectText(const string &text); 222 virtual void FindProcessKey(int ch); 223 224 public: 225 virtual void ProcessKey(int ch); 226 virtual Anchor ProcessCall(Anchor *p); 227 228 khHyperWindowWithFind(NCScreenManager &scrn_, int id_, 229 HyperDocument &html_, 230 StatusWindowBase &status_, 231 StatusWindowBase &url_, 232 ScrollBarBase &hscroll_, 233 ScrollBarBase &vscroll_, 234 const string &startSection_, 235 int lockKey_ = 0, int row = 0, int col = 0); 236 virtual ~khHyperWindowWithFind(); 237 }; 238 239 #endif /* __K_KHWIN_H */ 240