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