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