From 3306aec1240b38347abda1ad776df32b6687ad01 Mon Sep 17 00:00:00 2001
From: Julian Smart <julian@anthemion.co.uk>
Date: Sun, 24 Sep 2006 11:40:33 +0000
Subject: [PATCH] Added DoLoadFile, DoSaveFile to wxTextCtrlBase

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41410 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt                   | 44 +++++++++++++++++-------------
 docs/latex/wx/text.tex             |  8 ++++--
 include/wx/mac/carbon/textctrl.h   |  4 ---
 include/wx/mac/classic/textctrl.h  |  3 --
 include/wx/msw/textctrl.h          |  5 ++--
 include/wx/os2/textctrl.h          |  2 +-
 include/wx/palmos/textctrl.h       |  4 +--
 include/wx/richtext/richtextctrl.h | 13 ++++++---
 include/wx/textctrl.h              | 18 ++++++++----
 src/common/textcmn.cpp             | 17 ++++++++----
 src/mac/carbon/textctrl.cpp        |  5 ----
 src/mac/classic/textctrl.cpp       | 10 -------
 src/msw/textctrl.cpp               |  4 +--
 src/os2/textctrl.cpp               |  7 +++--
 src/palmos/textctrl.cpp            |  2 +-
 src/richtext/richtextctrl.cpp      | 41 ++++++++++++++++++----------
 16 files changed, 102 insertions(+), 85 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index e073c2e317..0a221c1b1c 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -56,21 +56,27 @@ Major changes in 2.7 release
 
 All:
 
-- Added wxDir::FindFirst() (Francesco Montorsi)
-- Added wxPlatformInfo class (Francesco Montorsi)
-- Added wxLocale::IsAvailable() (Creighton)
+- Added wxDir::FindFirst() (Francesco Montorsi).
+- Added wxPlatformInfo class (Francesco Montorsi).
+- Added wxLocale::IsAvailable() (Creighton).
 
 All (GUI):
 
-- Support for right-to-left text layout
-  (started by Diaa Sami during Google Summer of Code, with a lot of help from
-   Tim Kosse and others)
-- Added wxID_PAGE_SETUP standard id
-- Added wxSize::IncBy() and DecBy() methods
+- Support for right-to-left text layout (started by Diaa Sami during Google Summer of
+  Code, with a lot of help from Tim Kosse and others).
+- Added wxID_PAGE_SETUP standard id.
+- Added wxSize::IncBy() and DecBy() methods.
+- Added file type parameter to wxTextCtrl::LoadFile, wxTextCtrl::SaveFile for
+  consistency with wxRichTextCtrl.
+- wxRichTextCtrl: fixed range out-by-one bug to be consistent with wxTextCtrl API,
+  fixed some attribute bugs and added wxRichTextStyleComboCtrl.
 
 wxMSW:
 
-- Implemented wxComboBox::SetEditable()
+- Implemented wxComboBox::SetEditable().
+- Fixed a bug whereby static controls didn't use the correct text colour if the
+  parent's background colour had been set (most noticeable when switching to a
+  high-contrast theme).
 
 wxMac:
 
@@ -79,8 +85,8 @@ wxMac:
 
 wxGTK:
 
-- Automatically use stock items for the menu items with standard ids
-- Setting cursor now works for all controls
+- Automatically use stock items for menu items with standard ids.
+- Setting cursor now works for all controls.
 
 
 2.7.0
@@ -131,14 +137,14 @@ All:
   Previously, only the buffer would be returned, even if more data was requested.
 - Added wxPowerEvent (currently MSW-only).
 - Make wx-config compatible with Bourne shells.
-- Fixed wxDb::Open(wxDbConnectInf) when using connection string (Hellwolf Misty)
-- Fixed crash in wxDb::Open() in Unicode build (Massimiliano Marretta)
-- Fixed wxTimeSpan::Format() for negative time spans
-- Optionally count repeating wxLog messages instead of logging all (Lauri Nurmi)
+- Fixed wxDb::Open(wxDbConnectInf) when using connection string (Hellwolf Misty).
+- Fixed crash in wxDb::Open() in Unicode build (Massimiliano Marretta).
+- Fixed wxTimeSpan::Format() for negative time spans.
+- Optionally count repeating wxLog messages instead of logging all (Lauri Nurmi).
 
 All (GUI):
 
-- New AUI (Advanced User Interface) library for docking windows and much more
+- New AUI (Advanced User Interface) library for docking windows and much more.
 - Added wxComboCtrl and wxOwnerDrawnComboBox (Jaakko Salli).
 - Added wxTreebook (uses a wxTreeCtrl to control pages).
 - Added wxColour/Dir/File/Font/PickerCtrls (Francesco Montorsi).
@@ -213,8 +219,8 @@ All (GUI):
 - wxNB_HITTEST_* flags renamed to wxBK_HITTEST_* to serve all book controls.
 - Added wxTopLevelWindow::SetTransparent and CanSetTransparent, with
   implementations (so far) for wxMSW and wxMac.
-- Allow customizing individual grid lines appearance (Søren Lassen)
-- Fixed middle click events generation in generic wxTreeCtrl (Olly Betts)
+- Allow customizing individual grid lines appearance (Søren Lassen).
+- Fixed middle click events generation in generic wxTreeCtrl (Olly Betts).
 - Added wxEVT_MOUSE_CAPTURE_LOST event that must be handled by all windows
   that CaptureMouse() is called on.
 
@@ -225,7 +231,7 @@ wxMSW:
 - Switching page of a hidden notebook doesn't lose focus (Jamie Gadd).
 - Removed wxImageList *GetImageList(int) const.
 - Fixed MDI context menu problem.
-- Removed __WIN95__ define
+- Removed __WIN95__ define.
 - Create msw/rcdefs.h in setup.h's directory, which can be included by
   resource files. It containts platform/compiler specific defines (such as
   target cpu) which can be used in #ifs in .rc files.
diff --git a/docs/latex/wx/text.tex b/docs/latex/wx/text.tex
index 5992858843..8b3f029567 100644
--- a/docs/latex/wx/text.tex
+++ b/docs/latex/wx/text.tex
@@ -652,7 +652,7 @@ otherwise.
 
 \membersection{wxTextCtrl::LoadFile}\label{wxtextctrlloadfile}
 
-\func{bool}{LoadFile}{\param{const wxString\& }{ filename}}
+\func{bool}{LoadFile}{\param{const wxString\& }{ filename}, \param{int }{fileType = wxTEXT\_TYPE\_ANY}}
 
 Loads and displays the named file, if it exists.
 
@@ -660,6 +660,8 @@ Loads and displays the named file, if it exists.
 
 \docparam{filename}{The filename of the file to load.}
 
+\docparam{fileType}{The type of file to load. This is currently ignored in wxTextCtrl.}
+
 \wxheading{Return value}
 
 {\tt true} if successful, {\tt false} otherwise.
@@ -804,7 +806,7 @@ the character at the last position with the given text.
 
 \membersection{wxTextCtrl::SaveFile}\label{wxtextctrlsavefile}
 
-\func{bool}{SaveFile}{\param{const wxString\& }{ filename}}
+\func{bool}{SaveFile}{\param{const wxString\& }{ filename}, \param{int }{fileType = wxTEXT\_TYPE\_ANY}}
 
 Saves the contents of the control in a text file.
 
@@ -812,6 +814,8 @@ Saves the contents of the control in a text file.
 
 \docparam{filename}{The name of the file in which to save the text.}
 
+\docparam{fileType}{The type of file to save. This is currently ignored in wxTextCtrl.}
+
 \wxheading{Return value}
 
 {\tt true} if the operation was successful, {\tt false} otherwise.
diff --git a/include/wx/mac/carbon/textctrl.h b/include/wx/mac/carbon/textctrl.h
index 69615247a2..db4dbe7985 100644
--- a/include/wx/mac/carbon/textctrl.h
+++ b/include/wx/mac/carbon/textctrl.h
@@ -81,10 +81,6 @@ public:
     virtual void Replace(long from, long to, const wxString& value);
     virtual void Remove(long from, long to);
 
-    // load the controls contents from the file
-    virtual bool LoadFile(const wxString& file);
-    virtual bool LoadFile(const wxString& file, int WXUNUSED(fileType)) { return LoadFile(file); }
-
     // sets/clears the dirty flag
     virtual void MarkDirty();
     virtual void DiscardEdits();
diff --git a/include/wx/mac/classic/textctrl.h b/include/wx/mac/classic/textctrl.h
index d25ac7814a..09783ec921 100644
--- a/include/wx/mac/classic/textctrl.h
+++ b/include/wx/mac/classic/textctrl.h
@@ -69,9 +69,6 @@ public:
   virtual void Replace(long from, long to, const wxString& value);
   virtual void Remove(long from, long to);
 
-  // load the controls contents from the file
-  virtual bool LoadFile(const wxString& file);
-
   // sets/clears the dirty flag
   virtual void MarkDirty();
   virtual void DiscardEdits();
diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h
index 44cbc3653b..2988ed08df 100644
--- a/include/wx/msw/textctrl.h
+++ b/include/wx/msw/textctrl.h
@@ -66,9 +66,8 @@ public:
     virtual void Replace(long from, long to, const wxString& value);
     virtual void Remove(long from, long to);
 
-    // load the controls contents from the file
-    virtual bool LoadFile(const wxString& file);
-    virtual bool LoadFile(const wxString& file, int WXUNUSED(fileType)) { return LoadFile(file); }
+    // load the control's contents from the file
+    virtual bool DoLoadFile(const wxString& file, int fileType);
 
     // clears the dirty flag
     virtual void MarkDirty();
diff --git a/include/wx/os2/textctrl.h b/include/wx/os2/textctrl.h
index 547e1191a9..81085c80a3 100644
--- a/include/wx/os2/textctrl.h
+++ b/include/wx/os2/textctrl.h
@@ -72,7 +72,7 @@ public:
                         ,long lTo
                        );
 
-    virtual bool LoadFile(const wxString& rsFile);
+    virtual bool DoLoadFile(const wxString& rsFile, int fileType);
 
     virtual void MarkDirty();
     virtual void DiscardEdits(void);
diff --git a/include/wx/palmos/textctrl.h b/include/wx/palmos/textctrl.h
index 465d2134fa..6b1bb1ba54 100644
--- a/include/wx/palmos/textctrl.h
+++ b/include/wx/palmos/textctrl.h
@@ -64,8 +64,8 @@ public:
     virtual void Replace(long from, long to, const wxString& value);
     virtual void Remove(long from, long to);
 
-    // load the controls contents from the file
-    virtual bool LoadFile(const wxString& file);
+    // load the control's contents from the file
+    virtual bool DoLoadFile(const wxString& file, int fileType);
 
     // clears the dirty flag
     virtual void MarkDirty();
diff --git a/include/wx/richtext/richtextctrl.h b/include/wx/richtext/richtextctrl.h
index d1dd775079..9cad286cde 100644
--- a/include/wx/richtext/richtextctrl.h
+++ b/include/wx/richtext/richtextctrl.h
@@ -157,11 +157,14 @@ public:
     virtual void Replace(long from, long to, const wxString& value);
     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
-    virtual bool LoadFile(const wxString& file) { return LoadFile(file, wxRICHTEXT_TYPE_ANY); }
-    virtual bool LoadFile(const wxString& file, int type);
-    virtual bool SaveFile(const wxString& file = wxEmptyString) { return SaveFile(file, wxRICHTEXT_TYPE_ANY); }
-    virtual bool SaveFile(const wxString& file, int type);
+    virtual bool DoLoadFile(const wxString& file, int fileType);
+    virtual bool DoSaveFile(const wxString& file = wxEmptyString, int fileType = wxRICHTEXT_TYPE_ANY);
 
     // sets/clears the dirty flag
     virtual void MarkDirty();
@@ -735,8 +738,10 @@ private:
     /// Text buffer
     wxRichTextBuffer        m_buffer;
 
+#if !wxRICHTEXT_DERIVES_FROM_TEXTCTRLBASE
     /// Filename
     wxString                m_filename;
+#endif
 
     wxMenu*                 m_contextMenu;
 
diff --git a/include/wx/textctrl.h b/include/wx/textctrl.h
index ecdbef164f..204c28b7df 100644
--- a/include/wx/textctrl.h
+++ b/include/wx/textctrl.h
@@ -128,6 +128,12 @@ const wxTextCoord wxInvalidTextCoord    = -2;
 #define wxTE_CAPITALIZE     0
 #endif
 
+// ----------------------------------------------------------------------------
+// wxTextCtrl file types
+// ----------------------------------------------------------------------------
+
+#define wxTEXT_TYPE_ANY     0
+
 // ----------------------------------------------------------------------------
 // wxTextCtrl::HitTest return values
 // ----------------------------------------------------------------------------
@@ -320,11 +326,13 @@ public:
     virtual void Replace(long from, long to, const wxString& value) = 0;
     virtual void Remove(long from, long to) = 0;
 
-    // load/save the controls contents from/to the file
-    virtual bool LoadFile(const wxString& file);
-    virtual bool LoadFile(const wxString& file, int WXUNUSED(fileType)) { return LoadFile(file); }
-    virtual bool SaveFile(const wxString& file = wxEmptyString);
-    virtual bool SaveFile(const wxString& file, int WXUNUSED(fileType)) { return SaveFile(file); }
+    // load/save the control's contents from/to a file
+    bool LoadFile(const wxString& file, int fileType = wxTEXT_TYPE_ANY) { return DoLoadFile(file, fileType); }
+    bool SaveFile(const wxString& file = wxEmptyString, int fileType = wxTEXT_TYPE_ANY);
+
+    // implementation for loading/saving
+    virtual bool DoLoadFile(const wxString& file, int fileType);
+    virtual bool DoSaveFile(const wxString& file, int fileType);
 
     // sets/clears the dirty flag
     virtual void MarkDirty() = 0;
diff --git a/src/common/textcmn.cpp b/src/common/textcmn.cpp
index 9da659d9fb..8722f3ba0c 100644
--- a/src/common/textcmn.cpp
+++ b/src/common/textcmn.cpp
@@ -196,7 +196,7 @@ const wxTextAttr& wxTextCtrlBase::GetDefaultStyle() const
 // file IO functions
 // ----------------------------------------------------------------------------
 
-bool wxTextCtrlBase::LoadFile(const wxString& filename)
+bool wxTextCtrlBase::DoLoadFile(const wxString& filename, int WXUNUSED(fileType))
 {
 #if wxUSE_FFILE
     wxFFile file(filename);
@@ -221,7 +221,7 @@ bool wxTextCtrlBase::LoadFile(const wxString& filename)
     return false;
 }
 
-bool wxTextCtrlBase::SaveFile(const wxString& filename)
+bool wxTextCtrlBase::SaveFile(const wxString& filename, int fileType)
 {
     wxString filenameToUse = filename.empty() ? m_filename : filename;
     if ( filenameToUse.empty() )
@@ -232,16 +232,21 @@ bool wxTextCtrlBase::SaveFile(const wxString& filename)
         return false;
     }
 
+    return DoSaveFile(filenameToUse, fileType);
+}
+
+bool wxTextCtrlBase::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
+{
 #if wxUSE_FFILE
-    wxFFile file(filenameToUse, _T("w"));
+    wxFFile file(filename, _T("w"));
     if ( file.IsOpened() && file.Write(GetValue()) )
     {
+        // if it worked, save for future calls
+        m_filename = filename;
+        
         // it's not modified any longer
         DiscardEdits();
 
-        // if it worked, save for future calls
-        m_filename = filenameToUse;
-
         return true;
     }
 #endif // wxUSE_FFILE
diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp
index 41bcbaea0d..3ee3663952 100644
--- a/src/mac/carbon/textctrl.cpp
+++ b/src/mac/carbon/textctrl.cpp
@@ -705,11 +705,6 @@ void wxTextCtrl::SetSelection(long from, long to)
     GetPeer()->SetSelection( from , to ) ;
 }
 
-bool wxTextCtrl::LoadFile(const wxString& file)
-{
-    return wxTextCtrlBase::LoadFile( file );
-}
-
 void wxTextCtrl::WriteText(const wxString& str)
 {
     // TODO: this MPRemoting will be moved into a remoting peer proxy for any command
diff --git a/src/mac/classic/textctrl.cpp b/src/mac/classic/textctrl.cpp
index 076e53e031..633d379688 100644
--- a/src/mac/classic/textctrl.cpp
+++ b/src/mac/classic/textctrl.cpp
@@ -1275,16 +1275,6 @@ void wxTextCtrl::SetSelection(long from, long to)
     }
 }
 
-bool wxTextCtrl::LoadFile(const wxString& file)
-{
-    if ( wxTextCtrlBase::LoadFile(file) )
-    {
-        return true;
-    }
-
-    return false;
-}
-
 void wxTextCtrl::WriteText(const wxString& str)
 {
     wxString st = str ;
diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp
index f4193cf875..5db4094a34 100644
--- a/src/msw/textctrl.cpp
+++ b/src/msw/textctrl.cpp
@@ -1405,9 +1405,9 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
 // Working with files
 // ----------------------------------------------------------------------------
 
-bool wxTextCtrl::LoadFile(const wxString& file)
+bool wxTextCtrl::DoLoadFile(const wxString& file, int fileType)
 {
-    if ( wxTextCtrlBase::LoadFile(file) )
+    if ( wxTextCtrlBase::DoLoadFile(file, fileType) )
     {
         // update the size limit if needed
         AdjustSpaceLimit();
diff --git a/src/os2/textctrl.cpp b/src/os2/textctrl.cpp
index 0645fb3ed2..91a81672f6 100644
--- a/src/os2/textctrl.cpp
+++ b/src/os2/textctrl.cpp
@@ -680,10 +680,11 @@ void wxTextCtrl::SetSelection(
 } // end of wxTextCtrl::SetSelection
 
 bool wxTextCtrl::LoadFile(
-  const wxString&                   rsFile
+  const wxString&                   rsFile,
+  int                               fileType
 )
 {
-    if ( wxTextCtrlBase::LoadFile(rsFile) )
+    if ( wxTextCtrlBase::DoLoadFile(rsFile, fileType) )
     {
         //
         // Update the size limit if needed
@@ -692,7 +693,7 @@ bool wxTextCtrl::LoadFile(
         return true;
     }
     return false;
-} // end of wxTextCtrl::LoadFile
+} // end of wxTextCtrl::DoLoadFile
 
 bool wxTextCtrl::IsModified() const
 {
diff --git a/src/palmos/textctrl.cpp b/src/palmos/textctrl.cpp
index 13887eb9f4..b27b0c5f3b 100644
--- a/src/palmos/textctrl.cpp
+++ b/src/palmos/textctrl.cpp
@@ -390,7 +390,7 @@ void wxTextCtrl::DoSetSelection(long from, long to, bool scrollCaret)
 // Working with files
 // ----------------------------------------------------------------------------
 
-bool wxTextCtrl::LoadFile(const wxString& file)
+bool wxTextCtrl::DoLoadFile(const wxString& file, int fileType)
 {
     return false;
 }
diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp
index 7143227ccc..c617f47cfa 100644
--- a/src/richtext/richtextctrl.cpp
+++ b/src/richtext/richtextctrl.cpp
@@ -1525,9 +1525,30 @@ bool wxRichTextCtrl::RecreateBuffer(const wxSize& size)
 // 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;
 
@@ -1549,25 +1570,15 @@ bool wxRichTextCtrl::LoadFile(const wxString& filename, int type)
     }
 }
 
-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."));
-- 
2.45.2

