libyui  3.0.10
/usr/src/RPM/BUILD/libyui-3.0.10/src/YRadioButtonGroup.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:         YRadioButtonGroup.cc
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "ui"
00027 #include "YUILog.h"
00028 
00029 #include "YUISymbols.h"
00030 #include "YRadioButton.h"
00031 #include "YRadioButtonGroup.h"
00032 
00033 
00034 struct YRadioButtonGroupPrivate
00035 {
00036     YRadioButtonGroupPrivate()
00037         {}
00038 
00039 
00040     YRadioButtonList buttonList;
00041 };
00042 
00043 
00044 
00045 
00046 YRadioButtonGroup::YRadioButtonGroup( YWidget * parent )
00047     : YSingleChildContainerWidget( parent )
00048     , priv( new YRadioButtonGroupPrivate() )
00049 {
00050     YUI_CHECK_NEW( priv );
00051 }
00052 
00053 
00054 YRadioButtonGroup::~YRadioButtonGroup()
00055 {
00056 }
00057 
00058 
00059 YRadioButtonListConstIterator
00060 YRadioButtonGroup::radioButtonsBegin() const
00061 {
00062     return priv->buttonList.begin();
00063 }
00064 
00065 
00066 YRadioButtonListConstIterator
00067 YRadioButtonGroup::radioButtonsEnd() const
00068 {
00069     return priv->buttonList.end();
00070 }
00071 
00072 
00073 int
00074 YRadioButtonGroup::radioButtonsCount() const
00075 {
00076     return priv->buttonList.size();
00077 }
00078 
00079 
00080 void
00081 YRadioButtonGroup::addRadioButton( YRadioButton * button )
00082 {
00083     priv->buttonList.push_back( button );
00084 }
00085 
00086 
00087 void
00088 YRadioButtonGroup::removeRadioButton( YRadioButton * button )
00089 {
00090     priv->buttonList.remove( button );
00091 }
00092 
00093 
00094 void
00095 YRadioButtonGroup::uncheckOtherButtons( YRadioButton * selectedRadioButton )
00096 {
00097     for ( YRadioButtonListConstIterator it = radioButtonsBegin();
00098           it != radioButtonsEnd();
00099           ++it )
00100     {
00101         if ( *it != selectedRadioButton )
00102             (*it)->setValue( false );
00103     }
00104 }
00105 
00106 
00107 YRadioButton *
00108 YRadioButtonGroup::currentButton() const
00109 {
00110     for ( YRadioButtonListConstIterator it = radioButtonsBegin();
00111           it != radioButtonsEnd();
00112           ++it )
00113     {
00114         if ( (*it)->value() )
00115             return *it;
00116     }
00117 
00118     return 0;
00119 }
00120 
00121 
00122 const YPropertySet &
00123 YRadioButtonGroup::propertySet()
00124 {
00125     static YPropertySet propSet;
00126 
00127     if ( propSet.isEmpty() )
00128     {
00129         /*
00130          * @property any CurrentButton  widget ID of the currently selected RadioButton of this group
00131          * @property any Value          Alias for CurrentButton
00132          */
00133         propSet.add( YProperty( YUIProperty_Value,              YOtherProperty ) );
00134         propSet.add( YProperty( YUIProperty_CurrentButton,      YOtherProperty ) );
00135         propSet.add( YWidget::propertySet() );
00136     }
00137 
00138     return propSet;
00139 }
00140 
00141 
00142 bool
00143 YRadioButtonGroup::setProperty( const std::string & propertyName, const YPropertyValue & val )
00144 {
00145     propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
00146 
00147     if ( propertyName == YUIProperty_CurrentButton ||
00148          propertyName == YUIProperty_Value )            return false; // Needs special handling
00149     else
00150     {
00151         return YWidget::setProperty( propertyName, val );
00152     }
00153 
00154     return true; // success -- no special processing necessary
00155 }
00156 
00157 
00158 YPropertyValue
00159 YRadioButtonGroup::getProperty( const std::string & propertyName )
00160 {
00161     propertySet().check( propertyName ); // throws exceptions if not found
00162 
00163     if ( propertyName == YUIProperty_CurrentButton ||
00164          propertyName == YUIProperty_Value )            return YPropertyValue( YOtherProperty );
00165     else
00166     {
00167         return YWidget::getProperty( propertyName );
00168     }
00169 }
 All Classes Functions Variables Enumerations Friends