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