xref: /haiku/src/kits/tracker/TextWidget.h (revision 445d4fd926c569e7b9ae28017da86280aaecbae2)
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 _TEXT_WIDGET_H
36 #define _TEXT_WIDGET_H
37 
38 
39 #include "Model.h"
40 #include "WidgetAttributeText.h"
41 
42 
43 namespace BPrivate {
44 
45 class BPose;
46 class BPoseView;
47 class BColumn;
48 
49 
50 struct MouseUpParams {
51 	BPose* 		pose;
52 	BRect 		bounds;
53 	BPoseView* 	poseView;
54 };
55 
56 
57 class BTextWidget {
58 public:
59 	BTextWidget(Model*, BColumn*, BPoseView*);
60 	virtual ~BTextWidget();
61 
62 	void Draw(BRect widgetRect, BRect widgetTextRect, float width, BPoseView*,
63 		bool selected, uint32 clipboardMode);
64 	void Draw(BRect widgetRect, BRect widgetTextRect, float width, BPoseView*,
65 		BView* drawView, bool selected, uint32 clipboardMode, BPoint offset,
66 		bool direct);
67 		// second call is used for offscreen drawing, where PoseView
68 		// and current drawing view are different
69 
70 	void MouseUp(BRect bounds, BPoseView*, BPose*, BPoint mouseLoc);
71 
72 	BRect CalcRect(BPoint poseLoc, const BColumn*, const BPoseView*);
73 		// returns the rect derived from the formatted string width
74 		// may force WidgetAttributeText recalculation
75 	BRect CalcClickRect(BPoint poseLoc, const BColumn*, const BPoseView*);
76 		// calls CalcRect, if result too narow, returns a wider rect for
77 		// easy clicking
78 	BRect ColumnRect(BPoint poseLoc, const BColumn*, const BPoseView*);
79 		// returns the rect of the widget in a column, regardless
80 		// of the string width; faster than CalcRect
81 	BRect CalcOldRect(BPoint poseLoc, const BColumn*, const BPoseView*);
82 		// after an update call this to determine the old rect so that
83 		// we can invalidate properly
84 
85 	void StartEdit(BRect bounds, BPoseView*, BPose*);
86 	void StopEdit(bool saveChanges, BPoint loc, BPoseView*, BPose*,
87 		int32 index);
88 
89 	void SelectAll(BPoseView* view);
90 	void CheckAndUpdate(BPoint, const BColumn*, BPoseView*, bool visible);
91 
92 	uint32 AttrHash() const;
93 	bool IsEditable() const;
94 	void SetEditable(bool);
95 	bool IsVisible() const;
96 	void SetVisible(bool);
97 	bool IsActive() const;
98 	void SetActive(bool);
99 
100 	const char* Text(const BPoseView* view) const;
101 		// returns the untruncated version of the text
102 	float TextWidth(const BPoseView*) const;
103 	float PreferredWidth(const BPoseView*) const;
104 	int Compare(const BTextWidget&, BPoseView*) const;
105 		// used for sorting in PoseViews
106 
107 	void CheckExpiration();
108 	void CancelWait();
109 
110 	float MaxWidth() { return fMaxWidth; };
111 	void SetMaxWidth(float maxWidth) { fMaxWidth = maxWidth; };
112 
113 private:
114 	BRect CalcRectCommon(BPoint poseLoc, const BColumn*, const BPoseView*,
115 		float width);
116 
117 	WidgetAttributeText* fText;
118 	uint32 fAttrHash;
119 		// TODO: get rid of this
120 	alignment fAlignment;
121 
122 	bool fEditable : 1;
123 	bool fVisible : 1;
124 	bool fActive : 1;
125 	bool fSymLink : 1;
126 
127 	float fMaxWidth;
128 
129 	bigtime_t fLastClickedTime;
130 	struct MouseUpParams fParams;
131 };
132 
133 
134 inline uint32
135 BTextWidget::AttrHash() const
136 {
137 	return fAttrHash;
138 }
139 
140 
141 inline void
142 BTextWidget::SetEditable(bool on)
143 {
144 	fEditable = on;
145 }
146 
147 
148 inline bool
149 BTextWidget::IsEditable() const
150 {
151 	return fEditable && fText->IsEditable();
152 }
153 
154 
155 inline bool
156 BTextWidget::IsVisible() const
157 {
158 	return fVisible;
159 }
160 
161 
162 inline void
163 BTextWidget::SetVisible(bool on)
164 {
165 	fVisible = on;
166 }
167 
168 
169 inline bool
170 BTextWidget::IsActive() const
171 {
172 	return fActive;
173 }
174 
175 
176 inline void
177 BTextWidget::SetActive(bool on)
178 {
179 	fActive = on;
180 }
181 
182 
183 inline void
184 BTextWidget::Draw(BRect widgetRect, BRect widgetTextRect, float width,
185 	BPoseView* view, bool selected, uint32 clipboardMode)
186 {
187 	Draw(widgetRect, widgetTextRect, width, view, (BView*)view, selected,
188 		clipboardMode, B_ORIGIN, true);
189 }
190 
191 } // namespace BPrivate
192 
193 using namespace BPrivate;
194 
195 
196 #endif	// _TEXT_WIDGET_H
197