cwidget  0.5.17
multiplex.h
1 // multiplex.h (This is -*-c++-*-)
2 // Copyright 1999-2006, 2009 Daniel Burrows
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program; see the file COPYING. If not, write to
16 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 // Boston, MA 02111-1307, USA.
18 
19 #ifndef VSMULTIPLEX_H
20 #define VSMULTIPLEX_H
21 
22 #include <cwidget/curses++.h>
23 #include "passthrough.h"
24 
25 #include <cwidget/generic/util/eassert.h>
26 
27 #include <list>
28 #include <string>
29 
30 namespace cwidget
31 {
32  namespace widgets
33  {
46  class multiplex : public passthrough
47  {
48  struct child_info
49  {
50  widget_ref w;
51  std::wstring title;
52 
53  child_info(const widget_ref &_w, const std::wstring &_title)
54  :w(_w), title(_title)
55  {
56  }
57  };
58 
59  std::list<child_info> children;
60 
61  std::list<child_info>::iterator visible_child;
62 
67  bool show_tabs;
68 
72  bool tabs_visible() const;
73 
74  void show_widget(const widget_ref &widget);
75  // Used to bring a widget to the front
76  void hide_widget(const widget_ref &widget);
77  // Used to hide a widget
78 
79  void show_widget_bare(widget &widget);
80  void hide_widget_bare(widget &widget);
81 
82  void got_focus();
83  void lost_focus();
84  protected:
85  bool winavail() {return get_win();}
86 
87  multiplex(bool _show_tabs);
88  public:
89  static util::ref_ptr<multiplex> create(bool show_tabs = false)
90  {
91  util::ref_ptr<multiplex> rval(new multiplex(show_tabs));
92  rval->decref();
93  return rval;
94  }
95 
96  virtual ~multiplex();
97 
99  int width_request();
100 
102  int height_request(int width);
103 
104  void destroy();
105 
106  void layout_me();
107 
108  virtual widget_ref get_focus();
109  widget_ref visible_widget();
110  unsigned int num_children();
111  // Returns the number of widgets in the multiplexer.
112  unsigned int num_visible();
113 
114  virtual void paint(const style &st);
115  void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
116 
117  void show_all();
118 
119  void set_show_tabs(bool shown);
120 
125  void add_widget(const widget_ref &widget);
126  void add_widget(const widget_ref &widget, const std::wstring &title);
127  void add_widget_bare(widget &widget, const std::wstring &title)
128  {
129  add_widget(widget_ref(&widget), title);
130  }
131 
132  void add_widget_after(const widget_ref &widget,
133  const widget_ref &after);
134 
135  void add_widget_after_bare(cwidget::widgets::widget &widget,
137  {
138  add_widget_after(widget_ref(&widget), widget_ref(&after));
139  }
140 
141 
142  void add_widget_after(const widget_ref &widget,
143  const widget_ref &after,
144  const std::wstring &title);
145 
146 
147  void add_widget_after_bare(cwidget::widgets::widget &widget,
149  const std::wstring &title)
150  {
151  add_widget_after(widget_ref(&widget), widget_ref(&after), title);
152  }
153 
154 
155  void rem_widget(const widget_ref &widget);
156 
157  // These cycle forward and backwards through the list of visible items.
158  void cycle_forward();
159  void cycle_backward();
160 
162  sigc::signal0<void> cycled;
163  };
164 
166  }
167 }
168 
169 #endif
void destroy()
Destroys the visible representation of this widget and disconnects it from any children that it may h...
Definition: multiplex.cc:50
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
virtual void paint(const style &st)
Display this widget.
Definition: multiplex.cc:132
int width_request()
Returns the maximum width requested by any child.
Definition: multiplex.cc:87
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
int height_request(int width)
Returns the maximum height requested by any child.
Definition: multiplex.cc:101
sigc::signal0< void > cycled
Emitted when the currently visible widget changes.
Definition: multiplex.h:162
The basic widget interface.
Definition: widget.h:107
Definition: passthrough.h:15
void add_widget(const widget_ref &widget)
Add a title-less widget.
Definition: multiplex.cc:435
This widget displays exactly one of its children at once.
Definition: multiplex.h:46
void show_all()
Display this widget and all its subwidgets.
Definition: multiplex.cc:266