summaryrefslogtreecommitdiff
path: root/indra/newview/llpreview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llpreview.cpp')
-rw-r--r--indra/newview/llpreview.cpp407
1 files changed, 166 insertions, 241 deletions
diff --git a/indra/newview/llpreview.cpp b/indra/newview/llpreview.cpp
index cad38e36ff..69542764d2 100644
--- a/indra/newview/llpreview.cpp
+++ b/indra/newview/llpreview.cpp
@@ -2,30 +2,25 @@
* @file llpreview.cpp
* @brief LLPreview class implementation
*
- * $LicenseInfo:firstyear=2002&license=viewergpl$
- *
- * Copyright (c) 2002-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -33,142 +28,88 @@
#include "stdenums.h"
#include "llpreview.h"
+
#include "lllineeditor.h"
-#include "llinventory.h"
+#include "llinventorydefines.h"
#include "llinventorymodel.h"
#include "llresmgr.h"
#include "lltextbox.h"
+#include "llfloaterreg.h"
#include "llfocusmgr.h"
#include "lltooldraganddrop.h"
#include "llradiogroup.h"
#include "llassetstorage.h"
+#include "llviewerassettype.h"
#include "llviewerobject.h"
#include "llviewerobjectlist.h"
#include "lldbstrings.h"
#include "llagent.h"
-#include "llvoavatar.h"
+#include "llvoavatarself.h"
#include "llselectmgr.h"
-#include "llinventoryview.h"
#include "llviewerinventory.h"
+#include "llviewerwindow.h"
+#include "lltrans.h"
// Constants
-// Globals and statics
-LLPreview::preview_multimap_t LLPreview::sPreviewsBySource;
-LLPreview::preview_map_t LLPreview::sInstances;
-std::map<LLUUID, LLHandle<LLFloater> > LLMultiPreview::sAutoOpenPreviewHandles;
-
-// Functions
-LLPreview::LLPreview(const std::string& name) :
- LLFloater(name),
- mCopyToInvBtn(NULL),
+LLPreview::LLPreview(const LLSD& key)
+: LLFloater(key),
+ mItemUUID(key.asUUID()),
+ mObjectUUID(), // set later by setObjectID()
+ mCopyToInvBtn( NULL ),
mForceClose(FALSE),
mUserResized(FALSE),
mCloseAfterSave(FALSE),
mAssetStatus(PREVIEW_ASSET_UNLOADED),
- mItem(NULL),
mDirty(TRUE)
{
- // don't add to instance list, since ItemID is null
- mAuxItem = new LLInventoryItem; // (LLPointer is auto-deleted)
+ mAuxItem = new LLInventoryItem;
// don't necessarily steal focus on creation -- sometimes these guys pop up without user action
setAutoFocus(FALSE);
+
gInventory.addObserver(this);
+
+ refreshFromItem();
}
-LLPreview::LLPreview(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const LLUUID& object_uuid, BOOL allow_resize, S32 min_width, S32 min_height, LLPointer<LLViewerInventoryItem> inv_item )
-: LLFloater(name, rect, title, allow_resize, min_width, min_height ),
- mItemUUID(item_uuid),
- mSourceID(LLUUID::null),
- mObjectUUID(object_uuid),
- mCopyToInvBtn( NULL ),
- mForceClose( FALSE ),
- mUserResized(FALSE),
- mCloseAfterSave(FALSE),
- mAssetStatus(PREVIEW_ASSET_UNLOADED),
- mItem(inv_item),
- mDirty(TRUE)
+BOOL LLPreview::postBuild()
{
- mAuxItem = new LLInventoryItem;
- // don't necessarily steal focus on creation -- sometimes these guys pop up without user action
- setAutoFocus(FALSE);
-
- if (mItemUUID.notNull())
- {
- sInstances[mItemUUID] = this;
- }
- gInventory.addObserver(this);
+ refreshFromItem();
+ return TRUE;
}
LLPreview::~LLPreview()
{
gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit()
-
- if (mItemUUID.notNull())
- {
- sInstances.erase( mItemUUID );
- }
-
- if (mSourceID.notNull())
- {
- preview_multimap_t::iterator found_it = sPreviewsBySource.find(mSourceID);
- for (; found_it != sPreviewsBySource.end(); ++found_it)
- {
- if (found_it->second == getHandle())
- {
- sPreviewsBySource.erase(found_it);
- break;
- }
- }
- }
gInventory.removeObserver(this);
}
-void LLPreview::setItemID(const LLUUID& item_id)
-{
- if (mItemUUID.notNull())
- {
- sInstances.erase(mItemUUID);
- }
-
- mItemUUID = item_id;
-
- if (mItemUUID.notNull())
- {
- sInstances[mItemUUID] = this;
- }
-}
-
void LLPreview::setObjectID(const LLUUID& object_id)
{
mObjectUUID = object_id;
+ if (getAssetStatus() == PREVIEW_ASSET_UNLOADED)
+ {
+ loadAsset();
+ }
}
-void LLPreview::setSourceID(const LLUUID& source_id)
+void LLPreview::setItem( LLInventoryItem* item )
{
- if (mSourceID.notNull())
+ mItem = item;
+ if (mItem && getAssetStatus() == PREVIEW_ASSET_UNLOADED)
{
- // erase old one
- preview_multimap_t::iterator found_it = sPreviewsBySource.find(mSourceID);
- for (; found_it != sPreviewsBySource.end(); ++found_it)
- {
- if (found_it->second == getHandle())
- {
- sPreviewsBySource.erase(found_it);
- break;
- }
- }
+ loadAsset();
}
- mSourceID = source_id;
- sPreviewsBySource.insert(preview_multimap_t::value_type(mSourceID, getHandle()));
}
-const LLViewerInventoryItem *LLPreview::getItem() const
+const LLInventoryItem *LLPreview::getItem() const
{
- if(mItem)
- return mItem;
- const LLViewerInventoryItem *item = NULL;
- if(mObjectUUID.isNull())
+ const LLInventoryItem *item = NULL;
+ if (mItem.notNull())
+ {
+ item = mItem;
+ }
+ else if (mObjectUUID.isNull())
{
// it's an inventory item, so get the item.
item = gInventory.getItem(mItemUUID);
@@ -179,7 +120,7 @@ const LLViewerInventoryItem *LLPreview::getItem() const
LLViewerObject* object = gObjectList.findObject(mObjectUUID);
if(object)
{
- item = (LLViewerInventoryItem*)object->getInventoryObject(mItemUUID);
+ item = dynamic_cast<LLInventoryItem*>(object->getInventoryObject(mItemUUID));
}
}
return item;
@@ -188,10 +129,10 @@ const LLViewerInventoryItem *LLPreview::getItem() const
// Sub-classes should override this function if they allow editing
void LLPreview::onCommit()
{
- const LLViewerInventoryItem *item = getItem();
+ const LLViewerInventoryItem *item = dynamic_cast<const LLViewerInventoryItem*>(getItem());
if(item)
{
- if (!item->isComplete())
+ if (!item->isFinished())
{
// We are attempting to save an item that was never loaded
llwarns << "LLPreview::onCommit() called with mIsComplete == FALSE"
@@ -202,7 +143,14 @@ void LLPreview::onCommit()
}
LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
- new_item->setDescription(childGetText("desc"));
+ new_item->setDescription(getChild<LLUICtrl>("desc")->getValue().asString());
+
+ std::string new_name = getChild<LLUICtrl>("name")->getValue().asString();
+ if ( (new_item->getName() != new_name) && !new_name.empty())
+ {
+ new_item->rename(getChild<LLUICtrl>("name")->getValue().asString());
+ }
+
if(mObjectUUID.notNull())
{
// must be in an object
@@ -225,17 +173,16 @@ void LLPreview::onCommit()
// update the object itself.
if( item->getType() == LLAssetType::AT_OBJECT )
{
- LLVOAvatar* avatar = gAgent.getAvatarObject();
- if( avatar )
+ if (isAgentAvatarValid())
{
- LLViewerObject* obj = avatar->getWornAttachment( item->getUUID() );
+ LLViewerObject* obj = gAgentAvatarp->getWornAttachment( item->getUUID() );
if( obj )
{
- gSelectMgr->deselectAll();
- gSelectMgr->addAsIndividual( obj, SELECT_ALL_TES, FALSE );
- gSelectMgr->selectionSetObjectDescription( childGetText("desc") );
+ LLSelectMgr::getInstance()->deselectAll();
+ LLSelectMgr::getInstance()->addAsIndividual( obj, SELECT_ALL_TES, FALSE );
+ LLSelectMgr::getInstance()->selectionSetObjectDescription( getChild<LLUICtrl>("desc")->getValue().asString() );
- gSelectMgr->deselectAll();
+ LLSelectMgr::getInstance()->deselectAll();
}
}
}
@@ -248,27 +195,41 @@ void LLPreview::changed(U32 mask)
mDirty = TRUE;
}
+void LLPreview::setNotecardInfo(const LLUUID& notecard_inv_id,
+ const LLUUID& object_id)
+{
+ mNotecardInventoryID = notecard_inv_id;
+ mNotecardObjectID = object_id;
+}
+
void LLPreview::draw()
{
LLFloater::draw();
if (mDirty)
{
mDirty = FALSE;
- const LLViewerInventoryItem *item = getItem();
- if (item)
- {
- refreshFromItem(item);
- }
+ refreshFromItem();
}
}
-void LLPreview::refreshFromItem(const LLInventoryItem* item)
+void LLPreview::refreshFromItem()
{
- setTitle(llformat("%s: %s",getTitleName(),item->getName().c_str()));
- childSetText("desc",item->getDescription());
+ const LLInventoryItem* item = getItem();
+ if (!item)
+ {
+ return;
+ }
+ if (hasString("Title"))
+ {
+ LLStringUtil::format_map_t args;
+ args["[NAME]"] = item->getName();
+ LLUIString title = getString("Title", args);
+ setTitle(title.getString());
+ }
+ getChild<LLUICtrl>("desc")->setValue(item->getDescription());
BOOL can_agent_manipulate = item->getPermissions().allowModifyBy(gAgent.getID());
- childSetEnabled("desc",can_agent_manipulate);
+ getChildView("desc")->setEnabled(can_agent_manipulate);
}
// static
@@ -286,80 +247,32 @@ void LLPreview::onRadio(LLUICtrl*, void* userdata)
}
// static
-LLPreview* LLPreview::find(const LLUUID& item_uuid)
-{
- LLPreview* instance = NULL;
- preview_map_t::iterator found_it = LLPreview::sInstances.find(item_uuid);
- if(found_it != LLPreview::sInstances.end())
- {
- instance = found_it->second;
- }
- return instance;
-}
-
-// static
-LLPreview* LLPreview::show( const LLUUID& item_uuid, BOOL take_focus )
-{
- LLPreview* instance = LLPreview::find(item_uuid);
- if(instance)
- {
- if (LLFloater::getFloaterHost() && LLFloater::getFloaterHost() != instance->getHost())
- {
- // this preview window is being opened in a new context
- // needs to be rehosted
- LLFloater::getFloaterHost()->addFloater(instance, TRUE);
- }
- instance->open(); /*Flawfinder: ignore*/
- if (take_focus)
- {
- instance->setFocus(TRUE);
- }
- }
-
- return instance;
-}
-
-// static
-bool LLPreview::save( const LLUUID& item_uuid, LLPointer<LLInventoryItem>* itemptr )
-{
- bool res = false;
- LLPreview* instance = LLPreview::find(item_uuid);
- if(instance)
- {
- res = instance->saveItem(itemptr);
- }
- if (!res)
- {
- delete itemptr;
- }
- return res;
-}
-
-// static
void LLPreview::hide(const LLUUID& item_uuid, BOOL no_saving /* = FALSE */ )
{
- preview_map_t::iterator found_it = LLPreview::sInstances.find(item_uuid);
- if(found_it != LLPreview::sInstances.end())
+ LLFloater* floater = LLFloaterReg::findInstance("preview", LLSD(item_uuid));
+ if (!floater) floater = LLFloaterReg::findInstance("preview_avatar", LLSD(item_uuid));
+
+ LLPreview* preview = dynamic_cast<LLPreview*>(floater);
+ if (preview)
{
- LLPreview* instance = found_it->second;
-
if ( no_saving )
{
- instance->mForceClose = TRUE;
+ preview->mForceClose = TRUE;
}
-
- instance->close();
+ preview->closeFloater();
}
}
// static
-void LLPreview::rename(const LLUUID& item_uuid, const std::string& new_name)
+void LLPreview::dirty(const LLUUID& item_uuid)
{
- preview_map_t::iterator found_it = LLPreview::sInstances.find(item_uuid);
- if(found_it != LLPreview::sInstances.end())
+ LLFloater* floater = LLFloaterReg::findInstance("preview", LLSD(item_uuid));
+ if (!floater) floater = LLFloaterReg::findInstance("preview_avatar", LLSD(item_uuid));
+
+ LLPreview* preview = dynamic_cast<LLPreview*>(floater);
+ if(preview)
{
- LLPreview* instance = found_it->second;
- instance->setTitle( new_name );
+ preview->mDirty = TRUE;
}
}
@@ -374,7 +287,7 @@ BOOL LLPreview::handleMouseDown(S32 x, S32 y, MASK mask)
S32 screen_x;
S32 screen_y;
localPointToScreen(x, y, &screen_x, &screen_y );
- gToolDragAndDrop->setDragStart(screen_x, screen_y);
+ LLToolDragAndDrop::getInstance()->setDragStart(screen_x, screen_y);
return TRUE;
}
return LLFloater::handleMouseDown(x, y, mask);
@@ -396,16 +309,16 @@ BOOL LLPreview::handleHover(S32 x, S32 y, MASK mask)
{
S32 screen_x;
S32 screen_y;
- const LLViewerInventoryItem *item = getItem();
+ const LLInventoryItem *item = getItem();
localPointToScreen(x, y, &screen_x, &screen_y );
if(item
&& item->getPermissions().allowCopyBy(gAgent.getID(),
gAgent.getGroupID())
- && gToolDragAndDrop->isOverThreshold(screen_x, screen_y))
+ && LLToolDragAndDrop::getInstance()->isOverThreshold(screen_x, screen_y))
{
EDragAndDropType type;
- type = LLAssetType::lookupDragAndDropType(item->getType());
+ type = LLViewerAssetType::lookupDragAndDropType(item->getType());
LLToolDragAndDrop::ESource src = LLToolDragAndDrop::SOURCE_LIBRARY;
if(!mObjectUUID.isNull())
{
@@ -415,32 +328,30 @@ BOOL LLPreview::handleHover(S32 x, S32 y, MASK mask)
{
src = LLToolDragAndDrop::SOURCE_AGENT;
}
- gToolDragAndDrop->beginDrag(type,
+ LLToolDragAndDrop::getInstance()->beginDrag(type,
item->getUUID(),
src,
mObjectUUID);
- return gToolDragAndDrop->handleHover(x, y, mask );
+ return LLToolDragAndDrop::getInstance()->handleHover(x, y, mask );
}
}
return LLFloater::handleHover(x,y,mask);
}
-void LLPreview::open() /*Flawfinder: ignore*/
+void LLPreview::onOpen(const LLSD& key)
{
if (!getFloaterHost() && !getHost() && getAssetStatus() == PREVIEW_ASSET_UNLOADED)
{
loadAsset();
}
- LLFloater::open(); /*Flawfinder: ignore*/
}
-// virtual
-bool LLPreview::saveItem(LLPointer<LLInventoryItem>* itemptr)
+void LLPreview::setAuxItem( const LLInventoryItem* item )
{
- return false;
+ if ( mAuxItem )
+ mAuxItem->copyItem(item);
}
-
// static
void LLPreview::onBtnCopyToInv(void* userdata)
{
@@ -452,7 +363,7 @@ void LLPreview::onBtnCopyToInv(void* userdata)
// Copy to inventory
if (self->mNotecardInventoryID.notNull())
{
- copy_inventory_from_notecard(self->mObjectID,
+ copy_inventory_from_notecard(self->mNotecardObjectID,
self->mNotecardInventoryID, item);
}
else
@@ -467,14 +378,14 @@ void LLPreview::onBtnCopyToInv(void* userdata)
cb);
}
}
- self->close();
+ self->closeFloater();
}
// static
void LLPreview::onKeepBtn(void* data)
{
LLPreview* self = (LLPreview*)data;
- self->close();
+ self->closeFloater();
}
// static
@@ -482,11 +393,11 @@ void LLPreview::onDiscardBtn(void* data)
{
LLPreview* self = (LLPreview*)data;
- const LLViewerInventoryItem* item = self->getItem();
+ const LLInventoryItem* item = self->getItem();
if (!item) return;
self->mForceClose = TRUE;
- self->close();
+ self->closeFloater();
// Delete the item entirely
/*
@@ -496,7 +407,7 @@ void LLPreview::onDiscardBtn(void* data)
*/
// Move the item to the trash
- LLUUID trash_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_TRASH);
+ const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
if (item->getParentUUID() != trash_id)
{
LLInventoryModel::update_list_t update;
@@ -516,55 +427,60 @@ void LLPreview::onDiscardBtn(void* data)
}
}
-//static
-LLPreview* LLPreview::getFirstPreviewForSource(const LLUUID& source_id)
+void LLPreview::handleReshape(const LLRect& new_rect, bool by_user)
{
- preview_multimap_t::iterator found_it = sPreviewsBySource.find(source_id);
- if (found_it != sPreviewsBySource.end())
- {
- // just return first one
- return (LLPreview*)found_it->second.get();
- }
- return NULL;
-}
-
-void LLPreview::userSetShape(const LLRect& new_rect)
-{
- if(new_rect.getWidth() != getRect().getWidth() || new_rect.getHeight() != getRect().getHeight())
+ if(by_user
+ && (new_rect.getWidth() != getRect().getWidth() || new_rect.getHeight() != getRect().getHeight()))
{
userResized();
}
- LLFloater::userSetShape(new_rect);
+ LLFloater::handleReshape(new_rect, by_user);
}
//
// LLMultiPreview
//
-LLMultiPreview::LLMultiPreview(const LLRect& rect) : LLMultiFloater("Preview", rect)
+LLMultiPreview::LLMultiPreview()
+ : LLMultiFloater(LLSD())
{
+ // *TODO: There should be a .xml file for this
+ const LLRect& nextrect = LLFloaterReg::getFloaterRect("preview"); // place where the next preview should show up
+ if (nextrect.getWidth() > 0)
+ {
+ setRect(nextrect);
+ }
+ else
+ {
+ // start with a rect in the top-left corner ; will get resized
+ LLRect rect;
+ rect.setLeftTopAndSize(0, gViewerWindow->getWindowHeightScaled(), 200, 200);
+ setRect(rect);
+ }
+ setTitle(LLTrans::getString("MultiPreviewTitle"));
+ buildTabContainer();
setCanResize(TRUE);
}
-void LLMultiPreview::open() /*Flawfinder: ignore*/
+void LLMultiPreview::onOpen(const LLSD& key)
{
- LLMultiFloater::open(); /*Flawfinder: ignore*/
LLPreview* frontmost_preview = (LLPreview*)mTabContainer->getCurrentPanel();
if (frontmost_preview && frontmost_preview->getAssetStatus() == LLPreview::PREVIEW_ASSET_UNLOADED)
{
frontmost_preview->loadAsset();
}
+ LLMultiFloater::onOpen(key);
}
-void LLMultiPreview::userSetShape(const LLRect& new_rect)
+void LLMultiPreview::handleReshape(const LLRect& new_rect, bool by_user)
{
if(new_rect.getWidth() != getRect().getWidth() || new_rect.getHeight() != getRect().getHeight())
{
LLPreview* frontmost_preview = (LLPreview*)mTabContainer->getCurrentPanel();
if (frontmost_preview) frontmost_preview->userResized();
}
- LLFloater::userSetShape(new_rect);
+ LLFloater::handleReshape(new_rect, by_user);
}
@@ -577,22 +493,31 @@ void LLMultiPreview::tabOpen(LLFloater* opened_floater, bool from_click)
}
}
-//static
-LLMultiPreview* LLMultiPreview::getAutoOpenInstance(const LLUUID& id)
+
+void LLPreview::setAssetId(const LLUUID& asset_id)
{
- handle_map_t::iterator found_it = sAutoOpenPreviewHandles.find(id);
- if (found_it != sAutoOpenPreviewHandles.end())
+ const LLViewerInventoryItem* item = dynamic_cast<const LLViewerInventoryItem*>(getItem());
+ if(NULL == item)
{
- return (LLMultiPreview*)found_it->second.get();
+ return;
}
- return NULL;
-}
-
-//static
-void LLMultiPreview::setAutoOpenInstance(LLMultiPreview* previewp, const LLUUID& id)
-{
- if (previewp)
+
+ if(mObjectUUID.isNull())
+ {
+ // Update avatar inventory asset_id.
+ LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+ new_item->setAssetUUID(asset_id);
+ gInventory.updateItem(new_item);
+ gInventory.notifyObservers();
+ }
+ else
{
- sAutoOpenPreviewHandles[id] = previewp->getHandle();
+ // Update object inventory asset_id.
+ LLViewerObject* object = gObjectList.findObject(mObjectUUID);
+ if(NULL == object)
+ {
+ return;
+ }
+ object->updateViewerInventoryAsset(item, asset_id);
}
}