• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_MessageStyle.h

Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009     
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014     
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019     
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #ifndef __MYGUI_MESSAGE_BOX_STYLE_H__
00024 #define __MYGUI_MESSAGE_BOX_STYLE_H__
00025 
00026 #include "MyGUI_Prerequest.h"
00027 #include "MyGUI_Common.h"
00028 
00029 namespace MyGUI
00030 {
00031 
00032 
00033     struct MYGUI_EXPORT MessageBoxStyle
00034     {
00035 
00036         enum Enum
00037         {
00038             None = MYGUI_FLAG_NONE,
00039             Ok = MYGUI_FLAG(0),
00040             Yes = MYGUI_FLAG(1),
00041             No = MYGUI_FLAG(2),
00042             Abort = MYGUI_FLAG(3),
00043             Retry = MYGUI_FLAG(4),
00044             Ignore = MYGUI_FLAG(5),
00045             Cancel = MYGUI_FLAG(6),
00046             Try = MYGUI_FLAG(7),
00047             Continue = MYGUI_FLAG(8),
00048 
00049             _IndexUserButton1 = 9, // индекс первой кнопки юзера
00050 
00051             Button1 = MYGUI_FLAG(_IndexUserButton1),
00052             Button2 = MYGUI_FLAG(_IndexUserButton1 + 1),
00053             Button3 = MYGUI_FLAG(_IndexUserButton1 + 2),
00054             Button4 = MYGUI_FLAG(_IndexUserButton1 + 3),
00055 
00056             _CountUserButtons = 4, // колличество кнопок юзера
00057             _IndexIcon1 = _IndexUserButton1 + _CountUserButtons, // индекс первой иконки
00058 
00059             IconDefault = MYGUI_FLAG(_IndexIcon1),
00060 
00061             IconInfo = MYGUI_FLAG(_IndexIcon1),
00062             IconQuest = MYGUI_FLAG(_IndexIcon1 + 1),
00063             IconError = MYGUI_FLAG(_IndexIcon1 + 2),
00064             IconWarning = MYGUI_FLAG(_IndexIcon1 + 3),
00065 
00066             Icon1 = MYGUI_FLAG(_IndexIcon1),
00067             Icon2 = MYGUI_FLAG(_IndexIcon1 + 1),
00068             Icon3 = MYGUI_FLAG(_IndexIcon1 + 2),
00069             Icon4 = MYGUI_FLAG(_IndexIcon1 + 3),
00070             Icon5 = MYGUI_FLAG(_IndexIcon1 + 4),
00071             Icon6 = MYGUI_FLAG(_IndexIcon1 + 5),
00072             Icon7 = MYGUI_FLAG(_IndexIcon1 + 6),
00073             Icon8 = MYGUI_FLAG(_IndexIcon1 + 7)
00074         };
00075 
00076         MessageBoxStyle(Enum _value = None) : value(_value) { }
00077 
00078         MessageBoxStyle& operator |= (MessageBoxStyle const& _other) { value = Enum(int(value) | int(_other.value)); return *this; }
00079         friend MessageBoxStyle operator | (Enum const& a, Enum const& b) { return MessageBoxStyle(Enum(int(a) | int(b))); }
00080         MessageBoxStyle operator | (Enum const& a) { return MessageBoxStyle(Enum(int(value) | int(a))); }
00081 
00082         friend bool operator == (MessageBoxStyle const& a, MessageBoxStyle const& b) { return a.value == b.value; }
00083         friend bool operator != (MessageBoxStyle const& a, MessageBoxStyle const& b) { return a.value != b.value; }
00084 
00085         // возвращает индекс иконки
00086         size_t getIconIndex()
00087         {
00088             size_t index = 0;
00089             int num = value >> _IndexIcon1;
00090 
00091             while (num != 0)
00092             {
00093                 if ((num & 1) == 1) return index;
00094 
00095                 ++index;
00096                 num >>= 1;
00097             }
00098 
00099             return ITEM_NONE;
00100         }
00101 
00102         // возвращает индекс иконки
00103         size_t getButtonIndex()
00104         {
00105             size_t index = 0;
00106             int num = value;
00107 
00108             while (num != 0)
00109             {
00110                 if ((num & 1) == 1) return index;
00111 
00112                 ++index;
00113                 num >>= 1;
00114             }
00115 
00116             return ITEM_NONE;
00117         }
00118 
00119         // возвращает список кнопок
00120         std::vector<MessageBoxStyle> getButtons()
00121         {
00122             std::vector<MessageBoxStyle> buttons;
00123 
00124             size_t index = 0;
00125             int num = value;
00126             while (index < _IndexIcon1)
00127             {
00128                 if ((num & 1) == 1)
00129                 {
00130                     buttons.push_back( MessageBoxStyle::Enum( MYGUI_FLAG(index) ) );
00131                 }
00132 
00133                 ++index;
00134                 num >>= 1;
00135             }
00136 
00137             return buttons;
00138         }
00139 
00140         typedef std::map<std::string, int> MapAlign;
00141 
00142         static MessageBoxStyle parse(const std::string& _value)
00143         {
00144             MessageBoxStyle result(MessageBoxStyle::Enum(0));
00145             const MapAlign& map_names = result.getValueNames();
00146             const std::vector<std::string>& vec = utility::split(_value);
00147             for (size_t pos=0; pos<vec.size(); pos++)
00148             {
00149                 MapAlign::const_iterator iter = map_names.find(vec[pos]);
00150                 if (iter != map_names.end())
00151                 {
00152                     result.value = Enum(int(result.value) | int(iter->second));
00153                 }
00154                 else
00155                 {
00156                     MYGUI_LOG(Warning, "Cannot parse type '" << vec[pos] << "'");
00157                 }
00158             }
00159             return result;
00160         }
00161 
00162     private:
00163         const MapAlign& getValueNames()
00164         {
00165             static MapAlign map_names;
00166 
00167             if (map_names.empty())
00168             {
00169                 MYGUI_REGISTER_VALUE(map_names, None);
00170                 MYGUI_REGISTER_VALUE(map_names, Ok);
00171                 MYGUI_REGISTER_VALUE(map_names, Yes);
00172                 MYGUI_REGISTER_VALUE(map_names, No);
00173                 MYGUI_REGISTER_VALUE(map_names, Abort);
00174                 MYGUI_REGISTER_VALUE(map_names, Retry);
00175                 MYGUI_REGISTER_VALUE(map_names, Ignore);
00176                 MYGUI_REGISTER_VALUE(map_names, Cancel);
00177                 MYGUI_REGISTER_VALUE(map_names, Try);
00178                 MYGUI_REGISTER_VALUE(map_names, Continue);
00179 
00180                 MYGUI_REGISTER_VALUE(map_names, Button1);
00181                 MYGUI_REGISTER_VALUE(map_names, Button2);
00182                 MYGUI_REGISTER_VALUE(map_names, Button3);
00183                 MYGUI_REGISTER_VALUE(map_names, Button4);
00184 
00185                 MYGUI_REGISTER_VALUE(map_names, IconDefault);
00186 
00187                 MYGUI_REGISTER_VALUE(map_names, IconInfo);
00188                 MYGUI_REGISTER_VALUE(map_names, IconQuest);
00189                 MYGUI_REGISTER_VALUE(map_names, IconError);
00190                 MYGUI_REGISTER_VALUE(map_names, IconWarning);
00191 
00192                 MYGUI_REGISTER_VALUE(map_names, Icon1);
00193                 MYGUI_REGISTER_VALUE(map_names, Icon2);
00194                 MYGUI_REGISTER_VALUE(map_names, Icon3);
00195                 MYGUI_REGISTER_VALUE(map_names, Icon4);
00196                 MYGUI_REGISTER_VALUE(map_names, Icon5);
00197                 MYGUI_REGISTER_VALUE(map_names, Icon6);
00198                 MYGUI_REGISTER_VALUE(map_names, Icon7);
00199                 MYGUI_REGISTER_VALUE(map_names, Icon8);
00200             }
00201 
00202             return map_names;
00203         }
00204 
00205     private:
00206         Enum value;
00207     };
00208 
00209 } // namespace MyGUI
00210 
00211 #endif // __MYGUI_MESSAGE_BOX_STYLE_H__

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1