2 * Copyright 2001-2013, Haiku, Inc.
3 * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
4 * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
6 * Distributed under the terms of the MIT license.
8 * Stefano Ceccherini, stefano.ceccherini@gmail.com
9 * Kian Duffy, myob@users.sourceforge.net
10 * Ingo Weinhold, ingo_weinhold@gmx.de
11 * Siarzhuk Zharski, zharik@gmx.li
18 #include <Messenger.h>
19 #include <ObjectList.h>
24 #include "TermViewHighlight.h"
27 class ActiveProcessInfo
;
34 class BasicTerminalBuffer
;
35 class DefaultCharClassifier
;
39 class ShellParameters
;
45 class TermView
: public BView
, private TermViewHighlighter
{
49 typedef TermViewHighlighter Highlighter
;
50 typedef TermViewHighlight Highlight
;
54 const ShellParameters
& shellParameters
,
56 TermView(int rows
, int columns
,
57 const ShellParameters
& shellParameters
,
59 TermView(BMessage
* archive
);
62 static BArchivable
* Instantiate(BMessage
* data
);
63 virtual status_t
Archive(BMessage
* data
, bool deep
= true) const;
65 virtual void GetPreferredSize(float* _width
, float* _height
);
67 bool IsShellBusy() const;
68 bool GetActiveProcessInfo(
69 ActiveProcessInfo
& _info
) const;
70 bool GetShellInfo(ShellInfo
& _info
) const;
72 const char* TerminalName() const;
74 inline TerminalBuffer
* TextBuffer() const { return fTextBuffer
; }
76 void GetTermFont(BFont
* font
) const;
77 void SetTermFont(const BFont
* font
);
79 void GetFontSize(int* width
, int* height
);
82 BRect
SetTermSize(int rows
, int cols
,
84 void SetTermSize(BRect rect
,
85 bool notifyShell
= false);
86 void GetTermSizeFromRect(const BRect
&rect
,
87 int *rows
, int *columns
);
89 void SetTextColor(rgb_color fore
, rgb_color back
);
90 void SetCursorColor(rgb_color fore
, rgb_color back
);
91 void SetSelectColor(rgb_color fore
, rgb_color back
);
92 void SetTermColor(uint index
, rgb_color color
,
93 bool dynamic
= false);
96 void SetEncoding(int encoding
);
98 void SetScrollBar(BScrollBar
* scrollBar
);
99 BScrollBar
* ScrollBar() const { return fScrollBar
; };
101 void SetMouseClipboard(BClipboard
*);
103 void MakeDebugSnapshots();
104 void StartStopDebugCapture();
107 void Copy(BClipboard
* clipboard
);
108 void Paste(BClipboard
* clipboard
);
113 void GetFrameSize(float* width
, float* height
);
114 bool Find(const BString
& str
, bool forwardSearch
,
115 bool matchCase
, bool matchWord
);
116 void GetSelection(BString
& string
);
118 bool CheckShellGone() const;
122 void DisableResizeView(int32 disableCount
= 1);
124 void SetListener(Listener
* listener
)
125 { fListener
= listener
; }
128 virtual void AttachedToWindow();
129 virtual void DetachedFromWindow();
130 virtual void Draw(BRect updateRect
);
131 virtual void WindowActivated(bool active
);
132 virtual void MakeFocus(bool focusState
= true);
133 virtual void KeyDown(const char* bytes
, int32 numBytes
);
135 virtual void MouseDown(BPoint where
);
136 virtual void MouseMoved(BPoint where
, uint32 transit
,
137 const BMessage
* message
);
138 virtual void MouseUp(BPoint where
);
140 virtual void FrameResized(float width
, float height
);
141 virtual void MessageReceived(BMessage
* message
);
143 virtual void ScrollTo(BPoint where
);
144 virtual void TargetedByScrollView(BScrollView
*scrollView
);
146 virtual status_t
GetSupportedSuites(BMessage
* msg
);
147 virtual BHandler
* ResolveSpecifier(BMessage
* msg
, int32 index
,
148 BMessage
* specifier
, int32 form
,
149 const char* property
);
152 class TextBufferSyncLocker
;
153 friend class TextBufferSyncLocker
;
156 class StandardBaseState
;
159 class HyperLinkState
;
160 class HyperLinkMenuState
;
163 friend class StandardBaseState
;
164 friend class DefaultState
;
165 friend class SelectState
;
166 friend class HyperLinkState
;
167 friend class HyperLinkMenuState
;
169 typedef BObjectList
<Highlight
> HighlightList
;
172 // TermViewHighlighter
173 virtual rgb_color
ForegroundColor();
174 virtual rgb_color
BackgroundColor();
177 // point and text offset conversion
178 inline int32
_LineAt(float y
);
179 inline float _LineOffset(int32 index
);
180 TermPos
_ConvertToTerminal(const BPoint
& point
);
181 inline BPoint
_ConvertFromTerminal(const TermPos
& pos
);
183 inline void _InvalidateTextRect(int32 x1
, int32 y1
,
186 status_t
_InitObject(
187 const ShellParameters
& shellParameters
);
189 status_t
_AttachShell(Shell
* shell
);
194 void _SwitchCursorBlinking(bool blinkingOn
);
196 void _DrawLinePart(int32 x1
, int32 y1
, uint32 attr
,
197 char* buffer
, int32 width
,
198 Highlight
* highlight
, bool cursor
,
201 void _InvalidateTextRange(TermPos start
,
204 bool _IsCursorVisible() const;
206 void _ActivateCursor(bool invalidate
);
208 void _DoPrint(BRect updateRect
);
209 void _UpdateScrollBarRange();
210 void _SecondaryMouseButtonDropped(BMessage
* msg
);
211 void _DoSecondaryMouseDropAction(BMessage
* msg
);
212 void _DoFileDrop(entry_ref
&ref
);
214 void _SynchronizeWithTextBuffer(
215 int32 visibleDirtyTop
,
216 int32 visibleDirtyBottom
);
217 void _VisibleTextBufferChanged();
219 void _WritePTY(const char* text
, int32 numBytes
);
222 float _MouseDistanceSinceLastClick(BPoint where
);
223 void _Select(TermPos start
, TermPos end
,
224 bool inclusive
, bool setInitialSelection
);
225 void _ExtendSelection(TermPos
, bool inclusive
,
226 bool useInitialSelection
);
228 bool _HasSelection() const;
229 void _SelectWord(BPoint where
, bool extend
,
230 bool useInitialSelection
);
231 void _SelectLine(BPoint where
, bool extend
,
232 bool useInitialSelection
);
234 void _AddHighlight(Highlight
* highlight
);
235 void _RemoveHighlight(Highlight
* highlight
);
236 bool _ClearHighlight(Highlight
* highlight
);
238 Highlight
* _CheckHighlightRegion(const TermPos
& pos
) const;
239 Highlight
* _CheckHighlightRegion(int32 row
,
240 int32 firstColumn
, int32
& lastColumn
) const;
242 void _UpdateSIGWINCH();
244 void _ScrollTo(float y
, bool scrollGfx
);
245 void _ScrollToRange(TermPos start
, TermPos end
);
247 void _SendMouseEvent(int32 button
, int32 mode
,
248 int32 x
, int32 y
, bool motion
);
250 void _DrawInlineMethodString();
251 void _HandleInputMethodChanged(BMessage
* message
);
252 void _HandleInputMethodLocationRequest();
253 void _CancelInputMethod();
255 void _UpdateModifiers();
257 void _NextState(State
* state
);
263 BMessageRunner
* fWinchRunner
;
264 BMessageRunner
* fCursorBlinkRunner
;
265 BMessageRunner
* fAutoScrollRunner
;
266 BMessageRunner
* fResizeRunner
;
267 BStringView
* fResizeView
;
268 DefaultCharClassifier
* fCharClassifier
;
276 struct escapement_delta fEscapement
;
280 // frame resized flag.
282 int32 fResizeViewDisableCount
;
284 // Cursor Blinking, draw flag.
285 bigtime_t fLastActivityTime
;
288 bool fCursorBlinking
;
294 // Terminal rows and columns.
302 TerminalBuffer
* fTextBuffer
;
303 BasicTerminalBuffer
* fVisibleTextBuffer
;
304 bool fVisibleTextBufferChanged
;
305 BScrollBar
* fScrollBar
;
306 InlineInput
* fInline
;
308 // Color and Attribute.
309 rgb_color fTextForeColor
;
310 rgb_color fTextBackColor
;
311 rgb_color fCursorForeColor
;
312 rgb_color fCursorBackColor
;
313 rgb_color fSelectForeColor
;
314 rgb_color fSelectBackColor
;
319 // TODO: That's the history capacity -- only needed
320 // until the text buffer is created.
321 float fAutoScrollSpeed
;
324 bigtime_t fLastSyncTime
;
325 int32 fScrolledSinceLastSync
;
326 BMessageRunner
* fSyncRunner
;
327 bool fConsiderClockedSync
;
330 Highlight fSelection
;
331 TermPos fInitialSelectionStart
;
332 TermPos fInitialSelectionEnd
;
333 BPoint fLastClickPoint
;
335 HighlightList fHighlights
;
341 bool fReportX10MouseEvent
;
342 bool fReportNormalMouseEvent
;
343 bool fReportButtonMouseEvent
;
344 bool fReportAnyMouseEvent
;
345 BClipboard
* fMouseClipboard
;
348 DefaultState
* fDefaultState
;
349 SelectState
* fSelectState
;
350 HyperLinkState
* fHyperLinkState
;
351 HyperLinkMenuState
* fHyperLinkMenuState
;
356 class TermView::Listener
{
360 // all hooks called in the window thread
361 virtual void NotifyTermViewQuit(TermView
* view
,
363 virtual void SetTermViewTitle(TermView
* view
,
365 virtual void PreviousTermView(TermView
* view
);
366 virtual void NextTermView(TermView
* view
);