From 1577be257c3ccee27d3bbd3b27c9cd9375a1d1f0 Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Mon, 25 Oct 2010 09:32:31 +0100 Subject: [PATCH] Fix for osx10.5 window resizing. Misc Jucer tweaks. --- .../Source/Project/jucer_TreeViewTypes.h | 4 +- .../Utility/jucer_JucerTreeViewBase.cpp | 40 ++++++++++++++++++- .../Source/Utility/jucer_JucerTreeViewBase.h | 4 +- juce_amalgamated.cpp | 7 ++-- src/gui/components/menus/juce_PopupMenu.cpp | 4 +- .../mac/juce_mac_NSViewComponentPeer.mm | 3 +- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/extras/Jucer (experimental)/Source/Project/jucer_TreeViewTypes.h b/extras/Jucer (experimental)/Source/Project/jucer_TreeViewTypes.h index 2a3db75f2c..35102fd973 100644 --- a/extras/Jucer (experimental)/Source/Project/jucer_TreeViewTypes.h +++ b/extras/Jucer (experimental)/Source/Project/jucer_TreeViewTypes.h @@ -36,9 +36,10 @@ public: SourceFileTreeViewItem (const Project::Item& item); ~SourceFileTreeViewItem(); - bool acceptsFileDrop (const StringArray& files) const { return false; } + bool acceptsFileDrop (const StringArray& files) const { return false; } bool acceptsDragItems (const OwnedArray & selectedNodes) { return false; } ProjectTreeViewBase* createSubItem (const Project::Item& child); + void createLeftEdgeComponents (Array& components) {} void showDocument(); void showPopupMenu(); const String getDisplayName() const; @@ -58,6 +59,7 @@ public: void checkFileStatus(); void moveSelectedItemsTo (OwnedArray & selectedNodes, int insertIndex); ProjectTreeViewBase* createSubItem (const Project::Item& child); + void createLeftEdgeComponents (Array& components) {} void showDocument(); void showPopupMenu(); diff --git a/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.cpp b/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.cpp index 66c5f2030a..fccb3bfd3e 100644 --- a/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.cpp +++ b/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.cpp @@ -28,6 +28,7 @@ //============================================================================== JucerTreeViewBase::JucerTreeViewBase() + : numLeftHandComps (0) { setLinesDrawnForSubItems (false); } @@ -43,7 +44,7 @@ const Font JucerTreeViewBase::getFont() const int JucerTreeViewBase::getTextX() const { - return getItemHeight() + 6; + return (numLeftHandComps + 1) * getItemHeight() + 8; } void JucerTreeViewBase::paintItem (Graphics& g, int width, int height) @@ -55,7 +56,7 @@ void JucerTreeViewBase::paintItem (Graphics& g, int width, int height) g.setColour (isMissing() ? Colours::red : Colours::black); - g.drawImageWithin (getIcon(), 2, 2, x - 4, height - 4, + g.drawImageWithin (getIcon(), 0, 2, height + 6, height - 4, RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false); @@ -76,6 +77,41 @@ void JucerTreeViewBase::paintOpenCloseButton (Graphics& g, int width, int height g.fillPath (p); } +//============================================================================== +class TreeLeftHandButtonHolderComponent : public Component +{ +public: + TreeLeftHandButtonHolderComponent (const Array& comps) + { + components.addArray (comps); + setInterceptsMouseClicks (false, true); + + for (int i = 0; i < comps.size(); ++i) + addAndMakeVisible (comps.getUnchecked(i)); + } + + void resized() + { + const int edge = 1; + const int itemSize = getHeight() - edge * 2; + + for (int i = 0; i < components.size(); ++i) + components.getUnchecked(i)->setBounds (5 + (i + 1) * getHeight(), edge, itemSize, itemSize); + } + +private: + OwnedArray components; +}; + +Component* JucerTreeViewBase::createItemComponent() +{ + Array components; + createLeftEdgeComponents (components); + numLeftHandComps = components.size(); + + return numLeftHandComps == 0 ? 0 : new TreeLeftHandButtonHolderComponent (components); +} + //============================================================================== void JucerTreeViewBase::showRenameBox() { diff --git a/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.h b/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.h index 2a70435ed3..b9e891293f 100644 --- a/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.h +++ b/extras/Jucer (experimental)/Source/Utility/jucer_JucerTreeViewBase.h @@ -42,10 +42,10 @@ public: //============================================================================== int getItemWidth() const { return -1; } int getItemHeight() const { return 20; } - Component* createItemComponent() { return 0; } void paintItem (Graphics& g, int width, int height); void paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver); + Component* createItemComponent(); //============================================================================== virtual const String getRenamingName() const = 0; @@ -53,6 +53,7 @@ public: virtual void setName (const String& newName) = 0; virtual bool isMissing() = 0; virtual const Image getIcon() const = 0; + virtual void createLeftEdgeComponents (Array& components) = 0; virtual void showRenameBox(); @@ -64,6 +65,7 @@ public: //============================================================================== private: + int numLeftHandComps; const Font getFont() const; int getTextX() const; }; diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 2c1910c7b7..f680272ac6 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -70558,14 +70558,14 @@ int PopupMenu::showMenu (const Rectangle& target, if (callback->component == 0) return 0; - callbackDeleter.release(); - callback->component->enterModalState (false, userCallbackDeleter.release()); callback->component->toFront (false); // need to do this after making it modal, or it could // be stuck behind other comps that are already modal.. ModalComponentManager::getInstance()->attachCallback (callback->component, callback); + callbackDeleter.release(); + if (userCallback != 0) return 0; @@ -273245,7 +273245,8 @@ NSRect NSViewComponentPeer::constrainRect (NSRect r) #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_6 if ([window inLiveResize]) #else - if ([window performSelector: @selector (inLiveResize)]) + if ([window respondsToSelector: @selector (inLiveResize)] + && [window performSelector: @selector (inLiveResize)]) #endif { constrainer->checkBounds (pos, original, diff --git a/src/gui/components/menus/juce_PopupMenu.cpp b/src/gui/components/menus/juce_PopupMenu.cpp index 065600747d..e26ccc9e21 100644 --- a/src/gui/components/menus/juce_PopupMenu.cpp +++ b/src/gui/components/menus/juce_PopupMenu.cpp @@ -1546,14 +1546,14 @@ int PopupMenu::showMenu (const Rectangle& target, if (callback->component == 0) return 0; - callbackDeleter.release(); - callback->component->enterModalState (false, userCallbackDeleter.release()); callback->component->toFront (false); // need to do this after making it modal, or it could // be stuck behind other comps that are already modal.. ModalComponentManager::getInstance()->attachCallback (callback->component, callback); + callbackDeleter.release(); + if (userCallback != 0) return 0; diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index fbe6f09ead..5feeb69036 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -1075,7 +1075,8 @@ NSRect NSViewComponentPeer::constrainRect (NSRect r) #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_6 if ([window inLiveResize]) #else - if ([window performSelector: @selector (inLiveResize)]) + if ([window respondsToSelector: @selector (inLiveResize)] + && [window performSelector: @selector (inLiveResize)]) #endif { constrainer->checkBounds (pos, original,