Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

ncursesp.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       ncursesp.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 // * This makes emacs happy -*-Mode: C++;-*-
00020 #ifndef _CURSESP_H
00021 #define _CURSESP_H
00022 
00023 #include <iosfwd>
00024 
00025 // $Id: ncursesp.h 9894 2003-05-27 16:16:13Z ma $
00026 
00027 #include "ncursesw.h"
00028 
00029 extern "C" {
00030 #  include <panel.h>
00031 }
00032 
00036 class NCursesPanel : public NCursesWindow {
00037   friend std::ostream & operator<<( std::ostream & Stream, const NCursesPanel & Obj_Cv );
00038   friend std::ostream & operator<<( std::ostream & Stream, const NCursesPanel * Obj_Cv );
00039   friend class NCDialog;
00040 
00041 protected:
00042 
00043   PANEL *p;
00044   static NCursesPanel *dummy;
00045 
00046 private:
00051   typedef struct {
00055     void*               m_user;
00059     const NCursesPanel* m_back;
00063     const PANEL*        m_owner;
00064   } UserHook;
00065 
00069   void init();
00070 
00071 protected:
00075   void set_user(void *user) {
00076     UserHook* uptr = (UserHook*)::panel_userptr (p);
00077     assert (uptr && uptr->m_back==this && uptr->m_owner==p);
00078     uptr->m_user = user;
00079   }
00080 
00081   void *get_user() const {
00082     UserHook* uptr = (UserHook*)::panel_userptr (p);
00083     assert (uptr && uptr->m_back==this && uptr->m_owner==p);
00084     return uptr->m_user;
00085   }
00086 
00087   static const NCursesPanel * get_Panel_of( const PANEL & pan ) {
00088     UserHook* uptr = (UserHook*)::panel_userptr (&pan);
00089     if ( uptr && uptr->m_owner == &pan
00090          && uptr->m_back && uptr->m_back->p == &pan ) {
00091       return uptr->m_back;
00092     }
00093     return 0;
00094   }
00095 
00100   void OnError (int err) const THROWS((NCursesPanelException)) {
00101     if (err==ERR)
00102       THROW(new NCursesPanelException (this, err));
00103   }
00104 
00105 public:
00109   NCursesPanel(int lines,
00110                int cols,
00111                int begin_y = 0,
00112                int begin_x = 0)
00113     : NCursesWindow(lines,cols,begin_y,begin_x) {
00114       init();
00115   }
00116 
00121   NCursesPanel() : NCursesWindow(::stdscr) { init(); }
00122 
00123   virtual ~NCursesPanel();
00124 
00125   // basic manipulation
00126 
00130   virtual int resize(int lines, int columns) {
00131     ::wresize( w, lines, columns );
00132     return ::replace_panel( p, w );
00133   }
00134 
00138   inline void hide() {
00139     // [ma] hiding a hiden one should not abort.
00140     if ( !hidden() ) {
00141       OnError (::hide_panel(p));
00142     }
00143   }
00144 
00148   inline void show() {
00149     OnError (::show_panel(p));
00150   }
00151 
00155   inline void top() {
00156     OnError (::top_panel(p));
00157   }
00158 
00164   inline void bottom() {
00165     // warning FIX for broken bottom_panel (libpanel)
00166     // [ma] panel stack is messed up if the last panel is
00167     // moved to the bottom.
00168     if ( ::panel_above(0) != p ) {
00169       OnError (::bottom_panel(p));
00170     }
00171   }
00172 
00173   inline int mvwin(int y, int x) {
00174     OnError(::move_panel(p, y, x));
00175     return OK;
00176   }
00177 
00181   inline bool hidden() const {
00182     return (::panel_hidden(p));
00183   }
00184 
00194   inline NCursesPanel& above() const {
00195     OnError(ERR);
00196     return *dummy;
00197   }
00198 
00199   inline NCursesPanel& below() const {
00200     OnError(ERR);
00201     return *dummy;
00202   }
00203 
00204   inline PANEL * PANEL_above() const {
00205     return( p ? ::panel_above( p ) : 0 );
00206   }
00207 
00208   inline PANEL * PANEL_below() const {
00209     return( p ? ::panel_below( p ) : 0 );
00210   }
00211 
00212   int transparent( int y, int x );
00213 
00214   // Those two are rewrites of the corresponding virtual members of
00215   // NCursesWindow
00220   int refresh();
00221 
00225   int noutrefresh();
00226 
00230   static void redraw();
00231 
00232   // decorations
00237   virtual void frame(const char* title=NULL,
00238                      const char* btitle=NULL);
00239 
00243   virtual void boldframe(const char* title=NULL,
00244                          const char* btitle=NULL);
00245 
00249   virtual void label(const char* topLabel,
00250                      const char* bottomLabel);
00251 
00255   virtual void centertext(int row,const char* label);
00256 };
00257 
00264 template<class T> class NCursesUserPanel : public NCursesPanel
00265 {
00266 public:
00271   NCursesUserPanel (int lines,
00272                     int cols,
00273                     int begin_y = 0,
00274                     int begin_x = 0,
00275                     const T* p_UserData = (T*)0)
00276     : NCursesPanel (lines, cols, begin_y, begin_x) {
00277       if (p)
00278         set_user ((void *)p_UserData);
00279   };
00280 
00285   NCursesUserPanel(const T* p_UserData = (T*)0) : NCursesPanel() {
00286     if (p)
00287       set_user((void *)p_UserData);
00288   };
00289 
00290   virtual ~NCursesUserPanel() {};
00291 
00295   T* UserData (void) const {
00296     return (T*)get_user();
00297   };
00298 
00302   virtual void setUserData (const T* p_UserData) {
00303     if (p)
00304       set_user ((void *)p_UserData);
00305   }
00306 
00310   static T* UserDataOf( const PANEL & pan ) {
00311     const NCursesUserPanel<T> * p = dynamic_cast<const NCursesUserPanel<T>*>( get_Panel_of( pan ) );
00312     if ( p ) {
00313       return p->UserData();
00314     }
00315     return (T*)0;
00316   };
00317 
00318 
00319 };
00320 
00321 #endif // _CURSESP_H

Generated on Wed Sep 14 10:52:54 2005 for yast2-ncurses by  doxygen 1.4.4