fix compilation after recent wxTextCtrl changes

notice that it has become unfortunately impossible (or at least much more
difficult) to maintain compilation when wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
is unset so I simply removed it as the code wouldn't compile anyhow


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41755 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-10-08 22:42:20 +00:00
parent ee2ec18e88
commit 343ae70d4c
3 changed files with 33 additions and 153 deletions

View File

@@ -19,15 +19,7 @@
#include "wx/scrolwin.h" #include "wx/scrolwin.h"
#include "wx/caret.h" #include "wx/caret.h"
#if wxCHECK_VERSION(2,7,0)
#define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 1
#else
#define wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE 0
#endif
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
#include "wx/textctrl.h" #include "wx/textctrl.h"
#endif
#if !defined(__WXGTK__) && !defined(__WXMAC__) #if !defined(__WXGTK__) && !defined(__WXMAC__)
#define wxRICHTEXT_BUFFERED_PAINTING 1 #define wxRICHTEXT_BUFFERED_PAINTING 1
@@ -92,12 +84,8 @@ class WXDLLIMPEXP_RICHTEXT wxRichTextStyleDefinition;
* wxRichTextCtrl class declaration * wxRichTextCtrl class declaration
*/ */
class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl: class WXDLLIMPEXP_RICHTEXT wxRichTextCtrl : public wxTextCtrlBase,
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE public wxScrollHelper
public wxTextCtrlBase, public wxScrollHelper
#else
public wxScrolledWindow
#endif
{ {
DECLARE_CLASS( wxRichTextCtrl ) DECLARE_CLASS( wxRichTextCtrl )
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
@@ -124,7 +112,6 @@ public:
// Accessors // Accessors
virtual wxString GetValue() const; virtual wxString GetValue() const;
virtual void SetValue(const wxString& value);
virtual wxString GetRange(long from, long to) const; virtual wxString GetRange(long from, long to) const;
@@ -163,11 +150,6 @@ public:
virtual void Replace(long from, long to, const wxString& value); virtual void Replace(long from, long to, const wxString& value);
virtual void Remove(long from, long to); virtual void Remove(long from, long to);
#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
bool LoadFile(const wxString& file, int fileType = wxRICHTEXT_TYPE_ANY);
bool SaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY);
#endif
// load/save the controls contents from/to the file // load/save the controls contents from/to the file
virtual bool DoLoadFile(const wxString& file, int fileType); virtual bool DoLoadFile(const wxString& file, int fileType);
virtual bool DoSaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY); virtual bool DoSaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY);
@@ -641,19 +623,7 @@ public:
virtual void DoSetSelection(long from, long to, bool scrollCaret = true); virtual void DoSetSelection(long from, long to, bool scrollCaret = true);
/// Write text /// Write text
virtual void DoWriteText(const wxString& value, bool selectionOnly = true); virtual void DoWriteText(const wxString& value, int flags = 0);
/// Send an update event
virtual bool SendUpdateEvent();
/// Init command event
void InitCommandEvent(wxCommandEvent& event) const;
/// do the window-specific processing after processing the update event
// (duplicated code from wxTextCtrlBase)
#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
virtual void DoUpdateWindowUI(wxUpdateUIEvent& event);
#endif
/// Should we inherit colours? /// Should we inherit colours?
virtual bool ShouldInheritColours() const { return false; } virtual bool ShouldInheritColours() const { return false; }
@@ -744,15 +714,16 @@ public:
// Implementation // Implementation
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
WX_FORWARD_TO_SCROLL_HELPER() WX_FORWARD_TO_SCROLL_HELPER()
#endif
// Overrides // Overrides
protected: protected:
virtual wxSize DoGetBestSize() const ; virtual wxSize DoGetBestSize() const ;
virtual void DoSetValue(const wxString& value, int flags = 0);
// Data members // Data members
private: private:
@@ -767,11 +738,6 @@ private:
/// Text buffer /// Text buffer
wxRichTextBuffer m_buffer; wxRichTextBuffer m_buffer;
#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
/// Filename
wxString m_filename;
#endif
wxMenu* m_contextMenu; wxMenu* m_contextMenu;
/// Caret position (1 less than the character position, so -1 is the /// Caret position (1 less than the character position, so -1 is the

View File

@@ -5054,7 +5054,7 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent
m_ctrl->Refresh(false); m_ctrl->Refresh(false);
if (sendUpdateEvent) if (sendUpdateEvent)
m_ctrl->SendUpdateEvent(); m_ctrl->SendTextUpdatedEvent();
} }
} }
} }

View File

@@ -44,19 +44,11 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RIGHT_CLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_LEFT_DCLICK)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RETURN) DEFINE_EVENT_TYPE(wxEVT_COMMAND_RICHTEXT_RETURN)
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
IMPLEMENT_CLASS( wxRichTextCtrl, wxControl ) IMPLEMENT_CLASS( wxRichTextCtrl, wxControl )
#else
IMPLEMENT_CLASS( wxRichTextCtrl, wxScrolledWindow )
#endif
IMPLEMENT_CLASS( wxRichTextEvent, wxNotifyEvent ) IMPLEMENT_CLASS( wxRichTextEvent, wxNotifyEvent )
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
BEGIN_EVENT_TABLE( wxRichTextCtrl, wxControl ) BEGIN_EVENT_TABLE( wxRichTextCtrl, wxControl )
#else
BEGIN_EVENT_TABLE( wxRichTextCtrl, wxScrolledWindow )
#endif
EVT_PAINT(wxRichTextCtrl::OnPaint) EVT_PAINT(wxRichTextCtrl::OnPaint)
EVT_ERASE_BACKGROUND(wxRichTextCtrl::OnEraseBackground) EVT_ERASE_BACKGROUND(wxRichTextCtrl::OnEraseBackground)
EVT_IDLE(wxRichTextCtrl::OnIdle) EVT_IDLE(wxRichTextCtrl::OnIdle)
@@ -100,17 +92,18 @@ END_EVENT_TABLE()
*/ */
wxRichTextCtrl::wxRichTextCtrl() wxRichTextCtrl::wxRichTextCtrl()
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
: wxScrollHelper(this) : wxScrollHelper(this)
#endif
{ {
Init(); Init();
} }
wxRichTextCtrl::wxRichTextCtrl( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) wxRichTextCtrl::wxRichTextCtrl(wxWindow* parent,
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
long style)
: wxScrollHelper(this) : wxScrollHelper(this)
#endif
{ {
Init(); Init();
Create(parent, id, value, pos, size, style); Create(parent, id, value, pos, size, style);
@@ -119,15 +112,9 @@ wxRichTextCtrl::wxRichTextCtrl( wxWindow* parent, wxWindowID id, const wxString&
/// Creation /// Creation
bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style) bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style)
{ {
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE if (!wxTextCtrlBase::Create(parent, id, pos, size,
if (!wxTextCtrlBase::Create(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE style|wxFULL_REPAINT_ON_RESIZE))
))
return false; return false;
#else
if (!wxScrolledWindow::Create(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE
))
return false;
#endif
if (!GetFont().Ok()) if (!GetFont().Ok())
{ {
@@ -230,7 +217,7 @@ void wxRichTextCtrl::Clear()
SetupScrollbars(); SetupScrollbars();
Refresh(false); Refresh(false);
} }
SendUpdateEvent(); SendTextUpdatedEvent();
} }
/// Painting /// Painting
@@ -1652,27 +1639,6 @@ bool wxRichTextCtrl::RecreateBuffer(const wxSize& size)
// file IO functions // file IO functions
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
#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 wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType)
{ {
bool success = GetBuffer().LoadFile(filename, fileType); bool success = GetBuffer().LoadFile(filename, fileType);
@@ -1685,7 +1651,7 @@ bool wxRichTextCtrl::DoLoadFile(const wxString& filename, int fileType)
PositionCaret(); PositionCaret();
SetupScrollbars(true); SetupScrollbars(true);
Refresh(false); Refresh(false);
SendUpdateEvent(); SendTextUpdatedEvent();
if (success) if (success)
return true; return true;
@@ -1808,22 +1774,6 @@ wxString wxRichTextCtrl::GetStringSelection() const
return GetRange(from, to); return GetRange(from, to);
} }
// do the window-specific processing after processing the update event
#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
void wxRichTextCtrl::DoUpdateWindowUI(wxUpdateUIEvent& event)
{
// call inherited
wxWindowBase::DoUpdateWindowUI(event);
// update text
if ( event.GetSetText() )
{
if ( event.GetText() != GetValue() )
SetValue(event.GetText());
}
}
#endif // !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// hit testing // hit testing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1888,7 +1838,7 @@ wxString wxRichTextCtrl::GetRange(long from, long to) const
return GetBuffer().GetTextForRange(wxRichTextRange(from, to-1)); return GetBuffer().GetTextForRange(wxRichTextRange(from, to-1));
} }
void wxRichTextCtrl::SetValue(const wxString& value) void wxRichTextCtrl::DoSetValue(const wxString& value, int flags)
{ {
Clear(); Clear();
@@ -1898,15 +1848,18 @@ void wxRichTextCtrl::SetValue(const wxString& value)
// edit controls mostly) // edit controls mostly)
if ( (value.length() > 0x400) || (value != GetValue()) ) if ( (value.length() > 0x400) || (value != GetValue()) )
{ {
DoWriteText(value, false /* not selection only */); DoWriteText(value);
// for compatibility, don't move the cursor when doing SetValue() // for compatibility, don't move the cursor when doing SetValue()
SetInsertionPoint(0); SetInsertionPoint(0);
} }
else // same text else // same text
{
if ( flags & SetValue_SendEvent )
{ {
// still send an event for consistency // still send an event for consistency
SendUpdateEvent(); SendTextUpdatedEvent();
}
} }
// we should reset the modified flag even if the value didn't really change // we should reset the modified flag even if the value didn't really change
@@ -1921,11 +1874,14 @@ void wxRichTextCtrl::WriteText(const wxString& value)
DoWriteText(value); DoWriteText(value);
} }
void wxRichTextCtrl::DoWriteText(const wxString& value, bool WXUNUSED(selectionOnly)) void wxRichTextCtrl::DoWriteText(const wxString& value, int flags)
{ {
wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix); wxString valueUnix = wxTextFile::Translate(value, wxTextFileType_Unix);
GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this); GetBuffer().InsertTextWithUndo(m_caretPosition+1, valueUnix, this);
if ( flags & SetValue_SendEvent )
SendTextUpdatedEvent();
} }
void wxRichTextCtrl::AppendText(const wxString& text) void wxRichTextCtrl::AppendText(const wxString& text)
@@ -2140,13 +2096,14 @@ void wxRichTextCtrl::DoSetSelection(long from, long to, bool WXUNUSED(scrollCare
// Editing // Editing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxRichTextCtrl::Replace(long WXUNUSED(from), long WXUNUSED(to), const wxString& value) void wxRichTextCtrl::Replace(long WXUNUSED(from), long WXUNUSED(to),
const wxString& value)
{ {
BeginBatchUndo(_("Replace")); BeginBatchUndo(_("Replace"));
DeleteSelectedContent(); DeleteSelectedContent();
DoWriteText(value, true /* selection only */); DoWriteText(value, SetValue_SelectionOnly);
EndBatchUndo(); EndBatchUndo();
} }
@@ -2270,39 +2227,6 @@ void wxRichTextCtrl::OnDropFiles(wxDropFilesEvent& event)
} }
} }
// ----------------------------------------------------------------------------
// text control event processing
// ----------------------------------------------------------------------------
bool wxRichTextCtrl::SendUpdateEvent()
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
InitCommandEvent(event);
return GetEventHandler()->ProcessEvent(event);
}
void wxRichTextCtrl::InitCommandEvent(wxCommandEvent& event) const
{
event.SetEventObject((wxControlBase *)this); // const_cast
switch ( m_clientDataType )
{
case wxClientData_Void:
event.SetClientData(GetClientData());
break;
case wxClientData_Object:
event.SetClientObject(GetClientObject());
break;
case wxClientData_None:
// nothing to do
;
}
}
wxSize wxRichTextCtrl::DoGetBestSize() const wxSize wxRichTextCtrl::DoGetBestSize() const
{ {
return wxSize(10, 10); return wxSize(10, 10);
@@ -2505,22 +2429,12 @@ bool wxRichTextCtrl::GetUncombinedStyle(long position, wxRichTextAttr& style)
/// Set font, and also the buffer attributes /// Set font, and also the buffer attributes
bool wxRichTextCtrl::SetFont(const wxFont& font) bool wxRichTextCtrl::SetFont(const wxFont& font)
{ {
#if wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
wxControl::SetFont(font); wxControl::SetFont(font);
#else
wxScrolledWindow::SetFont(font);
#endif
wxTextAttrEx attr = GetBuffer().GetAttributes(); wxTextAttrEx attr = GetBuffer().GetAttributes();
attr.SetFont(font); attr.SetFont(font);
GetBuffer().SetBasicStyle(attr); 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); GetBuffer().Invalidate(wxRICHTEXT_ALL);
Refresh(false); Refresh(false);