PageRenderTime 19ms CodeModel.GetById 2ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lldockablefloater.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 263 lines | 196 code | 31 blank | 36 comment | 43 complexity | f5c731013a203121ba97568dbbb27daa MD5 | raw file
  1/** 
  2 * @file lldockablefloater.cpp
  3 * @brief Creates a panel of a specific kind for a toast
  4 *
  5 * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, 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 "linden_common.h"
 28
 29#include "lldockablefloater.h"
 30#include "llfloaterreg.h"
 31
 32//static
 33LLHandle<LLFloater> LLDockableFloater::sInstanceHandle;
 34
 35//static
 36void LLDockableFloater::init(LLDockableFloater* thiz)
 37{
 38	thiz->setDocked(thiz->mDockControl.get() != NULL
 39			&& thiz->mDockControl.get()->isDockVisible());
 40	thiz->resetInstance();
 41
 42	// all dockable floaters should have close, dock and minimize buttons
 43	thiz->setCanClose(TRUE);
 44	thiz->setCanDock(true);
 45	thiz->setCanMinimize(TRUE);
 46	thiz->setOverlapsScreenChannel(false);
 47	thiz->mForceDocking = false;
 48}
 49
 50LLDockableFloater::LLDockableFloater(LLDockControl* dockControl,
 51		const LLSD& key, const Params& params) :
 52	LLFloater(key, params), mDockControl(dockControl), mUniqueDocking(true)
 53{
 54	init(this);
 55	mUseTongue = true;
 56}
 57
 58LLDockableFloater::LLDockableFloater(LLDockControl* dockControl, bool uniqueDocking,
 59		const LLSD& key, const Params& params) :
 60	LLFloater(key, params), mDockControl(dockControl), mUniqueDocking(uniqueDocking)
 61{
 62	init(this);
 63	mUseTongue = true;
 64}
 65
 66LLDockableFloater::LLDockableFloater(LLDockControl* dockControl, bool uniqueDocking,
 67		bool useTongue, const LLSD& key, const Params& params) :
 68	LLFloater(key, params), mDockControl(dockControl), mUseTongue(useTongue), mUniqueDocking(uniqueDocking)
 69{
 70	init(this);
 71}
 72
 73LLDockableFloater::~LLDockableFloater()
 74{
 75}
 76
 77BOOL LLDockableFloater::postBuild()
 78{
 79	// Remember we should force docking when the floater is opened for the first time
 80	if (mIsDockedStateForcedCallback != NULL && mIsDockedStateForcedCallback())
 81	{
 82		mForceDocking = true;
 83	}
 84
 85	mDockTongue = LLUI::getUIImage("Flyout_Pointer");
 86	LLFloater::setDocked(true);
 87	return LLView::postBuild();
 88}
 89
 90//static
 91void LLDockableFloater::toggleInstance(const LLSD& sdname)
 92{
 93	LLSD key;
 94	std::string name = sdname.asString();
 95
 96	LLDockableFloater* instance =
 97			dynamic_cast<LLDockableFloater*> (LLFloaterReg::findInstance(name));
 98	// if floater closed or docked
 99	if (instance == NULL || (instance && instance->isDocked()))
100	{
101		LLFloaterReg::toggleInstance(name, key);
102		// restore button toggle state
103		if (instance != NULL)
104		{
105			instance->storeVisibilityControl();
106		}
107	}
108	// if floater undocked
109	else if (instance != NULL)
110	{
111		instance->setMinimized(FALSE);
112		if (instance->getVisible())
113		{
114			instance->setVisible(FALSE);
115		}
116		else
117		{
118			instance->setVisible(TRUE);
119			gFloaterView->bringToFront(instance);
120		}
121	}
122}
123
124void LLDockableFloater::resetInstance()
125{
126	if (mUniqueDocking && sInstanceHandle.get() != this)
127	{
128		if (sInstanceHandle.get() != NULL && sInstanceHandle.get()->isDocked())
129		{
130			sInstanceHandle.get()->setVisible(FALSE);
131		}
132		sInstanceHandle = getHandle();
133	}
134}
135
136void LLDockableFloater::setVisible(BOOL visible)
137{
138	// Force docking if requested
139	if (visible && mForceDocking)
140	{
141		setCanDock(true);
142		setDocked(true);
143		mForceDocking = false;
144	}
145
146	if(visible && isDocked())
147	{
148		resetInstance();
149	}
150
151	if (visible && mDockControl.get() != NULL)
152	{
153		mDockControl.get()->repositionDockable();
154	}
155
156	if (visible)
157	{
158		LLFloater::setFrontmost(getAutoFocus());
159	}
160	LLFloater::setVisible(visible);
161}
162
163void LLDockableFloater::setMinimized(BOOL minimize)
164{
165	if(minimize && isDocked())
166	{
167		// minimizing a docked floater just hides it
168		setVisible(FALSE);
169	}
170	else
171	{
172		LLFloater::setMinimized(minimize);
173	}
174}
175
176LLView * LLDockableFloater::getDockWidget()
177{
178	LLView * res = NULL;
179	if (getDockControl() != NULL) {
180		res = getDockControl()->getDock();
181	}
182
183	return res;
184}
185
186void LLDockableFloater::onDockHidden()
187{
188	setCanDock(FALSE);
189}
190
191void LLDockableFloater::onDockShown()
192{
193	if (!isMinimized())
194	{
195		setCanDock(TRUE);
196	}
197}
198
199void LLDockableFloater::setDocked(bool docked, bool pop_on_undock)
200{
201	if (mDockControl.get() != NULL && mDockControl.get()->isDockVisible())
202	{
203		if (docked)
204		{
205			resetInstance();
206			mDockControl.get()->on();
207		}
208		else
209		{
210			mDockControl.get()->off();
211		}
212
213		if (!docked && pop_on_undock)
214		{
215			// visually pop up a little bit to emphasize the undocking
216			translate(0, UNDOCK_LEAP_HEIGHT);
217		}
218	}
219
220	LLFloater::setDocked(docked, pop_on_undock);
221}
222
223void LLDockableFloater::draw()
224{
225	if (mDockControl.get() != NULL)
226	{
227		mDockControl.get()->repositionDockable();
228		if (isDocked())
229		{
230			mDockControl.get()->drawToungue();
231		}
232	}
233	LLFloater::draw();
234}
235
236void LLDockableFloater::setDockControl(LLDockControl* dockControl)
237{
238	mDockControl.reset(dockControl);
239	setDocked(isDocked());
240}
241
242const LLUIImagePtr& LLDockableFloater::getDockTongue(LLDockControl::DocAt dock_side)
243{
244	switch(dock_side)
245	{
246	case LLDockControl::LEFT:
247		mDockTongue = LLUI::getUIImage("Flyout_Left");
248		break;
249	case LLDockControl::RIGHT:
250		mDockTongue = LLUI::getUIImage("Flyout_Right");
251		break;
252	default:
253		mDockTongue = LLUI::getUIImage("Flyout_Pointer");
254		break;
255	}
256
257	return mDockTongue;
258}
259
260LLDockControl* LLDockableFloater::getDockControl()
261{
262	return mDockControl.get();
263}