GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/chatwindow.h Lines: 0 3 0.0 %
Date: 2017-11-29 Branches: 0 0 0.0 %

Line Branch Exec Source
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-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
#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
29
#include "enums/simpletypes/ignorerecord.h"
30
#include "enums/simpletypes/tryremovecolors.h"
31
32
#include "gui/widgets/window.h"
33
34
#include "listeners/actionlistener.h"
35
#include "listeners/attributelistener.h"
36
#include "listeners/debugmessagelistener.h"
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
49
/**
50
 * The chat window.
51
 *
52
 * \ingroup Interface
53
 */
54
class ChatWindow final : public Window,
55
                         public ActionListener,
56
                         public KeyListener,
57
                         public ConfigListener,
58
                         public AttributeListener,
59
                         public DebugMessageListener
60
{
61
    public:
62
        /**
63
         * Constructor.
64
         */
65
        explicit ChatWindow(const std::string &name);
66
67
        A_DELETE_COPY(ChatWindow)
68
69
        /**
70
         * Destructor: used to write back values to the config file
71
         */
72
        ~ChatWindow();
73
74
        /**
75
         * Gets the focused tab.
76
         */
77
        ChatTab *getFocused() const A_WARN_UNUSED;
78
79
        /**
80
         * Clear the given tab.
81
         */
82
        static void clearTab(ChatTab *const tab);
83
84
        /**
85
         * Clear the current tab.
86
         */
87
        void clearTab() const;
88
89
        /**
90
         * Switch to the previous tab in order
91
         */
92
        void prevTab();
93
94
        /**
95
         * Switch to the next tab in order
96
         */
97
        void nextTab();
98
99
        /**
100
         * Close current chat tab
101
         */
102
        void closeTab() const;
103
104
        /**
105
         * Switch to the default tab
106
         */
107
        void defaultTab();
108
109
        /**
110
         * Performs action.
111
         */
112
        void action(const ActionEvent &event) override final;
113
114
        /**
115
         * Request focus for typing chat message.
116
         *
117
         * \returns true if the input was shown
118
         *          false otherwise
119
         */
120
        bool requestChatFocus();
121
122
        /**
123
         * Checks whether ChatWindow is Focused or not.
124
         */
125
        bool isInputFocused() const A_WARN_UNUSED;
126
127
        /**
128
         * Passes the text to the current tab as input
129
         *
130
         * @param msg  The message text which is to be sent.
131
         */
132
        void chatInput(const std::string &msg) const;
133
134
        /**
135
         * Passes the text to the local chat tab as input
136
         *
137
         * @param msg  The message text which is to be sent.
138
         */
139
        void localChatInput(const std::string &msg) const;
140
141
        /** Called when key is pressed */
142
        void keyPressed(KeyEvent &event) override final;
143
144
        /** Set the chat input as the given text. */
145
        void setInputText(const std::string &text);
146
147
        /** Add the given text to the chat input. */
148
        void addInputText(const std::string &text, const bool space = true);
149
150
        /** Called to add item to chat */
151
        void addItemText(const std::string &item);
152
153
        /** Override to reset mTmpVisible */
154
        void setVisible(Visible visible) override final;
155
156
        /**
157
         * Handles mouse when dragged.
158
         */
159
        void mouseDragged(MouseEvent &event) override final;
160
161
        /**
162
         * Handles mouse when pressed.
163
         */
164
        void mousePressed(MouseEvent &event) override final;
165
166
        /**
167
         * Scrolls the chat window
168
         *
169
         * @param amount direction and amount to scroll.  Negative numbers scroll
170
         * up, positive numbers scroll down.  The absolute amount indicates the
171
         * amount of 1/8ths of chat window real estate that should be scrolled.
172
         */
173
        void scroll(const int amount) const;
174
175
        /**
176
         * Sets the file being recorded to
177
         *
178
         * @param msg The file to write out to. If null, then stop recording.
179
         */
180
        void setRecordingFile(const std::string &msg);
181
182
        bool getReturnTogglesChat() const noexcept2 A_WARN_UNUSED
183
        { return mReturnToggles; }
184
185
        void setReturnTogglesChat(const bool toggles)
186
        { mReturnToggles = toggles; }
187
188
        void doPresent() const;
189
190
        void addWhisper(const std::string &restrict nick,
191
                        const std::string &restrict mes,
192
                        const ChatMsgTypeT own = ChatMsgType::BY_OTHER);
193
194
        WhisperTab *addWhisperTab(const std::string &caption,
195
                                  const std::string &nick,
196
                                  const bool switchTo = false) A_WARN_UNUSED;
197
198
        WhisperTab *getWhisperTab(const std::string &nick) const A_WARN_UNUSED;
199
200
        ChatTab *addChannelTab(const std::string &name,
201
                               const bool switchTo = false);
202
203
        ChatTab *addSpecialChannelTab(const std::string &name,
204
                                      const bool switchTo = false);
205
206
        ChatTab *addChatTab(const std::string &name,
207
                            const bool switchTo,
208
                            const bool join) A_WARN_UNUSED;
209
210
        void joinRoom(const bool isJoin);
211
212
        void removeAllWhispers();
213
214
        void removeAllChannels();
215
216
        void ignoreAllWhispers();
217
218
        bool resortChatLog(std::string line, ChatMsgTypeT own,
219
                           const std::string &channel,
220
                           const IgnoreRecord ignoreRecord,
221
                           const TryRemoveColors tryRemoveColors);
222
223
        static void battleChatLog(const std::string &line,
224
                                  ChatMsgTypeT own
225
                                  = ChatMsgType::BY_UNKNOWN,
226
                                  const IgnoreRecord ignoreRecord
227
                                  = IgnoreRecord_false,
228
                                  const TryRemoveColors tryRemoveColors
229
                                  = TryRemoveColors_true);
230
231
        void channelChatLog(const std::string &channel,
232
                            const std::string &line,
233
                            ChatMsgTypeT own,
234
                            const IgnoreRecord ignoreRecord,
235
                            const TryRemoveColors tryRemoveColors);
236
237
        void updateOnline(const std::set<std::string> &onlinePlayers) const;
238
239
        void loadState();
240
241
        void saveState() const;
242
243
        bool saveTab(const int num,
244
                     const ChatTab *const tab) const;
245
246
        void loadCustomList();
247
248
        void loadGMCommands();
249
250
        static std::string doReplace(const std::string &msg) A_WARN_UNUSED;
251
252
        void adjustTabSize();
253
254
        void addToAwayLog(const std::string &line);
255
256
        void displayAwayLog() const;
257
258
        void clearAwayLog()
259
        { mAwayLog.clear(); }
260
261
        void parseHighlights();
262
263
        void parseGlobalsFilter();
264
265
        bool findHighlight(const std::string &str) A_WARN_UNUSED;
266
267
        void copyToClipboard(const int x, const int y) const;
268
269
        void optionChanged(const std::string &name) override final;
270
271
        void mouseEntered(MouseEvent& event) override final;
272
273
        void mouseMoved(MouseEvent &event) override final;
274
275
        void mouseExited(MouseEvent& event A_UNUSED) override final;
276
277
        void draw(Graphics *const graphics) override final A_NONNULL(2);
278
279
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
280
281
        void updateVisibility();
282
283
        void unHideWindow();
284
285
        void widgetResized(const Event &event) override final;
286
287
        void addGlobalMessage(const std::string &line);
288
289
        void postInit() override final;
290
291
        bool isTabPresent(const ChatTab *const tab) const A_WARN_UNUSED;
292
293
        void selectTabByType(const ChatTabTypeT &type);
294
295
        void attributeChanged(const AttributesT id,
296
                              const int64_t oldVal,
297
                              const int64_t newVal) override final;
298
299
        void postConnection();
300
301
        void showGMTab();
302
303
        void debugMessage(const std::string &msg) override final;
304
305
        void scheduleDelete() override final;
306
307
#ifdef USE_PROFILER
308
        void logicChildren();
309
#endif  // USE_PROFILER
310
311
    protected:
312
        friend class ChannelTab;
313
        friend class ChatTab;
314
        friend class WhisperTab;
315
        friend class PopupMenu;
316
317
        typedef std::list<std::string> History;
318
319
        /** Remove the given tab from the window */
320
        void removeTab(ChatTab *const tab);
321
322
        /** Add the tab to the window */
323
        void addTab(ChatTab *const tab);
324
325
        void removeWhisper(const std::string &nick);
326
327
        void removeChannel(const std::string &nick);
328
329
        void autoComplete();
330
331
        std::string addColors(std::string &msg);
332
333
        std::string autoCompleteHistory(const std::string &partName) const;
334
335
        std::string autoComplete(const std::string &partName,
336
                                 const History *const words) const;
337
338
        static std::string autoComplete(const StringVect &names,
339
                                        std::string partName);
340
341
        /** Used for showing item popup on clicking links **/
342
        ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
343
344
        /** Tabbed area for holding each channel. */
345
        TabbedArea *mChatTabs A_NONNULLPOINTER;
346
347
        /** Input box for typing chat messages. */
348
        ChatInput *mChatInput A_NONNULLPOINTER;
349
350
        void initTradeFilter();
351
352
        void toggleChatFocus();
353
354
        unsigned int mRainbowColor;
355
356
    private:
357
        void fillCommands();
358
359
        void loadCommandsFile(const std::string &name);
360
361
        void updateTabsMargin();
362
363
        bool addCurrentToHistory();
364
365
        typedef std::map<const std::string, WhisperTab*> TabMap;
366
        typedef std::map<const std::string, ChannelTab*> ChannelMap;
367
368
        /** Manage whisper tabs */
369
        TabMap mWhispers;
370
        ChannelMap mChannels;
371
372
        typedef History::iterator HistoryIterator;
373
        History mHistory;          /**< Command history. */
374
        HistoryIterator mCurHist;  /**< History iterator. */
375
376
        typedef std::list<std::string> ChatCommands;
377
        typedef ChatCommands::iterator ChatCommandsIterator;
378
        History mCommands;         /**< Command list. */
379
        History mCustomWords;
380
381
        StringVect mTradeFilter;
382
383
        ColorListModel *mColorListModel A_NONNULLPOINTER;
384
        DropDown *mColorPicker A_NONNULLPOINTER;
385
        Button *mChatButton A_NONNULLPOINTER;
386
        std::list<std::string> mAwayLog;
387
        StringVect mHighlights;
388
        StringVect mGlobalsFilter;
389
        int mChatColor;
390
        int mEmoteButtonSpacing;
391
        int mEmoteButtonY;
392
        unsigned int mChatHistoryIndex;
393
        bool mReturnToggles;  // Marks whether <Return> toggles the chat log
394
                              // or not
395
        bool mGMLoaded;
396
        bool mHaveMouse;
397
        bool mAutoHide;
398
        bool mShowBattleEvents;
399
        bool mShowAllLang;
400
        bool mEnableTradeFilter;
401
        bool mTmpVisible;
402
};
403
404
extern ChatWindow *chatWindow;
405
406
#endif  // GUI_WINDOWS_CHATWINDOW_H