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
345 } // end of wxTextCtrl::GetValue
347 void wxTextCtrl::SetValue(
348 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 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
362 } // end of wxTextCtrl::SetValue
364 void wxTextCtrl::WriteText(
365 const wxString
& rsValue
369 ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM((PCHAR
)rsValue
.c_str()), MPARAM(0));
371 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
373 } // end of wxTextCtrl::WriteText
375 void wxTextCtrl::AppendText(
376 const wxString
& rsText
379 SetInsertionPointEnd();
381 } // end of wxTextCtrl::AppendText
383 void wxTextCtrl::Clear()
385 ::WinSetWindowText(GetHwnd(), "");
386 } // end of wxTextCtrl::Clear
388 // ----------------------------------------------------------------------------
389 // Clipboard operations
390 // ----------------------------------------------------------------------------
392 void wxTextCtrl::Copy()
396 HWND hWnd
= GetHwnd();
398 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
400 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
402 } // end of wxTextCtrl::Copy
404 void wxTextCtrl::Cut()
408 HWND hWnd
= GetHwnd();
411 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
413 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
415 } // end of wxTextCtrl::Cut
417 void wxTextCtrl::Paste()
421 HWND hWnd
= GetHwnd();
423 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
425 } // end of wxTextCtrl::Paste
427 bool wxTextCtrl::CanCopy() const
430 // Can copy if there's a selection
435 GetSelection(&lFrom
, &lTo
);
436 return (lFrom
!= lTo
);
437 } // end of wxTextCtrl::CanCopy
439 bool wxTextCtrl::CanCut() const
442 // Can cut if there's a selection
447 GetSelection(&lFrom
, &lTo
);
448 return (lFrom
!= lTo
);
449 } // end of wxTextCtrl::CanCut
451 bool wxTextCtrl::CanPaste() const
453 bool bIsTextAvailable
= FALSE
;
459 // Check for straight text on clipboard
461 if (::WinOpenClipbrd(vHabmain
))
463 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
464 ::WinCloseClipbrd(vHabmain
);
466 return bIsTextAvailable
;
467 } // end of wxTextCtrl::CanPaste
469 // ----------------------------------------------------------------------------
471 // ----------------------------------------------------------------------------
473 void wxTextCtrl::SetEditable(
477 HWND hWnd
= GetHwnd();
480 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
482 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
483 } // end of wxTextCtrl::SetEditable
485 void wxTextCtrl::SetInsertionPoint(
489 HWND hWnd
= GetHwnd();
492 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
494 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
495 } // end of wxTextCtrl::SetInsertionPoint
497 void wxTextCtrl::SetInsertionPointEnd()
499 long lPos
= GetLastPosition();
501 SetInsertionPoint(lPos
);
502 } // end of wxTextCtrl::SetInsertionPointEnd
504 long wxTextCtrl::GetInsertionPoint() const
509 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
512 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
513 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
515 return (dwPos
& 0xFFFF);
516 } // end of wxTextCtrl::GetInsertionPoint
518 long wxTextCtrl::GetLastPosition() const
520 HWND hWnd
= GetHwnd();
529 // This just gets the total text length. The last will be this value
531 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
538 vParams
.fsStatus
= WPM_CCHTEXT
;
539 if (::WinSendMsg( GetHwnd()
540 ,WM_QUERYWINDOWPARAMS
545 lLineLength
= (long)vParams
.cchText
;
550 return(lCharIndex
+ lLineLength
);
551 } // end of wxTextCtrl::GetLastPosition
553 // If the return values from and to are the same, there is no
555 void wxTextCtrl::GetSelection(
563 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
566 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
568 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
569 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
570 } // end of wxTextCtrl::GetSelection
572 bool wxTextCtrl::IsEditable() const
575 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
577 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
578 } // end of wxTextCtrl::IsEditable
580 // ----------------------------------------------------------------------------
582 // ----------------------------------------------------------------------------
584 void wxTextCtrl::Replace(
587 , const wxString
& rsValue
591 HWND hWnd
= GetHwnd();
592 long lFromChar
= lFrom
;
596 // Set selection and remove it
600 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
601 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
605 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
606 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
610 // Now replace with 'value', by pasting.
612 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
614 // Paste into edit control
616 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
618 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
620 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
622 } // end of wxTextCtrl::Replace
624 void wxTextCtrl::Remove(
629 HWND hWnd
= GetHwnd();
630 long lFromChar
= lFrom
;
635 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
636 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
640 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
641 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
643 } // end of wxTextCtrl::Remove
645 void wxTextCtrl::SetSelection(
650 HWND hWnd
= GetHwnd();
651 long lFromChar
= lFrom
;
655 // If from and to are both -1, it means (in wxWindows) that all text should
656 // be selected. Translate into Windows convention
658 if ((lFrom
== -1L) && (lTo
== -1L))
664 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
666 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
667 } // end of wxTextCtrl::SetSelection
669 bool wxTextCtrl::LoadFile(
670 const wxString
& rsFile
673 if ( wxTextCtrlBase::LoadFile(rsFile
) )
676 // Update the size limit if needed
682 } // end of wxTextCtrl::LoadFile
684 bool wxTextCtrl::IsModified() const
689 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
691 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
693 } // end of wxTextCtrl::IsModified
696 // Makes 'unmodified'
698 void wxTextCtrl::DiscardEdits()
701 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
704 // EM controls do not have a SETCHANGED but issuing a query should reset it
706 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
707 } // end of wxTextCtrl::DiscardEdits
709 int wxTextCtrl::GetNumberOfLines() const
714 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
718 } // end of wxTextCtrl::GetNumberOfLines
720 long wxTextCtrl::XYToPosition(
725 HWND hWnd
= GetHwnd();
726 long lCharIndex
= 0L;
731 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
732 lCharIndex
= ((lLen
* lY
) + lX
);
737 } // end of wxTextCtrl::XYToPosition
739 bool wxTextCtrl::PositionToXY(
745 HWND hWnd
= GetHwnd();
750 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
761 // This gets the char index for the _beginning_ of this line
767 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
768 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
774 vParams
.fsStatus
= WPM_CCHTEXT
;
775 if (::WinSendMsg( hWnd
776 ,WM_QUERYWINDOWPARAMS
781 lCharIndex
= vParams
.cchText
;
787 if (lCharIndex
== -1)
793 // The X position must therefore be the difference between pos and charIndex
796 *plX
= lPos
- lCharIndex
;
801 } // end of wxTextCtrl::PositionToXY
803 void wxTextCtrl::ShowPosition(
807 HWND hWnd
= GetHwnd();
808 long lCurrentLineLineNo
= 0L;
810 // To scroll to a position, we pass the number of lines and characters
811 // to scroll *by*. This means that we need to:
812 // (1) Find the line position of the current line.
813 // (2) Find the line position of pos.
814 // (3) Scroll by (pos - current).
815 // For now, ignore the horizontal scrolling.
818 // Is this where scrolling is relative to - the line containing the caret?
819 // Or is the first visible line??? Try first visible line.
824 // In PM this is the actual char position
826 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
829 // This will cause a scroll to the selected position
831 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
833 } // end of wxTextCtrl::ShowPosition
835 int wxTextCtrl::GetLineLength(
842 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
847 vParams
.fsStatus
= WPM_CCHTEXT
;
848 if (::WinSendMsg( GetHwnd()
849 ,WM_QUERYWINDOWPARAMS
854 lLen
= vParams
.cchText
;
860 } // end ofwxTextCtrl::GetLineLength
862 wxString
wxTextCtrl::GetLineText(
866 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
871 // There must be at least enough place for the length WORD in the
874 lLen
+= sizeof(WORD
);
875 zBuf
= new char[lLen
];
882 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
883 lIndex
= lLen
* lLineNo
;
885 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
886 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
887 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
888 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
889 zBuf
[lCopied
] = '\0';
895 vParams
.fsStatus
= WPM_CCHTEXT
;
896 if (::WinSendMsg( GetHwnd()
897 ,WM_QUERYWINDOWPARAMS
901 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
902 zBuf
[vParams
.cchText
] = '\0';
907 } // end of wxTextCtrl::GetLineText
909 // ----------------------------------------------------------------------------
911 // ----------------------------------------------------------------------------
913 void wxTextCtrl::Undo()
918 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
919 // Simple entryfields cannot be undone
921 } // end of wxTextCtrl::Undo
923 void wxTextCtrl::Redo()
928 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
929 // Simple entryfields cannot be undone
931 } // end of wxTextCtrl::Redo
933 bool wxTextCtrl::CanUndo() const
938 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
940 bOk
= FALSE
; // can't undo regular edit fields in PM
942 } // end of wxTextCtrl::CanUndo
944 bool wxTextCtrl::CanRedo() const
949 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
951 bOk
= FALSE
; // can't undo regular edit fields in PM
953 } // end of wxTextCtrl::CanRedo
955 // ----------------------------------------------------------------------------
956 // implemenation details
957 // ----------------------------------------------------------------------------
959 void wxTextCtrl::Command(
960 wxCommandEvent
& rEvent
963 SetValue(rEvent
.GetString());
964 ProcessCommand (rEvent
);
965 } // end of wxTextCtrl::Command
967 void wxTextCtrl::OnDropFiles(
968 wxDropFilesEvent
& rEvent
971 // By default, load the first file into the text window.
972 if (rEvent
.GetNumberOfFiles() > 0)
974 LoadFile(rEvent
.GetFiles()[0]);
976 } // end of wxTextCtrl::OnDropFiles
978 WXHBRUSH
wxTextCtrl::OnCtlColor(
987 HPS hPS
= (HPS
)hWxDC
;
988 wxBrush
* pBrush
= NULL
;
989 wxColour vColBack
= GetBackgroundColour();
990 wxColour vColFore
= GetForegroundColour();
991 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
997 HBRUSH hBrush
= NULLHANDLE
;
1001 if (GetParent()->GetTransparentBackground())
1002 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1004 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1005 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1006 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1007 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1008 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1009 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1010 } // end of wxTextCtrl::OnCtlColor
1012 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1016 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1017 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1019 void wxTextCtrl::OnChar(
1023 switch (rEvent
.KeyCode())
1026 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1028 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1030 vEvent
.SetEventObject(this);
1031 if ( GetEventHandler()->ProcessEvent(vEvent
))
1034 //else: multiline controls need Enter for themselves
1039 // always produce navigation event - even if we process TAB
1040 // ourselves the fact that we got here means that the user code
1041 // decided to skip processing of this TAB - probably to let it
1042 // do its default job.
1044 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1045 // handled by Windows
1047 wxNavigationKeyEvent vEventNav
;
1049 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1050 vEventNav
.SetWindowChange(FALSE
);
1051 vEventNav
.SetEventObject(this);
1053 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1059 } // end of wxTextCtrl::OnChar
1061 bool wxTextCtrl::OS2Command(
1063 , WXWORD
WXUNUSED(vId
)
1071 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1076 vEvent
.SetEventObject(this);
1077 GetEventHandler()->ProcessEvent(vEvent
);
1083 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1087 InitCommandEvent(vEvent
);
1088 vEvent
.SetString((char*)GetValue().c_str());
1089 ProcessCommand(vEvent
);
1095 // The text size limit has been hit - increase it
1101 case EN_INSERTMODETOGGLE
:
1112 } // end of wxTextCtrl::OS2Command
1114 void wxTextCtrl::AdjustSpaceLimit()
1116 unsigned int uLen
= 0;
1117 unsigned int uLimit
= 0;
1119 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1122 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1133 vParams
.fsStatus
= WPM_CBCTLDATA
;
1134 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1136 if (::WinSendMsg( GetHwnd()
1137 ,WM_QUERYWINDOWPARAMS
1142 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1143 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1146 uLimit
= 32; //PM's default
1150 uLimit
= uLen
+ 0x8000; // 32Kb
1151 if (uLimit
> 0xffff)
1156 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1158 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1160 } // end of wxTextCtrl::AdjustSpaceLimit
1162 bool wxTextCtrl::AcceptsFocus() const
1165 // We don't want focus if we can't be edited
1167 return IsEditable() && wxControl::AcceptsFocus();
1168 } // end of wxTextCtrl::Command
1170 wxSize
wxTextCtrl::DoGetBestSize() const
1175 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1177 int wText
= DEFAULT_ITEM_WIDTH
;
1178 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1180 if (m_windowStyle
& wxTE_MULTILINE
)
1182 hText
*= wxMax(GetNumberOfLines(), 5);
1184 //else: for single line control everything is ok
1185 return wxSize(wText
, hText
);
1186 } // end of wxTextCtrl::DoGetBestSize
1188 // ----------------------------------------------------------------------------
1189 // standard handlers for standard edit menu events
1190 // ----------------------------------------------------------------------------
1192 void wxTextCtrl::OnCut(
1193 wxCommandEvent
& rEvent
1197 } // end of wxTextCtrl::OnCut
1199 void wxTextCtrl::OnCopy(
1200 wxCommandEvent
& rEvent
1204 } // end of wxTextCtrl::OnCopy
1206 void wxTextCtrl::OnPaste(
1207 wxCommandEvent
& rEvent
1211 } // end of wxTextCtrl::OnPaste
1213 void wxTextCtrl::OnUndo(
1214 wxCommandEvent
& rEvent
1218 } // end of wxTextCtrl::OnUndo
1220 void wxTextCtrl::OnRedo(
1221 wxCommandEvent
& rEvent
1225 } // end of wxTextCtrl::OnRedo
1227 void wxTextCtrl::OnUpdateCut(
1228 wxUpdateUIEvent
& rEvent
1231 rEvent
.Enable(CanCut());
1232 } // end of wxTextCtrl::OnUpdateCut
1234 void wxTextCtrl::OnUpdateCopy(
1235 wxUpdateUIEvent
& rEvent
1238 rEvent
.Enable(CanCopy());
1239 } // end of wxTextCtrl::OnUpdateCopy
1241 void wxTextCtrl::OnUpdatePaste(
1242 wxUpdateUIEvent
& rEvent
1245 rEvent
.Enable(CanPaste());
1246 } // end of wxTextCtrl::OnUpdatePaste
1248 void wxTextCtrl::OnUpdateUndo(
1249 wxUpdateUIEvent
& rEvent
1252 rEvent
.Enable(CanUndo());
1253 } // end of wxTextCtrl::OnUpdateUndo
1255 void wxTextCtrl::OnUpdateRedo(
1256 wxUpdateUIEvent
& rEvent
1259 rEvent
.Enable(CanRedo());
1260 } // end of wxTextCtrl::OnUpdateRedo
1262 bool wxTextCtrl::SetBackgroundColour(
1263 const wxColour
& rColour
1267 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1269 } // end of wxTextCtrl::SetBackgroundColour
1271 bool wxTextCtrl::SetForegroundColour(
1272 const wxColour
& rColour
1276 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1278 } // end of wxTextCtrl::SetForegroundColour
1280 bool wxTextCtrl::SetStyle(
1283 , const wxTextAttr
& rStyle
1286 HWND hWnd
= GetHwnd();
1297 // We can only change the format of the selection, so select the range we
1298 // want and restore the old selection later
1303 GetSelection( &lStartOld
1308 // But do we really have to change the selection?
1310 bool bChangeSel
= lStart
!= lStartOld
||
1316 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1318 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1322 // TODO:: finish this part
1325 } // end of wxTextCtrl::SetStyle