BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / terminal / TermView.h
blob10b42862a7b241d63808919bb307a799dd0be58c
1 /*
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.
7 * Authors:
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
13 #ifndef TERMVIEW_H
14 #define TERMVIEW_H
17 #include <Autolock.h>
18 #include <Messenger.h>
19 #include <ObjectList.h>
20 #include <String.h>
21 #include <View.h>
23 #include "TermPos.h"
24 #include "TermViewHighlight.h"
27 class ActiveProcessInfo;
28 class BClipboard;
29 class BMessageRunner;
30 class BScrollBar;
31 class BScrollView;
32 class BString;
33 class BStringView;
34 class BasicTerminalBuffer;
35 class DefaultCharClassifier;
36 class InlineInput;
37 class ResizeWindow;
38 class ShellInfo;
39 class ShellParameters;
40 class TermBuffer;
41 class TerminalBuffer;
42 class Shell;
45 class TermView : public BView, private TermViewHighlighter {
46 public:
47 class Listener;
49 typedef TermViewHighlighter Highlighter;
50 typedef TermViewHighlight Highlight;
52 public:
53 TermView(BRect frame,
54 const ShellParameters& shellParameters,
55 int32 historySize);
56 TermView(int rows, int columns,
57 const ShellParameters& shellParameters,
58 int32 historySize);
59 TermView(BMessage* archive);
60 ~TermView();
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);
80 int Rows() const;
81 int Columns() const;
82 BRect SetTermSize(int rows, int cols,
83 bool notifyShell);
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);
95 int Encoding() const;
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();
106 // edit functions
107 void Copy(BClipboard* clipboard);
108 void Paste(BClipboard* clipboard);
109 void SelectAll();
110 void Clear();
112 // Other
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;
120 void InitiateDrag();
122 void DisableResizeView(int32 disableCount = 1);
124 void SetListener(Listener* listener)
125 { fListener = listener; }
127 protected:
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);
151 private:
152 class TextBufferSyncLocker;
153 friend class TextBufferSyncLocker;
155 class State;
156 class StandardBaseState;
157 class DefaultState;
158 class SelectState;
159 class HyperLinkState;
160 class HyperLinkMenuState;
162 friend class State;
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;
171 private:
172 // TermViewHighlighter
173 virtual rgb_color ForegroundColor();
174 virtual rgb_color BackgroundColor();
176 private:
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,
184 int32 x2, int32 y2);
186 status_t _InitObject(
187 const ShellParameters& shellParameters);
189 status_t _AttachShell(Shell* shell);
190 void _DetachShell();
192 void _Activate();
193 void _Deactivate();
194 void _SwitchCursorBlinking(bool blinkingOn);
196 void _DrawLinePart(int32 x1, int32 y1, uint32 attr,
197 char* buffer, int32 width,
198 Highlight* highlight, bool cursor,
199 BView* inView);
200 void _DrawCursor();
201 void _InvalidateTextRange(TermPos start,
202 TermPos end);
204 bool _IsCursorVisible() const;
205 void _BlinkCursor();
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);
221 // selection
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);
227 void _Deselect();
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);
259 private:
260 Listener* fListener;
261 Shell* fShell;
263 BMessageRunner* fWinchRunner;
264 BMessageRunner* fCursorBlinkRunner;
265 BMessageRunner* fAutoScrollRunner;
266 BMessageRunner* fResizeRunner;
267 BStringView* fResizeView;
268 DefaultCharClassifier* fCharClassifier;
270 // Font and Width
271 BFont fHalfFont;
272 BFont fBoldFont;
273 int fFontWidth;
274 int fFontHeight;
275 int fFontAscent;
276 struct escapement_delta fEscapement;
277 bool fEmulateBold;
278 bool fAllowBold;
280 // frame resized flag.
281 bool fFrameResized;
282 int32 fResizeViewDisableCount;
284 // Cursor Blinking, draw flag.
285 bigtime_t fLastActivityTime;
286 int32 fCursorState;
287 int fCursorStyle;
288 bool fCursorBlinking;
289 bool fCursorHidden;
291 // Cursor position.
292 TermPos fCursor;
294 // Terminal rows and columns.
295 int fColumns;
296 int fRows;
298 int fEncoding;
299 bool fActive;
301 // Object pointer.
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;
316 // Scroll Region
317 float fScrollOffset;
318 int32 fScrBufSize;
319 // TODO: That's the history capacity -- only needed
320 // until the text buffer is created.
321 float fAutoScrollSpeed;
323 // redraw management
324 bigtime_t fLastSyncTime;
325 int32 fScrolledSinceLastSync;
326 BMessageRunner* fSyncRunner;
327 bool fConsiderClockedSync;
329 // selection
330 Highlight fSelection;
331 TermPos fInitialSelectionStart;
332 TermPos fInitialSelectionEnd;
333 BPoint fLastClickPoint;
335 HighlightList fHighlights;
337 // mouse
338 int32 fMouseButtons;
339 int32 fModifiers;
340 TermPos fPrevPos;
341 bool fReportX10MouseEvent;
342 bool fReportNormalMouseEvent;
343 bool fReportButtonMouseEvent;
344 bool fReportAnyMouseEvent;
345 BClipboard* fMouseClipboard;
347 // states
348 DefaultState* fDefaultState;
349 SelectState* fSelectState;
350 HyperLinkState* fHyperLinkState;
351 HyperLinkMenuState* fHyperLinkMenuState;
352 State* fActiveState;
356 class TermView::Listener {
357 public:
358 virtual ~Listener();
360 // all hooks called in the window thread
361 virtual void NotifyTermViewQuit(TermView* view,
362 int32 reason);
363 virtual void SetTermViewTitle(TermView* view,
364 const char* title);
365 virtual void PreviousTermView(TermView* view);
366 virtual void NextTermView(TermView* view);
370 #endif // TERMVIEW_H