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-2018 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 #ifndef GUI_WIDGETS_CHATINPUT_H
24 #define GUI_WIDGETS_CHATINPUT_H
25 
26 #include "gui/windows/chatwindow.h"
27 
28 #include "configuration.h"
29 
31 
32 #include "gui/widgets/textfield.h"
33 
34 #include "localconsts.h"
35 
39 class ChatInput final : public TextField
40 {
41  public:
42  explicit ChatInput(ChatWindow *const window) :
43  TextField(window, std::string(),
44  LoseFocusOnTab_false, nullptr, std::string(), false),
45  mWindow(window),
46  mFocusGaining(false)
47  {
49  addFocusListener(this);
50  }
51 
53 
54 
58  void focusLost(const Event &event) override final
59  {
60  TextField::focusLost(event);
61  if (mFocusGaining || !config.getBoolValue("protectChatFocus"))
62  {
64  if (chatWindow != nullptr)
66  mFocusGaining = false;
67  return;
68  }
69  mFocusGaining = true;
70  requestFocus();
71  mFocusGaining = false;
72  }
73 
74  void processVisible(const Visible n)
75  {
76  if (mWindow == nullptr || isVisible() == (n == Visible_true))
77  return;
78 
79  if (n == Visible_false)
80  mFocusGaining = true;
81  setVisible(n);
82  if (config.getBoolValue("hideChatInput")
83  || config.getBoolValue("showEmotesButton"))
84  {
86  }
87  if (emoteWindow != nullptr)
88  {
89  emoteWindow->hide();
90  }
91  }
92 
94  { mFocusGaining = true; }
95 
96  void setVisible(Visible visible)
97  {
98  TextField::setVisible(visible);
99  }
100 
101  private:
104 };
105 
106 #endif // GUI_WIDGETS_CHATINPUT_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
ChatWindow * chatWindow
Definition: chatwindow.cpp:88
const bool LoseFocusOnTab_false
void unprotectFocus()
Definition: chatinput.h:93
const bool Visible_true
Definition: visible.h:29
void updateVisibility()
void setVisible(Visible visible)
Definition: widget.cpp:224
Configuration config
#define final
Definition: localconsts.h:45
void addFocusListener(FocusListener *const focusListener)
Definition: widget.cpp:281
void focusLost(const Event &event)
Definition: textfield.cpp:798
void adjustTabSize()
Definition: chatwindow.cpp:275
bool mFocusGaining
Definition: chatinput.h:103
bool getBoolValue(const std::string &key) const
virtual void requestFocus()
Definition: widget.cpp:203
ChatInput(ChatWindow *const window)
Definition: chatinput.h:42
const bool Visible_false
Definition: visible.h:29
EmoteWindow * emoteWindow
Definition: emotewindow.cpp:48
void setVisible(Visible visible)
Definition: chatinput.h:96
#define nullptr
Definition: localconsts.h:44
ChatWindow * mWindow
Definition: chatinput.h:102
bool isVisible() const
Definition: widget.h:377
void focusLost(const Event &event)
Definition: chatinput.h:58
Definition: event.h:77
#define override
Definition: localconsts.h:46
void processVisible(const Visible n)
Definition: chatinput.h:74