ManaPlus
chatwindow.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_WINDOWS_CHATWINDOW_H
25 #define GUI_WINDOWS_CHATWINDOW_H
26 
27 #include "enums/gui/chatmsgtype.h"
28 #include "enums/gui/chattabtype.h"
29 
32 
33 #include "gui/widgets/window.h"
34 
38 #include "listeners/keylistener.h"
39 
40 class Button;
41 class ChannelTab;
42 class ChatTab;
43 class ChatInput;
44 class ColorListModel;
45 class DropDown;
46 class TabbedArea;
47 class ItemLinkHandler;
48 class WhisperTab;
49 
55 class ChatWindow final : public Window,
56  public ActionListener,
57  public KeyListener,
58  public ConfigListener,
59  public AttributeListener,
61 {
62  public:
66  explicit ChatWindow(const std::string &name);
67 
69 
70 
73  ~ChatWindow() override final;
74 
79 
83  static void clearTab(ChatTab *const tab);
84 
88  void clearTab() const;
89 
93  void prevTab();
94 
98  void nextTab();
99 
103  void closeTab() const;
104 
108  void defaultTab();
109 
113  void action(const ActionEvent &event) override final;
114 
121  bool requestChatFocus();
122 
126  bool isInputFocused() const A_WARN_UNUSED;
127 
133  void chatInput(const std::string &msg) const;
134 
140  void localChatInput(const std::string &msg) const;
141 
143  void keyPressed(KeyEvent &event) override final;
144 
146  void setInputText(const std::string &text);
147 
149  void addInputText(const std::string &text,
150  const bool space);
151 
153  void addItemText(const std::string &item);
154 
156  void setVisible(Visible visible) override final;
157 
161  void mouseDragged(MouseEvent &event) override final;
162 
166  void mousePressed(MouseEvent &event) override final;
167 
175  void scroll(const int amount) const;
176 
182  void setRecordingFile(const std::string &msg);
183 
185  { return mReturnToggles; }
186 
187  void setReturnTogglesChat(const bool toggles)
188  { mReturnToggles = toggles; }
189 
190  void doPresent() const;
191 
192  void addWhisper(const std::string &restrict nick,
193  const std::string &restrict mes,
194  const ChatMsgTypeT own);
195 
196  WhisperTab *addWhisperTab(const std::string &caption,
197  const std::string &nick,
198  const bool switchTo) A_WARN_UNUSED;
199 
200  WhisperTab *getWhisperTab(const std::string &nick) const A_WARN_UNUSED;
201 
202  ChatTab *addChannelTab(const std::string &name,
203  const bool switchTo);
204 
205  ChatTab *addSpecialChannelTab(const std::string &name,
206  const bool switchTo);
207 
208  ChatTab *addChatTab(const std::string &name,
209  const bool switchTo,
210  const bool join) A_WARN_UNUSED;
211 
212  void joinRoom(const bool isJoin);
213 
214  void removeAllWhispers();
215 
216  void removeAllChannels();
217 
218  void ignoreAllWhispers();
219 
220  bool resortChatLog(std::string line, ChatMsgTypeT own,
221  const std::string &channel,
222  const IgnoreRecord ignoreRecord,
223  const TryRemoveColors tryRemoveColors);
224 
225  static void battleChatLog(const std::string &line,
226  ChatMsgTypeT own,
227  const IgnoreRecord ignoreRecord,
228  const TryRemoveColors tryRemoveColors);
229 
230  void channelChatLog(const std::string &channel,
231  const std::string &line,
232  ChatMsgTypeT own,
233  const IgnoreRecord ignoreRecord,
234  const TryRemoveColors tryRemoveColors);
235 
236  void updateOnline(const std::set<std::string> &onlinePlayers) const;
237 
238  void loadState();
239 
240  void saveState() const;
241 
242  static bool saveTab(const int num,
243  const ChatTab *const tab);
244 
245  void loadCustomList();
246 
247  void loadGMCommands();
248 
249  static std::string doReplace(const std::string &msg) A_WARN_UNUSED;
250 
251  void adjustTabSize();
252 
253  void addToAwayLog(const std::string &line);
254 
255  void displayAwayLog() const;
256 
258  { mAwayLog.clear(); }
259 
260  void parseHighlights();
261 
262  void parseGlobalsFilter();
263 
264  bool findHighlight(const std::string &str) A_WARN_UNUSED;
265 
266  void copyToClipboard(const int x, const int y) const;
267 
268  void optionChanged(const std::string &name) override final;
269 
270  void mouseEntered(MouseEvent& event) override final;
271 
272  void mouseMoved(MouseEvent &event) override final;
273 
274  void mouseExited(MouseEvent& event A_UNUSED) override final;
275 
276  void draw(Graphics *const graphics) override final A_NONNULL(2);
277 
278  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
279 
280  void updateVisibility();
281 
282  void unHideWindow();
283 
284  void widgetResized(const Event &event) override final;
285 
286  void addGlobalMessage(const std::string &line);
287 
288  void postInit() override final;
289 
290  bool isTabPresent(const ChatTab *const tab) const A_WARN_UNUSED;
291 
292  void selectTabByType(const ChatTabTypeT &type);
293 
294  void attributeChanged(const AttributesT id,
295  const int64_t oldVal,
296  const int64_t newVal) override final;
297 
298  void postConnection();
299 
300  void showGMTab();
301 
302  void debugMessage(const std::string &msg) override final;
303 
305 
306 #ifdef USE_PROFILER
307  void logicChildren();
308 #endif // USE_PROFILER
309 
310  protected:
311  friend class ChannelTab;
312  friend class ChatTab;
313  friend class WhisperTab;
314  friend class PopupMenu;
315 
316  typedef std::list<std::string> History;
317 
319  void removeTab(ChatTab *const tab);
320 
322  void addTab(ChatTab *const tab);
323 
324  void removeWhisper(const std::string &nick);
325 
326  void removeChannel(const std::string &nick);
327 
328  void autoComplete();
329 
330  std::string addColors(std::string &msg);
331 
332  std::string autoCompleteHistory(const std::string &partName) const;
333 
334  static std::string autoComplete(const std::string &partName,
335  const History *const words);
336 
337  static std::string autoComplete(const StringVect &names,
338  std::string partName);
339 
342 
345 
348 
349  void initTradeFilter();
350 
351  void toggleChatFocus();
352 
353  unsigned int mRainbowColor;
354 
355  private:
356  void fillCommands();
357 
358  void loadCommandsFile(const std::string &name);
359 
360  void updateTabsMargin();
361 
362  bool addCurrentToHistory();
363 
364  typedef std::map<const std::string, WhisperTab*> TabMap;
365  typedef std::map<const std::string, ChannelTab*> ChannelMap;
366 
370 
371  typedef History::iterator HistoryIterator;
375  typedef std::list<std::string> ChatCommands;
376  typedef ChatCommands::iterator ChatCommandsIterator;
379 
381 
385  std::list<std::string> mAwayLog;
391  unsigned int mChatHistoryIndex;
392  bool mReturnToggles; // Marks whether <Return> toggles the chat log
393  // or not
394  bool mGMLoaded;
396  bool mAutoHide;
401 };
402 
403 extern ChatWindow *chatWindow;
404 
405 #endif // GUI_WINDOWS_CHATWINDOW_H
Attributes ::T AttributesT
Definition: attributes.h:118
ChatMsgType ::T ChatMsgTypeT
Definition: chatmsgtype.h:41
ChatTabType ::T ChatTabTypeT
Definition: chattabtype.h:49
ChatWindow * chatWindow
Definition: chatwindow.cpp:94
virtual void logicChildren()
Definition: button.h:102
bool mReturnToggles
Definition: chatwindow.h:392
StringVect mTradeFilter
Definition: chatwindow.h:380
void addWhisper(const std::string &nick, const std::string &mes, const ChatMsgTypeT own)
WhisperTab * addWhisperTab(const std::string &caption, const std::string &nick, const bool switchTo)
void channelChatLog(const std::string &channel, const std::string &line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
unsigned int mRainbowColor
Definition: chatwindow.h:353
bool mEnableTradeFilter
Definition: chatwindow.h:399
void postConnection()
void scroll(const int amount) const
Definition: chatwindow.cpp:733
ChatTab * addChannelTab(const std::string &name, const bool switchTo)
std::list< std::string > History
Definition: chatwindow.h:316
void chatInput(const std::string &msg) const
Definition: chatwindow.cpp:665
void optionChanged(const std::string &name)
void mousePressed(MouseEvent &event)
Definition: chatwindow.cpp:743
void parseGlobalsFilter()
unsigned int mChatHistoryIndex
Definition: chatwindow.h:391
void initTradeFilter()
std::string autoCompleteHistory(const std::string &partName) const
void addItemText(const std::string &item)
void fillCommands()
Definition: chatwindow.cpp:258
void clearAwayLog()
Definition: chatwindow.h:257
bool addCurrentToHistory()
bool resortChatLog(std::string line, ChatMsgTypeT own, const std::string &channel, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
ChatInput * mChatInput
Definition: chatwindow.h:347
void addTab(ChatTab *const tab)
Definition: chatwindow.cpp:589
void unHideWindow()
ChannelMap mChannels
Definition: chatwindow.h:369
void joinRoom(const bool isJoin)
TabbedArea * mChatTabs
Definition: chatwindow.h:344
StringVect mHighlights
Definition: chatwindow.h:386
bool isInputFocused() const
Definition: chatwindow.cpp:579
bool mShowAllLang
Definition: chatwindow.h:398
void setRecordingFile(const std::string &msg)
WhisperTab * getWhisperTab(const std::string &nick) const
void toggleChatFocus()
void defaultTab()
Definition: chatwindow.cpp:433
void removeWhisper(const std::string &nick)
Definition: chatwindow.cpp:598
ColorListModel * mColorListModel
Definition: chatwindow.h:382
void setInputText(const std::string &text)
static bool saveTab(const int num, const ChatTab *const tab)
void draw(Graphics *const graphics)
void updateVisibility()
void safeDraw(Graphics *const graphics)
bool getReturnTogglesChat() const
Definition: chatwindow.h:184
bool mTmpVisible
Definition: chatwindow.h:400
void updateOnline(const std::set< std::string > &onlinePlayers) const
void clearTab() const
Definition: chatwindow.cpp:368
void localChatInput(const std::string &msg) const
Definition: chatwindow.cpp:691
void closeTab() const
Definition: chatwindow.cpp:419
History::iterator HistoryIterator
Definition: chatwindow.h:371
void mouseMoved(MouseEvent &event)
bool mHaveMouse
Definition: chatwindow.h:395
void loadCustomList()
void scheduleDelete()
Button * mChatButton
Definition: chatwindow.h:384
void parseHighlights()
StringVect mGlobalsFilter
Definition: chatwindow.h:387
DropDown * mColorPicker
Definition: chatwindow.h:383
HistoryIterator mCurHist
Definition: chatwindow.h:373
bool requestChatFocus()
Definition: chatwindow.cpp:553
TabMap mWhispers
Definition: chatwindow.h:368
ItemLinkHandler * mItemLinkHandler
Definition: chatwindow.h:341
void nextTab()
Definition: chatwindow.cpp:387
void keyPressed(KeyEvent &event)
Definition: chatwindow.cpp:822
int mChatColor
Definition: chatwindow.h:388
void removeTab(ChatTab *const tab)
Definition: chatwindow.cpp:584
std::map< const std::string, WhisperTab * > TabMap
Definition: chatwindow.h:364
bool mShowBattleEvents
Definition: chatwindow.h:397
bool mGMLoaded
Definition: chatwindow.h:394
void updateTabsMargin()
Definition: chatwindow.cpp:273
void doPresent() const
Definition: chatwindow.cpp:699
void displayAwayLog() const
static std::string doReplace(const std::string &msg)
void showGMTab()
bool mAutoHide
Definition: chatwindow.h:396
void loadCommandsFile(const std::string &name)
Definition: chatwindow.cpp:242
bool isTabPresent(const ChatTab *const tab) const
bool findHighlight(const std::string &str)
ChatCommands::iterator ChatCommandsIterator
Definition: chatwindow.h:376
ChatWindow(const std::string &name)
Definition: chatwindow.cpp:98
void loadState()
void setVisible(Visible visible)
void prevTab()
Definition: chatwindow.cpp:373
std::list< std::string > mAwayLog
Definition: chatwindow.h:385
History mCommands
Definition: chatwindow.h:377
void copyToClipboard(const int x, const int y) const
void removeAllWhispers()
Definition: chatwindow.cpp:613
void addGlobalMessage(const std::string &line)
void debugMessage(const std::string &msg)
void addToAwayLog(const std::string &line)
ChatTab * addSpecialChannelTab(const std::string &name, const bool switchTo)
void loadGMCommands()
Definition: chatwindow.cpp:264
void ignoreAllWhispers()
Definition: chatwindow.cpp:645
void saveState() const
int mEmoteButtonSpacing
Definition: chatwindow.h:389
void widgetResized(const Event &event)
Definition: chatwindow.cpp:350
static void battleChatLog(const std::string &line, ChatMsgTypeT own, const IgnoreRecord ignoreRecord, const TryRemoveColors tryRemoveColors)
void mouseEntered(MouseEvent &event)
History mCustomWords
Definition: chatwindow.h:378
std::list< std::string > ChatCommands
Definition: chatwindow.h:375
void setReturnTogglesChat(const bool toggles)
Definition: chatwindow.h:187
void removeAllChannels()
Definition: chatwindow.cpp:629
std::map< const std::string, ChannelTab * > ChannelMap
Definition: chatwindow.h:365
void autoComplete()
void mouseExited(MouseEvent &event)
void action(const ActionEvent &event)
Definition: chatwindow.cpp:439
void mouseDragged(MouseEvent &event)
Definition: chatwindow.cpp:799
void attributeChanged(const AttributesT id, const int64_t oldVal, const int64_t newVal)
void postInit()
Definition: chatwindow.cpp:232
int mEmoteButtonY
Definition: chatwindow.h:390
void addInputText(const std::string &text, const bool space)
void adjustTabSize()
Definition: chatwindow.cpp:281
std::string addColors(std::string &msg)
ChatTab * getFocused() const
Definition: chatwindow.cpp:357
void removeChannel(const std::string &nick)
Definition: chatwindow.cpp:605
ChatTab * addChatTab(const std::string &name, const bool switchTo, const bool join)
History mHistory
Definition: chatwindow.h:372
void selectTabByType(const ChatTabTypeT &type)
Definition: chatwindow.cpp:401
Definition: event.h:79
Definition: window.h:102
bool IgnoreRecord
Definition: ignorerecord.h:30
#define restrict
Definition: localconsts.h:165
#define override
Definition: localconsts.h:47
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
#define A_UNUSED
Definition: localconsts.h:160
bool msg(InputEvent &event)
Definition: chat.cpp:39
std::vector< std::string > StringVect
Definition: stringvector.h:29
bool TryRemoveColors
bool Visible
Definition: visible.h:30