support backgroundColor for eWindow
[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(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         eDebug("eWindow: Set background color!");
58                 /* set background color for child, too */
59         eWidget::setBackgroundColor(col);
60         m_child->setBackgroundColor(col);
61 }
62
63 void eWindow::setFlag(int flags)
64 {
65         m_flags |= flags;
66 }
67
68 void eWindow::clearFlag(int flags)
69 {
70         m_flags &= ~flags;
71 }
72
73 int eWindow::event(int event, void *data, void *data2)
74 {
75         switch (event)
76         {
77         case evtWillChangeSize:
78         {
79                 eSize &new_size = *static_cast<eSize*>(data);
80                 eSize &offset = *static_cast<eSize*>(data2);
81                 if (!(m_flags & wfNoBorder))
82                 {
83                         ePtr<eWindowStyle> style;
84                         if (!getStyle(style))
85                         {
86 //                      eDebug("eWindow::evtWillChangeSize to %d %d", new_size.width(), new_size.height());
87                                 style->handleNewSize(this, new_size, offset);
88                         }
89                 } else
90                         m_child->resize(new_size);
91                 break;
92         }
93         case evtPaint:
94         {
95                 if (!(m_flags & wfNoBorder))
96                 {
97                         ePtr<eWindowStyle> style;
98                         if (!getStyle(style))
99                         {
100                                 gPainter &painter = *static_cast<gPainter*>(data2);
101                                 style->paintWindowDecoration(this, painter, m_title);
102                         }
103                 }
104                 return 0;
105         }
106         case evtTitleChanged:
107                         /* m_visible_region contains, in contrast to m_visible_with_childs,
108                            only the decoration. though repainting the whole decoration is bad,
109                            repainting the whole window is even worse. */
110                 invalidate(m_visible_region);
111                 break;
112         default:
113                 break;
114         }
115         return eWidget::event(event, data, data2);
116 }
117