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
106 // Base initialization
108 if ( !CreateBase( pParent
120 wxPoint vPos
= rPos
; // The OS/2 position
125 pParent
->AddChild(this);
128 m_windowStyle
= lStyle
;
131 long lSstyle
= WS_VISIBLE
| WS_TABSTOP
;
134 // Single and multiline edit fields are two different controls in PM
136 if ( m_windowStyle
& wxTE_MULTILINE
)
138 lSstyle
|= MLS_BORDER
| MLS_WORDWRAP
;
141 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
142 lSstyle
|= MLS_VSCROLL
;
143 if (m_windowStyle
& wxHSCROLL
)
144 lSstyle
|= MLS_HSCROLL
;
145 if (m_windowStyle
& wxTE_READONLY
)
146 lSstyle
|= MLS_READONLY
;
150 lSstyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
152 if (m_windowStyle
& wxHSCROLL
)
153 lSstyle
|= ES_AUTOSCROLL
;
154 if (m_windowStyle
& wxTE_READONLY
)
155 lSstyle
|= ES_READONLY
;
156 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
157 lSstyle
|= ES_UNREADABLE
;
162 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
163 ,WC_MLE
// Window class
164 ,(PSZ
)rsValue
.c_str() // Initial Text
165 ,(ULONG
)lSstyle
// Style flags
166 ,(LONG
)0 // X pos of origin
167 ,(LONG
)0 // Y pos of origin
168 ,(LONG
)0 // field width
169 ,(LONG
)0 // field height
170 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
171 ,HWND_TOP
// initial z position
172 ,(ULONG
)vId
// Window identifier
173 ,NULL
// no control data
174 ,NULL
// no Presentation parameters
179 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
180 ,WC_ENTRYFIELD
// Window class
181 ,(PSZ
)rsValue
.c_str() // Initial Text
182 ,(ULONG
)lSstyle
// Style flags
183 ,(LONG
)0 // X pos of origin
184 ,(LONG
)0 // Y pos of origin
185 ,(LONG
)0 // field width
186 ,(LONG
)0 // field height
187 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
188 ,HWND_TOP
// initial z position
189 ,(ULONG
)vId
// Window identifier
190 ,NULL
// no control data
191 ,NULL
// no Presentation parameters
200 SubclassWin(GetHWND());
203 // Set font, position, size and initial value
205 wxFont
* pTextFont
= new wxFont( 8
211 if (!rsValue
.IsEmpty())
217 // If X and/or Y are not zero the difference is the compensation value
218 // for margins for OS/2 controls.
220 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
223 SetSize( vPos
.x
- GetXComp()
230 } // end of wxTextCtrl::Create
233 // Make sure the window style (etc.) reflects the HWND style (roughly)
235 void wxTextCtrl::AdoptAttributesFromHWND()
237 HWND hWnd
= GetHwnd();
238 LONG lStyle
= ::WinQueryWindowULong(hWnd
, QWL_STYLE
);
240 wxWindow::AdoptAttributesFromHWND();
244 m_windowStyle
|= wxTE_MULTILINE
;
245 if (lStyle
& MLS_READONLY
)
246 m_windowStyle
|= wxTE_READONLY
;
250 if (lStyle
& ES_UNREADABLE
)
251 m_windowStyle
|= wxTE_PASSWORD
;
252 if (lStyle
& ES_READONLY
)
253 m_windowStyle
|= wxTE_READONLY
;
255 } // end of wxTextCtrl::AdoptAttributesFromHWND
257 WXDWORD
wxTextCtrl::OS2GetStyle(
259 , WXDWORD
* pdwExstyle
263 // Default border for the text controls is the sunken one
265 if ((lStyle
& wxBORDER_MASK
) == wxBORDER_DEFAULT
)
267 lStyle
|= wxBORDER_SUNKEN
;
270 long dwStyle
= wxControl::OS2GetStyle( lStyle
274 dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
277 // Single and multiline edit fields are two different controls in PM
279 if ( m_windowStyle
& wxTE_MULTILINE
)
281 dwStyle
|= MLS_BORDER
| MLS_WORDWRAP
;
282 if ((m_windowStyle
& wxTE_NO_VSCROLL
) == 0)
283 dwStyle
|= MLS_VSCROLL
;
284 if (m_windowStyle
& wxHSCROLL
)
285 dwStyle
|= MLS_HSCROLL
;
286 if (m_windowStyle
& wxTE_READONLY
)
287 dwStyle
|= MLS_READONLY
;
291 dwStyle
|= ES_LEFT
| ES_AUTOSCROLL
| ES_MARGIN
;
292 if (m_windowStyle
& wxHSCROLL
)
293 dwStyle
|= ES_AUTOSCROLL
;
294 if (m_windowStyle
& wxTE_READONLY
)
295 dwStyle
|= ES_READONLY
;
296 if (m_windowStyle
& wxTE_PASSWORD
) // hidden input
297 dwStyle
|= ES_UNREADABLE
;
300 } // end of wxTextCtrl::OS2GetStyle
302 void wxTextCtrl::SetWindowStyleFlag(
306 wxControl::SetWindowStyleFlag(lStyle
);
307 } // end of wxTextCtrl::SetWindowStyleFlag
309 void wxTextCtrl::SetupColours()
311 wxColour vBkgndColour
;
313 vBkgndColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
314 SetBackgroundColour(vBkgndColour
);
315 SetForegroundColour(GetParent()->GetForegroundColour());
318 ::WinSendMsg( GetHwnd()
320 ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel()
324 } // end of wxTextCtrl::SetupColours
326 // ----------------------------------------------------------------------------
327 // set/get the controls text
328 // ----------------------------------------------------------------------------
330 wxString
wxTextCtrl::GetValue() const
332 wxString sStr
= wxGetWindowText(GetHWND());
333 char* zStr
= (char*)sStr
.c_str();
335 for ( ; *zStr
; zStr
++ )
338 // this will replace \r\n with just \n
346 } // end of wxTextCtrl::GetValue
348 void wxTextCtrl::SetValue(
349 const wxString
& rsValue
353 // If the text is long enough, it's faster to just set it instead of first
354 // comparing it with the old one (chances are that it will be different
355 // anyhow, this comparison is there to avoid flicker for small single-line
356 // edit controls mostly)
358 if ((rsValue
.length() > 0x400) || (rsValue
!= GetValue()))
360 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
363 } // end of wxTextCtrl::SetValue
365 void wxTextCtrl::WriteText(
366 const wxString
& rsValue
370 ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM((PCHAR
)rsValue
.c_str()), MPARAM(0));
372 ::WinSetWindowText(GetHwnd(), rsValue
.c_str());
374 } // end of wxTextCtrl::WriteText
376 void wxTextCtrl::AppendText(
377 const wxString
& rsText
380 SetInsertionPointEnd();
382 } // end of wxTextCtrl::AppendText
384 void wxTextCtrl::Clear()
386 ::WinSetWindowText(GetHwnd(), "");
387 } // end of wxTextCtrl::Clear
389 bool wxTextCtrl::EmulateKeyPress(
390 const wxKeyEvent
& rEvent
394 return(wxTextCtrlBase::EmulateKeyPress(rEvent
));
395 } // end of wxTextCtrl::EmulateKeyPress
397 // ----------------------------------------------------------------------------
398 // Clipboard operations
399 // ----------------------------------------------------------------------------
401 void wxTextCtrl::Copy()
405 HWND hWnd
= GetHwnd();
407 ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0);
409 ::WinSendMsg(hWnd
, EM_COPY
, 0, 0);
411 } // end of wxTextCtrl::Copy
413 void wxTextCtrl::Cut()
417 HWND hWnd
= GetHwnd();
420 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
422 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
424 } // end of wxTextCtrl::Cut
426 void wxTextCtrl::Paste()
430 HWND hWnd
= GetHwnd();
432 ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0);
434 } // end of wxTextCtrl::Paste
436 bool wxTextCtrl::CanCopy() const
439 // Can copy if there's a selection
444 GetSelection(&lFrom
, &lTo
);
445 return (lFrom
!= lTo
);
446 } // end of wxTextCtrl::CanCopy
448 bool wxTextCtrl::CanCut() const
451 // Can cut if there's a selection
456 GetSelection(&lFrom
, &lTo
);
457 return (lFrom
!= lTo
);
458 } // end of wxTextCtrl::CanCut
460 bool wxTextCtrl::CanPaste() const
462 bool bIsTextAvailable
= FALSE
;
468 // Check for straight text on clipboard
470 if (::WinOpenClipbrd(vHabmain
))
472 bIsTextAvailable
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0);
473 ::WinCloseClipbrd(vHabmain
);
475 return bIsTextAvailable
;
476 } // end of wxTextCtrl::CanPaste
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
482 void wxTextCtrl::SetEditable(
486 HWND hWnd
= GetHwnd();
489 ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
491 ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0);
492 } // end of wxTextCtrl::SetEditable
494 void wxTextCtrl::SetInsertionPoint(
498 HWND hWnd
= GetHwnd();
501 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
);
503 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0);
504 } // end of wxTextCtrl::SetInsertionPoint
506 void wxTextCtrl::SetInsertionPointEnd()
508 long lPos
= GetLastPosition();
510 SetInsertionPoint(lPos
);
511 } // end of wxTextCtrl::SetInsertionPointEnd
513 long wxTextCtrl::GetInsertionPoint() const
518 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
521 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
522 dwPos
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
524 return (dwPos
& 0xFFFF);
525 } // end of wxTextCtrl::GetInsertionPoint
527 long wxTextCtrl::GetLastPosition() const
529 HWND hWnd
= GetHwnd();
538 // This just gets the total text length. The last will be this value
540 lLineLength
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0);
547 vParams
.fsStatus
= WPM_CCHTEXT
;
548 if (::WinSendMsg( GetHwnd()
549 ,WM_QUERYWINDOWPARAMS
554 lLineLength
= (long)vParams
.cchText
;
559 return(lCharIndex
+ lLineLength
);
560 } // end of wxTextCtrl::GetLastPosition
562 // If the return values from and to are the same, there is no
564 void wxTextCtrl::GetSelection(
572 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0);
575 dwPos
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0);
577 *plFrom
= SHORT1FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
578 *plTo
= SHORT2FROMMP((MPARAM
)dwPos
); // the first 16 bit value is the min pos
579 } // end of wxTextCtrl::GetSelection
581 bool wxTextCtrl::IsEditable() const
584 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0)));
586 return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0)));
587 } // end of wxTextCtrl::IsEditable
589 // ----------------------------------------------------------------------------
591 // ----------------------------------------------------------------------------
593 void wxTextCtrl::Replace(
596 , const wxString
& rsValue
600 HWND hWnd
= GetHwnd();
601 long lFromChar
= lFrom
;
605 // Set selection and remove it
609 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
610 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
614 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
615 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
619 // Now replace with 'value', by pasting.
621 wxSetClipboardData(wxDF_TEXT
, (wxObject
*) (const wxChar
*)rsValue
, 0, 0);
623 // Paste into edit control
625 ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0);
627 ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0);
629 wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0.");
631 } // end of wxTextCtrl::Replace
633 void wxTextCtrl::Remove(
638 HWND hWnd
= GetHwnd();
639 long lFromChar
= lFrom
;
644 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
645 ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0);
649 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0);
650 ::WinSendMsg(hWnd
, EM_CUT
, 0, 0);
652 } // end of wxTextCtrl::Remove
654 void wxTextCtrl::SetSelection(
659 HWND hWnd
= GetHwnd();
660 long lFromChar
= lFrom
;
664 // If from and to are both -1, it means (in wxWindows) that all text should
665 // be selected. Translate into Windows convention
667 if ((lFrom
== -1L) && (lTo
== -1L))
673 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
);
675 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0);
676 } // end of wxTextCtrl::SetSelection
678 bool wxTextCtrl::LoadFile(
679 const wxString
& rsFile
682 if ( wxTextCtrlBase::LoadFile(rsFile
) )
685 // Update the size limit if needed
691 } // end of wxTextCtrl::LoadFile
693 bool wxTextCtrl::IsModified() const
698 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0));
700 bRc
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0));
702 } // end of wxTextCtrl::IsModified
705 // Makes 'unmodified'
707 void wxTextCtrl::DiscardEdits()
710 ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0);
713 // EM controls do not have a SETCHANGED but issuing a query should reset it
715 ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0);
716 } // end of wxTextCtrl::DiscardEdits
718 int wxTextCtrl::GetNumberOfLines() const
723 nNumLines
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0);
727 } // end of wxTextCtrl::GetNumberOfLines
729 long wxTextCtrl::XYToPosition(
734 HWND hWnd
= GetHwnd();
735 long lCharIndex
= 0L;
740 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
741 lCharIndex
= ((lLen
* lY
) + lX
);
746 } // end of wxTextCtrl::XYToPosition
748 bool wxTextCtrl::PositionToXY(
754 HWND hWnd
= GetHwnd();
759 nLineNo
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0);
770 // This gets the char index for the _beginning_ of this line
776 lLineWidth
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0);
777 lCharIndex
= (nLineNo
+ 1) * lLineWidth
;
783 vParams
.fsStatus
= WPM_CCHTEXT
;
784 if (::WinSendMsg( hWnd
785 ,WM_QUERYWINDOWPARAMS
790 lCharIndex
= vParams
.cchText
;
796 if (lCharIndex
== -1)
802 // The X position must therefore be the difference between pos and charIndex
805 *plX
= lPos
- lCharIndex
;
810 } // end of wxTextCtrl::PositionToXY
812 void wxTextCtrl::ShowPosition(
816 HWND hWnd
= GetHwnd();
817 long lCurrentLineLineNo
= 0L;
819 // To scroll to a position, we pass the number of lines and characters
820 // to scroll *by*. This means that we need to:
821 // (1) Find the line position of the current line.
822 // (2) Find the line position of pos.
823 // (3) Scroll by (pos - current).
824 // For now, ignore the horizontal scrolling.
827 // Is this where scrolling is relative to - the line containing the caret?
828 // Or is the first visible line??? Try first visible line.
833 // In PM this is the actual char position
835 lCurrentLineLineNo
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0);
838 // This will cause a scroll to the selected position
840 ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
);
842 } // end of wxTextCtrl::ShowPosition
844 int wxTextCtrl::GetLineLength(
851 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
856 vParams
.fsStatus
= WPM_CCHTEXT
;
857 if (::WinSendMsg( GetHwnd()
858 ,WM_QUERYWINDOWPARAMS
863 lLen
= vParams
.cchText
;
869 } // end ofwxTextCtrl::GetLineLength
871 wxString
wxTextCtrl::GetLineText(
875 long lLen
= (long)GetLineLength((long)lLineNo
) + 1;
880 // There must be at least enough place for the length WORD in the
883 lLen
+= sizeof(WORD
);
884 zBuf
= new char[lLen
];
891 lLen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0);
892 lIndex
= lLen
* lLineNo
;
894 ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
);
895 ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
)));
896 lBuflen
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1));
897 lCopied
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
));
898 zBuf
[lCopied
] = '\0';
904 vParams
.fsStatus
= WPM_CCHTEXT
;
905 if (::WinSendMsg( GetHwnd()
906 ,WM_QUERYWINDOWPARAMS
910 memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
);
911 zBuf
[vParams
.cchText
] = '\0';
916 } // end of wxTextCtrl::GetLineText
918 // ----------------------------------------------------------------------------
920 // ----------------------------------------------------------------------------
922 void wxTextCtrl::Undo()
927 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
928 // Simple entryfields cannot be undone
930 } // end of wxTextCtrl::Undo
932 void wxTextCtrl::Redo()
937 ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0);
938 // Simple entryfields cannot be undone
940 } // end of wxTextCtrl::Redo
942 bool wxTextCtrl::CanUndo() const
947 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
949 bOk
= FALSE
; // can't undo regular edit fields in PM
951 } // end of wxTextCtrl::CanUndo
953 bool wxTextCtrl::CanRedo() const
958 bOk
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0);
960 bOk
= FALSE
; // can't undo regular edit fields in PM
962 } // end of wxTextCtrl::CanRedo
964 // ----------------------------------------------------------------------------
965 // implemenation details
966 // ----------------------------------------------------------------------------
968 void wxTextCtrl::Command(
969 wxCommandEvent
& rEvent
972 SetValue(rEvent
.GetString());
973 ProcessCommand (rEvent
);
974 } // end of wxTextCtrl::Command
976 void wxTextCtrl::OnDropFiles(
977 wxDropFilesEvent
& rEvent
980 // By default, load the first file into the text window.
981 if (rEvent
.GetNumberOfFiles() > 0)
983 LoadFile(rEvent
.GetFiles()[0]);
985 } // end of wxTextCtrl::OnDropFiles
987 WXHBRUSH
wxTextCtrl::OnCtlColor(
996 HPS hPS
= (HPS
)hWxDC
;
997 wxBrush
* pBrush
= NULL
;
998 wxColour vColBack
= GetBackgroundColour();
999 wxColour vColFore
= GetForegroundColour();
1000 wxBrush
* pBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour()
1006 HBRUSH hBrush
= NULLHANDLE
;
1010 if (GetParent()->GetTransparentBackground())
1011 ::GpiSetBackMix(hPS
, BM_LEAVEALONE
);
1013 ::GpiSetBackMix(hPS
, BM_OVERPAINT
);
1014 if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0)
1015 vColBack
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
);
1016 ::GpiSetBackColor(hPS
, vColBack
.GetPixel());
1017 ::GpiSetColor(hPS
, vColFore
.GetPixel());
1018 return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle();
1019 } // end of wxTextCtrl::OnCtlColor
1021 bool wxTextCtrl::OS2ShouldPreProcessMessage(
1025 return wxControl::OS2ShouldPreProcessMessage(pMsg
);
1026 } // end of wxTextCtrl::OS2ShouldPreProcessMessage
1028 void wxTextCtrl::OnChar(
1032 switch (rEvent
.KeyCode())
1035 if ( !(m_windowStyle
& wxTE_MULTILINE
) )
1037 wxCommandEvent
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
1039 vEvent
.SetEventObject(this);
1040 if ( GetEventHandler()->ProcessEvent(vEvent
))
1043 //else: multiline controls need Enter for themselves
1048 // always produce navigation event - even if we process TAB
1049 // ourselves the fact that we got here means that the user code
1050 // decided to skip processing of this TAB - probably to let it
1051 // do its default job.
1053 // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is
1054 // handled by Windows
1056 wxNavigationKeyEvent vEventNav
;
1058 vEventNav
.SetDirection(!rEvent
.ShiftDown());
1059 vEventNav
.SetWindowChange(FALSE
);
1060 vEventNav
.SetEventObject(this);
1062 if ( GetEventHandler()->ProcessEvent(vEventNav
) )
1068 } // end of wxTextCtrl::OnChar
1070 bool wxTextCtrl::OS2Command(
1072 , WXWORD
WXUNUSED(vId
)
1080 wxFocusEvent
vEvent( uParam
== EN_KILLFOCUS
? wxEVT_KILL_FOCUS
1085 vEvent
.SetEventObject(this);
1086 GetEventHandler()->ProcessEvent(vEvent
);
1092 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1096 InitCommandEvent(vEvent
);
1097 vEvent
.SetString((char*)GetValue().c_str());
1098 ProcessCommand(vEvent
);
1104 // The text size limit has been hit - increase it
1110 case EN_INSERTMODETOGGLE
:
1121 } // end of wxTextCtrl::OS2Command
1123 void wxTextCtrl::AdjustSpaceLimit()
1125 unsigned int uLen
= 0;
1126 unsigned int uLimit
= 0;
1128 uLen
= ::WinQueryWindowTextLength(GetHwnd());
1131 uLimit
= (unsigned int)::WinSendMsg( GetHwnd()
1142 vParams
.fsStatus
= WPM_CBCTLDATA
;
1143 vParams
.cbCtlData
= sizeof(ENTRYFDATA
);
1145 if (::WinSendMsg( GetHwnd()
1146 ,WM_QUERYWINDOWPARAMS
1151 pEfd
= (ENTRYFDATA
*)vParams
.pCtlData
;
1152 uLimit
= (unsigned int)pEfd
->cchEditLimit
;
1155 uLimit
= 32; //PM's default
1159 uLimit
= uLen
+ 0x8000; // 32Kb
1160 if (uLimit
> 0xffff)
1165 ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1167 ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0);
1169 } // end of wxTextCtrl::AdjustSpaceLimit
1171 bool wxTextCtrl::AcceptsFocus() const
1174 // We don't want focus if we can't be edited
1176 return IsEditable() && wxControl::AcceptsFocus();
1177 } // end of wxTextCtrl::Command
1179 wxSize
wxTextCtrl::DoGetBestSize() const
1184 wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont());
1186 int wText
= DEFAULT_ITEM_WIDTH
;
1187 int hText
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8);
1189 if (m_windowStyle
& wxTE_MULTILINE
)
1191 hText
*= wxMax(GetNumberOfLines(), 5);
1193 //else: for single line control everything is ok
1194 return wxSize(wText
, hText
);
1195 } // end of wxTextCtrl::DoGetBestSize
1197 // ----------------------------------------------------------------------------
1198 // standard handlers for standard edit menu events
1199 // ----------------------------------------------------------------------------
1201 void wxTextCtrl::OnCut(
1202 wxCommandEvent
& rEvent
1206 } // end of wxTextCtrl::OnCut
1208 void wxTextCtrl::OnCopy(
1209 wxCommandEvent
& rEvent
1213 } // end of wxTextCtrl::OnCopy
1215 void wxTextCtrl::OnPaste(
1216 wxCommandEvent
& rEvent
1220 } // end of wxTextCtrl::OnPaste
1222 void wxTextCtrl::OnUndo(
1223 wxCommandEvent
& rEvent
1227 } // end of wxTextCtrl::OnUndo
1229 void wxTextCtrl::OnRedo(
1230 wxCommandEvent
& rEvent
1234 } // end of wxTextCtrl::OnRedo
1236 void wxTextCtrl::OnUpdateCut(
1237 wxUpdateUIEvent
& rEvent
1240 rEvent
.Enable(CanCut());
1241 } // end of wxTextCtrl::OnUpdateCut
1243 void wxTextCtrl::OnUpdateCopy(
1244 wxUpdateUIEvent
& rEvent
1247 rEvent
.Enable(CanCopy());
1248 } // end of wxTextCtrl::OnUpdateCopy
1250 void wxTextCtrl::OnUpdatePaste(
1251 wxUpdateUIEvent
& rEvent
1254 rEvent
.Enable(CanPaste());
1255 } // end of wxTextCtrl::OnUpdatePaste
1257 void wxTextCtrl::OnUpdateUndo(
1258 wxUpdateUIEvent
& rEvent
1261 rEvent
.Enable(CanUndo());
1262 } // end of wxTextCtrl::OnUpdateUndo
1264 void wxTextCtrl::OnUpdateRedo(
1265 wxUpdateUIEvent
& rEvent
1268 rEvent
.Enable(CanRedo());
1269 } // end of wxTextCtrl::OnUpdateRedo
1271 bool wxTextCtrl::SetBackgroundColour(
1272 const wxColour
& rColour
1276 ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1278 } // end of wxTextCtrl::SetBackgroundColour
1280 bool wxTextCtrl::SetForegroundColour(
1281 const wxColour
& rColour
1285 ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
);
1287 } // end of wxTextCtrl::SetForegroundColour
1289 bool wxTextCtrl::SetStyle(
1292 , const wxTextAttr
& rStyle
1295 HWND hWnd
= GetHwnd();
1306 // We can only change the format of the selection, so select the range we
1307 // want and restore the old selection later
1312 GetSelection( &lStartOld
1317 // But do we really have to change the selection?
1319 bool bChangeSel
= lStart
!= lStartOld
||
1325 ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1327 ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0);
1331 // TODO:: finish this part
1334 } // end of wxTextCtrl::SetStyle