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 wxTextCtrl::~wxTextCtrl()
93 bool wxTextCtrl::Create(
96 , const wxString
& rsValue
101 , const wxValidator
& rValidator
103 , const wxString
& rsName
110 // Base initialization
112 if ( !CreateBase( pParent
124 wxPoint vPos
= rPos
; // The OS/2 position
129 pParent
->AddChild(this);
132 m_windowStyle
= lStyle
;
135 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
138 // Single and multiline edit fields are two different controls in PM
140 if ( m_windowStyle
& wxTE_MULTILINE
)
142 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
145 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
146 lSstyle
|= MLS_VSCROLL
;
147 if (m_windowStyle
& wxHSCROLL
)
148 lSstyle
|= MLS_HSCROLL
;
149 if (m_windowStyle
& wxTE_READONLY
)
150 lSstyle
|= MLS_READONLY
;
154 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
156 if (m_windowStyle
& wxHSCROLL
)
157 lSstyle
|= ES_AUTOSCROLL
;
158 if (m_windowStyle
& wxTE_READONLY
)
159 lSstyle
|= ES_READONLY
;
160 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
161 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
* pTextFont
= new wxFont( 8
215 if (!rsValue
.IsEmpty())
221 // If X and/or Y are not zero the difference is the compensation value
222 // for margins for OS/2 controls.
224 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
227 SetSize( vPos
.x
- GetXComp()
234 } // end of wxTextCtrl::Create
237 // Make sure the window style (etc.) reflects the HWND style (roughly)
239 void wxTextCtrl::AdoptAttributesFromHWND()
241 HWND hWnd
= GetHwnd();
242 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
244 wxWindow::AdoptAttributesFromHWND();
248 m_windowStyle
|= wxTE_MULTILINE
;
249 if (lStyle
& MLS_READONLY
)
250 m_windowStyle
|= wxTE_READONLY
;
254 if (lStyle
& ES_UNREADABLE
)
255 m_windowStyle
|= wxTE_PASSWORD
;
256 if (lStyle
& ES_READONLY
)
257 m_windowStyle
|= wxTE_READONLY
;
259 } // end of wxTextCtrl::AdoptAttributesFromHWND
261 WXDWORD
wxTextCtrl::OS2GetStyle(
263 , WXDWORD
* pdwExstyle
267 // Default border for the text controls is the sunken one
269 if ((lStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
271 lStyle
|= wxBORDER_SUNKEN
;
274 long dwStyle
= wxControl::OS2GetStyle( lStyle
278 dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
281 // Single and multiline edit fields are two different controls in PM
283 if ( m_windowStyle
& wxTE_MULTILINE
)
285 dwStyle
|= MLS_BORDER
| MLS_WORDWRAP
;
286 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
287 dwStyle
|= MLS_VSCROLL
;
288 if (m_windowStyle
& wxHSCROLL
)
289 dwStyle
|= MLS_HSCROLL
;
290 if (m_windowStyle
& wxTE_READONLY
)
291 dwStyle
|= MLS_READONLY
;
295 dwStyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
296 if (m_windowStyle
& wxHSCROLL
)
297 dwStyle
|= ES_AUTOSCROLL
;
298 if (m_windowStyle
& wxTE_READONLY
)
299 dwStyle
|= ES_READONLY
;
300 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
301 dwStyle
|= ES_UNREADABLE
;
304 } // end of wxTextCtrl::OS2GetStyle
306 void wxTextCtrl::SetWindowStyleFlag(
310 wxControl::SetWindowStyleFlag(lStyle
);
311 } // end of wxTextCtrl::SetWindowStyleFlag
313 void wxTextCtrl::SetupColours()
315 wxColour vBkgndColour
;
317 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
318 SetBackgroundColour(vBkgndColour
);
319 SetForegroundColour(GetParent()->GetForegroundColour());
322 ::WinSendMsg( GetHwnd()
324 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
328 } // end of wxTextCtrl::SetupColours
330 // ----------------------------------------------------------------------------
331 // set/get the controls text
332 // ----------------------------------------------------------------------------
334 wxString
wxTextCtrl::GetValue() const
336 wxString sStr
= wxGetWindowText(GetHWND());
337 char* zStr
= (char*)sStr
.c_str();
339 for ( ; *zStr
; zStr
++ )
342 // this will replace \r\n with just \n
350 } // end of wxTextCtrl::GetValue
352 void wxTextCtrl::SetValue(
353 const wxString
& rsValue
357 // If the text is long enough, it's faster to just set it instead of first
358 // comparing it with the old one (chances are that it will be different
359 // anyhow, this comparison is there to avoid flicker for small single-line
360 // edit controls mostly)
362 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
364 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
367 } // end of wxTextCtrl::SetValue
369 void wxTextCtrl::WriteText(
370 const wxString
& rsValue
374 ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM((PCHAR
)rsValue
.c_str()), MPARAM(0));
376 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
378 } // end of wxTextCtrl::WriteText
380 void wxTextCtrl::AppendText(
381 const wxString
& rsText
384 SetInsertionPointEnd();
386 } // end of wxTextCtrl::AppendText
388 void wxTextCtrl::Clear()
390 ::WinSetWindowText(GetHwnd(), "");
391 } // end of wxTextCtrl::Clear
393 bool wxTextCtrl::EmulateKeyPress(
394 const wxKeyEvent
& rEvent
398 return(wxTextCtrlBase::EmulateKeyPress(rEvent
));
399 } // end of wxTextCtrl::EmulateKeyPress
401 // ----------------------------------------------------------------------------
402 // Clipboard operations
403 // ----------------------------------------------------------------------------
405 void wxTextCtrl::Copy()
409 HWND hWnd
= GetHwnd();
411 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
413 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
415 } // end of wxTextCtrl::Copy
417 void wxTextCtrl::Cut()
421 HWND hWnd
= GetHwnd();
424 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
426 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
428 } // end of wxTextCtrl::Cut
430 void wxTextCtrl::Paste()
434 HWND hWnd
= GetHwnd();
436 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
438 } // end of wxTextCtrl::Paste
440 bool wxTextCtrl::CanCopy() const
443 // Can copy if there's a selection
448 GetSelection(&lFrom
, &lTo
);
449 return (lFrom
!= lTo
);
450 } // end of wxTextCtrl::CanCopy
452 bool wxTextCtrl::CanCut() const
455 // Can cut if there's a selection
460 GetSelection(&lFrom
, &lTo
);
461 return (lFrom
!= lTo
);
462 } // end of wxTextCtrl::CanCut
464 bool wxTextCtrl::CanPaste() const
466 bool bIsTextAvailable
= FALSE
;
472 // Check for straight text on clipboard
474 if (::WinOpenClipbrd(vHabmain
))
476 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
477 ::WinCloseClipbrd(vHabmain
);
479 return bIsTextAvailable
;
480 } // end of wxTextCtrl::CanPaste
482 // ----------------------------------------------------------------------------
484 // ----------------------------------------------------------------------------
486 void wxTextCtrl::SetEditable(
490 HWND hWnd
= GetHwnd();
493 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
495 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
496 } // end of wxTextCtrl::SetEditable
498 void wxTextCtrl::SetInsertionPoint(
502 HWND hWnd
= GetHwnd();
505 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
507 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
508 } // end of wxTextCtrl::SetInsertionPoint
510 void wxTextCtrl::SetInsertionPointEnd()
512 long lPos
= GetLastPosition();
514 SetInsertionPoint(lPos
);
515 } // end of wxTextCtrl::SetInsertionPointEnd
517 long wxTextCtrl::GetInsertionPoint() const
522 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
525 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
526 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
528 return (dwPos
& 0xFFFF);
529 } // end of wxTextCtrl::GetInsertionPoint
531 long wxTextCtrl::GetLastPosition() const
533 HWND hWnd
= GetHwnd();
542 // This just gets the total text length. The last will be this value
544 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
551 vParams
.fsStatus
= WPM_CCHTEXT
;
552 if (::WinSendMsg( GetHwnd()
553 ,WM_QUERYWINDOWPARAMS
558 lLineLength
= (long)vParams
.cchText
;
563 return(lCharIndex
+ lLineLength
);
564 } // end of wxTextCtrl::GetLastPosition
566 // If the return values from and to are the same, there is no
568 void wxTextCtrl::GetSelection(
576 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
579 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
581 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
582 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
583 } // end of wxTextCtrl::GetSelection
585 bool wxTextCtrl::IsEditable() const
588 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
590 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
591 } // end of wxTextCtrl::IsEditable
593 // ----------------------------------------------------------------------------
595 // ----------------------------------------------------------------------------
597 void wxTextCtrl::Replace(
600 , const wxString
& rsValue
604 HWND hWnd
= GetHwnd();
605 long lFromChar
= lFrom
;
609 // Set selection and remove it
613 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
614 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
618 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
619 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
623 // Now replace with 'value', by pasting.
625 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
627 // Paste into edit control
629 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
631 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
633 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
635 } // end of wxTextCtrl::Replace
637 void wxTextCtrl::Remove(
642 HWND hWnd
= GetHwnd();
643 long lFromChar
= lFrom
;
648 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
649 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
653 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
654 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
656 } // end of wxTextCtrl::Remove
658 void wxTextCtrl::SetSelection(
663 HWND hWnd
= GetHwnd();
664 long lFromChar
= lFrom
;
668 // If from and to are both -1, it means (in wxWindows) that all text should
669 // be selected. Translate into Windows convention
671 if ((lFrom
== -1L) && (lTo
== -1L))
677 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
679 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
680 } // end of wxTextCtrl::SetSelection
682 bool wxTextCtrl::LoadFile(
683 const wxString
& rsFile
686 if ( wxTextCtrlBase::LoadFile(rsFile
) )
689 // Update the size limit if needed
695 } // end of wxTextCtrl::LoadFile
697 bool wxTextCtrl::IsModified() const
702 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
704 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
706 } // end of wxTextCtrl::IsModified
709 // Makes 'unmodified'
711 void wxTextCtrl::DiscardEdits()
714 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
717 // EM controls do not have a SETCHANGED but issuing a query should reset it
719 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
720 } // end of wxTextCtrl::DiscardEdits
722 int wxTextCtrl::GetNumberOfLines() const
727 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
731 } // end of wxTextCtrl::GetNumberOfLines
733 long wxTextCtrl::XYToPosition(
738 HWND hWnd
= GetHwnd();
739 long lCharIndex
= 0L;
744 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
745 lCharIndex
= ((lLen
* lY
) + lX
);
750 } // end of wxTextCtrl::XYToPosition
752 bool wxTextCtrl::PositionToXY(
758 HWND hWnd
= GetHwnd();
763 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
774 // This gets the char index for the _beginning_ of this line
780 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
781 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
787 vParams
.fsStatus
= WPM_CCHTEXT
;
788 if (::WinSendMsg( hWnd
789 ,WM_QUERYWINDOWPARAMS
794 lCharIndex
= vParams
.cchText
;
800 if (lCharIndex
== -1)
806 // The X position must therefore be the difference between pos and charIndex
809 *plX
= lPos
- lCharIndex
;
814 } // end of wxTextCtrl::PositionToXY
816 void wxTextCtrl::ShowPosition(
820 HWND hWnd
= GetHwnd();
821 long lCurrentLineLineNo
= 0L;
823 // To scroll to a position, we pass the number of lines and characters
824 // to scroll *by*. This means that we need to:
825 // (1) Find the line position of the current line.
826 // (2) Find the line position of pos.
827 // (3) Scroll by (pos - current).
828 // For now, ignore the horizontal scrolling.
831 // Is this where scrolling is relative to - the line containing the caret?
832 // Or is the first visible line??? Try first visible line.
837 // In PM this is the actual char position
839 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
842 // This will cause a scroll to the selected position
844 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
846 } // end of wxTextCtrl::ShowPosition
848 int wxTextCtrl::GetLineLength(
855 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
860 vParams
.fsStatus
= WPM_CCHTEXT
;
861 if (::WinSendMsg( GetHwnd()
862 ,WM_QUERYWINDOWPARAMS
867 lLen
= vParams
.cchText
;
873 } // end ofwxTextCtrl::GetLineLength
875 wxString
wxTextCtrl::GetLineText(
879 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
884 // There must be at least enough place for the length WORD in the
887 lLen
+= sizeof(WORD
);
888 zBuf
= new char[lLen
];
895 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
896 lIndex
= lLen
* lLineNo
;
898 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
899 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
900 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
901 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
902 zBuf
[lCopied
] = '\0';
908 vParams
.fsStatus
= WPM_CCHTEXT
;
909 if (::WinSendMsg( GetHwnd()
910 ,WM_QUERYWINDOWPARAMS
914 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
915 zBuf
[vParams
.cchText
] = '\0';
920 } // end of wxTextCtrl::GetLineText
922 // ----------------------------------------------------------------------------
924 // ----------------------------------------------------------------------------
926 void wxTextCtrl::Undo()
931 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
932 // Simple entryfields cannot be undone
934 } // end of wxTextCtrl::Undo
936 void wxTextCtrl::Redo()
941 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
942 // Simple entryfields cannot be undone
944 } // end of wxTextCtrl::Redo
946 bool wxTextCtrl::CanUndo() const
951 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
953 bOk
= FALSE
; // can't undo regular edit fields in PM
955 } // end of wxTextCtrl::CanUndo
957 bool wxTextCtrl::CanRedo() const
962 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
964 bOk
= FALSE
; // can't undo regular edit fields in PM
966 } // end of wxTextCtrl::CanRedo
968 // ----------------------------------------------------------------------------
969 // implemenation details
970 // ----------------------------------------------------------------------------
972 void wxTextCtrl::Command(
973 wxCommandEvent
& rEvent
976 SetValue(rEvent
.GetString());
977 ProcessCommand (rEvent
);
978 } // end of wxTextCtrl::Command
980 void wxTextCtrl::OnDropFiles(
981 wxDropFilesEvent
& rEvent
984 // By default, load the first file into the text window.
985 if (rEvent
.GetNumberOfFiles() > 0)
987 LoadFile(rEvent
.GetFiles()[0]);
989 } // end of wxTextCtrl::OnDropFiles
991 WXHBRUSH
wxTextCtrl::OnCtlColor(
1000 HPS hPS
= (HPS
)hWxDC
;
1001 wxBrush
* pBrush
= NULL
;
1002 wxColour vColBack
= GetBackgroundColour();
1003 wxColour vColFore
= GetForegroundColour();
1004 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
1010 HBRUSH hBrush
= NULLHANDLE
;
1014 if (GetParent()->GetTransparentBackground())
1015 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1017 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1018 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1019 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1020 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1021 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1022 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1023 } // end of wxTextCtrl::OnCtlColor
1025 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1029 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1030 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1032 void wxTextCtrl::OnChar(
1036 switch (rEvent
.KeyCode())
1039 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1041 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1043 vEvent
.SetEventObject(this);
1044 if ( GetEventHandler()->ProcessEvent(vEvent
))
1047 //else: multiline controls need Enter for themselves
1052 // always produce navigation event - even if we process TAB
1053 // ourselves the fact that we got here means that the user code
1054 // decided to skip processing of this TAB - probably to let it
1055 // do its default job.
1057 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1058 // handled by Windows
1060 wxNavigationKeyEvent vEventNav
;
1062 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1063 vEventNav
.SetWindowChange(FALSE
);
1064 vEventNav
.SetEventObject(this);
1066 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1072 } // end of wxTextCtrl::OnChar
1074 bool wxTextCtrl::OS2Command(
1076 , WXWORD
WXUNUSED(vId
)
1084 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1089 vEvent
.SetEventObject(this);
1090 GetEventHandler()->ProcessEvent(vEvent
);
1096 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1100 InitCommandEvent(vEvent
);
1101 vEvent
.SetString((char*)GetValue().c_str());
1102 ProcessCommand(vEvent
);
1108 // The text size limit has been hit - increase it
1114 case EN_INSERTMODETOGGLE
:
1125 } // end of wxTextCtrl::OS2Command
1127 void wxTextCtrl::AdjustSpaceLimit()
1129 unsigned int uLen
= 0;
1130 unsigned int uLimit
= 0;
1132 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1135 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1146 vParams
.fsStatus
= WPM_CBCTLDATA
;
1147 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1149 if (::WinSendMsg( GetHwnd()
1150 ,WM_QUERYWINDOWPARAMS
1155 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1156 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1159 uLimit
= 32; //PM's default
1163 uLimit
= uLen
+ 0x8000; // 32Kb
1164 if (uLimit
> 0xffff)
1169 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1171 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1173 } // end of wxTextCtrl::AdjustSpaceLimit
1175 bool wxTextCtrl::AcceptsFocus() const
1178 // We don't want focus if we can't be edited
1180 return IsEditable() && wxControl::AcceptsFocus();
1181 } // end of wxTextCtrl::Command
1183 wxSize
wxTextCtrl::DoGetBestSize() const
1188 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1190 int wText
= DEFAULT_ITEM_WIDTH
;
1191 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1193 if (m_windowStyle
& wxTE_MULTILINE
)
1195 hText
*= wxMax(GetNumberOfLines(), 5);
1197 //else: for single line control everything is ok
1198 return wxSize(wText
, hText
);
1199 } // end of wxTextCtrl::DoGetBestSize
1201 // ----------------------------------------------------------------------------
1202 // standard handlers for standard edit menu events
1203 // ----------------------------------------------------------------------------
1205 void wxTextCtrl::OnCut(
1206 wxCommandEvent
& rEvent
1210 } // end of wxTextCtrl::OnCut
1212 void wxTextCtrl::OnCopy(
1213 wxCommandEvent
& rEvent
1217 } // end of wxTextCtrl::OnCopy
1219 void wxTextCtrl::OnPaste(
1220 wxCommandEvent
& rEvent
1224 } // end of wxTextCtrl::OnPaste
1226 void wxTextCtrl::OnUndo(
1227 wxCommandEvent
& rEvent
1231 } // end of wxTextCtrl::OnUndo
1233 void wxTextCtrl::OnRedo(
1234 wxCommandEvent
& rEvent
1238 } // end of wxTextCtrl::OnRedo
1240 void wxTextCtrl::OnDelete(
1241 wxCommandEvent
& rEvent
1247 GetSelection( &lFrom
1250 if (lFrom
!= -1 && lTo
!= -1)
1254 } // end of wxTextCtrl::OnDelete
1256 void wxTextCtrl::OnSelectAll(
1257 wxCommandEvent
& rEvent
1260 SetSelection(-1, -1);
1261 } // end of wxTextCtrl::OnSelectAll
1263 void wxTextCtrl::OnUpdateCut(
1264 wxUpdateUIEvent
& rEvent
1267 rEvent
.Enable(CanCut());
1268 } // end of wxTextCtrl::OnUpdateCut
1270 void wxTextCtrl::OnUpdateCopy(
1271 wxUpdateUIEvent
& rEvent
1274 rEvent
.Enable(CanCopy());
1275 } // end of wxTextCtrl::OnUpdateCopy
1277 void wxTextCtrl::OnUpdatePaste(
1278 wxUpdateUIEvent
& rEvent
1281 rEvent
.Enable(CanPaste());
1282 } // end of wxTextCtrl::OnUpdatePaste
1284 void wxTextCtrl::OnUpdateUndo(
1285 wxUpdateUIEvent
& rEvent
1288 rEvent
.Enable(CanUndo());
1289 } // end of wxTextCtrl::OnUpdateUndo
1291 void wxTextCtrl::OnUpdateRedo(
1292 wxUpdateUIEvent
& rEvent
1295 rEvent
.Enable(CanRedo());
1296 } // end of wxTextCtrl::OnUpdateRedo
1298 void wxTextCtrl::OnUpdateDelete(
1299 wxUpdateUIEvent
& rEvent
1305 GetSelection( &lFrom
1308 rEvent
.Enable( lFrom
!= -1L && lTo
!= -1L && lFrom
!= lTo
&& IsEditable()) ;
1309 } // end of wxTextCtrl::OnUpdateDelete
1311 void wxTextCtrl::OnUpdateSelectAll(
1312 wxUpdateUIEvent
& rEvent
1315 rEvent
.Enable(GetLastPosition() > 0);
1316 } // end of wxTextCtrl::OnUpdateSelectAll
1318 bool wxTextCtrl::SetBackgroundColour(
1319 const wxColour
& rColour
1323 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1325 } // end of wxTextCtrl::SetBackgroundColour
1327 bool wxTextCtrl::SetForegroundColour(
1328 const wxColour
& rColour
1332 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1334 } // end of wxTextCtrl::SetForegroundColour
1336 bool wxTextCtrl::SetStyle(
1339 , const wxTextAttr
& rStyle
1342 HWND hWnd
= GetHwnd();
1353 // We can only change the format of the selection, so select the range we
1354 // want and restore the old selection later
1359 GetSelection( &lStartOld
1364 // But do we really have to change the selection?
1366 bool bChangeSel
= lStart
!= lStartOld
||
1372 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1374 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1378 // TODO:: finish this part
1381 } // end of wxTextCtrl::SetStyle