2 * Copyright (C) 2010-2013 by CenterIM developers
4 * This file is part of CenterIM.
6 * CenterIM is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * CenterIM is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #ifndef __TEXTEDIT_H__
29 #define __TEXTEDIT_H__
43 FLAG_NUMERIC
= 1 << 0,
47 TextEdit(int w
, int h
, const char *text_
= NULL
, int flags_
= 0,
48 bool single_line
= false, bool accept_tabs_
= true,
49 bool masked_
= false);
53 virtual bool processInputText(const TermKeyKey
&key
);
56 virtual void draw(Curses::ViewPort area
);
61 virtual void setText(const char *new_text
);
67 * Returns inserted text.
69 virtual const char *getText() const;
71 virtual size_t getTextLength() const { return text_length
; }
73 virtual void setFlags(int new_flags
, bool revalidate
= true);
74 virtual int getFlags() const { return flags
; }
76 virtual void setSingleLineMode(bool new_single_line_mode
);
77 virtual bool isSingleLineMode() const { return single_line_mode
; }
79 virtual void setAcceptTabs(bool new_accept_tabs
);
80 virtual bool doesAcceptTabs() const { return accept_tabs
; }
82 virtual void setMasked(bool new_masked
);
83 virtual bool isMasked() const { return masked
; }
85 sigc::signal
<void, TextEdit
&> signal_text_change
;
94 MOVE_LOGICAL_POSITIONS
,
95 MOVE_VISUAL_POSITIONS
,
98 MOVE_DISPLAY_LINE_ENDS
,
103 MOVE_HORIZONTAL_PAGES
114 * Pointer to the start of line (points into buffer).
118 * Pointer to the first byte that is not part of this line.
122 * Precalculated length.
126 ScreenLine(const char *start_
, const char *end_
, size_t length_
)
127 : start(start_
), end(end_
), length(length_
) {}
128 bool operator==(const ScreenLine
& other
) const;
131 struct CmpScreenLineEnd
133 bool operator()(ScreenLine
& sline
, const char *tag
);
136 typedef std::deque
<ScreenLine
> ScreenLines
;
138 ScreenLines screen_lines
;
141 * Bitmask indicating which input is accepted.
146 bool single_line_mode
;
151 * Character position from the start of buffer.
155 * Cursor location in the buffer.
160 * Current cursor line (derived from current_pos and screen_lines).
162 size_t current_sc_line
;
164 * Current cursor character number (in the current line).
166 size_t current_sc_linepos
;
168 * Holds index into screen_lines that marks the first screen line.
173 * Start of text buffer.
177 * First location outside buffer.
183 mutable char *gapstart
;
185 * First location after the gap end.
187 mutable char *gapend
;
189 * Length in use, in chars.
193 mutable bool screen_lines_dirty
;
196 virtual void updateArea();
198 virtual void initBuffer(size_t size
);
199 virtual size_t getGapSize() const;
200 virtual void expandGap(size_t size
);
201 virtual void moveGapToCursor();
203 virtual char *getTextStart() const;
204 virtual char *prevChar(const char *p
) const;
205 virtual char *nextChar(const char *p
) const;
206 virtual int width(const char *start
, size_t chars
) const;
208 * Returns on-screen width of a given character in the same fashion as
209 * Curses::onscreen_width() does but handles the tab character and wide
210 * characters properly if the masked mode is active.
212 virtual int onScreenWidth(UTF8::UniChar uc
, int w
= 0) const;
214 virtual char *getScreenLine(const char *text
, int max_width
,
215 size_t *res_length
) const;
217 * Recalculates all screen lines.
219 virtual void updateScreenLines();
221 * Recalculates necessary amout of screen lines.
223 virtual void updateScreenLines(const char *begin
, const char *end
);
224 virtual void assertUpdatedScreenLines();
227 * Recalculates screen cursor position based on current_pos and
228 * screen_lines, sets current_sc_line and current_sc_linepos and handles
229 * scrolling if necessary.
231 virtual void updateScreenCursor();
234 * Inserts given text at the current cursor position.
236 virtual void insertTextAtCursor(const char *new_text
,
237 size_t new_text_bytes
);
238 virtual void insertTextAtCursor(const char *new_text
);
239 virtual void deleteFromCursor(DeleteType type
, Direction dir
);
240 virtual void moveCursor(CursorMovement step
, Direction dir
);
242 virtual void toggleOverwrite();
244 virtual size_t moveLogicallyFromCursor(Direction dir
) const;
245 virtual size_t moveWordFromCursor(Direction dir
, bool word_end
) const;
248 CONSUI_DISABLE_COPY(TextEdit
);
250 void actionMoveCursor(CursorMovement step
, Direction dir
);
251 void actionDelete(DeleteType type
, Direction dir
);
252 void actionToggleOverwrite();
254 void declareBindables();
257 } // namespace CppConsUI
259 #endif // __TEXTEDIT_H__
261 /* vim: set tabstop=2 shiftwidth=2 textwidth=78 expandtab : */