]>
git.saurik.com Git - wxWidgets.git/blob - src/common/textcmn.cpp
ccaa6e3bfa3b41a1d608b40dfd7c4f05acb27cfc
   1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        common/textcmn.cpp 
   3 // Purpose:     implementation of platform-independent functions of wxTextCtrl 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) wxWindows team 
   9 // Licence:     wxWindows license 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // for compilers that support precompilation, includes "wx.h". 
  17 #include "wx/wxprec.h" 
  26     #include "wx/textctrl.h" 
  31 // ---------------------------------------------------------------------------- 
  33 // ---------------------------------------------------------------------------- 
  35 // we don't have any objects of type wxTextCtrlBase in the program, only 
  36 // wxTextCtrl, so this cast is safe 
  37 #define TEXTCTRL(ptr)   ((wxTextCtrl *)(ptr)) 
  39 // ============================================================================ 
  41 // ============================================================================ 
  43 // ---------------------------------------------------------------------------- 
  45 // ---------------------------------------------------------------------------- 
  47 wxTextCtrlBase::wxTextCtrlBase() 
  49 #ifndef NO_TEXT_WINDOW_STREAM 
  52 #endif // NO_TEXT_WINDOW_STREAM 
  55 // ---------------------------------------------------------------------------- 
  57 // ---------------------------------------------------------------------------- 
  59 bool wxTextCtrlBase::LoadFile(const wxString
& filename
) 
  61     wxFFile 
file(filename
); 
  62     if ( file
.IsOpened() ) 
  65         if ( file
.ReadAll(&text
) ) 
  71             m_filename 
= filename
; 
  77     wxLogError(_("File couldn't be loaded.")); 
  82 bool wxTextCtrlBase::SaveFile(const wxString
& filename
) 
  84     wxString filenameToUse 
= filename
.IsEmpty() ? m_filename 
: filename
; 
  87         // what kind of message to give? is it an error or a program bug? 
  88         wxLogDebug(_T("Can't save textctrl to file without filename.")); 
  93     wxFFile 
file(filename
, "w"); 
  94     if ( file
.IsOpened() && file
.Write(GetValue()) ) 
  96         // it's not modified any longer 
  99         m_filename 
= filename
; 
 104     wxLogError(_("The text couldn't be saved.")); 
 109 // ---------------------------------------------------------------------------- 
 110 // stream-like insertion operator 
 111 // ---------------------------------------------------------------------------- 
 113 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
) 
 116     return *TEXTCTRL(this); 
 119 wxTextCtrl
& wxTextCtrlBase::operator<<(float f
) 
 122     str
.Printf(_T("%.2f"), f
); 
 124     return *TEXTCTRL(this); 
 127 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
) 
 130     str
.Printf(_T("%.2f"), d
); 
 132     return *TEXTCTRL(this); 
 135 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
) 
 138     str
.Printf(_T("%d"), i
); 
 140     return *TEXTCTRL(this); 
 143 wxTextCtrl
& wxTextCtrlBase::operator<<(long i
) 
 146     str
.Printf(_T("%ld"), i
); 
 148     return *TEXTCTRL(this); 
 151 wxTextCtrl
& wxTextCtrlBase::operator<<(const char c
) 
 153     return operator<<(wxString(c
)); 
 156 // ---------------------------------------------------------------------------- 
 157 // streambuf methods implementation 
 158 // ---------------------------------------------------------------------------- 
 160 #ifndef NO_TEXT_WINDOW_STREAM 
 162 int wxTextCtrlBase::overflow( int WXUNUSED(c
) ) 
 164     int len 
= pptr() - pbase(); 
 165     char *txt 
= new char[len
+1]; 
 166     strncpy(txt
, pbase(), len
); 
 169     setp(pbase(), epptr()); 
 174 int wxTextCtrlBase::sync() 
 176     int len 
= pptr() - pbase(); 
 177     char *txt 
= new char[len
+1]; 
 178     strncpy(txt
, pbase(), len
); 
 181     setp(pbase(), epptr()); 
 186 int wxTextCtrlBase::underflow() 
 191 #endif // NO_TEXT_WINDOW_STREAM