-
Notifications
You must be signed in to change notification settings - Fork 13
/
Awful_JuceComponents.h
2338 lines (1820 loc) · 85.6 KB
/
Awful_JuceComponents.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef __JUCER_HEADER_MAINCOMPONENT_MAINCOMPONENT_D0F6CD31__
#define __JUCER_HEADER_MAINCOMPONENT_MAINCOMPONENT_D0F6CD31__
#include "juce_amalgamated.h"
#include "awful_graphjuce.h"
#include "awful_juceext.h"
#include "rosic/basics/GlobalDefinitions.h"
class SliderBase;
class MainComponent;
class AGroupComponent;
class ASlider;
class ASliderListener;
class ALabel;
class ALabelListener;
class ALabelKeyboardFocusTraverser;
class AComboBox;
class AComboBoxListener;
class Animator;
class Posiator;
class DrawArea;
class AToggleButton;
class AButton;
class ATextButton;
class VSTParamComponent;
class CAudioDeviceManager;
class AMidiInputSelectorComponentListBox;
extern void drawGlassLozenge (Graphics& g,
const float x, const float y,
const float width, const float height,
const Colour& colour,
const float outlineThickness,
const float cornerSize,
const bool flatOnLeft,
const bool flatOnRight,
const bool flatOnTop,
const bool flatOnBottom);
/**
A class for receiving events from an AComboBox.
You can register a ComboBoxListener with a ComboBox using the ComboBox::addListener()
method, and it will be called when the selected item in the box changes.
@see ComboBox::addListener, ComboBox::removeListener
*/
class AComboBoxListener
{
public:
/** Destructor. */
virtual ~AComboBoxListener() {}
/** Called when a ComboBox has its selected item changed.
*/
virtual void comboBoxChanged (AComboBox* comboBoxThatHasChanged) = 0;
};
class ListeningComponent : public Component,
private AComboBoxListener
{
public:
AComboBox* comboCC;
bool pos1visible;
bool pos2visible;
bool old1visible;
bool old2visible;
int posX;
int posW;
int pX;
int pW;
int oldX;
int oldW;
bool posChanged;
int pos2Offs;
int pos2X;
int pos2W;
int old2X;
bool pos2Changed;
bool mhredraw;
int cx, cy, cw, ch;
int mx, my, mw, mh;
int numclicks;
int rc;
int rd;
bool mouse_stuff_redraw;
bool auxhighlights_redraw;
bool auxhighlights_redraw_wait;
DrawArea* first_temp_drawarea;
DrawArea* last_temp_drawarea;
MainComponent* maincomp;
ListeningComponent(MainComponent* mc);
void paint(Graphics& g);
//bool keyPressed(const KeyPress &key);
void mouseUp(const MouseEvent& e);
void mouseDown(const MouseEvent& e);
void mouseMove(const MouseEvent& e);
void mouseDrag(const MouseEvent& e);
void mouseExit(const MouseEvent& e);
void mouseEnter(const MouseEvent& e);
void mouseWheelMove(const MouseEvent& e, float wheelIncrementX, float wheelIncrementY);
void CheckAndRedraw();
void Redraw(int flags);
void UpdateRects();
void CommonInputActions();
void AddTempDrawArea(void* dobj, DrawObjType t, int x, int y, int w, int h);
void RemoveTempDrawArea(DrawArea* da);
void RefreshPos();
void RefreshMenus();
void comboBoxChanged (AComboBox* comboBoxThatHasChanged);
INLINE void UpdatePosData()
{
int oldPos = posX;
int old2Pos = pos2X;
posX = currPlayX - RoundFloat(OffsTick*tickWidth);
int w = GridX2 - GridX1;
if(posX - 3 > w || posX + 3 < 0)
{
pos1visible = false;
}
else
{
pos1visible = true;
}
if(AuxCheckPosData(&pos2X))
{
if(pos2X < 0 || pos2X > GridXS2 - GridXS1)
{
pos2visible = false;
}
else
{
pos2visible = true;
}
}
else
{
pos2visible = false;
}
if(oldPos != posX || pos1visible != old1visible)
{
posChanged = true;
}
if(old2Pos != pos2X || pos2visible != old2visible)
{
pos2Changed = true;
}
}
};
class DrawArea
{
public:
int ax;
int ay;
int aw;
int ah;
DrawObjType type;
void* drawobject;
bool changed;
bool redraw;
bool set;
DrawArea* prev;
DrawArea* next;
DrawArea(void* dobj, DrawObjType t);
void SetBounds(int x, int y, int w, int h);
void SetBounds(int x, int y, int w, int h, int xr, int yr, int wr, int hr);
void ResetBounds();
void Enable();
void EnableWithBounds(int x, int y, int w, int h);
void EnableWithBounds(int x, int y, int w, int h, int xr, int yr, int wr, int hr);
void Disable();
void DisableRedraw(Component* c);
void Change();
void UnChange();
bool isEnabled();
bool isChanged();
private:
bool enabled;
};
class HintComponent : public Component,
public Timer
{
public:
String text;
int width;
MainComponent* maincomp;
HintComponent(MainComponent* mc);
~HintComponent();
void paint(Graphics& g);
void SetText(String& text);
void Disable();
void timerCallback();
};
class MainComponent : public Component,
public ButtonListener
{
public:
int refresh;
int block;
Image* maingrid;
Image* auxgrid;
Image* mixer;
DrawArea* first_drawarea;
DrawArea* last_drawarea;
Animator* anim;
Posiator* poso;
ListeningComponent* listen;
HintComponent* hint;
MainComponent ();
~MainComponent();
void paint(Graphics& g);
void resized();
void buttonClicked(Button* buttonThatWasClicked);
void AddDrawArea(DrawArea* s);
void RemoveDrawArea(DrawArea* s);
void MakeSnapshot(Image** img, int x, int y, int w, int h, Image* otherimg = NULL);
void RefreshSeparates();
void EnableHint(String& text, int x, int y);
void DisableHint();
void ForceRefresh();
//==============================================================================
//[juce_UseDebuggingNewOperator
private:
//TextButton* quitButton;
MainComponent (const MainComponent&);
const MainComponent& operator= (const MainComponent&);
TextButton* animateButton;
ComponentAnimator animator;
};
class Animator : public Timer
{
public:
MainComponent* maincomp;
Animator(MainComponent* maincomp);
void timerCallback();
};
class Posiator : public Timer
{
public:
MainComponent* maincomp;
long mainPos;
long auxPos;
int add;
bool scheduled_pattern_refresh;
uint32 lasttime;
Posiator(MainComponent* maincomp);
void timerCallback();
void initTimer(int interval = 30);
void ScheduleRefresh();
};
class AButton : public Button
{
public:
AButton (const String& name);
~AButton();
void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown);
juce_UseDebuggingNewOperator
};
class ATextButton : public AButton
{
public:
ATextButton(const String& name);
ATextButton(const String& name, const String& toolTip);
~ATextButton();
void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown);
juce_UseDebuggingNewOperator
private:
void drawText (Graphics& g, ATextButton& button, bool isButtonDown);
};
/**
A component that draws an outline around itself and has an optional title at
the top, for drawing an outline around a group of controls.
*/
class AGroupComponent : public Component
{
public:
/** Creates a GroupComponent.
@param componentName the name to give the component
@param labelText the text to show at the top of the outline
*/
AGroupComponent(const String& componentName,
const String& labelText);
/** Destructor. */
~AGroupComponent();
/** Changes the text that's shown at the top of the component. */
void setText (const String& newText) throw();
/** Returns the currently displayed text label. */
const String getText() const throw();
/** Sets the positioning of the text label.
(The default is Justification::left)
@see getTextLabelPosition
*/
void setTextLabelPosition (const Justification& justification);
/** Returns the current text label position.
@see setTextLabelPosition
*/
const Justification getTextLabelPosition() const throw() { return justification; }
/** A set of colour IDs to use to change the colour of various aspects of the component.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
outlineColourId = 0x1005400, /**< The colour to use for drawing the line around the edge. */
textColourId = 0x1005410 /**< The colour to use to draw the text label. */
};
/** @internal */
void paint (Graphics& g);
/** @internal */
void enablementChanged();
/** @internal */
void colourChanged();
private:
String text;
Justification justification;
AGroupComponent (const AGroupComponent&);
const AGroupComponent& operator= (const AGroupComponent&);
};
/**
A component that displays a text string, and can optionally become a text
editor when clicked.
*/
/**
A component that displays a text string, and can optionally become a text
editor when clicked.
*/
class ALabel : public Component,
public SettableTooltipClient,
protected TextEditorListener,
private ComponentListener,
private AsyncUpdater
{
public:
/** Creates a Label.
@param componentName the name to give the component
@param labelText the text to show in the label
*/
ALabel (const String& componentName,
const String& labelText);
/** Destructor. */
~ALabel();
/** Changes the label text.
If broadcastChangeMessage is true and the new text is different to the current
text, then the class will broadcast a change message to any LabelListeners that
are registered.
*/
void setText (const String& newText,
const bool broadcastChangeMessage);
/** Returns the label's current text.
@param returnActiveEditorContents if this is true and the label is currently
being edited, then this method will return the
text as it's being shown in the editor. If false,
then the value returned here won't be updated until
the user has finished typing and pressed the return
key.
*/
const String getText (const bool returnActiveEditorContents = false) const throw();
/** Changes the font to use to draw the text.
@see getFont
*/
void setFont (const Font& newFont) throw();
/** Returns the font currently being used.
@see setFont
*/
const Font& getFont() const throw();
/** A set of colour IDs to use to change the colour of various aspects of the label.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
Note that you can also use the constants from TextEditor::ColourIds to change the
colour of the text editor that is opened when a label is editable.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
backgroundColourId = 0x1000280, /**< The background colour to fill the label with. */
textColourId = 0x1000281, /**< The colour for the text. */
outlineColourId = 0x1000282 /**< An optional colour to use to draw a border around the label.
Leave this transparent to not have an outline. */
};
/** Sets the style of justification to be used for positioning the text.
(The default is Justification::centredLeft)
*/
void setJustificationType (const Justification& justification) throw();
/** Returns the type of justification, as set in setJustificationType(). */
const Justification getJustificationType() const throw() { return justification; }
/** Makes this label "stick to" another component.
This will cause the label to follow another component around, staying
either to its left or above it.
@param owner the component to follow
@param onLeft if true, the label will stay on the left of its component; if
false, it will stay above it.
*/
void attachToComponent (Component* owner,
const bool onLeft);
/** If this label has been attached to another component using attachToComponent, this
returns the other component.
Returns 0 if the label is not attached.
*/
Component* getAttachedComponent() const throw() { return ownerComponent; }
/** If the label is attached to the left of another component, this returns true.
Returns false if the label is above the other component. This is only relevent if
attachToComponent() has been called.
*/
bool isAttachedOnLeft() const throw() { return leftOfOwnerComp; }
/** Registers a listener that will be called when the label's text changes. */
void addListener (ALabelListener* const listener) throw();
/** Deregisters a previously-registered listener. */
void removeListener (ALabelListener* const listener) throw();
/** Makes the label turn into a TextEditor when clicked.
By default this is turned off.
If turned on, then single- or double-clicking will turn the label into
an editor. If the user then changes the text, then the ChangeBroadcaster
base class will be used to send change messages to any listeners that
have registered.
If the user changes the text, the textWasEdited() method will be called
afterwards, and subclasses can override this if they need to do anything
special.
@param editOnSingleClick if true, just clicking once on the label will start editing the text
@param editOnDoubleClick if true, a double-click is needed to start editing
@param lossOfFocusDiscardsChanges if true, clicking somewhere else while the text is being
edited will discard any changes; if false, then this will
commit the changes.
@see showEditor, setEditorColours, TextEditor
*/
void setEditable (const bool editOnSingleClick,
const bool editOnDoubleClick = false,
const bool lossOfFocusDiscardsChanges = false) throw();
/** Returns true if this option was set using setEditable(). */
bool isEditableOnSingleClick() const throw() { return editSingleClick; }
/** Returns true if this option was set using setEditable(). */
bool isEditableOnDoubleClick() const throw() { return editDoubleClick; }
/** Returns true if this option has been set in a call to setEditable(). */
bool doesLossOfFocusDiscardChanges() const throw() { return lossOfFocusDiscardsChanges; }
/** Returns true if the user can edit this label's text. */
bool isEditable() const throw() { return editSingleClick || editDoubleClick; }
/** Makes the editor appear as if the label had been clicked by the user.
@see textWasEdited, setEditable
*/
void showEditor();
/** Hides the editor if it was being shown.
@param discardCurrentEditorContents if true, the label's text will be
reset to whatever it was before the editor
was shown; if false, the current contents of the
editor will be used to set the label's text
before it is hidden.
*/
void hideEditor (const bool discardCurrentEditorContents);
/** Returns true if the editor is currently focused and active. */
bool isBeingEdited() const throw();
juce_UseDebuggingNewOperator
protected:
/** @internal */
void paint (Graphics& g);
/** @internal */
void resized();
/** @internal */
void mouseUp (const MouseEvent& e);
/** @internal */
void mouseDoubleClick (const MouseEvent& e);
/** @internal */
void componentMovedOrResized (Component& component, bool wasMoved, bool wasResized);
/** @internal */
void componentParentHierarchyChanged (Component& component);
/** @internal */
void componentVisibilityChanged (Component& component);
/** @internal */
void inputAttemptWhenModal();
/** @internal */
void focusGained (FocusChangeType);
/** @internal */
void enablementChanged();
/** @internal */
KeyboardFocusTraverser* createFocusTraverser();
/** @internal */
void textEditorTextChanged (TextEditor& editor);
/** @internal */
void textEditorReturnKeyPressed (TextEditor& editor);
/** @internal */
void textEditorEscapeKeyPressed (TextEditor& editor);
/** @internal */
void textEditorFocusLost (TextEditor& editor);
/** @internal */
void handleAsyncUpdate();
/** @internal */
void colourChanged();
/** Creates the TextEditor component that will be used when the user has clicked on the label.
Subclasses can override this if they need to customise this component in some way.
*/
virtual TextEditor* createEditorComponent();
/** Called after the user changes the text.
*/
virtual void textWasEdited();
private:
String text;
Font font;
Justification justification;
TextEditor* editor;
SortedSet <void*> listeners;
Component* ownerComponent;
ComponentDeletionWatcher* deletionWatcher;
bool editSingleClick : 1;
bool editDoubleClick : 1;
bool lossOfFocusDiscardsChanges : 1;
bool leftOfOwnerComp : 1;
bool updateFromTextEditorContents();
ALabel (const ALabel&);
const ALabel& operator= (const ALabel&);
};
/**
A class for receiving events from a Label.
You can register a LabelListener with a Label using the Label::addListener()
method, and it will be called when the text of the label changes, either because
of a call to Label::setText() or by the user editing the text (if the label is
editable).
@see Label::addListener, Label::removeListener
*/
class ALabelListener
{
public:
/** Destructor. */
virtual ~ALabelListener() {}
/** Called when a Label's text has changed.
*/
virtual void labelTextChanged (ALabel* labelThatHasChanged) = 0;
};
class AComboBox : public Component,
public SettableTooltipClient,
private ALabelListener,
private AsyncUpdater
{
public:
/** Creates a combo-box.
On construction, the text field will be empty, so you should call the
setSelectedId() or setText() method to choose the initial value before
displaying it.
@param componentName the name to set for the component (see Component::setName())
*/
AComboBox (const String& componentName);
/** Destructor. */
~AComboBox();
/** Sets whether the test in the combo-box is editable.
The default state for a new ComboBox is non-editable, and can only be changed
by choosing from the drop-down list.
*/
void setEditableText (const bool isEditable);
/** Returns true if the text is directly editable.
@see setEditableText
*/
bool isTextEditable() const throw();
/** Sets the style of justification to be used for positioning the text.
The default is Justification::centredLeft. The text is displayed using a
Label component inside the ComboBox.
*/
void setJustificationType (const Justification& justification) throw();
/** Returns the current justification for the text box.
@see setJustificationType
*/
const Justification getJustificationType() const throw();
/** Adds an item to be shown in the drop-down list.
@param newItemText the text of the item to show in the list
@param newItemId an associated ID number that can be set or retrieved - see
getSelectedId() and setSelectedId()
@see setItemEnabled, addSeparator, addSectionHeading, removeItem, getNumItems, getItemText, getItemId
*/
void addItem (const String& newItemText,
const int newItemId) throw();
/** Adds a separator line to the drop-down list.
This is like adding a separator to a popup menu. See PopupMenu::addSeparator().
*/
void addSeparator() throw();
/** Adds a heading to the drop-down list, so that you can group the items into
different sections.
The headings are indented slightly differently to set them apart from the
items on the list, and obviously can't be selected. You might want to add
separators between your sections too.
@see addItem, addSeparator
*/
void addSectionHeading (const String& headingName) throw();
/** This allows items in the drop-down list to be selectively disabled.
When you add an item, it's enabled by default, but you can call this
method to change its status.
If you disable an item which is already selected, this won't change the
current selection - it just stops the user choosing that item from the list.
*/
void setItemEnabled (const int itemId,
const bool isEnabled) throw();
/** Changes the text for an existing item.
*/
void changeItemText (const int itemId,
const String& newText) throw();
/** Removes all the items from the drop-down list.
If this call causes the content to be cleared, then a change-message
will be broadcast unless dontSendChangeMessage is true.
@see addItem, removeItem, getNumItems
*/
void clear (const bool dontSendChangeMessage = false);
/** Returns the number of items that have been added to the list.
Note that this doesn't include headers or separators.
*/
int getNumItems() const throw();
/** Returns the text for one of the items in the list.
Note that this doesn't include headers or separators.
@param index the item's index from 0 to (getNumItems() - 1)
*/
const String getItemText (const int index) const throw();
/** Returns the ID for one of the items in the list.
Note that this doesn't include headers or separators.
@param index the item's index from 0 to (getNumItems() - 1)
*/
int getItemId (const int index) const throw();
/** Returns the ID of the item that's currently shown in the box.
If no item is selected, or if the text is editable and the user
has entered something which isn't one of the items in the list, then
this will return 0.
@see setSelectedId, getSelectedItemIndex, getText
*/
int getSelectedId() const throw();
/** Sets one of the items to be the current selection.
This will set the ComboBox's text to that of the item that matches
this ID.
@param newItemId the new item to select
@param dontSendChangeMessage if set to true, this method won't trigger a
change notification
@see getSelectedId, setSelectedItemIndex, setText
*/
void setSelectedId (const int newItemId,
const bool dontSendChangeMessage = false) throw();
/** Returns the index of the item that's currently shown in the box.
If no item is selected, or if the text is editable and the user
has entered something which isn't one of the items in the list, then
this will return -1.
@see setSelectedItemIndex, getSelectedId, getText
*/
int getSelectedItemIndex() const throw();
/** Sets one of the items to be the current selection.
This will set the ComboBox's text to that of the item at the given
index in the list.
@param newItemIndex the new item to select
@param dontSendChangeMessage if set to true, this method won't trigger a
change notification
@see getSelectedItemIndex, setSelectedId, setText
*/
void setSelectedItemIndex (const int newItemIndex,
const bool dontSendChangeMessage = false) throw();
/** Returns the text that is currently shown in the combo-box's text field.
If the ComboBox has editable text, then this text may have been edited
by the user; otherwise it will be one of the items from the list, or
possibly an empty string if nothing was selected.
@see setText, getSelectedId, getSelectedItemIndex
*/
const String getText() const throw();
/** Sets the contents of the combo-box's text field.
The text passed-in will be set as the current text regardless of whether
it is one of the items in the list. If the current text isn't one of the
items, then getSelectedId() will return -1, otherwise it wil return
the approriate ID.
@param newText the text to select
@param dontSendChangeMessage if set to true, this method won't trigger a
change notification
@see getText
*/
void setText (const String& newText,
const bool dontSendChangeMessage = false) throw();
/** Programmatically opens the text editor to allow the user to edit the current item.
This is the same effect as when the box is clicked-on.
@see Label::showEditor();
*/
void showEditor();
/** Registers a listener that will be called when the box's content changes. */
void addListener (AComboBoxListener* const listener) throw();
/** Deregisters a previously-registered listener. */
void removeListener (AComboBoxListener* const listener) throw();
/** Sets a message to display when there is no item currently selected.
@see getTextWhenNothingSelected
*/
void setTextWhenNothingSelected (const String& newMessage) throw();
/** Returns the text that is shown when no item is selected.
@see setTextWhenNothingSelected
*/
const String getTextWhenNothingSelected() const throw();
/** Sets the message to show when there are no items in the list, and the user clicks
on the drop-down box.
By default it just says "no choices", but this lets you change it to something more
meaningful.
*/
void setTextWhenNoChoicesAvailable (const String& newMessage) throw();
/** Returns the text shown when no items have been added to the list.
@see setTextWhenNoChoicesAvailable
*/
const String getTextWhenNoChoicesAvailable() const throw();
/** Gives the ComboBox a tooltip. */
void setTooltip (const String& newTooltip);
/** A set of colour IDs to use to change the colour of various aspects of the combo box.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
To change the colours of the menu that pops up
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
backgroundColourId = 0x1000b00, /**< The background colour to fill the box with. */
textColourId = 0x1000a00, /**< The colour for the text in the box. */
outlineColourId = 0x1000c00, /**< The colour for an outline around the box. */
buttonColourId = 0x1000d00, /**< The base colour for the button (a LookAndFeel class will probably use variations on this). */
arrowColourId = 0x1000e00, /**< The colour for the arrow shape that pops up the menu */
};
/** @internal */
void labelTextChanged (ALabel*);
/** @internal */
void enablementChanged();
/** @internal */
void colourChanged();
/** @internal */
void focusGained (Component::FocusChangeType cause);
/** @internal */
void focusLost (Component::FocusChangeType cause);
/** @internal */
void handleAsyncUpdate();
/** @internal */
const String getTooltip() { return label->getTooltip(); }
/** @internal */
void mouseDown (const MouseEvent&);
/** @internal */
void mouseDrag (const MouseEvent&);
/** @internal */
void mouseUp (const MouseEvent&);
/** @internal */
void lookAndFeelChanged();
/** @internal */
void paint (Graphics&);
/** @internal */
void resized();
/** @internal */
bool keyStateChanged();
/** @internal */
bool keyPressed (const KeyPress&);
juce_UseDebuggingNewOperator
private:
struct ItemInfo
{
String name;
int itemId;
bool isEnabled : 1, isHeading : 1;
bool isSeparator() const throw();
bool isRealItem() const throw();
};
OwnedArray <ItemInfo> items;
int currentIndex;
bool isButtonDown;
bool separatorPending;
bool menuActive;
SortedSet <void*> listeners;
ALabel* label;
String textWhenNothingSelected, noChoicesMessage;
void showPopup();
int lbx, lby;
ItemInfo* getItemForId (const int itemId) const throw();
ItemInfo* getItemForIndex (const int index) const throw();
AComboBox (const AComboBox&);
const AComboBox& operator= (const AComboBox&);
};
/**
A button that can be toggled on/off.
All buttons can be toggle buttons, but this lets you create one of the
standard ones which has a tick-box and a text label next to it.
@see Button, DrawableButton, TextButton
*/
class AToggleButton : public Button
{
public:
/** Creates a ToggleButton.
@param buttonText the text to put in the button (the component's name is also
initially set to this string, but these can be changed later
using the setName() and setButtonText() methods)
*/
AToggleButton (const String& buttonText);
/** Destructor. */
~AToggleButton();
/** Resizes the button to fit neatly around its current text.
The button's height won't be affected, only its width.
*/
void changeWidthToFitText();
void setType(int type);
int getType();
/** A set of colour IDs to use to change the colour of various aspects of the button.
These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
methods.
@see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
*/
enum ColourIds
{
textColourId = 0x1006501 /**< The colour to use for the button's text. */
};
juce_UseDebuggingNewOperator
protected: