JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ComboBox.h
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
29//==============================================================================
45class JUCE_API ComboBox : public Component,
47 public Value::Listener,
48 private AsyncUpdater
49{
50public:
51 //==============================================================================
60 explicit ComboBox (const String& componentName = {});
61
63 ~ComboBox() override;
64
65 //==============================================================================
71 void setEditableText (bool isEditable);
72
76 bool isTextEditable() const noexcept;
77
83 void setJustificationType (Justification justification);
84
88 Justification getJustificationType() const noexcept;
89
90 //==============================================================================
99 void addItem (const String& newItemText, int newItemId);
100
104 void addItemList (const StringArray& items, int firstItemIdOffset);
105
110 void addSeparator();
111
121 void addSectionHeading (const String& headingName);
122
131 void setItemEnabled (int itemId, bool shouldBeEnabled);
132
134 bool isItemEnabled (int itemId) const noexcept;
135
138 void changeItemText (int itemId, const String& newText);
139
147 void clear (NotificationType notification = sendNotificationAsync);
148
153 int getNumItems() const noexcept;
154
159 String getItemText (int index) const;
160
165 int getItemId (int index) const noexcept;
166
170 int indexOfItemId (int itemId) const noexcept;
171
172 //==============================================================================
181 int getSelectedId() const noexcept;
182
188 Value& getSelectedIdAsValue() { return currentId; }
189
200 void setSelectedId (int newItemId,
201 NotificationType notification = sendNotificationAsync);
202
203 //==============================================================================
212 int getSelectedItemIndex() const;
213
224 void setSelectedItemIndex (int newItemIndex,
225 NotificationType notification = sendNotificationAsync);
226
227 //==============================================================================
236 String getText() const;
237
250 void setText (const String& newText,
251 NotificationType notification = sendNotificationAsync);
252
258 void showEditor();
259
264 virtual void showPopup();
265
267 void hidePopup();
268
270 bool isPopupActive() const noexcept { return menuActive; }
271
275 PopupMenu* getRootMenu() noexcept { return &currentMenu; }
276
278 const PopupMenu* getRootMenu() const noexcept { return &currentMenu; }
279
280 //==============================================================================
289 class JUCE_API Listener
290 {
291 public:
293 virtual ~Listener() = default;
294
296 virtual void comboBoxChanged (ComboBox* comboBoxThatHasChanged) = 0;
297 };
298
300 void addListener (Listener* listener);
301
303 void removeListener (Listener* listener);
304
305 //==============================================================================
308
309 //==============================================================================
313 void setTextWhenNothingSelected (const String& newMessage);
314
318 String getTextWhenNothingSelected() const;
319
326 void setTextWhenNoChoicesAvailable (const String& newMessage);
327
331 String getTextWhenNoChoicesAvailable() const;
332
333 //==============================================================================
335 void setTooltip (const String& newTooltip) override;
336
341 void setScrollWheelEnabled (bool enabled) noexcept;
342
343
344 //==============================================================================
355 {
356 backgroundColourId = 0x1000b00,
357 textColourId = 0x1000a00,
358 outlineColourId = 0x1000c00,
359 buttonColourId = 0x1000d00,
360 arrowColourId = 0x1000e00,
361 focusedOutlineColourId = 0x1000f00
362 };
363
364 //==============================================================================
368 struct JUCE_API LookAndFeelMethods
369 {
370 virtual ~LookAndFeelMethods() = default;
371
372 virtual void drawComboBox (Graphics&, int width, int height, bool isButtonDown,
373 int buttonX, int buttonY, int buttonW, int buttonH,
374 ComboBox&) = 0;
375
376 virtual Font getComboBoxFont (ComboBox&) = 0;
377
378 virtual Label* createComboBoxTextBox (ComboBox&) = 0;
379
380 virtual void positionComboBoxText (ComboBox&, Label& labelToPosition) = 0;
381
382 virtual PopupMenu::Options getOptionsForComboBoxPopupMenu (ComboBox&, Label&) = 0;
383
384 virtual void drawComboBoxTextWhenNothingSelected (Graphics&, ComboBox&, Label&) = 0;
385 };
386
387 //==============================================================================
389 void enablementChanged() override;
391 void colourChanged() override;
393 void focusGained (Component::FocusChangeType) override;
395 void focusLost (Component::FocusChangeType) override;
397 void handleAsyncUpdate() override;
399 String getTooltip() override { return label->getTooltip(); }
401 void mouseDown (const MouseEvent&) override;
403 void mouseDrag (const MouseEvent&) override;
405 void mouseUp (const MouseEvent&) override;
407 void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
409 void lookAndFeelChanged() override;
411 void paint (Graphics&) override;
413 void resized() override;
415 bool keyStateChanged (bool) override;
417 bool keyPressed (const KeyPress&) override;
419 void valueChanged (Value&) override;
421 void parentHierarchyChanged() override;
423 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
424
425 //==============================================================================
426 #ifndef DOXYGEN
427 // These methods' bool parameters have changed: see their new method signatures.
428 [[deprecated]] void clear (bool);
429 [[deprecated]] void setSelectedId (int, bool);
430 [[deprecated]] void setSelectedItemIndex (int, bool);
431 [[deprecated]] void setText (const String&, bool);
432 #endif
433
434private:
435 //==============================================================================
436 enum EditableState
437 {
438 editableUnknown,
439 labelIsNotEditable,
440 labelIsEditable
441 };
442
443 PopupMenu currentMenu;
444 Value currentId;
445 int lastCurrentId = 0;
446 bool isButtonDown = false, menuActive = false, scrollWheelEnabled = false;
447 float mouseWheelAccumulator = 0;
448 ListenerList<Listener> listeners;
450 String textWhenNothingSelected, noChoicesMessage;
451 EditableState labelEditableState = editableUnknown;
452
453 PopupMenu::Item* getItemForId (int) const noexcept;
454 PopupMenu::Item* getItemForIndex (int) const noexcept;
455 bool selectIfEnabled (int index);
456 bool nudgeSelectedItem (int delta);
457 void sendChange (NotificationType);
458 void showPopupIfNotActive();
459
461};
462
463
464} // namespace juce
Has a callback method that is triggered asynchronously.
A class for receiving events from a ComboBox.
virtual ~Listener()=default
Destructor.
virtual void comboBoxChanged(ComboBox *comboBoxThatHasChanged)=0
Called when a ComboBox has its selected item changed.
A component that lets the user choose from a drop-down list of choices.
ColourIds
A set of colour IDs to use to change the colour of various aspects of the combo box.
bool isPopupActive() const noexcept
Returns true if the popup menu is currently being shown.
const PopupMenu * getRootMenu() const noexcept
Returns the PopupMenu object associated with the ComboBox.
Value & getSelectedIdAsValue()
Returns a Value object that can be used to get or set the selected item's ID.
std::function< void()> onChange
You can assign a lambda to this callback object to have it called when the selected ID is changed.
String getTooltip() override
Returns the string that this object wants to show as its tooltip.
PopupMenu * getRootMenu() noexcept
Returns the PopupMenu object associated with the ComboBox.
The base class for all JUCE user-interface objects.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
Represents a type of justification to be used when positioning graphical items.
Represents a key press, including any modifier keys that are needed.
A component that displays a text string, and can optionally become a text editor when clicked.
Definition juce_Label.h:41
Contains position and status information about a mouse event.
Class used to create a set of options to pass to the show() method.
Creates and displays a popup-menu.
An implementation of TooltipClient that stores the tooltip string and a method for changing it.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
Receives callbacks when a Value object changes.
Definition juce_Value.h:139
Represents a shared variant value.
Definition juce_Value.h:51
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
@ valueChanged
Indicates that the UI element's value has changed.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
@ sendNotificationAsync
Requests an asynchronous notification.
Contains status information about a mouse wheel event.
This abstract base class is implemented by LookAndFeel classes to provide ComboBox functionality.