fix satellites positions in the west
[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         m_child->destruct();
37 }
38
39 void eWindow::setTitle(const std::string &string)
40 {
41         if (m_title == string)  
42                 return;
43         m_title = string;
44         event(evtTitleChanged);
45 }
46
47 std::string eWindow::getTitle() const
48 {
49         return m_title;
50 }
51
52 void eWindow::setFlag(int flags)
53 {
54         m_flags |= flags;
55 }
56
57 void eWindow::clearFlag(int flags)
58 {
59         m_flags &= ~flags;
60 }
61
62 int eWindow::event(int event, void *data, void *data2)
63 {
64         switch (event)
65         {
66         case evtWillChangeSize:
67         {
68                 eSize &new_size = *static_cast<eSize*>(data);
69                 eSize &offset = *static_cast<eSize*>(data2);
70                 if (!(m_flags & wfNoBorder))
71                 {
72                         ePtr<eWindowStyle> style;
73                         if (!getStyle(style))
74                         {
75 //                      eDebug("eWindow::evtWillChangeSize to %d %d", new_size.width(), new_size.height());
76                                 style->handleNewSize(this, new_size, offset);
77                         }
78                 } else
79                         m_child->resize(new_size);
80                 break;
81         }
82         case evtPaint:
83         {
84                 if (!(m_flags & wfNoBorder))
85                 {
86                         ePtr<eWindowStyle> style;
87                         if (!getStyle(style))
88                         {
89                                 gPainter &painter = *static_cast<gPainter*>(data2);
90                                 style->paintWindowDecoration(this, painter, m_title);
91                         }
92                 }
93                 return 0;
94         }
95         case evtTitleChanged:
96                         /* m_visible_region contains, in contrast to m_visible_with_childs,
97                            only the decoration. though repainting the whole decoration is bad,
98                            repainting the whole window is even worse. */
99                 invalidate(m_visible_region);
100                 break;
101         default:
102                 break;
103         }
104         return eWidget::event(event, data, data2);
105 }
106