1 /* 2 * Copyright 2001-2009 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _TAB_VIEW_H 6 #define _TAB_VIEW_H 7 8 9 #include <View.h> 10 11 12 class BTabView; 13 14 15 enum tab_position { 16 B_TAB_FIRST = 999, 17 B_TAB_FRONT, 18 B_TAB_ANY 19 }; 20 21 22 class BTab : public BArchivable { 23 public: 24 BTab(BView* contentsView = NULL); 25 virtual ~BTab(); 26 27 BTab(BMessage* archive); 28 static BArchivable* Instantiate(BMessage* archive); 29 30 virtual status_t Archive(BMessage* data, bool deep = true) const; 31 virtual status_t Perform(uint32 d, void* arg); 32 33 const char* Label() const; 34 virtual void SetLabel(const char* label); 35 36 bool IsSelected() const; 37 virtual void Select(BView* owner); 38 virtual void Deselect(); 39 40 virtual void SetEnabled(bool enable); 41 bool IsEnabled() const; 42 43 void MakeFocus(bool focus = true); 44 bool IsFocus() const; 45 46 // sets/gets the view to be displayed for this tab 47 virtual void SetView(BView* view); 48 BView* View() const; 49 50 virtual void DrawFocusMark(BView* owner, BRect frame); 51 virtual void DrawLabel(BView* owner, BRect frame); 52 virtual void DrawTab(BView* owner, BRect frame, 53 tab_position position, bool full = true); 54 55 class Private; 56 57 private: 58 friend class Private; 59 60 // FBC padding and forbidden methods 61 virtual void _ReservedTab1(); 62 virtual void _ReservedTab2(); 63 virtual void _ReservedTab3(); 64 virtual void _ReservedTab4(); 65 virtual void _ReservedTab5(); 66 virtual void _ReservedTab6(); 67 virtual void _ReservedTab7(); 68 virtual void _ReservedTab8(); 69 virtual void _ReservedTab9(); 70 virtual void _ReservedTab10(); 71 virtual void _ReservedTab11(); 72 virtual void _ReservedTab12(); 73 74 BTab& operator=(const BTab&); 75 76 private: 77 bool fEnabled; 78 bool fSelected; 79 bool fFocus; 80 BView* fView; 81 BTabView* fTabView; 82 83 uint32 _reserved[11]; 84 }; 85 86 87 class BTabView : public BView { 88 public: 89 enum tab_side { 90 kLeftSide = 1 << 0, 91 kRightSide = 1 << 1, 92 kTopSide = 1 << 2, 93 kBottomSide = 1 << 3 94 }; 95 96 BTabView(const char* name, 97 button_width width = B_WIDTH_FROM_WIDEST, 98 uint32 flags = B_FULL_UPDATE_ON_RESIZE 99 | B_WILL_DRAW | B_NAVIGABLE_JUMP 100 | B_FRAME_EVENTS | B_NAVIGABLE); 101 BTabView(BRect frame, const char* name, 102 button_width width = B_WIDTH_AS_USUAL, 103 uint32 resizeMask = B_FOLLOW_ALL, 104 uint32 flags = B_FULL_UPDATE_ON_RESIZE 105 | B_WILL_DRAW | B_NAVIGABLE_JUMP 106 | B_FRAME_EVENTS | B_NAVIGABLE); 107 virtual ~BTabView(); 108 109 BTabView(BMessage* archive); 110 static BArchivable* Instantiate(BMessage* archive); 111 virtual status_t Archive(BMessage* into, 112 bool deep = true) const; 113 virtual status_t AllUnarchived(const BMessage* from); 114 virtual status_t Perform(perform_code d, void* arg); 115 116 virtual void AttachedToWindow(); 117 virtual void DetachedFromWindow(); 118 virtual void AllAttached(); 119 virtual void AllDetached(); 120 121 virtual void MessageReceived(BMessage* message); 122 virtual void KeyDown(const char* bytes, int32 numBytes); 123 virtual void MouseDown(BPoint where); 124 virtual void MouseUp(BPoint where); 125 virtual void MouseMoved(BPoint where, uint32 transit, 126 const BMessage* dragMessage); 127 virtual void Pulse(); 128 129 virtual void Select(int32 index); 130 int32 Selection() const; 131 132 virtual void WindowActivated(bool active); 133 virtual void MakeFocus(bool focused = true); 134 virtual void SetFocusTab(int32 tab, bool focused); 135 int32 FocusTab() const; 136 137 virtual void Draw(BRect updateRect); 138 virtual BRect DrawTabs(); 139 virtual void DrawBox(BRect selectedTabRect); 140 virtual BRect TabFrame(int32 index) const; 141 142 virtual void SetFlags(uint32 flags); 143 virtual void SetResizingMode(uint32 mode); 144 145 virtual void ResizeToPreferred(); 146 virtual void GetPreferredSize(float* _width, float* _height); 147 148 virtual BSize MinSize(); 149 virtual BSize MaxSize(); 150 virtual BSize PreferredSize(); 151 152 virtual void FrameMoved(BPoint newPosition); 153 virtual void FrameResized(float newWidth, float newHeight); 154 155 virtual BHandler* ResolveSpecifier(BMessage* message, 156 int32 index, BMessage* specifier, 157 int32 what, const char* property); 158 virtual status_t GetSupportedSuites(BMessage* message); 159 160 // BTabView 161 virtual void AddTab(BView* target, BTab* tab = NULL); 162 virtual BTab* RemoveTab(int32 tabIndex); 163 164 virtual BTab* TabAt(int32 index) const; 165 166 virtual void SetTabWidth(button_width width); 167 button_width TabWidth() const; 168 169 virtual void SetTabHeight(float height); 170 float TabHeight() const; 171 172 virtual void SetBorder(border_style borderStyle); 173 border_style Border() const; 174 175 virtual void SetTabSide(tab_side tabSide); 176 tab_side TabSide() const; 177 178 BView* ContainerView() const; 179 180 int32 CountTabs() const; 181 BView* ViewForTab(int32 tabIndex) const; 182 183 private: 184 // FBC padding and forbidden methods 185 virtual void _ReservedTabView3(); 186 virtual void _ReservedTabView4(); 187 virtual void _ReservedTabView5(); 188 virtual void _ReservedTabView6(); 189 virtual void _ReservedTabView7(); 190 virtual void _ReservedTabView8(); 191 virtual void _ReservedTabView9(); 192 virtual void _ReservedTabView10(); 193 virtual void _ReservedTabView11(); 194 virtual void _ReservedTabView12(); 195 196 BTabView(const BTabView&); 197 BTabView& operator=(const BTabView&); 198 199 private: 200 void _InitObject(bool layouted, button_width width); 201 void _InitContainerView(bool layouted); 202 BSize _TabsMinSize() const; 203 float _BorderWidth() const; 204 void _LayoutContainerView(bool layouted); 205 206 private: 207 BList* fTabList; 208 BView* fContainerView; 209 button_width fTabWidthSetting; 210 float fTabWidth; 211 float fTabHeight; 212 int32 fSelection; 213 int32 fInitialSelection; 214 int32 fFocus; 215 float fTabOffset; 216 border_style fBorderStyle; 217 tab_side fTabSide; 218 219 uint32 _reserved[9]; 220 }; 221 222 #endif // _TAB_VIEW_H 223