1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ----------------------------------------------------------------------------
14 // ----------------------------------------------------------------------------
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
20 #include "wx/textctrl.h"
21 #include "wx/scrolwin.h"
22 #include "wx/settings.h"
30 #include "wx/clipbrd.h"
33 #include "wx/textfile.h"
35 #include "wx/os2/private.h"
39 #include <sys/types.h>
47 #if !defined(MLE_INDEX)
53 // ----------------------------------------------------------------------------
54 // event tables and other macros
55 // ----------------------------------------------------------------------------
57 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
, wxControl
)
59 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
60 EVT_CHAR(wxTextCtrl::OnChar
)
61 EVT_DROP_FILES(wxTextCtrl::OnDropFiles
)
63 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
64 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
65 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
66 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
67 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
69 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
70 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
71 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
72 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
73 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
77 // ============================================================================
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 wxTextCtrl::wxTextCtrl()
89 bool wxTextCtrl::Create(
92 , const wxString
& rsValue
97 , const wxValidator
& rValidator
99 , const wxString
& rsName
105 // Base initialization
107 if ( !CreateBase( pParent
119 wxPoint vPos
= rPos
; // The OS/2 position
124 pParent
->AddChild(this);
127 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( 10
209 if (!rsValue
.IsEmpty())
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
);
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(), 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(), 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 long lPos
= GetLastPosition();
508 SetInsertionPoint(lPos
);
509 } // end of wxTextCtrl::SetInsertionPointEnd
511 long wxTextCtrl::GetInsertionPoint() const
516 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
519 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
520 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
522 return (dwPos
& 0xFFFF);
523 } // end of wxTextCtrl::GetInsertionPoint
525 long wxTextCtrl::GetLastPosition() const
527 HWND hWnd
= GetHwnd();
536 // This just gets the total text length. The last will be this value
538 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
545 vParams
.fsStatus
= WPM_CCHTEXT
;
546 if (::WinSendMsg( GetHwnd()
547 ,WM_QUERYWINDOWPARAMS
552 lLineLength
= (long)vParams
.cchText
;
557 return(lCharIndex
+ lLineLength
);
558 } // end of wxTextCtrl::GetLastPosition
560 // If the return values from and to are the same, there is no
562 void wxTextCtrl::GetSelection(
570 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
573 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
575 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
576 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
577 } // end of wxTextCtrl::GetSelection
579 bool wxTextCtrl::IsEditable() const
582 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
584 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
585 } // end of wxTextCtrl::IsEditable
587 // ----------------------------------------------------------------------------
589 // ----------------------------------------------------------------------------
591 void wxTextCtrl::Replace(
594 , const wxString
& rsValue
598 HWND hWnd
= GetHwnd();
599 long lFromChar
= lFrom
;
603 // Set selection and remove it
607 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
608 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
612 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
613 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
617 // Now replace with 'value', by pasting.
619 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
621 // Paste into edit control
623 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
625 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
627 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
629 } // end of wxTextCtrl::Replace
631 void wxTextCtrl::Remove(
636 HWND hWnd
= GetHwnd();
637 long lFromChar
= lFrom
;
642 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
643 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
647 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
648 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
650 } // end of wxTextCtrl::Remove
652 void wxTextCtrl::SetSelection(
657 HWND hWnd
= GetHwnd();
658 long lFromChar
= lFrom
;
662 // If from and to are both -1, it means (in wxWindows) that all text should
663 // be selected. Translate into Windows convention
665 if ((lFrom
== -1L) && (lTo
== -1L))
671 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
673 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
674 } // end of wxTextCtrl::SetSelection
676 bool wxTextCtrl::LoadFile(
677 const wxString
& rsFile
680 if ( wxTextCtrlBase::LoadFile(rsFile
) )
683 // Update the size limit if needed
689 } // end of wxTextCtrl::LoadFile
691 bool wxTextCtrl::IsModified() const
696 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
698 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
700 } // end of wxTextCtrl::IsModified
703 // Makes 'unmodified'
705 void wxTextCtrl::DiscardEdits()
708 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
711 // EM controls do not have a SETCHANGED but issuing a query should reset it
713 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
714 } // end of wxTextCtrl::DiscardEdits
716 int wxTextCtrl::GetNumberOfLines() const
721 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
725 } // end of wxTextCtrl::GetNumberOfLines
727 long wxTextCtrl::XYToPosition(
732 HWND hWnd
= GetHwnd();
733 long lCharIndex
= 0L;
738 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
739 lCharIndex
= ((lLen
* lY
) + lX
);
744 } // end of wxTextCtrl::XYToPosition
746 bool wxTextCtrl::PositionToXY(
752 HWND hWnd
= GetHwnd();
757 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
768 // This gets the char index for the _beginning_ of this line
774 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
775 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
781 vParams
.fsStatus
= WPM_CCHTEXT
;
782 if (::WinSendMsg( hWnd
783 ,WM_QUERYWINDOWPARAMS
788 lCharIndex
= vParams
.cchText
;
794 if (lCharIndex
== -1)
800 // The X position must therefore be the difference between pos and charIndex
803 *plX
= lPos
- lCharIndex
;
808 } // end of wxTextCtrl::PositionToXY
810 void wxTextCtrl::ShowPosition(
814 HWND hWnd
= GetHwnd();
815 long lCurrentLineLineNo
= 0L;
817 // To scroll to a position, we pass the number of lines and characters
818 // to scroll *by*. This means that we need to:
819 // (1) Find the line position of the current line.
820 // (2) Find the line position of pos.
821 // (3) Scroll by (pos - current).
822 // For now, ignore the horizontal scrolling.
825 // Is this where scrolling is relative to - the line containing the caret?
826 // Or is the first visible line??? Try first visible line.
831 // In PM this is the actual char position
833 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
836 // This will cause a scroll to the selected position
838 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
840 } // end of wxTextCtrl::ShowPosition
842 int wxTextCtrl::GetLineLength(
849 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
854 vParams
.fsStatus
= WPM_CCHTEXT
;
855 if (::WinSendMsg( GetHwnd()
856 ,WM_QUERYWINDOWPARAMS
861 lLen
= vParams
.cchText
;
867 } // end ofwxTextCtrl::GetLineLength
869 wxString
wxTextCtrl::GetLineText(
873 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
878 // There must be at least enough place for the length WORD in the
881 lLen
+= sizeof(WORD
);
882 zBuf
= new char[lLen
];
889 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
890 lIndex
= lLen
* lLineNo
;
892 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
893 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
894 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
895 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
896 zBuf
[lCopied
] = '\0';
902 vParams
.fsStatus
= WPM_CCHTEXT
;
903 if (::WinSendMsg( GetHwnd()
904 ,WM_QUERYWINDOWPARAMS
908 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
909 zBuf
[vParams
.cchText
] = '\0';
914 } // end of wxTextCtrl::GetLineText
916 // ----------------------------------------------------------------------------
918 // ----------------------------------------------------------------------------
920 void wxTextCtrl::Undo()
925 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
926 // Simple entryfields cannot be undone
928 } // end of wxTextCtrl::Undo
930 void wxTextCtrl::Redo()
935 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
936 // Simple entryfields cannot be undone
938 } // end of wxTextCtrl::Redo
940 bool wxTextCtrl::CanUndo() const
945 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
947 bOk
= FALSE
; // can't undo regular edit fields in PM
949 } // end of wxTextCtrl::CanUndo
951 bool wxTextCtrl::CanRedo() const
956 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
958 bOk
= FALSE
; // can't undo regular edit fields in PM
960 } // end of wxTextCtrl::CanRedo
962 // ----------------------------------------------------------------------------
963 // implemenation details
964 // ----------------------------------------------------------------------------
966 void wxTextCtrl::Command(
967 wxCommandEvent
& rEvent
970 SetValue(rEvent
.GetString());
971 ProcessCommand (rEvent
);
972 } // end of wxTextCtrl::Command
974 void wxTextCtrl::OnDropFiles(
975 wxDropFilesEvent
& rEvent
978 // By default, load the first file into the text window.
979 if (rEvent
.GetNumberOfFiles() > 0)
981 LoadFile(rEvent
.GetFiles()[0]);
983 } // end of wxTextCtrl::OnDropFiles
985 WXHBRUSH
wxTextCtrl::OnCtlColor(
994 HPS hPS
= (HPS
)hWxDC
;
995 wxBrush
* pBrush
= NULL
;
996 wxColour vColBack
= GetBackgroundColour();
997 wxColour vColFore
= GetForegroundColour();
998 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
1004 HBRUSH hBrush
= NULLHANDLE
;
1008 if (GetParent()->GetTransparentBackground())
1009 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1011 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1012 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1013 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1014 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1015 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1016 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1017 } // end of wxTextCtrl::OnCtlColor
1019 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1023 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1024 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1026 void wxTextCtrl::OnChar(
1030 switch (rEvent
.KeyCode())
1033 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1035 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1037 vEvent
.SetEventObject(this);
1038 if ( GetEventHandler()->ProcessEvent(vEvent
))
1041 //else: multiline controls need Enter for themselves
1046 // always produce navigation event - even if we process TAB
1047 // ourselves the fact that we got here means that the user code
1048 // decided to skip processing of this TAB - probably to let it
1049 // do its default job.
1051 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1052 // handled by Windows
1054 wxNavigationKeyEvent vEventNav
;
1056 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1057 vEventNav
.SetWindowChange(FALSE
);
1058 vEventNav
.SetEventObject(this);
1060 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1066 } // end of wxTextCtrl::OnChar
1068 bool wxTextCtrl::OS2Command(
1070 , WXWORD
WXUNUSED(vId
)
1078 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1083 vEvent
.SetEventObject(this);
1084 GetEventHandler()->ProcessEvent(vEvent
);
1090 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1094 InitCommandEvent(vEvent
);
1095 vEvent
.SetString((char*)GetValue().c_str());
1096 ProcessCommand(vEvent
);
1102 // The text size limit has been hit - increase it
1108 case EN_INSERTMODETOGGLE
:
1119 } // end of wxTextCtrl::OS2Command
1121 void wxTextCtrl::AdjustSpaceLimit()
1123 unsigned int uLen
= 0;
1124 unsigned int uLimit
= 0;
1126 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1129 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1140 vParams
.fsStatus
= WPM_CBCTLDATA
;
1141 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1143 if (::WinSendMsg( GetHwnd()
1144 ,WM_QUERYWINDOWPARAMS
1149 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1150 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1153 uLimit
= 32; //PM's default
1157 uLimit
= uLen
+ 0x8000; // 32Kb
1158 if (uLimit
> 0xffff)
1163 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1165 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1167 } // end of wxTextCtrl::AdjustSpaceLimit
1169 bool wxTextCtrl::AcceptsFocus() const
1172 // We don't want focus if we can't be edited
1174 return IsEditable() && wxControl::AcceptsFocus();
1175 } // end of wxTextCtrl::Command
1177 wxSize
wxTextCtrl::DoGetBestSize() const
1182 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1184 int wText
= DEFAULT_ITEM_WIDTH
;
1185 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1187 if (m_windowStyle
& wxTE_MULTILINE
)
1189 hText
*= wxMax(GetNumberOfLines(), 5);
1191 //else: for single line control everything is ok
1192 return wxSize(wText
, hText
);
1193 } // end of wxTextCtrl::DoGetBestSize
1195 // ----------------------------------------------------------------------------
1196 // standard handlers for standard edit menu events
1197 // ----------------------------------------------------------------------------
1199 void wxTextCtrl::OnCut(
1200 wxCommandEvent
& rEvent
1204 } // end of wxTextCtrl::OnCut
1206 void wxTextCtrl::OnCopy(
1207 wxCommandEvent
& rEvent
1211 } // end of wxTextCtrl::OnCopy
1213 void wxTextCtrl::OnPaste(
1214 wxCommandEvent
& rEvent
1218 } // end of wxTextCtrl::OnPaste
1220 void wxTextCtrl::OnUndo(
1221 wxCommandEvent
& rEvent
1225 } // end of wxTextCtrl::OnUndo
1227 void wxTextCtrl::OnRedo(
1228 wxCommandEvent
& rEvent
1232 } // end of wxTextCtrl::OnRedo
1234 void wxTextCtrl::OnUpdateCut(
1235 wxUpdateUIEvent
& rEvent
1238 rEvent
.Enable(CanCut());
1239 } // end of wxTextCtrl::OnUpdateCut
1241 void wxTextCtrl::OnUpdateCopy(
1242 wxUpdateUIEvent
& rEvent
1245 rEvent
.Enable(CanCopy());
1246 } // end of wxTextCtrl::OnUpdateCopy
1248 void wxTextCtrl::OnUpdatePaste(
1249 wxUpdateUIEvent
& rEvent
1252 rEvent
.Enable(CanPaste());
1253 } // end of wxTextCtrl::OnUpdatePaste
1255 void wxTextCtrl::OnUpdateUndo(
1256 wxUpdateUIEvent
& rEvent
1259 rEvent
.Enable(CanUndo());
1260 } // end of wxTextCtrl::OnUpdateUndo
1262 void wxTextCtrl::OnUpdateRedo(
1263 wxUpdateUIEvent
& rEvent
1266 rEvent
.Enable(CanRedo());
1267 } // end of wxTextCtrl::OnUpdateRedo
1269 bool wxTextCtrl::SetBackgroundColour(
1270 const wxColour
& rColour
1274 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1276 } // end of wxTextCtrl::SetBackgroundColour
1278 bool wxTextCtrl::SetForegroundColour(
1279 const wxColour
& rColour
1283 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1285 } // end of wxTextCtrl::SetForegroundColour
1287 bool wxTextCtrl::SetStyle(
1290 , const wxTextAttr
& rStyle
1293 HWND hWnd
= GetHwnd();
1304 // We can only change the format of the selection, so select the range we
1305 // want and restore the old selection later
1310 GetSelection( &lStartOld
1315 // But do we really have to change the selection?
1317 bool bChangeSel
= lStart
!= lStartOld
||
1323 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1325 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1329 // TODO:: finish this part
1332 } // end of wxTextCtrl::SetStyle