2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // DiagramItemGroup.h (Cortex/DiagramView)
35 // c.lenz 28sep99 Begun
37 #ifndef DIAGRAM_ITEM_GROUP_H
38 #define DIAGRAM_ITEM_GROUP_H
41 #include "cortex_defs.h"
43 #include "DiagramItem.h"
50 __BEGIN_CORTEX_NAMESPACE
53 class DiagramItemGroup
{
55 DiagramItemGroup(uint32 acceptedTypes
, bool multiSelection
= true);
56 virtual ~DiagramItemGroup();
59 // is called whenever the current selection has changed
60 virtual void SelectionChanged()
66 uint32
CountItems(uint32 whichType
= DiagramItem::M_ANY
) const;
67 DiagramItem
* ItemAt(uint32 index
,
68 uint32 whichType
= DiagramItem::M_ANY
) const;
69 DiagramItem
* ItemUnder(BPoint point
);
73 virtual bool AddItem(DiagramItem
* item
);
74 bool RemoveItem(DiagramItem
* item
);
75 void SortItems(uint32 itemType
,
76 int (*compareFunc
)(const void *, const void *));
77 void DrawItems(BRect updateRect
, uint32 whichType
= DiagramItem::M_ANY
,
78 BRegion
*updateRegion
= 0);
79 bool GetClippingAbove(DiagramItem
* which
, BRegion
* outRegion
);
81 // selection accessors
83 uint32
SelectedType() const;
84 uint32
CountSelectedItems() const;
85 DiagramItem
* SelectedItemAt(uint32 index
) const;
87 // returns the ability of the group to handle multiple selections
88 // as set in the constructor
89 bool MultipleSelection() const
91 return fMultiSelection
;
94 // selection related operations
96 bool SelectItem(DiagramItem
* which
, bool deselectOthers
= true);
97 bool DeselectItem(DiagramItem
*which
);
98 void SortSelectedItems(int (*compareFunc
)(const void *, const void *));
99 bool SelectAll(uint32 itemType
= DiagramItem::M_ANY
);
100 bool DeselectAll(uint32 itemType
= DiagramItem::M_ANY
);
101 void DragSelectionBy(float x
, float y
, BRegion
*updateRegion
);
102 void RemoveSelection();
106 // set/get the 'item alignment' grid size; this is used when
107 // items are being dragged and inserted
108 void SetItemAlignment(float horizontal
, float vertical
)
110 fItemAlignment
.Set(horizontal
, vertical
);
113 void GetItemAlignment(float *horizontal
, float *vertical
);
114 void Align(float *x
, float *y
) const;
115 BPoint
Align(BPoint point
) const;
117 protected: // accessors
119 /*! Returns a pointer to the last item returned by the ItemUnder()
120 function; this can be used by deriving classes to implement a
123 DiagramItem
* _LastItemUnder()
125 return fLastItemUnder
;
128 void _ResetItemUnder()
133 private: // data members
135 // pointers to the item-lists (one list for each item type)
141 // pointer to the list containing the current selection
144 // the DiagramItem type(s) of items this group will accept
146 BPoint fItemAlignment
;
147 // specifies the "grid"-size for the frames of items
149 bool fMultiSelection
;
150 // can multiple items be selected at once ?
152 DiagramItem
* fLastItemUnder
;
153 // cached pointer to the item that was found in ItemUnder()
156 __END_CORTEX_NAMESPACE
157 #endif // DIAGRAM_ITEM_GROUP_H