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