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 *font); 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 Insert(uchar *string, ushort attr); 69 void InsertCR(); 70 void InsertLF(); 71 void InsertNewLine(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 bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord); 115 void GetSelection(BString &str); 116 117 void CheckShellGone(); 118 119 void InitiateDrag(); 120 121 protected: 122 virtual void AttachedToWindow(); 123 virtual void DetachedFromWindow(); 124 virtual void Pulse(); 125 virtual void Draw(BRect updateRect); 126 virtual void WindowActivated(bool active); 127 virtual void KeyDown(const char*, int32); 128 129 virtual void MouseDown(BPoint where); 130 virtual void MouseMoved(BPoint, uint32, const BMessage *); 131 virtual void MouseUp(BPoint where); 132 133 virtual void FrameResized(float width, float height); 134 virtual void MessageReceived(BMessage* message); 135 136 virtual status_t GetSupportedSuites(BMessage *msg); 137 virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index, 138 BMessage *specifier, int32 form, 139 const char *property); 140 141 private: 142 status_t _InitObject(int32 argc, const char **argv); 143 144 status_t _AttachShell(Shell *shell); 145 void _DetachShell(); 146 147 void _AboutRequested(); 148 149 void _DrawLines(int , int, ushort, uchar *, int, int, int, BView *); 150 int _TermDraw(const CurPos &start, const CurPos &end); 151 int _TermDrawRegion(CurPos start, CurPos end); 152 int _TermDrawSelectedRegion(CurPos start, CurPos end); 153 inline void _Redraw(int, int, int, int); 154 155 void _DoPrint(BRect updateRect); 156 void _ResizeScrBarRange (void); 157 void _DoFileDrop(entry_ref &ref); 158 159 void _WritePTY(const uchar *text, int num_byteses); 160 161 // Comunicate Input Method 162 // void _DoIMStart (BMessage* message); 163 // void _DoIMStop (BMessage* message); 164 // void _DoIMChange (BMessage* message); 165 // void _DoIMLocation (BMessage* message); 166 // void _DoIMConfirm (void); 167 // void _ConfirmString(const char *, int32); 168 169 // Mouse select 170 void _Select(CurPos start, CurPos end); 171 void _AddSelectRegion(CurPos); 172 void _ResizeSelectRegion(CurPos); 173 174 void _DeSelect(); 175 bool _HasSelection() const; 176 177 // select word function 178 void _SelectWord(BPoint where, int mod); 179 void _SelectLine(BPoint where, int mod); 180 181 // point and text offset conversion. 182 CurPos _ConvertToTerminal(const BPoint &p); 183 BPoint _ConvertFromTerminal(const CurPos &pos); 184 185 bool _CheckSelectedRegion(const CurPos &pos); 186 187 void _UpdateSIGWINCH(); 188 189 static void _FixFontAttributes(BFont &font); 190 191 private: 192 Shell *fShell; 193 194 BMessageRunner *fWinchRunner; 195 196 // Font and Width 197 BFont fHalfFont; 198 int fFontWidth; 199 int fFontHeight; 200 int fFontAscent; 201 struct escapement_delta fEscapement; 202 203 // Flags 204 205 // Update flag (Set on Insert). 206 bool fUpdateFlag; 207 208 // Terminal insertmode flag (use Insert). 209 bool fInsertModeFlag; 210 211 // Scroll count, range. 212 int fScrollUpCount; 213 int fScrollBarRange; 214 215 // Frame Resized flag. 216 bool fFrameResized; 217 218 // Cursor Blinking, draw flag. 219 bigtime_t fLastCursorTime; 220 bool fCursorDrawFlag; 221 bool fCursorStatus; 222 bool fCursorBlinkingFlag; 223 bool fCursorRedrawFlag; 224 int fCursorHeight; 225 226 // Cursor position. 227 CurPos fCurPos; 228 CurPos fCurStack; 229 230 int fBufferStartPos; 231 232 // Terminal rows and columns. 233 int fTermRows; 234 int fTermColumns; 235 236 int fEncoding; 237 238 // Terminal view pointer. 239 int fTop; 240 241 // Object pointer. 242 TermBuffer *fTextBuffer; 243 BScrollBar *fScrollBar; 244 245 // Color and Attribute. 246 rgb_color fTextForeColor, fTextBackColor; 247 rgb_color fCursorForeColor, fCursorBackColor; 248 rgb_color fSelectForeColor, fSelectBackColor; 249 250 // Scroll Region 251 int fScrTop; 252 int fScrBot; 253 int32 fScrBufSize; 254 bool fScrRegionSet; 255 256 BPoint fClickPoint; 257 258 // view selection 259 CurPos fSelStart; 260 CurPos fSelEnd; 261 bool fMouseTracking; 262 263 // Input Method parameter. 264 int fIMViewPtr; 265 CurPos fIMStartPos; 266 CurPos fIMEndPos; 267 BString fIMString; 268 bool fIMflag; 269 BMessenger fIMMessenger; 270 int32 fImCodeState; 271 }; 272 273 274 #endif //TERMVIEW_H 275