#define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL
#if TARGET_API_MAC_OSX
- #define wxMAC_USE_MLTE 1
+ #define wxMAC_USE_MLTE 0
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
#define wxMAC_USE_MLTE_HIVIEW 1
#else
wxTextCtrl::~wxTextCtrl()
{
#if wxMAC_USE_MLTE
- SetControlReference((ControlRef)m_macControl, 0) ;
+ SetControlReference(*m_peer, 0) ;
#if !wxMAC_USE_MLTE_HIVIEW
TXNDeleteObject((TXNObject)m_macTXN);
#endif
if ( scrollView )
{
HIViewAddSubview( scrollView , textView ) ;
- m_macControl = (WXWidget) scrollView ;
+ m_peer = scrollView ;
}
else
{
- m_macControl = (WXWidget) textView ;
+ m_peer = textView ;
}
#else
short featurSet;
| kControlWantsActivate | kControlHandlesTracking | kControlHasSpecialBackground
| kControlGetsFocusOnClick | kControlSupportsLiveFeedback;
/* create the control */
- m_macControl = (WXWidget) ::NewControl(MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, "\p", true , featurSet, 0, featurSet, kControlUserPaneProc, (long) this );
- /* set up the mUP specific features and data */
+ m_peer = new wxMacControl() ;
+ verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, *m_peer ) );
+
wxMacWindowClipper c(this) ;
STPTextPaneVars *varsp ;
- mUPOpenControl( varsp, (ControlRef) m_macControl, m_windowStyle );
+ mUPOpenControl( varsp, *m_peer, m_windowStyle );
m_macTXNvars = varsp ;
m_macTXN = varsp->fTXNRec ;
#endif
{
wxMacWindowClipper clipper( this ) ;
#if !wxMAC_USE_MLTE_HIVIEW
- TPUpdateVisibility( (ControlRef) m_macControl ) ;
+ TPUpdateVisibility( *m_peer ) ;
#endif
SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNStartOffset, kTXNEndOffset ) ;
tback.bg.color = MAC_WXCOLORREF( GetBackgroundColour().GetPixel() );
TXNSetBackground( (TXNObject) m_macTXN , &tback);
- if ( m_windowStyle & wxTE_READONLY)
- {
- SetEditable( false ) ;
- }
#else
wxMacCFStringHolder cf(st , m_font.GetEncoding()) ;
- CreateEditUnicodeTextControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , cf , style & wxTE_PASSWORD , NULL , (ControlRef*) &m_macControl ) ;
+ CFStringRef cfr = cf ;
+ Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ;
+ m_peer = new wxMacControl() ;
+ CreateEditUnicodeTextControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds , cfr , isPassword , NULL , *m_peer ) ;
+
+ if ( !(m_windowStyle & wxTE_MULTILINE) )
+ {
+ Boolean singleline = true ;
+ ::SetControlData( *m_peer, kControlEditTextPart , kControlEditTextSingleLineTag , sizeof( singleline ) , &singleline ) ;
+ }
MacPostControlCreate(pos,size) ;
+
#endif
+ if ( m_windowStyle & wxTE_READONLY)
+ {
+ SetEditable( false ) ;
+ }
return TRUE;
void wxTextCtrl::MacVisibilityChanged()
{
-#if wxMAC_USE_MLTE && !wxMAC_USE_MLTE_HIVIEW
+#if wxMAC_USE_MLTE
+#if !wxMAC_USE_MLTE_HIVIEW
MLTESetObjectVisibility((STPTextPaneVars*) m_macTXNvars , MacIsReallyShown() , GetWindowStyle() ) ;
if ( !MacIsReallyShown() )
- InvalWindowRect( GetControlOwner( (ControlHandle) m_macControl ) , &((STPTextPaneVars *)m_macTXNvars)->fRBounds ) ;
+ InvalWindowRect( GetControlOwner( *m_peer ) , &((STPTextPaneVars *)m_macTXNvars)->fRBounds ) ;
+#endif
+#else
+ if ( !(m_windowStyle & wxTE_MULTILINE) && MacIsReallyShown() )
+ {
+ // work around a refresh issue insofar as not always the entire content is shown even if this would be possible
+ ControlEditTextSelectionRec sel ;
+ CFStringRef value = NULL ;
+ Size actualSize = 0 ;
+ ResType datatag = GetWindowStyle() & wxTE_PASSWORD ?
+ kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ;
+
+ verify_noerr( GetControlData( *m_peer , 0, kControlEditTextSelectionTag,
+ sizeof(ControlEditTextSelectionRec), &sel, &actualSize ) );
+ verify_noerr( GetControlData( *m_peer , 0, datatag , sizeof(CFStringRef), &value, &actualSize ) );
+
+ verify_noerr( SetControlData( *m_peer , 0, datatag, sizeof(CFStringRef), &value ) );
+ verify_noerr( SetControlData( *m_peer , 0, kControlEditTextSelectionTag, sizeof(ControlEditTextSelectionRec), &sel ) );
+
+ CFRelease( value ) ;
+ }
#endif
}
CFStringRef value = NULL ;
Size actualSize = 0 ;
- verify_noerr( GetControlData( (ControlRef) m_macControl , 0, GetWindowStyle() & wxTE_PASSWORD ?
+ verify_noerr( GetControlData( *m_peer , 0, GetWindowStyle() & wxTE_PASSWORD ?
kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag,
sizeof(CFStringRef), &value, &actualSize ) );
if ( value )
#else
ControlEditTextSelectionRec sel ;
Size actualSize ;
- verify_noerr( GetControlData( (ControlRef) m_macControl , 0, kControlEditTextSelectionTag,
+ verify_noerr( GetControlData( *m_peer , 0, kControlEditTextSelectionTag,
sizeof(ControlEditTextSelectionRec), &sel, &actualSize ) );
if ( from ) *from = sel.selStart ;
if ( to ) *to = sel.selEnd ;
#else
wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ;
CFStringRef value = cf ;
- verify_noerr( SetControlData( (ControlRef) m_macControl , 0, GetWindowStyle() & wxTE_PASSWORD ?
+ verify_noerr( SetControlData( *m_peer , 0, GetWindowStyle() & wxTE_PASSWORD ?
kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag,
sizeof(CFStringRef), &value ) );
#endif
ClearCurrentScrap();
TXNCopy((TXNObject)m_macTXN);
TXNConvertToPublicScrap();
+#else
+ m_peer->SendHICommand( kHICommandCopy ) ;
#endif
}
}
ClearCurrentScrap();
TXNCut((TXNObject)m_macTXN);
TXNConvertToPublicScrap();
+#else
+ m_peer->SendHICommand( kHICommandCut ) ;
#endif
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
event.SetString( GetValue() ) ;
TXNConvertFromPublicScrap();
TXNPaste((TXNObject)m_macTXN);
SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ;
+#else
+ m_peer->SendHICommand( kHICommandPaste ) ;
#endif
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
event.SetString( GetValue() ) ;
TXNControlTag tag[] = { kTXNIOPrivilegesTag } ;
TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ;
TXNSetTXNObjectControls( (TXNObject) m_macTXN , false , sizeof(tag) / sizeof (TXNControlTag) , tag , data ) ;
+#else
+ Boolean value = !editable ;
+ ::SetControlData( *m_peer, 0, kControlEditTextLockedTag , sizeof( value ) , &value ) ;
#endif
}
}
long wxTextCtrl::GetLastPosition() const
{
- Handle theText ;
long actualsize = 0 ;
#if wxMAC_USE_MLTE
+ Handle theText ;
OSErr err = TXNGetDataEncoded( (TXNObject) m_macTXN, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
/* all done */
if ( err )
ControlEditTextSelectionRec sel ;
sel.selStart = from ;
sel.selEnd = to ;
- verify_noerr( SetControlData( (ControlRef) m_macControl , 0, kControlEditTextSelectionTag,
+ verify_noerr( SetControlData( *m_peer , 0, kControlEditTextSelectionTag,
sizeof(ControlEditTextSelectionRec), &sel ) );
#endif
return FALSE;
}
+class wxMacFunctor
+{
+public :
+ wxMacFunctor(){}
+ virtual ~wxMacFunctor() {}
+ virtual void* operator()() = 0 ;
+ static void* CallBackProc(void *param)
+ {
+ wxMacFunctor* f = (wxMacFunctor*) param ;
+ void *result = (*f)() ;
+ return result ;
+ }
+} ;
+
+template<typename classtype,typename param1type>
+class wxMacObjectFunctor1 : public wxMacFunctor
+{
+ typedef void (classtype::*function)( param1type p1 ) ;
+ typedef void (classtype::*ref_function)( const param1type& p1 ) ;
+public :
+ wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) :
+ wxMacFunctor( )
+ {
+ m_object = obj ;
+ m_function = f ;
+ m_param1 = p1 ;
+ }
+
+ wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) :
+ wxMacFunctor( )
+ {
+ m_object = obj ;
+ m_refFunction = f ;
+ m_param1 = p1 ;
+ }
+
+ ~wxMacObjectFunctor1() {}
+
+ virtual void* operator()()
+ {
+ (m_object->*m_function)(m_param1) ;
+ return NULL ;
+ }
+private :
+ classtype* m_object ;
+ param1type m_param1 ;
+ union
+ {
+ function m_function ;
+ ref_function m_refFunction ;
+ } ;
+} ;
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 )
+{
+ wxMacObjectFunctor1<classtype,param1type> params(object,function,p1) ;
+ void *result =
+ MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ;
+ return result ;
+}
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 )
+{
+ wxMacObjectFunctor1<classtype,param1type> params(object,function,p1) ;
+ void *result =
+ MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ;
+ return result ;
+}
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 )
+{
+ wxMutexGuiLeave() ;
+ void *result = wxMacMPRemoteCall( object , function , p1 ) ;
+ wxMutexGuiEnter() ;
+ return result ;
+}
+
+template<typename classtype, typename param1type>
+void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 )
+{
+ wxMutexGuiLeave() ;
+ void *result = wxMacMPRemoteCall( object , function , p1 ) ;
+ wxMutexGuiEnter() ;
+ return result ;
+}
+
void wxTextCtrl::WriteText(const wxString& str)
{
- wxString st = str ;
- wxMacConvertNewlines13To10( &st ) ;
-#if wxMAC_USE_MLTE
- bool formerEditable = m_editable ;
- if ( !formerEditable )
- SetEditable(true) ;
+ if ( !wxIsMainThread() )
{
- wxMacWindowStateSaver( this ) ;
- long start , end , dummy ;
- GetSelection( &start , &dummy ) ;
- SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
- GetSelection( &dummy , &end ) ;
- SetStyle( start , end , GetDefaultStyle() ) ;
+ // unfortunately CW 8 is not able to correctly deduce the template types, so we have
+ // to instantiate explicitely
+ wxMacMPRemoteGUICall<wxTextCtrl,wxString>( this , &wxTextCtrl::WriteText , str ) ;
+ return ;
}
- if ( !formerEditable )
- SetEditable( formerEditable ) ;
+ else
+ {
+ wxString st = str ;
+ wxMacConvertNewlines13To10( &st ) ;
+ #if wxMAC_USE_MLTE
+ bool formerEditable = m_editable ;
+ if ( !formerEditable )
+ SetEditable(true) ;
+ {
+ wxMacWindowStateSaver s( this ) ;
+ long start , end , dummy ;
+ GetSelection( &start , &dummy ) ;
+ SetTXNData( (STPTextPaneVars *)m_macTXNvars , (TXNObject) m_macTXN , st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
+ GetSelection( &dummy , &end ) ;
+ SetStyle( start , end , GetDefaultStyle() ) ;
+ }
+ if ( !formerEditable )
+ SetEditable( formerEditable ) ;
- MacRedrawControl() ;
-#else
- wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ;
- CFStringRef value = cf ;
- SetControlData( (ControlRef) m_macControl , 0, kControlEditTextInsertCFStringRefTag,
- sizeof(CFStringRef), &value );
-#endif
+ MacRedrawControl() ;
+ #else
+ #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
+ wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ;
+ CFStringRef value = cf ;
+ SetControlData( *m_peer , 0, kControlEditTextInsertCFStringRefTag,
+ sizeof(CFStringRef), &value );
+ #else
+ wxString val = GetValue() ;
+ long start , end ;
+ GetSelection( &start , &end ) ;
+ val.Remove( start , end - start ) ;
+ val.insert( start , str ) ;
+ SetValue( val ) ;
+ SetInsertionPoint( start + str.Length() ) ;
+ #endif
+ #endif
+ }
}
void wxTextCtrl::AppendText(const wxString& text)
break ;
}
+#if !wxMAC_USE_MLTE
+ // unicode text control is using client size, ie 3 pixels on every side
+ // TODO make this fit into normal window size concept, probably having
+ // to reintroduce the margin vars
+ hText -= 6 ;
+#endif
+
if ( m_windowStyle & wxTE_MULTILINE )
{
hText *= 5 ;
ItemCount lines = 0 ;
#if wxMAC_USE_MLTE
TXNGetLineCount((TXNObject)m_macTXN, &lines ) ;
+#else
+ wxString content = GetValue() ;
+ lines = 1;
+ for (size_t i = 0; i < content.Length() ; i++)
+ {
+ if (content[i] == '\r') lines++;
+ }
#endif
return lines ;
}
int lastHeight = 0 ;
ItemCount n ;
- for ( n = 0 ; n <= lastpos ; ++n )
+ for ( n = 0 ; n <= (ItemCount) lastpos ; ++n )
{
if ( y == ypos && x == xpos )
return n ;
int lastHeight = 0 ;
ItemCount n ;
- for ( n = 0 ; n <= pos ; ++n )
+ for ( n = 0 ; n <= (ItemCount) pos ; ++n )
{
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
long lastpos = GetLastPosition() ;
ItemCount n ;
- for ( n = 0 ; n <= lastpos ; ++n )
+ for ( n = 0 ; n <= (ItemCount) lastpos ; ++n )
{
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
++xpos ;
}
}
+#else
+ // TODO change this if possible to reflect real lines
+ wxString content = GetValue() ;
+
+ // Find line first
+ int count = 0;
+ for (size_t i = 0; i < content.Length() ; i++)
+ {
+ if (count == lineNo)
+ {
+ // Count chars in line then
+ count = 0;
+ for (size_t j = i; j < content.Length(); j++)
+ {
+ count++;
+ if (content[j] == '\n') return count;
+ }
+
+ return count;
+ }
+ if (content[i] == '\n') count++;
+ }
#endif
return 0;
}
wxString wxTextCtrl::GetLineText(long lineNo) const
{
- Point curpt ;
- wxString line ;
#if wxMAC_USE_MLTE
+ wxString line ;
+ Point curpt ;
wxString content = GetValue() ;
if ( lineNo < GetNumberOfLines() )
long lastpos = GetLastPosition() ;
ItemCount n ;
- for ( n = 0 ; n <= lastpos ; ++n )
+ for ( n = 0 ; n <= (ItemCount)lastpos ; ++n )
{
TXNOffsetToPoint( (TXNObject) m_macTXN, n , &curpt);
}
}
}
-#endif
return line ;
+#else
+ // TODO change this if possible to reflect real lines
+ wxString content = GetValue() ;
+
+ // Find line first
+ int count = 0;
+ for (size_t i = 0; i < content.Length() ; i++)
+ {
+ if (count == lineNo)
+ {
+ // Add chars in line then
+ wxString tmp;
+
+ for (size_t j = i; j < content.Length(); j++)
+ {
+ if (content[j] == '\n')
+ return tmp;
+
+ tmp += content[j];
+ }
+
+ return tmp;
+ }
+ if (content[i] == '\n') count++;
+ }
+ return wxEmptyString ;
+#endif
}
/*
}
}
- // this will make wxWindows eat the ENTER key so that
+ // this will make wxWidgets eat the ENTER key so that
// we actually prevent line wrapping in a single line
// text control
eat_key = TRUE;
break;
case WXK_TAB:
- // always produce navigation event - even if we process TAB
- // ourselves the fact that we got here means that the user code
- // decided to skip processing of this TAB - probably to let it
- // do its default job.
+ if ( !(m_windowStyle & wxTE_PROCESS_TAB))
{
- wxNavigationKeyEvent eventNav;
- eventNav.SetDirection(!event.ShiftDown());
- eventNav.SetWindowChange(event.ControlDown());
- eventNav.SetEventObject(this);
-
- if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav) )
- return;
-
- event.Skip() ;
+ int flags = 0;
+ if (!event.ShiftDown())
+ flags |= wxNavigationKeyEvent::IsForward ;
+ if (event.ControlDown())
+ flags |= wxNavigationKeyEvent::WinChange ;
+ Navigate(flags);
return;
}
+ else
+ {
+ // This is necessary (don't know why) or the tab will not
+ // be inserted.
+ WriteText(wxT("\t"));
+ }
+
break;
}
keychar = short(ev->message & charCodeMask);
keycode = short(ev->message & keyCodeMask) >> 8 ;
- ::HandleControlKey( (ControlRef) m_macControl , keycode , keychar , ev->modifiers ) ;
+ ::HandleControlKey( *m_peer , keycode , keychar , ev->modifiers ) ;
}
}
}