X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/00c64037fb763781c64036f6e165fc0555a07d4e..a4353f07c6b37712634d4b2d86527b647a08044f:/src/stc/stc.cpp diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index f56024c0ca..1a8aca13cc 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -22,57 +22,42 @@ #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 lmAda; - extern LexerModule lmAVE; - extern LexerModule lmConf; - extern LexerModule lmCPP; - extern LexerModule lmNncrontab; - extern LexerModule lmEiffel; - extern LexerModule lmHTML; - extern LexerModule lmLISP; - extern LexerModule lmLua; - extern LexerModule lmBatch; // In LexOthers.cxx - extern LexerModule lmPascal; - extern LexerModule lmPerl; - extern LexerModule lmPython; - extern LexerModule lmRuby; - extern LexerModule lmSQL; - extern LexerModule lmVB; - - if ( &lmAda - && &lmAVE - && &lmConf - && &lmCPP - && &lmNncrontab - && &lmEiffel - && &lmHTML - && &lmLISP - && &lmLua - && &lmBatch - && &lmPascal - && &lmPerl - && &lmPython - && &lmRuby - && &lmSQL - && &lmVB ) - { - return 1; - } - else - { - return 0; - } +//---------------------------------------------------------------------- + +const wxChar* wxSTCNameStr = wxT("stcwindow"); + +#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; +} -const wxChar* wxSTCNameStr = "stcwindow"; + +static wxColour wxColourFromSpec(const wxString& spec) { + // spec should be "#RRGGBB" + long red, green, blue; + red = green = blue = 0; + spec.Mid(1,2).ToLong(&red, 16); + spec.Mid(3,2).ToLong(&green, 16); + spec.Mid(5,2).ToLong(&blue, 16); + return wxColour(red, green, blue); +} + +//---------------------------------------------------------------------- DEFINE_EVENT_TYPE( wxEVT_STC_CHANGE ) DEFINE_EVENT_TYPE( wxEVT_STC_STYLENEEDED ) @@ -93,25 +78,28 @@ DEFINE_EVENT_TYPE( wxEVT_STC_USERLISTSELECTION ) DEFINE_EVENT_TYPE( wxEVT_STC_URIDROPPED ) DEFINE_EVENT_TYPE( wxEVT_STC_DWELLSTART ) DEFINE_EVENT_TYPE( wxEVT_STC_DWELLEND ) -#if wxUSE_DRAG_AND_DROP DEFINE_EVENT_TYPE( wxEVT_STC_START_DRAG ) DEFINE_EVENT_TYPE( wxEVT_STC_DRAG_OVER ) DEFINE_EVENT_TYPE( wxEVT_STC_DO_DROP ) -#endif BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_PAINT (wxStyledTextCtrl::OnPaint) EVT_SCROLLWIN (wxStyledTextCtrl::OnScrollWin) + EVT_SCROLL (wxStyledTextCtrl::OnScroll) EVT_SIZE (wxStyledTextCtrl::OnSize) EVT_LEFT_DOWN (wxStyledTextCtrl::OnMouseLeftDown) -#ifdef __WXMSW__ +#if defined(__WXMSW__) || defined(__WXMAC__) // Let Scintilla see the double click as a second click EVT_LEFT_DCLICK (wxStyledTextCtrl::OnMouseLeftDown) #endif EVT_MOTION (wxStyledTextCtrl::OnMouseMove) EVT_LEFT_UP (wxStyledTextCtrl::OnMouseLeftUp) +#if defined(__WXGTK__) || defined(__WXMAC__) + EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) +#else EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) +#endif EVT_MOUSEWHEEL (wxStyledTextCtrl::OnMouseWheel) EVT_CHAR (wxStyledTextCtrl::OnChar) EVT_KEY_DOWN (wxStyledTextCtrl::OnKeyDown) @@ -127,6 +115,9 @@ END_EVENT_TABLE() IMPLEMENT_CLASS(wxStyledTextCtrl, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxStyledTextEvent, wxCommandEvent) +// forces the linking of the lexer modules +int Scintilla_LinkLexers(); + //---------------------------------------------------------------------- // Constructor and Destructor @@ -140,9 +131,16 @@ wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, wxDefaultValidator, name) { + Scintilla_LinkLexers(); m_swx = new ScintillaWX(this); m_stopWatch.Start(); m_lastKeyDownConsumed = FALSE; + m_vScrollBar = NULL; + m_hScrollBar = NULL; +#if wxUSE_UNICODE + // Put Scintilla into unicode (UTF-8) mode + SetCodePage(wxSTC_CP_UTF8); +#endif } @@ -159,35 +157,6 @@ long wxStyledTextCtrl::SendMsg(int msg, long wp, long 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 @@ -197,17 +166,18 @@ static wxColour wxColourFromSpec(const wxString& spec) { // Add text to the document void wxStyledTextCtrl::AddText(const wxString& text) { - SendMsg(2001, text.Len(), (long)text.c_str()); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + SendMsg(2001, strlen(buf), (long)(const char*)buf); } // Add array of cells to document -void wxStyledTextCtrl::AddStyledText(const wxString& text) { - SendMsg(2002, text.Len(), (long)text.c_str()); +void wxStyledTextCtrl::AddStyledText(const wxMemoryBuffer& data) { + SendMsg(2002, data.GetDataLen(), (long)data.GetData()); } // Insert string at a position void wxStyledTextCtrl::InsertText(int pos, const wxString& text) { - SendMsg(2003, pos, (long)text.c_str()); + SendMsg(2003, pos, (long)(const char*)wx2stc(text)); } // Delete all text in the document @@ -227,7 +197,7 @@ int wxStyledTextCtrl::GetLength() { // Returns the character byte at the position int wxStyledTextCtrl::GetCharAt(int pos) { - return SendMsg(2007, pos, 0); + return (unsigned char)SendMsg(2007, pos, 0); } // Returns the position of the caret @@ -242,7 +212,7 @@ int wxStyledTextCtrl::GetAnchor() { // Returns the style byte at the position int wxStyledTextCtrl::GetStyleAt(int pos) { - return SendMsg(2010, pos, 0); + return (unsigned char)SendMsg(2010, pos, 0); } // Redoes the next action on the undo history @@ -268,17 +238,22 @@ void wxStyledTextCtrl::SetSavePoint() { } // Retrieve a buffer of cells. -wxString wxStyledTextCtrl::GetStyledText(int startPos, int endPos) { - wxString text; +wxMemoryBuffer wxStyledTextCtrl::GetStyledText(int startPos, int endPos) { + wxMemoryBuffer buf; + if (endPos < startPos) { + int temp = startPos; + startPos = endPos; + endPos = temp; + } int len = endPos - startPos; - if (!len) return ""; + if (!len) return buf; TextRange tr; - tr.lpstrText = text.GetWriteBuf(len*2); + tr.lpstrText = (char*)buf.GetWriteBuf(len*2+1); tr.chrg.cpMin = startPos; tr.chrg.cpMax = endPos; - SendMsg(2015, 0, (long)&tr); - text.UngetWriteBuf(len*2); - return text; + len = SendMsg(2015, 0, (long)&tr); + buf.UngetWriteBuf(len); + return buf; } // Are there any redoable actions in the undo history. @@ -342,20 +317,20 @@ void wxStyledTextCtrl::SetAnchor(int posAnchor) { // Retrieve the text of the line containing the caret. // Returns the index of the caret on the line. wxString wxStyledTextCtrl::GetCurLine(int* linePos) { - wxString text; int len = LineLength(GetCurrentLine()); if (!len) { if (linePos) *linePos = 0; - return ""; + return wxEmptyString; } - // Need an extra byte because SCI_GETCURLINE writes a null to the string - char* buf = text.GetWriteBuf(len+1); + + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); int pos = SendMsg(2027, len+1, (long)buf); - text.UngetWriteBuf(len); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); if (linePos) *linePos = pos; - - return text; + return stc2wx(buf); } // Retrieve the position of the last correctly styled character. @@ -414,13 +389,19 @@ int wxStyledTextCtrl::GetTabWidth() { } // Set the code page used to interpret the bytes of the document as characters. -// The SC_CP_UTF8 value can be used to enter Unicode mode. void wxStyledTextCtrl::SetCodePage(int codePage) { - SendMsg(2037, codePage, 0); +#if wxUSE_UNICODE + wxASSERT_MSG(codePage == wxSTC_CP_UTF8, + wxT("Only wxSTC_CP_UTF8 may be used when wxUSE_UNICODE is on.")); +#else + wxASSERT_MSG(codePage != wxSTC_CP_UTF8, + wxT("wxSTC_CP_UTF8 may not be used when wxUSE_UNICODE is off.")); +#endif + SendMsg(2037, codePage); } // Set the symbol used for a particular marker number, -// and optionally the for and background colours. +// and optionally the fore and background colours. void wxStyledTextCtrl::MarkerDefine(int markerNumber, int markerSymbol, const wxColour& foreground, const wxColour& background) { @@ -442,9 +423,9 @@ void wxStyledTextCtrl::MarkerSetBackground(int markerNumber, const wxColour& bac SendMsg(2042, markerNumber, wxColourAsLong(back)); } -// Add a marker to a line. -void wxStyledTextCtrl::MarkerAdd(int line, int markerNumber) { - SendMsg(2043, line, markerNumber); +// Add a marker to a line, returning an ID which can be used to find or delete the marker. +int wxStyledTextCtrl::MarkerAdd(int line, int markerNumber) { + return SendMsg(2043, line, markerNumber); } // Delete a marker from a line @@ -544,7 +525,7 @@ void wxStyledTextCtrl::StyleSetSize(int style, int sizePoints) { // Set the font of a style. void wxStyledTextCtrl::StyleSetFaceName(int style, const wxString& fontName) { - SendMsg(2056, style, (long)fontName.c_str()); + SendMsg(2056, style, (long)(const char*)wx2stc(fontName)); } // Set a style to have its end of line filled or not. @@ -567,6 +548,11 @@ void wxStyledTextCtrl::StyleSetCase(int style, int caseForce) { SendMsg(2060, style, caseForce); } +// Set the character set of the font in a style. +void wxStyledTextCtrl::StyleSetCharacterSet(int style, int characterSet) { + SendMsg(2066, style, characterSet); +} + // Set the foreground colour of the selection and whether to use this setting. void wxStyledTextCtrl::SetSelForeground(bool useSetting, const wxColour& fore) { SendMsg(2067, useSetting, wxColourAsLong(fore)); @@ -620,7 +606,7 @@ void wxStyledTextCtrl::SetCaretPeriod(int periodMilliseconds) { // Set the set of characters making up words for when moving or selecting // by word. void wxStyledTextCtrl::SetWordChars(const wxString& characters) { - SendMsg(2077, 0, (long)characters.c_str()); + SendMsg(2077, 0, (long)(const char*)wx2stc(characters)); } // Start a sequence of actions that is undone and redone as a unit. @@ -687,7 +673,7 @@ bool wxStyledTextCtrl::GetCaretLineVisible() { return SendMsg(2095, 0, 0) != 0; } -// Display the background of the line containing the caret in a different colour. +// Dsplay the background of the line containing the caret in a different colour. void wxStyledTextCtrl::SetCaretLineVisible(bool show) { SendMsg(2096, show, 0); } @@ -703,11 +689,17 @@ void wxStyledTextCtrl::SetCaretLineBack(const wxColour& back) { SendMsg(2098, wxColourAsLong(back), 0); } +// Set a style to be changeable or not (read only). +// Experimental feature, currently buggy. +void wxStyledTextCtrl::StyleSetChangeable(int style, bool changeable) { + SendMsg(2099, style, changeable); +} + // Display a auto-completion list. // The lenEntered parameter indicates how many characters before // the caret should be used to provide context. void wxStyledTextCtrl::AutoCompShow(int lenEntered, const wxString& itemList) { - SendMsg(2100, lenEntered, (long)itemList.c_str()); + SendMsg(2100, lenEntered, (long)(const char*)wx2stc(itemList)); } // Remove the auto-completion list from the screen. @@ -733,7 +725,7 @@ void wxStyledTextCtrl::AutoCompComplete() { // Define a set of character that when typed cancel the auto-completion list. void wxStyledTextCtrl::AutoCompStops(const wxString& characterSet) { - SendMsg(2105, 0, (long)characterSet.c_str()); + SendMsg(2105, 0, (long)(const char*)wx2stc(characterSet)); } // Change the separator character in the string setting up an auto-completion @@ -749,7 +741,7 @@ int wxStyledTextCtrl::AutoCompGetSeparator() { // Select the item in the auto-completion list that starts with a string. void wxStyledTextCtrl::AutoCompSelect(const wxString& text) { - SendMsg(2108, 0, (long)text.c_str()); + SendMsg(2108, 0, (long)(const char*)wx2stc(text)); } // Should the auto-completion list be cancelled if the user backspaces to a @@ -763,9 +755,10 @@ bool wxStyledTextCtrl::AutoCompGetCancelAtStart() { return SendMsg(2111, 0, 0) != 0; } -// Define a set of character that when typed fills up the selected word. +// Define a set of characters that when typed will cause the autocompletion to +// choose the selected item. void wxStyledTextCtrl::AutoCompSetFillUps(const wxString& characterSet) { - SendMsg(2112, 0, (long)characterSet.c_str()); + SendMsg(2112, 0, (long)(const char*)wx2stc(characterSet)); } // Should a single item auto-completion list automatically choose the item. @@ -790,7 +783,7 @@ bool wxStyledTextCtrl::AutoCompGetIgnoreCase() { // Display a list of strings and send notification when user chooses one. void wxStyledTextCtrl::UserListShow(int listType, const wxString& itemList) { - SendMsg(2117, listType, (long)itemList.c_str()); + SendMsg(2117, listType, (long)(const char*)wx2stc(itemList)); } // Set whether or not autocompletion is hidden automatically when nothing matches @@ -803,6 +796,16 @@ bool wxStyledTextCtrl::AutoCompGetAutoHide() { return SendMsg(2119, 0, 0) != 0; } +// Set whether or not autocompletion deletes any word characters after the inserted text upon completion +void wxStyledTextCtrl::AutoCompSetDropRestOfWord(bool dropRestOfWord) { + SendMsg(2270, dropRestOfWord, 0); +} + +// Retrieve whether or not autocompletion deletes any word characters after the inserted text upon completion +bool wxStyledTextCtrl::AutoCompGetDropRestOfWord() { + return SendMsg(2271, 0, 0) != 0; +} + // Set the number of spaces used for one level of indentation. void wxStyledTextCtrl::SetIndent(int indentSize) { SendMsg(2122, indentSize, 0); @@ -943,16 +946,13 @@ int wxStyledTextCtrl::GetPrintColourMode() { // Find some text in the document. int wxStyledTextCtrl::FindText(int minPos, int maxPos, - const wxString& text, - bool caseSensitive, bool wholeWord) { + const wxString& text, + int flags) { 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(); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + ft.lpstrText = (char*)(const char*)buf; return SendMsg(2150, flags, (long)&ft); } @@ -967,6 +967,11 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos, wxRect pageRect) { RangeToFormat fr; + if (endPos < startPos) { + int temp = startPos; + startPos = endPos; + endPos = temp; + } fr.hdc = draw; fr.hdcTarget = target; fr.rc.top = renderRect.GetTop(); @@ -990,15 +995,15 @@ int wxStyledTextCtrl::GetFirstVisibleLine() { // Retrieve the contents of a line. wxString wxStyledTextCtrl::GetLine(int line) { - wxString text; int len = LineLength(line); - if (!len) return ""; - char* buf = text.GetWriteBuf(len); - - int pos = SendMsg(2153, line, (long)buf); - text.UngetWriteBuf(len); + if (!len) return wxEmptyString; - return text; + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(2153, line, (long)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); } // Returns the number of lines in the document. There is always at least one. @@ -1038,34 +1043,40 @@ void wxStyledTextCtrl::SetSelection(int start, int end) { // Retrieve the selected text. wxString wxStyledTextCtrl::GetSelectedText() { - wxString text; int start; int end; GetSelection(&start, &end); int len = end - start; - if (!len) return ""; - char* buff = text.GetWriteBuf(len); + if (!len) return wxEmptyString; - SendMsg(2161, 0, (long)buff); - text.UngetWriteBuf(len); - return text; + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(2161, 0, (long)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); } // Retrieve a range of text. wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) { - wxString text; + if (endPos < startPos) { + int temp = startPos; + startPos = endPos; + endPos = temp; + } int len = endPos - startPos; - if (!len) return ""; - char* buff = text.GetWriteBuf(len); + if (!len) return wxEmptyString; + wxMemoryBuffer mbuf(len+1); + char* buf = (char*)mbuf.GetWriteBuf(len); TextRange tr; - tr.lpstrText = buff; + tr.lpstrText = buf; tr.chrg.cpMin = startPos; tr.chrg.cpMax = endPos; - SendMsg(2162, 0, (long)&tr); - text.UngetWriteBuf(len); - return text; + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); } // Draw the selection in normal style or with selection highlighted. @@ -1095,7 +1106,7 @@ void wxStyledTextCtrl::EnsureCaretVisible() { // Replace the selected text with the argument text. void wxStyledTextCtrl::ReplaceSelection(const wxString& text) { - SendMsg(2170, 0, (long)text.c_str()); + SendMsg(2170, 0, (long)(const char*)wx2stc(text)); } // Set to read only or read write. @@ -1145,18 +1156,18 @@ void wxStyledTextCtrl::Clear() { // Replace the contents of the document with the argument text. void wxStyledTextCtrl::SetText(const wxString& text) { - SendMsg(2181, 0, (long)text.c_str()); + SendMsg(2181, 0, (long)(const char*)wx2stc(text)); } // Retrieve all the text in the document. wxString wxStyledTextCtrl::GetText() { - wxString text; - int len = GetTextLength(); - char* buff = text.GetWriteBuf(len+1); // leave room for the null... - - SendMsg(2182, len+1, (long)buff); - text.UngetWriteBuf(len); - return text; + int len = GetTextLength(); + wxMemoryBuffer mbuf(len+1); // leave room for the null... + char* buf = (char*)mbuf.GetWriteBuf(len+1); + SendMsg(2182, len+1, (long)buf); + mbuf.UngetWriteBuf(len); + mbuf.AppendByte(0); + return stc2wx(buf); } // Retrieve the number of characters in the document. @@ -1211,8 +1222,8 @@ int wxStyledTextCtrl::GetTargetEnd() { // Returns the length of the replacement text. int wxStyledTextCtrl::ReplaceTarget(const wxString& text) { - return SendMsg(2194, text.Len(), (long)text.c_str()); - + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + return SendMsg(2194, strlen(buf), (long)(const char*)buf); } // Replace the target text with the argument text after \d processing. @@ -1223,8 +1234,8 @@ int wxStyledTextCtrl::GetTargetEnd() { // caused by processing the \d patterns. int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) { - return SendMsg(2195, text.Len(), (long)text.c_str()); - + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + return SendMsg(2195, strlen(buf), (long)(const char*)buf); } // Search for a counted string in the target and set the target to the found @@ -1232,8 +1243,8 @@ int wxStyledTextCtrl::GetTargetEnd() { // Returns length of range or -1 for failure in which case target is not moved. int wxStyledTextCtrl::SearchInTarget(const wxString& text) { - return SendMsg(2197, text.Len(), (long)text.c_str()); - + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + return SendMsg(2197, strlen(buf), (long)(const char*)buf); } // Set the search flags used by SearchInTarget @@ -1248,7 +1259,7 @@ int wxStyledTextCtrl::GetSearchFlags() { // Show a call tip containing a definition near position pos. void wxStyledTextCtrl::CallTipShow(int pos, const wxString& definition) { - SendMsg(2200, pos, (long)definition.c_str()); + SendMsg(2200, pos, (long)(const char*)wx2stc(definition)); } // Remove the call tip from the screen. @@ -1384,6 +1395,36 @@ int wxStyledTextCtrl::GetMouseDwellTime() { return SendMsg(2265, 0, 0); } +// Get position of start of word +int wxStyledTextCtrl::WordStartPosition(int pos, bool onlyWordCharacters) { + return SendMsg(2266, pos, onlyWordCharacters); +} + +// Get position of end of word +int wxStyledTextCtrl::WordEndPosition(int pos, bool onlyWordCharacters) { + return SendMsg(2267, pos, onlyWordCharacters); +} + +// Sets whether text is word wrapped +void wxStyledTextCtrl::SetWrapMode(int mode) { + SendMsg(2268, mode, 0); +} + +// Retrieve whether text is word wrapped +int wxStyledTextCtrl::GetWrapMode() { + return SendMsg(2269, 0, 0); +} + +// Sets the degree of caching of layout information +void wxStyledTextCtrl::SetLayoutCache(int mode) { + SendMsg(2272, mode, 0); +} + +// Retrieve the degree of caching of layout information +int wxStyledTextCtrl::GetLayoutCache() { + return SendMsg(2273, 0, 0); +} + // Move the caret inside current view if it's not there already void wxStyledTextCtrl::MoveCaretInsideView() { SendMsg(2401, 0, 0); @@ -1475,13 +1516,13 @@ void wxStyledTextCtrl::SearchAnchor() { // Find some text starting at the search anchor. // Does not ensure the selection is visible. int wxStyledTextCtrl::SearchNext(int flags, const wxString& text) { - return SendMsg(2367, flags, (long)text.c_str()); + return SendMsg(2367, flags, (long)(const char*)wx2stc(text)); } // Find some text starting at the search anchor and moving backwards. // Does not ensure the selection is visible. int wxStyledTextCtrl::SearchPrev(int flags, const wxString& text) { - return SendMsg(2368, flags, (long)text.c_str()); + return SendMsg(2368, flags, (long)(const char*)wx2stc(text)); } // Set the way the line the caret is on is kept visible. @@ -1524,12 +1565,12 @@ void* wxStyledTextCtrl::CreateDocument() { // Extend life of document. void wxStyledTextCtrl::AddRefDocument(void* docPointer) { - SendMsg(2376, (long)docPointer); + SendMsg(2376, 0, (long)docPointer); } // Release a reference to the document, deleting document if it fades to black. void wxStyledTextCtrl::ReleaseDocument(void* docPointer) { - SendMsg(2377, (long)docPointer); + SendMsg(2377, 0, (long)docPointer); } // Get which document modification events are sent to the container. @@ -1577,6 +1618,17 @@ int wxStyledTextCtrl::GetCursor() { return SendMsg(2387, 0, 0); } +// Change the way control characters are displayed: +// If symbol is < 32, keep the drawn way, else, use the given character +void wxStyledTextCtrl::SetControlCharSymbol(int symbol) { + SendMsg(2388, symbol, 0); +} + +// Get the way control characters are displayed +int wxStyledTextCtrl::GetControlCharSymbol() { + return SendMsg(2389, 0, 0); +} + // Move to the previous change in capitalistion void wxStyledTextCtrl::WordPartLeft() { SendMsg(2390, 0, 0); @@ -1612,6 +1664,14 @@ void wxStyledTextCtrl::DelLineRight() { SendMsg(2396, 0, 0); } +// Get and Set the xOffset (ie, horizonal scroll position) +void wxStyledTextCtrl::SetXOffset(int newOffset) { + SendMsg(2397, newOffset, 0); +} +int wxStyledTextCtrl::GetXOffset() { + return SendMsg(2398, 0, 0); +} + // Start notifying the container of all key presses and commands. void wxStyledTextCtrl::StartRecord() { SendMsg(3001, 0, 0); @@ -1639,17 +1699,17 @@ void wxStyledTextCtrl::Colourise(int start, int end) { // Set up a value that may be used by a lexer for some optional feature. void wxStyledTextCtrl::SetProperty(const wxString& key, const wxString& value) { - SendMsg(4004, (long)key.c_str(), (long)value.c_str()); + SendMsg(4004, (long)(const char*)wx2stc(key), (long)(const char*)wx2stc(value)); } // Set up the key words used by the lexer. void wxStyledTextCtrl::SetKeyWords(int keywordSet, const wxString& keyWords) { - SendMsg(4005, keywordSet, (long)keyWords.c_str()); + SendMsg(4005, keywordSet, (long)(const char*)wx2stc(keyWords)); } // Set the lexing language of the document based on string name. void wxStyledTextCtrl::SetLexerLanguage(const wxString& language) { - SendMsg(4006, 0, (long)language.c_str()); + SendMsg(4006, 0, (long)(const char*)wx2stc(language)); } // END of generated section @@ -1677,38 +1737,38 @@ int wxStyledTextCtrl::GetCurrentLine() { // void wxStyledTextCtrl::StyleSetSpec(int styleNum, const wxString& spec) { - wxStringTokenizer tkz(spec, ","); + wxStringTokenizer tkz(spec, wxT(",")); while (tkz.HasMoreTokens()) { wxString token = tkz.GetNextToken(); wxString option = token.BeforeFirst(':'); wxString val = token.AfterFirst(':'); - if (option == "bold") + if (option == wxT("bold")) StyleSetBold(styleNum, true); - else if (option == "italic") + else if (option == wxT("italic")) StyleSetItalic(styleNum, true); - else if (option == "underline") + else if (option == wxT("underline")) StyleSetUnderline(styleNum, true); - else if (option == "eol") + else if (option == wxT("eol")) StyleSetEOLFilled(styleNum, true); - else if (option == "size") { + else if (option == wxT("size")) { long points; if (val.ToLong(&points)) StyleSetSize(styleNum, points); } - else if (option == "face") + else if (option == wxT("face")) StyleSetFaceName(styleNum, val); - else if (option == "fore") + else if (option == wxT("fore")) StyleSetForeground(styleNum, wxColourFromSpec(val)); - else if (option == "back") + else if (option == wxT("back")) StyleSetBackground(styleNum, wxColourFromSpec(val)); } } @@ -1801,12 +1861,23 @@ void wxStyledTextCtrl::OnScrollWin(wxScrollWinEvent& evt) { m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); } +void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) { + wxScrollBar* sb = wxDynamicCast(evt.GetEventObject(), wxScrollBar); + if (sb) { + if (sb->IsVertical()) + m_swx->DoVScroll(evt.GetEventType(), evt.GetPosition()); + else + m_swx->DoHScroll(evt.GetEventType(), evt.GetPosition()); + } +} + void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { wxSize sz = GetClientSize(); m_swx->DoSize(sz.x, sz.y); } void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { + SetFocus(); wxPoint pt = evt.GetPosition(); m_swx->DoButtonDown(Point(pt.x, pt.y), m_stopWatch.Time(), evt.ShiftDown(), evt.ControlDown(), evt.AltDown()); @@ -1824,6 +1895,12 @@ void wxStyledTextCtrl::OnMouseLeftUp(wxMouseEvent& evt) { } +void wxStyledTextCtrl::OnMouseRightUp(wxMouseEvent& evt) { + wxPoint pt = evt.GetPosition(); + m_swx->DoContextMenu(Point(pt.x, pt.y)); +} + + void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { wxPoint pt = evt.GetPosition(); ScreenToClient(&pt.x, &pt.y); @@ -1835,18 +1912,13 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { m_swx->DoMouseWheel(evt.GetWheelRotation(), evt.GetWheelDelta(), evt.GetLinesPerAction(), - evt.ControlDown()); + evt.ControlDown(), + evt.IsPageScroll()); } void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { - long key = evt.KeyCode(); - -// printf("OnChar key:%d consumed:%d ctrl:%d alt:%d\n", -// key, m_lastKeyDownConsumed, evt.ControlDown(), evt.AltDown()); - - // AltGr keys??? - // \|@#¬[]{}?£$~ ã,õ,Ã,Õ, ñ, Ñ + int key = evt.GetKeyCode(); // On (some?) non-US keyboards the AltGr key is required to enter some // common characters. It comes to us as both Alt and Ctrl down so we need @@ -1856,7 +1928,10 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { bool alt = evt.AltDown(); bool skip = ((ctrl || alt) && ! (ctrl && alt)); - if (key <= 0xff && !iscntrl(key) && !m_lastKeyDownConsumed && !skip) { +// printf("OnChar key:%d consumed:%d ctrl:%d alt:%d skip:%d\n", +// key, m_lastKeyDownConsumed, ctrl, alt, skip); + + if (key <= WXK_START && /*key >= 32 &&*/ !m_lastKeyDownConsumed && !skip) { m_swx->DoAddChar(key); return; } @@ -1865,15 +1940,15 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { - long key = evt.KeyCode(); + int key = evt.GetKeyCode(); bool shift = evt.ShiftDown(), - ctrl = evt.ControlDown(), - alt = evt.AltDown(); + ctrl = evt.ControlDown(), + alt = evt.AltDown(); int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, &m_lastKeyDownConsumed); -// printf("key: %d shift: %d ctrl: %d alt: %d processed: %d consumed: %d\n", -// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); +// printf("KeyDn key:%d shift:%d ctrl:%d alt:%d processed:%d consumed:%d\n", +// key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); if (!processed && !m_lastKeyDownConsumed) evt.Skip(); @@ -1966,8 +2041,14 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { case SCN_MODIFIED: evt.SetEventType(wxEVT_STC_MODIFIED); evt.SetModificationType(scn.modificationType); - if (scn.text) - evt.SetText(wxString(scn.text, scn.length)); + if (scn.text) { + // The unicode conversion MUST have a null byte to terminate the + // string so move it into a buffer first and give it one. + wxMemoryBuffer buf(scn.length+1); + buf.AppendData((void*)scn.text, scn.length); + buf.AppendByte(0); + evt.SetText(stc2wx(buf)); + } evt.SetLength(scn.length); evt.SetLinesAdded(scn.linesAdded); evt.SetLine(scn.line); @@ -1992,10 +2073,6 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { evt.SetLength(scn.length); break; - case SCN_POSCHANGED: - evt.SetEventType(wxEVT_STC_POSCHANGED); - break; - case SCN_PAINTED: evt.SetEventType(wxEVT_STC_PAINTED); break; @@ -2054,8 +2131,8 @@ wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) m_listType = 0; m_x = 0; m_y = 0; -#if wxUSE_DRAG_AND_DROP m_dragAllowMove = FALSE; +#if wxUSE_DRAG_AND_DROP m_dragResult = wxDragNone; #endif } @@ -2064,35 +2141,35 @@ 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; - - o->m_listType = m_listType; - o->m_x = m_x; - o->m_y = m_y; +wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): + wxCommandEvent(event) +{ + m_position = event.m_position; + m_key = event.m_key; + m_modifiers = event.m_modifiers; + m_modificationType = event.m_modificationType; + m_text = event.m_text; + m_length = event.m_length; + m_linesAdded = event.m_linesAdded; + m_line = event.m_line; + m_foldLevelNow = event.m_foldLevelNow; + m_foldLevelPrev = event.m_foldLevelPrev; + + m_margin = event.m_margin; + + m_message = event.m_message; + m_wParam = event.m_wParam; + m_lParam = event.m_lParam; + + m_listType = event.m_listType; + m_x = event.m_x; + m_y = event.m_y; + + m_dragText = event.m_dragText; + m_dragAllowMove =event.m_dragAllowMove; #if wxUSE_DRAG_AND_DROP - o->m_dragText = m_dragText; - o->m_dragAllowMove =m_dragAllowMove; - o->m_dragResult = m_dragResult; + m_dragResult = event.m_dragResult; #endif } @@ -2102,3 +2179,8 @@ void wxStyledTextEvent::CopyObject(wxObject& obj) const { + + + + +