]> git.saurik.com Git - wxWidgets.git/blob - src/motif/textctrl.cpp
Regenerated some more makefiles/filelists.
[wxWidgets.git] / src / motif / textctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.cpp
3 // Purpose: wxTextCtrl
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "textctrl.h"
22 #endif
23
24 #ifdef __VMS
25 #define XtParent XTPARENT
26 #endif
27
28 #include "wx/defs.h"
29
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #include <ctype.h>
33
34 #include "wx/textctrl.h"
35 #include "wx/settings.h"
36 #include "wx/filefn.h"
37 #include "wx/utils.h"
38
39 #ifdef __VMS__
40 #pragma message disable nosimpint
41 #endif
42 #include <Xm/Text.h>
43 #ifdef __VMS__
44 #pragma message enable nosimpint
45 #endif
46
47 #include "wx/motif/private.h"
48
49 // ----------------------------------------------------------------------------
50 // private functions
51 // ----------------------------------------------------------------------------
52
53 // helper: inserts the new text in the value of the text ctrl and returns the
54 // result in place
55 static void MergeChangesIntoString(wxString& value,
56 XmTextVerifyCallbackStruct *textStruct);
57
58 // callbacks
59 static void wxTextWindowChangedProc(Widget w, XtPointer clientData, XtPointer ptr);
60 static void wxTextWindowModifyProc(Widget w, XtPointer clientData, XmTextVerifyCallbackStruct *cbs);
61 static void wxTextWindowGainFocusProc(Widget w, XtPointer clientData, XmAnyCallbackStruct *cbs);
62 static void wxTextWindowLoseFocusProc(Widget w, XtPointer clientData, XmAnyCallbackStruct *cbs);
63 static void wxTextWindowActivateProc(Widget w, XtPointer clientData, XmAnyCallbackStruct *ptr);
64
65 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
66
67 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
68 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
69 EVT_CHAR(wxTextCtrl::OnChar)
70
71 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
72 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
73 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
74 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
75 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
76
77 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
78 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
79 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
80 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
81 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
82
83 END_EVENT_TABLE()
84
85 // ============================================================================
86 // implementation
87 // ============================================================================
88
89 // ----------------------------------------------------------------------------
90 // wxTextCtrl
91 // ----------------------------------------------------------------------------
92
93 // Text item
94 wxTextCtrl::wxTextCtrl()
95 {
96 m_tempCallbackStruct = (void*) NULL;
97 m_modified = FALSE;
98 m_processedDefault = FALSE;
99 }
100
101 bool wxTextCtrl::Create(wxWindow *parent,
102 wxWindowID id,
103 const wxString& value,
104 const wxPoint& pos,
105 const wxSize& size,
106 long style,
107 const wxValidator& validator,
108 const wxString& name)
109 {
110 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
111 return false;
112
113 m_tempCallbackStruct = (void*) NULL;
114 m_modified = FALSE;
115 m_processedDefault = FALSE;
116
117 m_backgroundColour = *wxWHITE;
118
119 Widget parentWidget = (Widget) parent->GetClientWidget();
120
121 bool wantHorizScrolling = ((m_windowStyle & wxHSCROLL) != 0);
122
123 // If we don't have horizontal scrollbars, we want word wrap.
124 bool wantWordWrap = !wantHorizScrolling;
125
126 if (m_windowStyle & wxTE_MULTILINE)
127 {
128 Arg args[2];
129 XtSetArg (args[0], XmNscrollHorizontal, wantHorizScrolling ? True : False);
130 XtSetArg (args[1], XmNwordWrap, wantWordWrap ? True : False);
131
132 m_mainWidget = (WXWidget) XmCreateScrolledText(parentWidget,
133 wxConstCast(name.c_str(), char),
134 args, 2);
135
136 XtVaSetValues ((Widget) m_mainWidget,
137 XmNeditable, ((style & wxTE_READONLY) ? False : True),
138 XmNeditMode, XmMULTI_LINE_EDIT,
139 NULL);
140 XtManageChild ((Widget) m_mainWidget);
141 }
142 else
143 {
144 m_mainWidget = (WXWidget)XtVaCreateManagedWidget
145 (
146 wxConstCast(name.c_str(), char),
147 xmTextWidgetClass,
148 parentWidget,
149 NULL
150 );
151
152 XtVaSetValues ((Widget) m_mainWidget,
153 XmNeditable, ((style & wxTE_READONLY) ? False : True),
154 NULL);
155
156 // TODO: Is this relevant? What does it do?
157 int noCols = 2;
158 if (!value.IsNull() && (value.Length() > (unsigned int) noCols))
159 noCols = value.Length();
160 XtVaSetValues((Widget) m_mainWidget,
161 XmNcolumns, noCols,
162 NULL);
163 }
164
165 // remove border if asked for
166 if ( style & wxNO_BORDER )
167 {
168 XtVaSetValues((Widget)m_mainWidget,
169 XmNshadowThickness, 0,
170 NULL);
171 }
172
173 if ( !value.empty() )
174 {
175 // do this instead... MB
176 //
177 XtVaSetValues( (Widget) m_mainWidget,
178 XmNvalue, wxConstCast(value.c_str(), char),
179 NULL);
180 }
181
182 // install callbacks
183 XtAddCallback((Widget) m_mainWidget, XmNvalueChangedCallback, (XtCallbackProc)wxTextWindowChangedProc, (XtPointer)this);
184
185 XtAddCallback((Widget) m_mainWidget, XmNmodifyVerifyCallback, (XtCallbackProc)wxTextWindowModifyProc, (XtPointer)this);
186
187 XtAddCallback((Widget) m_mainWidget, XmNactivateCallback, (XtCallbackProc)wxTextWindowActivateProc, (XtPointer)this);
188
189 XtAddCallback((Widget) m_mainWidget, XmNfocusCallback, (XtCallbackProc)wxTextWindowGainFocusProc, (XtPointer)this);
190
191 XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this);
192
193 // font
194 ChangeFont(FALSE);
195
196 wxSize best = GetBestSize();
197 if( size.x != -1 ) best.x = size.x;
198 if( size.y != -1 ) best.y = size.y;
199
200 SetCanAddEventHandler(TRUE);
201 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
202 pos.x, pos.y, best.x, best.y);
203
204 ChangeBackgroundColour();
205
206 return TRUE;
207 }
208
209 WXWidget wxTextCtrl::GetTopWidget() const
210 {
211 return IsMultiLine() ? (WXWidget)XtParent((Widget)m_mainWidget)
212 : m_mainWidget;
213 }
214
215 wxString wxTextCtrl::GetValue() const
216 {
217 wxString str; // result
218
219 if (m_windowStyle & wxTE_PASSWORD)
220 {
221 // the value is stored always in m_value because it can't be retrieved
222 // from the text control
223 str = m_value;
224 }
225 else
226 {
227 // just get the string from Motif
228 char *s = XmTextGetString ((Widget) m_mainWidget);
229 if ( s )
230 {
231 str = s;
232 XtFree (s);
233 }
234 //else: return empty string
235
236 if ( m_tempCallbackStruct )
237 {
238 // the string in the control isn't yet updated, can't use it as is
239 MergeChangesIntoString(str, (XmTextVerifyCallbackStruct *)
240 m_tempCallbackStruct);
241 }
242 }
243
244 return str;
245 }
246
247 void wxTextCtrl::SetValue(const wxString& value)
248 {
249 m_inSetValue = TRUE;
250
251 // do this instead... MB
252 //
253 // with (at least) OpenMotif 2.1 this causes a lot of flicker
254 #if 0
255 XtVaSetValues( (Widget) m_mainWidget,
256 XmNvalue, wxConstCast(value.c_str(), char),
257 NULL);
258 #endif
259
260 Clear();
261 AppendText( value );
262
263 m_inSetValue = FALSE;
264 }
265
266 // Clipboard operations
267 void wxTextCtrl::Copy()
268 {
269 XmTextCopy((Widget) m_mainWidget, CurrentTime);
270 }
271
272 void wxTextCtrl::Cut()
273 {
274 XmTextCut((Widget) m_mainWidget, CurrentTime);
275 }
276
277 void wxTextCtrl::Paste()
278 {
279 XmTextPaste((Widget) m_mainWidget);
280 }
281
282 bool wxTextCtrl::CanCopy() const
283 {
284 // Can copy if there's a selection
285 long from, to;
286 GetSelection(& from, & to);
287 return (from != to) ;
288 }
289
290 bool wxTextCtrl::CanCut() const
291 {
292 // Can cut if there's a selection
293 long from, to;
294 GetSelection(& from, & to);
295 return (from != to) && (IsEditable());
296 }
297
298 bool wxTextCtrl::CanPaste() const
299 {
300 return IsEditable() ;
301 }
302
303 // Undo/redo
304 void wxTextCtrl::Undo()
305 {
306 // Not possible in Motif
307 }
308
309 void wxTextCtrl::Redo()
310 {
311 // Not possible in Motif
312 }
313
314 bool wxTextCtrl::CanUndo() const
315 {
316 // No Undo in Motif
317 return FALSE;
318 }
319
320 bool wxTextCtrl::CanRedo() const
321 {
322 // No Redo in Motif
323 return FALSE;
324 }
325
326 // If the return values from and to are the same, there is no
327 // selection.
328 void wxTextCtrl::GetSelection(long* from, long* to) const
329 {
330 XmTextPosition left, right;
331
332 XmTextGetSelectionPosition((Widget) m_mainWidget, & left, & right);
333
334 *from = (long) left;
335 *to = (long) right;
336 }
337
338 bool wxTextCtrl::IsEditable() const
339 {
340 return (XmTextGetEditable((Widget) m_mainWidget) != 0);
341 }
342
343 void wxTextCtrl::SetEditable(bool editable)
344 {
345 XmTextSetEditable((Widget) m_mainWidget, (Boolean) editable);
346 }
347
348 void wxTextCtrl::SetInsertionPoint(long pos)
349 {
350 XmTextSetInsertionPosition ((Widget) m_mainWidget, (XmTextPosition) pos);
351 }
352
353 void wxTextCtrl::SetInsertionPointEnd()
354 {
355 long pos = GetLastPosition();
356 SetInsertionPoint(pos);
357 }
358
359 long wxTextCtrl::GetInsertionPoint() const
360 {
361 return (long) XmTextGetInsertionPosition ((Widget) m_mainWidget);
362 }
363
364 long wxTextCtrl::GetLastPosition() const
365 {
366 return (long) XmTextGetLastPosition ((Widget) m_mainWidget);
367 }
368
369 void wxTextCtrl::Replace(long from, long to, const wxString& value)
370 {
371 XmTextReplace ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
372 wxConstCast(value.c_str(), char));
373 }
374
375 void wxTextCtrl::Remove(long from, long to)
376 {
377 XmTextSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
378 (Time) 0);
379 XmTextRemove ((Widget) m_mainWidget);
380 }
381
382 void wxTextCtrl::SetSelection(long from, long to)
383 {
384 if( to == -1 )
385 to = GetLastPosition();
386
387 XmTextSetSelection ((Widget) m_mainWidget, (XmTextPosition) from, (XmTextPosition) to,
388 (Time) 0);
389 }
390
391 void wxTextCtrl::WriteText(const wxString& text)
392 {
393 long textPosition = GetInsertionPoint() + strlen (text);
394 XmTextInsert ((Widget) m_mainWidget, GetInsertionPoint(),
395 wxConstCast(text.c_str(), char));
396 XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL);
397 SetInsertionPoint(textPosition);
398 XmTextShowPosition ((Widget) m_mainWidget, textPosition);
399 m_modified = TRUE;
400 }
401
402 void wxTextCtrl::AppendText(const wxString& text)
403 {
404 long textPosition = GetLastPosition() + strlen(text);
405 XmTextInsert ((Widget) m_mainWidget, GetLastPosition(),
406 wxConstCast(text.c_str(), char));
407 XtVaSetValues ((Widget) m_mainWidget, XmNcursorPosition, textPosition, NULL);
408 SetInsertionPoint(textPosition);
409 XmTextShowPosition ((Widget) m_mainWidget, textPosition);
410 m_modified = TRUE;
411 }
412
413 void wxTextCtrl::Clear()
414 {
415 XmTextSetString ((Widget) m_mainWidget, "");
416 m_modified = FALSE;
417 }
418
419 bool wxTextCtrl::IsModified() const
420 {
421 return m_modified;
422 }
423
424 // Makes 'unmodified'
425 void wxTextCtrl::DiscardEdits()
426 {
427 m_modified = FALSE;
428 }
429
430 int wxTextCtrl::GetNumberOfLines() const
431 {
432 // HIDEOUSLY inefficient, but we have no choice.
433 char *s = XmTextGetString ((Widget) m_mainWidget);
434 if (s)
435 {
436 long i = 0;
437 int currentLine = 0;
438 bool finished = FALSE;
439 while (!finished)
440 {
441 int ch = s[i];
442 if (ch == '\n')
443 {
444 currentLine++;
445 i++;
446 }
447 else if (ch == 0)
448 {
449 finished = TRUE;
450 }
451 else
452 i++;
453 }
454
455 XtFree (s);
456 return currentLine;
457 }
458 return 0;
459 }
460
461 long wxTextCtrl::XYToPosition(long x, long y) const
462 {
463 /* It seems, that there is a bug in some versions of the Motif library,
464 so the original wxWin-Code doesn't work. */
465 /*
466 Widget textWidget = (Widget) handle;
467 return (long) XmTextXYToPos (textWidget, (Position) x, (Position) y);
468 */
469 /* Now a little workaround: */
470 long r=0;
471 for (int i=0; i<y; i++) r+=(GetLineLength(i)+1);
472 return r+x;
473 }
474
475 bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
476 {
477 Position xx, yy;
478 XmTextPosToXY((Widget) m_mainWidget, pos, &xx, &yy);
479 if ( x )
480 *x = xx;
481 if ( y )
482 *y = yy;
483
484 return TRUE;
485 }
486
487 void wxTextCtrl::ShowPosition(long pos)
488 {
489 XmTextShowPosition ((Widget) m_mainWidget, (XmTextPosition) pos);
490 }
491
492 int wxTextCtrl::GetLineLength(long lineNo) const
493 {
494 wxString str = GetLineText (lineNo);
495 return (int) str.Length();
496 }
497
498 wxString wxTextCtrl::GetLineText(long lineNo) const
499 {
500 // HIDEOUSLY inefficient, but we have no choice.
501 char *s = XmTextGetString ((Widget) m_mainWidget);
502
503 if (s)
504 {
505 wxString buf("");
506 long i;
507 int currentLine = 0;
508 for (i = 0; currentLine != lineNo && s[i]; i++ )
509 if (s[i] == '\n')
510 currentLine++;
511 // Now get the text
512 int j;
513 for (j = 0; s[i] && s[i] != '\n'; i++, j++ )
514 buf += s[i];
515
516 XtFree(s);
517 return buf;
518 }
519 else
520 return wxEmptyString;
521 }
522
523 /*
524 * Text item
525 */
526
527 void wxTextCtrl::Command(wxCommandEvent & event)
528 {
529 SetValue (event.GetString());
530 ProcessCommand (event);
531 }
532
533 void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
534 {
535 // By default, load the first file into the text window.
536 if (event.GetNumberOfFiles() > 0)
537 {
538 LoadFile(event.GetFiles()[0]);
539 }
540 }
541
542 void wxTextCtrl::OnChar(wxKeyEvent& event)
543 {
544 // Indicates that we should generate a normal command, because
545 // we're letting default behaviour happen (otherwise it's vetoed
546 // by virtue of overriding OnChar)
547 m_processedDefault = TRUE;
548
549 if (m_tempCallbackStruct)
550 {
551 XmTextVerifyCallbackStruct *textStruct =
552 (XmTextVerifyCallbackStruct *) m_tempCallbackStruct;
553 textStruct->doit = True;
554 if (isascii(event.m_keyCode) && (textStruct->text->length == 1))
555 {
556 textStruct->text->ptr[0] = ((event.m_keyCode == WXK_RETURN) ? 10 : event.m_keyCode);
557 }
558 }
559 }
560
561 void wxTextCtrl::ChangeFont(bool keepOriginalSize)
562 {
563 wxWindow::ChangeFont(keepOriginalSize);
564 }
565
566 void wxTextCtrl::ChangeBackgroundColour()
567 {
568 wxWindow::ChangeBackgroundColour();
569
570 /* TODO: should scrollbars be affected? Should probably have separate
571 * function to change them (by default, taken from wxSystemSettings)
572 */
573 if (m_windowStyle & wxTE_MULTILINE)
574 {
575 Widget parent = XtParent ((Widget) m_mainWidget);
576 Widget hsb, vsb;
577
578 XtVaGetValues (parent,
579 XmNhorizontalScrollBar, &hsb,
580 XmNverticalScrollBar, &vsb,
581 NULL);
582 wxColour backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
583 if (hsb)
584 DoChangeBackgroundColour((WXWidget) hsb, backgroundColour, TRUE);
585 if (vsb)
586 DoChangeBackgroundColour((WXWidget) vsb, backgroundColour, TRUE);
587
588 // MBN: why change parent background?
589 // DoChangeBackgroundColour((WXWidget) parent, m_backgroundColour, TRUE);
590 }
591 }
592
593 void wxTextCtrl::ChangeForegroundColour()
594 {
595 wxWindow::ChangeForegroundColour();
596
597 if (m_windowStyle & wxTE_MULTILINE)
598 {
599 Widget parent = XtParent ((Widget) m_mainWidget);
600 Widget hsb, vsb;
601
602 XtVaGetValues (parent,
603 XmNhorizontalScrollBar, &hsb,
604 XmNverticalScrollBar, &vsb,
605 NULL);
606
607 /* TODO: should scrollbars be affected? Should probably have separate
608 * function to change them (by default, taken from wxSystemSettings)
609 if (hsb)
610 DoChangeForegroundColour((WXWidget) hsb, m_foregroundColour);
611 if (vsb)
612 DoChangeForegroundColour((WXWidget) vsb, m_foregroundColour);
613 */
614 DoChangeForegroundColour((WXWidget) parent, m_foregroundColour);
615 }
616 }
617
618 void wxTextCtrl::DoSendEvents(void *wxcbs, long keycode)
619 {
620 // we're in process of updating the text control
621 m_tempCallbackStruct = wxcbs;
622
623 XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *)wxcbs;
624
625 wxKeyEvent event (wxEVT_CHAR);
626 event.SetId(GetId());
627 event.m_keyCode = keycode;
628 event.SetEventObject(this);
629
630 // Only if wxTextCtrl::OnChar is called will this be set to True (and
631 // the character passed through)
632 cbs->doit = False;
633
634 GetEventHandler()->ProcessEvent(event);
635
636 if ( !InSetValue() && m_processedDefault )
637 {
638 // Can generate a command
639 wxCommandEvent commandEvent(wxEVT_COMMAND_TEXT_UPDATED, GetId());
640 commandEvent.SetEventObject(this);
641 ProcessCommand(commandEvent);
642 }
643
644 // do it after the (user) event handlers processed the events because
645 // otherwise GetValue() would return incorrect (not yet updated value)
646 m_tempCallbackStruct = NULL;
647 }
648
649 wxSize wxDoGetSingleTextCtrlBestSize( Widget textWidget,
650 const wxWindow* window )
651 {
652 Dimension xmargin, ymargin, highlight, shadow;
653 char* value;
654
655 XtVaGetValues( textWidget,
656 XmNmarginWidth, &xmargin,
657 XmNmarginHeight, &ymargin,
658 XmNvalue, &value,
659 XmNhighlightThickness, &highlight,
660 XmNshadowThickness, &shadow,
661 NULL );
662
663 if( !value )
664 value = "|";
665
666 int x, y;
667 window->GetTextExtent( value, &x, &y );
668
669 if( x < 100 ) x = 100;
670
671 return wxSize( x + 2 * xmargin + 2 * highlight + 2 * shadow,
672 // MBN: +2 necessary: Lesstif bug or mine?
673 y + 2 * ymargin + 2 * highlight + 2 * shadow + 2 );
674 }
675
676 wxSize wxTextCtrl::DoGetBestSize() const
677 {
678 if( IsSingleLine() )
679 return wxDoGetSingleTextCtrlBestSize( (Widget)m_mainWidget, this );
680 else
681 return wxWindow::DoGetBestSize();
682 }
683
684 // ----------------------------------------------------------------------------
685 // helpers and Motif callbacks
686 // ----------------------------------------------------------------------------
687
688 static void MergeChangesIntoString(wxString& value,
689 XmTextVerifyCallbackStruct *cbs)
690 {
691 /* _sm_
692 * At least on my system (SunOS 4.1.3 + Motif 1.2), you need to think of
693 * every event as a replace event. cbs->text->ptr gives the replacement
694 * text, cbs->startPos gives the index of the first char affected by the
695 * replace, and cbs->endPos gives the index one more than the last char
696 * affected by the replace (startPos == endPos implies an empty range).
697 * Hence, a deletion is represented by replacing all input text with a
698 * blank string ("", *not* NULL!). A simple insertion that does not
699 * overwrite any text has startPos == endPos.
700 */
701
702 if ( !value )
703 {
704 // easy case: the ol value was empty
705 value = cbs->text->ptr;
706 }
707 else
708 {
709 // merge the changes into the value
710 const char * const passwd = value;
711 int len = value.length();
712
713 len += ( cbs->text->ptr ?
714 strlen(cbs->text->ptr) :
715 0 ) + 1; // + new text (if any) + NUL
716 len -= cbs->endPos - cbs->startPos; // - text from affected region.
717
718 char * newS = new char [len];
719 char * dest = newS,
720 * insert = cbs->text->ptr;
721
722 // Copy (old) text from passwd, up to the start posn of the change.
723 int i;
724 const char * p = passwd;
725 for (i = 0; i < cbs->startPos; ++i)
726 *dest++ = *p++;
727
728 // Copy the text to be inserted).
729 if (insert)
730 while (*insert)
731 *dest++ = *insert++;
732
733 // Finally, copy into newS any remaining text from passwd[endPos] on.
734 for (p = passwd + cbs->endPos; *p; )
735 *dest++ = *p++;
736 *dest = 0;
737
738 value = newS;
739
740 delete[] newS;
741 }
742 }
743
744 static void
745 wxTextWindowChangedProc (Widget w, XtPointer clientData, XtPointer WXUNUSED(ptr))
746 {
747 if (!wxGetWindowFromTable(w))
748 // Widget has been deleted!
749 return;
750
751 wxTextCtrl *tw = (wxTextCtrl *) clientData;
752 tw->SetModified(TRUE);
753 }
754
755 static void
756 wxTextWindowModifyProc (Widget WXUNUSED(w), XtPointer clientData, XmTextVerifyCallbackStruct *cbs)
757 {
758 wxTextCtrl *tw = (wxTextCtrl *) clientData;
759 tw->m_processedDefault = FALSE;
760
761 // First, do some stuff if it's a password control: in this case, we need
762 // to store the string inside the class because GetValue() can't retrieve
763 // it from the text ctrl. We do *not* do it in other circumstances because
764 // it would double the amount of memory needed.
765
766 if ( tw->GetWindowStyleFlag() & wxTE_PASSWORD )
767 {
768 MergeChangesIntoString(tw->m_value, cbs);
769
770 if ( cbs->text->length > 0 )
771 {
772 int i;
773 for (i = 0; i < cbs->text->length; ++i)
774 cbs->text->ptr[i] = '*';
775 cbs->text->ptr[i] = '\0';
776 }
777 }
778
779 if(tw->InSetValue())
780 return;
781
782 // If we're already within an OnChar, return: probably a programmatic
783 // insertion.
784 if (tw->m_tempCallbackStruct)
785 return;
786
787 // Check for a backspace
788 if (cbs->startPos == (cbs->currInsert - 1))
789 {
790 tw->DoSendEvents((void *)cbs, WXK_DELETE);
791
792 return;
793 }
794
795 // Pasting operation: let it through without calling OnChar
796 if (cbs->text->length > 1)
797 return;
798
799 // Something other than text
800 if (cbs->text->ptr == NULL)
801 return;
802
803 // normal key press
804 char ch = cbs->text->ptr[0];
805 tw->DoSendEvents((void *)cbs, ch == '\n' ? '\r' : ch);
806 }
807
808 static void
809 wxTextWindowGainFocusProc (Widget w, XtPointer clientData, XmAnyCallbackStruct *WXUNUSED(cbs))
810 {
811 if (!wxGetWindowFromTable(w))
812 return;
813
814 wxTextCtrl *tw = (wxTextCtrl *) clientData;
815 wxFocusEvent event(wxEVT_SET_FOCUS, tw->GetId());
816 event.SetEventObject(tw);
817 tw->GetEventHandler()->ProcessEvent(event);
818 }
819
820 static void
821 wxTextWindowLoseFocusProc (Widget w, XtPointer clientData, XmAnyCallbackStruct *WXUNUSED(cbs))
822 {
823 if (!wxGetWindowFromTable(w))
824 return;
825
826 wxTextCtrl *tw = (wxTextCtrl *) clientData;
827 wxFocusEvent event(wxEVT_KILL_FOCUS, tw->GetId());
828 event.SetEventObject(tw);
829 tw->GetEventHandler()->ProcessEvent(event);
830 }
831
832 static void wxTextWindowActivateProc(Widget w, XtPointer clientData,
833 XmAnyCallbackStruct *WXUNUSED(ptr))
834 {
835 if (!wxGetWindowFromTable(w))
836 return;
837
838 wxTextCtrl *tw = (wxTextCtrl *) clientData;
839
840 if (tw->InSetValue())
841 return;
842
843 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER);
844 event.SetId(tw->GetId());
845 event.SetEventObject(tw);
846 tw->ProcessCommand(event);
847 }
848
849 void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
850 {
851 Cut();
852 }
853
854 void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
855 {
856 Copy();
857 }
858
859 void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
860 {
861 Paste();
862 }
863
864 void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
865 {
866 Undo();
867 }
868
869 void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
870 {
871 Redo();
872 }
873
874 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
875 {
876 event.Enable( CanCut() );
877 }
878
879 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
880 {
881 event.Enable( CanCopy() );
882 }
883
884 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
885 {
886 event.Enable( CanPaste() );
887 }
888
889 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
890 {
891 event.Enable( CanUndo() );
892 }
893
894 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
895 {
896 event.Enable( CanRedo() );
897 }