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