Mana
Loading...
Searching...
No Matches
confirmdialog.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/confirmdialog.h"
23
24#include "gui/widgets/button.h"
25#include "gui/widgets/layout.h"
26#include "gui/widgets/textbox.h"
27
28#include "utils/gettext.h"
29
30#include <guichan/font.hpp>
31
32ConfirmDialog::ConfirmDialog(const std::string &title,
33 const std::string &msg,
34 Window *parent):
35 Window(title, true, parent)
36{
37 auto textBox = new TextBox;
38 textBox->setEditable(false);
39 textBox->setOpaque(false);
40 textBox->setTextWrapped(msg, 260);
41
42 gcn::Button *yesButton = new Button(_("Yes"), "yes", this);
43 gcn::Button *noButton = new Button(_("No"), "no", this);
44
45 auto place = getPlacer(0, 0);
46 place(0, 0, textBox);
47
48 place = getPlacer(0, 1);
49 place(0, 0, yesButton);
50 place(1, 0, noButton);
53
54 if (getParent())
55 {
56 center();
57 getParent()->moveToTop(this);
58 }
59 setVisible(true);
60 yesButton->requestFocus();
61}
62
63void ConfirmDialog::action(const gcn::ActionEvent &event)
64{
65 setActionEventId(event.getId());
66 distributeActionEvent();
68}
Button widget.
Definition button.h:38
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
ConfirmDialog(const std::string &title, const std::string &msg, Window *parent=nullptr)
LayoutCell & setHAlign(Alignment a)
Sets the horizontal alignment of the cell content.
Definition layout.h:185
A text box, meant to be used inside a scroll area.
Definition textbox.h:36
void setTextWrapped(const std::string &text, int minDimension)
Sets the text after wrapping it to the current width of the widget.
Definition textbox.cpp:42
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
ContainerPlacer getPlacer(int x, int y)
Returns a proxy for adding widgets in an inner table of the layout.
Definition window.cpp:743
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