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 GetTermFont(BFont *font) const; 44 void SetTermFont(const BFont *font); 45 46 void GetFontSize(int *width, int *height); 47 BRect SetTermSize(int rows, int cols, bool resize); 48 49 void SetTextColor(rgb_color fore, rgb_color back); 50 void SetSelectColor(rgb_color fore, rgb_color back); 51 void SetCursorColor(rgb_color fore, rgb_color back); 52 53 int Encoding() const; 54 void SetEncoding(int encoding); 55 56 // void SetIMAware (bool); 57 void SetScrollBar(BScrollBar *scrbar); 58 BScrollBar *ScrollBar() const { return fScrollBar; }; 59 60 virtual void SetTitle(const char *title); 61 virtual void NotifyQuit(int32 reason); 62 63 // edit functions 64 void Copy(BClipboard *clipboard); 65 void Paste(BClipboard *clipboard); 66 void SelectAll(); 67 void Clear(); 68 69 // Output Charactor 70 void Insert(uchar *string, ushort attr); 71 void InsertCR(); 72 void InsertLF(); 73 void InsertNewLine(int num); 74 void SetInsertMode(int flag); 75 void InsertSpace(int num); 76 77 // Delete Charactor 78 void EraseBelow(); 79 void DeleteChar(int num); 80 void DeleteColumns(); 81 void DeleteLine(int num); 82 83 // Get and Set Cursor position 84 void SetCurPos(int x, int y); 85 void SetCurX(int x); 86 void SetCurY(int y); 87 void GetCurPos(CurPos *inCurPos); 88 int GetCurX(); 89 int GetCurY(); 90 void SaveCursor(); 91 void RestoreCursor(); 92 93 // Move Cursor 94 void MoveCurRight(int num); 95 void MoveCurLeft(int num); 96 void MoveCurUp(int num); 97 void MoveCurDown(int num); 98 99 // Cursor setting 100 void DrawCursor(); 101 void BlinkCursor(); 102 void SetCurDraw(bool flag); 103 void SetCurBlinking(bool flag); 104 105 // Scroll region 106 void ScrollRegion(int top, int bot, int dir, int num); 107 void SetScrollRegion(int top, int bot); 108 void ScrollAtCursor(); 109 110 // Other 111 void DeviceStatusReport(int); 112 void UpdateLine(); 113 void ScrollScreen(); 114 void ScrollScreenDraw(); 115 void GetFrameSize(float *width, float *height); 116 bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord); 117 void GetSelection(BString &str); 118 119 void CheckShellGone(); 120 121 void InitiateDrag(); 122 123 protected: 124 virtual void AttachedToWindow(); 125 virtual void DetachedFromWindow(); 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 145 status_t _AttachShell(Shell *shell); 146 void _DetachShell(); 147 148 void _AboutRequested(); 149 150 void _DrawLines(int , int, ushort, uchar *, int, int, int, BView *); 151 int _TermDraw(const CurPos &start, const CurPos &end); 152 int _TermDrawRegion(CurPos start, CurPos end); 153 int _TermDrawSelectedRegion(CurPos start, CurPos end); 154 inline void _Redraw(int, int, int, int); 155 156 void _DoPrint(BRect updateRect); 157 void _ResizeScrBarRange(void); 158 void _DoFileDrop(entry_ref &ref); 159 160 void _WritePTY(const uchar *text, int num_byteses); 161 162 // Comunicate Input Method 163 // void _DoIMStart (BMessage* message); 164 // void _DoIMStop (BMessage* message); 165 // void _DoIMChange (BMessage* message); 166 // void _DoIMLocation (BMessage* message); 167 // void _DoIMConfirm (void); 168 // void _ConfirmString(const char *, int32); 169 170 // Mouse select 171 void _Select(CurPos start, CurPos end); 172 void _AddSelectRegion(CurPos); 173 void _ResizeSelectRegion(CurPos); 174 175 void _DeSelect(); 176 bool _HasSelection() const; 177 178 // select word function 179 void _SelectWord(BPoint where, int mod); 180 void _SelectLine(BPoint where, int mod); 181 182 // point and text offset conversion. 183 CurPos _ConvertToTerminal(const BPoint &p); 184 BPoint _ConvertFromTerminal(const CurPos &pos); 185 186 bool _CheckSelectedRegion(const CurPos &pos); 187 188 void _UpdateSIGWINCH(); 189 190 static void _FixFontAttributes(BFont &font); 191 192 private: 193 Shell *fShell; 194 195 BMessageRunner *fWinchRunner; 196 BMessageRunner *fCursorBlinkRunner; 197 198 // Font and Width 199 BFont fHalfFont; 200 int fFontWidth; 201 int fFontHeight; 202 int fFontAscent; 203 struct escapement_delta fEscapement; 204 205 // Flags 206 207 // Update flag (Set on Insert). 208 bool fUpdateFlag; 209 210 // Terminal insertmode flag (use Insert). 211 bool fInsertModeFlag; 212 213 // Scroll count, range. 214 int fScrollUpCount; 215 int fScrollBarRange; 216 217 // Frame Resized flag. 218 bool fFrameResized; 219 220 // Cursor Blinking, draw flag. 221 bigtime_t fLastCursorTime; 222 bool fCursorDrawFlag; 223 bool fCursorStatus; 224 bool fCursorBlinkingFlag; 225 bool fCursorRedrawFlag; 226 int fCursorHeight; 227 228 // Cursor position. 229 CurPos fCurPos; 230 CurPos fCurStack; 231 232 int fBufferStartPos; 233 234 // Terminal rows and columns. 235 int fTermRows; 236 int fTermColumns; 237 238 int fEncoding; 239 240 // Terminal view pointer. 241 int fTop; 242 243 // Object pointer. 244 TermBuffer *fTextBuffer; 245 BScrollBar *fScrollBar; 246 247 // Color and Attribute. 248 rgb_color fTextForeColor, fTextBackColor; 249 rgb_color fCursorForeColor, fCursorBackColor; 250 rgb_color fSelectForeColor, fSelectBackColor; 251 252 // Scroll Region 253 int fScrTop; 254 int fScrBot; 255 int32 fScrBufSize; 256 bool fScrRegionSet; 257 258 BPoint fClickPoint; 259 260 // view selection 261 CurPos fSelStart; 262 CurPos fSelEnd; 263 bool fMouseTracking; 264 265 // Input Method parameter. 266 int fIMViewPtr; 267 CurPos fIMStartPos; 268 CurPos fIMEndPos; 269 BString fIMString; 270 bool fIMflag; 271 BMessenger fIMMessenger; 272 int32 fImCodeState; 273 }; 274 275 276 #endif //TERMVIEW_H 277