cwidget  0.5.17
toplevel.h
Go to the documentation of this file.
1 // toplevel.h -*-c++-*-
2 //
3 // Copyright 2000, 2005, 2007-2008 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (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
13 // GNU 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 
30 #ifndef TOPLEVEL_H
31 #define TOPLEVEL_H
32 
33 #include <sigc++/signal.h>
34 
35 #include <cwidget/generic/util/ref_ptr.h>
36 
38 namespace cwidget
39 {
41  std::string version();
42 
43  namespace threads
44  {
45  class mutex;
46  }
47 
48  namespace widgets
49  {
50  class widget;
51  }
52 
61  namespace toplevel
62  {
66  class event
67  {
68  public:
69  virtual void dispatch() = 0;
70  virtual ~event();
71  };
72 
82  class slot_event : public event
83  {
84  sigc::slot0<void> the_slot;
85  public:
86  slot_event(const sigc::slot0<void> &_the_slot)
87  : the_slot(_the_slot)
88  {
89  }
90 
91  void dispatch();
92  };
93 
97  void init();
98 
109  void install_sighandlers();
110 
117 
121  void queuelayout();
122 
124  void layoutnow();
125 
126  // Main loop handlers:
127 
150  void mainloop(int synch=0);
151 
159  void post_event(event *ev);
160 
167  bool poll();
168 
169  void exitmain();
170  // Exits the main loop.
171 
172  void redraw();
173  // Redraws the screen completely from scratch
174 
176  void update();
177 
179  void tryupdate();
180 
184  void updatecursor();
185 
191  void suspend();
192 
198 
203  void shutdown();
204 
208  void resume();
209 
216  int addtimeout(event *ev, int msecs);
217 
219  void deltimeout(int id);
220 
221  void handleresize();
222  // Does anything needed to handle a window resize event.
223  // FIXME: I --think-- that this is now redundant
224 
225  // Return a mutex that is held whenever the main loop is processing
226  // events or drawing the screen. The mutex can be held by other
227  // threads that want to do their own drawing or processing, although
228  // this is highly discouraged (use the event posting system instead
229  // to run code in the main loop).
230  threads::mutex &get_mutex();
231 
242  int get_suspend_count();
243 
244  extern sigc::signal0<void> main_hook;
245  // Called right after we finish handling input in the mainloop. Can
246  // be used (eg) to insert extra actions to be performed after all
247  // user-input (aptitude uses this to check for apt errors and pop up a
248  // message about them)
249  }
250 }
251 
252 #endif
cwidget::get_style
const style & get_style(const std::string &name)
Look up a style in the global registry.
Definition: style.cc:31
cwidget::toplevel::addtimeout
int addtimeout(event *ev, int msecs)
Invoke the given event in at least msecs from the current time.
Definition: toplevel.cc:1300
cwidget::util::ref_ptr
Definition: ref_ptr.h:20
cwidget::toplevel::deltimeout
void deltimeout(int num)
Delete the event with the given identifier.
Definition: toplevel.cc:1308
cwidget::config::key
Represents a keystroke as seen by curses.
Definition: keybindings.h:43
cwidget::set_style
void set_style(const std::string &name, const style &style)
Place a style in the global registry.
Definition: style.cc:42
cwidget::fillbox
fragment * fillbox(fragment *contents)
Create a fillbox.
Definition: fragment.cc:775
cwidget::toplevel::init
void init()
Initializes curses and the global state of the cwidget library.
Definition: toplevel.cc:854
dialogs.h
Utility functions to construct prefabricated widgets.
cwidget::widgets::menu_info
Definition: menu.h:85
cwidget::toplevel::layoutnow
void layoutnow()
Immediately recalculates the layout of all widgets.
Definition: toplevel.cc:1104
cwidget::fragment_column_entry
Stores information on a single column of fragments.
Definition: fragment.h:281
cwidget::style_attrs_off
style style_attrs_off(attr_t attrs)
Definition: style.h:227
cwidget::widgets::table::set_colsep
void set_colsep(int n)
Set the separation between adjacent rows to the given number of characters.
Definition: table.cc:96
cwidget::widgets::table::show_all
void show_all()
Display this widget and all its subwidgets.
Definition: table.cc:387
cwidget::widgets::editline
Definition: editline.h:39
cwidget::config::global_bindings
keybindings global_bindings
The global keybindings object.
Definition: keybindings.cc:43
cwidget::widgets::point
Definition: widget.h:90
cwidget::toplevel::shutdown
void shutdown()
Does the same thing as suspend, except that it also destroys the top-level widget.
Definition: toplevel.cc:1231
cwidget::threads::mutex::lock::release
void release()
Unlock the associated mutex.
Definition: threads.h:375
cwidget::toplevel::tryupdate
void tryupdate()
Executes any pending draws or redraws.
Definition: toplevel.cc:1111
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::util::arg
slotarg< T > arg(const T &slot)
Convenience routine to construct a slotarg.
Definition: slotarg.h:98
cwidget::threads::mutex::lock
Represents a lock on a mutex.
Definition: threads.h:348
toplevel.h
Routines to manage the global cwidget state.
keybindings.h
Support for defining and remapping keybindings.
cwidget::util::ref_ptr::unsafe_get_ref
T * unsafe_get_ref() const
Extract the pointer.
Definition: ref_ptr.h:159
cwidget::threads::recursive_mutex
A mutex that is initialized to be recursive.
Definition: threads.h:457
cwidget::widgets::widget::destroy
virtual void destroy()
Destroys the visible representation of this widget and disconnects it from any children that it may h...
Definition: widget.cc:129
cwidget::toplevel::suspend_without_signals
void suspend_without_signals()
Hides all widgets and suspends Curses operation until resume() is called, but does NOT reset the SIGC...
Definition: toplevel.cc:1193
cwidget::clipbox
fragment * clipbox(fragment *contents)
Create a clipbox.
Definition: fragment.cc:916
cwidget::config::keybinding
std::vector< key > keybinding
The type used to store the keybindings of a function.
Definition: keybindings.h:74
cwidget::util::Exception
Definition: exception.h:38
cwidget::widgets::label
label widgets display some (possibly formatted) text statically.
Definition: label.h:25
cwidget::toplevel::mainloop
void mainloop(int synch)
Start the main event loop.
Definition: toplevel.cc:1155
cwidget::widgets::pager
A widget that displays text.
Definition: pager.h:29
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::widgets::tree
Definition: tree.h:58
cwidget::toplevel::get_suspend_count
int get_suspend_count()
Definition: toplevel.cc:86
cwidget::style_fg
style style_fg(short fg)
Definition: style.h:200
cwidget::toplevel::queuelayout
void queuelayout()
Posts a request to recalculate every widget's layout and update the screen.
Definition: toplevel.cc:1093
cwidget::style_attrs_on
style style_attrs_on(attr_t attrs)
Definition: style.h:219
cwidget::toplevel::suspend
void suspend()
Hides all widgets and suspends Curses operation until resume() is called.
Definition: toplevel.cc:1213
cwidget::widgets::table
Definition: table.h:19
cwidget::widgets::size
Definition: widget.h:84
cwidget::flowbox
fragment * flowbox(fragment *contents)
Create a flowbox.
Definition: fragment.cc:600
cwidget::widgets::menubar
Definition: menubar.h:42
cwidget::widgets::menu_item
Definition: menu.h:42
cwidget::toplevel::poll
bool poll()
Dispatch any events in the event queue.
Definition: toplevel.cc:1135
cwidget::threads::mutex
Definition: threads.h:287
cwidget::toplevel::install_sighandlers
void install_sighandlers()
Installs signal handlers to cleanly shut down cwidget.
Definition: toplevel.cc:1022
cwidget::toplevel::post_event
void post_event(event *ev)
Post the given event to the main event queue.
Definition: toplevel.cc:229
cwidget::fragf
fragment * fragf(const char *format,...)
A printf-alike for fragments.
Definition: fragment.cc:1358
cwidget::hardwrapbox
fragment * hardwrapbox(fragment *contents)
Create a hardwrapbox.
Definition: fragment.cc:853
cwidget::widgets::file_pager
Load a file from disk; it's assumed to be ASCII for now.
Definition: pager.h:211
cwidget::widgets::treeitem
Definition: treeitem.h:105
cwidget::style_fragment
fragment * style_fragment(fragment *f, const style &st)
Create a fragment which alters the style of its contents.
Definition: fragment.cc:204
cwidget::toplevel::update
void update()
Posts a request to redraw the screen; may be called from any thread.
Definition: toplevel.cc:1072
cwidget::util::sstrerror
string sstrerror(int errnum)
Like strerror_r, but handles all memory allocation and returns a C++ string.
Definition: ssprintf.cc:131
cwidget::widgets::layout_item
Definition: layout_item.h:35
colors.h
Routines to support independently changing foreground and background colors.
cwidget::indentbox
fragment * indentbox(size_t firstindent, size_t restindent, fragment *contents)
Create an indentbox.
Definition: fragment.cc:982
cwidget::toplevel::resume
void resume()
Returns to Curses mode after a suspend*, restoring any signal handlers that were modified by the susp...
Definition: toplevel.cc:1247
cwidget::toplevel::settoplevel
util::ref_ptr< widgets::widget > settoplevel(const util::ref_ptr< widgets::widget > &widget)
Sets the top-level widget to the new value, returning the old top-level widget.
cwidget
The namespace containing everything defined by cwidget.
Definition: columnify.cc:27
cwidget::widgets::menu
Definition: menu.h:121
KEY_CTRL
#define KEY_CTRL(x)
Attempt to compute the control character related to a terminal key.
Definition: keybindings.h:215
cwidget::newline_fragment
fragment * newline_fragment()
Create a fragment which simply produces a newline wherever it occurs.
Definition: fragment.cc:165
cwidget::toplevel::slot_event
An event based on sigc++ slots.
Definition: toplevel.h:83
cwidget::toplevel::updatecursor
void updatecursor()
Posts a request to update the cursor location; may be called from any thread.
Definition: toplevel.cc:1050
cwidget::widgets::subtree_generic
Definition: subtree.h:254
cwidget::widgets::widget
The basic widget interface.
Definition: widget.h:108
cwidget::style_bg
style style_bg(short bg)
Definition: style.h:210
cwidget::widgets::radiogroup
Definition: radiogroup.h:40
cwidget::widgets::pager::do_line_signal
void do_line_signal()
Emits a signal describing the verical location of the display within the text.
Definition: pager.cc:142
cwidget::widgets::pager::line_changed
sigc::signal2< void, int, int > line_changed
Announces that the user has scrolled vertically.
Definition: pager.h:200
cwidget::toplevel::event
An event in the global event queue.
Definition: toplevel.h:67
cwidget::threads::mutex::lock::acquire
void acquire()
Lock the associated mutex.
Definition: threads.h:365
cwidget::version
std::string version()
Return the version number of the library.
Definition: toplevel.cc:64
cwidget::config::keybindings::set
void set(std::string tag, keybinding strokes)
Modify a binding in this scope.
cwidget::widgets::widget::display
void display(const style &st)
Display this widget in the given style environment.
Definition: widget.cc:198