libyui-ncurses  2.54.5
NCWidgetFactory.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  Copyright (C) 2019 SUSE LLC
4  This library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU Lesser General Public License as
6  published by the Free Software Foundation; either version 2.1 of the
7  License, or (at your option) version 3.0 of the License. This library
8  is distributed in the hope that it will be useful, but WITHOUT ANY
9  WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
11  License for more details. You should have received a copy of the GNU
12  Lesser General Public License along with this library; if not, write
13  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
14  Floor, Boston, MA 02110-1301 USA
15 */
16 
17 
18 /*-/
19 
20  File: NCWidgetFactory.cc
21 
22  Authors: Stefan Hundhammer <sh@suse.de>
23  Gabriele Mohr <gs@suse.de>
24 
25 /-*/
26 
27 #include "NCWidgetFactory.h"
28 #include <yui/YUIException.h>
29 
30 #define YUILogComponent "ncurses"
31 #include <yui/YUILog.h>
32 #include "YNCursesUI.h"
33 
34 #include <string>
35 
36 
38  : YWidgetFactory()
39 {
40  // NOP
41 }
42 
43 
45 {
46  // NOP
47 }
48 
49 
50 
51 
52 //
53 // Dialogs
54 //
55 
56 NCDialog *
57 NCWidgetFactory::createDialog( YDialogType dialogType, YDialogColorMode colorMode )
58 {
59  yuiDebug() << "Flush input buffer - new dialog" << std::endl;
60  ::flushinp();
61 
62  NCDialog * dialog = new NCDialog( dialogType, colorMode );
63  YUI_CHECK_NEW( dialog );
64 
65  return dialog;
66 }
67 
68 
69 //
70 // Common Leaf Widgets
71 //
72 
74 NCWidgetFactory::createPushButton( YWidget * parent, const std::string & label )
75 {
76  NCPushButton * pushButton = new NCPushButton( parent, label );
77  YUI_CHECK_NEW( pushButton );
78 
79  return pushButton;
80 }
81 
82 
83 
84 NCLabel *
85 NCWidgetFactory::createLabel( YWidget * parent,
86  const std::string & text,
87  bool isHeading,
88  bool isOutputField )
89 {
90  NCLabel * label = new NCLabel( parent, text, isHeading, isOutputField );
91  YUI_CHECK_NEW( label );
92 
93  return label;
94 }
95 
96 
98 NCWidgetFactory::createInputField( YWidget * parent, const std::string & label, bool passwordMode )
99 {
100  NCInputField * inputField = new NCInputField( parent, label, passwordMode );
101  YUI_CHECK_NEW( inputField );
102 
103  return inputField;
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 
118 NCWidgetFactory::createRadioButton( YWidget * parent, const std::string & label, bool checked )
119 {
120  NCRadioButton * radioButton = new NCRadioButton( parent, label, checked );
121  YUI_CHECK_NEW( radioButton );
122 
123  // Register radio button with its button group.
124  // This has to be done after all constructors are done so virtual functions
125  // can be used.
126 
127  if ( radioButton->buttonGroup() )
128  radioButton->buttonGroup()->addRadioButton( radioButton );
129 
130  return radioButton;
131 }
132 
133 
134 NCComboBox *
135 NCWidgetFactory::createComboBox( YWidget * parent, const std::string & label, bool editable )
136 {
137  NCComboBox * comboBox = new NCComboBox( parent, label, editable );
138  YUI_CHECK_NEW( comboBox );
139 
140  return comboBox;
141 }
142 
143 
145 NCWidgetFactory::createSelectionBox( YWidget * parent, const std::string & label )
146 {
147  NCSelectionBox * selectionBox = new NCSelectionBox( parent, label );
148  YUI_CHECK_NEW( selectionBox );
149 
150  return selectionBox;
151 }
152 
153 
154 NCTree *
155 NCWidgetFactory::createTree( YWidget * parent, const std::string & label, bool multiselection, bool recursiveselection )
156 {
157  NCTree * tree = new NCTree( parent, label, multiselection, recursiveselection );
158  YUI_CHECK_NEW( tree );
159 
160  return tree;
161 }
162 
163 
164 NCTable *
165 NCWidgetFactory::createTable( YWidget * parent, YTableHeader * tableHeader, bool multiSelection )
166 {
167  NCTable *table = new NCTable( parent, tableHeader, multiSelection );
168  YUI_CHECK_NEW( table );
169 
170  return table;
171 }
172 
173 
175 NCWidgetFactory::createProgressBar( YWidget * parent, const std::string & label, int maxValue )
176 {
177  NCProgressBar * progressBar = new NCProgressBar( parent, label, maxValue );
178  YUI_CHECK_NEW( progressBar );
179 
180  return progressBar;
181 }
182 
183 
185 NCWidgetFactory::createBusyIndicator( YWidget * parent, const std::string & label, int timeout)
186 {
187  NCBusyIndicator * busyIndicator = new NCBusyIndicator( parent, label, timeout );
188  YUI_CHECK_NEW( busyIndicator );
189 
190  return busyIndicator;
191 }
192 
193 
194 NCRichText *
195 NCWidgetFactory::createRichText( YWidget * parent, const std::string & text, bool plainTextMode )
196 {
197  NCRichText * richText = new NCRichText( parent, text, plainTextMode );
198  YUI_CHECK_NEW( richText );
199 
200  return richText;
201 }
202 
203 
204 //
205 // Less Common Leaf Widgets
206 //
207 
208 NCIntField *
209 NCWidgetFactory::createIntField( YWidget * parent, const std::string & label, int minVal, int maxVal, int initialVal )
210 {
211  NCIntField * intField = new NCIntField( parent, label, minVal, maxVal, initialVal );
212  YUI_CHECK_NEW( intField );
213 
214  return intField;
215 }
216 
217 
218 NCMenuButton *
219 NCWidgetFactory::createMenuButton( YWidget * parent, const std::string & label )
220 {
221  NCMenuButton * menuButton = new NCMenuButton( parent, label );
222  YUI_CHECK_NEW( menuButton );
223 
224  return menuButton;
225 }
226 
227 
229 NCWidgetFactory::createMultiLineEdit( YWidget * parent, const std::string & label )
230 {
231  NCMultiLineEdit * multiLineEdit = new NCMultiLineEdit( parent, label );
232  YUI_CHECK_NEW( multiLineEdit );
233 
234  return multiLineEdit;
235 }
236 
237 
238 NCLogView *
239 NCWidgetFactory::createLogView( YWidget * parent, const std::string & label, int visibleLines, int storedLines )
240 {
241  NCLogView * logView = new NCLogView( parent, label, visibleLines, storedLines );
242  YUI_CHECK_NEW( logView );
243 
244  return logView;
245 }
246 
247 
249 NCWidgetFactory::createMultiSelectionBox( YWidget * parent, const std::string & label )
250 {
251  NCMultiSelectionBox * multiSelectionBox = new NCMultiSelectionBox( parent, label );
252  YUI_CHECK_NEW( multiSelectionBox );
253 
254  return multiSelectionBox;
255 }
256 
257 
259 NCWidgetFactory::createItemSelector( YWidget * parent, bool enforceSingleSelection )
260 {
261  NCItemSelector * itemSelector = new NCItemSelector( parent, enforceSingleSelection );
262  YUI_CHECK_NEW( itemSelector );
263 
264  return itemSelector;
265 }
266 
267 
269 NCWidgetFactory::createCustomStatusItemSelector( YWidget * parent, const YItemCustomStatusVector & customStates )
270 {
271  NCCustomStatusItemSelector * itemSelector = new NCCustomStatusItemSelector( parent, customStates );
272  YUI_CHECK_NEW( itemSelector );
273 
274  return itemSelector;
275 }
276 
277 
278 
279 //
280 // Layout Helpers
281 //
282 
283 NCSpacing *
284 NCWidgetFactory::createSpacing( YWidget * parent, YUIDimension dim, bool stretchable, YLayoutSize_t size )
285 {
286  NCSpacing * spacing = new NCSpacing( parent, dim, stretchable, size );
287  YUI_CHECK_NEW( spacing );
288 
289  return spacing;
290 }
291 
292 
293 NCLayoutBox *
294 NCWidgetFactory::createLayoutBox( YWidget * parent, YUIDimension dim )
295 {
296  NCLayoutBox * layoutBox = new NCLayoutBox( parent, dim );
297  YUI_CHECK_NEW( layoutBox );
298 
299  return layoutBox;
300 }
301 
302 
303 NCButtonBox *
304 NCWidgetFactory::createButtonBox( YWidget * parent )
305 {
306  NCButtonBox * buttonBox = new NCButtonBox( parent );
307  YUI_CHECK_NEW( buttonBox );
308 
309  return buttonBox;
310 }
311 
312 
313 NCEmpty *
314 NCWidgetFactory::createEmpty( YWidget * parent )
315 {
316  NCEmpty * empty = new NCEmpty( parent );
317  YUI_CHECK_NEW( empty );
318 
319  return empty;
320 }
321 
322 
323 NCAlignment *
324 NCWidgetFactory::createAlignment( YWidget * parent,
325  YAlignmentType horAlignment,
326  YAlignmentType vertAlignment )
327 {
328  NCAlignment * alignment = new NCAlignment( parent, horAlignment, vertAlignment );
329  YUI_CHECK_NEW( alignment );
330 
331  return alignment;
332 }
333 
334 
335 NCSquash *
336 NCWidgetFactory::createSquash( YWidget * parent, bool horSquash, bool vertSquash )
337 {
338  NCSquash * squash = new NCSquash( parent, horSquash, vertSquash );
339  YUI_CHECK_NEW( squash );
340 
341  return squash;
342 }
343 
344 
345 NCFrame *
346 NCWidgetFactory::createFrame( YWidget * parent, const std::string & label )
347 {
348  NCFrame * frame = new NCFrame( parent, label );
349  YUI_CHECK_NEW( frame );
350 
351  return frame;
352 }
353 
354 
356 NCWidgetFactory::createCheckBoxFrame( YWidget * parent, const std::string & label, bool checked )
357 {
358  NCCheckBoxFrame * checkBoxFrame = new NCCheckBoxFrame( parent, label, checked );
359  YUI_CHECK_NEW( checkBoxFrame );
360 
361  return checkBoxFrame;
362 }
363 
364 
366 NCWidgetFactory::createRadioButtonGroup( YWidget * parent )
367 {
368  NCRadioButtonGroup * radioButtonGroup = new NCRadioButtonGroup( parent );
369  YUI_CHECK_NEW( radioButtonGroup );
370 
371  return radioButtonGroup;
372 }
373 
374 
376 NCWidgetFactory::createReplacePoint( YWidget * parent )
377 {
378  NCReplacePoint * replacePoint = new NCReplacePoint( parent );
379  YUI_CHECK_NEW( replacePoint );
380 
381  return replacePoint;
382 }
383 
384 
385 NCImage *
386 NCWidgetFactory::createImage( YWidget * parent, const std::string & imageFileName, bool animated )
387 {
388  NCImage * image = new NCImage( parent, imageFileName, animated );
389  YUI_CHECK_NEW( image );
390 
391  return image;
392 }
393 
394 
395 YPackageSelector *
396 NCWidgetFactory::createPackageSelector( YWidget * parent, long modeFlags )
397 {
399 
400  if ( plugin )
401  return plugin->createPackageSelector( parent, modeFlags );
402  else
403  return 0;
404 }
405 
406 
407 // Creates special widgets used for the package selection dialog.
408 // This is special to the NCurses UI; there is no a corresponding widget
409 // in the Qt UI.
410 YWidget *
411 NCWidgetFactory::createPkgSpecial( YWidget * parent, const std::string & subwidget )
412 {
413  YWidget * w = 0;
414 
416 
417  if ( plugin )
418  {
419  w = plugin->createPkgSpecial( parent, subwidget );
420  }
421 
422  return w;
423 }
424 
425 
static YNCursesUI * ui()
Access the global Y2NCursesUI.
Definition: YNCursesUI.h:93
NCWidgetFactory()
Constructor.
virtual YWidget * createPkgSpecial(YWidget *parent, const std::string &subwidget)
Create a special widget.
virtual ~NCWidgetFactory()
Destructor.
NCPackageSelectorPluginStub * packageSelectorPlugin()
Returns the package selector plugin singleton of this UI or creates it (including loading the plugin ...
Definition: YNCursesUI.cc:208
Definition: NCTree.h:38
virtual YPackageSelector * createPackageSelector(YWidget *parent, long modeFlags)
Create a package selector.