#include "wx/tokenzr.h"
#include "wx/mstream.h"
#include "wx/image.h"
-#include "wx/ffile.h"
+#if wxUSE_FFILE
+ #include "wx/ffile.h"
+#elif wxUSE_FILE
+ #include "wx/ffile.h"
+#endif
#include "ScintillaWX.h"
wxDEFINE_EVENT( wxEVT_STC_INDICATOR_RELEASE, wxStyledTextEvent );
wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CANCELLED, wxStyledTextEvent );
wxDEFINE_EVENT( wxEVT_STC_AUTOCOMP_CHAR_DELETED, wxStyledTextEvent );
+wxDEFINE_EVENT( wxEVT_STC_HOTSPOT_RELEASE_CLICK, wxStyledTextEvent );
m_swx = new ScintillaWX(this);
m_stopWatch.Start();
m_lastKeyDownConsumed = false;
- m_timeToBlockWheelEventsUntil = 0;
m_vScrollBar = NULL;
m_hScrollBar = NULL;
#if wxUSE_UNICODE
SetInitialSize(size);
// Reduces flicker on GTK+/X11
- SetBackgroundStyle(wxBG_STYLE_CUSTOM);
+ SetBackgroundStyle(wxBG_STYLE_PAINT);
// Make sure it can take the focus
SetCanFocus(true);
// Add text to the document at current position.
void wxStyledTextCtrl::AddText(const wxString& text) {
- wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
- SendMsg(2001, strlen(buf), (sptr_t)(const char*)buf);
+ const wxWX2MBbuf buf = wx2stc(text);
+ SendMsg(2001, wx2stclen(text, buf), (sptr_t)(const char*)buf);
}
// Add array of cells to document.
SendMsg(2004, 0, 0);
}
+// Delete a range of text in the document.
+void wxStyledTextCtrl::DeleteRange(int pos, int deleteLength)
+{
+ SendMsg(2645, pos, deleteLength);
+}
+
// Set all style bytes to 0, remove all folding information.
void wxStyledTextCtrl::ClearDocumentStyle()
{
SendMsg(2042, markerNumber, wxColourAsLong(back));
}
+// Set the background colour used for a particular marker number when its folding block is selected.
+void wxStyledTextCtrl::MarkerSetBackgroundSelected(int markerNumber, const wxColour& back)
+{
+ SendMsg(2292, markerNumber, wxColourAsLong(back));
+}
+
+// Enable/disable highlight for current folding bloc (smallest one that contains the caret)
+void wxStyledTextCtrl::MarkerEnableHighlight(bool enabled)
+{
+ SendMsg(2293, enabled, 0);
+}
+
// 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(2046, line, 0);
}
-// Find the next line after lineStart that includes a marker in mask.
+// Find the next line at or after lineStart that includes a marker in mask.
+// Return -1 when no more lines.
int wxStyledTextCtrl::MarkerNext(int lineStart, int markerMask)
{
return SendMsg(2047, lineStart, markerMask);
return SendMsg(2247, margin, 0) != 0;
}
+// Set the cursor shown when the mouse is inside a margin.
+void wxStyledTextCtrl::SetMarginCursor(int margin, int cursor)
+{
+ SendMsg(2248, margin, cursor);
+}
+
+// Retrieve the cursor shown in a margin.
+int wxStyledTextCtrl::GetMarginCursor(int margin) const
+{
+ return SendMsg(2249, margin, 0);
+}
+
// Clear all the styles and make equivalent to the global default style.
void wxStyledTextCtrl::StyleClearAll()
{
SendMsg(2060, style, caseForce);
}
+// Set the size of characters of a style. Size is in points multiplied by 100.
+void wxStyledTextCtrl::StyleSetSizeFractional(int style, int caseForce)
+{
+ SendMsg(2061, style, caseForce);
+}
+
+// Get the size of characters of a style in points multiplied by 100
+int wxStyledTextCtrl::StyleGetSizeFractional(int style) const
+{
+ return SendMsg(2062, style, 0);
+}
+
+// Set the weight of characters of a style.
+void wxStyledTextCtrl::StyleSetWeight(int style, int weight)
+{
+ SendMsg(2063, style, weight);
+}
+
+// Get the weight of characters of a style.
+int wxStyledTextCtrl::StyleGetWeight(int style) const
+{
+ return SendMsg(2064, style, 0);
+}
+
// Set a style to be a hotspot or not.
void wxStyledTextCtrl::StyleSetHotSpot(int style, bool hotspot)
{
SendMsg(2077, 0, (sptr_t)(const char*)wx2stc(characters));
}
+// Get the set of characters making up words for when moving or selecting by word.
+wxString wxStyledTextCtrl::GetWordChars() const {
+ int msg = 2646;
+ int len = SendMsg(msg, 0, (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, 0, (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
// Start a sequence of actions that is undone and redone as a unit.
// May be nested.
void wxStyledTextCtrl::BeginUndoAction()
return SendMsg(2129, pos, 0);
}
+// Count characters between two positions.
+int wxStyledTextCtrl::CountCharacters(int startPos, int endPos)
+{
+ return SendMsg(2633, startPos, endPos);
+}
+
// Show or hide the horizontal scroll bar.
void wxStyledTextCtrl::SetUseHorizontalScrollBar(bool show)
{
return SendMsg(2145, 0, 0);
}
+// Set caret to a position, while removing any existing selection.
+void wxStyledTextCtrl::SetEmptySelection(int pos)
+{
+ SendMsg(2556, pos, 0);
+}
+
// Sets the print magnification added to the point size of each style for printing.
void wxStyledTextCtrl::SetPrintMagnification(int magnification)
{
TextToFind ft;
ft.chrg.cpMin = minPos;
ft.chrg.cpMax = maxPos;
- wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
+ const wxWX2MBbuf buf = wx2stc(text);
ft.lpstrText = (char*)(const char*)buf;
return SendMsg(2150, flags, (sptr_t)&ft);
// Retrieve the selected text.
wxString wxStyledTextCtrl::GetSelectedText() {
- long start;
- long end;
-
- GetSelection(&start, &end);
- int len = end - start;
+ const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
if (!len) return wxEmptyString;
wxMemoryBuffer mbuf(len+2);
// Returns the length of the replacement text.
int wxStyledTextCtrl::ReplaceTarget(const wxString& text) {
- wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
- return SendMsg(2194, strlen(buf), (sptr_t)(const char*)buf);
+ const wxWX2MBbuf buf = wx2stc(text);
+ return SendMsg(2194, wx2stclen(text, buf), (sptr_t)(const char*)buf);
}
// Replace the target text with the argument text after \d processing.
// caused by processing the \d patterns.
int wxStyledTextCtrl::ReplaceTargetRE(const wxString& text) {
- wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
- return SendMsg(2195, strlen(buf), (sptr_t)(const char*)buf);
+ const wxWX2MBbuf buf = wx2stc(text);
+ return SendMsg(2195, wx2stclen(text, buf), (sptr_t)(const char*)buf);
}
// Search for a counted string in the target and set the target to the found
// Returns length of range or -1 for failure in which case target is not moved.
int wxStyledTextCtrl::SearchInTarget(const wxString& text) {
- wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
- return SendMsg(2197, strlen(buf), (sptr_t)(const char*)buf);
+ const wxWX2MBbuf buf = wx2stc(text);
+ return SendMsg(2197, wx2stclen(text, buf), (sptr_t)(const char*)buf);
}
// Set the search flags used by SearchInTarget.
SendMsg(2212, tabSize, 0);
}
+// Set position of calltip, above or below text.
+void wxStyledTextCtrl::CallTipSetPosition(bool above)
+{
+ SendMsg(2213, above, 0);
+}
+
// Find the display line of a document line taking hidden lines into account.
int wxStyledTextCtrl::VisibleFromDocLine(int line)
{
return SendMsg(2228, line, 0) != 0;
}
+// Are all lines visible?
+bool wxStyledTextCtrl::GetAllLinesVisible() const
+{
+ return SendMsg(2236, 0, 0) != 0;
+}
+
// Show the children of a header line.
void wxStyledTextCtrl::SetFoldExpanded(int line, bool expanded)
{
// Append a string to the end of the document without changing the selection.
void wxStyledTextCtrl::AppendText(const wxString& text) {
- wxWX2MBbuf buf = (wxWX2MBbuf)wx2stc(text);
- SendMsg(2282, strlen(buf), (sptr_t)(const char*)buf);
+ const wxWX2MBbuf buf = wx2stc(text);
+ SendMsg(2282, wx2stclen(text, buf), (sptr_t)(const char*)buf);
}
// Is drawing done in two phases with backgrounds drawn before foregrounds?
SendMsg(2613, lineDisplay, 0);
}
+// Change the effect of pasting when there are multiple selections.
+void wxStyledTextCtrl::SetMultiPaste(int multiPaste)
+{
+ SendMsg(2614, multiPaste, 0);
+}
+
+// Retrieve the effect of pasting when there are multiple selections..
+int wxStyledTextCtrl::GetMultiPaste() const
+{
+ return SendMsg(2615, 0, 0);
+}
+
+// Retrieve the value of a tag from a regular expression search.
+wxString wxStyledTextCtrl::GetTag(int tagNumber) const {
+ int msg = 2616;
+ int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, tagNumber, (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
// Make the target range start and end be the same as the selection range start and end.
void wxStyledTextCtrl::TargetFromSelection()
{
SendMsg(2351, pos1, pos2);
}
+// Use specified indicator to highlight matching braces instead of changing their style.
+void wxStyledTextCtrl::BraceHighlightIndicator(bool useBraceHighlightIndicator, int indicator)
+{
+ SendMsg(2498, useBraceHighlightIndicator, indicator);
+}
+
// Highlight the character at a position indicating there is no matching brace.
void wxStyledTextCtrl::BraceBadLight(int pos)
{
SendMsg(2352, pos, 0);
}
+// Use specified indicator to highlight non matching brace instead of changing its style.
+void wxStyledTextCtrl::BraceBadLightIndicator(bool useBraceBadLightIndicator, int indicator)
+{
+ SendMsg(2499, useBraceBadLightIndicator, indicator);
+}
+
// Find the position of a matching brace or INVALID_POSITION if no match.
int wxStyledTextCtrl::BraceMatch(int pos)
{
SendMsg(2396, 0, 0);
}
-// Get and Set the xOffset (ie, horizonal scroll position).
+// Get and Set the xOffset (ie, horizontal scroll position).
void wxStyledTextCtrl::SetXOffset(int newOffset)
{
SendMsg(2397, newOffset, 0);
SendMsg(2399, 0, 0);
}
-// Set the way the caret is kept visible when going sideway.
+// Set the way the caret is kept visible when going sideways.
// The exclusion zone is given in pixels.
void wxStyledTextCtrl::SetXCaretPolicy(int caretPolicy, int caretSlop)
{
SendMsg(2443, 0, (sptr_t)(const char*)wx2stc(characters));
}
+// Get the set of characters making up whitespace for when moving or selecting by word.
+wxString wxStyledTextCtrl::GetWhitespaceChars() const {
+ int msg = 2647;
+ int len = SendMsg(msg, 0, (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, 0, (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
+// Set the set of characters making up punctuation characters
+// Should be called after SetWordChars.
+void wxStyledTextCtrl::SetPunctuationChars(const wxString& characters)
+{
+ SendMsg(2648, 0, (sptr_t)(const char*)wx2stc(characters));
+}
+
+// Get the set of characters making up punctuation characters
+wxString wxStyledTextCtrl::GetPunctuationChars() const {
+ int msg = 2649;
+ int len = SendMsg(msg, 0, (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, 0, (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
// Reset the set of characters for whitespace and word characters to the defaults.
void wxStyledTextCtrl::SetCharsDefault()
{
}
// Get currently selected item position in the auto-completion list
-int wxStyledTextCtrl::AutoCompGetCurrent()
+int wxStyledTextCtrl::AutoCompGetCurrent() const
{
return SendMsg(2445, 0, 0);
}
+// Set auto-completion case insensitive behaviour to either prefer case-sensitive matches or have no preference.
+void wxStyledTextCtrl::AutoCompSetCaseInsensitiveBehaviour(int behaviour)
+{
+ SendMsg(2634, behaviour, 0);
+}
+
+// Get auto-completion case insensitive behaviour.
+int wxStyledTextCtrl::AutoCompGetCaseInsensitiveBehaviour() const
+{
+ return SendMsg(2635, 0, 0);
+}
+
// Enlarge the document to a particular size of text bytes.
void wxStyledTextCtrl::Allocate(int bytes)
{
}
// Can the caret preferred x position only be changed by explicit movement commands?
-bool wxStyledTextCtrl::GetCaretSticky() const
+int wxStyledTextCtrl::GetCaretSticky() const
{
- return SendMsg(2457, 0, 0) != 0;
+ return SendMsg(2457, 0, 0);
}
// Stop the caret preferred x position changing when the user types.
-void wxStyledTextCtrl::SetCaretSticky(bool useCaretStickyBehaviour)
+void wxStyledTextCtrl::SetCaretSticky(int useCaretStickyBehaviour)
{
SendMsg(2458, useCaretStickyBehaviour, 0);
}
SendMsg(2502, value, 0);
}
-// Get the current indicator vaue
+// Get the current indicator value
int wxStyledTextCtrl::GetIndicatorValue() const
{
return SendMsg(2503, 0, 0);
// Compact the document buffer and return a read-only pointer to the
// characters in the document.
-const char* wxStyledTextCtrl::GetCharacterPointer() {
+const char* wxStyledTextCtrl::GetCharacterPointer() const {
return (const char*)SendMsg(2520, 0, 0);
}
+// Return a read-only pointer to a range of characters in the document.
+// May move the gap so that the range is contiguous, but will only move up
+// to rangeLength bytes.
+const char* wxStyledTextCtrl::GetRangePointer(int position, int rangeLength) const {
+ return (const char*)SendMsg(2643, position, rangeLength);
+}
+
+// Return a position which, to avoid performance costs, should not be within
+// the range of a call to GetRangePointer.
+int wxStyledTextCtrl::GetGapPosition() const
+{
+ return SendMsg(2644, 0, 0);
+}
+
// Always interpret keyboard input as Unicode
void wxStyledTextCtrl::SetKeysUnicode(bool keysUnicode)
{
return SendMsg(2524, indicator, 0);
}
+// Set the alpha outline colour of the given indicator.
+void wxStyledTextCtrl::IndicatorSetOutlineAlpha(int indicator, int alpha)
+{
+ SendMsg(2558, indicator, alpha);
+}
+
+// Get the alpha outline colour of the given indicator.
+int wxStyledTextCtrl::IndicatorGetOutlineAlpha(int indicator) const
+{
+ return SendMsg(2559, indicator, 0);
+}
+
// Set extra ascent for each line
void wxStyledTextCtrl::SetExtraAscent(int extraAscent)
{
return SendMsg(2538, 0, 0);
}
+// Set the margin options.
+void wxStyledTextCtrl::SetMarginOptions(int marginOptions)
+{
+ SendMsg(2539, marginOptions, 0);
+}
+
+// Get the margin options.
+int wxStyledTextCtrl::GetMarginOptions() const
+{
+ return SendMsg(2557, 0, 0);
+}
+
// Set the annotation text for a line
void wxStyledTextCtrl::AnnotationSetText(int line, const wxString& text)
{
SendMsg(2607, 0, 0);
}
+// Indicate that the internal state of a lexer has changed over a range and therefore
+// there may be a need to redraw.
+int wxStyledTextCtrl::ChangeLexerState(int start, int end)
+{
+ return SendMsg(2617, start, end);
+}
+
+// Find the next line at or after lineStart that is a contracted fold header line.
+// Return -1 when no more lines.
+int wxStyledTextCtrl::ContractedFoldNext(int lineStart)
+{
+ return SendMsg(2618, lineStart, 0);
+}
+
+// Centre current line in window.
+void wxStyledTextCtrl::VerticalCentreCaret()
+{
+ SendMsg(2619, 0, 0);
+}
+
+// Move the selected lines up one line, shifting the line above after the selection
+void wxStyledTextCtrl::MoveSelectedLinesUp()
+{
+ SendMsg(2620, 0, 0);
+}
+
+// Move the selected lines down one line, shifting the line below before the selection
+void wxStyledTextCtrl::MoveSelectedLinesDown()
+{
+ SendMsg(2621, 0, 0);
+}
+
+// Set the identifier reported as idFrom in notification messages.
+void wxStyledTextCtrl::SetIdentifier(int identifier)
+{
+ SendMsg(2622, identifier, 0);
+}
+
+// Get the identifier.
+int wxStyledTextCtrl::GetIdentifier() const
+{
+ return SendMsg(2623, 0, 0);
+}
+
+// Set the width for future RGBA image data.
+void wxStyledTextCtrl::RGBAImageSetWidth(int width)
+{
+ SendMsg(2624, width, 0);
+}
+
+// Set the height for future RGBA image data.
+void wxStyledTextCtrl::RGBAImageSetHeight(int height)
+{
+ SendMsg(2625, height, 0);
+}
+
+// Define a marker from RGBA data.
+// It has the width and height from RGBAImageSetWidth/Height
+void wxStyledTextCtrl::MarkerDefineRGBAImage(int markerNumber, const unsigned char* pixels) {
+ SendMsg(2626, markerNumber, (sptr_t)pixels);
+}
+
+// Register an RGBA image for use in autocompletion lists.
+// It has the width and height from RGBAImageSetWidth/Height
+void wxStyledTextCtrl::RegisterRGBAImage(int type, const unsigned char* pixels) {
+ SendMsg(2627, type, (sptr_t)pixels);
+}
+
+// Scroll to start of document.
+void wxStyledTextCtrl::ScrollToStart()
+{
+ SendMsg(2628, 0, 0);
+}
+
+// Scroll to end of document.
+void wxStyledTextCtrl::ScrollToEnd()
+{
+ SendMsg(2629, 0, 0);
+}
+
+// Set the technology used.
+void wxStyledTextCtrl::SetTechnology(int technology)
+{
+ SendMsg(2630, technology, 0);
+}
+
+// Get the tech.
+int wxStyledTextCtrl::GetTechnology() const
+{
+ return SendMsg(2631, 0, 0);
+}
+
+// Create an ILoader*.
+void* wxStyledTextCtrl::CreateLoader(int bytes) const {
+ return (void*)(sptr_t)SendMsg(2632, bytes);
+}
+
// Start notifying the container of all key presses and commands.
void wxStyledTextCtrl::StartRecord()
{
return SendMsg(4011, 0, 0);
}
+// For private communication between an application and a known lexer.
+void* wxStyledTextCtrl::PrivateLexerCall(int operation, void* pointer) {
+ return (void*)(sptr_t)SendMsg(4013, operation, (sptr_t)pointer);
+}
+
+// Retrieve a '\n' separated list of properties understood by the current lexer.
+wxString wxStyledTextCtrl::PropertyNames() const {
+ int msg = 4014;
+ int len = SendMsg(msg, 0, (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, 0, (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
+// Retrieve the type of a property.
+int wxStyledTextCtrl::PropertyType(const wxString& name)
+{
+ return SendMsg(4015, (sptr_t)(const char*)wx2stc(name), 0);
+}
+
+// Describe a property.
+wxString wxStyledTextCtrl::DescribeProperty(const wxString& name) const {
+ int msg = 4016;
+ int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
+// Retrieve a '\n' separated list of descriptions of the keyword sets understood by the current lexer.
+wxString wxStyledTextCtrl::DescribeKeyWordSets() const {
+ int msg = 4017;
+ int len = SendMsg(msg, 0, (sptr_t)NULL);
+ if (!len) return wxEmptyString;
+
+ wxMemoryBuffer mbuf(len+1);
+ char* buf = (char*)mbuf.GetWriteBuf(len+1);
+ SendMsg(msg, 0, (sptr_t)buf);
+ mbuf.UngetWriteBuf(len);
+ mbuf.AppendByte(0);
+ return stc2wx(buf);
+}
+
//}}}
//----------------------------------------------------------------------
}
-#if wxUSE_TEXTCTRL
-bool wxStyledTextCtrl::DoSaveFile(const wxString& filename, int fileType)
+void wxStyledTextCtrl::DoSetValue(const wxString& value, int flags)
{
- bool ok = wxTextAreaBase::DoSaveFile(filename, fileType);
-#else
-bool wxStyledTextCtrl::SaveFile(const wxString& filename)
+ if ( flags & SetValue_SelectionOnly )
+ ReplaceSelection(value);
+ else
+ SetText(value);
+
+ // We don't send wxEVT_COMMAND_TEXT_UPDATED anyhow, so ignore the
+ // SetValue_SendEvent bit of the flags
+}
+
+bool
+wxStyledTextCtrl::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
{
+#if wxUSE_FFILE || wxUSE_FILE
+
#if wxUSE_FFILE
- wxFFile file(filename, wxT("w"));
- bool ok = file.IsOpened() && file.Write(GetValue(), *wxConvCurrent);
-#else
- bool ok = false;
-#endif // wxUSE_FFILE
+ // Take care to use "b" to ensure that possibly non-native EOLs in the file
+ // contents are not mangled when saving it.
+ wxFFile file(filename, wxS("wb"));
+#elif wxUSE_FILE
+ wxFile file(filename, wxFile::write);
#endif
- if (ok)
+
+ if ( file.IsOpened() && file.Write(GetValue(), *wxConvCurrent) )
{
SetSavePoint();
+
+ return true;
}
- return ok;
+
+#endif // !wxUSE_FFILE && !wxUSE_FILE
+
+ return false;
}
-#if wxUSE_TEXTCTRL
-bool wxStyledTextCtrl::DoLoadFile(const wxString& filename, int fileType)
-{
- bool ok = wxTextAreaBase::DoLoadFile(filename, fileType);
-#else
-bool wxStyledTextCtrl::LoadFile(const wxString& filename)
+bool
+wxStyledTextCtrl::DoLoadFile(const wxString& filename, int WXUNUSED(fileType))
{
+#if wxUSE_FFILE || wxUSE_FILE
+
#if wxUSE_FFILE
- wxFFile file(filename);
- bool ok = file.IsOpened();
- if (ok)
+ // As above, we want to read the real EOLs from the file, e.g. without
+ // translating them to just LFs under Windows, so that the original CR LF
+ // are preserved when it's written back.
+ wxFFile file(filename, wxS("rb"));
+#else
+ wxFile file(filename);
+#endif
+
+ if ( file.IsOpened() )
{
wxString text;
- ok = file.ReadAll(&text, *wxConvCurrent);
- if (ok)
+ if ( file.ReadAll(&text, *wxConvCurrent) )
{
+ // Detect the EOL: we use just the first line because there is not
+ // much we can do if the file uses inconsistent EOLs anyhow, we'd
+ // need to ask the user about the one we should really use and we
+ // don't currently provide a way to do it.
+ //
+ // We also only check for Unix and DOS EOLs but not classic Mac
+ // CR-only one as it's obsolete by now.
+ const wxString::size_type posLF = text.find('\n');
+ if ( posLF != wxString::npos )
+ {
+ // Set EOL mode to ensure that the new lines inserted into the
+ // text use the same EOLs as the existing ones.
+ if ( posLF > 0 && text[posLF - 1] == '\r' )
+ SetEOLMode(wxSTC_EOL_CRLF);
+ else
+ SetEOLMode(wxSTC_EOL_LF);
+ }
+ //else: Use the default EOL for the current platform.
+
SetValue(text);
+ EmptyUndoBuffer();
+ SetSavePoint();
+
+ return true;
}
}
-#else
- bool ok = false;
-#endif // wxUSE_FFILE
-#endif
- if (ok)
- {
- EmptyUndoBuffer();
- SetSavePoint();
- }
- return ok;
+#endif // !wxUSE_FFILE && !wxUSE_FILE
+
+ return false;
+}
+
+// If we don't derive from wxTextAreaBase, we need to implement these methods
+// ourselves, otherwise we already inherit them.
+#if !wxUSE_TEXTCTRL
+
+bool wxStyledTextCtrl::SaveFile(const wxString& filename)
+{
+ if ( filename.empty() )
+ return false;
+
+ return DoSaveFile(filename, wxTEXT_TYPE_ANY);
+}
+
+bool wxStyledTextCtrl::LoadFile(const wxString& filename)
+{
+ if ( filename.empty() )
+ return false;
+
+ return DoLoadFile(filename, wxTEXT_TYPE_ANY);
}
+#endif // !wxUSE_TEXTCTRL
+
#if wxUSE_DRAG_AND_DROP
wxDragResult wxStyledTextCtrl::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) {
return m_swx->DoDragOver(x, y, def);
return m_swx->GetUseAntiAliasing();
}
+void wxStyledTextCtrl::AnnotationClearLine(int line) {
+ SendMsg(SCI_ANNOTATIONSETTEXT, line, NULL);
+}
-void wxStyledTextCtrl::AddTextRaw(const char* text)
+void wxStyledTextCtrl::AddTextRaw(const char* text, int length)
{
- SendMsg(SCI_ADDTEXT, strlen(text), (sptr_t)text);
+ if (length == -1)
+ length = strlen(text);
+ SendMsg(SCI_ADDTEXT, length, (sptr_t)text);
}
void wxStyledTextCtrl::InsertTextRaw(int pos, const char* text)
wxCharBuffer wxStyledTextCtrl::GetSelectedTextRaw()
{
- long start;
- long end;
-
- GetSelection(&start, &end);
- int len = end - start;
- if (!len) {
- wxCharBuffer empty;
- return empty;
- }
+ // Calculate the length needed first.
+ const int len = SendMsg(SCI_GETSELTEXT, 0, (sptr_t)0);
+ // And then really get the data.
wxCharBuffer buf(len);
SendMsg(SCI_GETSELTEXT, 0, (sptr_t)buf.data());
return buf;
return buf;
}
-void wxStyledTextCtrl::AppendTextRaw(const char* text)
+void wxStyledTextCtrl::AppendTextRaw(const char* text, int length)
{
- SendMsg(SCI_APPENDTEXT, strlen(text), (sptr_t)text);
+ if (length == -1)
+ length = strlen(text);
+ SendMsg(SCI_APPENDTEXT, length, (sptr_t)text);
}
void wxStyledTextCtrl::OnMouseWheel(wxMouseEvent& evt)
{
- // Prevent having an event queue with wheel events that cannot be processed
- // reasonably fast (see ticket #9057) by ignoring all of them that happen
- // during the time interval corresponding to the time it took us to handle
- // the last one.
- //
- // Notice the use of TimeInMicro() instead of Time() to avoid overflow in
- // long running programs.
- if ( m_timeToBlockWheelEventsUntil <= m_stopWatch.TimeInMicro() )
- {
- const wxLongLong beforeMouseWheel = m_stopWatch.TimeInMicro();
- m_swx->DoMouseWheel(evt.GetWheelRotation(),
- evt.GetWheelDelta(),
- evt.GetLinesPerAction(),
- evt.ControlDown(),
- evt.IsPageScroll());
- const wxLongLong afterMouseWheel = m_stopWatch.TimeInMicro();
- m_timeToBlockWheelEventsUntil = afterMouseWheel;
- m_timeToBlockWheelEventsUntil += afterMouseWheel - beforeMouseWheel;
- }
+ m_swx->DoMouseWheel(evt.GetWheelRotation(),
+ evt.GetWheelDelta(),
+ evt.GetLinesPerAction(),
+ evt.ControlDown(),
+ evt.IsPageScroll());
}
case SCN_DOUBLECLICK:
evt.SetEventType(wxEVT_STC_DOUBLECLICK);
+ evt.SetLine(scn.line);
break;
case SCN_UPDATEUI:
evt.SetEventType(wxEVT_STC_UPDATEUI);
+ evt.SetUpdated(scn.updated);
break;
case SCN_MODIFIED:
evt.SetLine(scn.line);
evt.SetFoldLevelNow(scn.foldLevelNow);
evt.SetFoldLevelPrev(scn.foldLevelPrev);
+ evt.SetToken(scn.token);
+ evt.SetAnnotationLinesAdded(scn.annotationLinesAdded);
break;
case SCN_MACRORECORD:
evt.SetEventType(wxEVT_STC_AUTOCOMP_CHAR_DELETED);
break;
+ case SCN_HOTSPOTRELEASECLICK:
+ evt.SetEventType(wxEVT_STC_HOTSPOT_RELEASE_CLICK);
+ break;
+
default:
return;
}
m_listType = 0;
m_x = 0;
m_y = 0;
+ m_token = 0;
+ m_annotationLinesAdded = 0;
+ m_updated = 0;
+
#if wxUSE_DRAG_AND_DROP
m_dragFlags = wxDrag_CopyOnly;
m_dragResult = wxDragNone;
m_x = event.m_x;
m_y = event.m_y;
+ m_token = event.m_token;
+ m_annotationLinesAdded = event.m_annotationLinesAdded;
+ m_updated = event.m_updated;
+
#if wxUSE_DRAG_AND_DROP
m_dragText = event.m_dragText;
m_dragFlags = event.m_dragFlags;
/*static*/ wxVersionInfo wxStyledTextCtrl::GetLibraryVersionInfo()
{
- return wxVersionInfo("Scintilla", 2, 3, 0, "Scintilla 2.03");
+ return wxVersionInfo("Scintilla", 3, 21, 0, "Scintilla 3.21");
}
#endif // wxUSE_STC