gui: experimental Z order for root widgets
[enigma2.git] / lib / gui / ewindow.cpp
1 #include <lib/gui/ewindow.h>
2 #include <lib/gui/ewidgetdesktop.h>
3
4 #include <lib/gui/ewindowstyle.h>
5 #include <lib/gui/ewindowstyleskinned.h>
6
7 #include <lib/gdi/epng.h>
8
9 eWindow::eWindow(eWidgetDesktop *desktop, int z): eWidget(0)
10 {
11         m_flags = 0;
12                 /* ask style manager for current style */
13         ePtr<eWindowStyleManager> mgr;
14         eWindowStyleManager::getInstance(mgr);
15         
16         ePtr<eWindowStyle> style;
17         if (mgr)
18                 mgr->getStyle(style);
19         
20                 /* when there is either no style manager or no style, revert to simple style. */
21         if (!style)
22                 style = new eWindowStyleSimple();
23         
24         setStyle(style);
25         
26         setZPosition(z); /* must be done before addRootWidget */
27
28                 /* we are the parent for the child window. */
29                 /* as we are in the constructor, this is thread safe. */
30         m_child = this;
31         m_child = new eWidget(this);
32         desktop->addRootWidget(this);
33 }
34
35 eWindow::~eWindow()
36 {
37         getDesktop()->removeRootWidget(this);
38         m_child->destruct();
39 }
40
41 void eWindow::setTitle(const std::string &string)
42 {
43         if (m_title == string)  
44                 return;
45         m_title = string;
46         event(evtTitleChanged);
47 }
48
49 std::string eWindow::getTitle() const
50 {
51         return m_title;
52 }
53
54 void eWindow::setFlag(int flags)
55 {
56         m_flags |= flags;
57 }
58
59 void eWindow::clearFlag(int flags)
60 {
61         m_flags &= ~flags;
62 }
63
64 int eWindow::event(int event, void *data, void *data2)
65 {
66         switch (event)
67         {
68         case evtWillChangeSize:
69         {
70                 eSize &new_size = *static_cast<eSize*>(data);
71                 eSize &offset = *static_cast<eSize*>(data2);
72                 if (!(m_flags & wfNoBorder))
73                 {
74                         ePtr<eWindowStyle> style;
75                         if (!getStyle(style))
76                         {
77 //                      eDebug("eWindow::evtWillChangeSize to %d %d", new_size.width(), new_size.height());
78                                 style->handleNewSize(this, new_size, offset);
79                         }
80                 } else
81                         m_child->resize(new_size);
82                 break;
83         }
84         case evtPaint:
85         {
86                 if (!(m_flags & wfNoBorder))
87                 {
88                         ePtr<eWindowStyle> style;
89                         if (!getStyle(style))
90                         {
91                                 gPainter &painter = *static_cast<gPainter*>(data2);
92                                 style->paintWindowDecoration(this, painter, m_title);
93                         }
94                 }
95                 return 0;
96         }
97         case evtTitleChanged:
98                         /* m_visible_region contains, in contrast to m_visible_with_childs,
99                            only the decoration. though repainting the whole decoration is bad,
100                            repainting the whole window is even worse. */
101                 invalidate(m_visible_region);
102                 break;
103         default:
104                 break;
105         }
106         return eWidget::event(event, data, data2);
107 }
108