qscilexercustom.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // This module implements the QsciLexerCustom class.
  2. //
  3. // Copyright (c) 2017 Riverbank Computing Limited <info@riverbankcomputing.com>
  4. //
  5. // This file is part of QScintilla.
  6. //
  7. // This file may be used under the terms of the GNU General Public License
  8. // version 3.0 as published by the Free Software Foundation and appearing in
  9. // the file LICENSE included in the packaging of this file. Please review the
  10. // following information to ensure the GNU General Public License version 3.0
  11. // requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  12. //
  13. // If you do not wish to use this file under the terms of the GPL version 3.0
  14. // then you may purchase a commercial license. For more information contact
  15. // info@riverbankcomputing.com.
  16. //
  17. // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  18. // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19. #include "Qsci/qscilexercustom.h"
  20. #include "Qsci/qsciscintilla.h"
  21. #include "Qsci/qsciscintillabase.h"
  22. #include "Qsci/qscistyle.h"
  23. // The ctor.
  24. QsciLexerCustom::QsciLexerCustom(QObject *parent)
  25. : QsciLexer(parent)
  26. {
  27. }
  28. // The dtor.
  29. QsciLexerCustom::~QsciLexerCustom()
  30. {
  31. }
  32. // Start styling.
  33. void QsciLexerCustom::startStyling(int start, int)
  34. {
  35. if (!editor())
  36. return;
  37. editor()->SendScintilla(QsciScintillaBase::SCI_STARTSTYLING, start);
  38. }
  39. // Set the style for a number of characters.
  40. void QsciLexerCustom::setStyling(int length, int style)
  41. {
  42. if (!editor())
  43. return;
  44. editor()->SendScintilla(QsciScintillaBase::SCI_SETSTYLING, length, style);
  45. }
  46. // Set the style for a number of characters.
  47. void QsciLexerCustom::setStyling(int length, const QsciStyle &style)
  48. {
  49. setStyling(length, style.style());
  50. }
  51. // Set the attached editor.
  52. void QsciLexerCustom::setEditor(QsciScintilla *new_editor)
  53. {
  54. if (editor())
  55. disconnect(editor(), SIGNAL(SCN_STYLENEEDED(int)), this,
  56. SLOT(handleStyleNeeded(int)));
  57. QsciLexer::setEditor(new_editor);
  58. if (editor())
  59. connect(editor(), SIGNAL(SCN_STYLENEEDED(int)), this,
  60. SLOT(handleStyleNeeded(int)));
  61. }
  62. // Return the number of style bits needed by the lexer.
  63. int QsciLexerCustom::styleBitsNeeded() const
  64. {
  65. return 5;
  66. }
  67. // Handle a request to style some text.
  68. void QsciLexerCustom::handleStyleNeeded(int pos)
  69. {
  70. int start = editor()->SendScintilla(QsciScintillaBase::SCI_GETENDSTYLED);
  71. int line = editor()->SendScintilla(QsciScintillaBase::SCI_LINEFROMPOSITION,
  72. start);
  73. start = editor()->SendScintilla(QsciScintillaBase::SCI_POSITIONFROMLINE,
  74. line);
  75. if (start != pos)
  76. styleText(start, pos);
  77. }