1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "textctrl.h"
24 #include <sys/types.h>
29 #include "wx/textctrl.h"
30 #include "wx/settings.h"
31 #include "wx/filefn.h"
36 #include "wx/motif/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // helper: inserts the new text in the value of the text ctrl and returns the
44 static void MergeChangesIntoString(wxString
& value
,
45 XmTextVerifyCallbackStruct
*textStruct
);
48 static void wxTextWindowChangedProc(Widget w
, XtPointer clientData
, XtPointer ptr
);
49 static void wxTextWindowModifyProc(Widget w
, XtPointer clientData
, XmTextVerifyCallbackStruct
*cbs
);
50 static void wxTextWindowGainFocusProc(Widget w
, XtPointer clientData
, XmAnyCallbackStruct
*cbs
);
51 static void wxTextWindowLoseFocusProc(Widget w
, XtPointer clientData
, XmAnyCallbackStruct
*cbs
);
52 static void wxTextWindowActivateProc(Widget w
, XtPointer clientData
, XmAnyCallbackStruct
*ptr
);
54 #if !USE_SHARED_LIBRARY
55 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
57 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
58 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
59 EVT_CHAR(wxTextCtrl::OnChar
)
61 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
62 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
63 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
64 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
65 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
67 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
68 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
69 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
70 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
71 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
85 wxTextCtrl::wxTextCtrl()
86 #ifndef NO_TEXT_WINDOW_STREAM
90 m_tempCallbackStruct
= (void*) NULL
;
92 m_processedDefault
= FALSE
;
95 bool wxTextCtrl::Create(wxWindow
*parent
,
97 const wxString
& value
,
101 const wxValidator
& validator
,
102 const wxString
& name
)
104 m_tempCallbackStruct
= (void*) NULL
;
106 m_processedDefault
= FALSE
;
107 // m_backgroundColour = parent->GetBackgroundColour();
108 m_backgroundColour
= * wxWHITE
;
109 m_foregroundColour
= parent
->GetForegroundColour();
112 SetValidator(validator
);
114 parent
->AddChild(this);
116 m_windowStyle
= style
;
119 m_windowId
= (int)NewControlId();
123 Widget parentWidget
= (Widget
) parent
->GetClientWidget();
125 bool wantHorizScrolling
= ((m_windowStyle
& wxHSCROLL
) != 0);
127 // If we don't have horizontal scrollbars, we want word wrap.
128 bool wantWordWrap
= !wantHorizScrolling
;
130 if (m_windowStyle
& wxTE_MULTILINE
)
133 XtSetArg (args
[0], XmNscrollHorizontal
, wantHorizScrolling
? True
: False
);
134 XtSetArg (args
[1], XmNwordWrap
, wantWordWrap
? True
: False
);
136 m_mainWidget
= (WXWidget
) XmCreateScrolledText(parentWidget
,
140 XtVaSetValues ((Widget
) m_mainWidget
,
141 XmNeditable
, ((style
& wxTE_READONLY
) ? False
: True
),
142 XmNeditMode
, XmMULTI_LINE_EDIT
,
144 XtManageChild ((Widget
) m_mainWidget
);
148 m_mainWidget
= (WXWidget
)XtVaCreateManagedWidget
156 // TODO: Is this relevant? What does it do?
158 if (!value
.IsNull() && (value
.Length() > (unsigned int) noCols
))
159 noCols
= value
.Length();
160 XtVaSetValues((Widget
) m_mainWidget
,
165 // remove border if asked for
166 if ( style
& wxNO_BORDER
)
168 XtVaSetValues((Widget
)m_mainWidget
,
169 XmNshadowThickness
, 0,
174 XmTextSetString ((Widget
) m_mainWidget
, (char*)value
.c_str());
177 XtAddCallback((Widget
) m_mainWidget
, XmNvalueChangedCallback
, (XtCallbackProc
)wxTextWindowChangedProc
, (XtPointer
)this);
179 XtAddCallback((Widget
) m_mainWidget
, XmNmodifyVerifyCallback
, (XtCallbackProc
)wxTextWindowModifyProc
, (XtPointer
)this);
181 XtAddCallback((Widget
) m_mainWidget
, XmNactivateCallback
, (XtCallbackProc
)wxTextWindowActivateProc
, (XtPointer
)this);
183 XtAddCallback((Widget
) m_mainWidget
, XmNfocusCallback
, (XtCallbackProc
)wxTextWindowGainFocusProc
, (XtPointer
)this);
185 XtAddCallback((Widget
) m_mainWidget
, XmNlosingFocusCallback
, (XtCallbackProc
)wxTextWindowLoseFocusProc
, (XtPointer
)this);
188 m_windowFont
= parent
->GetFont();
191 SetCanAddEventHandler(TRUE
);
192 AttachWidget (parent
, m_mainWidget
, (WXWidget
) NULL
, pos
.x
, pos
.y
, size
.x
, size
.y
);
194 ChangeBackgroundColour();
199 WXWidget
wxTextCtrl::GetTopWidget() const
201 return ((m_windowStyle
& wxTE_MULTILINE
) ? (WXWidget
) XtParent((Widget
) m_mainWidget
) : m_mainWidget
);
204 wxString
wxTextCtrl::GetValue() const
206 wxString str
; // result
208 if (m_windowStyle
& wxTE_PASSWORD
)
210 // the value is stored always in m_value because it can't be retrieved
211 // from the text control
216 // just get the string from Motif
217 char *s
= XmTextGetString ((Widget
) m_mainWidget
);
223 //else: return empty string
225 if ( m_tempCallbackStruct
)
227 // the string in the control isn't yet updated, can't use it as is
228 MergeChangesIntoString(str
, (XmTextVerifyCallbackStruct
*)
229 m_tempCallbackStruct
);
236 void wxTextCtrl::SetValue(const wxString
& value
)
240 XmTextSetString ((Widget
) m_mainWidget
, (char*)value
.c_str());
242 m_inSetValue
= FALSE
;
245 // Clipboard operations
246 void wxTextCtrl::Copy()
248 XmTextCopy((Widget
) m_mainWidget
, CurrentTime
);
251 void wxTextCtrl::Cut()
253 XmTextCut((Widget
) m_mainWidget
, CurrentTime
);
256 void wxTextCtrl::Paste()
258 XmTextPaste((Widget
) m_mainWidget
);
261 bool wxTextCtrl::CanCopy() const
263 // Can copy if there's a selection
265 GetSelection(& from
, & to
);
266 return (from
!= to
) ;
269 bool wxTextCtrl::CanCut() const
271 // Can cut if there's a selection
273 GetSelection(& from
, & to
);
274 return (from
!= to
) ;
277 bool wxTextCtrl::CanPaste() const
279 return IsEditable() ;
283 void wxTextCtrl::Undo()
285 // Not possible in Motif
288 void wxTextCtrl::Redo()
290 // Not possible in Motif
293 bool wxTextCtrl::CanUndo() const
299 bool wxTextCtrl::CanRedo() const
305 // If the return values from and to are the same, there is no
307 void wxTextCtrl::GetSelection(long* from
, long* to
) const
309 XmTextPosition left
, right
;
311 XmTextGetSelectionPosition((Widget
) m_mainWidget
, & left
, & right
);
317 bool wxTextCtrl::IsEditable() const
319 return (XmTextGetEditable((Widget
) m_mainWidget
) != 0);
322 void wxTextCtrl::SetEditable(bool editable
)
324 XmTextSetEditable((Widget
) m_mainWidget
, (Boolean
) editable
);
327 void wxTextCtrl::SetInsertionPoint(long pos
)
329 XmTextSetInsertionPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
332 void wxTextCtrl::SetInsertionPointEnd()
334 long pos
= GetLastPosition();
335 SetInsertionPoint(pos
);
338 long wxTextCtrl::GetInsertionPoint() const
340 return (long) XmTextGetInsertionPosition ((Widget
) m_mainWidget
);
343 long wxTextCtrl::GetLastPosition() const
345 return (long) XmTextGetLastPosition ((Widget
) m_mainWidget
);
348 void wxTextCtrl::Replace(long from
, long to
, const wxString
& value
)
350 XmTextReplace ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
351 (char*) (const char*) value
);
354 void wxTextCtrl::Remove(long from
, long to
)
356 XmTextSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
358 XmTextRemove ((Widget
) m_mainWidget
);
361 void wxTextCtrl::SetSelection(long from
, long to
)
363 XmTextSetSelection ((Widget
) m_mainWidget
, (XmTextPosition
) from
, (XmTextPosition
) to
,
367 bool wxTextCtrl::LoadFile(const wxString
& file
)
369 if (!wxFileExists(file
))
376 Widget textWidget
= (Widget
) m_mainWidget
;
380 if ((stat ((char*) (const char*) file
, &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
381 !(fp
= fopen ((char*) (const char*) file
, "r")))
387 long len
= statb
.st_size
;
389 if (!(text
= XtMalloc ((unsigned) (len
+ 1))))
394 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
400 XmTextSetString (textWidget
, text
);
401 // m_textPosition = len;
408 // If file is null, try saved file name first
409 // Returns TRUE if succeeds.
410 bool wxTextCtrl::SaveFile(const wxString
& file
)
412 wxString
theFile(file
);
414 theFile
= m_fileName
;
417 m_fileName
= theFile
;
419 Widget textWidget
= (Widget
) m_mainWidget
;
422 if (!(fp
= fopen ((char*) (const char*) theFile
, "w")))
428 char *text
= XmTextGetString (textWidget
);
429 long len
= XmTextGetLastPosition (textWidget
);
431 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
433 // Did not write whole file
435 // Make sure newline terminates the file
436 if (text
[len
- 1] != '\n')
446 void wxTextCtrl::WriteText(const wxString
& text
)
448 long textPosition
= GetInsertionPoint() + strlen (text
);
449 XmTextInsert ((Widget
) m_mainWidget
, GetInsertionPoint(), (char*) (const char*) text
);
450 XtVaSetValues ((Widget
) m_mainWidget
, XmNcursorPosition
, textPosition
, NULL
);
451 SetInsertionPoint(textPosition
);
452 XmTextShowPosition ((Widget
) m_mainWidget
, textPosition
);
456 void wxTextCtrl::AppendText(const wxString
& text
)
458 long textPosition
= GetLastPosition() + strlen(text
);
459 XmTextInsert ((Widget
) m_mainWidget
, GetLastPosition(), (char*) (const char*) text
);
460 XtVaSetValues ((Widget
) m_mainWidget
, XmNcursorPosition
, textPosition
, NULL
);
461 SetInsertionPoint(textPosition
);
462 XmTextShowPosition ((Widget
) m_mainWidget
, textPosition
);
466 void wxTextCtrl::Clear()
468 XmTextSetString ((Widget
) m_mainWidget
, "");
472 bool wxTextCtrl::IsModified() const
477 // Makes 'unmodified'
478 void wxTextCtrl::DiscardEdits()
480 XmTextSetString ((Widget
) m_mainWidget
, "");
484 int wxTextCtrl::GetNumberOfLines() const
486 // HIDEOUSLY inefficient, but we have no choice.
487 char *s
= XmTextGetString ((Widget
) m_mainWidget
);
492 bool finished
= FALSE
;
515 long wxTextCtrl::XYToPosition(long x
, long y
) const
517 /* It seems, that there is a bug in some versions of the Motif library,
518 so the original wxWin-Code doesn't work. */
520 Widget textWidget = (Widget) handle;
521 return (long) XmTextXYToPos (textWidget, (Position) x, (Position) y);
523 /* Now a little workaround: */
525 for (int i
=0; i
<y
; i
++) r
+=(GetLineLength(i
)+1);
529 void wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
532 XmTextPosToXY((Widget
) m_mainWidget
, pos
, &xx
, &yy
);
536 void wxTextCtrl::ShowPosition(long pos
)
538 XmTextShowPosition ((Widget
) m_mainWidget
, (XmTextPosition
) pos
);
541 int wxTextCtrl::GetLineLength(long lineNo
) const
543 wxString str
= GetLineText (lineNo
);
544 return (int) str
.Length();
547 wxString
wxTextCtrl::GetLineText(long lineNo
) const
549 // HIDEOUSLY inefficient, but we have no choice.
550 char *s
= XmTextGetString ((Widget
) m_mainWidget
);
557 for (i
= 0; currentLine
!= lineNo
&& s
[i
]; i
++ )
562 for (j
= 0; s
[i
] && s
[i
] != '\n'; i
++, j
++ )
569 return wxEmptyString
;
576 void wxTextCtrl::Command(wxCommandEvent
& event
)
578 SetValue (event
.GetString());
579 ProcessCommand (event
);
582 void wxTextCtrl::OnDropFiles(wxDropFilesEvent
& event
)
584 // By default, load the first file into the text window.
585 if (event
.GetNumberOfFiles() > 0)
587 LoadFile(event
.GetFiles()[0]);
591 // The streambuf code was partly taken from chapter 3 by Jerry Schwarz of
592 // AT&T's "C++ Lanuage System Release 3.0 Library Manual" - Stein Somers
594 //=========================================================================
595 // Called then the buffer is full (gcc 2.6.3)
596 // or when "endl" is output (Borland 4.5)
597 //=========================================================================
598 // Class declaration using multiple inheritance doesn't work properly for
599 // Borland. See note in wb_text.h.
600 #ifndef NO_TEXT_WINDOW_STREAM
601 int wxTextCtrl::overflow(int c
)
603 // Make sure there is a holding area
604 if ( allocate()==EOF
)
606 wxError("Streambuf allocation failed","Internal error");
610 // Verify that there are no characters in get area
611 if ( gptr() && gptr() < egptr() )
613 wxError("wxTextCtrl::overflow: Who's trespassing my get area?","Internal error");
620 // Make sure there is a put area
623 /* This doesn't seem to be fatal so comment out error message */
624 // wxError("Put area not opened","Internal error");
625 setp( base(), base() );
628 // Determine how many characters have been inserted but no consumed
629 int plen
= pptr() - pbase();
631 // Now Jerry relies on the fact that the buffer is at least 2 chars
632 // long, but the holding area "may be as small as 1" ???
633 // And we need an additional \0, so let's keep this inefficient but
636 // If c!=EOF, it is a character that must also be comsumed
637 int xtra
= c
==EOF
? 0 : 1;
639 // Write temporary C-string to wxTextWindow
641 char *txt
= new char[plen
+xtra
+1];
642 memcpy(txt
, pbase(), plen
);
643 txt
[plen
] = (char)c
; // append c
644 txt
[plen
+xtra
] = '\0'; // append '\0' or overwrite c
645 // If the put area already contained \0, output will be truncated there
651 setp(pbase(), epptr());
653 #if defined(__WATCOMC__)
655 #elif defined(zapeof) // HP-UX (all cfront based?)
658 return c
!=EOF
? c
: 0; // this should make everybody happy
662 //=========================================================================
663 // called then "endl" is output (gcc) or then explicit sync is done (Borland)
664 //=========================================================================
665 int wxTextCtrl::sync()
667 // Verify that there are no characters in get area
668 if ( gptr() && gptr() < egptr() )
670 wxError("Who's trespassing my get area?","Internal error");
674 if ( pptr() && pptr() > pbase() ) return overflow(EOF
);
678 int len = pptr() - pbase();
679 char *txt = new char[len+1];
680 strncpy(txt, pbase(), len);
683 setp(pbase(), epptr());
689 //=========================================================================
690 // Should not be called by a "ostream". Used by a "istream"
691 //=========================================================================
692 int wxTextCtrl::underflow()
698 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
704 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
707 str
.Printf("%.2f", f
);
712 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
715 str
.Printf("%.2f", d
);
720 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
728 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
731 str
.Printf("%ld", i
);
736 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
746 void wxTextCtrl::OnChar(wxKeyEvent
& event
)
748 // Indicates that we should generate a normal command, because
749 // we're letting default behaviour happen (otherwise it's vetoed
750 // by virtue of overriding OnChar)
751 m_processedDefault
= TRUE
;
753 if (m_tempCallbackStruct
)
755 XmTextVerifyCallbackStruct
*textStruct
=
756 (XmTextVerifyCallbackStruct
*) m_tempCallbackStruct
;
757 textStruct
->doit
= True
;
758 if (isascii(event
.m_keyCode
) && (textStruct
->text
->length
== 1))
760 textStruct
->text
->ptr
[0] = ((event
.m_keyCode
== WXK_RETURN
) ? 10 : event
.m_keyCode
);
765 void wxTextCtrl::ChangeFont(bool keepOriginalSize
)
767 wxWindow::ChangeFont(keepOriginalSize
);
770 void wxTextCtrl::ChangeBackgroundColour()
772 wxWindow::ChangeBackgroundColour();
774 /* TODO: should scrollbars be affected? Should probably have separate
775 * function to change them (by default, taken from wxSystemSettings)
777 if (m_windowStyle
& wxTE_MULTILINE
)
779 Widget parent
= XtParent ((Widget
) m_mainWidget
);
782 XtVaGetValues (parent
,
783 XmNhorizontalScrollBar
, &hsb
,
784 XmNverticalScrollBar
, &vsb
,
786 wxColour backgroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
788 DoChangeBackgroundColour((WXWidget
) hsb
, backgroundColour
, TRUE
);
790 DoChangeBackgroundColour((WXWidget
) vsb
, backgroundColour
, TRUE
);
792 DoChangeBackgroundColour((WXWidget
) parent
, m_backgroundColour
, TRUE
);
796 void wxTextCtrl::ChangeForegroundColour()
798 wxWindow::ChangeForegroundColour();
800 if (m_windowStyle
& wxTE_MULTILINE
)
802 Widget parent
= XtParent ((Widget
) m_mainWidget
);
805 XtVaGetValues (parent
,
806 XmNhorizontalScrollBar
, &hsb
,
807 XmNverticalScrollBar
, &vsb
,
810 /* TODO: should scrollbars be affected? Should probably have separate
811 * function to change them (by default, taken from wxSystemSettings)
813 DoChangeForegroundColour((WXWidget) hsb, m_foregroundColour);
815 DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
817 DoChangeForegroundColour((WXWidget
) parent
, m_foregroundColour
);
821 void wxTextCtrl::DoSendEvents(void *wxcbs
, long keycode
)
823 // we're in process of updating the text control
824 m_tempCallbackStruct
= wxcbs
;
826 XmTextVerifyCallbackStruct
*cbs
= (XmTextVerifyCallbackStruct
*)wxcbs
;
828 wxKeyEvent
event (wxEVT_CHAR
);
829 event
.SetId(GetId());
830 event
.m_keyCode
= keycode
;
831 event
.SetEventObject(this);
833 // Only if wxTextCtrl::OnChar is called will this be set to True (and
834 // the character passed through)
837 GetEventHandler()->ProcessEvent(event
);
839 if ( !InSetValue() && m_processedDefault
)
841 // Can generate a command
842 wxCommandEvent
commandEvent(wxEVT_COMMAND_TEXT_UPDATED
, GetId());
843 commandEvent
.SetEventObject(this);
844 ProcessCommand(commandEvent
);
847 // do it after the (user) event handlers processed the events because
848 // otherwise GetValue() would return incorrect (not yet updated value)
849 m_tempCallbackStruct
= NULL
;
852 // ----------------------------------------------------------------------------
853 // helpers and Motif callbacks
854 // ----------------------------------------------------------------------------
856 static void MergeChangesIntoString(wxString
& value
,
857 XmTextVerifyCallbackStruct
*cbs
)
860 * At least on my system (SunOS 4.1.3 + Motif 1.2), you need to think of
861 * every event as a replace event. cbs->text->ptr gives the replacement
862 * text, cbs->startPos gives the index of the first char affected by the
863 * replace, and cbs->endPos gives the index one more than the last char
864 * affected by the replace (startPos == endPos implies an empty range).
865 * Hence, a deletion is represented by replacing all input text with a
866 * blank string ("", *not* NULL!). A simple insertion that does not
867 * overwrite any text has startPos == endPos.
872 // easy case: the ol value was empty
873 value
= cbs
->text
->ptr
;
877 // merge the changes into the value
878 const char * const passwd
= value
;
879 int len
= value
.length();
881 len
+= strlen(cbs
->text
->ptr
) + 1; // + new text (if any) + NUL
882 len
-= cbs
->endPos
- cbs
->startPos
; // - text from affected region.
884 char * newS
= new char [len
];
886 * insert
= cbs
->text
->ptr
;
888 // Copy (old) text from passwd, up to the start posn of the change.
890 const char * p
= passwd
;
891 for (i
= 0; i
< cbs
->startPos
; ++i
)
894 // Copy the text to be inserted).
898 // Finally, copy into newS any remaining text from passwd[endPos] on.
899 for (p
= passwd
+ cbs
->endPos
; *p
; )
910 wxTextWindowChangedProc (Widget w
, XtPointer clientData
, XtPointer ptr
)
912 if (!wxGetWindowFromTable(w
))
913 // Widget has been deleted!
916 wxTextCtrl
*tw
= (wxTextCtrl
*) clientData
;
917 tw
->SetModified(TRUE
);
921 wxTextWindowModifyProc (Widget w
, XtPointer clientData
, XmTextVerifyCallbackStruct
*cbs
)
923 wxTextCtrl
*tw
= (wxTextCtrl
*) clientData
;
924 tw
->m_processedDefault
= FALSE
;
926 // First, do some stuff if it's a password control: in this case, we need
927 // to store the string inside the class because GetValue() can't retrieve
928 // it from the text ctrl. We do *not* do it in other circumstances because
929 // it would double the amount of memory needed.
931 if ( tw
->GetWindowStyleFlag() & wxTE_PASSWORD
)
933 MergeChangesIntoString(tw
->m_value
, cbs
);
935 if ( cbs
->text
->length
> 0 )
938 for (i
= 0; i
< cbs
->text
->length
; ++i
)
939 cbs
->text
->ptr
[i
] = '*';
940 cbs
->text
->ptr
[i
] = '\0';
944 // If we're already within an OnChar, return: probably a programmatic
946 if (tw
->m_tempCallbackStruct
)
949 // Check for a backspace
950 if (cbs
->startPos
== (cbs
->currInsert
- 1))
952 tw
->DoSendEvents((void *)cbs
, WXK_DELETE
);
957 // Pasting operation: let it through without calling OnChar
958 if (cbs
->text
->length
> 1)
961 // Something other than text
962 if (cbs
->text
->ptr
== NULL
)
966 char ch
= cbs
->text
->ptr
[0];
967 tw
->DoSendEvents((void *)cbs
, ch
== '\n' ? '\r' : ch
);
971 wxTextWindowGainFocusProc (Widget w
, XtPointer clientData
, XmAnyCallbackStruct
*cbs
)
973 if (!wxGetWindowFromTable(w
))
976 wxTextCtrl
*tw
= (wxTextCtrl
*) clientData
;
977 wxFocusEvent
event(wxEVT_SET_FOCUS
, tw
->GetId());
978 event
.SetEventObject(tw
);
979 tw
->GetEventHandler()->ProcessEvent(event
);
983 wxTextWindowLoseFocusProc (Widget w
, XtPointer clientData
, XmAnyCallbackStruct
*cbs
)
985 if (!wxGetWindowFromTable(w
))
988 wxTextCtrl
*tw
= (wxTextCtrl
*) clientData
;
989 wxFocusEvent
event(wxEVT_KILL_FOCUS
, tw
->GetId());
990 event
.SetEventObject(tw
);
991 tw
->GetEventHandler()->ProcessEvent(event
);
994 static void wxTextWindowActivateProc(Widget w
, XtPointer clientData
,
995 XmAnyCallbackStruct
*ptr
)
997 if (!wxGetWindowFromTable(w
))
1000 wxTextCtrl
*tw
= (wxTextCtrl
*) clientData
;
1002 if (tw
->InSetValue())
1005 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
);
1006 event
.SetId(tw
->GetId());
1007 event
.SetEventObject(tw
);
1008 tw
->ProcessCommand(event
);
1011 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1016 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1021 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1026 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1031 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1036 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1038 event
.Enable( CanCut() );
1041 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1043 event
.Enable( CanCopy() );
1046 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1048 event
.Enable( CanPaste() );
1051 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1053 event
.Enable( CanUndo() );
1056 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1058 event
.Enable( CanRedo() );