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 void wxTextCtrl::SetupColours() 
 257     wxColour                        vBkgndColour
; 
 259     vBkgndColour 
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
); 
 260     SetBackgroundColour(vBkgndColour
); 
 261     SetForegroundColour(GetParent()->GetForegroundColour()); 
 264         ::WinSendMsg( GetHwnd() 
 266                      ,(MPARAM
)GetParent()->GetForegroundColour().GetPixel() 
 270 } // end of wxTextCtrl::SetupColours 
 272 // ---------------------------------------------------------------------------- 
 273 // set/get the controls text 
 274 // ---------------------------------------------------------------------------- 
 276 wxString 
wxTextCtrl::GetValue() const 
 278     wxString                        sStr 
= wxGetWindowText(GetHWND()); 
 279     char*                           zStr 
= (char*)sStr
.c_str(); 
 281     for ( ; *zStr
; zStr
++ ) 
 284         // this will replace \r\n with just \n 
 293 } // end of wxTextCtrl::GetValue 
 295 void wxTextCtrl::SetValue( 
 296   const wxString
&                   rsValue
 
 300     // If the text is long enough, it's faster to just set it instead of first 
 301     // comparing it with the old one (chances are that it will be different 
 302     // anyhow, this comparison is there to avoid flicker for small single-line 
 303     // edit controls mostly) 
 305     if ((rsValue
.length() > 0x400) || (rsValue 
!= GetValue())) 
 307         ::WinSetWindowText(GetHwnd(), rsValue
.c_str()); 
 310 } // end of wxTextCtrl::SetValue 
 312 void wxTextCtrl::WriteText( 
 313   const wxString
&                   rsValue
 
 317         ::WinSendMsg(GetHwnd(), MLM_INSERT
, MPARAM((PCHAR
)rsValue
.c_str()), MPARAM(0)); 
 319         ::WinSetWindowText(GetHwnd(), rsValue
.c_str()); 
 321 } // end of wxTextCtrl::WriteText 
 323 void wxTextCtrl::AppendText( 
 324   const wxString
&                   rsText
 
 327     SetInsertionPointEnd(); 
 329 } // end of wxTextCtrl::AppendText 
 331 void wxTextCtrl::Clear() 
 333     ::WinSetWindowText(GetHwnd(), ""); 
 334 } // end of wxTextCtrl::Clear 
 336 // ---------------------------------------------------------------------------- 
 337 // Clipboard operations 
 338 // ---------------------------------------------------------------------------- 
 340 void wxTextCtrl::Copy() 
 344         HWND hWnd 
= GetHwnd(); 
 346             ::WinSendMsg(hWnd
, MLM_COPY
, 0, 0); 
 348             ::WinSendMsg(hWnd
, EM_COPY
, 0, 0); 
 350 } // end of wxTextCtrl::Copy 
 352 void wxTextCtrl::Cut() 
 356         HWND hWnd 
= GetHwnd(); 
 359             ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0); 
 361             ::WinSendMsg(hWnd
, EM_CUT
, 0, 0); 
 363 } // end of wxTextCtrl::Cut 
 365 void wxTextCtrl::Paste() 
 369         HWND                        hWnd 
= GetHwnd(); 
 371         ::WinSendMsg(hWnd
, EM_PASTE
, 0, 0); 
 373 } // end of wxTextCtrl::Paste 
 375 bool wxTextCtrl::CanCopy() const 
 378     // Can copy if there's a selection 
 383     GetSelection(&lFrom
, &lTo
); 
 384     return (lFrom 
!= lTo
); 
 385 } // end of wxTextCtrl::CanCopy 
 387 bool wxTextCtrl::CanCut() const 
 390     // Can cut if there's a selection 
 395     GetSelection(&lFrom
, &lTo
); 
 396     return (lFrom 
!= lTo
); 
 397 } // end of wxTextCtrl::CanCut 
 399 bool wxTextCtrl::CanPaste() const 
 401     bool                            bIsTextAvailable 
= FALSE
; 
 407     // Check for straight text on clipboard 
 409     if (::WinOpenClipbrd(vHabmain
)) 
 411         bIsTextAvailable 
= (::WinQueryClipbrdData(vHabmain
, CF_TEXT
) != 0); 
 412         ::WinCloseClipbrd(vHabmain
); 
 414     return bIsTextAvailable
; 
 415 } // end of wxTextCtrl::CanPaste 
 417 // ---------------------------------------------------------------------------- 
 419 // ---------------------------------------------------------------------------- 
 421 void wxTextCtrl::SetEditable( 
 425     HWND                            hWnd 
= GetHwnd(); 
 428         ::WinSendMsg(hWnd
, MLM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0); 
 430         ::WinSendMsg(hWnd
, EM_SETREADONLY
, MPFROMLONG(!bEditable
), (MPARAM
)0); 
 431 } // end of wxTextCtrl::SetEditable 
 433 void wxTextCtrl::SetInsertionPoint( 
 437     HWND                            hWnd 
= GetHwnd(); 
 440         ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lPos
, (MPARAM
)lPos
); 
 442         ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lPos
, (USHORT
)lPos
), (MPARAM
)0); 
 443 } // end of wxTextCtrl::SetInsertionPoint 
 445 void wxTextCtrl::SetInsertionPointEnd() 
 447     long                            lPos 
= GetLastPosition(); 
 449     SetInsertionPoint(lPos
); 
 450 } // end of wxTextCtrl::SetInsertionPointEnd 
 452 long wxTextCtrl::GetInsertionPoint() const 
 457         dwPos 
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0); 
 460         dwPos 
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0); 
 461         dwPos 
= SHORT1FROMMP((MPARAM
)dwPos
);  // the first 16 bit value is the min pos 
 463     return (dwPos 
& 0xFFFF); 
 464 } // end of wxTextCtrl::GetInsertionPoint 
 466 long wxTextCtrl::GetLastPosition() const 
 468     HWND                            hWnd 
= GetHwnd(); 
 477         // This just gets the total text length.  The last will be this value 
 479         lLineLength 
= (long)::WinSendMsg(hWnd
, MLM_QUERYTEXTLENGTH
, 0, 0); 
 486         vParams
.fsStatus 
= WPM_CCHTEXT
; 
 487         if (::WinSendMsg( GetHwnd() 
 488                          ,WM_QUERYWINDOWPARAMS
 
 493             lLineLength 
= (long)vParams
.cchText
; 
 498     return(lCharIndex 
+ lLineLength
); 
 499 } // end of wxTextCtrl::GetLastPosition 
 501 // If the return values from and to are the same, there is no 
 503 void wxTextCtrl::GetSelection( 
 511         dwPos 
= (WXDWORD
)::WinSendMsg(GetHwnd(), MLM_QUERYSEL
, (MPARAM
)MLFQS_MINSEL
, 0); 
 514         dwPos 
= (WXDWORD
)::WinSendMsg(GetHwnd(), EM_QUERYSEL
, 0, 0); 
 516     *plFrom 
= SHORT1FROMMP((MPARAM
)dwPos
);  // the first 16 bit value is the min pos 
 517     *plTo 
= SHORT2FROMMP((MPARAM
)dwPos
);  // the first 16 bit value is the min pos 
 518 } // end of wxTextCtrl::GetSelection 
 520 bool wxTextCtrl::IsEditable() const 
 523         return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYREADONLY
, 0, 0))); 
 525         return((bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYREADONLY
, 0, 0))); 
 526 } // end of wxTextCtrl::IsEditable 
 528 // ---------------------------------------------------------------------------- 
 530 // ---------------------------------------------------------------------------- 
 532 void wxTextCtrl::Replace( 
 535 , const wxString
&                   rsValue
 
 539     HWND                            hWnd      
= GetHwnd(); 
 540     long                            lFromChar 
= lFrom
; 
 544     // Set selection and remove it 
 548         ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0); 
 549         ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0); 
 553         ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0); 
 554         ::WinSendMsg(hWnd
, EM_CUT
, 0, 0); 
 558     // Now replace with 'value', by pasting. 
 560     wxSetClipboardData(wxDF_TEXT
, (wxObject 
*) (const wxChar 
*)rsValue
, 0, 0); 
 562     // Paste into edit control 
 564         ::WinSendMsg(hWnd
, MLM_PASTE
, (MPARAM
)0, (MPARAM
)0); 
 566         ::WinSendMsg(hWnd
, EM_PASTE
, (MPARAM
)0, (MPARAM
)0); 
 568     wxFAIL_MSG("wxTextCtrl::Replace not implemented if wxUSE_CLIPBOARD is 0."); 
 570 }  // end of wxTextCtrl::Replace 
 572 void wxTextCtrl::Remove( 
 577     HWND                            hWnd      
= GetHwnd(); 
 578     long                            lFromChar 
= lFrom
; 
 583         ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0); 
 584         ::WinSendMsg(hWnd
, MLM_CUT
, 0, 0); 
 588         ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFrom
, (USHORT
)lTo
), 0); 
 589         ::WinSendMsg(hWnd
, EM_CUT
, 0, 0); 
 591 } // end of wxTextCtrl::Remove 
 593 void wxTextCtrl::SetSelection( 
 598     HWND                            hWnd 
= GetHwnd(); 
 599     long                            lFromChar 
= lFrom
; 
 603     // If from and to are both -1, it means (in wxWindows) that all text should 
 604     // be selected. Translate into Windows convention 
 606     if ((lFrom 
== -1L) && (lTo 
== -1L)) 
 612         ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lFromChar
, (MPARAM
)lToChar
); 
 614         ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lFromChar
, (USHORT
)lToChar
), (MPARAM
)0); 
 615 } // end of wxTextCtrl::SetSelection 
 617 bool wxTextCtrl::LoadFile( 
 618   const wxString
&                   rsFile
 
 621     if ( wxTextCtrlBase::LoadFile(rsFile
) ) 
 624         // Update the size limit if needed 
 630 } // end of wxTextCtrl::LoadFile 
 632 bool wxTextCtrl::IsModified() const 
 637         bRc 
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), MLM_QUERYCHANGED
, 0, 0)); 
 639         bRc 
= (bool)LONGFROMMR(::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0)); 
 641 } // end of wxTextCtrl::IsModified 
 644 // Makes 'unmodified' 
 646 void wxTextCtrl::DiscardEdits() 
 649         ::WinSendMsg(GetHwnd(), MLM_SETCHANGED
, MPFROMLONG(FALSE
), 0); 
 652         // EM controls do not have a SETCHANGED but issuing a query should reset it 
 654         ::WinSendMsg(GetHwnd(), EM_QUERYCHANGED
, 0, 0); 
 655 } // end of wxTextCtrl::DiscardEdits 
 657 int wxTextCtrl::GetNumberOfLines() const 
 662         nNumLines 
= (int)::WinSendMsg(GetHwnd(), MLM_QUERYLINECOUNT
, 0, 0); 
 666 } // end of wxTextCtrl::GetNumberOfLines 
 668 long wxTextCtrl::XYToPosition( 
 673     HWND                            hWnd 
= GetHwnd(); 
 674     long                            lCharIndex 
= 0L; 
 679         lLen 
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0); 
 680         lCharIndex 
= ((lLen 
* lY
) + lX
); 
 685 } // end of wxTextCtrl::XYToPosition 
 687 bool wxTextCtrl::PositionToXY( 
 693     HWND                            hWnd 
= GetHwnd(); 
 698         nLineNo 
= (long)::WinSendMsg(hWnd
, MLM_LINEFROMCHAR
, (MPARAM
)lPos
, 0); 
 709     // This gets the char index for the _beginning_ of this line 
 715         lLineWidth 
= (long)::WinSendMsg(hWnd
, MLM_QUERYLINELENGTH
, (MPARAM
)0, (MPARAM
)0); 
 716         lCharIndex 
= (nLineNo 
+ 1) * lLineWidth
; 
 722         vParams
.fsStatus 
= WPM_CCHTEXT
; 
 723         if (::WinSendMsg( hWnd
 
 724                          ,WM_QUERYWINDOWPARAMS
 
 729             lCharIndex 
= vParams
.cchText
; 
 735     if (lCharIndex 
== -1) 
 741     // The X position must therefore be the difference between pos and charIndex 
 744         *plX 
= lPos 
- lCharIndex
; 
 749 } // end of wxTextCtrl::PositionToXY 
 751 void wxTextCtrl::ShowPosition( 
 755     HWND                            hWnd 
= GetHwnd(); 
 756     long                            lCurrentLineLineNo 
= 0L; 
 758     // To scroll to a position, we pass the number of lines and characters 
 759     // to scroll *by*. This means that we need to: 
 760     // (1) Find the line position of the current line. 
 761     // (2) Find the line position of pos. 
 762     // (3) Scroll by (pos - current). 
 763     // For now, ignore the horizontal scrolling. 
 766     // Is this where scrolling is relative to - the line containing the caret? 
 767     // Or is the first visible line??? Try first visible line. 
 772         // In PM this is the actual char position 
 774         lCurrentLineLineNo 
= (long)::WinSendMsg(hWnd
, MLM_QUERYFIRSTCHAR
, (MPARAM
)0, (MPARAM
)0); 
 777         // This will cause a scroll to the selected position 
 779         ::WinSendMsg(hWnd
, MLM_SETSEL
, (MPARAM
)lCurrentLineLineNo
, (MPARAM
)lCurrentLineLineNo
); 
 781 } // end of wxTextCtrl::ShowPosition 
 783 int wxTextCtrl::GetLineLength( 
 790         lLen 
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0); 
 795         vParams
.fsStatus 
= WPM_CCHTEXT
; 
 796         if (::WinSendMsg( GetHwnd() 
 797                          ,WM_QUERYWINDOWPARAMS
 
 802             lLen 
= vParams
.cchText
; 
 808 } // end ofwxTextCtrl::GetLineLength 
 810 wxString 
wxTextCtrl::GetLineText( 
 814     long                            lLen 
= (long)GetLineLength((long)lLineNo
) + 1; 
 819     // There must be at least enough place for the length WORD in the 
 822     lLen 
+= sizeof(WORD
); 
 823     zBuf 
= new char[lLen
]; 
 830         lLen 
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYLINELENGTH
, 0, 0); 
 831         lIndex 
= lLen 
* lLineNo
; 
 833         ::WinSendMsg(GetHwnd(), MLM_SETSEL
, (MPARAM
)lIndex
, (MPARAM
)lIndex
); 
 834         ::WinSendMsg(GetHwnd(), MLM_SETIMPORTEXPORT
, MPFROMP(zBuf
), MPFROMSHORT((USHORT
)sizeof(zBuf
))); 
 835         lBuflen 
= (long)::WinSendMsg(GetHwnd(), MLM_QUERYFORMATTEXTLENGTH
, MPFROMLONG(lIndex
), MPFROMLONG(-1)); 
 836         lCopied 
= (long)::WinSendMsg(GetHwnd(), MLM_EXPORT
, MPFROMP(&lIndex
), MPFROMP(&lBuflen
)); 
 837         zBuf
[lCopied
] = '\0'; 
 843         vParams
.fsStatus 
= WPM_CCHTEXT
; 
 844         if (::WinSendMsg( GetHwnd() 
 845                          ,WM_QUERYWINDOWPARAMS
 
 849          memcpy(zBuf
, vParams
.pszText
, vParams
.cchText
); 
 850          zBuf
[vParams
.cchText
] = '\0'; 
 855 } // end of wxTextCtrl::GetLineText 
 857 // ---------------------------------------------------------------------------- 
 859 // ---------------------------------------------------------------------------- 
 861 void wxTextCtrl::Undo() 
 866             ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0); 
 867         // Simple entryfields cannot be undone 
 869 } // end of wxTextCtrl::Undo 
 871 void wxTextCtrl::Redo() 
 876             ::WinSendMsg(GetHwnd(), MLM_UNDO
, 0, 0); 
 877         // Simple entryfields cannot be undone 
 879 } // end of wxTextCtrl::Redo 
 881 bool wxTextCtrl::CanUndo() const 
 886         bOk 
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0); 
 888         bOk 
= FALSE
; // can't undo regular edit fields in PM 
 890 } // end of wxTextCtrl::CanUndo 
 892 bool wxTextCtrl::CanRedo() const 
 897         bOk 
= (::WinSendMsg(GetHwnd(), MLM_QUERYUNDO
, 0, 0) != 0); 
 899         bOk 
= FALSE
; // can't undo regular edit fields in PM 
 901 } // end of wxTextCtrl::CanRedo 
 903 // ---------------------------------------------------------------------------- 
 904 // implemenation details 
 905 // ---------------------------------------------------------------------------- 
 907 void wxTextCtrl::Command( 
 908   wxCommandEvent
&                   rEvent
 
 911     SetValue(rEvent
.GetString()); 
 912     ProcessCommand (rEvent
); 
 913 } // end of wxTextCtrl::Command 
 915 void wxTextCtrl::OnDropFiles( 
 916   wxDropFilesEvent
&                 rEvent
 
 919     // By default, load the first file into the text window. 
 920     if (rEvent
.GetNumberOfFiles() > 0) 
 922         LoadFile(rEvent
.GetFiles()[0]); 
 924 } // end of wxTextCtrl::OnDropFiles 
 926 WXHBRUSH 
wxTextCtrl::OnCtlColor( 
 935     HPS                             hPS 
= (HPS
)hWxDC
; 
 936     wxBrush
*                        pBrush 
= NULL
; 
 937     wxColour                        vColBack 
= GetBackgroundColour(); 
 938     wxColour                        vColFore 
= GetForegroundColour(); 
 939     wxBrush
*                        pBackgroundBrush 
= wxTheBrushList
->FindOrCreateBrush( GetBackgroundColour() 
 945         HBRUSH                      hBrush 
= NULLHANDLE
; 
 949     if (GetParent()->GetTransparentBackground()) 
 950         ::GpiSetBackMix(hPS
, BM_LEAVEALONE
); 
 952         ::GpiSetBackMix(hPS
, BM_OVERPAINT
); 
 953     if (!IsEnabled() && (GetWindowStyle() & wxTE_MULTILINE
) == 0) 
 954         vColBack 
= wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
); 
 955     ::GpiSetBackColor(hPS
, vColBack
.GetPixel()); 
 956     ::GpiSetColor(hPS
, vColFore
.GetPixel()); 
 957     return (WXHBRUSH
)pBackgroundBrush
->GetResourceHandle(); 
 958 } // end of wxTextCtrl::OnCtlColor 
 960 bool wxTextCtrl::OS2ShouldPreProcessMessage( 
 964     return wxControl::OS2ShouldPreProcessMessage(pMsg
); 
 965 } // end of wxTextCtrl::OS2ShouldPreProcessMessage 
 967 void wxTextCtrl::OnChar( 
 971     switch (rEvent
.KeyCode()) 
 974             if ( !(m_windowStyle 
& wxTE_MULTILINE
) ) 
 976                 wxCommandEvent      
vEvent(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
); 
 978                 vEvent
.SetEventObject(this); 
 979                 if ( GetEventHandler()->ProcessEvent(vEvent
)) 
 982             //else: multiline controls need Enter for themselves 
 987             // always produce navigation event - even if we process TAB 
 988             // ourselves the fact that we got here means that the user code 
 989             // decided to skip processing of this TAB - probably to let it 
 990             // do its default job. 
 992             // NB: Notice that Ctrl-Tab is handled elsewhere and Alt-Tab is 
 993             //     handled by Windows 
 995                 wxNavigationKeyEvent    vEventNav
; 
 997                 vEventNav
.SetDirection(!rEvent
.ShiftDown()); 
 998                 vEventNav
.SetWindowChange(FALSE
); 
 999                 vEventNav
.SetEventObject(this); 
1001                 if ( GetEventHandler()->ProcessEvent(vEventNav
) ) 
1007 } // end of wxTextCtrl::OnChar 
1009 bool wxTextCtrl::OS2Command( 
1011 , WXWORD                            
WXUNUSED(vId
) 
1019                 wxFocusEvent        
vEvent( uParam 
== EN_KILLFOCUS 
? wxEVT_KILL_FOCUS
 
1024                 vEvent
.SetEventObject(this); 
1025                 GetEventHandler()->ProcessEvent(vEvent
); 
1031                 wxCommandEvent      
vEvent( wxEVT_COMMAND_TEXT_UPDATED
 
1035                 InitCommandEvent(vEvent
); 
1036                 vEvent
.SetString((char*)GetValue().c_str()); 
1037                 ProcessCommand(vEvent
); 
1043             // The text size limit has been hit - increase it 
1049         case EN_INSERTMODETOGGLE
: 
1060 } // end of wxTextCtrl::OS2Command 
1062 void wxTextCtrl::AdjustSpaceLimit() 
1064     unsigned int                    uLen 
= 0; 
1065     unsigned int                    uLimit 
= 0; 
1067     uLen   
= ::WinQueryWindowTextLength(GetHwnd()); 
1070         uLimit 
= (unsigned int)::WinSendMsg( GetHwnd() 
1081         vParams
.fsStatus 
= WPM_CBCTLDATA
; 
1082         vParams
.cbCtlData 
= sizeof(ENTRYFDATA
); 
1084         if (::WinSendMsg( GetHwnd() 
1085                          ,WM_QUERYWINDOWPARAMS
 
1090             pEfd 
= (ENTRYFDATA
*)vParams
.pCtlData
; 
1091             uLimit 
= (unsigned int)pEfd
->cchEditLimit
; 
1094             uLimit 
= 32; //PM's default 
1098         uLimit 
= uLen 
+ 0x8000;    // 32Kb 
1099         if (uLimit 
> 0xffff) 
1104             ::WinSendMsg(GetHwnd(), MLM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0); 
1106             ::WinSendMsg(GetHwnd(), EM_SETTEXTLIMIT
, MPFROMLONG(uLimit
), 0); 
1108 } // end of wxTextCtrl::AdjustSpaceLimit 
1110 bool wxTextCtrl::AcceptsFocus() const 
1113     // We don't want focus if we can't be edited 
1115     return IsEditable() && wxControl::AcceptsFocus(); 
1116 } // end of wxTextCtrl::Command 
1118 wxSize 
wxTextCtrl::DoGetBestSize() const 
1123     wxGetCharSize(GetHWND(), &nCx
, &nCy
, (wxFont
*)&GetFont()); 
1125     int                             wText 
= DEFAULT_ITEM_WIDTH
; 
1126     int                             hText 
= (EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * .8); 
1128     if (m_windowStyle 
& wxTE_MULTILINE
) 
1130         hText 
*= wxMax(GetNumberOfLines(), 5); 
1132     //else: for single line control everything is ok 
1133     return wxSize(wText
, hText
); 
1134 } // end of wxTextCtrl::DoGetBestSize 
1136 // ---------------------------------------------------------------------------- 
1137 // standard handlers for standard edit menu events 
1138 // ---------------------------------------------------------------------------- 
1140 void wxTextCtrl::OnCut( 
1141   wxCommandEvent
&                   rEvent
 
1145 } // end of wxTextCtrl::OnCut 
1147 void wxTextCtrl::OnCopy( 
1148   wxCommandEvent
&                   rEvent
 
1152 } // end of wxTextCtrl::OnCopy 
1154 void wxTextCtrl::OnPaste( 
1155   wxCommandEvent
&                   rEvent
 
1159 } // end of wxTextCtrl::OnPaste 
1161 void wxTextCtrl::OnUndo( 
1162   wxCommandEvent
&                   rEvent
 
1166 } // end of wxTextCtrl::OnUndo 
1168 void wxTextCtrl::OnRedo( 
1169   wxCommandEvent
&                   rEvent
 
1173 } // end of wxTextCtrl::OnRedo 
1175 void wxTextCtrl::OnUpdateCut( 
1176   wxUpdateUIEvent
&                  rEvent
 
1179     rEvent
.Enable(CanCut()); 
1180 } // end of wxTextCtrl::OnUpdateCut 
1182 void wxTextCtrl::OnUpdateCopy( 
1183   wxUpdateUIEvent
&                  rEvent
 
1186     rEvent
.Enable(CanCopy()); 
1187 } // end of wxTextCtrl::OnUpdateCopy 
1189 void wxTextCtrl::OnUpdatePaste( 
1190   wxUpdateUIEvent
&                  rEvent
 
1193     rEvent
.Enable(CanPaste()); 
1194 } // end of wxTextCtrl::OnUpdatePaste 
1196 void wxTextCtrl::OnUpdateUndo( 
1197   wxUpdateUIEvent
&                  rEvent
 
1200     rEvent
.Enable(CanUndo()); 
1201 } // end of wxTextCtrl::OnUpdateUndo 
1203 void wxTextCtrl::OnUpdateRedo( 
1204   wxUpdateUIEvent
&                  rEvent
 
1207     rEvent
.Enable(CanRedo()); 
1208 } // end of wxTextCtrl::OnUpdateRedo 
1210 bool wxTextCtrl::SetBackgroundColour( 
1211   const wxColour
&                   rColour
 
1215         ::WinSendMsg(GetHwnd(), MLM_SETBACKCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
); 
1217 } // end of wxTextCtrl::SetBackgroundColour 
1219 bool wxTextCtrl::SetForegroundColour( 
1220   const wxColour
&                   rColour
 
1224         ::WinSendMsg(GetHwnd(), MLM_SETTEXTCOLOR
, (MPARAM
)rColour
.GetPixel(), MLE_INDEX
); 
1226 } // end of wxTextCtrl::SetForegroundColour 
1228 bool wxTextCtrl::SetStyle( 
1231 , const wxTextAttr
&                 rStyle
 
1234     HWND                            hWnd 
= GetHwnd(); 
1245     // We can only change the format of the selection, so select the range we 
1246     // want and restore the old selection later 
1251     GetSelection( &lStartOld
 
1256     // But do we really have to change the selection? 
1258     bool                            bChangeSel 
= lStart 
!= lStartOld 
|| 
1264             ::WinSendMsg(hWnd
, MLM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0); 
1266             ::WinSendMsg(hWnd
, EM_SETSEL
, MPFROM2SHORT((USHORT
)lStart
, (USHORT
)lEnd
), 0); 
1270     // TODO:: finish this part 
1273 } // end of wxTextCtrl::SetStyle