From f97d84a63b21fffcc830390e5bc3fe0eedb6e15b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 30 Oct 2000 21:57:12 +0000 Subject: [PATCH] Merged some STC fixes over to the main branch git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8660 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/stc/stc.h | 9 + contrib/src/stc/PlatWX.cpp | 91 ++++- contrib/src/stc/ScintillaWX.cpp | 5 + contrib/src/stc/gen_iface.py | 684 ++++++++++++++++++++++++++++++++ contrib/src/stc/stc.cpp | 17 +- contrib/src/stc/stc.cpp.in | 523 ++++++++++++++++++++++++ contrib/src/stc/stc.h.in | 297 ++++++++++++++ include/wx/stc/stc.h | 9 + src/stc/PlatWX.cpp | 91 ++++- src/stc/ScintillaWX.cpp | 5 + src/stc/gen_iface.py | 684 ++++++++++++++++++++++++++++++++ src/stc/stc.cpp | 17 +- src/stc/stc.cpp.in | 523 ++++++++++++++++++++++++ src/stc/stc.h.in | 297 ++++++++++++++ 14 files changed, 3246 insertions(+), 6 deletions(-) create mode 100644 contrib/src/stc/gen_iface.py create mode 100644 contrib/src/stc/stc.cpp.in create mode 100644 contrib/src/stc/stc.h.in create mode 100644 src/stc/gen_iface.py create mode 100644 src/stc/stc.cpp.in create mode 100644 src/stc/stc.h.in diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index f98e25d714..fc07f2f616 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -1232,6 +1232,14 @@ public: // Retrieve the point in the window where a position is displayed. wxPoint PointFromPosition(int pos); + + // Scroll enough to make the given line visible + void ScrollToLine(int line); + + + // Scroll enough to make the given column visible + void ScrollToColumn(int column); + //---------------------------------------------------------------------- @@ -1377,6 +1385,7 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_POSCHANGED(id, fn) { wxEVT_STC_POSCHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #endif diff --git a/contrib/src/stc/PlatWX.cpp b/contrib/src/stc/PlatWX.cpp index 63b363ec0e..e0eeab7d98 100644 --- a/contrib/src/stc/PlatWX.cpp +++ b/contrib/src/stc/PlatWX.cpp @@ -9,6 +9,11 @@ #include "Platform.h" #include "wx/stc/stc.h" + +#ifdef __WXGTK__ +#include +#endif + Point Point::FromLong(long lpoint) { return Point(lpoint & 0xFFFF, lpoint >> 16); } @@ -446,6 +451,76 @@ void Window::SetTitle(const char *s) { } +class wxSTCListBox : public wxListBox { +public: + wxSTCListBox(wxWindow* parent, wxWindowID id) + : wxListBox(parent, id, wxDefaultPosition, wxDefaultSize, + 0, NULL, wxLB_SINGLE | wxLB_SORT | wxSIMPLE_BORDER) + {} + + void OnFocus(wxFocusEvent& event) { + GetParent()->SetFocus(); + event.Skip(); + } + +#ifdef __WXGTK__ + void DoSetFirstItem(int n); +#endif + +private: + DECLARE_EVENT_TABLE() +}; + +BEGIN_EVENT_TABLE(wxSTCListBox, wxListBox) + EVT_SET_FOCUS(wxSTCListBox::OnFocus) +END_EVENT_TABLE() + + + + +#ifdef __WXGTK__ + // This can be removed after 2.2.2 I think +void wxSTCListBox::DoSetFirstItem( int n ) +{ + wxCHECK_RET( m_list, wxT("invalid listbox") ); + + if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_list)) + return; + + // terribly efficient + const gchar *vadjustment_key = "gtk-vadjustment"; + guint vadjustment_key_id = g_quark_from_static_string (vadjustment_key); + + GtkAdjustment *adjustment = + (GtkAdjustment*) gtk_object_get_data_by_id (GTK_OBJECT (m_list), vadjustment_key_id); + wxCHECK_RET( adjustment, wxT("invalid listbox code") ); + + GList *target = g_list_nth( m_list->children, n ); + wxCHECK_RET( target, wxT("invalid listbox index") ); + + GtkWidget *item = GTK_WIDGET(target->data); + wxCHECK_RET( item, wxT("invalid listbox code") ); + + // find the last item before this one which is already realized + size_t nItemsBefore; + for ( nItemsBefore = 0; item && (item->allocation.y == -1); nItemsBefore++ ) + { + target = target->prev; + if ( !target ) + { + // nothing we can do if there are no allocated items yet + return; + } + + item = GTK_WIDGET(target->data); + } + + gtk_adjustment_set_value(adjustment, + item->allocation.y + + nItemsBefore*item->allocation.height); +} +#endif + ListBox::ListBox() { } @@ -454,8 +529,9 @@ ListBox::~ListBox() { } void ListBox::Create(Window &parent, int ctrlID) { - id = new wxListBox(parent.id, ctrlID, wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_SINGLE | wxLB_SORT); + id = new wxSTCListBox(parent.id, ctrlID); +// id = new wxListBox(parent.id, ctrlID, wxDefaultPosition, wxDefaultSize, +// 0, NULL, wxLB_SINGLE | wxLB_SORT | wxSIMPLE_BORDER); } PRectangle ListBox::GetDesiredRect() { @@ -463,6 +539,10 @@ PRectangle ListBox::GetDesiredRect() { PRectangle rc; rc.top = 0; rc.left = 0; + if (sz.x > 150) // TODO: A better way to determine these max sizes + sz.x = 150; + if (sz.y > 100) + sz.y = 100; rc.right = sz.x; rc.bottom = sz.y; @@ -491,6 +571,13 @@ int ListBox::Length() { void ListBox::Select(int n) { ((wxListBox*)id)->SetSelection(n); +#ifdef __WXGTK__ + if (n > 4) + n = n - 4; + else + n = 1; + ((wxListBox*)id)->SetFirstItem(n); +#endif } int ListBox::GetSelection() { diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index 650921ee5a..f7349c8d27 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -315,6 +315,11 @@ void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) { FullPaint(); } paintState = notPainting; +#ifdef __WXGTK__ + // On wxGTK the editor window paints can overwrite the listbox... + if (ac.Active()) + ((wxWindow*)ac.lb.GetID())->Refresh(TRUE); +#endif } diff --git a/contrib/src/stc/gen_iface.py b/contrib/src/stc/gen_iface.py new file mode 100644 index 0000000000..b7dd756715 --- /dev/null +++ b/contrib/src/stc/gen_iface.py @@ -0,0 +1,684 @@ +#!/bin/env python +#---------------------------------------------------------------------------- +# Name: gen_iface.py +# Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface +# +# Author: Robin Dunn +# +# Created: 5-Sept-2000 +# RCS-ID: $Id$ +# Copyright: (c) 2000 by Total Control Software +# Licence: wxWindows license +#---------------------------------------------------------------------------- + + +import sys, string, re +from fileinput import FileInput + + +IFACE = './scintilla/include/Scintilla.iface' +H_TEMPLATE = './stc.h.in' +CPP_TEMPLATE = './stc.cpp.in' +H_DEST = '../../include/wx/stc/stc.h' # './stc_test.h' # +CPP_DEST = './stc.cpp' #'./stc_test.cpp' + + +# Value prefixes to convert +valPrefixes = [('SCI_', ''), + ('SC_', ''), + ('SCN_', None), # just toss these... + ('SCEN_', None), + ('SCE_', ''), + ('SCLEX_', 'LEX_'), + ('SCK_', 'KEY_'), + ('SCFIND_', 'FIND_'), + ('SCWS_', 'WS_'), +] + +# Message funcion values that should have a CMD_ constant as well +cmdValues = [ (2300, 2350), 2011, 2013, (2176, 2180) ] + + +# Map some generic typenames to wx types, using return value syntax +retTypeMap = { + 'position': 'int', + 'string': 'wxString', + 'colour': 'wxColour', + } + +# Map some generic typenames to wx types, using parameter syntax +paramTypeMap = { + 'position': 'int', + 'string': 'const wxString&', + 'colour': 'const wxColour&', + 'keymod': 'int', +} + +# Map of method info that needs tweaked. Either the name needs changed, or +# the method definition/implementation. Tuple items are: +# +# 1. New method name. None to skip the method, 0 to leave the +# default name. +# 2. Method definition for the .h file, 0 to leave alone +# 3. Method implementation for the .cpp file, 0 to leave alone. +# 4. tuple of Doc string lines, or 0 to leave alone. +# +methodOverrideMap = { + 'AddText' : (0, + 'void %s(const wxString& text);', + + '''void %s(const wxString& text) { + SendMsg(%s, text.Len(), (long)text.c_str());''', + 0), + + 'AddStyledText' : (0, + 'void %s(const wxString& text);', + + '''void %s(const wxString& text) { + SendMsg(%s, text.Len(), (long)text.c_str());''', + 0), + + 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0), + 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0), + + 'GetStyledText' : (0, + 'wxString %s(int startPos, int endPos);', + + '''wxString %s(int startPos, int endPos) { + wxString text; + int len = endPos - startPos; + TextRange tr; + tr.lpstrText = text.GetWriteBuf(len*2+1); + tr.chrg.cpMin = startPos; + tr.chrg.cpMax = endPos; + SendMsg(%s, 0, (long)&tr); + text.UngetWriteBuf(len*2); + return text;''', + + ('Retrieve a buffer of cells.',)), + + + 'PositionFromPoint' : (0, + 'int %s(wxPoint pt);', + + '''int %s(wxPoint pt) { + return SendMsg(%s, pt.x, pt.y);''', + + 0), + + 'GetCurLine' : (0, + 'wxString %s(int* OUTPUT=NULL);', + + '''wxString %s(int* linePos) { + wxString text; + int len = LineLength(GetCurrentLine()); + char* buf = text.GetWriteBuf(len+1); + + int pos = SendMsg(%s, len, (long)buf); + text.UngetWriteBuf(); + if (linePos) *linePos = pos; + + return text;''', + + 0), + + 'SetUsePalette' : (None, 0,0,0), + + 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0), + 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0), + + 'MarkerDefine' : (0, + '''void %s(int markerNumber, int markerSymbol, + const wxColour& foreground = wxNullColour, + const wxColour& background = wxNullColour);''', + + '''void %s(int markerNumber, int markerSymbol, + const wxColour& foreground, + const wxColour& background) { + + SendMsg(%s, markerNumber, markerSymbol); + if (foreground.Ok()) + MarkerSetForeground(markerNumber, foreground); + if (background.Ok()) + MarkerSetBackground(markerNumber, background);''', + + ('Set the symbol used for a particular marker number,', + 'and optionally the for and background colours.')), + + 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0), + 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0), + 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0), + 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0), + 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0), + 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0), + 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0), + 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0), + + 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0), + 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0), + 'SetSelFore' : ('SetSelForeground', 0, 0, 0), + 'SetSelBack' : ('SetSelBackground', 0, 0, 0), + 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0), + 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0), + + # need to fix this to map between wx and scintilla encoding flags, leave it out for now... + 'StyleSetCharacterSet' : (None, 0, 0, 0), + + 'AssignCmdKey' : ('CmdKeyAssign', + 'void %s(int key, int modifiers, int cmd);', + + '''void %s(int key, int modifiers, int cmd) { + SendMsg(%s, MAKELONG(key, modifiers), cmd);''', + + 0), + + 'ClearCmdKey' : ('CmdKeyClear', + 'void %s(int key, int modifiers);', + + '''void %s(int key, int modifiers) { + SendMsg(%s, MAKELONG(key, modifiers));''', + + 0), + + 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0), + + + 'SetStylingEx' : ('SetStyleBytes', + 'void %s(int length, char* styleBytes);', + + '''void %s(int length, char* styleBytes) { + SendMsg(%s, length, (long)styleBytes);''', + + 0), + + + 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0), + 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0), + 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0), + 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0), + + 'AutoCShow' : ('AutoCompShow', 0, 0, 0), + 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0), + 'AutoCActive' : ('AutoCompActive', 0, 0, 0), + 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0), + 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0), + 'AutoCStops' : ('AutoCompStops', 0, 0, 0), + 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0), + 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0), + 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0), + 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0), + 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0), + 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0), + 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0), + 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0), + 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0), + 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0), + + 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0), + 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0), + + 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0), + + 'GetUsePalette' : (None, 0, 0, 0), + + 'FindText' : (0, + '''int %s(int minPos, int maxPos, + const wxString& text, + bool caseSensitive, bool wholeWord);''', + '''int %s(int minPos, int maxPos, + const wxString& text, + bool caseSensitive, bool wholeWord) { + TextToFind ft; + int flags = 0; + + flags |= caseSensitive ? SCFIND_MATCHCASE : 0; + flags |= wholeWord ? SCFIND_WHOLEWORD : 0; + ft.chrg.cpMin = minPos; + ft.chrg.cpMax = maxPos; + ft.lpstrText = (char*)text.c_str(); + + return SendMsg(%s, flags, (long)&ft);''', + 0), + + 'FormatRange' : (0, + '''int %s(bool doDraw, + int startPos, + int endPos, + wxDC* draw, + wxDC* target, // Why does it use two? Can they be the same? + wxRect renderRect, + wxRect pageRect);''', + ''' int %s(bool doDraw, + int startPos, + int endPos, + wxDC* draw, + wxDC* target, // Why does it use two? Can they be the same? + wxRect renderRect, + wxRect pageRect) { + RangeToFormat fr; + + fr.hdc = draw; + fr.hdcTarget = target; + fr.rc.top = renderRect.GetTop(); + fr.rc.left = renderRect.GetLeft(); + fr.rc.right = renderRect.GetRight(); + fr.rc.bottom = renderRect.GetBottom(); + fr.rcPage.top = pageRect.GetTop(); + fr.rcPage.left = pageRect.GetLeft(); + fr.rcPage.right = pageRect.GetRight(); + fr.rcPage.bottom = pageRect.GetBottom(); + fr.chrg.cpMin = startPos; + fr.chrg.cpMax = endPos; + + return SendMsg(%s, doDraw, (long)&fr);''', + 0), + + + 'GetLine' : (0, + 'wxString %s(int line);', + + '''wxString %s(int line) { + wxString text; + int len = LineLength(line); + char* buf = text.GetWriteBuf(len+1); + + int pos = SendMsg(%s, line, (long)buf); + text.UngetWriteBuf(); + + return text;''', + + ('Retrieve the contents of a line.',)), + + 'SetSel' : ('SetSelection', 0, 0, 0), + 'GetSelText' : ('GetSelectedText', + 'wxString %s();', + + '''wxString %s() { + wxString text; + int start; + int end; + + GetSelection(&start, &end); + int len = end - start; + char* buff = text.GetWriteBuf(len+1); + + SendMsg(%s, 0, (long)buff); + text.UngetWriteBuf(); + return text;''', + + ('Retrieve the selected text.',)), + + 'GetTextRange' : (0, + 'wxString %s(int startPos, int endPos);', + + '''wxString %s(int startPos, int endPos) { + wxString text; + int len = endPos - startPos; + char* buff = text.GetWriteBuf(len+1); + TextRange tr; + tr.lpstrText = buff; + tr.chrg.cpMin = startPos; + tr.chrg.cpMax = endPos; + + SendMsg(%s, 0, (long)&tr); + text.UngetWriteBuf(); + return text;''', + + ('Retrieve a range of text.',)), + + 'PointXFromPosition' : (None, 0, 0, 0), + 'PointYFromPosition' : (None, 0, 0, 0), + + 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0), + 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0), + 'Null' : (None, 0, 0, 0), + + 'GetText' : (0, + 'wxString %s();', + + '''wxString %s() { + wxString text; + int len = GetTextLength(); + char* buff = text.GetWriteBuf(len+1); + + SendMsg(%s, len, (long)buff); + buff[len] = 0; + text.UngetWriteBuf(); + return text;''', + + ('Retrieve all the text in the document.', )), + + 'GetDirectFunction' : (None, 0, 0, 0), + 'GetDirectPointer' : (None, 0, 0, 0), + + 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0), + 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0), + 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0), + + + # Remove all methods that are key commands since they can be + # executed with CmdKeyExecute + 'LineDown' : (None, 0, 0, 0), + 'LineDownExtend' : (None, 0, 0, 0), + 'LineUp' : (None, 0, 0, 0), + 'LineUpExtend' : (None, 0, 0, 0), + 'CharLeft' : (None, 0, 0, 0), + 'CharLeftExtend' : (None, 0, 0, 0), + 'CharRight' : (None, 0, 0, 0), + 'CharRightExtend' : (None, 0, 0, 0), + 'WordLeft' : (None, 0, 0, 0), + 'WordLeftExtend' : (None, 0, 0, 0), + 'WordRight' : (None, 0, 0, 0), + 'WordRightExtend' : (None, 0, 0, 0), + 'Home' : (None, 0, 0, 0), + 'HomeExtend' : (None, 0, 0, 0), + 'LineEnd' : (None, 0, 0, 0), + 'LineEndExtend' : (None, 0, 0, 0), + 'DocumentStart' : (None, 0, 0, 0), + 'DocumentStartExtend' : (None, 0, 0, 0), + 'DocumentEnd' : (None, 0, 0, 0), + 'DocumentEndExtend' : (None, 0, 0, 0), + 'PageUp' : (None, 0, 0, 0), + 'PageUpExtend' : (None, 0, 0, 0), + 'PageDown' : (None, 0, 0, 0), + 'PageDownExtend' : (None, 0, 0, 0), + 'EditToggleOvertype' : (None, 0, 0, 0), + 'Cancel' : (None, 0, 0, 0), + 'DeleteBack' : (None, 0, 0, 0), + 'Tab' : (None, 0, 0, 0), + 'BackTab' : (None, 0, 0, 0), + 'NewLine' : (None, 0, 0, 0), + 'FormFeed' : (None, 0, 0, 0), + 'VCHome' : (None, 0, 0, 0), + 'VCHomeExtend' : (None, 0, 0, 0), + 'ZoomIn' : (None, 0, 0, 0), + 'ZoomOut' : (None, 0, 0, 0), + 'DelWordLeft' : (None, 0, 0, 0), + 'DelWordRight' : (None, 0, 0, 0), + 'LineCut' : (None, 0, 0, 0), + 'LineDelete' : (None, 0, 0, 0), + 'LineTranspose' : (None, 0, 0, 0), + 'LowerCase' : (None, 0, 0, 0), + 'UpperCase' : (None, 0, 0, 0), + 'LineScrollDown' : (None, 0, 0, 0), + 'LineScrollUp' : (None, 0, 0, 0), + + + 'GetDocPointer' : (0, + 'void* %s();', + '''void* %s() { + return (void*)SendMsg(%s);''', + 0), + + 'SetDocPointer' : (0, + 'void %s(void* docPointer);', + '''void %s(void* docPointer) { + SendMsg(%s, (long)docPointer);''', + 0), + + 'CreateDocument' : (0, + 'void* %s();', + '''void* %s() { + return (void*)SendMsg(%s);''', + 0), + + 'AddRefDocument' : (0, + 'void %s(void* docPointer);', + '''void %s(void* docPointer) { + SendMsg(%s, (long)docPointer);''', + 0), + + 'ReleaseDocument' : (0, + 'void %s(void* docPointer);', + '''void %s(void* docPointer) { + SendMsg(%s, (long)docPointer);''', + 0), + + 'GrabFocus' : (None, 0, 0, 0), + + '' : ('', 0, 0, 0), + + } + +#---------------------------------------------------------------------------- + +def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest): + curDocStrings = [] + values = [] + methods = [] + + # parse iface file + fi = FileInput(iface) + for line in fi: + line = line[:-1] + if line[:2] == '##' or line == '': + #curDocStrings = [] + continue + + op = line[:4] + if line[:2] == '# ': # a doc string + curDocStrings.append(line[2:]) + + elif op == 'val ': + parseVal(line[4:], values, curDocStrings) + curDocStrings = [] + + elif op == 'fun ' or op == 'set ' or op == 'get ': + parseFun(line[4:], methods, curDocStrings, values) + curDocStrings = [] + + elif op == 'cat ': + if string.strip(line[4:]) == 'Deprecated': + break # skip the rest of the file + + elif op == 'evt ': + pass + + else: + print '***** Unknown line type: ', line + + + # process templates + data = {} + data['VALUES'] = processVals(values) + defs, imps = processMethods(methods) + data['METHOD_DEFS'] = defs + data['METHOD_IMPS'] = imps + + # get template text + h_text = open(h_tmplt).read() + cpp_text = open(cpp_tmplt).read() + + # do the substitutions + h_text = h_text % data + cpp_text = cpp_text % data + + # write out destination files + open(h_dest, 'w').write(h_text) + open(cpp_dest, 'w').write(cpp_text) + + + +#---------------------------------------------------------------------------- + +def processVals(values): + text = [] + for name, value, docs in values: + if docs: + text.append('') + for x in docs: + text.append('// ' + x) + text.append('#define %s %s' % (name, value)) + return string.join(text, '\n') + +#---------------------------------------------------------------------------- + +def processMethods(methods): + defs = [] + imps = [] + + for retType, name, number, param1, param2, docs in methods: + retType = retTypeMap.get(retType, retType) + params = makeParamString(param1, param2) + + name, theDef, theImp, docs = checkMethodOverride(name, number, docs) + + if name is None: + continue + + # Build the method definition for the .h file + if docs: + defs.append('') + for x in docs: + defs.append(' // ' + x) + if not theDef: + theDef = ' %s %s(%s);' % (retType, name, params) + defs.append(theDef) + + # Build the method implementation string + if docs: + imps.append('') + for x in docs: + imps.append('// ' + x) + if not theImp: + theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params) + + if retType == 'wxColour': + theImp = theImp + 'long c = ' + elif retType != 'void': + theImp = theImp + 'return ' + theImp = theImp + 'SendMsg(%s, %s, %s)' % (number, + makeArgString(param1), + makeArgString(param2)) + if retType == 'bool': + theImp = theImp + ' != 0' + if retType == 'wxColour': + theImp = theImp + ';\n return wxColourFromLong(c)' + + theImp = theImp + ';\n}' + imps.append(theImp) + + + return string.join(defs, '\n'), string.join(imps, '\n') + + +#---------------------------------------------------------------------------- + +def checkMethodOverride(name, number, docs): + theDef = theImp = None + if methodOverrideMap.has_key(name): + item = methodOverrideMap[name] + + if item[0] != 0: + name = item[0] + if item[1] != 0: + theDef = ' ' + (item[1] % name) + if item[2] != 0: + theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}' + if item[3] != 0: + docs = item[3] + + return name, theDef, theImp, docs + +#---------------------------------------------------------------------------- + +def makeArgString(param): + if not param: + return '0' + + typ, name = param + + if typ == 'string': + return '(long)%s.c_str()' % name + if typ == 'colour': + return 'wxColourAsLong(%s)' % name + + return name + +#---------------------------------------------------------------------------- + +def makeParamString(param1, param2): + def doOne(param): + if param: + aType = paramTypeMap.get(param[0], param[0]) + return aType + ' ' + param[1] + else: + return '' + + st = doOne(param1) + if st and param2: + st = st + ', ' + st = st + doOne(param2) + return st + + +#---------------------------------------------------------------------------- + +def parseVal(line, values, docs): + name, val = string.split(line, '=') + + # remove prefixes such as SCI, etc. + for old, new in valPrefixes: + lo = len(old) + if name[:lo] == old: + if new is None: + return + name = new + name[lo:] + + # add it to the list + values.append( ('wxSTC_' + name, val, docs) ) + +#---------------------------------------------------------------------------- + +funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # return type + '\s+([a-zA-Z0-9_]+)=' # name= + '([0-9]+)' # number + '\(([ a-zA-Z0-9_]*),' # (param, + '([ a-zA-Z0-9_]*)\)') # param) + +def parseFun(line, methods, docs, values): + def parseParam(param): + param = string.strip(param) + if param == '': + param = None + else: + param = tuple(string.split(param)) + return param + + mo = funregex.match(line) + if mo is None: + print "***** Line doesn't match! : " + line + + retType, name, number, param1, param2 = mo.groups() + + param1 = parseParam(param1) + param2 = parseParam(param2) + + # Special case. For the key command functionss we want a value defined too + num = string.atoi(number) + for v in cmdValues: + if (type(v) == type(()) and v[0] <= num < v[1]) or v == num: + parseVal('CMD_%s=%s' % (string.upper(name), number), values, ()) + + #if retType == 'void' and not param1 and not param2: + + methods.append( (retType, name, number, param1, param2, tuple(docs)) ) + + +#---------------------------------------------------------------------------- + + +def main(args): + # TODO: parse command line args to replace default input/output files??? + + # Now just do it + processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST) + + + +if __name__ == '__main__': + main(sys.argv) + +#---------------------------------------------------------------------------- + + diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index 506493658e..3573c3f648 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -98,7 +98,7 @@ wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, long style, const wxString& name) : wxControl(parent, id, pos, size, - style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS, + style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, wxDefaultValidator, name) { m_swx = new ScintillaWX(this); @@ -119,6 +119,10 @@ long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { } +#ifdef MAKELONG +#undef MAKELONG +#endif + #define MAKELONG(a, b) ((a) | ((b) << 16)) @@ -1478,6 +1482,17 @@ wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { } +// Scroll enough to make the given line visible +void wxStyledTextCtrl::ScrollToLine(int line) { + m_swx->DoScrollToLine(line); +} + + +// Scroll enough to make the given column visible +void wxStyledTextCtrl::ScrollToColumn(int column) { + m_swx->DoScrollToColumn(column); +} + //---------------------------------------------------------------------- // Event handlers diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in new file mode 100644 index 0000000000..b5df70df2a --- /dev/null +++ b/contrib/src/stc/stc.cpp.in @@ -0,0 +1,523 @@ +//////////////////////////////////////////////////////////////////////////// +// Name: stc.cpp +// Purpose: A wxWindows implementation of Scintilla. This class is the +// one meant to be used directly by wx applications. It does not +// derive directly from the Scintilla classes, but instead +// delegates most things to the real Scintilla class. +// This allows the use of Scintilla without polluting the +// namespace with all the classes and identifiers from Scintilla. +// +// Author: Robin Dunn +// +// Created: 13-Jan-2000 +// RCS-ID: $Id$ +// Copyright: (c) 2000 by Total Control Software +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include + +#include "wx/stc/stc.h" +#include "ScintillaWX.h" + +#include + +// The following code forces a reference to all of the Scintilla lexers. +// If we don't do something like this, then the linker tends to "optimize" +// them away. (eric@sourcegear.com) + +int wxForceScintillaLexers(void) +{ + extern LexerModule lmCPP; + extern LexerModule lmHTML; + extern LexerModule lmXML; + extern LexerModule lmProps; + extern LexerModule lmErrorList; + extern LexerModule lmMake; + extern LexerModule lmBatch; + extern LexerModule lmPerl; + extern LexerModule lmPython; + extern LexerModule lmSQL; + extern LexerModule lmVB; + + if ( + &lmCPP + && &lmHTML + && &lmXML + && &lmProps + && &lmErrorList + && &lmMake + && &lmBatch + && &lmPerl + && &lmPython + && &lmSQL + && &lmVB + ) + { + return 1; + } + else + { + return 0; + } +} + +//---------------------------------------------------------------------- + +const wxChar* wxSTCNameStr = "stcwindow"; + +BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) + EVT_PAINT (wxStyledTextCtrl::OnPaint) + EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin) + EVT_SIZE (wxStyledTextCtrl::OnSize) + EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) + EVT_MOTION (wxStyledTextCtrl::OnMouseMove) + EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) + EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) + EVT_CHAR (wxStyledTextCtrl::OnChar) + EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) + EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) + EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) + EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) + EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) + EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu) + EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) +END_EVENT_TABLE() + + +IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) + +//---------------------------------------------------------------------- +// Constructor and Destructor + +wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) : + wxControl(parent, id, pos, size, + style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, + wxDefaultValidator, name) +{ + m_swx = new ScintillaWX(this); + m_stopWatch.Start(); +} + + +wxStyledTextCtrl::~wxStyledTextCtrl() { + delete m_swx; +} + + +//---------------------------------------------------------------------- + +long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { + + return m_swx->WndProc(msg, wp, lp); +} + + +#ifdef MAKELONG +#undef MAKELONG +#endif + +#define MAKELONG(a, b) ((a) | ((b) << 16)) + + +static long wxColourAsLong(const wxColour& co) { + return (((long)co.Blue() << 16) | + ((long)co.Green() << 8) | + ((long)co.Red())); +} + +static wxColour wxColourFromLong(long c) { + wxColour clr; + clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff); + return clr; +} + + +static wxColour wxColourFromSpec(const wxString& spec) { + // spec should be #RRGGBB + char* junk; + int red = strtol(spec.Mid(1,2), &junk, 16); + int green = strtol(spec.Mid(3,2), &junk, 16); + int blue = strtol(spec.Mid(5,2), &junk, 16); + return wxColour(red, green, blue); +} + + +//---------------------------------------------------------------------- +// BEGIN generated section. The following code is automatically generated +// by gen_iface.py from the contents of Scintilla.iface. Do not edit +// this file. Edit stc.cpp.in or gen_iface.py instead and regenerate. + +%(METHOD_IMPS)s + +// END of generated section +//---------------------------------------------------------------------- + + +// Returns the line number of the line with the caret. +int wxStyledTextCtrl::GetCurrentLine() { + int line = LineFromPosition(GetCurrentPos()); + return line; +} + + +// Extract style settings from a spec-string which is composed of one or +// more of the following comma separated elements: +// +// bold turns on bold +// italic turns on italics +// fore:#RRGGBB sets the foreground colour +// back:#RRGGBB sets the background colour +// face:[facename] sets the font face name to use +// size:[num] sets the font size in points +// eol turns on eol filling +// underline turns on underlining +// +void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { + + wxStringTokenizer tkz(spec, ","); + while (tkz.HasMoreTokens()) { + wxString token = tkz.GetNextToken(); + + wxString option = token.BeforeFirst(':'); + wxString val = token.AfterFirst(':'); + + if (option == "bold") + StyleSetBold(styleNum, true); + + else if (option == "italic") + StyleSetItalic(styleNum, true); + + else if (option == "underline") + StyleSetUnderline(styleNum, true); + + else if (option == "eol") + StyleSetEOLFilled(styleNum, true); + + else if (option == "size") { + long points; + if (val.ToLong(&points)) + StyleSetSize(styleNum, points); + } + + else if (option == "face") + StyleSetFaceName(styleNum, val); + + else if (option == "fore") + StyleSetForeground(styleNum, wxColourFromSpec(val)); + + else if (option == "back") + StyleSetBackground(styleNum, wxColourFromSpec(val)); + } +} + + +// Set style size, face, bold, italic, and underline attributes from +// a wxFont's attributes. +void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { + int size = font.GetPointSize(); + wxString faceName = font.GetFaceName(); + bool bold = font.GetWeight() == wxBOLD; + bool italic = font.GetStyle() != wxNORMAL; + bool under = font.GetUnderlined(); + + // TODO: add encoding/charset mapping + StyleSetFontAttr(styleNum, size, faceName, bold, italic, under); +} + +// Set all font style attributes at once. +void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size, + const wxString& faceName, + bool bold, bool italic, + bool underline) { + StyleSetSize(styleNum, size); + StyleSetFaceName(styleNum, faceName); + StyleSetBold(styleNum, bold); + StyleSetItalic(styleNum, italic); + StyleSetUnderline(styleNum, underline); + + // TODO: add encoding/charset mapping +} + + +// Perform one of the operations defined by the wxSTC_CMD_* constants. +void wxStyledTextCtrl::CmdKeyExecute(int cmd) { + SendMsg(cmd); +} + + +// Set the left and right margin in the edit area, measured in pixels. +void wxStyledTextCtrl::SetMargins(int left, int right) { + SetMarginLeft(left); + SetMarginRight(right); +} + + +// Retrieve the start and end positions of the current selection. +void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) { + if (startPos != NULL) + *startPos = SendMsg(SCI_GETSELECTIONSTART); + if (endPos != NULL) + *endPos = SendMsg(SCI_GETSELECTIONEND); +} + + +// Retrieve the point in the window where a position is displayed. +wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { + int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos); + int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos); + return wxPoint(x, y); +} + +// Scroll enough to make the given line visible +void wxStyledTextCtrl::ScrollToLine(int line) { + m_swx->DoScrollToLine(line); +} + + +// Scroll enough to make the given column visible +void wxStyledTextCtrl::ScrollToColumn(int column) { + m_swx->DoScrollToColumn(column); +} + + + +//---------------------------------------------------------------------- +// Event handlers + +void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) { + wxPaintDC dc(this); + wxRegion region = GetUpdateRegion(); + + m_swx->DoPaint(&dc, region.GetBox()); +} + +void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) { + if (evt.GetOrientation() == wxHORIZONTAL) + m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); + else + m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); +} + +void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { + wxSize sz = GetClientSize(); + m_swx->DoSize(sz.x, sz.y); +} + +void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), + evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); +} + +void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoButtonMove(Point(pt.x, pt.y)); +} + +void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), + evt.ControlDown()); +} + + +void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoContextMenu(Point(pt.x, pt.y)); +} + +void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { + long key = evt.KeyCode(); + if ((key > WXK_ESCAPE) && + (key != WXK_DELETE) && (key < 255) && + !evt.ControlDown() && !evt.AltDown()) { + + m_swx->DoAddChar(key); + } + else { + evt.Skip(); + } +} + +void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { + long key = evt.KeyCode(); + key = toupper(key); + int processed = m_swx->DoKeyDown(key, evt.ShiftDown(), + evt.ControlDown(), evt.AltDown()); + if (! processed) + evt.Skip(); +} + +void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) { + m_swx->DoLoseFocus(); +} + +void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { + m_swx->DoGainFocus(); +} + +void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) { + m_swx->DoSysColourChange(); +} + +void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) { + // do nothing to help avoid flashing +} + + + +void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { + m_swx->DoCommand(evt.GetId()); +} + + +void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { + m_swx->DoOnListBox(); +} + + +//---------------------------------------------------------------------- +// Turn notifications from Scintilla into events + + +void wxStyledTextCtrl::NotifyChange() { + wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId()); + GetEventHandler()->ProcessEvent(evt); +} + +void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { + SCNotification& scn = *_scn; + int eventType = 0; + switch (scn.nmhdr.code) { + case SCN_STYLENEEDED: + eventType = wxEVT_STC_STYLENEEDED; + break; + case SCN_CHARADDED: + eventType = wxEVT_STC_CHARADDED; + break; + case SCN_UPDATEUI: + eventType = wxEVT_STC_UPDATEUI; + break; + case SCN_SAVEPOINTREACHED: + eventType = wxEVT_STC_SAVEPOINTREACHED; + break; + case SCN_SAVEPOINTLEFT: + eventType = wxEVT_STC_SAVEPOINTLEFT; + break; + case SCN_MODIFYATTEMPTRO: + eventType = wxEVT_STC_ROMODIFYATTEMPT; + break; + case SCN_DOUBLECLICK: + eventType = wxEVT_STC_DOUBLECLICK; + break; + case SCN_MODIFIED: + eventType = wxEVT_STC_MODIFIED; + break; + case SCN_KEY: + eventType = wxEVT_STC_KEY; + break; + case SCN_MACRORECORD: + eventType = wxEVT_STC_MACRORECORD; + break; + case SCN_MARGINCLICK: + eventType = wxEVT_STC_MARGINCLICK; + break; + case SCN_NEEDSHOWN: + eventType = wxEVT_STC_NEEDSHOWN; + break; + case SCN_POSCHANGED: + eventType = wxEVT_STC_POSCHANGED; + break; + } + if (eventType) { + wxStyledTextEvent evt(eventType, GetId()); + evt.SetPosition(scn.position); + evt.SetKey(scn.ch); + evt.SetModifiers(scn.modifiers); + if (eventType == wxEVT_STC_MODIFIED) { + evt.SetModificationType(scn.modificationType); + if (scn.text) + evt.SetText(wxString(scn.text, scn.length)); + evt.SetLength(scn.length); + evt.SetLinesAdded(scn.linesAdded); + evt.SetLine(scn.line); + evt.SetFoldLevelNow(scn.foldLevelNow); + evt.SetFoldLevelPrev(scn.foldLevelPrev); + } + if (eventType == wxEVT_STC_MARGINCLICK) + evt.SetMargin(scn.margin); + if (eventType == wxEVT_STC_MACRORECORD) { + evt.SetMessage(scn.message); + evt.SetWParam(scn.wParam); + evt.SetLParam(scn.lParam); + } + + GetEventHandler()->ProcessEvent(evt); + } +} + + + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- + +wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) + : wxCommandEvent(commandType, id) +{ + m_position = 0; + m_key = 0; + m_modifiers = 0; + m_modificationType = 0; + m_length = 0; + m_linesAdded = 0; + m_line = 0; + m_foldLevelNow = 0; + m_foldLevelPrev = 0; + m_margin = 0; + m_message = 0; + m_wParam = 0; + m_lParam = 0; + + +} + +bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } +bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; } +bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; } + +void wxStyledTextEvent::CopyObject(wxObject& obj) const { + wxCommandEvent::CopyObject(obj); + + wxStyledTextEvent* o = (wxStyledTextEvent*)&obj; + o->m_position = m_position; + o->m_key = m_key; + o->m_modifiers = m_modifiers; + o->m_modificationType = m_modificationType; + o->m_text = m_text; + o->m_length = m_length; + o->m_linesAdded = m_linesAdded; + o->m_line = m_line; + o->m_foldLevelNow = m_foldLevelNow; + o->m_foldLevelPrev = m_foldLevelPrev; + + o->m_margin = m_margin; + + o->m_message = m_message; + o->m_wParam = m_wParam; + o->m_lParam = m_lParam; + + + +} + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- + diff --git a/contrib/src/stc/stc.h.in b/contrib/src/stc/stc.h.in new file mode 100644 index 0000000000..d9c23f9be3 --- /dev/null +++ b/contrib/src/stc/stc.h.in @@ -0,0 +1,297 @@ +//////////////////////////////////////////////////////////////////////////// +// Name: stc.h +// Purpose: A wxWindows implementation of Scintilla. This class is the +// one meant to be used directly by wx applications. It does not +// derive directly from the Scintilla classes, and in fact there +// is no mention of Scintilla classes at all in this header. +// This class delegates all method calls and events to the +// Scintilla objects and so forth. This allows the use of +// Scintilla without polluting the namespace with all the +// classes and itentifiers from Scintilla. +// +// Author: Robin Dunn +// +// Created: 13-Jan-2000 +// RCS-ID: $Id$ +// Copyright: (c) 2000 by Total Control Software +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifndef __stc_h__ +#define __stc_h__ + + +#include + +//---------------------------------------------------------------------- +// BEGIN generated section. The following code is automatically generated +// by gen_iface.py. Do not edit this file. Edit stc.h.in instead +// and regenerate + +%(VALUES)s + +// END of generated section +//---------------------------------------------------------------------- +// Others + +#define wxSTC_MASK_FOLDERS ((1 << wxSTC_MARKNUM_FOLDER) | (1 << wxSTC_MARKNUM_FOLDEROPEN)) + + + +//---------------------------------------------------------------------- + +class ScintillaWX; // forward declare +class WordList; +struct SCNotification; + + +extern const wxChar* wxSTCNameStr; + +//---------------------------------------------------------------------- + +class wxStyledTextCtrl : public wxControl { +public: + +#ifdef SWIG + wxStyledTextCtrl(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const char* name = "styledtext"); +#else + wxStyledTextCtrl(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxString& name = wxSTCNameStr); +#endif + + +#ifndef SWIG + ~wxStyledTextCtrl(); +#endif + +//---------------------------------------------------------------------- +// BEGIN generated section. The following code is automatically generated +// by gen_iface.py. Do not edit this file. Edit stc.h.in instead +// and regenerate + +%(METHOD_DEFS)s + +// END of generated section +//---------------------------------------------------------------------- +// Others... + + + // Returns the line number of the line with the caret. + int GetCurrentLine(); + + // Extract style settings from a spec-string which is composed of one or + // more of the following comma separated elements: + // + // bold turns on bold + // italic turns on italics + // fore:#RRGGBB sets the foreground colour + // back:#RRGGBB sets the background colour + // face:[facename] sets the font face name to use + // size:[num] sets the font size in points + // eol turns on eol filling + // underline turns on underlining + // + void StyleSetSpec(int styleNum, const wxString& spec); + + + + // Set style size, face, bold, italic, and underline attributes from + // a wxFont's attributes. + void StyleSetFont(int styleNum, wxFont& font); + + + + // Set all font style attributes at once. + void StyleSetFontAttr(int styleNum, int size, + const wxString& faceName, + bool bold, bool italic, + bool underline); + + + + // Perform one of the operations defined by the wxSTC_CMD_* constants. + void CmdKeyExecute(int cmd); + + + + // Set the left and right margin in the edit area, measured in pixels. + void SetMargins(int left, int right); + + + // Retrieve the start and end positions of the current selection. +#ifdef SWIG + void GetSelection(int* OUTPUT, int* OUTPUT); +#else + void GetSelection(int* startPos, int* endPos); +#endif + + // Retrieve the point in the window where a position is displayed. + wxPoint PointFromPosition(int pos); + + + // Scroll enough to make the given line visible + void ScrollToLine(int line); + + + // Scroll enough to make the given column visible + void ScrollToColumn(int column); + +//---------------------------------------------------------------------- + + +#ifndef SWIG +private: + // Event handlers + void OnPaint(wxPaintEvent& evt); + void OnScrollWin(wxScrollWinEvent& evt); + void OnSize(wxSizeEvent& evt); + void OnMouseLeftDown(wxMouseEvent& evt); + void OnMouseMove(wxMouseEvent& evt); + void OnMouseLeftUp(wxMouseEvent& evt); + void OnMouseRightUp(wxMouseEvent& evt); + void OnChar(wxKeyEvent& evt); + void OnKeyDown(wxKeyEvent& evt); + void OnLoseFocus(wxFocusEvent& evt); + void OnGainFocus(wxFocusEvent& evt); + void OnSysColourChanged(wxSysColourChangedEvent& evt); + void OnEraseBackground(wxEraseEvent& evt); + void OnMenu(wxCommandEvent& evt); + void OnListBox(wxCommandEvent& evt); + + + // Turn notifications from Scintilla into events + void NotifyChange(); + void NotifyParent(SCNotification* scn); + + long SendMsg(int msg, long wp=0, long lp=0); + +private: + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxStyledTextCtrl) + + ScintillaWX* m_swx; + wxStopWatch m_stopWatch; + + + friend class ScintillaWX; + friend class Platform; +#endif +}; + +//---------------------------------------------------------------------- + +class wxStyledTextEvent : public wxCommandEvent { +public: + wxStyledTextEvent(wxEventType commandType=0, int id=0); + ~wxStyledTextEvent() {} + + void SetPosition(int pos) { m_position = pos; } + void SetKey(int k) { m_key = k; } + void SetModifiers(int m) { m_modifiers = m; } + void SetModificationType(int t) { m_modificationType = t; } + void SetText(const char* t) { m_text = t; } + void SetLength(int len) { m_length = len; } + void SetLinesAdded(int num) { m_linesAdded = num; } + void SetLine(int val) { m_line = val; } + void SetFoldLevelNow(int val) { m_foldLevelNow = val; } + void SetFoldLevelPrev(int val) { m_foldLevelPrev = val; } + void SetMargin(int val) { m_margin = val; } + void SetMessage(int val) { m_message = val; } + void SetWParam(int val) { m_wParam = val; } + void SetLParam(int val) { m_lParam = val; } + + int GetPosition() const { return m_position; } + int GetKey() const { return m_key; } + int GetModifiers() const { return m_modifiers; } + int GetModificationType() const { return m_modificationType; } + wxString GetText() const { return m_text; } + int GetLength() const { return m_length; } + int GetLinesAdded() const { return m_linesAdded; } + int GetLine() const { return m_line; } + int GetFoldLevelNow() const { return m_foldLevelNow; } + int GetFoldLevelPrev() const { return m_foldLevelPrev; } + int GetMargin() const { return m_margin; } + int GetMessage() const { return m_message; } + int GetWParam() const { return m_wParam; } + int GetLParam() const { return m_lParam; } + + bool GetShift() const; + bool GetControl() const; + bool GetAlt() const; + + void CopyObject(wxObject& obj) const; + +#ifndef SWIG +private: + DECLARE_DYNAMIC_CLASS(wxStyledTextEvent) + + int m_position; + int m_key; + int m_modifiers; + + int m_modificationType; // wxEVT_STC_MODIFIED + wxString m_text; + int m_length; + int m_linesAdded; + int m_line; + int m_foldLevelNow; + int m_foldLevelPrev; + + int m_margin; // wxEVT_STC_MARGINCLICK + + int m_message; // wxEVT_STC_MACRORECORD + int m_wParam; + int m_lParam; +#endif +}; + + +// Event types +enum { + wxEVT_STC_CHANGE = 1650, + wxEVT_STC_STYLENEEDED, + wxEVT_STC_CHARADDED, + wxEVT_STC_UPDATEUI, + wxEVT_STC_SAVEPOINTREACHED, + wxEVT_STC_SAVEPOINTLEFT, + wxEVT_STC_ROMODIFYATTEMPT, + wxEVT_STC_DOUBLECLICK, + wxEVT_STC_MODIFIED, + wxEVT_STC_KEY, + wxEVT_STC_MACRORECORD, + wxEVT_STC_MARGINCLICK, + wxEVT_STC_NEEDSHOWN, + wxEVT_STC_POSCHANGED +}; + + +#ifndef SWIG +typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); + +#define EVT_STC_CHANGE(id, fn) { wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_STYLENEEDED(id, fn) { wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_CHARADDED(id, fn) { wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_UPDATEUI(id, fn) { wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_SAVEPOINTREACHED(id, fn) { wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_SAVEPOINTLEFT(id, fn) { wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_KEY(id, fn) { wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_POSCHANGED(id, fn) { wxEVT_STC_POSCHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, + +#endif + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +#endif + + diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index f98e25d714..fc07f2f616 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -1232,6 +1232,14 @@ public: // Retrieve the point in the window where a position is displayed. wxPoint PointFromPosition(int pos); + + // Scroll enough to make the given line visible + void ScrollToLine(int line); + + + // Scroll enough to make the given column visible + void ScrollToColumn(int column); + //---------------------------------------------------------------------- @@ -1377,6 +1385,7 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_POSCHANGED(id, fn) { wxEVT_STC_POSCHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, #endif diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 63b363ec0e..e0eeab7d98 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -9,6 +9,11 @@ #include "Platform.h" #include "wx/stc/stc.h" + +#ifdef __WXGTK__ +#include +#endif + Point Point::FromLong(long lpoint) { return Point(lpoint & 0xFFFF, lpoint >> 16); } @@ -446,6 +451,76 @@ void Window::SetTitle(const char *s) { } +class wxSTCListBox : public wxListBox { +public: + wxSTCListBox(wxWindow* parent, wxWindowID id) + : wxListBox(parent, id, wxDefaultPosition, wxDefaultSize, + 0, NULL, wxLB_SINGLE | wxLB_SORT | wxSIMPLE_BORDER) + {} + + void OnFocus(wxFocusEvent& event) { + GetParent()->SetFocus(); + event.Skip(); + } + +#ifdef __WXGTK__ + void DoSetFirstItem(int n); +#endif + +private: + DECLARE_EVENT_TABLE() +}; + +BEGIN_EVENT_TABLE(wxSTCListBox, wxListBox) + EVT_SET_FOCUS(wxSTCListBox::OnFocus) +END_EVENT_TABLE() + + + + +#ifdef __WXGTK__ + // This can be removed after 2.2.2 I think +void wxSTCListBox::DoSetFirstItem( int n ) +{ + wxCHECK_RET( m_list, wxT("invalid listbox") ); + + if (gdk_pointer_is_grabbed () && GTK_WIDGET_HAS_GRAB (m_list)) + return; + + // terribly efficient + const gchar *vadjustment_key = "gtk-vadjustment"; + guint vadjustment_key_id = g_quark_from_static_string (vadjustment_key); + + GtkAdjustment *adjustment = + (GtkAdjustment*) gtk_object_get_data_by_id (GTK_OBJECT (m_list), vadjustment_key_id); + wxCHECK_RET( adjustment, wxT("invalid listbox code") ); + + GList *target = g_list_nth( m_list->children, n ); + wxCHECK_RET( target, wxT("invalid listbox index") ); + + GtkWidget *item = GTK_WIDGET(target->data); + wxCHECK_RET( item, wxT("invalid listbox code") ); + + // find the last item before this one which is already realized + size_t nItemsBefore; + for ( nItemsBefore = 0; item && (item->allocation.y == -1); nItemsBefore++ ) + { + target = target->prev; + if ( !target ) + { + // nothing we can do if there are no allocated items yet + return; + } + + item = GTK_WIDGET(target->data); + } + + gtk_adjustment_set_value(adjustment, + item->allocation.y + + nItemsBefore*item->allocation.height); +} +#endif + ListBox::ListBox() { } @@ -454,8 +529,9 @@ ListBox::~ListBox() { } void ListBox::Create(Window &parent, int ctrlID) { - id = new wxListBox(parent.id, ctrlID, wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_SINGLE | wxLB_SORT); + id = new wxSTCListBox(parent.id, ctrlID); +// id = new wxListBox(parent.id, ctrlID, wxDefaultPosition, wxDefaultSize, +// 0, NULL, wxLB_SINGLE | wxLB_SORT | wxSIMPLE_BORDER); } PRectangle ListBox::GetDesiredRect() { @@ -463,6 +539,10 @@ PRectangle ListBox::GetDesiredRect() { PRectangle rc; rc.top = 0; rc.left = 0; + if (sz.x > 150) // TODO: A better way to determine these max sizes + sz.x = 150; + if (sz.y > 100) + sz.y = 100; rc.right = sz.x; rc.bottom = sz.y; @@ -491,6 +571,13 @@ int ListBox::Length() { void ListBox::Select(int n) { ((wxListBox*)id)->SetSelection(n); +#ifdef __WXGTK__ + if (n > 4) + n = n - 4; + else + n = 1; + ((wxListBox*)id)->SetFirstItem(n); +#endif } int ListBox::GetSelection() { diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 650921ee5a..f7349c8d27 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -315,6 +315,11 @@ void ScintillaWX::DoPaint(wxDC* dc, wxRect rect) { FullPaint(); } paintState = notPainting; +#ifdef __WXGTK__ + // On wxGTK the editor window paints can overwrite the listbox... + if (ac.Active()) + ((wxWindow*)ac.lb.GetID())->Refresh(TRUE); +#endif } diff --git a/src/stc/gen_iface.py b/src/stc/gen_iface.py new file mode 100644 index 0000000000..b7dd756715 --- /dev/null +++ b/src/stc/gen_iface.py @@ -0,0 +1,684 @@ +#!/bin/env python +#---------------------------------------------------------------------------- +# Name: gen_iface.py +# Purpose: Generate stc.h and stc.cpp from the info in Scintilla.iface +# +# Author: Robin Dunn +# +# Created: 5-Sept-2000 +# RCS-ID: $Id$ +# Copyright: (c) 2000 by Total Control Software +# Licence: wxWindows license +#---------------------------------------------------------------------------- + + +import sys, string, re +from fileinput import FileInput + + +IFACE = './scintilla/include/Scintilla.iface' +H_TEMPLATE = './stc.h.in' +CPP_TEMPLATE = './stc.cpp.in' +H_DEST = '../../include/wx/stc/stc.h' # './stc_test.h' # +CPP_DEST = './stc.cpp' #'./stc_test.cpp' + + +# Value prefixes to convert +valPrefixes = [('SCI_', ''), + ('SC_', ''), + ('SCN_', None), # just toss these... + ('SCEN_', None), + ('SCE_', ''), + ('SCLEX_', 'LEX_'), + ('SCK_', 'KEY_'), + ('SCFIND_', 'FIND_'), + ('SCWS_', 'WS_'), +] + +# Message funcion values that should have a CMD_ constant as well +cmdValues = [ (2300, 2350), 2011, 2013, (2176, 2180) ] + + +# Map some generic typenames to wx types, using return value syntax +retTypeMap = { + 'position': 'int', + 'string': 'wxString', + 'colour': 'wxColour', + } + +# Map some generic typenames to wx types, using parameter syntax +paramTypeMap = { + 'position': 'int', + 'string': 'const wxString&', + 'colour': 'const wxColour&', + 'keymod': 'int', +} + +# Map of method info that needs tweaked. Either the name needs changed, or +# the method definition/implementation. Tuple items are: +# +# 1. New method name. None to skip the method, 0 to leave the +# default name. +# 2. Method definition for the .h file, 0 to leave alone +# 3. Method implementation for the .cpp file, 0 to leave alone. +# 4. tuple of Doc string lines, or 0 to leave alone. +# +methodOverrideMap = { + 'AddText' : (0, + 'void %s(const wxString& text);', + + '''void %s(const wxString& text) { + SendMsg(%s, text.Len(), (long)text.c_str());''', + 0), + + 'AddStyledText' : (0, + 'void %s(const wxString& text);', + + '''void %s(const wxString& text) { + SendMsg(%s, text.Len(), (long)text.c_str());''', + 0), + + 'GetViewWS' : ( 'GetViewWhiteSpace', 0, 0, 0), + 'SetViewWS' : ( 'SetViewWhiteSpace', 0, 0, 0), + + 'GetStyledText' : (0, + 'wxString %s(int startPos, int endPos);', + + '''wxString %s(int startPos, int endPos) { + wxString text; + int len = endPos - startPos; + TextRange tr; + tr.lpstrText = text.GetWriteBuf(len*2+1); + tr.chrg.cpMin = startPos; + tr.chrg.cpMax = endPos; + SendMsg(%s, 0, (long)&tr); + text.UngetWriteBuf(len*2); + return text;''', + + ('Retrieve a buffer of cells.',)), + + + 'PositionFromPoint' : (0, + 'int %s(wxPoint pt);', + + '''int %s(wxPoint pt) { + return SendMsg(%s, pt.x, pt.y);''', + + 0), + + 'GetCurLine' : (0, + 'wxString %s(int* OUTPUT=NULL);', + + '''wxString %s(int* linePos) { + wxString text; + int len = LineLength(GetCurrentLine()); + char* buf = text.GetWriteBuf(len+1); + + int pos = SendMsg(%s, len, (long)buf); + text.UngetWriteBuf(); + if (linePos) *linePos = pos; + + return text;''', + + 0), + + 'SetUsePalette' : (None, 0,0,0), + + 'MarkerSetFore' : ('MarkerSetForeground', 0, 0, 0), + 'MarkerSetBack' : ('MarkerSetBackground', 0, 0, 0), + + 'MarkerDefine' : (0, + '''void %s(int markerNumber, int markerSymbol, + const wxColour& foreground = wxNullColour, + const wxColour& background = wxNullColour);''', + + '''void %s(int markerNumber, int markerSymbol, + const wxColour& foreground, + const wxColour& background) { + + SendMsg(%s, markerNumber, markerSymbol); + if (foreground.Ok()) + MarkerSetForeground(markerNumber, foreground); + if (background.Ok()) + MarkerSetBackground(markerNumber, background);''', + + ('Set the symbol used for a particular marker number,', + 'and optionally the for and background colours.')), + + 'SetMarginTypeN' : ('SetMarginType', 0, 0, 0), + 'GetMarginTypeN' : ('GetMarginType', 0, 0, 0), + 'SetMarginWidthN' : ('SetMarginWidth', 0, 0, 0), + 'GetMarginWidthN' : ('GetMarginWidth', 0, 0, 0), + 'SetMarginMaskN' : ('SetMarginMask', 0, 0, 0), + 'GetMarginMaskN' : ('GetMarginMask', 0, 0, 0), + 'SetMarginSensitiveN' : ('SetMarginSensitive', 0, 0, 0), + 'GetMarginSensitiveN' : ('GetMarginSensitive', 0, 0, 0), + + 'StyleSetFore' : ('StyleSetForeground', 0, 0, 0), + 'StyleSetBack' : ('StyleSetBackground', 0, 0, 0), + 'SetSelFore' : ('SetSelForeground', 0, 0, 0), + 'SetSelBack' : ('SetSelBackground', 0, 0, 0), + 'SetCaretFore' : ('SetCaretForeground', 0, 0, 0), + 'StyleSetFont' : ('StyleSetFaceName', 0, 0, 0), + + # need to fix this to map between wx and scintilla encoding flags, leave it out for now... + 'StyleSetCharacterSet' : (None, 0, 0, 0), + + 'AssignCmdKey' : ('CmdKeyAssign', + 'void %s(int key, int modifiers, int cmd);', + + '''void %s(int key, int modifiers, int cmd) { + SendMsg(%s, MAKELONG(key, modifiers), cmd);''', + + 0), + + 'ClearCmdKey' : ('CmdKeyClear', + 'void %s(int key, int modifiers);', + + '''void %s(int key, int modifiers) { + SendMsg(%s, MAKELONG(key, modifiers));''', + + 0), + + 'ClearAllCmdKeys' : ('CmdKeyClearAll', 0, 0, 0), + + + 'SetStylingEx' : ('SetStyleBytes', + 'void %s(int length, char* styleBytes);', + + '''void %s(int length, char* styleBytes) { + SendMsg(%s, length, (long)styleBytes);''', + + 0), + + + 'IndicSetStyle' : ('IndicatorSetStyle', 0, 0, 0), + 'IndicGetStyle' : ('IndicatorGetStyle', 0, 0, 0), + 'IndicSetFore' : ('IndicatorSetForeground', 0, 0, 0), + 'IndicGetFore' : ('IndicatorGetForeground', 0, 0, 0), + + 'AutoCShow' : ('AutoCompShow', 0, 0, 0), + 'AutoCCancel' : ('AutoCompCancel', 0, 0, 0), + 'AutoCActive' : ('AutoCompActive', 0, 0, 0), + 'AutoCPosStart' : ('AutoCompPosStart', 0, 0, 0), + 'AutoCComplete' : ('AutoCompComplete', 0, 0, 0), + 'AutoCStops' : ('AutoCompStops', 0, 0, 0), + 'AutoCSetSeparator' : ('AutoCompSetSeparator', 0, 0, 0), + 'AutoCGetSeparator' : ('AutoCompGetSeparator', 0, 0, 0), + 'AutoCSelect' : ('AutoCompSelect', 0, 0, 0), + 'AutoCSetCancelAtStart' : ('AutoCompSetCancelAtStart', 0, 0, 0), + 'AutoCGetCancelAtStart' : ('AutoCompGetCancelAtStart', 0, 0, 0), + 'AutoCSetFillUps' : ('AutoCompSetFillUps', 0, 0, 0), + 'AutoCSetChooseSingle' : ('AutoCompSetChooseSingle', 0, 0, 0), + 'AutoCGetChooseSingle' : ('AutoCompGetChooseSingle', 0, 0, 0), + 'AutoCSetIgnoreCase' : ('AutoCompSetIgnoreCase', 0, 0, 0), + 'AutoCGetIgnoreCase' : ('AutoCompGetIgnoreCase', 0, 0, 0), + + 'SetHScrollBar' : ('SetUseHorizontalScrollBar', 0, 0, 0), + 'GetHScrollBar' : ('GetUseHorizontalScrollBar', 0, 0, 0), + + 'GetCaretFore' : ('GetCaretForeground', 0, 0, 0), + + 'GetUsePalette' : (None, 0, 0, 0), + + 'FindText' : (0, + '''int %s(int minPos, int maxPos, + const wxString& text, + bool caseSensitive, bool wholeWord);''', + '''int %s(int minPos, int maxPos, + const wxString& text, + bool caseSensitive, bool wholeWord) { + TextToFind ft; + int flags = 0; + + flags |= caseSensitive ? SCFIND_MATCHCASE : 0; + flags |= wholeWord ? SCFIND_WHOLEWORD : 0; + ft.chrg.cpMin = minPos; + ft.chrg.cpMax = maxPos; + ft.lpstrText = (char*)text.c_str(); + + return SendMsg(%s, flags, (long)&ft);''', + 0), + + 'FormatRange' : (0, + '''int %s(bool doDraw, + int startPos, + int endPos, + wxDC* draw, + wxDC* target, // Why does it use two? Can they be the same? + wxRect renderRect, + wxRect pageRect);''', + ''' int %s(bool doDraw, + int startPos, + int endPos, + wxDC* draw, + wxDC* target, // Why does it use two? Can they be the same? + wxRect renderRect, + wxRect pageRect) { + RangeToFormat fr; + + fr.hdc = draw; + fr.hdcTarget = target; + fr.rc.top = renderRect.GetTop(); + fr.rc.left = renderRect.GetLeft(); + fr.rc.right = renderRect.GetRight(); + fr.rc.bottom = renderRect.GetBottom(); + fr.rcPage.top = pageRect.GetTop(); + fr.rcPage.left = pageRect.GetLeft(); + fr.rcPage.right = pageRect.GetRight(); + fr.rcPage.bottom = pageRect.GetBottom(); + fr.chrg.cpMin = startPos; + fr.chrg.cpMax = endPos; + + return SendMsg(%s, doDraw, (long)&fr);''', + 0), + + + 'GetLine' : (0, + 'wxString %s(int line);', + + '''wxString %s(int line) { + wxString text; + int len = LineLength(line); + char* buf = text.GetWriteBuf(len+1); + + int pos = SendMsg(%s, line, (long)buf); + text.UngetWriteBuf(); + + return text;''', + + ('Retrieve the contents of a line.',)), + + 'SetSel' : ('SetSelection', 0, 0, 0), + 'GetSelText' : ('GetSelectedText', + 'wxString %s();', + + '''wxString %s() { + wxString text; + int start; + int end; + + GetSelection(&start, &end); + int len = end - start; + char* buff = text.GetWriteBuf(len+1); + + SendMsg(%s, 0, (long)buff); + text.UngetWriteBuf(); + return text;''', + + ('Retrieve the selected text.',)), + + 'GetTextRange' : (0, + 'wxString %s(int startPos, int endPos);', + + '''wxString %s(int startPos, int endPos) { + wxString text; + int len = endPos - startPos; + char* buff = text.GetWriteBuf(len+1); + TextRange tr; + tr.lpstrText = buff; + tr.chrg.cpMin = startPos; + tr.chrg.cpMax = endPos; + + SendMsg(%s, 0, (long)&tr); + text.UngetWriteBuf(); + return text;''', + + ('Retrieve a range of text.',)), + + 'PointXFromPosition' : (None, 0, 0, 0), + 'PointYFromPosition' : (None, 0, 0, 0), + + 'ScrollCaret' : ('EnsureCaretVisible', 0, 0, 0), + 'ReplaceSel' : ('ReplaceSelection', 0, 0, 0), + 'Null' : (None, 0, 0, 0), + + 'GetText' : (0, + 'wxString %s();', + + '''wxString %s() { + wxString text; + int len = GetTextLength(); + char* buff = text.GetWriteBuf(len+1); + + SendMsg(%s, len, (long)buff); + buff[len] = 0; + text.UngetWriteBuf(); + return text;''', + + ('Retrieve all the text in the document.', )), + + 'GetDirectFunction' : (None, 0, 0, 0), + 'GetDirectPointer' : (None, 0, 0, 0), + + 'CallTipPosStart' : ('CallTipPosAtStart', 0, 0, 0), + 'CallTipSetHlt' : ('CallTipSetHighlight', 0, 0, 0), + 'CallTipSetBack' : ('CallTipSetBackground', 0, 0, 0), + + + # Remove all methods that are key commands since they can be + # executed with CmdKeyExecute + 'LineDown' : (None, 0, 0, 0), + 'LineDownExtend' : (None, 0, 0, 0), + 'LineUp' : (None, 0, 0, 0), + 'LineUpExtend' : (None, 0, 0, 0), + 'CharLeft' : (None, 0, 0, 0), + 'CharLeftExtend' : (None, 0, 0, 0), + 'CharRight' : (None, 0, 0, 0), + 'CharRightExtend' : (None, 0, 0, 0), + 'WordLeft' : (None, 0, 0, 0), + 'WordLeftExtend' : (None, 0, 0, 0), + 'WordRight' : (None, 0, 0, 0), + 'WordRightExtend' : (None, 0, 0, 0), + 'Home' : (None, 0, 0, 0), + 'HomeExtend' : (None, 0, 0, 0), + 'LineEnd' : (None, 0, 0, 0), + 'LineEndExtend' : (None, 0, 0, 0), + 'DocumentStart' : (None, 0, 0, 0), + 'DocumentStartExtend' : (None, 0, 0, 0), + 'DocumentEnd' : (None, 0, 0, 0), + 'DocumentEndExtend' : (None, 0, 0, 0), + 'PageUp' : (None, 0, 0, 0), + 'PageUpExtend' : (None, 0, 0, 0), + 'PageDown' : (None, 0, 0, 0), + 'PageDownExtend' : (None, 0, 0, 0), + 'EditToggleOvertype' : (None, 0, 0, 0), + 'Cancel' : (None, 0, 0, 0), + 'DeleteBack' : (None, 0, 0, 0), + 'Tab' : (None, 0, 0, 0), + 'BackTab' : (None, 0, 0, 0), + 'NewLine' : (None, 0, 0, 0), + 'FormFeed' : (None, 0, 0, 0), + 'VCHome' : (None, 0, 0, 0), + 'VCHomeExtend' : (None, 0, 0, 0), + 'ZoomIn' : (None, 0, 0, 0), + 'ZoomOut' : (None, 0, 0, 0), + 'DelWordLeft' : (None, 0, 0, 0), + 'DelWordRight' : (None, 0, 0, 0), + 'LineCut' : (None, 0, 0, 0), + 'LineDelete' : (None, 0, 0, 0), + 'LineTranspose' : (None, 0, 0, 0), + 'LowerCase' : (None, 0, 0, 0), + 'UpperCase' : (None, 0, 0, 0), + 'LineScrollDown' : (None, 0, 0, 0), + 'LineScrollUp' : (None, 0, 0, 0), + + + 'GetDocPointer' : (0, + 'void* %s();', + '''void* %s() { + return (void*)SendMsg(%s);''', + 0), + + 'SetDocPointer' : (0, + 'void %s(void* docPointer);', + '''void %s(void* docPointer) { + SendMsg(%s, (long)docPointer);''', + 0), + + 'CreateDocument' : (0, + 'void* %s();', + '''void* %s() { + return (void*)SendMsg(%s);''', + 0), + + 'AddRefDocument' : (0, + 'void %s(void* docPointer);', + '''void %s(void* docPointer) { + SendMsg(%s, (long)docPointer);''', + 0), + + 'ReleaseDocument' : (0, + 'void %s(void* docPointer);', + '''void %s(void* docPointer) { + SendMsg(%s, (long)docPointer);''', + 0), + + 'GrabFocus' : (None, 0, 0, 0), + + '' : ('', 0, 0, 0), + + } + +#---------------------------------------------------------------------------- + +def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest): + curDocStrings = [] + values = [] + methods = [] + + # parse iface file + fi = FileInput(iface) + for line in fi: + line = line[:-1] + if line[:2] == '##' or line == '': + #curDocStrings = [] + continue + + op = line[:4] + if line[:2] == '# ': # a doc string + curDocStrings.append(line[2:]) + + elif op == 'val ': + parseVal(line[4:], values, curDocStrings) + curDocStrings = [] + + elif op == 'fun ' or op == 'set ' or op == 'get ': + parseFun(line[4:], methods, curDocStrings, values) + curDocStrings = [] + + elif op == 'cat ': + if string.strip(line[4:]) == 'Deprecated': + break # skip the rest of the file + + elif op == 'evt ': + pass + + else: + print '***** Unknown line type: ', line + + + # process templates + data = {} + data['VALUES'] = processVals(values) + defs, imps = processMethods(methods) + data['METHOD_DEFS'] = defs + data['METHOD_IMPS'] = imps + + # get template text + h_text = open(h_tmplt).read() + cpp_text = open(cpp_tmplt).read() + + # do the substitutions + h_text = h_text % data + cpp_text = cpp_text % data + + # write out destination files + open(h_dest, 'w').write(h_text) + open(cpp_dest, 'w').write(cpp_text) + + + +#---------------------------------------------------------------------------- + +def processVals(values): + text = [] + for name, value, docs in values: + if docs: + text.append('') + for x in docs: + text.append('// ' + x) + text.append('#define %s %s' % (name, value)) + return string.join(text, '\n') + +#---------------------------------------------------------------------------- + +def processMethods(methods): + defs = [] + imps = [] + + for retType, name, number, param1, param2, docs in methods: + retType = retTypeMap.get(retType, retType) + params = makeParamString(param1, param2) + + name, theDef, theImp, docs = checkMethodOverride(name, number, docs) + + if name is None: + continue + + # Build the method definition for the .h file + if docs: + defs.append('') + for x in docs: + defs.append(' // ' + x) + if not theDef: + theDef = ' %s %s(%s);' % (retType, name, params) + defs.append(theDef) + + # Build the method implementation string + if docs: + imps.append('') + for x in docs: + imps.append('// ' + x) + if not theImp: + theImp = '%s wxStyledTextCtrl::%s(%s) {\n ' % (retType, name, params) + + if retType == 'wxColour': + theImp = theImp + 'long c = ' + elif retType != 'void': + theImp = theImp + 'return ' + theImp = theImp + 'SendMsg(%s, %s, %s)' % (number, + makeArgString(param1), + makeArgString(param2)) + if retType == 'bool': + theImp = theImp + ' != 0' + if retType == 'wxColour': + theImp = theImp + ';\n return wxColourFromLong(c)' + + theImp = theImp + ';\n}' + imps.append(theImp) + + + return string.join(defs, '\n'), string.join(imps, '\n') + + +#---------------------------------------------------------------------------- + +def checkMethodOverride(name, number, docs): + theDef = theImp = None + if methodOverrideMap.has_key(name): + item = methodOverrideMap[name] + + if item[0] != 0: + name = item[0] + if item[1] != 0: + theDef = ' ' + (item[1] % name) + if item[2] != 0: + theImp = item[2] % ('wxStyledTextCtrl::'+name, number) + '\n}' + if item[3] != 0: + docs = item[3] + + return name, theDef, theImp, docs + +#---------------------------------------------------------------------------- + +def makeArgString(param): + if not param: + return '0' + + typ, name = param + + if typ == 'string': + return '(long)%s.c_str()' % name + if typ == 'colour': + return 'wxColourAsLong(%s)' % name + + return name + +#---------------------------------------------------------------------------- + +def makeParamString(param1, param2): + def doOne(param): + if param: + aType = paramTypeMap.get(param[0], param[0]) + return aType + ' ' + param[1] + else: + return '' + + st = doOne(param1) + if st and param2: + st = st + ', ' + st = st + doOne(param2) + return st + + +#---------------------------------------------------------------------------- + +def parseVal(line, values, docs): + name, val = string.split(line, '=') + + # remove prefixes such as SCI, etc. + for old, new in valPrefixes: + lo = len(old) + if name[:lo] == old: + if new is None: + return + name = new + name[lo:] + + # add it to the list + values.append( ('wxSTC_' + name, val, docs) ) + +#---------------------------------------------------------------------------- + +funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # return type + '\s+([a-zA-Z0-9_]+)=' # name= + '([0-9]+)' # number + '\(([ a-zA-Z0-9_]*),' # (param, + '([ a-zA-Z0-9_]*)\)') # param) + +def parseFun(line, methods, docs, values): + def parseParam(param): + param = string.strip(param) + if param == '': + param = None + else: + param = tuple(string.split(param)) + return param + + mo = funregex.match(line) + if mo is None: + print "***** Line doesn't match! : " + line + + retType, name, number, param1, param2 = mo.groups() + + param1 = parseParam(param1) + param2 = parseParam(param2) + + # Special case. For the key command functionss we want a value defined too + num = string.atoi(number) + for v in cmdValues: + if (type(v) == type(()) and v[0] <= num < v[1]) or v == num: + parseVal('CMD_%s=%s' % (string.upper(name), number), values, ()) + + #if retType == 'void' and not param1 and not param2: + + methods.append( (retType, name, number, param1, param2, tuple(docs)) ) + + +#---------------------------------------------------------------------------- + + +def main(args): + # TODO: parse command line args to replace default input/output files??? + + # Now just do it + processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, H_DEST, CPP_DEST) + + + +if __name__ == '__main__': + main(sys.argv) + +#---------------------------------------------------------------------------- + + diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 506493658e..3573c3f648 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -98,7 +98,7 @@ wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, long style, const wxString& name) : wxControl(parent, id, pos, size, - style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS, + style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, wxDefaultValidator, name) { m_swx = new ScintillaWX(this); @@ -119,6 +119,10 @@ long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { } +#ifdef MAKELONG +#undef MAKELONG +#endif + #define MAKELONG(a, b) ((a) | ((b) << 16)) @@ -1478,6 +1482,17 @@ wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { } +// Scroll enough to make the given line visible +void wxStyledTextCtrl::ScrollToLine(int line) { + m_swx->DoScrollToLine(line); +} + + +// Scroll enough to make the given column visible +void wxStyledTextCtrl::ScrollToColumn(int column) { + m_swx->DoScrollToColumn(column); +} + //---------------------------------------------------------------------- // Event handlers diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in new file mode 100644 index 0000000000..b5df70df2a --- /dev/null +++ b/src/stc/stc.cpp.in @@ -0,0 +1,523 @@ +//////////////////////////////////////////////////////////////////////////// +// Name: stc.cpp +// Purpose: A wxWindows implementation of Scintilla. This class is the +// one meant to be used directly by wx applications. It does not +// derive directly from the Scintilla classes, but instead +// delegates most things to the real Scintilla class. +// This allows the use of Scintilla without polluting the +// namespace with all the classes and identifiers from Scintilla. +// +// Author: Robin Dunn +// +// Created: 13-Jan-2000 +// RCS-ID: $Id$ +// Copyright: (c) 2000 by Total Control Software +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#include + +#include "wx/stc/stc.h" +#include "ScintillaWX.h" + +#include + +// The following code forces a reference to all of the Scintilla lexers. +// If we don't do something like this, then the linker tends to "optimize" +// them away. (eric@sourcegear.com) + +int wxForceScintillaLexers(void) +{ + extern LexerModule lmCPP; + extern LexerModule lmHTML; + extern LexerModule lmXML; + extern LexerModule lmProps; + extern LexerModule lmErrorList; + extern LexerModule lmMake; + extern LexerModule lmBatch; + extern LexerModule lmPerl; + extern LexerModule lmPython; + extern LexerModule lmSQL; + extern LexerModule lmVB; + + if ( + &lmCPP + && &lmHTML + && &lmXML + && &lmProps + && &lmErrorList + && &lmMake + && &lmBatch + && &lmPerl + && &lmPython + && &lmSQL + && &lmVB + ) + { + return 1; + } + else + { + return 0; + } +} + +//---------------------------------------------------------------------- + +const wxChar* wxSTCNameStr = "stcwindow"; + +BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) + EVT_PAINT (wxStyledTextCtrl::OnPaint) + EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin) + EVT_SIZE (wxStyledTextCtrl::OnSize) + EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) + EVT_MOTION (wxStyledTextCtrl::OnMouseMove) + EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) + EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) + EVT_CHAR (wxStyledTextCtrl::OnChar) + EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) + EVT_KILL_FOCUS (wxStyledTextCtrl::OnLoseFocus) + EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) + EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) + EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) + EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu) + EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) +END_EVENT_TABLE() + + +IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) + +//---------------------------------------------------------------------- +// Constructor and Destructor + +wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) : + wxControl(parent, id, pos, size, + style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, + wxDefaultValidator, name) +{ + m_swx = new ScintillaWX(this); + m_stopWatch.Start(); +} + + +wxStyledTextCtrl::~wxStyledTextCtrl() { + delete m_swx; +} + + +//---------------------------------------------------------------------- + +long wxStyledTextCtrl::SendMsg(int msg, long wp, long lp) { + + return m_swx->WndProc(msg, wp, lp); +} + + +#ifdef MAKELONG +#undef MAKELONG +#endif + +#define MAKELONG(a, b) ((a) | ((b) << 16)) + + +static long wxColourAsLong(const wxColour& co) { + return (((long)co.Blue() << 16) | + ((long)co.Green() << 8) | + ((long)co.Red())); +} + +static wxColour wxColourFromLong(long c) { + wxColour clr; + clr.Set(c & 0xff, (c >> 8) & 0xff, (c >> 16) & 0xff); + return clr; +} + + +static wxColour wxColourFromSpec(const wxString& spec) { + // spec should be #RRGGBB + char* junk; + int red = strtol(spec.Mid(1,2), &junk, 16); + int green = strtol(spec.Mid(3,2), &junk, 16); + int blue = strtol(spec.Mid(5,2), &junk, 16); + return wxColour(red, green, blue); +} + + +//---------------------------------------------------------------------- +// BEGIN generated section. The following code is automatically generated +// by gen_iface.py from the contents of Scintilla.iface. Do not edit +// this file. Edit stc.cpp.in or gen_iface.py instead and regenerate. + +%(METHOD_IMPS)s + +// END of generated section +//---------------------------------------------------------------------- + + +// Returns the line number of the line with the caret. +int wxStyledTextCtrl::GetCurrentLine() { + int line = LineFromPosition(GetCurrentPos()); + return line; +} + + +// Extract style settings from a spec-string which is composed of one or +// more of the following comma separated elements: +// +// bold turns on bold +// italic turns on italics +// fore:#RRGGBB sets the foreground colour +// back:#RRGGBB sets the background colour +// face:[facename] sets the font face name to use +// size:[num] sets the font size in points +// eol turns on eol filling +// underline turns on underlining +// +void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { + + wxStringTokenizer tkz(spec, ","); + while (tkz.HasMoreTokens()) { + wxString token = tkz.GetNextToken(); + + wxString option = token.BeforeFirst(':'); + wxString val = token.AfterFirst(':'); + + if (option == "bold") + StyleSetBold(styleNum, true); + + else if (option == "italic") + StyleSetItalic(styleNum, true); + + else if (option == "underline") + StyleSetUnderline(styleNum, true); + + else if (option == "eol") + StyleSetEOLFilled(styleNum, true); + + else if (option == "size") { + long points; + if (val.ToLong(&points)) + StyleSetSize(styleNum, points); + } + + else if (option == "face") + StyleSetFaceName(styleNum, val); + + else if (option == "fore") + StyleSetForeground(styleNum, wxColourFromSpec(val)); + + else if (option == "back") + StyleSetBackground(styleNum, wxColourFromSpec(val)); + } +} + + +// Set style size, face, bold, italic, and underline attributes from +// a wxFont's attributes. +void wxStyledTextCtrl::StyleSetFont(int styleNum, wxFont& font) { + int size = font.GetPointSize(); + wxString faceName = font.GetFaceName(); + bool bold = font.GetWeight() == wxBOLD; + bool italic = font.GetStyle() != wxNORMAL; + bool under = font.GetUnderlined(); + + // TODO: add encoding/charset mapping + StyleSetFontAttr(styleNum, size, faceName, bold, italic, under); +} + +// Set all font style attributes at once. +void wxStyledTextCtrl::StyleSetFontAttr(int styleNum, int size, + const wxString& faceName, + bool bold, bool italic, + bool underline) { + StyleSetSize(styleNum, size); + StyleSetFaceName(styleNum, faceName); + StyleSetBold(styleNum, bold); + StyleSetItalic(styleNum, italic); + StyleSetUnderline(styleNum, underline); + + // TODO: add encoding/charset mapping +} + + +// Perform one of the operations defined by the wxSTC_CMD_* constants. +void wxStyledTextCtrl::CmdKeyExecute(int cmd) { + SendMsg(cmd); +} + + +// Set the left and right margin in the edit area, measured in pixels. +void wxStyledTextCtrl::SetMargins(int left, int right) { + SetMarginLeft(left); + SetMarginRight(right); +} + + +// Retrieve the start and end positions of the current selection. +void wxStyledTextCtrl::GetSelection(int* startPos, int* endPos) { + if (startPos != NULL) + *startPos = SendMsg(SCI_GETSELECTIONSTART); + if (endPos != NULL) + *endPos = SendMsg(SCI_GETSELECTIONEND); +} + + +// Retrieve the point in the window where a position is displayed. +wxPoint wxStyledTextCtrl::PointFromPosition(int pos) { + int x = SendMsg(SCI_POINTXFROMPOSITION, 0, pos); + int y = SendMsg(SCI_POINTYFROMPOSITION, 0, pos); + return wxPoint(x, y); +} + +// Scroll enough to make the given line visible +void wxStyledTextCtrl::ScrollToLine(int line) { + m_swx->DoScrollToLine(line); +} + + +// Scroll enough to make the given column visible +void wxStyledTextCtrl::ScrollToColumn(int column) { + m_swx->DoScrollToColumn(column); +} + + + +//---------------------------------------------------------------------- +// Event handlers + +void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) { + wxPaintDC dc(this); + wxRegion region = GetUpdateRegion(); + + m_swx->DoPaint(&dc, region.GetBox()); +} + +void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) { + if (evt.GetOrientation() == wxHORIZONTAL) + m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); + else + m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); +} + +void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { + wxSize sz = GetClientSize(); + m_swx->DoSize(sz.x, sz.y); +} + +void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), + evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); +} + +void wxStyledTextCtrl::OnMouseMove(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoButtonMove(Point(pt.x, pt.y)); +} + +void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoButtonUp(Point(pt.x, pt.y), m_stopWatch.Time(), + evt.ControlDown()); +} + + +void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoContextMenu(Point(pt.x, pt.y)); +} + +void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { + long key = evt.KeyCode(); + if ((key > WXK_ESCAPE) && + (key != WXK_DELETE) && (key < 255) && + !evt.ControlDown() && !evt.AltDown()) { + + m_swx->DoAddChar(key); + } + else { + evt.Skip(); + } +} + +void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { + long key = evt.KeyCode(); + key = toupper(key); + int processed = m_swx->DoKeyDown(key, evt.ShiftDown(), + evt.ControlDown(), evt.AltDown()); + if (! processed) + evt.Skip(); +} + +void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) { + m_swx->DoLoseFocus(); +} + +void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { + m_swx->DoGainFocus(); +} + +void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) { + m_swx->DoSysColourChange(); +} + +void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) { + // do nothing to help avoid flashing +} + + + +void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { + m_swx->DoCommand(evt.GetId()); +} + + +void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { + m_swx->DoOnListBox(); +} + + +//---------------------------------------------------------------------- +// Turn notifications from Scintilla into events + + +void wxStyledTextCtrl::NotifyChange() { + wxStyledTextEvent evt(wxEVT_STC_CHANGE, GetId()); + GetEventHandler()->ProcessEvent(evt); +} + +void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { + SCNotification& scn = *_scn; + int eventType = 0; + switch (scn.nmhdr.code) { + case SCN_STYLENEEDED: + eventType = wxEVT_STC_STYLENEEDED; + break; + case SCN_CHARADDED: + eventType = wxEVT_STC_CHARADDED; + break; + case SCN_UPDATEUI: + eventType = wxEVT_STC_UPDATEUI; + break; + case SCN_SAVEPOINTREACHED: + eventType = wxEVT_STC_SAVEPOINTREACHED; + break; + case SCN_SAVEPOINTLEFT: + eventType = wxEVT_STC_SAVEPOINTLEFT; + break; + case SCN_MODIFYATTEMPTRO: + eventType = wxEVT_STC_ROMODIFYATTEMPT; + break; + case SCN_DOUBLECLICK: + eventType = wxEVT_STC_DOUBLECLICK; + break; + case SCN_MODIFIED: + eventType = wxEVT_STC_MODIFIED; + break; + case SCN_KEY: + eventType = wxEVT_STC_KEY; + break; + case SCN_MACRORECORD: + eventType = wxEVT_STC_MACRORECORD; + break; + case SCN_MARGINCLICK: + eventType = wxEVT_STC_MARGINCLICK; + break; + case SCN_NEEDSHOWN: + eventType = wxEVT_STC_NEEDSHOWN; + break; + case SCN_POSCHANGED: + eventType = wxEVT_STC_POSCHANGED; + break; + } + if (eventType) { + wxStyledTextEvent evt(eventType, GetId()); + evt.SetPosition(scn.position); + evt.SetKey(scn.ch); + evt.SetModifiers(scn.modifiers); + if (eventType == wxEVT_STC_MODIFIED) { + evt.SetModificationType(scn.modificationType); + if (scn.text) + evt.SetText(wxString(scn.text, scn.length)); + evt.SetLength(scn.length); + evt.SetLinesAdded(scn.linesAdded); + evt.SetLine(scn.line); + evt.SetFoldLevelNow(scn.foldLevelNow); + evt.SetFoldLevelPrev(scn.foldLevelPrev); + } + if (eventType == wxEVT_STC_MARGINCLICK) + evt.SetMargin(scn.margin); + if (eventType == wxEVT_STC_MACRORECORD) { + evt.SetMessage(scn.message); + evt.SetWParam(scn.wParam); + evt.SetLParam(scn.lParam); + } + + GetEventHandler()->ProcessEvent(evt); + } +} + + + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- + +wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) + : wxCommandEvent(commandType, id) +{ + m_position = 0; + m_key = 0; + m_modifiers = 0; + m_modificationType = 0; + m_length = 0; + m_linesAdded = 0; + m_line = 0; + m_foldLevelNow = 0; + m_foldLevelPrev = 0; + m_margin = 0; + m_message = 0; + m_wParam = 0; + m_lParam = 0; + + +} + +bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } +bool wxStyledTextEvent::GetControl() const { return (m_modifiers & SCI_CTRL) != 0; } +bool wxStyledTextEvent::GetAlt() const { return (m_modifiers & SCI_ALT) != 0; } + +void wxStyledTextEvent::CopyObject(wxObject& obj) const { + wxCommandEvent::CopyObject(obj); + + wxStyledTextEvent* o = (wxStyledTextEvent*)&obj; + o->m_position = m_position; + o->m_key = m_key; + o->m_modifiers = m_modifiers; + o->m_modificationType = m_modificationType; + o->m_text = m_text; + o->m_length = m_length; + o->m_linesAdded = m_linesAdded; + o->m_line = m_line; + o->m_foldLevelNow = m_foldLevelNow; + o->m_foldLevelPrev = m_foldLevelPrev; + + o->m_margin = m_margin; + + o->m_message = m_message; + o->m_wParam = m_wParam; + o->m_lParam = m_lParam; + + + +} + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- + diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in new file mode 100644 index 0000000000..d9c23f9be3 --- /dev/null +++ b/src/stc/stc.h.in @@ -0,0 +1,297 @@ +//////////////////////////////////////////////////////////////////////////// +// Name: stc.h +// Purpose: A wxWindows implementation of Scintilla. This class is the +// one meant to be used directly by wx applications. It does not +// derive directly from the Scintilla classes, and in fact there +// is no mention of Scintilla classes at all in this header. +// This class delegates all method calls and events to the +// Scintilla objects and so forth. This allows the use of +// Scintilla without polluting the namespace with all the +// classes and itentifiers from Scintilla. +// +// Author: Robin Dunn +// +// Created: 13-Jan-2000 +// RCS-ID: $Id$ +// Copyright: (c) 2000 by Total Control Software +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +#ifndef __stc_h__ +#define __stc_h__ + + +#include + +//---------------------------------------------------------------------- +// BEGIN generated section. The following code is automatically generated +// by gen_iface.py. Do not edit this file. Edit stc.h.in instead +// and regenerate + +%(VALUES)s + +// END of generated section +//---------------------------------------------------------------------- +// Others + +#define wxSTC_MASK_FOLDERS ((1 << wxSTC_MARKNUM_FOLDER) | (1 << wxSTC_MARKNUM_FOLDEROPEN)) + + + +//---------------------------------------------------------------------- + +class ScintillaWX; // forward declare +class WordList; +struct SCNotification; + + +extern const wxChar* wxSTCNameStr; + +//---------------------------------------------------------------------- + +class wxStyledTextCtrl : public wxControl { +public: + +#ifdef SWIG + wxStyledTextCtrl(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const char* name = "styledtext"); +#else + wxStyledTextCtrl(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, long style = 0, + const wxString& name = wxSTCNameStr); +#endif + + +#ifndef SWIG + ~wxStyledTextCtrl(); +#endif + +//---------------------------------------------------------------------- +// BEGIN generated section. The following code is automatically generated +// by gen_iface.py. Do not edit this file. Edit stc.h.in instead +// and regenerate + +%(METHOD_DEFS)s + +// END of generated section +//---------------------------------------------------------------------- +// Others... + + + // Returns the line number of the line with the caret. + int GetCurrentLine(); + + // Extract style settings from a spec-string which is composed of one or + // more of the following comma separated elements: + // + // bold turns on bold + // italic turns on italics + // fore:#RRGGBB sets the foreground colour + // back:#RRGGBB sets the background colour + // face:[facename] sets the font face name to use + // size:[num] sets the font size in points + // eol turns on eol filling + // underline turns on underlining + // + void StyleSetSpec(int styleNum, const wxString& spec); + + + + // Set style size, face, bold, italic, and underline attributes from + // a wxFont's attributes. + void StyleSetFont(int styleNum, wxFont& font); + + + + // Set all font style attributes at once. + void StyleSetFontAttr(int styleNum, int size, + const wxString& faceName, + bool bold, bool italic, + bool underline); + + + + // Perform one of the operations defined by the wxSTC_CMD_* constants. + void CmdKeyExecute(int cmd); + + + + // Set the left and right margin in the edit area, measured in pixels. + void SetMargins(int left, int right); + + + // Retrieve the start and end positions of the current selection. +#ifdef SWIG + void GetSelection(int* OUTPUT, int* OUTPUT); +#else + void GetSelection(int* startPos, int* endPos); +#endif + + // Retrieve the point in the window where a position is displayed. + wxPoint PointFromPosition(int pos); + + + // Scroll enough to make the given line visible + void ScrollToLine(int line); + + + // Scroll enough to make the given column visible + void ScrollToColumn(int column); + +//---------------------------------------------------------------------- + + +#ifndef SWIG +private: + // Event handlers + void OnPaint(wxPaintEvent& evt); + void OnScrollWin(wxScrollWinEvent& evt); + void OnSize(wxSizeEvent& evt); + void OnMouseLeftDown(wxMouseEvent& evt); + void OnMouseMove(wxMouseEvent& evt); + void OnMouseLeftUp(wxMouseEvent& evt); + void OnMouseRightUp(wxMouseEvent& evt); + void OnChar(wxKeyEvent& evt); + void OnKeyDown(wxKeyEvent& evt); + void OnLoseFocus(wxFocusEvent& evt); + void OnGainFocus(wxFocusEvent& evt); + void OnSysColourChanged(wxSysColourChangedEvent& evt); + void OnEraseBackground(wxEraseEvent& evt); + void OnMenu(wxCommandEvent& evt); + void OnListBox(wxCommandEvent& evt); + + + // Turn notifications from Scintilla into events + void NotifyChange(); + void NotifyParent(SCNotification* scn); + + long SendMsg(int msg, long wp=0, long lp=0); + +private: + DECLARE_EVENT_TABLE() + DECLARE_CLASS(wxStyledTextCtrl) + + ScintillaWX* m_swx; + wxStopWatch m_stopWatch; + + + friend class ScintillaWX; + friend class Platform; +#endif +}; + +//---------------------------------------------------------------------- + +class wxStyledTextEvent : public wxCommandEvent { +public: + wxStyledTextEvent(wxEventType commandType=0, int id=0); + ~wxStyledTextEvent() {} + + void SetPosition(int pos) { m_position = pos; } + void SetKey(int k) { m_key = k; } + void SetModifiers(int m) { m_modifiers = m; } + void SetModificationType(int t) { m_modificationType = t; } + void SetText(const char* t) { m_text = t; } + void SetLength(int len) { m_length = len; } + void SetLinesAdded(int num) { m_linesAdded = num; } + void SetLine(int val) { m_line = val; } + void SetFoldLevelNow(int val) { m_foldLevelNow = val; } + void SetFoldLevelPrev(int val) { m_foldLevelPrev = val; } + void SetMargin(int val) { m_margin = val; } + void SetMessage(int val) { m_message = val; } + void SetWParam(int val) { m_wParam = val; } + void SetLParam(int val) { m_lParam = val; } + + int GetPosition() const { return m_position; } + int GetKey() const { return m_key; } + int GetModifiers() const { return m_modifiers; } + int GetModificationType() const { return m_modificationType; } + wxString GetText() const { return m_text; } + int GetLength() const { return m_length; } + int GetLinesAdded() const { return m_linesAdded; } + int GetLine() const { return m_line; } + int GetFoldLevelNow() const { return m_foldLevelNow; } + int GetFoldLevelPrev() const { return m_foldLevelPrev; } + int GetMargin() const { return m_margin; } + int GetMessage() const { return m_message; } + int GetWParam() const { return m_wParam; } + int GetLParam() const { return m_lParam; } + + bool GetShift() const; + bool GetControl() const; + bool GetAlt() const; + + void CopyObject(wxObject& obj) const; + +#ifndef SWIG +private: + DECLARE_DYNAMIC_CLASS(wxStyledTextEvent) + + int m_position; + int m_key; + int m_modifiers; + + int m_modificationType; // wxEVT_STC_MODIFIED + wxString m_text; + int m_length; + int m_linesAdded; + int m_line; + int m_foldLevelNow; + int m_foldLevelPrev; + + int m_margin; // wxEVT_STC_MARGINCLICK + + int m_message; // wxEVT_STC_MACRORECORD + int m_wParam; + int m_lParam; +#endif +}; + + +// Event types +enum { + wxEVT_STC_CHANGE = 1650, + wxEVT_STC_STYLENEEDED, + wxEVT_STC_CHARADDED, + wxEVT_STC_UPDATEUI, + wxEVT_STC_SAVEPOINTREACHED, + wxEVT_STC_SAVEPOINTLEFT, + wxEVT_STC_ROMODIFYATTEMPT, + wxEVT_STC_DOUBLECLICK, + wxEVT_STC_MODIFIED, + wxEVT_STC_KEY, + wxEVT_STC_MACRORECORD, + wxEVT_STC_MARGINCLICK, + wxEVT_STC_NEEDSHOWN, + wxEVT_STC_POSCHANGED +}; + + +#ifndef SWIG +typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); + +#define EVT_STC_CHANGE(id, fn) { wxEVT_STC_CHANGE, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_STYLENEEDED(id, fn) { wxEVT_STC_STYLENEEDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_CHARADDED(id, fn) { wxEVT_STC_CHARADDED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_UPDATEUI(id, fn) { wxEVT_STC_UPDATEUI, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_SAVEPOINTREACHED(id, fn) { wxEVT_STC_SAVEPOINTREACHED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_SAVEPOINTLEFT(id, fn) { wxEVT_STC_SAVEPOINTLEFT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_ROMODIFYATTEMPT(id, fn) { wxEVT_STC_ROMODIFYATTEMPT, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_DOUBLECLICK(id, fn) { wxEVT_STC_DOUBLECLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_MODIFIED(id, fn) { wxEVT_STC_MODIFIED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_KEY(id, fn) { wxEVT_STC_KEY, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_MACRORECORD(id, fn) { wxEVT_STC_MACRORECORD, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_MARGINCLICK(id, fn) { wxEVT_STC_MARGINCLICK, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_NEEDSHOWN(id, fn) { wxEVT_STC_NEEDSHOWN, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, +#define EVT_STC_POSCHANGED(id, fn) { wxEVT_STC_POSCHANGED, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxStyledTextEventFunction) & fn, (wxObject *) NULL }, + +#endif + +//---------------------------------------------------------------------- +//---------------------------------------------------------------------- +#endif + + -- 2.45.2