MyGUI
3.0.3
|
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 00028 namespace MyGUI 00029 { 00030 00031 00032 struct MYGUI_EXPORT MessageBoxStyle 00033 { 00034 00035 enum Enum 00036 { 00037 None = MYGUI_FLAG_NONE, 00038 Ok = MYGUI_FLAG(0), 00039 Yes = MYGUI_FLAG(1), 00040 No = MYGUI_FLAG(2), 00041 Abort = MYGUI_FLAG(3), 00042 Retry = MYGUI_FLAG(4), 00043 Ignore = MYGUI_FLAG(5), 00044 Cancel = MYGUI_FLAG(6), 00045 Try = MYGUI_FLAG(7), 00046 Continue = MYGUI_FLAG(8), 00047 00048 _IndexUserButton1 = 9, // индекс первой кнопки юзера 00049 00050 Button1 = MYGUI_FLAG(_IndexUserButton1), 00051 Button2 = MYGUI_FLAG(_IndexUserButton1 + 1), 00052 Button3 = MYGUI_FLAG(_IndexUserButton1 + 2), 00053 Button4 = MYGUI_FLAG(_IndexUserButton1 + 3), 00054 00055 _CountUserButtons = 4, // колличество кнопок юзера 00056 _IndexIcon1 = _IndexUserButton1 + _CountUserButtons, // индекс первой иконки 00057 00058 IconDefault = MYGUI_FLAG(_IndexIcon1), 00059 00060 IconInfo = MYGUI_FLAG(_IndexIcon1), 00061 IconQuest = MYGUI_FLAG(_IndexIcon1 + 1), 00062 IconError = MYGUI_FLAG(_IndexIcon1 + 2), 00063 IconWarning = MYGUI_FLAG(_IndexIcon1 + 3), 00064 00065 Icon1 = MYGUI_FLAG(_IndexIcon1), 00066 Icon2 = MYGUI_FLAG(_IndexIcon1 + 1), 00067 Icon3 = MYGUI_FLAG(_IndexIcon1 + 2), 00068 Icon4 = MYGUI_FLAG(_IndexIcon1 + 3), 00069 Icon5 = MYGUI_FLAG(_IndexIcon1 + 4), 00070 Icon6 = MYGUI_FLAG(_IndexIcon1 + 5), 00071 Icon7 = MYGUI_FLAG(_IndexIcon1 + 6), 00072 Icon8 = MYGUI_FLAG(_IndexIcon1 + 7) 00073 }; 00074 00075 MessageBoxStyle(Enum _value = None) : value(_value) { } 00076 00077 MessageBoxStyle& operator |= (MessageBoxStyle const& _other) { value = Enum(int(value) | int(_other.value)); return *this; } 00078 friend MessageBoxStyle operator | (Enum const& a, Enum const& b) { return MessageBoxStyle(Enum(int(a) | int(b))); } 00079 MessageBoxStyle operator | (Enum const& a) { return MessageBoxStyle(Enum(int(value) | int(a))); } 00080 00081 friend bool operator == (MessageBoxStyle const& a, MessageBoxStyle const& b) { return a.value == b.value; } 00082 friend bool operator != (MessageBoxStyle const& a, MessageBoxStyle const& b) { return a.value != b.value; } 00083 00084 friend std::ostream& operator << ( std::ostream& _stream, const MessageBoxStyle& _value ) 00085 { 00086 //_stream << _value.print(); 00087 return _stream; 00088 } 00089 00090 friend std::istream& operator >> ( std::istream& _stream, MessageBoxStyle& _value ) 00091 { 00092 std::string value; 00093 _stream >> value; 00094 _value = MessageBoxStyle::parse(value); 00095 return _stream; 00096 } 00097 00098 // возвращает индекс иконки 00099 size_t getIconIndex() 00100 { 00101 size_t index = 0; 00102 int num = value >> _IndexIcon1; 00103 00104 while (num != 0) 00105 { 00106 if ((num & 1) == 1) return index; 00107 00108 ++index; 00109 num >>= 1; 00110 } 00111 00112 return ITEM_NONE; 00113 } 00114 00115 // возвращает индекс иконки 00116 size_t getButtonIndex() 00117 { 00118 size_t index = 0; 00119 int num = value; 00120 00121 while (num != 0) 00122 { 00123 if ((num & 1) == 1) return index; 00124 00125 ++index; 00126 num >>= 1; 00127 } 00128 00129 return ITEM_NONE; 00130 } 00131 00132 // возвращает список кнопок 00133 std::vector<MessageBoxStyle> getButtons() 00134 { 00135 std::vector<MessageBoxStyle> buttons; 00136 00137 size_t index = 0; 00138 int num = value; 00139 while (index < _IndexIcon1) 00140 { 00141 if ((num & 1) == 1) 00142 { 00143 buttons.push_back( MessageBoxStyle::Enum( MYGUI_FLAG(index) ) ); 00144 } 00145 00146 ++index; 00147 num >>= 1; 00148 } 00149 00150 return buttons; 00151 } 00152 00153 typedef std::map<std::string, int> MapAlign; 00154 00155 static MessageBoxStyle parse(const std::string& _value) 00156 { 00157 MessageBoxStyle result(MessageBoxStyle::Enum(0)); 00158 const MapAlign& map_names = result.getValueNames(); 00159 const std::vector<std::string>& vec = utility::split(_value); 00160 for (size_t pos=0; pos<vec.size(); pos++) 00161 { 00162 MapAlign::const_iterator iter = map_names.find(vec[pos]); 00163 if (iter != map_names.end()) 00164 { 00165 result.value = Enum(int(result.value) | int(iter->second)); 00166 } 00167 else 00168 { 00169 MYGUI_LOG(Warning, "Cannot parse type '" << vec[pos] << "'"); 00170 } 00171 } 00172 return result; 00173 } 00174 00175 private: 00176 const MapAlign& getValueNames() 00177 { 00178 static MapAlign map_names; 00179 00180 if (map_names.empty()) 00181 { 00182 MYGUI_REGISTER_VALUE(map_names, None); 00183 MYGUI_REGISTER_VALUE(map_names, Ok); 00184 MYGUI_REGISTER_VALUE(map_names, Yes); 00185 MYGUI_REGISTER_VALUE(map_names, No); 00186 MYGUI_REGISTER_VALUE(map_names, Abort); 00187 MYGUI_REGISTER_VALUE(map_names, Retry); 00188 MYGUI_REGISTER_VALUE(map_names, Ignore); 00189 MYGUI_REGISTER_VALUE(map_names, Cancel); 00190 MYGUI_REGISTER_VALUE(map_names, Try); 00191 MYGUI_REGISTER_VALUE(map_names, Continue); 00192 00193 MYGUI_REGISTER_VALUE(map_names, Button1); 00194 MYGUI_REGISTER_VALUE(map_names, Button2); 00195 MYGUI_REGISTER_VALUE(map_names, Button3); 00196 MYGUI_REGISTER_VALUE(map_names, Button4); 00197 00198 MYGUI_REGISTER_VALUE(map_names, IconDefault); 00199 00200 MYGUI_REGISTER_VALUE(map_names, IconInfo); 00201 MYGUI_REGISTER_VALUE(map_names, IconQuest); 00202 MYGUI_REGISTER_VALUE(map_names, IconError); 00203 MYGUI_REGISTER_VALUE(map_names, IconWarning); 00204 00205 MYGUI_REGISTER_VALUE(map_names, Icon1); 00206 MYGUI_REGISTER_VALUE(map_names, Icon2); 00207 MYGUI_REGISTER_VALUE(map_names, Icon3); 00208 MYGUI_REGISTER_VALUE(map_names, Icon4); 00209 MYGUI_REGISTER_VALUE(map_names, Icon5); 00210 MYGUI_REGISTER_VALUE(map_names, Icon6); 00211 MYGUI_REGISTER_VALUE(map_names, Icon7); 00212 MYGUI_REGISTER_VALUE(map_names, Icon8); 00213 } 00214 00215 return map_names; 00216 } 00217 00218 private: 00219 Enum value; 00220 }; 00221 00222 } // namespace MyGUI 00223 00224 #endif // __MYGUI_MESSAGE_BOX_STYLE_H__