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
111 wxPoint vPos
= rPos
; // The OS/2 position
115 pParent
->AddChild(this);
117 // OS2 uses normal coordinates, no bassackwards Windows ones
119 vPos
.y
= pParent
->GetSize().y
- (vPos
.y
+ rSize
.y
);
125 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
126 vPos
.y
= vRect
.yTop
- (vPos
.y
+ rSize
.y
);
129 m_windowStyle
= lStyle
;
131 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
134 // Single and multiline edit fields are two different controls in PM
136 if ( m_windowStyle
& wxTE_MULTILINE
)
139 m_windowStyle
|= wxTE_PROCESS_ENTER
;
141 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
142 lSstyle
|= MLS_VSCROLL
;
143 if (m_windowStyle
& wxHSCROLL
)
144 lSstyle
|= MLS_HSCROLL
;
145 if (m_windowStyle
& wxTE_READONLY
)
146 lSstyle
|= MLS_READONLY
;
152 if (m_windowStyle
& wxHSCROLL
)
153 lSstyle
|= ES_AUTOSCROLL
;
154 if (m_windowStyle
& wxTE_READONLY
)
155 lSstyle
|= ES_READONLY
;
156 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
157 lSstyle
|= ES_UNREADABLE
;
161 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
162 ,WC_MLE
// Window class
163 ,(PSZ
)rsValue
.c_str() // Initial Text
164 ,(ULONG
)lSstyle
// Style flags
165 ,(LONG
)vPos
.x
// X pos of origin
166 ,(LONG
)vPos
.y
// Y pos of origin
167 ,(LONG
)rSize
.x
// field width
168 ,(LONG
)rSize
.y
// field height
169 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
170 ,HWND_TOP
// initial z position
171 ,(ULONG
)vId
// Window identifier
172 ,NULL
// no control data
173 ,NULL
// no Presentation parameters
178 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
179 ,WC_ENTRYFIELD
// Window class
180 ,(PSZ
)rsValue
.c_str() // Initial Text
181 ,(ULONG
)lSstyle
// Style flags
182 ,(LONG
)vPos
.x
// X pos of origin
183 ,(LONG
)vPos
.y
// Y pos of origin
184 ,(LONG
)rSize
.x
// field width
185 ,(LONG
)rSize
.y
// field height
186 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
187 ,HWND_TOP
// initial z position
188 ,(ULONG
)vId
// Window identifier
189 ,NULL
// no control data
190 ,NULL
// no Presentation parameters
199 SubclassWin(GetHWND());
202 // Set font, position, size and initial value
204 wxFont
& vFontParent
= pParent
->GetFont();
206 if (vFontParent
.Ok())
208 SetFont(vFontParent
);
212 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
214 if (!rsValue
.IsEmpty())
225 } // end of wxTextCtrl::Create
228 // Make sure the window style (etc.) reflects the HWND style (roughly)
230 void wxTextCtrl::AdoptAttributesFromHWND()
232 HWND hWnd
= GetHwnd();
233 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
235 wxWindow::AdoptAttributesFromHWND();
239 m_windowStyle
|= wxTE_MULTILINE
;
240 if (lStyle
& MLS_READONLY
)
241 m_windowStyle
|= wxTE_READONLY
;
245 if (lStyle
& ES_UNREADABLE
)
246 m_windowStyle
|= wxTE_PASSWORD
;
247 if (lStyle
& ES_READONLY
)
248 m_windowStyle
|= wxTE_READONLY
;
250 } // end of wxTextCtrl::AdoptAttributesFromHWND
252 void wxTextCtrl::SetupColours()
254 wxColour vBkgndColour
;
256 vBkgndColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
);
257 SetBackgroundColour(vBkgndColour
);
258 SetForegroundColour(GetParent()->GetForegroundColour());
259 } // end of wxTextCtrl::SetupColours
261 // ----------------------------------------------------------------------------
262 // set/get the controls text
263 // ----------------------------------------------------------------------------
265 wxString
wxTextCtrl::GetValue() const
267 wxString sStr
= wxGetWindowText(GetHWND());
268 char* zStr
= (char*)sStr
.c_str();
270 for ( ; *zStr
; zStr
++ )
273 // this will replace \r\n with just \n
282 } // end of wxTextCtrl::GetValue
284 void wxTextCtrl::SetValue(
285 const wxString
& rsValue
289 // If the text is long enough, it's faster to just set it instead of first
290 // comparing it with the old one (chances are that it will be different
291 // anyhow, this comparison is there to avoid flicker for small single-line
292 // edit controls mostly)
294 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
296 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
299 } // end of wxTextCtrl::SetValue
301 void wxTextCtrl::WriteText(
302 const wxString
& rsValue
305 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
307 } // end of wxTextCtrl::WriteText
309 void wxTextCtrl::AppendText(
310 const wxString
& rsText
313 SetInsertionPointEnd();
315 } // end of wxTextCtrl::AppendText
317 void wxTextCtrl::Clear()
319 ::WinSetWindowText(GetHwnd(), "");
320 } // end of wxTextCtrl::Clear
322 // ----------------------------------------------------------------------------
323 // Clipboard operations
324 // ----------------------------------------------------------------------------
326 void wxTextCtrl::Copy()
330 HWND hWnd
= GetHwnd();
332 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
334 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
336 } // end of wxTextCtrl::Copy
338 void wxTextCtrl::Cut()
342 HWND hWnd
= GetHwnd();
345 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
347 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
349 } // end of wxTextCtrl::Cut
351 void wxTextCtrl::Paste()
355 HWND hWnd
= GetHwnd();
357 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
359 } // end of wxTextCtrl::Paste
361 bool wxTextCtrl::CanCopy() const
364 // Can copy if there's a selection
369 GetSelection(&lFrom
, &lTo
);
370 return (lFrom
!= lTo
);
371 } // end of wxTextCtrl::CanCopy
373 bool wxTextCtrl::CanCut() const
376 // Can cut if there's a selection
381 GetSelection(&lFrom
, &lTo
);
382 return (lFrom
!= lTo
);
383 } // end of wxTextCtrl::CanCut
385 bool wxTextCtrl::CanPaste() const
387 bool bIsTextAvailable
= FALSE
;
393 // Check for straight text on clipboard
395 if (::WinOpenClipbrd(vHabmain
))
397 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
398 ::WinCloseClipbrd(vHabmain
);
400 return bIsTextAvailable
;
401 } // end of wxTextCtrl::CanPaste
403 // ----------------------------------------------------------------------------
405 // ----------------------------------------------------------------------------
407 void wxTextCtrl::SetEditable(
411 HWND hWnd
= GetHwnd();
414 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
416 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
417 } // end of wxTextCtrl::SetEditable
419 void wxTextCtrl::SetInsertionPoint(
423 HWND hWnd
= GetHwnd();
426 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
428 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
429 } // end of wxTextCtrl::SetInsertionPoint
431 void wxTextCtrl::SetInsertionPointEnd()
433 long lPos
= GetLastPosition();
435 SetInsertionPoint(lPos
);
436 } // end of wxTextCtrl::SetInsertionPointEnd
438 long wxTextCtrl::GetInsertionPoint() const
443 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
446 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
447 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
449 return (dwPos
& 0xFFFF);
450 } // end of wxTextCtrl::GetInsertionPoint
452 long wxTextCtrl::GetLastPosition() const
454 HWND hWnd
= GetHwnd();
463 // This just gets the total text length. The last will be this value
465 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
472 vParams
.fsStatus
= WPM_CCHTEXT
;
473 if (::WinSendMsg( GetHwnd()
474 ,WM_QUERYWINDOWPARAMS
479 lLineLength
= (long)vParams
.cchText
;
484 return(lCharIndex
+ lLineLength
);
485 } // end of wxTextCtrl::GetLastPosition
487 // If the return values from and to are the same, there is no
489 void wxTextCtrl::GetSelection(
497 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
500 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
502 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
503 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
504 } // end of wxTextCtrl::GetSelection
506 bool wxTextCtrl::IsEditable() const
509 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
511 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
512 } // end of wxTextCtrl::IsEditable
514 // ----------------------------------------------------------------------------
516 // ----------------------------------------------------------------------------
518 void wxTextCtrl::Replace(
521 , const wxString
& rsValue
525 HWND hWnd
= GetHwnd();
526 long lFromChar
= lFrom
;
530 // Set selection and remove it
534 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
535 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
539 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
540 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
544 // Now replace with 'value', by pasting.
546 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
548 // Paste into edit control
550 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
552 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
554 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
556 } // end of wxTextCtrl::Replace
558 void wxTextCtrl::Remove(
563 HWND hWnd
= GetHwnd();
564 long lFromChar
= lFrom
;
569 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
570 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
574 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
575 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
577 } // end of wxTextCtrl::Remove
579 void wxTextCtrl::SetSelection(
584 HWND hWnd
= GetHwnd();
585 long lFromChar
= lFrom
;
589 // If from and to are both -1, it means (in wxWindows) that all text should
590 // be selected. Translate into Windows convention
592 if ((lFrom
== -1L) && (lTo
== -1L))
598 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
600 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
601 } // end of wxTextCtrl::SetSelection
603 bool wxTextCtrl::LoadFile(
604 const wxString
& rsFile
607 if ( wxTextCtrlBase::LoadFile(rsFile
) )
610 // Update the size limit if needed
616 } // end of wxTextCtrl::LoadFile
618 bool wxTextCtrl::IsModified() const
623 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
625 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
627 } // end of wxTextCtrl::IsModified
630 // Makes 'unmodified'
632 void wxTextCtrl::DiscardEdits()
635 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
638 // EM controls do not have a SETCHANGED but issuing a query should reset it
640 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
641 } // end of wxTextCtrl::DiscardEdits
643 int wxTextCtrl::GetNumberOfLines() const
648 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
652 } // end of wxTextCtrl::GetNumberOfLines
654 long wxTextCtrl::XYToPosition(
659 HWND hWnd
= GetHwnd();
660 long lCharIndex
= 0L;
665 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
666 lCharIndex
= ((lLen
* lY
) + lX
);
671 } // end of wxTextCtrl::XYToPosition
673 bool wxTextCtrl::PositionToXY(
679 HWND hWnd
= GetHwnd();
684 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
695 // This gets the char index for the _beginning_ of this line
701 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
702 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
708 vParams
.fsStatus
= WPM_CCHTEXT
;
709 if (::WinSendMsg( hWnd
710 ,WM_QUERYWINDOWPARAMS
715 lCharIndex
= vParams
.cchText
;
721 if (lCharIndex
== -1)
727 // The X position must therefore be the difference between pos and charIndex
730 *plX
= lPos
- lCharIndex
;
735 } // end of wxTextCtrl::PositionToXY
737 void wxTextCtrl::ShowPosition(
741 HWND hWnd
= GetHwnd();
742 long lCurrentLineLineNo
= 0L;
744 // To scroll to a position, we pass the number of lines and characters
745 // to scroll *by*. This means that we need to:
746 // (1) Find the line position of the current line.
747 // (2) Find the line position of pos.
748 // (3) Scroll by (pos - current).
749 // For now, ignore the horizontal scrolling.
752 // Is this where scrolling is relative to - the line containing the caret?
753 // Or is the first visible line??? Try first visible line.
758 // In PM this is the actual char position
760 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
763 // This will cause a scroll to the selected position
765 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
767 } // end of wxTextCtrl::ShowPosition
769 int wxTextCtrl::GetLineLength(
776 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
781 vParams
.fsStatus
= WPM_CCHTEXT
;
782 if (::WinSendMsg( GetHwnd()
783 ,WM_QUERYWINDOWPARAMS
788 lLen
= vParams
.cchText
;
794 } // end ofwxTextCtrl::GetLineLength
796 wxString
wxTextCtrl::GetLineText(
800 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
805 // There must be at least enough place for the length WORD in the
808 lLen
+= sizeof(WORD
);
809 zBuf
= new char[lLen
];
816 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
817 lIndex
= lLen
* lLineNo
;
819 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
820 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
821 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
822 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
823 zBuf
[lCopied
] = '\0';
829 vParams
.fsStatus
= WPM_CCHTEXT
;
830 if (::WinSendMsg( GetHwnd()
831 ,WM_QUERYWINDOWPARAMS
835 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
836 zBuf
[vParams
.cchText
] = '\0';
841 } // end of wxTextCtrl::GetLineText
843 // ----------------------------------------------------------------------------
845 // ----------------------------------------------------------------------------
847 void wxTextCtrl::Undo()
852 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
853 // Simple entryfields cannot be undone
855 } // end of wxTextCtrl::Undo
857 void wxTextCtrl::Redo()
862 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
863 // Simple entryfields cannot be undone
865 } // end of wxTextCtrl::Redo
867 bool wxTextCtrl::CanUndo() const
872 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
874 bOk
= FALSE
; // can't undo regular edit fields in PM
876 } // end of wxTextCtrl::CanUndo
878 bool wxTextCtrl::CanRedo() const
883 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
885 bOk
= FALSE
; // can't undo regular edit fields in PM
887 } // end of wxTextCtrl::CanRedo
889 // ----------------------------------------------------------------------------
890 // implemenation details
891 // ----------------------------------------------------------------------------
893 void wxTextCtrl::Command(
894 wxCommandEvent
& rEvent
897 SetValue(rEvent
.GetString());
898 ProcessCommand (rEvent
);
899 } // end of wxTextCtrl::Command
901 void wxTextCtrl::OnDropFiles(
902 wxDropFilesEvent
& rEvent
905 // By default, load the first file into the text window.
906 if (rEvent
.GetNumberOfFiles() > 0)
908 LoadFile(rEvent
.GetFiles()[0]);
910 } // end of wxTextCtrl::OnDropFiles
912 WXHBRUSH
wxTextCtrl::OnCtlColor(
921 HPS hPS
= (HPS
)hWxDC
;
922 wxBrush
* pBrush
= NULL
;
923 wxColour vColBack
= GetBackgroundColour();
924 wxColour vColFore
= GetForegroundColour();
925 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
931 HBRUSH hBrush
= NULLHANDLE
;
935 if (GetParent()->GetTransparentBackground())
936 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
938 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
939 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
940 vColBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
941 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
942 ::GpiSetColor(hPS
, vColFore
.GetPixel());
943 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
944 } // end of wxTextCtrl::OnCtlColor
946 void wxTextCtrl::OnChar(
950 switch (rEvent
.KeyCode())
953 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
955 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
957 vEvent
.SetEventObject(this);
958 if ( GetEventHandler()->ProcessEvent(vEvent
))
961 //else: multiline controls need Enter for themselves
966 // always produce navigation event - even if we process TAB
967 // ourselves the fact that we got here means that the user code
968 // decided to skip processing of this TAB - probably to let it
969 // do its default job.
971 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
972 // handled by Windows
974 wxNavigationKeyEvent vEventNav
;
976 vEventNav
.SetDirection(!rEvent
.ShiftDown());
977 vEventNav
.SetWindowChange(FALSE
);
978 vEventNav
.SetEventObject(this);
980 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
986 } // end of wxTextCtrl::OnChar
988 bool wxTextCtrl::OS2Command(
990 , WXWORD
WXUNUSED(vId
)
998 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1003 vEvent
.SetEventObject(this);
1004 GetEventHandler()->ProcessEvent(vEvent
);
1010 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1014 InitCommandEvent(vEvent
);
1015 vEvent
.SetString((char*)GetValue().c_str());
1016 ProcessCommand(vEvent
);
1022 // The text size limit has been hit - increase it
1028 case EN_INSERTMODETOGGLE
:
1039 } // end of wxTextCtrl::OS2Command
1041 void wxTextCtrl::AdjustSpaceLimit()
1043 unsigned int uLen
= 0;
1044 unsigned int uLimit
= 0;
1046 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1049 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1060 vParams
.fsStatus
= WPM_CBCTLDATA
;
1061 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1063 if (::WinSendMsg( GetHwnd()
1064 ,WM_QUERYWINDOWPARAMS
1069 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1070 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1073 uLimit
= 32; //PM's default
1077 uLimit
= uLen
+ 0x8000; // 32Kb
1078 if (uLimit
> 0xffff)
1083 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1085 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1087 } // end of wxTextCtrl::AdjustSpaceLimit
1089 bool wxTextCtrl::AcceptsFocus() const
1092 // We don't want focus if we can't be edited
1094 return IsEditable() && wxControl::AcceptsFocus();
1095 } // end of wxTextCtrl::Command
1097 wxSize
wxTextCtrl::DoGetBestSize() const
1102 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1104 int wText
= DEFAULT_ITEM_WIDTH
;
1105 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
);
1107 if (m_windowStyle
& wxTE_MULTILINE
)
1109 hText
*= wxMin(GetNumberOfLines(), 5);
1111 //else: for single line control everything is ok
1112 return wxSize(wText
, hText
);
1113 } // end of wxTextCtrl::DoGetBestSize
1115 // ----------------------------------------------------------------------------
1116 // standard handlers for standard edit menu events
1117 // ----------------------------------------------------------------------------
1119 void wxTextCtrl::OnCut(
1120 wxCommandEvent
& rEvent
1124 } // end of wxTextCtrl::OnCut
1126 void wxTextCtrl::OnCopy(
1127 wxCommandEvent
& rEvent
1131 } // end of wxTextCtrl::OnCopy
1133 void wxTextCtrl::OnPaste(
1134 wxCommandEvent
& rEvent
1138 } // end of wxTextCtrl::OnPaste
1140 void wxTextCtrl::OnUndo(
1141 wxCommandEvent
& rEvent
1145 } // end of wxTextCtrl::OnUndo
1147 void wxTextCtrl::OnRedo(
1148 wxCommandEvent
& rEvent
1152 } // end of wxTextCtrl::OnRedo
1154 void wxTextCtrl::OnUpdateCut(
1155 wxUpdateUIEvent
& rEvent
1158 rEvent
.Enable(CanCut());
1159 } // end of wxTextCtrl::OnUpdateCut
1161 void wxTextCtrl::OnUpdateCopy(
1162 wxUpdateUIEvent
& rEvent
1165 rEvent
.Enable(CanCopy());
1166 } // end of wxTextCtrl::OnUpdateCopy
1168 void wxTextCtrl::OnUpdatePaste(
1169 wxUpdateUIEvent
& rEvent
1172 rEvent
.Enable(CanPaste());
1173 } // end of wxTextCtrl::OnUpdatePaste
1175 void wxTextCtrl::OnUpdateUndo(
1176 wxUpdateUIEvent
& rEvent
1179 rEvent
.Enable(CanUndo());
1180 } // end of wxTextCtrl::OnUpdateUndo
1182 void wxTextCtrl::OnUpdateRedo(
1183 wxUpdateUIEvent
& rEvent
1186 rEvent
.Enable(CanRedo());
1187 } // end of wxTextCtrl::OnUpdateRedo
1189 bool wxTextCtrl::SetBackgroundColour(
1190 const wxColour
& rColour
1194 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1196 } // end of wxTextCtrl::SetBackgroundColour
1198 bool wxTextCtrl::SetForegroundColour(
1199 const wxColour
& rColour
1203 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1205 } // end of wxTextCtrl::SetForegroundColour