1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-30 02:50:05 +00:00

Couple of minor tweaks, and a fix for menu bars.

This commit is contained in:
Julian Storer 2010-10-08 20:35:04 +01:00
parent d508109296
commit acbfe6c645
10 changed files with 82 additions and 36 deletions

View file

@ -4830,6 +4830,7 @@ public:
const TermPtr createTermToEvaluateInput (const EvaluationContext& context, const Term* input_, double overallTarget, Term* topLevelTerm) const
{
(void) input_;
jassert (input_ == input);
const Term* const dest = findDestinationFor (topLevelTerm, this);
@ -5596,7 +5597,13 @@ Expression::ParseError::ParseError (const String& message)
Expression::EvaluationError::EvaluationError (const String& message)
: description (message)
{
DBG ("Expression::EvaluationError: " + message);
DBG ("Expression::EvaluationError: " + description);
}
Expression::EvaluationError::EvaluationError (const String& symbol, const String& member)
: description ("Unknown symbol: \"" + symbol + (member.isEmpty() ? "\"" : ("." + member + "\"")))
{
DBG ("Expression::EvaluationError: " + description);
}
Expression::EvaluationContext::EvaluationContext() {}
@ -5604,7 +5611,7 @@ Expression::EvaluationContext::~EvaluationContext() {}
const Expression Expression::EvaluationContext::getSymbolValue (const String& symbol, const String& member) const
{
throw EvaluationError ("Unknown symbol: \"" + symbol + (member.isEmpty() ? "\"" : ("." + member + "\"")));
throw EvaluationError (symbol, member);
}
double Expression::EvaluationContext::evaluateFunction (const String& functionName, const double* parameters, int numParams) const
@ -5629,14 +5636,10 @@ double Expression::EvaluationContext::evaluateFunction (const String& functionNa
}
else if (numParams == 1)
{
if (functionName == "sin")
return sin (parameters[0]);
else if (functionName == "cos")
return cos (parameters[0]);
else if (functionName == "tan")
return tan (parameters[0]);
else if (functionName == "abs")
return std::abs (parameters[0]);
if (functionName == "sin") return sin (parameters[0]);
else if (functionName == "cos") return cos (parameters[0]);
else if (functionName == "tan") return tan (parameters[0]);
else if (functionName == "abs") return std::abs (parameters[0]);
}
}
@ -68677,13 +68680,12 @@ void MenuBarComponent::paint (Graphics& g)
void MenuBarComponent::resized()
{
xPositions.clear();
int x = 2;
int x = 0;
xPositions.add (x);
for (int i = 0; i < menuNames.size(); ++i)
{
x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
xPositions.add (x);
}
}
@ -68799,7 +68801,9 @@ void MenuBarComponent::handleCommandMessage (int commandId)
{
const Point<int> mousePos (getMouseXYRelative());
updateItemUnderMouse (mousePos.getX(), mousePos.getY());
setOpenItem (-1);
if (currentPopupIndex == topLevelIndexClicked)
setOpenItem (-1);
if (commandId != 0 && model != 0)
model->menuItemSelected (commandId, topLevelIndexClicked);
@ -77065,13 +77069,19 @@ void AlertWindow::addTextEditor (const String& name,
updateLayout (false);
}
const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
TextEditor* AlertWindow::getTextEditor (const String& nameOfTextEditor) const
{
for (int i = textBoxes.size(); --i >= 0;)
if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
return ((TextEditor*)textBoxes[i])->getText();
if (static_cast <TextEditor*> (textBoxes.getUnchecked(i))->getName() == nameOfTextEditor)
return static_cast <TextEditor*> (textBoxes.getUnchecked(i));
return String::empty;
return 0;
}
const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
{
TextEditor* const t = getTextEditor (nameOfTextEditor);
return t != 0 ? t->getText() : String::empty;
}
void AlertWindow::addComboBox (const String& name,
@ -86404,7 +86414,7 @@ const Expression DrawableComposite::getSymbolValue (const String& symbol, const
return m->position.getExpression();
}
return Expression::EvaluationContext::getSymbolValue (symbol, member);
throw Expression::EvaluationError (symbol, member);
}
const Rectangle<float> DrawableComposite::getUntransformedBounds (const bool includeMarkers) const
@ -86662,6 +86672,7 @@ bool DrawableComposite::ValueTreeWrapper::containsMarker (bool xAxis, const Valu
const DrawableComposite::Marker DrawableComposite::ValueTreeWrapper::getMarker (bool xAxis, const ValueTree& state) const
{
(void) xAxis;
jassert (containsMarker (xAxis, state));
return Marker (state [nameProperty], RelativeCoordinate (state [posProperty].toString()));
@ -90744,6 +90755,11 @@ void TextLayout::clear()
totalLines = 0;
}
bool TextLayout::isEmpty() const
{
return tokens.size() == 0;
}
void TextLayout::appendText (const String& text, const Font& font)
{
const juce_wchar* t = text;

View file

@ -6923,6 +6923,7 @@ public:
{
public:
EvaluationError (const String& message);
EvaluationError (const String& symbolName, const String& memberName);
String description;
};
@ -54408,6 +54409,9 @@ public:
void setText (const String& newText,
const Font& fontToUse);
/** Returns true if the layout has not had any text added yet. */
bool isEmpty() const;
/** Breaks the text up to form a paragraph with the given width.
@param maximumWidth any text wider than this will be split
@ -54568,6 +54572,9 @@ public:
*/
const String getTextEditorContents (const String& nameOfTextEditor) const;
/** Returns a pointer to a textbox that was added with addTextEditor(). */
TextEditor* getTextEditor (const String& nameOfTextEditor) const;
/** Adds a drop-down list of choices to the box.
After the box has been shown, the getComboBoxComponent() method can

View file

@ -210,6 +210,7 @@ public:
const TermPtr createTermToEvaluateInput (const EvaluationContext& context, const Term* input_, double overallTarget, Term* topLevelTerm) const
{
(void) input_;
jassert (input_ == input);
const Term* const dest = findDestinationFor (topLevelTerm, this);
@ -987,7 +988,13 @@ Expression::ParseError::ParseError (const String& message)
Expression::EvaluationError::EvaluationError (const String& message)
: description (message)
{
DBG ("Expression::EvaluationError: " + message);
DBG ("Expression::EvaluationError: " + description);
}
Expression::EvaluationError::EvaluationError (const String& symbol, const String& member)
: description ("Unknown symbol: \"" + symbol + (member.isEmpty() ? "\"" : ("." + member + "\"")))
{
DBG ("Expression::EvaluationError: " + description);
}
//==============================================================================
@ -996,7 +1003,7 @@ Expression::EvaluationContext::~EvaluationContext() {}
const Expression Expression::EvaluationContext::getSymbolValue (const String& symbol, const String& member) const
{
throw EvaluationError ("Unknown symbol: \"" + symbol + (member.isEmpty() ? "\"" : ("." + member + "\"")));
throw EvaluationError (symbol, member);
}
double Expression::EvaluationContext::evaluateFunction (const String& functionName, const double* parameters, int numParams) const
@ -1021,14 +1028,10 @@ double Expression::EvaluationContext::evaluateFunction (const String& functionNa
}
else if (numParams == 1)
{
if (functionName == "sin")
return sin (parameters[0]);
else if (functionName == "cos")
return cos (parameters[0]);
else if (functionName == "tan")
return tan (parameters[0]);
else if (functionName == "abs")
return std::abs (parameters[0]);
if (functionName == "sin") return sin (parameters[0]);
else if (functionName == "cos") return cos (parameters[0]);
else if (functionName == "tan") return tan (parameters[0]);
else if (functionName == "abs") return std::abs (parameters[0]);
}
}

View file

@ -182,6 +182,7 @@ public:
{
public:
EvaluationError (const String& message);
EvaluationError (const String& symbolName, const String& memberName);
String description;
};

View file

@ -113,13 +113,12 @@ void MenuBarComponent::paint (Graphics& g)
void MenuBarComponent::resized()
{
xPositions.clear();
int x = 2;
int x = 0;
xPositions.add (x);
for (int i = 0; i < menuNames.size(); ++i)
{
x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
xPositions.add (x);
}
}
@ -235,7 +234,9 @@ void MenuBarComponent::handleCommandMessage (int commandId)
{
const Point<int> mousePos (getMouseXYRelative());
updateItemUnderMouse (mousePos.getX(), mousePos.getY());
setOpenItem (-1);
if (currentPopupIndex == topLevelIndexClicked)
setOpenItem (-1);
if (commandId != 0 && model != 0)
model->menuItemSelected (commandId, topLevelIndexClicked);

View file

@ -226,13 +226,19 @@ void AlertWindow::addTextEditor (const String& name,
updateLayout (false);
}
const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
TextEditor* AlertWindow::getTextEditor (const String& nameOfTextEditor) const
{
for (int i = textBoxes.size(); --i >= 0;)
if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
return ((TextEditor*)textBoxes[i])->getText();
if (static_cast <TextEditor*> (textBoxes.getUnchecked(i))->getName() == nameOfTextEditor)
return static_cast <TextEditor*> (textBoxes.getUnchecked(i));
return String::empty;
return 0;
}
const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
{
TextEditor* const t = getTextEditor (nameOfTextEditor);
return t != 0 ? t->getText() : String::empty;
}

View file

@ -142,6 +142,9 @@ public:
*/
const String getTextEditorContents (const String& nameOfTextEditor) const;
/** Returns a pointer to a textbox that was added with addTextEditor(). */
TextEditor* getTextEditor (const String& nameOfTextEditor) const;
//==============================================================================
/** Adds a drop-down list of choices to the box.

View file

@ -266,7 +266,7 @@ const Expression DrawableComposite::getSymbolValue (const String& symbol, const
return m->position.getExpression();
}
return Expression::EvaluationContext::getSymbolValue (symbol, member);
throw Expression::EvaluationError (symbol, member);
}
const Rectangle<float> DrawableComposite::getUntransformedBounds (const bool includeMarkers) const
@ -526,6 +526,7 @@ bool DrawableComposite::ValueTreeWrapper::containsMarker (bool xAxis, const Valu
const DrawableComposite::Marker DrawableComposite::ValueTreeWrapper::getMarker (bool xAxis, const ValueTree& state) const
{
(void) xAxis;
jassert (containsMarker (xAxis, state));
return Marker (state [nameProperty], RelativeCoordinate (state [posProperty].toString()));

View file

@ -136,6 +136,11 @@ void TextLayout::clear()
totalLines = 0;
}
bool TextLayout::isEmpty() const
{
return tokens.size() == 0;
}
void TextLayout::appendText (const String& text, const Font& font)
{
const juce_wchar* t = text;

View file

@ -88,6 +88,9 @@ public:
void setText (const String& newText,
const Font& fontToUse);
/** Returns true if the layout has not had any text added yet. */
bool isEmpty() const;
//==============================================================================
/** Breaks the text up to form a paragraph with the given width.