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
, int timeout
)
10 :eWindow(0), timer(0), sectimer(0), icon(0), def(0), timeout(timeout
)
14 timer
= new eTimer(eApp
);
18 CONNECT( timer
->timeout
, eMessageBox::pressedYes
);
21 CONNECT( timer
->timeout
, eMessageBox::pressedNo
);
24 CONNECT( timer
->timeout
, eMessageBox::pressedOK
);
28 CONNECT( timer
->timeout
, eMessageBox::pressedCancel
);
33 int fontsize
=eSkin::getActive()->queryValue("fontsize", 20);
34 int posx
= eSkin::getActive()->queryValue("eMessageBox.pos.x", 100);
35 int posy
= eSkin::getActive()->queryValue("eMessageBox.pos.y", 70);
36 move(ePoint(posx
, posy
));
37 resize(eSize(450, 430));
39 if ( flags
> 15 ) // we have to draw an icon
42 switch ( flags
& ~15 )
45 pm
= eSkin::getActive()->queryImage( "icon_info" );
48 pm
= eSkin::getActive()->queryImage( "icon_question" );
51 pm
= eSkin::getActive()->queryImage( "icon_warning" );
54 pm
= eSkin::getActive()->queryImage( "icon_error" );
59 icon
= new eLabel(this);
60 icon
->setPixmap( pm
);
61 icon
->pixmap_position
=ePoint(0,0);
62 icon
->resize( eSize(pm
->x
, pm
->y
) );
63 icon
->setBlitFlags( BF_ALPHATEST
);
67 text
=new eLabel(this);
68 text
->setText(message
);
69 text
->resize( eSize( clientrect
.width(), clientrect
.height() ));
70 text
->setFlags( RS_WRAP
|eLabel::flagVCenter
);
71 eSize txtSize
=text
->getExtend();
72 txtSize
+=eSize(15,10); // the given Size of the Text is okay... but the renderer sucks...
73 text
->resize(txtSize
);
75 // here the two labels ( icon, text) has the correct size.. now we calc the border
81 if ( icon
->getSize().height() > text
->getSize().height() )
83 eDebug("icon is higher");
84 eSize s
= icon
->getSize();
85 icon
->move( ePoint( 20, 20 ) );
86 text
->move( ePoint( 20 + s
.width() + 20, icon
->getPosition().y() + s
.height() / 2 - txtSize
.height() / 2 ) );
87 ext
.setHeight( icon
->getPosition().y() + icon
->getSize().height() + 20 );
91 eDebug("text is higher");
92 text
->move( ePoint( 20 + icon
->getSize().width() + 20 , 20 ) );
93 icon
->move( ePoint( 20, text
->getPosition().y() + text
->getSize().height() / 2 - icon
->getSize().height() / 2 ) );
94 ext
.setHeight( text
->getPosition().y() + text
->getSize().height() + 20 );
96 ext
.setWidth( text
->getPosition().x() + text
->getSize().width() + 20 );
100 text
->move( ePoint(20, 20) );
101 ext
.setWidth( text
->getPosition().x() + text
->getSize().width()+20 );
102 ext
.setHeight( text
->getPosition().y() + text
->getSize().height() + 20 );
112 for (int i
=btOK
; i
<btMax
; i
<<=1)
115 eButton
*b
=new eButton(this);
116 b
->resize(eSize(size
.width(), fontsize
+4));
117 const char *t
="", *shortcut
="";
120 case btOK
: t
=_("OK"); shortcut
="green"; CONNECT(b
->selected
, eMessageBox::pressedOK
); break;
121 case btCancel
: t
=_("Cancel"); shortcut
="red"; CONNECT(b
->selected
, eMessageBox::pressedCancel
); break;
122 case btYes
: t
=_("Yes"); shortcut
="green"; CONNECT(b
->selected
, eMessageBox::pressedYes
); break;
123 case btNo
: t
=_("No"); shortcut
="red"; CONNECT(b
->selected
, eMessageBox::pressedNo
); break;
125 b
->setProperty("shortcut", shortcut
);
127 eSize bSize
=b
->getExtend();
128 bSize
.setWidth( bSize
.width() * 2 );
129 bSize
.setHeight( fontsize
+ 4 + 10 );
131 b
->move( ePoint( xpos
, ext
.height() ) );
138 xpos
+= bSize
.width()+20;
143 lTimeout
= new eLabel(this);
144 lTimeout
->setText( eString().sprintf("%d", timeout
) );
145 lTimeout
->resize( eSize(50, fontsize
+4+10) );
146 lTimeout
->move( ePoint( xpos
+10, ext
.height() ) );
147 lTimeout
->setFlags(eLabel::flagVCenter
);
148 xpos
+= lTimeout
->getSize().width()+10;
151 if ( xpos
+20 > ext
.width() )
152 cresize( eSize( xpos
+20, ext
.height() + fontsize
+ 4 + 10 + 20 ) );
154 cresize( eSize( ext
.width(), ext
.height() + fontsize
+ 4 + 10 + 20 ) );
161 int eMessageBox::eventHandler( const eWidgetEvent
&e
)
165 case eWidgetEvent::evtAction
:
166 if ( timer
&& timer
->isActive() )
171 updateTimeoutLabel();
174 case eWidgetEvent::execBegin
:
179 timer
->start(timeout
*1000, true);
181 sectimer
= new eTimer(eApp
);
182 CONNECT( sectimer
->timeout
, eMessageBox::updateTimeoutLabel
);
183 sectimer
->start(1000);
188 return eWindow::eventHandler( e
);
191 void eMessageBox::pressedOK()
199 void eMessageBox::pressedCancel()
207 void eMessageBox::pressedYes()
215 void eMessageBox::pressedNo()
223 void eMessageBox::updateTimeoutLabel()
228 lTimeout
->setText(eString().sprintf("%d", timeout
));
234 eMessageBox::~eMessageBox()