X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/90b22acaa8a8673e9a6749aa5e5322d2c8913a85..bf44306ebca5d26e204ef17851516d844bc2f0a7:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 7e1450068d..c6a6d86e09 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -13,7 +13,11 @@ #pragma implementation "textctrl.h" #endif -#ifdef __UNIX__ +#include "wx/defs.h" + +#if wxUSE_TEXTCTRL + +#ifdef __DARWIN__ #include #include #else @@ -22,6 +26,7 @@ #include #include "wx/app.h" +#include "wx/dc.h" #include "wx/button.h" #include "wx/panel.h" #include "wx/textctrl.h" @@ -33,7 +38,7 @@ #if defined(__BORLANDC__) && !defined(__WIN32__) #include -#elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__WXMAC_X__) +#elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__) #include #endif @@ -106,6 +111,15 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, 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() ; @@ -193,7 +207,6 @@ void wxTextCtrl::SetValue(const wxString& st) UMADrawControl( m_macControl ) ; UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; - wxDC::MacInvalidateSetup() ; } } } @@ -282,7 +295,6 @@ void wxTextCtrl::Paste() UMADrawControl( m_macControl ) ; UMASetThemeWindowBackground( win->MacGetWindowData()->m_macWindow , win->MacGetWindowData()->m_macWindowBackgroundTheme , false ) ; - wxDC::MacInvalidateSetup() ; } } } @@ -395,7 +407,7 @@ void wxTextCtrl::Replace(long from, long to, const wxString& value) TESetSelect( from , to , teH ) ; TEDelete( teH ) ; TEInsert( value , value.Length() , teH ) ; -// MacInvalidateControl() ; + Refresh() ; } void wxTextCtrl::Remove(long from, long to) @@ -410,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 ) ; -// MacInvalidateControl() ; + Refresh() ; } void wxTextCtrl::SetSelection(long from, long to) @@ -545,8 +557,16 @@ void wxTextCtrl::DiscardEdits() 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 @@ -567,12 +587,59 @@ void wxTextCtrl::ShowPosition(long pos) 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 { - 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(""); } /* @@ -617,12 +684,15 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) } 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 @@ -654,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 ) ; - 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() ) ; @@ -718,3 +788,5 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) event.Enable( CanRedo() ); } +#endif + // wxUSE_TEXTCTRL