00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/confirm_dialog.h"
00023
00024 #include "gui/widgets/button.h"
00025 #include "gui/widgets/textbox.h"
00026
00027 #include "gui/gui.h"
00028
00029 #include "utils/gettext.h"
00030
00031 #include <guichan/font.hpp>
00032
00033 ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
00034 Window *parent):
00035 Window(title, true, parent)
00036 {
00037 mTextBox = new TextBox;
00038 mTextBox->setEditable(false);
00039 mTextBox->setOpaque(false);
00040 mTextBox->setTextWrapped(msg, 260);
00041
00042 gcn::Button *yesButton = new Button(_("Yes"), "yes", this);
00043 gcn::Button *noButton = new Button(_("No"), "no", this);
00044
00045 const int numRows = mTextBox->getNumberOfRows();
00046 const int inWidth = yesButton->getWidth() + noButton->getWidth() +
00047 (2 * getPadding());
00048 const int fontHeight = getFont()->getHeight();
00049 const int height = numRows * fontHeight;
00050 int width = getFont()->getWidth(title);
00051
00052 if (width < mTextBox->getMinWidth())
00053 width = mTextBox->getMinWidth();
00054 if (width < inWidth)
00055 width = inWidth;
00056
00057 setContentSize(mTextBox->getMinWidth() + fontHeight, height + fontHeight +
00058 noButton->getHeight());
00059 mTextBox->setPosition(getPadding(), getPadding());
00060
00061
00062
00063 yesButton->setPosition((width - inWidth) / 2, height + 8);
00064 noButton->setPosition(yesButton->getX() + inWidth - noButton->getWidth(),
00065 height + 8);
00066
00067 add(mTextBox);
00068 add(yesButton);
00069 add(noButton);
00070
00071 if (getParent())
00072 {
00073 center();
00074 getParent()->moveToTop(this);
00075 }
00076 setVisible(true);
00077 yesButton->requestFocus();
00078 }
00079
00080 void ConfirmDialog::action(const gcn::ActionEvent &event)
00081 {
00082
00083 ActionListenerIterator i;
00084 for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
00085 {
00086 (*i)->action(event);
00087 }
00088
00089
00090 if (event.getId() == "yes" || event.getId() == "no")
00091 scheduleDelete();
00092 }