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>
46 #if defined(__EMX__) && !defined(MLE_INDEX)
52 // ----------------------------------------------------------------------------
53 // event tables and other macros
54 // ----------------------------------------------------------------------------
56 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
58 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
59 EVT_CHAR(wxTextCtrl::OnChar
)
60 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
62 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
63 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
64 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
65 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
66 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
68 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
69 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
70 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
71 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
72 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 wxTextCtrl::wxTextCtrl()
88 bool wxTextCtrl::Create(
91 , const wxString
& rsValue
96 , const wxValidator
& rValidator
98 , const wxString
& rsName
102 // Base initialization
104 if ( !CreateBase( pParent
116 wxPoint vPos
= rPos
; // The OS/2 position
120 pParent
->AddChild(this);
122 // OS2 uses normal coordinates, no bassackwards Windows ones
124 // vPos.y = pParent->GetSize().y - (vPos.y + rSize.y);
130 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
131 // vPos.y = vRect.yTop - (vPos.y + rSize.y);
134 m_windowStyle
= lStyle
;
136 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
139 // Single and multiline edit fields are two different controls in PM
141 if ( m_windowStyle
& wxTE_MULTILINE
)
144 m_windowStyle
|= wxTE_PROCESS_ENTER
;
146 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
147 lSstyle
|= MLS_VSCROLL
;
148 if (m_windowStyle
& wxHSCROLL
)
149 lSstyle
|= MLS_HSCROLL
;
150 if (m_windowStyle
& wxTE_READONLY
)
151 lSstyle
|= MLS_READONLY
;
157 if (m_windowStyle
& wxHSCROLL
)
158 lSstyle
|= ES_AUTOSCROLL
;
159 if (m_windowStyle
& wxTE_READONLY
)
160 lSstyle
|= ES_READONLY
;
161 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
162 lSstyle
|= ES_UNREADABLE
;
166 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
167 ,WC_MLE
// Window class
168 ,(PSZ
)rsValue
.c_str() // Initial Text
169 ,(ULONG
)lSstyle
// Style flags
170 ,(LONG
)0 // X pos of origin
171 ,(LONG
)0 // Y pos of origin
172 ,(LONG
)0 // field width
173 ,(LONG
)0 // field height
174 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
175 ,HWND_TOP
// initial z position
176 ,(ULONG
)vId
// Window identifier
177 ,NULL
// no control data
178 ,NULL
// no Presentation parameters
183 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
184 ,WC_ENTRYFIELD
// Window class
185 ,(PSZ
)rsValue
.c_str() // Initial Text
186 ,(ULONG
)lSstyle
// Style flags
187 ,(LONG
)0 // X pos of origin
188 ,(LONG
)0 // Y pos of origin
189 ,(LONG
)0 // field width
190 ,(LONG
)0 // field height
191 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
192 ,HWND_TOP
// initial z position
193 ,(ULONG
)vId
// Window identifier
194 ,NULL
// no control data
195 ,NULL
// no Presentation parameters
204 SubclassWin(GetHWND());
207 // Set font, position, size and initial value
209 wxFont
& vFontParent
= pParent
->GetFont();
211 if (vFontParent
.Ok())
213 SetFont(vFontParent
);
217 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
219 if (!rsValue
.IsEmpty())
230 } // end of wxTextCtrl::Create
233 // Make sure the window style (etc.) reflects the HWND style (roughly)
235 void wxTextCtrl::AdoptAttributesFromHWND()
237 HWND hWnd
= GetHwnd();
238 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
240 wxWindow::AdoptAttributesFromHWND();
244 m_windowStyle
|= wxTE_MULTILINE
;
245 if (lStyle
& MLS_READONLY
)
246 m_windowStyle
|= wxTE_READONLY
;
250 if (lStyle
& ES_UNREADABLE
)
251 m_windowStyle
|= wxTE_PASSWORD
;
252 if (lStyle
& ES_READONLY
)
253 m_windowStyle
|= wxTE_READONLY
;
255 } // end of wxTextCtrl::AdoptAttributesFromHWND
257 void wxTextCtrl::SetupColours()
259 wxColour vBkgndColour
;
261 vBkgndColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
);
262 SetBackgroundColour(vBkgndColour
);
263 SetForegroundColour(GetParent()->GetForegroundColour());
264 } // end of wxTextCtrl::SetupColours
266 // ----------------------------------------------------------------------------
267 // set/get the controls text
268 // ----------------------------------------------------------------------------
270 wxString
wxTextCtrl::GetValue() const
272 wxString sStr
= wxGetWindowText(GetHWND());
273 char* zStr
= (char*)sStr
.c_str();
275 for ( ; *zStr
; zStr
++ )
278 // this will replace \r\n with just \n
287 } // end of wxTextCtrl::GetValue
289 void wxTextCtrl::SetValue(
290 const wxString
& rsValue
294 // If the text is long enough, it's faster to just set it instead of first
295 // comparing it with the old one (chances are that it will be different
296 // anyhow, this comparison is there to avoid flicker for small single-line
297 // edit controls mostly)
299 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
301 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
304 } // end of wxTextCtrl::SetValue
306 void wxTextCtrl::WriteText(
307 const wxString
& rsValue
310 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
312 } // end of wxTextCtrl::WriteText
314 void wxTextCtrl::AppendText(
315 const wxString
& rsText
318 SetInsertionPointEnd();
320 } // end of wxTextCtrl::AppendText
322 void wxTextCtrl::Clear()
324 ::WinSetWindowText(GetHwnd(), "");
325 } // end of wxTextCtrl::Clear
327 // ----------------------------------------------------------------------------
328 // Clipboard operations
329 // ----------------------------------------------------------------------------
331 void wxTextCtrl::Copy()
335 HWND hWnd
= GetHwnd();
337 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
339 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
341 } // end of wxTextCtrl::Copy
343 void wxTextCtrl::Cut()
347 HWND hWnd
= GetHwnd();
350 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
352 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
354 } // end of wxTextCtrl::Cut
356 void wxTextCtrl::Paste()
360 HWND hWnd
= GetHwnd();
362 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
364 } // end of wxTextCtrl::Paste
366 bool wxTextCtrl::CanCopy() const
369 // Can copy if there's a selection
374 GetSelection(&lFrom
, &lTo
);
375 return (lFrom
!= lTo
);
376 } // end of wxTextCtrl::CanCopy
378 bool wxTextCtrl::CanCut() const
381 // Can cut if there's a selection
386 GetSelection(&lFrom
, &lTo
);
387 return (lFrom
!= lTo
);
388 } // end of wxTextCtrl::CanCut
390 bool wxTextCtrl::CanPaste() const
392 bool bIsTextAvailable
= FALSE
;
398 // Check for straight text on clipboard
400 if (::WinOpenClipbrd(vHabmain
))
402 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
403 ::WinCloseClipbrd(vHabmain
);
405 return bIsTextAvailable
;
406 } // end of wxTextCtrl::CanPaste
408 // ----------------------------------------------------------------------------
410 // ----------------------------------------------------------------------------
412 void wxTextCtrl::SetEditable(
416 HWND hWnd
= GetHwnd();
419 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
421 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
422 } // end of wxTextCtrl::SetEditable
424 void wxTextCtrl::SetInsertionPoint(
428 HWND hWnd
= GetHwnd();
431 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
433 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
434 } // end of wxTextCtrl::SetInsertionPoint
436 void wxTextCtrl::SetInsertionPointEnd()
438 long lPos
= GetLastPosition();
440 SetInsertionPoint(lPos
);
441 } // end of wxTextCtrl::SetInsertionPointEnd
443 long wxTextCtrl::GetInsertionPoint() const
448 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
451 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
452 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
454 return (dwPos
& 0xFFFF);
455 } // end of wxTextCtrl::GetInsertionPoint
457 long wxTextCtrl::GetLastPosition() const
459 HWND hWnd
= GetHwnd();
468 // This just gets the total text length. The last will be this value
470 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
477 vParams
.fsStatus
= WPM_CCHTEXT
;
478 if (::WinSendMsg( GetHwnd()
479 ,WM_QUERYWINDOWPARAMS
484 lLineLength
= (long)vParams
.cchText
;
489 return(lCharIndex
+ lLineLength
);
490 } // end of wxTextCtrl::GetLastPosition
492 // If the return values from and to are the same, there is no
494 void wxTextCtrl::GetSelection(
502 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
505 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
507 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
508 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
509 } // end of wxTextCtrl::GetSelection
511 bool wxTextCtrl::IsEditable() const
514 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
516 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
517 } // end of wxTextCtrl::IsEditable
519 // ----------------------------------------------------------------------------
521 // ----------------------------------------------------------------------------
523 void wxTextCtrl::Replace(
526 , const wxString
& rsValue
530 HWND hWnd
= GetHwnd();
531 long lFromChar
= lFrom
;
535 // Set selection and remove it
539 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
540 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
544 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
545 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
549 // Now replace with 'value', by pasting.
551 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
553 // Paste into edit control
555 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
557 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
559 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
561 } // end of wxTextCtrl::Replace
563 void wxTextCtrl::Remove(
568 HWND hWnd
= GetHwnd();
569 long lFromChar
= lFrom
;
574 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
575 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
579 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
580 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
582 } // end of wxTextCtrl::Remove
584 void wxTextCtrl::SetSelection(
589 HWND hWnd
= GetHwnd();
590 long lFromChar
= lFrom
;
594 // If from and to are both -1, it means (in wxWindows) that all text should
595 // be selected. Translate into Windows convention
597 if ((lFrom
== -1L) && (lTo
== -1L))
603 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
605 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
606 } // end of wxTextCtrl::SetSelection
608 bool wxTextCtrl::LoadFile(
609 const wxString
& rsFile
612 if ( wxTextCtrlBase::LoadFile(rsFile
) )
615 // Update the size limit if needed
621 } // end of wxTextCtrl::LoadFile
623 bool wxTextCtrl::IsModified() const
628 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
630 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
632 } // end of wxTextCtrl::IsModified
635 // Makes 'unmodified'
637 void wxTextCtrl::DiscardEdits()
640 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
643 // EM controls do not have a SETCHANGED but issuing a query should reset it
645 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
646 } // end of wxTextCtrl::DiscardEdits
648 int wxTextCtrl::GetNumberOfLines() const
653 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
657 } // end of wxTextCtrl::GetNumberOfLines
659 long wxTextCtrl::XYToPosition(
664 HWND hWnd
= GetHwnd();
665 long lCharIndex
= 0L;
670 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
671 lCharIndex
= ((lLen
* lY
) + lX
);
676 } // end of wxTextCtrl::XYToPosition
678 bool wxTextCtrl::PositionToXY(
684 HWND hWnd
= GetHwnd();
689 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
700 // This gets the char index for the _beginning_ of this line
706 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
707 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
713 vParams
.fsStatus
= WPM_CCHTEXT
;
714 if (::WinSendMsg( hWnd
715 ,WM_QUERYWINDOWPARAMS
720 lCharIndex
= vParams
.cchText
;
726 if (lCharIndex
== -1)
732 // The X position must therefore be the difference between pos and charIndex
735 *plX
= lPos
- lCharIndex
;
740 } // end of wxTextCtrl::PositionToXY
742 void wxTextCtrl::ShowPosition(
746 HWND hWnd
= GetHwnd();
747 long lCurrentLineLineNo
= 0L;
749 // To scroll to a position, we pass the number of lines and characters
750 // to scroll *by*. This means that we need to:
751 // (1) Find the line position of the current line.
752 // (2) Find the line position of pos.
753 // (3) Scroll by (pos - current).
754 // For now, ignore the horizontal scrolling.
757 // Is this where scrolling is relative to - the line containing the caret?
758 // Or is the first visible line??? Try first visible line.
763 // In PM this is the actual char position
765 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
768 // This will cause a scroll to the selected position
770 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
772 } // end of wxTextCtrl::ShowPosition
774 int wxTextCtrl::GetLineLength(
781 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
786 vParams
.fsStatus
= WPM_CCHTEXT
;
787 if (::WinSendMsg( GetHwnd()
788 ,WM_QUERYWINDOWPARAMS
793 lLen
= vParams
.cchText
;
799 } // end ofwxTextCtrl::GetLineLength
801 wxString
wxTextCtrl::GetLineText(
805 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
810 // There must be at least enough place for the length WORD in the
813 lLen
+= sizeof(WORD
);
814 zBuf
= new char[lLen
];
821 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
822 lIndex
= lLen
* lLineNo
;
824 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
825 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
826 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
827 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
828 zBuf
[lCopied
] = '\0';
834 vParams
.fsStatus
= WPM_CCHTEXT
;
835 if (::WinSendMsg( GetHwnd()
836 ,WM_QUERYWINDOWPARAMS
840 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
841 zBuf
[vParams
.cchText
] = '\0';
846 } // end of wxTextCtrl::GetLineText
848 // ----------------------------------------------------------------------------
850 // ----------------------------------------------------------------------------
852 void wxTextCtrl::Undo()
857 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
858 // Simple entryfields cannot be undone
860 } // end of wxTextCtrl::Undo
862 void wxTextCtrl::Redo()
867 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
868 // Simple entryfields cannot be undone
870 } // end of wxTextCtrl::Redo
872 bool wxTextCtrl::CanUndo() const
877 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
879 bOk
= FALSE
; // can't undo regular edit fields in PM
881 } // end of wxTextCtrl::CanUndo
883 bool wxTextCtrl::CanRedo() const
888 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
890 bOk
= FALSE
; // can't undo regular edit fields in PM
892 } // end of wxTextCtrl::CanRedo
894 // ----------------------------------------------------------------------------
895 // implemenation details
896 // ----------------------------------------------------------------------------
898 void wxTextCtrl::Command(
899 wxCommandEvent
& rEvent
902 SetValue(rEvent
.GetString());
903 ProcessCommand (rEvent
);
904 } // end of wxTextCtrl::Command
906 void wxTextCtrl::OnDropFiles(
907 wxDropFilesEvent
& rEvent
910 // By default, load the first file into the text window.
911 if (rEvent
.GetNumberOfFiles() > 0)
913 LoadFile(rEvent
.GetFiles()[0]);
915 } // end of wxTextCtrl::OnDropFiles
917 WXHBRUSH
wxTextCtrl::OnCtlColor(
926 HPS hPS
= (HPS
)hWxDC
;
927 wxBrush
* pBrush
= NULL
;
928 wxColour vColBack
= GetBackgroundColour();
929 wxColour vColFore
= GetForegroundColour();
930 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
936 HBRUSH hBrush
= NULLHANDLE
;
940 if (GetParent()->GetTransparentBackground())
941 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
943 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
944 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
945 vColBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
946 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
947 ::GpiSetColor(hPS
, vColFore
.GetPixel());
948 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
949 } // end of wxTextCtrl::OnCtlColor
951 void wxTextCtrl::OnChar(
955 switch (rEvent
.KeyCode())
958 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
960 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
962 vEvent
.SetEventObject(this);
963 if ( GetEventHandler()->ProcessEvent(vEvent
))
966 //else: multiline controls need Enter for themselves
971 // always produce navigation event - even if we process TAB
972 // ourselves the fact that we got here means that the user code
973 // decided to skip processing of this TAB - probably to let it
974 // do its default job.
976 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
977 // handled by Windows
979 wxNavigationKeyEvent vEventNav
;
981 vEventNav
.SetDirection(!rEvent
.ShiftDown());
982 vEventNav
.SetWindowChange(FALSE
);
983 vEventNav
.SetEventObject(this);
985 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
991 } // end of wxTextCtrl::OnChar
993 bool wxTextCtrl::OS2Command(
995 , WXWORD
WXUNUSED(vId
)
1003 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1008 vEvent
.SetEventObject(this);
1009 GetEventHandler()->ProcessEvent(vEvent
);
1015 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1019 InitCommandEvent(vEvent
);
1020 vEvent
.SetString((char*)GetValue().c_str());
1021 ProcessCommand(vEvent
);
1027 // The text size limit has been hit - increase it
1033 case EN_INSERTMODETOGGLE
:
1044 } // end of wxTextCtrl::OS2Command
1046 void wxTextCtrl::AdjustSpaceLimit()
1048 unsigned int uLen
= 0;
1049 unsigned int uLimit
= 0;
1051 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1054 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1065 vParams
.fsStatus
= WPM_CBCTLDATA
;
1066 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1068 if (::WinSendMsg( GetHwnd()
1069 ,WM_QUERYWINDOWPARAMS
1074 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1075 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1078 uLimit
= 32; //PM's default
1082 uLimit
= uLen
+ 0x8000; // 32Kb
1083 if (uLimit
> 0xffff)
1088 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1090 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1092 } // end of wxTextCtrl::AdjustSpaceLimit
1094 bool wxTextCtrl::AcceptsFocus() const
1097 // We don't want focus if we can't be edited
1099 return IsEditable() && wxControl::AcceptsFocus();
1100 } // end of wxTextCtrl::Command
1102 wxSize
wxTextCtrl::DoGetBestSize() const
1107 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1109 int wText
= DEFAULT_ITEM_WIDTH
;
1110 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
);
1112 if (m_windowStyle
& wxTE_MULTILINE
)
1114 hText
*= wxMin(GetNumberOfLines(), 5);
1116 //else: for single line control everything is ok
1117 return wxSize(wText
, hText
);
1118 } // end of wxTextCtrl::DoGetBestSize
1120 // ----------------------------------------------------------------------------
1121 // standard handlers for standard edit menu events
1122 // ----------------------------------------------------------------------------
1124 void wxTextCtrl::OnCut(
1125 wxCommandEvent
& rEvent
1129 } // end of wxTextCtrl::OnCut
1131 void wxTextCtrl::OnCopy(
1132 wxCommandEvent
& rEvent
1136 } // end of wxTextCtrl::OnCopy
1138 void wxTextCtrl::OnPaste(
1139 wxCommandEvent
& rEvent
1143 } // end of wxTextCtrl::OnPaste
1145 void wxTextCtrl::OnUndo(
1146 wxCommandEvent
& rEvent
1150 } // end of wxTextCtrl::OnUndo
1152 void wxTextCtrl::OnRedo(
1153 wxCommandEvent
& rEvent
1157 } // end of wxTextCtrl::OnRedo
1159 void wxTextCtrl::OnUpdateCut(
1160 wxUpdateUIEvent
& rEvent
1163 rEvent
.Enable(CanCut());
1164 } // end of wxTextCtrl::OnUpdateCut
1166 void wxTextCtrl::OnUpdateCopy(
1167 wxUpdateUIEvent
& rEvent
1170 rEvent
.Enable(CanCopy());
1171 } // end of wxTextCtrl::OnUpdateCopy
1173 void wxTextCtrl::OnUpdatePaste(
1174 wxUpdateUIEvent
& rEvent
1177 rEvent
.Enable(CanPaste());
1178 } // end of wxTextCtrl::OnUpdatePaste
1180 void wxTextCtrl::OnUpdateUndo(
1181 wxUpdateUIEvent
& rEvent
1184 rEvent
.Enable(CanUndo());
1185 } // end of wxTextCtrl::OnUpdateUndo
1187 void wxTextCtrl::OnUpdateRedo(
1188 wxUpdateUIEvent
& rEvent
1191 rEvent
.Enable(CanRedo());
1192 } // end of wxTextCtrl::OnUpdateRedo
1194 bool wxTextCtrl::SetBackgroundColour(
1195 const wxColour
& rColour
1199 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1201 } // end of wxTextCtrl::SetBackgroundColour
1203 bool wxTextCtrl::SetForegroundColour(
1204 const wxColour
& rColour
1208 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1210 } // end of wxTextCtrl::SetForegroundColour