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 
28 namespace cwidget
29 {
30  class fragment;
31 
32  namespace widgets
33  {
49  class text_layout : public widget
50  {
51  protected:
52  text_layout();
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 
99  void append_fragment(fragment *f);
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
cwidget::util::ref_ptr
Definition: ref_ptr.h:19
cwidget::config::key
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
cwidget::widgets::text_layout::create
static util::ref_ptr< text_layout > create()
Create an empty text_layout.
Definition: text_layout.h:56
cwidget::widgets::text_layout::move_to_top
void move_to_top()
Move the view to the top of the widget.
Definition: text_layout.cc:240
cwidget::config::global_bindings
keybindings global_bindings
The global keybindings object.
Definition: keybindings.cc:43
cwidget::widgets::text_layout::handle_key
bool handle_key(const config::key &k)
Handle the given keypress.
Definition: text_layout.cc:56
cwidget::widgets::text_layout::line_down
void line_down()
Move the view one line down.
Definition: text_layout.cc:223
cwidget::widgets::point
Definition: widget.h:88
cwidget::fragment::layout
virtual fragment_contents layout(size_t firstw, size_t w, const style &st)=0
Return all the lines of this fragment, given the "shape" of the fragment.
cwidget::fragment::max_width
virtual size_t max_width(size_t first_indent, size_t rest_indent) const =0
cwidget::widgets::text_layout::scroll
void scroll(bool dir)
Page based on a scrollbar signal.
Definition: text_layout.cc:335
toplevel.h
Routines to manage the global cwidget state.
keybindings.h
Support for defining and remapping keybindings.
cwidget::config::keybindings::key_matches
bool key_matches(const key &k, std::string tag) const
Test whether a key is bound to a function.
Definition: keybindings.cc:325
cwidget::widgets::text_layout::location_changed
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
cwidget::style
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
cwidget::fragment
A fragment represents a logical unit of text.
Definition: fragment.h:37
cwidget::toplevel::queuelayout
void queuelayout()
Posts a request to recalculate every widget's layout and update the screen.
Definition: toplevel.cc:1093
cwidget::widgets::widget::handle_key
virtual bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition: widget.cc:228
cwidget::widgets::size
Definition: widget.h:82
cwidget::widgets::text_layout::focus_me
bool focus_me()
Return true iff this widget should be given focus.
Definition: text_layout.cc:181
cwidget::widgets::text_layout::get_cursorloc
point get_cursorloc()
Return the location of the cursor in this widget.
Definition: text_layout.cc:173
cwidget::wchstring
Definition: curses++.h:198
cwidget::widgets::text_layout::move_to_bottom
void move_to_bottom()
Move the view to the bottom of the widget.
Definition: text_layout.cc:245
cwidget::widgets::text_layout::search_for
void search_for(const std::wstring &s, bool search_forwards)
Search either forwards or backwards for the string s.
Definition: text_layout.cc:279
cwidget::widgets::text_layout
Code to display formatted text.
Definition: text_layout.h:49
cwidget::widgets::text_layout::page_down
void page_down()
Move a page forward.
Definition: text_layout.cc:260
cwidget::widgets::text_layout::get_cursorvisible
bool get_cursorvisible()
Return true iff the cursor is visible in this widget.
Definition: text_layout.cc:167
cwidget::fragment_contents
This class represents the formatted contents of a fragment.
Definition: fragment_contents.h:30
cwidget::widgets::text_layout::width_request
int width_request()
Return the requested width of this widget.
Definition: text_layout.cc:103
cwidget::widgets::text_layout::append_fragment
void append_fragment(fragment *f)
Append the given fragment to the current fragment.
Definition: text_layout.cc:137
cwidget::widgets::text_layout::create
static util::ref_ptr< text_layout > create(fragment *f)
Create a text_layout with the given root fragment.
Definition: text_layout.h:68
cwidget::widgets::text_layout::height_request
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
cwidget::widgets::text_layout::~text_layout
~text_layout()
Delete the root fragment.
Definition: text_layout.cc:120
cwidget::toplevel::update
void update()
Posts a request to redraw the screen; may be called from any thread.
Definition: toplevel.cc:1072
cwidget::widgets::text_layout::page_up
void page_up()
Move a page back.
Definition: text_layout.cc:252
cwidget
The namespace containing everything defined by cwidget.
Definition: columnify.cc:27
cwidget::newline_fragment
fragment * newline_fragment()
Create a fragment which simply produces a newline wherever it occurs.
Definition: fragment.cc:165
cwidget::widgets::widget
The basic widget interface.
Definition: widget.h:106
cwidget::widgets::text_layout::paint
void paint(const style &st)
Paint this widget.
Definition: text_layout.cc:194
cwidget::widgets::text_layout::set_fragment
void set_fragment(fragment *f)
Change the fragment being displayed in this layout widget.
Definition: text_layout.cc:125
cwidget::config::keybindings
Stores the keys bound to various functions.
Definition: keybindings.h:87
cwidget::widgets::text_layout::line_up
void line_up()
Move the view one line up.
Definition: text_layout.cc:231