libyui-ncurses  2.57.2
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 
228 NCMenuBar *
229 NCWidgetFactory::createMenuBar( YWidget * parent )
230 {
231  NCMenuBar * menuBar = new NCMenuBar( parent );
232  YUI_CHECK_NEW( menuBar );
233 
234  return menuBar;
235 }
236 
237 
239 NCWidgetFactory::createMultiLineEdit( YWidget * parent, const std::string & label )
240 {
241  NCMultiLineEdit * multiLineEdit = new NCMultiLineEdit( parent, label );
242  YUI_CHECK_NEW( multiLineEdit );
243 
244  return multiLineEdit;
245 }
246 
247 
248 NCLogView *
249 NCWidgetFactory::createLogView( YWidget * parent, const std::string & label, int visibleLines, int storedLines )
250 {
251  NCLogView * logView = new NCLogView( parent, label, visibleLines, storedLines );
252  YUI_CHECK_NEW( logView );
253 
254  return logView;
255 }
256 
257 
259 NCWidgetFactory::createMultiSelectionBox( YWidget * parent, const std::string & label )
260 {
261  NCMultiSelectionBox * multiSelectionBox = new NCMultiSelectionBox( parent, label );
262  YUI_CHECK_NEW( multiSelectionBox );
263 
264  return multiSelectionBox;
265 }
266 
267 
269 NCWidgetFactory::createItemSelector( YWidget * parent, bool enforceSingleSelection )
270 {
271  NCItemSelector * itemSelector = new NCItemSelector( parent, enforceSingleSelection );
272  YUI_CHECK_NEW( itemSelector );
273 
274  return itemSelector;
275 }
276 
277 
279 NCWidgetFactory::createCustomStatusItemSelector( YWidget * parent, const YItemCustomStatusVector & customStates )
280 {
281  NCCustomStatusItemSelector * itemSelector = new NCCustomStatusItemSelector( parent, customStates );
282  YUI_CHECK_NEW( itemSelector );
283 
284  return itemSelector;
285 }
286 
287 
288 
289 //
290 // Layout Helpers
291 //
292 
293 NCSpacing *
294 NCWidgetFactory::createSpacing( YWidget * parent, YUIDimension dim, bool stretchable, YLayoutSize_t size )
295 {
296  NCSpacing * spacing = new NCSpacing( parent, dim, stretchable, size );
297  YUI_CHECK_NEW( spacing );
298 
299  return spacing;
300 }
301 
302 
303 NCLayoutBox *
304 NCWidgetFactory::createLayoutBox( YWidget * parent, YUIDimension dim )
305 {
306  NCLayoutBox * layoutBox = new NCLayoutBox( parent, dim );
307  YUI_CHECK_NEW( layoutBox );
308 
309  return layoutBox;
310 }
311 
312 
313 NCButtonBox *
314 NCWidgetFactory::createButtonBox( YWidget * parent )
315 {
316  NCButtonBox * buttonBox = new NCButtonBox( parent );
317  YUI_CHECK_NEW( buttonBox );
318 
319  return buttonBox;
320 }
321 
322 
323 NCEmpty *
324 NCWidgetFactory::createEmpty( YWidget * parent )
325 {
326  NCEmpty * empty = new NCEmpty( parent );
327  YUI_CHECK_NEW( empty );
328 
329  return empty;
330 }
331 
332 
333 NCAlignment *
334 NCWidgetFactory::createAlignment( YWidget * parent,
335  YAlignmentType horAlignment,
336  YAlignmentType vertAlignment )
337 {
338  NCAlignment * alignment = new NCAlignment( parent, horAlignment, vertAlignment );
339  YUI_CHECK_NEW( alignment );
340 
341  return alignment;
342 }
343 
344 
345 NCSquash *
346 NCWidgetFactory::createSquash( YWidget * parent, bool horSquash, bool vertSquash )
347 {
348  NCSquash * squash = new NCSquash( parent, horSquash, vertSquash );
349  YUI_CHECK_NEW( squash );
350 
351  return squash;
352 }
353 
354 
355 NCFrame *
356 NCWidgetFactory::createFrame( YWidget * parent, const std::string & label )
357 {
358  NCFrame * frame = new NCFrame( parent, label );
359  YUI_CHECK_NEW( frame );
360 
361  return frame;
362 }
363 
364 
366 NCWidgetFactory::createCheckBoxFrame( YWidget * parent, const std::string & label, bool checked )
367 {
368  NCCheckBoxFrame * checkBoxFrame = new NCCheckBoxFrame( parent, label, checked );
369  YUI_CHECK_NEW( checkBoxFrame );
370 
371  return checkBoxFrame;
372 }
373 
374 
376 NCWidgetFactory::createRadioButtonGroup( YWidget * parent )
377 {
378  NCRadioButtonGroup * radioButtonGroup = new NCRadioButtonGroup( parent );
379  YUI_CHECK_NEW( radioButtonGroup );
380 
381  return radioButtonGroup;
382 }
383 
384 
386 NCWidgetFactory::createReplacePoint( YWidget * parent )
387 {
388  NCReplacePoint * replacePoint = new NCReplacePoint( parent );
389  YUI_CHECK_NEW( replacePoint );
390 
391  return replacePoint;
392 }
393 
394 
395 NCImage *
396 NCWidgetFactory::createImage( YWidget * parent, const std::string & imageFileName, bool animated )
397 {
398  NCImage * image = new NCImage( parent, imageFileName, animated );
399  YUI_CHECK_NEW( image );
400 
401  return image;
402 }
403 
404 
405 YPackageSelector *
406 NCWidgetFactory::createPackageSelector( YWidget * parent, long modeFlags )
407 {
409 
410  if ( plugin )
411  return plugin->createPackageSelector( parent, modeFlags );
412  else
413  return 0;
414 }
415 
416 
417 // Creates special widgets used for the package selection dialog.
418 // This is special to the NCurses UI; there is no a corresponding widget
419 // in the Qt UI.
420 YWidget *
421 NCWidgetFactory::createPkgSpecial( YWidget * parent, const std::string & subwidget )
422 {
423  YWidget * w = 0;
424 
426 
427  if ( plugin )
428  {
429  w = plugin->createPkgSpecial( parent, subwidget );
430  }
431 
432  return w;
433 }
434 
435 
NCTree
A tree selection widget with one-column tree items and optionally multy selection.
Definition: NCTree.h:47
NCRadioButton
Definition: NCRadioButton.h:37
NCLayoutBox
Definition: NCLayoutBox.h:37
YNCursesUI::ui
static YNCursesUI * ui()
Access the global Y2NCursesUI.
Definition: YNCursesUI.h:93
NCDialog
Definition: NCDialog.h:40
NCSpacing
Definition: NCSpacing.h:37
NCComboBox
Definition: NCComboBox.h:38
NCProgressBar
Definition: NCProgressBar.h:37
NCBusyIndicator
Definition: NCBusyIndicator.h:42
NCAlignment
Definition: NCAlignment.h:35
NCLogView
Definition: NCLogView.h:35
NCPushButton
Definition: NCPushButton.h:35
NCPackageSelectorPluginStub::createPkgSpecial
virtual YWidget * createPkgSpecial(YWidget *parent, const std::string &subwidget)
Create a special widget.
Definition: NCPackageSelectorPluginStub.cc:71
NCItemSelector
Definition: NCItemSelector.h:302
NCMenuButton
Definition: NCMenuButton.h:36
NCMenuBar
Definition: NCMenuBar.h:34
NCCheckBox
Definition: NCCheckBox.h:35
NCTable
A table with rows and columns.
Definition: NCTable.h:43
YNCursesUI::packageSelectorPlugin
NCPackageSelectorPluginStub * packageSelectorPlugin()
Returns the package selector plugin singleton of this UI or creates it (including loading the plugin ...
Definition: YNCursesUI.cc:209
NCRadioButtonGroup
Definition: NCRadioButtonGroup.h:38
NCPackageSelectorPluginStub
Definition: NCPackageSelectorPluginStub.h:41
NCMultiSelectionBox
Definition: NCMultiSelectionBox.h:36
NCWidgetFactory::~NCWidgetFactory
virtual ~NCWidgetFactory()
Destructor.
Definition: NCWidgetFactory.cc:44
NCSquash
Definition: NCSquash.h:35
NCLabel
Definition: NCLabel.h:38
NCCheckBoxFrame
Definition: NCCheckBoxFrame.h:38
NCButtonBox
Definition: NCButtonBox.h:37
NCIntField
Definition: NCIntField.h:35
NCFrame
Definition: NCFrame.h:37
NCPackageSelectorPluginStub::createPackageSelector
virtual YPackageSelector * createPackageSelector(YWidget *parent, long modeFlags)
Create a package selector.
Definition: NCPackageSelectorPluginStub.cc:64
NCMultiLineEdit
Definition: NCMultiLineEdit.h:36
NCImage
Definition: NCImage.h:37
NCCustomStatusItemSelector
Definition: NCCustomStatusItemSelector.h:82
NCInputField
Definition: NCInputField.h:35
NCReplacePoint
Definition: NCReplacePoint.h:37
NCRichText
Definition: NCRichText.h:36
NCWidgetFactory::NCWidgetFactory
NCWidgetFactory()
Constructor.
Definition: NCWidgetFactory.cc:37
NCEmpty
Definition: NCEmpty.h:35
NCSelectionBox
Definition: NCSelectionBox.h:36