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