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

Created a new class Component::SafePointer that keeps a pointer to a component and automatically nulls it if the component is deleted - this makes it a much more elegant replacement for the old ComponentDeletionWatcher class. Removed Component::getComponentUnderMouse(), which doesn't fit with multi-touch interfaces - for similar functionality, use the Desktop::getMouseInputSource() methods to find out what MouseInputSources are available, and ask them about the component they are over or dragging.

This commit is contained in:
Julian Storer 2010-02-25 22:33:44 +00:00
parent bc5a7a6b7e
commit 5fecb8a353
49 changed files with 1251 additions and 1152 deletions

View file

@ -28,6 +28,7 @@
BEGIN_JUCE_NAMESPACE
#include "juce_AlertWindow.h"
#include "../windows/juce_ComponentPeer.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../buttons/juce_TextButton.h"
#include "../controls/juce_TextEditor.h"

View file

@ -27,9 +27,8 @@
BEGIN_JUCE_NAMESPACE
#include "juce_ComponentPeer.h"
#include "../../../application/juce_Application.h"
#include "../juce_Component.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../juce_Desktop.h"
#include "../../../events/juce_MessageManager.h"
#include "../../../core/juce_Time.h"
@ -167,7 +166,7 @@ bool ComponentPeer::handleKeyPress (const int keyCode,
while (target != 0)
{
const ComponentDeletionWatcher deletionChecker (target);
const Component::SafePointer<Component> deletionChecker (target);
if (target->keyListeners_ != 0)
{
@ -175,7 +174,7 @@ bool ComponentPeer::handleKeyPress (const int keyCode,
{
keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
if (keyWasUsed || deletionChecker.hasBeenDeleted())
if (keyWasUsed || deletionChecker == 0)
return keyWasUsed;
i = jmin (i, target->keyListeners_->size());
@ -184,7 +183,7 @@ bool ComponentPeer::handleKeyPress (const int keyCode,
keyWasUsed = target->keyPressed (keyInfo);
if (keyWasUsed || deletionChecker.hasBeenDeleted())
if (keyWasUsed || deletionChecker == 0)
break;
if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
@ -221,11 +220,11 @@ bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
while (target != 0)
{
const ComponentDeletionWatcher deletionChecker (target);
const Component::SafePointer<Component> deletionChecker (target);
keyWasUsed = target->keyStateChanged (isKeyDown);
if (keyWasUsed || deletionChecker.hasBeenDeleted())
if (keyWasUsed || deletionChecker == 0)
break;
if (target->keyListeners_ != 0)
@ -234,7 +233,7 @@ bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
{
keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
if (keyWasUsed || deletionChecker.hasBeenDeleted())
if (keyWasUsed || deletionChecker == 0)
return keyWasUsed;
i = jmin (i, target->keyListeners_->size());
@ -295,7 +294,7 @@ void ComponentPeer::handleMovedOrResized()
if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
{
const ComponentDeletionWatcher deletionChecker (component);
const Component::SafePointer<Component> deletionChecker (component);
const Rectangle<int> newBounds (getBounds());
const bool wasMoved = (component->getPosition() != newBounds.getPosition());
@ -310,7 +309,7 @@ void ComponentPeer::handleMovedOrResized()
component->sendMovedResizedMessages (wasMoved, wasResized);
if (deletionChecker.hasBeenDeleted())
if (deletionChecker == 0)
return;
}
}
@ -409,10 +408,8 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<in
{
updateCurrentModifiers();
FileDragAndDropTarget* lastTarget = 0;
if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
FileDragAndDropTarget* lastTarget
= const_cast<FileDragAndDropTarget*> (dynamic_cast<const FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent)));
FileDragAndDropTarget* newTarget = 0;
@ -432,10 +429,8 @@ void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<in
if (newTarget != 0)
{
Component* const targetComp = dynamic_cast <Component*> (newTarget);
const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
newTarget->fileDragEnter (files, pos.getX(), pos.getY());
}
}
@ -466,9 +461,10 @@ void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<in
{
handleFileDragMove (files, position);
if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
if (dragAndDropTargetComponent != 0)
{
FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
FileDragAndDropTarget* const target
= const_cast<FileDragAndDropTarget*> (dynamic_cast<const FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent)));
dragAndDropTargetComponent = 0;
lastDragAndDropCompUnderMouse = 0;

View file

@ -26,8 +26,7 @@
#ifndef __JUCE_COMPONENTPEER_JUCEHEADER__
#define __JUCE_COMPONENTPEER_JUCEHEADER__
class Component;
class Graphics;
#include "../juce_Component.h"
#include "../mouse/juce_MouseCursor.h"
#include "../keyboard/juce_TextInputTarget.h"
#include "../../../events/juce_MessageListener.h"
@ -35,7 +34,6 @@ class Graphics;
#include "../../graphics/geometry/juce_RectangleList.h"
class ComponentBoundsConstrainer;
class ComponentDeletionWatcher;
//==============================================================================
@ -368,7 +366,7 @@ protected:
private:
//==============================================================================
Component* lastFocusedComponent;
ScopedPointer <ComponentDeletionWatcher> dragAndDropTargetComponent;
Component::SafePointer<Component> dragAndDropTargetComponent;
Component* lastDragAndDropCompUnderMouse;
bool fakeMouseMessageSent : 1, isWindowMinimised : 1;

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_DocumentWindow.h"
#include "juce_ComponentPeer.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../../graphics/imaging/juce_Image.h"

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_ResizableWindow.h"
#include "juce_ComponentPeer.h"
#include "../juce_Desktop.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../../graphics/geometry/juce_RectangleList.h"

View file

@ -28,6 +28,7 @@
BEGIN_JUCE_NAMESPACE
#include "juce_SplashScreen.h"
#include "../windows/juce_ComponentPeer.h"
#include "../../../events/juce_MessageManager.h"
#include "../../graphics/imaging/juce_ImageCache.h"
#include "../juce_Desktop.h"

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_TooltipWindow.h"
#include "../windows/juce_ComponentPeer.h"
#include "../../../core/juce_Time.h"
#include "../../../threads/juce_Process.h"
#include "../lookandfeel/juce_LookAndFeel.h"

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_TopLevelWindow.h"
#include "../windows/juce_ComponentPeer.h"
#include "../juce_Desktop.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../special/juce_DropShadower.h"