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 BEGIN_EVENT_TABLE(wxTextCtrl
, wxTextCtrlBase
)
59 EVT_CHAR(wxTextCtrl::OnChar
)
60 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
62 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
63 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
64 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
65 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
66 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
68 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
69 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
70 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
71 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
72 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 wxTextCtrl::wxTextCtrl()
88 wxTextCtrl::~wxTextCtrl()
92 bool wxTextCtrl::Create(
95 , const wxString
& rsValue
99 , const wxValidator
& rValidator
100 , const wxString
& rsName
104 // Base initialization
106 if ( !CreateBase( pParent
116 wxPoint vPos
= rPos
; // The OS/2 position
121 pParent
->AddChild(this);
124 m_windowStyle
= lStyle
;
126 m_bSkipUpdate
= false;
128 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
131 // Single and multiline edit fields are two different controls in PM
133 if ( m_windowStyle
& wxTE_MULTILINE
)
135 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
138 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
139 lSstyle
|= MLS_VSCROLL
;
140 if (m_windowStyle
& wxHSCROLL
)
141 lSstyle
|= MLS_HSCROLL
;
142 if (m_windowStyle
& wxTE_READONLY
)
143 lSstyle
|= MLS_READONLY
;
147 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
149 if (m_windowStyle
& wxHSCROLL
)
150 lSstyle
|= ES_AUTOSCROLL
;
151 if (m_windowStyle
& wxTE_READONLY
)
152 lSstyle
|= ES_READONLY
;
153 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
154 lSstyle
|= ES_UNREADABLE
;
159 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
160 ,WC_MLE
// Window class
161 ,rsValue
.c_str() // Initial Text
162 ,(ULONG
)lSstyle
// Style flags
163 ,(LONG
)0 // X pos of origin
164 ,(LONG
)0 // Y pos of origin
165 ,(LONG
)0 // field width
166 ,(LONG
)0 // field height
167 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
168 ,HWND_TOP
// initial z position
169 ,(ULONG
)vId
// Window identifier
170 ,NULL
// no control data
171 ,NULL
// no Presentation parameters
176 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
177 ,WC_ENTRYFIELD
// Window class
178 ,rsValue
.c_str() // Initial Text
179 ,(ULONG
)lSstyle
// Style flags
180 ,(LONG
)0 // X pos of origin
181 ,(LONG
)0 // Y pos of origin
182 ,(LONG
)0 // field width
183 ,(LONG
)0 // field height
184 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
185 ,HWND_TOP
// initial z position
186 ,(ULONG
)vId
// Window identifier
187 ,NULL
// no control data
188 ,NULL
// no Presentation parameters
197 SubclassWin(GetHWND());
200 // Set font, position, size and initial value
202 wxFont
* pTextFont
= new wxFont( 8
208 if (!rsValue
.empty())
214 // If X and/or Y are not zero the difference is the compensation value
215 // for margins for OS/2 controls.
217 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
220 SetSize( vPos
.x
- GetXComp()
227 } // end of wxTextCtrl::Create
230 // Make sure the window style (etc.) reflects the HWND style (roughly)
232 void wxTextCtrl::AdoptAttributesFromHWND()
234 HWND hWnd
= GetHwnd();
235 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
237 wxWindow::AdoptAttributesFromHWND();
241 m_windowStyle
|= wxTE_MULTILINE
;
242 if (lStyle
& MLS_READONLY
)
243 m_windowStyle
|= wxTE_READONLY
;
247 if (lStyle
& ES_UNREADABLE
)
248 m_windowStyle
|= wxTE_PASSWORD
;
249 if (lStyle
& ES_READONLY
)
250 m_windowStyle
|= wxTE_READONLY
;
252 } // end of wxTextCtrl::AdoptAttributesFromHWND
254 WXDWORD
wxTextCtrl::OS2GetStyle(
256 , WXDWORD
* pdwExstyle
260 // Default border for the text controls is the sunken one
262 if ((lStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
264 lStyle
|= wxBORDER_SUNKEN
;
267 long dwStyle
= wxControl::OS2GetStyle( lStyle
271 dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
274 // Single and multiline edit fields are two different controls in PM
276 if ( m_windowStyle
& wxTE_MULTILINE
)
278 dwStyle
|= MLS_BORDER
| MLS_WORDWRAP
;
279 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
280 dwStyle
|= MLS_VSCROLL
;
281 if (m_windowStyle
& wxHSCROLL
)
282 dwStyle
|= MLS_HSCROLL
;
283 if (m_windowStyle
& wxTE_READONLY
)
284 dwStyle
|= MLS_READONLY
;
288 dwStyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
289 if (m_windowStyle
& wxHSCROLL
)
290 dwStyle
|= ES_AUTOSCROLL
;
291 if (m_windowStyle
& wxTE_READONLY
)
292 dwStyle
|= ES_READONLY
;
293 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
294 dwStyle
|= ES_UNREADABLE
;
297 } // end of wxTextCtrl::OS2GetStyle
299 void wxTextCtrl::SetWindowStyleFlag(
303 wxControl::SetWindowStyleFlag(lStyle
);
304 } // end of wxTextCtrl::SetWindowStyleFlag
306 void wxTextCtrl::SetupColours()
308 wxColour vBkgndColour
;
310 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
311 SetBackgroundColour(vBkgndColour
);
312 SetForegroundColour(GetParent()->GetForegroundColour());
315 ::WinSendMsg( GetHwnd()
317 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
321 } // end of wxTextCtrl::SetupColours
323 // ----------------------------------------------------------------------------
324 // set/get the controls text
325 // ----------------------------------------------------------------------------
327 wxString
wxTextCtrl::GetValue() const
329 wxString sStr
= wxGetWindowText(GetHWND());
330 wxCharBuffer
buf(sStr
.char_str());
331 char* zStr
= buf
.data();
333 for ( ; *zStr
; zStr
++ )
336 // this will replace \r\n with just \n
344 } // end of wxTextCtrl::GetValue
346 void wxTextCtrl::DoSetValue(
347 const wxString
& rsValue
,
352 // If the text is long enough, it's faster to just set it instead of first
353 // comparing it with the old one (chances are that it will be different
354 // anyhow, this comparison is there to avoid flicker for small single-line
355 // edit controls mostly)
357 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
359 if ( flags
& SetValue_SendEvent
)
360 m_bSkipUpdate
= true;
362 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
365 } // end of wxTextCtrl::SetValue
367 void wxTextCtrl::WriteText(
368 const wxString
& rsValue
372 ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM(rsValue
.wx_str()), MPARAM(0));
374 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
376 } // end of wxTextCtrl::WriteText
378 void wxTextCtrl::AppendText(
379 const wxString
& rsText
382 SetInsertionPointEnd();
384 } // end of wxTextCtrl::AppendText
386 void wxTextCtrl::Clear()
388 ::WinSetWindowText(GetHwnd(), "");
389 } // end of wxTextCtrl::Clear
391 bool wxTextCtrl::EmulateKeyPress(
392 const wxKeyEvent
& rEvent
396 return(wxTextCtrlBase::EmulateKeyPress(rEvent
));
397 } // end of wxTextCtrl::EmulateKeyPress
399 // ----------------------------------------------------------------------------
400 // Clipboard operations
401 // ----------------------------------------------------------------------------
403 void wxTextCtrl::Copy()
407 HWND hWnd
= GetHwnd();
409 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
411 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
413 } // end of wxTextCtrl::Copy
415 void wxTextCtrl::Cut()
419 HWND hWnd
= GetHwnd();
422 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
424 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
426 } // end of wxTextCtrl::Cut
428 void wxTextCtrl::Paste()
432 HWND hWnd
= GetHwnd();
434 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
436 } // end of wxTextCtrl::Paste
438 bool wxTextCtrl::CanCopy() const
441 // Can copy if there's a selection
446 GetSelection(&lFrom
, &lTo
);
447 return (lFrom
!= lTo
);
448 } // end of wxTextCtrl::CanCopy
450 bool wxTextCtrl::CanCut() const
453 // Can cut if there's a selection
458 GetSelection(&lFrom
, &lTo
);
459 return (lFrom
!= lTo
);
460 } // end of wxTextCtrl::CanCut
462 bool wxTextCtrl::CanPaste() const
464 bool bIsTextAvailable
= false;
470 // Check for straight text on clipboard
472 if (::WinOpenClipbrd(vHabmain
))
474 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
475 ::WinCloseClipbrd(vHabmain
);
477 return bIsTextAvailable
;
478 } // end of wxTextCtrl::CanPaste
480 // ----------------------------------------------------------------------------
482 // ----------------------------------------------------------------------------
484 void wxTextCtrl::SetEditable(
488 HWND hWnd
= GetHwnd();
491 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
493 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
494 } // end of wxTextCtrl::SetEditable
496 void wxTextCtrl::SetInsertionPoint(
500 HWND hWnd
= GetHwnd();
503 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
505 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
506 } // end of wxTextCtrl::SetInsertionPoint
508 void wxTextCtrl::SetInsertionPointEnd()
510 wxTextPos lPos
= GetLastPosition();
513 // We must not do anything if the caret is already there because calling
514 // SetInsertionPoint() thaws the controls if Freeze() had been called even
515 // if it doesn't actually move the caret anywhere and so the simple fact of
516 // doing it results in horrible flicker when appending big amounts of text
517 // to the control in a few chunks (see DoAddText() test in the text sample)
519 if (GetInsertionPoint() == GetLastPosition())
521 SetInsertionPoint(lPos
);
522 } // end of wxTextCtrl::SetInsertionPointEnd
524 long wxTextCtrl::GetInsertionPoint() const
529 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
532 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
533 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
535 return (dwPos
& 0xFFFF);
536 } // end of wxTextCtrl::GetInsertionPoint
538 wxTextPos
wxTextCtrl::GetLastPosition() const
540 HWND hWnd
= GetHwnd();
549 // This just gets the total text length. The last will be this value
551 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
558 vParams
.fsStatus
= WPM_CCHTEXT
;
559 if (::WinSendMsg( GetHwnd()
560 ,WM_QUERYWINDOWPARAMS
565 lLineLength
= (long)vParams
.cchText
;
570 return(lCharIndex
+ lLineLength
);
571 } // end of wxTextCtrl::GetLastPosition
573 // If the return values from and to are the same, there is no
575 void wxTextCtrl::GetSelection(
583 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
586 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
588 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
589 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
590 } // end of wxTextCtrl::GetSelection
592 bool wxTextCtrl::IsEditable() const
595 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
597 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
598 } // end of wxTextCtrl::IsEditable
600 // ----------------------------------------------------------------------------
602 // ----------------------------------------------------------------------------
604 void wxTextCtrl::Replace( long lFrom
,
606 const wxString
& rsValue
)
609 HWND hWnd
= GetHwnd();
612 // Set selection and remove it
616 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
617 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
621 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
622 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
626 // Now replace with 'value', by pasting.
628 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
630 // Paste into edit control
632 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
634 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
638 wxUnusedVar(rsValue
);
639 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
641 } // end of wxTextCtrl::Replace
643 void wxTextCtrl::Remove(
648 HWND hWnd
= GetHwnd();
652 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
653 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
657 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
658 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
660 } // end of wxTextCtrl::Remove
662 void wxTextCtrl::SetSelection(
667 HWND hWnd
= GetHwnd();
668 long lFromChar
= lFrom
;
672 // If from and to are both -1, it means (in wxWidgets) that all text should
673 // be selected. Translate into Windows convention
675 if ((lFrom
== -1L) && (lTo
== -1L))
681 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
683 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
684 } // end of wxTextCtrl::SetSelection
686 bool wxTextCtrl::DoLoadFile(
687 const wxString
& rsFile
,
691 if ( wxTextCtrlBase::DoLoadFile(rsFile
, fileType
) )
694 // Update the size limit if needed
700 } // end of wxTextCtrl::DoLoadFile
702 bool wxTextCtrl::IsModified() const
707 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
709 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
711 } // end of wxTextCtrl::IsModified
713 void wxTextCtrl::MarkDirty()
716 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(TRUE
), 0);
718 // EM controls do not have a SETCHANGED, what can we do??
719 wxFAIL_MSG( wxT("not implemented") );
723 // Makes 'unmodified'
725 void wxTextCtrl::DiscardEdits()
728 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
731 // EM controls do not have a SETCHANGED but issuing a query should reset it
733 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
734 } // end of wxTextCtrl::DiscardEdits
736 int wxTextCtrl::GetNumberOfLines() const
741 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
745 } // end of wxTextCtrl::GetNumberOfLines
747 long wxTextCtrl::XYToPosition(
752 long lCharIndex
= 0L;
757 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
758 lCharIndex
= ((lLen
* lY
) + lX
);
763 } // end of wxTextCtrl::XYToPosition
765 bool wxTextCtrl::PositionToXY(
771 HWND hWnd
= GetHwnd();
776 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
787 // This gets the char index for the _beginning_ of this line
793 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
794 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
800 vParams
.fsStatus
= WPM_CCHTEXT
;
801 if (::WinSendMsg( hWnd
802 ,WM_QUERYWINDOWPARAMS
807 lCharIndex
= vParams
.cchText
;
813 if (lCharIndex
== -1)
819 // The X position must therefore be the difference between pos and charIndex
822 *plX
= lPos
- lCharIndex
;
827 } // end of wxTextCtrl::PositionToXY
829 void wxTextCtrl::ShowPosition( long WXUNUSED(lPos
) )
831 HWND hWnd
= GetHwnd();
832 long lCurrentLineLineNo
= 0L;
834 // To scroll to a position, we pass the number of lines and characters
835 // to scroll *by*. This means that we need to:
836 // (1) Find the line position of the current line.
837 // (2) Find the line position of pos.
838 // (3) Scroll by (pos - current).
839 // For now, ignore the horizontal scrolling.
842 // Is this where scrolling is relative to - the line containing the caret?
843 // Or is the first visible line??? Try first visible line.
848 // In PM this is the actual char position
850 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
853 // This will cause a scroll to the selected position
855 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
857 } // end of wxTextCtrl::ShowPosition
859 int wxTextCtrl::GetLineLength( long WXUNUSED(lLineNo
) ) const
865 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
871 vParams
.fsStatus
= WPM_CCHTEXT
;
872 if (::WinSendMsg( GetHwnd()
873 ,WM_QUERYWINDOWPARAMS
878 lLen
= vParams
.cchText
;
884 } // end ofwxTextCtrl::GetLineLength
886 wxString
wxTextCtrl::GetLineText(
890 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
895 // There must be at least enough place for the length WORD in the
898 lLen
+= sizeof(WORD
);
899 zBuf
= new wxChar
[lLen
];
906 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
907 lIndex
= lLen
* lLineNo
;
909 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
910 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)WXSIZEOF(zBuf
)));
911 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
912 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
913 zBuf
[lCopied
] = '\0';
919 vParams
.fsStatus
= WPM_CCHTEXT
;
920 if (::WinSendMsg( GetHwnd()
921 ,WM_QUERYWINDOWPARAMS
925 memcpy((char*)zBuf
, vParams
.pszText
, vParams
.cchText
);
926 zBuf
[vParams
.cchText
] = '\0';
931 } // end of wxTextCtrl::GetLineText
933 // ----------------------------------------------------------------------------
935 // ----------------------------------------------------------------------------
937 void wxTextCtrl::Undo()
942 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
943 // Simple entryfields cannot be undone
945 } // end of wxTextCtrl::Undo
947 void wxTextCtrl::Redo()
952 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
953 // Simple entryfields cannot be undone
955 } // end of wxTextCtrl::Redo
957 bool wxTextCtrl::CanUndo() const
962 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
964 bOk
= false; // can't undo regular edit fields in PM
966 } // end of wxTextCtrl::CanUndo
968 bool wxTextCtrl::CanRedo() const
973 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
975 bOk
= false; // can't undo regular edit fields in PM
977 } // end of wxTextCtrl::CanRedo
979 // ----------------------------------------------------------------------------
980 // implemenation details
981 // ----------------------------------------------------------------------------
983 void wxTextCtrl::Command(
984 wxCommandEvent
& rEvent
987 SetValue(rEvent
.GetString());
988 ProcessCommand (rEvent
);
989 } // end of wxTextCtrl::Command
991 void wxTextCtrl::OnDropFiles(
992 wxDropFilesEvent
& rEvent
995 // By default, load the first file into the text window.
996 if (rEvent
.GetNumberOfFiles() > 0)
998 LoadFile(rEvent
.GetFiles()[0]);
1000 } // end of wxTextCtrl::OnDropFiles
1002 WXHBRUSH
wxTextCtrl::OnCtlColor( WXHDC hWxDC
,
1003 WXHWND
WXUNUSED(hWnd
),
1004 WXUINT
WXUNUSED(uCtlColor
),
1005 WXUINT
WXUNUSED(uMessage
),
1006 WXWPARAM
WXUNUSED(wParam
),
1007 WXLPARAM
WXUNUSED(lParam
) )
1009 HPS hPS
= (HPS
)hWxDC
;
1010 wxColour vColBack
= GetBackgroundColour();
1011 wxColour vColFore
= GetForegroundColour();
1012 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
, wxSOLID
);
1016 HBRUSH hBrush
= NULLHANDLE
;
1020 if (GetParent()->GetTransparentBackground())
1021 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1023 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1024 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1025 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1026 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1027 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1028 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1029 } // end of wxTextCtrl::OnCtlColor
1031 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1035 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1036 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1038 void wxTextCtrl::OnChar(
1042 switch (rEvent
.GetKeyCode())
1045 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1047 wxCommandEvent
vEvent(wxEVT_TEXT_ENTER
, m_windowId
);
1049 vEvent
.SetEventObject(this);
1050 if ( HandleWindowEvent(vEvent
))
1053 //else: multiline controls need Enter for themselves
1058 // always produce navigation event - even if we process TAB
1059 // ourselves the fact that we got here means that the user code
1060 // decided to skip processing of this TAB - probably to let it
1061 // do its default job.
1063 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1064 // handled by Windows
1066 wxNavigationKeyEvent vEventNav
;
1068 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1069 vEventNav
.SetWindowChange(false);
1070 vEventNav
.SetEventObject(this);
1072 if ( HandleWindowEvent(vEventNav
) )
1078 } // end of wxTextCtrl::OnChar
1080 bool wxTextCtrl::OS2Command(
1082 , WXWORD
WXUNUSED(vId
)
1090 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1095 vEvent
.SetEventObject(this);
1096 HandleWindowEvent(vEvent
);
1104 m_bSkipUpdate
= false;
1108 wxCommandEvent
vEvent( wxEVT_TEXT
1112 InitCommandEvent(vEvent
);
1113 ProcessCommand(vEvent
);
1119 // The text size limit has been hit - increase it
1125 case EN_INSERTMODETOGGLE
:
1136 } // end of wxTextCtrl::OS2Command
1138 void wxTextCtrl::AdjustSpaceLimit()
1140 unsigned int uLen
= 0;
1141 unsigned int uLimit
= 0;
1143 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1146 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1157 vParams
.fsStatus
= WPM_CBCTLDATA
;
1158 vParams
.pCtlData
= &Efd
;
1159 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1161 if (::WinSendMsg( GetHwnd()
1162 ,WM_QUERYWINDOWPARAMS
1166 uLimit
= (unsigned int)Efd
.cchEditLimit
;
1168 uLimit
= 32; //PM's default
1174 uLimit
= uLen
+ 0x8000; // 32Kb
1175 if (uLimit
> 0xffff)
1184 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1186 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMSHORT(uLimit
), 0);
1188 } // end of wxTextCtrl::AdjustSpaceLimit
1190 bool wxTextCtrl::AcceptsFocus() const
1193 // We don't want focus if we can't be edited unless we're a multiline
1194 // control because then it might be still nice to get focus from keyboard
1195 // to be able to scroll it without mouse
1197 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1198 } // end of wxTextCtrl::Command
1200 wxSize
wxTextCtrl::DoGetBestSize() const
1204 wxFont vFont
= (wxFont
)GetFont();
1206 wxGetCharSize(GetHWND(), &nCx
, &nCy
, &vFont
);
1208 int wText
= DEFAULT_ITEM_WIDTH
;
1209 int hText
= (int)(EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1211 if (m_windowStyle
& wxTE_MULTILINE
)
1213 hText
*= wxMax(GetNumberOfLines(), 5);
1215 //else: for single line control everything is ok
1216 return wxSize(wText
, hText
);
1217 } // end of wxTextCtrl::DoGetBestSize
1219 // ----------------------------------------------------------------------------
1220 // standard handlers for standard edit menu events
1221 // ----------------------------------------------------------------------------
1223 void wxTextCtrl::OnCut( wxCommandEvent
& WXUNUSED(rEvent
) )
1226 } // end of wxTextCtrl::OnCut
1228 void wxTextCtrl::OnCopy( wxCommandEvent
& WXUNUSED(rEvent
) )
1231 } // end of wxTextCtrl::OnCopy
1233 void wxTextCtrl::OnPaste( wxCommandEvent
& WXUNUSED(rEvent
) )
1236 } // end of wxTextCtrl::OnPaste
1238 void wxTextCtrl::OnUndo( wxCommandEvent
& WXUNUSED(rEvent
) )
1241 } // end of wxTextCtrl::OnUndo
1243 void wxTextCtrl::OnRedo( wxCommandEvent
& WXUNUSED(rEvent
) )
1246 } // end of wxTextCtrl::OnRedo
1248 void wxTextCtrl::OnDelete( wxCommandEvent
& WXUNUSED(rEvent
) )
1252 GetSelection( &lFrom
, &lTo
);
1254 if (lFrom
!= -1 && lTo
!= -1)
1255 Remove( lFrom
, lTo
);
1256 } // end of wxTextCtrl::OnDelete
1258 void wxTextCtrl::OnSelectAll( wxCommandEvent
& WXUNUSED(rEvent
) )
1260 SetSelection(-1, -1);
1261 } // end of wxTextCtrl::OnSelectAll
1263 void wxTextCtrl::OnUpdateCut( wxUpdateUIEvent
& rEvent
)
1265 rEvent
.Enable(CanCut());
1266 } // end of wxTextCtrl::OnUpdateCut
1268 void wxTextCtrl::OnUpdateCopy( wxUpdateUIEvent
& rEvent
)
1270 rEvent
.Enable(CanCopy());
1271 } // end of wxTextCtrl::OnUpdateCopy
1273 void wxTextCtrl::OnUpdatePaste( wxUpdateUIEvent
& rEvent
)
1275 rEvent
.Enable(CanPaste());
1276 } // end of wxTextCtrl::OnUpdatePaste
1278 void wxTextCtrl::OnUpdateUndo( wxUpdateUIEvent
& rEvent
)
1280 rEvent
.Enable(CanUndo());
1281 } // end of wxTextCtrl::OnUpdateUndo
1283 void wxTextCtrl::OnUpdateRedo( wxUpdateUIEvent
& rEvent
)
1285 rEvent
.Enable(CanRedo());
1286 } // end of wxTextCtrl::OnUpdateRedo
1288 void wxTextCtrl::OnUpdateDelete( wxUpdateUIEvent
& rEvent
)
1292 GetSelection( &lFrom
, &lTo
);
1293 rEvent
.Enable( lFrom
!= -1L && lTo
!= -1L && lFrom
!= lTo
&& IsEditable()) ;
1294 } // end of wxTextCtrl::OnUpdateDelete
1296 void wxTextCtrl::OnUpdateSelectAll( wxUpdateUIEvent
& rEvent
)
1298 rEvent
.Enable(GetLastPosition() > 0);
1299 } // end of wxTextCtrl::OnUpdateSelectAll
1301 bool wxTextCtrl::SetBackgroundColour( const wxColour
& rColour
)
1304 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1306 } // end of wxTextCtrl::SetBackgroundColour
1308 bool wxTextCtrl::SetForegroundColour( const wxColour
& rColour
)
1311 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1313 } // end of wxTextCtrl::SetForegroundColour
1315 bool wxTextCtrl::SetStyle( long lStart
,
1317 const wxTextAttr
& WXUNUSED(rStyle
) )
1319 HWND hWnd
= GetHwnd();
1330 // We can only change the format of the selection, so select the range we
1331 // want and restore the old selection later
1333 long lStartOld
, lEndOld
;
1335 GetSelection( &lStartOld
, &lEndOld
);
1338 // But do we really have to change the selection?
1340 bool bChangeSel
= lStart
!= lStartOld
||
1346 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1348 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1352 // TODO:: finish this part
1355 } // end of wxTextCtrl::SetStyle