xref: /haiku/headers/private/interface/ColumnListView.h (revision 2600324b57fa31cdea1627d584d314f2a579c4a8)
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 	virtual float		GetPreferredWidth(BField *field, BView *parent) const;
187 
188 			bool		IsVisible() const;
189 			void		SetVisible(bool);
190 
191 			bool		WantsEvents() const;
192 			void		SetWantsEvents(bool);
193 
194 			bool		ShowHeading() const;
195 			void		SetShowHeading(bool);
196 
197 			alignment	Alignment() const;
198 			void		SetAlignment(alignment);
199 
200 			int32		LogicalFieldNum() const;
201 
202 	/*!
203 		\param field The BField derivative to validate.
204 
205 			Implement this function on your BColumn derivatives to validate BField derivatives
206 			that your BColumn will be drawing/manipulating.
207 
208 			This function will be called when BFields are added to the Column, use dynamic_cast<> to
209 			determine if it is of a kind that your BColumn know how ot handle. return false if it is not.
210 
211 			\note The debugger will be called if you return false from here with information about
212 			      what type of BField and BColumn and the logical field index where it occured.
213 
214 			\note Do not call the inherited version of this, it just returns true;
215 	  */
216 	virtual	bool		AcceptsField(const BField* field) const;
217 
218 private:
219 	float			fWidth;
220 	float 			fMinWidth;
221 	float			fMaxWidth;
222 	bool			fVisible;
223 	int32			fFieldID;
224 	BColumnListView	*fList;
225 	bool			fSortAscending;
226 	bool			fWantsEvents;
227 	bool			fShowHeading;
228 	alignment		fAlignment;
229 
230 	friend class	BPrivate::OutlineView;
231 	friend class	BColumnListView;
232 	friend class	BPrivate::TitleView;
233 };
234 
235 // The column list view class.
236 class BColumnListView : public BView, public BInvoker
237 {
238 public:
239 							BColumnListView(BRect rect,
240 						                const char *name,
241 						                uint32 resizingMode,
242 										uint32 drawFlags,
243 										border_style = B_NO_BORDER,
244 										bool showHorizontalScrollbar = true);
245 	virtual					~BColumnListView();
246 
247 	// Interaction
248 	virtual bool			InitiateDrag(BPoint, bool wasSelected);
249 	virtual void			MessageDropped(BMessage*, BPoint point);
250 	virtual void			ExpandOrCollapse(BRow *row, bool expand);
251 	virtual status_t		Invoke(BMessage *message = NULL);
252 	virtual void			ItemInvoked();
253 	virtual void			SetInvocationMessage(BMessage*);
254 			BMessage* 		InvocationMessage() const;
255 			uint32 			InvocationCommand() const;
256 			BRow* 			FocusRow() const;
257 			void 			SetFocusRow(int32 index, bool select=false);
258 			void 			SetFocusRow(BRow *row, bool select=false);
259 			void 			SetMouseTrackingEnabled(bool);
260 
261 	// Selection
262 			list_view_type	SelectionMode() const;
263 			void 			Deselect(BRow *row);
264 			void 			AddToSelection(BRow *row);
265 			void 			DeselectAll();
266 			BRow*			CurrentSelection(BRow *lastSelected = 0) const;
267 	virtual void			SelectionChanged();
268 	virtual void			SetSelectionMessage(BMessage *);
269 			BMessage*		SelectionMessage();
270 			uint32			SelectionCommand() const;
271 			void			SetSelectionMode(list_view_type);  // list_view_type is defined in ListView.h.
272 
273 	// Sorting
274 			void			SetSortingEnabled(bool);
275 			bool			SortingEnabled() const;
276 			void			SetSortColumn(BColumn *column, bool add, bool ascending);
277 			void			ClearSortColumns();
278 
279 	// The status view is a little area in the lower left hand corner.
280 			void			AddStatusView(BView *view);
281 			BView*			RemoveStatusView();
282 
283 	// Column Manipulation
284 			void			AddColumn(BColumn*, int32 logicalFieldIndex);
285 			void			MoveColumn(BColumn*, int32 index);
286 			void			RemoveColumn(BColumn*);
287 			int32			CountColumns() const;
288 			BColumn*		ColumnAt(int32 index) const;
289 			void			SetColumnVisible(BColumn*, bool isVisible);
290 			void			SetColumnVisible(int32, bool);
291 			bool			IsColumnVisible(int32) const;
292 			void			SetColumnFlags(column_flags flags);
293 
294 	// Row manipulation
295 	const	BRow*			RowAt(int32 index, BRow *parent = 0) const;
296 			BRow*			RowAt(int32 index, BRow *parent = 0);
297 	const	BRow*			RowAt(BPoint) const;
298 			BRow*			RowAt(BPoint);
299 			bool			GetRowRect(const BRow *row, BRect *outRect) const;
300 			bool			FindParent(BRow *row, BRow **outs_parent, bool *out_isVisible) const;
301 			int32			IndexOf(BRow *row);
302 			int32			CountRows(BRow *parent = 0) const;
303 			void			AddRow(BRow*, BRow *parent = 0);
304 			void			AddRow(BRow*, int32 index, BRow *parent = 0);
305 
306 			void			ScrollTo(const BRow* Row);
307 
308 	// Does not delete row or children at this time.
309 	// todo: Make delete row and children
310 			void			RemoveRow(BRow*);
311 
312 			void			UpdateRow(BRow*);
313 			void			Clear();
314 
315 	// Appearance (DEPRECATED)
316 			void			GetFont(BFont* font) const {BView::GetFont(font);}
317 	virtual void			SetFont(const BFont *font, uint32 mask = B_FONT_ALL);
318 	virtual void			SetHighColor(rgb_color);
319 			void			SetSelectionColor(rgb_color);
320 			void			SetBackgroundColor(rgb_color);
321 			void			SetEditColor(rgb_color);
322 	const 	rgb_color		SelectionColor() const;
323 	const 	rgb_color		BackgroundColor() const;
324 	const 	rgb_color		EditColor() const;
325 
326 	// Appearance (NEW STYLE)
327 			void			SetColor(ColumnListViewColor color_num, rgb_color color);
328 			void			SetFont(ColumnListViewFont font_num, const BFont* font, uint32 mask = B_FONT_ALL);
329 			rgb_color		Color(ColumnListViewColor color_num) const;
330 			void			GetFont(ColumnListViewFont font_num, BFont* font) const;
331 
332 			BPoint			SuggestTextPosition(const BRow* row, const BColumn* column=NULL) const;
333 
334 			void			SetLatchWidth(float width);
335 			float			LatchWidth() const;
336 	virtual void			DrawLatch(BView*, BRect, LatchType, BRow*);
337 	virtual void			MakeFocus(bool isfocus = true);
338 			void			SaveState(BMessage *msg);
339 			void			LoadState(BMessage *msg);
340 
341 			BView*			ScrollView() const { return (BView *)fOutlineView; }
342 			void			SetEditMode(bool state);
343 			void			Refresh();
344 
345 protected:
346 	virtual void 			MessageReceived(BMessage *message);
347 	virtual void 			KeyDown(const char *bytes, int32 numBytes);
348 	virtual void 			AttachedToWindow();
349 	virtual void 			WindowActivated(bool active);
350 	virtual void 			Draw(BRect);
351 
352 private:
353 	rgb_color 				fColorList[B_COLOR_TOTAL];
354 	BPrivate::TitleView*	fTitleView;
355 	BPrivate::OutlineView*	fOutlineView;
356 	BList 					fColumns;
357 	BScrollBar*				fHorizontalScrollBar;
358 	BScrollBar* 			fVerticalScrollBar;
359 	BList					fSortColumns;
360 	BView*					fStatusView;
361 	BMessage*				fSelectionMessage;
362 	bool					fSortingEnabled;
363 	float					fLatchWidth;
364 	border_style			fBorderStyle;
365 };
366 
367 #endif
368