libyui-ncurses  2.44.1
 All Classes Functions Variables
NCWidgetFactory.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: NCWidgetFactory.cc
20 
21  Authors: Stefan Hundhammer <sh@suse.de>
22  Gabriele Mohr <gs@suse.de>
23 
24 /-*/
25 
26 #include "NCWidgetFactory.h"
27 #include <yui/YUIException.h>
28 
29 #define YUILogComponent "ncurses"
30 #include <yui/YUILog.h>
31 #include "YNCursesUI.h"
32 
33 #include <string>
34 
35 
37  : YWidgetFactory()
38 {
39  // NOP
40 }
41 
43 {
44  // NOP
45 }
46 
47 
48 
49 
50 //
51 // Dialogs
52 //
53 
54 NCDialog *
55 NCWidgetFactory::createDialog( YDialogType dialogType, YDialogColorMode colorMode )
56 {
57  yuiDebug() << "Flush input buffer - new dialog" << std::endl;
58  ::flushinp();
59 
60  NCDialog * dialog = new NCDialog( dialogType, colorMode );
61  YUI_CHECK_NEW( dialog );
62 
63  return dialog;
64 }
65 
66 
67 //
68 // Common Leaf Widgets
69 //
70 
72 NCWidgetFactory::createPushButton( YWidget * parent, const std::string & label )
73 {
74  NCPushButton * pushButton = new NCPushButton( parent, label );
75  YUI_CHECK_NEW( pushButton );
76 
77  return pushButton;
78 }
79 
80 
81 
82 NCLabel *
83 NCWidgetFactory::createLabel( YWidget * parent,
84  const std::string & text,
85  bool isHeading,
86  bool isOutputField )
87 {
88  NCLabel * label = new NCLabel( parent, text, isHeading, isOutputField );
89  YUI_CHECK_NEW( label );
90 
91  return label;
92 }
93 
94 
95 
97 NCWidgetFactory::createInputField( YWidget * parent, const std::string & label, bool passwordMode )
98 {
99  NCInputField * inputField = new NCInputField( parent, label, passwordMode );
100  YUI_CHECK_NEW( inputField );
101 
102  return inputField;
103 }
104 
105 
106 
107 NCCheckBox *
108 NCWidgetFactory::createCheckBox( YWidget * parent, const std::string & label, bool isChecked )
109 {
110  NCCheckBox * checkBox = new NCCheckBox( parent, label, isChecked );
111  YUI_CHECK_NEW( checkBox );
112 
113  return checkBox;
114 }
115 
116 
117 
119 NCWidgetFactory::createRadioButton( YWidget * parent, const std::string & label, bool checked )
120 {
121  NCRadioButton * radioButton = new NCRadioButton( parent, label, checked );
122  YUI_CHECK_NEW( radioButton );
123 
124  // Register radio button with its button group.
125  // This has to be done after all constructors are done so virtual functions
126  // can be used.
127 
128  if ( radioButton->buttonGroup() )
129  radioButton->buttonGroup()->addRadioButton( radioButton );
130 
131  return radioButton;
132 }
133 
134 
135 
136 NCComboBox *
137 NCWidgetFactory::createComboBox( YWidget * parent, const std::string & label, bool editable )
138 {
139  NCComboBox * comboBox = new NCComboBox( parent, label, editable );
140  YUI_CHECK_NEW( comboBox );
141 
142  return comboBox;
143 }
144 
145 
146 
148 NCWidgetFactory::createSelectionBox( YWidget * parent, const std::string & label )
149 {
150  NCSelectionBox * selectionBox = new NCSelectionBox( parent, label );
151  YUI_CHECK_NEW( selectionBox );
152 
153  return selectionBox;
154 }
155 
156 
157 
158 NCTree *
159 NCWidgetFactory::createTree( YWidget * parent, const std::string & label, bool multiselection, bool recursiveselection )
160 {
161  NCTree * tree = new NCTree( parent, label, multiselection, recursiveselection );
162  YUI_CHECK_NEW( tree );
163 
164  return tree;
165 }
166 
167 
168 
169 NCTable *
170 NCWidgetFactory::createTable( YWidget * parent, YTableHeader * tableHeader, bool multiSelection )
171 {
172  NCTable *table = new NCTable( parent, tableHeader, multiSelection );
173  YUI_CHECK_NEW( table );
174 
175  return table;
176 }
177 
178 
179 
181 NCWidgetFactory::createProgressBar( YWidget * parent, const std::string & label, int maxValue )
182 {
183  NCProgressBar * progressBar = new NCProgressBar( parent, label, maxValue );
184  YUI_CHECK_NEW( progressBar );
185 
186  return progressBar;
187 }
188 
190 NCWidgetFactory::createBusyIndicator( YWidget * parent, const std::string & label, int timeout)
191 {
192  NCBusyIndicator * busyIndicator = new NCBusyIndicator( parent, label, timeout );
193  YUI_CHECK_NEW( busyIndicator );
194 
195  return busyIndicator;
196 }
197 
198 NCRichText *
199 NCWidgetFactory::createRichText( YWidget * parent, const std::string & text, bool plainTextMode )
200 {
201  NCRichText * richText = new NCRichText( parent, text, plainTextMode );
202  YUI_CHECK_NEW( richText );
203 
204  return richText;
205 }
206 
207 //
208 // Less Common Leaf Widgets
209 //
210 
211 NCIntField *
212 NCWidgetFactory::createIntField( YWidget * parent, const std::string & label, int minVal, int maxVal, int initialVal )
213 {
214  NCIntField * intField = new NCIntField( parent, label, minVal, maxVal, initialVal );
215  YUI_CHECK_NEW( intField );
216 
217  return intField;
218 }
219 
220 
221 
222 NCMenuButton *
223 NCWidgetFactory::createMenuButton( YWidget * parent, const std::string & label )
224 {
225  NCMenuButton * menuButton = new NCMenuButton( parent, label );
226  YUI_CHECK_NEW( menuButton );
227 
228  return menuButton;
229 }
230 
231 
232 
234 NCWidgetFactory::createMultiLineEdit( YWidget * parent, const std::string & label )
235 {
236  NCMultiLineEdit * multiLineEdit = new NCMultiLineEdit( parent, label );
237  YUI_CHECK_NEW( multiLineEdit );
238 
239  return multiLineEdit;
240 }
241 
242 NCLogView *
243 NCWidgetFactory::createLogView( YWidget * parent, const std::string & label, int visibleLines, int storedLines )
244 {
245  NCLogView * logView = new NCLogView( parent, label, visibleLines, storedLines );
246  YUI_CHECK_NEW( logView );
247 
248  return logView;
249 }
250 
251 
252 
254 NCWidgetFactory::createMultiSelectionBox( YWidget * parent, const std::string & label )
255 {
256  NCMultiSelectionBox * multiSelectionBox = new NCMultiSelectionBox( parent, label );
257  YUI_CHECK_NEW( multiSelectionBox );
258 
259  return multiSelectionBox;
260 }
261 
262 
263 //
264 // Layout Helpers
265 //
266 
267 NCSpacing *
268 NCWidgetFactory::createSpacing( YWidget * parent, YUIDimension dim, bool stretchable, YLayoutSize_t size )
269 {
270  NCSpacing * spacing = new NCSpacing( parent, dim, stretchable, size );
271  YUI_CHECK_NEW( spacing );
272 
273  return spacing;
274 }
275 
276 NCLayoutBox *
277 NCWidgetFactory::createLayoutBox( YWidget * parent, YUIDimension dim )
278 {
279  NCLayoutBox * layoutBox = new NCLayoutBox( parent, dim );
280  YUI_CHECK_NEW( layoutBox );
281 
282  return layoutBox;
283 }
284 
285 
286 NCButtonBox *
287 NCWidgetFactory::createButtonBox( YWidget * parent )
288 {
289  NCButtonBox * buttonBox = new NCButtonBox( parent );
290  YUI_CHECK_NEW( buttonBox );
291 
292  return buttonBox;
293 }
294 
295 
296 NCEmpty *
297 NCWidgetFactory::createEmpty( YWidget * parent )
298 {
299  NCEmpty * empty = new NCEmpty( parent );
300  YUI_CHECK_NEW( empty );
301 
302  return empty;
303 }
304 
305 
306 
307 NCAlignment *
308 NCWidgetFactory::createAlignment( YWidget * parent,
309  YAlignmentType horAlignment,
310  YAlignmentType vertAlignment )
311 {
312  NCAlignment * alignment = new NCAlignment( parent, horAlignment, vertAlignment );
313  YUI_CHECK_NEW( alignment );
314 
315  return alignment;
316 }
317 
318 
319 NCSquash *
320 NCWidgetFactory::createSquash( YWidget * parent, bool horSquash, bool vertSquash )
321 {
322  NCSquash * squash = new NCSquash( parent, horSquash, vertSquash );
323  YUI_CHECK_NEW( squash );
324 
325  return squash;
326 }
327 
328 
329 
330 NCFrame *
331 NCWidgetFactory::createFrame( YWidget * parent, const std::string & label )
332 {
333  NCFrame * frame = new NCFrame( parent, label );
334  YUI_CHECK_NEW( frame );
335 
336  return frame;
337 }
338 
339 
340 
342 NCWidgetFactory::createCheckBoxFrame( YWidget * parent, const std::string & label, bool checked )
343 {
344  NCCheckBoxFrame * checkBoxFrame = new NCCheckBoxFrame( parent, label, checked );
345  YUI_CHECK_NEW( checkBoxFrame );
346 
347  return checkBoxFrame;
348 }
349 
350 
351 
353 NCWidgetFactory::createRadioButtonGroup( YWidget * parent )
354 {
355  NCRadioButtonGroup * radioButtonGroup = new NCRadioButtonGroup( parent );
356  YUI_CHECK_NEW( radioButtonGroup );
357 
358  return radioButtonGroup;
359 }
360 
361 
362 
364 NCWidgetFactory::createReplacePoint( YWidget * parent )
365 {
366  NCReplacePoint * replacePoint = new NCReplacePoint( parent );
367  YUI_CHECK_NEW( replacePoint );
368 
369  return replacePoint;
370 }
371 
372 NCImage *
373 NCWidgetFactory::createImage( YWidget * parent, const std::string & imageFileName, bool animated )
374 {
375  NCImage * image = new NCImage( parent, imageFileName, animated );
376  YUI_CHECK_NEW( image );
377 
378  return image;
379 }
380 
381 
382 YPackageSelector *
383 NCWidgetFactory::createPackageSelector( YWidget * parent, long modeFlags )
384 {
386 
387  if ( plugin )
388  return plugin->createPackageSelector( parent, modeFlags );
389  else
390  return 0;
391 }
392 
393 
394 // Creates special widgets used for the package selection dialog.
395 // This is special to the NCurses UI; there is no a corresponding widget
396 // in the Qt UI.
397 YWidget *
398 NCWidgetFactory::createPkgSpecial( YWidget * parent, const std::string & subwidget )
399 {
400  YWidget * w = 0;
401 
403 
404  if ( plugin )
405  {
406  w = plugin->createPkgSpecial( parent, subwidget );
407  }
408 
409  return w;
410 }
411 
412 
static YNCursesUI * ui()
Definition: YNCursesUI.h:91
virtual YWidget * createPkgSpecial(YWidget *parent, const std::string &subwidget)
virtual ~NCWidgetFactory()
NCPackageSelectorPluginStub * packageSelectorPlugin()
Definition: YNCursesUI.cc:201
Definition: NCTree.h:38
virtual YPackageSelector * createPackageSelector(YWidget *parent, long modeFlags)