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