libyui  3.0.10
 All Classes Functions Variables Enumerations Friends
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  * Set a property.
154  * Reimplemented from YWidget.
155  *
156  * This function may throw YUIPropertyExceptions.
157  *
158  * This function returns 'true' if the value was successfully set and
159  * 'false' if that value requires special handling (not in error cases:
160  * those are covered by exceptions).
161  **/
162  virtual bool setProperty( const std::string & propertyName,
163  const YPropertyValue & val );
164 
165  /**
166  * Get a property.
167  * Reimplemented from YWidget.
168  *
169  * This method may throw YUIPropertyExceptions.
170  **/
171  virtual YPropertyValue getProperty( const std::string & propertyName );
172 
173  /**
174  * Return this class's property set.
175  * This also initializes the property upon the first call.
176  *
177  * Reimplemented from YWidget.
178  **/
179  virtual const YPropertySet & propertySet();
180 
181  /**
182  * Get the string of this widget that holds the keyboard shortcut.
183  *
184  * Reimplemented from YWidget.
185  **/
186  virtual std::string shortcutString() const { return label(); }
187 
188  /**
189  * Set the string of this widget that holds the keyboard shortcut.
190  *
191  * Reimplemented from YWidget.
192  **/
193  virtual void setShortcutString( const std::string & str )
194  { setLabel( str ); }
195 
196 
197 private:
198 
200 };
201 
202 
203 std::ostream & operator<<( std::ostream & stream, YButtonRole role );
204 
205 
206 typedef YPushButton YIconButton;
207 
208 
209 #endif // YPushButton_h
YWidget * parent() const
Definition: YWidget.cc:269
YButtonRole role() const
Definition: YPushButton.cc:164
bool isHelpButton() const
Definition: YPushButton.cc:125
virtual void setDefaultButton(bool def=true)
Definition: YPushButton.cc:96
virtual const char * widgetClass() const
Definition: YPushButton.h:52
virtual ~YPushButton()
Definition: YPushButton.cc:67
std::string label() const
Definition: YPushButton.cc:84
virtual void setShortcutString(const std::string &str)
Definition: YPushButton.h:193
virtual bool setProperty(const std::string &propertyName, const YPropertyValue &val)
Definition: YPushButton.cc:216
virtual const YPropertySet & propertySet()
Definition: YPushButton.cc:198
bool isDefaultButton() const
Definition: YPushButton.cc:90
virtual void setRole(YButtonRole role)
Definition: YPushButton.cc:140
virtual std::string shortcutString() const
Definition: YPushButton.h:186
virtual void setIcon(const std::string &iconName)
Definition: YPushButton.h:74
virtual void setFunctionKey(int fkey_no)
Definition: YPushButton.cc:172
virtual YPropertyValue getProperty(const std::string &propertyName)
Definition: YPushButton.cc:231
YPushButton(YWidget *parent, const std::string &label)
Definition: YPushButton.cc:56
virtual void setLabel(const std::string &label)
Definition: YPushButton.cc:78
virtual void setHelpButton(bool helpButton=true)
Definition: YPushButton.cc:131