]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/textctrl.cpp
Applied a modification of Patch #704995 which changes how the lines
[wxWidgets.git] / src / mac / textctrl.cpp
index c678b88edcdf81badb06b84d6d53d3b1a86c5dcc..ae6063d20c4bdabdc2a75c439e2af6fe191bb251 100644 (file)
@@ -1,11 +1,11 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        textctrl.cpp
 // Purpose:     wxTextCtrl
-// Author:      AUTHOR
+// Author:      Stefan Csomor
 // Modified by:
-// Created:     ??/??/98
+// Created:     1998-01-01
 // RCS-ID:      $Id$
-// Copyright:   (c) AUTHOR
+// Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
@@ -296,7 +296,13 @@ static pascal ControlPartCode TPPaneTrackingProc(ControlHandle theControl, Point
             case kmUPTextPart:
                 {   SetPort((**tpvars).fDrawingEnvironment);
                     wxMacWindowClipper clipper( wxFindControlFromMacControl(theControl ) ) ;
+#if !TARGET_CARBON 
                     TXNClick( varsp->fTXNRec, (const EventRecord*) wxTheApp->MacGetCurrentEvent());
+#else
+                    EventRecord rec ;
+                    ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
+                    TXNClick( varsp->fTXNRec, &rec );
+#endif
                 }
                 break;
             
@@ -656,15 +662,15 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
            const wxValidator& validator,
            const wxString& name)
 {
-  m_macTE = NULL ;
-  m_macTXN = NULL ;
-  m_macTXNvars = NULL ;
-  m_macUsesTXN = false ;
-  m_editable = true ;
-
-  m_macUsesTXN = ! (style & wxTE_PASSWORD ) ; 
-
-  m_macUsesTXN &= (TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress) ;
+    m_macTE = NULL ;
+    m_macTXN = NULL ;
+    m_macTXNvars = NULL ;
+    m_macUsesTXN = false ;
+    m_editable = true ;
+    
+    m_macUsesTXN = ! (style & wxTE_PASSWORD ) ; 
+    
+    m_macUsesTXN &= (TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress) ;
     
     // base initialization
     if ( !CreateBase(parent, id, pos, size, style, validator, name) )
@@ -729,10 +735,6 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         m_macControl = NewControl(MAC_WXHWND(parent->MacGetRootWindow()), &bounds, "\p", true, featurSet, 0, featurSet, kControlUserPaneProc, 0);
             /* set up the mUP specific features and data */
         mUPOpenControl((ControlHandle) m_macControl, m_windowStyle );
-        if ( parent )
-        {
-            parent->MacGetTopLevelWindow()->MacInstallEventHandler() ;
-        }
     }
     MacPostControlCreate() ;
 
@@ -762,51 +764,58 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart);
     }
   
-  return TRUE;
+    return TRUE;
 }
 
 wxString wxTextCtrl::GetValue() const
 {
-    Size actualsize;
-    
+    Size actualSize = 0;
+    wxString result ;
+    OSStatus err ;
     if ( !m_macUsesTXN )
     {
-        ::GetControlData( (ControlHandle) m_macControl, 0,
-            ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, 
-            32767 , wxBuffer , &actualsize ) ;
+        err = ::GetControlDataSize((ControlHandle) m_macControl, 0,
+            ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, &actualSize ) ;
+       
+           if ( err )
+               return wxEmptyString ;
+           
+           if ( actualSize > 0 )
+           {
+            wxChar *ptr = result.GetWriteBuf(actualSize) ;
+            
+            ::GetControlData( (ControlHandle) m_macControl, 0,
+                ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag, 
+                actualSize , ptr , &actualSize ) ;
+            ptr[actualSize] = 0 ;
+            result.UngetWriteBuf(actualSize) ;
+        }
+        
     }
     else
     {
         Handle theText ;
-        OSStatus err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
+        err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
         // all done
         if ( err )
         {
-            actualsize = 0 ;
+            actualSize = 0 ;
         }
         else
         {
-            actualsize = GetHandleSize( theText ) ;
-            if (actualsize != 0)
-              strncpy( wxBuffer , *theText , actualsize ) ;
+            actualSize = GetHandleSize( theText ) ;
+               if ( actualSize > 0 )
+               {
+                wxChar *ptr = result.GetWriteBuf(actualSize) ;
+                strncpy( ptr , *theText , actualSize ) ;
+                ptr[actualSize] = 0 ;
+                result.UngetWriteBuf( actualSize ) ;
+            }
             DisposeHandle( theText ) ;
         }
     }
     
-    wxBuffer[actualsize] = 0 ;
-    
-    wxString value;
-
-    if( wxApp::s_macDefaultEncodingIsPC )
-    {
-        value = wxMacMakePCStringFromMac( wxBuffer ) ;
-        value.Replace( "\r", "\n" );
-    }
-    else
-        value = wxBuffer;
-        
-    
-    return value;
+    return wxMacMakeStringFromMacString( result ) ;
 }
 
 void wxTextCtrl::GetSelection(long* from, long* to) const
@@ -829,7 +838,7 @@ void wxTextCtrl::SetValue(const wxString& st)
     if( wxApp::s_macDefaultEncodingIsPC )
     {
         value = wxMacMakeMacStringFromPC( st ) ;
-        value.Replace( "\n", "\r" );
+        // value.Replace( "\n", "\r" ); TODO this should be handled by the conversion
     }
     else
         value = st;
@@ -1081,42 +1090,42 @@ void wxTextCtrl::SetInsertionPointEnd()
 
 long wxTextCtrl::GetInsertionPoint() const
 {
-  long begin,end ;
-  GetSelection( &begin , &end ) ;
-  return begin ;
+    long begin,end ;
+    GetSelection( &begin , &end ) ;
+    return begin ;
 }
 
 long wxTextCtrl::GetLastPosition() const
 {
     if ( !m_macUsesTXN )
-  {
-    return (**((TEHandle) m_macTE)).teLength ;
-  }
-  else
-  {
-    Handle theText ;
-    long actualsize ;
-    OSErr err = TXNGetDataEncoded( (TXNObject) m_macTXN, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
-        /* all done */
-    if ( err )
     {
-      actualsize = 0 ;
+        return (**((TEHandle) m_macTE)).teLength ;
     }
     else
     {
-      actualsize = GetHandleSize( theText ) ;
-      DisposeHandle( theText ) ;
+        Handle theText ;
+        long actualsize ;
+        OSErr err = TXNGetDataEncoded( (TXNObject) m_macTXN, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
+        /* all done */
+        if ( err )
+        {
+            actualsize = 0 ;
+        }
+        else
+        {
+            actualsize = GetHandleSize( theText ) ;
+            DisposeHandle( theText ) ;
+        }
+        return actualsize ;
     }
-    return actualsize ;
-  }
 }
 
 void wxTextCtrl::Replace(long from, long to, const wxString& value)
 {
-  if ( !m_macUsesTXN )
-  {
+    if ( !m_macUsesTXN )
+    {
         ControlEditTextSelectionRec selection ;
-   
+        
         selection.selStart = from ;
         selection.selEnd = to ;
         ::SetControlData((ControlHandle)  m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
@@ -1132,7 +1141,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
         TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ;
         TXNClear( ((TXNObject) m_macTXN) ) ;
         TXNSetData( ((TXNObject) m_macTXN), kTXNTextData,  (void*)value.c_str(), value.Length(),
-        kTXNUseCurrentSelection, kTXNUseCurrentSelection);
+            kTXNUseCurrentSelection, kTXNUseCurrentSelection);
         if ( !formerEditable )
             SetEditable( formerEditable ) ;
     }
@@ -1141,52 +1150,52 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
 
 void wxTextCtrl::Remove(long from, long to)
 {
-  if ( !m_macUsesTXN )
-  {
-    ControlEditTextSelectionRec selection ;
-   
-    selection.selStart = from ;
-    selection.selEnd = to ;
-    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-    TEDelete( ((TEHandle) m_macTE) ) ;
-  }
-  else
-  {
-    bool formerEditable = IsEditable() ;
-    if ( !formerEditable )
-        SetEditable(true) ;
-    TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; 
-    TXNClear( ((TXNObject) m_macTXN) ) ; 
-    if ( !formerEditable )
-        SetEditable( formerEditable ) ;
-  }
+    if ( !m_macUsesTXN )
+    {
+        ControlEditTextSelectionRec selection ;
+        
+        selection.selStart = from ;
+        selection.selEnd = to ;
+        ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        TEDelete( ((TEHandle) m_macTE) ) ;
+    }
+    else
+    {
+        bool formerEditable = IsEditable() ;
+        if ( !formerEditable )
+            SetEditable(true) ;
+        TXNSetSelection( ((TXNObject) m_macTXN) , from , to ) ; 
+        TXNClear( ((TXNObject) m_macTXN) ) ; 
+        if ( !formerEditable )
+            SetEditable( formerEditable ) ;
+    }
     Refresh() ;
 }
 
 void wxTextCtrl::SetSelection(long from, long to)
 {
-
-  if ( !m_macUsesTXN )
-  {
-   ControlEditTextSelectionRec selection ;
-   selection.selStart = from ;
-   selection.selEnd = to ;
-   
-   TESetSelect( selection.selStart , selection.selEnd , ((TEHandle) m_macTE) ) ;
-   ::SetControlData((ControlHandle)  m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-  }
-  else
-  {
-    STPTextPaneVars **tpvars;
+    
+    if ( !m_macUsesTXN )
+    {
+        ControlEditTextSelectionRec selection ;
+        selection.selStart = from ;
+        selection.selEnd = to ;
+        
+        TESetSelect( selection.selStart , selection.selEnd , ((TEHandle) m_macTE) ) ;
+        ::SetControlData((ControlHandle)  m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    }
+    else
+    {
+        STPTextPaneVars **tpvars;
         /* set up our locals */
-    tpvars = (STPTextPaneVars **) GetControlReference((ControlHandle) m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference((ControlHandle) m_macControl);
         /* and our drawing environment as the operation
         may force a redraw in the text area. */
-    SetPort((**tpvars).fDrawingEnvironment);
+        SetPort((**tpvars).fDrawingEnvironment);
         /* change the selection */
-    TXNSetSelection( (**tpvars).fTXNRec, from, to);
-    TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart);
-  }
+        TXNSetSelection( (**tpvars).fTXNRec, from, to);
+        TXNShowSelection( (TXNObject) m_macTXN, kTXNShowStart);
+    }
 }
 
 bool wxTextCtrl::LoadFile(const wxString& file)
@@ -1205,7 +1214,7 @@ void wxTextCtrl::WriteText(const wxString& text)
     if( wxApp::s_macDefaultEncodingIsPC )
     {
         value = wxMacMakeMacStringFromPC( text ) ;
-        value.Replace( "\n", "\r" );
+        // value.Replace( "\n", "\r" ); // TODO this should be handled by the conversion
     }
     else
         value = text ;
@@ -1243,15 +1252,15 @@ void wxTextCtrl::Clear()
     {
         return ;
     }
-  if ( !m_macUsesTXN )
-  {
-    ::SetControlData((ControlHandle)  m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
-  }
-  else
-  {
+    if ( !m_macUsesTXN )
+    {
+        ::SetControlData((ControlHandle)  m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    }
+    else
+    {
         TXNSetSelection( (TXNObject)m_macTXN , kTXNStartOffset , kTXNEndOffset ) ;
         TXNClear((TXNObject)m_macTXN); 
-  }
+    }
     Refresh() ;
 }
 
@@ -1340,8 +1349,8 @@ void wxTextCtrl::DiscardEdits()
 
 int wxTextCtrl::GetNumberOfLines() const
 {
-  // TODO change this if possible to reflect real lines
-  wxString content = GetValue() ;
+    // TODO change this if possible to reflect real lines
+    wxString content = GetValue() ;
     
     int count = 1;
     for (size_t i = 0; i < content.Length() ; i++)
@@ -1370,8 +1379,8 @@ void wxTextCtrl::ShowPosition(long pos)
 
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
-  // TODO change this if possible to reflect real lines
-  wxString content = GetValue() ;
+    // TODO change this if possible to reflect real lines
+    wxString content = GetValue() ;
     
     // Find line first
     int count = 0;
@@ -1396,8 +1405,8 @@ int wxTextCtrl::GetLineLength(long lineNo) const
 
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
-  // TODO change this if possible to reflect real lines
-  wxString content = GetValue() ;
+    // TODO change this if possible to reflect real lines
+    wxString content = GetValue() ;
 
     // Find line first
     int count = 0;
@@ -1570,7 +1579,7 @@ bool  wxTextCtrl::Show(bool show)
     
     bool retval = wxControl::Show( show ) ;
     
-    if ( former != m_macControlIsShown && show )
+    if ( former != m_macControlIsShown && m_macUsesTXN )
     {
         if ( m_macControlIsShown )
             TXNSetFrameBounds( (TXNObject) m_macTXN, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.top, (**(STPTextPaneVars **)m_macTXNvars).fRTextArea.left,