dont open epglist when no epg is avail
[enigma2.git] / lib / gui / ewindowstyleskinned.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/gdi/esize.h>
3 #include <lib/gui/ewindow.h>
4 #include <lib/gui/ewindowstyle.h>
5 #include <lib/gui/ewindowstyleskinned.h>
6
7 DEFINE_REF(eWindowStyleSkinned);
8
9 eWindowStyleSkinned::eWindowStyleSkinned()
10 {
11         // m_background_color = gRGB(0x808080);
12         
13         // TODO: initialize colors!!
14 }
15
16 void eWindowStyleSkinned::handleNewSize(eWindow *wnd, eSize &size, eSize &offset)
17 {
18 //      eDebug("handle new size: %d x %d", size.width(), size.height());
19         
20         size = eSize(
21                         size.width() + m_border[bsWindow].m_border_left + m_border[bsWindow].m_border_right,
22                         size.height() + m_border[bsWindow].m_border_top + m_border[bsWindow].m_border_bottom
23                 );
24         
25         offset = eSize(-m_border[bsWindow].m_border_left, -m_border[bsWindow].m_border_top);
26         
27         eWidget *child = wnd->child();
28         
29         wnd->m_clip_region = eRect(ePoint(0, 0), size);
30         
31         child->move(ePoint(m_border[bsWindow].m_border_left, m_border[bsWindow].m_border_top));
32         child->resize(eSize(size.width() - m_border[bsWindow].m_border_left - m_border[bsWindow].m_border_right, size.height() - m_border[bsWindow].m_border_top - m_border[bsWindow].m_border_bottom));
33 }
34
35 void eWindowStyleSkinned::paintWindowDecoration(eWindow *wnd, gPainter &painter, const std::string &title)
36 {
37         drawBorder(painter, eRect(ePoint(0, 0), wnd->size()), m_border[bsWindow], bpAll);
38 }
39
40 void eWindowStyleSkinned::paintBackground(gPainter &painter, const ePoint &offset, const eSize &size)
41 {
42         painter.setBackgroundColor(m_color[colBackground]);
43         painter.clear();
44 }
45
46 void eWindowStyleSkinned::setStyle(gPainter &painter, int what)
47 {
48         switch (what)
49         {
50         case styleLabel:
51                 painter.setForegroundColor(m_color[colLabelForeground]);
52                 break;
53         case styleListboxSelected:
54                 painter.setForegroundColor(m_color[colListboxSelectedForeground]);
55                 painter.setBackgroundColor(m_color[colListboxSelectedBackground]);
56                 break;
57         case styleListboxNormal:
58                 painter.setForegroundColor(m_color[colListboxForeground]);
59                 painter.setBackgroundColor(m_color[colListboxBackground]);
60                 break;
61         case styleListboxMarked:
62                 painter.setForegroundColor(m_color[colListboxMarkedForeground]);
63                 painter.setBackgroundColor(m_color[colListboxMarkedBackground]);
64                 break;
65         }
66 }
67
68 void eWindowStyleSkinned::drawFrame(gPainter &painter, const eRect &frame, int what)
69 {
70         int bs;
71         switch (what)
72         {
73         case frameButton:
74                 bs = bsButton;
75                 break;
76         case frameListboxEntry:
77                 bs = bsListboxEntry;
78                 break;
79         default:
80                 eWarning("invalid frame style %d", what);
81                 return;
82         }
83         drawBorder(painter, frame, m_border[bs], bpAll);
84 }
85
86 void eWindowStyleSkinned::drawBorder(gPainter &painter, const eRect &pos, struct borderSet &border, int what)
87 {
88         int x = pos.left(), xm = pos.right();
89         
90         ePtr<gPixmap> 
91                 &tl = border.m_pixmap[bpiTopLeft],
92                 &t  = border.m_pixmap[bpiTop],
93                 &tr = border.m_pixmap[bpiTopRight],
94                 &l  = border.m_pixmap[bpiLeft],
95                 &r  = border.m_pixmap[bpiRight],
96                 &bl = border.m_pixmap[bpiBottomLeft],
97                 &b  = border.m_pixmap[bpiBottom],
98                 &br = border.m_pixmap[bpiBottomRight];
99         
100         if (tl)
101         {
102                 painter.blit(tl, ePoint(x, pos.top()));
103                 x += tl->size().width();
104         }
105         
106         if (tr)
107         {
108                 xm -= tr->size().width();
109                 painter.blit(tr, ePoint(xm, pos.top()), pos);
110         }
111
112         if (t)
113         {
114                 while (x < xm)
115                 {
116                         painter.blit(t, ePoint(x, pos.top()), eRect(x, pos.top(), xm - x, pos.height()));
117                         x += t->size().width();
118                 }
119         }
120         
121         x = pos.left();
122         xm = pos.right();
123         
124         if (bl)
125         {
126                 painter.blit(bl, ePoint(pos.left(), pos.bottom()-bl->size().height()));
127                 x += bl->size().width();
128         }
129         
130         if (br)
131         {
132                 xm -= br->size().width();
133                 painter.blit(br, ePoint(xm, pos.bottom()-br->size().height()), eRect(x, pos.bottom()-br->size().height(), pos.width() - x, bl->size().height()));
134         }
135         
136         if (b)
137         {
138                 while (x < xm)
139                 {
140                         painter.blit(b, ePoint(x, pos.bottom()-b->size().height()), eRect(x, pos.bottom()-b->size().height(), xm - x, pos.height()));
141                         x += b->size().width();
142                 }
143         }
144         
145         int y = 0;
146         if (tl)
147                 y = tl->size().height();
148         
149         y += pos.top();
150         
151         int ym = pos.bottom();
152         if (bl)
153                 ym -= bl->size().height();
154         
155         if (l)
156         {
157                 while (y < ym)
158                 {
159                         painter.blit(l, ePoint(pos.left(), y), eRect(pos.left(), y, pos.width(), ym - y));
160                         y += l->size().height();
161                 }
162         }
163         
164         y = 0;
165         
166         if (tr)
167                 y = tr->size().height();
168         
169         y += pos.top();
170         
171         ym = pos.bottom();
172         if (br)
173                 ym -= br->size().height();
174         
175         if (r)
176         {
177                 while (y < ym)
178                 {
179                         painter.blit(r, ePoint(pos.right() - r->size().width(), y), eRect(pos.right()-r->size().width(), y, r->size().width(), ym - y));
180                         y += r->size().height();
181                 }
182         }
183 }
184
185 RESULT eWindowStyleSkinned::getFont(int what, ePtr<gFont> &fnt)
186 {
187         fnt = 0;
188         switch (what)
189         {
190         case fontStatic:
191                 fnt = new gFont("Arial", 12);
192                 break;
193         case fontButton:
194                 fnt = new gFont("Arial", 20);
195                 break;
196         case fontTitlebar:
197                 fnt = new gFont("Arial", 25);
198                 break;
199         default:
200                 return -1;
201         }
202         return 0;
203 }
204
205 void eWindowStyleSkinned::setPixmap(int bs, int bp, gPixmap &pixmap)
206 {
207         if ((bs >= bsMax) || (bs < 0))
208                 return;
209         
210         int i = 0;
211         for (int b = 1; b < bpMax; b <<= 1, ++i)
212         {
213                 if (bp & b)
214                         m_border[bs].m_pixmap[i] = &pixmap;
215         }
216         
217                 /* recalc border sizes */
218         m_border[bs].m_border_top = 0;
219         m_border[bs].m_border_left = 0;
220         m_border[bs].m_border_bottom = 0;
221         m_border[bs].m_border_right = 0;
222         
223         for (int i = 0; i < 3; ++i)
224                 if (m_border[bs].m_pixmap[i])
225                         if (m_border[bs].m_border_top < m_border[bs].m_pixmap[i]->size().height())
226                                 m_border[bs].m_border_top = m_border[bs].m_pixmap[i]->size().height();
227         for (int i = 6; i < 9; ++i)
228                 if (m_border[bs].m_pixmap[i])
229                         if (m_border[bs].m_border_bottom < m_border[bs].m_pixmap[i]->size().height())
230                                 m_border[bs].m_border_bottom = m_border[bs].m_pixmap[i]->size().height();
231         for (int i = 0; i < 9; i += 3)
232                 if (m_border[bs].m_pixmap[i])
233                         if (m_border[bs].m_border_left < m_border[bs].m_pixmap[i]->size().width())
234                                 m_border[bs].m_border_left = m_border[bs].m_pixmap[i]->size().width();
235         for (int i = 2; i < 9; i += 3)
236                 if (m_border[bs].m_pixmap[i])
237                         if (m_border[bs].m_border_right < m_border[bs].m_pixmap[i]->size().width())
238                                 m_border[bs].m_border_right = m_border[bs].m_pixmap[i]->size().width();
239         eDebug("recalced border size for %d: %d:%d %d:%d",
240                 bs, 
241                 m_border[bs].m_border_left, m_border[bs].m_border_top, 
242                 m_border[bs].m_border_right, m_border[bs].m_border_bottom); 
243 }
244
245 void eWindowStyleSkinned::setColor(int what, const gRGB &col)
246 {
247         if ((what < colMax) && (what >= 0))
248                 m_color[what] = col;
249 }
250