aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llchatbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llchatbar.cpp155
1 files changed, 108 insertions, 47 deletions
diff --git a/linden/indra/newview/llchatbar.cpp b/linden/indra/newview/llchatbar.cpp
index 66ffdc4..9798796 100644
--- a/linden/indra/newview/llchatbar.cpp
+++ b/linden/indra/newview/llchatbar.cpp
@@ -47,6 +47,7 @@
47#include "llgesturemgr.h" 47#include "llgesturemgr.h"
48#include "llkeyboard.h" 48#include "llkeyboard.h"
49#include "lllineeditor.h" 49#include "lllineeditor.h"
50#include "llstatusbar.h"
50#include "lltextbox.h" 51#include "lltextbox.h"
51#include "lluiconstants.h" 52#include "lluiconstants.h"
52#include "llviewergesture.h" // for triggering gestures 53#include "llviewergesture.h" // for triggering gestures
@@ -70,15 +71,18 @@ const F32 AGENT_TYPING_TIMEOUT = 5.f; // seconds
70 71
71LLChatBar *gChatBar = NULL; 72LLChatBar *gChatBar = NULL;
72 73
73LLChatBarGestureObserver* LLChatBar::sObserver = NULL; 74// legacy calllback glue
75void toggleChatHistory(void* user_data);
74 76
75 77
76class LLChatBarGestureObserver : public LLGestureManagerObserver 78class LLChatBarGestureObserver : public LLGestureManagerObserver
77{ 79{
78public: 80public:
79 LLChatBarGestureObserver() {} 81 LLChatBarGestureObserver(LLChatBar* chat_barp) : mChatBar(chat_barp){}
80 virtual ~LLChatBarGestureObserver() {} 82 virtual ~LLChatBarGestureObserver() {}
81 virtual void changed() { gChatBar->refreshGestures(); } 83 virtual void changed() { mChatBar->refreshGestures(); }
84private:
85 LLChatBar* mChatBar;
82}; 86};
83 87
84 88
@@ -86,12 +90,29 @@ public:
86// Functions 90// Functions
87// 91//
88 92
89LLChatBar::LLChatBar(const std::string& name, const LLRect& rect) 93//inline constructor
94// for chat bars embedded in floaters, etc
95LLChatBar::LLChatBar(const std::string& name)
96: LLPanel(name, LLRect(), BORDER_NO),
97 mInputEditor(NULL),
98 mGestureLabelTimer(),
99 mLastSpecialChatChannel(0),
100 mIsBuilt(FALSE),
101 mDynamicLayout(FALSE),
102 mGestureCombo(NULL),
103 mObserver(NULL)
104{
105}
106
107LLChatBar::LLChatBar(const std::string& name, const LLRect& rect)
90: LLPanel(name, rect, BORDER_NO), 108: LLPanel(name, rect, BORDER_NO),
91 mInputEditor(NULL), 109 mInputEditor(NULL),
92 mGestureLabelTimer(), 110 mGestureLabelTimer(),
93 mLastSpecialChatChannel(0), 111 mLastSpecialChatChannel(0),
94 mIsBuilt(FALSE) 112 mIsBuilt(FALSE),
113 mDynamicLayout(TRUE),
114 mGestureCombo(NULL),
115 mObserver(NULL)
95{ 116{
96 setIsChrome(TRUE); 117 setIsChrome(TRUE);
97 118
@@ -107,29 +128,6 @@ LLChatBar::LLChatBar(const std::string& name, const LLRect& rect)
107 // Start visible if we left the app while chatting. 128 // Start visible if we left the app while chatting.
108 setVisible( gSavedSettings.getBOOL("ChatVisible") ); 129 setVisible( gSavedSettings.getBOOL("ChatVisible") );
109 130
110 mInputEditor = LLUICtrlFactory::getLineEditorByName(this, "Chat Editor");
111 if (mInputEditor)
112 {
113 mInputEditor->setCallbackUserData(this);
114 mInputEditor->setKeystrokeCallback(&onInputEditorKeystroke);
115 mInputEditor->setFocusLostCallback(&onInputEditorFocusLost);
116 mInputEditor->setFocusReceivedCallback( &onInputEditorGainFocus );
117 mInputEditor->setCommitOnFocusLost( FALSE );
118 mInputEditor->setRevertOnEsc( FALSE );
119 mInputEditor->setIgnoreTab(TRUE);
120 mInputEditor->setPassDelete(TRUE);
121 mInputEditor->setMaxTextLength(1023);
122 mInputEditor->setEnableLineHistory(TRUE);
123 }
124
125 // Build the list of gestures
126 refreshGestures();
127
128 sObserver = new LLChatBarGestureObserver;
129 gGestureManager.addObserver(sObserver);
130
131 mIsBuilt = TRUE;
132
133 // Apply custom layout. 131 // Apply custom layout.
134 layout(); 132 layout();
135 133
@@ -142,23 +140,43 @@ LLChatBar::LLChatBar(const std::string& name, const LLRect& rect)
142 140
143LLChatBar::~LLChatBar() 141LLChatBar::~LLChatBar()
144{ 142{
145 delete sObserver; 143 delete mObserver;
146 sObserver = NULL; 144 mObserver = NULL;
147 // LLView destructor cleans up children 145 // LLView destructor cleans up children
148} 146}
149 147
150BOOL LLChatBar::postBuild() 148BOOL LLChatBar::postBuild()
151{ 149{
152 childSetAction("History", LLFloaterChat::toggle, this); 150 childSetAction("History", toggleChatHistory, this);
153 childSetAction("Say", onClickSay, this); 151 childSetAction("Say", onClickSay, this);
154 childSetAction("Shout", onClickShout, this); 152 childSetAction("Shout", onClickShout, this);
155 childSetCommitCallback("Gesture", onCommitGesture, this); 153
156 LLButton * sayp = static_cast<LLButton*>(getChildByName("Say")); 154 // attempt to bind to an existing combo box named gesture
155 setGestureCombo(LLUICtrlFactory::getComboBoxByName(this, "Gesture"));
156
157 LLButton * sayp = static_cast<LLButton*>(getChildByName("Say", TRUE));
157 if(sayp) 158 if(sayp)
158 { 159 {
159 setDefaultBtn(sayp); 160 setDefaultBtn(sayp);
160 } 161 }
161 162
163 mInputEditor = LLUICtrlFactory::getLineEditorByName(this, "Chat Editor");
164 if (mInputEditor)
165 {
166 mInputEditor->setCallbackUserData(this);
167 mInputEditor->setKeystrokeCallback(&onInputEditorKeystroke);
168 mInputEditor->setFocusLostCallback(&onInputEditorFocusLost);
169 mInputEditor->setFocusReceivedCallback( &onInputEditorGainFocus );
170 mInputEditor->setCommitOnFocusLost( FALSE );
171 mInputEditor->setRevertOnEsc( FALSE );
172 mInputEditor->setIgnoreTab(TRUE);
173 mInputEditor->setPassDelete(TRUE);
174
175 mInputEditor->setMaxTextLength(1023);
176 }
177
178 mIsBuilt = TRUE;
179
162 return TRUE; 180 return TRUE;
163} 181}
164 182
@@ -206,7 +224,8 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent )
206 handled = TRUE; 224 handled = TRUE;
207 } 225 }
208 } 226 }
209 else if ( KEY_ESCAPE == key ) 227 // only do this in main chatbar
228 else if ( KEY_ESCAPE == key && gChatBar == this)
210 { 229 {
211 stopChat(); 230 stopChat();
212 231
@@ -219,6 +238,8 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask, BOOL called_from_parent )
219 238
220void LLChatBar::layout() 239void LLChatBar::layout()
221{ 240{
241 if (!mDynamicLayout) return;
242
222 S32 rect_width = mRect.getWidth(); 243 S32 rect_width = mRect.getWidth();
223 S32 count = 9; // number of elements in LLToolBar 244 S32 count = 9; // number of elements in LLToolBar
224 S32 pad = 4; 245 S32 pad = 4;
@@ -281,13 +302,16 @@ void LLChatBar::refresh()
281 // hide in mouselook, but keep previous visibility state 302 // hide in mouselook, but keep previous visibility state
282 //BOOL mouselook = gAgent.cameraMouselook(); 303 //BOOL mouselook = gAgent.cameraMouselook();
283 // call superclass setVisible so that we don't overwrite the saved setting 304 // call superclass setVisible so that we don't overwrite the saved setting
284 LLPanel::setVisible(gSavedSettings.getBOOL("ChatVisible")); 305 if (mDynamicLayout)
306 {
307 LLPanel::setVisible(gSavedSettings.getBOOL("ChatVisible"));
308 }
285 309
286 // HACK: Leave the name of the gesture in place for a few seconds. 310 // HACK: Leave the name of the gesture in place for a few seconds.
287 const F32 SHOW_GESTURE_NAME_TIME = 2.f; 311 const F32 SHOW_GESTURE_NAME_TIME = 2.f;
288 if (mGestureLabelTimer.getStarted() && mGestureLabelTimer.getElapsedTimeF32() > SHOW_GESTURE_NAME_TIME) 312 if (mGestureLabelTimer.getStarted() && mGestureLabelTimer.getElapsedTimeF32() > SHOW_GESTURE_NAME_TIME)
289 { 313 {
290 LLCtrlListInterface* gestures = childGetListInterface("Gesture"); 314 LLCtrlListInterface* gestures = mGestureCombo ? mGestureCombo->getListInterface() : NULL;
291 if (gestures) gestures->selectFirstItem(); 315 if (gestures) gestures->selectFirstItem();
292 mGestureLabelTimer.stop(); 316 mGestureLabelTimer.stop();
293 } 317 }
@@ -297,6 +321,8 @@ void LLChatBar::refresh()
297 gAgent.stopTyping(); 321 gAgent.stopTyping();
298 } 322 }
299 323
324 childSetValue("History", LLFloaterChat::instanceVisible(LLSD()));
325
300 childSetEnabled("Say", mInputEditor->getText().size() > 0); 326 childSetEnabled("Say", mInputEditor->getText().size() > 0);
301 childSetEnabled("Shout", mInputEditor->getText().size() > 0); 327 childSetEnabled("Shout", mInputEditor->getText().size() > 0);
302 328
@@ -304,16 +330,18 @@ void LLChatBar::refresh()
304 330
305void LLChatBar::refreshGestures() 331void LLChatBar::refreshGestures()
306{ 332{
307 LLCtrlListInterface* gestures = childGetListInterface("Gesture"); 333 LLCtrlListInterface* gestures = mGestureCombo ? mGestureCombo->getListInterface() : NULL;
308 if (gestures) 334 if (mGestureCombo && gestures)
309 { 335 {
310 //store current selection so we can maintain it 336 //store current selection so we can maintain it
311 LLString cur_gesture = childGetValue("Gesture").asString(); 337 LLString cur_gesture = mGestureCombo->getValue().asString();
312 gestures->selectFirstItem(); 338 gestures->selectFirstItem();
313 LLString label = childGetValue("Gesture").asString(); 339 LLString label = mGestureCombo->getValue().asString();;
314 // clear 340 // clear
315 gestures->clearRows(); 341 gestures->clearRows();
316 // add gestures 342
343 // collect list of unique gestures
344 std::map <std::string, BOOL> unique;
317 LLGestureManager::item_map_t::iterator it; 345 LLGestureManager::item_map_t::iterator it;
318 for (it = gGestureManager.mActive.begin(); it != gGestureManager.mActive.end(); ++it) 346 for (it = gGestureManager.mActive.begin(); it != gGestureManager.mActive.end(); ++it)
319 { 347 {
@@ -322,10 +350,18 @@ void LLChatBar::refreshGestures()
322 { 350 {
323 if (!gesture->mTrigger.empty()) 351 if (!gesture->mTrigger.empty())
324 { 352 {
325 gestures->addSimpleElement(gesture->mTrigger); 353 unique[gesture->mTrigger] = TRUE;
326 } 354 }
327 } 355 }
328 } 356 }
357
358 // ad unique gestures
359 std::map <std::string, BOOL>::iterator it2;
360 for (it2 = unique.begin(); it2 != unique.end(); ++it2)
361 {
362 gestures->addSimpleElement((*it2).first);
363 }
364
329 gestures->sortByColumn(0, TRUE); 365 gestures->sortByColumn(0, TRUE);
330 // Insert label after sorting 366 // Insert label after sorting
331 gestures->addSimpleElement(label, ADD_TOP); 367 gestures->addSimpleElement(label, ADD_TOP);
@@ -382,6 +418,23 @@ LLString LLChatBar::getCurrentChat()
382 return mInputEditor ? mInputEditor->getText() : LLString::null; 418 return mInputEditor ? mInputEditor->getText() : LLString::null;
383} 419}
384 420
421void LLChatBar::setGestureCombo(LLComboBox* combo)
422{
423 mGestureCombo = combo;
424 if (mGestureCombo)
425 {
426 mGestureCombo->setCommitCallback(onCommitGesture);
427 mGestureCombo->setCallbackUserData(this);
428
429 // now register observer since we have a place to put the results
430 mObserver = new LLChatBarGestureObserver(this);
431 gGestureManager.addObserver(mObserver);
432
433 // refresh list from current active gestures
434 refreshGestures();
435 }
436}
437
385//----------------------------------------------------------------------- 438//-----------------------------------------------------------------------
386// Internal functions 439// Internal functions
387//----------------------------------------------------------------------- 440//-----------------------------------------------------------------------
@@ -473,13 +526,13 @@ void LLChatBar::sendChat( EChatType type )
473 sendChatFromViewer(utf8_revised_text, type, TRUE); 526 sendChatFromViewer(utf8_revised_text, type, TRUE);
474 } 527 }
475 } 528 }
476 childSetValue("Chat Editor", LLSD(LLString::null)); 529 childSetValue("Chat Editor", LLString::null);
477 530
478 gAgent.stopTyping(); 531 gAgent.stopTyping();
479 532
480 // If the user wants to stop chatting on hitting return, lose focus 533 // If the user wants to stop chatting on hitting return, lose focus
481 // and go out of chat mode. 534 // and go out of chat mode.
482 if (gSavedSettings.getBOOL("CloseChatOnReturn")) 535 if (gChatBar == this && gSavedSettings.getBOOL("CloseChatOnReturn"))
483 { 536 {
484 stopChat(); 537 stopChat();
485 } 538 }
@@ -704,7 +757,7 @@ void LLChatBar::sendChatFromViewer(const LLWString &wtext, EChatType type, BOOL
704void LLChatBar::onCommitGesture(LLUICtrl* ctrl, void* data) 757void LLChatBar::onCommitGesture(LLUICtrl* ctrl, void* data)
705{ 758{
706 LLChatBar* self = (LLChatBar*)data; 759 LLChatBar* self = (LLChatBar*)data;
707 LLCtrlListInterface* gestures = self->childGetListInterface("Gesture"); 760 LLCtrlListInterface* gestures = self->mGestureCombo ? self->mGestureCombo->getListInterface() : NULL;
708 if (gestures) 761 if (gestures)
709 { 762 {
710 S32 index = gestures->getFirstSelectedIndex(); 763 S32 index = gestures->getFirstSelectedIndex();
@@ -728,6 +781,14 @@ void LLChatBar::onCommitGesture(LLUICtrl* ctrl, void* data)
728 } 781 }
729 } 782 }
730 self->mGestureLabelTimer.start(); 783 self->mGestureLabelTimer.start();
731 // free focus back to chat bar 784 if (self->mGestureCombo != NULL)
732 self->childSetFocus("Gesture", FALSE); 785 {
786 // free focus back to chat bar
787 self->mGestureCombo->setFocus(FALSE);
788 }
789}
790
791void toggleChatHistory(void* user_data)
792{
793 LLFloaterChat::toggleInstance(LLSD());
733} 794}