From bf8b35542c4be4b8eebb71ca2ad518da2e12b850 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Thu, 17 May 2012 12:46:29 +1000 Subject: Qt platform layer added. Based on an implementation from Jason Haslam at Scientific Toolworks, Inc. with additions performed for Wingware. --- qt/README | 36 + qt/ScintillaEdit/ScintillaDocument.cpp | 286 +++++ qt/ScintillaEdit/ScintillaDocument.h | 97 ++ qt/ScintillaEdit/ScintillaEdit.cpp.template | 59 + qt/ScintillaEdit/ScintillaEdit.h.template | 63 + qt/ScintillaEdit/ScintillaEdit.pro | 72 ++ qt/ScintillaEdit/WidgetGen.py | 275 +++++ qt/ScintillaEditBase/Notes.txt | 18 + qt/ScintillaEditBase/PlatQt.cpp | 1282 ++++++++++++++++++++ qt/ScintillaEditBase/PlatQt.h | 127 ++ qt/ScintillaEditBase/ScintillaEditBase.cpp | 635 ++++++++++ qt/ScintillaEditBase/ScintillaEditBase.h | 151 +++ qt/ScintillaEditBase/ScintillaEditBase.pro | 111 ++ qt/ScintillaEditBase/ScintillaQt.cpp | 772 ++++++++++++ qt/ScintillaEditBase/ScintillaQt.h | 158 +++ qt/ScintillaEditPy/README | 85 ++ qt/ScintillaEditPy/ScintillaConstants.py.template | 6 + qt/ScintillaEditPy/ScintillaEditPy.pro | 116 ++ qt/ScintillaEditPy/global.h | 4 + qt/ScintillaEditPy/sepbuild.py | 312 +++++ qt/ScintillaEditPy/testsepq.py | 157 +++ .../typesystem_ScintillaEdit.xml.template | 16 + 22 files changed, 4838 insertions(+) create mode 100644 qt/README create mode 100644 qt/ScintillaEdit/ScintillaDocument.cpp create mode 100644 qt/ScintillaEdit/ScintillaDocument.h create mode 100644 qt/ScintillaEdit/ScintillaEdit.cpp.template create mode 100644 qt/ScintillaEdit/ScintillaEdit.h.template create mode 100644 qt/ScintillaEdit/ScintillaEdit.pro create mode 100644 qt/ScintillaEdit/WidgetGen.py create mode 100644 qt/ScintillaEditBase/Notes.txt create mode 100644 qt/ScintillaEditBase/PlatQt.cpp create mode 100644 qt/ScintillaEditBase/PlatQt.h create mode 100644 qt/ScintillaEditBase/ScintillaEditBase.cpp create mode 100644 qt/ScintillaEditBase/ScintillaEditBase.h create mode 100644 qt/ScintillaEditBase/ScintillaEditBase.pro create mode 100644 qt/ScintillaEditBase/ScintillaQt.cpp create mode 100644 qt/ScintillaEditBase/ScintillaQt.h create mode 100644 qt/ScintillaEditPy/README create mode 100644 qt/ScintillaEditPy/ScintillaConstants.py.template create mode 100644 qt/ScintillaEditPy/ScintillaEditPy.pro create mode 100644 qt/ScintillaEditPy/global.h create mode 100644 qt/ScintillaEditPy/sepbuild.py create mode 100644 qt/ScintillaEditPy/testsepq.py create mode 100644 qt/ScintillaEditPy/typesystem_ScintillaEdit.xml.template diff --git a/qt/README b/qt/README new file mode 100644 index 000000000..a39008b38 --- /dev/null +++ b/qt/README @@ -0,0 +1,36 @@ +README for building of Scintilla on Qt + +There are three different Scintilla libraries that can be produced: + + ScintillaEditBase +A basic widget callable from C++ which is small and can be used just as is +or with higher level functionality added. + + ScintillaEdit +A more complete C++ widget with a method for every Scintilla API and a +secondary API allowing direct access to document objects. + + ScintillaEditPy +A Python callable version of ScintillaEdit using the PySide bindings. + + Building a library + +ScintillaEditBase can be built without performing any generation steps. +The ScintillaEditBase/ScintillaEditBase.pro project can be loaded into +Qt Creator and the "Build All" command performed. +Alternatively, run "qmake" to build make files and then use the platform +make to build. Most commonly, use "make" on Unix and "nmake" +on Windows. + +ScintillaEdit requires a generation command be run first. From the +ScintillaEdit directory: + +python WidgetGen.py + +After the generation command has run, the ScintillaEdit.h and +ScintillaEdit.cpp files will have been populated with the Scintilla API +methods. +To build, use Qt Creator or qmake and make as for ScintillaEditBase. + +ScintillaEditPy is more complex and instructions are found in +ScintillaEditPy/README. 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 +#include + +#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(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 + +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; +} + +QPairScintillaEdit::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(text); + + send(SCI_FINDTEXT, flags, (uptr_t) (&ft)); + + return QPair(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 + +#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; + + QPairfind_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 + QPairfindText(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 " + + + + -- cgit v1.2.3