Browse Source

Viewport positioning fix. Changed parameters of Viewport::visibleAreaChanged(). Small plugin header fix.

tags/2021-05-28
Julian Storer 14 years ago
parent
commit
efd1e4c88a
10 changed files with 119 additions and 121 deletions
  1. +4
    -0
      extras/audio plugins/wrapper/juce_PluginHeaders.h
  2. +1
    -1
      extras/juce demo/Source/demos/WidgetsDemo.cpp
  3. +51
    -58
      juce_amalgamated.cpp
  4. +6
    -2
      juce_amalgamated.h
  5. +1
    -5
      src/gui/components/controls/juce_ListBox.cpp
  6. +6
    -14
      src/gui/components/controls/juce_TextEditor.cpp
  7. +3
    -8
      src/gui/components/controls/juce_TreeView.cpp
  8. +15
    -5
      src/gui/components/layout/juce_Viewport.cpp
  9. +6
    -2
      src/gui/components/layout/juce_Viewport.h
  10. +26
    -26
      src/gui/components/windows/juce_ComponentPeer.cpp

+ 4
- 0
extras/audio plugins/wrapper/juce_PluginHeaders.h View File

@@ -26,6 +26,8 @@
#include "juce_IncludeCharacteristics.h"
#include "../../../juce_amalgamated.h"
#ifndef __JUCE_PLUGINHEADERS_JUCEHEADER__
#define __JUCE_PLUGINHEADERS_JUCEHEADER__
#if JUCE_MAC && JUCE_SUPPORT_CARBON
@@ -70,3 +72,5 @@ private:
#else
struct FakeMouseMoveGenerator {};
#endif
#endif

+ 1
- 1
extras/juce demo/Source/demos/WidgetsDemo.cpp View File

@@ -163,7 +163,7 @@ private:
};
//==============================================================================
class CustomMenuComponent : public PopupMenuCustomComponent,
class CustomMenuComponent : public PopupMenu::CustomComponent,
public Timer
{
public:


+ 51
- 58
juce_amalgamated.cpp View File

@@ -48483,10 +48483,6 @@ public:
content->setWantsKeyboardFocus (false);
}

~ListViewport()
{
}

ListBoxRowComponent* getComponentForRow (const int row) const throw()
{
return rows [row % jmax (1, rows.size())];
@@ -48510,7 +48506,7 @@ public:
return -1;
}

void visibleAreaChanged (int, int, int, int)
void visibleAreaChanged (const Rectangle<int>&)
{
updateVisibleArea (true);

@@ -52428,10 +52424,6 @@ public:
{
}

~Iterator()
{
}

bool next()
{
if (atom == &tempAtom)
@@ -52948,35 +52940,31 @@ private:
class TextEditorViewport : public Viewport
{
public:
TextEditorViewport (TextEditor* const owner_)
TextEditorViewport (TextEditor& owner_)
: owner (owner_), lastWordWrapWidth (0), rentrant (false)
{
}

~TextEditorViewport()
{
}

void visibleAreaChanged (int, int, int, int)
void visibleAreaChanged (const Rectangle<int>&)
{
if (! rentrant) // it's rare, but possible to get into a feedback loop as the viewport's scrollbars
// appear and disappear, causing the wrap width to change.
{
const float wordWrapWidth = owner->getWordWrapWidth();
const float wordWrapWidth = owner.getWordWrapWidth();

if (wordWrapWidth != lastWordWrapWidth)
{
lastWordWrapWidth = wordWrapWidth;

rentrant = true;
owner->updateTextHolderSize();
owner.updateTextHolderSize();
rentrant = false;
}
}
}

private:
TextEditor* const owner;
TextEditor& owner;
float lastWordWrapWidth;
bool rentrant;

@@ -53034,7 +53022,7 @@ TextEditor::TextEditor (const String& name,
{
setOpaque (true);

addAndMakeVisible (viewport = new TextEditorViewport (this));
addAndMakeVisible (viewport = new TextEditorViewport (*this));
viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
viewport->setWantsKeyboardFocus (false);
viewport->setScrollBarsShown (false, false);
@@ -55784,10 +55772,6 @@ public:
{
}

~TreeViewContentComponent()
{
}

void mouseDown (const MouseEvent& e)
{
updateButtonUnderMouse (e);
@@ -56168,7 +56152,6 @@ class TreeView::TreeViewport : public Viewport
{
public:
TreeViewport() throw() : lastX (-1) {}
~TreeViewport() throw() {}

void updateComponents (const bool triggerResize = false)
{
@@ -56184,10 +56167,10 @@ public:
repaint();
}

void visibleAreaChanged (int x, int, int, int)
void visibleAreaChanged (const Rectangle<int>& newVisibleArea)
{
const bool hasScrolledSideways = (x != lastX);
lastX = x;
const bool hasScrolledSideways = (newVisibleArea.getX() != lastX);
lastX = newVisibleArea.getX();
updateComponents (hasScrolledSideways);
}

@@ -64508,7 +64491,7 @@ Viewport::~Viewport()
deleteContentComp();
}

void Viewport::visibleAreaChanged (int, int, int, int)
void Viewport::visibleAreaChanged (const Rectangle<int>&)
{
}

@@ -64529,8 +64512,8 @@ void Viewport::setViewedComponent (Component* const newViewedComponent)

if (contentComp != 0)
{
contentComp->setTopLeftPosition (0, 0);
contentHolder.addAndMakeVisible (contentComp);
setViewPosition (0, 0);
contentComp->addComponentListener (this);
}

@@ -64654,9 +64637,9 @@ void Viewport::updateVisibleArea()

Rectangle<int> contentBounds;
if (contentComp != 0)
contentBounds = contentComp->getBounds();
contentBounds = contentHolder.getLocalArea (contentComp, contentComp->getLocalBounds());

const Point<int> visibleOrigin (-contentBounds.getPosition());
Point<int> visibleOrigin (-contentBounds.getPosition());

if (hBarVisible)
{
@@ -64666,6 +64649,10 @@ void Viewport::updateVisibleArea()
horizontalScrollBar.setSingleStepSize (singleStepX);
horizontalScrollBar.cancelPendingUpdate();
}
else
{
visibleOrigin.setX (0);
}

if (vBarVisible)
{
@@ -64675,11 +64662,17 @@ void Viewport::updateVisibleArea()
verticalScrollBar.setSingleStepSize (singleStepY);
verticalScrollBar.cancelPendingUpdate();
}
else
{
visibleOrigin.setY (0);
}

// Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers.
horizontalScrollBar.setVisible (hBarVisible);
verticalScrollBar.setVisible (vBarVisible);

setViewPosition (visibleOrigin);

const Rectangle<int> visibleArea (visibleOrigin.getX(), visibleOrigin.getY(),
jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()),
jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight()));
@@ -64687,7 +64680,7 @@ void Viewport::updateVisibleArea()
if (lastVisibleArea != visibleArea)
{
lastVisibleArea = visibleArea;
visibleAreaChanged (visibleArea.getX(), visibleArea.getY(), visibleArea.getWidth(), visibleArea.getHeight());
visibleAreaChanged (visibleArea);
}

horizontalScrollBar.handleUpdateNowIfNeeded();
@@ -77287,6 +77280,32 @@ void ComponentPeer::handleFileDragExit (const StringArray& files)
lastDragAndDropCompUnderMouse = 0;
}

// We'll use an async message to deliver the drop, because if the target decides
// to run a modal loop, it can gum-up the operating system..
class AsyncFileDropMessage : public CallbackMessage
{
public:
AsyncFileDropMessage (Component* target_, FileDragAndDropTarget* dropTarget_,
const Point<int>& position_, const StringArray& files_)
: target (target_), dropTarget (dropTarget_), position (position_), files (files_)
{
}

void messageCallback()
{
if (target != 0)
dropTarget->filesDropped (files, position.getX(), position.getY());
}

private:
WeakReference<Component> target;
FileDragAndDropTarget* const dropTarget;
const Point<int> position;
const StringArray files;

JUCE_DECLARE_NON_COPYABLE (AsyncFileDropMessage);
};

void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
{
handleFileDragMove (files, position);
@@ -77311,32 +77330,6 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<in
return;
}

// We'll use an async message to deliver the drop, because if the target decides
// to run a modal loop, it can gum-up the operating system..
class AsyncFileDropMessage : public CallbackMessage
{
public:
AsyncFileDropMessage (Component* target_, FileDragAndDropTarget* dropTarget_,
const Point<int>& position_, const StringArray& files_)
: target (target_), dropTarget (dropTarget_), position (position_), files (files_)
{
}

void messageCallback()
{
if (target != 0)
dropTarget->filesDropped (files, position.getX(), position.getY());
}

private:
WeakReference<Component> target;
FileDragAndDropTarget* dropTarget;
Point<int> position;
StringArray files;

// (NB: don't make this non-copyable, which messes up in VC)
};

(new AsyncFileDropMessage (targetComp, target, targetComp->getLocalPoint (component, position), files))->post();
}
}


+ 6
- 2
juce_amalgamated.h View File

@@ -37855,8 +37855,7 @@ public:
This will be called when the visible area is moved either be scrolling or
by calls to setViewPosition(), etc.
*/
virtual void visibleAreaChanged (int visibleX, int visibleY,
int visibleW, int visibleH);
virtual void visibleAreaChanged (const Rectangle<int>& newVisibleArea);

/** Turns scrollbars on or off.

@@ -37938,6 +37937,11 @@ private:
void updateVisibleArea();
void deleteContentComp();

#if JUCE_CATCH_DEPRECATED_CODE_MISUSE
// If you get an error here, it's because this method's parameters have changed! See the new definition above..
virtual int visibleAreaChanged (int, int, int, int) { return 0; }
#endif

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Viewport);
};



+ 1
- 5
src/gui/components/controls/juce_ListBox.cpp View File

@@ -169,10 +169,6 @@ public:
content->setWantsKeyboardFocus (false);
}
~ListViewport()
{
}
ListBoxRowComponent* getComponentForRow (const int row) const throw()
{
return rows [row % jmax (1, rows.size())];
@@ -196,7 +192,7 @@ public:
return -1;
}
void visibleAreaChanged (int, int, int, int)
void visibleAreaChanged (const Rectangle<int>&)
{
updateVisibleArea (true);


+ 6
- 14
src/gui/components/controls/juce_TextEditor.cpp View File

@@ -382,10 +382,6 @@ public:
{
}
~Iterator()
{
}
//==============================================================================
bool next()
{
@@ -912,35 +908,31 @@ private:
class TextEditorViewport : public Viewport
{
public:
TextEditorViewport (TextEditor* const owner_)
TextEditorViewport (TextEditor& owner_)
: owner (owner_), lastWordWrapWidth (0), rentrant (false)
{
}
~TextEditorViewport()
{
}
void visibleAreaChanged (int, int, int, int)
void visibleAreaChanged (const Rectangle<int>&)
{
if (! rentrant) // it's rare, but possible to get into a feedback loop as the viewport's scrollbars
// appear and disappear, causing the wrap width to change.
{
const float wordWrapWidth = owner->getWordWrapWidth();
const float wordWrapWidth = owner.getWordWrapWidth();
if (wordWrapWidth != lastWordWrapWidth)
{
lastWordWrapWidth = wordWrapWidth;
rentrant = true;
owner->updateTextHolderSize();
owner.updateTextHolderSize();
rentrant = false;
}
}
}
private:
TextEditor* const owner;
TextEditor& owner;
float lastWordWrapWidth;
bool rentrant;
@@ -1000,7 +992,7 @@ TextEditor::TextEditor (const String& name,
{
setOpaque (true);
addAndMakeVisible (viewport = new TextEditorViewport (this));
addAndMakeVisible (viewport = new TextEditorViewport (*this));
viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
viewport->setWantsKeyboardFocus (false);
viewport->setScrollBarsShown (false, false);


+ 3
- 8
src/gui/components/controls/juce_TreeView.cpp View File

@@ -47,10 +47,6 @@ public:
{
}
~TreeViewContentComponent()
{
}
void mouseDown (const MouseEvent& e)
{
updateButtonUnderMouse (e);
@@ -432,7 +428,6 @@ class TreeView::TreeViewport : public Viewport
{
public:
TreeViewport() throw() : lastX (-1) {}
~TreeViewport() throw() {}
void updateComponents (const bool triggerResize = false)
{
@@ -448,10 +443,10 @@ public:
repaint();
}
void visibleAreaChanged (int x, int, int, int)
void visibleAreaChanged (const Rectangle<int>& newVisibleArea)
{
const bool hasScrolledSideways = (x != lastX);
lastX = x;
const bool hasScrolledSideways = (newVisibleArea.getX() != lastX);
lastX = newVisibleArea.getX();
updateComponents (hasScrolledSideways);
}


+ 15
- 5
src/gui/components/layout/juce_Viewport.cpp View File

@@ -62,7 +62,7 @@ Viewport::~Viewport()
}
//==============================================================================
void Viewport::visibleAreaChanged (int, int, int, int)
void Viewport::visibleAreaChanged (const Rectangle<int>&)
{
}
@@ -84,8 +84,8 @@ void Viewport::setViewedComponent (Component* const newViewedComponent)
if (contentComp != 0)
{
contentComp->setTopLeftPosition (0, 0);
contentHolder.addAndMakeVisible (contentComp);
setViewPosition (0, 0);
contentComp->addComponentListener (this);
}
@@ -210,9 +210,9 @@ void Viewport::updateVisibleArea()
Rectangle<int> contentBounds;
if (contentComp != 0)
contentBounds = contentComp->getBounds();
contentBounds = contentHolder.getLocalArea (contentComp, contentComp->getLocalBounds());
const Point<int> visibleOrigin (-contentBounds.getPosition());
Point<int> visibleOrigin (-contentBounds.getPosition());
if (hBarVisible)
{
@@ -222,6 +222,10 @@ void Viewport::updateVisibleArea()
horizontalScrollBar.setSingleStepSize (singleStepX);
horizontalScrollBar.cancelPendingUpdate();
}
else
{
visibleOrigin.setX (0);
}
if (vBarVisible)
{
@@ -231,11 +235,17 @@ void Viewport::updateVisibleArea()
verticalScrollBar.setSingleStepSize (singleStepY);
verticalScrollBar.cancelPendingUpdate();
}
else
{
visibleOrigin.setY (0);
}
// Force the visibility *after* setting the ranges to avoid flicker caused by edge conditions in the numbers.
horizontalScrollBar.setVisible (hBarVisible);
verticalScrollBar.setVisible (vBarVisible);
setViewPosition (visibleOrigin);
const Rectangle<int> visibleArea (visibleOrigin.getX(), visibleOrigin.getY(),
jmin (contentBounds.getWidth() - visibleOrigin.getX(), contentArea.getWidth()),
jmin (contentBounds.getHeight() - visibleOrigin.getY(), contentArea.getHeight()));
@@ -243,7 +253,7 @@ void Viewport::updateVisibleArea()
if (lastVisibleArea != visibleArea)
{
lastVisibleArea = visibleArea;
visibleAreaChanged (visibleArea.getX(), visibleArea.getY(), visibleArea.getWidth(), visibleArea.getHeight());
visibleAreaChanged (visibleArea);
}
horizontalScrollBar.handleUpdateNowIfNeeded();


+ 6
- 2
src/gui/components/layout/juce_Viewport.h View File

@@ -179,8 +179,7 @@ public:
This will be called when the visible area is moved either be scrolling or
by calls to setViewPosition(), etc.
*/
virtual void visibleAreaChanged (int visibleX, int visibleY,
int visibleW, int visibleH);
virtual void visibleAreaChanged (const Rectangle<int>& newVisibleArea);
//==============================================================================
/** Turns scrollbars on or off.
@@ -265,6 +264,11 @@ private:
void updateVisibleArea();
void deleteContentComp();
#if JUCE_CATCH_DEPRECATED_CODE_MISUSE
// If you get an error here, it's because this method's parameters have changed! See the new definition above..
virtual int visibleAreaChanged (int, int, int, int) { return 0; }
#endif
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Viewport);
};


+ 26
- 26
src/gui/components/windows/juce_ComponentPeer.cpp View File

@@ -484,6 +484,32 @@ void ComponentPeer::handleFileDragExit (const StringArray& files)
lastDragAndDropCompUnderMouse = 0;
}
// We'll use an async message to deliver the drop, because if the target decides
// to run a modal loop, it can gum-up the operating system..
class AsyncFileDropMessage : public CallbackMessage
{
public:
AsyncFileDropMessage (Component* target_, FileDragAndDropTarget* dropTarget_,
const Point<int>& position_, const StringArray& files_)
: target (target_), dropTarget (dropTarget_), position (position_), files (files_)
{
}
void messageCallback()
{
if (target != 0)
dropTarget->filesDropped (files, position.getX(), position.getY());
}
private:
WeakReference<Component> target;
FileDragAndDropTarget* const dropTarget;
const Point<int> position;
const StringArray files;
JUCE_DECLARE_NON_COPYABLE (AsyncFileDropMessage);
};
void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
{
handleFileDragMove (files, position);
@@ -508,32 +534,6 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<in
return;
}
// We'll use an async message to deliver the drop, because if the target decides
// to run a modal loop, it can gum-up the operating system..
class AsyncFileDropMessage : public CallbackMessage
{
public:
AsyncFileDropMessage (Component* target_, FileDragAndDropTarget* dropTarget_,
const Point<int>& position_, const StringArray& files_)
: target (target_), dropTarget (dropTarget_), position (position_), files (files_)
{
}
void messageCallback()
{
if (target != 0)
dropTarget->filesDropped (files, position.getX(), position.getY());
}
private:
WeakReference<Component> target;
FileDragAndDropTarget* dropTarget;
Point<int> position;
StringArray files;
// (NB: don't make this non-copyable, which messes up in VC)
};
(new AsyncFileDropMessage (targetComp, target, targetComp->getLocalPoint (component, position), files))->post();
}
}


Loading…
Cancel
Save