MyGUI  3.0.1
MyGUI_MessageStyle.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_MESSAGE_BOX_STYLE_H__
24 #define __MYGUI_MESSAGE_BOX_STYLE_H__
25 
26 #include "MyGUI_Prerequest.h"
27 
28 namespace MyGUI
29 {
30 
31 
33  {
34 
35  enum Enum
36  {
38  Ok = MYGUI_FLAG(0),
39  Yes = MYGUI_FLAG(1),
40  No = MYGUI_FLAG(2),
41  Abort = MYGUI_FLAG(3),
42  Retry = MYGUI_FLAG(4),
43  Ignore = MYGUI_FLAG(5),
44  Cancel = MYGUI_FLAG(6),
45  Try = MYGUI_FLAG(7),
46  Continue = MYGUI_FLAG(8),
47 
48  _IndexUserButton1 = 9, // индекс первой кнопки юзера
49 
50  Button1 = MYGUI_FLAG(_IndexUserButton1),
51  Button2 = MYGUI_FLAG(_IndexUserButton1 + 1),
52  Button3 = MYGUI_FLAG(_IndexUserButton1 + 2),
53  Button4 = MYGUI_FLAG(_IndexUserButton1 + 3),
54 
55  _CountUserButtons = 4, // колличество кнопок юзера
56  _IndexIcon1 = _IndexUserButton1 + _CountUserButtons, // индекс первой иконки
57 
58  IconDefault = MYGUI_FLAG(_IndexIcon1),
59 
60  IconInfo = MYGUI_FLAG(_IndexIcon1),
61  IconQuest = MYGUI_FLAG(_IndexIcon1 + 1),
62  IconError = MYGUI_FLAG(_IndexIcon1 + 2),
63  IconWarning = MYGUI_FLAG(_IndexIcon1 + 3),
64 
65  Icon1 = MYGUI_FLAG(_IndexIcon1),
66  Icon2 = MYGUI_FLAG(_IndexIcon1 + 1),
67  Icon3 = MYGUI_FLAG(_IndexIcon1 + 2),
68  Icon4 = MYGUI_FLAG(_IndexIcon1 + 3),
69  Icon5 = MYGUI_FLAG(_IndexIcon1 + 4),
70  Icon6 = MYGUI_FLAG(_IndexIcon1 + 5),
71  Icon7 = MYGUI_FLAG(_IndexIcon1 + 6),
72  Icon8 = MYGUI_FLAG(_IndexIcon1 + 7)
73  };
74 
75  MessageBoxStyle(Enum _value = None) : value(_value) { }
76 
77  MessageBoxStyle& operator |= (MessageBoxStyle const& _other) { value = Enum(int(value) | int(_other.value)); return *this; }
78  friend MessageBoxStyle operator | (Enum const& a, Enum const& b) { return MessageBoxStyle(Enum(int(a) | int(b))); }
79  MessageBoxStyle operator | (Enum const& a) { return MessageBoxStyle(Enum(int(value) | int(a))); }
80 
81  friend bool operator == (MessageBoxStyle const& a, MessageBoxStyle const& b) { return a.value == b.value; }
82  friend bool operator != (MessageBoxStyle const& a, MessageBoxStyle const& b) { return a.value != b.value; }
83 
84  friend std::ostream& operator << ( std::ostream& _stream, const MessageBoxStyle& _value )
85  {
86  //_stream << _value.print();
87  return _stream;
88  }
89 
90  friend std::istream& operator >> ( std::istream& _stream, MessageBoxStyle& _value )
91  {
92  std::string value;
93  _stream >> value;
94  _value = MessageBoxStyle::parse(value);
95  return _stream;
96  }
97 
98  // возвращает индекс иконки
99  size_t getIconIndex()
100  {
101  size_t index = 0;
102  int num = value >> _IndexIcon1;
103 
104  while (num != 0)
105  {
106  if ((num & 1) == 1) return index;
107 
108  ++index;
109  num >>= 1;
110  }
111 
112  return ITEM_NONE;
113  }
114 
115  // возвращает индекс иконки
116  size_t getButtonIndex()
117  {
118  size_t index = 0;
119  int num = value;
120 
121  while (num != 0)
122  {
123  if ((num & 1) == 1) return index;
124 
125  ++index;
126  num >>= 1;
127  }
128 
129  return ITEM_NONE;
130  }
131 
132  // возвращает список кнопок
133  std::vector<MessageBoxStyle> getButtons()
134  {
135  std::vector<MessageBoxStyle> buttons;
136 
137  size_t index = 0;
138  int num = value;
139  while (index < _IndexIcon1)
140  {
141  if ((num & 1) == 1)
142  {
143  buttons.push_back( MessageBoxStyle::Enum( MYGUI_FLAG(index) ) );
144  }
145 
146  ++index;
147  num >>= 1;
148  }
149 
150  return buttons;
151  }
152 
153  typedef std::map<std::string, int> MapAlign;
154 
155  static MessageBoxStyle parse(const std::string& _value)
156  {
158  const MapAlign& map_names = result.getValueNames();
159  const std::vector<std::string>& vec = utility::split(_value);
160  for (size_t pos=0; pos<vec.size(); pos++)
161  {
162  MapAlign::const_iterator iter = map_names.find(vec[pos]);
163  if (iter != map_names.end())
164  {
165  result.value = Enum(int(result.value) | int(iter->second));
166  }
167  else
168  {
169  MYGUI_LOG(Warning, "Cannot parse type '" << vec[pos] << "'");
170  }
171  }
172  return result;
173  }
174 
175  private:
176  const MapAlign& getValueNames()
177  {
178  static MapAlign map_names;
179 
180  if (map_names.empty())
181  {
182  MYGUI_REGISTER_VALUE(map_names, None);
183  MYGUI_REGISTER_VALUE(map_names, Ok);
184  MYGUI_REGISTER_VALUE(map_names, Yes);
185  MYGUI_REGISTER_VALUE(map_names, No);
186  MYGUI_REGISTER_VALUE(map_names, Abort);
187  MYGUI_REGISTER_VALUE(map_names, Retry);
188  MYGUI_REGISTER_VALUE(map_names, Ignore);
189  MYGUI_REGISTER_VALUE(map_names, Cancel);
190  MYGUI_REGISTER_VALUE(map_names, Try);
191  MYGUI_REGISTER_VALUE(map_names, Continue);
192 
193  MYGUI_REGISTER_VALUE(map_names, Button1);
194  MYGUI_REGISTER_VALUE(map_names, Button2);
195  MYGUI_REGISTER_VALUE(map_names, Button3);
196  MYGUI_REGISTER_VALUE(map_names, Button4);
197 
198  MYGUI_REGISTER_VALUE(map_names, IconDefault);
199 
200  MYGUI_REGISTER_VALUE(map_names, IconInfo);
201  MYGUI_REGISTER_VALUE(map_names, IconQuest);
202  MYGUI_REGISTER_VALUE(map_names, IconError);
203  MYGUI_REGISTER_VALUE(map_names, IconWarning);
204 
205  MYGUI_REGISTER_VALUE(map_names, Icon1);
206  MYGUI_REGISTER_VALUE(map_names, Icon2);
207  MYGUI_REGISTER_VALUE(map_names, Icon3);
208  MYGUI_REGISTER_VALUE(map_names, Icon4);
209  MYGUI_REGISTER_VALUE(map_names, Icon5);
210  MYGUI_REGISTER_VALUE(map_names, Icon6);
211  MYGUI_REGISTER_VALUE(map_names, Icon7);
212  MYGUI_REGISTER_VALUE(map_names, Icon8);
213  }
214 
215  return map_names;
216  }
217 
218  private:
219  Enum value;
220  };
221 
222 } // namespace MyGUI
223 
224 #endif // __MYGUI_MESSAGE_BOX_STYLE_H__