MacPasteboardMime.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // This module implements part of the support for rectangular selections on
  2. // OS/X. It is a separate file to avoid clashes between OS/X and Scintilla
  3. // data types.
  4. //
  5. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  6. //
  7. // This file is part of QScintilla.
  8. //
  9. // This file may be used under the terms of the GNU General Public License
  10. // version 3.0 as published by the Free Software Foundation and appearing in
  11. // the file LICENSE included in the packaging of this file. Please review the
  12. // following information to ensure the GNU General Public License version 3.0
  13. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  14. //
  15. // If you do not wish to use this file under the terms of the GPL version 3.0
  16. // then you may purchase a commercial license. For more information contact
  17. // info@riverbankcomputing.com.
  18. //
  19. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  20. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. #include <qglobal.h>
  22. #if (QT_VERSION >= 0x040200 && QT_VERSION < 0x050000 && defined(Q_OS_MAC)) || (QT_VERSION >= 0x050200 && defined(Q_OS_OSX))
  23. #include <QByteArray>
  24. #include <QLatin1String>
  25. #include <QList>
  26. #include <QString>
  27. #include <QStringList>
  28. #include <QVariant>
  29. #include <QMacPasteboardMime>
  30. static const QLatin1String mimeRectangular("text/x-qscintilla-rectangular");
  31. static const QLatin1String utiRectangularMac("com.scintilla.utf16-plain-text.rectangular");
  32. class RectangularPasteboardMime : public QMacPasteboardMime
  33. {
  34. public:
  35. RectangularPasteboardMime() : QMacPasteboardMime(MIME_ALL)
  36. {
  37. }
  38. bool canConvert(const QString &mime, QString flav)
  39. {
  40. return mime == mimeRectangular && flav == utiRectangularMac;
  41. }
  42. QList<QByteArray> convertFromMime(const QString &, QVariant data, QString)
  43. {
  44. QList<QByteArray> converted;
  45. converted.append(data.toByteArray());
  46. return converted;
  47. }
  48. QVariant convertToMime(const QString &, QList<QByteArray> data, QString)
  49. {
  50. QByteArray converted;
  51. foreach (QByteArray i, data)
  52. {
  53. converted += i;
  54. }
  55. return QVariant(converted);
  56. }
  57. QString convertorName()
  58. {
  59. return QString("QScintillaRectangular");
  60. }
  61. QString flavorFor(const QString &mime)
  62. {
  63. if (mime == mimeRectangular)
  64. return QString(utiRectangularMac);
  65. return QString();
  66. }
  67. QString mimeFor(QString flav)
  68. {
  69. if (flav == utiRectangularMac)
  70. return QString(mimeRectangular);
  71. return QString();
  72. }
  73. };
  74. // Initialise the singleton instance.
  75. void initialiseRectangularPasteboardMime()
  76. {
  77. static RectangularPasteboardMime *instance = 0;
  78. if (!instance)
  79. {
  80. instance = new RectangularPasteboardMime();
  81. qRegisterDraggedTypes(QStringList(utiRectangularMac));
  82. }
  83. }
  84. #endif