1 #include <lib/gui/emessage.h>
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>
9 eMessageBox::eMessageBox(eString message, eString caption, int flags, int def): eWindow(0), icon(0)
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));
18 if ( flags > 15 ) // we have to draw an icon
21 switch ( flags & ~15 )
24 eSkin::getActive()->queryImage(pm, "icon_info" );
27 eSkin::getActive()->queryImage(pm, "icon_question" );
30 eSkin::getActive()->queryImage(pm, "icon_warning" );
33 eSkin::getActive()->queryImage(pm, "icon_error" );
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 );
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);
54 // here the two labels ( icon, text) has the correct size.. now we calc the border
60 if ( icon->getSize().height() > text->getSize().height() )
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 );
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 );
75 ext.setWidth( text->getPosition().x() + text->getSize().width() + 20 );
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 );
91 for (int i=btOK; i<btMax; i<<=1)
94 eButton *b=new eButton(this);
95 b->resize(eSize(size.width(), fontsize+4));
96 const char *t="", *shortcut="";
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;
104 b->setProperty("shortcut", shortcut);
106 eSize bSize=b->getExtend();
107 bSize.setWidth( bSize.width() * 2 );
108 bSize.setHeight( fontsize + 4 + 10 );
110 b->move( ePoint( xpos, ext.height() ) );
117 xpos += bSize.width()+20;
118 if ( xpos+20 > ext.width() )
119 cresize( eSize( xpos+20, ext.height() + bSize.height() + 20 ) );
121 cresize( eSize( ext.width(), ext.height() + bSize.height() + 20 ) );
129 eMessageBox::~eMessageBox()
133 void eMessageBox::pressedOK()
141 void eMessageBox::pressedCancel()
149 void eMessageBox::pressedYes()
157 void eMessageBox::pressedNo()