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
;
130 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
133 // Single and multiline edit fields are two different controls in PM
135 if ( m_windowStyle
& wxTE_MULTILINE
)
137 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
140 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
141 lSstyle
|= MLS_VSCROLL
;
142 if (m_windowStyle
& wxHSCROLL
)
143 lSstyle
|= MLS_HSCROLL
;
144 if (m_windowStyle
& wxTE_READONLY
)
145 lSstyle
|= MLS_READONLY
;
149 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
151 if (m_windowStyle
& wxHSCROLL
)
152 lSstyle
|= ES_AUTOSCROLL
;
153 if (m_windowStyle
& wxTE_READONLY
)
154 lSstyle
|= ES_READONLY
;
155 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
156 lSstyle
|= ES_UNREADABLE
;
161 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
162 ,WC_MLE
// Window class
163 ,(PSZ
)rsValue
.c_str() // Initial Text
164 ,(ULONG
)lSstyle
// Style flags
165 ,(LONG
)0 // X pos of origin
166 ,(LONG
)0 // Y pos of origin
167 ,(LONG
)0 // field width
168 ,(LONG
)0 // field height
169 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
170 ,HWND_TOP
// initial z position
171 ,(ULONG
)vId
// Window identifier
172 ,NULL
// no control data
173 ,NULL
// no Presentation parameters
178 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
179 ,WC_ENTRYFIELD
// Window class
180 ,(PSZ
)rsValue
.c_str() // Initial Text
181 ,(ULONG
)lSstyle
// Style flags
182 ,(LONG
)0 // X pos of origin
183 ,(LONG
)0 // Y pos of origin
184 ,(LONG
)0 // field width
185 ,(LONG
)0 // field height
186 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
187 ,HWND_TOP
// initial z position
188 ,(ULONG
)vId
// Window identifier
189 ,NULL
// no control data
190 ,NULL
// no Presentation parameters
199 SubclassWin(GetHWND());
202 // Set font, position, size and initial value
204 wxFont
* pTextFont
= new wxFont( 8
210 if (!rsValue
.IsEmpty())
216 // If X and/or Y are not zero the difference is the compensation value
217 // for margins for OS/2 controls.
219 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
222 SetSize( vPos
.x
- GetXComp()
229 } // end of wxTextCtrl::Create
232 // Make sure the window style (etc.) reflects the HWND style (roughly)
234 void wxTextCtrl::AdoptAttributesFromHWND()
236 HWND hWnd
= GetHwnd();
237 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
239 wxWindow::AdoptAttributesFromHWND();
243 m_windowStyle
|= wxTE_MULTILINE
;
244 if (lStyle
& MLS_READONLY
)
245 m_windowStyle
|= wxTE_READONLY
;
249 if (lStyle
& ES_UNREADABLE
)
250 m_windowStyle
|= wxTE_PASSWORD
;
251 if (lStyle
& ES_READONLY
)
252 m_windowStyle
|= wxTE_READONLY
;
254 } // end of wxTextCtrl::AdoptAttributesFromHWND
256 WXDWORD
wxTextCtrl::OS2GetStyle(
258 , WXDWORD
* pdwExstyle
262 // Default border for the text controls is the sunken one
264 if ((lStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
266 lStyle
|= wxBORDER_SUNKEN
;
269 long dwStyle
= wxControl::OS2GetStyle( lStyle
273 dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
276 // Single and multiline edit fields are two different controls in PM
278 if ( m_windowStyle
& wxTE_MULTILINE
)
280 dwStyle
|= MLS_BORDER
| MLS_WORDWRAP
;
281 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
282 dwStyle
|= MLS_VSCROLL
;
283 if (m_windowStyle
& wxHSCROLL
)
284 dwStyle
|= MLS_HSCROLL
;
285 if (m_windowStyle
& wxTE_READONLY
)
286 dwStyle
|= MLS_READONLY
;
290 dwStyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
291 if (m_windowStyle
& wxHSCROLL
)
292 dwStyle
|= ES_AUTOSCROLL
;
293 if (m_windowStyle
& wxTE_READONLY
)
294 dwStyle
|= ES_READONLY
;
295 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
296 dwStyle
|= ES_UNREADABLE
;
299 } // end of wxTextCtrl::OS2GetStyle
301 void wxTextCtrl::SetWindowStyleFlag(
305 wxControl::SetWindowStyleFlag(lStyle
);
306 } // end of wxTextCtrl::SetWindowStyleFlag
308 void wxTextCtrl::SetupColours()
310 wxColour vBkgndColour
;
312 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
313 SetBackgroundColour(vBkgndColour
);
314 SetForegroundColour(GetParent()->GetForegroundColour());
317 ::WinSendMsg( GetHwnd()
319 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
323 } // end of wxTextCtrl::SetupColours
325 // ----------------------------------------------------------------------------
326 // set/get the controls text
327 // ----------------------------------------------------------------------------
329 wxString
wxTextCtrl::GetValue() const
331 wxString sStr
= wxGetWindowText(GetHWND());
332 char* zStr
= (char*)sStr
.c_str();
334 for ( ; *zStr
; zStr
++ )
337 // 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 bool wxTextCtrl::OS2Command(
1071 , WXWORD
WXUNUSED(vId
)
1079 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1084 vEvent
.SetEventObject(this);
1085 GetEventHandler()->ProcessEvent(vEvent
);
1091 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1095 InitCommandEvent(vEvent
);
1096 vEvent
.SetString((char*)GetValue().c_str());
1097 ProcessCommand(vEvent
);
1103 // The text size limit has been hit - increase it
1109 case EN_INSERTMODETOGGLE
:
1120 } // end of wxTextCtrl::OS2Command
1122 void wxTextCtrl::AdjustSpaceLimit()
1124 unsigned int uLen
= 0;
1125 unsigned int uLimit
= 0;
1127 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1130 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1141 vParams
.fsStatus
= WPM_CBCTLDATA
;
1142 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1144 if (::WinSendMsg( GetHwnd()
1145 ,WM_QUERYWINDOWPARAMS
1150 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1151 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1154 uLimit
= 32; //PM's default
1158 uLimit
= uLen
+ 0x8000; // 32Kb
1159 if (uLimit
> 0xffff)
1164 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1166 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1168 } // end of wxTextCtrl::AdjustSpaceLimit
1170 bool wxTextCtrl::AcceptsFocus() const
1173 // We don't want focus if we can't be edited
1175 return IsEditable() && wxControl::AcceptsFocus();
1176 } // end of wxTextCtrl::Command
1178 wxSize
wxTextCtrl::DoGetBestSize() const
1183 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1185 int wText
= DEFAULT_ITEM_WIDTH
;
1186 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1188 if (m_windowStyle
& wxTE_MULTILINE
)
1190 hText
*= wxMax(GetNumberOfLines(), 5);
1192 //else: for single line control everything is ok
1193 return wxSize(wText
, hText
);
1194 } // end of wxTextCtrl::DoGetBestSize
1196 // ----------------------------------------------------------------------------
1197 // standard handlers for standard edit menu events
1198 // ----------------------------------------------------------------------------
1200 void wxTextCtrl::OnCut(
1201 wxCommandEvent
& rEvent
1205 } // end of wxTextCtrl::OnCut
1207 void wxTextCtrl::OnCopy(
1208 wxCommandEvent
& rEvent
1212 } // end of wxTextCtrl::OnCopy
1214 void wxTextCtrl::OnPaste(
1215 wxCommandEvent
& rEvent
1219 } // end of wxTextCtrl::OnPaste
1221 void wxTextCtrl::OnUndo(
1222 wxCommandEvent
& rEvent
1226 } // end of wxTextCtrl::OnUndo
1228 void wxTextCtrl::OnRedo(
1229 wxCommandEvent
& rEvent
1233 } // end of wxTextCtrl::OnRedo
1235 void wxTextCtrl::OnUpdateCut(
1236 wxUpdateUIEvent
& rEvent
1239 rEvent
.Enable(CanCut());
1240 } // end of wxTextCtrl::OnUpdateCut
1242 void wxTextCtrl::OnUpdateCopy(
1243 wxUpdateUIEvent
& rEvent
1246 rEvent
.Enable(CanCopy());
1247 } // end of wxTextCtrl::OnUpdateCopy
1249 void wxTextCtrl::OnUpdatePaste(
1250 wxUpdateUIEvent
& rEvent
1253 rEvent
.Enable(CanPaste());
1254 } // end of wxTextCtrl::OnUpdatePaste
1256 void wxTextCtrl::OnUpdateUndo(
1257 wxUpdateUIEvent
& rEvent
1260 rEvent
.Enable(CanUndo());
1261 } // end of wxTextCtrl::OnUpdateUndo
1263 void wxTextCtrl::OnUpdateRedo(
1264 wxUpdateUIEvent
& rEvent
1267 rEvent
.Enable(CanRedo());
1268 } // end of wxTextCtrl::OnUpdateRedo
1270 bool wxTextCtrl::SetBackgroundColour(
1271 const wxColour
& rColour
1275 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1277 } // end of wxTextCtrl::SetBackgroundColour
1279 bool wxTextCtrl::SetForegroundColour(
1280 const wxColour
& rColour
1284 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1286 } // end of wxTextCtrl::SetForegroundColour
1288 bool wxTextCtrl::SetStyle(
1291 , const wxTextAttr
& rStyle
1294 HWND hWnd
= GetHwnd();
1305 // We can only change the format of the selection, so select the range we
1306 // want and restore the old selection later
1311 GetSelection( &lStartOld
1316 // But do we really have to change the selection?
1318 bool bChangeSel
= lStart
!= lStartOld
||
1324 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1326 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1330 // TODO:: finish this part
1333 } // end of wxTextCtrl::SetStyle