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
cwidget::util::ref_ptr
Definition: ref_ptr.h:20
cwidget::config::key
Represents a keystroke as seen by curses.
Definition: keybindings.h:43
cwidget::widgets::text_layout::create
static util::ref_ptr< text_layout > create()
Create an empty text_layout.
Definition: text_layout.h:55
cwidget::widgets::text_layout::move_to_top
void move_to_top()
Move the view to the top of the widget.
Definition: text_layout.cc:247
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:55
cwidget::widgets::text_layout::line_down
void line_down()
Move the view one line down.
Definition: text_layout.cc:230
cwidget::widgets::point
Definition: widget.h:90
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::config::keybindings::key_matches
bool key_matches(const key &k, std::string tag)
Test whether a key is bound to a function.
Definition: keybindings.cc:325
cwidget::widgets::text_layout::scroll
void scroll(bool dir)
Page based on a scrollbar signal.
Definition: text_layout.cc:342
toplevel.h
Routines to manage the global cwidget state.
keybindings.h
Support for defining and remapping keybindings.
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:160
cwidget::style
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:52
cwidget::fragment
A fragment represents a logical unit of text.
Definition: fragment.h:38
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:84
cwidget::widgets::text_layout::focus_me
bool focus_me()
Return true iff this widget should be given focus.
Definition: text_layout.cc:188
cwidget::widgets::text_layout::get_cursorloc
point get_cursorloc()
Return the location of the cursor in this widget.
Definition: text_layout.cc:180
cwidget::wchstring
Definition: curses++.h:200
cwidget::widgets::text_layout::move_to_bottom
void move_to_bottom()
Move the view to the bottom of the widget.
Definition: text_layout.cc:252
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:286
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:267
cwidget::widgets::text_layout::get_cursorvisible
bool get_cursorvisible()
Return true iff the cursor is visible in this widget.
Definition: text_layout.cc:174
cwidget::fragment_contents
This class represents the formatted contents of a fragment.
Definition: fragment_contents.h:31
cwidget::widgets::text_layout::width_request
int width_request()
Return the requested width of this widget.
Definition: text_layout.cc:110
cwidget::widgets::text_layout::append_fragment
void append_fragment(fragment *f)
Append the given fragment to the current fragment.
Definition: text_layout.cc:144
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:67
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:118
cwidget::widgets::text_layout::~text_layout
~text_layout()
Delete the root fragment.
Definition: text_layout.cc:127
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:259
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:108
cwidget::widgets::text_layout::paint
void paint(const style &st)
Paint this widget.
Definition: text_layout.cc:201
cwidget::widgets::text_layout::set_fragment
void set_fragment(fragment *f)
Change the fragment being displayed in this layout widget.
Definition: text_layout.cc:132
cwidget::config::keybindings
Stores the keys bound to various functions.
Definition: keybindings.h:88
cwidget::widgets::text_layout::line_up
void line_up()
Move the view one line up.
Definition: text_layout.cc:238