MyGUI  3.2.0
MyGUI_WidgetStyle.h
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #ifndef __MYGUI_WIDGET_STYLE_H__
00023 #define __MYGUI_WIDGET_STYLE_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 #include <string.h>
00027 
00028 namespace MyGUI
00029 {
00030 
00031     struct MYGUI_EXPORT WidgetStyle
00032     {
00033         enum Enum
00034         {
00035             Child, 
00036             Popup, 
00037             Overlapped, 
00038             MAX
00039         };
00040 
00041         WidgetStyle() :
00042             value(MAX)
00043         {
00044         }
00045 
00046         WidgetStyle(Enum _value) :
00047             value(_value)
00048         {
00049         }
00050 
00051         static WidgetStyle parse(const std::string& _value)
00052         {
00053             WidgetStyle type;
00054             int value = 0;
00055             while (true)
00056             {
00057                 const char* name = type.getValueName(value);
00058                 if (strcmp(name, "") == 0 || name == _value)
00059                     break;
00060                 value++;
00061             }
00062             type.value = (Enum)value;
00063             return type;
00064         }
00065 
00066         friend bool operator == (WidgetStyle const& a, WidgetStyle const& b)
00067         {
00068             return a.value == b.value;
00069         }
00070 
00071         friend bool operator != (WidgetStyle const& a, WidgetStyle const& b)
00072         {
00073             return a.value != b.value;
00074         }
00075 
00076         friend std::ostream& operator << (std::ostream& _stream, const WidgetStyle&  _value)
00077         {
00078             _stream << _value.getValueName(_value.value);
00079             return _stream;
00080         }
00081 
00082         friend std::istream& operator >> (std::istream& _stream, WidgetStyle&  _value)
00083         {
00084             std::string value;
00085             _stream >> value;
00086             _value = parse(value);
00087             return _stream;
00088         }
00089 
00090         std::string print() const
00091         {
00092             return getValueName(value);
00093         }
00094 
00095     private:
00096         const char* getValueName(int _index) const
00097         {
00098             static const char* values[MAX + 1] = { "Child", "Popup", "Overlapped", "" };
00099             return values[(_index < MAX && _index >= 0) ? _index : MAX];
00100         }
00101 
00102     private:
00103         Enum value;
00104     };
00105 
00106 } // namespace MyGUI
00107 
00108 #endif // __MYGUI_WIDGET_STYLE_H__