- sdl is now default output
[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): 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                 /* we are the parent for the child window. */
27                 /* as we are in the constructor, this is thread safe. */
28         m_child = this;
29         m_child = new eWidget(this);
30         desktop->addRootWidget(this, 0);
31 }
32
33 eWindow::~eWindow()
34 {
35         getDesktop()->removeRootWidget(this);
36 }
37
38 void eWindow::setTitle(const std::string &string)
39 {
40         if (m_title == string)  
41                 return;
42         m_title = string;
43         event(evtTitleChanged);
44 }
45
46 void eWindow::setFlag(int flags)
47 {
48         m_flags |= flags;
49 }
50
51 void eWindow::clearFlag(int flags)
52 {
53         m_flags &= ~flags;
54 }
55
56 int eWindow::event(int event, void *data, void *data2)
57 {
58         switch (event)
59         {
60         case evtWillChangeSize:
61         {
62                 eSize &new_size = *static_cast<eSize*>(data);
63                 eSize &offset = *static_cast<eSize*>(data2);
64                 if (!(m_flags & wfNoBorder))
65                 {
66                         ePtr<eWindowStyle> style;
67                         if (!getStyle(style))
68                         {
69 //                      eDebug("eWindow::evtWillChangeSize to %d %d", new_size.width(), new_size.height());
70                                 style->handleNewSize(this, new_size, offset);
71                         }
72                 } else
73                 {
74                         m_child->resize(new_size);
75                 }
76                 break;
77         }
78         case evtPaint:
79         {
80                 if (!(m_flags & wfNoBorder))
81                 {
82                         ePtr<eWindowStyle> style;
83                         if (!getStyle(style))
84                         {
85                                 gPainter &painter = *static_cast<gPainter*>(data2);
86                                 style->paintWindowDecoration(this, painter, m_title);
87                         }
88                 }
89                 return 0;
90         }
91         default:
92                 break;
93         }
94         return eWidget::event(event, data, data2);
95 }
96