cwidget  0.5.16
multiplex.h
00001 // multiplex.h                       (This is -*-c++-*-)
00002 // Copyright 1999-2006, 2009 Daniel Burrows
00003 //
00004 //  This program is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; see the file COPYING.  If not, write to
00016 //  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017 //  Boston, MA 02111-1307, USA.
00018 
00019 #ifndef VSMULTIPLEX_H
00020 #define VSMULTIPLEX_H
00021 
00022 #include <cwidget/curses++.h>
00023 #include "passthrough.h"
00024 
00025 #include <cwidget/generic/util/eassert.h>
00026 
00027 #include <list>
00028 #include <string>
00029 
00030 namespace cwidget
00031 {
00032   namespace widgets
00033   {
00046     class multiplex : public passthrough
00047     {
00048       struct child_info
00049       {
00050         widget_ref w;
00051         std::wstring title;
00052 
00053         child_info(const widget_ref &_w, const std::wstring &_title)
00054           :w(_w), title(_title)
00055         {
00056         }
00057       };
00058 
00059       std::list<child_info> children;
00060 
00061       std::list<child_info>::iterator visible_child;
00062 
00067       bool show_tabs;
00068 
00072       bool tabs_visible() const;
00073 
00074       void show_widget(const widget_ref &widget);
00075       // Used to bring a widget to the front
00076       void hide_widget(const widget_ref &widget);
00077       // Used to hide a widget
00078 
00079       void show_widget_bare(widget &widget);
00080       void hide_widget_bare(widget &widget);
00081 
00082       void got_focus();
00083       void lost_focus();
00084     protected:
00085       bool winavail() {return get_win();}
00086 
00087       multiplex(bool _show_tabs);
00088     public:
00089       static util::ref_ptr<multiplex> create(bool show_tabs = false)
00090       {
00091         util::ref_ptr<multiplex> rval(new multiplex(show_tabs));
00092         rval->decref();
00093         return rval;
00094       }
00095 
00096       virtual ~multiplex();
00097 
00099       int width_request();
00100 
00102       int height_request(int width);
00103 
00104       void destroy();
00105 
00106       void layout_me();
00107 
00108       virtual widget_ref get_focus();
00109       widget_ref visible_widget();
00110       unsigned int num_children();
00111       // Returns the number of widgets in the multiplexer.
00112       unsigned int num_visible();
00113 
00114       virtual void paint(const style &st);
00115       void dispatch_mouse(short id, int x, int y, int z, mmask_t bstate);
00116 
00117       void show_all();
00118 
00119       void set_show_tabs(bool shown);
00120 
00125       void add_widget(const widget_ref &widget);
00126       void add_widget(const widget_ref &widget, const std::wstring &title);
00127       void add_widget_bare(widget &widget, const std::wstring &title)
00128       {
00129         add_widget(widget_ref(&widget), title);
00130       }
00131 
00132       void add_widget_after(const widget_ref &widget,
00133                             const widget_ref &after);
00134 
00135       void add_widget_after_bare(cwidget::widgets::widget &widget,
00136                                  cwidget::widgets::widget &after)
00137       {
00138         add_widget_after(widget_ref(&widget), widget_ref(&after));
00139       }
00140 
00141 
00142       void add_widget_after(const widget_ref &widget,
00143                             const widget_ref &after,
00144                             const std::wstring &title);
00145 
00146 
00147       void add_widget_after_bare(cwidget::widgets::widget &widget,
00148                                  cwidget::widgets::widget &after,
00149                                  const std::wstring &title)
00150       {
00151         add_widget_after(widget_ref(&widget), widget_ref(&after), title);
00152       }
00153 
00154 
00155       void rem_widget(const widget_ref &widget);
00156 
00157       // These cycle forward and backwards through the list of visible items.
00158       void cycle_forward();
00159       void cycle_backward();
00160 
00162       sigc::signal0<void> cycled;
00163     };
00164 
00165     typedef util::ref_ptr<multiplex> multiplex_ref;
00166   }
00167 }
00168 
00169 #endif