libyui-ncurses  2.44.1
/usr/src/RPM/BUILD/libyui-ncurses-2.44.1/src/NCWidgetFactory.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:         NCWidgetFactory.cc
00020 
00021   Authors:      Stefan Hundhammer <sh@suse.de>
00022                 Gabriele Mohr <gs@suse.de>
00023 
00024 /-*/
00025 
00026 #include "NCWidgetFactory.h"
00027 #include <yui/YUIException.h>
00028 
00029 #define  YUILogComponent "ncurses"
00030 #include <yui/YUILog.h>
00031 #include "YNCursesUI.h"
00032 
00033 #include <string>
00034 
00035 
00036 NCWidgetFactory::NCWidgetFactory()
00037     : YWidgetFactory()
00038 {
00039     // NOP
00040 }
00041 
00042 NCWidgetFactory::~NCWidgetFactory()
00043 {
00044     // NOP
00045 }
00046 
00047 
00048 
00049 
00050 //
00051 // Dialogs
00052 //
00053 
00054 NCDialog *
00055 NCWidgetFactory::createDialog( YDialogType dialogType, YDialogColorMode colorMode )
00056 {
00057     yuiDebug() << "Flush input buffer - new dialog" << std::endl;
00058     ::flushinp();
00059 
00060     NCDialog * dialog = new NCDialog( dialogType, colorMode );
00061     YUI_CHECK_NEW( dialog );
00062 
00063     return dialog;
00064 }
00065 
00066 
00067 //
00068 // Common Leaf Widgets
00069 //
00070 
00071 NCPushButton *
00072 NCWidgetFactory::createPushButton( YWidget * parent, const std::string & label )
00073 {
00074     NCPushButton * pushButton = new NCPushButton( parent, label );
00075     YUI_CHECK_NEW( pushButton );
00076 
00077     return pushButton;
00078 }
00079 
00080 
00081 
00082 NCLabel *
00083 NCWidgetFactory::createLabel( YWidget *         parent,
00084                               const std::string &       text,
00085                               bool              isHeading,
00086                               bool              isOutputField )
00087 {
00088     NCLabel * label = new NCLabel( parent, text, isHeading, isOutputField );
00089     YUI_CHECK_NEW( label );
00090 
00091     return label;
00092 }
00093 
00094 
00095 
00096 NCInputField *
00097 NCWidgetFactory::createInputField( YWidget * parent, const std::string & label, bool passwordMode )
00098 {
00099     NCInputField * inputField = new NCInputField( parent, label, passwordMode );
00100     YUI_CHECK_NEW( inputField );
00101 
00102     return inputField;
00103 }
00104 
00105 
00106 
00107 NCCheckBox *
00108 NCWidgetFactory::createCheckBox( YWidget * parent, const std::string & label, bool isChecked )
00109 {
00110     NCCheckBox * checkBox = new NCCheckBox( parent, label, isChecked );
00111     YUI_CHECK_NEW( checkBox );
00112 
00113     return checkBox;
00114 }
00115 
00116 
00117 
00118 NCRadioButton *
00119 NCWidgetFactory::createRadioButton( YWidget * parent, const std::string & label, bool checked )
00120 {
00121     NCRadioButton * radioButton = new NCRadioButton( parent, label, checked );
00122     YUI_CHECK_NEW( radioButton );
00123 
00124     // Register radio button with its button group.
00125     // This has to be done after all constructors are done so virtual functions
00126     // can be used.
00127 
00128     if ( radioButton->buttonGroup() )
00129         radioButton->buttonGroup()->addRadioButton( radioButton );
00130 
00131     return radioButton;
00132 }
00133 
00134 
00135 
00136 NCComboBox *
00137 NCWidgetFactory::createComboBox( YWidget * parent, const std::string & label, bool editable     )
00138 {
00139     NCComboBox * comboBox = new NCComboBox( parent, label, editable );
00140     YUI_CHECK_NEW( comboBox );
00141 
00142     return comboBox;
00143 }
00144 
00145 
00146 
00147 NCSelectionBox *
00148 NCWidgetFactory::createSelectionBox( YWidget * parent, const std::string & label )
00149 {
00150     NCSelectionBox * selectionBox = new NCSelectionBox( parent, label );
00151     YUI_CHECK_NEW( selectionBox );
00152 
00153     return selectionBox;
00154 }
00155 
00156 
00157 
00158 NCTree *
00159 NCWidgetFactory::createTree( YWidget * parent, const std::string & label, bool multiselection, bool recursiveselection )
00160 {
00161     NCTree * tree = new NCTree( parent, label, multiselection, recursiveselection );
00162     YUI_CHECK_NEW( tree );
00163 
00164     return tree;
00165 }
00166 
00167 
00168 
00169 NCTable *
00170 NCWidgetFactory::createTable( YWidget * parent, YTableHeader * tableHeader, bool multiSelection )
00171 {
00172     NCTable *table = new NCTable( parent, tableHeader, multiSelection );
00173     YUI_CHECK_NEW( table );
00174 
00175     return table;
00176 }
00177 
00178 
00179 
00180 NCProgressBar *
00181 NCWidgetFactory::createProgressBar( YWidget * parent, const std::string & label, int maxValue )
00182 {
00183     NCProgressBar * progressBar = new NCProgressBar( parent, label, maxValue );
00184     YUI_CHECK_NEW( progressBar );
00185 
00186     return progressBar;
00187 }
00188 
00189 NCBusyIndicator *
00190 NCWidgetFactory::createBusyIndicator( YWidget * parent, const std::string & label, int timeout)
00191 {
00192    NCBusyIndicator * busyIndicator = new NCBusyIndicator( parent, label, timeout );
00193    YUI_CHECK_NEW( busyIndicator );
00194 
00195    return busyIndicator;
00196 }
00197 
00198 NCRichText *
00199 NCWidgetFactory::createRichText( YWidget * parent, const std::string & text, bool plainTextMode )
00200 {
00201     NCRichText * richText = new NCRichText( parent, text, plainTextMode );
00202     YUI_CHECK_NEW( richText );
00203 
00204     return richText;
00205 }
00206 
00207 //
00208 // Less Common Leaf Widgets
00209 //
00210 
00211 NCIntField *
00212 NCWidgetFactory::createIntField( YWidget * parent, const std::string & label, int minVal, int maxVal, int initialVal )
00213 {
00214     NCIntField * intField = new NCIntField( parent, label, minVal, maxVal, initialVal );
00215     YUI_CHECK_NEW( intField );
00216 
00217     return intField;
00218 }
00219 
00220 
00221 
00222 NCMenuButton *
00223 NCWidgetFactory::createMenuButton( YWidget * parent, const std::string & label )
00224 {
00225     NCMenuButton * menuButton = new NCMenuButton( parent, label );
00226     YUI_CHECK_NEW( menuButton );
00227 
00228     return menuButton;
00229 }
00230 
00231 
00232 
00233 NCMultiLineEdit *
00234 NCWidgetFactory::createMultiLineEdit( YWidget * parent, const std::string & label )
00235 {
00236     NCMultiLineEdit * multiLineEdit = new NCMultiLineEdit( parent, label );
00237     YUI_CHECK_NEW( multiLineEdit );
00238 
00239     return multiLineEdit;
00240 }
00241 
00242 NCLogView *
00243 NCWidgetFactory::createLogView( YWidget * parent, const std::string & label, int visibleLines, int storedLines )
00244 {
00245     NCLogView * logView = new NCLogView( parent, label, visibleLines, storedLines );
00246     YUI_CHECK_NEW( logView );
00247 
00248     return logView;
00249 }
00250 
00251 
00252 
00253 NCMultiSelectionBox *
00254 NCWidgetFactory::createMultiSelectionBox( YWidget * parent, const std::string & label )
00255 {
00256     NCMultiSelectionBox * multiSelectionBox = new NCMultiSelectionBox( parent, label );
00257     YUI_CHECK_NEW( multiSelectionBox );
00258 
00259     return multiSelectionBox;
00260 }
00261 
00262 
00263 //
00264 // Layout Helpers
00265 //
00266 
00267 NCSpacing *
00268 NCWidgetFactory::createSpacing( YWidget * parent, YUIDimension dim, bool stretchable, YLayoutSize_t size )
00269 {
00270     NCSpacing * spacing = new NCSpacing( parent, dim, stretchable, size );
00271     YUI_CHECK_NEW( spacing );
00272 
00273     return spacing;
00274 }
00275 
00276 NCLayoutBox *
00277 NCWidgetFactory::createLayoutBox( YWidget * parent, YUIDimension dim )
00278 {
00279     NCLayoutBox * layoutBox = new NCLayoutBox( parent, dim );
00280     YUI_CHECK_NEW( layoutBox );
00281 
00282     return layoutBox;
00283 }
00284 
00285 
00286 NCButtonBox *
00287 NCWidgetFactory::createButtonBox( YWidget * parent )
00288 {
00289     NCButtonBox * buttonBox = new NCButtonBox( parent );
00290     YUI_CHECK_NEW( buttonBox );
00291 
00292     return buttonBox;
00293 }
00294 
00295 
00296 NCEmpty *
00297 NCWidgetFactory::createEmpty( YWidget * parent )
00298 {
00299     NCEmpty * empty = new NCEmpty( parent );
00300     YUI_CHECK_NEW( empty );
00301 
00302     return empty;
00303 }
00304 
00305 
00306 
00307 NCAlignment *
00308 NCWidgetFactory::createAlignment( YWidget *      parent,
00309                                   YAlignmentType horAlignment,
00310                                   YAlignmentType vertAlignment )
00311 {
00312     NCAlignment * alignment = new NCAlignment( parent, horAlignment, vertAlignment );
00313     YUI_CHECK_NEW( alignment );
00314 
00315     return alignment;
00316 }
00317 
00318 
00319 NCSquash *
00320 NCWidgetFactory::createSquash( YWidget * parent, bool horSquash, bool vertSquash )
00321 {
00322     NCSquash * squash = new NCSquash( parent, horSquash, vertSquash );
00323     YUI_CHECK_NEW( squash );
00324 
00325     return squash;
00326 }
00327 
00328 
00329 
00330 NCFrame *
00331 NCWidgetFactory::createFrame( YWidget * parent, const std::string & label )
00332 {
00333     NCFrame * frame = new NCFrame( parent, label );
00334     YUI_CHECK_NEW( frame );
00335 
00336     return frame;
00337 }
00338 
00339 
00340 
00341 NCCheckBoxFrame *
00342 NCWidgetFactory::createCheckBoxFrame( YWidget * parent, const std::string & label, bool checked )
00343 {
00344     NCCheckBoxFrame * checkBoxFrame = new NCCheckBoxFrame( parent, label, checked );
00345     YUI_CHECK_NEW( checkBoxFrame );
00346 
00347     return checkBoxFrame;
00348 }
00349 
00350 
00351 
00352 NCRadioButtonGroup *
00353 NCWidgetFactory::createRadioButtonGroup( YWidget * parent )
00354 {
00355     NCRadioButtonGroup * radioButtonGroup = new NCRadioButtonGroup( parent );
00356     YUI_CHECK_NEW( radioButtonGroup );
00357 
00358     return radioButtonGroup;
00359 }
00360 
00361 
00362 
00363 NCReplacePoint *
00364 NCWidgetFactory::createReplacePoint( YWidget * parent )
00365 {
00366     NCReplacePoint * replacePoint = new NCReplacePoint( parent );
00367     YUI_CHECK_NEW( replacePoint );
00368 
00369     return replacePoint;
00370 }
00371 
00372 NCImage *
00373 NCWidgetFactory::createImage( YWidget * parent, const std::string & imageFileName, bool animated )
00374 {
00375     NCImage * image = new NCImage( parent, imageFileName, animated );
00376     YUI_CHECK_NEW( image );
00377 
00378     return image;
00379 }
00380 
00381 
00382 YPackageSelector *
00383 NCWidgetFactory::createPackageSelector( YWidget * parent, long modeFlags )
00384 {
00385     NCPackageSelectorPluginStub * plugin = YNCursesUI::ui()->packageSelectorPlugin();
00386 
00387     if ( plugin )
00388         return plugin->createPackageSelector( parent, modeFlags );
00389     else
00390         return 0;
00391 }
00392 
00393 
00394 // Creates special widgets used for the package selection dialog.
00395 // This is special to the NCurses UI;  there is no  a corresponding widget
00396 // in the Qt UI.
00397 YWidget *
00398 NCWidgetFactory::createPkgSpecial( YWidget * parent, const std::string & subwidget )
00399 {
00400     YWidget * w = 0;
00401 
00402     NCPackageSelectorPluginStub * plugin = YNCursesUI::ui()->packageSelectorPlugin();
00403 
00404     if ( plugin )
00405     {
00406         w = plugin->createPkgSpecial( parent, subwidget );
00407     }
00408 
00409     return w;
00410 }
00411 
00412 
 All Classes Functions Variables