1 /*! 2 @file 3 @author Albert Semenov 4 @date 10/2010 5 */ 6 #ifndef MESSAGE_BOX_STYLE_H_ 7 #define MESSAGE_BOX_STYLE_H_ 8 9 #include <MyGUI.h> 10 11 namespace MyGUI 12 { 13 14 struct MessageBoxStyle 15 { 16 enum Enum 17 { 18 None = MYGUI_FLAG_NONE, 19 Ok = MYGUI_FLAG(0), 20 Yes = MYGUI_FLAG(1), 21 No = MYGUI_FLAG(2), 22 Abort = MYGUI_FLAG(3), 23 Retry = MYGUI_FLAG(4), 24 Ignore = MYGUI_FLAG(5), 25 Cancel = MYGUI_FLAG(6), 26 Try = MYGUI_FLAG(7), 27 Continue = MYGUI_FLAG(8), 28 29 _IndexUserButton1 = 9, // индекс первой кнопки юзера 30 31 Button1 = MYGUI_FLAG(_IndexUserButton1), 32 Button2 = MYGUI_FLAG(_IndexUserButton1 + 1), 33 Button3 = MYGUI_FLAG(_IndexUserButton1 + 2), 34 Button4 = MYGUI_FLAG(_IndexUserButton1 + 3), 35 36 _CountUserButtons = 4, // колличество кнопок юзера 37 _IndexIcon1 = _IndexUserButton1 + _CountUserButtons, // индекс первой иконки 38 39 IconDefault = MYGUI_FLAG(_IndexIcon1), 40 41 IconInfo = MYGUI_FLAG(_IndexIcon1), 42 IconQuest = MYGUI_FLAG(_IndexIcon1 + 1), 43 IconError = MYGUI_FLAG(_IndexIcon1 + 2), 44 IconWarning = MYGUI_FLAG(_IndexIcon1 + 3), 45 46 Icon1 = MYGUI_FLAG(_IndexIcon1), 47 Icon2 = MYGUI_FLAG(_IndexIcon1 + 1), 48 Icon3 = MYGUI_FLAG(_IndexIcon1 + 2), 49 Icon4 = MYGUI_FLAG(_IndexIcon1 + 3), 50 Icon5 = MYGUI_FLAG(_IndexIcon1 + 4), 51 Icon6 = MYGUI_FLAG(_IndexIcon1 + 5), 52 Icon7 = MYGUI_FLAG(_IndexIcon1 + 6), 53 Icon8 = MYGUI_FLAG(_IndexIcon1 + 7) 54 }; 55 56 MessageBoxStyle(Enum _value = None) : mValueMessageBoxStyle57 mValue(_value) 58 { 59 } 60 61 MessageBoxStyle& operator |= (MessageBoxStyle const& _other) 62 { 63 mValue = Enum(int(mValue) | int(_other.mValue)); 64 return *this; 65 } 66 67 friend MessageBoxStyle operator | (Enum const& a, Enum const& b) 68 { 69 return MessageBoxStyle(Enum(int(a) | int(b))); 70 } 71 72 MessageBoxStyle operator | (Enum const& a) 73 { 74 return MessageBoxStyle(Enum(int(mValue) | int(a))); 75 } 76 77 friend bool operator == (MessageBoxStyle const& a, MessageBoxStyle const& b) 78 { 79 return a.mValue == b.mValue; 80 } 81 82 friend bool operator != (MessageBoxStyle const& a, MessageBoxStyle const& b) 83 { 84 return a.mValue != b.mValue; 85 } 86 87 /*friend std::ostream& operator << (std::ostream& _stream, const MessageBoxStyle& _value) 88 { 89 //_stream << _value.print(); 90 return _stream; 91 }*/ 92 93 friend std::istream& operator >> (std::istream& _stream, MessageBoxStyle& _value) 94 { 95 std::string value; 96 _stream >> value; 97 _value = parse(value); 98 return _stream; 99 } 100 101 // возвращает индекс иконки getIconIndexMessageBoxStyle102 size_t getIconIndex() 103 { 104 size_t index = 0; 105 int num = mValue >> _IndexIcon1; 106 107 while (num != 0) 108 { 109 if ((num & 1) == 1) 110 return index; 111 112 ++index; 113 num >>= 1; 114 } 115 116 return ITEM_NONE; 117 } 118 119 // возвращает индекс иконки getButtonIndexMessageBoxStyle120 size_t getButtonIndex() 121 { 122 size_t index = 0; 123 int num = mValue; 124 125 while (num != 0) 126 { 127 if ((num & 1) == 1) 128 return index; 129 130 ++index; 131 num >>= 1; 132 } 133 134 return ITEM_NONE; 135 } 136 137 // возвращает список кнопок getButtonsMessageBoxStyle138 std::vector<MessageBoxStyle> getButtons() 139 { 140 std::vector<MessageBoxStyle> buttons; 141 142 size_t index = 0; 143 int num = mValue; 144 while (index < _IndexIcon1) 145 { 146 if ((num & 1) == 1) 147 { 148 buttons.push_back(MessageBoxStyle::Enum( MYGUI_FLAG(index))); 149 } 150 151 ++index; 152 num >>= 1; 153 } 154 155 return buttons; 156 } 157 158 typedef std::map<std::string, int> MapAlign; 159 parseMessageBoxStyle160 static MessageBoxStyle parse(const std::string& _value) 161 { 162 MessageBoxStyle result(MessageBoxStyle::Enum(0)); 163 const MapAlign& map_names = result.getValueNames(); 164 const std::vector<std::string>& vec = utility::split(_value); 165 for (size_t pos = 0; pos < vec.size(); pos++) 166 { 167 MapAlign::const_iterator iter = map_names.find(vec[pos]); 168 if (iter != map_names.end()) 169 { 170 result.mValue = Enum(int(result.mValue) | int(iter->second)); 171 } 172 else 173 { 174 MYGUI_LOG(Warning, "Cannot parse type '" << vec[pos] << "'"); 175 } 176 } 177 return result; 178 } 179 180 private: getValueNamesMessageBoxStyle181 const MapAlign& getValueNames() 182 { 183 static MapAlign map_names; 184 185 if (map_names.empty()) 186 { 187 MYGUI_REGISTER_VALUE(map_names, None); 188 MYGUI_REGISTER_VALUE(map_names, Ok); 189 MYGUI_REGISTER_VALUE(map_names, Yes); 190 MYGUI_REGISTER_VALUE(map_names, No); 191 MYGUI_REGISTER_VALUE(map_names, Abort); 192 MYGUI_REGISTER_VALUE(map_names, Retry); 193 MYGUI_REGISTER_VALUE(map_names, Ignore); 194 MYGUI_REGISTER_VALUE(map_names, Cancel); 195 MYGUI_REGISTER_VALUE(map_names, Try); 196 MYGUI_REGISTER_VALUE(map_names, Continue); 197 198 MYGUI_REGISTER_VALUE(map_names, Button1); 199 MYGUI_REGISTER_VALUE(map_names, Button2); 200 MYGUI_REGISTER_VALUE(map_names, Button3); 201 MYGUI_REGISTER_VALUE(map_names, Button4); 202 203 MYGUI_REGISTER_VALUE(map_names, IconDefault); 204 205 MYGUI_REGISTER_VALUE(map_names, IconInfo); 206 MYGUI_REGISTER_VALUE(map_names, IconQuest); 207 MYGUI_REGISTER_VALUE(map_names, IconError); 208 MYGUI_REGISTER_VALUE(map_names, IconWarning); 209 210 MYGUI_REGISTER_VALUE(map_names, Icon1); 211 MYGUI_REGISTER_VALUE(map_names, Icon2); 212 MYGUI_REGISTER_VALUE(map_names, Icon3); 213 MYGUI_REGISTER_VALUE(map_names, Icon4); 214 MYGUI_REGISTER_VALUE(map_names, Icon5); 215 MYGUI_REGISTER_VALUE(map_names, Icon6); 216 MYGUI_REGISTER_VALUE(map_names, Icon7); 217 MYGUI_REGISTER_VALUE(map_names, Icon8); 218 } 219 220 return map_names; 221 } 222 223 private: 224 Enum mValue; 225 }; 226 227 } // namespace MyGUI 228 229 #endif // MESSAGE_BOX_STYLE_H_ 230