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
)
163 m_windowStyle
|= wxTE_PROCESS_ENTER
;
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());
287 } // end of wxTextCtrl::SetupColours
289 // ----------------------------------------------------------------------------
290 // set/get the controls text
291 // ----------------------------------------------------------------------------
293 wxString
wxTextCtrl::GetValue() const
295 wxString sStr
= wxGetWindowText(GetHWND());
296 char* zStr
= (char*)sStr
.c_str();
298 for ( ; *zStr
; zStr
++ )
301 // this will replace \r\n with just \n
310 } // end of wxTextCtrl::GetValue
312 void wxTextCtrl::SetValue(
313 const wxString
& rsValue
317 // If the text is long enough, it's faster to just set it instead of first
318 // comparing it with the old one (chances are that it will be different
319 // anyhow, this comparison is there to avoid flicker for small single-line
320 // edit controls mostly)
322 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
324 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
327 } // end of wxTextCtrl::SetValue
329 void wxTextCtrl::WriteText(
330 const wxString
& rsValue
333 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
335 } // end of wxTextCtrl::WriteText
337 void wxTextCtrl::AppendText(
338 const wxString
& rsText
341 SetInsertionPointEnd();
343 } // end of wxTextCtrl::AppendText
345 void wxTextCtrl::Clear()
347 ::WinSetWindowText(GetHwnd(), "");
348 } // end of wxTextCtrl::Clear
350 // ----------------------------------------------------------------------------
351 // Clipboard operations
352 // ----------------------------------------------------------------------------
354 void wxTextCtrl::Copy()
358 HWND hWnd
= GetHwnd();
360 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
362 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
364 } // end of wxTextCtrl::Copy
366 void wxTextCtrl::Cut()
370 HWND hWnd
= GetHwnd();
373 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
375 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
377 } // end of wxTextCtrl::Cut
379 void wxTextCtrl::Paste()
383 HWND hWnd
= GetHwnd();
385 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
387 } // end of wxTextCtrl::Paste
389 bool wxTextCtrl::CanCopy() const
392 // Can copy if there's a selection
397 GetSelection(&lFrom
, &lTo
);
398 return (lFrom
!= lTo
);
399 } // end of wxTextCtrl::CanCopy
401 bool wxTextCtrl::CanCut() const
404 // Can cut if there's a selection
409 GetSelection(&lFrom
, &lTo
);
410 return (lFrom
!= lTo
);
411 } // end of wxTextCtrl::CanCut
413 bool wxTextCtrl::CanPaste() const
415 bool bIsTextAvailable
= FALSE
;
421 // Check for straight text on clipboard
423 if (::WinOpenClipbrd(vHabmain
))
425 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
426 ::WinCloseClipbrd(vHabmain
);
428 return bIsTextAvailable
;
429 } // end of wxTextCtrl::CanPaste
431 // ----------------------------------------------------------------------------
433 // ----------------------------------------------------------------------------
435 void wxTextCtrl::SetEditable(
439 HWND hWnd
= GetHwnd();
442 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
444 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
445 } // end of wxTextCtrl::SetEditable
447 void wxTextCtrl::SetInsertionPoint(
451 HWND hWnd
= GetHwnd();
454 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
456 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
457 } // end of wxTextCtrl::SetInsertionPoint
459 void wxTextCtrl::SetInsertionPointEnd()
461 long lPos
= GetLastPosition();
463 SetInsertionPoint(lPos
);
464 } // end of wxTextCtrl::SetInsertionPointEnd
466 long wxTextCtrl::GetInsertionPoint() const
471 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
474 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
475 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
477 return (dwPos
& 0xFFFF);
478 } // end of wxTextCtrl::GetInsertionPoint
480 long wxTextCtrl::GetLastPosition() const
482 HWND hWnd
= GetHwnd();
491 // This just gets the total text length. The last will be this value
493 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
500 vParams
.fsStatus
= WPM_CCHTEXT
;
501 if (::WinSendMsg( GetHwnd()
502 ,WM_QUERYWINDOWPARAMS
507 lLineLength
= (long)vParams
.cchText
;
512 return(lCharIndex
+ lLineLength
);
513 } // end of wxTextCtrl::GetLastPosition
515 // If the return values from and to are the same, there is no
517 void wxTextCtrl::GetSelection(
525 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
528 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
530 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
531 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
532 } // end of wxTextCtrl::GetSelection
534 bool wxTextCtrl::IsEditable() const
537 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
539 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
540 } // end of wxTextCtrl::IsEditable
542 // ----------------------------------------------------------------------------
544 // ----------------------------------------------------------------------------
546 void wxTextCtrl::Replace(
549 , const wxString
& rsValue
553 HWND hWnd
= GetHwnd();
554 long lFromChar
= lFrom
;
558 // Set selection and remove it
562 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
563 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
567 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
568 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
572 // Now replace with 'value', by pasting.
574 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
576 // Paste into edit control
578 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
580 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
582 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
584 } // end of wxTextCtrl::Replace
586 void wxTextCtrl::Remove(
591 HWND hWnd
= GetHwnd();
592 long lFromChar
= lFrom
;
597 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
598 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
602 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
603 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
605 } // end of wxTextCtrl::Remove
607 void wxTextCtrl::SetSelection(
612 HWND hWnd
= GetHwnd();
613 long lFromChar
= lFrom
;
617 // If from and to are both -1, it means (in wxWindows) that all text should
618 // be selected. Translate into Windows convention
620 if ((lFrom
== -1L) && (lTo
== -1L))
626 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
628 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
629 } // end of wxTextCtrl::SetSelection
631 bool wxTextCtrl::LoadFile(
632 const wxString
& rsFile
635 if ( wxTextCtrlBase::LoadFile(rsFile
) )
638 // Update the size limit if needed
644 } // end of wxTextCtrl::LoadFile
646 bool wxTextCtrl::IsModified() const
651 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
653 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
655 } // end of wxTextCtrl::IsModified
658 // Makes 'unmodified'
660 void wxTextCtrl::DiscardEdits()
663 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
666 // EM controls do not have a SETCHANGED but issuing a query should reset it
668 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
669 } // end of wxTextCtrl::DiscardEdits
671 int wxTextCtrl::GetNumberOfLines() const
676 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
680 } // end of wxTextCtrl::GetNumberOfLines
682 long wxTextCtrl::XYToPosition(
687 HWND hWnd
= GetHwnd();
688 long lCharIndex
= 0L;
693 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
694 lCharIndex
= ((lLen
* lY
) + lX
);
699 } // end of wxTextCtrl::XYToPosition
701 bool wxTextCtrl::PositionToXY(
707 HWND hWnd
= GetHwnd();
712 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
723 // This gets the char index for the _beginning_ of this line
729 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
730 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
736 vParams
.fsStatus
= WPM_CCHTEXT
;
737 if (::WinSendMsg( hWnd
738 ,WM_QUERYWINDOWPARAMS
743 lCharIndex
= vParams
.cchText
;
749 if (lCharIndex
== -1)
755 // The X position must therefore be the difference between pos and charIndex
758 *plX
= lPos
- lCharIndex
;
763 } // end of wxTextCtrl::PositionToXY
765 void wxTextCtrl::ShowPosition(
769 HWND hWnd
= GetHwnd();
770 long lCurrentLineLineNo
= 0L;
772 // To scroll to a position, we pass the number of lines and characters
773 // to scroll *by*. This means that we need to:
774 // (1) Find the line position of the current line.
775 // (2) Find the line position of pos.
776 // (3) Scroll by (pos - current).
777 // For now, ignore the horizontal scrolling.
780 // Is this where scrolling is relative to - the line containing the caret?
781 // Or is the first visible line??? Try first visible line.
786 // In PM this is the actual char position
788 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
791 // This will cause a scroll to the selected position
793 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
795 } // end of wxTextCtrl::ShowPosition
797 int wxTextCtrl::GetLineLength(
804 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
809 vParams
.fsStatus
= WPM_CCHTEXT
;
810 if (::WinSendMsg( GetHwnd()
811 ,WM_QUERYWINDOWPARAMS
816 lLen
= vParams
.cchText
;
822 } // end ofwxTextCtrl::GetLineLength
824 wxString
wxTextCtrl::GetLineText(
828 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
833 // There must be at least enough place for the length WORD in the
836 lLen
+= sizeof(WORD
);
837 zBuf
= new char[lLen
];
844 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
845 lIndex
= lLen
* lLineNo
;
847 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
848 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
849 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
850 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
851 zBuf
[lCopied
] = '\0';
857 vParams
.fsStatus
= WPM_CCHTEXT
;
858 if (::WinSendMsg( GetHwnd()
859 ,WM_QUERYWINDOWPARAMS
863 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
864 zBuf
[vParams
.cchText
] = '\0';
869 } // end of wxTextCtrl::GetLineText
871 // ----------------------------------------------------------------------------
873 // ----------------------------------------------------------------------------
875 void wxTextCtrl::Undo()
880 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
881 // Simple entryfields cannot be undone
883 } // end of wxTextCtrl::Undo
885 void wxTextCtrl::Redo()
890 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
891 // Simple entryfields cannot be undone
893 } // end of wxTextCtrl::Redo
895 bool wxTextCtrl::CanUndo() const
900 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
902 bOk
= FALSE
; // can't undo regular edit fields in PM
904 } // end of wxTextCtrl::CanUndo
906 bool wxTextCtrl::CanRedo() const
911 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
913 bOk
= FALSE
; // can't undo regular edit fields in PM
915 } // end of wxTextCtrl::CanRedo
917 // ----------------------------------------------------------------------------
918 // implemenation details
919 // ----------------------------------------------------------------------------
921 void wxTextCtrl::Command(
922 wxCommandEvent
& rEvent
925 SetValue(rEvent
.GetString());
926 ProcessCommand (rEvent
);
927 } // end of wxTextCtrl::Command
929 void wxTextCtrl::OnDropFiles(
930 wxDropFilesEvent
& rEvent
933 // By default, load the first file into the text window.
934 if (rEvent
.GetNumberOfFiles() > 0)
936 LoadFile(rEvent
.GetFiles()[0]);
938 } // end of wxTextCtrl::OnDropFiles
940 WXHBRUSH
wxTextCtrl::OnCtlColor(
949 HPS hPS
= (HPS
)hWxDC
;
950 wxBrush
* pBrush
= NULL
;
951 wxColour vColBack
= GetBackgroundColour();
952 wxColour vColFore
= GetForegroundColour();
953 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
959 HBRUSH hBrush
= NULLHANDLE
;
963 if (GetParent()->GetTransparentBackground())
964 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
966 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
967 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
968 vColBack
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
);
969 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
970 ::GpiSetColor(hPS
, vColFore
.GetPixel());
971 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
972 } // end of wxTextCtrl::OnCtlColor
974 void wxTextCtrl::OnChar(
978 switch (rEvent
.KeyCode())
981 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
983 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
985 vEvent
.SetEventObject(this);
986 if ( GetEventHandler()->ProcessEvent(vEvent
))
989 //else: multiline controls need Enter for themselves
994 // always produce navigation event - even if we process TAB
995 // ourselves the fact that we got here means that the user code
996 // decided to skip processing of this TAB - probably to let it
997 // do its default job.
999 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1000 // handled by Windows
1002 wxNavigationKeyEvent vEventNav
;
1004 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1005 vEventNav
.SetWindowChange(FALSE
);
1006 vEventNav
.SetEventObject(this);
1008 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1014 } // end of wxTextCtrl::OnChar
1016 bool wxTextCtrl::OS2Command(
1018 , WXWORD
WXUNUSED(vId
)
1026 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1031 vEvent
.SetEventObject(this);
1032 GetEventHandler()->ProcessEvent(vEvent
);
1038 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1042 InitCommandEvent(vEvent
);
1043 vEvent
.SetString((char*)GetValue().c_str());
1044 ProcessCommand(vEvent
);
1050 // The text size limit has been hit - increase it
1056 case EN_INSERTMODETOGGLE
:
1067 } // end of wxTextCtrl::OS2Command
1069 void wxTextCtrl::AdjustSpaceLimit()
1071 unsigned int uLen
= 0;
1072 unsigned int uLimit
= 0;
1074 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1077 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1088 vParams
.fsStatus
= WPM_CBCTLDATA
;
1089 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1091 if (::WinSendMsg( GetHwnd()
1092 ,WM_QUERYWINDOWPARAMS
1097 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1098 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1101 uLimit
= 32; //PM's default
1105 uLimit
= uLen
+ 0x8000; // 32Kb
1106 if (uLimit
> 0xffff)
1111 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1113 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1115 } // end of wxTextCtrl::AdjustSpaceLimit
1117 bool wxTextCtrl::AcceptsFocus() const
1120 // We don't want focus if we can't be edited
1122 return IsEditable() && wxControl::AcceptsFocus();
1123 } // end of wxTextCtrl::Command
1125 wxSize
wxTextCtrl::DoGetBestSize() const
1130 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1132 int wText
= DEFAULT_ITEM_WIDTH
;
1133 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1135 if (m_windowStyle
& wxTE_MULTILINE
)
1137 hText
*= wxMin(GetNumberOfLines(), 5);
1139 //else: for single line control everything is ok
1140 return wxSize(wText
, hText
);
1141 } // end of wxTextCtrl::DoGetBestSize
1143 // ----------------------------------------------------------------------------
1144 // standard handlers for standard edit menu events
1145 // ----------------------------------------------------------------------------
1147 void wxTextCtrl::OnCut(
1148 wxCommandEvent
& rEvent
1152 } // end of wxTextCtrl::OnCut
1154 void wxTextCtrl::OnCopy(
1155 wxCommandEvent
& rEvent
1159 } // end of wxTextCtrl::OnCopy
1161 void wxTextCtrl::OnPaste(
1162 wxCommandEvent
& rEvent
1166 } // end of wxTextCtrl::OnPaste
1168 void wxTextCtrl::OnUndo(
1169 wxCommandEvent
& rEvent
1173 } // end of wxTextCtrl::OnUndo
1175 void wxTextCtrl::OnRedo(
1176 wxCommandEvent
& rEvent
1180 } // end of wxTextCtrl::OnRedo
1182 void wxTextCtrl::OnUpdateCut(
1183 wxUpdateUIEvent
& rEvent
1186 rEvent
.Enable(CanCut());
1187 } // end of wxTextCtrl::OnUpdateCut
1189 void wxTextCtrl::OnUpdateCopy(
1190 wxUpdateUIEvent
& rEvent
1193 rEvent
.Enable(CanCopy());
1194 } // end of wxTextCtrl::OnUpdateCopy
1196 void wxTextCtrl::OnUpdatePaste(
1197 wxUpdateUIEvent
& rEvent
1200 rEvent
.Enable(CanPaste());
1201 } // end of wxTextCtrl::OnUpdatePaste
1203 void wxTextCtrl::OnUpdateUndo(
1204 wxUpdateUIEvent
& rEvent
1207 rEvent
.Enable(CanUndo());
1208 } // end of wxTextCtrl::OnUpdateUndo
1210 void wxTextCtrl::OnUpdateRedo(
1211 wxUpdateUIEvent
& rEvent
1214 rEvent
.Enable(CanRedo());
1215 } // end of wxTextCtrl::OnUpdateRedo
1217 bool wxTextCtrl::SetBackgroundColour(
1218 const wxColour
& rColour
1222 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1224 } // end of wxTextCtrl::SetBackgroundColour
1226 bool wxTextCtrl::SetForegroundColour(
1227 const wxColour
& rColour
1231 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1233 } // end of wxTextCtrl::SetForegroundColour
1235 bool wxTextCtrl::SetStyle(
1238 , const wxTextAttr
& rStyle
1241 HWND hWnd
= GetHwnd();
1252 // We can only change the format of the selection, so select the range we
1253 // want and restore the old selection later
1258 GetSelection( &lStartOld
1263 // But do we really have to change the selection?
1265 bool bChangeSel
= lStart
!= lStartOld
||
1271 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1273 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1277 // TODO:: finish this part
1280 } // end of wxTextCtrl::SetStyle