1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799
|
// This module implements the "official" low-level API.
//
// Copyright (c) 2015 Riverbank Computing Limited <info@riverbankcomputing.com>
//
// This file is part of QScintilla.
//
// This file may be used under the terms of the GNU General Public License
// version 3.0 as published by the Free Software Foundation and appearing in
// the file LICENSE included in the packaging of this file. Please review the
// following information to ensure the GNU General Public License version 3.0
// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
//
// If you do not wish to use this file under the terms of the GPL version 3.0
// then you may purchase a commercial license. For more information contact
// info@riverbankcomputing.com.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#include "Qsci/qsciscintillabase.h"
#include <QApplication>
#include <QClipboard>
#include <QColor>
#include <QContextMenuEvent>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDropEvent>
#include <QDragLeaveEvent>
#include <QFocusEvent>
#include <QKeyEvent>
#include <QList>
#include <QMimeData>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QScrollBar>
#include <QStyle>
#include <QTextCodec>
#include "ScintillaQt.h"
// The #defines in Scintilla.h and the enums in qsciscintillabase.h conflict
// (because we want to use the same names) so we have to undefine those we use
// in this file.
#undef SCI_SETCARETPERIOD
#undef SCK_DOWN
#undef SCK_UP
#undef SCK_LEFT
#undef SCK_RIGHT
#undef SCK_HOME
#undef SCK_END
#undef SCK_PRIOR
#undef SCK_NEXT
#undef SCK_DELETE
#undef SCK_INSERT
#undef SCK_ESCAPE
#undef SCK_BACK
#undef SCK_TAB
#undef SCK_RETURN
#undef SCK_ADD
#undef SCK_SUBTRACT
#undef SCK_DIVIDE
#undef SCK_WIN
#undef SCK_RWIN
#undef SCK_MENU
// Remember if we have linked the lexers.
static bool lexersLinked = false;
// The list of instances.
static QList<QsciScintillaBase *> poolList;
// Mime support.
static const QLatin1String mimeTextPlain("text/plain");
static const QLatin1String mimeRectangularWin("MSDEVColumnSelect");
static const QLatin1String mimeRectangular("text/x-qscintilla-rectangular");
#if (QT_VERSION >= 0x040200 && QT_VERSION < 0x050000 && defined(Q_OS_MAC)) || (QT_VERSION >= 0x050200 && defined(Q_OS_OSX))
extern void initialiseRectangularPasteboardMime();
#endif
// The ctor.
QsciScintillaBase::QsciScintillaBase(QWidget *parent)
: QAbstractScrollArea(parent), preeditPos(-1), preeditNrBytes(0)
#if QT_VERSION >= 0x050000
, clickCausedFocus(false)
#endif
{
connect(verticalScrollBar(), SIGNAL(valueChanged(int)),
SLOT(handleVSb(int)));
connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
SLOT(handleHSb(int)));
setAcceptDrops(true);
setFocusPolicy(Qt::WheelFocus);
setAttribute(Qt::WA_KeyCompression);
setAttribute(Qt::WA_InputMethodEnabled);
#if QT_VERSION >= 0x050100
setInputMethodHints(
Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText|Qt::ImhMultiLine);
#elif QT_VERSION >= 0x040600
setInputMethodHints(Qt::ImhNoAutoUppercase|Qt::ImhNoPredictiveText);
#endif
viewport()->setBackgroundRole(QPalette::Base);
viewport()->setMouseTracking(true);
viewport()->setAttribute(Qt::WA_NoSystemBackground);
triple_click.setSingleShot(true);
#if (QT_VERSION >= 0x040200 && QT_VERSION < 0x050000 && defined(Q_OS_MAC)) || (QT_VERSION >= 0x050200 && defined(Q_OS_OSX))
initialiseRectangularPasteboardMime();
#endif
sci = new QsciScintillaQt(this);
SendScintilla(SCI_SETCARETPERIOD, QApplication::cursorFlashTime() / 2);
// Make sure the lexers are linked in.
if (!lexersLinked)
{
Scintilla_LinkLexers();
lexersLinked = true;
}
QClipboard *cb = QApplication::clipboard();
if (cb->supportsSelection())
connect(cb, SIGNAL(selectionChanged()), SLOT(handleSelection()));
// Add it to the pool.
poolList.append(this);
}
// The dtor.
QsciScintillaBase::~QsciScintillaBase()
{
// The QsciScintillaQt object isn't a child so delete it explicitly.
delete sci;
// Remove it from the pool.
poolList.removeAt(poolList.indexOf(this));
}
// Return an instance from the pool.
QsciScintillaBase *QsciScintillaBase::pool()
{
return poolList.first();
}
// Tell Scintilla to update the scroll bars. Scintilla should be doing this
// itself.
void QsciScintillaBase::setScrollBars()
{
sci->SetScrollBars();
}
// Send a message to the real Scintilla widget using the low level Scintilla
// API.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
long lParam) const
{
return sci->WndProc(msg, wParam, lParam);
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
void *lParam) const
{
return sci->WndProc(msg, wParam, reinterpret_cast<sptr_t>(lParam));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
const char *lParam) const
{
return sci->WndProc(msg, wParam, reinterpret_cast<sptr_t>(lParam));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg,
const char *lParam) const
{
return sci->WndProc(msg, static_cast<uptr_t>(0),
reinterpret_cast<sptr_t>(lParam));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, const char *wParam,
const char *lParam) const
{
return sci->WndProc(msg, reinterpret_cast<uptr_t>(wParam),
reinterpret_cast<sptr_t>(lParam));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, long wParam) const
{
return sci->WndProc(msg, static_cast<uptr_t>(wParam),
static_cast<sptr_t>(0));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, int wParam) const
{
return sci->WndProc(msg, static_cast<uptr_t>(wParam),
static_cast<sptr_t>(0));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, long cpMin, long cpMax,
char *lpstrText) const
{
QSCI_SCI_NAMESPACE(TextRange) tr;
tr.chrg.cpMin = cpMin;
tr.chrg.cpMax = cpMax;
tr.lpstrText = lpstrText;
return sci->WndProc(msg, static_cast<uptr_t>(0),
reinterpret_cast<sptr_t>(&tr));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
const QColor &col) const
{
sptr_t lParam = (col.blue() << 16) | (col.green() << 8) | col.red();
return sci->WndProc(msg, wParam, lParam);
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, const QColor &col) const
{
uptr_t wParam = (col.blue() << 16) | (col.green() << 8) | col.red();
return sci->WndProc(msg, wParam, static_cast<sptr_t>(0));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
QPainter *hdc, const QRect &rc, long cpMin, long cpMax) const
{
QSCI_SCI_NAMESPACE(RangeToFormat) rf;
rf.hdc = rf.hdcTarget = reinterpret_cast<QSCI_SCI_NAMESPACE(SurfaceID)>(hdc);
rf.rc.left = rc.left();
rf.rc.top = rc.top();
rf.rc.right = rc.right() + 1;
rf.rc.bottom = rc.bottom() + 1;
rf.chrg.cpMin = cpMin;
rf.chrg.cpMax = cpMax;
return sci->WndProc(msg, wParam, reinterpret_cast<sptr_t>(&rf));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
const QPixmap &lParam) const
{
return sci->WndProc(msg, wParam, reinterpret_cast<sptr_t>(&lParam));
}
// Overloaded message send.
long QsciScintillaBase::SendScintilla(unsigned int msg, unsigned long wParam,
const QImage &lParam) const
{
return sci->WndProc(msg, wParam, reinterpret_cast<sptr_t>(&lParam));
}
// Send a message to the real Scintilla widget using the low level Scintilla
// API that returns a pointer result.
void *QsciScintillaBase::SendScintillaPtrResult(unsigned int msg) const
{
return reinterpret_cast<void *>(sci->WndProc(msg, static_cast<uptr_t>(0),
static_cast<sptr_t>(0)));
}
// Re-implemented to handle the context menu.
void QsciScintillaBase::contextMenuEvent(QContextMenuEvent *e)
{
sci->ContextMenu(QSCI_SCI_NAMESPACE(Point)(e->globalX(), e->globalY()));
}
// Re-implemented to tell the widget it has the focus.
void QsciScintillaBase::focusInEvent(QFocusEvent *e)
{
sci->SetFocusState(true);
#if QT_VERSION >= 0x050000
clickCausedFocus = (e->reason() == Qt::MouseFocusReason);
#endif
QAbstractScrollArea::focusInEvent(e);
}
// Re-implemented to tell the widget it has lost the focus.
void QsciScintillaBase::focusOutEvent(QFocusEvent *e)
{
if (e->reason() == Qt::ActiveWindowFocusReason)
{
// Only tell Scintilla we have lost focus if the new active window
// isn't our auto-completion list. This is probably only an issue on
// Linux and there are still problems because subsequent focus out
// events don't always seem to get generated (at least with Qt5).
QWidget *aw = QApplication::activeWindow();
if (!aw || aw->parent() != this || !aw->inherits("QsciSciListBox"))
sci->SetFocusState(false);
}
else
{
sci->SetFocusState(false);
}
QAbstractScrollArea::focusOutEvent(e);
}
// Re-implemented to make sure tabs are passed to the editor.
bool QsciScintillaBase::focusNextPrevChild(bool next)
{
if (!sci->pdoc->IsReadOnly())
return false;
return QAbstractScrollArea::focusNextPrevChild(next);
}
// Handle the selection changing.
void QsciScintillaBase::handleSelection()
{
if (!QApplication::clipboard()->ownsSelection())
sci->UnclaimSelection();
}
// Handle key presses.
void QsciScintillaBase::keyPressEvent(QKeyEvent *e)
{
int modifiers = 0;
if (e->modifiers() & Qt::ShiftModifier)
modifiers |= SCMOD_SHIFT;
if (e->modifiers() & Qt::ControlModifier)
modifiers |= SCMOD_CTRL;
if (e->modifiers() & Qt::AltModifier)
modifiers |= SCMOD_ALT;
if (e->modifiers() & Qt::MetaModifier)
modifiers |= SCMOD_META;
int key = commandKey(e->key(), modifiers);
if (key)
{
bool consumed = false;
sci->KeyDownWithModifiers(key, modifiers, &consumed);
if (consumed)
{
e->accept();
return;
}
}
QString text = e->text();
if (!text.isEmpty() && text[0].isPrint())
{
ScintillaBytes bytes = textAsBytes(text);
sci->AddCharUTF(bytes.data(), bytes.length());
e->accept();
}
else
{
QAbstractScrollArea::keyPressEvent(e);
}
}
// Map a Qt key to a valid Scintilla command key, or 0 if none.
int QsciScintillaBase::commandKey(int qt_key, int &modifiers)
{
int key;
switch (qt_key)
{
case Qt::Key_Down:
key = SCK_DOWN;
break;
case Qt::Key_Up:
key = SCK_UP;
break;
case Qt::Key_Left:
key = SCK_LEFT;
break;
case Qt::Key_Right:
key = SCK_RIGHT;
break;
case Qt::Key_Home:
key = SCK_HOME;
break;
case Qt::Key_End:
key = SCK_END;
break;
case Qt::Key_PageUp:
key = SCK_PRIOR;
break;
case Qt::Key_PageDown:
key = SCK_NEXT;
break;
case Qt::Key_Delete:
key = SCK_DELETE;
break;
case Qt::Key_Insert:
key = SCK_INSERT;
break;
case Qt::Key_Escape:
key = SCK_ESCAPE;
break;
case Qt::Key_Backspace:
key = SCK_BACK;
break;
case Qt::Key_Tab:
key = SCK_TAB;
break;
case Qt::Key_Backtab:
// Scintilla assumes a backtab is shift-tab.
key = SCK_TAB;
modifiers |= SCMOD_SHIFT;
break;
case Qt::Key_Return:
case Qt::Key_Enter:
key = SCK_RETURN;
break;
case Qt::Key_Super_L:
key = SCK_WIN;
break;
case Qt::Key_Super_R:
key = SCK_RWIN;
break;
case Qt::Key_Menu:
key = SCK_MENU;
break;
default:
if ((key = qt_key) > 0x7f)
key = 0;
}
return key;
}
// Encode a QString as bytes.
QsciScintillaBase::ScintillaBytes QsciScintillaBase::textAsBytes(const QString &text) const
{
if (sci->IsUnicodeMode())
return text.toUtf8();
return text.toLatin1();
}
// Decode bytes as a QString.
QString QsciScintillaBase::bytesAsText(const char *bytes) const
{
if (sci->IsUnicodeMode())
return QString::fromUtf8(bytes);
return QString::fromLatin1(bytes);
}
// Handle a mouse button double click.
void QsciScintillaBase::mouseDoubleClickEvent(QMouseEvent *e)
{
if (e->button() != Qt::LeftButton)
{
e->ignore();
return;
}
setFocus();
// Make sure Scintilla will interpret this as a double-click.
unsigned clickTime = sci->lastClickTime + QSCI_SCI_NAMESPACE(Platform)::DoubleClickTime() - 1;
bool shift = e->modifiers() & Qt::ShiftModifier;
bool ctrl = e->modifiers() & Qt::ControlModifier;
bool alt = e->modifiers() & Qt::AltModifier;
sci->ButtonDown(QSCI_SCI_NAMESPACE(Point)(e->x(), e->y()), clickTime,
shift, ctrl, alt);
// Remember the current position and time in case it turns into a triple
// click.
triple_click_at = e->globalPos();
triple_click.start(QApplication::doubleClickInterval());
}
// Handle a mouse move.
void QsciScintillaBase::mouseMoveEvent(QMouseEvent *e)
{
sci->ButtonMove(QSCI_SCI_NAMESPACE(Point)(e->x(), e->y()));
}
// Handle a mouse button press.
void QsciScintillaBase::mousePressEvent(QMouseEvent *e)
{
setFocus();
QSCI_SCI_NAMESPACE(Point) pt(e->x(), e->y());
if (e->button() == Qt::LeftButton)
{
unsigned clickTime;
// It is a triple click if the timer is running and the mouse hasn't
// moved too much.
if (triple_click.isActive() && (e->globalPos() - triple_click_at).manhattanLength() < QApplication::startDragDistance())
clickTime = sci->lastClickTime + QSCI_SCI_NAMESPACE(Platform)::DoubleClickTime() - 1;
else
clickTime = sci->lastClickTime + QSCI_SCI_NAMESPACE(Platform)::DoubleClickTime() + 1;
triple_click.stop();
// Scintilla uses the Alt modifier to initiate rectangular selection.
// However the GTK port (under X11, not Windows) uses the Control
// modifier (by default, although it is configurable). It does this
// because most X11 window managers hijack Alt-drag to move the window.
// We do the same, except that (for the moment at least) we don't allow
// the modifier to be configured.
bool shift = e->modifiers() & Qt::ShiftModifier;
bool ctrl = e->modifiers() & Qt::ControlModifier;
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
bool alt = e->modifiers() & Qt::AltModifier;
#else
bool alt = ctrl;
#endif
sci->ButtonDown(pt, clickTime, shift, ctrl, alt);
}
else if (e->button() == Qt::MidButton)
{
QClipboard *cb = QApplication::clipboard();
if (cb->supportsSelection())
{
int pos = sci->PositionFromLocation(pt);
sci->sel.Clear();
sci->SetSelection(pos, pos);
sci->pasteFromClipboard(QClipboard::Selection);
}
}
}
// Handle a mouse button releases.
void QsciScintillaBase::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() != Qt::LeftButton)
return;
QSCI_SCI_NAMESPACE(Point) pt(e->x(), e->y());
if (sci->HaveMouseCapture())
{
bool ctrl = e->modifiers() & Qt::ControlModifier;
sci->ButtonUp(pt, 0, ctrl);
}
#if QT_VERSION >= 0x050000
if (!sci->pdoc->IsReadOnly() && !sci->PointInSelMargin(pt) && qApp->autoSipEnabled())
{
QStyle::RequestSoftwareInputPanel rsip = QStyle::RequestSoftwareInputPanel(style()->styleHint(QStyle::SH_RequestSoftwareInputPanel));
if (!clickCausedFocus || rsip == QStyle::RSIP_OnMouseClick)
qApp->inputMethod()->show();
}
clickCausedFocus = false;
#endif
}
// Handle paint events.
void QsciScintillaBase::paintEvent(QPaintEvent *e)
{
sci->paintEvent(e);
}
// Handle resize events.
void QsciScintillaBase::resizeEvent(QResizeEvent *)
{
sci->ChangeSize();
}
// Re-implemented to suppress the default behaviour as Scintilla works at a
// more fundamental level.
void QsciScintillaBase::scrollContentsBy(int, int)
{
}
// Handle the vertical scrollbar.
void QsciScintillaBase::handleVSb(int value)
{
sci->ScrollTo(value);
}
// Handle the horizontal scrollbar.
void QsciScintillaBase::handleHSb(int value)
{
sci->HorizontalScrollTo(value);
}
// Handle drag enters.
void QsciScintillaBase::dragEnterEvent(QDragEnterEvent *e)
{
QsciScintillaBase::dragMoveEvent(e);
}
// Handle drag leaves.
void QsciScintillaBase::dragLeaveEvent(QDragLeaveEvent *)
{
sci->SetDragPosition(QSCI_SCI_NAMESPACE(SelectionPosition)());
}
// Handle drag moves.
void QsciScintillaBase::dragMoveEvent(QDragMoveEvent *e)
{
sci->SetDragPosition(
sci->SPositionFromLocation(
QSCI_SCI_NAMESPACE(Point)(e->pos().x(), e->pos().y()),
false, false, sci->UserVirtualSpace()));
acceptAction(e);
}
// Handle drops.
void QsciScintillaBase::dropEvent(QDropEvent *e)
{
bool moving;
int len;
const char *s;
bool rectangular;
acceptAction(e);
if (!e->isAccepted())
return;
moving = (e->dropAction() == Qt::MoveAction);
QByteArray text = fromMimeData(e->mimeData(), rectangular);
len = text.length();
s = text.data();
std::string dest = QSCI_SCI_NAMESPACE(Document)::TransformLineEnds(s, len,
sci->pdoc->eolMode);
sci->DropAt(sci->posDrop, dest.c_str(), dest.length(), moving,
rectangular);
sci->Redraw();
}
void QsciScintillaBase::acceptAction(QDropEvent *e)
{
if (sci->pdoc->IsReadOnly() || !canInsertFromMimeData(e->mimeData()))
e->ignore();
else
e->acceptProposedAction();
}
// See if a MIME data object can be decoded.
bool QsciScintillaBase::canInsertFromMimeData(const QMimeData *source) const
{
return source->hasFormat(mimeTextPlain);
}
// Create text from a MIME data object.
QByteArray QsciScintillaBase::fromMimeData(const QMimeData *source, bool &rectangular) const
{
// See if it is rectangular. We try all of the different formats that
// Scintilla supports in case we are working across different platforms.
if (source->hasFormat(mimeRectangularWin))
rectangular = true;
else if (source->hasFormat(mimeRectangular))
rectangular = true;
else
rectangular = false;
// Note that we don't support Scintilla's hack of adding a '\0' as Qt
// strips it off under the covers when pasting from another process.
QString utf8 = source->text();
QByteArray text;
if (sci->IsUnicodeMode())
text = utf8.toUtf8();
else
text = utf8.toLatin1();
return text;
}
// Create a MIME data object for some text.
QMimeData *QsciScintillaBase::toMimeData(const QByteArray &text, bool rectangular) const
{
QMimeData *mime = new QMimeData;
QString utf8;
if (sci->IsUnicodeMode())
utf8 = QString::fromUtf8(text.constData(), text.size());
else
utf8 = QString::fromLatin1(text.constData(), text.size());
mime->setText(utf8);
if (rectangular)
{
// Use the platform specific "standard" for specifying a rectangular
// selection.
#if defined(Q_OS_WIN)
mime->setData(mimeRectangularWin, QByteArray());
#else
mime->setData(mimeRectangular, QByteArray());
#endif
}
return mime;
}
|