1 /* 2 * tracker/TabHeaderControl.h 3 * 4 * Copyright 2009 Peter Barth 5 * 6 * This file is part of Milkytracker. 7 * 8 * Milkytracker is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * Milkytracker is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with Milkytracker. If not, see <http://www.gnu.org/licenses/>. 20 * 21 */ 22 23 /* 24 * TabHeaderControl.h 25 * MilkyTracker 26 * 27 * Created by Peter Barth on 09.12.07. 28 * 29 */ 30 31 #ifndef __TABHEADERCONTROL_H__ 32 #define __TABHEADERCONTROL_H__ 33 34 #include "BasicTypes.h" 35 #include "Control.h" 36 #include "Button.h" 37 #include "SimpleVector.h" 38 39 class TabHeaderControl : public PPControl, public EventListenerInterface 40 { 41 public: 42 struct TabHeader 43 { 44 PPString text; 45 pp_uint32 ID; 46 TabHeaderTabHeader47 TabHeader() : 48 text(""), 49 ID(0) 50 { 51 } 52 TabHeaderTabHeader53 TabHeader(const PPString& text, pp_uint32 ID) : 54 text(text), 55 ID(ID) 56 { 57 } 58 ~TabHeaderTabHeader59 ~TabHeader() 60 { 61 } 62 }; 63 64 private: 65 const PPColor* color; 66 PPButton* backgroundButton; 67 PPButton* leftButton; 68 PPButton* rightButton; 69 70 pp_int32 minSize; 71 pp_int32 maxSize; 72 73 PPSimpleVector<PPButton> tabButtons; 74 PPSimpleVector<TabHeader> tabHeaders; 75 76 // Control caught by mouse button press (left & right) 77 PPControl* caughtControl; 78 79 pp_int32 startIndex; 80 pp_int32 hitIndex; 81 82 pp_int32 oldHitIndex; 83 paintControls(PPGraphicsAbstract * g)84 void paintControls(PPGraphicsAbstract* g) 85 { 86 for (pp_int32 i = 0; i < tabButtons.size(); i++) 87 { 88 PPControl* ctrl = tabButtons.get(i); 89 if (ctrl->isVisible()) 90 ctrl->paint(g); 91 } 92 } 93 94 void handleTabClick(const PPPoint& p); 95 void setNumTabs(pp_uint32 numTabs); 96 void adjustLabels(); 97 void shiftTabs(pp_int32 offset = 1, bool repaint = true); 98 void assureTabVisible(pp_uint32 index); 99 100 public: 101 TabHeaderControl(pp_int32 id, PPScreen* parentScreen, EventListenerInterface* eventListener, 102 const PPPoint& location, const PPSize& size); 103 virtual ~TabHeaderControl(); 104 105 virtual void setSize(const PPSize& size); 106 virtual void setLocation(const PPPoint& location); 107 setColor(const PPColor & color)108 void setColor(const PPColor& color) { this->color = &color; backgroundButton->setColor(color); } 109 getColor()110 const PPColor& getColor() const { return *color; } 111 112 virtual void paint(PPGraphicsAbstract* graphics); 113 114 virtual pp_int32 dispatchEvent(PPEvent* event); 115 isVisible()116 virtual bool isVisible() const { return PPControl::isVisible() && getNumTabs() > 1; } 117 118 // from EventListenerInterface 119 pp_int32 handleEvent(PPObject* sender, PPEvent* event); 120 setTabMinSize(pp_int32 minSize)121 void setTabMinSize(pp_int32 minSize) { this->minSize = minSize; } getTabMinSize()122 pp_int32 getTabMinSize() const { return minSize; } 123 setTabMaxSize(pp_int32 maxSize)124 void setTabMaxSize(pp_int32 maxSize) { this->maxSize = maxSize; } getTabMaxSize()125 pp_int32 getTabMaxSize() const { return maxSize; } 126 clear()127 void clear() 128 { 129 tabHeaders.clear(); 130 tabButtons.clear(); 131 startIndex = hitIndex = 0; 132 } 133 getNumTabs()134 pp_uint32 getNumTabs() const { return (unsigned)tabHeaders.size(); } 135 void addTab(const TabHeader& tabHeader); 136 const TabHeader* getTab(pp_int32 index) const; 137 bool removeTab(pp_int32 index); 138 139 void setTabHeaderText(pp_int32 index, const PPString& text); 140 141 void setSelectedTab(pp_uint32 index); getSelectedTabIndex()142 pp_int32 getSelectedTabIndex() const { return hitIndex; } 143 }; 144 145 #endif 146