+void wxTextCtrl::DoSendEvents(void *wxcbs, long keycode)
+{
+ // we're in process of updating the text control
+ m_tempCallbackStruct = wxcbs;
+
+ XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)wxcbs;
+
+ wxKeyEvent event (wxEVT_CHAR);
+ event.SetId(GetId());
+ event.m_keyCode = keycode;
+ event.SetEventObject(this);
+
+ // Only if wxTextCtrl::OnChar is called will this be set to True (and
+ // the character passed through)
+ cbs->doit = False;
+
+ GetEventHandler()->ProcessEvent(event);
+
+ if ( !InSetValue() && m_processedDefault )
+ {
+ // Can generate a command
+ wxCommandEvent commandEvent(wxEVT_COMMAND_TEXT_UPDATED, GetId());
+ commandEvent.SetEventObject(this);
+ ProcessCommand(commandEvent);
+ }
+
+ // do it after the (user) event handlers processed the events because
+ // otherwise GetValue() would return incorrect (not yet updated value)
+ 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 = wxMOTIF_STR("|");
+
+ 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() )
+ {
+ wxSize best = wxControl::DoGetBestSize();
+
+ if( best.x < 110 ) best.x = 110;
+
+ return best;
+ }
+ else
+ return wxWindow::DoGetBestSize();
+}
+
+// ----------------------------------------------------------------------------
+// helpers and Motif callbacks
+// ----------------------------------------------------------------------------
+
+static void MergeChangesIntoString(wxString& value,
+ XmTextVerifyCallbackStruct *cbs)
+{
+ /* _sm_
+ * At least on my system (SunOS 4.1.3 + Motif 1.2), you need to think of
+ * every event as a replace event. cbs->text->ptr gives the replacement
+ * text, cbs->startPos gives the index of the first char affected by the
+ * replace, and cbs->endPos gives the index one more than the last char
+ * affected by the replace (startPos == endPos implies an empty range).
+ * Hence, a deletion is represented by replacing all input text with a
+ * blank string ("", *not* NULL!). A simple insertion that does not
+ * overwrite any text has startPos == endPos.
+ */
+
+ if ( !value )
+ {
+ // easy case: the ol value was empty
+ value = cbs->text->ptr;
+ }
+ else
+ {
+ // merge the changes into the value
+ const char * const passwd = value;
+ int len = value.length();
+
+ 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];
+ char * dest = newS,
+ * insert = cbs->text->ptr;
+
+ // Copy (old) text from passwd, up to the start posn of the change.
+ int i;
+ const char * p = passwd;
+ for (i = 0; i < cbs->startPos; ++i)
+ *dest++ = *p++;
+
+ // Copy the text to be inserted).
+ if (insert)
+ while (*insert)
+ *dest++ = *insert++;
+
+ // Finally, copy into newS any remaining text from passwd[endPos] on.
+ for (p = passwd + cbs->endPos; *p; )
+ *dest++ = *p++;
+ *dest = 0;
+
+ value = newS;
+
+ delete[] newS;
+ }
+}
+
+static void
+wxTextWindowChangedProc (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr))