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/scrolwin.h"
22 #include "wx/settings.h"
30 #include "wx/clipbrd.h"
33 #include "wx/textfile.h"
35 #include "wx/os2/private.h"
39 #include <sys/types.h>
47 #if !defined(MLE_INDEX)
53 // ----------------------------------------------------------------------------
54 // event tables and other macros
55 // ----------------------------------------------------------------------------
57 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
59 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
60 EVT_CHAR(wxTextCtrl::OnChar
)
61 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
63 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
64 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
65 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
66 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
67 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
69 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
70 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
71 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
72 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
73 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 wxTextCtrl::wxTextCtrl()
89 bool wxTextCtrl::Create(
92 , const wxString
& rsValue
97 , const wxValidator
& rValidator
99 , const wxString
& rsName
105 // Base initialization
107 if ( !CreateBase( pParent
119 wxPoint vPos
= rPos
; // The OS/2 position
123 pParent
->AddChild(this);
124 hParent
= GetWinHwnd(pParent
);
126 // OS2 uses normal coordinates, no bassackwards Windows ones
128 if (pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)) ||
129 pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
))
132 wxWindow
* pGrandParent
= NULL
;
134 pGrandParent
= pParent
->GetParent();
136 nTempy
= pGrandParent
->GetSize().y
- (vPos
.y
+ rSize
.y
);
138 nTempy
= pParent
->GetSize().y
- (vPos
.y
+ rSize
.y
);
141 nTempy
= pParent
->GetSize().y
- (vPos
.y
+ rSize
.y
);
148 ::WinQueryWindowRect(HWND_DESKTOP
, &vRect
);
149 hParent
= HWND_DESKTOP
;
150 vPos
.y
= vRect
.yTop
- (vPos
.y
+ rSize
.y
);
153 m_windowStyle
= lStyle
;
155 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
158 // Single and multiline edit fields are two different controls in PM
160 if ( m_windowStyle
& wxTE_MULTILINE
)
162 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
165 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
166 lSstyle
|= MLS_VSCROLL
;
167 if (m_windowStyle
& wxHSCROLL
)
168 lSstyle
|= MLS_HSCROLL
;
169 if (m_windowStyle
& wxTE_READONLY
)
170 lSstyle
|= MLS_READONLY
;
174 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
176 if (m_windowStyle
& wxHSCROLL
)
177 lSstyle
|= ES_AUTOSCROLL
;
178 if (m_windowStyle
& wxTE_READONLY
)
179 lSstyle
|= ES_READONLY
;
180 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
181 lSstyle
|= ES_UNREADABLE
;
183 if ( pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)) ||
184 pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
))
186 lSstyle
|= WS_CLIPSIBLINGS
;
189 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
190 ,WC_MLE
// Window class
191 ,(PSZ
)rsValue
.c_str() // Initial Text
192 ,(ULONG
)lSstyle
// Style flags
193 ,(LONG
)0 // X pos of origin
194 ,(LONG
)0 // Y pos of origin
195 ,(LONG
)0 // field width
196 ,(LONG
)0 // field height
197 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
198 ,HWND_TOP
// initial z position
199 ,(ULONG
)vId
// Window identifier
200 ,NULL
// no control data
201 ,NULL
// no Presentation parameters
206 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
207 ,WC_ENTRYFIELD
// Window class
208 ,(PSZ
)rsValue
.c_str() // Initial Text
209 ,(ULONG
)lSstyle
// Style flags
210 ,(LONG
)0 // X pos of origin
211 ,(LONG
)0 // Y pos of origin
212 ,(LONG
)0 // field width
213 ,(LONG
)0 // field height
214 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
215 ,HWND_TOP
// initial z position
216 ,(ULONG
)vId
// Window identifier
217 ,NULL
// no control data
218 ,NULL
// no Presentation parameters
227 SubclassWin(GetHWND());
230 // Set font, position, size and initial value
232 wxFont
& vFontParent
= pParent
->GetFont();
234 if (vFontParent
.Ok())
236 SetFont(vFontParent
);
240 SetFont(wxSystemSettings::GetSystemFont(wxSYS_SYSTEM_FONT
));
242 if (!rsValue
.IsEmpty())
253 } // end of wxTextCtrl::Create
256 // Make sure the window style (etc.) reflects the HWND style (roughly)
258 void wxTextCtrl::AdoptAttributesFromHWND()
260 HWND hWnd
= GetHwnd();
261 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
263 wxWindow::AdoptAttributesFromHWND();
267 m_windowStyle
|= wxTE_MULTILINE
;
268 if (lStyle
& MLS_READONLY
)
269 m_windowStyle
|= wxTE_READONLY
;
273 if (lStyle
& ES_UNREADABLE
)
274 m_windowStyle
|= wxTE_PASSWORD
;
275 if (lStyle
& ES_READONLY
)
276 m_windowStyle
|= wxTE_READONLY
;
278 } // end of wxTextCtrl::AdoptAttributesFromHWND
280 void wxTextCtrl::SetupColours()
282 wxColour vBkgndColour
;
284 vBkgndColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
);
285 SetBackgroundColour(vBkgndColour
);
286 SetForegroundColour(GetParent()->GetForegroundColour());
289 ::WinSendMsg( GetHwnd()
291 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
295 } // end of wxTextCtrl::SetupColours
297 // ----------------------------------------------------------------------------
298 // set/get the controls text
299 // ----------------------------------------------------------------------------
301 wxString
wxTextCtrl::GetValue() const
303 wxString sStr
= wxGetWindowText(GetHWND());
304 char* zStr
= (char*)sStr
.c_str();
306 for ( ; *zStr
; zStr
++ )
309 // this will replace \r\n with just \n
318 } // end of wxTextCtrl::GetValue
320 void wxTextCtrl::SetValue(
321 const wxString
& rsValue
325 // If the text is long enough, it's faster to just set it instead of first
326 // comparing it with the old one (chances are that it will be different
327 // anyhow, this comparison is there to avoid flicker for small single-line
328 // edit controls mostly)
330 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
332 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
335 } // end of wxTextCtrl::SetValue
337 void wxTextCtrl::WriteText(
338 const wxString
& rsValue
341 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
343 } // end of wxTextCtrl::WriteText
345 void wxTextCtrl::AppendText(
346 const wxString
& rsText
349 SetInsertionPointEnd();
351 } // end of wxTextCtrl::AppendText
353 void wxTextCtrl::Clear()
355 ::WinSetWindowText(GetHwnd(), "");
356 } // end of wxTextCtrl::Clear
358 // ----------------------------------------------------------------------------
359 // Clipboard operations
360 // ----------------------------------------------------------------------------
362 void wxTextCtrl::Copy()
366 HWND hWnd
= GetHwnd();
368 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
370 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
372 } // end of wxTextCtrl::Copy
374 void wxTextCtrl::Cut()
378 HWND hWnd
= GetHwnd();
381 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
383 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
385 } // end of wxTextCtrl::Cut
387 void wxTextCtrl::Paste()
391 HWND hWnd
= GetHwnd();
393 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
395 } // end of wxTextCtrl::Paste
397 bool wxTextCtrl::CanCopy() const
400 // Can copy if there's a selection
405 GetSelection(&lFrom
, &lTo
);
406 return (lFrom
!= lTo
);
407 } // end of wxTextCtrl::CanCopy
409 bool wxTextCtrl::CanCut() const
412 // Can cut if there's a selection
417 GetSelection(&lFrom
, &lTo
);
418 return (lFrom
!= lTo
);
419 } // end of wxTextCtrl::CanCut
421 bool wxTextCtrl::CanPaste() const
423 bool bIsTextAvailable
= FALSE
;
429 // Check for straight text on clipboard
431 if (::WinOpenClipbrd(vHabmain
))
433 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
434 ::WinCloseClipbrd(vHabmain
);
436 return bIsTextAvailable
;
437 } // end of wxTextCtrl::CanPaste
439 // ----------------------------------------------------------------------------
441 // ----------------------------------------------------------------------------
443 void wxTextCtrl::SetEditable(
447 HWND hWnd
= GetHwnd();
450 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
452 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
453 } // end of wxTextCtrl::SetEditable
455 void wxTextCtrl::SetInsertionPoint(
459 HWND hWnd
= GetHwnd();
462 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
464 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
465 } // end of wxTextCtrl::SetInsertionPoint
467 void wxTextCtrl::SetInsertionPointEnd()
469 long lPos
= GetLastPosition();
471 SetInsertionPoint(lPos
);
472 } // end of wxTextCtrl::SetInsertionPointEnd
474 long wxTextCtrl::GetInsertionPoint() const
479 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
482 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
483 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
485 return (dwPos
& 0xFFFF);
486 } // end of wxTextCtrl::GetInsertionPoint
488 long wxTextCtrl::GetLastPosition() const
490 HWND hWnd
= GetHwnd();
499 // This just gets the total text length. The last will be this value
501 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
508 vParams
.fsStatus
= WPM_CCHTEXT
;
509 if (::WinSendMsg( GetHwnd()
510 ,WM_QUERYWINDOWPARAMS
515 lLineLength
= (long)vParams
.cchText
;
520 return(lCharIndex
+ lLineLength
);
521 } // end of wxTextCtrl::GetLastPosition
523 // If the return values from and to are the same, there is no
525 void wxTextCtrl::GetSelection(
533 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
536 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
538 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
539 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
540 } // end of wxTextCtrl::GetSelection
542 bool wxTextCtrl::IsEditable() const
545 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
547 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
548 } // end of wxTextCtrl::IsEditable
550 // ----------------------------------------------------------------------------
552 // ----------------------------------------------------------------------------
554 void wxTextCtrl::Replace(
557 , const wxString
& rsValue
561 HWND hWnd
= GetHwnd();
562 long lFromChar
= lFrom
;
566 // Set selection and remove it
570 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
571 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
575 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
576 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
580 // Now replace with 'value', by pasting.
582 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
584 // Paste into edit control
586 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
588 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
590 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
592 } // end of wxTextCtrl::Replace
594 void wxTextCtrl::Remove(
599 HWND hWnd
= GetHwnd();
600 long lFromChar
= lFrom
;
605 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
606 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
610 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
611 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
613 } // end of wxTextCtrl::Remove
615 void wxTextCtrl::SetSelection(
620 HWND hWnd
= GetHwnd();
621 long lFromChar
= lFrom
;
625 // If from and to are both -1, it means (in wxWindows) that all text should
626 // be selected. Translate into Windows convention
628 if ((lFrom
== -1L) && (lTo
== -1L))
634 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
636 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
637 } // end of wxTextCtrl::SetSelection
639 bool wxTextCtrl::LoadFile(
640 const wxString
& rsFile
643 if ( wxTextCtrlBase::LoadFile(rsFile
) )
646 // Update the size limit if needed
652 } // end of wxTextCtrl::LoadFile
654 bool wxTextCtrl::IsModified() const
659 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
661 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
663 } // end of wxTextCtrl::IsModified
666 // Makes 'unmodified'
668 void wxTextCtrl::DiscardEdits()
671 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
674 // EM controls do not have a SETCHANGED but issuing a query should reset it
676 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
677 } // end of wxTextCtrl::DiscardEdits
679 int wxTextCtrl::GetNumberOfLines() const
684 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
688 } // end of wxTextCtrl::GetNumberOfLines
690 long wxTextCtrl::XYToPosition(
695 HWND hWnd
= GetHwnd();
696 long lCharIndex
= 0L;
701 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
702 lCharIndex
= ((lLen
* lY
) + lX
);
707 } // end of wxTextCtrl::XYToPosition
709 bool wxTextCtrl::PositionToXY(
715 HWND hWnd
= GetHwnd();
720 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
731 // This gets the char index for the _beginning_ of this line
737 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
738 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
744 vParams
.fsStatus
= WPM_CCHTEXT
;
745 if (::WinSendMsg( hWnd
746 ,WM_QUERYWINDOWPARAMS
751 lCharIndex
= vParams
.cchText
;
757 if (lCharIndex
== -1)
763 // The X position must therefore be the difference between pos and charIndex
766 *plX
= lPos
- lCharIndex
;
771 } // end of wxTextCtrl::PositionToXY
773 void wxTextCtrl::ShowPosition(
777 HWND hWnd
= GetHwnd();
778 long lCurrentLineLineNo
= 0L;
780 // To scroll to a position, we pass the number of lines and characters
781 // to scroll *by*. This means that we need to:
782 // (1) Find the line position of the current line.
783 // (2) Find the line position of pos.
784 // (3) Scroll by (pos - current).
785 // For now, ignore the horizontal scrolling.
788 // Is this where scrolling is relative to - the line containing the caret?
789 // Or is the first visible line??? Try first visible line.
794 // In PM this is the actual char position
796 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
799 // This will cause a scroll to the selected position
801 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
803 } // end of wxTextCtrl::ShowPosition
805 int wxTextCtrl::GetLineLength(
812 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
817 vParams
.fsStatus
= WPM_CCHTEXT
;
818 if (::WinSendMsg( GetHwnd()
819 ,WM_QUERYWINDOWPARAMS
824 lLen
= vParams
.cchText
;
830 } // end ofwxTextCtrl::GetLineLength
832 wxString
wxTextCtrl::GetLineText(
836 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
841 // There must be at least enough place for the length WORD in the
844 lLen
+= sizeof(WORD
);
845 zBuf
= new char[lLen
];
852 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
853 lIndex
= lLen
* lLineNo
;
855 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
856 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
857 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
858 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
859 zBuf
[lCopied
] = '\0';
865 vParams
.fsStatus
= WPM_CCHTEXT
;
866 if (::WinSendMsg( GetHwnd()
867 ,WM_QUERYWINDOWPARAMS
871 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
872 zBuf
[vParams
.cchText
] = '\0';
877 } // end of wxTextCtrl::GetLineText
879 // ----------------------------------------------------------------------------
881 // ----------------------------------------------------------------------------
883 void wxTextCtrl::Undo()
888 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
889 // Simple entryfields cannot be undone
891 } // end of wxTextCtrl::Undo
893 void wxTextCtrl::Redo()
898 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
899 // Simple entryfields cannot be undone
901 } // end of wxTextCtrl::Redo
903 bool wxTextCtrl::CanUndo() const
908 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
910 bOk
= FALSE
; // can't undo regular edit fields in PM
912 } // end of wxTextCtrl::CanUndo
914 bool wxTextCtrl::CanRedo() const
919 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
921 bOk
= FALSE
; // can't undo regular edit fields in PM
923 } // end of wxTextCtrl::CanRedo
925 // ----------------------------------------------------------------------------
926 // implemenation details
927 // ----------------------------------------------------------------------------
929 void wxTextCtrl::Command(
930 wxCommandEvent
& rEvent
933 SetValue(rEvent
.GetString());
934 ProcessCommand (rEvent
);
935 } // end of wxTextCtrl::Command
937 void wxTextCtrl::OnDropFiles(
938 wxDropFilesEvent
& rEvent
941 // By default, load the first file into the text window.
942 if (rEvent
.GetNumberOfFiles() > 0)
944 LoadFile(rEvent
.GetFiles()[0]);
946 } // end of wxTextCtrl::OnDropFiles
948 WXHBRUSH
wxTextCtrl::OnCtlColor(
957 HPS hPS
= (HPS
)hWxDC
;
958 wxBrush
* pBrush
= NULL
;
959 wxColour vColBack
= GetBackgroundColour();
960 wxColour vColFore
= GetForegroundColour();
961 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
967 HBRUSH hBrush
= NULLHANDLE
;
971 if (GetParent()->GetTransparentBackground())
972 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
974 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
975 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
976 vColBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
977 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
978 ::GpiSetColor(hPS
, vColFore
.GetPixel());
979 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
980 } // end of wxTextCtrl::OnCtlColor
982 void wxTextCtrl::OnChar(
986 switch (rEvent
.KeyCode())
989 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
991 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
993 vEvent
.SetEventObject(this);
994 if ( GetEventHandler()->ProcessEvent(vEvent
))
997 //else: multiline controls need Enter for themselves
1002 // always produce navigation event - even if we process TAB
1003 // ourselves the fact that we got here means that the user code
1004 // decided to skip processing of this TAB - probably to let it
1005 // do its default job.
1007 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1008 // handled by Windows
1010 wxNavigationKeyEvent vEventNav
;
1012 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1013 vEventNav
.SetWindowChange(FALSE
);
1014 vEventNav
.SetEventObject(this);
1016 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1022 } // end of wxTextCtrl::OnChar
1024 bool wxTextCtrl::OS2Command(
1026 , WXWORD
WXUNUSED(vId
)
1034 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1039 vEvent
.SetEventObject(this);
1040 GetEventHandler()->ProcessEvent(vEvent
);
1046 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1050 InitCommandEvent(vEvent
);
1051 vEvent
.SetString((char*)GetValue().c_str());
1052 ProcessCommand(vEvent
);
1058 // The text size limit has been hit - increase it
1064 case EN_INSERTMODETOGGLE
:
1075 } // end of wxTextCtrl::OS2Command
1077 void wxTextCtrl::AdjustSpaceLimit()
1079 unsigned int uLen
= 0;
1080 unsigned int uLimit
= 0;
1082 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1085 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1096 vParams
.fsStatus
= WPM_CBCTLDATA
;
1097 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1099 if (::WinSendMsg( GetHwnd()
1100 ,WM_QUERYWINDOWPARAMS
1105 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1106 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1109 uLimit
= 32; //PM's default
1113 uLimit
= uLen
+ 0x8000; // 32Kb
1114 if (uLimit
> 0xffff)
1119 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1121 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1123 } // end of wxTextCtrl::AdjustSpaceLimit
1125 bool wxTextCtrl::AcceptsFocus() const
1128 // We don't want focus if we can't be edited
1130 return IsEditable() && wxControl::AcceptsFocus();
1131 } // end of wxTextCtrl::Command
1133 wxSize
wxTextCtrl::DoGetBestSize() const
1138 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1140 int wText
= DEFAULT_ITEM_WIDTH
;
1141 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1143 if (m_windowStyle
& wxTE_MULTILINE
)
1145 hText
*= wxMin(GetNumberOfLines(), 5);
1147 //else: for single line control everything is ok
1148 return wxSize(wText
, hText
);
1149 } // end of wxTextCtrl::DoGetBestSize
1151 // ----------------------------------------------------------------------------
1152 // standard handlers for standard edit menu events
1153 // ----------------------------------------------------------------------------
1155 void wxTextCtrl::OnCut(
1156 wxCommandEvent
& rEvent
1160 } // end of wxTextCtrl::OnCut
1162 void wxTextCtrl::OnCopy(
1163 wxCommandEvent
& rEvent
1167 } // end of wxTextCtrl::OnCopy
1169 void wxTextCtrl::OnPaste(
1170 wxCommandEvent
& rEvent
1174 } // end of wxTextCtrl::OnPaste
1176 void wxTextCtrl::OnUndo(
1177 wxCommandEvent
& rEvent
1181 } // end of wxTextCtrl::OnUndo
1183 void wxTextCtrl::OnRedo(
1184 wxCommandEvent
& rEvent
1188 } // end of wxTextCtrl::OnRedo
1190 void wxTextCtrl::OnUpdateCut(
1191 wxUpdateUIEvent
& rEvent
1194 rEvent
.Enable(CanCut());
1195 } // end of wxTextCtrl::OnUpdateCut
1197 void wxTextCtrl::OnUpdateCopy(
1198 wxUpdateUIEvent
& rEvent
1201 rEvent
.Enable(CanCopy());
1202 } // end of wxTextCtrl::OnUpdateCopy
1204 void wxTextCtrl::OnUpdatePaste(
1205 wxUpdateUIEvent
& rEvent
1208 rEvent
.Enable(CanPaste());
1209 } // end of wxTextCtrl::OnUpdatePaste
1211 void wxTextCtrl::OnUpdateUndo(
1212 wxUpdateUIEvent
& rEvent
1215 rEvent
.Enable(CanUndo());
1216 } // end of wxTextCtrl::OnUpdateUndo
1218 void wxTextCtrl::OnUpdateRedo(
1219 wxUpdateUIEvent
& rEvent
1222 rEvent
.Enable(CanRedo());
1223 } // end of wxTextCtrl::OnUpdateRedo
1225 bool wxTextCtrl::SetBackgroundColour(
1226 const wxColour
& rColour
1230 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1232 } // end of wxTextCtrl::SetBackgroundColour
1234 bool wxTextCtrl::SetForegroundColour(
1235 const wxColour
& rColour
1239 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1241 } // end of wxTextCtrl::SetForegroundColour
1243 bool wxTextCtrl::SetStyle(
1246 , const wxTextAttr
& rStyle
1249 HWND hWnd
= GetHwnd();
1260 // We can only change the format of the selection, so select the range we
1261 // want and restore the old selection later
1266 GetSelection( &lStartOld
1271 // But do we really have to change the selection?
1273 bool bChangeSel
= lStart
!= lStartOld
||
1279 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1281 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1285 // TODO:: finish this part
1288 } // end of wxTextCtrl::SetStyle