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 * 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 00349 virtual const char *userInputProperty() { return (const char *) 0; } 00350 00351 00352 // NCurses optimizations 00353 00354 00361 virtual void startMultipleChanges() {} 00362 00369 virtual void doneMultipleChanges() {} 00370 00371 00372 private: 00373 00377 void invalidate() { magic=0; } 00378 00383 int magic; 00384 00385 protected: 00386 00392 YCPValue user_widget_id; 00393 00398 int internal_widget_id; 00399 00404 static int next_internal_widget_id; 00405 00409 YWidget *yparent; 00410 00414 bool enabled; 00415 00419 bool notify; 00420 00424 bool _sendKeyEvents; 00425 00430 bool _autoShortcut; 00431 00436 void * rep; 00437 00441 bool _stretch [ YUIAllDimensions ]; 00442 00446 long _weight [ YUIAllDimensions ]; 00447 00451 long windowID; 00452 00453 00454 public: 00460 class OptimizeChanges 00461 { 00462 public: 00463 OptimizeChanges( YWidget & w ) : yw(w) { yw.startMultipleChanges(); } 00464 ~OptimizeChanges() { yw.doneMultipleChanges(); } 00465 private: 00466 OptimizeChanges( const OptimizeChanges & ); // no copy 00467 void operator=( const OptimizeChanges & ); // no assign 00468 YWidget & yw; 00469 }; 00470 00471 }; 00472 00473 00474 #endif // YWidget_h