From c8bceee3653b4d4dc399586fe0e1c38edd9f754b Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 14 Jan 2020 12:21:00 +0000 Subject: [PATCH] macOS: Fixed some spurious dynamic_cast warnings when loading dynamic libraries --- .../juce_gui_basics/menus/juce_PopupMenu.cpp | 74 +++++++++++-------- 1 file changed, 43 insertions(+), 31 deletions(-) diff --git a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp index 675b5d1613..582d6da58b 100644 --- a/modules/juce_gui_basics/menus/juce_PopupMenu.cpp +++ b/modules/juce_gui_basics/menus/juce_PopupMenu.cpp @@ -55,10 +55,7 @@ struct HeaderItemComponent : public PopupMenu::CustomComponent setName (name); } - void paint (Graphics& g) override - { - getLookAndFeel().drawPopupMenuSectionHeader (g, getLocalBounds(), getName()); - } + void paint (Graphics& g) override; void getIdealSize (int& idealWidth, int& idealHeight) override { @@ -97,13 +94,7 @@ struct ItemComponent : public Component addMouseListener (&parent, false); } - ~ItemComponent() override - { - if (customComp != nullptr) - setItem (*customComp, nullptr); - - removeChildComponent (customComp.get()); - } + ~ItemComponent() override; void getIdealSize (int& idealWidth, int& idealHeight, const int standardItemHeight) { @@ -273,13 +264,7 @@ struct MenuWindow : public Component getMouseState (Desktop::getInstance().getMainMouseSource()); // forces creation of a mouse source watcher for the main mouse } - ~MenuWindow() override - { - getActiveWindows().removeFirstMatchingValue (this); - Desktop::getInstance().removeGlobalMouseListener (this); - activeSubMenu.reset(); - items.clear(); - } + ~MenuWindow() override; //============================================================================== void paint (Graphics& g) override @@ -1013,14 +998,7 @@ public: startTimerHz (20); } - void handleMouseEvent (const MouseEvent& e) - { - if (! window.windowIsStillValid()) - return; - - startTimerHz (20); - handleMousePosition (e.getScreenPosition()); - } + void handleMouseEvent (const MouseEvent& e); void timerCallback() override { @@ -1250,11 +1228,7 @@ struct NormalComponentWrapper : public PopupMenu::CustomComponent addAndMakeVisible (comp); } - void getIdealSize (int& idealWidth, int& idealHeight) override - { - idealWidth = width; - idealHeight = height; - } + void getIdealSize (int& idealWidth, int& idealHeight) override; void resized() override { @@ -1269,6 +1243,44 @@ struct NormalComponentWrapper : public PopupMenu::CustomComponent }; +// The following implementations are outside of the class definitions to avoid spurious +// warning messages when dynamically loading libraries at runtime on macOS +void PopupMenu::HelperClasses::HeaderItemComponent::paint (Graphics& g) +{ + getLookAndFeel().drawPopupMenuSectionHeader (g, getLocalBounds(), getName()); +} + +PopupMenu::HelperClasses::ItemComponent::~ItemComponent() +{ + if (customComp != nullptr) + setItem (*customComp, nullptr); + + removeChildComponent (customComp.get()); +} + +PopupMenu::HelperClasses::MenuWindow::~MenuWindow() +{ + getActiveWindows().removeFirstMatchingValue (this); + Desktop::getInstance().removeGlobalMouseListener (this); + activeSubMenu.reset(); + items.clear(); +} + +void PopupMenu::HelperClasses::MouseSourceState::handleMouseEvent (const MouseEvent& e) +{ + if (! window.windowIsStillValid()) + return; + + startTimerHz (20); + handleMousePosition (e.getScreenPosition()); +} + +void PopupMenu::HelperClasses::NormalComponentWrapper::getIdealSize (int& idealWidth, int& idealHeight) +{ + idealWidth = width; + idealHeight = height; +} + //============================================================================== PopupMenu::PopupMenu() {