libyui  3.3.1
YWidgetFactory.cc
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: 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 
35 {
36  // NOP
37 }
38 
40 {
41  // NOP
42  yuiMilestone() << "YWidgetFactory removed" << std::endl;
43 }
44 
45 
46 YDialog *
47 YWidgetFactory::createMainDialog( YDialogColorMode colorMode )
48 {
49  return createDialog( YMainDialog, colorMode );
50 }
51 
52 
53 YDialog *
54 YWidgetFactory::createPopupDialog( YDialogColorMode colorMode )
55 {
56  return createDialog( YPopupDialog, colorMode );
57 }
58 
59 
60 YLayoutBox *
61 YWidgetFactory::createVBox( YWidget * parent )
62 {
63  return createLayoutBox( parent, YD_VERT );
64 }
65 
66 
67 YLayoutBox *
68 YWidgetFactory::createHBox( YWidget * parent )
69 {
70  return createLayoutBox( parent, YD_HORIZ );
71 }
72 
73 
74 YSpacing *
75 YWidgetFactory::createHStretch( YWidget * parent )
76 {
77  return createSpacing( parent,
78  YD_HORIZ,
79  true ); // stretchable
80 }
81 
82 
83 YSpacing *
84 YWidgetFactory::createVStretch( YWidget * parent )
85 {
86  return createSpacing( parent,
87  YD_VERT,
88  true ); // stretchable
89 }
90 
91 
92 YSpacing *
93 YWidgetFactory::createHSpacing( YWidget * parent, YLayoutSize_t size )
94 {
95  return createSpacing( parent,
96  YD_HORIZ,
97  false, // not stretchable
98  size );
99 }
100 
101 
102 YSpacing *
103 YWidgetFactory::createVSpacing( YWidget * parent, YLayoutSize_t size )
104 {
105  return createSpacing( parent,
106  YD_VERT,
107  false, // not stretchable
108  size );
109 }
110 
111 
112 YAlignment *
113 YWidgetFactory::createLeft( YWidget * parent )
114 {
115  return createAlignment( parent, YAlignBegin, YAlignUnchanged );
116 }
117 
118 
119 YAlignment *
120 YWidgetFactory::createRight( YWidget * parent )
121 {
122  return createAlignment( parent, YAlignEnd, YAlignUnchanged );
123 }
124 
125 
126 YAlignment *
127 YWidgetFactory::createTop( YWidget * parent )
128 {
129  return createAlignment( parent, YAlignUnchanged, YAlignBegin );
130 }
131 
132 
133 YAlignment *
134 YWidgetFactory::createBottom( YWidget * parent )
135 {
136  return createAlignment( parent, YAlignUnchanged, YAlignEnd );
137 }
138 
139 
140 YAlignment *
141 YWidgetFactory::createHCenter( YWidget * parent )
142 {
143  return createAlignment( parent, YAlignCenter, YAlignUnchanged );
144 }
145 
146 
147 YAlignment *
148 YWidgetFactory::createVCenter( YWidget * parent )
149 {
150  return createAlignment( parent, YAlignUnchanged, YAlignCenter );
151 }
152 
153 
154 YAlignment *
155 YWidgetFactory::createHVCenter( YWidget * parent )
156 {
157  return createAlignment( parent, YAlignCenter, YAlignCenter );
158 }
159 
160 
161 YAlignment *
162 YWidgetFactory::createMarginBox( YWidget * parent, YLayoutSize_t horMargin, YLayoutSize_t vertMargin )
163 {
164  return createMarginBox( parent,
165  horMargin, horMargin,
166  vertMargin, vertMargin );
167 }
168 
169 
170 
171 YAlignment *
172 YWidgetFactory::createMarginBox( YWidget * parent,
173  YLayoutSize_t leftMargin, YLayoutSize_t rightMargin,
174  YLayoutSize_t topMargin, YLayoutSize_t bottomMargin )
175 {
176  YAlignment * alignment = createAlignment( parent, YAlignUnchanged, YAlignUnchanged );
177 
178  alignment->setLeftMargin ( YUI::app()->deviceUnits( YD_HORIZ, leftMargin ) );
179  alignment->setRightMargin ( YUI::app()->deviceUnits( YD_HORIZ, rightMargin ) );
180  alignment->setTopMargin ( YUI::app()->deviceUnits( YD_VERT, topMargin ) );
181  alignment->setBottomMargin( YUI::app()->deviceUnits( YD_VERT, bottomMargin ) );
182 
183  return alignment;
184 }
185 
186 
187 YAlignment *
188 YWidgetFactory::createMinWidth( YWidget * parent, YLayoutSize_t minWidth )
189 {
190  return createMinSize( parent, minWidth, 0 );
191 }
192 
193 
194 YAlignment *
195 YWidgetFactory::createMinHeight( YWidget * parent, YLayoutSize_t minHeight )
196 {
197  return createMinSize( parent, 0, minHeight );
198 }
199 
200 
201 YAlignment *
202 YWidgetFactory::createMinSize( YWidget * parent, YLayoutSize_t minWidth, YLayoutSize_t minHeight )
203 {
204  YAlignment * alignment = createAlignment( parent, YAlignUnchanged, YAlignUnchanged );
205 
206  alignment->setMinWidth ( YUI::app()->deviceUnits( YD_HORIZ, minWidth ) );
207  alignment->setMinHeight( YUI::app()->deviceUnits( YD_VERT, minHeight ) );
208 
209  return alignment;
210 }
211 
212 
213 YSquash *
214 YWidgetFactory::createHSquash( YWidget * parent )
215 {
216  return createSquash( parent, true, false );
217 }
218 
219 
220 YSquash *
221 YWidgetFactory::createVSquash( YWidget * parent )
222 {
223  return createSquash( parent, false, true );
224 }
225 
226 
227 YSquash *
228 YWidgetFactory::createHVSquash( YWidget * parent )
229 {
230  return createSquash( parent, true, true );
231 }
232 
233 
234 YPushButton *
235 YWidgetFactory::createIconButton( YWidget * parent,
236  const std::string & iconName,
237  const std::string & fallbackTextLabel )
238 {
239  YPushButton * button = createPushButton( parent, fallbackTextLabel );
240  button->setIcon( iconName );
241 
242  return button;
243 }
244 
245 
246 YLabel *
247 YWidgetFactory::createHeading( YWidget * parent, const std::string & text )
248 {
249  return createLabel( parent,
250  text,
251  true, // isHeading
252  false ); // isOutputField
253 }
254 
255 
256 YLabel *
257 YWidgetFactory::createOutputField( YWidget * parent, const std::string & text )
258 {
259  return createLabel( parent,
260  text,
261  false, // isHeading
262  true); // isOutputField
263 }
264 
265 
266 YInputField *
267 YWidgetFactory::createPasswordField( YWidget * parent, const std::string & label )
268 {
269  return createInputField( parent,
270  label,
271  true ); // passwordMode
272 }
YWidgetFactory()
Constructor.
A vertical or horizontal stacking of widgets, implementing HBox and VBox.
Definition: YLayoutBox.h:37
Implementation of the Label, Heading and OutputField widgets.
Definition: YLabel.h:38
virtual ~YWidgetFactory()
Destructor.
HSquash, VSquash HVSquash: reduce child to its preferred size.
Definition: YSquash.h:41
void setMinHeight(int height)
Set the minimum height to return for preferredHeight().
Definition: YAlignment.cc:165
void setMinWidth(int width)
Set the minimum width to return for preferredWidth().
Definition: YAlignment.cc:159
void setRightMargin(int margin)
Set the right margin in pixels.
Definition: YAlignment.cc:129
A push button; may have an icon, and a F-key shortcut.
Definition: YPushButton.h:37
void setBottomMargin(int margin)
Set the bottom margin in pixels.
Definition: YAlignment.cc:141
Implementation of all the alignment widgets:
Definition: YAlignment.h:41
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
HSpacing, VSpacing, HStretch, VStretch.
Definition: YSpacing.h:37
void setTopMargin(int margin)
Set the top margin in pixels.
Definition: YAlignment.cc:135
static YApplication * app()
Return the global YApplication object.
Definition: YUI.cc:156
InputField: General purpose one line input field for entering text and other data.
Definition: YInputField.h:46
A window in the desktop environment.
Definition: YDialog.h:47
Abstract base class of all UI widgets.
Definition: YWidget.h:54
void setLeftMargin(int margin)
Set the left margin in pixels.
Definition: YAlignment.cc:123