X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0d57be459406c2830f6abc9d99ae99166c6d133b..3c67202dee33f95fa48b176dec8994340c70eaa2:/src/motif/textctrl.cpp diff --git a/src/motif/textctrl.cpp b/src/motif/textctrl.cpp index 3016f39932..b9f564264c 100644 --- a/src/motif/textctrl.cpp +++ b/src/motif/textctrl.cpp @@ -80,7 +80,8 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, m_modified = FALSE; m_processedDefault = FALSE; m_fileName = ""; - m_backgroundColour = parent->GetBackgroundColour(); + // m_backgroundColour = parent->GetBackgroundColour(); + m_backgroundColour = * wxWHITE; m_foregroundColour = parent->GetForegroundColour(); SetName(name); @@ -143,10 +144,12 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, 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()); ChangeBackgroundColour(); return TRUE; @@ -179,7 +182,9 @@ wxString wxTextCtrl::GetValue() const 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); @@ -257,37 +262,36 @@ bool wxTextCtrl::LoadFile(const wxString& file) 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 @@ -301,13 +305,31 @@ bool wxTextCtrl::SaveFile(const wxString& file) 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) @@ -467,7 +489,7 @@ int wxTextCtrl::overflow(int c) // Verify that there are no characters in get area if ( gptr() && gptr() < egptr() ) { - wxError("Who's trespassing my get area?","Internal error"); + wxError("wxTextCtrl::overflow: Who's trespassing my get area?","Internal error"); return EOF; } @@ -619,19 +641,60 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) } } -void wxTextCtrl::ChangeFont() +void wxTextCtrl::ChangeFont(bool keepOriginalSize) { - // TODO + wxWindow::ChangeFont(keepOriginalSize); } void wxTextCtrl::ChangeBackgroundColour() { - // TODO + wxWindow::ChangeBackgroundColour(); + + /* TODO: should scrollbars be affected? Should probably have separate + * function to change them (by default, taken from wxSystemSettings) + */ + if (m_windowStyle & wxTE_MULTILINE) + { + Widget parent = XtParent ((Widget) m_mainWidget); + Widget hsb, vsb; + + XtVaGetValues (parent, + XmNhorizontalScrollBar, &hsb, + XmNverticalScrollBar, &vsb, + NULL); + wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE); + if (hsb) + DoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE); + if (vsb) + DoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE); + + DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE); + } } void wxTextCtrl::ChangeForegroundColour() { - // TODO + wxWindow::ChangeForegroundColour(); + + if (m_windowStyle & wxTE_MULTILINE) + { + 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)