xref: /haiku/src/kits/tracker/TextWidget.h (revision b30304acc8c37e678a1bf66976d15bdab103f931)
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 		bool delayedEdit);
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 *);
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;
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 	void RecalculateText(const BPoseView *view);
96 
97 private:
98 	BRect CalcRectCommon(BPoint poseLoc, const BColumn *, const BPoseView *, float width);
99 
100 	WidgetAttributeText *fText;
101 	uint32 fAttrHash;	// ToDo: get rid of this
102 	alignment fAlignment;
103 
104 	bool fEditable : 1;
105 	bool fVisible : 1;
106 	bool fActive : 1;
107 	bool fSymLink : 1;
108 };
109 
110 inline uint32
111 BTextWidget::AttrHash() const
112 {
113 	return fAttrHash;
114 }
115 
116 inline void
117 BTextWidget::SetEditable(bool on)
118 {
119 	fEditable = on;
120 }
121 
122 inline bool
123 BTextWidget::IsEditable() const
124 {
125 	return fEditable && fText->IsEditable();
126 }
127 
128 inline bool
129 BTextWidget::IsVisible() const
130 {
131 	return fVisible;
132 }
133 
134 inline void
135 BTextWidget::SetVisible(bool on)
136 {
137 	fVisible = on;
138 }
139 
140 inline bool
141 BTextWidget::IsActive() const
142 {
143 	return fActive;
144 }
145 
146 inline void
147 BTextWidget::SetActive(bool on)
148 {
149 	fActive = on;
150 }
151 
152 
153 inline void
154 BTextWidget::Draw(BRect widgetRect, BRect widgetTextRect, float width,
155 	BPoseView *view, bool selected, uint32 clipboardMode)
156 {
157 	Draw(widgetRect, widgetTextRect, width, view, (BView *)view, selected,
158 		clipboardMode, BPoint(0, 0), true);
159 }
160 
161 } // namespace BPrivate
162 
163 using namespace BPrivate;
164 
165 #endif
166