Merge branch 'experimental' of git.opendreambox.org:/git/enigma2 into experimental
[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         m_desktop = desktop;
13                 /* ask style manager for current style */
14         ePtr<eWindowStyleManager> mgr;
15         eWindowStyleManager::getInstance(mgr);
16         
17         ePtr<eWindowStyle> style;
18         if (mgr)
19                 mgr->getStyle(desktop->getStyleID(), style);
20         
21                 /* when there is either no style manager or no style, revert to simple style. */
22         if (!style)
23                 style = new eWindowStyleSimple();
24         
25         setStyle(style);
26         
27         setZPosition(z); /* must be done before addRootWidget */
28
29                 /* we are the parent for the child window. */
30                 /* as we are in the constructor, this is thread safe. */
31         m_child = this;
32         m_child = new eWidget(this);
33         desktop->addRootWidget(this);
34 }
35
36 eWindow::~eWindow()
37 {
38         m_desktop->removeRootWidget(this);
39         m_child->destruct();
40 }
41
42 void eWindow::setTitle(const std::string &string)
43 {
44         if (m_title == string)  
45                 return;
46         m_title = string;
47         event(evtTitleChanged);
48 }
49
50 std::string eWindow::getTitle() const
51 {
52         return m_title;
53 }
54
55 void eWindow::setBackgroundColor(const gRGB &col)
56 {
57                 /* set background color for child, too */
58         eWidget::setBackgroundColor(col);
59         m_child->setBackgroundColor(col);
60 }
61
62 void eWindow::setFlag(int flags)
63 {
64         m_flags |= flags;
65 }
66
67 void eWindow::clearFlag(int flags)
68 {
69         m_flags &= ~flags;
70 }
71
72 int eWindow::event(int event, void *data, void *data2)
73 {
74         switch (event)
75         {
76         case evtWillChangeSize:
77         {
78                 eSize &new_size = *static_cast<eSize*>(data);
79                 eSize &offset = *static_cast<eSize*>(data2);
80                 if (!(m_flags & wfNoBorder))
81                 {
82                         ePtr<eWindowStyle> style;
83                         if (!getStyle(style))
84                         {
85 //                      eDebug("eWindow::evtWillChangeSize to %d %d", new_size.width(), new_size.height());
86                                 style->handleNewSize(this, new_size, offset);
87                         }
88                 } else
89                         m_child->resize(new_size);
90                 break;
91         }
92         case evtPaint:
93         {
94                 if (!(m_flags & wfNoBorder))
95                 {
96                         ePtr<eWindowStyle> style;
97                         if (!getStyle(style))
98                         {
99                                 gPainter &painter = *static_cast<gPainter*>(data2);
100                                 style->paintWindowDecoration(this, painter, m_title);
101                         }
102                 }
103                 return 0;
104         }
105         case evtTitleChanged:
106                         /* m_visible_region contains, in contrast to m_visible_with_childs,
107                            only the decoration. though repainting the whole decoration is bad,
108                            repainting the whole window is even worse. */
109                 invalidate(m_visible_region);
110                 break;
111         default:
112                 break;
113         }
114         return eWidget::event(event, data, data2);
115 }
116