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
;
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::DoLoadFile(
683 const wxString
& rsFile
,
687 if ( wxTextCtrlBase::DoLoadFile(rsFile
, fileType
) )
690 // Update the size limit if needed
696 } // end of wxTextCtrl::DoLoadFile
698 bool wxTextCtrl::IsModified() const
703 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
705 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
707 } // end of wxTextCtrl::IsModified
709 void wxTextCtrl::MarkDirty()
712 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(TRUE
), 0);
714 // EM controls do not have a SETCHANGED, what can we do??
715 wxFAIL_MSG( _T("not implemented") );
719 // Makes 'unmodified'
721 void wxTextCtrl::DiscardEdits()
724 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
727 // EM controls do not have a SETCHANGED but issuing a query should reset it
729 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
730 } // end of wxTextCtrl::DiscardEdits
732 int wxTextCtrl::GetNumberOfLines() const
737 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
741 } // end of wxTextCtrl::GetNumberOfLines
743 long wxTextCtrl::XYToPosition(
748 long lCharIndex
= 0L;
753 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
754 lCharIndex
= ((lLen
* lY
) + lX
);
759 } // end of wxTextCtrl::XYToPosition
761 bool wxTextCtrl::PositionToXY(
767 HWND hWnd
= GetHwnd();
772 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
783 // This gets the char index for the _beginning_ of this line
789 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
790 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
796 vParams
.fsStatus
= WPM_CCHTEXT
;
797 if (::WinSendMsg( hWnd
798 ,WM_QUERYWINDOWPARAMS
803 lCharIndex
= vParams
.cchText
;
809 if (lCharIndex
== -1)
815 // The X position must therefore be the difference between pos and charIndex
818 *plX
= lPos
- lCharIndex
;
823 } // end of wxTextCtrl::PositionToXY
825 void wxTextCtrl::ShowPosition( long WXUNUSED(lPos
) )
827 HWND hWnd
= GetHwnd();
828 long lCurrentLineLineNo
= 0L;
830 // To scroll to a position, we pass the number of lines and characters
831 // to scroll *by*. This means that we need to:
832 // (1) Find the line position of the current line.
833 // (2) Find the line position of pos.
834 // (3) Scroll by (pos - current).
835 // For now, ignore the horizontal scrolling.
838 // Is this where scrolling is relative to - the line containing the caret?
839 // Or is the first visible line??? Try first visible line.
844 // In PM this is the actual char position
846 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
849 // This will cause a scroll to the selected position
851 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
853 } // end of wxTextCtrl::ShowPosition
855 int wxTextCtrl::GetLineLength( long WXUNUSED(lLineNo
) ) const
861 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
867 vParams
.fsStatus
= WPM_CCHTEXT
;
868 if (::WinSendMsg( GetHwnd()
869 ,WM_QUERYWINDOWPARAMS
874 lLen
= vParams
.cchText
;
880 } // end ofwxTextCtrl::GetLineLength
882 wxString
wxTextCtrl::GetLineText(
886 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
891 // There must be at least enough place for the length WORD in the
894 lLen
+= sizeof(WORD
);
895 zBuf
= new wxChar
[lLen
];
902 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
903 lIndex
= lLen
* lLineNo
;
905 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
906 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)WXSIZEOF(zBuf
)));
907 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
908 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
909 zBuf
[lCopied
] = '\0';
915 vParams
.fsStatus
= WPM_CCHTEXT
;
916 if (::WinSendMsg( GetHwnd()
917 ,WM_QUERYWINDOWPARAMS
921 memcpy((char*)zBuf
, vParams
.pszText
, vParams
.cchText
);
922 zBuf
[vParams
.cchText
] = '\0';
927 } // end of wxTextCtrl::GetLineText
929 // ----------------------------------------------------------------------------
931 // ----------------------------------------------------------------------------
933 void wxTextCtrl::Undo()
938 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
939 // Simple entryfields cannot be undone
941 } // end of wxTextCtrl::Undo
943 void wxTextCtrl::Redo()
948 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
949 // Simple entryfields cannot be undone
951 } // end of wxTextCtrl::Redo
953 bool wxTextCtrl::CanUndo() const
958 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
960 bOk
= false; // can't undo regular edit fields in PM
962 } // end of wxTextCtrl::CanUndo
964 bool wxTextCtrl::CanRedo() const
969 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
971 bOk
= false; // can't undo regular edit fields in PM
973 } // end of wxTextCtrl::CanRedo
975 // ----------------------------------------------------------------------------
976 // implemenation details
977 // ----------------------------------------------------------------------------
979 void wxTextCtrl::Command(
980 wxCommandEvent
& rEvent
983 SetValue(rEvent
.GetString());
984 ProcessCommand (rEvent
);
985 } // end of wxTextCtrl::Command
987 void wxTextCtrl::OnDropFiles(
988 wxDropFilesEvent
& rEvent
991 // By default, load the first file into the text window.
992 if (rEvent
.GetNumberOfFiles() > 0)
994 LoadFile(rEvent
.GetFiles()[0]);
996 } // end of wxTextCtrl::OnDropFiles
998 WXHBRUSH
wxTextCtrl::OnCtlColor( WXHDC hWxDC
,
999 WXHWND
WXUNUSED(hWnd
),
1000 WXUINT
WXUNUSED(uCtlColor
),
1001 WXUINT
WXUNUSED(uMessage
),
1002 WXWPARAM
WXUNUSED(wParam
),
1003 WXLPARAM
WXUNUSED(lParam
) )
1005 HPS hPS
= (HPS
)hWxDC
;
1006 wxColour vColBack
= GetBackgroundColour();
1007 wxColour vColFore
= GetForegroundColour();
1008 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( vColBack
, wxSOLID
);
1012 HBRUSH hBrush
= NULLHANDLE
;
1016 if (GetParent()->GetTransparentBackground())
1017 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1019 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1020 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1021 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1022 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1023 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1024 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1025 } // end of wxTextCtrl::OnCtlColor
1027 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1031 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1032 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1034 void wxTextCtrl::OnChar(
1038 switch (rEvent
.GetKeyCode())
1041 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1043 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1045 vEvent
.SetEventObject(this);
1046 if ( GetEventHandler()->ProcessEvent(vEvent
))
1049 //else: multiline controls need Enter for themselves
1054 // always produce navigation event - even if we process TAB
1055 // ourselves the fact that we got here means that the user code
1056 // decided to skip processing of this TAB - probably to let it
1057 // do its default job.
1059 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1060 // handled by Windows
1062 wxNavigationKeyEvent vEventNav
;
1064 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1065 vEventNav
.SetWindowChange(false);
1066 vEventNav
.SetEventObject(this);
1068 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1074 } // end of wxTextCtrl::OnChar
1076 bool wxTextCtrl::OS2Command(
1078 , WXWORD
WXUNUSED(vId
)
1086 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1091 vEvent
.SetEventObject(this);
1092 GetEventHandler()->ProcessEvent(vEvent
);
1098 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1102 InitCommandEvent(vEvent
);
1103 ProcessCommand(vEvent
);
1109 // The text size limit has been hit - increase it
1115 case EN_INSERTMODETOGGLE
:
1126 } // end of wxTextCtrl::OS2Command
1128 void wxTextCtrl::AdjustSpaceLimit()
1130 unsigned int uLen
= 0;
1131 unsigned int uLimit
= 0;
1133 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1136 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1147 vParams
.fsStatus
= WPM_CBCTLDATA
;
1148 vParams
.pCtlData
= &Efd
;
1149 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1151 if (::WinSendMsg( GetHwnd()
1152 ,WM_QUERYWINDOWPARAMS
1156 uLimit
= (unsigned int)Efd
.cchEditLimit
;
1158 uLimit
= 32; //PM's default
1162 uLimit
= uLen
+ 0x8000; // 32Kb
1163 if (uLimit
> 0xffff)
1168 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1170 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMSHORT(uLimit
), 0);
1172 } // end of wxTextCtrl::AdjustSpaceLimit
1174 bool wxTextCtrl::AcceptsFocus() const
1177 // We don't want focus if we can't be edited unless we're a multiline
1178 // control because then it might be still nice to get focus from keyboard
1179 // to be able to scroll it without mouse
1181 return (IsEditable() || IsMultiLine()) && wxControl::AcceptsFocus();
1182 } // end of wxTextCtrl::Command
1184 wxSize
wxTextCtrl::DoGetBestSize() const
1188 wxFont vFont
= (wxFont
)GetFont();
1190 wxGetCharSize(GetHWND(), &nCx
, &nCy
, &vFont
);
1192 int wText
= DEFAULT_ITEM_WIDTH
;
1193 int hText
= (int)(EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1195 if (m_windowStyle
& wxTE_MULTILINE
)
1197 hText
*= wxMax(GetNumberOfLines(), 5);
1199 //else: for single line control everything is ok
1200 return wxSize(wText
, hText
);
1201 } // end of wxTextCtrl::DoGetBestSize
1203 // ----------------------------------------------------------------------------
1204 // standard handlers for standard edit menu events
1205 // ----------------------------------------------------------------------------
1207 void wxTextCtrl::OnCut( wxCommandEvent
& WXUNUSED(rEvent
) )
1210 } // end of wxTextCtrl::OnCut
1212 void wxTextCtrl::OnCopy( wxCommandEvent
& WXUNUSED(rEvent
) )
1215 } // end of wxTextCtrl::OnCopy
1217 void wxTextCtrl::OnPaste( wxCommandEvent
& WXUNUSED(rEvent
) )
1220 } // end of wxTextCtrl::OnPaste
1222 void wxTextCtrl::OnUndo( wxCommandEvent
& WXUNUSED(rEvent
) )
1225 } // end of wxTextCtrl::OnUndo
1227 void wxTextCtrl::OnRedo( wxCommandEvent
& WXUNUSED(rEvent
) )
1230 } // end of wxTextCtrl::OnRedo
1232 void wxTextCtrl::OnDelete( wxCommandEvent
& WXUNUSED(rEvent
) )
1236 GetSelection( &lFrom
, &lTo
);
1238 if (lFrom
!= -1 && lTo
!= -1)
1239 Remove( lFrom
, lTo
);
1240 } // end of wxTextCtrl::OnDelete
1242 void wxTextCtrl::OnSelectAll( wxCommandEvent
& WXUNUSED(rEvent
) )
1244 SetSelection(-1, -1);
1245 } // end of wxTextCtrl::OnSelectAll
1247 void wxTextCtrl::OnUpdateCut( wxUpdateUIEvent
& rEvent
)
1249 rEvent
.Enable(CanCut());
1250 } // end of wxTextCtrl::OnUpdateCut
1252 void wxTextCtrl::OnUpdateCopy( wxUpdateUIEvent
& rEvent
)
1254 rEvent
.Enable(CanCopy());
1255 } // end of wxTextCtrl::OnUpdateCopy
1257 void wxTextCtrl::OnUpdatePaste( wxUpdateUIEvent
& rEvent
)
1259 rEvent
.Enable(CanPaste());
1260 } // end of wxTextCtrl::OnUpdatePaste
1262 void wxTextCtrl::OnUpdateUndo( wxUpdateUIEvent
& rEvent
)
1264 rEvent
.Enable(CanUndo());
1265 } // end of wxTextCtrl::OnUpdateUndo
1267 void wxTextCtrl::OnUpdateRedo( wxUpdateUIEvent
& rEvent
)
1269 rEvent
.Enable(CanRedo());
1270 } // end of wxTextCtrl::OnUpdateRedo
1272 void wxTextCtrl::OnUpdateDelete( wxUpdateUIEvent
& rEvent
)
1276 GetSelection( &lFrom
, &lTo
);
1277 rEvent
.Enable( lFrom
!= -1L && lTo
!= -1L && lFrom
!= lTo
&& IsEditable()) ;
1278 } // end of wxTextCtrl::OnUpdateDelete
1280 void wxTextCtrl::OnUpdateSelectAll( wxUpdateUIEvent
& rEvent
)
1282 rEvent
.Enable(GetLastPosition() > 0);
1283 } // end of wxTextCtrl::OnUpdateSelectAll
1285 bool wxTextCtrl::SetBackgroundColour( const wxColour
& rColour
)
1288 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1290 } // end of wxTextCtrl::SetBackgroundColour
1292 bool wxTextCtrl::SetForegroundColour( const wxColour
& rColour
)
1295 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1297 } // end of wxTextCtrl::SetForegroundColour
1299 bool wxTextCtrl::SetStyle( long lStart
,
1301 const wxTextAttr
& WXUNUSED(rStyle
) )
1303 HWND hWnd
= GetHwnd();
1314 // We can only change the format of the selection, so select the range we
1315 // want and restore the old selection later
1317 long lStartOld
, lEndOld
;
1319 GetSelection( &lStartOld
, &lEndOld
);
1322 // But do we really have to change the selection?
1324 bool bChangeSel
= lStart
!= lStartOld
||
1330 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1332 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1336 // TODO:: finish this part
1339 } // end of wxTextCtrl::SetStyle