Extend FindText() to return end position of matched text in wxSTC

New 5th parameter of FindText() can be used to receive the end position of matched text returned by SCI_FINDTEXT API.

Closes #17305.
Closes https://github.com/wxWidgets/wxWidgets/pull/23
This commit is contained in:
New Pagodi
2017-03-13 20:21:41 +01:00
committed by Artur Wieczorek
parent 187c4692c8
commit 91a2869b0e
6 changed files with 64 additions and 15 deletions

View File

@@ -130,6 +130,8 @@ All (GUI):
- Fix drawing filled arc with wxPostScriptDC::DrawArc().
- Optimize PostScript code emitted by wxPostScriptDC to draw elliptic arcs.
- Add wxStyledTextCtrl::AutoCompGetCurrentText() (NewPagodi).
- Extend wxStyledTextCtrl::FindText() to return end position of matched
text (NewPagodi).
wxGTK:

View File

@@ -3555,7 +3555,8 @@ public:
int GetPrintColourMode() const;
// Find some text in the document.
int FindText(int minPos, int maxPos, const wxString& text, int flags=0);
int FindText(int minPos, int maxPos, const wxString& text, int flags=0,
int* findEnd=NULL);
// On Windows, will draw the document into a display context such as a printer.
int FormatRange(bool doDraw,

View File

@@ -3091,10 +3091,32 @@ public:
/**
Find some text in the document.
The fourth argument should be a bit list containing one or more of the
@link wxStyledTextCtrl::wxSTC_FIND_WHOLEWORD wxSTC_FIND_* @endlink constants.
@param minPos
The position (starting from zero) in the document at which to begin
the search
@param maxPos
The last position (starting from zero) in the document to which
the search will be restricted.
@param text
The text to search for.
@param flags
(Optional) The search flags. This should be a bit list containing
one or more of the @link wxStyledTextCtrl::wxSTC_FIND_WHOLEWORD
wxSTC_FIND_* @endlink constants.
@param findEnd
(Optional) This parameter can optionally be used to receive the
end position (starting from zero) of the found text. This is
primarily needed when searching using regular expressions.
This parameter is available since wxWidgets 3.1.1.
@return
The position (starting from zero) in the document at which the text
was found or wxSTC_INVALID_POSITION if the search fails.
@remarks
A backwards search can be performed by setting minPos to be greater
than maxPos.
*/
int FindText(int minPos, int maxPos, const wxString& text, int flags=0);
int FindText(int minPos, int maxPos, const wxString& text, int flags=0,
int* findEnd=NULL);
/**
Sets the position that starts the target which is used for updating the

View File

@@ -1225,8 +1225,29 @@ extendedDocs = {
('The input should be a time in milliseconds or wxSTC_TIME_FOREVER.',),
'FindText':
('The fourth argument should be a bit list containing one or more of the',
'@link wxStyledTextCtrl::wxSTC_FIND_WHOLEWORD wxSTC_FIND_* @endlink constants.',),
('@param minPos',
' The position (starting from zero) in the document at which to begin',
' the search',
'@param maxPos',
' The last position (starting from zero) in the document to which',
' the search will be restricted.',
'@param text',
' The text to search for.',
'@param flags',
' (Optional) The search flags. This should be a bit list containing',
' one or more of the @link wxStyledTextCtrl::wxSTC_FIND_WHOLEWORD',
' wxSTC_FIND_* @endlink constants.',
'@param findEnd',
' (Optional) This parameter can optionally be used to receive the',
' end position (starting from zero) of the found text. This is',
' primarily needed when searching using regular expressions.',
' This parameter is available since wxWidgets 3.1.1.',
'@return',
' The position (starting from zero) in the document at which the text',
' was found or wxSTC_INVALID_POSITION if the search fails.',
'@remarks',
' A backwards search can be performed by setting minPos to be greater',
' than maxPos.',),
'AddUndoAction':
('The flags argument can be either 0 or wxSTC_UNDO_MAY_COALESCE.',),

View File

@@ -580,18 +580,20 @@ methodOverrideMap = {
'FindText' :
(0,
'''int %s(int minPos, int maxPos, const wxString& text, int flags=0);''',
'''int %s(int minPos, int maxPos, const wxString& text, int flags=0,
int* findEnd=NULL);''',
'''int %s(int minPos, int maxPos,
const wxString& text,
int flags) {
'''int %s(int minPos, int maxPos, const wxString& text,
int flags, int* findEnd) {
Sci_TextToFind ft;
ft.chrg.cpMin = minPos;
ft.chrg.cpMax = maxPos;
const wxWX2MBbuf buf = wx2stc(text);
ft.lpstrText = (char*)(const char*)buf;
return SendMsg(%s, flags, (sptr_t)&ft);'''
int pos = SendMsg(%s, flags, (sptr_t)&ft);
if (findEnd) *findEnd=(pos==-1?wxSTC_INVALID_POSITION:ft.chrgText.cpMax);
return pos;'''
),
'FormatRange' :

View File

@@ -1704,16 +1704,17 @@ int wxStyledTextCtrl::GetPrintColourMode() const
}
// Find some text in the document.
int wxStyledTextCtrl::FindText(int minPos, int maxPos,
const wxString& text,
int flags) {
int wxStyledTextCtrl::FindText(int minPos, int maxPos, const wxString& text,
int flags, int* findEnd) {
Sci_TextToFind ft;
ft.chrg.cpMin = minPos;
ft.chrg.cpMax = maxPos;
const wxWX2MBbuf buf = wx2stc(text);
ft.lpstrText = (char*)(const char*)buf;
return SendMsg(SCI_FINDTEXT, flags, (sptr_t)&ft);
int pos = SendMsg(SCI_FINDTEXT, flags, (sptr_t)&ft);
if (findEnd) *findEnd=(pos==-1?wxSTC_INVALID_POSITION:ft.chrgText.cpMax);
return pos;
}
// On Windows, will draw the document into a display context such as a printer.