PageRenderTime 40ms CodeModel.GetById 2ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llchicletbar.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 345 lines | 240 code | 56 blank | 49 comment | 34 complexity | 106c93b22bf6aff76ed1d57657e7e885 MD5 | raw file
  1/** 
  2 * @file llchicletbar.cpp
  3 * @brief LLChicletBar class implementation
  4 *
  5 * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library 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 GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h" // must be first include
 28
 29#include "llchicletbar.h"
 30
 31// library includes
 32#include "llfloaterreg.h"
 33#include "lllayoutstack.h"
 34
 35// newview includes
 36#include "llchiclet.h"
 37#include "llimfloater.h" // for LLIMFloater
 38#include "llpaneltopinfobar.h"
 39#include "llsyswellwindow.h"
 40
 41namespace
 42{
 43	const std::string& PANEL_CHICLET_NAME	= "chiclet_list_panel";
 44
 45	S32 get_curr_width(LLUICtrl* ctrl)
 46	{
 47		S32 cur_width = 0;
 48		if ( ctrl && ctrl->getVisible() )
 49		{
 50			cur_width = ctrl->getRect().getWidth();
 51		}
 52		return cur_width;
 53	}
 54}
 55
 56LLChicletBar::LLChicletBar(const LLSD&)
 57:	mChicletPanel(NULL),
 58	mToolbarStack(NULL)
 59{
 60	// Firstly add our self to IMSession observers, so we catch session events
 61	// before chiclets do that.
 62	LLIMMgr::getInstance()->addSessionObserver(this);
 63
 64	buildFromFile("panel_chiclet_bar.xml");
 65}
 66
 67LLChicletBar::~LLChicletBar()
 68{
 69	if (!LLSingleton<LLIMMgr>::destroyed())
 70	{
 71		LLIMMgr::getInstance()->removeSessionObserver(this);
 72	}
 73}
 74
 75LLIMChiclet* LLChicletBar::createIMChiclet(const LLUUID& session_id)
 76{
 77	LLIMChiclet::EType im_chiclet_type = LLIMChiclet::getIMSessionType(session_id);
 78
 79	switch (im_chiclet_type)
 80	{
 81	case LLIMChiclet::TYPE_IM:
 82		return getChicletPanel()->createChiclet<LLIMP2PChiclet>(session_id);
 83	case LLIMChiclet::TYPE_GROUP:
 84		return getChicletPanel()->createChiclet<LLIMGroupChiclet>(session_id);
 85	case LLIMChiclet::TYPE_AD_HOC:
 86		return getChicletPanel()->createChiclet<LLAdHocChiclet>(session_id);
 87	case LLIMChiclet::TYPE_UNKNOWN:
 88		break;
 89	}
 90
 91	return NULL;
 92}
 93
 94//virtual
 95void LLChicletBar::sessionAdded(const LLUUID& session_id, const std::string& name, const LLUUID& other_participant_id)
 96{
 97	if (!getChicletPanel()) return;
 98
 99	LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(session_id);
100	if (!session) return;
101
102	// no need to spawn chiclets for participants in P2P calls called through Avaline
103	if (session->isP2P() && session->isOtherParticipantAvaline()) return;
104
105	if (getChicletPanel()->findChiclet<LLChiclet>(session_id)) return;
106
107	LLIMChiclet* chiclet = createIMChiclet(session_id);
108	if(chiclet)
109	{
110		chiclet->setIMSessionName(name);
111		chiclet->setOtherParticipantId(other_participant_id);
112		
113		LLIMFloater::onIMChicletCreated(session_id);
114
115	}
116	else
117	{
118		llwarns << "Could not create chiclet" << llendl;
119	}
120}
121
122//virtual
123void LLChicletBar::sessionRemoved(const LLUUID& session_id)
124{
125	if(getChicletPanel())
126	{
127		// IM floater should be closed when session removed and associated chiclet closed
128		LLIMFloater* iMfloater = LLFloaterReg::findTypedInstance<LLIMFloater>("impanel", session_id);
129		if (iMfloater != NULL)
130		{
131			iMfloater->closeFloater();
132		}
133
134		getChicletPanel()->removeChiclet(session_id);
135	}
136}
137
138void LLChicletBar::sessionIDUpdated(const LLUUID& old_session_id, const LLUUID& new_session_id)
139{
140	//this is only needed in case of outgoing ad-hoc/group chat sessions
141	LLChicletPanel* chiclet_panel = getChicletPanel();
142	if (chiclet_panel)
143	{
144		//it should be ad-hoc im chiclet or group im chiclet
145		LLChiclet* chiclet = chiclet_panel->findChiclet<LLChiclet>(old_session_id);
146		if (chiclet) chiclet->setSessionId(new_session_id);
147	}
148}
149
150S32 LLChicletBar::getTotalUnreadIMCount()
151{
152	return getChicletPanel()->getTotalUnreadIMCount();
153}
154
155BOOL LLChicletBar::postBuild()
156{
157	mToolbarStack = getChild<LLLayoutStack>("toolbar_stack");
158	mChicletPanel = getChild<LLChicletPanel>("chiclet_list");
159
160	showWellButton("im_well", !LLIMWellWindow::getInstance()->isWindowEmpty());
161	showWellButton("notification_well", !LLNotificationWellWindow::getInstance()->isWindowEmpty());
162
163	LLPanelTopInfoBar::instance().setResizeCallback(boost::bind(&LLChicletBar::fitWithTopInfoBar, this));
164	LLPanelTopInfoBar::instance().setVisibleCallback(boost::bind(&LLChicletBar::fitWithTopInfoBar, this));
165
166	return TRUE;
167}
168
169void LLChicletBar::showWellButton(const std::string& well_name, bool visible)
170{
171	LLView * panel = findChild<LLView>(well_name + "_panel");
172	if (!panel)	return;
173
174	panel->setVisible(visible);
175}
176
177void LLChicletBar::log(LLView* panel, const std::string& descr)
178{
179	if (NULL == panel) return;
180	LLView* layout = panel->getParent();
181	LL_DEBUGS("Chiclet Bar Rects") << descr << ": "
182		<< "panel: " << panel->getName()
183		<< ", rect: " << panel->getRect()
184		<< " layout: " << layout->getName()
185		<< ", rect: " << layout->getRect()
186		<< LL_ENDL;
187}
188
189void LLChicletBar::reshape(S32 width, S32 height, BOOL called_from_parent)
190{
191	static S32 debug_calling_number = 0;
192	lldebugs << "**************************************** " << ++debug_calling_number << llendl;
193
194	S32 current_width = getRect().getWidth();
195	S32 delta_width = width - current_width;
196	lldebugs << "Reshaping: "
197		<< ", width: " << width
198		<< ", cur width: " << current_width
199		<< ", delta_width: " << delta_width
200		<< ", called_from_parent: " << called_from_parent
201		<< llendl;
202
203	if (mChicletPanel)			log(mChicletPanel, "before");
204
205	// Difference between chiclet bar width required to fit its children and the actual width. (see EXT-991)
206	// Positive value means that chiclet bar is not wide enough.
207	// Negative value means that there is free space.
208	static S32 extra_shrink_width = 0;
209	bool should_be_reshaped = true;
210
211	if (mChicletPanel && mToolbarStack)
212	{
213		// Firstly, update layout stack to ensure we deal with correct panel sizes.
214		{
215			// Force the updating of layout to reset panels collapse factor.
216			mToolbarStack->updateLayout();
217		}
218
219		// chiclet bar is narrowed
220		if (delta_width < 0)
221		{
222			if (extra_shrink_width > 0) // not enough space
223			{
224				extra_shrink_width += llabs(delta_width);
225				should_be_reshaped = false;
226			}
227			else
228			{
229				extra_shrink_width = processWidthDecreased(delta_width);
230
231				// increase new width to extra_shrink_width value to not reshape less than chiclet bar minimum
232				width += extra_shrink_width;
233			}
234		}
235		// chiclet bar is widened
236		else
237		{
238			if (extra_shrink_width > delta_width)
239			{
240				// Still not enough space.
241				// Only subtract the delta from the required delta and don't reshape.
242				extra_shrink_width -= delta_width;
243				should_be_reshaped = false;
244			}
245			else if (extra_shrink_width > 0)
246			{
247				// If we have some extra shrink width let's reduce delta_width & width
248				delta_width -= extra_shrink_width;
249				width -= extra_shrink_width;
250				extra_shrink_width = 0;
251			}
252		}
253	}
254
255	if (should_be_reshaped)
256	{
257		lldebugs << "Reshape all children with width: " << width << llendl;
258		LLPanel::reshape(width, height, called_from_parent);
259	}
260
261	if (mChicletPanel)			log(mChicletPanel, "after");
262}
263
264S32 LLChicletBar::processWidthDecreased(S32 delta_width)
265{
266	bool still_should_be_processed = true;
267
268	const S32 chiclet_panel_shrink_headroom = getChicletPanelShrinkHeadroom();
269
270	// Decreasing width of chiclet panel.
271	if (chiclet_panel_shrink_headroom > 0)
272	{
273		// we have some space to decrease chiclet panel
274		S32 shrink_by = llmin(-delta_width, chiclet_panel_shrink_headroom);
275
276		lldebugs << "delta_width: " << delta_width
277			<< ", panel_delta_min: " << chiclet_panel_shrink_headroom
278			<< ", shrink_by: " << shrink_by
279			<< llendl;
280
281		// is chiclet panel wide enough to process resizing?
282		delta_width += chiclet_panel_shrink_headroom;
283
284		still_should_be_processed = delta_width < 0;
285
286		lldebugs << "Shrinking chiclet panel by " << shrink_by << " px" << llendl;
287		mChicletPanel->getParent()->reshape(mChicletPanel->getParent()->getRect().getWidth() - shrink_by, mChicletPanel->getParent()->getRect().getHeight());
288		log(mChicletPanel, "after processing panel decreasing via chiclet panel");
289
290		lldebugs << "RS_CHICLET_PANEL"
291			<< ", delta_width: " << delta_width
292			<< llendl;
293	}
294
295	S32 extra_shrink_width = 0;
296
297	if (still_should_be_processed)
298	{
299		extra_shrink_width = -delta_width;
300		llwarns << "There is no enough width to reshape all children: "
301			<< extra_shrink_width << llendl;
302	}
303
304	return extra_shrink_width;
305}
306
307S32 LLChicletBar::getChicletPanelShrinkHeadroom() const
308{
309	static const S32 min_width = mChicletPanel->getMinWidth();
310	const S32 cur_width = mChicletPanel->getParent()->getRect().getWidth();
311
312	S32 shrink_headroom = cur_width - min_width;
313	llassert(shrink_headroom >= 0); // the panel cannot get narrower than the minimum
314	return shrink_headroom;
315}
316
317void LLChicletBar::fitWithTopInfoBar()
318{
319	LLPanelTopInfoBar& top_info_bar = LLPanelTopInfoBar::instance();
320
321	LLRect rect = getRect();
322	S32 width = rect.getWidth();
323
324	if (top_info_bar.getVisible())
325	{
326		S32 delta = top_info_bar.calcScreenRect().mRight - calcScreenRect().mLeft;
327		if (delta < 0 && rect.mLeft < llabs(delta))
328			delta = -rect.mLeft;
329		rect.setLeftTopAndSize(rect.mLeft + delta, rect.mTop, rect.getWidth(), rect.getHeight());
330		width = rect.getWidth() - delta;
331	}
332	else
333	{
334		LLView* parent = getParent();
335		if (parent)
336		{
337			LLRect parent_rect = parent->getRect();
338			rect.setLeftTopAndSize(0, rect.mTop, rect.getWidth(), rect.getHeight());
339			width = parent_rect.getWidth();
340		}
341	}
342
343	setRect(rect);
344	LLPanel::reshape(width, rect.getHeight(), false);
345}