cwidget  0.5.17
Namespaces | Classes | Typedefs | Functions | Variables
cwidget Namespace Reference

The namespace containing everything defined by cwidget. More...

Namespaces

 config
 Routines that support parsing and interpreting user configuration.
 
 dialogs
 Routines to construct simple dialog boxes.
 
 threads
 C++ wrappers for the POSIX threading primitives.
 
 toplevel
 The namespace containing functions to manage the global state of cwidget.
 
 util
 Miscellaneous utility functions that are not directly related to the core functionality of cwidget.
 

Classes

class  chstring
 A string class which stores attributes along with characters. More...
 
struct  column
 
struct  column_disposition
 
class  cwindow
 
class  fragment
 A fragment represents a logical unit of text. More...
 
class  fragment_cache
 A fragment that caches its contents; a cached result is used if the same width is passed to the layout routine twice in a row. More...
 
struct  fragment_column_entry
 Stores information on a single column of fragments. More...
 
class  fragment_contents
 This class represents the formatted contents of a fragment. More...
 
class  style
 A "style" is a setting to be applied to a display element (widget, text, etc). More...
 
class  wchstring
 
struct  wchtype
 A structure that amalgamates a wchar_t together with attributes. More...
 

Typedefs

typedef std::list< columncolumn_list
 
typedef std::list< columnlayout
 
typedef wchstring fragment_line
 The type used to represent a line of a fragment; it might be worthwhile to change this to a rope<chtype> if this class is used to format larger pieces of text.
 

Functions

wstring columnify (const layout &format, int width)
 
void init_curses ()
 
void resize ()
 
chtype _getbkgd (WINDOW *win)
 
int _box (WINDOW *win, chtype verch, chtype horch)
 
void _getyx (WINDOW *win, int &y, int &x)
 
void _getparyx (WINDOW *win, int &y, int &x)
 
void _getbegyx (WINDOW *win, int &y, int &x)
 
void _getmaxyx (WINDOW *win, int &y, int &x)
 
int _getmaxy (WINDOW *win)
 
int _getmaxx (WINDOW *win)
 
int _touchwin (WINDOW *win)
 
int _untouchwin (WINDOW *win)
 
fragmenttext_fragment (const wstring &s)
 
fragmenttext_fragment (const wstring &s, const style &st)
 
fragmenttext_fragment (const string &s, const char *encoding)
 
fragmenttext_fragment (const string &s, const style &st, const char *encoding)
 
fragmentnewline_fragment ()
 Create a fragment which simply produces a newline wherever it occurs. More...
 
fragmentstyle_fragment (fragment *f, const style &st)
 Create a fragment which alters the style of its contents. More...
 
fragmentsequence_fragment (const vector< fragment *> &contents)
 
fragmentsequence_fragment (fragment *f,...)
 Create a fragment from a sequence of other fragments. More...
 
fragmentjoin_fragments (const vector< fragment *> &fragments, const wstring &between)
 
fragmentflowbox (fragment *contents)
 Create a flowbox. More...
 
fragmentfillbox (fragment *contents)
 Create a fillbox. More...
 
fragmenthardwrapbox (fragment *contents)
 Create a hardwrapbox. More...
 
fragmentclipbox (fragment *contents)
 Create a clipbox. More...
 
fragmentindentbox (size_t firstindent, size_t restindent, fragment *contents)
 Create an indentbox. More...
 
fragmentdropbox (fragment *header, fragment *contents)
 Indent a paragraph, placing the given text on the first line. More...
 
fragmentfragment_columns (const vector< fragment_column_entry > &columns)
 
string char_to_str (char code)
 
fragmentfragf (const char *format,...)
 A printf-alike for fragments. More...
 
fragmenttext_fragment (const std::wstring &s)
 Create a fragment from a string of text. More...
 
fragmenttext_fragment (const std::wstring &s, const style &st)
 Create a fragment from a string of text. More...
 
fragmenttext_fragment (const std::string &s, const char *encoding=NULL)
 Create a fragment from a string of multibyte-encoded text. More...
 
fragmenttext_fragment (const std::string &s, const style &st, const char *encoding=NULL)
 Create a fragment from a string of multibyte-encoded text, wrapping an implicit style_fragment around it.
 
fragmenttext_fragment (const char *s, const style &st=style())
 Create a fragment from a string of text. More...
 
fragmentsequence_fragment (const std::vector< fragment *> &fragments)
 Create a fragment from a sequence of other fragments. More...
 
fragmentjoin_fragments (const std::vector< fragment *> &fragments, const std::wstring &between)
 Join fragments into a single fragment, placing text between them. More...
 
fragmentfragment_columns (const std::vector< fragment_column_entry > &columns)
 A fragment that formats its contents into columns. More...
 
const styleget_style (const std::string &name)
 Look up a style in the global registry. More...
 
void set_style (const std::string &name, const style &style)
 Place a style in the global registry. More...
 
style style_fg (short fg)
 
style style_bg (short bg)
 
style style_attrs_on (attr_t attrs)
 
style style_attrs_off (attr_t attrs)
 
style style_attrs_flip (attr_t attrs)
 
std::string version ()
 Return the version number of the library. More...
 

Variables

cwindow rootwin =NULL
 
cwindow rootwinhack =NULL
 
map< string, stylestyles
 

Detailed Description

The namespace containing everything defined by cwidget.

Function Documentation

◆ clipbox()

fragment * cwidget::clipbox ( fragment contents)

Create a clipbox.

Each line of the fragment placed inside the clipbox will be clipped to the current width. The whole layout widget implicitly uses one of these, but there may be other uses for clipboxes as well.

Parameters
contentsthe contents of the clipbox
Returns
the new clipbox

References cwidget::wchstring::apply_style(), clipbox(), and cwidget::style::get_attrs().

Referenced by clipbox(), and text_fragment().

◆ dropbox()

fragment * cwidget::dropbox ( fragment header,
fragment contents 
)

Indent a paragraph, placing the given text on the first line.

This just expands to an invocation of indentbox, with the indentation constants set appropriately. The result will consist of "header" prepended to the first line of "contents", with successive lines of "contents" indented to line up with the first line of "contents".

References dropbox(), cwidget::fragment_column_entry::expandable, cwidget::style::get_attrs(), indentbox(), cwidget::fragment::layout(), cwidget::fragment_column_entry::lines, cwidget::fragment::max_width(), cwidget::fragment_column_entry::proportional, and cwidget::wchstring::width().

Referenced by dropbox(), and text_fragment().

◆ fillbox()

fragment * cwidget::fillbox ( fragment contents)

Create a fillbox.

Each line of the fragment placed inside the fillbox will be reflowed (word-wrapped) and expanded to the current width, possibly to several lines.

The contents of a fillbox always have final_nl=true.

Parameters
contentsthe contents of the fillbox
Returns
the new fillbox

References fillbox().

Referenced by fillbox(), and text_fragment().

◆ flowbox()

fragment * cwidget::flowbox ( fragment contents)

Create a flowbox.

Each line of the fragment placed inside the flowbox will be reflowed (word-wrapped) to the current width, possibly to several lines.

The contents of a flowbox always have final_nl=true. (ie, a flowbox is always followed by a line break)

Parameters
contentsthe contents of the flowbox
Returns
the new flowbox

References flowbox(), cwidget::style::get_attrs(), and cwidget::wchstring::width().

Referenced by flowbox(), and text_fragment().

◆ fragf()

fragment * cwidget::fragf ( const char *  format,
  ... 
)

A printf-alike for fragments.

Formatting codes:

  • F: substitutes a fragment into the sequence being built
  • s: substitutes a const char * into the sequence being built with transcoding according to LC_CTYPE
  • n: substitutes a newline fragment into the sequence being built
  • %%: inserts a literal %
  • B/b: toggle the bold character attribute
  • R/r: toggle the reverse video character attribute
  • D/d: toggle the dim character attribute
  • S: Apply the style corresponding to a string (looked up via get_style) to the attributes.
  • N: Reset the text style to the empty ("null") style.

For instance,

fragf("%S%BWARNING%b: something bad happened in routine %s," "expect a segfault.", "Error", some_routine);

Note: if you use a parameter index multiple times, you are virtually GUARANTEED to segfault!

Parameters
formatthe format string
Returns
the formatted fragment, or NULL if there is an error in the format.

References cwidget::style::attrs_flip(), fragf(), get_style(), and newline_fragment().

Referenced by fragf(), and cwidget::fragment_column_entry::fragment_column_entry().

◆ fragment_columns()

fragment* cwidget::fragment_columns ( const std::vector< fragment_column_entry > &  columns)

A fragment that formats its contents into columns.

If the fixed-width columns overflow the available space, they will be clipped hard.

This fragment may NOT be placed inside an indent box or any other box that alters the shape of its contents. Doing so will cause the program to abort.

Parameters
columnsa list of column entry information ordered from left to right.

◆ get_style()

const style & cwidget::get_style ( const std::string &  name)

◆ hardwrapbox()

fragment * cwidget::hardwrapbox ( fragment contents)

Create a hardwrapbox.

Each line of the fragment inside the box will be hard-wrapped to the current width.

The contents of a wrapbox always have final_nl=true.

Parameters
contentsthe contents of the hardwrapbox
Returns
the new hardwrapbox

References hardwrapbox().

Referenced by hardwrapbox(), and text_fragment().

◆ indentbox()

fragment * cwidget::indentbox ( size_t  firstindent,
size_t  restindent,
fragment contents 
)

Create an indentbox.

Each line of the indentbox will be indented by the specified amount. (this effectively decreases the width of each line) If desired, the first line can be indented a different amount (typically less) than the remaining lines, although it is formatted to the same width; this supports things like bulletted lists.

Parameters
firstindentthe number of spaces of indentation to use for the first line
restindentthe number of spaces of indentation to use for later lines
contentsthe contents of the indentbox
Returns
the new indentbox

References indentbox().

Referenced by dropbox(), indentbox(), and text_fragment().

◆ join_fragments()

fragment* cwidget::join_fragments ( const std::vector< fragment *> &  fragments,
const std::wstring &  between 
)

Join fragments into a single fragment, placing text between them.

This is useful for creating lists, for instance. The new fragment takes ownership of all pointers in fragments.

Parameters
fragmentsthe list of fragments to join
betweena string to place between adjacent items in the input list

◆ newline_fragment()

fragment * cwidget::newline_fragment ( )

Create a fragment which simply produces a newline wherever it occurs.

References newline_fragment().

Referenced by fragf(), newline_fragment(), text_fragment(), and cwidget::fragment::~fragment().

◆ sequence_fragment() [1/2]

fragment* cwidget::sequence_fragment ( const std::vector< fragment *> &  fragments)

Create a fragment from a sequence of other fragments.

The fragment will simply "shove" the two sequences together, respecting the value of final_nl on each.

Todo:
can this be made more efficient? It should be possible to just "plug" the sequences together if they're lists – but that only works if they aren't cached elsewhere.
Parameters
fragmentsthe fragments in the sequence
Returns
the new fragment

◆ sequence_fragment() [2/2]

fragment * cwidget::sequence_fragment ( fragment f,
  ... 
)

Create a fragment from a sequence of other fragments.

The fragment will simply "shove" the two sequences together, respecting the value of final_nl on each.

Parameters
fthe first fragment in the sequence; the sequence should be terminated with a NULL pointer.
Returns
the new fragment

◆ set_style()

void cwidget::set_style ( const std::string &  name,
const style style 
)

Place a style in the global registry.

References set_style().

Referenced by cwidget::toplevel::init(), set_style(), and style_attrs_flip().

◆ style_attrs_flip()

style cwidget::style_attrs_flip ( attr_t  attrs)
inline
Returns
a style that just flips the given attributes.

References cwidget::style::attrs_flip(), get_style(), and set_style().

Referenced by cwidget::widgets::togglebutton::paint(), cwidget::widgets::button::paint(), and cwidget::dialogs::yesno().

◆ style_attrs_off()

style cwidget::style_attrs_off ( attr_t  attrs)
inline
Returns
a style that just clears the given attributes.

References cwidget::style::attrs_off().

Referenced by cwidget::toplevel::init().

◆ style_attrs_on()

style cwidget::style_attrs_on ( attr_t  attrs)
inline
Returns
a style that just sets the given attributes.

References cwidget::style::attrs_on().

Referenced by cwidget::toplevel::init(), cwidget::widgets::staticitem::paint(), and cwidget::widgets::menu::paint().

◆ style_bg()

style cwidget::style_bg ( short  bg)
inline
Returns
a style that just sets the background color to the given value.

References cwidget::style::set_bg().

Referenced by cwidget::toplevel::init().

◆ style_fg()

style cwidget::style_fg ( short  fg)
inline
Returns
a style that just sets the foreground color to the given value.

References cwidget::style::set_fg().

Referenced by cwidget::toplevel::init().

◆ style_fragment()

fragment * cwidget::style_fragment ( fragment f,
const style st 
)

Create a fragment which alters the style of its contents.

Parameters
fthe child of this fragment
attrthe text attribute which should be assigned to f
Returns
the new fragment

References style_fragment(), and cwidget::wchstring::width().

Referenced by style_fragment(), text_fragment(), and cwidget::fragment::~fragment().

◆ text_fragment() [1/4]

fragment* cwidget::text_fragment ( const std::wstring &  s)

Create a fragment from a string of text.

The text will simply be formatted as is, with line breaks at newlines and tabs replaced by eight spaces.

Parameters
sthe text to use
Returns
the new fragment

◆ text_fragment() [2/4]

fragment* cwidget::text_fragment ( const std::wstring &  s,
const style st 
)

Create a fragment from a string of text.

The text will simply be formatted as a single line without clipping.

Parameters
sthe text to use
stylethe base style for the new fragment; an implicit style_fragment for this style is wrapped around the new text_fragment.
Returns
the new fragment

◆ text_fragment() [3/4]

fragment* cwidget::text_fragment ( const std::string &  s,
const char *  encoding = NULL 
)

Create a fragment from a string of multibyte-encoded text.

Parameters
sthe text to use
encodingthe text's encoding; if this is null or unspecified, LC_CTYPE will be used.
Returns
the new fragment

◆ text_fragment() [4/4]

fragment* cwidget::text_fragment ( const char *  s,
const style st = style() 
)
inline

Create a fragment from a string of text.

The text will simply be formatted as a single line without clipping.

Parameters
sthe text to use
attrattributes to assign to it
Returns
the new fragment

References clipbox(), dropbox(), fillbox(), flowbox(), hardwrapbox(), indentbox(), newline_fragment(), and style_fragment().

◆ version()

std::string cwidget::version ( )

Return the version number of the library.