LMMS
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//==============================================================================
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
189
200 void setSelectedId (int newItemId,
202
203 //==============================================================================
212 int getSelectedItemIndex() const;
213
224 void setSelectedItemIndex (int newItemIndex,
226
227 //==============================================================================
236 String getText() const;
237
250 void setText (const String& newText,
252
258 void showEditor();
259
264 virtual void showPopup();
265
267 void hidePopup();
268
271
276
279
280 //==============================================================================
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 //==============================================================================
307 std::function<void()> onChange;
308
309 //==============================================================================
313 void setTextWhenNothingSelected (const String& newMessage);
314
319
326 void setTextWhenNoChoicesAvailable (const String& newMessage);
327
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,
362 };
363
364 //==============================================================================
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
377
379
380 virtual void positionComboBoxText (ComboBox&, Label& labelToPosition) = 0;
381
383
385 };
386
387 //==============================================================================
389 void enablementChanged() override;
391 void colourChanged() 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;
422
423 //==============================================================================
424 #ifndef DOXYGEN
425 // These methods' bool parameters have changed: see their new method signatures.
426 [[deprecated]] void clear (bool);
427 [[deprecated]] void setSelectedId (int, bool);
428 [[deprecated]] void setSelectedItemIndex (int, bool);
429 [[deprecated]] void setText (const String&, bool);
430 #endif
431
432private:
433 //==============================================================================
440
444 bool isButtonDown = false, menuActive = false, scrollWheelEnabled = false;
447 std::unique_ptr<Label> label;
450
451 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
452 PopupMenu::Item* getItemForId (int) const noexcept;
453 PopupMenu::Item* getItemForIndex (int) const noexcept;
454 bool selectIfEnabled (int index);
455 bool nudgeSelectedItem (int delta);
458
460};
461
462
463} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
AsyncUpdater()
Definition juce_AsyncUpdater.cpp:44
Definition juce_ComboBox.h:290
virtual ~Listener()=default
virtual void comboBoxChanged(ComboBox *comboBoxThatHasChanged)=0
bool menuActive
Definition juce_ComboBox.h:444
void handleAsyncUpdate() override
Definition juce_ComboBox.cpp:622
ColourIds
Definition juce_ComboBox.h:355
@ arrowColourId
Definition juce_ComboBox.h:360
@ outlineColourId
Definition juce_ComboBox.h:358
@ focusedOutlineColourId
Definition juce_ComboBox.h:361
@ textColourId
Definition juce_ComboBox.h:357
@ buttonColourId
Definition juce_ComboBox.h:359
@ backgroundColourId
Definition juce_ComboBox.h:356
bool isPopupActive() const noexcept
Definition juce_ComboBox.h:270
void colourChanged() override
Definition juce_ComboBox.cpp:393
void addItemList(const StringArray &items, int firstItemIdOffset)
Definition juce_ComboBox.cpp:99
bool selectIfEnabled(int index)
Definition juce_ComboBox.cpp:276
const PopupMenu * getRootMenu() const noexcept
Definition juce_ComboBox.h:278
bool scrollWheelEnabled
Definition juce_ComboBox.h:444
String noChoicesMessage
Definition juce_ComboBox.h:448
void setJustificationType(Justification justification)
Definition juce_ComboBox.cpp:67
float mouseWheelAccumulator
Definition juce_ComboBox.h:445
bool nudgeSelectedItem(int delta)
Definition juce_ComboBox.cpp:290
void clear(NotificationType notification=sendNotificationAsync)
Definition juce_ComboBox.cpp:141
int lastCurrentId
Definition juce_ComboBox.h:443
ListenerList< Listener > listeners
Definition juce_ComboBox.h:446
Value & getSelectedIdAsValue()
Definition juce_ComboBox.h:188
PopupMenu currentMenu
Definition juce_ComboBox.h:441
bool isItemEnabled(int itemId) const noexcept
Definition juce_ComboBox.cpp:125
bool isButtonDown
Definition juce_ComboBox.h:444
void addSectionHeading(const String &headingName)
Definition juce_ComboBox.cpp:110
void focusGained(Component::FocusChangeType) override
Definition juce_ComboBox.cpp:482
PopupMenu::Item * getItemForId(int) const noexcept
Definition juce_ComboBox.cpp:150
Value currentId
Definition juce_ComboBox.h:442
void setItemEnabled(int itemId, bool shouldBeEnabled)
Definition juce_ComboBox.cpp:119
void showPopupIfNotActive()
Definition juce_ComboBox.cpp:486
void addListener(Listener *listener)
Definition juce_ComboBox.cpp:619
String textWhenNothingSelected
Definition juce_ComboBox.h:448
EditableState
Definition juce_ComboBox.h:435
@ labelIsEditable
Definition juce_ComboBox.h:438
@ labelIsNotEditable
Definition juce_ComboBox.h:437
@ editableUnknown
Definition juce_ComboBox.h:436
void setScrollWheelEnabled(bool enabled) noexcept
Definition juce_ComboBox.cpp:613
Justification getJustificationType() const noexcept
Definition juce_ComboBox.cpp:72
std::function< void()> onChange
Definition juce_ComboBox.h:307
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Definition juce_ComboBox.cpp:707
void setTextWhenNothingSelected(const String &newMessage)
Definition juce_ComboBox.cpp:344
String getItemText(int index) const
Definition juce_ComboBox.cpp:197
void setTooltip(const String &newTooltip) override
Definition juce_ComboBox.cpp:77
String getTooltip() override
Definition juce_ComboBox.h:399
bool isTextEditable() const noexcept
Definition juce_ComboBox.cpp:62
void setEditableText(bool isEditable)
Definition juce_ComboBox.cpp:46
int indexOfItemId(int itemId) const noexcept
Definition juce_ComboBox.cpp:213
int getItemId(int index) const noexcept
Definition juce_ComboBox.cpp:205
void addSeparator()
Definition juce_ComboBox.cpp:105
ComboBox(const String &componentName={})
Definition juce_ComboBox.cpp:29
String getTextWhenNoChoicesAvailable() const
Definition juce_ComboBox.cpp:363
PopupMenu::Item * getItemForIndex(int) const noexcept
Definition juce_ComboBox.cpp:166
void changeItemText(int itemId, const String &newText)
Definition juce_ComboBox.cpp:133
void focusLost(Component::FocusChangeType) override
Definition juce_ComboBox.cpp:483
void sendChange(NotificationType)
Definition juce_ComboBox.cpp:637
int getSelectedId() const noexcept
Definition juce_ComboBox.cpp:250
void addItem(const String &newItemText, int newItemId)
Definition juce_ComboBox.cpp:84
PopupMenu * getRootMenu() noexcept
Definition juce_ComboBox.h:275
int getNumItems() const noexcept
Definition juce_ComboBox.cpp:182
String getTextWhenNothingSelected() const
Definition juce_ComboBox.cpp:353
std::unique_ptr< Label > label
Definition juce_ComboBox.h:447
void enablementChanged() override
Definition juce_ComboBox.cpp:385
EditableState labelEditableState
Definition juce_ComboBox.h:449
void removeListener(Listener *listener)
Definition juce_ComboBox.cpp:620
void setTextWhenNoChoicesAvailable(const String &newMessage)
Definition juce_ComboBox.cpp:358
FocusChangeType
Definition juce_Component.h:1890
String componentName
Definition juce_Component.h:2534
Component() noexcept
Definition juce_Component.cpp:517
Definition juce_Font.h:42
Definition juce_GraphicsContext.h:45
Definition juce_Justification.h:41
Definition juce_KeyPress.h:40
Definition juce_Label.h:41
Definition juce_ListenerList.h:70
Definition juce_MouseEvent.h:39
Definition juce_PopupMenu.h:457
Definition juce_PopupMenu.h:80
Definition juce_StringArray.h:35
Definition juce_String.h:53
Definition juce_Value.h:139
Definition juce_Value.h:51
static int int height
Definition pugl.h:1594
static int width
Definition pugl.h:1593
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
@ valueChanged
Definition juce_AccessibilityEvent.h:44
NotificationType
Definition juce_NotificationType.h:32
@ sendNotificationAsync
Definition juce_NotificationType.h:36
Definition juce_ComboBox.h:369
virtual PopupMenu::Options getOptionsForComboBoxPopupMenu(ComboBox &, Label &)=0
virtual void positionComboBoxText(ComboBox &, Label &labelToPosition)=0
virtual Font getComboBoxFont(ComboBox &)=0
virtual void drawComboBox(Graphics &, int width, int height, bool isButtonDown, int buttonX, int buttonY, int buttonW, int buttonH, ComboBox &)=0
virtual Label * createComboBoxTextBox(ComboBox &)=0
virtual void drawComboBoxTextWhenNothingSelected(Graphics &, ComboBox &, Label &)=0
virtual ~LookAndFeelMethods()=default
Definition juce_MouseEvent.h:392
Definition juce_PopupMenu.h:111
#define void
Definition unzip.h:396
#define const
Definition zconf.h:137