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
124 pParent
->AddChild(this);
127 m_windowStyle
= lStyle
;
129 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
132 // Single and multiline edit fields are two different controls in PM
134 if ( m_windowStyle
& wxTE_MULTILINE
)
136 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
139 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
140 lSstyle
|= MLS_VSCROLL
;
141 if (m_windowStyle
& wxHSCROLL
)
142 lSstyle
|= MLS_HSCROLL
;
143 if (m_windowStyle
& wxTE_READONLY
)
144 lSstyle
|= MLS_READONLY
;
148 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
150 if (m_windowStyle
& wxHSCROLL
)
151 lSstyle
|= ES_AUTOSCROLL
;
152 if (m_windowStyle
& wxTE_READONLY
)
153 lSstyle
|= ES_READONLY
;
154 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
155 lSstyle
|= ES_UNREADABLE
;
158 // If the parent is a scrolled window the controls must
159 // have this style or they will overlap the scrollbars
162 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
163 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
164 lSstyle
|= WS_CLIPSIBLINGS
;
168 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
169 ,WC_MLE
// Window class
170 ,(PSZ
)rsValue
.c_str() // Initial Text
171 ,(ULONG
)lSstyle
// Style flags
172 ,(LONG
)0 // X pos of origin
173 ,(LONG
)0 // Y pos of origin
174 ,(LONG
)0 // field width
175 ,(LONG
)0 // field height
176 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
177 ,HWND_TOP
// initial z position
178 ,(ULONG
)vId
// Window identifier
179 ,NULL
// no control data
180 ,NULL
// no Presentation parameters
185 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
186 ,WC_ENTRYFIELD
// Window class
187 ,(PSZ
)rsValue
.c_str() // Initial Text
188 ,(ULONG
)lSstyle
// Style flags
189 ,(LONG
)0 // X pos of origin
190 ,(LONG
)0 // Y pos of origin
191 ,(LONG
)0 // field width
192 ,(LONG
)0 // field height
193 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
194 ,HWND_TOP
// initial z position
195 ,(ULONG
)vId
// Window identifier
196 ,NULL
// no control data
197 ,NULL
// no Presentation parameters
206 SubclassWin(GetHWND());
209 // Set font, position, size and initial value
211 SetFont(*wxSMALL_FONT
);
212 if (!rsValue
.IsEmpty())
218 // If X and/or Y are not zero the difference is the compensation value
219 // for margins for OS/2 controls.
221 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
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::GetColour(wxSYS_COLOUR_WINDOW
);
262 SetBackgroundColour(vBkgndColour
);
263 SetForegroundColour(GetParent()->GetForegroundColour());
266 ::WinSendMsg( GetHwnd()
268 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
272 } // end of wxTextCtrl::SetupColours
274 // ----------------------------------------------------------------------------
275 // set/get the controls text
276 // ----------------------------------------------------------------------------
278 wxString
wxTextCtrl::GetValue() const
280 wxString sStr
= wxGetWindowText(GetHWND());
281 char* zStr
= (char*)sStr
.c_str();
283 for ( ; *zStr
; zStr
++ )
286 // this will replace \r\n with just \n
295 } // end of wxTextCtrl::GetValue
297 void wxTextCtrl::SetValue(
298 const wxString
& rsValue
302 // If the text is long enough, it's faster to just set it instead of first
303 // comparing it with the old one (chances are that it will be different
304 // anyhow, this comparison is there to avoid flicker for small single-line
305 // edit controls mostly)
307 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
309 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
312 } // end of wxTextCtrl::SetValue
314 void wxTextCtrl::WriteText(
315 const wxString
& rsValue
318 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
320 } // end of wxTextCtrl::WriteText
322 void wxTextCtrl::AppendText(
323 const wxString
& rsText
326 SetInsertionPointEnd();
328 } // end of wxTextCtrl::AppendText
330 void wxTextCtrl::Clear()
332 ::WinSetWindowText(GetHwnd(), "");
333 } // end of wxTextCtrl::Clear
335 // ----------------------------------------------------------------------------
336 // Clipboard operations
337 // ----------------------------------------------------------------------------
339 void wxTextCtrl::Copy()
343 HWND hWnd
= GetHwnd();
345 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
347 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
349 } // end of wxTextCtrl::Copy
351 void wxTextCtrl::Cut()
355 HWND hWnd
= GetHwnd();
358 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
360 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
362 } // end of wxTextCtrl::Cut
364 void wxTextCtrl::Paste()
368 HWND hWnd
= GetHwnd();
370 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
372 } // end of wxTextCtrl::Paste
374 bool wxTextCtrl::CanCopy() const
377 // Can copy if there's a selection
382 GetSelection(&lFrom
, &lTo
);
383 return (lFrom
!= lTo
);
384 } // end of wxTextCtrl::CanCopy
386 bool wxTextCtrl::CanCut() const
389 // Can cut if there's a selection
394 GetSelection(&lFrom
, &lTo
);
395 return (lFrom
!= lTo
);
396 } // end of wxTextCtrl::CanCut
398 bool wxTextCtrl::CanPaste() const
400 bool bIsTextAvailable
= FALSE
;
406 // Check for straight text on clipboard
408 if (::WinOpenClipbrd(vHabmain
))
410 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
411 ::WinCloseClipbrd(vHabmain
);
413 return bIsTextAvailable
;
414 } // end of wxTextCtrl::CanPaste
416 // ----------------------------------------------------------------------------
418 // ----------------------------------------------------------------------------
420 void wxTextCtrl::SetEditable(
424 HWND hWnd
= GetHwnd();
427 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
429 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
430 } // end of wxTextCtrl::SetEditable
432 void wxTextCtrl::SetInsertionPoint(
436 HWND hWnd
= GetHwnd();
439 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
441 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
442 } // end of wxTextCtrl::SetInsertionPoint
444 void wxTextCtrl::SetInsertionPointEnd()
446 long lPos
= GetLastPosition();
448 SetInsertionPoint(lPos
);
449 } // end of wxTextCtrl::SetInsertionPointEnd
451 long wxTextCtrl::GetInsertionPoint() const
456 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
459 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
460 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
462 return (dwPos
& 0xFFFF);
463 } // end of wxTextCtrl::GetInsertionPoint
465 long wxTextCtrl::GetLastPosition() const
467 HWND hWnd
= GetHwnd();
476 // This just gets the total text length. The last will be this value
478 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
485 vParams
.fsStatus
= WPM_CCHTEXT
;
486 if (::WinSendMsg( GetHwnd()
487 ,WM_QUERYWINDOWPARAMS
492 lLineLength
= (long)vParams
.cchText
;
497 return(lCharIndex
+ lLineLength
);
498 } // end of wxTextCtrl::GetLastPosition
500 // If the return values from and to are the same, there is no
502 void wxTextCtrl::GetSelection(
510 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
513 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
515 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
516 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
517 } // end of wxTextCtrl::GetSelection
519 bool wxTextCtrl::IsEditable() const
522 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
524 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
525 } // end of wxTextCtrl::IsEditable
527 // ----------------------------------------------------------------------------
529 // ----------------------------------------------------------------------------
531 void wxTextCtrl::Replace(
534 , const wxString
& rsValue
538 HWND hWnd
= GetHwnd();
539 long lFromChar
= lFrom
;
543 // Set selection and remove it
547 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
548 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
552 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
553 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
557 // Now replace with 'value', by pasting.
559 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
561 // Paste into edit control
563 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
565 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
567 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
569 } // end of wxTextCtrl::Replace
571 void wxTextCtrl::Remove(
576 HWND hWnd
= GetHwnd();
577 long lFromChar
= lFrom
;
582 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
583 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
587 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
588 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
590 } // end of wxTextCtrl::Remove
592 void wxTextCtrl::SetSelection(
597 HWND hWnd
= GetHwnd();
598 long lFromChar
= lFrom
;
602 // If from and to are both -1, it means (in wxWindows) that all text should
603 // be selected. Translate into Windows convention
605 if ((lFrom
== -1L) && (lTo
== -1L))
611 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
613 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
614 } // end of wxTextCtrl::SetSelection
616 bool wxTextCtrl::LoadFile(
617 const wxString
& rsFile
620 if ( wxTextCtrlBase::LoadFile(rsFile
) )
623 // Update the size limit if needed
629 } // end of wxTextCtrl::LoadFile
631 bool wxTextCtrl::IsModified() const
636 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
638 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
640 } // end of wxTextCtrl::IsModified
643 // Makes 'unmodified'
645 void wxTextCtrl::DiscardEdits()
648 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
651 // EM controls do not have a SETCHANGED but issuing a query should reset it
653 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
654 } // end of wxTextCtrl::DiscardEdits
656 int wxTextCtrl::GetNumberOfLines() const
661 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
665 } // end of wxTextCtrl::GetNumberOfLines
667 long wxTextCtrl::XYToPosition(
672 HWND hWnd
= GetHwnd();
673 long lCharIndex
= 0L;
678 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
679 lCharIndex
= ((lLen
* lY
) + lX
);
684 } // end of wxTextCtrl::XYToPosition
686 bool wxTextCtrl::PositionToXY(
692 HWND hWnd
= GetHwnd();
697 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
708 // This gets the char index for the _beginning_ of this line
714 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
715 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
721 vParams
.fsStatus
= WPM_CCHTEXT
;
722 if (::WinSendMsg( hWnd
723 ,WM_QUERYWINDOWPARAMS
728 lCharIndex
= vParams
.cchText
;
734 if (lCharIndex
== -1)
740 // The X position must therefore be the difference between pos and charIndex
743 *plX
= lPos
- lCharIndex
;
748 } // end of wxTextCtrl::PositionToXY
750 void wxTextCtrl::ShowPosition(
754 HWND hWnd
= GetHwnd();
755 long lCurrentLineLineNo
= 0L;
757 // To scroll to a position, we pass the number of lines and characters
758 // to scroll *by*. This means that we need to:
759 // (1) Find the line position of the current line.
760 // (2) Find the line position of pos.
761 // (3) Scroll by (pos - current).
762 // For now, ignore the horizontal scrolling.
765 // Is this where scrolling is relative to - the line containing the caret?
766 // Or is the first visible line??? Try first visible line.
771 // In PM this is the actual char position
773 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
776 // This will cause a scroll to the selected position
778 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
780 } // end of wxTextCtrl::ShowPosition
782 int wxTextCtrl::GetLineLength(
789 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
794 vParams
.fsStatus
= WPM_CCHTEXT
;
795 if (::WinSendMsg( GetHwnd()
796 ,WM_QUERYWINDOWPARAMS
801 lLen
= vParams
.cchText
;
807 } // end ofwxTextCtrl::GetLineLength
809 wxString
wxTextCtrl::GetLineText(
813 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
818 // There must be at least enough place for the length WORD in the
821 lLen
+= sizeof(WORD
);
822 zBuf
= new char[lLen
];
829 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
830 lIndex
= lLen
* lLineNo
;
832 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
833 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
834 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
835 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
836 zBuf
[lCopied
] = '\0';
842 vParams
.fsStatus
= WPM_CCHTEXT
;
843 if (::WinSendMsg( GetHwnd()
844 ,WM_QUERYWINDOWPARAMS
848 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
849 zBuf
[vParams
.cchText
] = '\0';
854 } // end of wxTextCtrl::GetLineText
856 // ----------------------------------------------------------------------------
858 // ----------------------------------------------------------------------------
860 void wxTextCtrl::Undo()
865 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
866 // Simple entryfields cannot be undone
868 } // end of wxTextCtrl::Undo
870 void wxTextCtrl::Redo()
875 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
876 // Simple entryfields cannot be undone
878 } // end of wxTextCtrl::Redo
880 bool wxTextCtrl::CanUndo() const
885 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
887 bOk
= FALSE
; // can't undo regular edit fields in PM
889 } // end of wxTextCtrl::CanUndo
891 bool wxTextCtrl::CanRedo() const
896 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
898 bOk
= FALSE
; // can't undo regular edit fields in PM
900 } // end of wxTextCtrl::CanRedo
902 // ----------------------------------------------------------------------------
903 // implemenation details
904 // ----------------------------------------------------------------------------
906 void wxTextCtrl::Command(
907 wxCommandEvent
& rEvent
910 SetValue(rEvent
.GetString());
911 ProcessCommand (rEvent
);
912 } // end of wxTextCtrl::Command
914 void wxTextCtrl::OnDropFiles(
915 wxDropFilesEvent
& rEvent
918 // By default, load the first file into the text window.
919 if (rEvent
.GetNumberOfFiles() > 0)
921 LoadFile(rEvent
.GetFiles()[0]);
923 } // end of wxTextCtrl::OnDropFiles
925 WXHBRUSH
wxTextCtrl::OnCtlColor(
934 HPS hPS
= (HPS
)hWxDC
;
935 wxBrush
* pBrush
= NULL
;
936 wxColour vColBack
= GetBackgroundColour();
937 wxColour vColFore
= GetForegroundColour();
938 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
944 HBRUSH hBrush
= NULLHANDLE
;
948 if (GetParent()->GetTransparentBackground())
949 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
951 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
952 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
953 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
954 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
955 ::GpiSetColor(hPS
, vColFore
.GetPixel());
956 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
957 } // end of wxTextCtrl::OnCtlColor
959 bool wxTextCtrl::OS2ShouldPreProcessMessage(
963 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
964 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
966 void wxTextCtrl::OnChar(
970 switch (rEvent
.KeyCode())
973 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
975 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
977 vEvent
.SetEventObject(this);
978 if ( GetEventHandler()->ProcessEvent(vEvent
))
981 //else: multiline controls need Enter for themselves
986 // always produce navigation event - even if we process TAB
987 // ourselves the fact that we got here means that the user code
988 // decided to skip processing of this TAB - probably to let it
989 // do its default job.
991 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
992 // handled by Windows
994 wxNavigationKeyEvent vEventNav
;
996 vEventNav
.SetDirection(!rEvent
.ShiftDown());
997 vEventNav
.SetWindowChange(FALSE
);
998 vEventNav
.SetEventObject(this);
1000 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1006 } // end of wxTextCtrl::OnChar
1008 bool wxTextCtrl::OS2Command(
1010 , WXWORD
WXUNUSED(vId
)
1018 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1023 vEvent
.SetEventObject(this);
1024 GetEventHandler()->ProcessEvent(vEvent
);
1030 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1034 InitCommandEvent(vEvent
);
1035 vEvent
.SetString((char*)GetValue().c_str());
1036 ProcessCommand(vEvent
);
1042 // The text size limit has been hit - increase it
1048 case EN_INSERTMODETOGGLE
:
1059 } // end of wxTextCtrl::OS2Command
1061 void wxTextCtrl::AdjustSpaceLimit()
1063 unsigned int uLen
= 0;
1064 unsigned int uLimit
= 0;
1066 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1069 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1080 vParams
.fsStatus
= WPM_CBCTLDATA
;
1081 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1083 if (::WinSendMsg( GetHwnd()
1084 ,WM_QUERYWINDOWPARAMS
1089 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1090 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1093 uLimit
= 32; //PM's default
1097 uLimit
= uLen
+ 0x8000; // 32Kb
1098 if (uLimit
> 0xffff)
1103 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1105 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1107 } // end of wxTextCtrl::AdjustSpaceLimit
1109 bool wxTextCtrl::AcceptsFocus() const
1112 // We don't want focus if we can't be edited
1114 return IsEditable() && wxControl::AcceptsFocus();
1115 } // end of wxTextCtrl::Command
1117 wxSize
wxTextCtrl::DoGetBestSize() const
1122 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1124 int wText
= DEFAULT_ITEM_WIDTH
;
1125 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1127 if (m_windowStyle
& wxTE_MULTILINE
)
1129 hText
*= wxMin(GetNumberOfLines(), 5);
1131 //else: for single line control everything is ok
1132 return wxSize(wText
, hText
);
1133 } // end of wxTextCtrl::DoGetBestSize
1135 // ----------------------------------------------------------------------------
1136 // standard handlers for standard edit menu events
1137 // ----------------------------------------------------------------------------
1139 void wxTextCtrl::OnCut(
1140 wxCommandEvent
& rEvent
1144 } // end of wxTextCtrl::OnCut
1146 void wxTextCtrl::OnCopy(
1147 wxCommandEvent
& rEvent
1151 } // end of wxTextCtrl::OnCopy
1153 void wxTextCtrl::OnPaste(
1154 wxCommandEvent
& rEvent
1158 } // end of wxTextCtrl::OnPaste
1160 void wxTextCtrl::OnUndo(
1161 wxCommandEvent
& rEvent
1165 } // end of wxTextCtrl::OnUndo
1167 void wxTextCtrl::OnRedo(
1168 wxCommandEvent
& rEvent
1172 } // end of wxTextCtrl::OnRedo
1174 void wxTextCtrl::OnUpdateCut(
1175 wxUpdateUIEvent
& rEvent
1178 rEvent
.Enable(CanCut());
1179 } // end of wxTextCtrl::OnUpdateCut
1181 void wxTextCtrl::OnUpdateCopy(
1182 wxUpdateUIEvent
& rEvent
1185 rEvent
.Enable(CanCopy());
1186 } // end of wxTextCtrl::OnUpdateCopy
1188 void wxTextCtrl::OnUpdatePaste(
1189 wxUpdateUIEvent
& rEvent
1192 rEvent
.Enable(CanPaste());
1193 } // end of wxTextCtrl::OnUpdatePaste
1195 void wxTextCtrl::OnUpdateUndo(
1196 wxUpdateUIEvent
& rEvent
1199 rEvent
.Enable(CanUndo());
1200 } // end of wxTextCtrl::OnUpdateUndo
1202 void wxTextCtrl::OnUpdateRedo(
1203 wxUpdateUIEvent
& rEvent
1206 rEvent
.Enable(CanRedo());
1207 } // end of wxTextCtrl::OnUpdateRedo
1209 bool wxTextCtrl::SetBackgroundColour(
1210 const wxColour
& rColour
1214 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1216 } // end of wxTextCtrl::SetBackgroundColour
1218 bool wxTextCtrl::SetForegroundColour(
1219 const wxColour
& rColour
1223 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1225 } // end of wxTextCtrl::SetForegroundColour
1227 bool wxTextCtrl::SetStyle(
1230 , const wxTextAttr
& rStyle
1233 HWND hWnd
= GetHwnd();
1244 // We can only change the format of the selection, so select the range we
1245 // want and restore the old selection later
1250 GetSelection( &lStartOld
1255 // But do we really have to change the selection?
1257 bool bChangeSel
= lStart
!= lStartOld
||
1263 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1265 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1269 // TODO:: finish this part
1272 } // end of wxTextCtrl::SetStyle