1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/textctrl.cpp
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"
19 #include "wx/textctrl.h"
22 #include "wx/scrolwin.h"
23 #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
, wxTextCtrlBase
)
60 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
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
;
128 m_bSkipUpdate
= false;
130 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
133 // Single and multiline edit fields are two different controls in PM
135 if ( m_windowStyle
& wxTE_MULTILINE
)
137 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
140 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
141 lSstyle
|= MLS_VSCROLL
;
142 if (m_windowStyle
& wxHSCROLL
)
143 lSstyle
|= MLS_HSCROLL
;
144 if (m_windowStyle
& wxTE_READONLY
)
145 lSstyle
|= MLS_READONLY
;
149 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
151 if (m_windowStyle
& wxHSCROLL
)
152 lSstyle
|= ES_AUTOSCROLL
;
153 if (m_windowStyle
& wxTE_READONLY
)
154 lSstyle
|= ES_READONLY
;
155 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
156 lSstyle
|= ES_UNREADABLE
;
161 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
162 ,WC_MLE
// Window class
163 ,(PSZ
)rsValue
.c_str() // Initial Text
164 ,(ULONG
)lSstyle
// Style flags
165 ,(LONG
)0 // X pos of origin
166 ,(LONG
)0 // Y pos of origin
167 ,(LONG
)0 // field width
168 ,(LONG
)0 // field height
169 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
170 ,HWND_TOP
// initial z position
171 ,(ULONG
)vId
// Window identifier
172 ,NULL
// no control data
173 ,NULL
// no Presentation parameters
178 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
179 ,WC_ENTRYFIELD
// Window class
180 ,(PSZ
)rsValue
.c_str() // Initial Text
181 ,(ULONG
)lSstyle
// Style flags
182 ,(LONG
)0 // X pos of origin
183 ,(LONG
)0 // Y pos of origin
184 ,(LONG
)0 // field width
185 ,(LONG
)0 // field height
186 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
187 ,HWND_TOP
// initial z position
188 ,(ULONG
)vId
// Window identifier
189 ,NULL
// no control data
190 ,NULL
// no Presentation parameters
199 SubclassWin(GetHWND());
202 // Set font, position, size and initial value
204 wxFont
* pTextFont
= new wxFont( 8
210 if (!rsValue
.empty())
216 // If X and/or Y are not zero the difference is the compensation value
217 // for margins for OS/2 controls.
219 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
222 SetSize( vPos
.x
- GetXComp()
229 } // end of wxTextCtrl::Create
232 // Make sure the window style (etc.) reflects the HWND style (roughly)
234 void wxTextCtrl::AdoptAttributesFromHWND()
236 HWND hWnd
= GetHwnd();
237 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
239 wxWindow::AdoptAttributesFromHWND();
243 m_windowStyle
|= wxTE_MULTILINE
;
244 if (lStyle
& MLS_READONLY
)
245 m_windowStyle
|= wxTE_READONLY
;
249 if (lStyle
& ES_UNREADABLE
)
250 m_windowStyle
|= wxTE_PASSWORD
;
251 if (lStyle
& ES_READONLY
)
252 m_windowStyle
|= wxTE_READONLY
;
254 } // end of wxTextCtrl::AdoptAttributesFromHWND
256 WXDWORD
wxTextCtrl::OS2GetStyle(
258 , WXDWORD
* pdwExstyle
262 // Default border for the text controls is the sunken one
264 if ((lStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
266 lStyle
|= wxBORDER_SUNKEN
;
269 long dwStyle
= wxControl::OS2GetStyle( lStyle
273 dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
276 // Single and multiline edit fields are two different controls in PM
278 if ( m_windowStyle
& wxTE_MULTILINE
)
280 dwStyle
|= MLS_BORDER
| MLS_WORDWRAP
;
281 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
282 dwStyle
|= MLS_VSCROLL
;
283 if (m_windowStyle
& wxHSCROLL
)
284 dwStyle
|= MLS_HSCROLL
;
285 if (m_windowStyle
& wxTE_READONLY
)
286 dwStyle
|= MLS_READONLY
;
290 dwStyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
291 if (m_windowStyle
& wxHSCROLL
)
292 dwStyle
|= ES_AUTOSCROLL
;
293 if (m_windowStyle
& wxTE_READONLY
)
294 dwStyle
|= ES_READONLY
;
295 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
296 dwStyle
|= ES_UNREADABLE
;
299 } // end of wxTextCtrl::OS2GetStyle
301 void wxTextCtrl::SetWindowStyleFlag(
305 wxControl::SetWindowStyleFlag(lStyle
);
306 } // end of wxTextCtrl::SetWindowStyleFlag
308 void wxTextCtrl::SetupColours()
310 wxColour vBkgndColour
;
312 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
313 SetBackgroundColour(vBkgndColour
);
314 SetForegroundColour(GetParent()->GetForegroundColour());
317 ::WinSendMsg( GetHwnd()
319 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
323 } // end of wxTextCtrl::SetupColours
325 // ----------------------------------------------------------------------------
326 // set/get the controls text
327 // ----------------------------------------------------------------------------
329 wxString
wxTextCtrl::GetValue() const
331 wxString sStr
= wxGetWindowText(GetHWND());
332 char* zStr
= (char*)sStr
.c_str();
334 for ( ; *zStr
; zStr
++ )
337 // this will replace \r\n with just \n
345 } // end of wxTextCtrl::GetValue
347 void wxTextCtrl::DoSetValue(
348 const wxString
& rsValue
,
353 // If the text is long enough, it's faster to just set it instead of first
354 // comparing it with the old one (chances are that it will be different
355 // anyhow, this comparison is there to avoid flicker for small single-line
356 // edit controls mostly)
358 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
360 if ( flags
& SetValue_SendEvent
)
361 m_bSkipUpdate
= true;
363 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
366 } // end of wxTextCtrl::SetValue
368 void wxTextCtrl::WriteText(
369 const wxString
& rsValue
373 ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM((PCHAR
)rsValue
.c_str()), MPARAM(0));
375 ::WinSetWindowText(GetHwnd(), (PSZ
)rsValue
.c_str());
377 } // end of wxTextCtrl::WriteText
379 void wxTextCtrl::AppendText(
380 const wxString
& rsText
383 SetInsertionPointEnd();
385 } // end of wxTextCtrl::AppendText
387 void wxTextCtrl::Clear()
389 ::WinSetWindowText(GetHwnd(), "");
390 } // end of wxTextCtrl::Clear
392 bool wxTextCtrl::EmulateKeyPress(
393 const wxKeyEvent
& rEvent
397 return(wxTextCtrlBase::EmulateKeyPress(rEvent
));
398 } // end of wxTextCtrl::EmulateKeyPress
400 // ----------------------------------------------------------------------------
401 // Clipboard operations
402 // ----------------------------------------------------------------------------
404 void wxTextCtrl::Copy()
408 HWND hWnd
= GetHwnd();
410 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
412 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
414 } // end of wxTextCtrl::Copy
416 void wxTextCtrl::Cut()
420 HWND hWnd
= GetHwnd();
423 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
425 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
427 } // end of wxTextCtrl::Cut
429 void wxTextCtrl::Paste()
433 HWND hWnd
= GetHwnd();
435 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
437 } // end of wxTextCtrl::Paste
439 bool wxTextCtrl::CanCopy() const
442 // Can copy if there's a selection
447 GetSelection(&lFrom
, &lTo
);
448 return (lFrom
!= lTo
);
449 } // end of wxTextCtrl::CanCopy
451 bool wxTextCtrl::CanCut() const
454 // Can cut if there's a selection
459 GetSelection(&lFrom
, &lTo
);
460 return (lFrom
!= lTo
);
461 } // end of wxTextCtrl::CanCut
463 bool wxTextCtrl::CanPaste() const
465 bool bIsTextAvailable
= false;
471 // Check for straight text on clipboard
473 if (::WinOpenClipbrd(vHabmain
))
475 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
476 ::WinCloseClipbrd(vHabmain
);
478 return bIsTextAvailable
;
479 } // end of wxTextCtrl::CanPaste
481 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
485 void wxTextCtrl::SetEditable(
489 HWND hWnd
= GetHwnd();
492 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
494 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
495 } // end of wxTextCtrl::SetEditable
497 void wxTextCtrl::SetInsertionPoint(
501 HWND hWnd
= GetHwnd();
504 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
506 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
507 } // end of wxTextCtrl::SetInsertionPoint
509 void wxTextCtrl::SetInsertionPointEnd()
511 wxTextPos lPos
= GetLastPosition();
514 // We must not do anything if the caret is already there because calling
515 // SetInsertionPoint() thaws the controls if Freeze() had been called even
516 // if it doesn't actually move the caret anywhere and so the simple fact of
517 // doing it results in horrible flicker when appending big amounts of text
518 // to the control in a few chunks (see DoAddText() test in the text sample)
520 if (GetInsertionPoint() == GetLastPosition())
522 SetInsertionPoint(lPos
);
523 } // end of wxTextCtrl::SetInsertionPointEnd
525 long wxTextCtrl::GetInsertionPoint() const
530 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
533 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
534 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
536 return (dwPos
& 0xFFFF);
537 } // end of wxTextCtrl::GetInsertionPoint
539 wxTextPos
wxTextCtrl::GetLastPosition() const
541 HWND hWnd
= GetHwnd();
550 // This just gets the total text length. The last will be this value
552 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
559 vParams
.fsStatus
= WPM_CCHTEXT
;
560 if (::WinSendMsg( GetHwnd()
561 ,WM_QUERYWINDOWPARAMS
566 lLineLength
= (long)vParams
.cchText
;
571 return(lCharIndex
+ lLineLength
);
572 } // end of wxTextCtrl::GetLastPosition
574 // If the return values from and to are the same, there is no
576 void wxTextCtrl::GetSelection(
584 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
587 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
589 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
590 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
591 } // end of wxTextCtrl::GetSelection
593 bool wxTextCtrl::IsEditable() const
596 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
598 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
599 } // end of wxTextCtrl::IsEditable
601 // ----------------------------------------------------------------------------
603 // ----------------------------------------------------------------------------
605 void wxTextCtrl::Replace( long lFrom
,
607 const wxString
& rsValue
)
610 HWND hWnd
= GetHwnd();
613 // Set selection and remove it
617 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
618 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
622 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
623 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
627 // Now replace with 'value', by pasting.
629 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
631 // Paste into edit control
633 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
635 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
639 wxUnusedVar(rsValue
);
640 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
642 } // end of wxTextCtrl::Replace
644 void wxTextCtrl::Remove(
649 HWND hWnd
= GetHwnd();
653 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
654 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
658 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
659 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
661 } // end of wxTextCtrl::Remove
663 void wxTextCtrl::SetSelection(
668 HWND hWnd
= GetHwnd();
669 long lFromChar
= lFrom
;
673 // If from and to are both -1, it means (in wxWidgets) that all text should
674 // be selected. Translate into Windows convention
676 if ((lFrom
== -1L) && (lTo
== -1L))
682 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
684 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
685 } // end of wxTextCtrl::SetSelection
687 bool wxTextCtrl::DoLoadFile(
688 const wxString
& rsFile
,
692 if ( wxTextCtrlBase::DoLoadFile(rsFile
, fileType
) )
695 // Update the size limit if needed
701 } // end of wxTextCtrl::DoLoadFile
703 bool wxTextCtrl::IsModified() const
708 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
710 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
712 } // end of wxTextCtrl::IsModified
714 void wxTextCtrl::MarkDirty()
717 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(TRUE
), 0);
719 // EM controls do not have a SETCHANGED, what can we do??
720 wxFAIL_MSG( _T("not implemented") );
724 // Makes 'unmodified'
726 void wxTextCtrl::DiscardEdits()
729 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
732 // EM controls do not have a SETCHANGED but issuing a query should reset it
734 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
735 } // end of wxTextCtrl::DiscardEdits
737 int wxTextCtrl::GetNumberOfLines() const
742 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
746 } // end of wxTextCtrl::GetNumberOfLines
748 long wxTextCtrl::XYToPosition(
753 long lCharIndex
= 0L;
758 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
759 lCharIndex
= ((lLen
* lY
) + lX
);
764 } // end of wxTextCtrl::XYToPosition
766 bool wxTextCtrl::PositionToXY(
772 HWND hWnd
= GetHwnd();
777 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
788 // This gets the char index for the _beginning_ of this line
794 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
795 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
801 vParams
.fsStatus
= WPM_CCHTEXT
;
802 if (::WinSendMsg( hWnd
803 ,WM_QUERYWINDOWPARAMS
808 lCharIndex
= vParams
.cchText
;
814 if (lCharIndex
== -1)
820 // The X position must therefore be the difference between pos and charIndex
823 *plX
= lPos
- lCharIndex
;
828 } // end of wxTextCtrl::PositionToXY
830 void wxTextCtrl::ShowPosition( long WXUNUSED(lPos
) )
832 HWND hWnd
= GetHwnd();
833 long lCurrentLineLineNo
= 0L;
835 // To scroll to a position, we pass the number of lines and characters
836 // to scroll *by*. This means that we need to:
837 // (1) Find the line position of the current line.
838 // (2) Find the line position of pos.
839 // (3) Scroll by (pos - current).
840 // For now, ignore the horizontal scrolling.
843 // Is this where scrolling is relative to - the line containing the caret?
844 // Or is the first visible line??? Try first visible line.
849 // In PM this is the actual char position
851 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
854 // This will cause a scroll to the selected position
856 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
858 } // end of wxTextCtrl::ShowPosition
860 int wxTextCtrl::GetLineLength( long WXUNUSED(lLineNo
) ) const
866 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
872 vParams
.fsStatus
= WPM_CCHTEXT
;
873 if (::WinSendMsg( GetHwnd()
874 ,WM_QUERYWINDOWPARAMS
879 lLen
= vParams
.cchText
;
885 } // end ofwxTextCtrl::GetLineLength
887 wxString
wxTextCtrl::GetLineText(
891 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
896 // There must be at least enough place for the length WORD in the
899 lLen
+= sizeof(WORD
);
900 zBuf
= new wxChar
[lLen
];
907 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
908 lIndex
= lLen
* lLineNo
;
910 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
911 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)WXSIZEOF(zBuf
)));
912 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
913 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
914 zBuf
[lCopied
] = '\0';
920 vParams
.fsStatus
= WPM_CCHTEXT
;
921 if (::WinSendMsg( GetHwnd()
922 ,WM_QUERYWINDOWPARAMS
926 memcpy((char*)zBuf
, vParams
.pszText
, vParams
.cchText
);
927 zBuf
[vParams
.cchText
] = '\0';
932 } // end of wxTextCtrl::GetLineText
934 // ----------------------------------------------------------------------------
936 // ----------------------------------------------------------------------------
938 void wxTextCtrl::Undo()
943 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
944 // Simple entryfields cannot be undone
946 } // end of wxTextCtrl::Undo
948 void wxTextCtrl::Redo()
953 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
954 // Simple entryfields cannot be undone
956 } // end of wxTextCtrl::Redo
958 bool wxTextCtrl::CanUndo() const
963 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
965 bOk
= false; // can't undo regular edit fields in PM
967 } // end of wxTextCtrl::CanUndo
969 bool wxTextCtrl::CanRedo() const
974 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
976 bOk
= false; // can't undo regular edit fields in PM
978 } // end of wxTextCtrl::CanRedo
980 // ----------------------------------------------------------------------------
981 // implemenation details
982 // ----------------------------------------------------------------------------
984 void wxTextCtrl::Command(
985 wxCommandEvent
& rEvent
988 SetValue(rEvent
.GetString());
989 ProcessCommand (rEvent
);
990 } // end of wxTextCtrl::Command
992 void wxTextCtrl::OnDropFiles(
993 wxDropFilesEvent
& rEvent
996 // By default, load the first file into the text window.
997 if (rEvent
.GetNumberOfFiles() > 0)
999 LoadFile(rEvent
.GetFiles()[0]);
1001 } // end of wxTextCtrl::OnDropFiles
1003 WXHBRUSH
wxTextCtrl::OnCtlColor( WXHDC hWxDC
,
1004 WXHWND
WXUNUSED(hWnd
),
1005 WXUINT
WXUNUSED(uCtlColor
),
1006 WXUINT
WXUNUSED(uMessage
),
1007 WXWPARAM
WXUNUSED(wParam
),
1008 WXLPARAM
WXUNUSED(lParam
) )
1010 HPS hPS
= (HPS
)hWxDC
;
1011 wxColour vColBack
= GetBackgroundColour();
1012 wxColour vColFore
= GetForegroundColour();
1013 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
, wxSOLID
);
1017 HBRUSH hBrush
= NULLHANDLE
;
1021 if (GetParent()->GetTransparentBackground())
1022 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1024 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1025 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1026 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1027 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1028 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1029 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1030 } // end of wxTextCtrl::OnCtlColor
1032 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1036 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1037 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1039 void wxTextCtrl::OnChar(
1043 switch (rEvent
.GetKeyCode())
1046 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1048 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1050 vEvent
.SetEventObject(this);
1051 if ( GetEventHandler()->ProcessEvent(vEvent
))
1054 //else: multiline controls need Enter for themselves
1059 // always produce navigation event - even if we process TAB
1060 // ourselves the fact that we got here means that the user code
1061 // decided to skip processing of this TAB - probably to let it
1062 // do its default job.
1064 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1065 // handled by Windows
1067 wxNavigationKeyEvent vEventNav
;
1069 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1070 vEventNav
.SetWindowChange(false);
1071 vEventNav
.SetEventObject(this);
1073 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1079 } // end of wxTextCtrl::OnChar
1081 bool wxTextCtrl::OS2Command(
1083 , WXWORD
WXUNUSED(vId
)
1091 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1096 vEvent
.SetEventObject(this);
1097 GetEventHandler()->ProcessEvent(vEvent
);
1105 m_bSkipUpdate
= false;
1109 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1113 InitCommandEvent(vEvent
);
1114 ProcessCommand(vEvent
);
1120 // The text size limit has been hit - increase it
1126 case EN_INSERTMODETOGGLE
:
1137 } // end of wxTextCtrl::OS2Command
1139 void wxTextCtrl::AdjustSpaceLimit()
1141 unsigned int uLen
= 0;
1142 unsigned int uLimit
= 0;
1144 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1147 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1158 vParams
.fsStatus
= WPM_CBCTLDATA
;
1159 vParams
.pCtlData
= &Efd
;
1160 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1162 if (::WinSendMsg( GetHwnd()
1163 ,WM_QUERYWINDOWPARAMS
1167 uLimit
= (unsigned int)Efd
.cchEditLimit
;
1169 uLimit
= 32; //PM's default
1173 uLimit
= uLen
+ 0x8000; // 32Kb
1174 if (uLimit
> 0xffff)
1179 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1181 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMSHORT(uLimit
), 0);
1183 } // end of wxTextCtrl::AdjustSpaceLimit
1185 bool wxTextCtrl::AcceptsFocus() const
1188 // We don't want focus if we can't be edited unless we're a multiline
1189 // control because then it might be still nice to get focus from keyboard
1190 // to be able to scroll it without mouse
1192 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1193 } // end of wxTextCtrl::Command
1195 wxSize
wxTextCtrl::DoGetBestSize() const
1199 wxFont vFont
= (wxFont
)GetFont();
1201 wxGetCharSize(GetHWND(), &nCx
, &nCy
, &vFont
);
1203 int wText
= DEFAULT_ITEM_WIDTH
;
1204 int hText
= (int)(EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1206 if (m_windowStyle
& wxTE_MULTILINE
)
1208 hText
*= wxMax(GetNumberOfLines(), 5);
1210 //else: for single line control everything is ok
1211 return wxSize(wText
, hText
);
1212 } // end of wxTextCtrl::DoGetBestSize
1214 // ----------------------------------------------------------------------------
1215 // standard handlers for standard edit menu events
1216 // ----------------------------------------------------------------------------
1218 void wxTextCtrl::OnCut( wxCommandEvent
& WXUNUSED(rEvent
) )
1221 } // end of wxTextCtrl::OnCut
1223 void wxTextCtrl::OnCopy( wxCommandEvent
& WXUNUSED(rEvent
) )
1226 } // end of wxTextCtrl::OnCopy
1228 void wxTextCtrl::OnPaste( wxCommandEvent
& WXUNUSED(rEvent
) )
1231 } // end of wxTextCtrl::OnPaste
1233 void wxTextCtrl::OnUndo( wxCommandEvent
& WXUNUSED(rEvent
) )
1236 } // end of wxTextCtrl::OnUndo
1238 void wxTextCtrl::OnRedo( wxCommandEvent
& WXUNUSED(rEvent
) )
1241 } // end of wxTextCtrl::OnRedo
1243 void wxTextCtrl::OnDelete( wxCommandEvent
& WXUNUSED(rEvent
) )
1247 GetSelection( &lFrom
, &lTo
);
1249 if (lFrom
!= -1 && lTo
!= -1)
1250 Remove( lFrom
, lTo
);
1251 } // end of wxTextCtrl::OnDelete
1253 void wxTextCtrl::OnSelectAll( wxCommandEvent
& WXUNUSED(rEvent
) )
1255 SetSelection(-1, -1);
1256 } // end of wxTextCtrl::OnSelectAll
1258 void wxTextCtrl::OnUpdateCut( wxUpdateUIEvent
& rEvent
)
1260 rEvent
.Enable(CanCut());
1261 } // end of wxTextCtrl::OnUpdateCut
1263 void wxTextCtrl::OnUpdateCopy( wxUpdateUIEvent
& rEvent
)
1265 rEvent
.Enable(CanCopy());
1266 } // end of wxTextCtrl::OnUpdateCopy
1268 void wxTextCtrl::OnUpdatePaste( wxUpdateUIEvent
& rEvent
)
1270 rEvent
.Enable(CanPaste());
1271 } // end of wxTextCtrl::OnUpdatePaste
1273 void wxTextCtrl::OnUpdateUndo( wxUpdateUIEvent
& rEvent
)
1275 rEvent
.Enable(CanUndo());
1276 } // end of wxTextCtrl::OnUpdateUndo
1278 void wxTextCtrl::OnUpdateRedo( wxUpdateUIEvent
& rEvent
)
1280 rEvent
.Enable(CanRedo());
1281 } // end of wxTextCtrl::OnUpdateRedo
1283 void wxTextCtrl::OnUpdateDelete( wxUpdateUIEvent
& rEvent
)
1287 GetSelection( &lFrom
, &lTo
);
1288 rEvent
.Enable( lFrom
!= -1L && lTo
!= -1L && lFrom
!= lTo
&& IsEditable()) ;
1289 } // end of wxTextCtrl::OnUpdateDelete
1291 void wxTextCtrl::OnUpdateSelectAll( wxUpdateUIEvent
& rEvent
)
1293 rEvent
.Enable(GetLastPosition() > 0);
1294 } // end of wxTextCtrl::OnUpdateSelectAll
1296 bool wxTextCtrl::SetBackgroundColour( const wxColour
& rColour
)
1299 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1301 } // end of wxTextCtrl::SetBackgroundColour
1303 bool wxTextCtrl::SetForegroundColour( const wxColour
& rColour
)
1306 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1308 } // end of wxTextCtrl::SetForegroundColour
1310 bool wxTextCtrl::SetStyle( long lStart
,
1312 const wxTextAttr
& WXUNUSED(rStyle
) )
1314 HWND hWnd
= GetHwnd();
1325 // We can only change the format of the selection, so select the range we
1326 // want and restore the old selection later
1328 long lStartOld
, lEndOld
;
1330 GetSelection( &lStartOld
, &lEndOld
);
1333 // But do we really have to change the selection?
1335 bool bChangeSel
= lStart
!= lStartOld
||
1341 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1343 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1347 // TODO:: finish this part
1350 } // end of wxTextCtrl::SetStyle