cwidget  0.5.17
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
cwidget::widgets::text_layout Class Reference

Code to display formatted text. More...

#include <text_layout.h>

Inheritance diagram for cwidget::widgets::text_layout:
cwidget::widgets::widget

Public Member Functions

bool handle_key (const config::key &k)
 Handle the given keypress. More...
 
void dispatch_mouse (short id, int x, int y, int z, mmask_t bstate)
 
void set_fragment (fragment *f)
 Change the fragment being displayed in this layout widget. More...
 
void append_fragment (fragment *f)
 Append the given fragment to the current fragment. More...
 
int width_request ()
 Return the requested width of this widget. More...
 
int height_request (int w)
 Return the requested height of this widget given its width, by running the fragment-layout algorithm.
 
bool get_cursorvisible ()
 Return true iff the cursor is visible in this widget. More...
 
point get_cursorloc ()
 Return the location of the cursor in this widget. More...
 
bool focus_me ()
 Return true iff this widget should be given focus. More...
 
void paint (const style &st)
 Paint this widget. More...
 
void line_down ()
 Move the view one line down. More...
 
void line_up ()
 Move the view one line up. More...
 
void move_to_top ()
 Move the view to the top of the widget. More...
 
void move_to_bottom ()
 Move the view to the bottom of the widget. More...
 
void page_down ()
 Move a page forward. More...
 
void page_up ()
 Move a page back. More...
 
void search_for (const std::wstring &s, bool search_forwards)
 Search either forwards or backwards for the string s. More...
 
void scroll (bool dir)
 Page based on a scrollbar signal. More...
 
 ~text_layout ()
 Delete the root fragment. More...
 
- Public Member Functions inherited from cwidget::widgets::widget
void incref ()
 
void decref ()
 
void show ()
 
virtual void show_all ()
 
void hide ()
 
void toggle_visible ()
 
void set_visible (bool _visible)
 
bool dispatch_key (const config::key &k)
 
void alloc_size (int x, int y, int w, int h)
 Set the size and location in the parent of this widget. More...
 
bool get_isfocussed ()
 
void set_owner (container *w)
 
void display (const style &st)
 Display this widget in the given style environment. More...
 
int timeout (int msecs)
 
virtual void destroy ()
 Destroys the visible representation of this widget and disconnects it from any children that it may have.
 
util::ref_ptr< containerget_owner ()
 
int get_startx ()
 
int get_starty ()
 
int get_width ()
 
int get_height ()
 
bool get_visible ()
 
void sync ()
 
int scroll (int n=1)
 
int addch (chtype ch)
 
int mvaddch (int y, int x, chtype ch)
 
int add_wch (wchar_t wch)
 
int add_wch (const cchar_t *cch)
 
int mvadd_wch (int y, int x, wchar_t wch)
 
int mvadd_wch (int y, int x, const cchar_t *cch)
 
int addstr (const char *str)
 
int addnstr (const char *str, int n)
 
int mvaddstr (int y, int x, const char *str)
 
int mvaddnstr (int y, int x, const char *str, int n)
 
int addstr (const wchar_t *str)
 
int addnstr (const wchar_t *str, int n)
 
int mvaddstr (int y, int x, const wchar_t *str)
 
int mvaddnstr (int y, int x, const wchar_t *str, int n)
 
int addstr (const std::wstring &str)
 
int addnstr (const std::wstring &str, int n)
 
int mvaddstr (int y, int x, const std::wstring &str)
 
int mvaddnstr (int y, int x, const std::wstring &str, int n)
 
int addstr (const wchstring &str)
 
int addnstr (const wchstring &str, int n)
 
int mvaddstr (int y, int x, const wchstring &str)
 
int mvaddnstr (int y, int x, const wchstring &str, int n)
 
int addstr (const chstring &str)
 
int addnstr (const chstring &str, int n)
 
int mvaddstr (int y, int x, const chstring &str)
 
int mvaddnstr (int y, int x, const chstring &str, int n)
 
int attroff (int attrs)
 
int attron (int attrs)
 
int attrset (int attrs)
 
void bkgdset (const chtype ch)
 
int bkgd (const chtype ch)
 
chtype getbkgd ()
 
int border (chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br)
 
int box (chtype verch, chtype horch)
 
int hline (chtype ch, int n)
 
int vline (chtype ch, int n)
 
int mvhline (int y, int x, chtype ch, int n)
 
int mvvline (int y, int x, chtype ch, int n)
 
int delch ()
 
int mvdelch (int y, int x)
 
int deleteln ()
 
int insdelln (int n)
 
int insertln ()
 
int echochar (chtype ch)
 
int move (int y, int x)
 
void getyx (int &y, int &x)
 
void getbegyx (int &y, int &x)
 
void getmaxyx (int &y, int &x)
 
int getmaxy ()
 
int getmaxx ()
 
void show_string_as_progbar (int x, int y, const std::wstring &s, const style &st1, const style &st2, int size1, int totalsize)
 
void display_header (std::wstring s, const style &st)
 
void display_status (std::wstring s, const style &st)
 
int erase ()
 
int clear ()
 
int clrtobot ()
 
int clrtoeol ()
 
int keypad (bool bf)
 
int meta (bool bf)
 
bool enclose (int y, int x)
 
void set_opaque (bool opaque)
 Enable or disable clearing the background before displaying the widget. More...
 
void set_bg_style (const style &new_style)
 Update this widget's basic style to the given value. More...
 
void apply_style (const style &st)
 Set the display attributes of our associated window directly from the given style. More...
 
key_connection connect_key (const std::string &key, config::keybindings *bindings, const sigc::slot0< void > &slot)
 
key_connection connect_key_post (const std::string &key, config::keybindings *bindings, const sigc::slot0< void > &slot)
 
void disconnect_key (key_connection c)
 
void disconnect_key_post (key_connection c)
 

Static Public Member Functions

static util::ref_ptr< text_layoutcreate ()
 Create an empty text_layout. More...
 
static util::ref_ptr< text_layoutcreate (fragment *f)
 Create a text_layout with the given root fragment. More...
 
static void init_bindings ()
 
- Static Public Member Functions inherited from cwidget::widgets::widget
static void handle_pending_deletes ()
 

Public Attributes

sigc::signal2< void, int, int > location_changed
 A signal that is called whenever the "location" of the view within the text changes.
 
- Public Attributes inherited from cwidget::widgets::widget
sigc::signal0< void > shown_sig
 
sigc::signal0< void > hidden_sig
 
sigc::signal0< void > destroyed
 
sigc::signal0< void > do_layout
 
sigc::signal0< void > focussed
 
sigc::signal0< void > unfocussed
 

Static Public Attributes

static config::keybindingsbindings
 

Protected Member Functions

 text_layout (fragment *f)
 
- Protected Member Functions inherited from cwidget::widgets::widget
cwindow get_win ()
 
void cleanup ()
 Handle cleanup when the reference count goes to 0. More...
 

Additional Inherited Members

- Public Types inherited from cwidget::widgets::widget
typedef std::list< binding_connection >::iterator key_connection
 

Detailed Description

Code to display formatted text.

The text to display is composed of a tree of "fragments". A fragment stores some amount of text; at any time, it can be formatted to a particular width. The main layout mechanisms provided are flowboxes and clipboxes: flowboxes word-wrap their contents to a particular width, while clipboxes clip their contents to a particular width. These boxes can be nested, if the user feels like it for some reason or other, although some nestings are non-sensical (for instance, placing a flowbox inside a smaller flowbox is likely to lead to really ugly text).

This provides some primitive layout mechanisms; higher-level layouts can be expressed in terms of these.

Constructor & Destructor Documentation

◆ ~text_layout()

cwidget::widgets::text_layout::~text_layout ( )

Delete the root fragment.

Referenced by create().

Member Function Documentation

◆ append_fragment()

void cwidget::widgets::text_layout::append_fragment ( fragment f)

Append the given fragment to the current fragment.

Note
this is slightly less efficient than placing the two fragments into the text_layout up-front via a single sequence_fragment. Normally this isn't a problem, but if you want to append hundreds of fragments this way, it might be.
Todo:
this is only needed for memory-management reasons (otherwise I could safely extract the current fragment and create my own sequence). Would refcounting help?
Todo:
if this becomes very useful, it would be better to just explicitly store a sequence of fragments in the layout.

References cwidget::toplevel::queuelayout(), and cwidget::toplevel::update().

Referenced by create().

◆ create() [1/2]

static util::ref_ptr<text_layout> cwidget::widgets::text_layout::create ( )
inlinestatic

Create an empty text_layout.

Referenced by cwidget::dialogs::yesno().

◆ create() [2/2]

static util::ref_ptr<text_layout> cwidget::widgets::text_layout::create ( fragment f)
inlinestatic

Create a text_layout with the given root fragment.

All fragments are implicitly placed within a clipbox of width equal to the width of this widget.

References append_fragment(), focus_me(), get_cursorloc(), get_cursorvisible(), handle_key(), height_request(), line_down(), line_up(), move_to_bottom(), move_to_top(), page_down(), page_up(), paint(), scroll(), search_for(), set_fragment(), width_request(), and ~text_layout().

◆ focus_me()

bool cwidget::widgets::text_layout::focus_me ( )
virtual

Return true iff this widget should be given focus.

This widget can get focus if it can scroll: ie, if its contents take up more lines than it was allocated.

Reimplemented from cwidget::widgets::widget.

Referenced by create().

◆ get_cursorloc()

point cwidget::widgets::text_layout::get_cursorloc ( )
virtual

Return the location of the cursor in this widget.

The cursor is always located in the upper-left-hand corner.

Implements cwidget::widgets::widget.

Referenced by create().

◆ get_cursorvisible()

bool cwidget::widgets::text_layout::get_cursorvisible ( )
virtual

Return true iff the cursor is visible in this widget.

Implements cwidget::widgets::widget.

Referenced by create().

◆ handle_key()

bool cwidget::widgets::text_layout::handle_key ( const config::key k)
virtual

Handle the given keypress.

Returns true if the keystroke was "consumed" by this widget.

Reimplemented from cwidget::widgets::widget.

References cwidget::widgets::widget::handle_key(), and cwidget::config::keybindings::key_matches().

Referenced by create().

◆ line_down()

void cwidget::widgets::text_layout::line_down ( )

Move the view one line down.

Referenced by create().

◆ line_up()

void cwidget::widgets::text_layout::line_up ( )

Move the view one line up.

Referenced by create().

◆ move_to_bottom()

void cwidget::widgets::text_layout::move_to_bottom ( )

Move the view to the bottom of the widget.

Referenced by create().

◆ move_to_top()

void cwidget::widgets::text_layout::move_to_top ( )

Move the view to the top of the widget.

Referenced by create().

◆ page_down()

void cwidget::widgets::text_layout::page_down ( )

Move a page forward.

Referenced by create().

◆ page_up()

void cwidget::widgets::text_layout::page_up ( )

Move a page back.

Referenced by create().

◆ paint()

void cwidget::widgets::text_layout::paint ( const style st)
virtual

Paint this widget.

Paint by refreshing the contents [if necessary], then drawing, starting from the current line.

Implements cwidget::widgets::widget.

Referenced by create().

◆ scroll()

void cwidget::widgets::text_layout::scroll ( bool  dir)

Page based on a scrollbar signal.

Parameters
dirthe direction to page: if true, call page_up(); else call page_down().

Referenced by create(), and cwidget::dialogs::yesno().

◆ search_for()

void cwidget::widgets::text_layout::search_for ( const std::wstring &  s,
bool  search_forwards 
)

Search either forwards or backwards for the string s.

The search will start on either the next or the previous line from the top of the screen.

Referenced by create().

◆ set_fragment()

void cwidget::widgets::text_layout::set_fragment ( fragment f)

Change the fragment being displayed in this layout widget.

References cwidget::toplevel::queuelayout().

Referenced by create().

◆ width_request()

int cwidget::widgets::text_layout::width_request ( )
virtual

Return the requested width of this widget.

The requested width will be the largest possible width of any line.

Implements cwidget::widgets::widget.

Referenced by create().


The documentation for this class was generated from the following files: