ManaPlus
chatinput.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WIDGETS_CHATINPUT_H
25 #define GUI_WIDGETS_CHATINPUT_H
26 
27 #include "gui/windows/chatwindow.h"
28 
29 #include "configuration.h"
30 
32 
33 #include "gui/widgets/textfield.h"
34 
35 #include "localconsts.h"
36 
40 class ChatInput final : public TextField
41 {
42  public:
43  explicit ChatInput(ChatWindow *const window) :
44  TextField(window, std::string(),
45  LoseFocusOnTab_false, nullptr, std::string(), false),
46  mWindow(window),
47  mFocusGaining(false)
48  {
50  addFocusListener(this);
51  }
52 
54 
55 
59  void focusLost(const Event &event) override final
60  {
61  TextField::focusLost(event);
62  if (mFocusGaining || !config.getBoolValue("protectChatFocus"))
63  {
65  if (chatWindow != nullptr)
67  mFocusGaining = false;
68  return;
69  }
70  mFocusGaining = true;
71  requestFocus();
72  mFocusGaining = false;
73  }
74 
75  void processVisible(const Visible n)
76  {
77  if (mWindow == nullptr || isVisible() == (n == Visible_true))
78  return;
79 
80  if (n == Visible_false)
81  mFocusGaining = true;
82  setVisible(n);
83  if (config.getBoolValue("hideChatInput")
84  || config.getBoolValue("showEmotesButton"))
85  {
87  }
88  if (emoteWindow != nullptr)
89  {
90  emoteWindow->hide();
91  }
92  }
93 
95  { mFocusGaining = true; }
96 
97  void setVisible(Visible visible)
98  {
99  TextField::setVisible(visible);
100  }
101 
102  private:
105 };
106 
107 #endif // GUI_WIDGETS_CHATINPUT_H
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
void unprotectFocus()
Definition: chatinput.h:94
void processVisible(const Visible n)
Definition: chatinput.h:75
void setVisible(Visible visible)
Definition: chatinput.h:97
void focusLost(const Event &event)
Definition: chatinput.h:59
bool mFocusGaining
Definition: chatinput.h:104
ChatInput(ChatWindow *const window)
Definition: chatinput.h:43
ChatWindow * mWindow
Definition: chatinput.h:103
void updateVisibility()
void adjustTabSize()
Definition: chatwindow.cpp:281
bool getBoolValue(const std::string &key) const
Definition: event.h:79
void focusLost(const Event &event)
Definition: textfield.cpp:799
void setVisible(Visible visible)
Definition: widget.cpp:225
virtual void requestFocus()
Definition: widget.cpp:204
void addFocusListener(FocusListener *const focusListener)
Definition: widget.cpp:282
bool isVisible() const
Definition: widget.h:378
Configuration config
EmoteWindow * emoteWindow
Definition: emotewindow.cpp:49
#define override
Definition: localconsts.h:47
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define nullptr
Definition: localconsts.h:45
const bool LoseFocusOnTab_false
bool Visible
Definition: visible.h:30
const bool Visible_false
Definition: visible.h:30
const bool Visible_true
Definition: visible.h:30