]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/textctrl.cpp
Updated to new PyCrust
[wxWidgets.git] / src / mac / carbon / textctrl.cpp
index af3919bb7bd4ca122df4e2cf3dbfcc9c3a4fd069..c6a6d86e092aec816ccd0c601333fc1677a232e1 100644 (file)
 #pragma implementation "textctrl.h"
 #endif
 
 #pragma implementation "textctrl.h"
 #endif
 
-#ifndef __WXMAC__
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "wx/defs.h"
+
+#if wxUSE_TEXTCTRL
+
+#ifdef __DARWIN__
+  #include <sys/types.h>
+  #include <sys/stat.h>
 #else
 #else
-#include <stat.h>
+  #include <stat.h>
 #endif
 #include <fstream.h>
 
 #endif
 #include <fstream.h>
 
+#include "wx/app.h"
+#include "wx/dc.h"
+#include "wx/button.h"
+#include "wx/panel.h"
 #include "wx/textctrl.h"
 #include "wx/textctrl.h"
+#include "wx/notebook.h"
+#include "wx/tabctrl.h"
 #include "wx/settings.h"
 #include "wx/filefn.h"
 #include "wx/utils.h"
 
 #if defined(__BORLANDC__) && !defined(__WIN32__)
 #include "wx/settings.h"
 #include "wx/filefn.h"
 #include "wx/utils.h"
 
 #if defined(__BORLANDC__) && !defined(__WIN32__)
-#include <alloc.h>
-#else
-#ifndef __MWERKS__
-#ifndef __GNUWIN32__
-#include <malloc.h>
-#endif
-#endif
+  #include <alloc.h>
+#elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__)
+  #include <malloc.h>
 #endif
 
 #include "wx/mac/uma.h"
 #endif
 
 #include "wx/mac/uma.h"
@@ -105,12 +111,29 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
 
        MacPreControlCreate( parent , id ,  "" , pos , mySize ,style, validator , name , &bounds , title ) ;
 
 
        MacPreControlCreate( parent , id ,  "" , pos , mySize ,style, validator , name , &bounds , title ) ;
 
+    if ( m_windowStyle & wxTE_MULTILINE )
+    {
+        wxASSERT_MSG( !(m_windowStyle & wxTE_PROCESS_ENTER),
+                      wxT("wxTE_PROCESS_ENTER style is ignored for multiline text controls (they always process it)") );
+
+        m_windowStyle |= wxTE_PROCESS_ENTER;
+    }
+
+
        m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
                ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ;
        MacPostControlCreate() ;
 
        wxString value ;
        
        m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, 
                ( style & wxTE_PASSWORD ) ? kControlEditTextPasswordProc : kControlEditTextProc , (long) this ) ;
        MacPostControlCreate() ;
 
        wxString value ;
        
+       {
+               TEHandle teH ;
+               long size ;
+   
+               UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
+               (*teH)->lineHeight = -1 ;
+       }
+       
        if( wxApp::s_macDefaultEncodingIsPC )
                value = wxMacMakeMacStringFromPC( st ) ;
        else
        if( wxApp::s_macDefaultEncodingIsPC )
                value = wxMacMakeMacStringFromPC( st ) ;
        else
@@ -152,8 +175,40 @@ void wxTextCtrl::SetValue(const wxString& st)
        else
                value = st ;
        UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
        else
                value = st ;
        UMASetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , value.Length() , (char*) ((const char*)value) ) ;
-       Refresh() ;
-//     MacInvalidateControl() ;
+       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 ) ;
+               }
+       }
 }
 
 // Clipboard operations
 }
 
 // Clipboard operations
@@ -208,7 +263,40 @@ void wxTextCtrl::Paste()
                UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
                TEFromScrap() ;
                TEPaste( teH ) ;
                UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
                TEFromScrap() ;
                TEPaste( teH ) ;
-//     MacInvalidateControl() ;
+               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 ) ;
+                       }
+               }
        }
 }
 
        }
 }
 
@@ -319,7 +407,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value)
        TESetSelect( from , to  , teH ) ;
        TEDelete( teH ) ;
                TEInsert( value , value.Length() , teH ) ;
        TESetSelect( from , to  , teH ) ;
        TEDelete( teH ) ;
                TEInsert( value , value.Length() , teH ) ;
-//     MacInvalidateControl() ;
+       Refresh() ;
 }
 
 void wxTextCtrl::Remove(long from, long to)
 }
 
 void wxTextCtrl::Remove(long from, long to)
@@ -334,7 +422,7 @@ void wxTextCtrl::Remove(long from, long to)
        UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
        UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
        TEDelete( teH ) ;
        UMASetControlData( m_macControl , 0, kControlEditTextSelectionTag , sizeof( selection ) , (char*) &selection ) ;
        UMAGetControlData( m_macControl , 0, kControlEditTextTEHandleTag , sizeof( TEHandle ) , (char*) &teH , &size ) ;
        TEDelete( teH ) ;
-//     MacInvalidateControl() ;
+       Refresh() ;
 }
 
 void wxTextCtrl::SetSelection(long from, long to)
 }
 
 void wxTextCtrl::SetSelection(long from, long to)
@@ -469,8 +557,16 @@ void wxTextCtrl::DiscardEdits()
 
 int wxTextCtrl::GetNumberOfLines() const
 {
 
 int wxTextCtrl::GetNumberOfLines() const
 {
-    // TODO
-    return 0;
+       Size actualsize;
+       UMAGetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+       
+       int count = 1;
+       for (int i = 0; i < actualsize; i++)
+       {
+           if (wxBuffer[i] == '\r') count++;
+       }
+       
+    return count;
 }
 
 long wxTextCtrl::XYToPosition(long x, long y) const
 }
 
 long wxTextCtrl::XYToPosition(long x, long y) const
@@ -491,12 +587,59 @@ void wxTextCtrl::ShowPosition(long pos)
 
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
 
 int wxTextCtrl::GetLineLength(long lineNo) const
 {
-    return GetValue().Length();
+       Size actualsize;
+       UMAGetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+       
+       // Find line first
+       int count = 0;
+       for (int i = 0; i < actualsize; i++)
+       {
+           if (count == lineNo)
+           {
+               // Count chars in line then
+               count = 0;
+               for (int j = i; j < actualsize; j++)
+               {
+                   count++;
+                   if (wxBuffer[j] == '\r') return count;
+               }
+               
+               return count;
+           }
+           if (wxBuffer[i] == '\r') count++;
+       }
+       
+    return 0;
 }
 
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
 }
 
 wxString wxTextCtrl::GetLineText(long lineNo) const
 {
-    return GetValue();
+       Size actualsize;
+       UMAGetControlData( m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , 32767 , wxBuffer , &actualsize) ;
+       
+       // Find line first
+       int count = 0;
+       for (int i = 0; i < actualsize; i++)
+       {
+           if (count == lineNo)
+           {
+               // Add chars in line then
+               wxString tmp("");
+               
+               for (int j = i; j < actualsize; j++)
+               {
+                   if (wxBuffer[j] == '\r')
+                       return tmp;
+                       
+                   tmp += wxBuffer[j];
+               }
+               
+               return tmp;
+           }
+           if (wxBuffer[i] == '\r') count++;
+       }
+       
+    return wxString("");
 }
 
 /*
 }
 
 /*
@@ -541,12 +684,15 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
                        }
                        if ( panel && panel->GetDefaultItem() )
                        {
                        }
                        if ( panel && panel->GetDefaultItem() )
                        {
-                               wxButton *def = panel->GetDefaultItem() ;
-                               wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
-                                       event.SetEventObject(def);
-                                       def->Command(event);
-                               event.Skip() ;
-                       return ;
+                    wxButton *def = wxDynamicCast(panel->GetDefaultItem(),
+                                                          wxButton);
+                               if ( def && def->IsEnabled() )
+                               {
+                                   wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
+                                           event.SetEventObject(def);
+                                           def->Command(event);
+                       return ;
+                   }
                        }
             }
             //else: multiline controls need Enter for themselves
                        }
             }
             //else: multiline controls need Enter for themselves
@@ -578,7 +724,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
        keychar = short(ev->message & charCodeMask);
        keycode = short(ev->message & keyCodeMask) >> 8 ;
        UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
        keychar = short(ev->message & charCodeMask);
        keycode = short(ev->message & keyCodeMask) >> 8 ;
        UMAHandleControlKey( m_macControl , keycode , keychar , ev->modifiers ) ;
-       if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN)
+       if ( keychar >= 0x20 || event.KeyCode() == WXK_RETURN || event.KeyCode() == WXK_DELETE || event.KeyCode() == WXK_BACK)
        {
         wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
         event.SetString( GetValue() ) ;
        {
         wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
         event.SetString( GetValue() ) ;
@@ -642,3 +788,5 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
     event.Enable( CanRedo() );
 }
 
     event.Enable( CanRedo() );
 }
 
+#endif
+    // wxUSE_TEXTCTRL