Debian Codegraph @

scintilla/qt/ScintillaEdit/ScintillaEdit.cpp.template

raw
1 // @file ScintillaEdit.cpp
2 // Extended version of ScintillaEditBase with a method for each API
3 // Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware
4
5 #include "ScintillaEdit.h"
6
7 using namespace Scintilla;
8
9 ScintillaEdit::ScintillaEdit(QWidget *parent) : ScintillaEditBase(parent) {
10 }
11
12 ScintillaEdit::~ScintillaEdit() {
13 }
14
15 QByteArray ScintillaEdit::TextReturner(int message, uptr_t wParam) const {
16 // While Scintilla can return strings longer than maximum(int), QByteArray uses int size
17 const int length = static_cast<int>(send(message, wParam, 0));
18 QByteArray ba(length + 1, '\0');
19 send(message, wParam, (sptr_t)ba.data());
20 // Remove extra NULs
21 if (ba.at(ba.size()-1) == 0)
22 ba.chop(1);
23 return ba;
24 }
25
26 QPair<int, int>ScintillaEdit::find_text(int flags, const char *text, int cpMin, int cpMax) {
27 struct Sci_TextToFind ft = {{0, 0}, 0, {0, 0}};
28 ft.chrg.cpMin = cpMin;
29 ft.chrg.cpMax = cpMax;
30 ft.chrgText.cpMin = cpMin;
31 ft.chrgText.cpMax = cpMax;
32 ft.lpstrText = text;
33
34 int start = send(SCI_FINDTEXT, flags, (uptr_t) (&ft));
35
36 return QPair<int,int>(start, ft.chrgText.cpMax);
37 }
38
39 QByteArray ScintillaEdit::get_text_range(int start, int end) {
40 if (start > end)
41 start = end;
42
43 int length = end-start;
44 QByteArray ba(length+1, '\0');
45 struct Sci_TextRange tr = {{start, end}, ba.data()};
46
47 send(SCI_GETTEXTRANGE, 0, (sptr_t)&tr);
48 ba.chop(1); // Remove extra NUL
49
50 return ba;
51 }
52
53 ScintillaDocument *ScintillaEdit::get_doc() {
54 return new ScintillaDocument(0, (void *)send(SCI_GETDOCPOINTER, 0, 0));
55 }
56
57 void ScintillaEdit::set_doc(ScintillaDocument *pdoc_) {
58 send(SCI_SETDOCPOINTER, 0, (sptr_t)(pdoc_->pointer()));
59 }
60
61 long ScintillaEdit::format_range(bool draw, QPaintDevice* target, QPaintDevice* measure,
62 const QRect& print_rect, const QRect& page_rect,
63 long range_start, long range_end)
64 {
65 Sci_RangeToFormat to_format;
66
67 to_format.hdc = target;
68 to_format.hdcTarget = measure;
69
70 to_format.rc.left = print_rect.left();
71 to_format.rc.top = print_rect.top();
72 to_format.rc.right = print_rect.right();
73 to_format.rc.bottom = print_rect.bottom();
74
75 to_format.rcPage.left = page_rect.left();
76 to_format.rcPage.top = page_rect.top();
77 to_format.rcPage.right = page_rect.right();
78 to_format.rcPage.bottom = page_rect.bottom();
79
80 to_format.chrg.cpMin = range_start;
81 to_format.chrg.cpMax = range_end;
82
83 return send(SCI_FORMATRANGE, draw, reinterpret_cast<sptr_t>(&to_format));
84 }
85
86 /* ++Autogenerated -- start of section automatically generated from Scintilla.iface */
87 /* --Autogenerated -- end of section automatically generated from Scintilla.iface */