// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "textctrl.h"
#endif
#define XtParent XTPARENT
#endif
+#include "wx/defs.h"
+
#include <sys/types.h>
#include <sys/stat.h>
-#include <fstream.h>
#include <ctype.h>
#include "wx/textctrl.h"
const wxValidator& validator,
const wxString& name)
{
+ if( !CreateControl( parent, id, pos, size, style, validator, name ) )
+ return false;
+
m_tempCallbackStruct = (void*) NULL;
m_modified = FALSE;
m_processedDefault = FALSE;
- // m_backgroundColour = parent->GetBackgroundColour();
- m_backgroundColour = * wxWHITE;
- m_foregroundColour = parent->GetForegroundColour();
-
- SetName(name);
- SetValidator(validator);
- if (parent)
- parent->AddChild(this);
-
- m_windowStyle = style;
- if ( id == -1 )
- m_windowId = (int)NewControlId();
- else
- m_windowId = id;
+ m_backgroundColour = *wxWHITE;
Widget parentWidget = (Widget) parent->GetClientWidget();
XtSetArg (args[1], XmNwordWrap, wantWordWrap ? True : False);
m_mainWidget = (WXWidget) XmCreateScrolledText(parentWidget,
- (char*)name.c_str(),
+ wxConstCast(name.c_str(), char),
args, 2);
XtVaSetValues ((Widget) m_mainWidget,
{
m_mainWidget = (WXWidget)XtVaCreateManagedWidget
(
- (char*)name.c_str(),
+ wxConstCast(name.c_str(), char),
xmTextWidgetClass,
parentWidget,
NULL
NULL);
}
- if ( !!value )
+ if ( !value.empty() )
{
-#if 0
- // don't do this because it is just linking the text to a source
- // string which is unsafe. MB
- //
- XmTextSetString ((Widget) m_mainWidget, (char*)value.c_str());
-#else
// do this instead... MB
//
XtVaSetValues( (Widget) m_mainWidget,
- XmNvalue, (char *)value.c_str(),
+ XmNvalue, wxConstCast(value.c_str(), char),
NULL);
-#endif
}
// install callbacks
XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this);
// font
- m_font = parent->GetFont();
ChangeFont(FALSE);
- SetCanAddEventHandler(TRUE);
- AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y);
+ wxSize best = GetBestSize();
+ if( size.x != -1 ) best.x = size.x;
+ if( size.y != -1 ) best.y = size.y;
+
+ AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
+ pos.x, pos.y, best.x, best.y);
ChangeBackgroundColour();
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
{
m_inSetValue = TRUE;
-#if 0
- // don't do this because it is just linking the text to a source
- // string which is unsafe. MB
- //
- XmTextSetString ((Widget) m_mainWidget, (char*)value.c_str());
-#else
// do this instead... MB
//
+ // with (at least) OpenMotif 2.1 this causes a lot of flicker
+#if 0
XtVaSetValues( (Widget) m_mainWidget,
- XmNvalue, (char *)value.c_str(),
+ XmNvalue, wxConstCast(value.c_str(), char),
NULL);
#endif
+ Clear();
+ AppendText( value );
+
m_inSetValue = FALSE;
}
void wxTextCtrl::Replace(long from, long to, const wxString& value)
{
XmTextReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
- (char*) (const char*) value);
+ wxConstCast(value.c_str(), char));
}
void wxTextCtrl::Remove(long from, long to)
void wxTextCtrl::SetSelection(long from, long to)
{
+ if( to == -1 )
+ to = GetLastPosition();
+
XmTextSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) 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 ((char*) (const char*) file, &statb) == -1) || (statb.st_mode & S_IFMT) != S_IFREG ||
- !(fp = fopen ((char*) (const char*) file, "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 ((char*) (const char*) theFile, "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);
- XmTextInsert ((Widget) m_mainWidget, GetInsertionPoint(), (char*) (const char*) text);
+ XmTextInsert ((Widget) m_mainWidget, GetInsertionPoint(),
+ wxConstCast(text.c_str(), char));
XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL);
SetInsertionPoint(textPosition);
XmTextShowPosition ((Widget) m_mainWidget, textPosition);
void wxTextCtrl::AppendText(const wxString& text)
{
- long textPosition = GetLastPosition() + strlen(text);
- XmTextInsert ((Widget) m_mainWidget, GetLastPosition(), (char*) (const char*) text);
+ long textPosition = GetLastPosition() + text.length();
+ XmTextInsert ((Widget) m_mainWidget, GetLastPosition(),
+ wxConstCast(text.c_str(), char));
XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL);
SetInsertionPoint(textPosition);
XmTextShowPosition ((Widget) m_mainWidget, textPosition);
XmNhorizontalScrollBar, &hsb,
XmNverticalScrollBar, &vsb,
NULL);
- wxColour backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
+ wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
if (hsb)
- DoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE);
+ wxDoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE);
if (vsb)
- DoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE);
+ wxDoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE);
- DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
+ // MBN: why change parent background?
+ // DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
}
}
if (vsb)
DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
*/
- DoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
+ wxDoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
}
}
m_tempCallbackStruct = NULL;
}
+wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
+ const wxWindow* window )
+{
+ Dimension xmargin, ymargin, highlight, shadow;
+ char* value;
+
+ XtVaGetValues( textWidget,
+ XmNmarginWidth, &xmargin,
+ XmNmarginHeight, &ymargin,
+ XmNvalue, &value,
+ XmNhighlightThickness, &highlight,
+ XmNshadowThickness, &shadow,
+ NULL );
+
+ if( !value )
+ value = "|";
+
+ int x, y;
+ window->GetTextExtent( value, &x, &y );
+
+ if( x < 100 ) x = 100;
+
+ return wxSize( x + 2 * xmargin + 2 * highlight + 2 * shadow,
+ // MBN: +2 necessary: Lesstif bug or mine?
+ y + 2 * ymargin + 2 * highlight + 2 * shadow + 2 );
+}
+
+wxSize wxTextCtrl::DoGetBestSize() const
+{
+ if( IsSingleLine() )
+ return wxDoGetSingleTextCtrlBestSize( (Widget)m_mainWidget, this );
+ else
+ return wxWindow::DoGetBestSize();
+}
+
// ----------------------------------------------------------------------------
// helpers and Motif callbacks
// ----------------------------------------------------------------------------
const char * const passwd = value;
int len = value.length();
- len += strlen(cbs->text->ptr) + 1; // + new text (if any) + NUL
+ len += ( cbs->text->ptr ?
+ strlen(cbs->text->ptr) :
+ 0 ) + 1; // + new text (if any) + NUL
len -= cbs->endPos - cbs->startPos; // - text from affected region.
char * newS = new char [len];
*dest++ = *p++;
// Copy the text to be inserted).
- while (*insert)
- *dest++ = *insert++;
+ if (insert)
+ while (*insert)
+ *dest++ = *insert++;
// Finally, copy into newS any remaining text from passwd[endPos] on.
for (p = passwd + cbs->endPos; *p; )
}
}
+ if(tw->InSetValue())
+ return;
+
// If we're already within an OnChar, return: probably a programmatic
// insertion.
if (tw->m_tempCallbackStruct)