X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4d7528a1dfd0f4ebd6b3a7075b3292ca14949e34..6eaa4426e06c03017b47beaf4235d9f079edf5fe:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 5b29292da4..4e40be1ffd 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -9,10 +9,6 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "textctrl.h" -#endif - #include "wx/wxprec.h" #if wxUSE_TEXTCTRL @@ -40,12 +36,12 @@ #include "wx/button.h" #include "wx/toplevel.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" #include "wx/sysopt.h" +#include "wx/menu.h" +#include "wx/intl.h" #if defined(__BORLANDC__) && !defined(__WIN32__) #include @@ -64,22 +60,24 @@ #endif #ifndef __WXMAC_OSX__ -enum +enum { kTXNVisibilityTag = 'visb' /*set the visibility state of the object */ }; #endif +#ifndef __DARWIN__ #include #include #include #include +#endif #include "wx/mac/uma.h" class wxMacFunctor { public : - wxMacFunctor(){} + wxMacFunctor() {} virtual ~wxMacFunctor() {} virtual void* operator()() = 0 ; static void* CallBackProc(void *param) @@ -119,6 +117,7 @@ public : (m_object->*m_function)(m_param1) ; return NULL ; } + private : classtype* m_object ; param1type m_param1 ; @@ -164,6 +163,7 @@ void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( con wxMutexGuiEnter() ; return result ; } + // common interface for all implementations class wxMacTextControl : public wxMacControl { @@ -180,11 +180,12 @@ public : virtual bool CanPaste() const ; virtual void SetEditable(bool editable) ; virtual wxTextPos GetLastPosition() const ; - virtual void Replace( long from , long to , const wxString str ) ; - virtual void Remove( long from , long to ) = 0 ; + virtual void Replace( long from , long to , const wxString &str ) ; + virtual void Remove( long from , long to ) ; virtual void SetSelection( long from , long to ) = 0 ; virtual void GetSelection( long* from, long* to) const = 0 ; virtual void WriteText(const wxString& str) = 0 ; + virtual bool HasOwnContextMenu() const { return false ; } virtual void Clear() ; virtual bool CanUndo() const; @@ -232,12 +233,25 @@ public : virtual bool CanPaste() const ; virtual void SetEditable(bool editable) ; virtual wxTextPos GetLastPosition() const ; - virtual void Replace( long from , long to , const wxString str ) ; + virtual void Replace( long from , long to , const wxString &str ) ; virtual void Remove( long from , long to ) ; virtual void GetSelection( long* from, long* to) const ; virtual void SetSelection( long from , long to ) ; virtual void WriteText(const wxString& str) ; + virtual bool HasOwnContextMenu() const + { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + if ( UMAGetSystemVersion() >= 0x1040 ) + { + TXNCommandEventSupportOptions options ; + TXNGetCommandEventSupport( m_txn , & options ) ; + return options & kTXNSupportEditCommandProcessing ; + } +#endif + return false ; + } + virtual void Clear() ; virtual bool CanUndo() const ; @@ -273,6 +287,8 @@ public : const wxSize& size, long style ) ; virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; virtual bool HasFocus() const ; + virtual void SetBackground( const wxBrush &brush) ; + protected : HIViewRef m_scrollView ; HIViewRef m_textView ; @@ -296,10 +312,10 @@ public : virtual void Paste(); virtual bool CanPaste() const; virtual void SetEditable(bool editable) ; - virtual void Remove( long from , long to ) ; virtual void GetSelection( long* from, long* to) const ; virtual void SetSelection( long from , long to ) ; virtual void WriteText(const wxString& str) ; + protected : // contains the tag for the content (is different for password and non-password controls) OSType m_valueTag ; @@ -335,12 +351,13 @@ public : protected : OSStatus DoCreate(); - + void MacUpdatePosition() ; void MacActivatePaneText(Boolean setActive) ; void MacFocusPaneText(Boolean setFocus) ; void MacSetObjectVisibility(Boolean vis) ; + private : TXNFrameID m_txnFrameID ; GrafPtr m_txnPort ; @@ -349,7 +366,7 @@ private : Rect m_txnControlBounds ; Rect m_txnVisBounds ; #ifdef __WXMAC_OSX__ - static pascal void TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, + static pascal void TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon) ; static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ; ControlRef m_sbHorizontal ; @@ -361,7 +378,6 @@ private : #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) @@ -373,29 +389,36 @@ BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) + EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) + EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) + + EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) + EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) + EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) END_EVENT_TABLE() -#endif // Text item void wxTextCtrl::Init() { - m_editable = true ; - m_dirty = false; + m_editable = true ; + m_dirty = false; + + m_privateContextMenu = NULL; - m_maxLength = TE_UNLIMITED_LENGTH ; + m_maxLength = TE_UNLIMITED_LENGTH ; } wxTextCtrl::~wxTextCtrl() { + delete m_privateContextMenu; } - bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, const wxString& str, const wxPoint& pos, @@ -455,16 +478,14 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, MacSuperChangedPosition() ; if ( m_windowStyle & wxTE_READONLY) - { SetEditable( false ) ; - } - + SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; return true; } -void wxTextCtrl::MacSuperChangedPosition() +void wxTextCtrl::MacSuperChangedPosition() { wxWindow::MacSuperChangedPosition() ; GetPeer()->SuperChangedPosition() ; @@ -534,9 +555,7 @@ bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) void wxTextCtrl::Copy() { if (CanCopy()) - { GetPeer()->Copy() ; - } } void wxTextCtrl::Cut() @@ -575,9 +594,8 @@ bool wxTextCtrl::CanCopy() const bool wxTextCtrl::CanCut() const { if ( !IsEditable() ) - { return false ; - } + // Can cut if there's a selection long from, to; GetSelection(& from, & to); @@ -642,9 +660,7 @@ void wxTextCtrl::SetSelection(long from, long to) bool wxTextCtrl::LoadFile(const wxString& file) { if ( wxTextCtrlBase::LoadFile(file) ) - { return true; - } return false; } @@ -655,7 +671,7 @@ void wxTextCtrl::WriteText(const wxString& str) if ( !wxIsMainThread() ) { // unfortunately CW 8 is not able to correctly deduce the template types, so we have - // to instantiate explicitely + // to instantiate explicitly wxMacMPRemoteGUICall( this , &wxTextCtrl::WriteText , str ) ; return ; } @@ -698,20 +714,23 @@ wxSize wxTextCtrl::DoGetBestSize() const int hText; - // these are the numbers from the HIG, we reduce them by the borders - // first + // these are the numbers from the HIG: + // we reduce them by the borders first switch( m_windowVariant ) { case wxWINDOW_VARIANT_NORMAL : hText = 22 - 6 ; break ; + case wxWINDOW_VARIANT_SMALL : hText = 19 - 6 ; break ; + case wxWINDOW_VARIANT_MINI : hText= 15 - 6 ; break ; + default : hText = 22 - 6; break ; @@ -720,9 +739,7 @@ wxSize wxTextCtrl::DoGetBestSize() const // as the above numbers have some free space around the text // we get 5 lines like this anyway if ( m_windowStyle & wxTE_MULTILINE ) - { hText *= 5 ; - } if ( !HasFlag(wxNO_BORDER) ) hText += 6 ; @@ -737,34 +754,28 @@ wxSize wxTextCtrl::DoGetBestSize() const void wxTextCtrl::Undo() { if (CanUndo()) - { GetPeer()->Undo() ; - } } void wxTextCtrl::Redo() { if (CanRedo()) - { GetPeer()->Redo() ; - } } bool wxTextCtrl::CanUndo() const { if ( !IsEditable() ) - { return false ; - } + return GetPeer()->CanUndo() ; } bool wxTextCtrl::CanRedo() const { if ( !IsEditable() ) - { return false ; - } + return GetPeer()->CanRedo() ; } @@ -808,10 +819,6 @@ wxString wxTextCtrl::GetLineText(long lineNo) const return GetPeer()->GetLineText(lineNo) ; } -/* - * Text item - */ - void wxTextCtrl::Command(wxCommandEvent & event) { SetValue (event.GetString()); @@ -822,9 +829,7 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) { // By default, load the first file into the text window. if (event.GetNumberOfFiles() > 0) - { LoadFile(event.GetFiles()[0]); - } } void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) @@ -882,6 +887,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) Cut() ; return ; } + switch ( key ) { case WXK_RETURN: @@ -909,7 +915,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) event.SetEventObject(def); def->Command(event); return ; - } + } } // this will make wxWidgets eat the ENTER key so that @@ -917,7 +923,6 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // text control eat_key = true; } - break; case WXK_TAB: @@ -937,7 +942,9 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) // be inserted. WriteText(wxT("\t")); } + break; + default: break; } @@ -961,6 +968,7 @@ void wxTextCtrl::OnChar(wxKeyEvent& event) } } } + if ( ( key >= 0x20 && key < WXK_START ) || key == WXK_RETURN || key == WXK_DELETE || @@ -1001,6 +1009,19 @@ void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) Redo(); } +void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) +{ + long from, to; + GetSelection(& from, & to); + if (from != -1 && to != -1) + Remove(from, to); +} + +void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) +{ + SetSelection(-1, -1); +} + void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) { event.Enable( CanCut() ); @@ -1026,6 +1047,46 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) event.Enable( CanRedo() ); } +void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) +{ + long from, to; + GetSelection(& from, & to); + event.Enable(from != -1 && to != -1 && from != to && IsEditable()) ; +} + +void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) +{ + event.Enable(GetLastPosition() > 0); +} + +// CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment + +void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) +{ + if ( GetPeer()->HasOwnContextMenu() ) + { + event.Skip() ; + return ; + } + + if (m_privateContextMenu == NULL) + { + m_privateContextMenu = new wxMenu; + m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); + m_privateContextMenu->Append(wxID_REDO, _("&Redo")); + m_privateContextMenu->AppendSeparator(); + m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); + m_privateContextMenu->Append(wxID_COPY, _("&Copy")); + m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); + m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); + m_privateContextMenu->AppendSeparator(); + m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); + } + + if (m_privateContextMenu != NULL) + PopupMenu(m_privateContextMenu); +} + bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) { if ( !GetPeer()->SetupCursor(pt) ) @@ -1033,6 +1094,7 @@ bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) else return true ; } + #if !TARGET_API_MAC_OSX // user pane implementation @@ -1078,6 +1140,7 @@ void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) } #endif + // ---------------------------------------------------------------------------- // implementation base class // ---------------------------------------------------------------------------- @@ -1121,8 +1184,16 @@ wxTextPos wxMacTextControl::GetLastPosition() const return GetStringValue().Length() ; } -void wxMacTextControl::Replace( long from , long to , const wxString str ) +void wxMacTextControl::Replace( long from , long to , const wxString &val ) { + SetSelection( from , to ) ; + WriteText( val) ; +} + +void wxMacTextControl::Remove( long from , long to ) +{ + SetSelection( from , to ) ; + WriteText( wxEmptyString) ; } void wxMacTextControl::Clear() @@ -1135,7 +1206,9 @@ bool wxMacTextControl::CanUndo() const return false ; } -void wxMacTextControl::Undo() { } +void wxMacTextControl::Undo() +{ +} bool wxMacTextControl::CanRedo() const { @@ -1169,6 +1242,7 @@ int wxMacTextControl::GetNumberOfLines() const { if (content[i] == '\r') lines++; } + return lines ; } @@ -1196,12 +1270,14 @@ wxString wxMacTextControl::GetLineText(long lineNo) const return tmp; } + if (content[i] == '\n') count++; } + return wxEmptyString ; } -int wxMacTextControl::GetLineLength(long lineNo) const +int wxMacTextControl::GetLineLength(long lineNo) const { // TODO change this if possible to reflect real lines wxString content = GetStringValue() ; @@ -1217,13 +1293,16 @@ int wxMacTextControl::GetLineLength(long lineNo) const for (size_t j = i; j < content.Length(); j++) { count++; - if (content[j] == '\n') return count; + if (content[j] == '\n') + return count; } return count; } + if (content[i] == '\n') count++; } + return 0 ; } @@ -1250,9 +1329,7 @@ wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, CreateEditUnicodeTextControl( MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr , isPassword , NULL , &m_controlRef ) ; if ( !(m_windowStyle & wxTE_MULTILINE) ) - { SetData( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; - } } wxMacUnicodeTextControl::~wxMacUnicodeTextControl() @@ -1275,6 +1352,7 @@ void wxMacUnicodeTextControl::VisibilityChanged(bool shown) CFRelease( value ) ; } } + wxString wxMacUnicodeTextControl::GetStringValue() const { wxString result ; @@ -1284,13 +1362,16 @@ wxString wxMacUnicodeTextControl::GetStringValue() const wxMacCFStringHolder cf(value) ; result = cf.AsString() ; } + #if '\n' == 10 wxMacConvertNewlines13To10( &result ) ; #else wxMacConvertNewlines10To13( &result ) ; #endif + return result ; } + void wxMacUnicodeTextControl::SetStringValue( const wxString &str) { wxString st = str ; @@ -1298,29 +1379,31 @@ void wxMacUnicodeTextControl::SetStringValue( const wxString &str) wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; verify_noerr( SetData( 0, m_valueTag , cf ) ) ; } + void wxMacUnicodeTextControl::Copy() { SendHICommand( kHICommandCopy ) ; } + void wxMacUnicodeTextControl::Cut() { SendHICommand( kHICommandCut ) ; } + void wxMacUnicodeTextControl::Paste() { SendHICommand( kHICommandPaste ) ; } + bool wxMacUnicodeTextControl::CanPaste() const { return true ; } + void wxMacUnicodeTextControl::SetEditable(bool editable) { SetData( 0 , kControlEditTextLockedTag , (Boolean) !editable ) ; } -void wxMacUnicodeTextControl::Remove( long from , long to ) -{ -} void wxMacUnicodeTextControl::GetSelection( long* from, long* to) const { @@ -1333,6 +1416,12 @@ void wxMacUnicodeTextControl::GetSelection( long* from, long* to) const void wxMacUnicodeTextControl::SetSelection( long from , long to ) { ControlEditTextSelectionRec sel ; + if ((from == -1) && (to == -1)) + { + from = 0 ; + to = 32767 ; // sel has 16 bit signed values, max is 32767 + } + sel.selStart = from ; sel.selEnd = to ; SetData( 0 , kControlEditTextSelectionTag, &sel ) ; @@ -1363,7 +1452,7 @@ void wxMacUnicodeTextControl::WriteText(const wxString& str) // MLTE control implementation (common part) // ---------------------------------------------------------------------------- -// if mlte is on read only , no changes at all are allowed, not even from +// if MTLE is read only, no changes at all are allowed, not even from // procedural API, in order to allow changes via API all the same we must undo // the readonly status while we are executing, this class helps to do so @@ -1381,22 +1470,22 @@ public : TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ; } } + ~wxMacEditHelper() { TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; if ( m_data[0].uValue == kTXNReadOnly ) - { TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ; - } } + protected : TXNObject m_txn ; TXNControlData m_data[1] ; } ; -wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer ) +wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) : wxMacTextControl( peer ) { - SetNeedsFocusRect( true ) ; + SetNeedsFocusRect( true ) ; } wxString wxMacMLTEControl::GetStringValue() const @@ -1426,7 +1515,7 @@ wxString wxMacMLTEControl::GetStringValue() const SetHandleSize( theText , ( actualSize + 1 ) * sizeof( UniChar ) ) ; HLock( theText ) ; (((UniChar*)*theText)[actualSize]) = 0 ; - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; ptr = new wxChar[noChars + 1] ; @@ -1438,6 +1527,7 @@ wxString wxMacMLTEControl::GetStringValue() const result = wxString( ptr ) ; delete[] ptr ; } + DisposeHandle( theText ) ; } #else @@ -1457,15 +1547,18 @@ wxString wxMacMLTEControl::GetStringValue() const result = wxString( *theText , wxConvLocal , actualSize ) ; HUnlock( theText ) ; } + DisposeHandle( theText ) ; } #endif } + #if '\n' == 10 wxMacConvertNewlines13To10( &result ) ; #else wxMacConvertNewlines10To13( &result ) ; #endif + return result ; } @@ -1488,7 +1581,11 @@ void wxMacMLTEControl::SetStringValue( const wxString &str) TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) { TXNFrameOptions frameOptions = - kTXNDontDrawCaretWhenInactiveMask ; + kTXNDontDrawCaretWhenInactiveMask +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 + | kTXNDoFontSubstitutionMask +#endif + ; if ( ! ( wxStyle & wxTE_NOHIDESEL ) ) frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; @@ -1521,17 +1618,17 @@ TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, bool visible ) { - TXNControlTag iControlTags[] = - { - kTXNDoFontSubstitution, + TXNControlTag iControlTags[] = + { + kTXNDoFontSubstitution, kTXNWordWrapStateTag , }; - TXNControlData iControlData[] = - { - {false}, + TXNControlData iControlData[] = + { + {true}, {kTXNNoAutoWrap}, }; - + int toptag = WXSIZEOF( iControlTags ) ; if ( m_windowStyle & wxTE_MULTILINE ) @@ -1566,7 +1663,7 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo kTXNStartOffset, kTXNEndOffset) ); } - + if ( m_windowStyle & wxTE_PASSWORD ) { UniChar c = 0xA5 ; @@ -1577,6 +1674,22 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo tback.bgType = kTXNBackgroundTypeRGB; tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); TXNSetBackground( m_txn , &tback); + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 + if ( UMAGetSystemVersion() >= 0x1040 ) + { + TXNCommandEventSupportOptions options ; + if ( TXNGetCommandEventSupport( m_txn, &options) == noErr ) + { + options |= kTXNSupportEditCommandProcessing ; + options |= kTXNSupportSpellCheckCommandProcessing ; + options |= kTXNSupportFontCommandProcessing ; + options |= kTXNSupportFontCommandUpdating ; + + TXNSetCommandEventSupport( m_txn , options ) ; + } + } +#endif } void wxMacMLTEControl::SetBackground( const wxBrush &brush ) @@ -1638,6 +1751,7 @@ void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground wxMacEditHelper help(m_txn) ; TXNSetAttribute( wxTextAttr(foreground,wxNullColour,font) , kTXNStartOffset,kTXNEndOffset ) ; } + void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style) { wxMacEditHelper help(m_txn) ; @@ -1696,7 +1810,7 @@ wxTextPos wxMacMLTEControl::GetLastPosition() const return actualsize ; } -void wxMacMLTEControl::Replace( long from , long to , const wxString str ) +void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) { wxString value = str ; wxMacConvertNewlines10To13( &value ) ; @@ -1745,6 +1859,7 @@ void wxMacMLTEControl::WriteText(const wxString& str) wxMacEditHelper helper( m_txn ) ; SetTXNData( st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; } + GetSelection( &dummy , &end ) ; // TODO SetStyle( start , end , GetDefaultStyle() ) ; } @@ -1816,6 +1931,7 @@ long wxMacMLTEControl::XYToPosition(long x, long y) const else ++xpos ; } + return 0 ; } @@ -1853,6 +1969,7 @@ bool wxMacMLTEControl::PositionToXY(long pos, long *x, long *y) const else ++xpos ; } + if ( y ) *y = ypos ; if ( x ) *x = xpos ; } @@ -1894,7 +2011,7 @@ void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOff TXNSetData( m_txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end); #else - wxMBConvUTF16BE converter ; + wxMBConvUTF16 converter ; ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ; UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ; converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ; @@ -1909,7 +2026,6 @@ void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOff #endif } - wxString wxMacMLTEControl::GetLineText(long lineNo) const { wxString line ; @@ -2004,13 +2120,13 @@ int wxMacMLTEControl::GetLineLength(long lineNo) const TXNScrollInfoUPP gTXNScrollInfoProc = NULL ; ControlActionUPP gTXNScrollActionProc = NULL ; -pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation +pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon) { wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ; SInt32 value = wxMax( iValue , 0 ) ; SInt32 maximum = wxMax( iMaximumValue , 0 ) ; - + if ( iScrollBarOrientation == kTXNHorizontal ) { if ( mlte->m_sbHorizontal ) @@ -2037,12 +2153,12 @@ pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ; if ( mlte == NULL ) return ; - + if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal ) - return ; - - bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ; - + return ; + + bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ; + SInt32 minimum = 0 ; SInt32 maximum = GetControl32BitMaximum( controlRef ) ; SInt32 value = GetControl32BitValue( controlRef ) ; @@ -2062,7 +2178,7 @@ pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef delta = -GetControlViewSize( controlRef ) ; break ; case kControlIndicatorPart : - delta = value - + delta = value - ( isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue ) ; break ; default : @@ -2071,7 +2187,7 @@ pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef if ( delta != 0 ) { SInt32 newValue = value ; - + if ( partCode != kControlIndicatorPart ) { if( value + delta < minimum ) @@ -2082,13 +2198,13 @@ pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef SetControl32BitValue( controlRef , value + delta ) ; newValue = value + delta ; } - + SInt32 verticalDelta = isHorizontal ? 0 : delta ; SInt32 horizontalDelta = isHorizontal ? delta : 0 ; - + err = TXNScroll( mlte->m_txn , kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, &verticalDelta , &horizontalDelta ); - + if ( isHorizontal ) mlte->m_lastHorizontalValue = newValue ; else @@ -2098,7 +2214,7 @@ pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef #endif // make correct activations -void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive) +void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive) { wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); @@ -2111,29 +2227,29 @@ void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive) TXNFocus( m_txn, setActive); } -void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus) +void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus) { TXNFocus( m_txn, setFocus); } -// guards against inappropriate redraw (hidden objects drawing onto window) +// guards against inappropriate redraw (hidden objects drawing onto window) void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis) { ControlRef controlFocus = 0 ; GetKeyboardFocus( m_txnWindow , &controlFocus ) ; - + if ( controlFocus == m_controlRef && vis == false ) { SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; } - + TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; TXNControlData iControlData[1] = { {(UInt32) false } }; verify_noerr( TXNGetTXNObjectControls( m_txn , 1, iControlTags, iControlData ) ) ; - + if ( iControlData[0].uValue != vis ) { iControlData[0].uValue = vis ; @@ -2147,7 +2263,7 @@ void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis) // make sure that the TXNObject is at the right position -void wxMacMLTEClassicControl::MacUpdatePosition() +void wxMacMLTEClassicControl::MacUpdatePosition() { wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); if ( textctrl == NULL ) @@ -2155,14 +2271,14 @@ void wxMacMLTEClassicControl::MacUpdatePosition() Rect bounds ; UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); - + wxRect visRect = textctrl->MacGetClippedClientRect() ; Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ; int x , y ; x = y = 0 ; textctrl->MacWindowToRootWindow( &x , &y ) ; OffsetRect( &visBounds , x , y ) ; - + if ( !EqualRect( &bounds , &m_txnControlBounds ) || !EqualRect( &visBounds , &m_txnVisBounds) ) { m_txnControlBounds = bounds ; @@ -2184,10 +2300,10 @@ void wxMacMLTEClassicControl::MacUpdatePosition() sbBounds.top = h - 14 ; sbBounds.right = w + 1 ; sbBounds.bottom = h + 1 ; - + if ( !isCompositing ) OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; - + SetControlBounds( m_sbHorizontal , &sbBounds ) ; SetControlViewSize( m_sbHorizontal , w ) ; } @@ -2199,7 +2315,7 @@ void wxMacMLTEClassicControl::MacUpdatePosition() sbBounds.top = -1 ; sbBounds.right = w + 1 ; sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ; - + if ( !isCompositing ) OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; @@ -2207,54 +2323,55 @@ void wxMacMLTEClassicControl::MacUpdatePosition() SetControlViewSize( m_sbVertical , h ) ; } } - + Rect oldviewRect ; TXNLongRect olddestRect ; TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ; - + Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left, m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left, m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; - + if ( olddestRect.right >= 10000 ) destRect.right = destRect.left + 32000 ; - + if ( olddestRect.bottom >= 0x20000000 ) destRect.bottom = destRect.top + 0x40000000 ; - - SectRect( &viewRect , &visBounds , &viewRect ) ; + + SectRect( &viewRect , &visBounds , &viewRect ) ; TXNSetRectBounds( m_txn , &viewRect , &destRect , true ) ; /* TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left, m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID); */ #else - + TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left, - wxMax( m_txnControlBounds.bottom , m_txnControlBounds.top ) , + wxMax( m_txnControlBounds.bottom , m_txnControlBounds.top ) , wxMax( m_txnControlBounds.right , m_txnControlBounds.left ) , m_txnFrameID); - - // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a +#endif + // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a // movement, therefore we have to force it + // according to David Surovell this problem also sometimes occurs under OSX, so we use this as well + TXNLongRect textRect ; - TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ; + TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ; if ( textRect.left < m_txnControlBounds.left ) { TXNShowSelection( m_txn , false ) ; } -#endif } } -void wxMacMLTEClassicControl::SetRect( Rect *r ) +void wxMacMLTEClassicControl::SetRect( Rect *r ) { wxMacControl::SetRect( r ) ; MacUpdatePosition() ; } -void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart) +void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart) { wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); if ( textctrl == NULL ) @@ -2267,17 +2384,13 @@ void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart) } } -wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) +wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) { Point where = { y , x } ; - ControlPartCode result; + ControlPartCode result = kControlNoPart; - result = 0; wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); - if ( textctrl == NULL ) - return 0 ; - - if (textctrl->MacIsReallyShown() ) + if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) { if (PtInRect(where, &m_txnControlBounds)) result = kControlEditTextPart ; @@ -2293,24 +2406,20 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt1 } if (PtInRect(where, &m_txnControlBounds)) result = kControlEditTextPart ; - else - result = 0; } } + return result; } -wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc ) +wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc ) { - wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); - if ( textctrl == NULL ) - return 0; + ControlPartCode result = kControlNoPart; - ControlPartCode partCodeResult = 0; - - if (textctrl->MacIsReallyShown() ) + wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); + if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) { - Point startPt = { y ,x } ; + Point startPt = { y , x } ; // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) { @@ -2329,23 +2438,26 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxIn EventRecord rec ; ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; TXNClick( m_txn, &rec ); - } break; + + default : + break; } } - return partCodeResult; + + return result; } -void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() +void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() { wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); if ( textctrl == NULL ) return ; - if (textctrl->MacIsReallyShown()) + if (textctrl->MacIsReallyShown()) { - if (IsControlActive(m_controlRef)) + if (IsControlActive(m_controlRef)) { Point mousep; @@ -2354,7 +2466,7 @@ void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() TXNIdle(m_txn); - if (PtInRect(mousep, &m_txnControlBounds)) + if (PtInRect(mousep, &m_txnControlBounds)) { RgnHandle theRgn; RectRgn((theRgn = NewRgn()), &m_txnControlBounds); @@ -2365,11 +2477,11 @@ void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() } } -wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) +wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) { wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); if ( textctrl == NULL ) - return 0; + return kControlNoPart; wxMacWindowClipper clipper( textctrl ) ; @@ -2379,16 +2491,16 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, ev.modifiers = modifiers ; ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ; TXNKeyDown( m_txn , &ev); - + return kControlEntireControl; } -void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating) +void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating) { MacActivatePaneText( activating ); } -wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) +wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) { ControlPartCode focusResult; @@ -2398,22 +2510,22 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) return 0; wxMacWindowClipper clipper( textctrl ) ; - - ControlRef controlFocus = 0 ; + + ControlRef controlFocus = NULL ; GetKeyboardFocus( m_txnWindow , &controlFocus ) ; bool wasFocused = ( controlFocus == m_controlRef ) ; - switch (action) + switch (action) { case kControlFocusPrevPart: case kControlFocusNextPart: MacFocusPaneText( ( !wasFocused)); focusResult = (!wasFocused) ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart; break; - + case kControlFocusNoPart: default: - MacFocusPaneText( false); + MacFocusPaneText( false ); focusResult = kControlFocusNoPart; break; } @@ -2433,26 +2545,28 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, m_font = wxPeer->GetFont() ; m_windowStyle = style ; Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; - wxString st = str ; - wxMacConvertNewlines10To13( &st ) ; - short featurSet; + short featureSet; - featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle + featureSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle | kControlWantsActivate | kControlHandlesTracking // | kControlHasSpecialBackground | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; - verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, &m_controlRef ) ); + verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featureSet, &m_controlRef ) ); DoCreate(); - AdjustCreationAttributes( *wxWHITE , true) ; + AdjustCreationAttributes( *wxWHITE , true ) ; MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; - wxMacWindowClipper clipper( m_peer ) ; - SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; - TXNSetSelection( m_txn, 0, 0); + { + wxString st = str ; + wxMacConvertNewlines10To13( &st ) ; + wxMacWindowClipper clipper( m_peer ) ; + SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; + TXNSetSelection( m_txn, 0, 0); + } } wxMacMLTEClassicControl::~wxMacMLTEClassicControl() @@ -2582,7 +2696,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() /* set the initial settings for our private data */ - m_txnWindow =GetControlOwner(m_controlRef); + m_txnWindow = GetControlOwner(m_controlRef); m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow); #ifdef __WXMAC_OSX__ @@ -2597,10 +2711,10 @@ OSStatus wxMacMLTEClassicControl::DoCreate() #endif /* calculate the rectangles used by the control */ UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds); - + m_txnControlBounds = bounds ; m_txnVisBounds = bounds ; - + CGrafPtr origPort = NULL ; GDHandle origDev = NULL ; GetGWorld( &origPort , &origDev ) ; @@ -2620,7 +2734,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate() m_sbVertical = 0 ; m_lastHorizontalValue = 0 ; m_lastVerticalValue = 0 ; - + Rect sb = { 0 , 0 , 0 , 0 } ; if ( frameOptions & kTXNWantVScrollBarMask ) { @@ -2651,21 +2765,21 @@ OSStatus wxMacMLTEClassicControl::DoCreate() &m_txn, &m_txnFrameID, NULL ) ); /* TXNCarbonEventInfo cInfo ; - + cInfo.useCarbonEvents = false ; cInfo.filler = 0 ; cInfo.flags = 0 ; cInfo.fDictionary = NULL ; - TXNControlTag iControlTags[] = - { + TXNControlTag iControlTags[] = + { kTXNUseCarbonEvents , }; - TXNControlData iControlData[] = - { + TXNControlData iControlData[] = + { {(UInt32) &cInfo }, }; - + int toptag = WXSIZEOF( iControlTags ) ; verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag, @@ -2699,7 +2813,8 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, wxString st = str ; wxMacConvertNewlines10To13( &st ) ; - HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ; + HIRect hr = { { bounds.left , bounds.top} , + { bounds.right - bounds.left , bounds.bottom - bounds.top} } ; m_scrollView = NULL ; TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; @@ -2735,7 +2850,6 @@ wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, TXNSetSelection( m_txn, 0, 0); TXNShowSelection( m_txn, kTXNShowStart); - } OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) @@ -2751,6 +2865,25 @@ bool wxMacMLTEHIViewControl::HasFocus() const return control == m_textView ; } +void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush ) +{ + wxMacMLTEControl::SetBackground( brush ) ; +/* + CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); + RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; + + float component[4] ; + component[0] = col.red / 65536.0 ; + component[1] = col.green / 65536.0 ; + component[2] = col.blue / 65536.0 ; + component[3] = 1.0 ; // alpha + + CGColorRef color = CGColorCreate (rgbSpace , component ); + HITextViewSetBackgroundColor( m_textView , color ) ; + CGColorSpaceRelease( rgbSpace ); +*/ +} + #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2