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