2 * Copyright 2007-2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
25 struct text_run_array
{
44 class BTextView
: public BView
{
46 BTextView(BRect frame
, const char* name
,
47 BRect textRect
, uint32 resizeMask
,
49 = B_WILL_DRAW
| B_PULSE_NEEDED
);
50 BTextView(BRect frame
, const char* name
,
51 BRect textRect
, const BFont
* initialFont
,
52 const rgb_color
* initialColor
,
53 uint32 resizeMask
, uint32 flags
);
55 BTextView(const char* name
,
57 = B_WILL_DRAW
| B_PULSE_NEEDED
);
58 BTextView(const char* name
,
59 const BFont
* initialFont
,
60 const rgb_color
* initialColor
,
63 BTextView(BMessage
* archive
);
67 static BArchivable
* Instantiate(BMessage
* archive
);
68 virtual status_t
Archive(BMessage
* archive
,
69 bool deep
= true) const;
71 virtual void AttachedToWindow();
72 virtual void DetachedFromWindow();
73 virtual void Draw(BRect updateRect
);
74 virtual void MouseDown(BPoint where
);
75 virtual void MouseUp(BPoint where
);
76 virtual void MouseMoved(BPoint where
, uint32 code
,
77 const BMessage
* dragMessage
);
78 virtual void WindowActivated(bool active
);
79 virtual void KeyDown(const char* bytes
, int32 numBytes
);
81 virtual void FrameResized(float newWidth
, float newHeight
);
82 virtual void MakeFocus(bool focus
= true);
83 virtual void MessageReceived(BMessage
* message
);
85 virtual BHandler
* ResolveSpecifier(BMessage
* message
,
86 int32 index
, BMessage
* specifier
,
87 int32 form
, const char* property
);
88 virtual status_t
GetSupportedSuites(BMessage
* data
);
89 virtual status_t
Perform(perform_code code
, void* data
);
91 void SetText(const char* text
,
92 const text_run_array
* runs
= NULL
);
93 void SetText(const char* text
, int32 length
,
94 const text_run_array
* runs
= NULL
);
95 void SetText(BFile
* file
, int32 offset
,
97 const text_run_array
* runs
= NULL
);
99 void Insert(const char* text
,
100 const text_run_array
* runs
= NULL
);
101 void Insert(const char* text
, int32 length
,
102 const text_run_array
* runs
= NULL
);
103 void Insert(int32 offset
, const char* text
,
105 const text_run_array
* runs
= NULL
);
108 void Delete(int32 startOffset
, int32 endOffset
);
110 const char* Text() const;
111 int32
TextLength() const;
112 void GetText(int32 offset
, int32 length
,
114 uint8
ByteAt(int32 offset
) const;
116 int32
CountLines() const;
117 int32
CurrentLine() const;
118 void GoToLine(int32 lineNumber
);
120 virtual void Cut(BClipboard
* clipboard
);
121 virtual void Copy(BClipboard
* clipboard
);
122 virtual void Paste(BClipboard
* clipboard
);
125 virtual bool AcceptsPaste(BClipboard
* clipboard
);
126 virtual bool AcceptsDrop(const BMessage
* message
);
128 virtual void Select(int32 startOffset
, int32 endOffset
);
130 void GetSelection(int32
* _start
, int32
* _end
) const;
132 void SetFontAndColor(const BFont
* font
,
133 uint32 mode
= B_FONT_ALL
,
134 const rgb_color
* color
= NULL
);
135 void SetFontAndColor(int32 startOffset
,
136 int32 endOffset
, const BFont
* font
,
137 uint32 mode
= B_FONT_ALL
,
138 const rgb_color
* color
= NULL
);
140 void GetFontAndColor(int32 offset
, BFont
* _font
,
141 rgb_color
* _color
= NULL
) const;
142 void GetFontAndColor(BFont
* _font
, uint32
* _mode
,
143 rgb_color
* _color
= NULL
,
144 bool* _sameColor
= NULL
) const;
146 void SetRunArray(int32 startOffset
, int32 endOffset
,
147 const text_run_array
* runs
);
148 text_run_array
* RunArray(int32 startOffset
, int32 endOffset
,
149 int32
* _size
= NULL
) const;
151 int32
LineAt(int32 offset
) const;
152 int32
LineAt(BPoint point
) const;
153 BPoint
PointAt(int32 offset
,
154 float* _height
= NULL
) const;
155 int32
OffsetAt(BPoint point
) const;
156 int32
OffsetAt(int32 line
) const;
158 virtual void FindWord(int32 offset
, int32
* _fromOffset
,
161 virtual bool CanEndLine(int32 offset
);
163 float LineWidth(int32 lineNumber
= 0) const;
164 float LineHeight(int32 lineNumber
= 0) const;
165 float TextHeight(int32 startLine
,
166 int32 endLine
) const;
168 void GetTextRegion(int32 startOffset
,
169 int32 endOffset
, BRegion
* outRegion
) const;
171 virtual void ScrollToOffset(int32 offset
);
172 void ScrollToSelection();
174 void Highlight(int32 startOffset
, int32 endOffset
);
176 void SetTextRect(BRect rect
);
177 BRect
TextRect() const;
178 void SetInsets(float left
, float top
, float right
,
180 void GetInsets(float* _left
, float* _top
,
181 float* _right
, float* _bottom
) const;
183 void SetStylable(bool stylable
);
184 bool IsStylable() const;
185 void SetTabWidth(float width
);
186 float TabWidth() const;
187 void MakeSelectable(bool selectable
= true);
188 bool IsSelectable() const;
189 void MakeEditable(bool editable
= true);
190 bool IsEditable() const;
191 void SetWordWrap(bool wrap
);
192 bool DoesWordWrap() const;
193 void SetMaxBytes(int32 max
);
194 int32
MaxBytes() const;
195 void DisallowChar(uint32 character
);
196 void AllowChar(uint32 character
);
197 void SetAlignment(alignment align
);
198 alignment
Alignment() const;
199 void SetAutoindent(bool state
);
200 bool DoesAutoindent() const;
201 void SetColorSpace(color_space colors
);
202 color_space
ColorSpace() const;
203 void MakeResizable(bool resize
,
204 BView
* resizeView
= NULL
);
205 bool IsResizable() const;
206 void SetDoesUndo(bool undo
);
207 bool DoesUndo() const;
208 void HideTyping(bool enabled
);
209 bool IsTypingHidden() const;
211 virtual void ResizeToPreferred();
212 virtual void GetPreferredSize(float* _width
, float* _height
);
214 virtual void AllAttached();
215 virtual void AllDetached();
217 static text_run_array
* AllocRunArray(int32 entryCount
,
218 int32
* outSize
= NULL
);
219 static text_run_array
* CopyRunArray(const text_run_array
* orig
,
220 int32 countDelta
= 0);
221 static void FreeRunArray(text_run_array
* array
);
222 static void* FlattenRunArray(const text_run_array
* runArray
,
223 int32
* _size
= NULL
);
224 static text_run_array
* UnflattenRunArray(const void* data
,
225 int32
* _size
= NULL
);
228 virtual void InsertText(const char* text
, int32 length
,
229 int32 offset
, const text_run_array
* runs
);
230 virtual void DeleteText(int32 fromOffset
, int32 toOffset
);
233 virtual void Undo(BClipboard
* clipboard
);
234 undo_state
UndoState(bool* isRedo
) const;
237 virtual void GetDragParameters(BMessage
* drag
,
238 BBitmap
** _bitmap
, BPoint
* point
,
239 BHandler
** _handler
);
241 virtual void LayoutInvalidated(bool descendants
);
242 virtual void DoLayout();
245 virtual BSize
MinSize();
246 virtual BSize
MaxSize();
247 virtual BSize
PreferredSize();
249 virtual bool HasHeightForWidth();
250 virtual void GetHeightForWidth(float width
, float* min
,
251 float* max
, float* preferred
);
254 // FBC padding and forbidden methods
255 virtual void _ReservedTextView3();
256 virtual void _ReservedTextView4();
257 virtual void _ReservedTextView5();
258 virtual void _ReservedTextView6();
259 virtual void _ReservedTextView7();
260 virtual void _ReservedTextView8();
261 virtual void _ReservedTextView9();
262 virtual void _ReservedTextView10();
263 virtual void _ReservedTextView11();
264 virtual void _ReservedTextView12();
271 class TextTrackState
;
274 // UndoBuffer derivatives
276 class PasteUndoBuffer
;
277 class ClearUndoBuffer
;
278 class DropUndoBuffer
;
279 class TypingUndoBuffer
;
281 friend class TextTrackState
;
283 void _InitObject(BRect textRect
,
284 const BFont
* initialFont
,
285 const rgb_color
* initialColor
);
287 void _ValidateLayoutData();
288 void _ResetTextRect();
290 void _HandleBackspace();
291 void _HandleArrowKey(uint32 arrowKey
,
292 int32 modifiers
= -1);
293 void _HandleDelete();
294 void _HandlePageKey(uint32 pageKey
,
295 int32 modifiers
= -1);
296 void _HandleAlphaKey(const char* bytes
,
299 void _Refresh(int32 fromOffset
, int32 toOffset
,
301 void _RecalculateLineBreaks(int32
* startLine
,
303 int32
_FindLineBreak(int32 fromOffset
,
304 float* _ascent
, float* _descent
,
307 float _StyledWidth(int32 fromOffset
, int32 length
,
308 float* _ascent
= NULL
,
309 float* _descent
= NULL
) const;
310 float _TabExpandedStyledWidth(int32 offset
,
311 int32 length
, float* _ascent
= NULL
,
312 float* _descent
= NULL
) const;
314 float _ActualTabWidth(float location
) const;
316 void _DoInsertText(const char* text
, int32 length
,
317 int32 offset
, const text_run_array
* runs
);
319 void _DoDeleteText(int32 fromOffset
,
322 void _DrawLine(BView
* view
, const int32
&startLine
,
323 const int32
& startOffset
,
324 const bool& erase
, BRect
& eraseRect
,
325 BRegion
& inputRegion
);
327 void _DrawLines(int32 startLine
, int32 endLine
,
328 int32 startOffset
= -1,
330 void _RequestDrawLines(int32 startLine
,
333 void _DrawCaret(int32 offset
, bool visible
);
337 void _DragCaret(int32 offset
);
339 void _StopMouseTracking();
340 bool _PerformMouseUp(BPoint where
);
341 bool _PerformMouseMoved(BPoint where
, uint32 code
);
343 void _TrackMouse(BPoint where
,
344 const BMessage
* message
,
347 void _TrackDrag(BPoint where
);
348 void _InitiateDrag();
349 bool _MessageDropped(BMessage
* message
,
350 BPoint where
, BPoint offset
);
352 void _PerformAutoScrolling();
353 void _UpdateScrollbars();
354 void _ScrollBy(float horizontalStep
,
356 void _ScrollTo(float x
, float y
);
358 void _AutoResize(bool doRedraw
= true);
360 void _NewOffscreen(float padding
= 0.0);
361 void _DeleteOffscreen();
366 void _NormalizeFont(BFont
* font
);
368 void _SetRunArray(int32 startOffset
, int32 endOffset
,
369 const text_run_array
* runs
);
371 void _ApplyStyleRange(int32 fromOffset
,
373 uint32 mode
= B_FONT_ALL
,
374 const BFont
* font
= NULL
,
375 const rgb_color
* color
= NULL
,
376 bool syncNullStyle
= true);
378 uint32
_CharClassification(int32 offset
) const;
379 int32
_NextInitialByte(int32 offset
) const;
380 int32
_PreviousInitialByte(int32 offset
) const;
382 int32
_PreviousLineStart(int32 offset
);
383 int32
_NextLineEnd(int32 offset
);
385 int32
_PreviousWordBoundary(int32 offset
);
386 int32
_NextWordBoundary(int32 offset
);
388 int32
_PreviousWordStart(int32 offset
);
389 int32
_NextWordEnd(int32 offset
);
391 bool _GetProperty(BMessage
* specifier
, int32 form
,
392 const char* property
, BMessage
* reply
);
393 bool _SetProperty(BMessage
* specifier
, int32 form
,
394 const char* property
, BMessage
* reply
);
395 bool _CountProperties(BMessage
* specifier
,
396 int32 form
, const char* property
,
399 void _HandleInputMethodChanged(BMessage
* message
);
400 void _HandleInputMethodLocationRequest();
401 void _CancelInputMethod();
403 int32
_LineAt(int32 offset
) const;
404 int32
_LineAt(const BPoint
& point
) const;
405 bool _IsOnEmptyLastLine(int32 offset
) const;
407 float _NullStyleHeight() const;
409 void _ShowContextMenu(BPoint where
);
411 void _FilterDisallowedChars(char* text
,
412 ssize_t
& length
, text_run_array
* runArray
);
415 BPrivate::TextGapBuffer
* fText
;
417 StyleBuffer
* fStyles
;
422 bigtime_t fCaretTime
;
425 bigtime_t fClickTime
;
435 BList
* fDisallowedChars
;
436 alignment fAlignment
;
439 color_space fColorSpace
;
441 BView
* fContainerView
;
443 InlineInput
* fInline
;
444 BMessageRunner
* fDragRunner
;
445 BMessageRunner
* fClickRunner
;
447 TextTrackState
* fTrackingMouse
;
449 float fMinTextRectWidth
;
450 LayoutData
* fLayoutData
;
451 int32 fLastClickOffset
;
453 bool fInstalledNavigateCommandWordwiseShortcuts
;
454 bool fInstalledNavigateOptionWordwiseShortcuts
;
455 bool fInstalledNavigateOptionLinewiseShortcuts
;
456 bool fInstalledNavigateHomeEndDocwiseShortcuts
;
458 bool fInstalledSelectCommandWordwiseShortcuts
;
459 bool fInstalledSelectOptionWordwiseShortcuts
;
460 bool fInstalledSelectOptionLinewiseShortcuts
;
461 bool fInstalledSelectHomeEndDocwiseShortcuts
;
466 #endif // _TEXTVIEW_H