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 #ifndef _TITLE_VIEW_H 35 #define _TITLE_VIEW_H 36 37 38 #include <Cursor.h> 39 #include <DataIO.h> 40 #include <ObjectList.h> 41 #include <View.h> 42 43 44 namespace BPrivate { 45 46 47 class BPoseView; 48 class BColumn; 49 class BColumnTitle; 50 class ColumnTrackState; 51 class OffscreenBitmap; 52 53 const int32 kEdgeSize = 6; 54 const int32 kTitleColumnLeftExtraMargin = 11; 55 const int32 kTitleColumnRightExtraMargin = 5; 56 const int32 kTitleColumnExtraMargin = kTitleColumnLeftExtraMargin 57 + kTitleColumnRightExtraMargin; 58 const int32 kMinColumnWidth = 20; 59 const int32 kRemoveTitleMargin = 10; 60 const int32 kColumnStart = 40; 61 62 63 class BTitleView : public BView { 64 public: 65 BTitleView(BPoseView*); 66 virtual ~BTitleView(); 67 68 virtual void MouseDown(BPoint where); 69 virtual void MouseUp(BPoint where); 70 virtual void Draw(BRect updateRect); 71 72 virtual BSize MinSize(); 73 virtual BSize MaxSize(); 74 75 void Draw(BRect, bool useOffscreen = false, 76 bool updateOnly = true, 77 const BColumnTitle* pressedColumn = 0, 78 void (*trackRectBlitter)(BView*, BRect) = 0, 79 BRect passThru = BRect(0, 0, 0, 0)); 80 81 void AddTitle(BColumn*, const BColumn* after = 0); 82 void RemoveTitle(BColumn*); 83 void Reset(); 84 85 BPoseView* PoseView() const; 86 87 protected: 88 void MouseMoved(BPoint, uint32, const BMessage*); 89 90 private: 91 BColumnTitle* FindColumnTitle(BPoint) const; 92 BColumnTitle* InColumnResizeArea(BPoint) const; 93 BColumnTitle* FindColumnTitle(const BColumn*) const; 94 95 private: 96 BPoseView* fPoseView; 97 BObjectList<BColumnTitle> fTitleList; 98 BCursor fHorizontalResizeCursor; 99 float fPreferredHeight; 100 101 BColumnTitle* fPreviouslyClickedColumnTitle; 102 bigtime_t fPreviousLeftClickTime; 103 ColumnTrackState* fTrackingState; 104 105 static OffscreenBitmap* sOffscreen; 106 107 typedef BView _inherited; 108 109 friend class ColumnTrackState; 110 friend class ColumnDragState; 111 }; 112 113 114 class BColumnTitle { 115 public: 116 BColumnTitle(BTitleView*, BColumn*); 117 virtual ~BColumnTitle() {} 118 119 virtual void Draw(BView*, bool pressed = false); 120 121 BColumn* Column() const; 122 BRect Bounds() const; 123 124 bool InColumnResizeArea(BPoint) const; 125 126 private: 127 BColumn* fColumn; 128 BTitleView* fParent; 129 130 friend class ColumnResizeState; 131 }; 132 133 134 // Utility classes to handle dragging state 135 class ColumnTrackState { 136 public: 137 ColumnTrackState(BTitleView* titleView, BColumnTitle* columnTitle, 138 BPoint where, bigtime_t pastClickTime); 139 virtual ~ColumnTrackState() {} 140 141 void MouseMoved(BPoint where, uint32 buttons); 142 void MouseUp(BPoint where); 143 144 protected: 145 virtual void Moved(BPoint where, uint32 buttons) = 0; 146 virtual void Clicked(BPoint where) = 0; 147 virtual void Done(BPoint where) = 0; 148 virtual bool ValueChanged(BPoint where) = 0; 149 150 BTitleView* fTitleView; 151 BColumnTitle* fTitle; 152 BPoint fFirstClickPoint; 153 bigtime_t fPastClickTime; 154 bool fHasMoved; 155 }; 156 157 158 class ColumnResizeState : public ColumnTrackState { 159 public: 160 ColumnResizeState(BTitleView* titleView, BColumnTitle* columnTitle, 161 BPoint where, bigtime_t pastClickTime); 162 163 protected: 164 virtual void Moved(BPoint where, uint32 buttons); 165 virtual void Done(BPoint where); 166 virtual void Clicked(BPoint where); 167 virtual bool ValueChanged(BPoint); 168 169 void DrawLine(); 170 void UndrawLine(); 171 172 private: 173 float fLastLineDrawPos; 174 float fInitialTrackOffset; 175 176 typedef ColumnTrackState _inherited; 177 }; 178 179 180 class ColumnDragState : public ColumnTrackState { 181 public: 182 ColumnDragState(BTitleView* titleView, BColumnTitle* columnTitle, 183 BPoint where, bigtime_t pastClickTime); 184 185 protected: 186 virtual void Moved(BPoint where, uint32 buttons); 187 virtual void Done(BPoint where); 188 virtual void Clicked(BPoint where); 189 virtual bool ValueChanged(BPoint); 190 191 void DrawOutline(float); 192 void UndrawOutline(); 193 void DrawPressNoOutline(); 194 195 private: 196 float fInitialMouseTrackOffset; 197 bool fTrackingRemovedColumn; 198 BMallocIO fColumnArchive; 199 200 typedef ColumnTrackState _inherited; 201 }; 202 203 204 inline BColumn* 205 BColumnTitle::Column() const 206 { 207 return fColumn; 208 } 209 210 211 inline BPoseView* 212 BTitleView::PoseView() const 213 { 214 return fPoseView; 215 } 216 217 218 } // namespace BPrivate 219 220 using namespace BPrivate; 221 222 223 #endif // _TITLE_VIEW_H 224