Mana
Loading...
Searching...
No Matches
okdialog.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/okdialog.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
32OkDialog::OkDialog(const std::string &title, const std::string &msg,
33 bool modal, Window *parent):
34 Window(title, modal, parent)
35{
36 auto textBox = new TextBox;
37 textBox->setEditable(false);
38 textBox->setOpaque(false);
39 textBox->setTextWrapped(msg, 260);
40
41 gcn::Button *okButton = new Button(_("OK"), "ok", this);
42
43 place(0, 0, textBox);
44 place(0, 1, okButton).setHAlign(Layout::CENTER);
46
47 center();
48 setVisible(true);
49 okButton->requestFocus();
50}
51
52void OkDialog::action(const gcn::ActionEvent &event)
53{
54 setActionEventId(event.getId());
55 distributeActionEvent();
57}
Button widget.
Definition button.h:38
LayoutCell & setHAlign(Alignment a)
Sets the horizontal alignment of the cell content.
Definition layout.h:185
void action(const gcn::ActionEvent &event) override
Called when receiving actions from the widgets.
Definition okdialog.cpp:52
OkDialog(const std::string &title, const std::string &msg, bool modal=true, Window *parent=nullptr)
Definition okdialog.cpp:32
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
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