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 bool wxTextCtrl::EmulateKeyPress(
389 const wxKeyEvent
& rEvent
393 return(wxTextCtrlBase::EmulateKeyPress(rEvent
));
394 } // end of wxTextCtrl::EmulateKeyPress
396 // ----------------------------------------------------------------------------
397 // Clipboard operations
398 // ----------------------------------------------------------------------------
400 void wxTextCtrl::Copy()
404 HWND hWnd
= GetHwnd();
406 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
408 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
410 } // end of wxTextCtrl::Copy
412 void wxTextCtrl::Cut()
416 HWND hWnd
= GetHwnd();
419 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
421 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
423 } // end of wxTextCtrl::Cut
425 void wxTextCtrl::Paste()
429 HWND hWnd
= GetHwnd();
431 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
433 } // end of wxTextCtrl::Paste
435 bool wxTextCtrl::CanCopy() const
438 // Can copy if there's a selection
443 GetSelection(&lFrom
, &lTo
);
444 return (lFrom
!= lTo
);
445 } // end of wxTextCtrl::CanCopy
447 bool wxTextCtrl::CanCut() const
450 // Can cut if there's a selection
455 GetSelection(&lFrom
, &lTo
);
456 return (lFrom
!= lTo
);
457 } // end of wxTextCtrl::CanCut
459 bool wxTextCtrl::CanPaste() const
461 bool bIsTextAvailable
= FALSE
;
467 // Check for straight text on clipboard
469 if (::WinOpenClipbrd(vHabmain
))
471 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
472 ::WinCloseClipbrd(vHabmain
);
474 return bIsTextAvailable
;
475 } // end of wxTextCtrl::CanPaste
477 // ----------------------------------------------------------------------------
479 // ----------------------------------------------------------------------------
481 void wxTextCtrl::SetEditable(
485 HWND hWnd
= GetHwnd();
488 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
490 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
491 } // end of wxTextCtrl::SetEditable
493 void wxTextCtrl::SetInsertionPoint(
497 HWND hWnd
= GetHwnd();
500 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
502 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
503 } // end of wxTextCtrl::SetInsertionPoint
505 void wxTextCtrl::SetInsertionPointEnd()
507 long lPos
= GetLastPosition();
509 SetInsertionPoint(lPos
);
510 } // end of wxTextCtrl::SetInsertionPointEnd
512 long wxTextCtrl::GetInsertionPoint() const
517 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
520 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
521 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
523 return (dwPos
& 0xFFFF);
524 } // end of wxTextCtrl::GetInsertionPoint
526 long wxTextCtrl::GetLastPosition() const
528 HWND hWnd
= GetHwnd();
537 // This just gets the total text length. The last will be this value
539 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
546 vParams
.fsStatus
= WPM_CCHTEXT
;
547 if (::WinSendMsg( GetHwnd()
548 ,WM_QUERYWINDOWPARAMS
553 lLineLength
= (long)vParams
.cchText
;
558 return(lCharIndex
+ lLineLength
);
559 } // end of wxTextCtrl::GetLastPosition
561 // If the return values from and to are the same, there is no
563 void wxTextCtrl::GetSelection(
571 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
574 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
576 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
577 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
578 } // end of wxTextCtrl::GetSelection
580 bool wxTextCtrl::IsEditable() const
583 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
585 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
586 } // end of wxTextCtrl::IsEditable
588 // ----------------------------------------------------------------------------
590 // ----------------------------------------------------------------------------
592 void wxTextCtrl::Replace(
595 , const wxString
& rsValue
599 HWND hWnd
= GetHwnd();
600 long lFromChar
= lFrom
;
604 // Set selection and remove it
608 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
609 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
613 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
614 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
618 // Now replace with 'value', by pasting.
620 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
622 // Paste into edit control
624 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
626 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
628 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
630 } // end of wxTextCtrl::Replace
632 void wxTextCtrl::Remove(
637 HWND hWnd
= GetHwnd();
638 long lFromChar
= lFrom
;
643 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
644 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
648 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
649 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
651 } // end of wxTextCtrl::Remove
653 void wxTextCtrl::SetSelection(
658 HWND hWnd
= GetHwnd();
659 long lFromChar
= lFrom
;
663 // If from and to are both -1, it means (in wxWindows) that all text should
664 // be selected. Translate into Windows convention
666 if ((lFrom
== -1L) && (lTo
== -1L))
672 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
674 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
675 } // end of wxTextCtrl::SetSelection
677 bool wxTextCtrl::LoadFile(
678 const wxString
& rsFile
681 if ( wxTextCtrlBase::LoadFile(rsFile
) )
684 // Update the size limit if needed
690 } // end of wxTextCtrl::LoadFile
692 bool wxTextCtrl::IsModified() const
697 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
699 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
701 } // end of wxTextCtrl::IsModified
704 // Makes 'unmodified'
706 void wxTextCtrl::DiscardEdits()
709 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
712 // EM controls do not have a SETCHANGED but issuing a query should reset it
714 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
715 } // end of wxTextCtrl::DiscardEdits
717 int wxTextCtrl::GetNumberOfLines() const
722 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
726 } // end of wxTextCtrl::GetNumberOfLines
728 long wxTextCtrl::XYToPosition(
733 HWND hWnd
= GetHwnd();
734 long lCharIndex
= 0L;
739 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
740 lCharIndex
= ((lLen
* lY
) + lX
);
745 } // end of wxTextCtrl::XYToPosition
747 bool wxTextCtrl::PositionToXY(
753 HWND hWnd
= GetHwnd();
758 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
769 // This gets the char index for the _beginning_ of this line
775 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
776 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
782 vParams
.fsStatus
= WPM_CCHTEXT
;
783 if (::WinSendMsg( hWnd
784 ,WM_QUERYWINDOWPARAMS
789 lCharIndex
= vParams
.cchText
;
795 if (lCharIndex
== -1)
801 // The X position must therefore be the difference between pos and charIndex
804 *plX
= lPos
- lCharIndex
;
809 } // end of wxTextCtrl::PositionToXY
811 void wxTextCtrl::ShowPosition(
815 HWND hWnd
= GetHwnd();
816 long lCurrentLineLineNo
= 0L;
818 // To scroll to a position, we pass the number of lines and characters
819 // to scroll *by*. This means that we need to:
820 // (1) Find the line position of the current line.
821 // (2) Find the line position of pos.
822 // (3) Scroll by (pos - current).
823 // For now, ignore the horizontal scrolling.
826 // Is this where scrolling is relative to - the line containing the caret?
827 // Or is the first visible line??? Try first visible line.
832 // In PM this is the actual char position
834 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
837 // This will cause a scroll to the selected position
839 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
841 } // end of wxTextCtrl::ShowPosition
843 int wxTextCtrl::GetLineLength(
850 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
855 vParams
.fsStatus
= WPM_CCHTEXT
;
856 if (::WinSendMsg( GetHwnd()
857 ,WM_QUERYWINDOWPARAMS
862 lLen
= vParams
.cchText
;
868 } // end ofwxTextCtrl::GetLineLength
870 wxString
wxTextCtrl::GetLineText(
874 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
879 // There must be at least enough place for the length WORD in the
882 lLen
+= sizeof(WORD
);
883 zBuf
= new char[lLen
];
890 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
891 lIndex
= lLen
* lLineNo
;
893 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
894 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
895 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
896 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
897 zBuf
[lCopied
] = '\0';
903 vParams
.fsStatus
= WPM_CCHTEXT
;
904 if (::WinSendMsg( GetHwnd()
905 ,WM_QUERYWINDOWPARAMS
909 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
910 zBuf
[vParams
.cchText
] = '\0';
915 } // end of wxTextCtrl::GetLineText
917 // ----------------------------------------------------------------------------
919 // ----------------------------------------------------------------------------
921 void wxTextCtrl::Undo()
926 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
927 // Simple entryfields cannot be undone
929 } // end of wxTextCtrl::Undo
931 void wxTextCtrl::Redo()
936 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
937 // Simple entryfields cannot be undone
939 } // end of wxTextCtrl::Redo
941 bool wxTextCtrl::CanUndo() const
946 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
948 bOk
= FALSE
; // can't undo regular edit fields in PM
950 } // end of wxTextCtrl::CanUndo
952 bool wxTextCtrl::CanRedo() const
957 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
959 bOk
= FALSE
; // can't undo regular edit fields in PM
961 } // end of wxTextCtrl::CanRedo
963 // ----------------------------------------------------------------------------
964 // implemenation details
965 // ----------------------------------------------------------------------------
967 void wxTextCtrl::Command(
968 wxCommandEvent
& rEvent
971 SetValue(rEvent
.GetString());
972 ProcessCommand (rEvent
);
973 } // end of wxTextCtrl::Command
975 void wxTextCtrl::OnDropFiles(
976 wxDropFilesEvent
& rEvent
979 // By default, load the first file into the text window.
980 if (rEvent
.GetNumberOfFiles() > 0)
982 LoadFile(rEvent
.GetFiles()[0]);
984 } // end of wxTextCtrl::OnDropFiles
986 WXHBRUSH
wxTextCtrl::OnCtlColor(
995 HPS hPS
= (HPS
)hWxDC
;
996 wxBrush
* pBrush
= NULL
;
997 wxColour vColBack
= GetBackgroundColour();
998 wxColour vColFore
= GetForegroundColour();
999 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
1005 HBRUSH hBrush
= NULLHANDLE
;
1009 if (GetParent()->GetTransparentBackground())
1010 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1012 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1013 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1014 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1015 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1016 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1017 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1018 } // end of wxTextCtrl::OnCtlColor
1020 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1024 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1025 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1027 void wxTextCtrl::OnChar(
1031 switch (rEvent
.KeyCode())
1034 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1036 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1038 vEvent
.SetEventObject(this);
1039 if ( GetEventHandler()->ProcessEvent(vEvent
))
1042 //else: multiline controls need Enter for themselves
1047 // always produce navigation event - even if we process TAB
1048 // ourselves the fact that we got here means that the user code
1049 // decided to skip processing of this TAB - probably to let it
1050 // do its default job.
1052 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1053 // handled by Windows
1055 wxNavigationKeyEvent vEventNav
;
1057 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1058 vEventNav
.SetWindowChange(FALSE
);
1059 vEventNav
.SetEventObject(this);
1061 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1067 } // end of wxTextCtrl::OnChar
1069 void wxTextCtrl::SetFocus()
1071 wxTextCtrlBase::SetFocus();
1072 if ( !HasFlag(wxTE_MULTILINE
) )
1074 SetSelection(-1, -1);
1076 } // end of wxTextCtrl::SetFocus
1078 bool wxTextCtrl::OS2Command(
1080 , WXWORD
WXUNUSED(vId
)
1088 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1093 vEvent
.SetEventObject(this);
1094 GetEventHandler()->ProcessEvent(vEvent
);
1100 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1104 InitCommandEvent(vEvent
);
1105 vEvent
.SetString((char*)GetValue().c_str());
1106 ProcessCommand(vEvent
);
1112 // The text size limit has been hit - increase it
1118 case EN_INSERTMODETOGGLE
:
1129 } // end of wxTextCtrl::OS2Command
1131 void wxTextCtrl::AdjustSpaceLimit()
1133 unsigned int uLen
= 0;
1134 unsigned int uLimit
= 0;
1136 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1139 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1150 vParams
.fsStatus
= WPM_CBCTLDATA
;
1151 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1153 if (::WinSendMsg( GetHwnd()
1154 ,WM_QUERYWINDOWPARAMS
1159 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1160 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1163 uLimit
= 32; //PM's default
1167 uLimit
= uLen
+ 0x8000; // 32Kb
1168 if (uLimit
> 0xffff)
1173 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1175 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1177 } // end of wxTextCtrl::AdjustSpaceLimit
1179 bool wxTextCtrl::AcceptsFocus() const
1182 // We don't want focus if we can't be edited
1184 return IsEditable() && wxControl::AcceptsFocus();
1185 } // end of wxTextCtrl::Command
1187 wxSize
wxTextCtrl::DoGetBestSize() const
1192 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1194 int wText
= DEFAULT_ITEM_WIDTH
;
1195 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1197 if (m_windowStyle
& wxTE_MULTILINE
)
1199 hText
*= wxMax(GetNumberOfLines(), 5);
1201 //else: for single line control everything is ok
1202 return wxSize(wText
, hText
);
1203 } // end of wxTextCtrl::DoGetBestSize
1205 // ----------------------------------------------------------------------------
1206 // standard handlers for standard edit menu events
1207 // ----------------------------------------------------------------------------
1209 void wxTextCtrl::OnCut(
1210 wxCommandEvent
& rEvent
1214 } // end of wxTextCtrl::OnCut
1216 void wxTextCtrl::OnCopy(
1217 wxCommandEvent
& rEvent
1221 } // end of wxTextCtrl::OnCopy
1223 void wxTextCtrl::OnPaste(
1224 wxCommandEvent
& rEvent
1228 } // end of wxTextCtrl::OnPaste
1230 void wxTextCtrl::OnUndo(
1231 wxCommandEvent
& rEvent
1235 } // end of wxTextCtrl::OnUndo
1237 void wxTextCtrl::OnRedo(
1238 wxCommandEvent
& rEvent
1242 } // end of wxTextCtrl::OnRedo
1244 void wxTextCtrl::OnUpdateCut(
1245 wxUpdateUIEvent
& rEvent
1248 rEvent
.Enable(CanCut());
1249 } // end of wxTextCtrl::OnUpdateCut
1251 void wxTextCtrl::OnUpdateCopy(
1252 wxUpdateUIEvent
& rEvent
1255 rEvent
.Enable(CanCopy());
1256 } // end of wxTextCtrl::OnUpdateCopy
1258 void wxTextCtrl::OnUpdatePaste(
1259 wxUpdateUIEvent
& rEvent
1262 rEvent
.Enable(CanPaste());
1263 } // end of wxTextCtrl::OnUpdatePaste
1265 void wxTextCtrl::OnUpdateUndo(
1266 wxUpdateUIEvent
& rEvent
1269 rEvent
.Enable(CanUndo());
1270 } // end of wxTextCtrl::OnUpdateUndo
1272 void wxTextCtrl::OnUpdateRedo(
1273 wxUpdateUIEvent
& rEvent
1276 rEvent
.Enable(CanRedo());
1277 } // end of wxTextCtrl::OnUpdateRedo
1279 bool wxTextCtrl::SetBackgroundColour(
1280 const wxColour
& rColour
1284 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1286 } // end of wxTextCtrl::SetBackgroundColour
1288 bool wxTextCtrl::SetForegroundColour(
1289 const wxColour
& rColour
1293 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1295 } // end of wxTextCtrl::SetForegroundColour
1297 bool wxTextCtrl::SetStyle(
1300 , const wxTextAttr
& 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
1320 GetSelection( &lStartOld
1325 // But do we really have to change the selection?
1327 bool bChangeSel
= lStart
!= lStartOld
||
1333 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1335 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1339 // TODO:: finish this part
1342 } // end of wxTextCtrl::SetStyle