#include "wx/richtext/richtextstyles.h"
#ifndef WX_PRECOMP
+ #include "wx/wx.h"
#include "wx/settings.h"
- #include "wx/menu.h"
- #include "wx/intl.h"
- #include "wx/log.h"
- #include "wx/stopwatch.h"
#endif
#include "wx/textfile.h"
attributes.SetBackgroundColour(*wxWHITE);
attributes.SetAlignment(wxTEXT_ALIGNMENT_LEFT);
attributes.SetFlags(wxTEXT_ATTR_ALL);
-
- SetDefaultStyle(attributes);
SetBasicStyle(attributes);
+ // The default attributes will be merged with base attributes, so
+ // can be empty to begin with
+ wxTextAttrEx defaultAttributes;
+ SetDefaultStyle(defaultAttributes);
+
SetBackgroundColour(*wxWHITE);
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
DeleteSelectedContent(& newPos);
- GetBuffer().InsertNewlineWithUndo(newPos+1, this);
+ GetBuffer().InsertNewlineWithUndo(newPos+1, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
wxRichTextEvent cmdEvent(
wxEVT_COMMAND_RICHTEXT_RETURN,
DeleteSelectedContent(& newPos);
wxString str = (wxChar) event.GetKeyCode();
- GetBuffer().InsertTextWithUndo(newPos+1, str, this);
+ GetBuffer().InsertTextWithUndo(newPos+1, str, this, wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
EndBatchUndo();
// file IO functions
// ----------------------------------------------------------------------------
-bool wxRichTextCtrl::LoadFile(const wxString& filename, int type)
+#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
+bool wxRichTextCtrl::LoadFile(const wxString& filename, int fileType)
+{
+ return DoLoadFile(filename, fileType);
+}
+
+bool wxRichTextCtrl::SaveFile(const wxString& filename, int fileType)
+{
+ wxString filenameToUse = filename.empty() ? m_filename : filename;
+ if ( filenameToUse.empty() )
+ {
+ // what kind of message to give? is it an error or a program bug?
+ wxLogDebug(wxT("Can't save textctrl to file without filename."));
+
+ return false;
+ }
+
+ return DoSaveFile(filenameToUse, fileType);
+}
+#endif
+
+bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType)
{
- bool success = GetBuffer().LoadFile(filename, type);
+ bool success = GetBuffer().LoadFile(filename, fileType);
if (success)
m_filename = filename;
}
}
-bool wxRichTextCtrl::SaveFile(const wxString& filename, int type)
+bool wxRichTextCtrl::DoSaveFile(const wxString& filename, int fileType)
{
- wxString filenameToUse = filename.empty() ? m_filename : filename;
- if ( filenameToUse.empty() )
- {
- // what kind of message to give? is it an error or a program bug?
- wxLogDebug(wxT("Can't save textctrl to file without filename."));
-
- return false;
- }
-
- if (GetBuffer().SaveFile(filenameToUse, type))
+ if (GetBuffer().SaveFile(filename, fileType))
{
- m_filename = filenameToUse;
+ m_filename = filename;
DiscardEdits();
return true;
-
}
wxLogError(_("The text couldn't be saved."));
void wxRichTextCtrl::DoWriteText(const wxString& value, bool WXUNUSED(selectionOnly))
{
- GetBuffer().InsertTextWithUndo(m_caretPosition+1, value, this);
+ wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Unix);
+
+ GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueDos, this);
}
void wxRichTextCtrl::AppendText(const wxString& text)
{
if (CanCopy())
{
- wxRichTextRange range = GetSelectionRange();
+ wxRichTextRange range = GetInternalSelectionRange();
GetBuffer().CopyToClipboard(range);
}
}
{
if (CanCut())
{
- wxRichTextRange range = GetSelectionRange();
+ wxRichTextRange range = GetInternalSelectionRange();
GetBuffer().CopyToClipboard(range);
DeleteSelectedContent();
return GetBuffer().GetDefaultStyle();
}
-bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style) const
+bool wxRichTextCtrl::GetStyle(long position, wxTextAttr& style)
{
- wxTextAttrEx attr;
+ wxTextAttrEx attr(style);
if (GetBuffer().GetStyle(position, attr))
{
style = attr;
return false;
}
-bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style) const
+bool wxRichTextCtrl::GetStyle(long position, wxTextAttrEx& style)
{
return GetBuffer().GetStyle(position, style);
}
-bool wxRichTextCtrl::GetStyle(long position, wxRichTextAttr& style) const
+bool wxRichTextCtrl::GetStyle(long position, wxRichTextAttr& style)
{
return GetBuffer().GetStyle(position, style);
}
+/// Get the content (uncombined) attributes for this position.
+
+bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttr& style)
+{
+ wxTextAttrEx attr(style);
+ if (GetBuffer().GetUncombinedStyle(position, attr))
+ {
+ style = attr;
+ return true;
+ }
+ else
+ return false;
+}
+
+bool wxRichTextCtrl::GetUncombinedStyle(long position, wxTextAttrEx& style)
+{
+ return GetBuffer().GetUncombinedStyle(position, style);
+}
+
+bool wxRichTextCtrl::GetUncombinedStyle(long position, wxRichTextAttr& style)
+{
+ return GetBuffer().GetUncombinedStyle(position, style);
+}
+
/// Set font, and also the buffer attributes
bool wxRichTextCtrl::SetFont(const wxFont& font)
{
wxTextAttrEx attr = GetBuffer().GetAttributes();
attr.SetFont(font);
GetBuffer().SetBasicStyle(attr);
+
+#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
+ // Don't set the default style, since it will be inherited from
+ // the basic style.
GetBuffer().SetDefaultStyle(attr);
+#endif
+
+ GetBuffer().Invalidate(wxRICHTEXT_ALL);
+ Refresh(false);
return true;
}
}
/// Is all of the selection bold?
-bool wxRichTextCtrl::IsSelectionBold() const
+bool wxRichTextCtrl::IsSelectionBold()
{
if (HasSelection())
{
}
/// Is all of the selection italics?
-bool wxRichTextCtrl::IsSelectionItalics() const
+bool wxRichTextCtrl::IsSelectionItalics()
{
if (HasSelection())
{
}
/// Is all of the selection underlined?
-bool wxRichTextCtrl::IsSelectionUnderlined() const
+bool wxRichTextCtrl::IsSelectionUnderlined()
{
if (HasSelection())
{
// to see what the effect would be if we started typing.
wxRichTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE);
-
long pos = GetAdjustedCaretPosition(GetCaretPosition());
+
if (GetStyle(pos, attr))
{
if (IsDefaultStyleShowing())
}
/// Is all of the selection aligned according to the specified flag?
-bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) const
+bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment)
{
if (HasSelection())
{
SetAndShowDefaultStyle(attr);
}
+/// Apply the style sheet to the buffer, for example if the styles have changed.
+bool wxRichTextCtrl::ApplyStyleSheet(wxRichTextStyleSheet* styleSheet)
+{
+ if (!styleSheet)
+ styleSheet = GetBuffer().GetStyleSheet();
+ if (!styleSheet)
+ return false;
+
+ if (GetBuffer().ApplyStyleSheet(styleSheet))
+ {
+ GetBuffer().Invalidate(wxRICHTEXT_ALL);
+ Refresh(false);
+ return true;
+ }
+ else
+ return false;
+}
+
/// Sets the default style to the style under the cursor
bool wxRichTextCtrl::SetDefaultStyleToCursorStyle()
{
// If at the start of a paragraph, use the next position.
long pos = GetAdjustedCaretPosition(GetCaretPosition());
+#if wxRICHTEXT_USE_DYNAMIC_STYLES
+ if (GetUncombinedStyle(pos, attr))
+#else
if (GetStyle(pos, attr))
+#endif
{
SetDefaultStyle(attr);
return true;
range1.SetEnd(range1.GetEnd() - 1);
wxASSERT( range1.GetStart() > range1.GetEnd() );
-
+
SetInternalSelectionRange(range1);
}