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