00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef CHAT_H 00023 #define CHAT_H 00024 00025 #include "gui/widgets/window.h" 00026 00027 #include <guichan/actionlistener.hpp> 00028 #include <guichan/keylistener.hpp> 00029 #include <guichan/widget.hpp> 00030 #include <guichan/widgetlistener.hpp> 00031 00032 #include <list> 00033 #include <string> 00034 #include <map> 00035 00036 class BrowserBox; 00037 class Channel; 00038 class ChatTab; 00039 class ChatInput; 00040 class Recorder; 00041 class ScrollArea; 00042 class TabbedArea; 00043 class ItemLinkHandler; 00044 class Tab; 00045 class WhisperTab; 00046 00047 #define DEFAULT_CHAT_WINDOW_SCROLL 7 // 1 means `1/8th of the window size'. 00048 00050 struct CHATLOG 00051 { 00052 std::string nick; 00053 std::string text; 00054 int own; 00055 }; 00056 00062 class ChatWindow : public Window, 00063 public gcn::ActionListener, 00064 public gcn::KeyListener 00065 { 00066 public: 00070 ChatWindow(); 00071 00075 ~ChatWindow(); 00076 00081 void widgetResized(const gcn::Event &event); 00082 00083 void logic(); 00084 00089 void resetToDefaultSize(); 00090 00094 ChatTab* getFocused() const; 00095 00099 void clearTab(ChatTab* tab); 00100 00104 void clearTab(); 00105 00109 void prevTab(); 00110 00114 void nextTab(); 00115 00119 void action(const gcn::ActionEvent &event); 00120 00127 bool requestChatFocus(); 00128 00132 bool isInputFocused(); 00133 00139 void chatInput(std::string &msg); 00140 00142 void keyPressed(gcn::KeyEvent &event); 00143 00145 void addInputText(std::string input_str); 00146 00148 void addItemText(const std::string &item); 00149 00151 void setVisible(bool visible); 00152 00160 void scroll(int amount); 00161 00167 void setRecordingFile(const std::string &msg); 00168 00169 bool getReturnTogglesChat() const { return mReturnToggles; } 00170 void setReturnTogglesChat(bool toggles) { mReturnToggles = toggles; } 00171 00172 void doPresent(); 00173 00174 void whisper(const std::string &nick, std::string mes, 00175 bool own = false); 00176 00177 ChatTab *addWhisperTab(const std::string &nick, bool switchTo = false); 00178 00179 protected: 00180 friend class ChatTab; 00181 friend class WhisperTab; 00182 00184 void removeTab(ChatTab *tab); 00185 00187 void addTab(ChatTab *tab); 00188 00189 void removeWhisper(std::string nick); 00190 00191 void adjustTabSize(); 00192 00194 ItemLinkHandler *mItemLinkHandler; 00195 Recorder *mRecorder; 00196 00198 ChatInput *mChatInput; 00199 00200 private: 00201 bool mTmpVisible; 00202 00204 TabbedArea *mChatTabs; 00205 Tab *mCurrentTab; 00206 00207 typedef std::map<const std::string, ChatTab*> TabMap; 00209 TabMap mWhispers; 00210 00211 typedef std::list<std::string> History; 00212 typedef History::iterator HistoryIterator; 00213 History mHistory; 00214 HistoryIterator mCurHist; 00215 bool mReturnToggles; 00217 }; 00218 00219 extern ChatWindow *chatWindow; 00220 00221 #endif