openshot-audio  0.1.6
juce_Button.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_BUTTON_H_INCLUDED
26 #define JUCE_BUTTON_H_INCLUDED
27 
28 
29 //==============================================================================
39 class JUCE_API Button : public Component,
41 {
42 protected:
43  //==============================================================================
50  explicit Button (const String& buttonName);
51 
52 public:
54  virtual ~Button();
55 
56  //==============================================================================
60  void setButtonText (const String& newText);
61 
65  const String& getButtonText() const { return text; }
66 
67  //==============================================================================
71  bool isDown() const noexcept;
72 
77  bool isOver() const noexcept;
78 
79  //==============================================================================
95  void setToggleState (bool shouldBeOn, NotificationType notification);
96 
105  bool getToggleState() const noexcept { return isOn.getValue(); }
106 
113  Value& getToggleStateValue() noexcept { return isOn; }
114 
121  void setClickingTogglesState (bool shouldAutoToggleOnClick) noexcept;
122 
126  bool getClickingTogglesState() const noexcept;
127 
128  //==============================================================================
149  void setRadioGroupId (int newGroupId, NotificationType notification = sendNotification);
150 
154  int getRadioGroupId() const noexcept { return radioGroupId; }
155 
156  //==============================================================================
163  {
164  public:
166  virtual ~Listener() {}
167 
169  virtual void buttonClicked (Button*) = 0;
170 
172  virtual void buttonStateChanged (Button*) {}
173  };
174 
179  void addListener (Listener* newListener);
180 
184  void removeListener (Listener* listener);
185 
186  //==============================================================================
194  virtual void triggerClick();
195 
196  //==============================================================================
211  void setCommandToTrigger (ApplicationCommandManager* commandManagerToUse,
212  CommandID commandID,
213  bool generateTooltip);
214 
216  CommandID getCommandID() const noexcept { return commandID; }
217 
218  //==============================================================================
228  void addShortcut (const KeyPress&);
229 
233  void clearShortcuts();
234 
238  bool isRegisteredForShortcut (const KeyPress&) const;
239 
240  //==============================================================================
254  void setRepeatSpeed (int initialDelayInMillisecs,
255  int repeatDelayInMillisecs,
256  int minimumDelayInMillisecs = -1) noexcept;
257 
267  void setTriggeredOnMouseDown (bool isTriggeredOnMouseDown) noexcept;
268 
272  uint32 getMillisecondsSinceButtonDown() const noexcept;
273 
274  //==============================================================================
278  void setTooltip (const String& newTooltip) override;
279 
280  //==============================================================================
283  {
284  ConnectedOnLeft = 1,
285  ConnectedOnRight = 2,
286  ConnectedOnTop = 4,
287  ConnectedOnBottom = 8
288  };
289 
301  void setConnectedEdges (int connectedEdgeFlags);
302 
304  int getConnectedEdgeFlags() const noexcept { return connectedEdgeFlags; }
305 
309  bool isConnectedOnLeft() const noexcept { return (connectedEdgeFlags & ConnectedOnLeft) != 0; }
310 
314  bool isConnectedOnRight() const noexcept { return (connectedEdgeFlags & ConnectedOnRight) != 0; }
315 
319  bool isConnectedOnTop() const noexcept { return (connectedEdgeFlags & ConnectedOnTop) != 0; }
320 
324  bool isConnectedOnBottom() const noexcept { return (connectedEdgeFlags & ConnectedOnBottom) != 0; }
325 
326 
327  //==============================================================================
330  {
333  buttonDown
334  };
335 
344  void setState (ButtonState newState);
345 
347  ButtonState getState() const noexcept { return buttonState; }
348 
349  // This method's parameters have changed - see the new version.
350  JUCE_DEPRECATED (void setToggleState (bool, bool));
351 
352  //==============================================================================
357  {
358  virtual ~LookAndFeelMethods() {}
359 
360  virtual void drawButtonBackground (Graphics&, Button&, const Colour& backgroundColour,
361  bool isMouseOverButton, bool isButtonDown) = 0;
362 
363  virtual Font getTextButtonFont (TextButton&, int buttonHeight) = 0;
364  virtual int getTextButtonWidthToFitText (TextButton&, int buttonHeight) = 0;
365 
367  virtual void drawButtonText (Graphics&, TextButton&, bool isMouseOverButton, bool isButtonDown) = 0;
368 
370  virtual void drawToggleButton (Graphics&, ToggleButton&, bool isMouseOverButton, bool isButtonDown) = 0;
371 
372  virtual void changeToggleButtonWidthToFitText (ToggleButton&) = 0;
373 
374  virtual void drawTickBox (Graphics&, Component&, float x, float y, float w, float h,
375  bool ticked, bool isEnabled, bool isMouseOverButton, bool isButtonDown) = 0;
376 
377  virtual void drawDrawableButton (Graphics&, DrawableButton&, bool isMouseOverButton, bool isButtonDown) = 0;
378 
379  private:
380  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
381  // These method have been deprecated: see their replacements above.
382  virtual int getTextButtonFont (TextButton&) { return 0; }
383  virtual int changeTextButtonWidthToFitText (TextButton&, int) { return 0; }
384  #endif
385  };
386 
387 protected:
388  //==============================================================================
399  virtual void clicked();
400 
408  virtual void clicked (const ModifierKeys& modifiers);
409 
420  virtual void paintButton (Graphics& g,
421  bool isMouseOverButton,
422  bool isButtonDown) = 0;
423 
431  virtual void buttonStateChanged();
432 
433  //==============================================================================
435  virtual void internalClickCallback (const ModifierKeys&);
437  void handleCommandMessage (int commandId) override;
439  void mouseEnter (const MouseEvent&) override;
441  void mouseExit (const MouseEvent&) override;
443  void mouseDown (const MouseEvent&) override;
445  void mouseDrag (const MouseEvent&) override;
447  void mouseUp (const MouseEvent&) override;
449  bool keyPressed (const KeyPress&) override;
453  void paint (Graphics&) override;
455  void parentHierarchyChanged() override;
457  void visibilityChanged() override;
459  void focusGained (FocusChangeType) override;
461  void focusLost (FocusChangeType) override;
463  void enablementChanged() override;
464 
465 private:
466  //==============================================================================
467  Array<KeyPress> shortcuts;
468  WeakReference<Component> keySource;
469  String text;
470  ListenerList<Listener> buttonListeners;
471 
473  friend class CallbackHelper;
475  ScopedPointer<CallbackHelper> callbackHelper;
476  uint32 buttonPressTime, lastRepeatTime;
477  ApplicationCommandManager* commandManagerToUse;
478  int autoRepeatDelay, autoRepeatSpeed, autoRepeatMinimumDelay;
479  int radioGroupId, connectedEdgeFlags;
480  CommandID commandID;
481  ButtonState buttonState;
482 
483  Value isOn;
484  bool lastToggleState;
485  bool clickTogglesState;
486  bool needsToRelease;
487  bool needsRepainting;
488  bool isKeyDown;
489  bool triggerOnMouseDown;
490  bool generateTooltip;
491 
492  void repeatTimerCallback();
493  bool keyStateChangedCallback();
494  void applicationCommandListChangeCallback();
495  void updateAutomaticTooltip (const ApplicationCommandInfo&);
496 
497  ButtonState updateState();
498  ButtonState updateState (bool isOver, bool isDown);
499  bool isShortcutPressed() const;
500  void turnOffOtherButtonsInGroup (NotificationType);
501 
502  void flashButtonState();
503  void sendClickMessage (const ModifierKeys&);
504  void sendStateMessage();
505 
507 };
508 
509 #ifndef DOXYGEN
510 
512 #endif
513 
514 #endif // JUCE_BUTTON_H_INCLUDED
Definition: juce_ApplicationCommandManager.h:84
virtual ~LookAndFeelMethods()
Definition: juce_Button.h:358
CommandID getCommandID() const noexcept
Definition: juce_Button.h:216
Definition: juce_Button.h:331
Definition: juce_KeyPress.h:37
ButtonState getState() const noexcept
Definition: juce_Button.h:347
Definition: juce_Font.h:39
virtual void buttonStateChanged(Button *)
Definition: juce_Button.h:172
#define noexcept
Definition: juce_CompilerSupport.h:141
Definition: juce_Button.h:332
Definition: juce_Button.h:39
FocusChangeType
Definition: juce_Component.h:1702
Definition: juce_ModifierKeys.h:38
Definition: juce_TextButton.h:36
Definition: juce_DrawableButton.h:38
ConnectedEdgeFlags
Definition: juce_Button.h:282
Definition: juce_String.h:43
#define JUCE_API
Definition: juce_StandardHeader.h:139
bool isConnectedOnRight() const noexcept
Definition: juce_Button.h:314
NotificationType
Definition: juce_NotificationType.h:33
Definition: juce_TooltipClient.h:63
Definition: juce_Button.h:356
int getRadioGroupId() const noexcept
Definition: juce_Button.h:154
unsigned int uint32
Definition: juce_MathsFunctions.h:51
Definition: juce_Colour.h:35
virtual bool keyStateChanged(bool isKeyDown)
Definition: juce_Component.cpp:3005
bool isConnectedOnTop() const noexcept
Definition: juce_Button.h:319
Definition: juce_ListenerList.h:69
Definition: juce_Button.cpp:25
ButtonState
Definition: juce_Button.h:329
Button::Listener ButtonListener
Definition: juce_Button.h:511
bool isConnectedOnBottom() const noexcept
Definition: juce_Button.h:324
Definition: juce_Component.h:33
Definition: juce_ScopedPointer.h:70
const String & getButtonText() const
Definition: juce_Button.h:65
Definition: juce_Button.h:162
#define JUCE_DEPRECATED(functionDef)
Definition: juce_PlatformDefs.h:319
Definition: juce_ContainerDeletePolicy.h:44
int CommandID
Definition: juce_ApplicationCommandID.h:37
Definition: juce_Value.h:44
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
virtual ~Listener()
Definition: juce_Button.h:166
Definition: juce_GraphicsContext.h:42
Definition: juce_ApplicationCommandInfo.h:42
bool isConnectedOnLeft() const noexcept
Definition: juce_Button.h:309
Definition: juce_NotificationType.h:36
Definition: juce_ToggleButton.h:38
int getConnectedEdgeFlags() const noexcept
Definition: juce_Button.h:304
Definition: juce_MouseEvent.h:36
bool getToggleState() const noexcept
Definition: juce_Button.h:105
Value & getToggleStateValue() noexcept
Definition: juce_Button.h:113