OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
layout.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_MWGUI_LAYOUT_H
2 #define OPENMW_MWGUI_LAYOUT_H
3 
4 #include <string>
5 #include <MyGUI_WidgetDefines.h>
6 #include <MyGUI_Widget.h>
7 
9 
10 namespace MWGui
11 {
15  class Layout
16  {
17  public:
18  Layout(const std::string & _layout, MyGUI::Widget* _parent = nullptr)
19  : mMainWidget(nullptr)
20  { initialise(_layout, _parent); }
21  virtual ~Layout()
22  {
23  try
24  {
25  shutdown();
26  }
27  catch(const MyGUI::Exception& e)
28  {
29  Log(Debug::Error) << "Error in the destructor: " << e.what();
30  }
31  }
32 
33  MyGUI::Widget* getWidget(const std::string& _name);
34 
35  template <typename T>
36  void getWidget(T * & _widget, const std::string & _name)
37  {
38  MyGUI::Widget* w = getWidget(_name);
39  T* cast = w->castType<T>(false);
40  if (!cast)
41  {
42  MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName()
43  << "' source name = '" << w->getName()
44  << "' source type = '" << w->getTypeName() << "' in layout '" << mLayoutName << "'");
45  }
46  else
47  _widget = cast;
48  }
49 
50  private:
51  void initialise(const std::string & _layout,
52  MyGUI::Widget* _parent = nullptr);
53 
54  void shutdown();
55 
56  public:
57  void setCoord(int x, int y, int w, int h);
58 
59  virtual void setVisible(bool b);
60 
61  void setText(const std::string& name, const std::string& caption);
62 
63  // NOTE: this assume that mMainWidget is of type Window.
64  void setTitle(const std::string& title);
65 
66  MyGUI::Widget* mMainWidget;
67 
68  protected:
69 
70  std::string mPrefix;
71  std::string mLayoutName;
72  MyGUI::VectorWidgetPtr mListWindowRoot;
73  };
74 }
75 #endif
void getWidget(T *&_widget, const std::string &_name)
Definition: layout.hpp:36
Layout(const std::string &_layout, MyGUI::Widget *_parent=nullptr)
Definition: layout.hpp:18
void setText(const std::string &name, const std::string &caption)
Definition: layout.cpp:52
virtual ~Layout()
Definition: layout.hpp:21
Definition: debuglog.hpp:12
MyGUI::Widget * mMainWidget
Definition: layout.hpp:66
MyGUI::Widget * getWidget(const std::string &_name)
Definition: layout.cpp:64
Definition: debuglog.hpp:22
std::string mLayoutName
Definition: layout.hpp:71
void shutdown()
Definition: layout.cpp:36
void initialise(const std::string &_layout, MyGUI::Widget *_parent=nullptr)
Definition: layout.cpp:11
std::string mPrefix
Definition: layout.hpp:70
MyGUI::VectorWidgetPtr mListWindowRoot
Definition: layout.hpp:72
Definition: layout.hpp:15
virtual void setVisible(bool b)
Definition: layout.cpp:47
void setTitle(const std::string &title)
Definition: layout.cpp:59
void setCoord(int x, int y, int w, int h)
Definition: layout.cpp:42
const char * name
Definition: crashcatcher.cpp:67