]>
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 // ----------------------------------------------------------------------------
73 // style functions - not implemented here
74 // ----------------------------------------------------------------------------
76 // apply styling to text range
77 bool wxTextCtrlBase::SetStyle(long WXUNUSED(start
), long WXUNUSED(end
),
78 const wxTextAttr
& WXUNUSED(style
))
80 // to be implemented in derived TextCtrl classes
84 // change default text attributes
85 bool wxTextCtrlBase::SetDefaultStyle(const wxTextAttr
&style
)
87 m_defaultStyle
= style
;
91 // get default text attributes
92 const wxTextAttr
& wxTextCtrlBase::GetDefaultStyle() const
94 return m_defaultStyle
;
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 bool wxTextCtrlBase::LoadFile(const wxString
& filename
)
103 wxFFile
file(filename
);
104 if ( file
.IsOpened() )
107 if ( file
.ReadAll(&text
) )
113 m_filename
= filename
;
119 wxLogError(_("File couldn't be loaded."));
124 bool wxTextCtrlBase::SaveFile(const wxString
& filename
)
126 wxString filenameToUse
= filename
.IsEmpty() ? m_filename
: filename
;
127 if ( !filenameToUse
)
129 // what kind of message to give? is it an error or a program bug?
130 wxLogDebug(wxT("Can't save textctrl to file without filename."));
135 wxFFile
file(filename
, "w");
136 if ( file
.IsOpened() && file
.Write(GetValue()) )
138 // it's not modified any longer
141 m_filename
= filename
;
146 wxLogError(_("The text couldn't be saved."));
151 // ----------------------------------------------------------------------------
152 // stream-like insertion operator
153 // ----------------------------------------------------------------------------
155 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
158 return *TEXTCTRL(this);
161 wxTextCtrl
& wxTextCtrlBase::operator<<(float f
)
164 str
.Printf(wxT("%.2f"), f
);
166 return *TEXTCTRL(this);
169 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
172 str
.Printf(wxT("%.2f"), d
);
174 return *TEXTCTRL(this);
177 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
180 str
.Printf(wxT("%d"), i
);
182 return *TEXTCTRL(this);
185 wxTextCtrl
& wxTextCtrlBase::operator<<(long i
)
188 str
.Printf(wxT("%ld"), i
);
190 return *TEXTCTRL(this);
193 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxChar c
)
195 return operator<<(wxString(c
));
198 // ----------------------------------------------------------------------------
199 // streambuf methods implementation
200 // ----------------------------------------------------------------------------
202 #ifndef NO_TEXT_WINDOW_STREAM
204 int wxTextCtrlBase::overflow( int WXUNUSED(c
) )
206 int len
= pptr() - pbase();
207 char *txt
= new char[len
+1];
208 strncpy(txt
, pbase(), len
);
211 setp(pbase(), epptr());
216 int wxTextCtrlBase::sync()
218 int len
= pptr() - pbase();
219 char *txt
= new char[len
+1];
220 strncpy(txt
, pbase(), len
);
223 setp(pbase(), epptr());
228 int wxTextCtrlBase::underflow()
233 #endif // NO_TEXT_WINDOW_STREAM