]>
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
55 #endif // NO_TEXT_WINDOW_STREAM
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 bool wxTextCtrlBase::LoadFile(const wxString
& filename
)
64 wxFFile
file(filename
);
65 if ( file
.IsOpened() )
68 if ( file
.ReadAll(&text
) )
74 m_filename
= filename
;
80 wxLogError(_("File couldn't be loaded."));
85 bool wxTextCtrlBase::SaveFile(const wxString
& filename
)
87 wxString filenameToUse
= filename
.IsEmpty() ? m_filename
: filename
;
90 // what kind of message to give? is it an error or a program bug?
91 wxLogDebug(wxT("Can't save textctrl to file without filename."));
96 wxFFile
file(filename
, "w");
97 if ( file
.IsOpened() && file
.Write(GetValue()) )
99 // it's not modified any longer
102 m_filename
= filename
;
107 wxLogError(_("The text couldn't be saved."));
112 // ----------------------------------------------------------------------------
113 // stream-like insertion operator
114 // ----------------------------------------------------------------------------
116 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
119 return *TEXTCTRL(this);
122 wxTextCtrl
& wxTextCtrlBase::operator<<(float f
)
125 str
.Printf(wxT("%.2f"), f
);
127 return *TEXTCTRL(this);
130 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
133 str
.Printf(wxT("%.2f"), d
);
135 return *TEXTCTRL(this);
138 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
141 str
.Printf(wxT("%d"), i
);
143 return *TEXTCTRL(this);
146 wxTextCtrl
& wxTextCtrlBase::operator<<(long i
)
149 str
.Printf(wxT("%ld"), i
);
151 return *TEXTCTRL(this);
154 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxChar c
)
156 return operator<<(wxString(c
));
159 // ----------------------------------------------------------------------------
160 // streambuf methods implementation
161 // ----------------------------------------------------------------------------
163 #ifndef NO_TEXT_WINDOW_STREAM
165 int wxTextCtrlBase::overflow( int WXUNUSED(c
) )
167 int len
= pptr() - pbase();
168 char *txt
= new char[len
+1];
169 strncpy(txt
, pbase(), len
);
172 setp(pbase(), epptr());
177 int wxTextCtrlBase::sync()
179 int len
= pptr() - pbase();
180 char *txt
= new char[len
+1];
181 strncpy(txt
, pbase(), len
);
184 setp(pbase(), epptr());
189 int wxTextCtrlBase::underflow()
194 #endif // NO_TEXT_WINDOW_STREAM