Esempio n. 1
0
int wxGxTreeViewBase::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
{
    wxGxTreeItemData* pData1 = (wxGxTreeItemData*)GetItemData(item1);
    wxGxTreeItemData* pData2 = (wxGxTreeItemData*)GetItemData(item2);
    wxGxObject* pGxObject1 = m_pCatalog->GetRegisterObject(pData1->m_nObjectID);
    wxGxObject* pGxObject2 = m_pCatalog->GetRegisterObject(pData2->m_nObjectID);
    return GxObjectCompareFunction(pGxObject1, pGxObject2, 1);
}
Esempio n. 2
0
int wxCALLBACK GxObjectCVCompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)
{
    wxGxCatalogBase* pCatalog = GetGxCatalog();
    if(!pCatalog)
        return 0;

    wxGxContentView::LPITEMDATA pItem1 = (wxGxContentView::LPITEMDATA)item1;
 	wxGxContentView::LPITEMDATA pItem2 = (wxGxContentView::LPITEMDATA)item2;
    LPSORTDATA psortdata = (LPSORTDATA)sortData;

    wxGxObject* pGxObject1 = pCatalog->GetRegisterObject(pItem1->nObjectID);
    wxGxObject* pGxObject2 = pCatalog->GetRegisterObject(pItem2->nObjectID);

    if(psortdata->currentSortCol == 0)
        return GxObjectCompareFunction(pGxObject1, pGxObject2, psortdata->bSortAsc);
    else
    {
	    IGxObjectSort* pGxObjectSort1 = dynamic_cast<IGxObjectSort*>(pGxObject1);
        IGxObjectSort* pGxObjectSort2 = dynamic_cast<IGxObjectSort*>(pGxObject2);
        if(pGxObjectSort1 && !pGxObjectSort2)
		    return psortdata->bSortAsc == 0 ? 1 : -1;
        if(!pGxObjectSort1 && pGxObjectSort2)
		    return psortdata->bSortAsc == 0 ? -1 : 1;
        if(pGxObjectSort1 && pGxObjectSort2)
        {
            bool bAlwaysTop1 = pGxObjectSort1->IsAlwaysTop();
            bool bAlwaysTop2 = pGxObjectSort2->IsAlwaysTop();
            if(bAlwaysTop1 && !bAlwaysTop2)
		        return psortdata->bSortAsc == 0 ? 1 : -1;
            if(!bAlwaysTop1 && bAlwaysTop2)
		        return psortdata->bSortAsc == 0 ? -1 : 1;
            bool bSortEnables1 = pGxObjectSort1->IsSortEnabled();
            bool bSortEnables2 = pGxObjectSort2->IsSortEnabled();
            if(!bSortEnables1 || !bSortEnables1)
                return 0;
        }

        bool bContainerDst1 = pGxObject1->IsKindOf(wxCLASSINFO(wxGxDataset)) || pGxObject1->IsKindOf(wxCLASSINFO(wxGxDatasetContainer));
        bool bContainerDst2 = pGxObject2->IsKindOf(wxCLASSINFO(wxGxDataset)) || pGxObject2->IsKindOf(wxCLASSINFO(wxGxDatasetContainer));
        bool bContainer1 = pGxObject1->IsKindOf(wxCLASSINFO(wxGxObjectContainer));
        bool bContainer2 = pGxObject2->IsKindOf(wxCLASSINFO(wxGxObjectContainer));
        if(bContainer1 && !bContainerDst1 && bContainerDst2)
	        return psortdata->bSortAsc == 0 ? 1 : -1;
        if(bContainer2 && !bContainerDst2 && bContainerDst1)
	        return psortdata->bSortAsc == 0 ? -1 : 1;
        if(bContainer1 && !bContainer2)
	        return psortdata->bSortAsc == 0 ? 1 : -1;
        if(!bContainer1 && bContainer2)
	        return psortdata->bSortAsc == 0 ? -1 : 1;

        if(psortdata->currentSortCol == 1)
        {
            return pGxObject1->GetCategory().CmpNoCase(pGxObject2->GetCategory()) * (psortdata->bSortAsc == 0 ? -1 : 1);
        }
        else if(psortdata->currentSortCol == 2)
        {
            if(!bContainerDst1 && bContainerDst2)
                return psortdata->bSortAsc == 0 ? -1 : 1;
            else if(bContainerDst1 && !bContainerDst2)
                return psortdata->bSortAsc == 0 ? 1 : -1;
            else if(!bContainerDst1 && !bContainerDst2)
                return 0;
            else
            {
                IGxDataset* pDSt1 = dynamic_cast<IGxDataset*>(pGxObject1);
                IGxDataset* pDSt2 = dynamic_cast<IGxDataset*>(pGxObject2);
                long diff = long(pDSt1->GetSize().ToULong()) - long(pDSt2->GetSize().ToULong());
                return diff * (psortdata->bSortAsc == 0 ? -1 : 1);
            }
        }
        else if(psortdata->currentSortCol == 3)
        {
            if(!bContainerDst1 && bContainerDst2)
                return psortdata->bSortAsc == 0 ? 1 : -1;
            else if(bContainerDst1 && !bContainerDst2)
                return psortdata->bSortAsc == 0 ? -1 : 1;
            else if(!bContainerDst1 && !bContainerDst2)
                return 0;
            else
            {
                IGxDataset* pDSt1 = dynamic_cast<IGxDataset*>(pGxObject1);
                IGxDataset* pDSt2 = dynamic_cast<IGxDataset*>(pGxObject2);
                return (pDSt1->GetModificationDate() - pDSt2->GetModificationDate()).GetSeconds().ToLong() * (psortdata->bSortAsc == 0 ? -1 : 1);
            }
        }
    }
    return 0;
}