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