Mana
Loading...
Searching...
No Matches
textdialog.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/textdialog.h"
23
24#include "actorspritemanager.h"
25
26#include "gui/widgets/button.h"
27#include "gui/widgets/label.h"
29
30#include "utils/gettext.h"
31
33
34TextDialog::TextDialog(const std::string &title, const std::string &msg,
35 Window *parent, bool autoCompleteEnabled):
36 Window(title, true, parent)
37{
38 gcn::Label *textLabel = new Label(msg);
39 mOkButton = new Button(_("OK"), "OK", this);
40 gcn::Button *cancelButton = new Button(_("Cancel"), "CANCEL", this);
41
42 // In TextField the escape key will either cause autoComplete or lose focus
43 mTextField = new TextField(std::string(), ! autoCompleteEnabled);
44 if (autoCompleteEnabled)
46
47 mTextField->addActionListener(this);
48
49 place(0, 0, textLabel, 4);
50 place(0, 1, mTextField, 4);
51 place(2, 2, mOkButton);
52 place(3, 2, cancelButton);
53
54 reflowLayout(textLabel->getWidth() + 20);
55
56 if (getParent())
57 {
58 center();
59 getParent()->moveToTop(this);
60 }
61 setVisible(true);
62 requestModalFocus();
63 mTextField->requestFocus();
64
65 instances++;
66}
67
72
73void TextDialog::action(const gcn::ActionEvent &event)
74{
75 if (event.getId() == "CANCEL")
76 setActionEventId("~" + getActionEventId());
77
78 distributeActionEvent();
80}
81
82const std::string &TextDialog::getText() const
83{
84 return mTextField->getText();
85}
ActorSpriteManager * actorSpriteManager
Definition game.cpp:110
AutoCompleteLister * getPlayerNameLister() const
Button widget.
Definition button.h:38
Label widget.
Definition label.h:34
static int instances
Definition textdialog.h:56
const std::string & getText() const
Get the text in the textfield.
gcn::Button * mOkButton
Definition textdialog.h:59
TextDialog(const std::string &title, const std::string &msg, Window *parent=nullptr, bool autoCompleteEnabled=false)
~TextDialog() override
TextField * mTextField
Definition textdialog.h:58
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
A text field.
Definition textfield.h:72
void setAutoComplete(AutoCompleteLister *lister)
Sets the TextField's source of autocomplete.
Definition textfield.h:133
A window.
Definition window.h:59
void center()
Positions the window in the center of it's parent.
Definition window.cpp:768
virtual void setVisible(bool visible)
Overloads window setVisible by Guichan to allow sticky window handling.
Definition window.cpp:282
void reflowLayout(int w=0, int h=0)
Computes the position of the widgets according to the current layout.
Definition window.cpp:748
LayoutCell & place(int x, int y, gcn::Widget *, int w=1, int h=1)
Adds a widget to the window and sets it at given cell.
Definition window.cpp:737
void scheduleDelete()
Schedule this window for deletion.
Definition window.cpp:299
#define _(s)
Definition gettext.h:38