LMMS
Loading...
Searching...
No Matches
juce_TabbedComponent.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
30{
31 const Identifier deleteComponentId ("deleteByTabComp_");
32
34 {
35 if (comp != nullptr && (bool) comp->getProperties() [deleteComponentId])
36 delete comp;
37 }
38
40 TabbedButtonBar::Orientation orientation, int tabDepth)
41 {
42 switch (orientation)
43 {
44 case TabbedButtonBar::TabsAtTop: outline.setTop (0); return content.removeFromTop (tabDepth);
45 case TabbedButtonBar::TabsAtBottom: outline.setBottom (0); return content.removeFromBottom (tabDepth);
46 case TabbedButtonBar::TabsAtLeft: outline.setLeft (0); return content.removeFromLeft (tabDepth);
47 case TabbedButtonBar::TabsAtRight: outline.setRight (0); return content.removeFromRight (tabDepth);
48 default: jassertfalse; break;
49 }
50
51 return Rectangle<int>();
52 }
53}
54
55//==============================================================================
57{
59 : TabbedButtonBar (o), owner (tabComp)
60 {
61 }
62
63 void currentTabChanged (int newCurrentTabIndex, const String& newTabName)
64 {
65 owner.changeCallback (newCurrentTabIndex, newTabName);
66 }
67
68 void popupMenuClickOnTab (int tabIndex, const String& tabName)
69 {
70 owner.popupMenuClickOnTab (tabIndex, tabName);
71 }
72
74 {
75 return owner.tabs->getTabBackgroundColour (tabIndex);
76 }
77
78 TabBarButton* createTabButton (const String& tabName, int tabIndex)
79 {
80 return owner.createTabButton (tabName, tabIndex);
81 }
82
84
86};
87
88//==============================================================================
90{
91 tabs.reset (new ButtonBar (*this, orientation));
92 addAndMakeVisible (tabs.get());
93}
94
100
101//==============================================================================
103{
104 tabs->setOrientation (orientation);
105 resized();
106}
107
112
114{
115 if (tabDepth != newDepth)
116 {
117 tabDepth = newDepth;
118 resized();
119 }
120}
121
122TabBarButton* TabbedComponent::createTabButton (const String& tabName, int /*tabIndex*/)
123{
124 return new TabBarButton (tabName, *tabs);
125}
126
127//==============================================================================
129{
130 if (panelComponent != nullptr)
131 {
132 panelComponent->setVisible (false);
134 panelComponent = nullptr;
135 }
136
137 tabs->clearTabs();
138
139 for (int i = contentComponents.size(); --i >= 0;)
141
142 contentComponents.clear();
143}
144
145void TabbedComponent::addTab (const String& tabName,
146 Colour tabBackgroundColour,
147 Component* contentComponent,
148 bool deleteComponentWhenNotNeeded,
149 int insertIndex)
150{
151 contentComponents.insert (insertIndex, WeakReference<Component> (contentComponent));
152
153 if (deleteComponentWhenNotNeeded && contentComponent != nullptr)
155
156 tabs->addTab (tabName, tabBackgroundColour, insertIndex);
157 resized();
158}
159
160void TabbedComponent::setTabName (int tabIndex, const String& newName)
161{
162 tabs->setTabName (tabIndex, newName);
163}
164
165void TabbedComponent::removeTab (int tabIndex)
166{
167 if (isPositiveAndBelow (tabIndex, contentComponents.size()))
168 {
169 TabbedComponentHelpers::deleteIfNecessary (contentComponents.getReference (tabIndex).get());
170 contentComponents.remove (tabIndex);
171 tabs->removeTab (tabIndex);
172 }
173}
174
175void TabbedComponent::moveTab (int currentIndex, int newIndex, bool animate)
176{
177 contentComponents.move (currentIndex, newIndex);
178 tabs->moveTab (currentIndex, newIndex, animate);
179}
180
182{
183 return tabs->getNumTabs();
184}
185
187{
188 return tabs->getTabNames();
189}
190
192{
193 return contentComponents[tabIndex].get();
194}
195
197{
198 return tabs->getTabBackgroundColour (tabIndex);
199}
200
202{
203 tabs->setTabBackgroundColour (tabIndex, newColour);
204
205 if (getCurrentTabIndex() == tabIndex)
206 repaint();
207}
208
209void TabbedComponent::setCurrentTabIndex (int newTabIndex, bool sendChangeMessage)
210{
211 tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
212}
213
215{
216 return tabs->getCurrentTabIndex();
217}
218
220{
221 return tabs->getCurrentTabName();
222}
223
224void TabbedComponent::setOutline (int thickness)
225{
226 outlineThickness = thickness;
227 resized();
228 repaint();
229}
230
231void TabbedComponent::setIndent (int indentThickness)
232{
233 edgeIndent = indentThickness;
234 resized();
235 repaint();
236}
237
239{
240 g.fillAll (findColour (backgroundColourId));
241
242 auto content = getLocalBounds();
245
246 g.reduceClipRegion (content);
247 g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
248
249 if (outlineThickness > 0)
250 {
251 RectangleList<int> rl (content);
252 rl.subtract (outline.subtractedFrom (content));
253
254 g.reduceClipRegion (rl);
255 g.fillAll (findColour (outlineColourId));
256 }
257}
258
260{
261 auto content = getLocalBounds();
263
264 tabs->setBounds (TabbedComponentHelpers::getTabArea (content, outline, getOrientation(), tabDepth));
265 content = BorderSize<int> (edgeIndent).subtractedFrom (outline.subtractedFrom (content));
266
267 for (auto& c : contentComponents)
268 if (auto comp = c.get())
269 comp->setBounds (content);
270}
271
273{
274 for (auto& c : contentComponents)
275 if (auto comp = c.get())
276 comp->lookAndFeelChanged();
277}
278
279void TabbedComponent::changeCallback (int newCurrentTabIndex, const String& newTabName)
280{
281 auto* newPanelComp = getTabContentComponent (getCurrentTabIndex());
282
283 if (newPanelComp != panelComponent)
284 {
285 if (panelComponent != nullptr)
286 {
287 panelComponent->setVisible (false);
289 }
290
291 panelComponent = newPanelComp;
292
293 if (panelComponent != nullptr)
294 {
295 // do these ops as two stages instead of addAndMakeVisible() so that the
296 // component has always got a parent when it gets the visibilityChanged() callback
298 panelComponent->sendLookAndFeelChange();
299 panelComponent->setVisible (true);
300 panelComponent->toFront (true);
301 }
302
303 repaint();
304 }
305
306 resized();
307 currentTabChanged (newCurrentTabIndex, newTabName);
308}
309
312
313//==============================================================================
314std::unique_ptr<AccessibilityHandler> TabbedComponent::createAccessibilityHandler()
315{
316 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::group);
317}
318
319} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_BorderSize.h:42
void setTop(ValueType newTopGap) noexcept
Definition juce_BorderSize.h:88
void setRight(ValueType newRightGap) noexcept
Definition juce_BorderSize.h:97
Rectangle< ValueType > subtractedFrom(const Rectangle< ValueType > &original) const noexcept
Definition juce_BorderSize.h:101
void setBottom(ValueType newBottomGap) noexcept
Definition juce_BorderSize.h:94
void setLeft(ValueType newLeftGap) noexcept
Definition juce_BorderSize.h:91
Definition juce_Colour.h:38
Definition juce_Component.h:36
void addAndMakeVisible(Component *child, int zOrder=-1)
Definition juce_Component.cpp:1554
void repaint()
Definition juce_Component.cpp:1917
Component() noexcept
Definition juce_Component.cpp:517
NamedValueSet & getProperties() noexcept
Definition juce_Component.h:2209
void removeChildComponent(Component *childToRemove)
Definition juce_Component.cpp:1569
Colour findColour(int colourID, bool inheritFromParent=false) const
Definition juce_Component.cpp:2219
Rectangle< int > getLocalBounds() const noexcept
Definition juce_Component.cpp:2283
void addChildComponent(Component *child, int zOrder=-1)
Definition juce_Component.cpp:1548
Definition juce_GraphicsContext.h:45
Definition juce_Identifier.h:39
bool set(const Identifier &name, const var &newValue)
Definition juce_NamedValueSet.cpp:183
Definition juce_Rectangle.h:67
Rectangle removeFromRight(ValueType amountToRemove) noexcept
Definition juce_Rectangle.h:542
Rectangle removeFromBottom(ValueType amountToRemove) noexcept
Definition juce_Rectangle.h:559
Rectangle removeFromTop(ValueType amountToRemove) noexcept
Definition juce_Rectangle.h:510
Rectangle removeFromLeft(ValueType amountToRemove) noexcept
Definition juce_Rectangle.h:526
Definition juce_RectangleList.h:43
void subtract(RectangleType rect)
Definition juce_RectangleList.h:204
Definition juce_StringArray.h:35
Definition juce_String.h:53
Definition juce_TabbedButtonBar.h:44
TabbedButtonBar(Orientation orientation)
Definition juce_TabbedButtonBar.cpp:199
Orientation
Definition juce_TabbedButtonBar.h:162
@ TabsAtLeft
Definition juce_TabbedButtonBar.h:165
@ TabsAtTop
Definition juce_TabbedButtonBar.h:163
@ TabsAtBottom
Definition juce_TabbedButtonBar.h:164
@ TabsAtRight
Definition juce_TabbedButtonBar.h:166
Array< WeakReference< Component > > contentComponents
Definition juce_TabbedComponent.h:215
int outlineThickness
Definition juce_TabbedComponent.h:217
void clearTabs()
Definition juce_TabbedComponent.cpp:128
void addTab(const String &tabName, Colour tabBackgroundColour, Component *contentComponent, bool deleteComponentWhenNotNeeded, int insertIndex=-1)
Definition juce_TabbedComponent.cpp:145
void paint(Graphics &) override
Definition juce_TabbedComponent.cpp:238
~TabbedComponent() override
Definition juce_TabbedComponent.cpp:95
virtual TabBarButton * createTabButton(const String &tabName, int tabIndex)
Definition juce_TabbedComponent.cpp:122
int tabDepth
Definition juce_TabbedComponent.h:217
int getCurrentTabIndex() const
Definition juce_TabbedComponent.cpp:214
void setTabBarDepth(int newDepth)
Definition juce_TabbedComponent.cpp:113
void setOutline(int newThickness)
Definition juce_TabbedComponent.cpp:224
@ outlineColourId
Definition juce_TabbedComponent.h:189
@ backgroundColourId
Definition juce_TabbedComponent.h:188
int getNumTabs() const
Definition juce_TabbedComponent.cpp:181
std::unique_ptr< TabbedButtonBar > tabs
Definition juce_TabbedComponent.h:211
virtual void popupMenuClickOnTab(int tabIndex, const String &tabName)
Definition juce_TabbedComponent.cpp:311
virtual void currentTabChanged(int newCurrentTabIndex, const String &newCurrentTabName)
Definition juce_TabbedComponent.cpp:310
void removeTab(int tabIndex)
Definition juce_TabbedComponent.cpp:165
void resized() override
Definition juce_TabbedComponent.cpp:259
void setCurrentTabIndex(int newTabIndex, bool sendChangeMessage=true)
Definition juce_TabbedComponent.cpp:209
WeakReference< Component > panelComponent
Definition juce_TabbedComponent.h:216
void changeCallback(int newCurrentTabIndex, const String &newTabName)
Definition juce_TabbedComponent.cpp:279
void setTabBackgroundColour(int tabIndex, Colour newColour)
Definition juce_TabbedComponent.cpp:201
TabbedComponent(TabbedButtonBar::Orientation orientation)
Definition juce_TabbedComponent.cpp:89
Colour getTabBackgroundColour(int tabIndex) const noexcept
Definition juce_TabbedComponent.cpp:196
void setTabName(int tabIndex, const String &newName)
Definition juce_TabbedComponent.cpp:160
void setIndent(int indentThickness)
Definition juce_TabbedComponent.cpp:231
int edgeIndent
Definition juce_TabbedComponent.h:217
void setOrientation(TabbedButtonBar::Orientation orientation)
Definition juce_TabbedComponent.cpp:102
TabbedButtonBar::Orientation getOrientation() const noexcept
Definition juce_TabbedComponent.cpp:108
StringArray getTabNames() const
Definition juce_TabbedComponent.cpp:186
void lookAndFeelChanged() override
Definition juce_TabbedComponent.cpp:272
Component * getTabContentComponent(int tabIndex) const noexcept
Definition juce_TabbedComponent.cpp:191
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_TabbedComponent.cpp:314
String getCurrentTabName() const
Definition juce_TabbedComponent.cpp:219
void moveTab(int currentIndex, int newIndex, bool animate=false)
Definition juce_TabbedComponent.cpp:175
Definition juce_WeakReference.h:78
int g
Definition inflate.c:1573
register unsigned i
Definition inflate.c:1575
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define jassertfalse
static int JUCE_CDECL comp(const void *a, const void *b)
Definition lsp.c:298
Definition juce_TabbedComponent.cpp:30
static Rectangle< int > getTabArea(Rectangle< int > &content, BorderSize< int > &outline, TabbedButtonBar::Orientation orientation, int tabDepth)
Definition juce_TabbedComponent.cpp:39
static void deleteIfNecessary(Component *comp)
Definition juce_TabbedComponent.cpp:33
const Identifier deleteComponentId("deleteByTabComp_")
Definition carla_juce.cpp:31
bool isPositiveAndBelow(Type1 valueToTest, Type2 upperLimit) noexcept
Definition juce_MathsFunctions.h:279
@ group
Definition juce_AccessibilityRole.h:61
Definition juce_TabbedComponent.cpp:57
TabBarButton * createTabButton(const String &tabName, int tabIndex)
Definition juce_TabbedComponent.cpp:78
TabbedComponent & owner
Definition juce_TabbedComponent.cpp:83
Colour getTabBackgroundColour(int tabIndex)
Definition juce_TabbedComponent.cpp:73
void currentTabChanged(int newCurrentTabIndex, const String &newTabName)
Definition juce_TabbedComponent.cpp:63
ButtonBar(TabbedComponent &tabComp, TabbedButtonBar::Orientation o)
Definition juce_TabbedComponent.cpp:58
void popupMenuClickOnTab(int tabIndex, const String &tabName)
Definition juce_TabbedComponent.cpp:68
return c
Definition crypt.c:175
#define const
Definition zconf.h:137