cwidget  0.5.17
text_layout.h
1 // text_layout.h -*-c++-*-
2 //
3 // Copyright (C) 2004-2005, 2007 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of
8 // the License, or (at your option) any later version.
9 //
10 // This program 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 GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; see the file COPYING. If not, write to
17 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 // Boston, MA 02111-1307, USA.
19 
20 
21 #ifndef TEXT_LAYOUT_H
22 #define TEXT_LAYOUT_H
23 
24 #include "widget.h"
25 #include <cwidget/fragment_contents.h>
26 
27 namespace cwidget
28 {
29  class fragment;
30 
31  namespace widgets
32  {
48  class text_layout : public widget
49  {
50  protected:
51  text_layout();
53  public:
56  {
58  rval->decref();
59  return rval;
60  }
61 
68  {
70  rval->decref();
71  return rval;
72  }
73 
77  bool handle_key(const config::key &k);
78 
79  void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
80 
82  void set_fragment(fragment *f);
83 
98  void append_fragment(fragment *f);
99 
103  int width_request();
104 
108  int height_request(int w);
109 
111  bool get_cursorvisible();
112 
115 
117  bool focus_me();
118 
120  void paint(const style &st);
121 
123  void line_down();
124 
126  void line_up();
127 
129  void move_to_top();
130 
132  void move_to_bottom();
133 
135  void page_down();
136 
138  void page_up();
139 
144  void search_for(const std::wstring &s,
145  bool search_forwards);
146 
152  void scroll(bool dir);
153 
155  ~text_layout();
156 
160  sigc::signal2<void, int, int> location_changed;
161 
162  static config::keybindings *bindings;
163 
164  static void init_bindings();
165  private:
167  void set_start(unsigned int new_start);
168 
170  void freshen_contents(const style &st);
171 
173  void layout_me();
174 
176  void do_signal();
177 
179  size_t start;
180 
182  fragment *f;
183 
185  fragment_contents contents;
186 
188  bool stale;
189 
191  int lastw;
192 
194  style lastst;
195  };
196 
198  }
199 }
200 
201 #endif
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
This class represents the formatted contents of a fragment.
Definition: fragment_contents.h:30
Stores the keys bound to various functions.
Definition: keybindings.h:87
void move_to_bottom()
Move the view to the bottom of the widget.
Definition: text_layout.cc:244
static util::ref_ptr< text_layout > create(fragment *f)
Create a text_layout with the given root fragment.
Definition: text_layout.h:67
Definition: widget.h:89
Definition: ref_ptr.h:19
void search_for(const std::wstring &s, bool search_forwards)
Search either forwards or backwards for the string s.
Definition: text_layout.cc:278
void page_down()
Move a page forward.
Definition: text_layout.cc:259
void append_fragment(fragment *f)
Append the given fragment to the current fragment.
Definition: text_layout.cc:136
void page_up()
Move a page back.
Definition: text_layout.cc:251
~text_layout()
Delete the root fragment.
Definition: text_layout.cc:119
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
static util::ref_ptr< text_layout > create()
Create an empty text_layout.
Definition: text_layout.h:55
void move_to_top()
Move the view to the top of the widget.
Definition: text_layout.cc:239
The basic widget interface.
Definition: widget.h:107
void set_fragment(fragment *f)
Change the fragment being displayed in this layout widget.
Definition: text_layout.cc:124
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
void scroll(bool dir)
Page based on a scrollbar signal.
Definition: text_layout.cc:334
void paint(const style &st)
Paint this widget.
Definition: text_layout.cc:193
void line_up()
Move the view one line up.
Definition: text_layout.cc:230
bool handle_key(const config::key &k)
Handle the given keypress.
Definition: text_layout.cc:55
void line_down()
Move the view one line down.
Definition: text_layout.cc:222
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:160
Code to display formatted text.
Definition: text_layout.h:48
A fragment represents a logical unit of text.
Definition: fragment.h:37
bool focus_me()
Return true iff this widget should be given focus.
Definition: text_layout.cc:180
bool get_cursorvisible()
Return true iff the cursor is visible in this widget.
Definition: text_layout.cc:166
point get_cursorloc()
Return the location of the cursor in this widget.
Definition: text_layout.cc:172
int width_request()
Return the requested width of this widget.
Definition: text_layout.cc:102
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:110