1 /* 2 * Copyright 2001-2010, Haiku, Inc. 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 * Ingo Weinhold, ingo_weinhold@gmx.de 11 */ 12 #ifndef TERMVIEW_H 13 #define TERMVIEW_H 14 15 16 #include <Autolock.h> 17 #include <Messenger.h> 18 #include <String.h> 19 #include <View.h> 20 21 #include "TermPos.h" 22 23 24 class ActiveProcessInfo; 25 class BClipboard; 26 class BMessageRunner; 27 class BScrollBar; 28 class BScrollView; 29 class BString; 30 class BStringView; 31 class BasicTerminalBuffer; 32 class InlineInput; 33 class ResizeWindow; 34 class ShellInfo; 35 class ShellParameters; 36 class TermBuffer; 37 class TerminalBuffer; 38 class Shell; 39 40 class TermView : public BView { 41 public: 42 class Listener; 43 44 public: 45 TermView(BRect frame, 46 const ShellParameters& shellParameters, 47 int32 historySize); 48 TermView(int rows, int columns, 49 const ShellParameters& shellParameters, 50 int32 historySize); 51 TermView(BMessage* archive); 52 ~TermView(); 53 54 static BArchivable* Instantiate(BMessage* data); 55 virtual status_t Archive(BMessage* data, bool deep = true) const; 56 57 virtual void GetPreferredSize(float* _width, float* _height); 58 59 bool IsShellBusy() const; 60 bool GetActiveProcessInfo( 61 ActiveProcessInfo& _info) const; 62 bool GetShellInfo(ShellInfo& _info) const; 63 64 const char* TerminalName() const; 65 66 inline TerminalBuffer* TextBuffer() const { return fTextBuffer; } 67 68 void GetTermFont(BFont* font) const; 69 void SetTermFont(const BFont* font); 70 71 void GetFontSize(int* width, int* height); 72 int Rows() const; 73 int Columns() const; 74 BRect SetTermSize(int rows, int cols); 75 void SetTermSize(BRect rect); 76 void GetTermSizeFromRect(const BRect &rect, 77 int *rows, int *columns); 78 79 void SetTextColor(rgb_color fore, rgb_color back); 80 void SetSelectColor(rgb_color fore, rgb_color back); 81 82 int Encoding() const; 83 void SetEncoding(int encoding); 84 85 void SetScrollBar(BScrollBar* scrollBar); 86 BScrollBar* ScrollBar() const { return fScrollBar; }; 87 88 void SetMouseClipboard(BClipboard *); 89 90 // edit functions 91 void Copy(BClipboard* clipboard); 92 void Paste(BClipboard* clipboard); 93 void SelectAll(); 94 void Clear(); 95 96 // Other 97 void GetFrameSize(float* width, float* height); 98 bool Find(const BString& str, bool forwardSearch, 99 bool matchCase, bool matchWord); 100 void GetSelection(BString& string); 101 102 bool CheckShellGone() const; 103 104 void InitiateDrag(); 105 106 void DisableResizeView(int32 disableCount = 1); 107 108 void SetListener(Listener* listener) 109 { fListener = listener; } 110 111 protected: 112 virtual void AttachedToWindow(); 113 virtual void DetachedFromWindow(); 114 virtual void Draw(BRect updateRect); 115 virtual void WindowActivated(bool active); 116 virtual void MakeFocus(bool focusState = true); 117 virtual void KeyDown(const char* bytes, int32 numBytes); 118 119 virtual void MouseDown(BPoint where); 120 virtual void MouseMoved(BPoint where, uint32 transit, 121 const BMessage* message); 122 virtual void MouseUp(BPoint where); 123 124 virtual void FrameResized(float width, float height); 125 virtual void MessageReceived(BMessage* message); 126 127 virtual void ScrollTo(BPoint where); 128 virtual void TargetedByScrollView(BScrollView *scrollView); 129 130 virtual status_t GetSupportedSuites(BMessage* msg); 131 virtual BHandler* ResolveSpecifier(BMessage* msg, int32 index, 132 BMessage* specifier, int32 form, 133 const char* property); 134 135 private: 136 class CharClassifier; 137 138 private: 139 // point and text offset conversion 140 inline int32 _LineAt(float y); 141 inline float _LineOffset(int32 index); 142 inline TermPos _ConvertToTerminal(const BPoint& point); 143 inline BPoint _ConvertFromTerminal(const TermPos& pos); 144 145 inline void _InvalidateTextRect(int32 x1, int32 y1, 146 int32 x2, int32 y2); 147 148 status_t _InitObject( 149 const ShellParameters& shellParameters); 150 151 status_t _AttachShell(Shell* shell); 152 void _DetachShell(); 153 154 void _Activate(); 155 void _Deactivate(); 156 157 void _DrawLinePart(int32 x1, int32 y1, uint32 attr, 158 char* buffer, int32 width, bool mouse, 159 bool cursor, BView* inView); 160 void _DrawCursor(); 161 void _InvalidateTextRange(TermPos start, 162 TermPos end); 163 164 bool _IsCursorVisible() const; 165 void _BlinkCursor(); 166 void _ActivateCursor(bool invalidate); 167 168 void _DoPrint(BRect updateRect); 169 void _UpdateScrollBarRange(); 170 void _SecondaryMouseButtonDropped(BMessage* msg); 171 void _DoSecondaryMouseDropAction(BMessage* msg); 172 void _DoFileDrop(entry_ref &ref); 173 174 void _SynchronizeWithTextBuffer( 175 int32 visibleDirtyTop, 176 int32 visibleDirtyBottom); 177 178 void _WritePTY(const char* text, int32 numBytes); 179 180 // selection 181 float _MouseDistanceSinceLastClick(BPoint where); 182 void _Select(TermPos start, TermPos end, 183 bool inclusive, bool setInitialSelection); 184 void _ExtendSelection(TermPos, bool inclusive, 185 bool useInitialSelection); 186 void _Deselect(); 187 bool _HasSelection() const; 188 void _SelectWord(BPoint where, bool extend, 189 bool useInitialSelection); 190 void _SelectLine(BPoint where, bool extend, 191 bool useInitialSelection); 192 193 void _AutoScrollUpdate(); 194 195 bool _CheckSelectedRegion(const TermPos& pos) const; 196 bool _CheckSelectedRegion(int32 row, 197 int32 firstColumn, int32& lastColumn) const; 198 199 void _UpdateSIGWINCH(); 200 201 void _ScrollTo(float y, bool scrollGfx); 202 void _ScrollToRange(TermPos start, TermPos end); 203 204 void _SendMouseEvent(int32 button, int32 mode, 205 int32 x, int32 y, bool motion); 206 207 void _DrawInlineMethodString(); 208 void _HandleInputMethodChanged(BMessage* message); 209 void _HandleInputMethodLocationRequest(); 210 void _CancelInputMethod(); 211 212 private: 213 Listener* fListener; 214 Shell* fShell; 215 216 BMessageRunner* fWinchRunner; 217 BMessageRunner* fCursorBlinkRunner; 218 BMessageRunner* fAutoScrollRunner; 219 BMessageRunner* fResizeRunner; 220 BStringView* fResizeView; 221 CharClassifier* fCharClassifier; 222 223 // Font and Width 224 BFont fHalfFont; 225 int fFontWidth; 226 int fFontHeight; 227 int fFontAscent; 228 struct escapement_delta fEscapement; 229 230 // frame resized flag. 231 bool fFrameResized; 232 int32 fResizeViewDisableCount; 233 234 // Cursor Blinking, draw flag. 235 bigtime_t fLastActivityTime; 236 int32 fCursorState; 237 int fCursorHeight; 238 239 // Cursor position. 240 TermPos fCursor; 241 242 int32 fMouseButtons; 243 244 // Terminal rows and columns. 245 int fColumns; 246 int fRows; 247 248 int fEncoding; 249 bool fActive; 250 251 // Object pointer. 252 TerminalBuffer* fTextBuffer; 253 BasicTerminalBuffer* fVisibleTextBuffer; 254 BScrollBar* fScrollBar; 255 InlineInput* fInline; 256 257 // Color and Attribute. 258 rgb_color fSelectForeColor; 259 rgb_color fSelectBackColor; 260 261 // Scroll Region 262 float fScrollOffset; 263 int32 fScrBufSize; 264 // TODO: That's the history capacity -- only needed 265 // until the text buffer is created. 266 float fAutoScrollSpeed; 267 268 // redraw management 269 bigtime_t fLastSyncTime; 270 int32 fScrolledSinceLastSync; 271 BMessageRunner* fSyncRunner; 272 bool fConsiderClockedSync; 273 274 // selection 275 TermPos fSelStart; 276 TermPos fSelEnd; 277 TermPos fInitialSelectionStart; 278 TermPos fInitialSelectionEnd; 279 bool fMouseTracking; 280 bool fCheckMouseTracking; 281 int fSelectGranularity; 282 BPoint fLastClickPoint; 283 284 // mouse 285 TermPos fPrevPos; 286 bool fReportX10MouseEvent; 287 bool fReportNormalMouseEvent; 288 bool fReportButtonMouseEvent; 289 bool fReportAnyMouseEvent; 290 BClipboard* fMouseClipboard; 291 }; 292 293 294 class TermView::Listener { 295 public: 296 virtual ~Listener(); 297 298 // all hooks called in the window thread 299 virtual void NotifyTermViewQuit(TermView* view, 300 int32 reason); 301 virtual void SetTermViewTitle(TermView* view, 302 const char* title); 303 virtual void PreviousTermView(TermView* view); 304 virtual void NextTermView(TermView* view); 305 }; 306 307 308 #endif // TERMVIEW_H 309