10 #include "tb_linklist.h"
11 #include "tb_widgets_common.h"
19 class TBTextFragmentContent;
20 class TBTextFragmentContentFactory;
29 virtual void OnChange() {};
30 virtual bool OnEnter() {
return false; };
31 virtual void Invalidate(
const TBRect &rect) = 0;
32 virtual void DrawString(int32_t x, int32_t y,
TBFontFace *font,
const TBColor &color,
const char *str, int32_t len = TB_ALL_TO_TERMINATION) = 0;
33 virtual void DrawRect(
const TBRect &rect,
const TBColor &color) = 0;
34 virtual void DrawRectFill(
const TBRect &rect,
const TBColor &color) = 0;
35 virtual void DrawTextSelectionBg(
const TBRect &rect) = 0;
36 virtual void DrawContentSelectionFg(
const TBRect &rect) = 0;
37 virtual void DrawCaret(
const TBRect &rect) = 0;
38 virtual void Scroll(int32_t dx, int32_t dy) = 0;
39 virtual void UpdateScrollbars() = 0;
40 virtual void CaretBlinkStart() = 0;
41 virtual void CaretBlinkStop() = 0;
67 void Set(
TBBlock *new_block, int32_t new_ofs) { block = new_block; ofs = new_ofs; }
68 void Set(
const TBTextOfs &pos) { block = pos.block; ofs = pos.ofs; }
85 void Invalidate()
const;
88 void Select(
int glob_ofs_from,
int glob_ofs_to);
89 void SelectToCaret(
TBBlock *old_caret_block, int32_t old_caret_ofs);
93 void CopyToClipboard();
94 bool IsBlockSelected(
TBBlock *block)
const;
96 bool IsSelected()
const;
98 bool GetText(
TBStr &text)
const;
106 TB_CARET_POS_BEGINNING,
118 bool Move(
bool forward,
bool word);
119 bool Place(
const TBPoint &point);
120 bool Place(
TBBlock *block,
int ofs,
bool allow_snap =
true,
bool snap_forward =
false);
121 void Place(TB_CARET_POS place);
122 void AvoidLineBreak();
123 void Paint(int32_t translate_x, int32_t translate_y);
125 void UpdateWantedX();
127 int32_t GetGlobalOfs()
const {
return pos.GetGlobalOfs(styledit); }
128 void SetGlobalOfs(int32_t gofs,
bool allow_snap =
true,
bool snap_forward =
false);
132 void SwitchBlock(
bool second);
178 void Set(
TBStr newstr);
181 int32_t InsertText(int32_t ofs,
const char * text, int32_t len,
bool allow_line_recurse);
182 void RemoveContent(int32_t ofs, int32_t len);
193 void Layout(
bool update_fragments,
bool propagate_height);
197 void SetSize(int32_t old_w, int32_t new_w, int32_t new_h,
bool propagate_height);
199 TBTextFragment *FindFragment(int32_t ofs,
bool prefer_first =
false)
const;
202 int32_t CalculateStringWidth(
TBFontFace *font,
const char * str,
int len = TB_ALL_TO_TERMINATION)
const;
203 int32_t CalculateTabWidth(
TBFontFace *font, int32_t xpos)
const;
204 int32_t CalculateLineHeight(
TBFontFace *font)
const;
205 int32_t CalculateBaseline(
TBFontFace *font)
const;
207 void Invalidate()
const;
208 void BuildSelectionRegion(int32_t translate_x, int32_t translate_y,
TBTextProps *props,
210 void Paint(int32_t translate_x, int32_t translate_y,
TBTextProps *props);
224 int GetStartIndentation(
TBFontFace *font,
int first_line_len)
const;
247 void Clear(
bool clear_undo,
bool clear_redo);
276 , content(content) {}
279 void Init(
TBBlock *block, uint16_t ofs, uint16_t len);
281 void UpdateContentPos();
283 void BuildSelectionRegion(int32_t translate_x, int32_t translate_y,
TBTextProps *props,
285 void Paint(int32_t translate_x, int32_t translate_y,
TBTextProps *props);
286 void Click(
int button, uint32_t modifierkeys);
288 bool IsText()
const {
return !IsEmbedded(); }
289 bool IsEmbedded()
const {
return content ?
true :
false; }
290 bool IsBreak()
const;
291 bool IsSpace()
const;
294 int32_t GetCharX(
TBFontFace *font, int32_t ofs);
295 int32_t GetCharOfs(
TBFontFace *font, int32_t x);
300 bool GetAllowBreakBefore()
const;
301 bool GetAllowBreakAfter()
const;
303 const char *Str()
const {
return block->str.
CStr() + ofs; }
312 uint16_t line_height;
331 bool KeyDown(
int key, SPECIAL_KEY special_key, MODIFIER_KEYS modifierkeys);
332 bool MouseDown(
const TBPoint &point,
int button,
int clicks, MODIFIER_KEYS modifierkeys,
bool touch);
333 bool MouseUp(
const TBPoint &point,
int button, MODIFIER_KEYS modifierkeys,
bool touch);
334 bool MouseMove(
const TBPoint &point);
335 void Focus(
bool focus);
337 void Clear(
bool init_new =
true);
338 bool SetText(
const TBStr & text, TB_CARET_POS pos = TB_CARET_POS_BEGINNING);
340 bool GetText(
TBStr &text)
const;
341 bool IsEmpty()
const;
346 void SetMultiline(
bool multiline =
true);
347 void SetStyling(
bool styling =
true);
348 void SetReadOnly(
bool readonly =
true);
349 void SetSelection(
bool selection =
true);
350 void SetPassword(
bool password =
true);
351 void SetWrapping(
bool wrapping =
true);
368 bool CanUndo()
const {
return undoredo.undos.GetNumItems() ?
true :
false; }
369 bool CanRedo()
const {
return undoredo.redos.GetNumItems() ?
true :
false; }
371 void InsertText(
const char *text, int32_t len = TB_ALL_TO_TERMINATION,
372 bool after_last =
false,
bool clear_undo_redo =
false);
373 void AppendText(
const char *text, int32_t len = TB_ALL_TO_TERMINATION,
374 bool clear_undo_redo =
false) { InsertText(text, len,
true, clear_undo_redo); }
377 TBBlock *FindBlock(int32_t y)
const;
379 void ScrollIfNeeded(
bool x =
true,
bool y =
true);
380 void SetScrollPos(int32_t x, int32_t y);
381 void SetLayoutSize(int32_t width, int32_t height,
bool is_virtual_reformat);
382 void Reformat(
bool update_fragments);
384 int32_t GetContentWidth();
385 int32_t GetContentHeight()
const;
387 int32_t GetOverflowX()
const {
return MAX(content_width - layout_width, 0); }
388 int32_t GetOverflowY()
const {
return MAX(content_height - layout_height, 0); }
390 TBStyleEditListener *listener;
391 TBTextFragmentContentFactory default_content_factory;
392 TBTextFragmentContentFactory *content_factory;
393 int32_t layout_width;
394 int32_t layout_height;
395 int32_t content_width;
396 int32_t content_height;
398 TBLinkListOf<TBBlock> blocks;
401 TBSelection selection;
402 TBUndoRedoStack undoredo;
408 TBPoint mousedown_point;
409 TBTextFragment *mousedown_fragment;
417 uint32_t multiline_on : 1;
418 uint32_t styling_on : 1;
419 uint32_t read_only : 1;
420 uint32_t selection_on : 1;
421 uint32_t show_whitespace : 1;
422 uint32_t password_on : 1;
423 uint32_t wrapping : 1;
424 uint32_t win_style_br : 1;
428 uint32_t packed_init;
435 void EndLockScrollbars();
TBLinkListOf is a double linked linklist.
Definition: tb_linklist.h:122
Keeps track of all TBUndoEvents used for undo and redo functionality.
Definition: tb_style_edit.h:239
Event in the TBUndoRedoStack.
Definition: tb_style_edit.h:229
void SetLayoutSize(int32_t width, int32_t height, bool is_virtual_reformat)
Definition: tb_style_edit.cpp:1513
void SetAlign(TB_TEXT_ALIGN align)
Set the default text alignment and all currently selected blocks, or the block of the current caret p...
Definition: tb_style_edit.cpp:1964
bool GetSizeAffectsLayout() const
Return true if changing layout_width and layout_height requires relayouting.
Definition: tb_style_edit.cpp:1532
Listener for TBStyleEdit.
Definition: tb_style_edit.h:24
int32_t GetStringWidth(TBFontFace *font, const char *str, int len)
Get the stringwidth.
Definition: tb_style_edit.cpp:1334
void Merge()
Check if we've lost the ending break on this block and if so merge it with the next block...
Definition: tb_style_edit.cpp:827
uint32_t lock_scrollbars_counter
Incremental counter for if UpdateScrollbar should be probhited.
Definition: tb_style_edit.h:426
Content for a non-text TBTextFragment.
Definition: tb_style_edit_content.h:17
Definition: tb_style_edit.h:149
TBFontFace represents a loaded font that can measure and render strings.
Definition: tb_font_renderer.h:142
A block of text (a line, that might be wrapped)
Definition: tb_style_edit.h:171
TBFontFace * font
DEPRECATED! This will be removed when using different fonts is properly supported! ...
Definition: tb_style_edit.h:412
TB_TEXT_ALIGN
TB_TEXT_ALIGN specifies horizontal text alignment.
Definition: tb_widgets_common.h:22
Simple point class.
Definition: tb_geometry.h:15
TBRegion does calculations on regions represented by a list of rectangles.
Definition: tb_geometry.h:63
void SetWindowsStyleBreak(bool win_style_br)
Set if line breaks should be inserted in windows style ( ) or unix style ( ).
Definition: tb_style_edit.h:359
Definition: tb_style_edit.h:61
void BeginLockScrollbars()
Call BeginLockScrollbars & EndLockScrollbars around a scope which does lots of changes, to prevent UpdateScrollbar from happening for each block (May cause recalculation of content_width by iterating through all blocks)
Definition: tb_style_edit.cpp:1501
virtual TBTextFragmentContent * CreateFragmentContent(const char *text, int text_len)
Create content for a string previosly consumed by calling GetContent.
Definition: tb_style_edit_content.cpp:31
virtual int GetContent(const char *text)
Should return then length of the text that represents content that can be created by this factory...
Definition: tb_style_edit_content.cpp:15
TBFontFace * GetFont()
Get the font face from the current font description.
Definition: tb_style_edit.cpp:695
TBTextProps is a stack of properties used during layout & paint of TBStyleEdit.
Definition: tb_style_edit.h:146
Edit and formats TBTextFragment's.
Definition: tb_style_edit.h:319
Handles the selected text in a TBStyleEdit.
Definition: tb_style_edit.h:80
void SetSize(int32_t old_w, int32_t new_w, int32_t new_h, bool propagate_height)
Update the size of this block.
Definition: tb_style_edit.cpp:1077
uint32_t calculate_content_width_needed
If content_width needs to be updated next GetContentWidth-.
Definition: tb_style_edit.h:425
void Layout(bool update_fragments, bool propagate_height)
Layout the block.
Definition: tb_style_edit.cpp:899
TBListOf is a list (array) of pointers to the specified object type.
Definition: tb_list.h:47
TBStr is a simple string class.
Definition: tb_str.h:62
void Split()
Check if this block contains extra line breaks and split into new blocks if it does.
Definition: tb_style_edit.cpp:798
Simple rectangle class.
Definition: tb_geometry.h:25
Creates TBTextFragmentContent if the sequence of text matches known content.
Definition: tb_style_edit.h:46
The textfragment baseclass for TBStyleEdit.
Definition: tb_style_edit.h:265
Definition: tb_linklist.h:83
TBColor contains a 32bit color.
Definition: tb_color.h:21
The caret in a TBStyleEdit.
Definition: tb_style_edit.h:112
TBFontDescription describes a font.
Definition: tb_font_desc.h:18
char * CStr() const
Get the c-string raw (char *)
Definition: tb_str.h:93
int32_t y
Relative to the styledit.
Definition: tb_style_edit.h:135