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