* Implemented BOutlineListView::FullListSortItems() and SortItemsUnder() - dunno

what Be's implementation did wrong but instead of taking almost 30 seconds to
  sort the MIME type database (roughly 1100 entries, and yes, that's why the
  original FileTypes is that slow when it has to show the internal types), this
  one needs only 4 ms for the same task (that's an amply 7500x speedup).
* Implemented some more missing functions - it's by no means complete yet, though.
* Rewrote OutlineListView.h, ListItem.h, and StringItem.h.
* Fixed some minor bugs, but there are probably a lot more.
* Major cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16349 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-02-11 15:23:23 +00:00
parent 3da4d36c6a
commit 7c74b12b2a
4 changed files with 759 additions and 609 deletions

View File

@ -1,17 +1,11 @@
/*******************************************************************************
/
/ File: ListItem.h
/
/ Description: BListView represents a one-dimensional list view.
/
/ Copyright 1996-98, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _LIST_ITEM_H
#define _LIST_ITEM_H
#include <BeBuild.h>
#include <Archivable.h>
#include <Rect.h>
@ -20,68 +14,64 @@ class BMessage;
class BOutlineListView;
class BView;
/*----------------------------------------------------------------*/
/*----- BListItem class ------------------------------------------*/
class BListItem : public BArchivable {
public:
BListItem(uint32 outlineLevel = 0, bool expanded = true);
BListItem(BMessage *data);
virtual ~BListItem();
virtual status_t Archive(BMessage *data, bool deep = true) const;
public:
BListItem(uint32 outlineLevel = 0, bool expanded = true);
BListItem(BMessage* archive);
virtual ~BListItem();
float Height() const;
float Width() const;
bool IsSelected() const;
void Select();
void Deselect();
virtual status_t Archive(BMessage* archive, bool deep = true) const;
virtual void SetEnabled(bool on);
bool IsEnabled() const;
float Height() const;
float Width() const;
bool IsSelected() const;
void Select();
void Deselect();
void SetHeight(float height);
void SetWidth(float width);
virtual void DrawItem(BView *owner,
BRect bounds,
bool complete = false) = 0;
virtual void Update(BView *owner, const BFont *font);
virtual void SetEnabled(bool enabled);
bool IsEnabled() const;
virtual status_t Perform(perform_code d, void *arg);
void SetHeight(float height);
void SetWidth(float width);
virtual void DrawItem(BView* owner, BRect frame,
bool complete = false) = 0;
virtual void Update(BView* owner, const BFont* font);
bool IsExpanded() const;
void SetExpanded(bool expanded);
uint32 OutlineLevel() const;
virtual status_t Perform(perform_code code, void* arg);
/*----- Private or reserved -----------------------------------------*/
private:
friend class BOutlineListView;
bool IsExpanded() const;
void SetExpanded(bool expanded);
uint32 OutlineLevel() const;
bool HasSubitems() const;
private:
friend class BOutlineListView;
virtual void _ReservedListItem1();
virtual void _ReservedListItem2();
bool HasSubitems() const;
BListItem(const BListItem &);
BListItem &operator=(const BListItem &);
virtual void _ReservedListItem1();
virtual void _ReservedListItem2();
/* calls used by BOutlineListView*/
bool IsItemVisible() const;
void SetItemVisible(bool);
BListItem(const BListItem& item);
BListItem& operator=(const BListItem& item);
uint32 _reserved[2];
float fWidth;
float fHeight;
uint32 fLevel;
bool fSelected;
bool fEnabled;
bool fExpanded;
bool fHasSubitems : 1;
bool fVisible : 1;
bool IsItemVisible() const;
void SetItemVisible(bool visible);
private:
uint32 _reserved[1];
BList* fTemporaryList;
float fWidth;
float fHeight;
uint32 fLevel;
bool fSelected;
bool fEnabled;
bool fExpanded;
bool fHasSubitems : 1;
bool fVisible : 1;
};
#include <StringItem.h>
// to maintain source compatibility
/*-------------------------------------------------------------*/
#include <StringItem.h> /* to maintain compatibility */
#endif /* _LIST_ITEM_H */
#endif // _LIST_ITEM_H

View File

@ -1,156 +1,137 @@
/*******************************************************************************
/
/ File: OutlineListView.h
/
/ Description: BOutlineListView represents a "nestable" list view.
/
/ Copyright 1997-98, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _OUTLINE_LIST_VIEW_H
#define _OUTLINE_LIST_VIEW_H
#include <BeBuild.h>
#include <ListView.h>
class BListItem;
/*----------------------------------------------------------------*/
/*----- BOutlineListView class -----------------------------------*/
class BOutlineListView : public BListView {
public:
BOutlineListView(BRect frame,
const char * name,
list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
| B_NAVIGABLE);
BOutlineListView(BMessage *data);
virtual ~BOutlineListView();
public:
BOutlineListView(BRect frame, const char* name,
list_view_type type = B_SINGLE_SELECTION_LIST,
uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
| B_NAVIGABLE);
BOutlineListView(BMessage* archive);
virtual ~BOutlineListView();
static BArchivable *Instantiate(BMessage *data);
virtual status_t Archive(BMessage *data, bool deep = true) const;
static BArchivable* Instantiate(BMessage* archive);
virtual status_t Archive(BMessage* archive, bool deep = true) const;
virtual void MouseDown(BPoint where);
virtual void KeyDown(const char *bytes, int32 numBytes);
virtual void FrameMoved(BPoint new_position);
virtual void FrameResized(float new_width, float new_height);
virtual void MouseUp(BPoint where);
virtual bool AddUnder(BListItem *item, BListItem *underItem);
virtual void MouseDown(BPoint where);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void FrameMoved(BPoint newPosition);
virtual void FrameResized(float newWidth, float newHeight);
virtual void MouseUp(BPoint where);
virtual bool AddItem(BListItem *item);
virtual bool AddItem(BListItem *item, int32 fullListIndex);
virtual bool AddList(BList *newItems);
virtual bool AddList(BList *newItems, int32 fullListIndex);
virtual bool AddUnder(BListItem* item, BListItem* underItem);
virtual bool RemoveItem(BListItem *item);
virtual BListItem *RemoveItem(int32 fullListIndex);
virtual bool RemoveItems(int32 fullListIndex, int32 count);
virtual bool AddItem(BListItem* item);
virtual bool AddItem(BListItem* item, int32 fullListIndex);
virtual bool AddList(BList* newItems);
virtual bool AddList(BList* newItems, int32 fullListIndex);
virtual bool RemoveItem(BListItem* item);
virtual BListItem* RemoveItem(int32 fullListIndex);
virtual bool RemoveItems(int32 fullListIndex, int32 count);
/* The following calls operator on the full outlinelist */
BListItem *FullListItemAt(int32 fullListIndex) const;
int32 FullListIndexOf(BPoint point) const;
int32 FullListIndexOf(BListItem *item) const;
BListItem *FullListFirstItem() const;
BListItem *FullListLastItem() const;
bool FullListHasItem(BListItem *item) const;
int32 FullListCountItems() const;
int32 FullListCurrentSelection(int32 index = 0) const;
virtual void MakeEmpty();
bool FullListIsEmpty() const;
void FullListDoForEach(bool (*func)(BListItem *));
void FullListDoForEach(bool (*func)(BListItem *, void *), void*);
BListItem* FullListItemAt(int32 fullListIndex) const;
int32 FullListIndexOf(BPoint point) const;
int32 FullListIndexOf(BListItem* item) const;
BListItem* FullListFirstItem() const;
BListItem* FullListLastItem() const;
bool FullListHasItem(BListItem* item) const;
int32 FullListCountItems() const;
int32 FullListCurrentSelection(int32 index = 0) const;
BListItem *Superitem(const BListItem *item);
virtual void MakeEmpty();
bool FullListIsEmpty() const;
void FullListDoForEach(bool (*func)(BListItem* item));
void FullListDoForEach(bool (*func)(BListItem* item, void *), void*);
void Expand(BListItem *item);
void Collapse(BListItem *item);
bool IsExpanded(int32 fullListIndex);
BListItem* Superitem(const BListItem* item);
virtual BHandler *ResolveSpecifier(BMessage *msg,
int32 index,
BMessage *specifier,
int32 form,
const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
virtual status_t Perform(perform_code d, void *arg);
void Expand(BListItem* item);
void Collapse(BListItem* item);
virtual void ResizeToPreferred();
virtual void GetPreferredSize(float *width, float *height);
virtual void MakeFocus(bool state = true);
virtual void AllAttached();
virtual void AllDetached();
virtual void DetachedFromWindow();
bool IsExpanded(int32 fullListIndex);
virtual BHandler* ResolveSpecifier(BMessage* message, int32 index,
BMessage* specifier, int32 what, const char* property);
virtual status_t GetSupportedSuites(BMessage* data);
virtual status_t Perform(perform_code d, void* arg);
virtual void ResizeToPreferred();
virtual void GetPreferredSize(float* _width, float* _height);
virtual void MakeFocus(bool focus = true);
virtual void AllAttached();
virtual void AllDetached();
virtual void DetachedFromWindow();
void FullListSortItems(int (*compareFunc)(const BListItem *,
const BListItem *));
void SortItemsUnder(BListItem *underItem,
bool oneLevelOnly,
int (*compareFunc)(const BListItem *,
const BListItem*));
int32 CountItemsUnder(BListItem *under, bool oneLevelOnly) const;
BListItem *EachItemUnder(BListItem *underItem,
bool oneLevelOnly,
BListItem *(*eachFunc)(BListItem *, void *),
void *);
BListItem *ItemUnderAt(BListItem *underItem,
bool oneLevelOnly,
void FullListSortItems(int (*compareFunc)(const BListItem* first,
const BListItem* second));
void SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
int (*compareFunc)(const BListItem* first,
const BListItem* second));
int32 CountItemsUnder(BListItem* under, bool oneLevelOnly) const;
BListItem* EachItemUnder(BListItem* underItem, bool oneLevelOnly,
BListItem* (*eachFunc)(BListItem* item, void* arg),
void* arg);
BListItem* ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
int32 index) const;
protected:
virtual bool DoMiscellaneous(MiscCode code, MiscData * data);
virtual void MessageReceived(BMessage *);
protected:
virtual bool DoMiscellaneous(MiscCode code, MiscData* data);
virtual void MessageReceived(BMessage *message);
/*----- Private or reserved -----------------------------------------*/
private:
virtual void _ReservedOutlineListView1();
virtual void _ReservedOutlineListView2();
virtual void _ReservedOutlineListView3();
virtual void _ReservedOutlineListView4();
private:
virtual void _ReservedOutlineListView1();
virtual void _ReservedOutlineListView2();
virtual void _ReservedOutlineListView3();
virtual void _ReservedOutlineListView4();
typedef BListView _inherited;
typedef BListView _inherited;
int32 FullListIndex(int32 index) const;
int32 ListViewIndex(int32 index) const;
int32 FullListIndex(int32 index) const;
int32 ListViewIndex(int32 index) const;
#if !_PR3_COMPATIBLE_
protected:
#endif
virtual void ExpandOrCollapse(BListItem *underItem, bool expand);
protected:
virtual void ExpandOrCollapse(BListItem* underItem, bool expand);
virtual BRect LatchRect(BRect itemRect, int32 level) const;
virtual void DrawLatch(BRect itemRect, int32 level, bool collapsed,
bool highlighted, bool misTracked);
virtual void DrawItem(BListItem* item, BRect itemRect, bool complete = false);
private:
private:
void _PopulateTree(BList* tree, BList& target,
int32& firstIndex, bool onlyVisible);
void _SortTree(BList* tree, bool oneLevelOnly,
int (*compareFunc)(const BListItem* a, const BListItem* b));
void _DestructTree(BList* tree);
BList* _BuildTree(BListItem* underItem, int32& index);
virtual BRect LatchRect(BRect itemRect, int32 level) const;
virtual void DrawLatch(BRect itemRect, int32 level, bool collapsed,
bool highlighted, bool misTracked);
virtual void DrawItem(BListItem *i, BRect cRect, bool complete = false);
BListItem* RemoveCommon(int32 fullListIndex);
BListItem* RemoveOne(int32 fullListIndex);
BListItem *RemoveCommon(int32 fullListIndex);
BListItem *RemoveOne(int32 fullListIndex);
static void TrackInLatchItem(void *);
static void TrackOutLatchItem(void *);
static void TrackInLatchItem(void *);
static void TrackOutLatchItem(void *);
bool OutlineSwapItems(int32 a, int32 b);
bool OutlineMoveItem(int32 from, int32 to);
bool OutlineReplaceItem(int32 index, BListItem* item);
void CommonMoveItems(int32 from, int32 count, int32 to);
BListItem* SuperitemForIndex(int32 fullListIndex, int32 level);
int32 FindPreviousVisibleIndex(int32 fullListIndex);
bool OutlineSwapItems(int32 a, int32 b);
bool OutlineMoveItem(int32 from, int32 to);
bool OutlineReplaceItem(int32 index, BListItem *item);
void CommonMoveItems(int32 from, int32 count, int32 to);
BListItem *SuperitemForIndex(int32 fullListIndex, int32 level);
int32 FindPreviousVisibleIndex(int32 fullListIndex);
BList fullList;
uint32 _reserved[2];
private:
BList fFullList;
uint32 _reserved[2];
};
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
#endif /* _OUTLINE_LIST_VIEW_H */
#endif // _OUTLINE_LIST_VIEW_H

View File

@ -1,58 +1,42 @@
////////////////////////////////////////////////////////////////////////////////
//
// File: StringItem.h
//
// Description:
//
// Copyright 2001, Ulrich Wimboeck
//
////////////////////////////////////////////////////////////////////////////////
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _STRING_ITEM_H
#define _STRING_ITEM_H
#include <ListItem.h>
#ifdef USE_OPENBEOS_NAMESPACE
namespace OpenBeOS {
#endif
class BStringItem : public BListItem {
public:
BStringItem(const char* text, uint32 outlineLevel = 0,
bool expanded = true);
BStringItem(BMessage* archive);
virtual ~BStringItem();
static BArchivable* Instantiate(BMessage* archive);
virtual status_t Archive(BMessage* archive, bool deep = true) const;
//----- BStringItem class ----------------------------------------
virtual void DrawItem(BView* owner, BRect frame, bool complete = false);
virtual void SetText(const char* text);
const char* Text() const;
class BStringItem : public BListItem
{
public:
BStringItem(const char *text, uint32 outlineLevel = 0, bool expanded = true);
BStringItem(BMessage *data);
virtual ~BStringItem();
virtual void Update(BView* owner, const BFont* font);
static BArchivable *Instantiate(BMessage *data);
virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual status_t Perform(perform_code code, void* arg);
virtual void DrawItem(BView *owner, BRect frame, bool complete = false);
virtual void SetText(const char *text);
const char *Text() const;
private:
virtual void _ReservedStringItem1();
virtual void _ReservedStringItem2();
virtual void Update(BView *owner, const BFont *font);
BStringItem(const BStringItem& item);
BStringItem& operator=(const BStringItem& item);
virtual status_t Perform(perform_code code, void *arg);
private:
virtual void _ReservedStringItem1();
virtual void _ReservedStringItem2();
BStringItem(const BStringItem &);
BStringItem& operator=(const BStringItem &);
char *fText;
float fBaselineOffset;
uint32 _reserved[2];
char* fText;
float fBaselineOffset;
uint32 _reserved[2];
};
#ifdef USE_OPENBEOS_NAMESPACE
}
#endif
#endif /* _STRING_ITEM_H */
#endif // _STRING_ITEM_H

File diff suppressed because it is too large Load Diff