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 wxFont
* pTextFont
= new wxFont( 10
217 if (!rsValue
.IsEmpty())
223 // If X and/or Y are not zero the difference is the compensation value
224 // for margins for OS/2 controls.
226 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
235 } // end of wxTextCtrl::Create
238 // Make sure the window style (etc.) reflects the HWND style (roughly)
240 void wxTextCtrl::AdoptAttributesFromHWND()
242 HWND hWnd
= GetHwnd();
243 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
245 wxWindow::AdoptAttributesFromHWND();
249 m_windowStyle
|= wxTE_MULTILINE
;
250 if (lStyle
& MLS_READONLY
)
251 m_windowStyle
|= wxTE_READONLY
;
255 if (lStyle
& ES_UNREADABLE
)
256 m_windowStyle
|= wxTE_PASSWORD
;
257 if (lStyle
& ES_READONLY
)
258 m_windowStyle
|= wxTE_READONLY
;
260 } // end of wxTextCtrl::AdoptAttributesFromHWND
262 void wxTextCtrl::SetupColours()
264 wxColour vBkgndColour
;
266 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
267 SetBackgroundColour(vBkgndColour
);
268 SetForegroundColour(GetParent()->GetForegroundColour());
271 ::WinSendMsg( GetHwnd()
273 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
277 } // end of wxTextCtrl::SetupColours
279 // ----------------------------------------------------------------------------
280 // set/get the controls text
281 // ----------------------------------------------------------------------------
283 wxString
wxTextCtrl::GetValue() const
285 wxString sStr
= wxGetWindowText(GetHWND());
286 char* zStr
= (char*)sStr
.c_str();
288 for ( ; *zStr
; zStr
++ )
291 // this will replace \r\n with just \n
300 } // end of wxTextCtrl::GetValue
302 void wxTextCtrl::SetValue(
303 const wxString
& rsValue
307 // If the text is long enough, it's faster to just set it instead of first
308 // comparing it with the old one (chances are that it will be different
309 // anyhow, this comparison is there to avoid flicker for small single-line
310 // edit controls mostly)
312 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
314 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
317 } // end of wxTextCtrl::SetValue
319 void wxTextCtrl::WriteText(
320 const wxString
& rsValue
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::LoadFile(
622 const wxString
& rsFile
625 if ( wxTextCtrlBase::LoadFile(rsFile
) )
628 // Update the size limit if needed
634 } // end of wxTextCtrl::LoadFile
636 bool wxTextCtrl::IsModified() const
641 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
643 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
645 } // end of wxTextCtrl::IsModified
648 // Makes 'unmodified'
650 void wxTextCtrl::DiscardEdits()
653 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
656 // EM controls do not have a SETCHANGED but issuing a query should reset it
658 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
659 } // end of wxTextCtrl::DiscardEdits
661 int wxTextCtrl::GetNumberOfLines() const
666 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
670 } // end of wxTextCtrl::GetNumberOfLines
672 long wxTextCtrl::XYToPosition(
677 HWND hWnd
= GetHwnd();
678 long lCharIndex
= 0L;
683 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
684 lCharIndex
= ((lLen
* lY
) + lX
);
689 } // end of wxTextCtrl::XYToPosition
691 bool wxTextCtrl::PositionToXY(
697 HWND hWnd
= GetHwnd();
702 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
713 // This gets the char index for the _beginning_ of this line
719 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
720 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
726 vParams
.fsStatus
= WPM_CCHTEXT
;
727 if (::WinSendMsg( hWnd
728 ,WM_QUERYWINDOWPARAMS
733 lCharIndex
= vParams
.cchText
;
739 if (lCharIndex
== -1)
745 // The X position must therefore be the difference between pos and charIndex
748 *plX
= lPos
- lCharIndex
;
753 } // end of wxTextCtrl::PositionToXY
755 void wxTextCtrl::ShowPosition(
759 HWND hWnd
= GetHwnd();
760 long lCurrentLineLineNo
= 0L;
762 // To scroll to a position, we pass the number of lines and characters
763 // to scroll *by*. This means that we need to:
764 // (1) Find the line position of the current line.
765 // (2) Find the line position of pos.
766 // (3) Scroll by (pos - current).
767 // For now, ignore the horizontal scrolling.
770 // Is this where scrolling is relative to - the line containing the caret?
771 // Or is the first visible line??? Try first visible line.
776 // In PM this is the actual char position
778 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
781 // This will cause a scroll to the selected position
783 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
785 } // end of wxTextCtrl::ShowPosition
787 int wxTextCtrl::GetLineLength(
794 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
799 vParams
.fsStatus
= WPM_CCHTEXT
;
800 if (::WinSendMsg( GetHwnd()
801 ,WM_QUERYWINDOWPARAMS
806 lLen
= vParams
.cchText
;
812 } // end ofwxTextCtrl::GetLineLength
814 wxString
wxTextCtrl::GetLineText(
818 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
823 // There must be at least enough place for the length WORD in the
826 lLen
+= sizeof(WORD
);
827 zBuf
= new char[lLen
];
834 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
835 lIndex
= lLen
* lLineNo
;
837 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
838 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
839 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
840 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
841 zBuf
[lCopied
] = '\0';
847 vParams
.fsStatus
= WPM_CCHTEXT
;
848 if (::WinSendMsg( GetHwnd()
849 ,WM_QUERYWINDOWPARAMS
853 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
854 zBuf
[vParams
.cchText
] = '\0';
859 } // end of wxTextCtrl::GetLineText
861 // ----------------------------------------------------------------------------
863 // ----------------------------------------------------------------------------
865 void wxTextCtrl::Undo()
870 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
871 // Simple entryfields cannot be undone
873 } // end of wxTextCtrl::Undo
875 void wxTextCtrl::Redo()
880 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
881 // Simple entryfields cannot be undone
883 } // end of wxTextCtrl::Redo
885 bool wxTextCtrl::CanUndo() const
890 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
892 bOk
= FALSE
; // can't undo regular edit fields in PM
894 } // end of wxTextCtrl::CanUndo
896 bool wxTextCtrl::CanRedo() const
901 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
903 bOk
= FALSE
; // can't undo regular edit fields in PM
905 } // end of wxTextCtrl::CanRedo
907 // ----------------------------------------------------------------------------
908 // implemenation details
909 // ----------------------------------------------------------------------------
911 void wxTextCtrl::Command(
912 wxCommandEvent
& rEvent
915 SetValue(rEvent
.GetString());
916 ProcessCommand (rEvent
);
917 } // end of wxTextCtrl::Command
919 void wxTextCtrl::OnDropFiles(
920 wxDropFilesEvent
& rEvent
923 // By default, load the first file into the text window.
924 if (rEvent
.GetNumberOfFiles() > 0)
926 LoadFile(rEvent
.GetFiles()[0]);
928 } // end of wxTextCtrl::OnDropFiles
930 WXHBRUSH
wxTextCtrl::OnCtlColor(
939 HPS hPS
= (HPS
)hWxDC
;
940 wxBrush
* pBrush
= NULL
;
941 wxColour vColBack
= GetBackgroundColour();
942 wxColour vColFore
= GetForegroundColour();
943 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
949 HBRUSH hBrush
= NULLHANDLE
;
953 if (GetParent()->GetTransparentBackground())
954 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
956 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
957 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
958 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
959 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
960 ::GpiSetColor(hPS
, vColFore
.GetPixel());
961 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
962 } // end of wxTextCtrl::OnCtlColor
964 bool wxTextCtrl::OS2ShouldPreProcessMessage(
968 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
969 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
971 void wxTextCtrl::OnChar(
975 switch (rEvent
.KeyCode())
978 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
980 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
982 vEvent
.SetEventObject(this);
983 if ( GetEventHandler()->ProcessEvent(vEvent
))
986 //else: multiline controls need Enter for themselves
991 // always produce navigation event - even if we process TAB
992 // ourselves the fact that we got here means that the user code
993 // decided to skip processing of this TAB - probably to let it
994 // do its default job.
996 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
997 // handled by Windows
999 wxNavigationKeyEvent vEventNav
;
1001 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1002 vEventNav
.SetWindowChange(FALSE
);
1003 vEventNav
.SetEventObject(this);
1005 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1011 } // end of wxTextCtrl::OnChar
1013 bool wxTextCtrl::OS2Command(
1015 , WXWORD
WXUNUSED(vId
)
1023 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1028 vEvent
.SetEventObject(this);
1029 GetEventHandler()->ProcessEvent(vEvent
);
1035 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1039 InitCommandEvent(vEvent
);
1040 vEvent
.SetString((char*)GetValue().c_str());
1041 ProcessCommand(vEvent
);
1047 // The text size limit has been hit - increase it
1053 case EN_INSERTMODETOGGLE
:
1064 } // end of wxTextCtrl::OS2Command
1066 void wxTextCtrl::AdjustSpaceLimit()
1068 unsigned int uLen
= 0;
1069 unsigned int uLimit
= 0;
1071 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1074 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1085 vParams
.fsStatus
= WPM_CBCTLDATA
;
1086 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1088 if (::WinSendMsg( GetHwnd()
1089 ,WM_QUERYWINDOWPARAMS
1094 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1095 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1098 uLimit
= 32; //PM's default
1102 uLimit
= uLen
+ 0x8000; // 32Kb
1103 if (uLimit
> 0xffff)
1108 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1110 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1112 } // end of wxTextCtrl::AdjustSpaceLimit
1114 bool wxTextCtrl::AcceptsFocus() const
1117 // We don't want focus if we can't be edited
1119 return IsEditable() && wxControl::AcceptsFocus();
1120 } // end of wxTextCtrl::Command
1122 wxSize
wxTextCtrl::DoGetBestSize() const
1127 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1129 int wText
= DEFAULT_ITEM_WIDTH
;
1130 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1132 if (m_windowStyle
& wxTE_MULTILINE
)
1134 hText
*= wxMin(GetNumberOfLines(), 5);
1136 //else: for single line control everything is ok
1137 return wxSize(wText
, hText
);
1138 } // end of wxTextCtrl::DoGetBestSize
1140 // ----------------------------------------------------------------------------
1141 // standard handlers for standard edit menu events
1142 // ----------------------------------------------------------------------------
1144 void wxTextCtrl::OnCut(
1145 wxCommandEvent
& rEvent
1149 } // end of wxTextCtrl::OnCut
1151 void wxTextCtrl::OnCopy(
1152 wxCommandEvent
& rEvent
1156 } // end of wxTextCtrl::OnCopy
1158 void wxTextCtrl::OnPaste(
1159 wxCommandEvent
& rEvent
1163 } // end of wxTextCtrl::OnPaste
1165 void wxTextCtrl::OnUndo(
1166 wxCommandEvent
& rEvent
1170 } // end of wxTextCtrl::OnUndo
1172 void wxTextCtrl::OnRedo(
1173 wxCommandEvent
& rEvent
1177 } // end of wxTextCtrl::OnRedo
1179 void wxTextCtrl::OnUpdateCut(
1180 wxUpdateUIEvent
& rEvent
1183 rEvent
.Enable(CanCut());
1184 } // end of wxTextCtrl::OnUpdateCut
1186 void wxTextCtrl::OnUpdateCopy(
1187 wxUpdateUIEvent
& rEvent
1190 rEvent
.Enable(CanCopy());
1191 } // end of wxTextCtrl::OnUpdateCopy
1193 void wxTextCtrl::OnUpdatePaste(
1194 wxUpdateUIEvent
& rEvent
1197 rEvent
.Enable(CanPaste());
1198 } // end of wxTextCtrl::OnUpdatePaste
1200 void wxTextCtrl::OnUpdateUndo(
1201 wxUpdateUIEvent
& rEvent
1204 rEvent
.Enable(CanUndo());
1205 } // end of wxTextCtrl::OnUpdateUndo
1207 void wxTextCtrl::OnUpdateRedo(
1208 wxUpdateUIEvent
& rEvent
1211 rEvent
.Enable(CanRedo());
1212 } // end of wxTextCtrl::OnUpdateRedo
1214 bool wxTextCtrl::SetBackgroundColour(
1215 const wxColour
& rColour
1219 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1221 } // end of wxTextCtrl::SetBackgroundColour
1223 bool wxTextCtrl::SetForegroundColour(
1224 const wxColour
& rColour
1228 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1230 } // end of wxTextCtrl::SetForegroundColour
1232 bool wxTextCtrl::SetStyle(
1235 , const wxTextAttr
& rStyle
1238 HWND hWnd
= GetHwnd();
1249 // We can only change the format of the selection, so select the range we
1250 // want and restore the old selection later
1255 GetSelection( &lStartOld
1260 // But do we really have to change the selection?
1262 bool bChangeSel
= lStart
!= lStartOld
||
1268 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1270 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1274 // TODO:: finish this part
1277 } // end of wxTextCtrl::SetStyle