]>
git.saurik.com Git - wxWidgets.git/blob - src/common/textcmn.cpp
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 #pragma implementation "textctrlbase.h"
19 // for compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/textctrl.h"
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 // we don't have any objects of type wxTextCtrlBase in the program, only
39 // wxTextCtrl, so this cast is safe
40 #define TEXTCTRL(ptr) ((wxTextCtrl *)(ptr))
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxTextCtrlBase::wxTextCtrlBase()
52 #ifndef NO_TEXT_WINDOW_STREAM
57 m_streambuf
=new char[64];
58 setp(m_streambuf
,m_streambuf
+64);
59 #endif //wxUSE_IOSTREAMH
60 #endif // NO_TEXT_WINDOW_STREAM
63 wxTextCtrlBase::~wxTextCtrlBase()
65 #ifndef NO_TEXT_WINDOW_STREAM
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
76 bool wxTextCtrlBase::LoadFile(const wxString
& filename
)
78 wxFFile
file(filename
);
79 if ( file
.IsOpened() )
82 if ( file
.ReadAll(&text
) )
88 m_filename
= filename
;
94 wxLogError(_("File couldn't be loaded."));
99 bool wxTextCtrlBase::SaveFile(const wxString
& filename
)
101 wxString filenameToUse
= filename
.IsEmpty() ? m_filename
: filename
;
102 if ( !filenameToUse
)
104 // what kind of message to give? is it an error or a program bug?
105 wxLogDebug(wxT("Can't save textctrl to file without filename."));
110 wxFFile
file(filename
, "w");
111 if ( file
.IsOpened() && file
.Write(GetValue()) )
113 // it's not modified any longer
116 m_filename
= filename
;
121 wxLogError(_("The text couldn't be saved."));
126 // ----------------------------------------------------------------------------
127 // stream-like insertion operator
128 // ----------------------------------------------------------------------------
130 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
133 return *TEXTCTRL(this);
136 wxTextCtrl
& wxTextCtrlBase::operator<<(float f
)
139 str
.Printf(wxT("%.2f"), f
);
141 return *TEXTCTRL(this);
144 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
147 str
.Printf(wxT("%.2f"), d
);
149 return *TEXTCTRL(this);
152 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
155 str
.Printf(wxT("%d"), i
);
157 return *TEXTCTRL(this);
160 wxTextCtrl
& wxTextCtrlBase::operator<<(long i
)
163 str
.Printf(wxT("%ld"), i
);
165 return *TEXTCTRL(this);
168 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxChar c
)
170 return operator<<(wxString(c
));
173 // ----------------------------------------------------------------------------
174 // streambuf methods implementation
175 // ----------------------------------------------------------------------------
177 #ifndef NO_TEXT_WINDOW_STREAM
179 int wxTextCtrlBase::overflow( int WXUNUSED(c
) )
181 int len
= pptr() - pbase();
182 char *txt
= new char[len
+1];
183 strncpy(txt
, pbase(), len
);
186 setp(pbase(), epptr());
191 int wxTextCtrlBase::sync()
193 int len
= pptr() - pbase();
194 char *txt
= new char[len
+1];
195 strncpy(txt
, pbase(), len
);
198 setp(pbase(), epptr());
203 int wxTextCtrlBase::underflow()
208 #endif // NO_TEXT_WINDOW_STREAM