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

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

Namespaces

namespace  config
 

Routines that support parsing and interpreting user configuration.


namespace  dialogs
 

Routines to construct simple dialog boxes.


namespace  threads
 

C++ wrappers for the POSIX threading primitives.


namespace  toplevel
 

The namespace containing functions to manage the global state of cwidget.


namespace  util
 

Miscellaneous utility functions that are not directly related to the core functionality of cwidget.


Classes

struct  column_disposition
struct  column
struct  wchtype
 A structure that amalgamates a wchar_t together with attributes. More...
class  chstring
 A string class which stores attributes along with characters. More...
class  wchstring
class  cwindow
class  fragment
 A fragment represents a logical unit of text. More...
struct  fragment_column_entry
 Stores information on a single column of fragments. 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...
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...

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.
fragmentstyle_fragment (fragment *f, const style &st)
 Create a fragment which alters the style of its contents.
fragmentsequence_fragment (const vector< fragment * > &contents)
fragmentsequence_fragment (fragment *f,...)
 Create a fragment from a sequence of other fragments.
fragmentjoin_fragments (const vector< fragment * > &fragments, const wstring &between)
fragmentflowbox (fragment *contents)
 Create a flowbox.
fragmentfillbox (fragment *contents)
 Create a fillbox.
fragmenthardwrapbox (fragment *contents)
 Create a hardwrapbox.
fragmentclipbox (fragment *contents)
 Create a clipbox.
fragmentindentbox (size_t firstindent, size_t restindent, fragment *contents)
 Create an indentbox.
fragmentdropbox (fragment *header, fragment *contents)
 Indent a paragraph, placing the given text on the first line.
fragmentfragment_columns (const vector< fragment_column_entry > &columns)
string char_to_str (char code)
fragmentfragf (const char *format,...)
 A printf-alike for fragments.
fragmenttext_fragment (const std::wstring &s)
 Create a fragment from a string of text.
fragmenttext_fragment (const std::wstring &s, const style &st)
 Create a fragment from a string of text.
fragmenttext_fragment (const std::string &s, const char *encoding=NULL)
 Create a fragment from a string of multibyte-encoded text.
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.
fragmentsequence_fragment (const std::vector< fragment * > &fragments)
 Create a fragment from a sequence of other fragments.
fragmentjoin_fragments (const std::vector< fragment * > &fragments, const std::wstring &between)
 Join fragments into a single fragment, placing text between them.
fragmentfragment_columns (const std::vector< fragment_column_entry > &columns)
 A fragment that formats its contents into columns.
const styleget_style (const std::string &name)
 Look up a style in the global registry.
void set_style (const std::string &name, const style &style)
 Place a style in the global registry.
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.

Variables

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

Detailed Description

The namespace containing everything defined by cwidget.


Function Documentation

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 clipbox().

Referenced by clipbox().

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(), indentbox(), and cwidget::fragment::max_width().

Referenced by dropbox().

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().

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().

Referenced by flowbox().

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().

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.
const style & cwidget::get_style ( const std::string &  name)

Look up a style in the global registry.

Exceptions:
NoSuchStyleif the style does not exist.

References get_style().

Referenced by fragf(), get_style(), cwidget::widgets::multiplex::paint(), cwidget::widgets::tree::paint(), cwidget::widgets::menubar::paint(), cwidget::widgets::menu::paint(), and cwidget::toplevel::resume().

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().

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(), and indentbox().

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

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

References newline_fragment().

Referenced by fragf(), and newline_fragment().

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
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
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(), and set_style().

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

References cwidget::style::attrs_flip().

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

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 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 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 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().

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().

Referenced by style_fragment().

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
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
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
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
std::string cwidget::version ( )

Return the version number of the library.