Inherit LoadFile and SaveFile from wxTextCtrlBase, reduce

flicker caused by SetValue (the text itself still flickers a
bit, but now borders don't).


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19885 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon 2003-03-30 19:32:00 +00:00
parent fdfd5d49eb
commit ccb234b4d0
2 changed files with 11 additions and 82 deletions

View File

@ -87,8 +87,6 @@ public:
virtual void GetSelection(long* from, long* to) const;
virtual bool IsEditable() const ;
virtual bool LoadFile(const wxString& file);
virtual bool SaveFile(const wxString& file);
virtual void WriteText(const wxString& text);
virtual void AppendText(const wxString& text);
virtual void DiscardEdits();

View File

@ -208,7 +208,8 @@ bool wxTextCtrl::Create(wxWindow *parent,
WXWidget wxTextCtrl::GetTopWidget() const
{
return ((m_windowStyle & wxTE_MULTILINE) ? (WXWidget) XtParent((Widget) m_mainWidget) : m_mainWidget);
return IsMultiLine() ? (WXWidget)XtParent((Widget)m_mainWidget)
: m_mainWidget;
}
wxString wxTextCtrl::GetValue() const
@ -249,9 +250,15 @@ void wxTextCtrl::SetValue(const wxString& value)
// do this instead... MB
//
// with (at least) OpenMotif 2.1 this causes a lot of flicker
#if 0
XtVaSetValues( (Widget) m_mainWidget,
XmNvalue, wxConstCast(value.c_str(), char),
NULL);
#endif
Clear();
AppendText( value );
m_inSetValue = FALSE;
}
@ -381,85 +388,6 @@ void wxTextCtrl::SetSelection(long from, long to)
(Time) 0);
}
bool wxTextCtrl::LoadFile(const wxString& file)
{
if (!wxFileExists(file))
return FALSE;
m_fileName = file;
Clear();
Widget textWidget = (Widget) m_mainWidget;
FILE *fp = 0;
struct stat statb;
if ((stat (wxConstCast(file.c_str(), char), &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
!(fp = fopen (wxConstCast(file.c_str(), char), "r")))
{
return FALSE;
}
else
{
long len = statb.st_size;
char *text;
if (!(text = XtMalloc ((unsigned) (len + 1))))
{
fclose (fp);
return FALSE;
}
if (fread (text, sizeof (char), len, fp) != (size_t) len)
{
}
fclose (fp);
text[len] = 0;
XmTextSetString (textWidget, text);
// m_textPosition = len;
XtFree (text);
m_modified = FALSE;
return TRUE;
}
}
// If file is null, try saved file name first
// Returns TRUE if succeeds.
bool wxTextCtrl::SaveFile(const wxString& file)
{
wxString theFile(file);
if (theFile == "")
theFile = m_fileName;
if (theFile == "")
return FALSE;
m_fileName = theFile;
Widget textWidget = (Widget) m_mainWidget;
FILE *fp;
if (!(fp = fopen (wxConstCast(theFile.c_str(), char), "w")))
{
return FALSE;
}
else
{
char *text = XmTextGetString (textWidget);
long len = XmTextGetLastPosition (textWidget);
if (fwrite (text, sizeof (char), len, fp) != (size_t) len)
{
// Did not write whole file
}
// Make sure newline terminates the file
if (text[len - 1] != '\n')
fputc ('\n', fp);
fclose (fp);
XtFree (text);
m_modified = FALSE;
return TRUE;
}
}
void wxTextCtrl::WriteText(const wxString& text)
{
long textPosition = GetInsertionPoint() + strlen (text);
@ -848,6 +776,9 @@ wxTextWindowModifyProc (Widget WXUNUSED(w), XtPointer clientData, XmTextVerifyCa
}
}
if(tw->InSetValue())
return;
// If we're already within an OnChar, return: probably a programmatic
// insertion.
if (tw->m_tempCallbackStruct)