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 if (m_defaultStyle
.HasFont() || m_defaultStyle
.HasTextColour())
315 GetSelection( &lStart
323 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
325 } // end of wxTextCtrl::WriteText
327 void wxTextCtrl::AppendText(
328 const wxString
& rsText
331 SetInsertionPointEnd();
333 } // end of wxTextCtrl::AppendText
335 void wxTextCtrl::Clear()
337 ::WinSetWindowText(GetHwnd(), "");
338 } // end of wxTextCtrl::Clear
340 // ----------------------------------------------------------------------------
341 // Clipboard operations
342 // ----------------------------------------------------------------------------
344 void wxTextCtrl::Copy()
348 HWND hWnd
= GetHwnd();
350 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
352 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
354 } // end of wxTextCtrl::Copy
356 void wxTextCtrl::Cut()
360 HWND hWnd
= GetHwnd();
363 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
365 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
367 } // end of wxTextCtrl::Cut
369 void wxTextCtrl::Paste()
373 HWND hWnd
= GetHwnd();
375 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
377 } // end of wxTextCtrl::Paste
379 bool wxTextCtrl::CanCopy() const
382 // Can copy if there's a selection
387 GetSelection(&lFrom
, &lTo
);
388 return (lFrom
!= lTo
);
389 } // end of wxTextCtrl::CanCopy
391 bool wxTextCtrl::CanCut() const
394 // Can cut if there's a selection
399 GetSelection(&lFrom
, &lTo
);
400 return (lFrom
!= lTo
);
401 } // end of wxTextCtrl::CanCut
403 bool wxTextCtrl::CanPaste() const
405 bool bIsTextAvailable
= FALSE
;
411 // Check for straight text on clipboard
413 if (::WinOpenClipbrd(vHabmain
))
415 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
416 ::WinCloseClipbrd(vHabmain
);
418 return bIsTextAvailable
;
419 } // end of wxTextCtrl::CanPaste
421 // ----------------------------------------------------------------------------
423 // ----------------------------------------------------------------------------
425 void wxTextCtrl::SetEditable(
429 HWND hWnd
= GetHwnd();
432 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
434 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
435 } // end of wxTextCtrl::SetEditable
437 void wxTextCtrl::SetInsertionPoint(
441 HWND hWnd
= GetHwnd();
444 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
446 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
447 } // end of wxTextCtrl::SetInsertionPoint
449 void wxTextCtrl::SetInsertionPointEnd()
451 long lPos
= GetLastPosition();
453 SetInsertionPoint(lPos
);
454 } // end of wxTextCtrl::SetInsertionPointEnd
456 long wxTextCtrl::GetInsertionPoint() const
461 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
464 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
465 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
467 return (dwPos
& 0xFFFF);
468 } // end of wxTextCtrl::GetInsertionPoint
470 long wxTextCtrl::GetLastPosition() const
472 HWND hWnd
= GetHwnd();
481 // This just gets the total text length. The last will be this value
483 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
490 vParams
.fsStatus
= WPM_CCHTEXT
;
491 if (::WinSendMsg( GetHwnd()
492 ,WM_QUERYWINDOWPARAMS
497 lLineLength
= (long)vParams
.cchText
;
502 return(lCharIndex
+ lLineLength
);
503 } // end of wxTextCtrl::GetLastPosition
505 // If the return values from and to are the same, there is no
507 void wxTextCtrl::GetSelection(
515 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
518 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
520 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
521 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
522 } // end of wxTextCtrl::GetSelection
524 bool wxTextCtrl::IsEditable() const
527 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
529 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
530 } // end of wxTextCtrl::IsEditable
532 // ----------------------------------------------------------------------------
534 // ----------------------------------------------------------------------------
536 void wxTextCtrl::Replace(
539 , const wxString
& rsValue
543 HWND hWnd
= GetHwnd();
544 long lFromChar
= lFrom
;
548 // Set selection and remove it
552 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
553 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
557 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
558 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
562 // Now replace with 'value', by pasting.
564 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
566 // Paste into edit control
568 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
570 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
572 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
574 } // end of wxTextCtrl::Replace
576 void wxTextCtrl::Remove(
581 HWND hWnd
= GetHwnd();
582 long lFromChar
= lFrom
;
587 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
588 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
592 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
593 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
595 } // end of wxTextCtrl::Remove
597 void wxTextCtrl::SetSelection(
602 HWND hWnd
= GetHwnd();
603 long lFromChar
= lFrom
;
607 // If from and to are both -1, it means (in wxWindows) that all text should
608 // be selected. Translate into Windows convention
610 if ((lFrom
== -1L) && (lTo
== -1L))
616 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
618 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
619 } // end of wxTextCtrl::SetSelection
621 bool wxTextCtrl::SetStyle(
624 , const wxTextAttr
& rStyle
627 HWND hWnd
= GetHwnd();
629 // Order the range if needed
640 // We can only change the format of the selection, so select the range we
641 // want and restore the old selection later
645 GetSelection( &lStartOld
650 // But do we really have to change the selection?
652 bool bChangeSel
= lStart
!= lStartOld
|| lEnd
!= lEndOld
;
657 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
659 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
662 // TODO:: finish this by setting fonts and colors
665 } // end of wxTextCtrl::SetStyle
667 bool wxTextCtrl::LoadFile(
668 const wxString
& rsFile
671 if ( wxTextCtrlBase::LoadFile(rsFile
) )
674 // Update the size limit if needed
680 } // end of wxTextCtrl::LoadFile
682 bool wxTextCtrl::IsModified() const
687 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
689 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
691 } // end of wxTextCtrl::IsModified
694 // Makes 'unmodified'
696 void wxTextCtrl::DiscardEdits()
699 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
702 // EM controls do not have a SETCHANGED but issuing a query should reset it
704 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
705 } // end of wxTextCtrl::DiscardEdits
707 int wxTextCtrl::GetNumberOfLines() const
712 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
716 } // end of wxTextCtrl::GetNumberOfLines
718 long wxTextCtrl::XYToPosition(
723 HWND hWnd
= GetHwnd();
724 long lCharIndex
= 0L;
729 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
730 lCharIndex
= ((lLen
* lY
) + lX
);
735 } // end of wxTextCtrl::XYToPosition
737 bool wxTextCtrl::PositionToXY(
743 HWND hWnd
= GetHwnd();
748 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
759 // This gets the char index for the _beginning_ of this line
765 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
766 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
772 vParams
.fsStatus
= WPM_CCHTEXT
;
773 if (::WinSendMsg( hWnd
774 ,WM_QUERYWINDOWPARAMS
779 lCharIndex
= vParams
.cchText
;
785 if (lCharIndex
== -1)
791 // The X position must therefore be the difference between pos and charIndex
794 *plX
= lPos
- lCharIndex
;
799 } // end of wxTextCtrl::PositionToXY
801 void wxTextCtrl::ShowPosition(
805 HWND hWnd
= GetHwnd();
806 long lCurrentLineLineNo
= 0L;
808 // To scroll to a position, we pass the number of lines and characters
809 // to scroll *by*. This means that we need to:
810 // (1) Find the line position of the current line.
811 // (2) Find the line position of pos.
812 // (3) Scroll by (pos - current).
813 // For now, ignore the horizontal scrolling.
816 // Is this where scrolling is relative to - the line containing the caret?
817 // Or is the first visible line??? Try first visible line.
822 // In PM this is the actual char position
824 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
827 // This will cause a scroll to the selected position
829 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
831 } // end of wxTextCtrl::ShowPosition
833 int wxTextCtrl::GetLineLength(
840 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
845 vParams
.fsStatus
= WPM_CCHTEXT
;
846 if (::WinSendMsg( GetHwnd()
847 ,WM_QUERYWINDOWPARAMS
852 lLen
= vParams
.cchText
;
858 } // end ofwxTextCtrl::GetLineLength
860 wxString
wxTextCtrl::GetLineText(
864 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
869 // There must be at least enough place for the length WORD in the
872 lLen
+= sizeof(WORD
);
873 zBuf
= new char[lLen
];
880 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
881 lIndex
= lLen
* lLineNo
;
883 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
884 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
885 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
886 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
887 zBuf
[lCopied
] = '\0';
893 vParams
.fsStatus
= WPM_CCHTEXT
;
894 if (::WinSendMsg( GetHwnd()
895 ,WM_QUERYWINDOWPARAMS
899 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
900 zBuf
[vParams
.cchText
] = '\0';
905 } // end of wxTextCtrl::GetLineText
907 // ----------------------------------------------------------------------------
909 // ----------------------------------------------------------------------------
911 void wxTextCtrl::Undo()
916 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
917 // Simple entryfields cannot be undone
919 } // end of wxTextCtrl::Undo
921 void wxTextCtrl::Redo()
926 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
927 // Simple entryfields cannot be undone
929 } // end of wxTextCtrl::Redo
931 bool wxTextCtrl::CanUndo() const
936 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
938 bOk
= FALSE
; // can't undo regular edit fields in PM
940 } // end of wxTextCtrl::CanUndo
942 bool wxTextCtrl::CanRedo() const
947 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
949 bOk
= FALSE
; // can't undo regular edit fields in PM
951 } // end of wxTextCtrl::CanRedo
953 // ----------------------------------------------------------------------------
954 // implemenation details
955 // ----------------------------------------------------------------------------
957 void wxTextCtrl::Command(
958 wxCommandEvent
& rEvent
961 SetValue(rEvent
.GetString());
962 ProcessCommand (rEvent
);
963 } // end of wxTextCtrl::Command
965 void wxTextCtrl::OnDropFiles(
966 wxDropFilesEvent
& rEvent
969 // By default, load the first file into the text window.
970 if (rEvent
.GetNumberOfFiles() > 0)
972 LoadFile(rEvent
.GetFiles()[0]);
974 } // end of wxTextCtrl::OnDropFiles
976 WXHBRUSH
wxTextCtrl::OnCtlColor(
985 HPS hPS
= (HPS
)hWxDC
;
986 wxBrush
* pBrush
= NULL
;
987 wxColour vColBack
= GetBackgroundColour();
988 wxColour vColFore
= GetForegroundColour();
989 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
995 HBRUSH hBrush
= NULLHANDLE
;
999 if (GetParent()->GetTransparentBackground())
1000 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1002 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1003 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1004 vColBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
1005 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1006 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1007 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1008 } // end of wxTextCtrl::OnCtlColor
1010 void wxTextCtrl::OnChar(
1014 switch (rEvent
.KeyCode())
1017 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1019 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1021 vEvent
.SetEventObject(this);
1022 if ( GetEventHandler()->ProcessEvent(vEvent
))
1025 //else: multiline controls need Enter for themselves
1030 // always produce navigation event - even if we process TAB
1031 // ourselves the fact that we got here means that the user code
1032 // decided to skip processing of this TAB - probably to let it
1033 // do its default job.
1035 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1036 // handled by Windows
1038 wxNavigationKeyEvent vEventNav
;
1040 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1041 vEventNav
.SetWindowChange(FALSE
);
1042 vEventNav
.SetEventObject(this);
1044 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1050 } // end of wxTextCtrl::OnChar
1052 bool wxTextCtrl::OS2Command(
1054 , WXWORD
WXUNUSED(vId
)
1062 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1067 vEvent
.SetEventObject(this);
1068 GetEventHandler()->ProcessEvent(vEvent
);
1074 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1078 InitCommandEvent(vEvent
);
1079 vEvent
.SetString((char*)GetValue().c_str());
1080 ProcessCommand(vEvent
);
1086 // The text size limit has been hit - increase it
1092 case EN_INSERTMODETOGGLE
:
1103 } // end of wxTextCtrl::OS2Command
1105 void wxTextCtrl::AdjustSpaceLimit()
1107 unsigned int uLen
= 0;
1108 unsigned int uLimit
= 0;
1110 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1113 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1124 vParams
.fsStatus
= WPM_CBCTLDATA
;
1125 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1127 if (::WinSendMsg( GetHwnd()
1128 ,WM_QUERYWINDOWPARAMS
1133 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1134 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1137 uLimit
= 32; //PM's default
1141 uLimit
= uLen
+ 0x8000; // 32Kb
1142 if (uLimit
> 0xffff)
1147 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1149 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1151 } // end of wxTextCtrl::AdjustSpaceLimit
1153 bool wxTextCtrl::AcceptsFocus() const
1156 // We don't want focus if we can't be edited
1158 return IsEditable() && wxControl::AcceptsFocus();
1159 } // end of wxTextCtrl::Command
1161 wxSize
wxTextCtrl::DoGetBestSize() const
1166 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1168 int wText
= DEFAULT_ITEM_WIDTH
;
1169 int hText
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
);
1171 if (m_windowStyle
& wxTE_MULTILINE
)
1173 hText
*= wxMin(GetNumberOfLines(), 5);
1175 //else: for single line control everything is ok
1176 return wxSize(wText
, hText
);
1177 } // end of wxTextCtrl::DoGetBestSize
1179 // ----------------------------------------------------------------------------
1180 // standard handlers for standard edit menu events
1181 // ----------------------------------------------------------------------------
1183 void wxTextCtrl::OnCut(
1184 wxCommandEvent
& rEvent
1188 } // end of wxTextCtrl::OnCut
1190 void wxTextCtrl::OnCopy(
1191 wxCommandEvent
& rEvent
1195 } // end of wxTextCtrl::OnCopy
1197 void wxTextCtrl::OnPaste(
1198 wxCommandEvent
& rEvent
1202 } // end of wxTextCtrl::OnPaste
1204 void wxTextCtrl::OnUndo(
1205 wxCommandEvent
& rEvent
1209 } // end of wxTextCtrl::OnUndo
1211 void wxTextCtrl::OnRedo(
1212 wxCommandEvent
& rEvent
1216 } // end of wxTextCtrl::OnRedo
1218 void wxTextCtrl::OnUpdateCut(
1219 wxUpdateUIEvent
& rEvent
1222 rEvent
.Enable(CanCut());
1223 } // end of wxTextCtrl::OnUpdateCut
1225 void wxTextCtrl::OnUpdateCopy(
1226 wxUpdateUIEvent
& rEvent
1229 rEvent
.Enable(CanCopy());
1230 } // end of wxTextCtrl::OnUpdateCopy
1232 void wxTextCtrl::OnUpdatePaste(
1233 wxUpdateUIEvent
& rEvent
1236 rEvent
.Enable(CanPaste());
1237 } // end of wxTextCtrl::OnUpdatePaste
1239 void wxTextCtrl::OnUpdateUndo(
1240 wxUpdateUIEvent
& rEvent
1243 rEvent
.Enable(CanUndo());
1244 } // end of wxTextCtrl::OnUpdateUndo
1246 void wxTextCtrl::OnUpdateRedo(
1247 wxUpdateUIEvent
& rEvent
1250 rEvent
.Enable(CanRedo());
1251 } // end of wxTextCtrl::OnUpdateRedo
1253 bool wxTextCtrl::SetBackgroundColour(
1254 const wxColour
& rColour
1258 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1260 } // end of wxTextCtrl::SetBackgroundColour
1262 bool wxTextCtrl::SetForegroundColour(
1263 const wxColour
& rColour
1267 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1269 } // end of wxTextCtrl::SetForegroundColour