1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: TabView.h 23 // Author: Marc Flerackers (mflerackers@androme.be) 24 // Description: BTab creates individual "tabs" that can be assigned 25 // to specific views. 26 // BTabView provides the framework for containing and 27 // managing groups of BTab objects. 28 //------------------------------------------------------------------------------ 29 30 #ifndef _TAB_VIEW_H 31 #define _TAB_VIEW_H 32 33 34 #include <BeBuild.h> 35 #include <View.h> 36 37 38 enum tab_position { 39 B_TAB_FIRST = 999, 40 B_TAB_FRONT, 41 B_TAB_ANY 42 }; 43 44 45 // BTab class ------------------------------------------------------------------ 46 class BTab : public BArchivable { 47 48 public: 49 BTab(BView * tabView = NULL); 50 virtual ~BTab(); 51 52 BTab(BMessage *archive); 53 static BArchivable *Instantiate(BMessage *archive); 54 55 virtual status_t Archive(BMessage *archive, bool deep = true) const; 56 virtual status_t Perform(uint32 d, void *arg); 57 58 const char *Label() const; 59 virtual void SetLabel(const char *label); 60 61 bool IsSelected() const; 62 virtual void Select(BView *owner); 63 virtual void Deselect(); 64 65 virtual void SetEnabled(bool enabled); 66 bool IsEnabled() const; 67 68 void MakeFocus(bool inFocus = true); 69 bool IsFocus() const; 70 71 // sets/gets the view to be displayed for this tab 72 virtual void SetView(BView *view); 73 BView *View() const; 74 75 virtual void DrawFocusMark(BView *owner, BRect frame); 76 virtual void DrawLabel(BView *owner, BRect frame); 77 virtual void DrawTab(BView *owner, BRect frame, tab_position position, 78 bool full = true); 79 80 private: 81 virtual void _ReservedTab1(); 82 virtual void _ReservedTab2(); 83 virtual void _ReservedTab3(); 84 virtual void _ReservedTab4(); 85 virtual void _ReservedTab5(); 86 virtual void _ReservedTab6(); 87 virtual void _ReservedTab7(); 88 virtual void _ReservedTab8(); 89 virtual void _ReservedTab9(); 90 virtual void _ReservedTab10(); 91 virtual void _ReservedTab11(); 92 virtual void _ReservedTab12(); 93 94 BTab &operator=(const BTab &); 95 96 bool fEnabled; 97 bool fSelected; 98 bool fFocus; 99 BView *fView; 100 uint32 _reserved[12]; 101 }; 102 //------------------------------------------------------------------------------ 103 104 105 // BTabView class -------------------------------------------------------------- 106 class BTabView : public BView 107 { 108 public: 109 BTabView(BRect frame, const char *name, 110 button_width width = B_WIDTH_AS_USUAL, 111 uint32 resizingMode = B_FOLLOW_ALL, 112 uint32 flags = B_FULL_UPDATE_ON_RESIZE | 113 B_WILL_DRAW | B_NAVIGABLE_JUMP | 114 B_FRAME_EVENTS | B_NAVIGABLE); 115 ~BTabView(); 116 117 BTabView(BMessage *archive); 118 static BArchivable *Instantiate(BMessage *archive); 119 virtual status_t Archive(BMessage*, bool deep=true) const; 120 virtual status_t Perform(perform_code d, void *arg); 121 122 virtual void WindowActivated(bool active); 123 virtual void AttachedToWindow(); 124 virtual void AllAttached(); 125 virtual void AllDetached(); 126 virtual void DetachedFromWindow(); 127 128 virtual void MessageReceived(BMessage *message); 129 virtual void FrameMoved(BPoint newLocation); 130 virtual void FrameResized(float width,float height); 131 virtual void KeyDown(const char *bytes, int32 numBytes); 132 virtual void MouseDown(BPoint point); 133 virtual void MouseUp(BPoint point); 134 virtual void MouseMoved(BPoint point, uint32 transit, 135 const BMessage *message); 136 virtual void Pulse(); 137 138 virtual void Select(int32 tab); 139 int32 Selection() const; 140 141 virtual void MakeFocus(bool focused = true); 142 virtual void SetFocusTab(int32 tab, bool focused); 143 int32 FocusTab() const; 144 145 virtual void Draw(BRect updateRect); 146 virtual BRect DrawTabs(); 147 virtual void DrawBox(BRect selTabRect); 148 virtual BRect TabFrame(int32 tab_index) const; 149 150 virtual void SetFlags(uint32 flags); 151 virtual void SetResizingMode(uint32 mode); 152 153 virtual void GetPreferredSize(float *width, float *height); 154 virtual void ResizeToPreferred(); 155 156 virtual BHandler *ResolveSpecifier(BMessage *message, int32 index, 157 BMessage *specifier, int32 what, const char *property); 158 virtual status_t GetSupportedSuites(BMessage *message); 159 160 virtual void AddTab(BView *target, BTab *tab = NULL); 161 virtual BTab *RemoveTab(int32 tabIndex); 162 163 virtual BTab *TabAt ( int32 tab_index ) const; 164 165 virtual void SetTabWidth(button_width width); 166 button_width TabWidth() const; 167 168 virtual void SetTabHeight(float height); 169 float TabHeight() const; 170 171 BView *ContainerView() const; 172 173 int32 CountTabs() const; 174 BView *ViewForTab(int32 tabIndex) const; 175 176 private: 177 void _InitObject(); 178 179 virtual void _ReservedTabView1(); 180 virtual void _ReservedTabView2(); 181 virtual void _ReservedTabView3(); 182 virtual void _ReservedTabView4(); 183 virtual void _ReservedTabView5(); 184 virtual void _ReservedTabView6(); 185 virtual void _ReservedTabView7(); 186 virtual void _ReservedTabView8(); 187 virtual void _ReservedTabView9(); 188 virtual void _ReservedTabView10(); 189 virtual void _ReservedTabView11(); 190 virtual void _ReservedTabView12(); 191 192 BTabView(const BTabView &); 193 BTabView &operator=(const BTabView &); 194 195 BList *fTabList; 196 BView *fContainerView; 197 button_width fTabWidthSetting; 198 float fTabWidth; 199 float fTabHeight; 200 int32 fSelection; 201 int32 fInitialSelection; 202 int32 fFocus; 203 float fTabOffset; 204 uint32 _reserved[11]; 205 }; 206 207 #endif // _TAB_VIEW_H 208