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"
31 #include "wx/clipbrd.h"
34 #include "wx/textfile.h"
36 #include "wx/os2/private.h"
40 #include <sys/types.h>
48 #if !defined(MLE_INDEX)
54 // ----------------------------------------------------------------------------
55 // event tables and other macros
56 // ----------------------------------------------------------------------------
58 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
60 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
61 EVT_CHAR(wxTextCtrl::OnChar
)
62 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
64 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
65 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
66 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
67 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
68 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
70 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
71 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
72 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
73 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
74 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
78 // ============================================================================
80 // ============================================================================
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 wxTextCtrl::wxTextCtrl()
90 wxTextCtrl::~wxTextCtrl()
94 bool wxTextCtrl::Create(
97 , const wxString
& rsValue
101 , const wxValidator
& rValidator
102 , const wxString
& rsName
106 // Base initialization
108 if ( !CreateBase( pParent
118 wxPoint vPos
= rPos
; // The OS/2 position
123 pParent
->AddChild(this);
126 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
;
160 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
161 ,WC_MLE
// Window class
162 ,(PSZ
)rsValue
.c_str() // Initial Text
163 ,(ULONG
)lSstyle
// Style flags
164 ,(LONG
)0 // X pos of origin
165 ,(LONG
)0 // Y pos of origin
166 ,(LONG
)0 // field width
167 ,(LONG
)0 // field height
168 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
169 ,HWND_TOP
// initial z position
170 ,(ULONG
)vId
// Window identifier
171 ,NULL
// no control data
172 ,NULL
// no Presentation parameters
177 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
178 ,WC_ENTRYFIELD
// Window class
179 ,(PSZ
)rsValue
.c_str() // Initial Text
180 ,(ULONG
)lSstyle
// Style flags
181 ,(LONG
)0 // X pos of origin
182 ,(LONG
)0 // Y pos of origin
183 ,(LONG
)0 // field width
184 ,(LONG
)0 // field height
185 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
186 ,HWND_TOP
// initial z position
187 ,(ULONG
)vId
// Window identifier
188 ,NULL
// no control data
189 ,NULL
// no Presentation parameters
198 SubclassWin(GetHWND());
201 // Set font, position, size and initial value
203 wxFont
* pTextFont
= new wxFont( 8
209 if (!rsValue
.empty())
215 // If X and/or Y are not zero the difference is the compensation value
216 // for margins for OS/2 controls.
218 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
221 SetSize( vPos
.x
- GetXComp()
228 } // end of wxTextCtrl::Create
231 // Make sure the window style (etc.) reflects the HWND style (roughly)
233 void wxTextCtrl::AdoptAttributesFromHWND()
235 HWND hWnd
= GetHwnd();
236 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
238 wxWindow::AdoptAttributesFromHWND();
242 m_windowStyle
|= wxTE_MULTILINE
;
243 if (lStyle
& MLS_READONLY
)
244 m_windowStyle
|= wxTE_READONLY
;
248 if (lStyle
& ES_UNREADABLE
)
249 m_windowStyle
|= wxTE_PASSWORD
;
250 if (lStyle
& ES_READONLY
)
251 m_windowStyle
|= wxTE_READONLY
;
253 } // end of wxTextCtrl::AdoptAttributesFromHWND
255 WXDWORD
wxTextCtrl::OS2GetStyle(
257 , WXDWORD
* pdwExstyle
261 // Default border for the text controls is the sunken one
263 if ((lStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
265 lStyle
|= wxBORDER_SUNKEN
;
268 long dwStyle
= wxControl::OS2GetStyle( lStyle
272 dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
275 // Single and multiline edit fields are two different controls in PM
277 if ( m_windowStyle
& wxTE_MULTILINE
)
279 dwStyle
|= MLS_BORDER
| MLS_WORDWRAP
;
280 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
281 dwStyle
|= MLS_VSCROLL
;
282 if (m_windowStyle
& wxHSCROLL
)
283 dwStyle
|= MLS_HSCROLL
;
284 if (m_windowStyle
& wxTE_READONLY
)
285 dwStyle
|= MLS_READONLY
;
289 dwStyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
290 if (m_windowStyle
& wxHSCROLL
)
291 dwStyle
|= ES_AUTOSCROLL
;
292 if (m_windowStyle
& wxTE_READONLY
)
293 dwStyle
|= ES_READONLY
;
294 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
295 dwStyle
|= ES_UNREADABLE
;
298 } // end of wxTextCtrl::OS2GetStyle
300 void wxTextCtrl::SetWindowStyleFlag(
304 wxControl::SetWindowStyleFlag(lStyle
);
305 } // end of wxTextCtrl::SetWindowStyleFlag
307 void wxTextCtrl::SetupColours()
309 wxColour vBkgndColour
;
311 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
312 SetBackgroundColour(vBkgndColour
);
313 SetForegroundColour(GetParent()->GetForegroundColour());
316 ::WinSendMsg( GetHwnd()
318 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
322 } // end of wxTextCtrl::SetupColours
324 // ----------------------------------------------------------------------------
325 // set/get the controls text
326 // ----------------------------------------------------------------------------
328 wxString
wxTextCtrl::GetValue() const
330 wxString sStr
= wxGetWindowText(GetHWND());
331 char* zStr
= (char*)sStr
.c_str();
333 for ( ; *zStr
; zStr
++ )
336 // this will replace \r\n with just \n
344 } // end of wxTextCtrl::GetValue
346 void wxTextCtrl::SetValue(
347 const wxString
& rsValue
351 // If the text is long enough, it's faster to just set it instead of first
352 // comparing it with the old one (chances are that it will be different
353 // anyhow, this comparison is there to avoid flicker for small single-line
354 // edit controls mostly)
356 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
358 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
361 } // end of wxTextCtrl::SetValue
363 void wxTextCtrl::WriteText(
364 const wxString
& rsValue
368 ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM((PCHAR
)rsValue
.c_str()), MPARAM(0));
370 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
372 } // end of wxTextCtrl::WriteText
374 void wxTextCtrl::AppendText(
375 const wxString
& rsText
378 SetInsertionPointEnd();
380 } // end of wxTextCtrl::AppendText
382 void wxTextCtrl::Clear()
384 ::WinSetWindowText(GetHwnd(), "");
385 } // end of wxTextCtrl::Clear
387 bool wxTextCtrl::EmulateKeyPress(
388 const wxKeyEvent
& rEvent
392 return(wxTextCtrlBase::EmulateKeyPress(rEvent
));
393 } // end of wxTextCtrl::EmulateKeyPress
395 // ----------------------------------------------------------------------------
396 // Clipboard operations
397 // ----------------------------------------------------------------------------
399 void wxTextCtrl::Copy()
403 HWND hWnd
= GetHwnd();
405 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
407 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
409 } // end of wxTextCtrl::Copy
411 void wxTextCtrl::Cut()
415 HWND hWnd
= GetHwnd();
418 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
420 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
422 } // end of wxTextCtrl::Cut
424 void wxTextCtrl::Paste()
428 HWND hWnd
= GetHwnd();
430 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
432 } // end of wxTextCtrl::Paste
434 bool wxTextCtrl::CanCopy() const
437 // Can copy if there's a selection
442 GetSelection(&lFrom
, &lTo
);
443 return (lFrom
!= lTo
);
444 } // end of wxTextCtrl::CanCopy
446 bool wxTextCtrl::CanCut() const
449 // Can cut if there's a selection
454 GetSelection(&lFrom
, &lTo
);
455 return (lFrom
!= lTo
);
456 } // end of wxTextCtrl::CanCut
458 bool wxTextCtrl::CanPaste() const
460 bool bIsTextAvailable
= false;
466 // Check for straight text on clipboard
468 if (::WinOpenClipbrd(vHabmain
))
470 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
471 ::WinCloseClipbrd(vHabmain
);
473 return bIsTextAvailable
;
474 } // end of wxTextCtrl::CanPaste
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
480 void wxTextCtrl::SetEditable(
484 HWND hWnd
= GetHwnd();
487 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
489 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
490 } // end of wxTextCtrl::SetEditable
492 void wxTextCtrl::SetInsertionPoint(
496 HWND hWnd
= GetHwnd();
499 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
501 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
502 } // end of wxTextCtrl::SetInsertionPoint
504 void wxTextCtrl::SetInsertionPointEnd()
506 wxTextPos lPos
= GetLastPosition();
509 // We must not do anything if the caret is already there because calling
510 // SetInsertionPoint() thaws the controls if Freeze() had been called even
511 // if it doesn't actually move the caret anywhere and so the simple fact of
512 // doing it results in horrible flicker when appending big amounts of text
513 // to the control in a few chunks (see DoAddText() test in the text sample)
515 if (GetInsertionPoint() == GetLastPosition())
517 SetInsertionPoint(lPos
);
518 } // end of wxTextCtrl::SetInsertionPointEnd
520 long wxTextCtrl::GetInsertionPoint() const
525 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
528 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
529 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
531 return (dwPos
& 0xFFFF);
532 } // end of wxTextCtrl::GetInsertionPoint
534 wxTextPos
wxTextCtrl::GetLastPosition() const
536 HWND hWnd
= GetHwnd();
545 // This just gets the total text length. The last will be this value
547 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
554 vParams
.fsStatus
= WPM_CCHTEXT
;
555 if (::WinSendMsg( GetHwnd()
556 ,WM_QUERYWINDOWPARAMS
561 lLineLength
= (long)vParams
.cchText
;
566 return(lCharIndex
+ lLineLength
);
567 } // end of wxTextCtrl::GetLastPosition
569 // If the return values from and to are the same, there is no
571 void wxTextCtrl::GetSelection(
579 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
582 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
584 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
585 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
586 } // end of wxTextCtrl::GetSelection
588 bool wxTextCtrl::IsEditable() const
591 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
593 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
594 } // end of wxTextCtrl::IsEditable
596 // ----------------------------------------------------------------------------
598 // ----------------------------------------------------------------------------
600 void wxTextCtrl::Replace( long lFrom
,
602 const wxString
& rsValue
)
605 HWND hWnd
= GetHwnd();
608 // Set selection and remove it
612 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
613 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
617 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
618 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
622 // Now replace with 'value', by pasting.
624 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
626 // Paste into edit control
628 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
630 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
634 wxUnusedVar(rsValue
);
635 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
637 } // end of wxTextCtrl::Replace
639 void wxTextCtrl::Remove(
644 HWND hWnd
= GetHwnd();
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 wxWidgets) 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
708 void wxTextCtrl::MarkDirty()
711 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(TRUE
), 0);
713 // EM controls do not have a SETCHANGED, what can we do??
714 wxFAIL_MSG( _T("not implemented") );
718 // Makes 'unmodified'
720 void wxTextCtrl::DiscardEdits()
723 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
726 // EM controls do not have a SETCHANGED but issuing a query should reset it
728 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
729 } // end of wxTextCtrl::DiscardEdits
731 int wxTextCtrl::GetNumberOfLines() const
736 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
740 } // end of wxTextCtrl::GetNumberOfLines
742 long wxTextCtrl::XYToPosition(
747 long lCharIndex
= 0L;
752 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
753 lCharIndex
= ((lLen
* lY
) + lX
);
758 } // end of wxTextCtrl::XYToPosition
760 bool wxTextCtrl::PositionToXY(
766 HWND hWnd
= GetHwnd();
771 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
782 // This gets the char index for the _beginning_ of this line
788 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
789 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
795 vParams
.fsStatus
= WPM_CCHTEXT
;
796 if (::WinSendMsg( hWnd
797 ,WM_QUERYWINDOWPARAMS
802 lCharIndex
= vParams
.cchText
;
808 if (lCharIndex
== -1)
814 // The X position must therefore be the difference between pos and charIndex
817 *plX
= lPos
- lCharIndex
;
822 } // end of wxTextCtrl::PositionToXY
824 void wxTextCtrl::ShowPosition( long WXUNUSED(lPos
) )
826 HWND hWnd
= GetHwnd();
827 long lCurrentLineLineNo
= 0L;
829 // To scroll to a position, we pass the number of lines and characters
830 // to scroll *by*. This means that we need to:
831 // (1) Find the line position of the current line.
832 // (2) Find the line position of pos.
833 // (3) Scroll by (pos - current).
834 // For now, ignore the horizontal scrolling.
837 // Is this where scrolling is relative to - the line containing the caret?
838 // Or is the first visible line??? Try first visible line.
843 // In PM this is the actual char position
845 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
848 // This will cause a scroll to the selected position
850 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
852 } // end of wxTextCtrl::ShowPosition
854 int wxTextCtrl::GetLineLength( long WXUNUSED(lLineNo
) ) const
860 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
866 vParams
.fsStatus
= WPM_CCHTEXT
;
867 if (::WinSendMsg( GetHwnd()
868 ,WM_QUERYWINDOWPARAMS
873 lLen
= vParams
.cchText
;
879 } // end ofwxTextCtrl::GetLineLength
881 wxString
wxTextCtrl::GetLineText(
885 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
890 // There must be at least enough place for the length WORD in the
893 lLen
+= sizeof(WORD
);
894 zBuf
= new wxChar
[lLen
];
901 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
902 lIndex
= lLen
* lLineNo
;
904 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
905 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)WXSIZEOF(zBuf
)));
906 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
907 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
908 zBuf
[lCopied
] = '\0';
914 vParams
.fsStatus
= WPM_CCHTEXT
;
915 if (::WinSendMsg( GetHwnd()
916 ,WM_QUERYWINDOWPARAMS
920 memcpy((char*)zBuf
, vParams
.pszText
, vParams
.cchText
);
921 zBuf
[vParams
.cchText
] = '\0';
926 } // end of wxTextCtrl::GetLineText
928 // ----------------------------------------------------------------------------
930 // ----------------------------------------------------------------------------
932 void wxTextCtrl::Undo()
937 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
938 // Simple entryfields cannot be undone
940 } // end of wxTextCtrl::Undo
942 void wxTextCtrl::Redo()
947 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
948 // Simple entryfields cannot be undone
950 } // end of wxTextCtrl::Redo
952 bool wxTextCtrl::CanUndo() const
957 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
959 bOk
= false; // can't undo regular edit fields in PM
961 } // end of wxTextCtrl::CanUndo
963 bool wxTextCtrl::CanRedo() const
968 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
970 bOk
= false; // can't undo regular edit fields in PM
972 } // end of wxTextCtrl::CanRedo
974 // ----------------------------------------------------------------------------
975 // implemenation details
976 // ----------------------------------------------------------------------------
978 void wxTextCtrl::Command(
979 wxCommandEvent
& rEvent
982 SetValue(rEvent
.GetString());
983 ProcessCommand (rEvent
);
984 } // end of wxTextCtrl::Command
986 void wxTextCtrl::OnDropFiles(
987 wxDropFilesEvent
& rEvent
990 // By default, load the first file into the text window.
991 if (rEvent
.GetNumberOfFiles() > 0)
993 LoadFile(rEvent
.GetFiles()[0]);
995 } // end of wxTextCtrl::OnDropFiles
997 WXHBRUSH
wxTextCtrl::OnCtlColor( WXHDC hWxDC
,
998 WXHWND
WXUNUSED(hWnd
),
999 WXUINT
WXUNUSED(uCtlColor
),
1000 WXUINT
WXUNUSED(uMessage
),
1001 WXWPARAM
WXUNUSED(wParam
),
1002 WXLPARAM
WXUNUSED(lParam
) )
1004 HPS hPS
= (HPS
)hWxDC
;
1005 wxColour vColBack
= GetBackgroundColour();
1006 wxColour vColFore
= GetForegroundColour();
1007 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
, wxSOLID
);
1011 HBRUSH hBrush
= NULLHANDLE
;
1015 if (GetParent()->GetTransparentBackground())
1016 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1018 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1019 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1020 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1021 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1022 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1023 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1024 } // end of wxTextCtrl::OnCtlColor
1026 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1030 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1031 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1033 void wxTextCtrl::OnChar(
1037 switch (rEvent
.GetKeyCode())
1040 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1042 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1044 vEvent
.SetEventObject(this);
1045 if ( GetEventHandler()->ProcessEvent(vEvent
))
1048 //else: multiline controls need Enter for themselves
1053 // always produce navigation event - even if we process TAB
1054 // ourselves the fact that we got here means that the user code
1055 // decided to skip processing of this TAB - probably to let it
1056 // do its default job.
1058 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1059 // handled by Windows
1061 wxNavigationKeyEvent vEventNav
;
1063 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1064 vEventNav
.SetWindowChange(false);
1065 vEventNav
.SetEventObject(this);
1067 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1073 } // end of wxTextCtrl::OnChar
1075 bool wxTextCtrl::OS2Command(
1077 , WXWORD
WXUNUSED(vId
)
1085 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1090 vEvent
.SetEventObject(this);
1091 GetEventHandler()->ProcessEvent(vEvent
);
1097 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1101 InitCommandEvent(vEvent
);
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
.pCtlData
= &Efd
;
1148 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1150 if (::WinSendMsg( GetHwnd()
1151 ,WM_QUERYWINDOWPARAMS
1155 uLimit
= (unsigned int)Efd
.cchEditLimit
;
1157 uLimit
= 32; //PM's default
1161 uLimit
= uLen
+ 0x8000; // 32Kb
1162 if (uLimit
> 0xffff)
1167 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1169 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMSHORT(uLimit
), 0);
1171 } // end of wxTextCtrl::AdjustSpaceLimit
1173 bool wxTextCtrl::AcceptsFocus() const
1176 // We don't want focus if we can't be edited unless we're a multiline
1177 // control because then it might be still nice to get focus from keyboard
1178 // to be able to scroll it without mouse
1180 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1181 } // end of wxTextCtrl::Command
1183 wxSize
wxTextCtrl::DoGetBestSize() const
1187 wxFont vFont
= (wxFont
)GetFont();
1189 wxGetCharSize(GetHWND(), &nCx
, &nCy
, &vFont
);
1191 int wText
= DEFAULT_ITEM_WIDTH
;
1192 int hText
= (int)(EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1194 if (m_windowStyle
& wxTE_MULTILINE
)
1196 hText
*= wxMax(GetNumberOfLines(), 5);
1198 //else: for single line control everything is ok
1199 return wxSize(wText
, hText
);
1200 } // end of wxTextCtrl::DoGetBestSize
1202 // ----------------------------------------------------------------------------
1203 // standard handlers for standard edit menu events
1204 // ----------------------------------------------------------------------------
1206 void wxTextCtrl::OnCut( wxCommandEvent
& WXUNUSED(rEvent
) )
1209 } // end of wxTextCtrl::OnCut
1211 void wxTextCtrl::OnCopy( wxCommandEvent
& WXUNUSED(rEvent
) )
1214 } // end of wxTextCtrl::OnCopy
1216 void wxTextCtrl::OnPaste( wxCommandEvent
& WXUNUSED(rEvent
) )
1219 } // end of wxTextCtrl::OnPaste
1221 void wxTextCtrl::OnUndo( wxCommandEvent
& WXUNUSED(rEvent
) )
1224 } // end of wxTextCtrl::OnUndo
1226 void wxTextCtrl::OnRedo( wxCommandEvent
& WXUNUSED(rEvent
) )
1229 } // end of wxTextCtrl::OnRedo
1231 void wxTextCtrl::OnDelete( wxCommandEvent
& WXUNUSED(rEvent
) )
1235 GetSelection( &lFrom
, &lTo
);
1237 if (lFrom
!= -1 && lTo
!= -1)
1238 Remove( lFrom
, lTo
);
1239 } // end of wxTextCtrl::OnDelete
1241 void wxTextCtrl::OnSelectAll( wxCommandEvent
& WXUNUSED(rEvent
) )
1243 SetSelection(-1, -1);
1244 } // end of wxTextCtrl::OnSelectAll
1246 void wxTextCtrl::OnUpdateCut( wxUpdateUIEvent
& rEvent
)
1248 rEvent
.Enable(CanCut());
1249 } // end of wxTextCtrl::OnUpdateCut
1251 void wxTextCtrl::OnUpdateCopy( wxUpdateUIEvent
& rEvent
)
1253 rEvent
.Enable(CanCopy());
1254 } // end of wxTextCtrl::OnUpdateCopy
1256 void wxTextCtrl::OnUpdatePaste( wxUpdateUIEvent
& rEvent
)
1258 rEvent
.Enable(CanPaste());
1259 } // end of wxTextCtrl::OnUpdatePaste
1261 void wxTextCtrl::OnUpdateUndo( wxUpdateUIEvent
& rEvent
)
1263 rEvent
.Enable(CanUndo());
1264 } // end of wxTextCtrl::OnUpdateUndo
1266 void wxTextCtrl::OnUpdateRedo( wxUpdateUIEvent
& rEvent
)
1268 rEvent
.Enable(CanRedo());
1269 } // end of wxTextCtrl::OnUpdateRedo
1271 void wxTextCtrl::OnUpdateDelete( wxUpdateUIEvent
& rEvent
)
1275 GetSelection( &lFrom
, &lTo
);
1276 rEvent
.Enable( lFrom
!= -1L && lTo
!= -1L && lFrom
!= lTo
&& IsEditable()) ;
1277 } // end of wxTextCtrl::OnUpdateDelete
1279 void wxTextCtrl::OnUpdateSelectAll( wxUpdateUIEvent
& rEvent
)
1281 rEvent
.Enable(GetLastPosition() > 0);
1282 } // end of wxTextCtrl::OnUpdateSelectAll
1284 bool wxTextCtrl::SetBackgroundColour( const wxColour
& rColour
)
1287 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1289 } // end of wxTextCtrl::SetBackgroundColour
1291 bool wxTextCtrl::SetForegroundColour( const wxColour
& rColour
)
1294 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1296 } // end of wxTextCtrl::SetForegroundColour
1298 bool wxTextCtrl::SetStyle( long lStart
,
1300 const wxTextAttr
& WXUNUSED(rStyle
) )
1302 HWND hWnd
= GetHwnd();
1313 // We can only change the format of the selection, so select the range we
1314 // want and restore the old selection later
1316 long lStartOld
, lEndOld
;
1318 GetSelection( &lStartOld
, &lEndOld
);
1321 // But do we really have to change the selection?
1323 bool bChangeSel
= lStart
!= lStartOld
||
1329 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1331 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1335 // TODO:: finish this part
1338 } // end of wxTextCtrl::SetStyle