m_tempCallbackStruct = (void*) NULL;
m_modified = FALSE;
m_processedDefault = FALSE;
- m_inSetValue = FALSE;
}
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
m_modified = FALSE;
m_processedDefault = FALSE;
m_fileName = "";
- m_inSetValue = FALSE;
+ m_backgroundColour = parent->GetBackgroundColour();
+ m_foregroundColour = parent->GetForegroundColour();
SetName(name);
SetValidator(validator);
XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this);
+ m_windowFont = parent->GetFont();
+ ChangeFont(FALSE);
+
SetCanAddEventHandler(TRUE);
AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
- SetFont(* parent->GetFont());
- ChangeColour(m_mainWidget);
+ ChangeBackgroundColour();
return TRUE;
}
void wxTextCtrl::SetValue(const wxString& value)
{
- wxASSERT_MSG( (!value.IsNull()), "Must not pass a null string to wxTextCtrl::SetValue." ) ;
+ // This assert is wrong -- means that you can't set an empty
+ // string (IsNull == IsEmpty).
+ // wxASSERT_MSG( (!value.IsNull()), "Must not pass a null string to wxTextCtrl::SetValue." ) ;
m_inSetValue = TRUE;
XmTextSetString ((Widget) m_mainWidget, (char*) (const char*) value);
Clear();
- ifstream input((char*) (const char*) file, ios::nocreate | ios::in);
+ Widget textWidget = (Widget) m_mainWidget;
+ FILE *fp;
- if (!input.bad())
+ struct stat statb;
+ if ((stat ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
+ !(fp = fopen ((char*) (const char*) file, "r")))
{
- struct stat stat_buf;
- if (stat(file, &stat_buf) < 0)
- return FALSE;
- // This may need to be a bigger buffer than the file size suggests,
- // if it's a UNIX file. Give it an extra 1000 just in case.
- char *tmp_buffer = (char*)malloc((size_t)(stat_buf.st_size+1+1000));
- long no_lines = 0;
- long pos = 0;
- while (!input.eof() && input.peek() != EOF)
- {
- input.getline(wxBuffer, 500);
- int len = strlen(wxBuffer);
- wxBuffer[len] = 13;
- wxBuffer[len+1] = 10;
- wxBuffer[len+2] = 0;
- strcpy(tmp_buffer+pos, wxBuffer);
- pos += strlen(wxBuffer);
- no_lines++;
- }
-
- // TODO add line
-
- free(tmp_buffer);
-
- return TRUE;
+ 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;
}
- return FALSE;
}
// If file is null, try saved file name first
return FALSE;
m_fileName = theFile;
- ofstream output((char*) (const char*) theFile);
- if (output.bad())
- return FALSE;
+ Widget textWidget = (Widget) m_mainWidget;
+ FILE *fp;
- // TODO get and save text
+ if (!(fp = fopen ((char*) (const char*) theFile, "w")))
+ {
+ return FALSE;
+ }
+ else
+ {
+ char *text = XmTextGetString (textWidget);
+ long len = XmTextGetLastPosition (textWidget);
- return FALSE;
+ 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)
}
}
+void wxTextCtrl::ChangeFont(bool keepOriginalSize)
+{
+ wxWindow::ChangeFont(keepOriginalSize);
+}
+
+void wxTextCtrl::ChangeBackgroundColour()
+{
+ wxWindow::ChangeBackgroundColour();
+
+ Widget parent = XtParent ((Widget) m_mainWidget);
+ Widget hsb, vsb;
+
+ XtVaGetValues (parent,
+ XmNhorizontalScrollBar, &hsb,
+ XmNverticalScrollBar, &vsb,
+ NULL);
+
+ /* TODO: should scrollbars be affected? Should probably have separate
+ * function to change them (by default, taken from wxSystemSettings)
+ if (hsb)
+ DoChangeBackgroundColour((WXWidget) hsb, m_backgroundColour, TRUE);
+ if (vsb)
+ DoChangeBackgroundColour((WXWidget) vsb, m_backgroundColour, TRUE);
+ */
+
+ DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
+}
+
+void wxTextCtrl::ChangeForegroundColour()
+{
+ wxWindow::ChangeForegroundColour();
+
+
+ Widget parent = XtParent ((Widget) m_mainWidget);
+ Widget hsb, vsb;
+
+ XtVaGetValues (parent,
+ XmNhorizontalScrollBar, &hsb,
+ XmNverticalScrollBar, &vsb,
+ NULL);
+
+ /* TODO: should scrollbars be affected? Should probably have separate
+ * function to change them (by default, taken from wxSystemSettings)
+ if (hsb)
+ DoChangeForegroundColour((WXWidget) hsb, m_foregroundColour);
+ if (vsb)
+ DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
+ */
+ DoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
+}
+
static void wxTextWindowChangedProc (Widget w, XtPointer clientData, XtPointer ptr)
{
if (!wxGetWindowFromTable(w))
tw->m_tempCallbackStruct = NULL;
- if (tw->m_inSetValue)
+ if (tw->InSetValue())
return;
if (tw->m_processedDefault)
tw->m_tempCallbackStruct = NULL;
- if (tw->m_inSetValue)
+ if (tw->InSetValue())
return;
if (tw->m_processedDefault)
}
*/
- if (tw->m_inSetValue)
+ if (tw->InSetValue())
return;
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER);