1 /* 2 * Copyright 2001-2009, Haiku Inc. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _SHELF_H 6 #define _SHELF_H 7 8 #include <Dragger.h> 9 #include <Handler.h> 10 #include <List.h> 11 #include <Locker.h> 12 #include <String.h> 13 14 #include <map> 15 #include <utility> 16 17 class BDataIO; 18 class BPoint; 19 class BView; 20 class BEntry; 21 class _BZombieReplicantView_; 22 struct entry_ref; 23 24 namespace BPrivate { 25 class replicant_data; 26 class ShelfContainerViewFilter; 27 }; 28 29 30 class BShelf : public BHandler { 31 public: 32 BShelf(BView* view, bool allowDrags = true, const char* shelfType = NULL); 33 BShelf(const entry_ref* ref, BView* view, bool allowDrags = true, 34 const char* shelfType = NULL); 35 BShelf(BDataIO* stream, BView* view, bool allowDrags = true, 36 const char* shelfType = NULL); 37 BShelf(BMessage *data); 38 virtual ~BShelf(); 39 40 virtual status_t Archive(BMessage* data, bool deep = true) const; 41 static BArchivable* Instantiate(BMessage* archive); 42 43 virtual void MessageReceived(BMessage *msg); 44 status_t Save(); 45 virtual void SetDirty(bool state); 46 bool IsDirty() const; 47 48 virtual BHandler* ResolveSpecifier(BMessage *msg, 49 int32 index, BMessage *specifier, 50 int32 form, const char *property); 51 virtual status_t GetSupportedSuites(BMessage* data); 52 53 virtual status_t Perform(perform_code d, void *arg); 54 bool AllowsDragging() const; 55 void SetAllowsDragging(bool state); 56 bool AllowsZombies() const; 57 void SetAllowsZombies(bool state); 58 bool DisplaysZombies() const; 59 void SetDisplaysZombies(bool state); 60 bool IsTypeEnforced() const; 61 void SetTypeEnforced(bool state); 62 63 status_t SetSaveLocation(BDataIO *data_io); 64 status_t SetSaveLocation(const entry_ref *ref); 65 BDataIO* SaveLocation(entry_ref *ref) const; 66 67 status_t AddReplicant(BMessage *data, BPoint location); 68 status_t DeleteReplicant(BView *replicant); 69 status_t DeleteReplicant(BMessage *data); 70 status_t DeleteReplicant(int32 index); 71 int32 CountReplicants() const; 72 BMessage* ReplicantAt(int32 index, 73 BView **view = NULL, 74 uint32 *uid = NULL, 75 status_t *perr = NULL) const; 76 int32 IndexOf(const BView *replicantView) const; 77 int32 IndexOf(const BMessage *archive) const; 78 int32 IndexOf(uint32 id) const; 79 80 protected: 81 virtual bool CanAcceptReplicantMessage(BMessage*) const; 82 virtual bool CanAcceptReplicantView(BRect, BView*, BMessage*) const; 83 virtual BPoint AdjustReplicantBy(BRect, BMessage*) const; 84 85 virtual void ReplicantDeleted(int32 index, const BMessage *archive, 86 const BView *replicant); 87 88 private: 89 friend class BPrivate::ShelfContainerViewFilter; 90 91 virtual void _ReservedShelf2(); 92 virtual void _ReservedShelf3(); 93 virtual void _ReservedShelf4(); 94 virtual void _ReservedShelf5(); 95 virtual void _ReservedShelf6(); 96 virtual void _ReservedShelf7(); 97 virtual void _ReservedShelf8(); 98 99 BShelf(const BShelf& other); 100 BShelf& operator=(const BShelf& other); 101 102 status_t _Archive(BMessage* data) const; 103 void _InitData(BEntry* entry, BDataIO* stream, 104 BView* view, bool allowDrags); 105 status_t _DeleteReplicant(BPrivate::replicant_data* replicant); 106 status_t _AddReplicant(BMessage* data, 107 BPoint* location, uint32 uniqueID); 108 BView *_GetReplicant(BMessage *data, BView *view, const BPoint &point, 109 BDragger *&dragger, BDragger::relation &relation); 110 _BZombieReplicantView_ *_CreateZombie(BMessage *data, BDragger *&dragger); 111 112 status_t _GetProperty(BMessage* message, BMessage* reply); 113 static void _GetReplicantData(BMessage *message, BView *view, BView *&replicant, 114 BDragger *&dragger, BDragger::relation &relation); 115 static BArchivable* _InstantiateObject(BMessage *archive, image_id *image); 116 117 private: 118 BView* fContainerView; 119 BDataIO* fStream; 120 BEntry* fEntry; 121 BList fReplicants; 122 BPrivate::ShelfContainerViewFilter* fFilter; 123 uint32 fGenCount; 124 bool fAllowDragging; 125 bool fDirty; 126 bool fDisplayZombies; 127 bool fAllowZombies; 128 bool fTypeEnforced; 129 130 typedef std::map<BString, std::pair<image_id, int32> > LoadedImageMap; 131 static LoadedImageMap sLoadedImages; 132 static BLocker sLoadedImageMapLocker; 133 134 uint32 _reserved[8]; 135 }; 136 137 #endif /* _SHELF_H */ 138