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