libyui  3.1.4
 All Classes Files Functions Variables Typedefs Enumerations Friends Pages
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 class YPushButton : public YWidget
35 {
36 protected:
37  /**
38  * Constructor.
39  **/
40  YPushButton( YWidget * parent, const std::string & label );
41 
42 public:
43  /**
44  * Destructor.
45  **/
46  virtual ~YPushButton();
47 
48  /**
49  * Return a descriptive name of this widget class for logging,
50  * debugging etc.
51  **/
52  virtual const char * widgetClass() const { return "YPushButton"; }
53 
54  /**
55  * Get the label (the text on the button).
56  **/
57  std::string label() const;
58 
59  /**
60  * Set the label (the text on the button).
61  *
62  * Derived classes are free to reimplement this, but they should call this
63  * base class method at the end of the overloaded function.
64  **/
65  virtual void setLabel( const std::string & label );
66 
67  /**
68  * Set this button's icon from an icon file in the UI's default icon
69  * directory. Clear the icon if the name is empty.
70  *
71  * This default implementation does nothing.
72  * UIs that can handle icons can choose to overwrite this method.
73  **/
74  virtual void setIcon( const std::string & iconName ) {}
75 
76  /**
77  * Returns 'true' if this is the dialog's default button, i.e. the one
78  * button that gets activated if the user hits the [Return] key anywhere in
79  * the dialog.
80  **/
81  bool isDefaultButton() const;
82 
83  /**
84  * Make this button the default button.
85  *
86  * Derived classes should reimplement this, but call this base class
87  * function in the overwritten function.
88  **/
89  virtual void setDefaultButton( bool def = true );
90 
91  /**
92  * Set a predefined role for this button.
93  *
94  * This is important when the button is a child of a YButtonBox so the
95  * layout can be arranged according to the conventions of the current UI or
96  * desktop environment.
97  *
98  * See YButtonBox.h for more details. YButtonRole is defined in YTypes.h
99  *
100  * The default is YCustomButton, i.e., no predefined role.
101  * setFunctionKey() uses some heuristics to map function keys to buttons:
102  *
103  * F10 -> YOkButton
104  * F9 -> YCancelButton
105  * F1 -> YHelpButton
106  *
107  * Derived classes are free to reimplement this, but they should call this
108  * base class function in the overwritten function.
109  **/
110  virtual void setRole( YButtonRole role );
111 
112  /**
113  * Return the role of this button.
114  **/
115  YButtonRole role() const;
116 
117  /**
118  * Assign a function key to this widget
119  * (1 for F1, 2 for F2, etc.; 0 for none)
120  *
121  * Reimplemented from YWidget to map function keys to button roles.
122  *
123  * Derived classes may want to overwrite this function, but they should
124  * call this base class function in the new function.
125  **/
126  virtual void setFunctionKey( int fkey_no );
127 
128 
129  /**
130  * Returns 'true' if this is a "Help" button.
131  *
132  * When activated, a help button will traverse up its widget hierarchy and
133  * search for the topmost widget with a helpText() set and display that
134  * help text in a pop-up dialog (with a local event loop).
135  *
136  * NOTE that this is only done during YDialog::waitForEvent() (i.e. in YCP
137  * UI::WaitForEvent(), UI::UserInput(), UI::TimeoutUserInput() ) and not
138  * during YDialog::pollEvent() (i.e. YCP UI::PollInput()) since displaying
139  * the help text will block the application until the user closes the help
140  * text.
141  **/
142  bool isHelpButton() const;
143 
144  /**
145  * Make this button a help button.
146  *
147  * Derived classes are free to reimplement this, but they should call this
148  * base class method in the overloaded function.
149  **/
150  virtual void setHelpButton( bool helpButton = true );
151 
152  /**
153  * Returns 'true' if this is a "Release Notes" button.
154  *
155  * NOTE that this is only done during YDialog::waitForEvent() (i.e. in YCP
156  * UI::WaitForEvent(), UI::UserInput(), UI::TimeoutUserInput() ) and not
157  * during YDialog::pollEvent() (i.e. YCP UI::PollInput()) since displaying
158  * the release notes will block the application until the user closes the
159  * text.
160  **/
161  bool isRelNotesButton() const;
162 
163  /**
164  * Make this button a release notes button.
165  *
166  * Derived classes are free to reimplement this, but they should call this
167  * base class method in the overloaded function.
168  **/
169  virtual void setRelNotesButton( bool relNotesButton = true );
170 
171  /**
172  * Set a property.
173  * Reimplemented from YWidget.
174  *
175  * This function may throw YUIPropertyExceptions.
176  *
177  * This function returns 'true' if the value was successfully set and
178  * 'false' if that value requires special handling (not in error cases:
179  * those are covered by exceptions).
180  **/
181  virtual bool setProperty( const std::string & propertyName,
182  const YPropertyValue & val );
183 
184  /**
185  * Get a property.
186  * Reimplemented from YWidget.
187  *
188  * This method may throw YUIPropertyExceptions.
189  **/
190  virtual YPropertyValue getProperty( const std::string & propertyName );
191 
192  /**
193  * Return this class's property set.
194  * This also initializes the property upon the first call.
195  *
196  * Reimplemented from YWidget.
197  **/
198  virtual const YPropertySet & propertySet();
199 
200  /**
201  * Get the string of this widget that holds the keyboard shortcut.
202  *
203  * Reimplemented from YWidget.
204  **/
205  virtual std::string shortcutString() const { return label(); }
206 
207  /**
208  * Set the string of this widget that holds the keyboard shortcut.
209  *
210  * Reimplemented from YWidget.
211  **/
212  virtual void setShortcutString( const std::string & str )
213  { setLabel( str ); }
214 
215 
216 private:
217 
219 };
220 
221 
222 std::ostream & operator<<( std::ostream & stream, YButtonRole role );
223 
224 
225 typedef YPushButton YIconButton;
226 
227 
228 #endif // YPushButton_h
YWidget * parent() const
Return this widget's parent or 0 if it doesn't have a parent.
Definition: YWidget.cc:269
YButtonRole role() const
Return the role of this button.
Definition: YPushButton.cc:178
bool isHelpButton() const
Returns 'true' if this is a "Help" button.
Definition: YPushButton.cc:127
Transport class for the value of simple properties.
Definition: YProperty.h:104
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:184
virtual const char * widgetClass() const
Return a descriptive name of this widget class for logging, debugging etc.
Definition: YPushButton.h:52
virtual ~YPushButton()
Destructor.
Definition: YPushButton.cc:69
std::string label() const
Get the label (the text on the button).
Definition: YPushButton.cc:86
virtual void setShortcutString(const std::string &str)
Set the string of this widget that holds the keyboard shortcut.
Definition: YPushButton.h:212
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Set a property.
Definition: YPushButton.cc:230
virtual const YPropertySet & propertySet()
Return this class's property set.
Definition: YPushButton.cc:212
bool isDefaultButton() const
Returns 'true' if this is the dialog's default button, i.e.
Definition: YPushButton.cc:92
virtual void setRole(YButtonRole role)
Set a predefined role for this button.
Definition: YPushButton.cc:154
virtual std::string shortcutString() const
Get the string of this widget that holds the keyboard shortcut.
Definition: YPushButton.h:205
virtual void setIcon(const std::string &iconName)
Set this button's icon from an icon file in the UI's default icon directory.
Definition: YPushButton.h:74
bool isRelNotesButton() const
Returns 'true' if this is a "Release Notes" button.
Definition: YPushButton.cc:139
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
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