xref: /haiku/src/kits/tracker/DialogPane.h (revision 25a7b01d15612846f332751841da3579db313082)
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 #ifndef _DIALOG_PANE_
35 #define _DIALOG_PANE_
36 
37 
38 #include <Control.h>
39 
40 #include "ObjectList.h"
41 
42 
43 namespace BPrivate {
44 
45 class ViewList : public BObjectList<BView> {
46 public:
47 								ViewList()
48 									:	BObjectList<BView>(5, true)
49 								{}
50 
51 			void				RemoveAll(BView* fromParent);
52 			void				AddAll(BView* toParent);
53 };
54 
55 
56 class DialogPane : public BView {
57 	// dialog with collapsible panes
58 public:
59 								DialogPane(BRect mode1Frame, BRect mode2Frame,
60 									int32 initialMode, const char* name,
61 									uint32 followFlags
62 										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
63 									uint32 flags = B_WILL_DRAW);
64 								DialogPane(BRect mode1Frame, BRect mode2Frame,
65 									BRect mode3Frame, int32 initialMode,
66 									const char* name, uint32 followFlags
67 										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
68 									uint32 flags = B_WILL_DRAW);
69 
70 	virtual						~DialogPane();
71 
72 			BRect				FrameForMode(int32);
73 			BRect				BoundsForMode(int32);
74 
75 			int32				Mode() const;
76 	virtual	void				SetMode(int32, bool initialSetup = false);
77 
78 			void				AddItem(BView*, int32 toMode);
79 
80 			void				SetSwitch(BControl*);
81 
82 	virtual	void				AttachedToWindow();
83 
84 protected:
85 			void				ResizeParentWindow(int32 from, int32 to);
86 	static	BRect				FrameForMode(int32, BRect, BRect, BRect);
87 		// called only by the constructor
88 
89 	virtual	void				MessageReceived(BMessage* message);
90 
91 private:
92 			int32				fMode;
93 
94 			BRect				fMode1Frame;
95 			BRect				fMode2Frame;
96 			BRect				fMode3Frame;
97 
98 			ViewList			fMode2Items;
99 			ViewList			fMode3Items;
100 			BControl*			fLatch;
101 
102 	typedef BView _inherited;
103 };
104 
105 
106 inline int32
107 DialogPane::Mode() const
108 {
109 	return fMode;
110 }
111 
112 
113 class PaneSwitch : public BControl {
114 public:
115 								PaneSwitch(BRect frame, const char* name,
116 									bool leftAligned = true,
117 									uint32 resizeMask
118 										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
119 									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
120 
121 								PaneSwitch(const char* name,
122 									bool leftAligned = true,
123 									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
124 
125 	virtual						~PaneSwitch();
126 
127 	virtual	void				Draw(BRect updateRect);
128 	virtual	void				MouseDown(BPoint where);
129 
130 	virtual	void				GetPreferredSize(float* _width,
131 									float* _height);
132 
133 	virtual	BSize				MinSize();
134 	virtual	BSize				MaxSize();
135 	virtual	BSize				PreferredSize();
136 
137 			void				SetLabels(const char* labelOn,
138 									const char* labelOff);
139 
140 protected:
141 			void				DoneTracking(BPoint where);
142 			void				Track(BPoint where, uint32);
143 
144 			enum State {
145 				kCollapsed,
146 				kPressed,
147 				kExpanded
148 			};
149 
150 	virtual	void				DrawInState(PaneSwitch::State state);
151 
152 private:
153 			bool				fLeftAligned;
154 			bool				fPressing;
155 
156 			char*				fLabelOn;
157 			char*				fLabelOff;
158 
159 	static	const int32			sLatchSize = 11;
160 };
161 
162 } // namespace BPrivate
163 
164 using namespace BPrivate;
165 
166 #endif
167