Proposed Changes in ComboBox


#1

Here is the scenario. I have a midi instrument plugin in with a Juce control panel. There is an array of 16 combo boxes representing 16 midi channels. The name in the ComboBox represents the patch currently selected for that midi channel. Single clicking on the ComboBox label makes it the currently selected midi channel and that channels patch properties are displayed lower on the control panel. Double clicking on the ComboBox label edits the patch name.

Now here’s the problem. ComboBox::lookAndFeelChanged() overides single and double clicking settings that may have been setup up in MyLookAndFeel::createComboBoxTextBox() such as editOnDoubleClick. The reason this is true is that newLabel->setEditable (label->isEditable()) forces editOnSingleClick. I believe these behaviors are rightfully part of the LookAndFeel and they should not be overridden. In the NewComboBox below I have commented out the lines in ComboBox::lookAndFeelChanged() and changed CNewComboBox::setEditableText (const bool isEditable) so that LookAndFeel settings are not overridden. I also believe this change is backward compatible as long as default look and feel makes appropriate settings.

All this however required hacking the original Juce ComboBox code to make label protected rather than private.

Do you have a better idea of how this should be done?

CNewComboBox::CNewComboBox(const String& componentName)
:
ComboBox(componentName)
{
CNewComboBox::lookAndFeelChanged();
}

void CNewComboBox::lookAndFeelChanged()
{
repaint();

{
ScopedPointer newLabel (getLookAndFeel().createComboBoxTextBox (*this));
jassert (newLabel != nullptr);

if (label != nullptr)
{
  // newLabel->setEditable (label->isEditable());
  newLabel->setJustificationType (label->getJustificationType());
  newLabel->setTooltip (label->getTooltip());
  newLabel->setText (label->getText(), false);
}

label = newLabel;

}

addAndMakeVisible (label);
setWantsKeyboardFocus (! label->isEditable());

label->addListener (this);
label->addMouseListener (this, false);

// label->setColour (Label::backgroundColourId, Colours::transparentBlack);
// label->setColour (Label::textColourId, findColour (ComboBox::textColourId));

// label->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
// label->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
// label->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
// label->setColour (TextEditor::outlineColourId, Colours::transparentBlack);

resized();
}

//==============================================================================
void CNewComboBox::setEditableText (const bool isEditable)
{
if( isEditable) {
if( !(label->isEditable())) {
label->setEditable (true, true, false);
}
setWantsKeyboardFocus (false);
} else {
label->setEditable (false, false, false);
setWantsKeyboardFocus (true);
}
resized();
}


#2

(Use the ‘code’ tag when pasting code!)

Well, making private members protected is definitely not an option. Perhaps all of that label set-up code that you commented out should actually be done in the look and feel method? But that might break other people’s code… No time to think about this myself right now, but feel free to offer other suggestions!