Update list of wide characters
[centerim5.git] / cppconsui / TextView.h
blob6f887856e25729b422dc69e4654aaf4cd3d7cb35
1 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
2 //
3 // This file is part of CenterIM.
4 //
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
18 /// @file
19 /// TextView class.
20 ///
21 /// @ingroup cppconsui
23 #ifndef TEXTVIEW_H
24 #define TEXTVIEW_H
26 #include "Widget.h"
28 #include <deque>
30 namespace CppConsUI {
32 /// Line oriented text view widget.
33 class TextView : public Widget {
34 public:
35 TextView(int w, int h, bool autoscroll_ = false, bool scrollbar_ = false);
36 virtual ~TextView() override;
38 // Widget
39 virtual int draw(Curses::ViewPort area, Error &error) override;
41 /// Appends text after the last line.
42 virtual void append(const char *text, int color = 0);
44 /// Inserts text before specified line number. Text can contain multiple lines
45 /// and should end with the '\n' character just before the '\0' byte.
46 virtual void insert(std::size_t line_num, const char *text, int color = 0);
48 /// Removes a specified line.
49 virtual void erase(std::size_t line_num);
51 /// Removes specified range of lines. Parameter end_line represents the line
52 /// after the last removed line, thus range of <start_line, end_line) lines is
53 /// removed.
54 virtual void erase(std::size_t start_line, std::size_t end_line);
56 /// Removes all lines.
57 virtual void clear();
59 /// Returns string for a specified line number.
60 virtual const char *getLine(std::size_t line_num) const;
62 /// Returns count of all lines.
63 virtual std::size_t getLinesNumber() const;
65 virtual void setAutoScroll(bool new_autoscroll);
66 virtual bool hasAutoScroll() const { return autoscroll_; }
68 virtual void setScrollBar(bool new_scrollbar);
69 virtual bool hasScrollBar() const { return scrollbar_; }
71 protected:
72 /// Struct Line saves a real line. All text added into TextView is split on
73 /// '\\n' character and stored into Line objects.
74 struct Line {
75 /// UTF-8 encoded text. Note: Newline character is not part of text.
76 char *text;
78 /// Text length in characters.
79 std::size_t length;
81 /// Color number.
82 int color;
84 Line(const char *text_, std::size_t bytes, int color_);
85 virtual ~Line();
88 /// ScreenLine represents an on-screen line.
89 struct ScreenLine {
90 /// Parent Line that this ScreenLine shows.
91 Line *parent;
93 /// Pointer into parent's text where this ScreenLine starts.
94 const char *text;
96 /// Length in characters (Unicode).
97 int length;
99 ScreenLine(Line &parent_, const char *text_, int length_);
102 typedef std::deque<Line *> Lines;
103 typedef std::deque<ScreenLine> ScreenLines;
105 std::size_t view_top_;
106 bool autoscroll_;
107 bool autoscroll_suspended_;
108 bool scrollbar_;
110 /// Array of real lines.
111 Lines lines_;
113 /// Array of on-screen lines.
114 ScreenLines screen_lines_;
116 // Widget
117 virtual void updateArea() override;
119 virtual const char *proceedLine(
120 const char *text, int area_width, int *res_length) const;
122 /// Recalculates on-screen lines for a specified line number.
123 virtual std::size_t updateScreenLines(
124 std::size_t line_num, std::size_t start = 0);
126 /// Recalculates all screen lines.
127 virtual void updateAllScreenLines();
129 virtual std::size_t eraseScreenLines(std::size_t line_num,
130 std::size_t start = 0, std::size_t *deleted = nullptr);
132 private:
133 CONSUI_DISABLE_COPY(TextView);
135 void actionScroll(int direction);
137 void declareBindables();
140 } // namespace CppConsUI
142 #endif // TEXTVIEW_H
144 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: