libyui
3.0.10
|
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: YCheckBoxFrame.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 "YCheckBoxFrame.h" 00031 00032 00033 struct YCheckBoxFramePrivate 00034 { 00035 YCheckBoxFramePrivate( const std::string & label ) 00036 : label( label ) 00037 , autoEnable( true ) 00038 , invertAutoEnable( false ) 00039 {} 00040 00041 std::string label; 00042 bool autoEnable; 00043 bool invertAutoEnable; 00044 }; 00045 00046 00047 00048 00049 YCheckBoxFrame::YCheckBoxFrame( YWidget * parent, 00050 const std::string & label, 00051 bool isChecked ) 00052 : YSingleChildContainerWidget( parent ) 00053 , priv( new YCheckBoxFramePrivate( label ) ) 00054 { 00055 YUI_CHECK_NEW( priv ); 00056 } 00057 00058 00059 YCheckBoxFrame::~YCheckBoxFrame() 00060 { 00061 // NOP 00062 } 00063 00064 00065 std::string YCheckBoxFrame::label() const 00066 { 00067 return priv->label; 00068 } 00069 00070 void YCheckBoxFrame::setLabel( const std::string & label ) 00071 { 00072 priv->label = label; 00073 } 00074 00075 bool YCheckBoxFrame::autoEnable() const 00076 { 00077 return priv->autoEnable; 00078 } 00079 00080 void YCheckBoxFrame::setAutoEnable( bool autoEnable ) 00081 { 00082 // yuiDebug() << "Auto enable: " << boolalpha << autoEnable << std::endl; 00083 priv->autoEnable = autoEnable; 00084 } 00085 00086 bool YCheckBoxFrame::invertAutoEnable() const 00087 { 00088 return priv->invertAutoEnable; 00089 } 00090 00091 void YCheckBoxFrame::setInvertAutoEnable( bool invertAutoEnable ) 00092 { 00093 // yuiDebug() << "Invert auto enable: ", boolalpha << invertAutoEnable << std::endl; 00094 priv->invertAutoEnable = invertAutoEnable; 00095 } 00096 00097 00098 void YCheckBoxFrame::handleChildrenEnablement( bool enabled ) 00099 { 00100 if ( autoEnable() ) 00101 { 00102 if ( invertAutoEnable() ) 00103 enabled = ! enabled; 00104 00105 yuiDebug() << ( enabled ? "Enabling" : "Disabling" ) << " child widgets of " << this << std::endl; 00106 setChildrenEnabled( enabled ); 00107 } 00108 } 00109 00110 00111 const YPropertySet & 00112 YCheckBoxFrame::propertySet() 00113 { 00114 static YPropertySet propSet; 00115 00116 if ( propSet.isEmpty() ) 00117 { 00118 /* 00119 * @property boolean Value the on/off state of the CheckBoxFrame's check box 00120 * @property std::string Label the text on the frame 00121 */ 00122 00123 propSet.add( YProperty( YUIProperty_Value, YBoolProperty ) ); 00124 propSet.add( YProperty( YUIProperty_Label, YStringProperty ) ); 00125 propSet.add( YWidget::propertySet() ); 00126 } 00127 00128 return propSet; 00129 } 00130 00131 00132 bool 00133 YCheckBoxFrame::setProperty( const std::string & propertyName, const YPropertyValue & val ) 00134 { 00135 propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch 00136 00137 if ( propertyName == YUIProperty_Value ) setValue( val.boolVal() ); 00138 else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() ); 00139 else 00140 { 00141 return YWidget::setProperty( propertyName, val ); 00142 } 00143 00144 return true; // success -- no special processing necessary 00145 } 00146 00147 00148 YPropertyValue 00149 YCheckBoxFrame::getProperty( const std::string & propertyName ) 00150 { 00151 propertySet().check( propertyName ); // throws exceptions if not found 00152 00153 if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() ); 00154 else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() ); 00155 else 00156 { 00157 return YWidget::getProperty( propertyName ); 00158 } 00159 }