llclipboard.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /**
  2. * @file llclipboard.cpp
  3. * @brief LLClipboard base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. * Copyright (c) 2009-2023, Henri Beauchamp.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "linden_common.h"
  34. #include "llclipboard.h"
  35. #include "llwindow.h"
  36. // Global singleton
  37. LLClipboard gClipboard;
  38. void LLClipboard::copyFromSubstring(const LLWString& src, S32 pos, S32 len)
  39. {
  40. if (pos >= 0 && pos < (S32)src.length())
  41. {
  42. mString = src.substr(pos, len);
  43. }
  44. else
  45. {
  46. mString.clear();
  47. }
  48. if (gWindowp)
  49. {
  50. gWindowp->copyTextToClipboard(mString);
  51. }
  52. }
  53. const LLWString& LLClipboard::getPasteWString()
  54. {
  55. if (gWindowp)
  56. {
  57. gWindowp->pasteTextFromClipboard(mString);
  58. }
  59. return mString;
  60. }
  61. bool LLClipboard::canPasteString() const
  62. {
  63. return gWindowp && gWindowp->isClipboardTextAvailable();
  64. }
  65. void LLClipboard::copyFromPrimarySubstring(const LLWString& src, S32 pos,
  66. S32 len)
  67. {
  68. if (pos >= 0 && pos < (S32)src.length())
  69. {
  70. mString = src.substr(pos, len);
  71. }
  72. else
  73. {
  74. mString.clear();
  75. }
  76. if (gWindowp)
  77. {
  78. gWindowp->copyTextToPrimary(mString);
  79. }
  80. }
  81. const LLWString& LLClipboard::getPastePrimaryWString()
  82. {
  83. if (gWindowp)
  84. {
  85. gWindowp->pasteTextFromPrimary(mString);
  86. }
  87. return mString;
  88. }
  89. bool LLClipboard::canPastePrimaryString() const
  90. {
  91. return gWindowp && gWindowp->isPrimaryTextAvailable();
  92. }