]> git.saurik.com Git - wxWidgets.git/blob - src/os2/textctrl.cpp
Filling out common controls now.
[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
47 // ----------------------------------------------------------------------------
48 // event tables and other macros
49 // ----------------------------------------------------------------------------
50
51 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
52
53 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
54 EVT_CHAR(wxTextCtrl::OnChar)
55 EVT_DROP_FILES(wxTextCtrl::OnDropFiles)
56
57 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
58 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
59 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
60 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
61 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
62
63 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
64 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
65 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
66 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
67 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
68 END_EVENT_TABLE()
69
70
71 // ============================================================================
72 // implementation
73 // ============================================================================
74
75 // ----------------------------------------------------------------------------
76 // creation
77 // ----------------------------------------------------------------------------
78
79 wxTextCtrl::wxTextCtrl()
80 {
81 }
82
83 bool wxTextCtrl::Create(
84 wxWindow* pParent
85 , wxWindowID vId
86 , const wxString& rsValue
87 , const wxPoint& rPos
88 , const wxSize& rSize
89 , long lStyle
90 #if wxUSE_VALIDATORS
91 , const wxValidator& rValidator
92 #endif
93 , const wxString& rsName
94 )
95 {
96 //
97 // Base initialization
98 //
99 if ( !CreateBase( pParent
100 ,vId
101 ,rPos
102 ,rSize
103 ,lStyle
104 #if wxUSE_VALIDATORS
105 ,rValidator
106 #endif
107 ,rsName
108 ))
109 return FALSE;
110
111 if (pParent )
112 pParent->AddChild(this);
113
114 m_windowStyle = lStyle;
115
116 long lSstyle = WS_VISIBLE | WS_TABSTOP;
117
118 //
119 // Single and multiline edit fields are two different controls in PM
120 //
121 if ( m_windowStyle & wxTE_MULTILINE )
122 {
123 m_bIsMLE = TRUE;
124 m_windowStyle |= wxTE_PROCESS_ENTER;
125
126 if ((m_windowStyle & wxTE_NO_VSCROLL) == 0)
127 lSstyle |= MLS_VSCROLL;
128 if (m_windowStyle & wxHSCROLL)
129 lSstyle |= MLS_HSCROLL;
130 if (m_windowStyle & wxTE_READONLY)
131 lSstyle |= MLS_READONLY;
132 }
133 else
134 {
135 lSstyle |= ES_LEFT;
136
137 if (m_windowStyle & wxHSCROLL)
138 lSstyle |= ES_AUTOSCROLL;
139 if (m_windowStyle & wxTE_READONLY)
140 lSstyle |= ES_READONLY;
141 if (m_windowStyle & wxTE_PASSWORD) // hidden input
142 lSstyle |= ES_UNREADABLE;
143 }
144 if (m_bIsMLE)
145 {
146 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
147 ,WC_MLE // Window class
148 ,(PSZ)rsValue.c_str() // Initial Text
149 ,(ULONG)lSstyle // Style flags
150 ,(LONG)rPos.x // X pos of origin
151 ,(LONG)rPos.y // Y pos of origin
152 ,(LONG)rSize.x // field width
153 ,(LONG)rSize.y // field height
154 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
155 ,HWND_TOP // initial z position
156 ,(ULONG)vId // Window identifier
157 ,NULL // no control data
158 ,NULL // no Presentation parameters
159 );
160 }
161 else
162 {
163 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
164 ,WC_ENTRYFIELD // Window class
165 ,(PSZ)rsValue.c_str() // Initial Text
166 ,(ULONG)lSstyle // Style flags
167 ,(LONG)rPos.x // X pos of origin
168 ,(LONG)rPos.y // Y pos of origin
169 ,(LONG)rSize.x // field width
170 ,(LONG)rSize.y // field height
171 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
172 ,HWND_TOP // initial z position
173 ,(ULONG)vId // Window identifier
174 ,NULL // no control data
175 ,NULL // no Presentation parameters
176 );
177 }
178
179 if (m_hWnd == 0)
180 {
181 return FALSE;
182 }
183
184 SubclassWin(GetHWND());
185
186 //
187 // Set font, position, size and initial value
188 //
189 wxFont& vFontParent = pParent->GetFont();
190
191 if (vFontParent.Ok())
192 {
193 SetFont(vFontParent);
194 }
195 else
196 {
197 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT));
198 }
199 if (!rsValue.IsEmpty())
200 {
201 SetValue(rsValue);
202 }
203 SetupColours();
204 SetSize( rPos.x
205 ,rPos.y
206 ,rSize.x
207 ,rSize.y
208 );
209 return TRUE;
210 } // end of wxTextCtrl::Create
211
212 //
213 // Make sure the window style (etc.) reflects the HWND style (roughly)
214 //
215 void wxTextCtrl::AdoptAttributesFromHWND()
216 {
217 HWND hWnd = GetHwnd();
218 LONG lStyle = ::WinQueryWindowULong(hWnd, QWL_STYLE);
219
220 wxWindow::AdoptAttributesFromHWND();
221
222 if (m_bIsMLE)
223 {
224 m_windowStyle |= wxTE_MULTILINE;
225 if (lStyle & MLS_READONLY)
226 m_windowStyle |= wxTE_READONLY;
227 }
228 else
229 {
230 if (lStyle & ES_UNREADABLE)
231 m_windowStyle |= wxTE_PASSWORD;
232 if (lStyle & ES_READONLY)
233 m_windowStyle |= wxTE_READONLY;
234 }
235 }
236
237 void wxTextCtrl::SetupColours()
238 {
239 // FIXME why is bg colour not inherited from parent?
240 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
241 SetForegroundColour(GetParent()->GetForegroundColour());
242 }
243
244 // ----------------------------------------------------------------------------
245 // set/get the controls text
246 // ----------------------------------------------------------------------------
247
248 wxString wxTextCtrl::GetValue() const
249 {
250 return wxGetWindowText(GetHWND());
251 }
252
253 void wxTextCtrl::SetValue(const wxString& value)
254 {
255 // TODO:
256 /*
257 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
258
259 SetWindowText(GetHwnd(), valueDos);
260
261 AdjustSpaceLimit();
262 */
263 }
264
265 void wxTextCtrl::WriteText(const wxString& value)
266 {
267 // TODO:
268 /*
269 wxString valueDos = wxTextFile::Translate(value, wxTextFileType_Dos);
270
271 SendMessage(GetHwnd(), EM_REPLACESEL, 0, (LPARAM)valueDos.c_str());
272
273 AdjustSpaceLimit();
274 */
275 }
276
277 void wxTextCtrl::AppendText(const wxString& text)
278 {
279 // TODO:
280 /*
281 SetInsertionPointEnd();
282 WriteText(text);
283 */
284 }
285
286 void wxTextCtrl::Clear()
287 {
288 // SetWindowText(GetHwnd(), wxT(""));
289 }
290
291 // ----------------------------------------------------------------------------
292 // Clipboard operations
293 // ----------------------------------------------------------------------------
294
295 void wxTextCtrl::Copy()
296 {
297 if (CanCopy())
298 {
299 HWND hWnd = GetHwnd();
300 if (m_bIsMLE)
301 ::WinSendMsg(hWnd, MLM_COPY, 0, 0);
302 else
303 ::WinSendMsg(hWnd, EM_COPY, 0, 0);
304 }
305 } // end of wxTextCtrl::Copy
306
307 void wxTextCtrl::Cut()
308 {
309 if (CanCut())
310 {
311 HWND hWnd = GetHwnd();
312
313 if (m_bIsMLE)
314 ::WinSendMsg(hWnd, MLM_CUT, 0, 0);
315 else
316 ::WinSendMsg(hWnd, EM_CUT, 0, 0);
317 }
318 }
319
320 void wxTextCtrl::Paste()
321 {
322 if (CanPaste())
323 {
324 HWND hWnd = GetHwnd();
325 // SendMessage(hWnd, WM_PASTE, 0, 0L);
326 }
327 }
328
329 bool wxTextCtrl::CanCopy() const
330 {
331 // Can copy if there's a selection
332 long from = 0L;
333 long to = 0L;
334 // GetSelection(& from, & to);
335 return (from != to);
336 }
337
338 bool wxTextCtrl::CanCut() const
339 {
340 // Can cut if there's a selection
341 long from = 0L;
342 long to = 0L;
343 // GetSelection(& from, & to);
344 return (from != to);
345 }
346
347 bool wxTextCtrl::CanPaste() const
348 {
349 bool bIsTextAvailable = FALSE;
350
351 if (!IsEditable())
352 return FALSE;
353
354 //
355 // Check for straight text on clipboard
356 //
357 if (::WinOpenClipbrd(vHabmain))
358 {
359 bIsTextAvailable = (::WinQueryClipbrdData(vHabmain, CF_TEXT) != 0);
360 ::WinCloseClipbrd(vHabmain);
361 }
362 return bIsTextAvailable;
363 } // end of wxTextCtrl::CanPaste
364
365 // ----------------------------------------------------------------------------
366 // Accessors
367 // ----------------------------------------------------------------------------
368
369 void wxTextCtrl::SetEditable(bool editable)
370 {
371 HWND hWnd = GetHwnd();
372 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
373 }
374
375 void wxTextCtrl::SetInsertionPoint(long pos)
376 {
377 // TODO:
378 /*
379 HWND hWnd = GetHwnd();
380 {
381 SendMessage(hWnd, EM_SETSEL, pos, pos);
382 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
383 }
384 static const char *nothing = "";
385 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
386 */
387 }
388
389 void wxTextCtrl::SetInsertionPointEnd()
390 {
391 }
392
393 long wxTextCtrl::GetInsertionPoint() const
394 {
395 WXDWORD dwPos = 0L;
396
397 if (m_bIsMLE)
398 dwPos = (WXDWORD)::WinSendMsg(GetHwnd(), MLM_QUERYSEL, (MPARAM)MLFQS_MINSEL, 0);
399 else
400 {
401 dwPos = (WXDWORD)::WinSendMsg(GetHwnd(), EM_QUERYSEL, 0, 0);
402 dwPos = SHORT1FROMMP((MPARAM)dwPos); // the first 16 bit value is the min pos
403 }
404 return (dwPos & 0xFFFF);
405 } // end of wxTextCtrl::GetInsertionPoint
406
407 long wxTextCtrl::GetLastPosition() const
408 {
409 HWND hWnd = GetHwnd();
410 long lCharIndex;
411 long lLineLength;
412
413 if (m_bIsMLE)
414 {
415 lCharIndex = 0;
416
417 //
418 // This just gets the total text length. The last will be this value
419 //
420 lLineLength = (long)::WinSendMsg(hWnd, MLM_QUERYTEXTLENGTH, 0, 0);
421 }
422 else
423 {
424 WNDPARAMS vParams;
425
426 lCharIndex = 0;
427 vParams.fsStatus = WPM_CCHTEXT;
428 if (::WinSendMsg( GetHwnd()
429 ,WM_QUERYWINDOWPARAMS
430 ,&vParams
431 ,0
432 ))
433 {
434 lLineLength = (long)vParams.cchText;
435 }
436 else
437 lLineLength = 0;
438 }
439 return(lCharIndex + lLineLength);
440 } // end of wxTextCtrl::GetLastPosition
441
442 // If the return values from and to are the same, there is no
443 // selection.
444 void wxTextCtrl::GetSelection(long* from, long* to) const
445 {
446 DWORD dwStart, dwEnd;
447 MPARAM wParam = (MPARAM) (DWORD*) & dwStart; // receives starting position
448 MPARAM lParam = (MPARAM) (DWORD*) & dwEnd; // receives ending position
449
450 // ::SendMessage(GetHwnd(), EM_GETSEL, wParam, lParam);
451
452 *from = dwStart;
453 *to = dwEnd;
454 }
455
456 bool wxTextCtrl::IsEditable() const
457 {
458 // TODO:
459 /*
460 long style = ::GetWindowLong(GetHwnd(), GWL_STYLE);
461
462 return ((style & ES_READONLY) == 0);
463 */
464 return FALSE;
465 }
466
467 // ----------------------------------------------------------------------------
468 // Editing
469 // ----------------------------------------------------------------------------
470
471 void wxTextCtrl::Replace(long from, long to, const wxString& value)
472 {
473 #if wxUSE_CLIPBOARD
474 HWND hWnd = GetHwnd();
475 long fromChar = from;
476 long toChar = to;
477
478 // Set selection and remove it
479 // SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
480 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
481
482 // Now replace with 'value', by pasting.
483 wxSetClipboardData(wxDF_TEXT, (wxObject *) (const wxChar *)value, 0, 0);
484
485 // Paste into edit control
486 // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
487 #else
488 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
489 #endif
490 }
491
492 void wxTextCtrl::Remove(long from, long to)
493 {
494 HWND hWnd = GetHwnd();
495 long fromChar = from;
496 long toChar = to;
497
498 // Cut all selected text
499 // SendMessage(hWnd, EM_SETSEL, fromChar, toChar);
500 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
501 }
502
503 void wxTextCtrl::SetSelection(long from, long to)
504 {
505 HWND hWnd = GetHwnd();
506 long fromChar = from;
507 long toChar = to;
508
509 // if from and to are both -1, it means (in wxWindows) that all text should
510 // be selected. Translate into Windows convention
511 if ((from == -1) && (to == -1))
512 {
513 fromChar = 0;
514 toChar = -1;
515 }
516
517 // SendMessage(hWnd, EM_SETSEL, (WPARAM)fromChar, (LPARAM)toChar);
518 // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
519 }
520
521 bool wxTextCtrl::LoadFile(const wxString& file)
522 {
523 // TODO:
524 /*
525 if ( wxTextCtrlBase::LoadFile(file) )
526 {
527 // update the size limit if needed
528 AdjustSpaceLimit();
529
530 return TRUE;
531 }
532 */
533 return FALSE;
534 }
535
536 bool wxTextCtrl::IsModified() const
537 {
538 // return (SendMessage(GetHwnd(), EM_GETMODIFY, 0, 0) != 0);
539 return FALSE;
540 }
541
542 //
543 // Makes 'unmodified'
544 //
545 void wxTextCtrl::DiscardEdits()
546 {
547 if (m_bIsMLE)
548 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED, MPFROMLONG(FALSE), 0);
549 else
550 //
551 // EM controls do not have a SETCHANGED but issuing a query should reset it
552 //
553 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED, 0, 0);
554 } // end of wxTextCtrl::DiscardEdits
555
556 int wxTextCtrl::GetNumberOfLines() const
557 {
558 // return (int)SendMessage(GetHwnd(), EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0);
559 return 0;
560 }
561
562 long wxTextCtrl::XYToPosition(long x, long y) const
563 {
564 HWND hWnd = GetHwnd();
565
566 // This gets the char index for the _beginning_ of this line
567 // TODO:
568 /*
569 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)y, (LPARAM)0);
570 return (long)(x + charIndex);
571 */
572 return 0L;
573 }
574
575 bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const
576 {
577 HWND hWnd = GetHwnd();
578
579 // This gets the line number containing the character
580 int lineNo = -1;
581 // lineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, 0);
582
583 if ( lineNo == -1 )
584 {
585 // no such line
586 return FALSE;
587 }
588
589 // This gets the char index for the _beginning_ of this line
590 int charIndex = 0; // TODO: (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)lineNo, (LPARAM)0);
591 if ( charIndex == -1 )
592 {
593 return FALSE;
594 }
595
596 // The X position must therefore be the different between pos and charIndex
597 if ( x )
598 *x = (long)(pos - charIndex);
599 if ( y )
600 *y = (long)lineNo;
601
602 return TRUE;
603 }
604
605 void wxTextCtrl::ShowPosition(long pos)
606 {
607 HWND hWnd = GetHwnd();
608
609 // To scroll to a position, we pass the number of lines and characters
610 // to scroll *by*. This means that we need to:
611 // (1) Find the line position of the current line.
612 // (2) Find the line position of pos.
613 // (3) Scroll by (pos - current).
614 // For now, ignore the horizontal scrolling.
615
616 // Is this where scrolling is relative to - the line containing the caret?
617 // Or is the first visible line??? Try first visible line.
618 // int currentLineLineNo1 = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, (LPARAM)0L);
619
620 // TODO:
621 /*
622 int currentLineLineNo = (int)SendMessage(hWnd, EM_GETFIRSTVISIBLELINE, (WPARAM)0, (LPARAM)0L);
623
624 int specifiedLineLineNo = (int)SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)pos, (LPARAM)0L);
625
626 int linesToScroll = specifiedLineLineNo - currentLineLineNo;
627
628 if (linesToScroll != 0)
629 (void)SendMessage(hWnd, EM_LINESCROLL, (WPARAM)0, (LPARAM)linesToScroll);
630 */
631 }
632
633 int wxTextCtrl::GetLineLength(
634 long lLineNo
635 ) const
636 {
637 long lLen = 0L;
638
639 if (m_bIsMLE)
640 lLen = (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH, 0, 0);
641 else
642 {
643 WNDPARAMS vParams;
644
645 vParams.fsStatus = WPM_CCHTEXT;
646 if (::WinSendMsg( GetHwnd()
647 ,WM_QUERYWINDOWPARAMS
648 ,&vParams
649 ,0
650 ))
651 {
652 lLen = vParams.cchText;
653 }
654 else
655 lLen = 32;
656 }
657 return lLen;
658 } // end of
659
660 wxString wxTextCtrl::GetLineText(long lineNo) const
661 {
662 size_t len = (size_t)GetLineLength(lineNo) + 1;
663 char *buf = (char *)malloc(len);
664 *(WORD *)buf = len;
665 int noChars = 0; // TODO:(int)SendMessage(GetHwnd(), EM_GETLINE, lineNo, (LPARAM)buf);
666 buf[noChars] = 0;
667
668 wxString str(buf);
669
670 free(buf);
671
672 return str;
673 }
674
675 // ----------------------------------------------------------------------------
676 // Undo/redo
677 // ----------------------------------------------------------------------------
678
679 void wxTextCtrl::Undo()
680 {
681 if (CanUndo())
682 {
683 // ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
684 }
685 }
686
687 void wxTextCtrl::Redo()
688 {
689 if (CanRedo())
690 {
691 // Same as Undo, since Undo undoes the undo, i.e. a redo.
692 // ::SendMessage(GetHwnd(), EM_UNDO, 0, 0);
693 }
694 }
695
696 bool wxTextCtrl::CanUndo() const
697 {
698 bool bOk;
699
700 if (m_bIsMLE)
701 bOk = (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO, 0, 0) != 0);
702 else
703 bOk = FALSE; // can't undo regular edit fields in PM
704 return bOk;
705 } // end of wxTextCtrl::CanUndo
706
707 bool wxTextCtrl::CanRedo() const
708 {
709 bool bOk;
710
711 if (m_bIsMLE)
712 bOk = (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO, 0, 0) != 0);
713 else
714 bOk = FALSE; // can't undo regular edit fields in PM
715 return bOk;
716 } // end of wxTextCtrl::CanRedo
717
718 // ----------------------------------------------------------------------------
719 // implemenation details
720 // ----------------------------------------------------------------------------
721
722 void wxTextCtrl::Command(wxCommandEvent & event)
723 {
724 SetValue(event.GetString());
725 ProcessCommand (event);
726 }
727
728 void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event)
729 {
730 // By default, load the first file into the text window.
731 if (event.GetNumberOfFiles() > 0)
732 {
733 LoadFile(event.GetFiles()[0]);
734 }
735 }
736
737 WXHBRUSH wxTextCtrl::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
738 WXUINT message, WXWPARAM wParam,
739 WXLPARAM lParam)
740 {
741 HDC hdc = (HDC)pDC;
742 // TODO:
743 /*
744 SetBkMode(hdc, GetParent()->GetTransparentBackground() ? TRANSPARENT
745 : OPAQUE);
746
747 ::SetBkColor(hdc, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
748 ::SetTextColor(hdc, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
749 */
750 wxBrush *backgroundBrush = wxTheBrushList->FindOrCreateBrush(GetBackgroundColour(), wxSOLID);
751
752 return (WXHBRUSH) backgroundBrush->GetResourceHandle();
753 }
754
755 void wxTextCtrl::OnChar(wxKeyEvent& event)
756 {
757 switch ( event.KeyCode() )
758 {
759 // TODO:
760 /*
761 case WXK_RETURN:
762 if ( !(m_windowStyle & wxTE_MULTILINE) )
763 {
764 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
765 event.SetEventObject( this );
766 if ( GetEventHandler()->ProcessEvent(event) )
767 return;
768 }
769 //else: multiline controls need Enter for themselves
770
771 break;
772
773 case WXK_TAB:
774 // always produce navigation event - even if we process TAB
775 // ourselves the fact that we got here means that the user code
776 // decided to skip processing of this TAB - probably to let it
777 // do its default job.
778 //
779 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
780 // handled by Windows
781 {
782 wxNavigationKeyEvent eventNav;
783 eventNav.SetDirection(!event.ShiftDown());
784 eventNav.SetWindowChange(FALSE);
785 eventNav.SetEventObject(this);
786
787 if ( GetEventHandler()->ProcessEvent(eventNav) )
788 return;
789 }
790 break;
791 */
792 default:
793 event.Skip();
794 return;
795 }
796
797 // don't just call event.Skip() because this will cause TABs and ENTERs
798 // be passed upwards and we don't always want this - instead process it
799 // right here
800
801 // FIXME
802 event.Skip();
803 }
804
805 bool wxTextCtrl::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
806 {
807 switch (param)
808 {
809 // TODO:
810 /*
811 case EN_SETFOCUS:
812 case EN_KILLFOCUS:
813 {
814 wxFocusEvent event(param == EN_KILLFOCUS ? wxEVT_KILL_FOCUS
815 : wxEVT_SET_FOCUS,
816 m_windowId);
817 event.SetEventObject( this );
818 GetEventHandler()->ProcessEvent(event);
819 }
820 break;
821
822 case EN_CHANGE:
823 {
824 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
825 wxString val(GetValue());
826 if ( !val.IsNull() )
827 event.m_commandString = WXSTRINGCAST val;
828 event.SetEventObject( this );
829 ProcessCommand(event);
830 }
831 break;
832
833 case EN_ERRSPACE:
834 // the text size limit has been hit - increase it
835 AdjustSpaceLimit();
836 break;
837
838 // the other notification messages are not processed
839 case EN_UPDATE:
840 case EN_MAXTEXT:
841 case EN_HSCROLL:
842 case EN_VSCROLL:
843 */
844 default:
845 return FALSE;
846 }
847
848 // processed
849 return TRUE;
850 }
851
852 void wxTextCtrl::AdjustSpaceLimit()
853 {
854 unsigned int uLen = 0;
855 unsigned int uLimit = 0;
856
857 uLen = ::WinQueryWindowTextLength(GetHwnd());
858 if (m_bIsMLE)
859 {
860 uLimit = (unsigned int)::WinSendMsg( GetHwnd()
861 ,MLM_QUERYTEXTLIMIT
862 ,0
863 ,0
864 );
865 }
866 else
867 {
868 ENTRYFDATA* pEfd;
869 WNDPARAMS vParams;
870
871 vParams.fsStatus = WPM_CBCTLDATA;
872 vParams.cbCtlData = sizeof(ENTRYFDATA);
873
874 if (::WinSendMsg( GetHwnd()
875 ,WM_QUERYWINDOWPARAMS
876 ,&vParams
877 ,0
878 ))
879 {
880 pEfd = (ENTRYFDATA*)vParams.pCtlData;
881 uLimit = (unsigned int)pEfd->cchEditLimit;
882 }
883 else
884 uLimit = 32; //PM's default
885 }
886 if (uLen >= uLimit)
887 {
888 uLimit = uLen + 0x8000; // 32Kb
889 if (uLimit > 0xffff)
890 {
891 uLimit = 0L;
892 }
893 if (m_bIsMLE)
894 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT, MPFROMLONG(uLimit), 0);
895 else
896 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT, MPFROMLONG(uLimit), 0);
897 }
898 } // end of wxTextCtrl::AdjustSpaceLimit
899
900 bool wxTextCtrl::AcceptsFocus() const
901 {
902 // we don't want focus if we can't be edited
903 return IsEditable() && wxControl::AcceptsFocus();
904 }
905
906 wxSize wxTextCtrl::DoGetBestSize() const
907 {
908 int cx, cy;
909 wxGetCharSize(GetHWND(), &cx, &cy, (wxFont*)&GetFont());
910
911 int wText = DEFAULT_ITEM_WIDTH;
912
913 int hText = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
914 if ( m_windowStyle & wxTE_MULTILINE )
915 {
916 hText *= wxMin(GetNumberOfLines(), 5);
917 }
918 //else: for single line control everything is ok
919
920 return wxSize(wText, hText);
921 }
922
923 // ----------------------------------------------------------------------------
924 // standard handlers for standard edit menu events
925 // ----------------------------------------------------------------------------
926
927 void wxTextCtrl::OnCut(wxCommandEvent& event)
928 {
929 Cut();
930 }
931
932 void wxTextCtrl::OnCopy(wxCommandEvent& event)
933 {
934 Copy();
935 }
936
937 void wxTextCtrl::OnPaste(wxCommandEvent& event)
938 {
939 Paste();
940 }
941
942 void wxTextCtrl::OnUndo(wxCommandEvent& event)
943 {
944 Undo();
945 }
946
947 void wxTextCtrl::OnRedo(wxCommandEvent& event)
948 {
949 Redo();
950 }
951
952 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
953 {
954 event.Enable( CanCut() );
955 }
956
957 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
958 {
959 event.Enable( CanCopy() );
960 }
961
962 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
963 {
964 event.Enable( CanPaste() );
965 }
966
967 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
968 {
969 event.Enable( CanUndo() );
970 }
971
972 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
973 {
974 event.Enable( CanRedo() );
975 }
976