libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCWidget.h
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019    File:       NCWidget.h
00020 
00021    Author:     Michael Andres <ma@suse.de>
00022 
00023 /-*/
00024 
00025 #ifndef NCWidget_h
00026 #define NCWidget_h
00027 
00028 
00029 #include <iosfwd>
00030 
00031 #include "NCurses.h"
00032 #include "tnode.h"
00033 
00034 class NCursesWindow;
00035 class NClabel;
00036 
00037 
00038 #define DLOC location() << ' '
00039 
00040 #define YWIDGET_MAGIC   42
00041 
00042 
00043 class NCWidget : public tnode<NCWidget*>, protected NCursesError
00044 {
00045 private:
00046 
00047     friend std::ostream & operator<<( std::ostream & STREAM, const NCWidget & OBJ );
00048     friend std::ostream & operator<<( std::ostream & STREAM, const NCWidget * OBJ );
00049 
00050     NCWidget & operator=( const NCWidget & );
00051     NCWidget( const NCWidget & );
00052 
00053 
00054     /**
00055      * Make this widget invalid. This operation cannot be reversed.
00056      */
00057     void invalidate() { magic = 0; }
00058 
00059     /**
00060      * This object is only valid if this magic number is YWIDGET_MAGIC.
00061      */
00062     int magic;
00063 
00064 protected:
00065 
00066     virtual const char * location() const { return "NCWidget"; }
00067 
00068     virtual void PreDisconnect();
00069     virtual void PostDisconnect();
00070     virtual void PreReparent();
00071     virtual void PostReparent();
00072 
00073     NCursesWindow * ParentWin();
00074 
00075     NCWidget *const grabedBy;
00076     bool grabFocus();
00077     virtual void grabNotify( NCWidget * ) {}
00078 
00079     virtual bool wantFocus( NCWidget & ngrab ) { return false; }
00080 
00081 public:
00082 
00083     void grabSet( NCWidget * ngrab )
00084     {
00085         if ( grabedBy && grabedBy != ngrab )
00086             grabedBy->grabNotify( this );
00087 
00088         const_cast<NCWidget *&>( grabedBy ) = ngrab;
00089     }
00090 
00091     void grabRelease( NCWidget * ograb )
00092     {
00093         if ( grabedBy && grabedBy != ograb )
00094             grabedBy->grabNotify( this );
00095 
00096         const_cast<NCWidget *&>( grabedBy ) = 0;
00097     }
00098 
00099 protected:
00100 
00101     NCursesWindow * win;
00102     wsze            defsze;
00103     wrect           framedim;
00104     wrect           inparent;
00105     bool            noUpdates;
00106     bool            skipNoDimWin;
00107 
00108     void wMoveChildTo( NCWidget & child, const wpos & newpos );
00109     void wRelocate( const wrect & newrect );
00110     void wRelocate( const wpos & newpos, const wsze & newsze )
00111     {
00112         wRelocate( wrect( newpos, newsze ) );
00113     }
00114 
00115     virtual void wCreate( const wrect & newrect );
00116     virtual void wMoveTo( const wpos & newpos );
00117     virtual void wDelete();
00118     virtual void wUpdate( bool forced_br = false );
00119 
00120     wpos ScreenPos() const;
00121 
00122     NC::WState wstate;
00123 
00124     virtual void wRedraw();
00125     virtual void wRecoded();
00126 
00127     NClabel * hotlabel;
00128 
00129 public:
00130 
00131     NCWidget( NCWidget * myparent );
00132     NCWidget( YWidget * parent = 0 );
00133     virtual ~NCWidget();
00134 
00135     bool isValid() const        { return magic == YWIDGET_MAGIC; }
00136 
00137     bool winExist() const       { return win != ( NCursesWindow * )0; }
00138 
00139     virtual const NCstyle::Style & wStyle() const
00140     {
00141         if ( Parent() )
00142             return Top().Value()->wStyle();
00143 
00144         return NCurses::style()[NCstyle::DefaultStyle];
00145     }
00146 
00147     const NCstyle::StWidget & widgetStyle( bool nonactive = false ) const
00148         { return wStyle().getWidget( GetState(), nonactive ); }
00149 
00150     const NCstyle::StWidget & frameStyle()  const
00151         { return wStyle().getFrame( GetState() ); }
00152 
00153     const NCstyle::StList   & listStyle()   const
00154         { return wStyle().getList( GetState() ); }
00155 
00156     wsze wGetDefsze() const { return defsze; }
00157 
00158     wrect wGetSize() const { return inparent; }
00159 
00160     void Update();
00161     void Redraw( const bool sub = false );
00162     void Recoded();
00163 
00164     NC::WState GetState() const { return wstate; }
00165 
00166     void SetState( const NC::WState newstate, const bool force = false );
00167 
00168     /**
00169      * Pure virtual to make sure every widget implements it. Necessary to make
00170      * sure that UI requests via YWidget::setEnabled perform, and behave the
00171      * same way as direct calls to NCWidget::setEnabled.
00172      **/
00173     virtual void setEnabled( bool do_bv ) = 0;
00174 
00175     virtual bool HasHotkey( int key );
00176     virtual bool HasFunctionHotkey( int key ) const;
00177 
00178     virtual NCursesEvent wHandleHotkey( wint_t key );
00179     virtual NCursesEvent wHandleInput( wint_t key );
00180 
00181     void DumpOn( std::ostream & str, std::string prfx ) const;
00182 };
00183 
00184 
00185 #include "NCstring.h"
00186 #include "NCtext.h"
00187 
00188 
00189 #endif // NCWidget_h
 All Classes Functions Variables