/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. #include "linden_common.h"
  27. #include "llclipboard.h"
  28. #include "llerror.h"
  29. #include "llmath.h"
  30. #include "llstring.h"
  31. #include "llview.h"
  32. #include "llwindow.h"
  33. // Global singleton
  34. LLClipboard gClipboard;
  35. LLClipboard::LLClipboard()
  36. {
  37. mSourceItem = NULL;
  38. }
  39. LLClipboard::~LLClipboard()
  40. {
  41. }
  42. void LLClipboard::copyFromSubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
  43. {
  44. mSourceID = source_id;
  45. mString = src.substr(pos, len);
  46. LLView::getWindow()->copyTextToClipboard( mString );
  47. }
  48. void LLClipboard::copyFromString(const LLWString &src, const LLUUID& source_id )
  49. {
  50. mSourceID = source_id;
  51. mString = src;
  52. LLView::getWindow()->copyTextToClipboard( mString );
  53. }
  54. const LLWString& LLClipboard::getPasteWString( LLUUID* source_id )
  55. {
  56. if( mSourceID.notNull() )
  57. {
  58. LLWString temp_string;
  59. LLView::getWindow()->pasteTextFromClipboard(temp_string);
  60. if( temp_string != mString )
  61. {
  62. mSourceID.setNull();
  63. mString = temp_string;
  64. }
  65. }
  66. else
  67. {
  68. LLView::getWindow()->pasteTextFromClipboard(mString);
  69. }
  70. if( source_id )
  71. {
  72. *source_id = mSourceID;
  73. }
  74. return mString;
  75. }
  76. BOOL LLClipboard::canPasteString() const
  77. {
  78. return LLView::getWindow()->isClipboardTextAvailable();
  79. }
  80. void LLClipboard::copyFromPrimarySubstring(const LLWString &src, S32 pos, S32 len, const LLUUID& source_id )
  81. {
  82. mSourceID = source_id;
  83. mString = src.substr(pos, len);
  84. LLView::getWindow()->copyTextToPrimary( mString );
  85. }
  86. const LLWString& LLClipboard::getPastePrimaryWString( LLUUID* source_id )
  87. {
  88. if( mSourceID.notNull() )
  89. {
  90. LLWString temp_string;
  91. LLView::getWindow()->pasteTextFromPrimary(temp_string);
  92. if( temp_string != mString )
  93. {
  94. mSourceID.setNull();
  95. mString = temp_string;
  96. }
  97. }
  98. else
  99. {
  100. LLView::getWindow()->pasteTextFromPrimary(mString);
  101. }
  102. if( source_id )
  103. {
  104. *source_id = mSourceID;
  105. }
  106. return mString;
  107. }
  108. BOOL LLClipboard::canPastePrimaryString() const
  109. {
  110. return LLView::getWindow()->isPrimaryTextAvailable();
  111. }
  112. void LLClipboard::setSourceObject(const LLUUID& source_id, LLAssetType::EType type)
  113. {
  114. mSourceItem = new LLInventoryObject (source_id, LLUUID::null, type, "");
  115. }