1 |
|
|
/* |
2 |
|
|
* The ManaPlus Client |
3 |
|
|
* Copyright (C) 2009 The Mana World Development Team |
4 |
|
|
* Copyright (C) 2011-2019 The ManaPlus Developers |
5 |
|
|
* Copyright (C) 2009-2021 Andrei Karas |
6 |
|
|
* |
7 |
|
|
* This file is part of The ManaPlus Client. |
8 |
|
|
* |
9 |
|
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU General Public License as published by |
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
12 |
|
|
* any later version. |
13 |
|
|
* |
14 |
|
|
* This program is distributed in the hope that it will be useful, |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
|
|
* GNU General Public License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU General Public License |
20 |
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
#include "gui/windows/editdialog.h" |
24 |
|
|
|
25 |
|
|
#include "gui/widgets/button.h" |
26 |
|
|
|
27 |
|
|
#include "utils/foreach.h" |
28 |
|
|
#include "utils/gettext.h" |
29 |
|
|
|
30 |
|
|
#include "debug.h" |
31 |
|
|
|
32 |
|
1 |
EditDialog::EditDialog(const std::string &restrict title, |
33 |
|
|
const std::string &restrict msg, |
34 |
|
|
const std::string &restrict eventOk, |
35 |
|
|
const int width, |
36 |
|
|
Window *const parent, |
37 |
|
1 |
const Modal modal) : |
38 |
|
|
Window(title, modal, parent, "edit.xml"), |
39 |
|
|
ActionListener(), |
40 |
|
|
mEventOk(eventOk), |
41 |
|
2 |
mTextField(new TextField(this, std::string(), LoseFocusOnTab_true, |
42 |
✓✗✓✗ ✓✗ |
9 |
nullptr, std::string(), false)) |
43 |
|
|
{ |
44 |
|
1 |
mDefaultWidth = width; |
45 |
✓✗ |
1 |
mTextField->setText(msg); |
46 |
|
1 |
} |
47 |
|
|
|
48 |
|
1 |
void EditDialog::postInit() |
49 |
|
|
{ |
50 |
|
1 |
Window::postInit(); |
51 |
|
|
Button *const okButton = new Button(this, |
52 |
|
|
// TRANSLATORS: edit dialog label |
53 |
|
1 |
_("OK"), |
54 |
|
|
mEventOk, |
55 |
|
|
BUTTON_SKIN, |
56 |
✓✗✓✗
|
4 |
this); |
57 |
|
|
|
58 |
|
1 |
const int pad = getPadding(); |
59 |
|
1 |
const int pad2 = pad * 2; |
60 |
|
1 |
mTextField->setPosition(pad, pad); |
61 |
|
1 |
mTextField->setWidth(mDefaultWidth - pad2); |
62 |
✓✗ |
4 |
const int buttonPadding = getOption("buttonPadding", 8) |
63 |
|
2 |
+ mTextField->getHeight(); |
64 |
|
3 |
setContentSize(mDefaultWidth, okButton->getHeight() |
65 |
|
2 |
+ buttonPadding + pad2); |
66 |
|
2 |
okButton->setPosition((mDefaultWidth - okButton->getWidth()) / 2, |
67 |
|
1 |
buttonPadding + pad); |
68 |
|
|
|
69 |
|
1 |
add(mTextField); |
70 |
|
1 |
add(okButton); |
71 |
|
|
|
72 |
|
1 |
center(); |
73 |
|
1 |
setVisible(Visible_true); |
74 |
|
1 |
okButton->requestFocus(); |
75 |
|
1 |
} |
76 |
|
|
|
77 |
|
|
void EditDialog::action(const ActionEvent &event) |
78 |
|
|
{ |
79 |
|
|
// Proxy button events to our listeners |
80 |
|
|
FOR_EACH (ActionListenerIterator, i, mActionListeners) |
81 |
|
|
(*i)->action(event); |
82 |
|
|
|
83 |
|
|
if (event.getId() == mEventOk) |
84 |
|
|
scheduleDelete(); |
85 |
✓✗✓✗
|
3 |
} |