yes! ich habs kaputt gemacht! (doesn't compile anymore, doesn't work anymore,
[enigma2.git] / lib / gui / emessage.cpp
1 #include <lib/gui/emessage.h>
2
3 #include <lib/gui/elabel.h>
4 #include <lib/gui/ebutton.h>
5 #include <lib/gui/eskin.h>
6 #include <lib/gdi/font.h>
7 #include <lib/base/i18n.h>
8
9 eMessageBox::eMessageBox(eString message, eString caption, int flags, int def): eWindow(0), icon(0)
10 {
11         setText(caption);       
12         int fontsize=eSkin::getActive()->queryValue("fontsize", 20);
13         int posx = eSkin::getActive()->queryValue("eMessageBox.pos.x", 100);
14         int posy = eSkin::getActive()->queryValue("eMessageBox.pos.y", 70);
15         move(ePoint(posx, posy));
16         resize(eSize(450, 430));
17
18         if ( flags > 15 ) // we have to draw an icon
19         {
20                 ePtr<gPixmap> pm;
21                 switch ( flags & ~15 )
22                 {
23                         case iconInfo:
24                                 eSkin::getActive()->queryImage(pm, "icon_info" );                       
25                                 break;
26                         case iconQuestion:
27                                 eSkin::getActive()->queryImage(pm, "icon_question" );                   
28                                 break;
29                         case iconWarning:
30                                 eSkin::getActive()->queryImage(pm, "icon_warning" );                    
31                                 break;
32                         case iconError:
33                                 eSkin::getActive()->queryImage(pm, "icon_error" );                      
34                                 break;
35                 }
36                 if (pm)
37                 {
38                         icon = new eLabel(this);
39                         icon->setPixmap( pm );
40                         icon->pixmap_position=ePoint(0,0);
41                         icon->resize( eSize(pm->x, pm->y) );
42                         icon->setBlitFlags( BF_ALPHATEST );
43                 }
44         }
45
46         text=new eLabel(this);
47         text->setText(message);
48         text->resize( eSize( clientrect.width(), clientrect.height() ));
49         text->setFlags( RS_WRAP|eLabel::flagVCenter );
50         eSize txtSize=text->getExtend();
51         txtSize+=eSize(8,4);  // the given Size of the Text is okay... but the renderer sucks...
52         text->resize(txtSize);
53
54         // here the two labels ( icon, text) has the correct size..  now we calc the border
55
56         eSize ext;
57
58         if ( icon )
59         {
60                 if ( icon->getSize().height() > text->getSize().height() )
61                 {
62                         eDebug("icon is higher");
63                         eSize s = icon->getSize();
64                         icon->move( ePoint( 20, 20 ) );
65                         text->move( ePoint( 20 + s.width() + 20, icon->getPosition().y() + s.height() / 2 - txtSize.height() / 2 ) );
66                         ext.setHeight( icon->getPosition().y() + icon->getSize().height() + 20 );
67                 }
68                 else
69                 {
70                         eDebug("text is higher");
71                         text->move( ePoint( 20 + icon->getSize().width() + 20 , 20 ) );
72                         icon->move( ePoint( 20, text->getPosition().y() + text->getSize().height() / 2 - icon->getSize().height() / 2 ) );
73                         ext.setHeight( text->getPosition().y() + text->getSize().height() + 20 );
74                 }
75                 ext.setWidth( text->getPosition().x() + text->getSize().width() + 20 );
76         }
77         else
78         {
79                 text->move( ePoint(20, 20) );
80                 ext.setWidth( text->getPosition().x() + text->getSize().width()+20 );
81                 ext.setHeight( text->getPosition().y() + text->getSize().height() + 20 );
82         }
83         
84         if (ext.width()<150)
85                 ext.setWidth(150);
86
87         int xpos=20;
88
89         if ( flags & 15)
90         {
91                 for (int i=btOK; i<btMax; i<<=1)
92                         if (flags & i)
93                         {
94                                 eButton *b=new eButton(this);
95                                 b->resize(eSize(size.width(), fontsize+4));
96                                 const char *t="", *shortcut="";
97                                 switch (i)
98                                 {
99                                         case btOK: t=_("OK"); shortcut="green"; CONNECT(b->selected, eMessageBox::pressedOK); break;
100                                         case btCancel: t=_("Cancel"); shortcut="red"; CONNECT(b->selected, eMessageBox::pressedCancel); break;
101                                         case btYes: t=_("Yes"); shortcut="green"; CONNECT(b->selected, eMessageBox::pressedYes); break;
102                                         case btNo: t=_("No"); shortcut="red"; CONNECT(b->selected, eMessageBox::pressedNo); break;
103                                 }
104                                 b->setProperty("shortcut", shortcut);
105                                 b->setText(t);
106                                 eSize bSize=b->getExtend();
107                                 bSize.setWidth( bSize.width() * 2 );
108                                 bSize.setHeight( fontsize + 4 + 10 );
109                                 b->resize(bSize);
110                                 b->move( ePoint( xpos, ext.height() ) );
111
112                                 b->loadDeco();
113                         
114                                 if (def == i)
115                                         setFocus(b);
116                         
117                                 xpos += bSize.width()+20;
118                                 if ( xpos+20 > ext.width() )
119                                         cresize( eSize( xpos+20, ext.height() + bSize.height() + 20 ) );
120                                 else
121                                         cresize( eSize( ext.width(), ext.height() + bSize.height() + 20 ) );
122                         }
123         }
124         else
125                 cresize( ext );
126         zOrderRaise();
127 }
128
129 eMessageBox::~eMessageBox()
130 {
131 }
132
133 void eMessageBox::pressedOK()
134 {
135         if ( in_loop )
136           close(btOK);
137         else
138                 hide();
139 }
140
141 void eMessageBox::pressedCancel()
142 {
143         if ( in_loop )
144           close(btCancel);
145         else
146                 hide();
147 }
148
149 void eMessageBox::pressedYes()
150 {
151         if ( in_loop )
152           close(btYes);
153         else
154                 hide();
155 }
156
157 void eMessageBox::pressedNo()
158 {
159         if ( in_loop )
160           close(btNo);
161         else
162                 hide();
163 }