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
|
// ScintillaDocument.cpp
// Wrapper for Scintilla document object so it can be manipulated independently.
// Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware
#include <stdexcept>
#include <vector>
#include <map>
#include "ScintillaDocument.h"
#include "Platform.h"
#include "ILexer.h"
#include "Scintilla.h"
#include "Position.h"
#include "SplitVector.h"
#include "Partitioning.h"
#include "RunStyles.h"
#include "ContractionState.h"
#include "CellBuffer.h"
#include "KeyMap.h"
#include "Indicator.h"
#include "XPM.h"
#include "LineMarker.h"
#include "Style.h"
#include "ViewStyle.h"
#include "CharClassify.h"
#include "Decoration.h"
#include "CaseFolder.h"
#include "Document.h"
#ifdef SCI_NAMESPACE
using namespace Scintilla;
#endif
class WatcherHelper : public DocWatcher {
ScintillaDocument *owner;
public:
explicit WatcherHelper(ScintillaDocument *owner_);
virtual ~WatcherHelper();
void NotifyModifyAttempt(Document *doc, void *userData);
void NotifySavePoint(Document *doc, void *userData, bool atSavePoint);
void NotifyModified(Document *doc, DocModification mh, void *userData);
void NotifyDeleted(Document *doc, void *userData);
void NotifyStyleNeeded(Document *doc, void *userData, int endPos);
void NotifyLexerChanged(Document *doc, void *userData);
void NotifyErrorOccurred(Document *doc, void *userData, int status);
};
WatcherHelper::WatcherHelper(ScintillaDocument *owner_) : owner(owner_) {
}
WatcherHelper::~WatcherHelper() {
}
void WatcherHelper::NotifyModifyAttempt(Document *, void *) {
owner->emit_modify_attempt();
}
void WatcherHelper::NotifySavePoint(Document *, void *, bool atSavePoint) {
owner->emit_save_point(atSavePoint);
}
void WatcherHelper::NotifyModified(Document *, DocModification mh, void *) {
int length = mh.length;
if (!mh.text)
length = 0;
QByteArray ba = QByteArray::fromRawData(mh.text, length);
owner->emit_modified(mh.position, mh.modificationType, ba, length,
mh.linesAdded, mh.line, mh.foldLevelNow, mh.foldLevelPrev);
}
void WatcherHelper::NotifyDeleted(Document *, void *) {
}
void WatcherHelper::NotifyStyleNeeded(Document *, void *, int endPos) {
owner->emit_style_needed(endPos);
}
void WatcherHelper::NotifyLexerChanged(Document *, void *) {
owner->emit_lexer_changed();
}
void WatcherHelper::NotifyErrorOccurred(Document *, void *, int status) {
owner->emit_error_occurred(status);
}
ScintillaDocument::ScintillaDocument(QObject *parent, void *pdoc_) :
QObject(parent), pdoc(pdoc_), docWatcher(0) {
if (!pdoc) {
pdoc = new Document();
}
docWatcher = new WatcherHelper(this);
(static_cast<Document *>(pdoc))->AddRef();
(static_cast<Document *>(pdoc))->AddWatcher(docWatcher, pdoc);
}
ScintillaDocument::~ScintillaDocument() {
Document *doc = static_cast<Document *>(pdoc);
if (doc) {
doc->RemoveWatcher(docWatcher, doc);
doc->Release();
}
pdoc = NULL;
delete docWatcher;
docWatcher = NULL;
}
void *ScintillaDocument::pointer() {
return pdoc;
}
int ScintillaDocument::line_from_position(int pos) {
return (static_cast<Document *>(pdoc))->LineFromPosition(pos);
}
bool ScintillaDocument::is_cr_lf(int pos) {
return (static_cast<Document *>(pdoc))->IsCrLf(pos);
}
bool ScintillaDocument::delete_chars(int pos, int len) {
return (static_cast<Document *>(pdoc))->DeleteChars(pos, len);
}
int ScintillaDocument::undo() {
return (static_cast<Document *>(pdoc))->Undo();
}
int ScintillaDocument::redo() {
return (static_cast<Document *>(pdoc))->Redo();
}
bool ScintillaDocument::can_undo() {
return (static_cast<Document *>(pdoc))->CanUndo();
}
bool ScintillaDocument::can_redo() {
return (static_cast<Document *>(pdoc))->CanRedo();
}
void ScintillaDocument::delete_undo_history() {
(static_cast<Document *>(pdoc))->DeleteUndoHistory();
}
bool ScintillaDocument::set_undo_collection(bool collect_undo) {
return (static_cast<Document *>(pdoc))->SetUndoCollection(collect_undo);
}
bool ScintillaDocument::is_collecting_undo() {
return (static_cast<Document *>(pdoc))->IsCollectingUndo();
}
void ScintillaDocument::begin_undo_action() {
(static_cast<Document *>(pdoc))->BeginUndoAction();
}
void ScintillaDocument::end_undo_action() {
(static_cast<Document *>(pdoc))->EndUndoAction();
}
void ScintillaDocument::set_save_point() {
(static_cast<Document *>(pdoc))->SetSavePoint();
}
bool ScintillaDocument::is_save_point() {
return (static_cast<Document *>(pdoc))->IsSavePoint();
}
void ScintillaDocument::set_read_only(bool read_only) {
(static_cast<Document *>(pdoc))->SetReadOnly(read_only);
}
bool ScintillaDocument::is_read_only() {
return (static_cast<Document *>(pdoc))->IsReadOnly();
}
void ScintillaDocument::insert_string(int position, QByteArray &str) {
(static_cast<Document *>(pdoc))->InsertString(position, str.data(), str.size());
}
QByteArray ScintillaDocument::get_char_range(int position, int length) {
Document *doc = static_cast<Document *>(pdoc);
if (position < 0 || length <= 0 || position + length > doc->Length())
return QByteArray();
QByteArray ba(length, '\0');
doc->GetCharRange(ba.data(), position, length);
return ba;
}
char ScintillaDocument::style_at(int position) {
return (static_cast<Document *>(pdoc))->StyleAt(position);
}
int ScintillaDocument::line_start(int lineno) {
return (static_cast<Document *>(pdoc))->LineStart(lineno);
}
int ScintillaDocument::line_end(int lineno) {
return (static_cast<Document *>(pdoc))->LineEnd(lineno);
}
int ScintillaDocument::line_end_position(int pos) {
return (static_cast<Document *>(pdoc))->LineEndPosition(pos);
}
int ScintillaDocument::length() {
return (static_cast<Document *>(pdoc))->Length();
}
int ScintillaDocument::lines_total() {
return (static_cast<Document *>(pdoc))->LinesTotal();
}
void ScintillaDocument::start_styling(int position, char flags) {
(static_cast<Document *>(pdoc))->StartStyling(position, flags);
}
bool ScintillaDocument::set_style_for(int length, char style) {
return (static_cast<Document *>(pdoc))->SetStyleFor(length, style);
}
int ScintillaDocument::get_end_styled() {
return (static_cast<Document *>(pdoc))->GetEndStyled();
}
void ScintillaDocument::ensure_styled_to(int position) {
(static_cast<Document *>(pdoc))->EnsureStyledTo(position);
}
void ScintillaDocument::set_current_indicator(int indic) {
(static_cast<Document *>(pdoc))->decorations.SetCurrentIndicator(indic);
}
void ScintillaDocument::decoration_fill_range(int position, int value, int fillLength) {
(static_cast<Document *>(pdoc))->DecorationFillRange(position, value, fillLength);
}
int ScintillaDocument::decorations_value_at(int indic, int position) {
return (static_cast<Document *>(pdoc))->decorations.ValueAt(indic, position);
}
int ScintillaDocument::decorations_start(int indic, int position) {
return (static_cast<Document *>(pdoc))->decorations.Start(indic, position);
}
int ScintillaDocument::decorations_end(int indic, int position) {
return (static_cast<Document *>(pdoc))->decorations.End(indic, position);
}
int ScintillaDocument::get_code_page() {
return (static_cast<Document *>(pdoc))->CodePage();
}
void ScintillaDocument::set_code_page(int code_page) {
(static_cast<Document *>(pdoc))->dbcsCodePage = code_page;
}
int ScintillaDocument::get_eol_mode() {
return (static_cast<Document *>(pdoc))->eolMode;
}
void ScintillaDocument::set_eol_mode(int eol_mode) {
(static_cast<Document *>(pdoc))->eolMode = eol_mode;
}
int ScintillaDocument::move_position_outside_char(int pos, int move_dir, bool check_line_end) {
return (static_cast<Document *>(pdoc))->MovePositionOutsideChar(pos, move_dir, check_line_end);
}
int ScintillaDocument::get_character(int pos) {
return (static_cast<Document *>(pdoc))->GetCharacterAndWidth(pos, NULL);
}
// Signal emitters
void ScintillaDocument::emit_modify_attempt() {
emit modify_attempt();
}
void ScintillaDocument::emit_save_point(bool atSavePoint) {
emit save_point(atSavePoint);
}
void ScintillaDocument::emit_modified(int position, int modification_type, const QByteArray& text, int length,
int linesAdded, int line, int foldLevelNow, int foldLevelPrev) {
emit modified(position, modification_type, text, length,
linesAdded, line, foldLevelNow, foldLevelPrev);
}
void ScintillaDocument::emit_style_needed(int pos) {
emit style_needed(pos);
}
void ScintillaDocument::emit_lexer_changed() {
emit lexer_changed();
}
void ScintillaDocument::emit_error_occurred(int status) {
emit error_occurred(status);
}
|