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