]>
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
54 #endif //NO_TEXT_WINDOW_STREAM
55 #endif //!wxUSE_IOSTREAMH
58 #ifndef NO_TEXT_WINDOW_STREAM
61 #endif // NO_TEXT_WINDOW_STREAM
62 #endif //wxUSE_IOSTREAMH
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 bool wxTextCtrlBase::LoadFile(const wxString
& filename
)
71 wxFFile
file(filename
);
72 if ( file
.IsOpened() )
75 if ( file
.ReadAll(&text
) )
81 m_filename
= filename
;
87 wxLogError(_("File couldn't be loaded."));
92 bool wxTextCtrlBase::SaveFile(const wxString
& filename
)
94 wxString filenameToUse
= filename
.IsEmpty() ? m_filename
: filename
;
97 // what kind of message to give? is it an error or a program bug?
98 wxLogDebug(wxT("Can't save textctrl to file without filename."));
103 wxFFile
file(filename
, "w");
104 if ( file
.IsOpened() && file
.Write(GetValue()) )
106 // it's not modified any longer
109 m_filename
= filename
;
114 wxLogError(_("The text couldn't be saved."));
119 // ----------------------------------------------------------------------------
120 // stream-like insertion operator
121 // ----------------------------------------------------------------------------
123 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
126 return *TEXTCTRL(this);
129 wxTextCtrl
& wxTextCtrlBase::operator<<(float f
)
132 str
.Printf(wxT("%.2f"), f
);
134 return *TEXTCTRL(this);
137 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
140 str
.Printf(wxT("%.2f"), d
);
142 return *TEXTCTRL(this);
145 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
148 str
.Printf(wxT("%d"), i
);
150 return *TEXTCTRL(this);
153 wxTextCtrl
& wxTextCtrlBase::operator<<(long i
)
156 str
.Printf(wxT("%ld"), i
);
158 return *TEXTCTRL(this);
161 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxChar c
)
163 return operator<<(wxString(c
));
166 // ----------------------------------------------------------------------------
167 // streambuf methods implementation
168 // ----------------------------------------------------------------------------
170 #ifndef NO_TEXT_WINDOW_STREAM
172 int wxTextCtrlBase::overflow( int WXUNUSED(c
) )
174 int len
= pptr() - pbase();
175 char *txt
= new char[len
+1];
176 strncpy(txt
, pbase(), len
);
179 setp(pbase(), epptr());
184 int wxTextCtrlBase::sync()
186 int len
= pptr() - pbase();
187 char *txt
= new char[len
+1];
188 strncpy(txt
, pbase(), len
);
191 setp(pbase(), epptr());
196 int wxTextCtrlBase::underflow()
201 #endif // NO_TEXT_WINDOW_STREAM