libyui
3.0.10
|
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: YPushButton.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YPushButton_h 00026 #define YPushButton_h 00027 00028 #include "YWidget.h" 00029 00030 class YPushButtonPrivate; 00031 00032 00033 00034 class YPushButton : public YWidget 00035 { 00036 protected: 00037 /** 00038 * Constructor. 00039 **/ 00040 YPushButton( YWidget * parent, const std::string & label ); 00041 00042 public: 00043 /** 00044 * Destructor. 00045 **/ 00046 virtual ~YPushButton(); 00047 00048 /** 00049 * Return a descriptive name of this widget class for logging, 00050 * debugging etc. 00051 **/ 00052 virtual const char * widgetClass() const { return "YPushButton"; } 00053 00054 /** 00055 * Get the label (the text on the button). 00056 **/ 00057 std::string label() const; 00058 00059 /** 00060 * Set the label (the text on the button). 00061 * 00062 * Derived classes are free to reimplement this, but they should call this 00063 * base class method at the end of the overloaded function. 00064 **/ 00065 virtual void setLabel( const std::string & label ); 00066 00067 /** 00068 * Set this button's icon from an icon file in the UI's default icon 00069 * directory. Clear the icon if the name is empty. 00070 * 00071 * This default implementation does nothing. 00072 * UIs that can handle icons can choose to overwrite this method. 00073 **/ 00074 virtual void setIcon( const std::string & iconName ) {} 00075 00076 /** 00077 * Returns 'true' if this is the dialog's default button, i.e. the one 00078 * button that gets activated if the user hits the [Return] key anywhere in 00079 * the dialog. 00080 **/ 00081 bool isDefaultButton() const; 00082 00083 /** 00084 * Make this button the default button. 00085 * 00086 * Derived classes should reimplement this, but call this base class 00087 * function in the overwritten function. 00088 **/ 00089 virtual void setDefaultButton( bool def = true ); 00090 00091 /** 00092 * Set a predefined role for this button. 00093 * 00094 * This is important when the button is a child of a YButtonBox so the 00095 * layout can be arranged according to the conventions of the current UI or 00096 * desktop environment. 00097 * 00098 * See YButtonBox.h for more details. YButtonRole is defined in YTypes.h 00099 * 00100 * The default is YCustomButton, i.e., no predefined role. 00101 * setFunctionKey() uses some heuristics to map function keys to buttons: 00102 * 00103 * F10 -> YOkButton 00104 * F9 -> YCancelButton 00105 * F1 -> YHelpButton 00106 * 00107 * Derived classes are free to reimplement this, but they should call this 00108 * base class function in the overwritten function. 00109 **/ 00110 virtual void setRole( YButtonRole role ); 00111 00112 /** 00113 * Return the role of this button. 00114 **/ 00115 YButtonRole role() const; 00116 00117 /** 00118 * Assign a function key to this widget 00119 * (1 for F1, 2 for F2, etc.; 0 for none) 00120 * 00121 * Reimplemented from YWidget to map function keys to button roles. 00122 * 00123 * Derived classes may want to overwrite this function, but they should 00124 * call this base class function in the new function. 00125 **/ 00126 virtual void setFunctionKey( int fkey_no ); 00127 00128 00129 /** 00130 * Returns 'true' if this is a "Help" button. 00131 * 00132 * When activated, a help button will traverse up its widget hierarchy and 00133 * search for the topmost widget with a helpText() set and display that 00134 * help text in a pop-up dialog (with a local event loop). 00135 * 00136 * NOTE that this is only done during YDialog::waitForEvent() (i.e. in YCP 00137 * UI::WaitForEvent(), UI::UserInput(), UI::TimeoutUserInput() ) and not 00138 * during YDialog::pollEvent() (i.e. YCP UI::PollInput()) since displaying 00139 * the help text will block the application until the user closes the help 00140 * text. 00141 **/ 00142 bool isHelpButton() const; 00143 00144 /** 00145 * Make this button a help button. 00146 * 00147 * Derived classes are free to reimplement this, but they should call this 00148 * base class method in the overloaded function. 00149 **/ 00150 virtual void setHelpButton( bool helpButton = true ); 00151 00152 /** 00153 * Set a property. 00154 * Reimplemented from YWidget. 00155 * 00156 * This function may throw YUIPropertyExceptions. 00157 * 00158 * This function returns 'true' if the value was successfully set and 00159 * 'false' if that value requires special handling (not in error cases: 00160 * those are covered by exceptions). 00161 **/ 00162 virtual bool setProperty( const std::string & propertyName, 00163 const YPropertyValue & val ); 00164 00165 /** 00166 * Get a property. 00167 * Reimplemented from YWidget. 00168 * 00169 * This method may throw YUIPropertyExceptions. 00170 **/ 00171 virtual YPropertyValue getProperty( const std::string & propertyName ); 00172 00173 /** 00174 * Return this class's property set. 00175 * This also initializes the property upon the first call. 00176 * 00177 * Reimplemented from YWidget. 00178 **/ 00179 virtual const YPropertySet & propertySet(); 00180 00181 /** 00182 * Get the string of this widget that holds the keyboard shortcut. 00183 * 00184 * Reimplemented from YWidget. 00185 **/ 00186 virtual std::string shortcutString() const { return label(); } 00187 00188 /** 00189 * Set the string of this widget that holds the keyboard shortcut. 00190 * 00191 * Reimplemented from YWidget. 00192 **/ 00193 virtual void setShortcutString( const std::string & str ) 00194 { setLabel( str ); } 00195 00196 00197 private: 00198 00199 ImplPtr<YPushButtonPrivate> priv; 00200 }; 00201 00202 00203 std::ostream & operator<<( std::ostream & stream, YButtonRole role ); 00204 00205 00206 typedef YPushButton YIconButton; 00207 00208 00209 #endif // YPushButton_h