GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/editdialog.cpp Lines: 25 30 83.3 %
Date: 2017-11-29 Branches: 14 30 46.7 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  Andrei Karas
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
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
2
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
2
                       const Modal modal) :
38
    Window(title, modal, parent, "edit.xml"),
39
    ActionListener(),
40
    mEventOk(eventOk),
41



24
    mTextField(new TextField(this))
42
{
43
2
    mDefaultWidth = width;
44
2
    mTextField->setText(msg);
45
2
}
46
47
2
void EditDialog::postInit()
48
{
49
2
    Window::postInit();
50
    // TRANSLATORS: edit dialog label
51

8
    Button *const okButton = new Button(this, _("OK"), mEventOk, this);
52
53
2
    const int pad = getPadding();
54
2
    const int pad2 = pad * 2;
55
2
    mTextField->setPosition(pad, pad);
56
2
    mTextField->setWidth(mDefaultWidth - pad2);
57

8
    const int buttonPadding = getOption("buttonPadding", 8)
58
4
        + mTextField->getHeight();
59
6
    setContentSize(mDefaultWidth, okButton->getHeight()
60
2
        + buttonPadding + pad2);
61
4
    okButton->setPosition((mDefaultWidth - okButton->getWidth()) / 2,
62
        buttonPadding + pad);
63
64
2
    add(mTextField);
65
2
    add(okButton);
66
67
2
    center();
68
2
    setVisible(Visible_true);
69
2
    okButton->requestFocus();
70
2
}
71
72
void EditDialog::action(const ActionEvent &event)
73
{
74
    // Proxy button events to our listeners
75
    FOR_EACH (ActionListenerIterator, i, mActionListeners)
76
        (*i)->action(event);
77
78
    if (event.getId() == mEventOk)
79
        scheduleDelete();
80

6
}