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 
8 namespace MWGui
9 {
13  class Layout
14  {
15  public:
16  Layout(const std::string & _layout, MyGUI::Widget* _parent = nullptr)
17  : mMainWidget(nullptr)
18  { initialise(_layout, _parent); }
19  virtual ~Layout() { shutdown(); }
20 
21  MyGUI::Widget* getWidget(const std::string& _name);
22 
23  template <typename T>
24  void getWidget(T * & _widget, const std::string & _name)
25  {
26  MyGUI::Widget* w = getWidget(_name);
27  T* cast = w->castType<T>(false);
28  if (!cast)
29  {
30  MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName()
31  << "' source name = '" << w->getName()
32  << "' source type = '" << w->getTypeName() << "' in layout '" << mLayoutName << "'");
33  }
34  else
35  _widget = cast;
36  }
37 
38  private:
39  void initialise(const std::string & _layout,
40  MyGUI::Widget* _parent = nullptr);
41 
42  void shutdown();
43 
44  public:
45  void setCoord(int x, int y, int w, int h);
46 
47  virtual void setVisible(bool b);
48 
49  void setText(const std::string& name, const std::string& caption);
50 
51  // NOTE: this assume that mMainWidget is of type Window.
52  void setTitle(const std::string& title);
53 
54  MyGUI::Widget* mMainWidget;
55 
56  protected:
57 
58  std::string mPrefix;
59  std::string mLayoutName;
60  MyGUI::VectorWidgetPtr mListWindowRoot;
61  };
62 }
63 #endif
void getWidget(T *&_widget, const std::string &_name)
Definition: layout.hpp:24
Layout(const std::string &_layout, MyGUI::Widget *_parent=nullptr)
Definition: layout.hpp:16
void setText(const std::string &name, const std::string &caption)
Definition: layout.cpp:52
virtual ~Layout()
Definition: layout.hpp:19
MyGUI::Widget * mMainWidget
Definition: layout.hpp:54
MyGUI::Widget * getWidget(const std::string &_name)
Definition: layout.cpp:64
std::string mLayoutName
Definition: layout.hpp:59
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:58
MyGUI::VectorWidgetPtr mListWindowRoot
Definition: layout.hpp:60
Definition: layout.hpp:13
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:59