]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/textctrl.cpp
Fixed programming error (and BCC warning).
[wxWidgets.git] / src / mac / textctrl.cpp
index 3e2ba6550fb190fa9a27f02a2c5151e1ac54744f..f479c01bb70ef9dcf6a05e8d85902fd4b6b8cf92 100644 (file)
@@ -28,7 +28,7 @@
 #include "wx/app.h"
 #include "wx/dc.h"
 #include "wx/button.h"
-#include "wx/panel.h"
+#include "wx/toplevel.h"
 #include "wx/textctrl.h"
 #include "wx/notebook.h"
 #include "wx/tabctrl.h"
   #include <malloc.h>
 #endif
 
+#ifndef __DARWIN__
+#include <Scrap.h>
+#include <MacTextEditor.h>
+#endif
 #include "wx/mac/uma.h"
 
 #define wxUSE_MLTE 0
@@ -124,7 +128,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
     }
 
 
-    m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
+    m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1, 
         ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ;
     MacPostControlCreate() ;
 
@@ -134,7 +138,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         (*teH)->lineHeight = -1 ;
     }
     
@@ -142,7 +146,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         value = wxMacMakeMacStringFromPC( st ) ;
     else
         value = st ;
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
 
   return TRUE;
 }
@@ -150,7 +154,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
 wxString wxTextCtrl::GetValue() const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     wxBuffer[actualsize] = 0 ;
     if( wxApp::s_macDefaultEncodingIsPC )
         return wxMacMakePCStringFromMac( wxBuffer ) ;
@@ -164,7 +168,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 
     *from = (**teH).selStart;
     *to = (**teH).selEnd;
@@ -178,41 +182,10 @@ void wxTextCtrl::SetValue(const wxString& st)
         value = wxMacMakeMacStringFromPC( st ) ;
     else
         value = st ;
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
-    WindowRef window = GetMacRootWindow() ;
-    if ( window )
-    {
-        wxWindow* win = wxFindWinFromMacWindow( window ) ;
-        if ( win )
-        {
-            wxMacDrawingHelper help( win ) ;
-            // the mac control manager always assumes to have the origin at 0,0
-            SetOrigin( 0 , 0 ) ;
-            
-            bool            hasTabBehind = false ;
-            wxWindow* parent = GetParent() ;
-            while ( parent )
-            {
-                if( parent->MacGetWindowData() )
-                {
-                    ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
-                    break ;
-                }
-                
-                if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ||  parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
-                {
-                    if ( ((wxControl*)parent)->GetMacControl() )
-                        SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ;
-                    break ;
-                }
-                
-                parent = parent->GetParent() ;
-            } 
-            
-            UMADrawControl( m_macControl ) ;
-            ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
-        }
-    }
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+
+    MacRedrawControl() ;
+    Update();
 }
 
 // Clipboard operations
@@ -223,16 +196,10 @@ void wxTextCtrl::Copy()
         TEHandle teH ;
         long size ;
    
-         ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-        TECopy( teH ) ;
-#if TARGET_CARBON
-        OSStatus err ;
-        err = ClearCurrentScrap( );
-#else
-        OSErr err ;
-        err = ZeroScrap( );
-#endif
-        TEToScrap() ;
+          ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECopy( teH ) ;
+        ClearCurrentScrap();
+            TEToScrap() ;
     }
 }
 
@@ -243,18 +210,12 @@ void wxTextCtrl::Cut()
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-        TECut( teH ) ;
-#if TARGET_CARBON
-        OSStatus err ;
-        err = ClearCurrentScrap( );
-#else
-        OSErr err ;
-        err = ZeroScrap( );
-#endif
-        TEToScrap() ;
-        //  MacInvalidateControl() ;
-    }
+          ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            TECut( teH ) ;
+        ClearCurrentScrap();
+            TEToScrap() ;
+            //  MacInvalidateControl() ;
+      }
 }
 
 void wxTextCtrl::Paste()
@@ -264,43 +225,10 @@ void wxTextCtrl::Paste()
         TEHandle teH ;
         long size ;
    
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEFromScrap() ;
         TEPaste( teH ) ;
-        WindowRef window = GetMacRootWindow() ;
-        if ( window )
-        {
-            wxWindow* win = wxFindWinFromMacWindow( window ) ;
-            if ( win )
-            {
-                wxMacDrawingHelper help( win ) ;
-                // the mac control manager always assumes to have the origin at 0,0
-                SetOrigin( 0 , 0 ) ;
-                
-                bool            hasTabBehind = false ;
-                wxWindow* parent = GetParent() ;
-                while ( parent )
-                {
-                    if( parent->MacGetWindowData() )
-                    {
-                        ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
-                        break ;
-                    }
-                    
-                    if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ||  parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
-                    {
-                        if ( ((wxControl*)parent)->GetMacControl() )
-                            SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ;
-                        break ;
-                    }
-                    
-                    parent = parent->GetParent() ;
-                } 
-                
-                UMADrawControl( m_macControl ) ;
-                ::SetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
-            }
-        }
+        MacRedrawControl() ;
     }
 }
 
@@ -325,7 +253,6 @@ bool wxTextCtrl::CanPaste() const
     if (!IsEditable())
         return FALSE;
 
-    long offset ;
 #if TARGET_CARBON
     OSStatus err = noErr;
     ScrapRef scrapRef;
@@ -347,6 +274,7 @@ bool wxTextCtrl::CanPaste() const
     return FALSE;
     
 #else
+    long offset ;
     if ( GetScrap( NULL , 'TEXT' , &offset ) > 0 )
     {
         return TRUE ;
@@ -358,9 +286,9 @@ bool wxTextCtrl::CanPaste() const
 void wxTextCtrl::SetEditable(bool editable)
 {
     if ( editable )
-        UMAActivateControl( m_macControl ) ;
+        UMAActivateControl( (ControlHandle) m_macControl ) ;
     else
-        UMADeactivateControl( m_macControl ) ;
+        UMADeactivateControl( (ControlHandle) m_macControl ) ;
 }
 
 void wxTextCtrl::SetInsertionPoint(long pos)
@@ -376,24 +304,24 @@ void wxTextCtrl::SetInsertionPointEnd()
 
 long wxTextCtrl::GetInsertionPoint() const
 {
-   ControlEditTextSelectionRec selection ;
+    //   ControlEditTextSelectionRec selection ;
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).selStart ;
 }
 
 long wxTextCtrl::GetLastPosition() const
 {
-   ControlEditTextSelectionRec selection ;
+    //   ControlEditTextSelectionRec selection ;
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).teLength ;
 }
 
@@ -406,8 +334,8 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TESetSelect( from , to  , teH ) ;
     TEDelete( teH ) ;
         TEInsert( value , value.Length() , teH ) ;
@@ -423,8 +351,8 @@ void wxTextCtrl::Remove(long from, long to)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TEDelete( teH ) ;
     Refresh() ;
 }
@@ -435,12 +363,12 @@ void wxTextCtrl::SetSelection(long from, long to)
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
    selection.selStart = from ;
    selection.selEnd = to ;
    
-   ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+   ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
    TESetSelect( selection.selStart , selection.selEnd , teH ) ;
 }
 
@@ -463,10 +391,10 @@ void wxTextCtrl::WriteText(const wxString& text)
     wxBuffer[text.Length() ] = 0 ;
 //    wxMacConvertNewlines( wxBuffer , wxBuffer ) ;
    
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-        TEInsert( wxBuffer , strlen( wxBuffer) , teH ) ;
-        Refresh() ;
+    TEInsert( wxBuffer , strlen( wxBuffer) , teH ) ;
+    Refresh() ;
 }
 
 void wxTextCtrl::AppendText(const wxString& text)
@@ -477,7 +405,7 @@ void wxTextCtrl::AppendText(const wxString& text)
 
 void wxTextCtrl::Clear()
 {
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
     Refresh() ;
 }
 
@@ -562,7 +490,7 @@ void wxTextCtrl::DiscardEdits()
 int wxTextCtrl::GetNumberOfLines() const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     int count = 1;
     for (int i = 0; i < actualsize; i++)
@@ -592,7 +520,7 @@ void wxTextCtrl::ShowPosition(long pos)
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     // Find line first
     int count = 0;
@@ -619,7 +547,7 @@ int wxTextCtrl::GetLineLength(long lineNo) const
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
     Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+    ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
     
     // Find line first
     int count = 0;
@@ -683,15 +611,12 @@ void wxTextCtrl::OnChar(wxKeyEvent& key_event)
             if ( !(m_windowStyle & wxTE_MULTILINE) )
             {
                 wxWindow *parent = GetParent();
-                wxPanel *panel = wxDynamicCast(parent, wxPanel);
-                while ( parent != NULL && panel == NULL )
-                {
-                    parent = parent->GetParent() ;
-                    panel = wxDynamicCast(parent, wxPanel);
+                while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
+                  parent = parent->GetParent() ;
                 }
-                if ( panel && panel->GetDefaultItem() )
+                if ( parent && parent->GetDefaultItem() )
                 {
-                    wxButton *def = wxDynamicCast(panel->GetDefaultItem(),
+                    wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
                                                           wxButton);
                     if ( def && def->IsEnabled() )
                     {
@@ -699,9 +624,9 @@ void wxTextCtrl::OnChar(wxKeyEvent& key_event)
                         event.SetEventObject(def);
                         def->Command(event);
                         return ;
-                   }                              
+                   }
                 }
-                
+               
                 // this will make wxWindows eat the ENTER key so that
                 // we actually prevent line wrapping in a single line
                 // text control
@@ -730,12 +655,12 @@ void wxTextCtrl::OnChar(wxKeyEvent& key_event)
             break;
     }
     
-    EventRecord *ev = wxTheApp->MacGetCurrentEvent();
+    EventRecord *ev = (EventRecord*) wxTheApp->MacGetCurrentEvent();
     short keychar = short(ev->message & charCodeMask);
     if (!eat_key)
     {
         short keycode = short(ev->message & keyCodeMask) >> 8 ;
-        ::HandleControlKey( m_macControl , keycode , keychar , ev->modifiers );
+        ::HandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers );
     }
     if ( keychar >= 0x20 ||
          key_event.KeyCode() == WXK_RETURN ||
@@ -805,19 +730,7 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
 
 #else
 
-#if !TARGET_CARBON
-#define GetControlOwner( control ) (**control).contrlOwner
-#endif
-
-//todo add access to global event record
-
-EventRecord event ;
-
-static EventRecord *GetCurrentEventRecord()
-{
-  return &event ;
-}
-
+extern wxApp *wxTheApp ;
 // CS:We will replace the TextEdit by using the MultiLanguageTextEngine based on the following code written by apple
 
 /*
@@ -1025,7 +938,7 @@ ControlUserPaneFocusUPP gTPFocusProc = NULL;
 
     /* events handled by our focus advance override routine */
 #if TARGET_CARBON
-static const EventTypeSpec gMLTEEvents[] = { { kEventClassTextInput, kEventUnicodeForKeyEvent } };
+static const EventTypeSpec gMLTEEvents[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } };
 #define kMLTEEventCount (sizeof( gMLTEEvents ) / sizeof( EventTypeSpec ))
 #endif
 
@@ -1372,7 +1285,7 @@ bail:
     should refer to a user pane control that you have either created
     yourself or extracted from a dialog's control heirarchy using
     the GetDialogItemAsControl routine.  */
-OSStatus mUPOpenControl(ControlHandle theControl) {
+OSStatus mUPOpenControl(ControlHandle theControl, bool multiline) {
     Rect bounds;
     WindowPtr theWindow;
     STPTextPaneVars **tpvars, *varsp;
@@ -1446,7 +1359,6 @@ OSStatus mUPOpenControl(ControlHandle theControl) {
     err = InstallWindowEventHandler( varsp->fOwner, varsp->handlerUPP,
         kMLTEEventCount, gMLTEEvents, tpvars, &varsp->handlerRef );
 #endif
-        
         /* unlock our storage */
     HUnlock((Handle) tpvars);
         /* perform final activations and setup for our text field.  Here,
@@ -1798,14 +1710,14 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
     }
 
 
-  if ( style & wxTE_PASSWORD )
-  {
-      m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
+    if ( style & wxTE_PASSWORD )
+    {
+      m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , true , 0 , 0 , 1, 
         kControlEditTextPasswordProc , (long) this ) ;
     }
     else
     {
-    if ( mUPCreateControl(parent->GetMacRootWindow(), &bounds, &m_macControl) != noErr ) 
+    if ( mUPCreateControl(parent->MacGetRootWindow(), &bounds, &m_macControl) != noErr ) 
       return FALSE ;
     }
     MacPostControlCreate() ;
@@ -1819,13 +1731,13 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
         
     if ( style & wxTE_PASSWORD )
     {
-      ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+      ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* set the text in the record */
     TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
       kTXNStartOffset, kTXNEndOffset);
@@ -1839,14 +1751,14 @@ wxString wxTextCtrl::GetValue() const
     Size actualsize;
   if ( m_windowStyle & wxTE_PASSWORD )
   {
-      ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+      ::GetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
     OSStatus err;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* extract the text from the record */
     Handle theText ;
     err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
@@ -1877,7 +1789,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
 
     *from = (**teH).selStart;
     *to = (**teH).selEnd;
@@ -1887,7 +1799,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
         STPTextPaneVars **tpvars;
 
             /* set up locals */
-        tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
 
         TXNGetSelection(  (**tpvars).fTXNRec , (TXNOffset*) from , (TXNOffset*) to ) ;
 
@@ -1904,51 +1816,18 @@ void wxTextCtrl::SetValue(const wxString& st)
         value = st ;
   if ( m_windowStyle & wxTE_PASSWORD )
   {
-      ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
+      ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+    tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
         /* set the text in the record */
     TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
       kTXNStartOffset, kTXNEndOffset);
   }
-    WindowRef window = GetMacRootWindow() ;
-    if ( window )
-    {
-        wxWindow* win = wxFindWinFromMacWindow( window ) ;
-        if ( win )
-        {
-            wxMacDrawingHelper help( win ) ;
-            // the mac control manager always assumes to have the origin at 0,0
-            SetOrigin( 0 , 0 ) ;
-            
-            bool            hasTabBehind = false ;
-            wxWindow* parent = GetParent() ;
-            while ( parent )
-            {
-                if( parent->MacGetWindowData() )
-                {
-                    UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
-                    break ;
-                }
-                
-                if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ||  parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
-                {
-                    if ( ((wxControl*)parent)->GetMacControl() )
-                        SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ;
-                    break ;
-                }
-                
-                parent = parent->GetParent() ;
-            } 
-            
-            UMADrawControl( m_macControl ) ;
-            UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
-        }
-    }
+  MacRedrawControl() ;
 }
 
 // Clipboard operations
@@ -1961,17 +1840,15 @@ void wxTextCtrl::Copy()
             TEHandle teH ;
             long size ;
        
-             ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+             ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
             TECopy( teH ) ;
-    #if TARGET_CARBON
-            OSStatus err ;
-            err = ClearCurrentScrap( );
-    #else
-            OSErr err ;
-            err = ZeroScrap( );
-    #endif
+            ClearCurrentScrap();
             TEToScrap() ;
         }
+        else
+        {
+          mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCopy ) ;
+        }
     }
 }
 
@@ -1984,18 +1861,16 @@ void wxTextCtrl::Cut()
             TEHandle teH ;
             long size ;
        
-            ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
             TECut( teH ) ;
-    #if TARGET_CARBON
-            OSStatus err ;
-            err = ClearCurrentScrap( );
-    #else
-            OSErr err ;
-            err = ZeroScrap( );
-    #endif
+            ClearCurrentScrap();
             TEToScrap() ;
             //  MacInvalidateControl() ;
     }
+        else
+        {
+          mUPDoEditCommand( (ControlHandle) m_macControl , kmUPCut ) ;
+        }
     }
 }
 
@@ -2008,43 +1883,14 @@ void wxTextCtrl::Paste()
             TEHandle teH ;
             long size ;
      
-            ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+            ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEFromScrap() ;
         TEPaste( teH ) ;
-        WindowRef window = GetMacRootWindow() ;
-        if ( window )
-        {
-            wxWindow* win = wxFindWinFromMacWindow( window ) ;
-            if ( win )
-            {
-                wxMacDrawingHelper help( win ) ;
-                // the mac control manager always assumes to have the origin at 0,0
-                SetOrigin( 0 , 0 ) ;
-                
-                bool            hasTabBehind = false ;
-                wxWindow* parent = GetParent() ;
-                while ( parent )
-                {
-                    if( parent->MacGetWindowData() )
-                    {
-                        UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , kThemeBrushDialogBackgroundActive , false ) ;
-                        break ;
-                    }
-                    
-                    if( parent->IsKindOf( CLASSINFO( wxNotebook ) ) ||  parent->IsKindOf( CLASSINFO( wxTabCtrl ) ))
-                    {
-                        if ( ((wxControl*)parent)->GetMacControl() )
-                            SetUpControlBackground( ((wxControl*)parent)->GetMacControl() , -1 , true ) ;
-                        break ;
-                    }
-                    
-                    parent = parent->GetParent() ;
-                } 
-                
-                UMADrawControl( m_macControl ) ;
-                UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ;
-            }
-        }
+      MacRedrawControl() ;
+    }
+    else
+    {
+      mUPDoEditCommand( (ControlHandle) m_macControl , kmUPPaste ) ;
     }
     }
 }
@@ -2103,9 +1949,9 @@ bool wxTextCtrl::CanPaste() const
 void wxTextCtrl::SetEditable(bool editable)
 {
     if ( editable )
-        UMAActivateControl( m_macControl ) ;
+        UMAActivateControl( (ControlHandle) m_macControl ) ;
     else
-        UMADeactivateControl( m_macControl ) ;
+        UMADeactivateControl( (ControlHandle) m_macControl ) ;
 }
 
 void wxTextCtrl::SetInsertionPoint(long pos)
@@ -2135,11 +1981,30 @@ long wxTextCtrl::GetLastPosition() const
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
-//   ::GetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
+//   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection , &size ) ;
     return (**teH).teLength ;
   }
+  else
+  {
+     STPTextPaneVars**  tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
+
+    int actualsize = 0 ;
+    Handle theText ;
+    OSErr err = TXNGetDataEncoded( (**tpvars).fTXNRec, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
+        /* all done */
+    if ( err )
+    {
+      actualsize = 0 ;
+    }
+    else
+    {
+      actualsize = GetHandleSize( theText ) ;
+      DisposeHandle( theText ) ;
+    }
+    return actualsize ;
+  }
 }
 
 void wxTextCtrl::Replace(long from, long to, const wxString& value)
@@ -2153,12 +2018,16 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-        ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+        ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TESetSelect( from , to  , teH ) ;
     TEDelete( teH ) ;
         TEInsert( value , value.Length() , teH ) ;
     }
+    else
+    {
+      // TODO
+    }
     Refresh() ;
 }
 
@@ -2173,9 +2042,13 @@ void wxTextCtrl::Remove(long from, long to)
    
     selection.selStart = from ;
     selection.selEnd = to ;
-    ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
-    ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+    ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+    ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
     TEDelete( teH ) ;
+  }
+  else
+  {
+    //TODO
   }
     Refresh() ;
 }
@@ -2188,19 +2061,19 @@ void wxTextCtrl::SetSelection(long from, long to)
    TEHandle teH ;
    long size ;
    
-   ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+   ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
    
    selection.selStart = from ;
    selection.selEnd = to ;
    
-   ::SetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
+   ::SetControlData( (ControlHandle) m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
    TESetSelect( selection.selStart , selection.selEnd , teH ) ;
   }
   else
   {
     STPTextPaneVars **tpvars;
         /* set up our locals */
-    tpvars = (STPTextPaneVars **) GetControlReference(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);
@@ -2231,14 +2104,14 @@ void wxTextCtrl::WriteText(const wxString& text)
       TEHandle teH ;
       long size ;
           
-      ::GetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+      ::GetControlData( (ControlHandle) m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
         TEInsert( value , value.Length() , teH ) ;
         }
         else
         {
         STPTextPaneVars **tpvars;
             /* set up locals */
-        tpvars = (STPTextPaneVars **) GetControlReference(m_macControl);
+        tpvars = (STPTextPaneVars **) GetControlReference( (ControlHandle) m_macControl);
             /* set the text in the record */
         TXNSetData( (**tpvars).fTXNRec, kTXNTextData,  (const char*)value, value.Length(),
           kTXNUseCurrentSelection, kTXNUseCurrentSelection);
@@ -2257,7 +2130,11 @@ void wxTextCtrl::Clear()
   if ( m_windowStyle & wxTE_PASSWORD )
   {
 
-    ::SetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+    ::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 0 , (char*) ((const char*)NULL) ) ;
+  }
+  else
+  {
+    mUPDoEditCommand( (ControlHandle) m_macControl , kmUPClear) ;
   }
     Refresh() ;
 }
@@ -2342,19 +2219,16 @@ void wxTextCtrl::DiscardEdits()
 
 int wxTextCtrl::GetNumberOfLines() const
 {
-  if ( m_windowStyle & wxTE_PASSWORD )
-  {
-    Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+  // TODO change this if possible to reflect real lines
+  wxString content = GetValue() ;
     
     int count = 1;
-    for (int i = 0; i < actualsize; i++)
+    for (int i = 0; i < content.Length() ; i++)
     {
-        if (wxBuffer[i] == '\r') count++;
+        if (content[i] == '\r') count++;
     }
     
-    return count;
-  }
+  return count;
 }
 
 long wxTextCtrl::XYToPosition(long x, long y) const
@@ -2375,61 +2249,55 @@ void wxTextCtrl::ShowPosition(long pos)
 
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
-  if ( m_windowStyle & wxTE_PASSWORD )
-  {
-    Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+  // TODO change this if possible to reflect real lines
+  wxString content = GetValue() ;
     
     // Find line first
     int count = 0;
-    for (int i = 0; i < actualsize; i++)
+    for (int i = 0; i < content.Length() ; i++)
     {
         if (count == lineNo)
         {
             // Count chars in line then
             count = 0;
-            for (int j = i; j < actualsize; j++)
+            for (int j = i; j < content.Length(); j++)
             {
                 count++;
-                if (wxBuffer[j] == '\r') return count;
+                if (content[j] == '\r') return count;
             }
             
             return count;
         }
-        if (wxBuffer[i] == '\r') count++;
-    }
+        if (content[i] == '\r') count++;
     }
     return 0;
 }
 
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
-  if ( m_windowStyle & wxTE_PASSWORD )
-  {
-    Size actualsize;
-    ::GetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
-    
+  // TODO change this if possible to reflect real lines
+  wxString content = GetValue() ;
+
     // Find line first
     int count = 0;
-    for (int i = 0; i < actualsize; i++)
+    for (int i = 0; i < content.Length() ; i++)
     {
         if (count == lineNo)
         {
             // Add chars in line then
             wxString tmp("");
             
-            for (int j = i; j < actualsize; j++)
+            for (int j = i; j < content.Length(); j++)
             {
-                if (wxBuffer[j] == '\r')
+                if (content[j] == '\r')
                     return tmp;
                     
-                tmp += wxBuffer[j];
+                tmp += content[j];
             }
             
             return tmp;
         }
-        if (wxBuffer[i] == '\r') count++;
-    }
+        if (content[i] == '\r') count++;
     }
     return wxString("");
 }
@@ -2468,15 +2336,12 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
             if ( !(m_windowStyle & wxTE_MULTILINE) )
             {
                 wxWindow *parent = GetParent();
-                wxPanel *panel = wxDynamicCast(parent, wxPanel);
-                while ( parent != NULL && panel == NULL )
-                {
-                    parent = parent->GetParent() ;
-                    panel = wxDynamicCast(parent, wxPanel);
+                while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) {
+                  parent = parent->GetParent() ;
                 }
-                if ( panel && panel->GetDefaultItem() )
+                if ( parent && parent->GetDefaultItem() )
                 {
-                    wxButton *def = wxDynamicCast(panel->GetDefaultItem(),
+                    wxButton *def = wxDynamicCast(parent->GetDefaultItem(),
                                                           wxButton);
                     if ( def && def->IsEnabled() )
                     {
@@ -2515,7 +2380,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
     short keychar ;
     keychar = short(ev->message & charCodeMask);
     keycode = short(ev->message & keyCodeMask) >> 8 ;
-    UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
+    UMAHandleControlKey( (ControlHandle) m_macControl , keycode , keychar , ev->modifiers ) ;
     if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN || event.KeyCode() == WXK_DELETE || event.KeyCode() == WXK_BACK)
     {
         wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);