GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/windows/chatwindow.h Lines: 0 3 0.0 %
Date: 2018-05-24 20:11:55 Branches: 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-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
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() override final;
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,
149
                          const bool space);
150
151
        /** Called to add item to chat */
152
        void addItemText(const std::string &item);
153
154
        /** Override to reset mTmpVisible */
155
        void setVisible(Visible visible) override final;
156
157
        /**
158
         * Handles mouse when dragged.
159
         */
160
        void mouseDragged(MouseEvent &event) override final;
161
162
        /**
163
         * Handles mouse when pressed.
164
         */
165
        void mousePressed(MouseEvent &event) override final;
166
167
        /**
168
         * Scrolls the chat window
169
         *
170
         * @param amount direction and amount to scroll.  Negative numbers scroll
171
         * up, positive numbers scroll down.  The absolute amount indicates the
172
         * amount of 1/8ths of chat window real estate that should be scrolled.
173
         */
174
        void scroll(const int amount) const;
175
176
        /**
177
         * Sets the file being recorded to
178
         *
179
         * @param msg The file to write out to. If null, then stop recording.
180
         */
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
256
        void clearAwayLog()
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
317
        /** Remove the given tab from the window */
318
        void removeTab(ChatTab *const tab);
319
320
        /** Add the tab to the window */
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
339
        /** Used for showing item popup on clicking links **/
340
        ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER;
341
342
        /** Tabbed area for holding each channel. */
343
        TabbedArea *mChatTabs A_NONNULLPOINTER;
344
345
        /** Input box for typing chat messages. */
346
        ChatInput *mChatInput A_NONNULLPOINTER;
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
366
        /** Manage whisper tabs */
367
        TabMap mWhispers;
368
        ChannelMap mChannels;
369
370
        typedef History::iterator HistoryIterator;
371
        History mHistory;          /**< Command history. */
372
        HistoryIterator mCurHist;  /**< History iterator. */
373
374
        typedef std::list<std::string> ChatCommands;
375
        typedef ChatCommands::iterator ChatCommandsIterator;
376
        History mCommands;         /**< Command list. */
377
        History mCustomWords;
378
379
        StringVect mTradeFilter;
380
381
        ColorListModel *mColorListModel A_NONNULLPOINTER;
382
        DropDown *mColorPicker A_NONNULLPOINTER;
383
        Button *mChatButton A_NONNULLPOINTER;
384
        std::list<std::string> mAwayLog;
385
        StringVect mHighlights;
386
        StringVect mGlobalsFilter;
387
        int mChatColor;
388
        int mEmoteButtonSpacing;
389
        int mEmoteButtonY;
390
        unsigned int mChatHistoryIndex;
391
        bool mReturnToggles;  // Marks whether <Return> toggles the chat log
392
                              // or not
393
        bool mGMLoaded;
394
        bool mHaveMouse;
395
        bool mAutoHide;
396
        bool mShowBattleEvents;
397
        bool mShowAllLang;
398
        bool mEnableTradeFilter;
399
        bool mTmpVisible;
400
};
401
402
extern ChatWindow *chatWindow;
403
404
#endif  // GUI_WINDOWS_CHATWINDOW_H