X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0b9dfbc00e0251cdabc4c1a8d5c67bf28e8b28b2..7e48d7d9fb4b546e6a68239e8a77ce7ef79df3b0:/src/stc/stc.cpp diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index 6c468c320f..39cbba6900 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -27,6 +27,38 @@ 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; +} + + +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 ) DEFINE_EVENT_TYPE( wxEVT_STC_CHARADDED ) @@ -57,13 +89,13 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) 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) -#ifdef __WXGTK__ +#if defined(__WXGTK__) || defined(__WXMAC__) EVT_RIGHT_UP (wxStyledTextCtrl::OnMouseRightUp) #else EVT_CONTEXT_MENU (wxStyledTextCtrl::OnContextMenu) @@ -75,7 +107,7 @@ BEGIN_EVENT_TABLE(wxStyledTextCtrl, wxControl) EVT_SET_FOCUS (wxStyledTextCtrl::OnGainFocus) EVT_SYS_COLOUR_CHANGED (wxStyledTextCtrl::OnSysColourChanged) EVT_ERASE_BACKGROUND (wxStyledTextCtrl::OnEraseBackground) - EVT_MENU_RANGE (-1, -1, wxStyledTextCtrl::OnMenu) + EVT_MENU_RANGE (10, 16, wxStyledTextCtrl::OnMenu) EVT_LISTBOX_DCLICK (-1, wxStyledTextCtrl::OnListBox) END_EVENT_TABLE() @@ -125,36 +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" - 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); -} - //---------------------------------------------------------------------- // BEGIN generated section. The following code is automatically generated @@ -164,7 +166,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 +177,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 @@ -195,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 @@ -210,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 @@ -328,7 +330,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 +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)(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 +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)(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 +699,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 +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)(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 +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)(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 +758,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 +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)(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 @@ -944,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*)(const char*)text.mb_str(wxConvUTF8); + wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text); + ft.lpstrText = (char*)(const char*)buf; return SendMsg(2150, flags, (long)&ft); } @@ -1004,7 +1003,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 +1055,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 +1076,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 +1106,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 +1156,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 +1167,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 +1222,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 +1234,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 +1243,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 +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)(const char*)definition.mb_str(wxConvUTF8)); + SendMsg(2200, pos, (long)(const char*)wx2stc(definition)); } // Remove the call tip from the screen. @@ -1517,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)(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. @@ -1566,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. @@ -1700,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)(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 @@ -1738,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)); } } @@ -1875,10 +1874,10 @@ void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) { void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { wxSize sz = GetClientSize(); m_swx->DoSize(sz.x, sz.y); - Refresh(FALSE); } 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()); @@ -1913,7 +1912,8 @@ void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt) { m_swx->DoMouseWheel(evt.GetWheelRotation(), evt.GetWheelDelta(), evt.GetLinesPerAction(), - evt.ControlDown()); + evt.ControlDown(), + evt.IsPageScroll()); } @@ -1928,8 +1928,8 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { bool alt = evt.AltDown(); bool skip = ((ctrl || alt) && ! (ctrl && alt)); - //printf("OnChar key:%d consumed:%d ctrl:%d alt:%d skip:%d\n", - // key, m_lastKeyDownConsumed, ctrl, alt, 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); @@ -1947,8 +1947,8 @@ void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { 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(); @@ -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); @@ -2132,7 +2132,9 @@ wxStyledTextEvent::wxStyledTextEvent(wxEventType commandType, int id) m_x = 0; m_y = 0; m_dragAllowMove = FALSE; +#if wxUSE_DRAG_AND_DROP m_dragResult = wxDragNone; +#endif } bool wxStyledTextEvent::GetShift() const { return (m_modifiers & SCI_SHIFT) != 0; } @@ -2166,7 +2168,9 @@ wxStyledTextEvent::wxStyledTextEvent(const wxStyledTextEvent& event): m_dragText = event.m_dragText; m_dragAllowMove =event.m_dragAllowMove; +#if wxUSE_DRAG_AND_DROP m_dragResult = event.m_dragResult; +#endif } //----------------------------------------------------------------------