00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: NCWidget.h 00014 00015 Author: Michael Andres <ma@suse.de> 00016 Maintainer: Michael Andres <ma@suse.de> 00017 00018 /-*/ 00019 #ifndef NCWidget_h 00020 #define NCWidget_h 00021 00022 #include <iosfwd> 00023 00024 #include "NCurses.h" 00025 #include "tnode.h" 00026 #include "YWidgetOpt.h" 00027 00028 class NCWidget; 00029 class NCursesWindow; 00030 class NClabel; 00031 00032 #define DLOC location() << ' ' 00033 00034 #define YWIDGET_MAGIC 42 00035 00037 // 00038 // CLASS NAME : NCWidget 00039 // 00040 // DESCRIPTION : 00041 // 00042 class NCWidget : public tnode<NCWidget*>, protected NCursesError { 00043 00044 friend std::ostream & operator<<( std::ostream & STREAM, const NCWidget & OBJ ); 00045 friend std::ostream & operator<<( std::ostream & STREAM, const NCWidget * OBJ ); 00046 00047 NCWidget & operator=( const NCWidget & ); 00048 NCWidget ( const NCWidget & ); 00049 00050 private: 00051 00055 void invalidate() { magic=0; } 00056 00060 int magic; 00061 00062 protected: 00063 00064 virtual const char * location() const { return "NCWidget"; } 00065 00066 protected: 00067 00068 virtual void PreDisconnect(); 00069 virtual void PostDisconnect(); 00070 virtual void PreReparent(); 00071 virtual void PostReparent(); 00072 00073 NCursesWindow * ParentWin(); 00074 00075 protected: 00076 00077 NCWidget *const grabedBy; 00078 bool grabFocus(); 00079 virtual void grabNotify( NCWidget * ) {} 00080 virtual bool wantFocus( NCWidget & ngrab ) { return false; } 00081 00082 public: 00083 void grabSet( NCWidget * ngrab ) { 00084 if ( grabedBy && grabedBy != ngrab ) 00085 grabedBy->grabNotify( this ); 00086 const_cast<NCWidget *&>( grabedBy ) = ngrab; 00087 } 00088 void grabRelease( NCWidget * ograb ) { 00089 if ( grabedBy && grabedBy != ograb ) 00090 grabedBy->grabNotify( this ); 00091 const_cast<NCWidget *&>( grabedBy ) = 0; 00092 } 00093 00094 protected: 00095 00096 NCursesWindow * win; 00097 wsze defsze; 00098 wrect framedim; 00099 wrect inparent; 00100 bool noUpdates; 00101 bool skipNoDimWin; 00102 00103 void wMoveChildTo( NCWidget & child, const wpos & newpos ); 00104 void wRelocate( const wrect & newrect ); 00105 void wRelocate( const wpos & newpos, const wsze & newsze ) { 00106 wRelocate( wrect( newpos, newsze ) ); 00107 } 00108 00109 virtual void wCreate( const wrect & newrect ); 00110 virtual void wMoveTo( const wpos & newpos ); 00111 virtual void wDelete(); 00112 virtual void wUpdate( bool forced_br = false ); 00113 00114 wpos ScreenPos() const; 00115 00116 protected: 00117 00118 NC::WState wstate; 00119 00120 virtual void wRedraw(); 00121 virtual void wRecoded(); 00122 00123 protected: 00124 00125 NClabel * hotlabel; 00126 int hotfkey; 00127 00128 virtual void setFunctionHotkey( const YWidgetOpt & opt ); 00129 00130 public: 00131 00132 NCWidget( NCWidget * myparent = 0 ); 00133 virtual ~NCWidget(); 00134 00135 bool isValid() const { return magic == YWIDGET_MAGIC; } 00136 bool winExist() const { return win != (NCursesWindow *)0; } 00137 00138 virtual const NCstyle::Style & wStyle() const { 00139 if ( Parent() ) 00140 return Top().Value()->wStyle(); 00141 return NCurses::style()[NCstyle::DefaultStyle]; 00142 } 00143 const NCstyle::StWidget & widgetStyle( bool nonactive = false ) const { return wStyle().getWidget( GetState(), nonactive ); } 00144 const NCstyle::StWidget & frameStyle() const { return wStyle().getFrame( GetState() ); } 00145 const NCstyle::StList & listStyle() const { return wStyle().getList( GetState() ); } 00146 00147 wsze wGetDefsze() const { return defsze; } 00148 00149 void Update(); 00150 void Redraw( const bool sub = false ); 00151 void Recoded(); 00152 00153 NC::WState GetState() const { return wstate; } 00154 void SetState( const NC::WState newstate, const bool force = false ); 00155 00164 virtual void setEnabling( bool do_bv ) = 0; 00165 00166 virtual bool HasHotkey( int key ) const; 00167 virtual bool HasFunctionHotkey( int key ) const; 00168 virtual int GetFunctionHotkey() const; 00169 00170 virtual NCursesEvent wHandleHotkey( wint_t key ); 00171 virtual NCursesEvent wHandleInput( wint_t key ); 00172 00173 void DumpOn( std::ostream & str, string prfx ) const; 00174 }; 00175 00177 00178 #include "NCstring.h" 00179 #include "NCtext.h" 00180 00182 00183 #endif // NCWidget_h