]> git.saurik.com Git - wxWidgets.git/blob - src/os2/textctrl.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / os2 / textctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textctrl.cpp
3 // Purpose: wxTextCtrl
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ----------------------------------------------------------------------------
13 // headers
14 // ----------------------------------------------------------------------------
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifndef WX_PRECOMP
20 #include "wx/textctrl.h"
21 #include "wx/settings.h"
22 #include "wx/brush.h"
23 #include "wx/utils.h"
24 #include "wx/log.h"
25 #endif
26
27 #if wxUSE_CLIPBOARD
28 #include "wx/app.h"
29 #include "wx/clipbrd.h"
30 #endif
31
32 #include "wx/textfile.h"
33
34 #include "wx/os2/private.h"
35
36 #include <string.h>
37 #include <stdlib.h>
38 #include <sys/types.h>
39
40 #if wxUSE_IOSTREAMH
41 # include <fstream.h>
42 #else
43 # include <fstream>
44 #endif
45
46 #if !USE_SHARED_LIBRARY
47
48 // ----------------------------------------------------------------------------
49 // event tables and other macros
50 // ----------------------------------------------------------------------------
51
52 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
53
54 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
55 EVT_CHAR(wxTextCtrl::OnChar)
56 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
57
58 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
59 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
60 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
61 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
62 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
63
64 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
65 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
66 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
67 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
68 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
69 END_EVENT_TABLE()
70
71 #endif // USE_SHARED_LIBRARY
72
73 // ============================================================================
74 // implementation
75 // ============================================================================
76
77 // ----------------------------------------------------------------------------
78 // creation
79 // ----------------------------------------------------------------------------
80
81 wxTextCtrl::wxTextCtrl()
82 {
83 }
84
85 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
86 const wxString& value,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 #if wxUSE_VALIDATORS
91 # if defined(__VISAGECPP__)
92 const wxValidator* validator,
93 # else
94 const wxValidator& validator,
95 # endif
96 #endif
97 const wxString& name)
98 {
99 // base initialization
100 if ( !CreateBase(parent, id, pos, size, style, validator, name) )
101 return FALSE;
102
103 // Validator was set in CreateBase
104 //SetValidator(validator);
105 if ( parent )
106 parent->AddChild(this);
107
108 // set colours
109 SetupColours();
110
111 // translate wxWin style flags to MSW ones, checking for consistency while
112 // doing it
113 // TODO:
114 /*
115 long msStyle = ES_LEFT | WS_VISIBLE | WS_CHILD | WS_TABSTOP;
116 if ( m_windowStyle & wxTE_MULTILINE )
117 {
118 wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
119 wxT("wxTE_PROCESS_ENTER style is ignored for multiline "
120 "text controls (they always process it)") );
121
122 msStyle |= ES_MULTILINE | ES_WANTRETURN;
123 if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
124 msStyle |= WS_VSCROLL;
125 m_windowStyle |= wxTE_PROCESS_ENTER;
126 }
127 else
128 msStyle |= ES_AUTOHSCROLL;
129
130 if (m_windowStyle & wxHSCROLL)
131 msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
132
133 if (m_windowStyle & wxTE_READONLY)
134 msStyle |= ES_READONLY;
135
136 if (m_windowStyle & wxHSCROLL)
137 msStyle |= (WS_HSCROLL | ES_AUTOHSCROLL);
138 if (m_windowStyle & wxTE_PASSWORD) // hidden input
139 msStyle |= ES_PASSWORD;
140
141 // we always want the characters and the arrows
142 m_lDlgCode = DLGC_WANTCHARS | DLGC_WANTARROWS;
143
144 // we may have several different cases:
145 // 1. normal case: both TAB and ENTER are used for dialog navigation
146 // 2. ctrl which wants TAB for itself: ENTER is used to pass to the next
147 // control in the dialog
148 // 3. ctrl which wants ENTER for itself: TAB is used for dialog navigation
149 // 4. ctrl which wants both TAB and ENTER: Ctrl-ENTER is used to pass to
150 // the next control
151 if ( m_windowStyle & wxTE_PROCESS_ENTER )
152 m_lDlgCode |= DLGC_WANTMESSAGE;
153 if ( m_windowStyle & wxTE_PROCESS_TAB )
154 m_lDlgCode |= DLGC_WANTTAB;
155
156 // do create the control - either an EDIT or RICHEDIT
157 const wxChar *windowClass = wxT("EDIT");
158
159 bool want3D;
160 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D);
161
162 // Even with extended styles, need to combine with WS_BORDER for them to
163 // look right.
164 if ( want3D || wxStyleHasBorder(m_windowStyle) )
165 msStyle |= WS_BORDER;
166
167 // NB: don't use pos and size as CreateWindowEx arguments because they
168 // might be -1 in which case we should use the default values (and
169 // SetSize called below takes care of it)
170 m_hWnd = (WXHWND)::CreateWindowEx(exStyle,
171 windowClass,
172 NULL,
173 msStyle,
174 0, 0, 0, 0,
175 GetHwndOf(parent),
176 (HMENU)m_windowId,
177 wxGetInstance(),
178 NULL);
179
180 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create text ctrl") );
181 */
182 SubclassWin(GetHWND());
183
184 // set font, position, size and initial value
185 wxFont& fontParent = parent->GetFont();
186 if ( fontParent.Ok() )
187 {
188 SetFont(fontParent);
189 }
190 else
191 {
192 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
193 }
194
195 SetSize(pos.x, pos.y, size.x, size.y);
196
197 return TRUE;
198 }
199
200 // Make sure the window style (etc.) reflects the HWND style (roughly)
201 void wxTextCtrl::AdoptAttributesFromHWND()
202 {
203 wxWindow::AdoptAttributesFromHWND();
204
205 HWND hWnd = GetHwnd();
206 // TODO:
207 /*
208 long style = GetWindowLong(hWnd, GWL_STYLE);
209
210 if (style & ES_MULTILINE)
211 m_windowStyle |= wxTE_MULTILINE;
212 if (style & ES_PASSWORD)
213 m_windowStyle |= wxTE_PASSWORD;
214 if (style & ES_READONLY)
215 m_windowStyle |= wxTE_READONLY;
216 if (style & ES_WANTRETURN)
217 m_windowStyle |= wxTE_PROCESS_ENTER;
218 */
219 }
220
221 void wxTextCtrl::SetupColours()
222 {
223 // FIXME why is bg colour not inherited from parent?
224 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
225 SetForegroundColour(GetParent()->GetForegroundColour());
226 }
227
228 // ----------------------------------------------------------------------------
229 // set/get the controls text
230 // ----------------------------------------------------------------------------
231
232 wxString wxTextCtrl::GetValue() const
233 {
234 return wxGetWindowText(GetHWND());
235 }
236
237 void wxTextCtrl::SetValue(const wxString& value)
238 {
239 // TODO:
240 /*
241 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
242
243 SetWindowText(GetHwnd(), valueDos);
244
245 AdjustSpaceLimit();
246 */
247 }
248
249 void wxTextCtrl::WriteText(const wxString& value)
250 {
251 // TODO:
252 /*
253 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
254
255 SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str());
256
257 AdjustSpaceLimit();
258 */
259 }
260
261 void wxTextCtrl::AppendText(const wxString& text)
262 {
263 // TODO:
264 /*
265 SetInsertionPointEnd();
266 WriteText(text);
267 */
268 }
269
270 void wxTextCtrl::Clear()
271 {
272 // SetWindowText(GetHwnd(), wxT(""));
273 }
274
275 // ----------------------------------------------------------------------------
276 // Clipboard operations
277 // ----------------------------------------------------------------------------
278
279 void wxTextCtrl::Copy()
280 {
281 if (CanCopy())
282 {
283 HWND hWnd = GetHwnd();
284 // SendMessage(hWnd, WM_COPY, 0, 0L);
285 }
286 }
287
288 void wxTextCtrl::Cut()
289 {
290 if (CanCut())
291 {
292 HWND hWnd = GetHwnd();
293 // SendMessage(hWnd, WM_CUT, 0, 0L);
294 }
295 }
296
297 void wxTextCtrl::Paste()
298 {
299 if (CanPaste())
300 {
301 HWND hWnd = GetHwnd();
302 // SendMessage(hWnd, WM_PASTE, 0, 0L);
303 }
304 }
305
306 bool wxTextCtrl::CanCopy() const
307 {
308 // Can copy if there's a selection
309 long from, to;
310 // GetSelection(& from, & to);
311 return (from != to);
312 }
313
314 bool wxTextCtrl::CanCut() const
315 {
316 // Can cut if there's a selection
317 long from, to;
318 // GetSelection(& from, & to);
319 return (from != to);
320 }
321
322 bool wxTextCtrl::CanPaste() const
323 {
324 if (!IsEditable())
325 return FALSE;
326
327 // Standard edit control: check for straight text on clipboard
328 bool isTextAvailable = FALSE;
329 //TODO:
330 /*
331 if ( ::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) )
332 {
333 isTextAvailable = (::IsClipboardFormatAvailable(CF_TEXT) != 0);
334 ::CloseClipboard();
335 }
336 */
337 return isTextAvailable;
338 }
339
340 // ----------------------------------------------------------------------------
341 // Accessors
342 // ----------------------------------------------------------------------------
343
344 void wxTextCtrl::SetEditable(bool editable)
345 {
346 HWND hWnd = GetHwnd();
347 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
348 }
349
350 void wxTextCtrl::SetInsertionPoint(long pos)
351 {
352 // TODO:
353 /*
354 HWND hWnd = GetHwnd();
355 {
356 SendMessage(hWnd, EM_SETSEL, pos, pos);
357 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
358 }
359 static const char *nothing = "";
360 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
361 */
362 }
363
364 void wxTextCtrl::SetInsertionPointEnd()
365 {
366 // TODO:
367 /*
368 long pos = GetLastPosition();
369 SetInsertionPoint(pos);
370 */
371 }
372
373 long wxTextCtrl::GetInsertionPoint() const
374 {
375 // TODO:
376 /*
377 DWORD Pos = (DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
378 return Pos & 0xFFFF;
379 */
380 return 0;
381 }
382
383 long wxTextCtrl::GetLastPosition() const
384 {
385 HWND hWnd = GetHwnd();
386
387 // TODO:
388 /*
389 // Will always return a number > 0 (according to docs)
390 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
391
392 // This gets the char index for the _beginning_ of the last line
393 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
394
395 // Get number of characters in the last line. We'll add this to the character
396 // index for the last line, 1st position.
397 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
398
399 return (long)(charIndex + lineLength);
400 */
401 return 0L;
402 }
403
404 // If the return values from and to are the same, there is no
405 // selection.
406 void wxTextCtrl::GetSelection(long* from, long* to) const
407 {
408 DWORD dwStart, dwEnd;
409 MPARAM wParam = (MPARAM) (DWORD*) & dwStart; // receives starting position
410 MPARAM lParam = (MPARAM) (DWORD*) & dwEnd; // receives ending position
411
412 // ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
413
414 *from = dwStart;
415 *to = dwEnd;
416 }
417
418 bool wxTextCtrl::IsEditable() const
419 {
420 // TODO:
421 /*
422 long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
423
424 return ((style & ES_READONLY) == 0);
425 */
426 return FALSE;
427 }
428
429 // ----------------------------------------------------------------------------
430 // Editing
431 // ----------------------------------------------------------------------------
432
433 void wxTextCtrl::Replace(long from, long to, const wxString& value)
434 {
435 #if wxUSE_CLIPBOARD
436 HWND hWnd = GetHwnd();
437 long fromChar = from;
438 long toChar = to;
439
440 // Set selection and remove it
441 // SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
442 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
443
444 // Now replace with 'value', by pasting.
445 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)value, 0, 0);
446
447 // Paste into edit control
448 // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
449 #else
450 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
451 #endif
452 }
453
454 void wxTextCtrl::Remove(long from, long to)
455 {
456 HWND hWnd = GetHwnd();
457 long fromChar = from;
458 long toChar = to;
459
460 // Cut all selected text
461 // SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
462 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
463 }
464
465 void wxTextCtrl::SetSelection(long from, long to)
466 {
467 HWND hWnd = GetHwnd();
468 long fromChar = from;
469 long toChar = to;
470
471 // if from and to are both -1, it means (in wxWindows) that all text should
472 // be selected. Translate into Windows convention
473 if ((from == -1) && (to == -1))
474 {
475 fromChar = 0;
476 toChar = -1;
477 }
478
479 // SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
480 // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
481 }
482
483 bool wxTextCtrl::LoadFile(const wxString& file)
484 {
485 // TODO:
486 /*
487 if ( wxTextCtrlBase::LoadFile(file) )
488 {
489 // update the size limit if needed
490 AdjustSpaceLimit();
491
492 return TRUE;
493 }
494 */
495 return FALSE;
496 }
497
498 bool wxTextCtrl::IsModified() const
499 {
500 // return (SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0);
501 return FALSE;
502 }
503
504 // Makes 'unmodified'
505 void wxTextCtrl::DiscardEdits()
506 {
507 // SendMessage(GetHwnd(), EM_SETMODIFY, FALSE, 0L);
508 }
509
510 int wxTextCtrl::GetNumberOfLines() const
511 {
512 // return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
513 return 0;
514 }
515
516 long wxTextCtrl::XYToPosition(long x, long y) const
517 {
518 HWND hWnd = GetHwnd();
519
520 // This gets the char index for the _beginning_ of this line
521 // TODO:
522 /*
523 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
524 return (long)(x + charIndex);
525 */
526 return 0L;
527 }
528
529 bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
530 {
531 HWND hWnd = GetHwnd();
532
533 // This gets the line number containing the character
534 int lineNo;
535 // lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
536
537 if ( lineNo == -1 )
538 {
539 // no such line
540 return FALSE;
541 }
542
543 // This gets the char index for the _beginning_ of this line
544 int charIndex = 0; // TODO: (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
545 if ( charIndex == -1 )
546 {
547 return FALSE;
548 }
549
550 // The X position must therefore be the different between pos and charIndex
551 if ( x )
552 *x = (long)(pos - charIndex);
553 if ( y )
554 *y = (long)lineNo;
555
556 return TRUE;
557 }
558
559 void wxTextCtrl::ShowPosition(long pos)
560 {
561 HWND hWnd = GetHwnd();
562
563 // To scroll to a position, we pass the number of lines and characters
564 // to scroll *by*. This means that we need to:
565 // (1) Find the line position of the current line.
566 // (2) Find the line position of pos.
567 // (3) Scroll by (pos - current).
568 // For now, ignore the horizontal scrolling.
569
570 // Is this where scrolling is relative to - the line containing the caret?
571 // Or is the first visible line??? Try first visible line.
572 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
573
574 // TODO:
575 /*
576 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
577
578 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
579
580 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
581
582 if (linesToScroll != 0)
583 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
584 */
585 }
586
587 int wxTextCtrl::GetLineLength(long lineNo) const
588 {
589 // TODO:
590 /*
591
592 long charIndex = XYToPosition(0, lineNo);
593 int len = (int)SendMessage(GetHwnd(), EM_LINELENGTH, charIndex, 0);
594 return len;
595 */
596 return 0;
597 }
598
599 wxString wxTextCtrl::GetLineText(long lineNo) const
600 {
601 size_t len = (size_t)GetLineLength(lineNo) + 1;
602 char *buf = (char *)malloc(len);
603 *(WORD *)buf = len;
604 int noChars = 0; // TODO:(int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
605 buf[noChars] = 0;
606
607 wxString str(buf);
608
609 free(buf);
610
611 return str;
612 }
613
614 // ----------------------------------------------------------------------------
615 // Undo/redo
616 // ----------------------------------------------------------------------------
617
618 void wxTextCtrl::Undo()
619 {
620 if (CanUndo())
621 {
622 // ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
623 }
624 }
625
626 void wxTextCtrl::Redo()
627 {
628 if (CanRedo())
629 {
630 // Same as Undo, since Undo undoes the undo, i.e. a redo.
631 // ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
632 }
633 }
634
635 bool wxTextCtrl::CanUndo() const
636 {
637 // return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
638 return FALSE;
639 }
640
641 bool wxTextCtrl::CanRedo() const
642 {
643 // return (::SendMessage(GetHwnd(), EM_CANUNDO, 0, 0) != 0);
644 return FALSE;
645 }
646
647 // ----------------------------------------------------------------------------
648 // implemenation details
649 // ----------------------------------------------------------------------------
650
651 void wxTextCtrl::Command(wxCommandEvent & event)
652 {
653 SetValue(event.GetString());
654 ProcessCommand (event);
655 }
656
657 void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
658 {
659 // By default, load the first file into the text window.
660 if (event.GetNumberOfFiles() > 0)
661 {
662 LoadFile(event.GetFiles()[0]);
663 }
664 }
665
666 WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
667 WXUINT message, WXWPARAM wParam,
668 WXLPARAM lParam)
669 {
670 HDC hdc = (HDC)pDC;
671 // TODO:
672 /*
673 SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
674 : OPAQUE);
675
676 ::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
677 ::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
678 */
679 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
680
681 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
682 }
683
684 void wxTextCtrl::OnChar(wxKeyEvent& event)
685 {
686 switch ( event.KeyCode() )
687 {
688 // TODO:
689 /*
690 case WXK_RETURN:
691 if ( !(m_windowStyle & wxTE_MULTILINE) )
692 {
693 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
694 event.SetEventObject( this );
695 if ( GetEventHandler()->ProcessEvent(event) )
696 return;
697 }
698 //else: multiline controls need Enter for themselves
699
700 break;
701
702 case WXK_TAB:
703 // always produce navigation event - even if we process TAB
704 // ourselves the fact that we got here means that the user code
705 // decided to skip processing of this TAB - probably to let it
706 // do its default job.
707 //
708 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
709 // handled by Windows
710 {
711 wxNavigationKeyEvent eventNav;
712 eventNav.SetDirection(!event.ShiftDown());
713 eventNav.SetWindowChange(FALSE);
714 eventNav.SetEventObject(this);
715
716 if ( GetEventHandler()->ProcessEvent(eventNav) )
717 return;
718 }
719 break;
720 */
721 default:
722 event.Skip();
723 return;
724 }
725
726 // don't just call event.Skip() because this will cause TABs and ENTERs
727 // be passed upwards and we don't always want this - instead process it
728 // right here
729
730 // FIXME
731 event.Skip();
732 }
733
734 bool wxTextCtrl::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
735 {
736 switch (param)
737 {
738 // TODO:
739 /*
740 case EN_SETFOCUS:
741 case EN_KILLFOCUS:
742 {
743 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
744 : wxEVT_SET_FOCUS,
745 m_windowId);
746 event.SetEventObject( this );
747 GetEventHandler()->ProcessEvent(event);
748 }
749 break;
750
751 case EN_CHANGE:
752 {
753 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
754 wxString val(GetValue());
755 if ( !val.IsNull() )
756 event.m_commandString = WXSTRINGCAST val;
757 event.SetEventObject( this );
758 ProcessCommand(event);
759 }
760 break;
761
762 case EN_ERRSPACE:
763 // the text size limit has been hit - increase it
764 AdjustSpaceLimit();
765 break;
766
767 // the other notification messages are not processed
768 case EN_UPDATE:
769 case EN_MAXTEXT:
770 case EN_HSCROLL:
771 case EN_VSCROLL:
772 */
773 default:
774 return FALSE;
775 }
776
777 // processed
778 return TRUE;
779 }
780
781 void wxTextCtrl::AdjustSpaceLimit()
782 {
783 // TODO:
784 /*
785 unsigned int len = ::GetWindowTextLength(GetHwnd()),
786 limit = ::SendMessage(GetHwnd(), EM_GETLIMITTEXT, 0, 0);
787 if ( len > limit )
788 {
789 limit = len + 0x8000; // 32Kb
790
791 if ( limit > 0xffff )
792 ::SendMessage(GetHwnd(), EM_LIMITTEXT, 0, limit);
793 else
794 ::SendMessage(GetHwnd(), EM_LIMITTEXT, limit, 0);
795 }
796 */
797 }
798
799 bool wxTextCtrl::AcceptsFocus() const
800 {
801 // we don't want focus if we can't be edited
802 return IsEditable() && wxControl::AcceptsFocus();
803 }
804
805 wxSize wxTextCtrl::DoGetBestSize()
806 {
807 int cx, cy;
808 wxGetCharSize(GetHWND(), &cx, &cy, &GetFont());
809
810 int wText = DEFAULT_ITEM_WIDTH;
811
812 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
813 if ( m_windowStyle & wxTE_MULTILINE )
814 {
815 hText *= wxMin(GetNumberOfLines(), 5);
816 }
817 //else: for single line control everything is ok
818
819 return wxSize(wText, hText);
820 }
821
822 // ----------------------------------------------------------------------------
823 // standard handlers for standard edit menu events
824 // ----------------------------------------------------------------------------
825
826 void wxTextCtrl::OnCut(wxCommandEvent& event)
827 {
828 Cut();
829 }
830
831 void wxTextCtrl::OnCopy(wxCommandEvent& event)
832 {
833 Copy();
834 }
835
836 void wxTextCtrl::OnPaste(wxCommandEvent& event)
837 {
838 Paste();
839 }
840
841 void wxTextCtrl::OnUndo(wxCommandEvent& event)
842 {
843 Undo();
844 }
845
846 void wxTextCtrl::OnRedo(wxCommandEvent& event)
847 {
848 Redo();
849 }
850
851 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
852 {
853 event.Enable( CanCut() );
854 }
855
856 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
857 {
858 event.Enable( CanCopy() );
859 }
860
861 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
862 {
863 event.Enable( CanPaste() );
864 }
865
866 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
867 {
868 event.Enable( CanUndo() );
869 }
870
871 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
872 {
873 event.Enable( CanRedo() );
874 }
875