OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ChatDlg.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2007-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2013-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // IRC client dialog
17 
18 #ifndef INC_C4ChatDlg
19 #define INC_C4ChatDlg
20 
21 #include "gui/C4Gui.h"
23 
24 // a GUI control to chat in
26 {
27 private:
28  // one open channel or query
29  class ChatSheet : public C4GUI::Tabular::Sheet
30  {
31  public:
32  // one item in the nick list
33  class NickItem : public C4GUI::Window
34  {
35  private:
36  C4GUI::Icon *pStatusIcon; // status icon indicating channel status (e.g. operator)
37  C4GUI::Label *pNameLabel; // the nickname
38  bool fFlaggedExisting; // flagged for existance; used by user update func
39  int32_t iStatus;
40 
41  public:
42  NickItem(class C4Network2IRCUser *pByUser);
43 
44  protected:
45  virtual void UpdateOwnPos();
46 
47  public:
48  const char *GetNick() const { return pNameLabel->GetText(); }
49  int32_t GetStatus() const { return iStatus; }
50 
51  void Update(class C4Network2IRCUser *pByUser);
52  void SetFlaggedExisting(bool fToVal) { fFlaggedExisting = fToVal; }
53  bool IsFlaggedExisting() const { return fFlaggedExisting; }
54 
55  static int32_t SortFunc(const C4GUI::Element *pEl1, const C4GUI::Element *pEl2, void *);
56 
57  };
58 
59  enum SheetType { CS_Server, CS_Channel, CS_Query };
60  private:
61  C4ChatControl *pChatControl;
62  C4GUI::TextWindow *pChatBox;
63  C4GUI::ListBox *pNickList;
64  C4GUI::WoodenLabel *pInputLbl;
65  C4GUI::Edit *pInputEdit;
66  int32_t iBackBufferIndex; // chat message history index
67  SheetType eType;
68  StdStrBuf sIdent;
69  bool fHasUnread;
70  StdStrBuf sChatTitle; // topic for channels; name+ident for queries; server name for server sheet
71 
72  C4KeyBinding *pKeyHistoryUp, *pKeyHistoryDown; // keys used to scroll through chat history
73 
74  public:
75  ChatSheet(C4ChatControl *pChatControl, const char *szTitle, const char *szIdent, SheetType eType);
76  virtual ~ChatSheet();
77 
78  C4GUI::Edit *GetInputEdit() const { return pInputEdit; }
79  SheetType GetSheetType() const { return eType; }
80  const char *GetIdent() const { return sIdent.getData(); }
81  void SetIdent(const char *szToIdent) { sIdent.Copy(szToIdent); }
82  const char *GetChatTitle() const { return sChatTitle.getData(); }
83  void SetChatTitle(const char *szNewTitle) { sChatTitle.Copy(szNewTitle); }
84 
85  void AddTextLine(const char *szText, uint32_t dwClr);
86  void DoError(const char *szError);
87  void Update(bool fLock);
88  void UpdateUsers(C4Network2IRCUser *pUsers);
89  void ResetUnread(); // mark messages as read
90 
91  protected:
92  virtual void UpdateSize();
93  virtual void OnShown(bool fByUser);
94  virtual void UserClose(); // user pressed close button: Close queries, part channels, etc.
95 
96  C4GUI::Edit::InputResult OnChatInput(C4GUI::Edit *edt, bool fPasting, bool fPastingMore);
97  bool KeyHistoryUpDown(bool fUp);
98  void OnNickDblClick(class C4GUI::Element *pEl);
99 
100  private:
101  NickItem *GetNickItem(const char *szByNick);
102  NickItem *GetFirstNickItem() { return pNickList ? static_cast<NickItem *>(pNickList->GetFirst()) : nullptr; }
103  NickItem *GetNextNickItem(NickItem *pPrev) { return static_cast<NickItem *>(pPrev->GetNext()); }
104  };
105 
106 private:
107  C4GUI::Tabular *pTabMain, *pTabChats;
108  // login controls
109  C4GUI::Label *pLblLoginNick, *pLblLoginPass, *pLblLoginRealName, *pLblLoginChannel;
110  C4GUI::Edit *pEdtLoginNick, *pEdtLoginPass, *pEdtLoginRealName, *pEdtLoginChannel;
111  C4GUI::Button *pBtnLogin;
112 
113  StdStrBuf sTitle;
114  C4GUI::BaseInputCallback *pTitleChangeBC;
115 
116  C4Network2IRCClient *pIRCClient;
117  bool fInitialMessagesReceived; // set after initial update call, which fetches all messages. Subsequent calls fetch only unread messages
118 
119 public:
121  virtual ~C4ChatControl();
122 
123 protected:
124  virtual void UpdateSize();
125  C4GUI::Edit::InputResult OnLoginDataEnter(C4GUI::Edit *edt, bool fPasting, bool fPastingMore); // advance focus when user presses enter in one of the login edits
126  void OnConnectBtn(C4GUI::Control *btn); // callback: connect button pressed
127 
128 public:
129  virtual class C4GUI::Control *GetDefaultControl();
130  C4Network2IRCClient *getIRCClient() { return pIRCClient; }
131 
133  virtual void OnShown(); // callback when shown
134  void UpdateShownPage();
135  void Update();
136  void UpdateTitle();
137  bool DlgEnter();
138  void OnSec1Timer() { Update(); } // timer proc
139  bool ProcessInput(const char *szInput, ChatSheet *pChatSheet); // process chat input - return false if no more pasting is to be done (i.e., on /quit or /part in channel)
140  const char *GetTitle() { return sTitle.getData(); }
141  void UserQueryQuit();
142  ChatSheet *OpenQuery(const char *szForNick, bool fSelect, const char *szIdentFallback);
143 
144 private:
145  static bool IsServiceName(const char *szName);
146  ChatSheet *GetActiveChatSheet();
147  ChatSheet *GetSheetByTitle(const char *szTitle, C4ChatControl::ChatSheet::SheetType eType);
148  ChatSheet *GetSheetByIdent(const char *szIdent, C4ChatControl::ChatSheet::SheetType eType);
149  ChatSheet *GetServerSheet();
150  void ClearChatSheets();
151 
152  // IRC event hook
153  virtual void OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData) { if (pEventData == pIRCClient) Update(); }
154 
155 };
156 
157 // container dialog for the C4ChatControl
158 class C4ChatDlg : public C4GUI::Dialog
159 {
160 private:
161  static C4ChatDlg *pInstance;
162  class C4ChatControl *pChatCtrl;
163  C4GUI::Button *pBtnClose;
164 
165 public:
166  C4ChatDlg();
167  virtual ~C4ChatDlg();
168 
169  static C4ChatDlg *ShowChat();
170  static void StopChat();
171  static bool IsChatActive();
172  static bool IsChatEnabled();
173  static bool ToggleChat();
174 
175 protected:
176  // default control to be set if unprocessed keyboard input has been detected
177  virtual class C4GUI::Control *GetDefaultControl();
178 
179  // true for dialogs that should span the whole screen
180  // not just the mouse-viewport
181  virtual bool IsFreePlaceDialog() { return true; }
182 
183  // true for dialogs that receive keyboard input even in shared mode
184  virtual bool IsExclusiveDialog() { return true; }
185 
186  // for custom placement procedures; should call SetPos
187  virtual bool DoPlacement(C4GUI::Screen *pOnScreen, const C4Rect &rPreferredDlgRect);
188 
189  virtual void OnClosed(bool fOK); // callback when dlg got closed
190  virtual void OnShown(); // callback when shown - should not delete the dialog
191 
192  virtual void UpdateSize();
193 
194  void OnExitBtn(C4GUI::Control *btn); // callback: exit button pressed
195  void OnChatTitleChange(const StdStrBuf &sNewTitle);
196 };
197 
198 #endif // INC_C4ChatDlg
const char * getData() const
Definition: StdBuf.h:450
ChatSheet * OpenQuery(const char *szForNick, bool fSelect, const char *szIdentFallback)
Definition: C4ChatDlg.cpp:734
virtual class C4GUI::Control * GetDefaultControl()
Definition: C4ChatDlg.cpp:1011
bool DlgEnter()
Definition: C4ChatDlg.cpp:786
C4Network2IRCClient * getIRCClient()
Definition: C4ChatDlg.h:130
void Update(class C4Network2IRCUser *pByUser)
Definition: C4ChatDlg.cpp:55
Definition: C4Rect.h:29
Element * GetFirst()
Definition: C4Gui.h:1571
void OnChatTitleChange(const StdStrBuf &sNewTitle)
Definition: C4ChatDlg.cpp:1057
static int32_t SortFunc(const C4GUI::Element *pEl1, const C4GUI::Element *pEl2, void *)
Definition: C4ChatDlg.cpp:77
bool fOK
Definition: C4Gui.h:2082
virtual ~C4ChatDlg()
Definition: C4ChatDlg.cpp:964
virtual void OnShown()
Definition: C4ChatDlg.cpp:1034
void UpdateShownPage()
Definition: C4ChatDlg.cpp:549
NickItem(class C4Network2IRCUser *pByUser)
Definition: C4ChatDlg.cpp:29
Element * pPrev
Definition: C4Gui.h:377
void UpdateTitle()
Definition: C4ChatDlg.cpp:757
void OnSec1Timer()
Definition: C4ChatDlg.h:138
virtual void UpdateSize()
Definition: C4ChatDlg.cpp:1042
void OnExitBtn(C4GUI::Control *btn)
Definition: C4ChatDlg.cpp:1052
C4InteractiveEventType
virtual void OnShown()
Definition: C4ChatDlg.cpp:421
C4GUI::Edit::InputResult OnLoginDataEnter(C4GUI::Edit *edt, bool fPasting, bool fPastingMore)
Definition: C4ChatDlg.cpp:480
void UserQueryQuit()
Definition: C4ChatDlg.cpp:931
virtual bool IsExclusiveDialog()
Definition: C4ChatDlg.h:184
static void StopChat()
Definition: C4ChatDlg.cpp:982
virtual ~C4ChatControl()
Definition: C4ChatDlg.cpp:377
const char * GetText()
Definition: C4Gui.h:503
const char * GetTitle()
Definition: C4ChatDlg.h:140
virtual bool DoPlacement(C4GUI::Screen *pOnScreen, const C4Rect &rPreferredDlgRect)
Definition: C4ChatDlg.cpp:1016
static bool IsChatEnabled()
Definition: C4ChatDlg.cpp:1006
static C4ChatDlg * ShowChat()
Definition: C4ChatDlg.cpp:968
static bool IsChatActive()
Definition: C4ChatDlg.cpp:998
static bool ToggleChat()
Definition: C4ChatDlg.cpp:989
void OnConnectBtn(C4GUI::Control *btn)
Definition: C4ChatDlg.cpp:488
C4ChatControl(C4Network2IRCClient *pIRC)
Definition: C4ChatDlg.cpp:337
virtual class C4GUI::Control * GetDefaultControl()
Definition: C4ChatDlg.cpp:426
virtual bool IsFreePlaceDialog()
Definition: C4ChatDlg.h:181
virtual void UpdateSize()
Definition: C4ChatDlg.cpp:391
bool ProcessInput(const char *szInput, ChatSheet *pChatSheet)
Definition: C4ChatDlg.cpp:800
void Copy()
Definition: StdBuf.h:475
void SetFlaggedExisting(bool fToVal)
Definition: C4ChatDlg.h:52
void SetTitleChangeCB(C4GUI::BaseInputCallback *pNewCB)
Definition: C4ChatDlg.cpp:383
virtual void OnClosed(bool fOK)
Definition: C4ChatDlg.cpp:1026
const char * GetNick() const
Definition: C4ChatDlg.h:48