libyui
|
00001 /************************************************************************** 00002 Copyright (C) 2000 - 2010 Novell, Inc. 00003 All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 **************************************************************************/ 00020 00021 00022 /*---------------------------------------------------------------------\ 00023 | | 00024 | __ __ ____ _____ ____ | 00025 | \ \ / /_ _/ ___|_ _|___ \ | 00026 | \ V / _` \___ \ | | __) | | 00027 | | | (_| |___) || | / __/ | 00028 | |_|\__,_|____/ |_| |_____| | 00029 | | 00030 | core system | 00031 | (C) SuSE GmbH | 00032 \----------------------------------------------------------------------/ 00033 00034 File: YWidget.h 00035 00036 Author: Stefan Hundhammer <sh@suse.de> 00037 00038 /-*/ 00039 00040 #ifndef YWidget_h 00041 #define YWidget_h 00042 00043 #include <string> 00044 #include <iosfwd> 00045 00046 #include "YTypes.h" 00047 #include "YProperty.h" 00048 #include "YUISymbols.h" 00049 #include "YUIException.h" 00050 #include "YChildrenManager.h" 00051 #include "ImplPtr.h" 00052 00053 00054 class YDialog; 00055 class YWidgetID; 00056 class YMacroRecorder; 00057 00058 using std::string; 00059 00060 typedef YChildrenManager<YWidget> YWidgetChildrenManager; 00061 typedef YSingleChildManager<YWidget> YSingleWidgetChildManager; 00062 typedef YChildrenRejector<YWidget> YWidgetChildrenRejector; 00063 00064 class YWidgetPrivate; 00065 00066 00070 class YWidget 00071 { 00072 protected: 00076 YWidget( YWidget * parent ); 00077 00078 public: 00082 virtual ~YWidget(); 00083 00088 virtual const char * widgetClass() const { return "YWidget"; } 00089 00101 virtual string debugLabel() const; 00102 00106 string helpText() const; 00107 00115 void setHelpText( const string & helpText ); 00116 00117 00118 // 00119 // Property Management 00120 // 00121 00154 virtual const YPropertySet & propertySet(); 00155 00168 virtual bool setProperty( const string & propertyName, 00169 const YPropertyValue & val ); 00170 00177 virtual YPropertyValue getProperty( const string & propertyName ); 00178 00179 00180 // 00181 // Children Management 00182 // 00183 // Even though many widget classes are leaf classes and thus cannot have 00184 // children by design, it makes sense to have the children management in 00185 // this base class: Then descending down a widget tree is transparent to 00186 // the outside without the need to check for container widget classes, 00187 // casting to those container widget classes and only calling child 00188 // management methods in that case. 00189 // 00190 // By default, YWidget and derived classes have a YWidgetChildrenRejector 00191 // as their children manager, i.e. any attempt to add a child will result 00192 // in a YUITooManyChildrenException. 00193 // 00194 // Derived classes that can (semantically) handle children should set the 00195 // children manager to one of 00196 // 00197 // - YWidgetChildrenManager: handles any number of child widgets; 00198 // useful for VBox / HBox 00199 // 00200 // - YSingleWidgetChildManager: handles exactly one child 00201 // useful for widgets like Alignment, Frame, Dialog 00202 // 00203 00204 00208 bool hasChildren() const 00209 { return childrenManager()->hasChildren(); } 00210 00215 YWidget * firstChild() const 00216 { return childrenManager()->firstChild(); } 00217 00221 YWidget * lastChild() const 00222 { return childrenManager()->lastChild(); } 00223 00228 YWidgetListConstIterator childrenBegin() const 00229 { return childrenManager()->begin(); } 00230 00234 YWidgetListConstIterator childrenEnd() const 00235 { return childrenManager()->end(); } 00236 00240 int childrenCount() const { return childrenManager()->count(); } 00241 00245 bool contains( YWidget * child ) const 00246 { return childrenManager()->contains( child ); } 00247 00254 virtual void addChild( YWidget * child ); 00255 00260 virtual void removeChild( YWidget * child ); 00261 00265 void deleteChildren(); 00266 00270 YWidget * parent() const; 00271 00275 bool hasParent() const; 00276 00280 void setParent( YWidget * newParent ); 00281 00286 YDialog * findDialog(); 00287 00294 YWidget * findWidget( YWidgetID * id, bool doThrow = true ) const; 00295 00296 00297 // 00298 // Geometry Management 00299 // 00300 00306 virtual int preferredWidth() = 0; 00307 00313 virtual int preferredHeight() = 0; 00314 00325 virtual int preferredSize( YUIDimension dim ); 00326 00342 virtual void setSize( int newWidth, int newHeight ) = 0; 00343 00344 00345 // 00346 // Misc 00347 // 00348 00349 00357 bool isValid() const; 00358 00362 bool beingDestroyed() const; 00363 00368 void * widgetRep() const; 00369 00379 void setWidgetRep( void * toolkitWidgetRep ); 00380 00384 bool hasId() const; 00385 00389 YWidgetID * id() const; 00390 00402 void setId( YWidgetID * newId_disown ); 00403 00410 virtual void setEnabled( bool enabled = true ); 00411 00415 void setDisabled() { setEnabled( false); } 00416 00420 virtual bool isEnabled() const; 00421 00430 virtual bool stretchable( YUIDimension dim ) const; 00431 00436 void setStretchable( YUIDimension dim, bool newStretch ); 00437 00442 void setDefaultStretchable( YUIDimension dim, bool newStretch ); 00443 00454 virtual int weight( YUIDimension dim ); 00455 00460 bool hasWeight( YUIDimension dim ); 00461 00465 void setWeight( YUIDimension dim, int weight ); 00466 00470 void setNotify( bool notify = true ); 00471 00476 bool notify() const; 00477 00481 void setNotifyContextMenu( bool notifyContextMenu = true ); 00482 00487 bool notifyContextMenu() const; 00488 00489 00494 bool sendKeyEvents() const; 00495 00499 void setSendKeyEvents( bool doSend ); 00500 00505 bool autoShortcut() const; 00506 00510 void setAutoShortcut( bool _newAutoShortcut ); 00511 00516 int functionKey() const; 00517 00521 bool hasFunctionKey() const; 00522 00530 virtual void setFunctionKey( int fkey_no ); 00531 00541 virtual bool setKeyboardFocus(); 00542 00549 virtual string shortcutString() const { return string( "" ); } 00550 00557 virtual void setShortcutString( const string & str ); 00558 00565 virtual const char * userInputProperty() { return (const char *) 0; } 00566 00571 void dumpWidgetTree( int indentationLevel = 0 ); 00572 00579 void dumpDialogWidgetTree(); 00580 00584 void setChildrenEnabled( bool enabled ); 00585 00586 // 00587 // Macro Recorder Support 00588 // 00589 00608 virtual void saveUserInput( YMacroRecorder *macroRecorder ); 00609 00617 void * operator new( size_t size ); 00618 00619 00620 // NCurses optimizations 00621 00622 00629 virtual void startMultipleChanges() {} 00630 virtual void doneMultipleChanges() {} 00631 00632 00633 protected: 00634 00638 YWidgetChildrenManager * childrenManager() const; 00639 00653 void setChildrenManager( YWidgetChildrenManager * manager ); 00654 00663 void setBeingDestroyed(); 00664 00669 void dumpWidget( YWidget *w, int indentationLevel ); 00670 00671 00672 private: 00673 00677 void invalidate(); 00678 00682 YWidget( const YWidget & other ); 00683 00687 const YWidget & operator=( const YWidget & other ); 00688 00689 private: 00690 00691 // 00692 // Data Members 00693 // 00694 00695 int _magic; // should always be the first member 00696 ImplPtr<YWidgetPrivate> priv; 00697 static YPropertySet _propertySet; 00698 static bool _usedOperatorNew; 00699 00700 00701 #include "YWidget_OptimizeChanges.h" 00702 00703 }; 00704 00705 00706 std::ostream & operator<<( std::ostream & stream, const YWidget * widget ); 00707 00708 00709 #endif // YWidget_h