xref: /haiku/headers/private/interface/ColumnListView.h (revision ed6250c95736c0b55da79d6e9dd01369532260c0)
1 /*
2 Open Tracker License
3 
4 Terms and Conditions
5 
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
28 
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
33 */
34 
35 /*******************************************************************************
36 /
37 /	File:			ColumnListView.h
38 /
39 /   Description:    Experimental multi-column list view.
40 /
41 /	Copyright 2000+, Be Incorporated, All Rights Reserved
42 /
43 *******************************************************************************/
44 
45 
46 #ifndef _COLUMN_LIST_VIEW_H
47 #define _COLUMN_LIST_VIEW_H
48 
49 #include <BeBuild.h>
50 #include <View.h>
51 #include <List.h>
52 #include <Invoker.h>
53 #include <ListView.h>
54 
55 class BScrollBar;
56 
57 namespace BPrivate {
58 
59 class OutlineView;
60 class TitleView;
61 class BRowContainer;
62 class RecursiveOutlineIterator;
63 
64 }	// ns BPrivate
65 
66 class BField;
67 class BRow;
68 class BColumn;
69 class BColumnListView;
70 
71 enum LatchType {
72 	B_NO_LATCH,
73 	B_OPEN_LATCH,
74 	B_PRESSED_LATCH,
75 	B_CLOSED_LATCH
76 };
77 
78 typedef enum {
79 	B_ALLOW_COLUMN_NONE = 0,
80 	B_ALLOW_COLUMN_MOVE = 1,
81 	B_ALLOW_COLUMN_RESIZE = 2,
82 	B_ALLOW_COLUMN_POPUP = 4,
83 	B_ALLOW_COLUMN_REMOVE = 8,
84 } column_flags;
85 
86 enum ColumnListViewColor {
87 	B_COLOR_BACKGROUND			=  0,
88 	B_COLOR_TEXT				=  1,
89 	B_COLOR_ROW_DIVIDER			=  2,
90 	B_COLOR_SELECTION			=  3,
91 	B_COLOR_SELECTION_TEXT		=  4,
92 	B_COLOR_NON_FOCUS_SELECTION	=  5,
93 	B_COLOR_EDIT_BACKGROUND		=  6,
94 	B_COLOR_EDIT_TEXT			=  7,
95 	B_COLOR_HEADER_BACKGROUND	=  8,
96 	B_COLOR_HEADER_TEXT			=  9,
97 	B_COLOR_SEPARATOR_LINE		= 10,
98 	B_COLOR_SEPARATOR_BORDER	= 11,
99 
100 	B_COLOR_TOTAL				= 12
101 };
102 
103 enum ColumnListViewFont {
104 	B_FONT_ROW					=  0,
105 	B_FONT_HEADER				=  1,
106 
107 	B_FONT_TOTAL				=  2
108 };
109 
110 
111 // A single row/column intersection in the list.
112 class BField {
113 public:
114 						BField();
115 	virtual				~BField();
116 };
117 
118 // A single line in the list.  Each line contains a BField object
119 // for each column in the list, associated by their "logical field"
120 // index.  Hierarchies are formed by adding other BRow objects as
121 // a parent of a row, using the AddRow() function in BColumnListView().
122 class BRow {
123 public:
124 						BRow(float height = 16.0);
125 	virtual 			~BRow();
126 	virtual bool 		HasLatch() const;
127 
128 			int32		CountFields() const;
129 			BField*		GetField(int32 logicalFieldIndex);
130 	const	BField*		GetField(int32 logicalFieldIndex) const;
131 			void		SetField(BField* field, int32 logicalFieldIndex);
132 
133 			float 		Height() const;
134 			bool 		IsExpanded() const;
135 
136 private:
137 	// Blows up into the debugger if the validation fails.
138 			void		ValidateFields() const;
139 			void		ValidateField(const BField *field, int32 logicalFieldIndex) const;
140 private:
141 	BList				fFields;
142 	BPrivate::
143 	BRowContainer*		fChildList;
144 	bool				fIsExpanded;
145 	float				fHeight;
146 	BRow*				fNextSelected;
147 	BRow*				fPrevSelected;
148 	BRow*				fParent;
149 	BColumnListView*	fList;
150 
151 
152 	friend class BColumnListView;
153 	friend class BPrivate::RecursiveOutlineIterator;
154 	friend class BPrivate::OutlineView;
155 };
156 
157 // Information about a single column in the list.  A column knows
158 // how to display the BField objects that occur at its location in
159 // each of the list's rows.  See ColumnTypes.h for particular
160 // subclasses of BField and BColumn that handle common data types.
161 class BColumn
162 {
163 public:
164 						BColumn(float width,
165 						        float minWidth,
166 						        float maxWidth,
167 						        alignment align = B_ALIGN_LEFT);
168 	virtual 			~BColumn();
169 
170 			float		Width() const;
171 			void		SetWidth(float width);
172 			float		MinWidth() const;
173 			float		MaxWidth() const;
174 
175 	virtual void		DrawTitle(BRect rect, BView *targetView);
176 	virtual void		DrawField(BField *field, BRect rect, BView *targetView);
177 	virtual int			CompareFields(BField *field1, BField *field2);
178 
179 	virtual void		MouseMoved(BColumnListView *parent, BRow *row, BField *field,
180 					               BRect field_rect, BPoint point, uint32 buttons, int32 code);
181 	virtual void		MouseDown(BColumnListView *parent, BRow *row, BField *field,
182 					              BRect field_rect, BPoint point, uint32 buttons);
183 	virtual	void		MouseUp(BColumnListView *parent, BRow *row, BField *field);
184 
185 	virtual void		GetColumnName(BString* into) const;
186 
187 			bool		IsVisible() const;
188 			void		SetVisible(bool);
189 
190 			bool		WantsEvents() const;
191 			void		SetWantsEvents(bool);
192 
193 			bool		ShowHeading() const;
194 			void		SetShowHeading(bool);
195 
196 			alignment	Alignment() const;
197 			void		SetAlignment(alignment);
198 
199 			int32		LogicalFieldNum() const;
200 
201 	/*!
202 		\param field The BField derivative to validate.
203 
204 			Implement this function on your BColumn derivatives to validate BField derivatives
205 			that your BColumn will be drawing/manipulating.
206 
207 			This function will be called when BFields are added to the Column, use dynamic_cast<> to
208 			determine if it is of a kind that your BColumn know how ot handle. return false if it is not.
209 
210 			\note The debugger will be called if you return false from here with information about
211 			      what type of BField and BColumn and the logical field index where it occured.
212 
213 			\note Do not call the inherited version of this, it just returns true;
214 	  */
215 	virtual	bool		AcceptsField(const BField* field) const;
216 
217 private:
218 	float			fWidth;
219 	float 			fMinWidth;
220 	float			fMaxWidth;
221 	bool			fVisible;
222 	int32			fFieldID;
223 	BColumnListView	*fList;
224 	bool			fSortAscending;
225 	bool			fWantsEvents;
226 	bool			fShowHeading;
227 	alignment		fAlignment;
228 
229 	friend class	BPrivate::OutlineView;
230 	friend class	BColumnListView;
231 	friend class	BPrivate::TitleView;
232 };
233 
234 // The column list view class.
235 class BColumnListView : public BView, public BInvoker
236 {
237 public:
238 							BColumnListView(BRect rect,
239 						                const char *name,
240 						                uint32 resizingMode,
241 										uint32 drawFlags,
242 										border_style = B_NO_BORDER,
243 										bool showHorizontalScrollbar = true);
244 	virtual					~BColumnListView();
245 
246 	// Interaction
247 	virtual bool			InitiateDrag(BPoint, bool wasSelected);
248 	virtual void			MessageDropped(BMessage*, BPoint point);
249 	virtual void			ExpandOrCollapse(BRow *row, bool expand);
250 	virtual status_t		Invoke(BMessage *message = NULL);
251 	virtual void			ItemInvoked();
252 	virtual void			SetInvocationMessage(BMessage*);
253 			BMessage* 		InvocationMessage() const;
254 			uint32 			InvocationCommand() const;
255 			BRow* 			FocusRow() const;
256 			void 			SetFocusRow(int32 index, bool select=false);
257 			void 			SetFocusRow(BRow *row, bool select=false);
258 			void 			SetMouseTrackingEnabled(bool);
259 
260 	// Selection
261 			list_view_type	SelectionMode() const;
262 			void 			Deselect(BRow *row);
263 			void 			AddToSelection(BRow *row);
264 			void 			DeselectAll();
265 			BRow*			CurrentSelection(BRow *lastSelected = 0) const;
266 	virtual void			SelectionChanged();
267 	virtual void			SetSelectionMessage(BMessage *);
268 			BMessage*		SelectionMessage();
269 			uint32			SelectionCommand() const;
270 			void			SetSelectionMode(list_view_type);  // list_view_type is defined in ListView.h.
271 
272 	// Sorting
273 			void			SetSortingEnabled(bool);
274 			bool			SortingEnabled() const;
275 			void			SetSortColumn(BColumn *column, bool add, bool ascending);
276 			void			ClearSortColumns();
277 
278 	// The status view is a little area in the lower left hand corner.
279 			void			AddStatusView(BView *view);
280 			BView*			RemoveStatusView();
281 
282 	// Column Manipulation
283 			void			AddColumn(BColumn*, int32 logicalFieldIndex);
284 			void			MoveColumn(BColumn*, int32 index);
285 			void			RemoveColumn(BColumn*);
286 			int32			CountColumns() const;
287 			BColumn*		ColumnAt(int32 index) const;
288 			void			SetColumnVisible(BColumn*, bool isVisible);
289 			void			SetColumnVisible(int32, bool);
290 			bool			IsColumnVisible(int32) const;
291 			void			SetColumnFlags(column_flags flags);
292 
293 	// Row manipulation
294 	const	BRow*			RowAt(int32 index, BRow *parent = 0) const;
295 			BRow*			RowAt(int32 index, BRow *parent = 0);
296 	const	BRow*			RowAt(BPoint) const;
297 			BRow*			RowAt(BPoint);
298 			bool			GetRowRect(const BRow *row, BRect *outRect) const;
299 			bool			FindParent(BRow *row, BRow **outs_parent, bool *out_isVisible) const;
300 			int32			IndexOf(BRow *row);
301 			int32			CountRows(BRow *parent = 0) const;
302 			void			AddRow(BRow*, BRow *parent = 0);
303 			void			AddRow(BRow*, int32 index, BRow *parent = 0);
304 
305 			void			ScrollTo(const BRow* Row);
306 
307 	// Does not delete row or children at this time.
308 	// todo: Make delete row and children
309 			void			RemoveRow(BRow*);
310 
311 			void			UpdateRow(BRow*);
312 			void			Clear();
313 
314 	// Appearance (DEPRECATED)
315 			void			GetFont(BFont* font) const {BView::GetFont(font);}
316 	virtual void			SetFont(const BFont *font, uint32 mask = B_FONT_ALL);
317 	virtual void			SetHighColor(rgb_color);
318 			void			SetSelectionColor(rgb_color);
319 			void			SetBackgroundColor(rgb_color);
320 			void			SetEditColor(rgb_color);
321 	const 	rgb_color		SelectionColor() const;
322 	const 	rgb_color		BackgroundColor() const;
323 	const 	rgb_color		EditColor() const;
324 
325 	// Appearance (NEW STYLE)
326 			void			SetColor(ColumnListViewColor color_num, rgb_color color);
327 			void			SetFont(ColumnListViewFont font_num, const BFont* font, uint32 mask = B_FONT_ALL);
328 			rgb_color		Color(ColumnListViewColor color_num) const;
329 			void			GetFont(ColumnListViewFont font_num, BFont* font) const;
330 
331 			BPoint			SuggestTextPosition(const BRow* row, const BColumn* column=NULL) const;
332 
333 			void			SetLatchWidth(float width);
334 			float			LatchWidth() const;
335 	virtual void			DrawLatch(BView*, BRect, LatchType, BRow*);
336 	virtual void			MakeFocus(bool isfocus = true);
337 			void			SaveState(BMessage *msg);
338 			void			LoadState(BMessage *msg);
339 
340 			BView*			ScrollView() const { return (BView *)fOutlineView; }
341 			void			SetEditMode(bool state);
342 			void			Refresh();
343 
344 protected:
345 	virtual void 			MessageReceived(BMessage *message);
346 	virtual void 			KeyDown(const char *bytes, int32 numBytes);
347 	virtual void 			AttachedToWindow();
348 	virtual void 			WindowActivated(bool active);
349 	virtual void 			Draw(BRect);
350 
351 private:
352 	rgb_color 				fColorList[B_COLOR_TOTAL];
353 	BPrivate::TitleView*	fTitleView;
354 	BPrivate::OutlineView*	fOutlineView;
355 	BList 					fColumns;
356 	BScrollBar*				fHorizontalScrollBar;
357 	BScrollBar* 			fVerticalScrollBar;
358 	BList					fSortColumns;
359 	BView*					fStatusView;
360 	BMessage*				fSelectionMessage;
361 	bool					fSortingEnabled;
362 	float					fLatchWidth;
363 	border_style			fBorderStyle;
364 };
365 
366 #endif
367