00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/textdialog.h"
00023
00024 #include "gui/widgets/button.h"
00025 #include "gui/widgets/label.h"
00026 #include "gui/widgets/textfield.h"
00027
00028 #include "utils/gettext.h"
00029
00030 TextDialog::TextDialog(const std::string &title, const std::string &msg,
00031 Window *parent):
00032 Window(title, true, parent),
00033 mTextField(new TextField)
00034 {
00035 gcn::Label *textLabel = new Label(msg);
00036 mOkButton = new Button(_("OK"), "OK", this);
00037 gcn::Button *cancelButton = new Button(_("Cancel"), "CANCEL", this);
00038
00039 int w = textLabel->getWidth() + 20;
00040 int inWidth = mOkButton->getWidth() + cancelButton->getWidth() + 5;
00041 int h = textLabel->getHeight() + 25 + mOkButton->getHeight() + mTextField->getHeight();
00042
00043 if (w < inWidth + 10)
00044 w = inWidth + 10;
00045
00046 setContentSize(w, h);
00047 textLabel->setPosition(10, 10);
00048 mTextField->setWidth(85);
00049 mTextField->setPosition(10,20 + textLabel->getHeight());
00050 mOkButton->setPosition((w - inWidth) / 2,
00051 h - 5 - cancelButton->getHeight());
00052 cancelButton->setPosition(mOkButton->getX() + mOkButton->getWidth() + 5,
00053 h - 5 - cancelButton->getHeight());
00054
00055 add(textLabel);
00056 add(mTextField);
00057 add(mOkButton);
00058 add(cancelButton);
00059
00060 if (getParent()) {
00061 setLocationRelativeTo(getParent());
00062 getParent()->moveToTop(this);
00063 }
00064 setVisible(true);
00065 mTextField->requestFocus();
00066 }
00067
00068 void TextDialog::action(const gcn::ActionEvent &event)
00069 {
00070
00071 ActionListenerIterator i;
00072 for (i = mActionListeners.begin(); i != mActionListeners.end(); ++i)
00073 {
00074 (*i)->action(event);
00075 }
00076
00077 if (event.getId() == "CANCEL" || event.getId() == "OK")
00078 {
00079 scheduleDelete();
00080 }
00081 }
00082
00083 const std::string &TextDialog::getText() const
00084 {
00085 return mTextField->getText();
00086 }
00087
00088 void TextDialog::setOKButtonActionId(const std::string &name)
00089 {
00090 mOkButton->setActionEventId(name);
00091 }