00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: YWidget.h 00014 00015 Author: Mathias Kettner <kettner@suse.de> 00016 Maintainer: Stefan Hundhammer <sh@suse.de> 00017 00018 /-*/ 00019 00020 #ifndef YWidget_h 00021 #define YWidget_h 00022 00023 #include <string> 00024 #include <list> 00025 #include <ycp/YCPValue.h> 00026 #include "YWidgetOpt.h" 00027 #include "YUISymbols.h" 00028 00029 #define YWIDGET_MAGIC 42 // what else? ;- ) 00030 00031 class YCPSymbol; 00032 class YMacroRecorder; 00033 00034 #define YUIAllDimensions 2 00035 00036 enum YUIDimension { YD_HORIZ, YD_VERT }; 00037 00038 00039 class YWidget; 00040 typedef std::list<YWidget *> YWidgetList; 00041 typedef std::list<YWidget *>::iterator YWidgetListIterator; 00042 typedef std::list<YWidget *>::const_iterator YWidgetListConstIterator; 00043 00044 00048 class YWidget 00049 { 00050 public: 00054 YWidget( const YWidgetOpt & opt ); 00055 00059 virtual ~YWidget(); 00060 00065 virtual char * widgetClass() { return "YWidget"; } 00066 00078 virtual std::string debugLabel(); 00079 00085 bool isValid() const { return magic == YWIDGET_MAGIC; } 00086 00090 int internalId() const { return internal_widget_id; } 00091 00095 void setId( const YCPValue & id ); 00096 00100 bool hasId() const; 00101 00105 YCPValue id() const; 00106 00110 void setParent( YWidget *parent ); 00111 00115 YWidget * YWidget::yParent() const; 00116 00121 YWidget * yDialog(); 00122 00133 virtual void childDeleted( YWidget *child ) {} 00134 00139 virtual bool isDialog() const; 00140 00145 virtual bool isContainer() const; 00146 00151 virtual bool isReplacePoint() const; 00152 00157 virtual bool isRadioButtonGroup() const; 00158 00164 virtual bool isLayoutStretch( YUIDimension dim ) const; 00165 00173 virtual long nicesize( YUIDimension dim ) = 0; 00174 00185 virtual bool stretchable( YUIDimension dim ) const; 00186 00191 void setStretchable( YUIDimension dim, bool newStretch ); 00192 00197 void setDefaultStretchable( YUIDimension dim, bool newStretch ); 00198 00199 00209 virtual long weight( YUIDimension dim ); 00210 00214 virtual bool hasWeight( YUIDimension dim ); 00215 00226 virtual void setSize( long newwidth, long newheight ); 00227 00232 virtual void setEnabling( bool enabled ); 00233 00237 bool getEnabling() const; 00238 00242 void setNotify( bool notify ); 00243 00248 bool getNotify() const; 00249 00254 bool sendKeyEvents() const { return _sendKeyEvents; } 00255 00259 void setSendKeyEvents( bool doSend ) { _sendKeyEvents = doSend; } 00260 00265 bool autoShortcut() const { return _autoShortcut; } 00266 00270 void setAutoShortcut( bool _newAutoShortcut ) { _autoShortcut = _newAutoShortcut; } 00271 00277 virtual YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue ); 00278 00287 virtual YCPValue changeWidgetTerm( const YCPTerm & property, const YCPValue & newvalue ); 00288 00294 virtual YCPValue queryWidget( const YCPSymbol & property ); 00295 00302 virtual YCPValue queryWidgetTerm( const YCPTerm & property ); 00303 00307 void *widgetRep(); 00308 00312 void setWidgetRep( void * ); 00313 00323 virtual bool setKeyboardFocus(); 00324 00325 00334 virtual void saveUserInput( YMacroRecorder *macroRecorder ); 00335 00336 00341 virtual const char *shortcutProperty() { return ( const char * ) 0; } 00342 00343 00344 // NCurses optimizations 00345 00346 00353 virtual void startMultipleChanges() {} 00354 00361 virtual void doneMultipleChanges() {} 00362 00363 00364 private: 00365 00369 void invalidate() { magic=0; } 00370 00375 int magic; 00376 00377 protected: 00378 00384 YCPValue user_widget_id; 00385 00390 int internal_widget_id; 00391 00396 static int next_internal_widget_id; 00397 00401 YWidget *yparent; 00402 00406 bool enabled; 00407 00411 bool notify; 00412 00416 bool _sendKeyEvents; 00417 00422 bool _autoShortcut; 00423 00428 void * rep; 00429 00433 bool _stretch [ YUIAllDimensions ]; 00434 00438 long _weight [ YUIAllDimensions ]; 00439 00443 long windowID; 00444 00445 00446 public: 00452 class OptimizeChanges 00453 { 00454 public: 00455 OptimizeChanges( YWidget & w ) : yw(w) { yw.startMultipleChanges(); } 00456 ~OptimizeChanges() { yw.doneMultipleChanges(); } 00457 private: 00458 OptimizeChanges( const OptimizeChanges & ); // no copy 00459 void operator=( const OptimizeChanges & ); // no assign 00460 YWidget & yw; 00461 }; 00462 00463 }; 00464 00465 00466 #endif // YWidget_h