ManaPlus
src
gui
windows
editdialog.cpp
Go to the documentation of this file.
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
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
const
Modal
modal) :
38
Window
(title, modal, parent,
"edit.xml"
),
39
ActionListener
(),
40
mEventOk(eventOk),
41
mTextField(
new
TextField
(this,
std
::string(),
LoseFocusOnTab_true
,
42
nullptr
,
std
::string(), false))
43
{
44
mDefaultWidth
= width;
45
mTextField
->
setText
(
msg
);
46
}
47
48
void
EditDialog::postInit
()
49
{
50
Window::postInit
();
51
Button
*
const
okButton =
new
Button
(
this
,
52
// TRANSLATORS: edit dialog label
53
_
(
"OK"
),
54
mEventOk
,
55
BUTTON_SKIN
,
56
this
);
57
58
const
int
pad =
getPadding
();
59
const
int
pad2 = pad * 2;
60
mTextField
->
setPosition
(pad, pad);
61
mTextField
->
setWidth
(
mDefaultWidth
- pad2);
62
const
int
buttonPadding =
getOption
(
"buttonPadding"
, 8)
63
+
mTextField
->
getHeight
();
64
setContentSize
(
mDefaultWidth
, okButton->
getHeight
()
65
+ buttonPadding + pad2);
66
okButton->
setPosition
((
mDefaultWidth
- okButton->
getWidth
()) / 2,
67
buttonPadding + pad);
68
69
add
(
mTextField
);
70
add
(okButton);
71
72
center
();
73
setVisible
(
Visible_true
);
74
okButton->
requestFocus
();
75
}
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
}
button.h
BUTTON_SKIN
const std::string BUTTON_SKIN
Definition:
button.h:89
ActionEvent
Definition:
actionevent.h:98
ActionEvent::getId
const std::string & getId() const
Definition:
actionevent.h:122
ActionListener
Definition:
actionlistener.h:79
BasicContainer2::add
virtual void add(Widget *const widget)
Definition:
basiccontainer2.cpp:113
Button
Definition:
button.h:102
EditDialog::postInit
void postInit()
Definition:
editdialog.cpp:48
EditDialog::mTextField
TextField * mTextField
Definition:
editdialog.h:70
EditDialog::action
void action(const ActionEvent &event)
Definition:
editdialog.cpp:77
EditDialog::EditDialog
EditDialog(const std::string &title, const std::string &msg, const std::string &eventOk, const int width, Window *const parent, const Modal modal)
Definition:
editdialog.cpp:32
EditDialog::mEventOk
std::string mEventOk
Definition:
editdialog.h:69
TextField
Definition:
textfield.h:93
TextField::setText
void setText(const std::string &text)
Definition:
textfield.cpp:803
Widget::setWidth
void setWidth(const int width)
Definition:
widget.cpp:133
Widget::mActionListeners
ActionListenerList mActionListeners
Definition:
widget.h:1034
Widget::requestFocus
virtual void requestFocus()
Definition:
widget.cpp:204
Widget::setPosition
void setPosition(const int x, const int y)
Definition:
widget.cpp:161
Widget::ActionListenerIterator
ActionListenerList::iterator ActionListenerIterator
Definition:
widget.h:1039
Widget::getHeight
int getHeight() const
Definition:
widget.h:240
Widget::getWidth
int getWidth() const
Definition:
widget.h:221
Window
Definition:
window.h:102
Window::center
void center()
Definition:
window.cpp:1417
Window::setVisible
virtual void setVisible(Visible visible)
Definition:
window.cpp:778
Window::setContentSize
void setContentSize(int width, int height)
Definition:
window.cpp:492
Window::getOption
int getOption(const std::string &name, const int def) const
Definition:
window.cpp:1454
Window::mDefaultWidth
int mDefaultWidth
Definition:
window.h:652
Window::postInit
void postInit()
Definition:
window.cpp:249
Window::getPadding
int getPadding() const
Definition:
window.h:504
Window::scheduleDelete
virtual void scheduleDelete()
Definition:
window.cpp:831
debug.h
new
#define new
Definition:
debug_new.h:147
editdialog.h
foreach.h
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition:
foreach.h:25
gettext.h
_
#define _(s)
Definition:
gettext.h:35
restrict
#define restrict
Definition:
localconsts.h:165
nullptr
#define nullptr
Definition:
localconsts.h:45
LoseFocusOnTab_true
const bool LoseFocusOnTab_true
Definition:
losefocusontab.h:30
Modal
bool Modal
Definition:
modal.h:30
Actions::msg
bool msg(InputEvent &event)
Definition:
chat.cpp:39
std
Definition:
mseprimitives.h:398
Visible_true
const bool Visible_true
Definition:
visible.h:30
Generated on Wed Mar 17 2021 19:19:07 for ManaPlus by
1.9.1