openshot-audio  0.1.7
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_COMBOBOX_H_INCLUDED
26 #define JUCE_COMBOBOX_H_INCLUDED
27 
28 
29 //==============================================================================
44 class JUCE_API ComboBox : public Component,
45  public SettableTooltipClient,
46  public LabelListener, // (can't use Label::Listener due to idiotic VC2005 bug)
47  public ValueListener,
48  private AsyncUpdater
49 {
50 public:
51  //==============================================================================
60  explicit ComboBox (const String& componentName = String::empty);
61 
63  ~ComboBox();
64 
65  //==============================================================================
71  void setEditableText (bool isEditable);
72 
76  bool isTextEditable() const noexcept;
77 
83  void setJustificationType (Justification justification);
84 
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 
273  virtual void addItemsToMenu (PopupMenu&) const;
274 
275  //==============================================================================
285  {
286  public:
288  virtual ~Listener() {}
289 
291  virtual void comboBoxChanged (ComboBox* comboBoxThatHasChanged) = 0;
292  };
293 
295  void addListener (Listener* listener);
296 
298  void removeListener (Listener* listener);
299 
300  //==============================================================================
304  void setTextWhenNothingSelected (const String& newMessage);
305 
309  String getTextWhenNothingSelected() const;
310 
317  void setTextWhenNoChoicesAvailable (const String& newMessage);
318 
322  String getTextWhenNoChoicesAvailable() const;
323 
324  //==============================================================================
326  void setTooltip (const String& newTooltip) override;
327 
332  void setScrollWheelEnabled (bool enabled) noexcept;
333 
334 
335  //==============================================================================
346  {
347  backgroundColourId = 0x1000b00,
348  textColourId = 0x1000a00,
349  outlineColourId = 0x1000c00,
350  buttonColourId = 0x1000d00,
351  arrowColourId = 0x1000e00,
352  };
353 
354  //==============================================================================
359  {
360  virtual ~LookAndFeelMethods() {}
361 
362  virtual void drawComboBox (Graphics&, int width, int height, bool isButtonDown,
363  int buttonX, int buttonY, int buttonW, int buttonH,
364  ComboBox&) = 0;
365 
366  virtual Font getComboBoxFont (ComboBox&) = 0;
367 
368  virtual Label* createComboBoxTextBox (ComboBox&) = 0;
369 
370  virtual void positionComboBoxText (ComboBox&, Label& labelToPosition) = 0;
371  };
372 
373  //==============================================================================
375  void labelTextChanged (Label*) override;
377  void enablementChanged() override;
379  void colourChanged() override;
381  void focusGained (Component::FocusChangeType) override;
383  void focusLost (Component::FocusChangeType) override;
385  void handleAsyncUpdate() override;
387  String getTooltip() override { return label->getTooltip(); }
389  void mouseDown (const MouseEvent&) override;
391  void mouseDrag (const MouseEvent&) override;
393  void mouseUp (const MouseEvent&) override;
395  void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
397  void lookAndFeelChanged() override;
399  void paint (Graphics&) override;
401  void resized() override;
403  bool keyStateChanged (bool) override;
405  bool keyPressed (const KeyPress&) override;
407  void valueChanged (Value&) override;
409  void parentHierarchyChanged() override;
410 
411  // These methods' bool parameters have changed: see their new method signatures.
412  JUCE_DEPRECATED (void clear (bool));
413  JUCE_DEPRECATED (void setSelectedId (int, bool));
414  JUCE_DEPRECATED (void setSelectedItemIndex (int, bool));
415  JUCE_DEPRECATED (void setText (const String&, bool));
416 
417 private:
418  //==============================================================================
419  struct ItemInfo
420  {
421  ItemInfo (const String&, int itemId, bool isEnabled, bool isHeading);
422  bool isSeparator() const noexcept;
423  bool isRealItem() const noexcept;
424 
425  String name;
426  int itemId;
427  bool isEnabled : 1, isHeading : 1;
428  };
429 
430  OwnedArray<ItemInfo> items;
431  Value currentId;
432  int lastCurrentId;
433  bool isButtonDown, separatorPending, menuActive, scrollWheelEnabled;
434  float mouseWheelAccumulator;
435  ListenerList<Listener> listeners;
436  ScopedPointer<Label> label;
437  String textWhenNothingSelected, noChoicesMessage;
438 
439  ItemInfo* getItemForId (int) const noexcept;
440  ItemInfo* getItemForIndex (int) const noexcept;
441  bool selectIfEnabled (int index);
442  bool nudgeSelectedItem (int delta);
443  void sendChange (NotificationType);
444  void showPopupIfNotActive();
445 
447 };
448 
450 typedef ComboBox::Listener ComboBoxListener;
451 
452 #endif // JUCE_COMBOBOX_H_INCLUDED
ComboBox::Listener
Definition: juce_ComboBox.h:284
ListenerList
Definition: juce_ListenerList.h:69
ComboBox::getTooltip
String getTooltip() override
Definition: juce_ComboBox.h:387
ComboBox::LookAndFeelMethods
Definition: juce_ComboBox.h:358
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
ComboBox::ColourIds
ColourIds
Definition: juce_ComboBox.h:345
ComboBox::getSelectedIdAsValue
Value & getSelectedIdAsValue()
Definition: juce_ComboBox.h:188
sendNotificationAsync
@ sendNotificationAsync
Definition: juce_NotificationType.h:38
String
Definition: juce_String.h:43
Value
Definition: juce_Value.h:44
Component::FocusChangeType
FocusChangeType
Definition: juce_Component.h:1702
PopupMenu
Definition: juce_PopupMenu.h:77
JUCE_API
#define JUCE_API
Definition: juce_StandardHeader.h:139
AsyncUpdater
Definition: juce_AsyncUpdater.h:39
ScopedPointer
Definition: juce_ScopedPointer.h:70
String::empty
static const String empty
Definition: juce_String.h:152
ComboBox
Definition: juce_ComboBox.h:44
Graphics
Definition: juce_GraphicsContext.h:42
SettableTooltipClient
Definition: juce_TooltipClient.h:63
Label::getJustificationType
Justification getJustificationType() const noexcept
Definition: juce_Label.h:120
noexcept
#define noexcept
Definition: juce_CompilerSupport.h:141
Label::showEditor
void showEditor()
Definition: juce_Label.cpp:210
Value::Listener
Definition: juce_Value.h:130
KeyPress
Definition: juce_KeyPress.h:37
Font
Definition: juce_Font.h:39
OwnedArray
Definition: juce_OwnedArray.h:55
NotificationType
NotificationType
Definition: juce_NotificationType.h:33
ComboBox::LookAndFeelMethods::~LookAndFeelMethods
virtual ~LookAndFeelMethods()
Definition: juce_ComboBox.h:360
Component
Definition: juce_Component.h:33
Label
Definition: juce_Label.h:34
ComboBox::Listener::~Listener
virtual ~Listener()
Definition: juce_ComboBox.h:288
JUCE_DEPRECATED
#define JUCE_DEPRECATED(functionDef)
Definition: juce_PlatformDefs.h:319
Label::setJustificationType
void setJustificationType(Justification justification)
Definition: juce_Label.cpp:117
Label::Listener
Definition: juce_Label.h:180
Label::getText
String getText(bool returnActiveEditorContents=false) const
Definition: juce_Label.cpp:77
MouseEvent
Definition: juce_MouseEvent.h:36
Justification
Definition: juce_Justification.h:38
MouseWheelDetails
Definition: juce_MouseEvent.h:329
StringArray
Definition: juce_StringArray.h:39
ComboBox::isPopupActive
bool isPopupActive() const noexcept
Definition: juce_ComboBox.h:270
Label::setText
void setText(const String &newText, NotificationType notification)
Definition: juce_Label.cpp:56