libyui  3.10.0
YWidgetFactory.cc
1 /*
2  Copyright (C) 2000-2019 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: YWidgetFactory.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #include "YWidgetFactory.h"
26 #include "YAlignment.h"
27 #include "YPushButton.h"
28 #include "YUI.h"
29 #include "YApplication.h"
30 
31 #define YUILogComponent "wf"
32 #include "YUILog.h"
33 
34 using std::string;
35 
36 
38 {
39  // NOP
40 }
41 
42 
44 {
45  // NOP
46 }
47 
48 
49 YDialog *
50 YWidgetFactory::createMainDialog( YDialogColorMode colorMode )
51 {
52  return createDialog( YMainDialog, colorMode );
53 }
54 
55 
56 YDialog *
57 YWidgetFactory::createPopupDialog( YDialogColorMode colorMode )
58 {
59  return createDialog( YPopupDialog, colorMode );
60 }
61 
62 
63 YLayoutBox *
64 YWidgetFactory::createVBox( YWidget * parent )
65 {
66  return createLayoutBox( parent, YD_VERT );
67 }
68 
69 
70 YLayoutBox *
71 YWidgetFactory::createHBox( YWidget * parent )
72 {
73  return createLayoutBox( parent, YD_HORIZ );
74 }
75 
76 
77 YSpacing *
78 YWidgetFactory::createHStretch( YWidget * parent )
79 {
80  return createSpacing( parent,
81  YD_HORIZ,
82  true ); // stretchable
83 }
84 
85 
86 YSpacing *
87 YWidgetFactory::createVStretch( YWidget * parent )
88 {
89  return createSpacing( parent,
90  YD_VERT,
91  true ); // stretchable
92 }
93 
94 
95 YSpacing *
96 YWidgetFactory::createHSpacing( YWidget * parent, YLayoutSize_t size )
97 {
98  return createSpacing( parent,
99  YD_HORIZ,
100  false, // not stretchable
101  size );
102 }
103 
104 
105 YSpacing *
106 YWidgetFactory::createVSpacing( YWidget * parent, YLayoutSize_t size )
107 {
108  return createSpacing( parent,
109  YD_VERT,
110  false, // not stretchable
111  size );
112 }
113 
114 
115 YAlignment *
116 YWidgetFactory::createLeft( YWidget * parent )
117 {
118  return createAlignment( parent, YAlignBegin, YAlignUnchanged );
119 }
120 
121 
122 YAlignment *
123 YWidgetFactory::createRight( YWidget * parent )
124 {
125  return createAlignment( parent, YAlignEnd, YAlignUnchanged );
126 }
127 
128 
129 YAlignment *
130 YWidgetFactory::createTop( YWidget * parent )
131 {
132  return createAlignment( parent, YAlignUnchanged, YAlignBegin );
133 }
134 
135 
136 YAlignment *
137 YWidgetFactory::createBottom( YWidget * parent )
138 {
139  return createAlignment( parent, YAlignUnchanged, YAlignEnd );
140 }
141 
142 
143 YAlignment *
144 YWidgetFactory::createHCenter( YWidget * parent )
145 {
146  return createAlignment( parent, YAlignCenter, YAlignUnchanged );
147 }
148 
149 
150 YAlignment *
151 YWidgetFactory::createVCenter( YWidget * parent )
152 {
153  return createAlignment( parent, YAlignUnchanged, YAlignCenter );
154 }
155 
156 
157 YAlignment *
158 YWidgetFactory::createHVCenter( YWidget * parent )
159 {
160  return createAlignment( parent, YAlignCenter, YAlignCenter );
161 }
162 
163 
164 YAlignment *
165 YWidgetFactory::createMarginBox( YWidget * parent, YLayoutSize_t horMargin, YLayoutSize_t vertMargin )
166 {
167  return createMarginBox( parent,
168  horMargin, horMargin,
169  vertMargin, vertMargin );
170 }
171 
172 
173 
174 YAlignment *
175 YWidgetFactory::createMarginBox( YWidget * parent,
176  YLayoutSize_t leftMargin, YLayoutSize_t rightMargin,
177  YLayoutSize_t topMargin, YLayoutSize_t bottomMargin )
178 {
179  YAlignment * alignment = createAlignment( parent, YAlignUnchanged, YAlignUnchanged );
180 
181  alignment->setLeftMargin ( YUI::app()->deviceUnits( YD_HORIZ, leftMargin ) );
182  alignment->setRightMargin ( YUI::app()->deviceUnits( YD_HORIZ, rightMargin ) );
183  alignment->setTopMargin ( YUI::app()->deviceUnits( YD_VERT, topMargin ) );
184  alignment->setBottomMargin( YUI::app()->deviceUnits( YD_VERT, bottomMargin ) );
185 
186  return alignment;
187 }
188 
189 
190 YAlignment *
191 YWidgetFactory::createMinWidth( YWidget * parent, YLayoutSize_t minWidth )
192 {
193  return createMinSize( parent, minWidth, 0 );
194 }
195 
196 
197 YAlignment *
198 YWidgetFactory::createMinHeight( YWidget * parent, YLayoutSize_t minHeight )
199 {
200  return createMinSize( parent, 0, minHeight );
201 }
202 
203 
204 YAlignment *
205 YWidgetFactory::createMinSize( YWidget * parent, YLayoutSize_t minWidth, YLayoutSize_t minHeight )
206 {
207  YAlignment * alignment = createAlignment( parent, YAlignUnchanged, YAlignUnchanged );
208 
209  alignment->setMinWidth ( YUI::app()->deviceUnits( YD_HORIZ, minWidth ) );
210  alignment->setMinHeight( YUI::app()->deviceUnits( YD_VERT, minHeight ) );
211 
212  return alignment;
213 }
214 
215 
216 YSquash *
217 YWidgetFactory::createHSquash( YWidget * parent )
218 {
219  return createSquash( parent, true, false );
220 }
221 
222 
223 YSquash *
224 YWidgetFactory::createVSquash( YWidget * parent )
225 {
226  return createSquash( parent, false, true );
227 }
228 
229 
230 YSquash *
231 YWidgetFactory::createHVSquash( YWidget * parent )
232 {
233  return createSquash( parent, true, true );
234 }
235 
236 
237 YPushButton *
238 YWidgetFactory::createIconButton( YWidget * parent,
239  const string & iconName,
240  const string & fallbackTextLabel )
241 {
242  YPushButton * button = createPushButton( parent, fallbackTextLabel );
243  button->setIcon( iconName );
244 
245  return button;
246 }
247 
248 
249 YLabel *
250 YWidgetFactory::createHeading( YWidget * parent, const string & text )
251 {
252  return createLabel( parent,
253  text,
254  true, // isHeading
255  false ); // isOutputField
256 }
257 
258 
259 YLabel *
260 YWidgetFactory::createOutputField( YWidget * parent, const string & text )
261 {
262  return createLabel( parent,
263  text,
264  false, // isHeading
265  true); // isOutputField
266 }
267 
268 
269 YInputField *
270 YWidgetFactory::createPasswordField( YWidget * parent, const string & label )
271 {
272  return createInputField( parent,
273  label,
274  true ); // passwordMode
275 }
276 
277 
279 YWidgetFactory::createItemSelector( YWidget * parent, bool enforceSingleSelection )
280 {
281  (void) parent;
282  (void) enforceSingleSelection;
283 
284  // Default implementation returning 0 to give community-maintained UIs
285  // (libyui-gtk) a chance to catch up with development. Remove this and make
286  // it pure virtual when this is implemented there as well.
287 
288  yuiError() << "YItemSelector not implemented in this UI" << endl;
289 
290  return 0;
291 }
292 
293 
295 YWidgetFactory::createSingleItemSelector( YWidget * parent )
296 {
297  return createItemSelector( parent,
298  true ); // enforceSingleSelection
299 }
300 
301 
303 YWidgetFactory::createMultiItemSelector( YWidget * parent )
304 {
305  return createItemSelector( parent,
306  false ); // enforceSingleSelection
307 }
308 
309 
311 YWidgetFactory::createCustomStatusItemSelector( YWidget * parent,
312  const YItemCustomStatusVector & customStates )
313 {
314  (void) customStates;
315 
316  return createItemSelector( parent,
317  false ); // enforceSingleSelection
318 }
YWidgetFactory::YWidgetFactory
YWidgetFactory()
Constructor.
Definition: YWidgetFactory.cc:37
YWidget
Abstract base class of all UI widgets.
Definition: YWidget.h:55
YAlignment::setMinWidth
void setMinWidth(int width)
Set the minimum width to return for preferredWidth().
Definition: YAlignment.cc:158
YSpacing
HSpacing, VSpacing, HStretch, VStretch.
Definition: YSpacing.h:38
YInputField
InputField: General purpose one line input field for entering text and other data.
Definition: YInputField.h:47
YItemSelector
Scrollable item selector widget with not only a label for each item, but also a (possible multi-line)...
Definition: YItemSelector.h:44
YAlignment
Implementation of all the alignment widgets:
Definition: YAlignment.h:42
YWidgetFactory::~YWidgetFactory
virtual ~YWidgetFactory()
Destructor.
Definition: YWidgetFactory.cc:43
YLabel
Implementation of the Label, Heading and OutputField widgets.
Definition: YLabel.h:39
YPushButton::setIcon
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:77
YAlignment::setBottomMargin
void setBottomMargin(int margin)
Set the bottom margin in pixels.
Definition: YAlignment.cc:140
YAlignment::setTopMargin
void setTopMargin(int margin)
Set the top margin in pixels.
Definition: YAlignment.cc:134
YAlignment::setRightMargin
void setRightMargin(int margin)
Set the right margin in pixels.
Definition: YAlignment.cc:128
YUI::app
static YApplication * app()
Return the global YApplication object.
Definition: YUI.cc:162
YLayoutBox
A vertical or horizontal stacking of widgets, implementing HBox and VBox.
Definition: YLayoutBox.h:38
YSquash
HSquash, VSquash HVSquash: reduce child to its preferred size.
Definition: YSquash.h:42
YAlignment::setLeftMargin
void setLeftMargin(int margin)
Set the left margin in pixels.
Definition: YAlignment.cc:122
YAlignment::setMinHeight
void setMinHeight(int height)
Set the minimum height to return for preferredHeight().
Definition: YAlignment.cc:164
YDialog
A window in the desktop environment.
Definition: YDialog.h:48
YPushButton
A push button; may have an icon, and a F-key shortcut.
Definition: YPushButton.h:38