cwidget 0.5.18
text_layout.h
1// text_layout.h -*-c++-*-
2//
3// Copyright (C) 2004-2005, 2007 Daniel Burrows
4// Copyright (C) 2019 Manuel A. Fernandez Montecelo
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License as
8// published by the Free Software Foundation; either version 2 of
9// the License, or (at your option) any later version.
10//
11// This program 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 GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; see the file COPYING. If not, write to
18// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19// Boston, MA 02111-1307, USA.
20
21
22#ifndef TEXT_LAYOUT_H
23#define TEXT_LAYOUT_H
24
25#include "widget.h"
26#include <cwidget/fragment_contents.h>
27
28namespace cwidget
29{
30 class fragment;
31
32 namespace widgets
33 {
49 class text_layout : public widget
50 {
51 protected:
54 public:
57 {
59 rval->decref();
60 return rval;
61 }
62
69 {
71 rval->decref();
72 return rval;
73 }
74
78 bool handle_key(const config::key &k);
79
80 void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
81
83 void set_fragment(fragment *f);
84
100
104 int width_request();
105
109 int height_request(int w);
110
112 bool get_cursorvisible();
113
116
118 bool focus_me();
119
121 void paint(const style &st);
122
124 void line_down();
125
127 void line_up();
128
130 void move_to_top();
131
133 void move_to_bottom();
134
136 void page_down();
137
139 void page_up();
140
145 void search_for(const std::wstring &s,
146 bool search_forwards);
147
153 void scroll(bool dir);
154
156 ~text_layout();
157
161 sigc::signal2<void, int, int> location_changed;
162
163 static config::keybindings *bindings;
164
165 static void init_bindings();
166 private:
168 void set_start(unsigned int new_start);
169
171 void freshen_contents(const style &st);
172
174 void layout_me();
175
177 void do_signal();
178
180 size_t start;
181
183 fragment *f;
184
186 fragment_contents contents;
187
189 bool stale;
190
192 int lastw;
193
195 style lastst;
196 };
197
199 }
200}
201
202#endif
Stores the keys bound to various functions.
Definition: keybindings.h:88
This class represents the formatted contents of a fragment.
Definition: fragment_contents.h:31
A fragment represents a logical unit of text.
Definition: fragment.h:38
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:52
Definition: ref_ptr.h:20
Code to display formatted text.
Definition: text_layout.h:50
point get_cursorloc()
Return the location of the cursor in this widget.
Definition: text_layout.cc:173
~text_layout()
Delete the root fragment.
Definition: text_layout.cc:120
void scroll(bool dir)
Page based on a scrollbar signal.
Definition: text_layout.cc:335
int height_request(int w)
Return the requested height of this widget given its width, by running the fragment-layout algorithm.
Definition: text_layout.cc:111
void move_to_top()
Move the view to the top of the widget.
Definition: text_layout.cc:240
void move_to_bottom()
Move the view to the bottom of the widget.
Definition: text_layout.cc:245
void page_up()
Move a page back.
Definition: text_layout.cc:252
static util::ref_ptr< text_layout > create()
Create an empty text_layout.
Definition: text_layout.h:56
void line_up()
Move the view one line up.
Definition: text_layout.cc:231
bool get_cursorvisible()
Return true iff the cursor is visible in this widget.
Definition: text_layout.cc:167
bool handle_key(const config::key &k)
Handle the given keypress.
Definition: text_layout.cc:56
void append_fragment(fragment *f)
Append the given fragment to the current fragment.
Definition: text_layout.cc:137
void search_for(const std::wstring &s, bool search_forwards)
Search either forwards or backwards for the string s.
Definition: text_layout.cc:279
static util::ref_ptr< text_layout > create(fragment *f)
Create a text_layout with the given root fragment.
Definition: text_layout.h:68
void line_down()
Move the view one line down.
Definition: text_layout.cc:223
void paint(const style &st)
Paint this widget.
Definition: text_layout.cc:194
int width_request()
Return the requested width of this widget.
Definition: text_layout.cc:103
sigc::signal2< void, int, int > location_changed
A signal that is called whenever the "location" of the view within the text changes.
Definition: text_layout.h:161
bool focus_me()
Return true iff this widget should be given focus.
Definition: text_layout.cc:181
void page_down()
Move a page forward.
Definition: text_layout.cc:260
void set_fragment(fragment *f)
Change the fragment being displayed in this layout widget.
Definition: text_layout.cc:125
The basic widget interface.
Definition: widget.h:107
The namespace containing everything defined by cwidget.
Definition: columnify.cc:28
Represents a keystroke as seen by curses.
Definition: keybindings.h:43
Definition: widget.h:89