openshot-audio  0.1.4
juce_Label.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_LABEL_H_INCLUDED
26 #define JUCE_LABEL_H_INCLUDED
27 
28 
29 //==============================================================================
34 class JUCE_API Label : public Component,
35  public SettableTooltipClient,
36  protected TextEditorListener,
37  private ComponentListener,
38  private ValueListener
39 {
40 public:
41  //==============================================================================
47  Label (const String& componentName = String::empty,
48  const String& labelText = String::empty);
49 
51  ~Label();
52 
53  //==============================================================================
59  void setText (const String& newText,
60  NotificationType notification);
61 
71  String getText (bool returnActiveEditorContents = false) const;
72 
77  Value& getTextValue() noexcept { return textValue; }
78 
79  //==============================================================================
83  void setFont (const Font& newFont);
84 
89  Font getFont() const noexcept;
90 
91  //==============================================================================
103  {
104  backgroundColourId = 0x1000280,
105  textColourId = 0x1000281,
106  outlineColourId = 0x1000282,
108  backgroundWhenEditingColourId = 0x1000283,
109  textWhenEditingColourId = 0x1000284,
110  outlineWhenEditingColourId = 0x1000285
111  };
112 
113  //==============================================================================
117  void setJustificationType (Justification justification);
118 
120  Justification getJustificationType() const noexcept { return justification; }
121 
126  void setBorderSize (BorderSize<int> newBorderSize);
127 
129  BorderSize<int> getBorderSize() const noexcept { return border; }
130 
140  void attachToComponent (Component* owner, bool onLeft);
141 
147  Component* getAttachedComponent() const;
148 
154  bool isAttachedOnLeft() const noexcept { return leftOfOwnerComp; }
155 
161  void setMinimumHorizontalScale (float newScale);
162 
164  float getMinimumHorizontalScale() const noexcept { return minimumHorizontalScale; }
165 
167  void setKeyboardType (TextInputTarget::VirtualKeyboardType type) noexcept { keyboardType = type; }
168 
169  //==============================================================================
181  {
182  public:
184  virtual ~Listener() {}
185 
187  virtual void labelTextChanged (Label* labelThatHasChanged) = 0;
188 
190  virtual void editorShown (Label*, TextEditor&) {}
191 
193  virtual void editorHidden (Label*, TextEditor&) {}
194  };
195 
197  void addListener (Listener* listener);
198 
200  void removeListener (Listener* listener);
201 
202  //==============================================================================
223  void setEditable (bool editOnSingleClick,
224  bool editOnDoubleClick = false,
225  bool lossOfFocusDiscardsChanges = false);
226 
228  bool isEditableOnSingleClick() const noexcept { return editSingleClick; }
229 
231  bool isEditableOnDoubleClick() const noexcept { return editDoubleClick; }
232 
234  bool doesLossOfFocusDiscardChanges() const noexcept { return lossOfFocusDiscardsChanges; }
235 
237  bool isEditable() const noexcept { return editSingleClick || editDoubleClick; }
238 
242  void showEditor();
243 
252  void hideEditor (bool discardCurrentEditorContents);
253 
255  bool isBeingEdited() const noexcept;
256 
258  TextEditor* getCurrentTextEditor() const noexcept;
259 
260  //==============================================================================
265  {
266  virtual ~LookAndFeelMethods() {}
267 
268  virtual void drawLabel (Graphics&, Label&) = 0;
269  virtual Font getLabelFont (Label&) = 0;
270  };
271 
272 protected:
273  //==============================================================================
277  virtual TextEditor* createEditorComponent();
278 
280  virtual void textWasEdited();
281 
283  virtual void textWasChanged();
284 
286  virtual void editorShown (TextEditor*);
287 
289  virtual void editorAboutToBeHidden (TextEditor*);
290 
291  //==============================================================================
293  void paint (Graphics&) override;
295  void resized() override;
297  void mouseUp (const MouseEvent&) override;
299  void mouseDoubleClick (const MouseEvent&) override;
301  void componentMovedOrResized (Component&, bool wasMoved, bool wasResized) override;
303  void componentParentHierarchyChanged (Component&) override;
305  void componentVisibilityChanged (Component&) override;
307  void inputAttemptWhenModal() override;
309  void focusGained (FocusChangeType) override;
311  void enablementChanged() override;
313  KeyboardFocusTraverser* createFocusTraverser() override;
315  void textEditorTextChanged (TextEditor&) override;
317  void textEditorReturnKeyPressed (TextEditor&) override;
319  void textEditorEscapeKeyPressed (TextEditor&) override;
321  void textEditorFocusLost (TextEditor&) override;
323  void colourChanged() override;
325  void valueChanged (Value&) override;
327  void callChangeListeners();
328 
329 private:
330  //==============================================================================
331  Value textValue;
332  String lastTextValue;
333  Font font;
334  Justification justification;
336  ListenerList<Listener> listeners;
337  WeakReference<Component> ownerComponent;
338  BorderSize<int> border;
341  bool editSingleClick;
342  bool editDoubleClick;
343  bool lossOfFocusDiscardsChanges;
344  bool leftOfOwnerComp;
345 
346  bool updateFromTextEditorContents (TextEditor&);
347 
349 };
350 
353 
354 #endif // JUCE_LABEL_H_INCLUDED
bool isEditableOnSingleClick() const noexcept
Definition: juce_Label.h:228
Definition: juce_TextEditor.h:280
Definition: juce_ComponentListener.h:40
void setKeyboardType(TextInputTarget::VirtualKeyboardType type) noexcept
Definition: juce_Label.h:167
bool isAttachedOnLeft() const noexcept
Definition: juce_Label.h:154
static const String empty
Definition: juce_String.h:152
Definition: juce_Font.h:39
Definition: juce_Label.h:264
#define noexcept
Definition: juce_CompilerSupport.h:141
BorderSize< int > getBorderSize() const noexcept
Definition: juce_Label.h:129
Definition: juce_Justification.h:38
FocusChangeType
Definition: juce_Component.h:1702
Definition: juce_Value.h:130
Label::Listener LabelListener
Definition: juce_Label.h:352
Definition: juce_String.h:43
float getMinimumHorizontalScale() const noexcept
Definition: juce_Label.h:164
#define JUCE_API
Definition: juce_StandardHeader.h:139
String getText() const
Definition: juce_TextEditor.cpp:2342
float minimumHorizontalScale
Definition: juce_Font.cpp:33
Definition: juce_Label.h:34
NotificationType
Definition: juce_NotificationType.h:33
Definition: juce_TooltipClient.h:63
Justification getJustificationType() const noexcept
Definition: juce_Label.h:120
virtual ~Listener()
Definition: juce_Label.h:184
Definition: juce_ListenerList.h:69
Definition: juce_KeyboardFocusTraverser.h:49
Definition: juce_Component.h:33
Definition: juce_TextEditor.h:38
VirtualKeyboardType
Definition: juce_TextInputTarget.h:78
ColourIds
Definition: juce_Label.h:102
Value & getTextValue() noexcept
Definition: juce_Label.h:77
Definition: juce_BorderSize.h:39
bool doesLossOfFocusDiscardChanges() const noexcept
Definition: juce_Label.h:234
const Font & getFont() const noexcept
Definition: juce_TextEditor.h:248
virtual ~LookAndFeelMethods()
Definition: juce_Label.h:266
Definition: juce_Value.h:44
virtual void editorHidden(Label *, TextEditor &)
Definition: juce_Label.h:193
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_GraphicsContext.h:42
Definition: juce_Label.h:180
bool isEditable() const noexcept
Definition: juce_Label.h:237
bool isEditableOnDoubleClick() const noexcept
Definition: juce_Label.h:231
virtual void editorShown(Label *, TextEditor &)
Definition: juce_Label.h:190
void setText(const String &newText, bool sendTextChangeMessage=true)
Definition: juce_TextEditor.cpp:1169
void setFont(const Font &newFont)
Definition: juce_TextEditor.cpp:1054
Definition: juce_MouseEvent.h:36