From b668a73527cd08aae1321bfb1c604c9b96fffbed Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Thu, 10 May 2001 05:27:07 +0000 Subject: [PATCH] corrected a bug in dc which resetted the port , exchanged the wxchoice implementation git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10096 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/choice.h | 6 +- src/mac/aga.cpp | 3 +- src/mac/carbon/aga.cpp | 3 +- src/mac/carbon/choice.cpp | 221 +++++++++++++++++++++++--------------- src/mac/carbon/dc.cpp | 2 +- src/mac/choice.cpp | 221 +++++++++++++++++++++++--------------- src/mac/dc.cpp | 2 +- 7 files changed, 275 insertions(+), 183 deletions(-) diff --git a/include/wx/mac/choice.h b/include/wx/mac/choice.h index 335bebd869..01faf5e769 100644 --- a/include/wx/mac/choice.h +++ b/include/wx/mac/choice.h @@ -88,15 +88,11 @@ protected: virtual void DoSetItemClientObject( int n, wxClientData* clientData ); virtual wxClientData* DoGetItemClientObject( int n ) const; - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); - // free all memory we have (used by Clear() and dtor) void Free(); wxArrayString m_strings; - wxChoiceDataArray m_dataArray ; + wxChoiceDataArray m_datas ; MenuHandle m_macPopUpMenuHandle ; }; diff --git a/src/mac/aga.cpp b/src/mac/aga.cpp index 572caed82a..9a752cbe6d 100644 --- a/src/mac/aga.cpp +++ b/src/mac/aga.cpp @@ -2586,7 +2586,7 @@ void AGAPortHelper::Setup( GrafPtr newport ) GetPenState( &oldPenState ) ; GetBackColor( &oldBackColor ) ; GetForeColor( &oldForeColor ) ; - + wxASSERT( clip == NULL ) ; clip = NewRgn() ; GetClip( clip ); font = GetPortTextFont( newport); @@ -2608,6 +2608,7 @@ AGAPortHelper::~AGAPortHelper() if ( clip ) { SetPort( nport ) ; + PenNormal() ; SetClip( clip ) ; DisposeRgn( clip ) ; RGBForeColor(&oldForeColor); diff --git a/src/mac/carbon/aga.cpp b/src/mac/carbon/aga.cpp index 572caed82a..9a752cbe6d 100644 --- a/src/mac/carbon/aga.cpp +++ b/src/mac/carbon/aga.cpp @@ -2586,7 +2586,7 @@ void AGAPortHelper::Setup( GrafPtr newport ) GetPenState( &oldPenState ) ; GetBackColor( &oldBackColor ) ; GetForeColor( &oldForeColor ) ; - + wxASSERT( clip == NULL ) ; clip = NewRgn() ; GetClip( clip ); font = GetPortTextFont( newport); @@ -2608,6 +2608,7 @@ AGAPortHelper::~AGAPortHelper() if ( clip ) { SetPort( nport ) ; + PenNormal() ; SetClip( clip ) ; DisposeRgn( clip ) ; RGBForeColor(&oldForeColor); diff --git a/src/mac/carbon/choice.cpp b/src/mac/carbon/choice.cpp index bac3579f34..9c4e7d94a9 100644 --- a/src/mac/carbon/choice.cpp +++ b/src/mac/carbon/choice.cpp @@ -30,14 +30,6 @@ wxChoice::~wxChoice() DisposeMenu( m_macPopUpMenuHandle ) ; } -int wxChoice::GetCount() const { - return m_strings.Count() ; -} - -void wxChoice::SetString( int n , const wxString& s ) { - m_strings[n] = s ; -} - bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, @@ -52,57 +44,156 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; - m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 , kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; - for ( int i = 0 ; i < n ; i++ ) - { - Str255 label; - wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); - AppendMenu( m_macPopUpMenuHandle , label ) ; - m_strings.Add( choices[i] ) ; - m_dataArray.Add( NULL ); - } - SetControlMinimum( m_macControl , 0 ) ; - SetControlMaximum( m_macControl , Number()) ; + SetControlMinimum( m_macControl , 0 ) ; + SetControlMaximum( m_macControl , 0) ; if ( n > 0 ) SetControlValue( m_macControl , 1 ) ; MacPostControlCreate() ; + for ( int i = 0; i < n; i++ ) + { + Append(choices[i]); + } return TRUE; } +// ---------------------------------------------------------------------------- +// adding/deleting items to/from the list +// ---------------------------------------------------------------------------- + int wxChoice::DoAppend(const wxString& item) { Str255 label; wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); AppendMenu( m_macPopUpMenuHandle , label ) ; m_strings.Add( item ) ; - m_dataArray.Add( NULL ); - return m_strings.Count() ; + m_datas.Add( NULL ) ; + int index = m_strings.GetCount() - 1 ; + DoSetItemClientData( index , NULL ) ; + SetControlMaximum( m_macControl , Number()) ; + return index ; +} + +void wxChoice::Delete(int n) +{ + wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") ); + + if ( HasClientObjectData() ) + { + delete GetClientObject(n); + } + + ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; + m_strings.Remove( n ) ; + SetControlMaximum( m_macControl , Number()) ; +} + +void wxChoice::Clear() +{ + Free(); + + for ( int i = 0 ; i < GetCount() ; i++ ) + { + ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; + } + m_strings.Empty() ; + m_datas.Empty() ; + SetControlMaximum( m_macControl , 0 ) ; +} + +void wxChoice::Free() +{ + if ( HasClientObjectData() ) + { + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + delete GetClientObject(n); + } + } +} + +// ---------------------------------------------------------------------------- +// selection +// ---------------------------------------------------------------------------- + +int wxChoice::GetSelection() const +{ + return GetControlValue( m_macControl ) -1 ; +} + +void wxChoice::SetSelection(int n) +{ + SetControlValue( m_macControl , n + 1 ) ; +} + +// ---------------------------------------------------------------------------- +// string list functions +// ---------------------------------------------------------------------------- + +int wxChoice::GetCount() const +{ + return m_strings.GetCount() ; +} + +int wxChoice::FindString(const wxString& s) const +{ + for( int i = 0 ; i < GetCount() ; i++ ) + { + if ( GetString( i ).IsSameAs(s, FALSE) ) + return i ; + } + return wxNOT_FOUND ; +} + +void wxChoice::SetString(int n, const wxString& s) +{ + wxFAIL_MSG(wxT("not implemented")); + +#if 0 // should do this, but no Insert() so far + Delete(n); + Insert(n + 1, s); +#endif +} + + +wxString wxChoice::GetString(int n) const +{ + return m_strings[n] ; +} + +// ---------------------------------------------------------------------------- +// client data +// ---------------------------------------------------------------------------- + +void wxChoice::DoSetItemClientData( int n, void* clientData ) +{ + wxCHECK_RET( n >= 0 && n < m_datas.GetCount(), + "invalid index in wxChoice::SetClientData" ); + wxASSERT_MSG( m_datas.GetCount() >= n , "invalid client_data array" ) ; + + if ( m_datas.GetCount() > n ) + { + m_datas[n] = (char*) clientData ; + } + else + { + m_datas.Add( (char*) clientData ) ; + } } void *wxChoice::DoGetItemClientData(int N) const { - return (void *)m_dataArray[N]; -} + wxCHECK_MSG( N >= 0 && N < m_datas.GetCount(), NULL, + "invalid index in wxChoice::GetClientData" ); -void wxChoice::DoSetItemClientData( int N, void* Client_data ) -{ - wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ; - - if ( m_dataArray.GetCount() > N ) - { - m_dataArray[N] = (char*) Client_data ; - } - else - { - m_dataArray.Add( (char*) Client_data ) ; - } + return (void *)m_datas[N]; } void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) @@ -110,67 +201,23 @@ void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) DoSetItemClientData(n, clientData); } -wxClientData* wxChoice::DoGetItemClientObject( int N ) const +wxClientData* wxChoice::DoGetItemClientObject( int n ) const { - return (wxClientData *) DoGetItemClientData( N ) ; -} - -void wxChoice::Delete(int n) -{ - ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; - m_strings.Remove( n ) ; - m_dataArray.Remove( n ) ; - SetControlMaximum( m_macControl , Number()) ; -} - -void wxChoice::Clear() -{ - for ( int i = 0 ; i < Number() ; i++ ) - { - ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; - } - m_strings.Clear() ; - m_dataArray.Empty() ; - SetControlMaximum( m_macControl , Number()) ; -} - -int wxChoice::GetSelection() const -{ - return GetControlValue( m_macControl ) -1 ; + return (wxClientData *)DoGetItemClientData(n); } void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) { wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); - event.SetInt(GetSelection()); + event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(GetStringSelection()); ProcessCommand(event); } - - -void wxChoice::SetSelection(int n) +/* +void wxChoice::Command(wxCommandEvent & event) { - SetControlValue( m_macControl , n + 1 ) ; + SetSelection (event.GetInt()); + ProcessCommand (event); } - -int wxChoice::FindString(const wxString& s) const -{ - for( int i = 0 ; i < Number() ; i++ ) - { - if ( GetString( i ) == s ) - return i ; - } - return -1; -} - -wxString wxChoice::GetString(int n) const -{ - return m_strings[n] ; -} - -void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxControl::SetSize( x,y,width,height,sizeFlags ) ; -} - +*/ diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index 8285afd1c6..9daa29987f 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -103,7 +103,7 @@ wxDC::~wxDC(void) void wxDC::MacSetupPort(AGAPortHelper* help) const { - help->Setup( m_macPort ) ; +// help->Setup( m_macPort ) ; ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v); ::ClipRect(&m_macClipRect); diff --git a/src/mac/choice.cpp b/src/mac/choice.cpp index bac3579f34..9c4e7d94a9 100644 --- a/src/mac/choice.cpp +++ b/src/mac/choice.cpp @@ -30,14 +30,6 @@ wxChoice::~wxChoice() DisposeMenu( m_macPopUpMenuHandle ) ; } -int wxChoice::GetCount() const { - return m_strings.Count() ; -} - -void wxChoice::SetString( int n , const wxString& s ) { - m_strings[n] = s ; -} - bool wxChoice::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, @@ -52,57 +44,156 @@ bool wxChoice::Create(wxWindow *parent, wxWindowID id, MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; - m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0 , kControlPopupButtonProc + kControlPopupFixedWidthVariant , (long) this ) ; m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; - for ( int i = 0 ; i < n ; i++ ) - { - Str255 label; - wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); - AppendMenu( m_macPopUpMenuHandle , label ) ; - m_strings.Add( choices[i] ) ; - m_dataArray.Add( NULL ); - } - SetControlMinimum( m_macControl , 0 ) ; - SetControlMaximum( m_macControl , Number()) ; + SetControlMinimum( m_macControl , 0 ) ; + SetControlMaximum( m_macControl , 0) ; if ( n > 0 ) SetControlValue( m_macControl , 1 ) ; MacPostControlCreate() ; + for ( int i = 0; i < n; i++ ) + { + Append(choices[i]); + } return TRUE; } +// ---------------------------------------------------------------------------- +// adding/deleting items to/from the list +// ---------------------------------------------------------------------------- + int wxChoice::DoAppend(const wxString& item) { Str255 label; wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); AppendMenu( m_macPopUpMenuHandle , label ) ; m_strings.Add( item ) ; - m_dataArray.Add( NULL ); - return m_strings.Count() ; + m_datas.Add( NULL ) ; + int index = m_strings.GetCount() - 1 ; + DoSetItemClientData( index , NULL ) ; + SetControlMaximum( m_macControl , Number()) ; + return index ; +} + +void wxChoice::Delete(int n) +{ + wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") ); + + if ( HasClientObjectData() ) + { + delete GetClientObject(n); + } + + ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; + m_strings.Remove( n ) ; + SetControlMaximum( m_macControl , Number()) ; +} + +void wxChoice::Clear() +{ + Free(); + + for ( int i = 0 ; i < GetCount() ; i++ ) + { + ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; + } + m_strings.Empty() ; + m_datas.Empty() ; + SetControlMaximum( m_macControl , 0 ) ; +} + +void wxChoice::Free() +{ + if ( HasClientObjectData() ) + { + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + delete GetClientObject(n); + } + } +} + +// ---------------------------------------------------------------------------- +// selection +// ---------------------------------------------------------------------------- + +int wxChoice::GetSelection() const +{ + return GetControlValue( m_macControl ) -1 ; +} + +void wxChoice::SetSelection(int n) +{ + SetControlValue( m_macControl , n + 1 ) ; +} + +// ---------------------------------------------------------------------------- +// string list functions +// ---------------------------------------------------------------------------- + +int wxChoice::GetCount() const +{ + return m_strings.GetCount() ; +} + +int wxChoice::FindString(const wxString& s) const +{ + for( int i = 0 ; i < GetCount() ; i++ ) + { + if ( GetString( i ).IsSameAs(s, FALSE) ) + return i ; + } + return wxNOT_FOUND ; +} + +void wxChoice::SetString(int n, const wxString& s) +{ + wxFAIL_MSG(wxT("not implemented")); + +#if 0 // should do this, but no Insert() so far + Delete(n); + Insert(n + 1, s); +#endif +} + + +wxString wxChoice::GetString(int n) const +{ + return m_strings[n] ; +} + +// ---------------------------------------------------------------------------- +// client data +// ---------------------------------------------------------------------------- + +void wxChoice::DoSetItemClientData( int n, void* clientData ) +{ + wxCHECK_RET( n >= 0 && n < m_datas.GetCount(), + "invalid index in wxChoice::SetClientData" ); + wxASSERT_MSG( m_datas.GetCount() >= n , "invalid client_data array" ) ; + + if ( m_datas.GetCount() > n ) + { + m_datas[n] = (char*) clientData ; + } + else + { + m_datas.Add( (char*) clientData ) ; + } } void *wxChoice::DoGetItemClientData(int N) const { - return (void *)m_dataArray[N]; -} + wxCHECK_MSG( N >= 0 && N < m_datas.GetCount(), NULL, + "invalid index in wxChoice::GetClientData" ); -void wxChoice::DoSetItemClientData( int N, void* Client_data ) -{ - wxASSERT_MSG( m_dataArray.GetCount() >= N , "invalid client_data array" ) ; - - if ( m_dataArray.GetCount() > N ) - { - m_dataArray[N] = (char*) Client_data ; - } - else - { - m_dataArray.Add( (char*) Client_data ) ; - } + return (void *)m_datas[N]; } void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) @@ -110,67 +201,23 @@ void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) DoSetItemClientData(n, clientData); } -wxClientData* wxChoice::DoGetItemClientObject( int N ) const +wxClientData* wxChoice::DoGetItemClientObject( int n ) const { - return (wxClientData *) DoGetItemClientData( N ) ; -} - -void wxChoice::Delete(int n) -{ - ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; - m_strings.Remove( n ) ; - m_dataArray.Remove( n ) ; - SetControlMaximum( m_macControl , Number()) ; -} - -void wxChoice::Clear() -{ - for ( int i = 0 ; i < Number() ; i++ ) - { - ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; - } - m_strings.Clear() ; - m_dataArray.Empty() ; - SetControlMaximum( m_macControl , Number()) ; -} - -int wxChoice::GetSelection() const -{ - return GetControlValue( m_macControl ) -1 ; + return (wxClientData *)DoGetItemClientData(n); } void wxChoice::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) { wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId ); - event.SetInt(GetSelection()); + event.SetInt(GetSelection()); event.SetEventObject(this); event.SetString(GetStringSelection()); ProcessCommand(event); } - - -void wxChoice::SetSelection(int n) +/* +void wxChoice::Command(wxCommandEvent & event) { - SetControlValue( m_macControl , n + 1 ) ; + SetSelection (event.GetInt()); + ProcessCommand (event); } - -int wxChoice::FindString(const wxString& s) const -{ - for( int i = 0 ; i < Number() ; i++ ) - { - if ( GetString( i ) == s ) - return i ; - } - return -1; -} - -wxString wxChoice::GetString(int n) const -{ - return m_strings[n] ; -} - -void wxChoice::DoSetSize(int x, int y, int width, int height, int sizeFlags) -{ - wxControl::SetSize( x,y,width,height,sizeFlags ) ; -} - +*/ diff --git a/src/mac/dc.cpp b/src/mac/dc.cpp index 8285afd1c6..9daa29987f 100644 --- a/src/mac/dc.cpp +++ b/src/mac/dc.cpp @@ -103,7 +103,7 @@ wxDC::~wxDC(void) void wxDC::MacSetupPort(AGAPortHelper* help) const { - help->Setup( m_macPort ) ; +// help->Setup( m_macPort ) ; ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v); ::ClipRect(&m_macClipRect);