From 0c5b83b0fa94deaa77ff72760bb9ba0e51a03202 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 13 May 2002 23:31:02 +0000 Subject: [PATCH] Added some inline helpers so the dependence on wxUSE_UNICODE and wxUSE_WCHAR_T can be localized instead of having #if's all over the place. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15545 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/stc/stc.h | 33 ++++++++++++++++++++ contrib/src/stc/PlatWX.cpp | 39 ++++++++---------------- contrib/src/stc/ScintillaWX.cpp | 10 +++--- contrib/src/stc/gen_iface.py | 22 +++++++------- contrib/src/stc/stc.cpp | 54 ++++++++++++++++----------------- contrib/src/stc/stc.cpp.in | 2 +- contrib/src/stc/stc.h.in | 33 ++++++++++++++++++++ include/wx/stc/stc.h | 33 ++++++++++++++++++++ src/stc/PlatWX.cpp | 39 ++++++++---------------- src/stc/ScintillaWX.cpp | 10 +++--- src/stc/gen_iface.py | 22 +++++++------- src/stc/stc.cpp | 54 ++++++++++++++++----------------- src/stc/stc.cpp.in | 2 +- src/stc/stc.h.in | 33 ++++++++++++++++++++ 14 files changed, 246 insertions(+), 140 deletions(-) diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index 62bc6db594..4512d0a592 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -2031,6 +2031,39 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #endif //---------------------------------------------------------------------- +// Utility functions used within wxSTC + +#ifndef SWIG + +inline wxString stc2wx(const char* str) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8); +#else + return wxString(str); +#endif +} + +inline wxString stc2wx(const char* str, size_t len) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8, len); +#else + return wxString(str, len); +#endif +} + +#if wxUSE_UNICODE +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mb_str(wxConvUTF8); +} +#else +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mbc_str(); +} +#endif + +#endif + + //---------------------------------------------------------------------- #endif diff --git a/contrib/src/stc/PlatWX.cpp b/contrib/src/stc/PlatWX.cpp index 9e477cc58a..d23d0a981b 100644 --- a/contrib/src/stc/PlatWX.cpp +++ b/contrib/src/stc/PlatWX.cpp @@ -187,7 +187,7 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, false, - wxString(faceName, wxConvUTF8), + stc2wx(faceName), encoding); } @@ -393,12 +393,9 @@ void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, int ybase, hdc->SetTextBackground(wxColourFromCA(back)); FillRectangle(rc, back); - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(str, rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); } void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, @@ -410,11 +407,8 @@ void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, FillRectangle(rc, back); hdc->SetClippingRegion(wxRectFromPRectangle(rc)); - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - // see comments above - hdc->DrawText(str, rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); hdc->DestroyClippingRegion(); } @@ -423,17 +417,13 @@ int SurfaceImpl::WidthText(Font &font, const char *s, int len) { int w; int h; - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - - hdc->GetTextExtent(str, &w, &h); + hdc->GetTextExtent(stc2wx(s, len), &w, &h); return w; } void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) { - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); + wxString str = stc2wx(s, len); SetFont(font); // Calculate the position of each character based on the widths of @@ -481,9 +471,7 @@ int SurfaceImpl::WidthChar(Font &font, char ch) { int h; char s[2] = { ch, 0 }; - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, 1); - hdc->GetTextExtent(str, &w, &h); + hdc->GetTextExtent(stc2wx(s, 1), &w, &h); return w; } @@ -643,9 +631,7 @@ void Window::SetCursor(Cursor curs) { void Window::SetTitle(const char *s) { - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8); - GETWIN(id)->SetTitle(str); + GETWIN(id)->SetTitle(stc2wx(s)); } @@ -807,7 +793,7 @@ int ListBox::Find(const char *prefix) { void ListBox::GetValue(int n, char *value, int len) { wxString text = GETLB(id)->GetString(n); - strncpy(value, text.mb_str(wxConvUTF8), len); + strncpy(value, wx2stc(text), len); value[len-1] = '\0'; } @@ -864,7 +850,7 @@ unsigned int Platform::DoubleClickTime() { } void Platform::DebugDisplay(const char *s) { - wxLogDebug(wxString(s, *wxConvCurrent)); + wxLogDebug(stc2wx(s)); } bool Platform::IsKeyDown(int key) { @@ -923,9 +909,10 @@ void Platform::Assert(const char *c, const char *file, int line) { char buffer[2000]; sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); if (assertionPopUps) { - int idButton = wxMessageBox(wxString(buffer, *wxConvCurrent), - wxT("Assertion failure"), - wxICON_HAND | wxOK); + /*int idButton = */ + wxMessageBox(stc2wx(buffer), + wxT("Assertion failure"), + wxICON_HAND | wxOK); // if (idButton == IDRETRY) { // ::DebugBreak(); // } else if (idButton == IDIGNORE) { diff --git a/contrib/src/stc/ScintillaWX.cpp b/contrib/src/stc/ScintillaWX.cpp index 8a2c4d27b1..a633e35e70 100644 --- a/contrib/src/stc/ScintillaWX.cpp +++ b/contrib/src/stc/ScintillaWX.cpp @@ -172,7 +172,7 @@ void ScintillaWX::Finalise() { void ScintillaWX::StartDrag() { #if wxUSE_DRAG_AND_DROP - wxString dragText(drag.s, wxConvUTF8, drag.len); + wxString dragText = stc2wx(drag.s, drag.len); // Send an event to allow the drag text to be changed wxStyledTextEvent evt(wxEVT_STC_START_DRAG, stc->GetId()); @@ -320,7 +320,7 @@ void ScintillaWX::Copy() { SelectionText st; CopySelectionRange(&st); wxTheClipboard->Open(); - wxString text(st.s, wxConvUTF8, st.len); + wxString text = stc2wx(st.s, st.len); wxTheClipboard->SetData(new wxTextDataObject(text)); wxTheClipboard->Close(); } @@ -338,7 +338,7 @@ void ScintillaWX::Paste() { gotData = wxTheClipboard->GetData(data); wxTheClipboard->Close(); if (gotData) { - wxWX2MBbuf buf = (wxWX2MBbuf)data.GetText().mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText()); int len = strlen(buf); pdoc->InsertString(currentPos, buf, len); SetEmptySelection(currentPos + len); @@ -370,7 +370,7 @@ void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) { if (!label[0]) ((wxMenu*)popup.GetID())->AppendSeparator(); else - ((wxMenu*)popup.GetID())->Append(cmd, wxString(label, *wxConvCurrent)); + ((wxMenu*)popup.GetID())->Append(cmd, stc2wx(label)); if (!enabled) ((wxMenu*)popup.GetID())->Enable(cmd, enabled); @@ -601,7 +601,7 @@ bool ScintillaWX::DoDropText(long x, long y, const wxString& data) { dragResult = evt.GetDragResult(); if (dragResult == wxDragMove || dragResult == wxDragCopy) { DropAt(evt.GetPosition(), - evt.GetDragText().mb_str(wxConvUTF8), + wx2stc(evt.GetDragText()), dragResult == wxDragMove, FALSE); // TODO: rectangular? return TRUE; diff --git a/contrib/src/stc/gen_iface.py b/contrib/src/stc/gen_iface.py index 8de2af862f..b85de2fa9f 100644 --- a/contrib/src/stc/gen_iface.py +++ b/contrib/src/stc/gen_iface.py @@ -68,7 +68,7 @@ methodOverrideMap = { 'void %s(const wxString& text);', '''void %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -130,7 +130,7 @@ methodOverrideMap = { mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); if (linePos) *linePos = pos; - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', 0), @@ -249,7 +249,7 @@ methodOverrideMap = { flags |= wholeWord ? SCFIND_WHOLEWORD : 0; ft.chrg.cpMin = minPos; ft.chrg.cpMax = maxPos; - ft.lpstrText = (char*)(const char*)text.mb_str(wxConvUTF8); + ft.lpstrText = (char*)(const char*)wx2stc(text); return SendMsg(%s, flags, (long)&ft);''', 0), @@ -305,7 +305,7 @@ methodOverrideMap = { SendMsg(%s, line, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve the contents of a line.',)), @@ -326,7 +326,7 @@ methodOverrideMap = { SendMsg(%s, 0, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve the selected text.',)), @@ -350,7 +350,7 @@ methodOverrideMap = { SendMsg(%s, 0, (long)&tr); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve a range of text.',)), @@ -371,7 +371,7 @@ methodOverrideMap = { SendMsg(%s, len+1, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve all the text in the document.', )), @@ -388,7 +388,7 @@ methodOverrideMap = { ''' int %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -397,7 +397,7 @@ methodOverrideMap = { ''' int %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -406,7 +406,7 @@ methodOverrideMap = { ''' int %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -662,7 +662,7 @@ def makeArgString(param): typ, name = param if typ == 'string': - return '(long)(const char*)%s.mb_str(wxConvUTF8)' % name + return '(long)(const char*)wx2stc(%s)' % name if typ == 'colour': return 'wxColourAsLong(%s)' % name diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index 6c468c320f..b763cac229 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -164,7 +164,7 @@ static wxColour wxColourFromSpec(const wxString& spec) { // Add text to the document void wxStyledTextCtrl::AddText(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); SendMsg(2001, strlen(buf), (long)(const char*)buf); } @@ -175,7 +175,7 @@ void wxStyledTextCtrl::AddStyledText(const wxMemoryBuffer& data) { // Insert string at a position void wxStyledTextCtrl::InsertText(int pos, const wxString& text) { - SendMsg(2003, pos, (long)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2003, pos, (long)(const char*)wx2stc(text)); } // Delete all text in the document @@ -328,7 +328,7 @@ wxString wxStyledTextCtrl::GetCurLine(int* linePos) { mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); if (linePos) *linePos = pos; - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Retrieve the position of the last correctly styled character. @@ -523,7 +523,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)(const char*)fontName.mb_str(wxConvUTF8)); + SendMsg(2056, style, (long)(const char*)wx2stc(fontName)); } // Set a style to have its end of line filled or not. @@ -604,7 +604,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)(const char*)characters.mb_str(wxConvUTF8)); + SendMsg(2077, 0, (long)(const char*)wx2stc(characters)); } // Start a sequence of actions that is undone and redone as a unit. @@ -697,7 +697,7 @@ void wxStyledTextCtrl::StyleSetChangeable(int style, bool changeable) { // 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)(const char*)itemList.mb_str(wxConvUTF8)); + SendMsg(2100, lenEntered, (long)(const char*)wx2stc(itemList)); } // Remove the auto-completion list from the screen. @@ -723,7 +723,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)(const char*)characterSet.mb_str(wxConvUTF8)); + SendMsg(2105, 0, (long)(const char*)wx2stc(characterSet)); } // Change the separator character in the string setting up an auto-completion @@ -739,7 +739,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)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2108, 0, (long)(const char*)wx2stc(text)); } // Should the auto-completion list be cancelled if the user backspaces to a @@ -756,7 +756,7 @@ bool wxStyledTextCtrl::AutoCompGetCancelAtStart() { // 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)(const char*)characterSet.mb_str(wxConvUTF8)); + SendMsg(2112, 0, (long)(const char*)wx2stc(characterSet)); } // Should a single item auto-completion list automatically choose the item. @@ -781,7 +781,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)(const char*)itemList.mb_str(wxConvUTF8)); + SendMsg(2117, listType, (long)(const char*)wx2stc(itemList)); } // Set whether or not autocompletion is hidden automatically when nothing matches @@ -953,7 +953,7 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos, flags |= wholeWord ? SCFIND_WHOLEWORD : 0; ft.chrg.cpMin = minPos; ft.chrg.cpMax = maxPos; - ft.lpstrText = (char*)(const char*)text.mb_str(wxConvUTF8); + ft.lpstrText = (char*)(const char*)wx2stc(text); return SendMsg(2150, flags, (long)&ft); } @@ -1004,7 +1004,7 @@ wxString wxStyledTextCtrl::GetLine(int line) { SendMsg(2153, line, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Returns the number of lines in the document. There is always at least one. @@ -1056,7 +1056,7 @@ wxString wxStyledTextCtrl::GetSelectedText() { SendMsg(2161, 0, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Retrieve a range of text. @@ -1077,7 +1077,7 @@ wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) { SendMsg(2162, 0, (long)&tr); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Draw the selection in normal style or with selection highlighted. @@ -1107,7 +1107,7 @@ void wxStyledTextCtrl::EnsureCaretVisible() { // Replace the selected text with the argument text. void wxStyledTextCtrl::ReplaceSelection(const wxString& text) { - SendMsg(2170, 0, (long)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2170, 0, (long)(const char*)wx2stc(text)); } // Set to read only or read write. @@ -1157,7 +1157,7 @@ void wxStyledTextCtrl::Clear() { // Replace the contents of the document with the argument text. void wxStyledTextCtrl::SetText(const wxString& text) { - SendMsg(2181, 0, (long)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2181, 0, (long)(const char*)wx2stc(text)); } // Retrieve all the text in the document. @@ -1168,7 +1168,7 @@ wxString wxStyledTextCtrl::GetText() { SendMsg(2182, len+1, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Retrieve the number of characters in the document. @@ -1223,7 +1223,7 @@ int wxStyledTextCtrl::GetTargetEnd() { // Returns the length of the replacement text. int wxStyledTextCtrl::ReplaceTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(2194, strlen(buf), (long)(const char*)buf); } @@ -1235,7 +1235,7 @@ int wxStyledTextCtrl::GetTargetEnd() { // caused by processing the \d patterns. int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(2195, strlen(buf), (long)(const char*)buf); } @@ -1244,7 +1244,7 @@ int wxStyledTextCtrl::GetTargetEnd() { // Returns length of range or -1 for failure in which case target is not moved. int wxStyledTextCtrl::SearchInTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(2197, strlen(buf), (long)(const char*)buf); } @@ -1260,7 +1260,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)(const char*)definition.mb_str(wxConvUTF8)); + SendMsg(2200, pos, (long)(const char*)wx2stc(definition)); } // Remove the call tip from the screen. @@ -1517,13 +1517,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)(const char*)text.mb_str(wxConvUTF8)); + 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)(const char*)text.mb_str(wxConvUTF8)); + return SendMsg(2368, flags, (long)(const char*)wx2stc(text)); } // Set the way the line the caret is on is kept visible. @@ -1700,17 +1700,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)(const char*)key.mb_str(wxConvUTF8), (long)(const char*)value.mb_str(wxConvUTF8)); + 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)(const char*)keyWords.mb_str(wxConvUTF8)); + 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)(const char*)language.mb_str(wxConvUTF8)); + SendMsg(4006, 0, (long)(const char*)wx2stc(language)); } // END of generated section @@ -2047,7 +2047,7 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { wxMemoryBuffer buf(scn.length+1); buf.AppendData((void*)scn.text, scn.length); buf.AppendByte(0); - evt.SetText(wxString(buf, wxConvUTF8)); + evt.SetText(stc2wx(buf)); } evt.SetLength(scn.length); evt.SetLinesAdded(scn.linesAdded); diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in index f6c30c0896..b68d69655d 100644 --- a/contrib/src/stc/stc.cpp.in +++ b/contrib/src/stc/stc.cpp.in @@ -497,7 +497,7 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { wxMemoryBuffer buf(scn.length+1); buf.AppendData((void*)scn.text, scn.length); buf.AppendByte(0); - evt.SetText(wxString(buf, wxConvUTF8)); + evt.SetText(stc2wx(buf)); } evt.SetLength(scn.length); evt.SetLinesAdded(scn.linesAdded); diff --git a/contrib/src/stc/stc.h.in b/contrib/src/stc/stc.h.in index 0e56b08abb..1243324bb9 100644 --- a/contrib/src/stc/stc.h.in +++ b/contrib/src/stc/stc.h.in @@ -381,6 +381,39 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #endif //---------------------------------------------------------------------- +// Utility functions used within wxSTC + +#ifndef SWIG + +inline wxString stc2wx(const char* str) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8); +#else + return wxString(str); +#endif +} + +inline wxString stc2wx(const char* str, size_t len) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8, len); +#else + return wxString(str, len); +#endif +} + +#if wxUSE_UNICODE +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mb_str(wxConvUTF8); +} +#else +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mbc_str(); +} +#endif + +#endif + + //---------------------------------------------------------------------- #endif diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 62bc6db594..4512d0a592 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -2031,6 +2031,39 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #endif //---------------------------------------------------------------------- +// Utility functions used within wxSTC + +#ifndef SWIG + +inline wxString stc2wx(const char* str) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8); +#else + return wxString(str); +#endif +} + +inline wxString stc2wx(const char* str, size_t len) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8, len); +#else + return wxString(str, len); +#endif +} + +#if wxUSE_UNICODE +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mb_str(wxConvUTF8); +} +#else +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mbc_str(); +} +#endif + +#endif + + //---------------------------------------------------------------------- #endif diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 9e477cc58a..d23d0a981b 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -187,7 +187,7 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, false, - wxString(faceName, wxConvUTF8), + stc2wx(faceName), encoding); } @@ -393,12 +393,9 @@ void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, int ybase, hdc->SetTextBackground(wxColourFromCA(back)); FillRectangle(rc, back); - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(str, rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); } void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, @@ -410,11 +407,8 @@ void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, FillRectangle(rc, back); hdc->SetClippingRegion(wxRectFromPRectangle(rc)); - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - // see comments above - hdc->DrawText(str, rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); hdc->DestroyClippingRegion(); } @@ -423,17 +417,13 @@ int SurfaceImpl::WidthText(Font &font, const char *s, int len) { int w; int h; - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - - hdc->GetTextExtent(str, &w, &h); + hdc->GetTextExtent(stc2wx(s, len), &w, &h); return w; } void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) { - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); + wxString str = stc2wx(s, len); SetFont(font); // Calculate the position of each character based on the widths of @@ -481,9 +471,7 @@ int SurfaceImpl::WidthChar(Font &font, char ch) { int h; char s[2] = { ch, 0 }; - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, 1); - hdc->GetTextExtent(str, &w, &h); + hdc->GetTextExtent(stc2wx(s, 1), &w, &h); return w; } @@ -643,9 +631,7 @@ void Window::SetCursor(Cursor curs) { void Window::SetTitle(const char *s) { - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8); - GETWIN(id)->SetTitle(str); + GETWIN(id)->SetTitle(stc2wx(s)); } @@ -807,7 +793,7 @@ int ListBox::Find(const char *prefix) { void ListBox::GetValue(int n, char *value, int len) { wxString text = GETLB(id)->GetString(n); - strncpy(value, text.mb_str(wxConvUTF8), len); + strncpy(value, wx2stc(text), len); value[len-1] = '\0'; } @@ -864,7 +850,7 @@ unsigned int Platform::DoubleClickTime() { } void Platform::DebugDisplay(const char *s) { - wxLogDebug(wxString(s, *wxConvCurrent)); + wxLogDebug(stc2wx(s)); } bool Platform::IsKeyDown(int key) { @@ -923,9 +909,10 @@ void Platform::Assert(const char *c, const char *file, int line) { char buffer[2000]; sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); if (assertionPopUps) { - int idButton = wxMessageBox(wxString(buffer, *wxConvCurrent), - wxT("Assertion failure"), - wxICON_HAND | wxOK); + /*int idButton = */ + wxMessageBox(stc2wx(buffer), + wxT("Assertion failure"), + wxICON_HAND | wxOK); // if (idButton == IDRETRY) { // ::DebugBreak(); // } else if (idButton == IDIGNORE) { diff --git a/src/stc/ScintillaWX.cpp b/src/stc/ScintillaWX.cpp index 8a2c4d27b1..a633e35e70 100644 --- a/src/stc/ScintillaWX.cpp +++ b/src/stc/ScintillaWX.cpp @@ -172,7 +172,7 @@ void ScintillaWX::Finalise() { void ScintillaWX::StartDrag() { #if wxUSE_DRAG_AND_DROP - wxString dragText(drag.s, wxConvUTF8, drag.len); + wxString dragText = stc2wx(drag.s, drag.len); // Send an event to allow the drag text to be changed wxStyledTextEvent evt(wxEVT_STC_START_DRAG, stc->GetId()); @@ -320,7 +320,7 @@ void ScintillaWX::Copy() { SelectionText st; CopySelectionRange(&st); wxTheClipboard->Open(); - wxString text(st.s, wxConvUTF8, st.len); + wxString text = stc2wx(st.s, st.len); wxTheClipboard->SetData(new wxTextDataObject(text)); wxTheClipboard->Close(); } @@ -338,7 +338,7 @@ void ScintillaWX::Paste() { gotData = wxTheClipboard->GetData(data); wxTheClipboard->Close(); if (gotData) { - wxWX2MBbuf buf = (wxWX2MBbuf)data.GetText().mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(data.GetText()); int len = strlen(buf); pdoc->InsertString(currentPos, buf, len); SetEmptySelection(currentPos + len); @@ -370,7 +370,7 @@ void ScintillaWX::AddToPopUp(const char *label, int cmd, bool enabled) { if (!label[0]) ((wxMenu*)popup.GetID())->AppendSeparator(); else - ((wxMenu*)popup.GetID())->Append(cmd, wxString(label, *wxConvCurrent)); + ((wxMenu*)popup.GetID())->Append(cmd, stc2wx(label)); if (!enabled) ((wxMenu*)popup.GetID())->Enable(cmd, enabled); @@ -601,7 +601,7 @@ bool ScintillaWX::DoDropText(long x, long y, const wxString& data) { dragResult = evt.GetDragResult(); if (dragResult == wxDragMove || dragResult == wxDragCopy) { DropAt(evt.GetPosition(), - evt.GetDragText().mb_str(wxConvUTF8), + wx2stc(evt.GetDragText()), dragResult == wxDragMove, FALSE); // TODO: rectangular? return TRUE; diff --git a/src/stc/gen_iface.py b/src/stc/gen_iface.py index 8de2af862f..b85de2fa9f 100644 --- a/src/stc/gen_iface.py +++ b/src/stc/gen_iface.py @@ -68,7 +68,7 @@ methodOverrideMap = { 'void %s(const wxString& text);', '''void %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -130,7 +130,7 @@ methodOverrideMap = { mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); if (linePos) *linePos = pos; - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', 0), @@ -249,7 +249,7 @@ methodOverrideMap = { flags |= wholeWord ? SCFIND_WHOLEWORD : 0; ft.chrg.cpMin = minPos; ft.chrg.cpMax = maxPos; - ft.lpstrText = (char*)(const char*)text.mb_str(wxConvUTF8); + ft.lpstrText = (char*)(const char*)wx2stc(text); return SendMsg(%s, flags, (long)&ft);''', 0), @@ -305,7 +305,7 @@ methodOverrideMap = { SendMsg(%s, line, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve the contents of a line.',)), @@ -326,7 +326,7 @@ methodOverrideMap = { SendMsg(%s, 0, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve the selected text.',)), @@ -350,7 +350,7 @@ methodOverrideMap = { SendMsg(%s, 0, (long)&tr); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve a range of text.',)), @@ -371,7 +371,7 @@ methodOverrideMap = { SendMsg(%s, len+1, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8);''', + return stc2wx(buf);''', ('Retrieve all the text in the document.', )), @@ -388,7 +388,7 @@ methodOverrideMap = { ''' int %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -397,7 +397,7 @@ methodOverrideMap = { ''' int %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -406,7 +406,7 @@ methodOverrideMap = { ''' int %s(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(%s, strlen(buf), (long)(const char*)buf);''', 0), @@ -662,7 +662,7 @@ def makeArgString(param): typ, name = param if typ == 'string': - return '(long)(const char*)%s.mb_str(wxConvUTF8)' % name + return '(long)(const char*)wx2stc(%s)' % name if typ == 'colour': return 'wxColourAsLong(%s)' % name diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 6c468c320f..b763cac229 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -164,7 +164,7 @@ static wxColour wxColourFromSpec(const wxString& spec) { // Add text to the document void wxStyledTextCtrl::AddText(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); SendMsg(2001, strlen(buf), (long)(const char*)buf); } @@ -175,7 +175,7 @@ void wxStyledTextCtrl::AddStyledText(const wxMemoryBuffer& data) { // Insert string at a position void wxStyledTextCtrl::InsertText(int pos, const wxString& text) { - SendMsg(2003, pos, (long)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2003, pos, (long)(const char*)wx2stc(text)); } // Delete all text in the document @@ -328,7 +328,7 @@ wxString wxStyledTextCtrl::GetCurLine(int* linePos) { mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); if (linePos) *linePos = pos; - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Retrieve the position of the last correctly styled character. @@ -523,7 +523,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)(const char*)fontName.mb_str(wxConvUTF8)); + SendMsg(2056, style, (long)(const char*)wx2stc(fontName)); } // Set a style to have its end of line filled or not. @@ -604,7 +604,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)(const char*)characters.mb_str(wxConvUTF8)); + SendMsg(2077, 0, (long)(const char*)wx2stc(characters)); } // Start a sequence of actions that is undone and redone as a unit. @@ -697,7 +697,7 @@ void wxStyledTextCtrl::StyleSetChangeable(int style, bool changeable) { // 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)(const char*)itemList.mb_str(wxConvUTF8)); + SendMsg(2100, lenEntered, (long)(const char*)wx2stc(itemList)); } // Remove the auto-completion list from the screen. @@ -723,7 +723,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)(const char*)characterSet.mb_str(wxConvUTF8)); + SendMsg(2105, 0, (long)(const char*)wx2stc(characterSet)); } // Change the separator character in the string setting up an auto-completion @@ -739,7 +739,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)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2108, 0, (long)(const char*)wx2stc(text)); } // Should the auto-completion list be cancelled if the user backspaces to a @@ -756,7 +756,7 @@ bool wxStyledTextCtrl::AutoCompGetCancelAtStart() { // 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)(const char*)characterSet.mb_str(wxConvUTF8)); + SendMsg(2112, 0, (long)(const char*)wx2stc(characterSet)); } // Should a single item auto-completion list automatically choose the item. @@ -781,7 +781,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)(const char*)itemList.mb_str(wxConvUTF8)); + SendMsg(2117, listType, (long)(const char*)wx2stc(itemList)); } // Set whether or not autocompletion is hidden automatically when nothing matches @@ -953,7 +953,7 @@ int wxStyledTextCtrl::FindText(int minPos, int maxPos, flags |= wholeWord ? SCFIND_WHOLEWORD : 0; ft.chrg.cpMin = minPos; ft.chrg.cpMax = maxPos; - ft.lpstrText = (char*)(const char*)text.mb_str(wxConvUTF8); + ft.lpstrText = (char*)(const char*)wx2stc(text); return SendMsg(2150, flags, (long)&ft); } @@ -1004,7 +1004,7 @@ wxString wxStyledTextCtrl::GetLine(int line) { SendMsg(2153, line, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Returns the number of lines in the document. There is always at least one. @@ -1056,7 +1056,7 @@ wxString wxStyledTextCtrl::GetSelectedText() { SendMsg(2161, 0, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Retrieve a range of text. @@ -1077,7 +1077,7 @@ wxString wxStyledTextCtrl::GetTextRange(int startPos, int endPos) { SendMsg(2162, 0, (long)&tr); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Draw the selection in normal style or with selection highlighted. @@ -1107,7 +1107,7 @@ void wxStyledTextCtrl::EnsureCaretVisible() { // Replace the selected text with the argument text. void wxStyledTextCtrl::ReplaceSelection(const wxString& text) { - SendMsg(2170, 0, (long)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2170, 0, (long)(const char*)wx2stc(text)); } // Set to read only or read write. @@ -1157,7 +1157,7 @@ void wxStyledTextCtrl::Clear() { // Replace the contents of the document with the argument text. void wxStyledTextCtrl::SetText(const wxString& text) { - SendMsg(2181, 0, (long)(const char*)text.mb_str(wxConvUTF8)); + SendMsg(2181, 0, (long)(const char*)wx2stc(text)); } // Retrieve all the text in the document. @@ -1168,7 +1168,7 @@ wxString wxStyledTextCtrl::GetText() { SendMsg(2182, len+1, (long)buf); mbuf.UngetWriteBuf(len); mbuf.AppendByte(0); - return wxString(buf, wxConvUTF8); + return stc2wx(buf); } // Retrieve the number of characters in the document. @@ -1223,7 +1223,7 @@ int wxStyledTextCtrl::GetTargetEnd() { // Returns the length of the replacement text. int wxStyledTextCtrl::ReplaceTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(2194, strlen(buf), (long)(const char*)buf); } @@ -1235,7 +1235,7 @@ int wxStyledTextCtrl::GetTargetEnd() { // caused by processing the \d patterns. int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(2195, strlen(buf), (long)(const char*)buf); } @@ -1244,7 +1244,7 @@ int wxStyledTextCtrl::GetTargetEnd() { // Returns length of range or -1 for failure in which case target is not moved. int wxStyledTextCtrl::SearchInTarget(const wxString& text) { - wxWX2MBbuf buf = (wxWX2MBbuf)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); return SendMsg(2197, strlen(buf), (long)(const char*)buf); } @@ -1260,7 +1260,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)(const char*)definition.mb_str(wxConvUTF8)); + SendMsg(2200, pos, (long)(const char*)wx2stc(definition)); } // Remove the call tip from the screen. @@ -1517,13 +1517,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)(const char*)text.mb_str(wxConvUTF8)); + 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)(const char*)text.mb_str(wxConvUTF8)); + return SendMsg(2368, flags, (long)(const char*)wx2stc(text)); } // Set the way the line the caret is on is kept visible. @@ -1700,17 +1700,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)(const char*)key.mb_str(wxConvUTF8), (long)(const char*)value.mb_str(wxConvUTF8)); + 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)(const char*)keyWords.mb_str(wxConvUTF8)); + 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)(const char*)language.mb_str(wxConvUTF8)); + SendMsg(4006, 0, (long)(const char*)wx2stc(language)); } // END of generated section @@ -2047,7 +2047,7 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { wxMemoryBuffer buf(scn.length+1); buf.AppendData((void*)scn.text, scn.length); buf.AppendByte(0); - evt.SetText(wxString(buf, wxConvUTF8)); + evt.SetText(stc2wx(buf)); } evt.SetLength(scn.length); evt.SetLinesAdded(scn.linesAdded); diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index f6c30c0896..b68d69655d 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -497,7 +497,7 @@ void wxStyledTextCtrl::NotifyParent(SCNotification* _scn) { wxMemoryBuffer buf(scn.length+1); buf.AppendData((void*)scn.text, scn.length); buf.AppendByte(0); - evt.SetText(wxString(buf, wxConvUTF8)); + evt.SetText(stc2wx(buf)); } evt.SetLength(scn.length); evt.SetLinesAdded(scn.linesAdded); diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index 0e56b08abb..1243324bb9 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -381,6 +381,39 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&); #endif //---------------------------------------------------------------------- +// Utility functions used within wxSTC + +#ifndef SWIG + +inline wxString stc2wx(const char* str) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8); +#else + return wxString(str); +#endif +} + +inline wxString stc2wx(const char* str, size_t len) { +#if wxUSE_UNICODE + return wxString(str, wxConvUTF8, len); +#else + return wxString(str, len); +#endif +} + +#if wxUSE_UNICODE +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mb_str(wxConvUTF8); +} +#else +inline const wxWX2MBbuf wx2stc(const wxString& str) { + return str.mbc_str(); +} +#endif + +#endif + + //---------------------------------------------------------------------- #endif -- 2.45.2