PageRenderTime 31ms CodeModel.GetById 1ms app.highlight 24ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/llui/llclipboard.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 142 lines | 89 code | 27 blank | 26 comment | 8 complexity | 64dede0673bdf86ee0dd08f2cc509eaa MD5 | raw file
  1/** 
  2 * @file llclipboard.cpp
  3 * @brief LLClipboard base class
  4 *
  5 * $LicenseInfo:firstyear=2001&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 "llclipboard.h"
 30
 31#include "llerror.h"
 32#include "llmath.h"
 33#include "llstring.h"
 34#include "llview.h"
 35#include "llwindow.h"
 36
 37// Global singleton
 38LLClipboard gClipboard;
 39
 40
 41LLClipboard::LLClipboard()
 42{
 43	mSourceItem = NULL;
 44}
 45
 46
 47LLClipboard::~LLClipboard()
 48{
 49}
 50
 51
 52void LLClipboard::copyFromSubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
 53{
 54	mSourceID = source_id;
 55	mString = src.substr(pos, len);
 56	LLView::getWindow()->copyTextToClipboard( mString );
 57}
 58
 59void LLClipboard::copyFromString(const LLWString &src, const LLUUID& source_id )
 60{
 61	mSourceID = source_id;
 62	mString = src;
 63	LLView::getWindow()->copyTextToClipboard( mString );
 64}
 65
 66const LLWString& LLClipboard::getPasteWString( LLUUID* source_id )
 67{
 68	if( mSourceID.notNull() )
 69	{
 70		LLWString temp_string;
 71		LLView::getWindow()->pasteTextFromClipboard(temp_string);
 72
 73		if( temp_string != mString )
 74		{
 75			mSourceID.setNull();
 76			mString = temp_string;
 77		}
 78	}
 79	else
 80	{
 81		LLView::getWindow()->pasteTextFromClipboard(mString);
 82	}
 83
 84	if( source_id )
 85	{
 86		*source_id = mSourceID;
 87	}
 88
 89	return mString;
 90}
 91
 92
 93BOOL LLClipboard::canPasteString() const
 94{
 95	return LLView::getWindow()->isClipboardTextAvailable();
 96}
 97
 98
 99void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
100{
101	mSourceID = source_id;
102	mString = src.substr(pos, len);
103	LLView::getWindow()->copyTextToPrimary( mString );
104}
105
106
107const LLWString& LLClipboard::getPastePrimaryWString( LLUUID* source_id )
108{
109	if( mSourceID.notNull() )
110	{
111		LLWString temp_string;
112		LLView::getWindow()->pasteTextFromPrimary(temp_string);
113
114		if( temp_string != mString )
115		{
116			mSourceID.setNull();
117			mString = temp_string;
118		}
119	}
120	else
121	{
122		LLView::getWindow()->pasteTextFromPrimary(mString);
123	}
124
125	if( source_id )
126	{
127		*source_id = mSourceID;
128	}
129
130	return mString;
131}
132
133
134BOOL LLClipboard::canPastePrimaryString() const
135{
136	return LLView::getWindow()->isPrimaryTextAvailable();
137}
138
139void LLClipboard::setSourceObject(const LLUUID& source_id, LLAssetType::EType type) 
140{
141	mSourceItem = new LLInventoryObject (source_id, LLUUID::null, type, "");
142}