removing the menu from the public API of wxChoice on osx
on iOS pickers are having data sources that are not implemented using a menu, therefore the implementation API had to be changed
This commit is contained in:
@@ -91,7 +91,6 @@ protected:
|
|||||||
|
|
||||||
wxArrayString m_strings;
|
wxArrayString m_strings;
|
||||||
wxChoiceDataArray m_datas ;
|
wxChoiceDataArray m_datas ;
|
||||||
wxMenu* m_popUpMenu ;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This should be called when the number of items in the control changes.
|
// This should be called when the number of items in the control changes.
|
||||||
|
@@ -726,7 +726,7 @@ private:
|
|||||||
wxDECLARE_NO_COPY_CLASS(wxTextWidgetImpl);
|
wxDECLARE_NO_COPY_CLASS(wxTextWidgetImpl);
|
||||||
};
|
};
|
||||||
|
|
||||||
// common interface for all implementations
|
// common interface for all combobox implementations
|
||||||
class WXDLLIMPEXP_CORE wxComboWidgetImpl
|
class WXDLLIMPEXP_CORE wxComboWidgetImpl
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -753,6 +753,41 @@ public :
|
|||||||
virtual int FindString(const wxString& WXUNUSED(text)) const { return -1; }
|
virtual int FindString(const wxString& WXUNUSED(text)) const { return -1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// common interface for choice
|
||||||
|
//
|
||||||
|
|
||||||
|
class WXDLLIMPEXP_CORE wxChoiceWidgetImpl
|
||||||
|
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
wxChoiceWidgetImpl() {}
|
||||||
|
|
||||||
|
virtual ~wxChoiceWidgetImpl() {}
|
||||||
|
|
||||||
|
virtual int GetSelectedItem() const { return -1; }
|
||||||
|
|
||||||
|
virtual void SetSelectedItem(int WXUNUSED(item)) {}
|
||||||
|
|
||||||
|
virtual size_t GetNumberOfItems() const = 0;
|
||||||
|
|
||||||
|
virtual void InsertItem(size_t pos, int itemid, const wxString& text) = 0;
|
||||||
|
|
||||||
|
virtual void RemoveItem(size_t pos) = 0;
|
||||||
|
|
||||||
|
virtual void Clear()
|
||||||
|
{
|
||||||
|
size_t count = GetNumberOfItems();
|
||||||
|
for ( size_t i = 0 ; i < count ; i++ )
|
||||||
|
{
|
||||||
|
RemoveItem( 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void SetItem(int pos, const wxString& item) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// common interface for buttons
|
// common interface for buttons
|
||||||
//
|
//
|
||||||
|
@@ -30,7 +30,6 @@ wxChoice::~wxChoice()
|
|||||||
for ( i = 0; i < max; ++i )
|
for ( i = 0; i < max; ++i )
|
||||||
delete GetClientObject( i );
|
delete GetClientObject( i );
|
||||||
}
|
}
|
||||||
delete m_popUpMenu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxChoice::Create(wxWindow *parent,
|
bool wxChoice::Create(wxWindow *parent,
|
||||||
@@ -70,10 +69,7 @@ bool wxChoice::Create(wxWindow *parent,
|
|||||||
if ( !wxChoiceBase::Create( parent, id, pos, size, style, validator, name ) )
|
if ( !wxChoiceBase::Create( parent, id, pos, size, style, validator, name ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_popUpMenu = new wxMenu();
|
SetPeer(wxWidgetImpl::CreateChoice( this, parent, id, NULL, pos, size, style, GetExtraStyle() ));
|
||||||
m_popUpMenu->SetNoEventsMode(true);
|
|
||||||
|
|
||||||
SetPeer(wxWidgetImpl::CreateChoice( this, parent, id, m_popUpMenu, pos, size, style, GetExtraStyle() ));
|
|
||||||
|
|
||||||
MacPostControlCreate( pos, size );
|
MacPostControlCreate( pos, size );
|
||||||
|
|
||||||
@@ -133,7 +129,7 @@ int wxChoice::DoInsertItems(const wxArrayStringsAdapter & items,
|
|||||||
wxString text = items[i];
|
wxString text = items[i];
|
||||||
if (text.empty())
|
if (text.empty())
|
||||||
text = " "; // menu items can't have empty labels
|
text = " "; // menu items can't have empty labels
|
||||||
m_popUpMenu->Insert( idx, i+1, text );
|
dynamic_cast<wxChoiceWidgetImpl*>(GetPeer())->InsertItem( idx, i+1, text );
|
||||||
m_datas.Insert( NULL, idx );
|
m_datas.Insert( NULL, idx );
|
||||||
AssignNewItemClientData(idx, clientData, i, type);
|
AssignNewItemClientData(idx, clientData, i, type);
|
||||||
}
|
}
|
||||||
@@ -150,8 +146,7 @@ void wxChoice::DoDeleteOneItem(unsigned int n)
|
|||||||
if ( HasClientObjectData() )
|
if ( HasClientObjectData() )
|
||||||
delete GetClientObject( n );
|
delete GetClientObject( n );
|
||||||
|
|
||||||
m_popUpMenu->Delete( m_popUpMenu->FindItemByPosition( n ) );
|
dynamic_cast<wxChoiceWidgetImpl*>(GetPeer())->RemoveItem(n);
|
||||||
|
|
||||||
m_strings.RemoveAt( n ) ;
|
m_strings.RemoveAt( n ) ;
|
||||||
m_datas.RemoveAt( n ) ;
|
m_datas.RemoveAt( n ) ;
|
||||||
|
|
||||||
@@ -160,10 +155,7 @@ void wxChoice::DoDeleteOneItem(unsigned int n)
|
|||||||
|
|
||||||
void wxChoice::DoClear()
|
void wxChoice::DoClear()
|
||||||
{
|
{
|
||||||
for ( unsigned int i = 0 ; i < GetCount() ; i++ )
|
dynamic_cast<wxChoiceWidgetImpl*>(GetPeer())->Clear();
|
||||||
{
|
|
||||||
m_popUpMenu->Delete( m_popUpMenu->FindItemByPosition( 0 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
m_strings.Empty() ;
|
m_strings.Empty() ;
|
||||||
m_datas.Empty() ;
|
m_datas.Empty() ;
|
||||||
@@ -210,7 +202,7 @@ void wxChoice::SetString(unsigned int n, const wxString& s)
|
|||||||
|
|
||||||
m_strings[n] = s ;
|
m_strings[n] = s ;
|
||||||
|
|
||||||
m_popUpMenu->FindItemByPosition( n )->SetItemLabel( s ) ;
|
dynamic_cast<wxChoiceWidgetImpl*>(GetPeer())->SetItem(n,s);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxChoice::GetString(unsigned int n) const
|
wxString wxChoice::GetString(unsigned int n) const
|
||||||
|
@@ -55,12 +55,22 @@
|
|||||||
- (NSControlSize)controlSize;
|
- (NSControlSize)controlSize;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
class wxChoiceCocoaImpl : public wxWidgetCocoaImpl
|
class wxChoiceCocoaImpl : public wxWidgetCocoaImpl, public wxChoiceWidgetImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxChoiceCocoaImpl(wxWindowMac *wxpeer, wxNSPopUpButton *v)
|
wxChoiceCocoaImpl(wxWindowMac *wxpeer, wxNSPopUpButton *v)
|
||||||
: wxWidgetCocoaImpl(wxpeer, v)
|
: wxWidgetCocoaImpl(wxpeer, v)
|
||||||
{
|
{
|
||||||
|
m_popUpMenu = new wxMenu();
|
||||||
|
m_popUpMenu->SetNoEventsMode(true);
|
||||||
|
[v setMenu: m_popUpMenu->GetHMenu()];
|
||||||
|
[v setAutoenablesItems:NO];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
~wxChoiceCocoaImpl()
|
||||||
|
{
|
||||||
|
delete m_popUpMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetLayoutInset(int &left , int &top , int &right, int &bottom) const wxOVERRIDE
|
void GetLayoutInset(int &left , int &top , int &right, int &bottom) const wxOVERRIDE
|
||||||
@@ -96,6 +106,29 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InsertItem( size_t pos, int itemid, const wxString& text) wxOVERRIDE
|
||||||
|
{
|
||||||
|
m_popUpMenu->Insert( pos, itemid, text );
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GetNumberOfItems() const wxOVERRIDE
|
||||||
|
{
|
||||||
|
return m_popUpMenu->GetMenuItemCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveItem( size_t pos ) wxOVERRIDE
|
||||||
|
{
|
||||||
|
m_popUpMenu->Delete( m_popUpMenu->FindItemByPosition( pos ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetItem(int pos, const wxString& s) wxOVERRIDE
|
||||||
|
{
|
||||||
|
m_popUpMenu->FindItemByPosition( pos )->SetItemLabel( s ) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxMenu* m_popUpMenu;
|
||||||
};
|
};
|
||||||
|
|
||||||
wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
|
wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
|
||||||
@@ -109,8 +142,6 @@ wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
|
|||||||
{
|
{
|
||||||
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
|
NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
|
||||||
wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
|
wxNSPopUpButton* v = [[wxNSPopUpButton alloc] initWithFrame:r pullsDown:NO];
|
||||||
[v setMenu: menu->GetHMenu()];
|
|
||||||
[v setAutoenablesItems:NO];
|
|
||||||
wxWidgetCocoaImpl* c = new wxChoiceCocoaImpl( wxpeer, v );
|
wxWidgetCocoaImpl* c = new wxChoiceCocoaImpl( wxpeer, v );
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
142
src/osx/iphone/choice.mm
Normal file
142
src/osx/iphone/choice.mm
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: src/osx/cocoa/choice.mm
|
||||||
|
// Purpose: wxChoice
|
||||||
|
// Author: Stefan Csomor
|
||||||
|
// Modified by:
|
||||||
|
// Created: 1998-01-01
|
||||||
|
// Copyright: (c) Stefan Csomor
|
||||||
|
// Licence: wxWindows licence
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#if wxUSE_CHOICE
|
||||||
|
|
||||||
|
#include "wx/choice.h"
|
||||||
|
|
||||||
|
#ifndef WX_PRECOMP
|
||||||
|
#include "wx/menu.h"
|
||||||
|
#include "wx/dcclient.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "wx/osx/private.h"
|
||||||
|
|
||||||
|
@interface wxUIPickerView : UIPickerView<UIPickerViewDelegate,UIPickerViewDataSource>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@property (readonly) NSMutableArray *rows;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation wxUIPickerView
|
||||||
|
|
||||||
|
+ (void)initialize
|
||||||
|
{
|
||||||
|
static BOOL initialized = NO;
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
initialized = YES;
|
||||||
|
wxOSXIPhoneClassAddWXMethods( self );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)initWithFrame:(CGRect)rectBox
|
||||||
|
{
|
||||||
|
if ( self = [super initWithFrame:rectBox] )
|
||||||
|
{
|
||||||
|
_rows = [[NSMutableArray alloc] init];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
[_rows dealloc];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
|
||||||
|
{
|
||||||
|
if ( component == 0 )
|
||||||
|
return [_rows count];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
|
||||||
|
{
|
||||||
|
return [_rows objectAtIndex:row];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int) intValue
|
||||||
|
{
|
||||||
|
return (int) [self selectedRowInComponent:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setIntValue: (int) v
|
||||||
|
{
|
||||||
|
[self selectRow:v inComponent:0 animated:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
class wxChoiceIPhoneImpl : public wxWidgetIPhoneImpl, public wxChoiceWidgetImpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
wxChoiceIPhoneImpl(wxWindowMac *wxpeer, wxUIPickerView *v)
|
||||||
|
: wxWidgetIPhoneImpl(wxpeer, v)
|
||||||
|
{
|
||||||
|
[v setDelegate:v];
|
||||||
|
[v setDataSource:v];
|
||||||
|
}
|
||||||
|
|
||||||
|
void InsertItem( size_t pos, int itemid, const wxString& text) wxOVERRIDE
|
||||||
|
{
|
||||||
|
wxCFStringRef cftext(text);
|
||||||
|
[((wxUIPickerView*)m_osxView).rows insertObject:cftext.AsNSString() atIndex:pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t GetNumberOfItems() const wxOVERRIDE
|
||||||
|
{
|
||||||
|
return [((wxUIPickerView*)m_osxView).rows count];
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoveItem( size_t pos ) wxOVERRIDE
|
||||||
|
{
|
||||||
|
[((wxUIPickerView*)m_osxView).rows removeObjectAtIndex:pos];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetItem(int pos, const wxString& text) wxOVERRIDE
|
||||||
|
{
|
||||||
|
wxCFStringRef cftext(text);
|
||||||
|
[((wxUIPickerView*)m_osxView).rows replaceObjectAtIndex:pos withObject:cftext.AsNSString()];
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
wxWidgetImplType* wxWidgetImpl::CreateChoice( wxWindowMac* wxpeer,
|
||||||
|
wxWindowMac* WXUNUSED(parent),
|
||||||
|
wxWindowID WXUNUSED(id),
|
||||||
|
wxMenu* menu,
|
||||||
|
const wxPoint& pos,
|
||||||
|
const wxSize& size,
|
||||||
|
long WXUNUSED(style),
|
||||||
|
long WXUNUSED(extraStyle))
|
||||||
|
{
|
||||||
|
CGRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
|
||||||
|
wxUIPickerView* v = [[wxUIPickerView alloc] initWithFrame:r];
|
||||||
|
|
||||||
|
wxChoiceIPhoneImpl* c = new wxChoiceIPhoneImpl( wxpeer, v );
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // wxUSE_CHOICE
|
Reference in New Issue
Block a user