1 /* 2 * Copyright 2001-2007, Haiku. 3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> 4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. 5 * 6 * Distributed under the terms of the MIT license. 7 * Authors: 8 * Stefano Ceccherini <stefano.ceccherini@gmail.com> 9 * Kian Duffy, myob@users.sourceforge.net 10 */ 11 12 #ifndef TERMVIEW_H 13 #define TERMVIEW_H 14 15 16 #include "CurPos.h" 17 18 #include <Messenger.h> 19 #include <String.h> 20 #include <View.h> 21 22 23 class BClipboard; 24 class BMessageRunner; 25 class BScrollBar; 26 class BString; 27 class Shell; 28 class TermBuffer; 29 class TermView : public BView { 30 public: 31 TermView(BRect frame, int32 argc, const char **argv, int32 historySize = 1000); 32 TermView(int rows, int columns, int32 argc, const char **argv, int32 historySize = 1000); 33 TermView(BMessage *archive); 34 ~TermView(); 35 36 static BArchivable* Instantiate(BMessage* data); 37 virtual status_t Archive(BMessage* data, bool deep = true) const; 38 39 virtual void GetPreferredSize(float *width, float *height); 40 41 const char *TerminalName() const; 42 43 void SetTermFont(const BFont *halfFont, const BFont *fullFont); 44 void GetFontSize(int *width, int *height); 45 BRect SetTermSize(int rows, int cols, bool resize); 46 47 void SetTextColor(rgb_color fore, rgb_color back); 48 void SetSelectColor(rgb_color fore, rgb_color back); 49 void SetCursorColor(rgb_color fore, rgb_color back); 50 51 int Encoding() const; 52 void SetEncoding(int encoding); 53 54 // void SetIMAware (bool); 55 void SetScrollBar(BScrollBar *scrbar); 56 BScrollBar *ScrollBar() const { return fScrollBar; }; 57 58 virtual void SetTitle(const char *title); 59 virtual void NotifyQuit(int32 reason); 60 61 // edit functions 62 void Copy(BClipboard *clipboard); 63 void Paste(BClipboard *clipboard); 64 void SelectAll(); 65 void Clear(); 66 67 // Output Charactor 68 void PutChar(uchar *string, ushort attr, int width); 69 void PutCR(void); 70 void PutLF(void); 71 void PutNL(int num); 72 void SetInsertMode(int flag); 73 void InsertSpace(int num); 74 75 // Delete Charactor 76 void EraseBelow(); 77 void DeleteChar(int num); 78 void DeleteColumns(); 79 void DeleteLine(int num); 80 81 // Get and Set Cursor position 82 void SetCurPos(int x, int y); 83 void SetCurX(int x); 84 void SetCurY(int y); 85 void GetCurPos(CurPos *inCurPos); 86 int GetCurX(); 87 int GetCurY(); 88 void SaveCursor(); 89 void RestoreCursor(); 90 91 // Move Cursor 92 void MoveCurRight(int num); 93 void MoveCurLeft(int num); 94 void MoveCurUp(int num); 95 void MoveCurDown(int num); 96 97 // Cursor setting 98 void DrawCursor(); 99 void BlinkCursor(); 100 void SetCurDraw(bool flag); 101 void SetCurBlinking(bool flag); 102 103 // Scroll region 104 void ScrollRegion(int top, int bot, int dir, int num); 105 void SetScrollRegion(int top, int bot); 106 void ScrollAtCursor(); 107 108 // Other 109 void DeviceStatusReport(int); 110 void UpdateLine(); 111 void ScrollScreen(); 112 void ScrollScreenDraw(); 113 void GetFrameSize(float *width, float *height); 114 void GetFontInfo(int *, int*); 115 bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord); 116 void GetSelection(BString &str); 117 118 void CheckShellGone(); 119 120 void InitiateDrag(); 121 122 protected: 123 virtual void AttachedToWindow(); 124 virtual void DetachedFromWindow(); 125 virtual void Pulse(); 126 virtual void Draw(BRect updateRect); 127 virtual void WindowActivated(bool active); 128 virtual void KeyDown(const char*, int32); 129 130 virtual void MouseDown(BPoint where); 131 virtual void MouseMoved(BPoint, uint32, const BMessage *); 132 virtual void MouseUp(BPoint where); 133 134 virtual void FrameResized(float width, float height); 135 virtual void MessageReceived(BMessage* message); 136 137 virtual status_t GetSupportedSuites(BMessage *msg); 138 virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index, 139 BMessage *specifier, int32 form, 140 const char *property); 141 142 private: 143 status_t _InitObject(int32 argc, const char **argv); 144 status_t _InitMouseThread(); 145 146 status_t _AttachShell(Shell *shell); 147 void _DetachShell(); 148 149 void _AboutRequested(); 150 151 void _DrawLines(int , int, ushort, uchar *, int, int, int, BView *); 152 int _TermDraw(const CurPos &start, const CurPos &end); 153 int _TermDrawRegion(CurPos start, CurPos end); 154 int _TermDrawSelectedRegion(CurPos start, CurPos end); 155 inline void _Redraw(int, int, int, int); 156 157 void _DoPrint(BRect updateRect); 158 void _ResizeScrBarRange (void); 159 void _DoFileDrop(entry_ref &ref); 160 161 void _WritePTY(const uchar *text, int num_byteses); 162 163 // Comunicate Input Method 164 // void _DoIMStart (BMessage* message); 165 // void _DoIMStop (BMessage* message); 166 // void _DoIMChange (BMessage* message); 167 // void _DoIMLocation (BMessage* message); 168 // void _DoIMConfirm (void); 169 void _ConfirmString(const char *, int32); 170 int32 _GetCharFromUTF8String(const char *, char *); 171 int32 _GetWidthFromUTF8String(const char *); 172 173 // Mouse select 174 void _Select(CurPos start, CurPos end); 175 void _AddSelectRegion(CurPos); 176 void _ResizeSelectRegion(CurPos); 177 178 void _DeSelect(); 179 bool _HasSelection() const; 180 181 // select word function 182 void _SelectWord(BPoint where, int mod); 183 void _SelectLine(BPoint where, int mod); 184 185 // point and text offset conversion. 186 CurPos _BPointToCurPos(const BPoint &p); 187 BPoint _CurPosToBPoint(const CurPos &pos); 188 189 bool _CheckSelectedRegion(const CurPos &pos); 190 191 void _UpdateSIGWINCH(); 192 193 static void _FixFontAttributes(BFont &font); 194 195 Shell *fShell; 196 197 BMessageRunner *fWinchRunner; 198 199 // Font and Width 200 BFont fHalfFont; 201 BFont fFullFont; 202 int fFontWidth; 203 int fFontHeight; 204 int fFontAscent; 205 struct escapement_delta fEscapement; 206 207 // Flags 208 209 // Update flag (Set on PutChar). 210 bool fUpdateFlag; 211 212 // Terminal insertmode flag (use PutChar). 213 bool fInsertModeFlag; 214 215 // Scroll count, range. 216 int fScrollUpCount; 217 int fScrollBarRange; 218 219 // Frame Resized flag. 220 bool fFrameResized; 221 222 // Cursor Blinking, draw flag. 223 bigtime_t fLastCursorTime; 224 bool fCursorDrawFlag; 225 bool fCursorStatus; 226 bool fCursorBlinkingFlag; 227 bool fCursorRedrawFlag; 228 int fCursorHeight; 229 230 // Cursor position. 231 CurPos fCurPos; 232 CurPos fCurStack; 233 234 int fBufferStartPos; 235 236 // Terminal rows and columns. 237 int fTermRows; 238 int fTermColumns; 239 240 int fEncoding; 241 242 // Terminal view pointer. 243 int fTop; 244 245 // Object pointer. 246 247 TermBuffer *fTextBuffer; 248 BScrollBar *fScrollBar; 249 250 // Color and Attribute. 251 252 rgb_color fTextForeColor, fTextBackColor; 253 rgb_color fCursorForeColor, fCursorBackColor; 254 rgb_color fSelectForeColor, fSelectBackColor; 255 256 // Scroll Region 257 int fScrTop; 258 int fScrBot; 259 int32 fScrBufSize; 260 bool fScrRegionSet; 261 262 BPoint fPreviousMousePoint; 263 264 // view selection 265 CurPos fSelStart; 266 CurPos fSelEnd; 267 bool fMouseTracking; 268 269 // Input Method parameter. 270 int fIMViewPtr; 271 CurPos fIMStartPos; 272 CurPos fIMEndPos; 273 BString fIMString; 274 bool fIMflag; 275 BMessenger fIMMessenger; 276 int32 fImCodeState; 277 }; 278 279 280 #endif //TERMVIEW_H 281