1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ----------------------------------------------------------------------------
14 // ----------------------------------------------------------------------------
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #include "wx/textctrl.h"
21 #include "wx/settings.h"
29 #include "wx/clipbrd.h"
32 #include "wx/textfile.h"
34 #include "wx/os2/private.h"
38 #include <sys/types.h>
47 // ----------------------------------------------------------------------------
48 // event tables and other macros
49 // ----------------------------------------------------------------------------
51 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
53 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
54 EVT_CHAR(wxTextCtrl::OnChar
)
55 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
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
)
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
)
71 // ============================================================================
73 // ============================================================================
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
79 wxTextCtrl::wxTextCtrl()
83 bool wxTextCtrl::Create(
86 , const wxString
& rsValue
91 , const wxValidator
& rValidator
93 , const wxString
& rsName
97 // Base initialization
99 if ( !CreateBase( pParent
112 pParent
->AddChild(this);
114 m_windowStyle
= lStyle
;
116 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
119 // Single and multiline edit fields are two different controls in PM
121 if ( m_windowStyle
& wxTE_MULTILINE
)
124 m_windowStyle
|= wxTE_PROCESS_ENTER
;
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
;
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
;
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
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
184 SubclassWin(GetHWND());
187 // Set font, position, size and initial value
189 wxFont
& vFontParent
= pParent
->GetFont();
191 if (vFontParent
.Ok())
193 SetFont(vFontParent
);
197 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
199 if (!rsValue
.IsEmpty())
210 } // end of wxTextCtrl::Create
213 // Make sure the window style (etc.) reflects the HWND style (roughly)
215 void wxTextCtrl::AdoptAttributesFromHWND()
217 HWND hWnd
= GetHwnd();
218 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
220 wxWindow::AdoptAttributesFromHWND();
224 m_windowStyle
|= wxTE_MULTILINE
;
225 if (lStyle
& MLS_READONLY
)
226 m_windowStyle
|= wxTE_READONLY
;
230 if (lStyle
& ES_UNREADABLE
)
231 m_windowStyle
|= wxTE_PASSWORD
;
232 if (lStyle
& ES_READONLY
)
233 m_windowStyle
|= wxTE_READONLY
;
235 } // end of wxTextCtrl::AdoptAttributesFromHWND
237 void wxTextCtrl::SetupColours()
239 wxColour vBkgndColour
;
241 vBkgndColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
);
242 SetBackgroundColour(vBkgndColour
);
243 SetForegroundColour(GetParent()->GetForegroundColour());
244 } // end of wxTextCtrl::SetupColours
246 // ----------------------------------------------------------------------------
247 // set/get the controls text
248 // ----------------------------------------------------------------------------
250 wxString
wxTextCtrl::GetValue() const
252 wxString sStr
= wxGetWindowText(GetHWND());
253 char* zStr
= (char*)sStr
.c_str();
255 for ( ; *zStr
; zStr
++ )
258 // this will replace \r\n with just \n
267 } // end of wxTextCtrl::GetValue
269 void wxTextCtrl::SetValue(
270 const wxString
& rsValue
274 // If the text is long enough, it's faster to just set it instead of first
275 // comparing it with the old one (chances are that it will be different
276 // anyhow, this comparison is there to avoid flicker for small single-line
277 // edit controls mostly)
279 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
281 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
284 } // end of wxTextCtrl::SetValue
286 void wxTextCtrl::WriteText(
287 const wxString
& rsValue
290 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
292 } // end of wxTextCtrl::WriteText
294 void wxTextCtrl::AppendText(
295 const wxString
& rsText
298 SetInsertionPointEnd();
300 } // end of wxTextCtrl::AppendText
302 void wxTextCtrl::Clear()
304 ::WinSetWindowText(GetHwnd(), "");
305 } // end of wxTextCtrl::Clear
307 // ----------------------------------------------------------------------------
308 // Clipboard operations
309 // ----------------------------------------------------------------------------
311 void wxTextCtrl::Copy()
315 HWND hWnd
= GetHwnd();
317 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
319 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
321 } // end of wxTextCtrl::Copy
323 void wxTextCtrl::Cut()
327 HWND hWnd
= GetHwnd();
330 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
332 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
334 } // end of wxTextCtrl::Cut
336 void wxTextCtrl::Paste()
340 HWND hWnd
= GetHwnd();
342 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
344 } // end of wxTextCtrl::Paste
346 bool wxTextCtrl::CanCopy() const
349 // Can copy if there's a selection
354 GetSelection(&lFrom
, &lTo
);
355 return (lFrom
!= lTo
);
356 } // end of wxTextCtrl::CanCopy
358 bool wxTextCtrl::CanCut() const
361 // Can cut if there's a selection
366 GetSelection(&lFrom
, &lTo
);
367 return (lFrom
!= lTo
);
368 } // end of wxTextCtrl::CanCut
370 bool wxTextCtrl::CanPaste() const
372 bool bIsTextAvailable
= FALSE
;
378 // Check for straight text on clipboard
380 if (::WinOpenClipbrd(vHabmain
))
382 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
383 ::WinCloseClipbrd(vHabmain
);
385 return bIsTextAvailable
;
386 } // end of wxTextCtrl::CanPaste
388 // ----------------------------------------------------------------------------
390 // ----------------------------------------------------------------------------
392 void wxTextCtrl::SetEditable(
396 HWND hWnd
= GetHwnd();
399 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
401 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
402 } // end of wxTextCtrl::SetEditable
404 void wxTextCtrl::SetInsertionPoint(
408 HWND hWnd
= GetHwnd();
411 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
413 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
414 } // end of wxTextCtrl::SetInsertionPoint
416 void wxTextCtrl::SetInsertionPointEnd()
418 long lPos
= GetLastPosition();
420 SetInsertionPoint(lPos
);
421 } // end of wxTextCtrl::SetInsertionPointEnd
423 long wxTextCtrl::GetInsertionPoint() const
428 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
431 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
432 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
434 return (dwPos
& 0xFFFF);
435 } // end of wxTextCtrl::GetInsertionPoint
437 long wxTextCtrl::GetLastPosition() const
439 HWND hWnd
= GetHwnd();
448 // This just gets the total text length. The last will be this value
450 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
457 vParams
.fsStatus
= WPM_CCHTEXT
;
458 if (::WinSendMsg( GetHwnd()
459 ,WM_QUERYWINDOWPARAMS
464 lLineLength
= (long)vParams
.cchText
;
469 return(lCharIndex
+ lLineLength
);
470 } // end of wxTextCtrl::GetLastPosition
472 // If the return values from and to are the same, there is no
474 void wxTextCtrl::GetSelection(
482 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
485 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
487 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
488 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
489 } // end of wxTextCtrl::GetSelection
491 bool wxTextCtrl::IsEditable() const
494 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
496 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
497 } // end of wxTextCtrl::IsEditable
499 // ----------------------------------------------------------------------------
501 // ----------------------------------------------------------------------------
503 void wxTextCtrl::Replace(
506 , const wxString
& rsValue
510 HWND hWnd
= GetHwnd();
511 long lFromChar
= lFrom
;
515 // Set selection and remove it
519 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
520 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
524 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
525 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
529 // Now replace with 'value', by pasting.
531 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
533 // Paste into edit control
535 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
537 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
539 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
541 } // end of wxTextCtrl::Replace
543 void wxTextCtrl::Remove(
548 HWND hWnd
= GetHwnd();
549 long lFromChar
= lFrom
;
554 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
555 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
559 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
560 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
562 } // end of wxTextCtrl::Remove
564 void wxTextCtrl::SetSelection(
569 HWND hWnd
= GetHwnd();
570 long lFromChar
= lFrom
;
574 // If from and to are both -1, it means (in wxWindows) that all text should
575 // be selected. Translate into Windows convention
577 if ((lFrom
== -1L) && (lTo
== -1L))
583 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
585 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
586 } // end of wxTextCtrl::SetSelection
588 bool wxTextCtrl::LoadFile(
589 const wxString
& rsFile
592 if ( wxTextCtrlBase::LoadFile(rsFile
) )
595 // Update the size limit if needed
601 } // end of wxTextCtrl::LoadFile
603 bool wxTextCtrl::IsModified() const
608 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
610 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
612 } // end of wxTextCtrl::IsModified
615 // Makes 'unmodified'
617 void wxTextCtrl::DiscardEdits()
620 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
623 // EM controls do not have a SETCHANGED but issuing a query should reset it
625 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
626 } // end of wxTextCtrl::DiscardEdits
628 int wxTextCtrl::GetNumberOfLines() const
633 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
637 } // end of wxTextCtrl::GetNumberOfLines
639 long wxTextCtrl::XYToPosition(
644 HWND hWnd
= GetHwnd();
645 long lCharIndex
= 0L;
650 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
651 lCharIndex
= ((lLen
* lY
) + lX
);
656 } // end of wxTextCtrl::XYToPosition
658 bool wxTextCtrl::PositionToXY(
664 HWND hWnd
= GetHwnd();
669 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
680 // This gets the char index for the _beginning_ of this line
686 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
687 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
693 vParams
.fsStatus
= WPM_CCHTEXT
;
694 if (::WinSendMsg( hWnd
695 ,WM_QUERYWINDOWPARAMS
700 lCharIndex
= vParams
.cchText
;
706 if (lCharIndex
== -1)
712 // The X position must therefore be the difference between pos and charIndex
715 *plX
= lPos
- lCharIndex
;
720 } // end of wxTextCtrl::PositionToXY
722 void wxTextCtrl::ShowPosition(
726 HWND hWnd
= GetHwnd();
727 long lCurrentLineLineNo
= 0L;
729 // To scroll to a position, we pass the number of lines and characters
730 // to scroll *by*. This means that we need to:
731 // (1) Find the line position of the current line.
732 // (2) Find the line position of pos.
733 // (3) Scroll by (pos - current).
734 // For now, ignore the horizontal scrolling.
737 // Is this where scrolling is relative to - the line containing the caret?
738 // Or is the first visible line??? Try first visible line.
743 // In PM this is the actual char position
745 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
748 // This will cause a scroll to the selected position
750 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
752 } // end of wxTextCtrl::ShowPosition
754 int wxTextCtrl::GetLineLength(
761 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
766 vParams
.fsStatus
= WPM_CCHTEXT
;
767 if (::WinSendMsg( GetHwnd()
768 ,WM_QUERYWINDOWPARAMS
773 lLen
= vParams
.cchText
;
779 } // end ofwxTextCtrl::GetLineLength
781 wxString
wxTextCtrl::GetLineText(
785 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
790 // There must be at least enough place for the length WORD in the
793 lLen
+= sizeof(WORD
);
794 zBuf
= new char[lLen
];
801 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
802 lIndex
= lLen
* lLineNo
;
804 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
805 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
806 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
807 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
808 zBuf
[lCopied
] = '\0';
814 vParams
.fsStatus
= WPM_CCHTEXT
;
815 if (::WinSendMsg( GetHwnd()
816 ,WM_QUERYWINDOWPARAMS
820 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
821 zBuf
[vParams
.cchText
] = '\0';
826 } // end of wxTextCtrl::GetLineText
828 // ----------------------------------------------------------------------------
830 // ----------------------------------------------------------------------------
832 void wxTextCtrl::Undo()
837 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
838 // Simple entryfields cannot be undone
840 } // end of wxTextCtrl::Undo
842 void wxTextCtrl::Redo()
847 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
848 // Simple entryfields cannot be undone
850 } // end of wxTextCtrl::Redo
852 bool wxTextCtrl::CanUndo() const
857 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
859 bOk
= FALSE
; // can't undo regular edit fields in PM
861 } // end of wxTextCtrl::CanUndo
863 bool wxTextCtrl::CanRedo() const
868 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
870 bOk
= FALSE
; // can't undo regular edit fields in PM
872 } // end of wxTextCtrl::CanRedo
874 // ----------------------------------------------------------------------------
875 // implemenation details
876 // ----------------------------------------------------------------------------
878 void wxTextCtrl::Command(
879 wxCommandEvent
& rEvent
882 SetValue(rEvent
.GetString());
883 ProcessCommand (rEvent
);
884 } // end of wxTextCtrl::Command
886 void wxTextCtrl::OnDropFiles(
887 wxDropFilesEvent
& rEvent
890 // By default, load the first file into the text window.
891 if (rEvent
.GetNumberOfFiles() > 0)
893 LoadFile(rEvent
.GetFiles()[0]);
895 } // end of wxTextCtrl::OnDropFiles
897 WXHBRUSH
wxTextCtrl::OnCtlColor(
906 HPS hPS
= (HPS
)hWxDC
;
907 wxBrush
* pBrush
= NULL
;
908 wxColour vColBack
= GetBackgroundColour();
909 wxColour vColFore
= GetForegroundColour();
910 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
916 HBRUSH hBrush
= NULLHANDLE
;
920 if (GetParent()->GetTransparentBackground())
921 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
923 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
924 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
925 vColBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
926 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
927 ::GpiSetColor(hPS
, vColFore
.GetPixel());
928 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
929 } // end of wxTextCtrl::OnCtlColor
931 void wxTextCtrl::OnChar(
935 switch (rEvent
.KeyCode())
938 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
940 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
942 vEvent
.SetEventObject(this);
943 if ( GetEventHandler()->ProcessEvent(vEvent
))
946 //else: multiline controls need Enter for themselves
951 // always produce navigation event - even if we process TAB
952 // ourselves the fact that we got here means that the user code
953 // decided to skip processing of this TAB - probably to let it
954 // do its default job.
956 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
957 // handled by Windows
959 wxNavigationKeyEvent vEventNav
;
961 vEventNav
.SetDirection(!rEvent
.ShiftDown());
962 vEventNav
.SetWindowChange(FALSE
);
963 vEventNav
.SetEventObject(this);
965 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
971 } // end of wxTextCtrl::OnChar
973 bool wxTextCtrl::OS2Command(
975 , WXWORD
WXUNUSED(vId
)
983 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
988 vEvent
.SetEventObject(this);
989 GetEventHandler()->ProcessEvent(vEvent
);
995 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
999 InitCommandEvent(vEvent
);
1000 vEvent
.SetString((char*)GetValue().c_str());
1001 ProcessCommand(vEvent
);
1007 // The text size limit has been hit - increase it
1013 case EN_INSERTMODETOGGLE
:
1024 } // end of wxTextCtrl::OS2Command
1026 void wxTextCtrl::AdjustSpaceLimit()
1028 unsigned int uLen
= 0;
1029 unsigned int uLimit
= 0;
1031 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1034 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1045 vParams
.fsStatus
= WPM_CBCTLDATA
;
1046 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1048 if (::WinSendMsg( GetHwnd()
1049 ,WM_QUERYWINDOWPARAMS
1054 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1055 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1058 uLimit
= 32; //PM's default
1062 uLimit
= uLen
+ 0x8000; // 32Kb
1063 if (uLimit
> 0xffff)
1068 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1070 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1072 } // end of wxTextCtrl::AdjustSpaceLimit
1074 bool wxTextCtrl::AcceptsFocus() const
1077 // We don't want focus if we can't be edited
1079 return IsEditable() && wxControl::AcceptsFocus();
1080 } // end of wxTextCtrl::Command
1082 wxSize
wxTextCtrl::DoGetBestSize() const
1087 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1089 int wText
= DEFAULT_ITEM_WIDTH
;
1090 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
);
1092 if (m_windowStyle
& wxTE_MULTILINE
)
1094 hText
*= wxMin(GetNumberOfLines(), 5);
1096 //else: for single line control everything is ok
1097 return wxSize(wText
, hText
);
1098 } // end of wxTextCtrl::DoGetBestSize
1100 // ----------------------------------------------------------------------------
1101 // standard handlers for standard edit menu events
1102 // ----------------------------------------------------------------------------
1104 void wxTextCtrl::OnCut(
1105 wxCommandEvent
& rEvent
1109 } // end of wxTextCtrl::OnCut
1111 void wxTextCtrl::OnCopy(
1112 wxCommandEvent
& rEvent
1116 } // end of wxTextCtrl::OnCopy
1118 void wxTextCtrl::OnPaste(
1119 wxCommandEvent
& rEvent
1123 } // end of wxTextCtrl::OnPaste
1125 void wxTextCtrl::OnUndo(
1126 wxCommandEvent
& rEvent
1130 } // end of wxTextCtrl::OnUndo
1132 void wxTextCtrl::OnRedo(
1133 wxCommandEvent
& rEvent
1137 } // end of wxTextCtrl::OnRedo
1139 void wxTextCtrl::OnUpdateCut(
1140 wxUpdateUIEvent
& rEvent
1143 rEvent
.Enable(CanCut());
1144 } // end of wxTextCtrl::OnUpdateCut
1146 void wxTextCtrl::OnUpdateCopy(
1147 wxUpdateUIEvent
& rEvent
1150 rEvent
.Enable(CanCopy());
1151 } // end of wxTextCtrl::OnUpdateCopy
1153 void wxTextCtrl::OnUpdatePaste(
1154 wxUpdateUIEvent
& rEvent
1157 rEvent
.Enable(CanPaste());
1158 } // end of wxTextCtrl::OnUpdatePaste
1160 void wxTextCtrl::OnUpdateUndo(
1161 wxUpdateUIEvent
& rEvent
1164 rEvent
.Enable(CanUndo());
1165 } // end of wxTextCtrl::OnUpdateUndo
1167 void wxTextCtrl::OnUpdateRedo(
1168 wxUpdateUIEvent
& rEvent
1171 rEvent
.Enable(CanRedo());
1172 } // end of wxTextCtrl::OnUpdateRedo
1174 bool wxTextCtrl::SetBackgroundColour(
1175 const wxColour
& rColour
1179 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1181 } // end of wxTextCtrl::SetBackgroundColour
1183 bool wxTextCtrl::SetForegroundColour(
1184 const wxColour
& rColour
1188 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1190 } // end of wxTextCtrl::SetForegroundColour