libyui  3.3.2
YPushButton.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YPushButton.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YPushButton_h
26 #define YPushButton_h
27 
28 #include "YWidget.h"
29 
30 class YPushButtonPrivate;
31 
32 
33 
34 /**
35  * A push button; may have an icon, and a F-key shortcut.
36  **/
37 class YPushButton : public YWidget
38 {
39 protected:
40  /**
41  * Constructor.
42  **/
43  YPushButton( YWidget * parent, const std::string & label );
44 
45 public:
46  /**
47  * Destructor.
48  **/
49  virtual ~YPushButton();
50 
51  /**
52  * Return a descriptive name of this widget class for logging,
53  * debugging etc.
54  **/
55  virtual const char * widgetClass() const { return "YPushButton"; }
56 
57  /**
58  * Get the label (the text on the button).
59  **/
60  std::string label() const;
61 
62  /**
63  * Set the label (the text on the button).
64  *
65  * Derived classes are free to reimplement this, but they should call this
66  * base class method at the end of the overloaded function.
67  **/
68  virtual void setLabel( const std::string & label );
69 
70  /**
71  * Set this button's icon from an icon file in the UI's default icon
72  * directory. Clear the icon if the name is empty.
73  *
74  * This default implementation does nothing.
75  * UIs that can handle icons can choose to overwrite this method.
76  **/
77  virtual void setIcon( const std::string & iconName ) {}
78 
79  /**
80  * Returns 'true' if this is the dialog's default button, i.e. the one
81  * button that gets activated if the user hits the [Return] key anywhere in
82  * the dialog.
83  **/
84  bool isDefaultButton() const;
85 
86  /**
87  * Make this button the default button.
88  *
89  * Derived classes should reimplement this, but call this base class
90  * function in the overwritten function.
91  **/
92  virtual void setDefaultButton( bool def = true );
93 
94  /**
95  * Set a predefined role for this button.
96  *
97  * This is important when the button is a child of a YButtonBox so the
98  * layout can be arranged according to the conventions of the current UI or
99  * desktop environment.
100  *
101  * See YButtonBox.h for more details. YButtonRole is defined in YTypes.h
102  *
103  * The default is YCustomButton, i.e., no predefined role.
104  * setFunctionKey() uses some heuristics to map function keys to buttons:
105  *
106  * F10 -> YOkButton
107  * F9 -> YCancelButton
108  * F1 -> YHelpButton
109  *
110  * Derived classes are free to reimplement this, but they should call this
111  * base class function in the overwritten function.
112  **/
113  virtual void setRole( YButtonRole role );
114 
115  /**
116  * Return the role of this button.
117  **/
118  YButtonRole role() const;
119 
120  /**
121  * Assign a function key to this widget
122  * (1 for F1, 2 for F2, etc.; 0 for none)
123  *
124  * Reimplemented from YWidget to map function keys to button roles.
125  *
126  * Derived classes may want to overwrite this function, but they should
127  * call this base class function in the new function.
128  **/
129  virtual void setFunctionKey( int fkey_no );
130 
131 
132  /**
133  * Returns 'true' if this is a "Help" button.
134  *
135  * When activated, a help button will traverse up its widget hierarchy and
136  * search for the topmost widget with a helpText() set and display that
137  * help text in a pop-up dialog (with a local event loop).
138  *
139  * NOTE that this is only done during YDialog::waitForEvent() (i.e. in YCP
140  * UI::WaitForEvent(), UI::UserInput(), UI::TimeoutUserInput() ) and not
141  * during YDialog::pollEvent() (i.e. YCP UI::PollInput()) since displaying
142  * the help text will block the application until the user closes the help
143  * text.
144  **/
145  bool isHelpButton() const;
146 
147  /**
148  * Make this button a help button.
149  *
150  * Derived classes are free to reimplement this, but they should call this
151  * base class method in the overloaded function.
152  **/
153  virtual void setHelpButton( bool helpButton = true );
154 
155  /**
156  * Returns 'true' if this is a "Release Notes" button.
157  *
158  * NOTE that this is only done during YDialog::waitForEvent() (i.e. in YCP
159  * UI::WaitForEvent(), UI::UserInput(), UI::TimeoutUserInput() ) and not
160  * during YDialog::pollEvent() (i.e. YCP UI::PollInput()) since displaying
161  * the release notes will block the application until the user closes the
162  * text.
163  **/
164  bool isRelNotesButton() const;
165 
166  /**
167  * Make this button a release notes button.
168  *
169  * Derived classes are free to reimplement this, but they should call this
170  * base class method in the overloaded function.
171  **/
172  virtual void setRelNotesButton( bool relNotesButton = true );
173 
174  /**
175  * Set a property.
176  * Reimplemented from YWidget.
177  *
178  * This function may throw YUIPropertyExceptions.
179  *
180  * This function returns 'true' if the value was successfully set and
181  * 'false' if that value requires special handling (not in error cases:
182  * those are covered by exceptions).
183  **/
184  virtual bool setProperty( const std::string & propertyName,
185  const YPropertyValue & val );
186 
187  /**
188  * Get a property.
189  * Reimplemented from YWidget.
190  *
191  * This method may throw YUIPropertyExceptions.
192  **/
193  virtual YPropertyValue getProperty( const std::string & propertyName );
194 
195  /**
196  * Return this class's property set.
197  * This also initializes the property upon the first call.
198  *
199  * Reimplemented from YWidget.
200  **/
201  virtual const YPropertySet & propertySet();
202 
203  /**
204  * Get the string of this widget that holds the keyboard shortcut.
205  *
206  * Reimplemented from YWidget.
207  **/
208  virtual std::string shortcutString() const { return label(); }
209 
210  /**
211  * Set the string of this widget that holds the keyboard shortcut.
212  *
213  * Reimplemented from YWidget.
214  **/
215  virtual void setShortcutString( const std::string & str )
216  { setLabel( str ); }
217 
218 
219 private:
220 
222 };
223 
224 
225 std::ostream & operator<<( std::ostream & stream, YButtonRole role );
226 
227 
228 typedef YPushButton YIconButton;
229 
230 
231 #endif // YPushButton_h
bool isHelpButton() const
Returns &#39;true&#39; if this is a "Help" button.
Definition: YPushButton.cc:127
Transport class for the value of simple properties.
Definition: YProperty.h:104
bool isDefaultButton() const
Returns &#39;true&#39; if this is the dialog&#39;s default button, i.e.
Definition: YPushButton.cc:92
std::string label() const
Get the label (the text on the button).
Definition: YPushButton.cc:86
virtual void setDefaultButton(bool def=true)
Make this button the default button.
Definition: YPushButton.cc:98
A set of properties to check names and types against.
Definition: YProperty.h:197
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
virtual ~YPushButton()
Destructor.
Definition: YPushButton.cc:69
virtual const char * widgetClass() const
Return a descriptive name of this widget class for logging, debugging etc.
Definition: YPushButton.h:55
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YPushButton.h:215
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YPushButton.cc:230
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YPushButton.h:208
virtual const YPropertySet & propertySet()
Return this class&#39;s property set.
Definition: YPushButton.cc:212
A push button; may have an icon, and a F-key shortcut.
Definition: YPushButton.h:37
virtual void setRole(YButtonRole role)
Set a predefined role for this button.
Definition: YPushButton.cc:154
virtual void setIcon(const std::string &iconName)
Set this button&#39;s icon from an icon file in the UI&#39;s default icon directory.
Definition: YPushButton.h:77
YButtonRole role() const
Return the role of this button.
Definition: YPushButton.cc:178
virtual void setFunctionKey(int fkey_no)
Assign a function key to this widget (1 for F1, 2 for F2, etc.
Definition: YPushButton.cc:186
virtual void setRelNotesButton(bool relNotesButton=true)
Make this button a release notes button.
Definition: YPushButton.cc:145
bool isRelNotesButton() const
Returns &#39;true&#39; if this is a "Release Notes" button.
Definition: YPushButton.cc:139
virtual YPropertyValue getProperty(const std::string &propertyName)
Get a property.
Definition: YPushButton.cc:245
YPushButton(YWidget *parent, const std::string &label)
Constructor.
Definition: YPushButton.cc:58
virtual void setLabel(const std::string &label)
Set the label (the text on the button).
Definition: YPushButton.cc:80
Abstract base class of all UI widgets.
Definition: YWidget.h:54
virtual void setHelpButton(bool helpButton=true)
Make this button a help button.
Definition: YPushButton.cc:133