diff options
Diffstat (limited to 'qt/ScintillaEdit')
-rw-r--r-- | qt/ScintillaEdit/ScintillaDocument.cpp | 286 | ||||
-rw-r--r-- | qt/ScintillaEdit/ScintillaDocument.h | 97 | ||||
-rw-r--r-- | qt/ScintillaEdit/ScintillaEdit.cpp.template | 59 | ||||
-rw-r--r-- | qt/ScintillaEdit/ScintillaEdit.h.template | 63 | ||||
-rw-r--r-- | qt/ScintillaEdit/ScintillaEdit.pro | 72 | ||||
-rw-r--r-- | qt/ScintillaEdit/WidgetGen.py | 275 |
6 files changed, 852 insertions, 0 deletions
diff --git a/qt/ScintillaEdit/ScintillaDocument.cpp b/qt/ScintillaEdit/ScintillaDocument.cpp new file mode 100644 index 000000000..801f6a385 --- /dev/null +++ b/qt/ScintillaEdit/ScintillaDocument.cpp @@ -0,0 +1,286 @@ +// ScintillaDocument.cpp +// Wrapper for Scintilla document object so it can be manipulated independently. +// Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware + +#include <vector> +#include <map> + +#include "ScintillaDocument.h" + +#include "Platform.h" + +#include "ILexer.h" +#include "Scintilla.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 "Document.h" + +class WatcherHelper : public DocWatcher { + ScintillaDocument *owner; +public: + 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); + ((Document *)pdoc)->AddRef(); + ((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 ((Document *)pdoc)->LineFromPosition(pos); +} + +bool ScintillaDocument::is_cr_lf(int pos) { + return ((Document *)pdoc)->IsCrLf(pos); +} + +bool ScintillaDocument::delete_chars(int pos, int len) { + return ((Document *)pdoc)->DeleteChars(pos, len); +} + +int ScintillaDocument::undo() { + return ((Document *)pdoc)->Undo(); +} + +int ScintillaDocument::redo() { + return ((Document *)pdoc)->Redo(); +} + +bool ScintillaDocument::can_undo() { + return ((Document *)pdoc)->CanUndo(); +} + +bool ScintillaDocument::can_redo() { + return ((Document *)pdoc)->CanRedo(); +} + +void ScintillaDocument::delete_undo_history() { + ((Document *)pdoc)->DeleteUndoHistory(); +} + +bool ScintillaDocument::set_undo_collection(bool collect_undo) { + return ((Document *)pdoc)->SetUndoCollection(collect_undo); +} + +bool ScintillaDocument::is_collecting_undo() { + return ((Document *)pdoc)->IsCollectingUndo(); +} + +void ScintillaDocument::begin_undo_action() { + ((Document *)pdoc)->BeginUndoAction(); +} + +void ScintillaDocument::end_undo_action() { + ((Document *)pdoc)->EndUndoAction(); +} + +void ScintillaDocument::set_save_point() { + ((Document *)pdoc)->SetSavePoint(); +} + +bool ScintillaDocument::is_save_point() { + return ((Document *)pdoc)->IsSavePoint(); +} + +void ScintillaDocument::set_read_only(bool read_only) { + ((Document *)pdoc)->SetReadOnly(read_only); +} + +bool ScintillaDocument::is_read_only() { + return ((Document *)pdoc)->IsReadOnly(); +} + +void ScintillaDocument::insert_string(int position, QByteArray &str) { + ((Document *)pdoc)->InsertString(position, str.data(), str.size()); +} + +QByteArray ScintillaDocument::get_char_range(int position, int length) { + Document *doc = (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 ((Document *)pdoc)->StyleAt(position); +} + +int ScintillaDocument::line_start(int lineno) { + return ((Document *)pdoc)->LineStart(lineno); +} + +int ScintillaDocument::line_end(int lineno) { + return ((Document *)pdoc)->LineEnd(lineno); +} + +int ScintillaDocument::line_end_position(int pos) { + return ((Document *)pdoc)->LineEndPosition(pos); +} + +int ScintillaDocument::length() { + return ((Document *)pdoc)->Length(); +} + +int ScintillaDocument::lines_total() { + return ((Document *)pdoc)->LinesTotal(); +} + +void ScintillaDocument::start_styling(int position, char flags) { + ((Document *)pdoc)->StartStyling(position, flags); +} + +bool ScintillaDocument::set_style_for(int length, char style) { + return ((Document *)pdoc)->SetStyleFor(length, style); +} + +int ScintillaDocument::get_end_styled() { + return ((Document *)pdoc)->GetEndStyled(); +} + +void ScintillaDocument::ensure_styled_to(int position) { + ((Document *)pdoc)->EnsureStyledTo(position); +} + +void ScintillaDocument::set_current_indicator(int indic) { + ((Document *)pdoc)->decorations.SetCurrentIndicator(indic); +} + +void ScintillaDocument::decoration_fill_range(int position, int value, int fillLength) { + ((Document *)pdoc)->DecorationFillRange(position, value, fillLength); +} + +int ScintillaDocument::decorations_value_at(int indic, int position) { + return ((Document *)pdoc)->decorations.ValueAt(indic, position); +} + +int ScintillaDocument::decorations_start(int indic, int position) { + return ((Document *)pdoc)->decorations.Start(indic, position); +} + +int ScintillaDocument::decorations_end(int indic, int position) { + return ((Document *)pdoc)->decorations.End(indic, position); +} + +int ScintillaDocument::get_code_page() { + return ((Document *)pdoc)->CodePage(); +} + +void ScintillaDocument::set_code_page(int code_page) { + ((Document *)pdoc)->dbcsCodePage = code_page; +} + +int ScintillaDocument::move_position_outside_char(int pos, int move_dir, bool check_line_end) { + return ((Document *)pdoc)->MovePositionOutsideChar(pos, move_dir, check_line_end); +} + +// 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); +} + diff --git a/qt/ScintillaEdit/ScintillaDocument.h b/qt/ScintillaEdit/ScintillaDocument.h new file mode 100644 index 000000000..3cf16e334 --- /dev/null +++ b/qt/ScintillaEdit/ScintillaDocument.h @@ -0,0 +1,97 @@ +// ScintillaDocument.h +// Wrapper for Scintilla document object so it can be manipulated independently. +// Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware + +#ifndef SCINTILLADOCUMENT_H +#define SCINTILLADOCUMENT_H + +#include <QObject> + +class WatcherHelper; + +#ifndef EXPORT_IMPORT_API +#ifdef WIN32 +#ifdef MAKING_LIBRARY +#define EXPORT_IMPORT_API __declspec(dllexport) +#else +// Defining dllimport upsets moc +#define EXPORT_IMPORT_API __declspec(dllimport) +//#define EXPORT_IMPORT_API +#endif +#else +#define EXPORT_IMPORT_API +#endif +#endif + +class EXPORT_IMPORT_API ScintillaDocument : public QObject +{ + Q_OBJECT + + void *pdoc; + WatcherHelper *docWatcher; + +public: + explicit ScintillaDocument(QObject *parent = 0, void *pdoc_=0); + virtual ~ScintillaDocument(); + void *pointer(); + + int line_from_position(int pos); + bool is_cr_lf(int pos); + bool delete_chars(int pos, int len); + int undo(); + int redo(); + bool can_undo(); + bool can_redo(); + void delete_undo_history(); + bool set_undo_collection(bool collect_undo); + bool is_collecting_undo(); + void begin_undo_action(); + void end_undo_action(); + void set_save_point(); + bool is_save_point(); + void set_read_only(bool read_only); + bool is_read_only(); + void insert_string(int position, QByteArray &str); + QByteArray get_char_range(int position, int length); + char style_at(int position); + int line_start(int lineno); + int line_end(int lineno); + int line_end_position(int pos); + int length(); + int lines_total(); + void start_styling(int position, char flags); + bool set_style_for(int length, char style); + int get_end_styled(); + void ensure_styled_to(int position); + void set_current_indicator(int indic); + void decoration_fill_range(int position, int value, int fillLength); + int decorations_value_at(int indic, int position); + int decorations_start(int indic, int position); + int decorations_end(int indic, int position); + int get_code_page(); + void set_code_page(int code_page); + int move_position_outside_char(int pos, int move_dir, bool check_line_end); + +private: + void emit_modify_attempt(); + void emit_save_point(bool atSavePoint); + void emit_modified(int position, int modification_type, const QByteArray& text, int length, + int linesAdded, int line, int foldLevelNow, int foldLevelPrev); + void emit_style_needed(int pos); + void emit_lexer_changed(); + void emit_error_occurred(int status); + +signals: + void modify_attempt(); + void save_point(bool atSavePoint); + void modified(int position, int modification_type, const QByteArray& text, int length, + int linesAdded, int line, int foldLevelNow, int foldLevelPrev); + void style_needed(int pos); + void lexer_changed(); + void error_occurred(int status); + + friend class WatcherHelper; + +}; + +#endif // SCINTILLADOCUMENT_H diff --git a/qt/ScintillaEdit/ScintillaEdit.cpp.template b/qt/ScintillaEdit/ScintillaEdit.cpp.template new file mode 100644 index 000000000..431e79c4e --- /dev/null +++ b/qt/ScintillaEdit/ScintillaEdit.cpp.template @@ -0,0 +1,59 @@ +// ScintillaEdit.cpp +// Extended version of ScintillaEditBase with a method for each API +// Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware + +#include "ScintillaEdit.h" + +ScintillaEdit::ScintillaEdit(QWidget *parent) : ScintillaEditBase(parent) { +} + +ScintillaEdit::~ScintillaEdit() { +} + +QByteArray ScintillaEdit::TextReturner(int message, uptr_t wParam) const { + int length = send(message, wParam, 0); + QByteArray ba(length, '\0'); + send(message, wParam, (sptr_t)ba.data()); + // Remove extra NULs + if (ba.size() > 0 && ba.at(ba.size()-1) == 0) + ba.chop(1); + return ba; +} + +QPair<int, int>ScintillaEdit::find_text(int flags, const char *text, int cpMin, int cpMax) { + struct TextToFind ft = {{0, 0}, 0, {0, 0}}; + ft.chrg.cpMin = cpMin; + ft.chrg.cpMax = cpMax; + ft.chrgText.cpMin = cpMin; + ft.chrgText.cpMax = cpMax; + ft.lpstrText = const_cast<char *>(text); + + send(SCI_FINDTEXT, flags, (uptr_t) (&ft)); + + return QPair<int,int>(ft.chrgText.cpMin, ft.chrgText.cpMax); +} + +QByteArray ScintillaEdit::get_text_range(int start, int end) { + if (start > end) + start = end; + + int length = end-start; + QByteArray ba(length+1, '\0'); + struct TextRange tr = {{start, end}, ba.data()}; + + length = send(SCI_GETTEXTRANGE, 0, (sptr_t)&tr); + ba.chop(1); // Remove extra NUL + + return ba; +} + +ScintillaDocument *ScintillaEdit::get_doc() { + return new ScintillaDocument(0, (void *)send(SCI_GETDOCPOINTER, 0, 0)); +} + +void ScintillaEdit::set_doc(ScintillaDocument *pdoc_) { + send(SCI_SETDOCPOINTER, 0, (sptr_t)(pdoc_->pointer())); +} + +/* ++Autogenerated -- start of section automatically generated from Scintilla.iface */ +/* --Autogenerated -- end of section automatically generated from Scintilla.iface */ diff --git a/qt/ScintillaEdit/ScintillaEdit.h.template b/qt/ScintillaEdit/ScintillaEdit.h.template new file mode 100644 index 000000000..32c8a7726 --- /dev/null +++ b/qt/ScintillaEdit/ScintillaEdit.h.template @@ -0,0 +1,63 @@ +// ScintillaEdit.h +// Extended version of ScintillaEditBase with a method for each API +// Copyright (c) 2011 Archaeopteryx Software, Inc. d/b/a Wingware + +#ifndef SCINTILLAEDIT_H +#define SCINTILLAEDIT_H + +#include <QPair> + +#include "ScintillaEditBase.h" +#include "ScintillaDocument.h" + +#ifdef SCI_NAMESPACE +namespace Scintilla { +#endif + +#ifndef EXPORT_IMPORT_API +#ifdef WIN32 +#ifdef MAKING_LIBRARY +#define EXPORT_IMPORT_API __declspec(dllexport) +#else +// Defining dllimport upsets moc +#define EXPORT_IMPORT_API __declspec(dllimport) +//#define EXPORT_IMPORT_API +#endif +#else +#define EXPORT_IMPORT_API +#endif +#endif + +class EXPORT_IMPORT_API ScintillaEdit : public ScintillaEditBase { + Q_OBJECT + +public: + ScintillaEdit(QWidget *parent = 0); + virtual ~ScintillaEdit(); + + QByteArray TextReturner(int message, uptr_t wParam) const; + + QPair<int, int>find_text(int flags, const char *text, int cpMin, int cpMax); + QByteArray get_text_range(int start, int end); + ScintillaDocument *get_doc(); + void set_doc(ScintillaDocument *pdoc_); + + // Same as previous two methods but with Qt style names + QPair<int, int>findText(int flags, const char *text, int cpMin, int cpMax) { + return find_text(flags, text, cpMin, cpMax); + } + + QByteArray textRange(int start, int end) { + return get_text_range(start, end); + } + +/* ++Autogenerated -- start of section automatically generated from Scintilla.iface */ +/* --Autogenerated -- end of section automatically generated from Scintilla.iface */ + +}; + +#ifdef SCI_NAMESPACE +} +#endif + +#endif /* SCINTILLAEDIT_H */ diff --git a/qt/ScintillaEdit/ScintillaEdit.pro b/qt/ScintillaEdit/ScintillaEdit.pro new file mode 100644 index 000000000..d6422ac54 --- /dev/null +++ b/qt/ScintillaEdit/ScintillaEdit.pro @@ -0,0 +1,72 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-05-05T12:41:23 +# +#------------------------------------------------- + +QT += core gui + +TARGET = ScintillaEdit +TEMPLATE = lib +CONFIG += lib_bundle + +VERSION = 3.1.0 + +SOURCES += \ + ScintillaEdit.cpp \ + ScintillaDocument.cpp \ + ../ScintillaEditBase/PlatQt.cpp \ + ../ScintillaEditBase/ScintillaQt.cpp \ + ../ScintillaEditBase/ScintillaEditBase.cpp \ + ../../src/XPM.cxx \ + ../../src/ViewStyle.cxx \ + ../../src/UniConversion.cxx \ + ../../src/Style.cxx \ + ../../src/Selection.cxx \ + ../../src/ScintillaBase.cxx \ + ../../src/RunStyles.cxx \ + ../../src/RESearch.cxx \ + ../../src/PositionCache.cxx \ + ../../src/PerLine.cxx \ + ../../src/LineMarker.cxx \ + ../../src/KeyMap.cxx \ + ../../src/Indicator.cxx \ + ../../src/ExternalLexer.cxx \ + ../../src/Editor.cxx \ + ../../src/Document.cxx \ + ../../src/Decoration.cxx \ + ../../src/ContractionState.cxx \ + ../../src/CharClassify.cxx \ + ../../src/CellBuffer.cxx \ + ../../src/Catalogue.cxx \ + ../../src/CallTip.cxx \ + ../../src/AutoComplete.cxx \ + ../../lexlib/WordList.cxx \ + ../../lexlib/StyleContext.cxx \ + ../../lexlib/PropSetSimple.cxx \ + ../../lexlib/LexerSimple.cxx \ + ../../lexlib/LexerNoExceptions.cxx \ + ../../lexlib/LexerModule.cxx \ + ../../lexlib/LexerBase.cxx \ + ../../lexlib/CharacterSet.cxx \ + ../../lexlib/Accessor.cxx \ + ../../lexers/*.cxx + +HEADERS += \ + ScintillaEdit.h \ + ScintillaDocument.h \ + ../ScintillaEditBase/ScintillaEditBase.h \ + ../ScintillaEditBase/ScintillaQt.h + +OTHER_FILES += + +INCLUDEPATH += ../ScintillaEditBase ../../include ../../src ../../lexlib + +DEFINES += SCINTILLA_QT=1 MAKING_LIBRARY=1 SCI_LEXER=1 _CRT_SECURE_NO_DEPRECATE=1 + +DESTDIR = ../../bin +DLLDESTDIR = ../../bin + +macx { + QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../Frameworks/ +} diff --git a/qt/ScintillaEdit/WidgetGen.py b/qt/ScintillaEdit/WidgetGen.py new file mode 100644 index 000000000..8065b5f9d --- /dev/null +++ b/qt/ScintillaEdit/WidgetGen.py @@ -0,0 +1,275 @@ +#!/usr/bin/env python +# WidgetGen.py - regenerate the ScintillaWidgetCpp.cpp and ScintillaWidgetCpp.h files +# Check that API includes all gtkscintilla2 functions + +import sys +import os +import getopt + +scintillaDirectory = "../.." +scintillaIncludeDirectory = os.path.join(scintillaDirectory, "include") +sys.path.append(scintillaIncludeDirectory) +import Face + +def Contains(s,sub): + return s.find(sub) != -1 + +def underscoreName(s): + # Name conversion fixes to match gtkscintilla2 + irregular = ['WS', 'EOL', 'AutoC', 'KeyWords', 'BackSpace', 'UnIndents', 'RE', 'RGBA'] + for word in irregular: + replacement = word[0] + word[1:].lower() + s = s.replace(word, replacement) + + out = "" + for c in s: + if c.isupper(): + if out: + out += "_" + out += c.lower() + else: + out += c + return out + +def normalisedName(s, options, role=None): + if options["qtStyle"]: + if role == "get": + s = s.replace("Get", "") + return s[0].lower() + s[1:] + else: + return underscoreName(s) + +typeAliases = { + "position": "int", + "colour": "int", + "keymod": "int", + "string": "const char *", + "stringresult": "const char *", + "cells": "const char *", +} + +def cppAlias(s): + if s in typeAliases: + return typeAliases[s] + else: + return s + +understoodTypes = ["", "void", "int", "bool", "position", + "colour", "keymod", "string", "stringresult", "cells"] + +def checkTypes(name, v): + understandAllTypes = True + if v["ReturnType"] not in understoodTypes: + #~ print("Do not understand", v["ReturnType"], "for", name) + understandAllTypes = False + if v["Param1Type"] not in understoodTypes: + #~ print("Do not understand", v["Param1Type"], "for", name) + understandAllTypes = False + if v["Param2Type"] not in understoodTypes: + #~ print("Do not understand", v["Param2Type"], "for", name) + understandAllTypes = False + return understandAllTypes + +def arguments(v, stringResult, options): + ret = "" + p1Type = cppAlias(v["Param1Type"]) + if p1Type: + ret = ret + p1Type + " " + normalisedName(v["Param1Name"], options) + p2Type = cppAlias(v["Param2Type"]) + if p2Type and not stringResult: + if p1Type: + ret = ret + ", " + ret = ret + p2Type + " " + normalisedName(v["Param2Name"], options) + return ret + +def printPyFile(f,out, options): + for name in f.order: + v = f.features[name] + if v["Category"] != "Deprecated": + feat = v["FeatureType"] + if feat in ["val"]: + out.write(name + "=" + v["Value"] + "\n") + if feat in ["evt"]: + out.write("SCN_" + name.upper() + "=" + v["Value"] + "\n") + +def printHFile(f,out, options): + for name in f.order: + v = f.features[name] + if v["Category"] != "Deprecated": + feat = v["FeatureType"] + if feat in ["fun", "get", "set"]: + if checkTypes(name, v): + constDeclarator = " const" if feat == "get" else "" + returnType = cppAlias(v["ReturnType"]) + stringResult = v["Param2Type"] == "stringresult" + if stringResult: + returnType = "QByteArray" + out.write("\t" + returnType + " " + normalisedName(name, options, feat) + "(") + out.write(arguments(v, stringResult, options)) + out.write(")" + constDeclarator + ";\n") + +def methodNames(f, options): + for name in f.order: + v = f.features[name] + if v["Category"] != "Deprecated": + feat = v["FeatureType"] + if feat in ["fun", "get", "set"]: + if checkTypes(name, v): + yield normalisedName(name, options) + +def printCPPFile(f,out, options): + for name in f.order: + v = f.features[name] + if v["Category"] != "Deprecated": + feat = v["FeatureType"] + if feat in ["fun", "get", "set"]: + if checkTypes(name, v): + constDeclarator = " const" if feat == "get" else "" + featureDefineName = "SCI_" + name.upper() + returnType = cppAlias(v["ReturnType"]) + stringResult = v["Param2Type"] == "stringresult" + if stringResult: + returnType = "QByteArray" + returnStatement = "" + if returnType != "void": + returnStatement = "return " + out.write(returnType + " ScintillaEdit::" + normalisedName(name, options, feat) + "(") + out.write(arguments(v, stringResult, options)) + out.write(")" + constDeclarator + " {\n") + if stringResult: + out.write(" " + returnStatement + "TextReturner(" + featureDefineName + ", ") + if "*" in cppAlias(v["Param1Type"]): + out.write("(uptr_t)") + if v["Param1Name"]: + out.write(normalisedName(v["Param1Name"], options)) + else: + out.write("0") + out.write(");\n") + else: + out.write(" " + returnStatement + "send(" + featureDefineName + ", ") + if "*" in cppAlias(v["Param1Type"]): + out.write("(uptr_t)") + if v["Param1Name"]: + out.write(normalisedName(v["Param1Name"], options)) + else: + out.write("0") + out.write(", ") + if "*" in cppAlias(v["Param2Type"]): + out.write("(sptr_t)") + if v["Param2Name"]: + out.write(normalisedName(v["Param2Name"], options)) + else: + out.write("0") + out.write(");\n") + out.write("}\n") + out.write("\n") + +def CopyWithInsertion(input, output, genfn, definition, options): + copying = 1 + for line in input.readlines(): + if copying: + output.write(line) + if "/* ++Autogenerated" in line or "# ++Autogenerated" in line or "<!-- ++Autogenerated" in line: + copying = 0 + genfn(definition, output, options) + # ~~ form needed as XML comments can not contain -- + if "/* --Autogenerated" in line or "# --Autogenerated" in line or "<!-- ~~Autogenerated" in line: + copying = 1 + output.write(line) + +def contents(filename): + with open(filename, "U") as f: + t = f.read() + return t + +def Generate(templateFile, destinationFile, genfn, definition, options): + inText = contents(templateFile) + try: + currentText = contents(destinationFile) + except IOError: + currentText = "" + tempname = "WidgetGen.tmp" + with open(tempname, "w") as out: + with open(templateFile, "U") as hfile: + CopyWithInsertion(hfile, out, genfn, definition, options) + outText = contents(tempname) + if currentText == outText: + os.unlink(tempname) + else: + try: + os.unlink(destinationFile) + except OSError: + # Will see failure if file does not yet exist + pass + os.rename(tempname, destinationFile) + +def gtkNames(): + # The full path on my machine: should be altered for anyone else + p = "C:/Users/Neil/Downloads/wingide-source-4.0.1-1/wingide-source-4.0.1-1/external/gtkscintilla2/gtkscintilla.c" + with open(p) as f: + for l in f.readlines(): + if "gtk_scintilla_" in l: + name = l.split()[1][14:] + if '(' in name: + name = name.split('(')[0] + yield name + +def usage(): + print("WidgetGen.py [-c|--clean][-h|--help][-u|--underscore-names]") + print("") + print("Generate full APIs for ScintillaEdit class and ScintillaConstants.py.") + print("") + print("options:") + print("") + print("-c --clean remove all generated code from files") + print("-h --help display this text") + print("-u --underscore-names use method_names consistent with GTK+ standards") + +def readInterface(cleanGenerated): + f = Face.Face() + if not cleanGenerated: + f.ReadFromFile("../../include/Scintilla.iface") + return f + +def main(argv): + # Using local path for gtkscintilla2 so don't default to checking + checkGTK = False + cleanGenerated = False + qtStyleInterface = True + # The --gtk-check option checks for full coverage of the gtkscintilla2 API but + # depends on a particular directory so is not mentioned in --help. + opts, args = getopt.getopt(argv, "hcgu", ["help", "clean", "gtk-check", "underscore-names"]) + for opt, arg in opts: + if opt in ("-h", "--help"): + usage() + sys.exit() + elif opt in ("-c", "--clean"): + cleanGenerated = True + elif opt in ("-g", "--gtk-check"): + checkGTK = True + elif opt in ("-u", "--underscore-names"): + qtStyleInterface = False + + options = {"qtStyle": qtStyleInterface} + f = readInterface(cleanGenerated) + try: + Generate("ScintillaEdit.cpp.template", "ScintillaEdit.cpp", printCPPFile, f, options) + Generate("ScintillaEdit.h.template", "ScintillaEdit.h", printHFile, f, options) + Generate("../ScintillaEditPy/ScintillaConstants.py.template", + "../ScintillaEditPy/ScintillaConstants.py", + printPyFile, f, options) + if checkGTK: + names = set(methodNames(f)) + #~ print("\n".join(names)) + namesGtk = set(gtkNames()) + for name in namesGtk: + if name not in names: + print(name, "not found in Qt version") + for name in names: + if name not in namesGtk: + print(name, "not found in GTK+ version") + except: + raise + +if __name__ == "__main__": + main(sys.argv[1:]) |