listbox rewrite, cleanup
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38832 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
|
||||
BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl
|
||||
{
|
||||
public:
|
||||
wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style );
|
||||
~wxMacDataBrowserCheckListControl();
|
||||
|
||||
virtual wxMacListBoxItem* CreateItem();
|
||||
|
||||
virtual bool MacIsChecked(unsigned int n) const;
|
||||
virtual void MacCheck(unsigned int n, bool bCheck = true);
|
||||
};
|
||||
|
||||
void wxCheckListBox::Init()
|
||||
{
|
||||
}
|
||||
@@ -69,9 +81,9 @@ bool wxCheckListBox::Create(
|
||||
return false;
|
||||
|
||||
// this will be increased by our Append command
|
||||
m_noItems = 0;
|
||||
|
||||
m_peer = (wxMacControl*) CreateMacListControl(pos , size , style );
|
||||
wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style );
|
||||
control->SetClientDataType( m_clientDataItemsType );
|
||||
m_peer = control;
|
||||
|
||||
MacPostControlCreate(pos,size);
|
||||
|
||||
@@ -92,7 +104,7 @@ bool wxCheckListBox::IsChecked(unsigned int item) const
|
||||
wxCHECK_MSG( IsValid(item), false,
|
||||
wxT("invalid index in wxCheckListBox::IsChecked") );
|
||||
|
||||
return m_checks[item] != 0;
|
||||
return GetPeer()->MacIsChecked( item );
|
||||
}
|
||||
|
||||
void wxCheckListBox::Check(unsigned int item, bool check)
|
||||
@@ -100,62 +112,158 @@ void wxCheckListBox::Check(unsigned int item, bool check)
|
||||
wxCHECK_RET( IsValid(item),
|
||||
wxT("invalid index in wxCheckListBox::Check") );
|
||||
|
||||
bool isChecked = m_checks[item] != 0;
|
||||
bool isChecked = GetPeer()->MacIsChecked( item );
|
||||
if ( check != isChecked )
|
||||
{
|
||||
m_checks[item] = check;
|
||||
MacUpdateLine( item );
|
||||
GetPeer()->MacCheck( item , check );
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// methods forwarded to wxCheckListBox
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxCheckListBox::Delete(unsigned int n)
|
||||
wxMacCheckListControl* wxCheckListBox::GetPeer() const
|
||||
{
|
||||
wxCHECK_RET( IsValid(n), wxT("invalid index in wxCheckListBox::Delete") );
|
||||
|
||||
wxListBox::Delete( n );
|
||||
m_checks.RemoveAt( n );
|
||||
return dynamic_cast<wxMacCheckListControl*>(m_peer);
|
||||
}
|
||||
|
||||
int wxCheckListBox::DoAppend(const wxString& item)
|
||||
const short kCheckboxColumnId = 1026;
|
||||
|
||||
wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style)
|
||||
: wxMacDataBrowserListControl( peer, pos, size, style )
|
||||
{
|
||||
int pos = wxListBox::DoAppend( item );
|
||||
OSStatus err = noErr;
|
||||
|
||||
// the item is initially unchecked
|
||||
m_checks.Insert( false, pos );
|
||||
DataBrowserListViewColumnDesc columnDesc;
|
||||
columnDesc.headerBtnDesc.titleOffset = 0;
|
||||
columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
|
||||
|
||||
return pos;
|
||||
columnDesc.headerBtnDesc.btnFontStyle.flags =
|
||||
kControlUseFontMask | kControlUseJustMask;
|
||||
|
||||
columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
|
||||
columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
|
||||
columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
|
||||
columnDesc.headerBtnDesc.btnFontStyle.style = normal;
|
||||
columnDesc.headerBtnDesc.titleString = NULL;
|
||||
|
||||
columnDesc.headerBtnDesc.minimumWidth = 30;
|
||||
columnDesc.headerBtnDesc.maximumWidth = 30;
|
||||
|
||||
columnDesc.propertyDesc.propertyID = kCheckboxColumnId;
|
||||
columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType;
|
||||
columnDesc.propertyDesc.propertyFlags =
|
||||
kDataBrowserPropertyIsMutable
|
||||
| kDataBrowserTableViewSelectionColumn
|
||||
| kDataBrowserDefaultPropertyFlags;
|
||||
|
||||
err = AddColumn( &columnDesc, 0 );
|
||||
verify_noerr( err );
|
||||
}
|
||||
|
||||
void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
|
||||
wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
|
||||
{
|
||||
wxListBox::DoInsertItems( items, pos );
|
||||
|
||||
unsigned int count = items.GetCount();
|
||||
for ( unsigned int n = 0; n < count; n++ )
|
||||
}
|
||||
|
||||
class wxMacCheckListBoxItem : public wxMacListBoxItem
|
||||
{
|
||||
public :
|
||||
wxMacCheckListBoxItem()
|
||||
{
|
||||
m_checks.Insert( false, pos + n );
|
||||
m_isChecked = false;
|
||||
}
|
||||
}
|
||||
|
||||
void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData)
|
||||
{
|
||||
// call it first as it does DoClear()
|
||||
wxListBox::DoSetItems( items, clientData );
|
||||
|
||||
unsigned int count = items.GetCount();
|
||||
for ( unsigned int n = 0; n < count; n++ )
|
||||
~wxMacCheckListBoxItem()
|
||||
{
|
||||
m_checks.Add( false );
|
||||
}
|
||||
|
||||
virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
|
||||
DataBrowserPropertyID property,
|
||||
DataBrowserItemDataRef itemData,
|
||||
bool changeValue )
|
||||
{
|
||||
OSStatus err = errDataBrowserPropertyNotSupported;
|
||||
|
||||
wxCheckListBox *checklist = wxDynamicCast( owner->GetPeer() , wxCheckListBox );
|
||||
wxCHECK_MSG( checklist != NULL , errDataBrowserPropertyNotSupported , wxT("wxCheckListBox expected"));
|
||||
|
||||
if ( !changeValue )
|
||||
{
|
||||
switch (property)
|
||||
{
|
||||
case kCheckboxColumnId:
|
||||
verify_noerr(SetDataBrowserItemDataButtonValue( itemData, m_isChecked ? kThemeButtonOn : kThemeButtonOff ));
|
||||
err = noErr;
|
||||
break;
|
||||
|
||||
case kDataBrowserItemIsEditableProperty:
|
||||
verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
|
||||
err = noErr;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (property)
|
||||
{
|
||||
case kCheckboxColumnId:
|
||||
{
|
||||
// we have to change this behind the back, since Check() would be triggering another update round
|
||||
bool newVal = !m_isChecked;
|
||||
verify_noerr(SetDataBrowserItemDataButtonValue( itemData, newVal ? kThemeButtonOn : kThemeButtonOff ));
|
||||
m_isChecked = newVal;
|
||||
err = noErr;
|
||||
|
||||
wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() );
|
||||
event.SetInt( owner->GetLineFromItem( this ) );
|
||||
event.SetEventObject( checklist );
|
||||
checklist->GetEventHandler()->ProcessEvent( event );
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( err == errDataBrowserPropertyNotSupported )
|
||||
err = wxMacListBoxItem::GetSetData( owner , property, itemData , changeValue);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void Check( bool check )
|
||||
{
|
||||
m_isChecked = check;
|
||||
}
|
||||
bool IsChecked() const
|
||||
{
|
||||
return m_isChecked;
|
||||
}
|
||||
|
||||
protected :
|
||||
bool m_isChecked;
|
||||
};
|
||||
|
||||
wxMacListBoxItem* wxMacDataBrowserCheckListControl::CreateItem()
|
||||
{
|
||||
return new wxMacCheckListBoxItem();
|
||||
}
|
||||
|
||||
void wxCheckListBox::DoClear()
|
||||
void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck)
|
||||
{
|
||||
m_checks.Empty();
|
||||
wxMacCheckListBoxItem* item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n) );
|
||||
item->Check( bCheck);
|
||||
UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId);
|
||||
}
|
||||
|
||||
bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
|
||||
{
|
||||
wxMacCheckListBoxItem * item = dynamic_cast<wxMacCheckListBoxItem*>( GetItemFromLine( n ) );
|
||||
return item->IsChecked();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // wxUSE_CHECKLISTBOX
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user