00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/ok_dialog.h"
00023
00024 #include "gui/gui.h"
00025
00026 #include "gui/widgets/button.h"
00027 #include "gui/widgets/textbox.h"
00028
00029 #include "utils/gettext.h"
00030
00031 #include <guichan/font.hpp>
00032
00033 OkDialog::OkDialog(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 *okButton = new Button(_("Ok"), "ok", this);
00043
00044 const int numRows = mTextBox->getNumberOfRows();
00045 const int fontHeight = getFont()->getHeight();
00046 const int height = numRows * fontHeight;
00047 int width = getFont()->getWidth(title);
00048
00049 if (width < mTextBox->getMinWidth())
00050 width = mTextBox->getMinWidth();
00051 if (width < okButton->getWidth())
00052 width = okButton->getWidth();
00053
00054 setContentSize(mTextBox->getMinWidth() + fontHeight, height +
00055 fontHeight + okButton->getHeight());
00056 mTextBox->setPosition(getPadding(), getPadding());
00057
00058
00059
00060 okButton->setPosition((width - okButton->getWidth()) / 2, height + 8);
00061
00062 add(mTextBox);
00063 add(okButton);
00064
00065 center();
00066 setVisible(true);
00067 okButton->requestFocus();
00068 }
00069
00070 void OkDialog::action(const gcn::ActionEvent &event)
00071 {
00072
00073 ActionListenerIterator i;
00074 for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
00075 {
00076 (*i)->action(event);
00077 }
00078
00079
00080 if (event.getId() == "ok")
00081 scheduleDelete();
00082 }