wxInt32 SortRoutine(wxInt32 Order, wxListItem &Item1, wxListItem &Item2)
{
    if (Order == 1)
        return NaturalCompare(Item1.GetText(), Item2.GetText());

    return NaturalCompare(Item2.GetText(), Item1.GetText());
}
Example #2
0
int wxCALLBACK wxCompareFunction(wxIntPtr item1, wxIntPtr item2, 
                                 wxIntPtr sortData)
{
    wxInt32 SortCol, SortOrder;
    wxListItem Item;
    wxString Str1, Str2;
    wxAdvancedListCtrl *ListCtrl;
    
    ListCtrl = (wxAdvancedListCtrl *)sortData; 
    
    ListCtrl->GetSortColumnAndOrder(SortCol, SortOrder);
    
    Item.SetColumn(SortCol);
    Item.SetMask(wxLIST_MASK_TEXT);
    
    if (SortCol == ListCtrl->GetSpecialSortColumn())
    {
        int Img1, Img2;
        
        Item.SetMask(wxLIST_MASK_IMAGE);
        
        Item.SetId(item1);
    
        ListCtrl->GetItem(Item);
    
        Img1 = Item.GetImage();
    
        Item.SetId(item2);
    
        ListCtrl->GetItem(Item);
    
        Img2 = Item.GetImage();
        
        return SortOrder ? Img2 - Img1 : Img1 - Img2;
    }
    
    Item.SetId(item1);
    
    ListCtrl->GetItem(Item);
    
    Str1 = Item.GetText();
    
    Item.SetId(item2);
    
    ListCtrl->GetItem(Item);
    
    Str2 = Item.GetText();
    
    return SortOrder ? NaturalCompare(Str1, Str2) : NaturalCompare(Str2, Str1);
}
Example #3
0
int
BPackageVersion::Compare(const BPackageVersion& other) const
{
	int majorDiff = NaturalCompare(fMajor.String(), other.fMajor.String());
	if (majorDiff != 0)
		return majorDiff;

	int minorDiff = NaturalCompare(fMinor.String(), other.fMinor.String());
	if (minorDiff != 0)
		return minorDiff;

	int microDiff = NaturalCompare(fMicro.String(), other.fMicro.String());
	if (microDiff != 0)
		return microDiff;

	return (int)fRelease - (int)other.fRelease;
}
Example #4
0
/*static*/ int32
TWindowMenuItem::InsertIndexFor(BMenu* menu, int32 startIndex,
	TWindowMenuItem* newItem)
{
	for (int32 index = startIndex;; index++) {
		TWindowMenuItem* item
			= dynamic_cast<TWindowMenuItem*>(menu->ItemAt(index));
		if (item == NULL || NaturalCompare(item->FullTitle(),
				newItem->FullTitle()) > 0)
			return index;
	}
}
Example #5
0
int
StringAttributeText::Compare(WidgetAttributeText& attr, BPoseView* view)
{
	StringAttributeText* compareTo = dynamic_cast<StringAttributeText*>(&attr);
	ThrowOnAssert(compareTo != NULL);

	if (fValueDirty)
		ReadValue(&fFullValueText);

	return NaturalCompare(fFullValueText.String(),
		compareTo->ValueAsText(view));
}
Example #6
0
bool Utils::String::naturalCompareCaseInsensitive(const QString &left, const QString &right)
{
    // provide a single `NaturalCompare` instance for easy use
    // https://doc.qt.io/qt-5/threads-reentrancy.html
#ifdef Q_OS_MAC  // workaround for Apple xcode: https://stackoverflow.com/a/29929949
    static QThreadStorage<NaturalCompare> nCmp;
    if (!nCmp.hasLocalData()) nCmp.setLocalData(NaturalCompare(false));
    return (nCmp.localData())(left, right);
#else
    thread_local NaturalCompare nCmp(false);
    return nCmp(left, right);
#endif
}
Example #7
0
int
NameAttributeText::Compare(WidgetAttributeText& attr, BPoseView* view)
{
	NameAttributeText* compareTo = dynamic_cast<NameAttributeText*>(&attr);
	ThrowOnAssert(compareTo != NULL);

	if (fValueDirty)
		ReadValue(&fFullValueText);

	if (NameAttributeText::sSortFolderNamesFirst)
		return fModel->CompareFolderNamesFirst(attr.TargetModel());

	return NaturalCompare(fFullValueText.String(),
		compareTo->ValueAsText(view));
}
Example #8
0
int
Model::CompareFolderNamesFirst(const Model *compareModel) const
{
    if (compareModel == NULL)
        return -1;

    const Model *resolvedCompareModel = compareModel->ResolveIfLink();
    const Model *resolvedMe = ResolveIfLink();

    if (resolvedMe->IsVolume()) {
        if (!resolvedCompareModel->IsVolume())
            return -1;
    } else if (resolvedCompareModel->IsVolume())
        return 1;

    if (resolvedMe->IsDirectory()) {
        if (!resolvedCompareModel->IsDirectory())
            return -1;
    } else if (resolvedCompareModel->IsDirectory())
        return 1;

    return NaturalCompare(Name(), compareModel->Name());
}
Example #9
0
int
Model::CompareFolderNamesFirst(const Model* compareModel) const
{
	if (compareModel == NULL)
		return -1;

	const Model* resolvedCompareModel = compareModel->ResolveIfLink();
	const Model* resolvedMe = ResolveIfLink();

	bool meIsDirOrVolume = resolvedMe->IsDirectory() || resolvedMe->IsVolume()
		|| resolvedMe->IsVirtualDirectory();
	bool otherIsDirOrVolume = resolvedCompareModel->IsDirectory()
		|| resolvedCompareModel->IsVolume()
		|| resolvedCompareModel->IsVirtualDirectory();

	if (meIsDirOrVolume) {
		if (!otherIsDirOrVolume)
			return -1;
	} else if (otherIsDirOrVolume)
		return 1;

	return NaturalCompare(Name(), compareModel->Name());
}