]>
git.saurik.com Git - wxWidgets.git/blob - src/common/textcmn.cpp
33796a5371efc7ea745a8113f01e5f13021a99bc
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"
24 #include "wx/textctrl.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 // we don't have any objects of type wxTextCtrlBase in the program, only
34 // wxTextCtrl, so this cast is safe
35 #define TEXTCTRL(ptr) ((wxTextCtrl *)(ptr))
37 // ============================================================================
39 // ============================================================================
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 wxTextCtrlBase::wxTextCtrlBase()
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 bool wxTextCtrlBase::LoadFile(const wxString
& filename
)
55 wxFFile
file(filename
);
56 if ( file
.IsOpened() )
59 if ( file
.ReadAll(&text
) )
65 m_filename
= filename
;
71 wxLogError(_("File couldn't be loaded."));
76 bool wxTextCtrlBase::SaveFile(const wxString
& filename
)
78 wxString filenameToUse
= filename
.IsEmpty() ? m_filename
: filename
;
81 // what kind of message to give? is it an error or a program bug?
82 wxLogDebug(_T("Can't save textctrl to file without filename."));
87 wxFFile
file(filename
, "w");
88 if ( file
.IsOpened() && file
.Write(GetValue()) )
90 // it's not modified any longer
93 m_filename
= filename
;
98 wxLogError(_("The text couldn't be saved."));
103 // ----------------------------------------------------------------------------
104 // stream-like insertion operator
105 // ----------------------------------------------------------------------------
107 wxTextCtrl
& wxTextCtrlBase::operator<<(const wxString
& s
)
110 return *TEXTCTRL(this);
113 wxTextCtrl
& wxTextCtrlBase::operator<<(float f
)
116 str
.Printf(_T("%.2f"), f
);
118 return *TEXTCTRL(this);
121 wxTextCtrl
& wxTextCtrlBase::operator<<(double d
)
124 str
.Printf(_T("%.2f"), d
);
126 return *TEXTCTRL(this);
129 wxTextCtrl
& wxTextCtrlBase::operator<<(int i
)
132 str
.Printf(_T("%d"), i
);
134 return *TEXTCTRL(this);
137 wxTextCtrl
& wxTextCtrlBase::operator<<(long i
)
140 str
.Printf(_T("%ld"), i
);
142 return *TEXTCTRL(this);
145 wxTextCtrl
& wxTextCtrlBase::operator<<(const char c
)
147 return operator<<(wxString(c
));
150 // ----------------------------------------------------------------------------
151 // streambuf methods implementation
152 // ----------------------------------------------------------------------------
154 #ifndef NO_TEXT_WINDOW_STREAM
156 int wxTextCtrlBase::overflow( int WXUNUSED(c
) )
158 int len
= pptr() - pbase();
159 char *txt
= new char[len
+1];
160 strncpy(txt
, pbase(), len
);
163 setp(pbase(), epptr());
168 int wxTextCtrlBase::sync()
170 int len
= pptr() - pbase();
171 char *txt
= new char[len
+1];
172 strncpy(txt
, pbase(), len
);
175 setp(pbase(), epptr());
180 int wxTextCtrlBase::underflow()
185 #endif // NO_TEXT_WINDOW_STREAM