1 // DiagramItemGroup.h (Cortex/DiagramView) 2 // 3 // * HISTORY 4 // c.lenz 28sep99 Begun 5 // 6 #ifndef DIAGRAM_ITEM_GROUP_H 7 #define DIAGRAM_ITEM_GROUP_H 8 9 10 #include "cortex_defs.h" 11 12 #include "DiagramItem.h" 13 14 #include <List.h> 15 #include <Point.h> 16 17 18 19 __BEGIN_CORTEX_NAMESPACE 20 21 22 class DiagramItemGroup { 23 public: 24 DiagramItemGroup(uint32 acceptedTypes, bool multiSelection = true); 25 virtual ~DiagramItemGroup(); 26 27 // hook function 28 // is called whenever the current selection has changed 29 virtual void SelectionChanged() 30 { 31 } 32 33 // item accessors 34 35 uint32 CountItems(uint32 whichType = DiagramItem::M_ANY) const; 36 DiagramItem* ItemAt(uint32 index, 37 uint32 whichType = DiagramItem::M_ANY) const; 38 DiagramItem* ItemUnder(BPoint point); 39 40 // item operations 41 42 virtual bool AddItem(DiagramItem* item); 43 bool RemoveItem(DiagramItem* item); 44 void SortItems(uint32 itemType, 45 int (*compareFunc)(const void *, const void *)); 46 void DrawItems(BRect updateRect, uint32 whichType = DiagramItem::M_ANY, 47 BRegion *updateRegion = 0); 48 bool GetClippingAbove(DiagramItem* which, BRegion* outRegion); 49 50 // selection accessors 51 52 uint32 SelectedType() const; 53 uint32 CountSelectedItems() const; 54 DiagramItem* SelectedItemAt(uint32 index) const; 55 56 // returns the ability of the group to handle multiple selections 57 // as set in the constructor 58 bool MultipleSelection() const 59 { 60 return fMultiSelection; 61 } 62 63 // selection related operations 64 65 bool SelectItem(DiagramItem* which, bool deselectOthers = true); 66 bool DeselectItem(DiagramItem *which); 67 void SortSelectedItems(int (*compareFunc)(const void *, const void *)); 68 bool SelectAll(uint32 itemType = DiagramItem::M_ANY); 69 bool DeselectAll(uint32 itemType = DiagramItem::M_ANY); 70 void DragSelectionBy(float x, float y, BRegion *updateRegion); 71 void RemoveSelection(); 72 73 // alignment related 74 75 // set/get the 'item alignment' grid size; this is used when 76 // items are being dragged and inserted 77 void SetItemAlignment(float horizontal, float vertical) 78 { 79 fItemAlignment.Set(horizontal, vertical); 80 } 81 82 void GetItemAlignment(float *horizontal, float *vertical); 83 void Align(float *x, float *y) const; 84 BPoint Align(BPoint point) const; 85 86 protected: // accessors 87 88 /*! Returns a pointer to the last item returned by the ItemUnder() 89 function; this can be used by deriving classes to implement a 90 transit system 91 */ 92 DiagramItem* _LastItemUnder() 93 { 94 return fLastItemUnder; 95 } 96 97 void _ResetItemUnder() 98 { 99 fLastItemUnder = 0; 100 } 101 102 private: // data members 103 104 // pointers to the item-lists (one list for each item type) 105 BList* fBoxes; 106 BList* fWires; 107 BList* fEndPoints; 108 109 BList* fSelection; 110 // pointer to the list containing the current selection 111 112 uint32 fTypes; 113 // the DiagramItem type(s) of items this group will accept 114 115 BPoint fItemAlignment; 116 // specifies the "grid"-size for the frames of items 117 118 bool fMultiSelection; 119 // can multiple items be selected at once ? 120 121 DiagramItem* fLastItemUnder; 122 // cached pointer to the item that was found in ItemUnder() 123 }; 124 125 __END_CORTEX_NAMESPACE 126 #endif // DIAGRAM_ITEM_GROUP_H 127