]> git.saurik.com Git - wxWidgets.git/commitdiff
1. wxTextCtrl compilation fixes for wxGTK and more ugfixes (untested yet)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 15 Jul 1999 13:42:27 +0000 (13:42 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 15 Jul 1999 13:42:27 +0000 (13:42 +0000)
   for wxMSW. Small doc update, too.
2. wxFFile compilation fixes for wxGTK
3. new files added to gtk/Makefile.am

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3006 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
docs/latex/wx/text.tex
include/wx/gtk/textctrl.h
include/wx/gtk1/textctrl.h
include/wx/msw/textctrl.h
include/wx/textctrl.h
src/common/ffile.cpp
src/common/textcmn.cpp
src/gtk/Makefile.am
src/gtk/textctrl.cpp
src/gtk1/Makefile.am
src/gtk1/textctrl.cpp
src/msw/textctrl.cpp

index d0324945c58b88e12486385ca8799c53fc27b02f..deb52984b49d2db8b8f84375859f163b91b5ed85 100644 (file)
@@ -390,7 +390,7 @@ Pastes text from the clipboard to the text item.
 
 \membersection{wxTextCtrl::PositionToXY}\label{wxtextctrlpositiontoxy}
 
-\constfunc{long}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
+\constfunc{bool}{PositionToXY}{\param{long }{pos}, \param{long *}{x}, \param{long *}{y}}
 
 Converts given position to a zero-based column, line number pair.
 
@@ -404,7 +404,7 @@ Converts given position to a zero-based column, line number pair.
 
 \wxheading{Return value}
 
-Non-zero on success, zero on failure (most likely due to a too large position
+TRUE on success, FALSE on failure (most likely due to a too large position
 parameter).
 
 \wxheading{See also}
index b480306b089d1f40c93a2aae5dc3565fd0d28ec4..a12d3ccae226a5eb230da466fc279c2c658d98f6 100644 (file)
@@ -62,10 +62,6 @@ public:
     virtual void Replace(long from, long to, const wxString& value);
     virtual void Remove(long from, long to);
 
-    // load/save the controls contents from/to the file
-    virtual bool LoadFile(const wxString& file);
-    virtual bool SaveFile(const wxString& file);
-
     // clears the dirty flag
     virtual void DiscardEdits();
 
@@ -78,7 +74,7 @@ public:
     // considering all its contents as a single strings) and (x, y) coordinates
     // which represent column and line.
     virtual long XYToPosition(long x, long y) const;
-    virtual void PositionToXY(long pos, long *x, long *y) const;
+    virtual bool PositionToXY(long pos, long *x, long *y) const;
 
     virtual void ShowPosition(long pos);
 
@@ -132,6 +128,8 @@ public:
     void ApplyWidgetStyle();
     void CalculateScrollbar();
 
+    void SetModified() { m_modified = TRUE; }
+
 private:
     bool        m_modified;
     GtkWidget  *m_text;
index b480306b089d1f40c93a2aae5dc3565fd0d28ec4..a12d3ccae226a5eb230da466fc279c2c658d98f6 100644 (file)
@@ -62,10 +62,6 @@ public:
     virtual void Replace(long from, long to, const wxString& value);
     virtual void Remove(long from, long to);
 
-    // load/save the controls contents from/to the file
-    virtual bool LoadFile(const wxString& file);
-    virtual bool SaveFile(const wxString& file);
-
     // clears the dirty flag
     virtual void DiscardEdits();
 
@@ -78,7 +74,7 @@ public:
     // considering all its contents as a single strings) and (x, y) coordinates
     // which represent column and line.
     virtual long XYToPosition(long x, long y) const;
-    virtual void PositionToXY(long pos, long *x, long *y) const;
+    virtual bool PositionToXY(long pos, long *x, long *y) const;
 
     virtual void ShowPosition(long pos);
 
@@ -132,6 +128,8 @@ public:
     void ApplyWidgetStyle();
     void CalculateScrollbar();
 
+    void SetModified() { m_modified = TRUE; }
+
 private:
     bool        m_modified;
     GtkWidget  *m_text;
index 3e66b4a49e7f0dcf7cb704edc878236fe2eefbb5..00675d4c95e08ac141d67300ed7a654bb0888f5f 100644 (file)
@@ -88,7 +88,7 @@ public:
     // considering all its contents as a single strings) and (x, y) coordinates
     // which represent column and line.
     virtual long XYToPosition(long x, long y) const;
-    virtual void PositionToXY(long pos, long *x, long *y) const;
+    virtual bool PositionToXY(long pos, long *x, long *y) const;
 
     virtual void ShowPosition(long pos);
 
index 77500f4a5db688d1c183fc18e0f0c754c7df16a2..ec72f8f37719fdcb511712341354450d6fc4b00e 100644 (file)
@@ -36,6 +36,8 @@
     #endif // wxUSE_STD_IOSTREAM/!wxUSE_STD_IOSTREAM
 #endif
 
+class WXDLLEXPORT wxTextCtrl;
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
@@ -100,7 +102,7 @@ public:
     // considering all its contents as a single strings) and (x, y) coordinates
     // which represent column and line.
     virtual long XYToPosition(long x, long y) const = 0;
-    virtual void PositionToXY(long pos, long *x, long *y) const = 0;
+    virtual bool PositionToXY(long pos, long *x, long *y) const = 0;
 
     virtual void ShowPosition(long pos) = 0;
 
index 69d1c04af8d5db3718a2135dc0072ba1f91caba4..4e1aea21ecce0669d15c8a441479fc8fd558b9cb 100644 (file)
@@ -31,6 +31,8 @@
 #if wxUSE_FILE
 
 #ifndef WX_PRECOMP
+    #include "wx/intl.h"
+    #include "wx/log.h"
 #endif
 
 #include "wx/ffile.h"
index 33796a5371efc7ea745a8113f01e5f13021a99bc..ccaa6e3bfa3b41a1d608b40dfd7c4f05acb27cfc 100644 (file)
@@ -21,6 +21,8 @@
 #endif
 
 #ifndef WX_PRECOMP
+    #include "wx/intl.h"
+    #include "wx/log.h"
     #include "wx/textctrl.h"
 #endif // WX_PRECOMP
 
 
 wxTextCtrlBase::wxTextCtrlBase()
 {
+#ifndef NO_TEXT_WINDOW_STREAM
+    if (allocate())
+        setp(base(),ebuf());
+#endif // NO_TEXT_WINDOW_STREAM
 }
 
 // ----------------------------------------------------------------------------
index 596102f8d1c10d7b5d3ad45ea629d62142124381..edda346de00d9f54be242ae2c0ab1a580dfa5b70 100644 (file)
@@ -41,6 +41,7 @@ libwx_gtk_la_SOURCES = \
  dynarray.cpp \
  dynlib.cpp \
  event.cpp \
+ ffile.cpp \
  file.cpp \
  fileconf.cpp \
  filefn.cpp \
@@ -88,6 +89,7 @@ libwx_gtk_la_SOURCES = \
  string.cpp \
  tbarbase.cpp \
  tbarsmpl.cpp \
+ textcmn.cpp \
  textfile.cpp \
  txtstrm.cpp \
  time.cpp \
index 8e7d38a8869bb0630b738894a824e1de90faeac6..93d3bf216b8a8913d50830a307da3f59b92cbc22 100644 (file)
@@ -94,31 +94,11 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
     EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
 END_EVENT_TABLE()
 
-#if wxUSE_STD_IOSTREAM
-wxTextCtrl::wxTextCtrl() : streambuf()
-{
-    if (allocate()) setp(base(),ebuf());
-
-    m_modified = FALSE;
-}
-#else
 wxTextCtrl::wxTextCtrl()
 {
     m_modified = FALSE;
 }
-#endif
-
-#if wxUSE_STD_IOSTREAM
-wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
-      const wxPoint &pos, const wxSize &size,
-      int style, const wxValidator& validator, const wxString &name ) : streambuf()
-{
-    if (allocate()) setp(base(),ebuf());
 
-    m_modified = FALSE;
-    Create( parent, id, value, pos, size, style, validator, name );
-}
-#else
 wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
       const wxPoint &pos, const wxSize &size,
       int style, const wxValidator& validator, const wxString &name )
@@ -126,7 +106,6 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
     m_modified = FALSE;
     Create( parent, id, value, pos, size, style, validator, name );
 }
-#endif
 
 bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
       const wxPoint &pos, const wxSize &size,
@@ -438,108 +417,6 @@ void wxTextCtrl::AppendText( const wxString &text )
       GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
 }
 
-bool wxTextCtrl::LoadFile( const wxString &file )
-{
-    wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
-
-    if (!wxFileExists(file)) return FALSE;
-
-    Clear();
-
-    FILE *fp = (FILE*) NULL;
-    struct stat statb;
-
-    if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
-        !(fp = fopen (FNSTRINGCAST file.fn_str(), "r")))
-    {
-        return FALSE;
-    }
-    else
-    {
-        gint len = statb.st_size;
-        char *text;
-        if (!(text = (char*)malloc ((unsigned) (len + 1))))
-        {
-            fclose (fp);
-            return FALSE;
-        }
-        if (fread (text, sizeof (char), len, fp) != (size_t) len)
-        {
-        }
-        fclose (fp);
-
-        text[len] = 0;
-
-        gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
-          GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
-
-        if (m_windowStyle & wxTE_MULTILINE)
-        {
-            gint pos = 0;
-            gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos );
-        }
-        else
-        {
-            gtk_entry_set_text( GTK_ENTRY(m_text), text );
-        }
-
-        gtk_signal_connect( GTK_OBJECT(m_text), "changed",
-          GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
-
-        free (text);
-        m_modified = FALSE;
-        return TRUE;
-    }
-    return FALSE;
-}
-
-bool wxTextCtrl::SaveFile( const wxString &file )
-{
-    wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
-
-    if (file == _T("")) return FALSE;
-
-    FILE *fp;
-
-    if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w")))
-    {
-        return FALSE;
-    }
-    else
-    {
-      char *text = (char*) NULL;
-      gint len = 0;
-
-      if (m_windowStyle & wxTE_MULTILINE)
-      {
-          len = gtk_text_get_length( GTK_TEXT(m_text) );
-          text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
-      }
-      else
-      {
-          text = gtk_entry_get_text( GTK_ENTRY(m_text) );
-      }
-
-      if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
-      {
-          // Did not write whole file
-      }
-
-      // Make sure newline terminates the file
-      if (text[len - 1] != '\n')
-          fputc ('\n', fp);
-
-      fclose (fp);
-
-      if (m_windowStyle & wxTE_MULTILINE) g_free( text );
-
-      m_modified = FALSE;
-      return TRUE;
-    }
-
-    return TRUE;
-}
-
 wxString wxTextCtrl::GetLineText( long lineNo ) const
 {
   if (m_windowStyle & wxTE_MULTILINE)
@@ -580,7 +457,7 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
     wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
 }
 
-long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
+bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
 {
     if ( m_windowStyle & wxTE_MULTILINE )
     {
@@ -727,6 +604,11 @@ void wxTextCtrl::SetEditable( bool editable )
         gtk_entry_set_editable( GTK_ENTRY(m_text), editable );
 }
 
+void wxTextCtrl::DiscardEdits()
+{
+    m_modified = FALSE;
+}
+
 void wxTextCtrl::SetSelection( long from, long to )
 {
     wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
@@ -913,6 +795,11 @@ bool wxTextCtrl::IsEditable() const
     return GTK_EDITABLE(m_text)->editable;
 }
 
+bool wxTextCtrl::IsModified() const
+{
+    return m_modified;
+}
+
 void wxTextCtrl::Clear()
 {
     SetValue( _T("") );
index 596102f8d1c10d7b5d3ad45ea629d62142124381..edda346de00d9f54be242ae2c0ab1a580dfa5b70 100644 (file)
@@ -41,6 +41,7 @@ libwx_gtk_la_SOURCES = \
  dynarray.cpp \
  dynlib.cpp \
  event.cpp \
+ ffile.cpp \
  file.cpp \
  fileconf.cpp \
  filefn.cpp \
@@ -88,6 +89,7 @@ libwx_gtk_la_SOURCES = \
  string.cpp \
  tbarbase.cpp \
  tbarsmpl.cpp \
+ textcmn.cpp \
  textfile.cpp \
  txtstrm.cpp \
  time.cpp \
index 8e7d38a8869bb0630b738894a824e1de90faeac6..93d3bf216b8a8913d50830a307da3f59b92cbc22 100644 (file)
@@ -94,31 +94,11 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
     EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
 END_EVENT_TABLE()
 
-#if wxUSE_STD_IOSTREAM
-wxTextCtrl::wxTextCtrl() : streambuf()
-{
-    if (allocate()) setp(base(),ebuf());
-
-    m_modified = FALSE;
-}
-#else
 wxTextCtrl::wxTextCtrl()
 {
     m_modified = FALSE;
 }
-#endif
-
-#if wxUSE_STD_IOSTREAM
-wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
-      const wxPoint &pos, const wxSize &size,
-      int style, const wxValidator& validator, const wxString &name ) : streambuf()
-{
-    if (allocate()) setp(base(),ebuf());
 
-    m_modified = FALSE;
-    Create( parent, id, value, pos, size, style, validator, name );
-}
-#else
 wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
       const wxPoint &pos, const wxSize &size,
       int style, const wxValidator& validator, const wxString &name )
@@ -126,7 +106,6 @@ wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value,
     m_modified = FALSE;
     Create( parent, id, value, pos, size, style, validator, name );
 }
-#endif
 
 bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
       const wxPoint &pos, const wxSize &size,
@@ -438,108 +417,6 @@ void wxTextCtrl::AppendText( const wxString &text )
       GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
 }
 
-bool wxTextCtrl::LoadFile( const wxString &file )
-{
-    wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
-
-    if (!wxFileExists(file)) return FALSE;
-
-    Clear();
-
-    FILE *fp = (FILE*) NULL;
-    struct stat statb;
-
-    if ((stat (FNSTRINGCAST file.fn_str(), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
-        !(fp = fopen (FNSTRINGCAST file.fn_str(), "r")))
-    {
-        return FALSE;
-    }
-    else
-    {
-        gint len = statb.st_size;
-        char *text;
-        if (!(text = (char*)malloc ((unsigned) (len + 1))))
-        {
-            fclose (fp);
-            return FALSE;
-        }
-        if (fread (text, sizeof (char), len, fp) != (size_t) len)
-        {
-        }
-        fclose (fp);
-
-        text[len] = 0;
-
-        gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
-          GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
-
-        if (m_windowStyle & wxTE_MULTILINE)
-        {
-            gint pos = 0;
-            gtk_editable_insert_text( GTK_EDITABLE(m_text), text, len, &pos );
-        }
-        else
-        {
-            gtk_entry_set_text( GTK_ENTRY(m_text), text );
-        }
-
-        gtk_signal_connect( GTK_OBJECT(m_text), "changed",
-          GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
-
-        free (text);
-        m_modified = FALSE;
-        return TRUE;
-    }
-    return FALSE;
-}
-
-bool wxTextCtrl::SaveFile( const wxString &file )
-{
-    wxCHECK_MSG( m_text != NULL, FALSE, _T("invalid text ctrl") );
-
-    if (file == _T("")) return FALSE;
-
-    FILE *fp;
-
-    if (!(fp = fopen (FNSTRINGCAST file.fn_str(), "w")))
-    {
-        return FALSE;
-    }
-    else
-    {
-      char *text = (char*) NULL;
-      gint len = 0;
-
-      if (m_windowStyle & wxTE_MULTILINE)
-      {
-          len = gtk_text_get_length( GTK_TEXT(m_text) );
-          text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
-      }
-      else
-      {
-          text = gtk_entry_get_text( GTK_ENTRY(m_text) );
-      }
-
-      if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
-      {
-          // Did not write whole file
-      }
-
-      // Make sure newline terminates the file
-      if (text[len - 1] != '\n')
-          fputc ('\n', fp);
-
-      fclose (fp);
-
-      if (m_windowStyle & wxTE_MULTILINE) g_free( text );
-
-      m_modified = FALSE;
-      return TRUE;
-    }
-
-    return TRUE;
-}
-
 wxString wxTextCtrl::GetLineText( long lineNo ) const
 {
   if (m_windowStyle & wxTE_MULTILINE)
@@ -580,7 +457,7 @@ void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
     wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
 }
 
-long wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
+bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
 {
     if ( m_windowStyle & wxTE_MULTILINE )
     {
@@ -727,6 +604,11 @@ void wxTextCtrl::SetEditable( bool editable )
         gtk_entry_set_editable( GTK_ENTRY(m_text), editable );
 }
 
+void wxTextCtrl::DiscardEdits()
+{
+    m_modified = FALSE;
+}
+
 void wxTextCtrl::SetSelection( long from, long to )
 {
     wxCHECK_RET( m_text != NULL, _T("invalid text ctrl") );
@@ -913,6 +795,11 @@ bool wxTextCtrl::IsEditable() const
     return GTK_EDITABLE(m_text)->editable;
 }
 
+bool wxTextCtrl::IsModified() const
+{
+    return m_modified;
+}
+
 void wxTextCtrl::Clear()
 {
     SetValue( _T("") );
index 0a3471b403f09cc226d01408acbb0eff6f7e0617..55e3e77492451babc8e3e8348e8e761c62021761 100644 (file)
@@ -603,17 +603,41 @@ long wxTextCtrl::XYToPosition(long x, long y) const
     return (long)(x + charIndex);
 }
 
-void wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
+bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
 {
     HWND hWnd = GetHwnd();
 
     // This gets the line number containing the character
-    int lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0);
+    int lineNo;
+#if wxUSE_RICHEDIT
+    if ( m_isRich )
+    {
+        lineNo = (int)SendMessage(hWnd, EM_EXLINEFROMCHAR, 0, (LPARAM)pos);
+    }
+    else
+#endif // wxUSE_RICHEDIT
+        lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
+
+    if ( lineNo == -1 )
+    {
+        // no such line
+        return FALSE;
+    }
+
     // This gets the char index for the _beginning_ of this line
     int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
+    if ( charIndex == -1 )
+    {
+        return FALSE;
+    }
+
     // The X position must therefore be the different between pos and charIndex
-    *x = (long)(pos - charIndex);
-    *y = (long)lineNo;
+    if ( x )
+        *x = (long)(pos - charIndex);
+    if ( y )
+        *y = (long)lineNo;
+
+    return TRUE;
 }
 
 void wxTextCtrl::ShowPosition(long pos)