1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-29 02:40:05 +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

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_ApplicationCommandManager.h"
#include "juce_Application.h"
#include "../gui/components/windows/juce_ComponentPeer.h"
#include "../gui/components/keyboard/juce_KeyPressMappingSet.h"
#include "../gui/components/windows/juce_ResizableWindow.h"
#include "../gui/components/juce_Desktop.h"

View file

@ -111,7 +111,7 @@ public:
{
const ScopedLockType lock (getLock());
return (((unsigned int) index) < (unsigned int) numUsed) ? data.elements [index]
: (ObjectClass*) 0;
: static_cast <ObjectClass*> (0);
}
/** Returns a pointer to the object at this index in the array, without checking whether the index is in-range.
@ -135,7 +135,7 @@ public:
{
const ScopedLockType lock (getLock());
return numUsed > 0 ? data.elements [0]
: (ObjectClass*) 0;
: static_cast <ObjectClass*> (0);
}
/** Returns a pointer to the last object in the array.
@ -147,7 +147,7 @@ public:
{
const ScopedLockType lock (getLock());
return numUsed > 0 ? data.elements [numUsed - 1]
: (ObjectClass*) 0;
: static_cast <ObjectClass*> (0);
}
//==============================================================================

View file

@ -28,7 +28,6 @@
BEGIN_JUCE_NAMESPACE
#include "juce_Button.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../keyboard/juce_KeyPressMappingSet.h"
#include "../../../text/juce_LocalisedStrings.h"
#include "../../../events/juce_Timer.h"
@ -145,16 +144,20 @@ void Button::setToggleState (const bool shouldBeOn,
{
if (shouldBeOn != lastToggleState)
{
const ComponentDeletionWatcher deletionWatcher (this);
isOn = shouldBeOn;
lastToggleState = shouldBeOn;
repaint();
if (sendChangeNotification)
{
Component::SafePointer<Component> deletionWatcher (this);
sendClickMessage (ModifierKeys());
if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
if (deletionWatcher == 0)
return;
}
if (lastToggleState)
turnOffOtherButtonsInGroup (sendChangeNotification);
}
}
@ -198,7 +201,7 @@ void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
if (p != 0 && radioGroupId != 0)
{
const ComponentDeletionWatcher deletionWatcher (this);
Component::SafePointer<Component> deletionWatcher (this);
for (int i = p->getNumChildComponents(); --i >= 0;)
{
@ -212,7 +215,7 @@ void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
{
b->setToggleState (false, sendChangeNotification);
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
}
}
@ -365,7 +368,7 @@ void Button::removeButtonListener (ButtonListener* const listener)
void Button::sendClickMessage (const ModifierKeys& modifiers)
{
const ComponentDeletionWatcher cdw (this);
Component::SafePointer<Component> deletionWatcher (this);
if (commandManagerToUse != 0 && commandID != 0)
{
@ -378,7 +381,7 @@ void Button::sendClickMessage (const ModifierKeys& modifiers)
clicked (modifiers);
if (! cdw.hasBeenDeleted())
if (deletionWatcher != 0)
{
for (int i = buttonListeners.size(); --i >= 0;)
{
@ -388,7 +391,7 @@ void Button::sendClickMessage (const ModifierKeys& modifiers)
{
bl->buttonClicked (this);
if (cdw.hasBeenDeleted())
if (deletionWatcher == 0)
return;
}
}
@ -397,11 +400,11 @@ void Button::sendClickMessage (const ModifierKeys& modifiers)
void Button::sendStateMessage()
{
const ComponentDeletionWatcher cdw (this);
Component::SafePointer<Component> deletionWatcher (this);
buttonStateChanged();
if (cdw.hasBeenDeleted())
if (deletionWatcher == 0)
return;
for (int i = buttonListeners.size(); --i >= 0;)
@ -412,7 +415,7 @@ void Button::sendStateMessage()
{
bl->buttonStateChanged (this);
if (cdw.hasBeenDeleted())
if (deletionWatcher == 0)
return;
}
}
@ -694,13 +697,13 @@ void Button::repeatTimerCallback()
lastTimeCallbackTime = now;
const ComponentDeletionWatcher cdw (this);
Component::SafePointer<Component> deletionWatcher (this);
for (int i = numTimesToCallback; --i >= 0;)
{
internalClickCallback (ModifierKeys::getCurrentModifiers());
if (cdw.hasBeenDeleted() || ! isDown())
if (deletionWatcher == 0 || ! isDown())
return;
}
}

View file

@ -29,7 +29,6 @@ BEGIN_JUCE_NAMESPACE
#include "juce_ToggleButton.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../juce_ComponentDeletionWatcher.h"
//==============================================================================

View file

@ -525,7 +525,7 @@ void ComboBox::showPopup()
if (! menuActive)
{
const int selectedId = getSelectedId();
ComponentDeletionWatcher deletionWatcher (this);
Component::SafePointer<Component> deletionWatcher (this);
PopupMenu menu;
@ -553,7 +553,7 @@ void ComboBox::showPopup()
const int resultId = menu.showAt (this, selectedId,
getWidth(), 1, itemHeight);
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
menuActive = false;

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_Label.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../windows/juce_ComponentPeer.h"
//==============================================================================
@ -58,7 +59,7 @@ Label::~Label()
{
textValue.removeListener (this);
if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
if (ownerComponent != 0)
ownerComponent->removeComponentListener (this);
editor = 0;
@ -78,7 +79,7 @@ void Label::setText (const String& newText,
textWasChanged();
if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
if (ownerComponent != 0)
componentMovedOrResized (*ownerComponent, true, true);
if (broadcastChangeMessage)
@ -137,21 +138,23 @@ void Label::setBorderSize (int h, int v)
}
//==============================================================================
Component* Label::getAttachedComponent() const
{
return const_cast <Component*> (static_cast <const Component*> (ownerComponent));
}
void Label::attachToComponent (Component* owner,
const bool onLeft)
{
if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
if (ownerComponent != 0)
ownerComponent->removeComponentListener (this);
deletionWatcher = 0;
ownerComponent = owner;
leftOfOwnerComp = onLeft;
if (ownerComponent != 0)
{
deletionWatcher = new ComponentDeletionWatcher (owner);
setVisible (owner->isVisible());
ownerComponent->addComponentListener (this);
componentParentHierarchyChanged (*ownerComponent);
@ -241,7 +244,7 @@ bool Label::updateFromTextEditorContents()
textWasChanged();
if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
if (ownerComponent != 0)
componentMovedOrResized (*ownerComponent, true, true);
return true;

View file

@ -26,7 +26,6 @@
#ifndef __JUCE_LABEL_JUCEHEADER__
#define __JUCE_LABEL_JUCEHEADER__
#include "../juce_ComponentDeletionWatcher.h"
#include "juce_TextEditor.h"
class Label;
@ -178,7 +177,7 @@ public:
Returns 0 if the label is not attached.
*/
Component* getAttachedComponent() const throw() { return ownerComponent; }
Component* getAttachedComponent() const;
/** If the label is attached to the left of another component, this returns true.
@ -329,8 +328,7 @@ private:
Justification justification;
ScopedPointer <TextEditor> editor;
SortedSet <void*> listeners;
Component* ownerComponent;
ScopedPointer <ComponentDeletionWatcher> deletionWatcher;
Component::SafePointer<Component> ownerComponent;
int horizontalBorderSize, verticalBorderSize;
float minimumHorizontalScale;
bool editSingleClick : 1;

View file

@ -28,6 +28,7 @@
BEGIN_JUCE_NAMESPACE
#include "juce_TextEditor.h"
#include "../windows/juce_ComponentPeer.h"
#include "../../graphics/fonts/juce_GlyphArrangement.h"
#include "../../../utilities/juce_SystemClipboard.h"
#include "../../../core/juce_Time.h"
@ -2165,7 +2166,7 @@ void TextEditor::resized()
void TextEditor::handleCommandMessage (const int commandId)
{
const ComponentDeletionWatcher deletionChecker (this);
Component::SafePointer<Component> deletionChecker (this);
for (int i = listeners.size(); --i >= 0;)
{
@ -2196,7 +2197,7 @@ void TextEditor::handleCommandMessage (const int commandId)
break;
}
if (i > 0 && deletionChecker.hasBeenDeleted())
if (deletionChecker == 0)
return;
}
}

View file

@ -31,6 +31,7 @@ BEGIN_JUCE_NAMESPACE
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../../../containers/juce_BitArray.h"
#include "../mouse/juce_DragAndDropContainer.h"
#include "../mouse/juce_MouseInputSource.h"
#include "../../graphics/imaging/juce_Image.h"
@ -168,6 +169,24 @@ public:
void paint (Graphics& g);
TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
static bool isMouseDraggingInChildCompOf (Component* const comp)
{
for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
{
MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
if (source->isDragging())
{
Component* const underMouse = source->getComponentUnderMouse();
if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
return true;
}
}
return false;
}
void updateComponents()
{
const int visibleTop = -getY();
@ -229,10 +248,7 @@ public:
}
}
if ((! keep)
&& Component::isMouseButtonDownAnywhere()
&& (comp == Component::getComponentUnderMouse()
|| comp->isParentOf (Component::getComponentUnderMouse())))
if ((! keep) && isMouseDraggingInChildCompOf (comp))
{
keep = true;
comp->setSize (0, 0);

View file

@ -28,7 +28,6 @@
BEGIN_JUCE_NAMESPACE
#include "juce_DirectoryContentsDisplayComponent.h"
#include "../juce_ComponentDeletionWatcher.h"
//==============================================================================
@ -61,13 +60,13 @@ void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* con
void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
{
const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
Component::SafePointer<Component> deletionWatcher (dynamic_cast <Component*> (this));
for (int i = listeners.size(); --i >= 0;)
{
((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
i = jmin (i, listeners.size() - 1);
@ -78,13 +77,13 @@ void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file,
{
if (fileList.getDirectory().exists())
{
const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
Component::SafePointer<Component> deletionWatcher (dynamic_cast <Component*> (this));
for (int i = listeners.size(); --i >= 0;)
{
((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
i = jmin (i, listeners.size() - 1);
@ -96,13 +95,13 @@ void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file
{
if (fileList.getDirectory().exists())
{
const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
Component::SafePointer<Component> deletionWatcher (dynamic_cast <Component*> (this));
for (int i = listeners.size(); --i >= 0;)
{
((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
i = jmin (i, listeners.size() - 1);

View file

@ -26,6 +26,7 @@
#ifndef __JUCE_DIRECTORYCONTENTSDISPLAYCOMPONENT_JUCEHEADER__
#define __JUCE_DIRECTORYCONTENTSDISPLAYCOMPONENT_JUCEHEADER__
#include "../juce_Component.h"
#include "juce_DirectoryContentsList.h"
#include "juce_FileBrowserListener.h"

View file

@ -302,18 +302,19 @@ void FileBrowserComponent::resized()
//==============================================================================
void FileBrowserComponent::sendListenerChangeMessage()
{
ComponentDeletionWatcher deletionWatcher (this);
Component::SafePointer<Component> deletionWatcher (this);
if (previewComp != 0)
previewComp->selectedFileChanged (getSelectedFile (0));
jassert (! deletionWatcher.hasBeenDeleted());
// You shouldn't delete the browser when the file gets changed!
jassert (deletionWatcher != 0);
for (int i = listeners.size(); --i >= 0;)
{
((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
i = jmin (i, listeners.size() - 1);
@ -350,13 +351,13 @@ void FileBrowserComponent::selectionChanged()
void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
{
ComponentDeletionWatcher deletionWatcher (this);
Component::SafePointer<Component> deletionWatcher (this);
for (int i = listeners.size(); --i >= 0;)
{
((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
i = jmin (i, listeners.size() - 1);
@ -371,13 +372,13 @@ void FileBrowserComponent::fileDoubleClicked (const File& f)
}
else
{
ComponentDeletionWatcher deletionWatcher (this);
Component::SafePointer<Component> deletionWatcher (this);
for (int i = listeners.size(); --i >= 0;)
{
((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
if (deletionWatcher.hasBeenDeleted())
if (deletionWatcher == 0)
return;
i = jmin (i, listeners.size() - 1);

View file

@ -102,11 +102,7 @@ bool FileChooser::showDialog (const bool selectsDirectories,
const bool selectMultipleFiles,
FilePreviewComponent* const previewComponent)
{
ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
if (currentlyFocused != 0)
currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
results.clear();
@ -160,8 +156,8 @@ bool FileChooser::showDialog (const bool selectsDirectories,
}
}
if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
currentlyFocused->grabKeyboardFocus();
if (previouslyFocused != 0)
previouslyFocused->grabKeyboardFocus();
return results.size() > 0;
}

View file

@ -30,6 +30,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_Component.h"
#include "juce_ComponentDeletionWatcher.h"
#include "juce_Desktop.h"
#include "windows/juce_ComponentPeer.h"
#include "keyboard/juce_KeyListener.h"
#include "lookandfeel/juce_LookAndFeel.h"
#include "../../application/juce_Application.h"
@ -44,7 +45,6 @@ BEGIN_JUCE_NAMESPACE
#include "mouse/juce_MouseInputSource.h"
//==============================================================================
Component* Component::componentUnderMouse = 0;
Component* Component::currentlyFocusedComponent = 0;
static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
@ -92,6 +92,17 @@ Component::Component (const String& name) throw()
Component::~Component()
{
if (componentListeners_ != 0)
{
for (int i = componentListeners_->size(); --i >= 0;)
{
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentBeingDeleted (*this);
i = jmin (i, componentListeners_->size());
}
}
if (parentComponent_ != 0)
{
parentComponent_->removeChildComponent (this);
@ -102,9 +113,6 @@ Component::~Component()
giveAwayFocus();
}
if (componentUnderMouse == this)
componentUnderMouse = 0;
if (flags.hasHeavyweightPeerFlag)
removeFromDesktop();
@ -141,14 +149,14 @@ void Component::setName (const String& name)
if (componentListeners_ != 0)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
for (int i = componentListeners_->size(); --i >= 0;)
{
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentNameChanged (*this);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, componentListeners_->size());
@ -166,7 +174,7 @@ void Component::setVisible (bool shouldBeVisible)
// thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
checkMessageManagerIsLocked
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
flags.visibleFlag = shouldBeVisible;
@ -188,7 +196,7 @@ void Component::setVisible (bool shouldBeVisible)
sendVisibilityChangeMessage();
if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
{
ComponentPeer* const peer = getPeer();
@ -208,18 +216,18 @@ void Component::visibilityChanged()
void Component::sendVisibilityChangeMessage()
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
visibilityChanged();
if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
if (safePointer != 0 && componentListeners_ != 0)
{
for (int i = componentListeners_->size(); --i >= 0;)
{
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentVisibilityChanged (*this);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, componentListeners_->size());
@ -398,7 +406,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
#if JUCE_LINUX
// it's wise to give the component a non-zero size before
@ -430,7 +438,7 @@ void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
if (parentComponent_ != 0)
parentComponent_->removeChildComponent (this);
if (! deletionChecker.hasBeenDeleted())
if (safePointer != 0)
{
flags.hasHeavyweightPeerFlag = true;
@ -900,14 +908,14 @@ void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasRes
if (componentListeners_ != 0)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
for (int i = componentListeners_->size(); --i >= 0;)
{
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentMovedOrResized (*this, wasMoved, wasResized);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, componentListeners_->size());
@ -1302,14 +1310,14 @@ void Component::childrenChanged()
void Component::internalChildrenChanged()
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
const bool hasListeners = componentListeners_ != 0;
childrenChanged();
if (hasListeners)
{
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
for (int i = componentListeners_->size(); --i >= 0;)
@ -1317,7 +1325,7 @@ void Component::internalChildrenChanged()
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentChildrenChanged (*this);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, componentListeners_->size());
@ -1329,7 +1337,7 @@ void Component::internalHierarchyChanged()
{
parentHierarchyChanged();
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
if (componentListeners_ != 0)
{
@ -1338,7 +1346,7 @@ void Component::internalHierarchyChanged()
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentParentHierarchyChanged (*this);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, componentListeners_->size());
@ -1351,8 +1359,8 @@ void Component::internalHierarchyChanged()
// you really shouldn't delete the parent component during a callback telling you
// that it's changed..
jassert (! deletionChecker.hasBeenDeleted());
if (deletionChecker.hasBeenDeleted())
jassert (safePointer != 0);
if (safePointer == 0)
return;
i = jmin (i, childComponentList_.size());
@ -1375,11 +1383,7 @@ int Component::runModalLoop()
->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
}
Component* const prevFocused = getCurrentlyFocusedComponent();
ScopedPointer <ComponentDeletionWatcher> deletionChecker;
if (prevFocused != 0)
deletionChecker = new ComponentDeletionWatcher (prevFocused);
SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
if (! isCurrentlyModal())
enterModalState();
@ -1420,7 +1424,7 @@ int Component::runModalLoop()
modalComponentStack.removeValue (this);
if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
if (prevFocused != 0)
prevFocused->grabKeyboardFocus();
return returnValue;
@ -1824,13 +1828,13 @@ void Component::sendLookAndFeelChange()
// during the lookAndFeelChanged() callback)
jassert (isValidComponent());
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
for (int i = childComponentList_.size(); --i >= 0;)
{
childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, childComponentList_.size());
@ -2206,7 +2210,7 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point<int>&
flags.mouseOverFlag = true;
flags.draggingFlag = false;
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
if (flags.repaintOnMouseActivityFlag)
repaint();
@ -2217,7 +2221,7 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point<int>&
mouseEnter (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
Desktop::getInstance().resetTimer();
@ -2226,7 +2230,7 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point<int>&
{
((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, Desktop::getInstance().mouseListeners.size());
@ -2238,24 +2242,24 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point<int>&
{
((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, mouseListeners_->size());
}
}
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2268,13 +2272,13 @@ void Component::internalMouseEnter (MouseInputSource& source, const Point<int>&
void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
if (flags.draggingFlag)
{
internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
}
@ -2292,7 +2296,7 @@ void Component::internalMouseExit (MouseInputSource& source, const Point<int>& r
time, 0, false);
mouseExit (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
Desktop::getInstance().resetTimer();
@ -2301,7 +2305,7 @@ void Component::internalMouseExit (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, Desktop::getInstance().mouseListeners.size());
@ -2313,24 +2317,24 @@ void Component::internalMouseExit (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, mouseListeners_->size());
}
}
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2360,7 +2364,7 @@ public:
Desktop& desktop = Desktop::getInstance();
int numMiceDown = 0;
for (int i = desktop.getNumMouseInputSources(); --i >= 0;)
for (int i = desktop.getNumMouseSources(); --i >= 0;)
{
MouseInputSource* const source = desktop.getMouseSource(i);
if (source->isDragging())
@ -2402,13 +2406,13 @@ void Component::internalMouseDown (MouseInputSource& source, const Point<int>& r
{
Desktop& desktop = Desktop::getInstance();
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
if (isCurrentlyBlockedByAnotherModalComponent())
{
internalModalInputAttempt();
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
// If processing the input attempt has exited the modal loop, we'll allow the event
@ -2426,7 +2430,7 @@ void Component::internalMouseDown (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2445,7 +2449,7 @@ void Component::internalMouseDown (MouseInputSource& source, const Point<int>& r
{
c->toFront (true);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
}
@ -2454,67 +2458,69 @@ void Component::internalMouseDown (MouseInputSource& source, const Point<int>& r
}
if (! flags.dontFocusOnMouseClickFlag)
{
grabFocusInternal (focusChangedByMouseClick);
if (! deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
}
flags.draggingFlag = true;
flags.mouseOverFlag = true;
if (flags.repaintOnMouseActivityFlag)
repaint();
const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
this, time, relativePos, time,
source.getNumberOfMultipleClicks(), false);
mouseDown (me);
if (safePointer == 0)
return;
desktop.resetTimer();
for (int i = desktop.mouseListeners.size(); --i >= 0;)
{
flags.draggingFlag = true;
flags.mouseOverFlag = true;
((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
if (flags.repaintOnMouseActivityFlag)
repaint();
const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
this, time, relativePos, time,
source.getNumberOfMultipleClicks(), false);
mouseDown (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
desktop.resetTimer();
i = jmin (i, desktop.mouseListeners.size());
}
for (int i = desktop.mouseListeners.size(); --i >= 0;)
if (mouseListeners_ != 0)
{
for (int i = mouseListeners_->size(); --i >= 0;)
{
((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
i = jmin (i, mouseListeners_->size());
}
}
if (mouseListeners_ != 0)
Component* p = parentComponent_;
while (p != 0)
{
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
for (int i = mouseListeners_->size(); --i >= 0;)
{
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
if (deletionChecker.hasBeenDeleted())
return;
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, mouseListeners_->size());
}
i = jmin (i, p->numDeepMouseListeners);
}
const Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
return;
i = jmin (i, p->numDeepMouseListeners);
}
p = p->parentComponent_;
}
p = p->parentComponent_;
}
}
@ -2527,7 +2533,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
flags.draggingFlag = false;
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
if (flags.repaintOnMouseActivityFlag)
repaint();
@ -2541,7 +2547,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
mouseUp (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
desktop.resetTimer();
@ -2550,7 +2556,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
{
((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2562,7 +2568,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
{
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, mouseListeners_->size());
@ -2570,17 +2576,17 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
}
{
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2602,7 +2608,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
{
((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2610,7 +2616,7 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
for (i = numListeners; --i >= 0;)
{
if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
if (safePointer == 0 || mouseListeners_ == 0)
return;
MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
@ -2618,20 +2624,20 @@ void Component::internalMouseUp (MouseInputSource& source, const Point<int>& rel
ml->mouseDoubleClick (me);
}
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2651,7 +2657,7 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& r
flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
const MouseEvent me (source, relativePos,
source.getCurrentModifiers(), this, time,
@ -2662,7 +2668,7 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& r
mouseDrag (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
desktop.resetTimer();
@ -2671,7 +2677,7 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2683,24 +2689,24 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, mouseListeners_->size());
}
}
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2713,7 +2719,7 @@ void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& r
void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
if (isValidComponent())
{
@ -2734,7 +2740,7 @@ void Component::internalMouseMove (MouseInputSource& source, const Point<int>& r
mouseMove (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
desktop.resetTimer();
@ -2743,7 +2749,7 @@ void Component::internalMouseMove (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2755,24 +2761,24 @@ void Component::internalMouseMove (MouseInputSource& source, const Point<int>& r
{
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, mouseListeners_->size());
}
}
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2788,7 +2794,7 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point<int>&
const Time& time, const float amountX, const float amountY)
{
Desktop& desktop = Desktop::getInstance();
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
const float wheelIncrementX = amountX * (1.0f / 256.0f);
const float wheelIncrementY = amountY * (1.0f / 256.0f);
@ -2803,7 +2809,7 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point<int>&
{
((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2813,14 +2819,14 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point<int>&
{
mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
for (int i = desktop.mouseListeners.size(); --i >= 0;)
{
((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, desktop.mouseListeners.size());
@ -2832,24 +2838,24 @@ void Component::internalMouseWheel (MouseInputSource& source, const Point<int>&
{
((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, mouseListeners_->size());
}
}
const Component* p = parentComponent_;
Component* p = parentComponent_;
while (p != 0)
{
const ComponentDeletionWatcher parentDeletionChecker (p);
SafePointer<Component> parentPointer (p);
for (int i = p->numDeepMouseListeners; --i >= 0;)
{
((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
if (safePointer == 0 || parentPointer == 0)
return;
i = jmin (i, p->numDeepMouseListeners);
@ -2876,10 +2882,10 @@ void Component::internalBroughtToFront()
if (flags.hasHeavyweightPeerFlag)
Desktop::getInstance().componentBroughtToFront (this);
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
broughtToFront();
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
if (componentListeners_ != 0)
@ -2889,7 +2895,7 @@ void Component::internalBroughtToFront()
((ComponentListener*) componentListeners_->getUnchecked (i))
->componentBroughtToFront (*this);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
i = jmin (i, componentListeners_->size());
@ -2913,11 +2919,11 @@ void Component::focusGained (FocusChangeType)
void Component::internalFocusGain (const FocusChangeType cause)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
focusGained (cause);
if (! deletionChecker.hasBeenDeleted())
if (safePointer != 0)
internalChildFocusChange (cause);
}
@ -2928,11 +2934,11 @@ void Component::focusLost (FocusChangeType)
void Component::internalFocusLoss (const FocusChangeType cause)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
focusLost (focusChangedDirectly);
if (! deletionChecker.hasBeenDeleted())
if (safePointer != 0)
internalChildFocusChange (cause);
}
@ -2949,10 +2955,10 @@ void Component::internalChildFocusChange (FocusChangeType cause)
{
flags.childCompFocusedFlag = childIsNowFocused;
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
focusOfChildComponentChanged (cause);
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
}
@ -2982,11 +2988,11 @@ void Component::setEnabled (const bool shouldBeEnabled)
void Component::sendEnablementChangeMessage()
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
enablementChanged();
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
for (int i = getNumChildComponents(); --i >= 0;)
@ -2997,7 +3003,7 @@ void Component::sendEnablementChangeMessage()
{
c->sendEnablementChangeMessage();
if (deletionChecker.hasBeenDeleted())
if (safePointer == 0)
return;
}
}
@ -3068,7 +3074,7 @@ void Component::takeKeyboardFocus (const FocusChangeType cause)
if (peer != 0)
{
const ComponentDeletionWatcher deletionChecker (this);
SafePointer<Component> safePointer (this);
peer->grabFocus();
@ -3089,7 +3095,7 @@ void Component::takeKeyboardFocus (const FocusChangeType cause)
{
focusGained (cause);
if (! deletionChecker.hasBeenDeleted())
if (safePointer != 0)
internalChildFocusChange (cause);
}
}
@ -3184,11 +3190,10 @@ void Component::moveKeyboardFocusToSibling (const bool moveToNext)
{
if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
{
const ComponentDeletionWatcher deletionChecker (nextComp);
SafePointer<Component> safePointer (this);
internalModalInputAttempt();
if (deletionChecker.hasBeenDeleted()
|| nextComp->isCurrentlyBlockedByAnotherModalComponent())
if (safePointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
return;
}
@ -3249,11 +3254,6 @@ const Point<int> Component::getMouseXYRelative() const
return globalPositionToRelative (Desktop::getMousePosition());
}
Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
{
return componentUnderMouse;
}
//==============================================================================
const Rectangle<int> Component::getParentMonitorArea() const throw()
{

View file

@ -35,7 +35,6 @@
#include "../graphics/effects/juce_ImageEffectFilter.h"
#include "../graphics/geometry/juce_RectangleList.h"
#include "../graphics/geometry/juce_BorderSize.h"
#include "windows/juce_ComponentPeer.h"
#include "../../events/juce_MessageListener.h"
#include "../../text/juce_StringArray.h"
#include "../../containers/juce_VoidArray.h"
@ -43,7 +42,7 @@
class LookAndFeel;
class MouseInputSource;
class MouseInputSourceInternal;
class ComponentPeer;
//==============================================================================
/**
@ -1602,13 +1601,6 @@ public:
*/
const Point<int> getMouseXYRelative() const;
/** Returns the component that's currently underneath the mouse.
@returns the component or 0 if there isn't one.
@see contains, getComponentAt
*/
static Component* JUCE_CALLTYPE getComponentUnderMouse() throw();
//==============================================================================
/** Called when this component's size has been changed.
@ -1896,6 +1888,71 @@ public:
*/
uint32 getComponentUID() const throw() { return componentUID; }
//==============================================================================
/** Holds a pointer to some type of Component, which automatically becomes null if
the component is deleted.
If you're using a component which may be deleted by another event that's outside
of your control, use a SafePointer instead of a normal pointer to refer to it,
and you can test whether it's null before using it to see if something has deleted
it.
The ComponentType typedef must be Component, or some subclass of Component.
Note that this class isn't thread-safe, and assumes that all the code that uses
it is running on the message thread.
*/
template <class ComponentType>
class JUCE_API SafePointer : private ComponentListener
{
public:
/** Creates a null SafePointer. */
SafePointer() : comp (0) {}
/** Creates a SafePointer that points at the given component. */
SafePointer (ComponentType* const component) : comp (component) { attach(); }
/** Creates a copy of another SafePointer. */
SafePointer (const SafePointer& other) : comp (other.comp) { attach(); }
/** Destructor. */
~SafePointer() { detach(); }
/** Copies another pointer to this one. */
SafePointer& operator= (const SafePointer& other) { return operator= (other.comp); }
/** Copies another pointer to this one. */
SafePointer& operator= (ComponentType* const newComponent)
{
detach();
comp = newComponent;
attach();
return *this;
}
/** Returns the component that this pointer refers to, or null if the component no longer exists. */
operator ComponentType*() throw() { return comp; }
/** Returns the component that this pointer refers to, or null if the component no longer exists. */
operator const ComponentType*() const throw() { return comp; }
/** Returns the component that this pointer refers to, or null if the component no longer exists. */
ComponentType* operator->() throw() { jassert (comp != 0); return comp; }
/** Returns the component that this pointer refers to, or null if the component no longer exists. */
const ComponentType* operator->() const throw() { jassert (comp != 0); return comp; }
//==============================================================================
juce_UseDebuggingNewOperator
private:
ComponentType* comp;
void attach() { if (comp != 0) comp->addComponentListener (this); }
void detach() { if (comp != 0) comp->removeComponentListener (this); }
void componentBeingDeleted (Component&) { comp = 0; }
};
//==============================================================================
juce_UseDebuggingNewOperator
@ -1907,7 +1964,6 @@ private:
friend class MouseInputSourceInternal;
static Component* currentlyFocusedComponent;
static Component* componentUnderMouse;
//==============================================================================
String componentName_;

View file

@ -27,33 +27,15 @@
BEGIN_JUCE_NAMESPACE
#include "juce_ComponentListener.h"
//==============================================================================
void ComponentListener::componentMovedOrResized (Component&, bool, bool)
{
}
void ComponentListener::componentBroughtToFront (Component&)
{
}
void ComponentListener::componentVisibilityChanged (Component&)
{
}
void ComponentListener::componentChildrenChanged (Component&)
{
}
void ComponentListener::componentParentHierarchyChanged (Component&)
{
}
void ComponentListener::componentNameChanged (Component&)
{
}
void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
void ComponentListener::componentBroughtToFront (Component&) {}
void ComponentListener::componentVisibilityChanged (Component&) {}
void ComponentListener::componentChildrenChanged (Component&) {}
void ComponentListener::componentParentHierarchyChanged (Component&) {}
void ComponentListener::componentNameChanged (Component&) {}
void ComponentListener::componentBeingDeleted (Component& component) {}
END_JUCE_NAMESPACE

View file

@ -95,6 +95,16 @@ public:
@see Component::setName, Component::getName
*/
virtual void componentNameChanged (Component& component);
/** Called when the component is in the process of being deleted.
This callback is made from inside the destructor, so be very, very cautious
about what you do inside the callback.
It will be called before the component has been removed from its parent, and
before any child components have been removed.
*/
virtual void componentBeingDeleted (Component& component);
};

View file

@ -29,7 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_Desktop.h"
#include "juce_ComponentDeletionWatcher.h"
#include "windows/juce_ComponentPeer.h"
#include "mouse/juce_MouseInputSource.h"
#include "mouse/juce_MouseListener.h"
#include "mouse/juce_MouseEvent.h"
@ -222,6 +222,35 @@ void Desktop::incrementMouseClickCounter() throw()
++mouseClickCounter;
}
int Desktop::getNumDraggingMouseSources() const throw()
{
int num = 0;
for (int i = mouseSources.size(); --i >= 0;)
if (mouseSources.getUnchecked(i)->isDragging())
++num;
return num;
}
MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
{
int num = 0;
for (int i = mouseSources.size(); --i >= 0;)
{
MouseInputSource* const mi = mouseSources.getUnchecked(i);
if (mi->isDragging())
{
if (index == num)
return mi;
++num;
}
}
return 0;
}
//==============================================================================
void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
{
@ -287,7 +316,7 @@ void Desktop::sendMouseMove()
if (target != 0)
{
ComponentDeletionWatcher deletionChecker (target);
Component::SafePointer<Component> deletionChecker (target);
const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
const Time now (Time::getCurrentTime());
@ -301,7 +330,7 @@ void Desktop::sendMouseMove()
else
((MouseListener*) mouseListeners[i])->mouseMove (me);
if (deletionChecker.hasBeenDeleted())
if (deletionChecker == 0)
return;
i = jmin (i, mouseListeners.size());

View file

@ -227,6 +227,41 @@ public:
Component* findComponentAt (const Point<int>& screenPosition) const;
//==============================================================================
/** Returns the number of MouseInputSource objects the system has at its disposal.
In a traditional single-mouse system, there might be only one object. On a multi-touch
system, there could be one input source per potential finger.
To find out how many mouse events are currently happening, use getNumDraggingMouseSources().
@see getMouseSource
*/
int getNumMouseSources() const throw() { return mouseSources.size(); }
/** Returns one of the system's MouseInputSource objects.
The index should be from 0 to getNumMouseSources() - 1. Out-of-range indexes will return
a null pointer.
In a traditional single-mouse system, there might be only one object. On a multi-touch
system, there could be one input source per potential finger.
*/
MouseInputSource* getMouseSource (int index) const throw() { return mouseSources [index]; }
/** Returns the main mouse input device that the system is using.
@see getNumMouseSources()
*/
MouseInputSource& getMainMouseSource() const throw() { return *mouseSources.getUnchecked(0); }
/** Returns the number of mouse-sources that are currently being dragged.
In a traditional single-mouse system, this will be 0 or 1, depending on whether a
juce component has the button down on it. In a multi-touch system, this could
be any number from 0 to the number of simultaneous touches that can be detected.
*/
int getNumDraggingMouseSources() const throw();
/** Returns one of the mouse sources that's currently being dragged.
The index should be between 0 and getNumDraggingMouseSources() - 1. If the index is
out of range, or if no mice or fingers are down, this will return a null pointer.
*/
MouseInputSource* getDraggingMouseSource (int index) const throw();
//==============================================================================
juce_UseDebuggingNewOperator
@ -239,10 +274,6 @@ public:
/** True if the OS supports semitransparent windows */
static bool canUseSemiTransparentWindows() throw();
int getNumMouseInputSources() const throw() { return mouseSources.size(); }
MouseInputSource* getMouseSource (int index) const throw() { return mouseSources [index]; }
MouseInputSource& getMainMouseSource() const throw() { return *mouseSources.getUnchecked(0); }
private:
//==============================================================================
static Desktop* instance;

View file

@ -35,13 +35,11 @@ BEGIN_JUCE_NAMESPACE
struct AnimationTask
{
AnimationTask (Component* const comp)
: component (comp),
watcher (comp)
: component (comp)
{
}
Component* component;
ComponentDeletionWatcher watcher;
Component::SafePointer<Component> component;
Rectangle<int> destination;
int msElapsed, msTotal;
double startSpeed, midSpeed, endSpeed, lastProgress;
@ -49,7 +47,7 @@ struct AnimationTask
bool useTimeslice (const int elapsed)
{
if (watcher.hasBeenDeleted())
if (component == 0)
return false;
msElapsed += elapsed;
@ -88,7 +86,7 @@ struct AnimationTask
void moveToFinalDestination()
{
if (! watcher.hasBeenDeleted())
if (component != 0)
component->setBounds (destination);
}

View file

@ -27,7 +27,6 @@
#define __JUCE_COMPONENTANIMATOR_JUCEHEADER__
#include "../juce_Component.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../../../events/juce_ChangeBroadcaster.h"
#include "../../../events/juce_Timer.h"

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_ComponentBoundsConstrainer.h"
#include "../juce_Desktop.h"
#include "../windows/juce_ComponentPeer.h"
//==============================================================================

View file

@ -38,10 +38,6 @@ ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
{
jassert (component != 0); // can't use this with a null pointer..
#ifdef JUCE_DEBUG
deletionWatcher = new ComponentDeletionWatcher (component_);
#endif
component->addComponentListener (this);
registerWithParentComps();
@ -57,10 +53,8 @@ ComponentMovementWatcher::~ComponentMovementWatcher()
//==============================================================================
void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
{
#ifdef JUCE_DEBUG
// agh! don't delete the target component without deleting this object first!
jassert (! deletionWatcher->hasBeenDeleted());
#endif
jassert (component != 0);
if (! reentrant)
{
@ -70,11 +64,9 @@ void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
if (peer != lastPeer)
{
ComponentDeletionWatcher watcher (component);
componentPeerChanged();
if (watcher.hasBeenDeleted())
if (component == 0)
return;
lastPeer = peer;
@ -91,10 +83,8 @@ void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
{
#ifdef JUCE_DEBUG
// agh! don't delete the target component without deleting this object first!
jassert (! deletionWatcher->hasBeenDeleted());
#endif
jassert (component != 0);
if (wasMoved)
{

View file

@ -27,7 +27,6 @@
#define __JUCE_COMPONENTMOVEMENTWATCHER_JUCEHEADER__
#include "../juce_Component.h"
#include "../juce_ComponentDeletionWatcher.h"
//==============================================================================
@ -77,14 +76,11 @@ public:
private:
//==============================================================================
Component* const component;
Component::SafePointer<Component> component;
ComponentPeer* lastPeer;
VoidArray registeredParentComps;
bool reentrant;
Rectangle<int> lastBounds;
#ifdef JUCE_DEBUG
ScopedPointer <ComponentDeletionWatcher> deletionWatcher;
#endif
void unregister() throw();
void registerWithParentComps() throw();

View file

@ -35,6 +35,7 @@ BEGIN_JUCE_NAMESPACE
#include "../buttons/juce_ImageButton.h"
#include "../buttons/juce_DrawableButton.h"
#include "../buttons/juce_HyperlinkButton.h"
#include "../windows/juce_ComponentPeer.h"
#include "../windows/juce_AlertWindow.h"
#include "../windows/juce_DocumentWindow.h"
#include "../windows/juce_ResizableWindow.h"

View file

@ -193,13 +193,8 @@ void MenuBarComponent::showMenu (int index)
currentPopup = 0;
menuBarItemsChanged (0);
Component* const prevFocused = getCurrentlyFocusedComponent();
ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
if (prevFocused != 0)
prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
ComponentDeletionWatcher deletionChecker (this);
Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
Component::SafePointer<Component> deletionChecker (this);
enterModalState (false);
inModalState = true;
@ -244,7 +239,7 @@ void MenuBarComponent::showMenu (int index)
// be stuck behind other comps that are already modal..
result = currentPopup->runModalLoop();
if (deletionChecker.hasBeenDeleted())
if (deletionChecker == 0)
return;
const int lastPopupIndex = currentPopupIndex;
@ -276,7 +271,7 @@ void MenuBarComponent::showMenu (int index)
inModalState = false;
exitModalState (0);
if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
if (prevFocused != 0)
prevFocused->grabKeyboardFocus();
const Point<int> mousePos (getMouseXYRelative());

View file

@ -29,8 +29,8 @@ BEGIN_JUCE_NAMESPACE
#include "juce_PopupMenu.h"
#include "juce_PopupMenuCustomComponent.h"
#include "../windows/juce_ComponentPeer.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../juce_Desktop.h"
#include "../../graphics/imaging/juce_Image.h"
#include "../keyboard/juce_KeyPressMappingSet.h"
@ -270,7 +270,6 @@ public:
activeSubMenu (0),
menuBarComponent (0),
managerOfChosenCommand (0),
componentAttachedTo (0),
minimumWidth (0),
maximumNumColumns (7),
standardItemHeight (0),
@ -309,7 +308,6 @@ public:
activeSubMenu = 0;
deleteAllChildren();
attachedCompWatcher = 0;
}
//==============================================================================
@ -353,7 +351,6 @@ public:
mw->menuBarComponent = menuBarComponent;
mw->managerOfChosenCommand = managerOfChosenCommand;
mw->componentAttachedTo = componentAttachedTo;
mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
mw->setTopLeftPosition (mw->windowPos.getX(),
@ -562,7 +559,7 @@ public:
if (! isOverAnyMenu())
{
if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
if (componentAttachedTo != 0)
{
// we want to dismiss the menu, but if we do it synchronously, then
// the mouse-click will be allowed to pass through. That's good, except
@ -597,7 +594,7 @@ public:
if (! isVisible())
return;
if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
if (componentAttachedTo == 0)
{
dismissMenu (0);
return;
@ -750,8 +747,7 @@ private:
ScopedPointer <Window> activeSubMenu;
Component* menuBarComponent;
ApplicationCommandManager** managerOfChosenCommand;
Component* componentAttachedTo;
ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
Component::SafePointer<Component> componentAttachedTo;
Rectangle<int> windowPos;
Point<int> lastMouse;
int minimumWidth, maximumNumColumns, standardItemHeight;
@ -1546,16 +1542,8 @@ int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
const bool alignToRectangle,
Component* const componentAttachedTo)
{
Component* const prevFocused = Component::getCurrentlyFocusedComponent();
ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
if (prevFocused != 0)
deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
if (prevTopLevel != 0)
deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
Window::wasHiddenBecauseOfAppChange() = false;
@ -1582,10 +1570,10 @@ int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
if (! Window::wasHiddenBecauseOfAppChange())
{
if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
if (prevTopLevel != 0)
prevTopLevel->toFront (true);
if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
if (prevFocused != 0)
prevFocused->grabKeyboardFocus();
}
}

View file

@ -28,12 +28,13 @@
BEGIN_JUCE_NAMESPACE
#include "juce_DragAndDropContainer.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../windows/juce_ComponentPeer.h"
#include "../juce_Desktop.h"
#include "../../../events/juce_Timer.h"
#include "../../../core/juce_Random.h"
#include "../../graphics/imaging/juce_Image.h"
#include "../mouse/juce_MouseEvent.h"
#include "../mouse/juce_MouseInputSource.h"
#include "juce_FileDragAndDropTarget.h"
bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
@ -47,13 +48,14 @@ class DragImageComponent : public Component,
public:
DragImageComponent (Image* const im,
const String& desc,
Component* const s,
Component* const sourceComponent,
Component* const mouseDragSource_,
DragAndDropContainer* const o,
const Point<int>& imageOffset_)
: image (im),
source (s),
source (sourceComponent),
mouseDragSource (mouseDragSource_),
owner (o),
currentlyOver (0),
dragDesc (desc),
imageOffset (imageOffset_),
hasCheckedForExternalDrag (false),
@ -61,14 +63,9 @@ public:
{
setSize (im->getWidth(), im->getHeight());
sourceWatcher = new ComponentDeletionWatcher (source);
mouseDragSource = Component::getComponentUnderMouse();
if (mouseDragSource == 0)
mouseDragSource = source;
mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
mouseDragSource->addMouseListener (this, false);
startTimer (200);
@ -82,13 +79,12 @@ public:
if (owner->dragImageComponent == this)
owner->dragImageComponent.release();
if (! mouseDragSourceWatcher->hasBeenDeleted())
if (mouseDragSource != 0)
{
mouseDragSource->removeMouseListener (this);
if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
if (currentlyOver->isInterestedInDragSource (dragDesc, source))
currentlyOver->itemDragExit (dragDesc, source);
if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
getCurrentlyOver()->itemDragExit (dragDesc, source);
}
}
@ -104,8 +100,7 @@ public:
}
}
DragAndDropTarget* findTarget (const Point<int>& screenPos,
Point<int>& relativePos) const
DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
{
Component* hit = getParentComponent();
@ -143,7 +138,7 @@ public:
{
if (e.originalComponent != this)
{
if (! mouseDragSourceWatcher->hasBeenDeleted())
if (mouseDragSource != 0)
mouseDragSource->removeMouseListener (this);
bool dropAccepted = false;
@ -161,7 +156,7 @@ public:
setVisible (true);
if (dropAccepted || sourceWatcher->hasBeenDeleted())
if (dropAccepted || source == 0)
{
fadeOutComponent (120);
}
@ -188,8 +183,7 @@ public:
// a modal loop and deletes this object before the method completes)
const String dragDescLocal (dragDesc);
currentlyOverWatcher = 0;
currentlyOver = 0;
currentlyOverComp = 0;
ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
}
@ -215,46 +209,28 @@ public:
Point<int> relPos;
DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
Component* ddtComp = dynamic_cast <Component*> (ddt);
drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
if (ddt != currentlyOver)
if (ddtComp != currentlyOverComp)
{
if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
if (currentlyOverComp != 0 && source != 0
&& getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
{
Component* const over = dynamic_cast <Component*> (currentlyOver);
if (over != 0
&& over->isValidComponent()
&& ! (sourceWatcher->hasBeenDeleted())
&& currentlyOver->isInterestedInDragSource (dragDescLocal, source))
{
currentlyOver->itemDragExit (dragDescLocal, source);
}
getCurrentlyOver()->itemDragExit (dragDescLocal, source);
}
currentlyOver = ddt;
currentlyOverWatcher = 0;
currentlyOverComp = ddtComp;
if (ddt != 0)
{
currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
currentlyOver->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
}
}
else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
{
currentlyOver = 0;
currentlyOverWatcher = 0;
if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
}
if (currentlyOver != 0
&& currentlyOver->isInterestedInDragSource (dragDescLocal, source))
currentlyOver->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
if (currentlyOver == 0
if (getCurrentlyOver() == 0
&& canDoExternalDrag
&& ! hasCheckedForExternalDrag)
{
@ -267,13 +243,13 @@ public:
if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
&& files.size() > 0)
{
ComponentDeletionWatcher cdw (this);
Component::SafePointer<Component> cdw (this);
setVisible (false);
if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
if (! cdw.hasBeenDeleted())
if (cdw != 0)
delete this;
return;
@ -291,13 +267,13 @@ public:
void timerCallback()
{
if (sourceWatcher->hasBeenDeleted())
if (source == 0)
{
delete this;
}
else if (! isMouseButtonDownAnywhere())
{
if (! mouseDragSourceWatcher->hasBeenDeleted())
if (mouseDragSource != 0)
mouseDragSource->removeMouseListener (this);
delete this;
@ -306,12 +282,15 @@ public:
private:
ScopedPointer<Image> image;
Component* const source;
Component::SafePointer<Component> source;
Component::SafePointer<Component> mouseDragSource;
DragAndDropContainer* const owner;
ScopedPointer<ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
Component* mouseDragSource;
DragAndDropTarget* currentlyOver;
Component::SafePointer<Component> currentlyOverComp;
DragAndDropTarget* getCurrentlyOver()
{
return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
}
String dragDesc;
const Point<int> imageOffset;
@ -344,90 +323,95 @@ void DragAndDropContainer::startDragging (const String& sourceDescription,
{
Component* const thisComp = dynamic_cast <Component*> (this);
if (thisComp != 0)
if (thisComp == 0)
{
const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
Point<int> imageOffset;
jassertfalse; // Your DragAndDropContainer needs to be a Component!
return;
}
if (dragImage == 0)
MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
if (draggingSource == 0 || ! draggingSource->isDragging())
{
jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
return;
}
const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
Point<int> imageOffset;
if (dragImage == 0)
{
dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
if (dragImage->getFormat() != Image::ARGB)
{
dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
Graphics g2 (*newIm);
g2.drawImageAt (dragImage, 0, 0);
if (dragImage->getFormat() != Image::ARGB)
dragImage = newIm;
}
dragImage->multiplyAllAlphas (0.6f);
const int lo = 150;
const int hi = 400;
Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
.getConstrainedPoint (relPos));
for (int y = dragImage->getHeight(); --y >= 0;)
{
const double dy = (y - clipped.getY()) * (y - clipped.getY());
for (int x = dragImage->getWidth(); --x >= 0;)
{
Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
Graphics g2 (*newIm);
g2.drawImageAt (dragImage, 0, 0);
const int dx = x - clipped.getX();
const int distance = roundToInt (sqrt (dx * dx + dy));
dragImage = newIm;
}
dragImage->multiplyAllAlphas (0.6f);
const int lo = 150;
const int hi = 400;
Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
.getConstrainedPoint (relPos));
for (int y = dragImage->getHeight(); --y >= 0;)
{
const double dy = (y - clipped.getY()) * (y - clipped.getY());
for (int x = dragImage->getWidth(); --x >= 0;)
if (distance > lo)
{
const int dx = x - clipped.getX();
const int distance = roundToInt (sqrt (dx * dx + dy));
const float alpha = (distance > hi) ? 0
: (hi - distance) / (float) (hi - lo)
+ Random::getSystemRandom().nextFloat() * 0.008f;
if (distance > lo)
{
const float alpha = (distance > hi) ? 0
: (hi - distance) / (float) (hi - lo)
+ Random::getSystemRandom().nextFloat() * 0.008f;
dragImage->multiplyAlphaAt (x, y, alpha);
}
dragImage->multiplyAlphaAt (x, y, alpha);
}
}
imageOffset = -clipped;
}
else
{
if (imageOffsetFromMouse == 0)
imageOffset = Point<int> (dragImage->getWidth() / -2,
dragImage->getHeight() / -2);
else
imageOffset = *imageOffsetFromMouse;
}
dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
this, imageOffset);
currentDragDesc = sourceDescription;
if (allowDraggingToExternalWindows)
{
if (! Desktop::canUseSemiTransparentWindows())
dragImageComponent->setOpaque (true);
dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
}
else
thisComp->addChildComponent (dragImageComponent);
static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
dragImageComponent->setVisible (true);
imageOffset = -clipped;
}
else
{
// this class must only be implemented by an object that
// is also a Component.
jassertfalse
if (imageOffsetFromMouse == 0)
imageOffset = Point<int> (dragImage->getWidth() / -2,
dragImage->getHeight() / -2);
else
imageOffset = *imageOffsetFromMouse;
}
dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
draggingSource->getComponentUnderMouse(), this, imageOffset);
currentDragDesc = sourceDescription;
if (allowDraggingToExternalWindows)
{
if (! Desktop::canUseSemiTransparentWindows())
dragImageComponent->setOpaque (true);
dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
| ComponentPeer::windowIsTemporary
| ComponentPeer::windowIgnoresKeyPresses);
}
else
thisComp->addChildComponent (dragImageComponent);
static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
dragImageComponent->setVisible (true);
}
}

View file

@ -30,9 +30,9 @@ BEGIN_JUCE_NAMESPACE
#include "juce_MouseInputSource.h"
#include "juce_MouseEvent.h"
#include "../juce_Component.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../../../events/juce_AsyncUpdater.h"
#include "../lookandfeel/juce_LookAndFeel.h"
#include "../windows/juce_ComponentPeer.h"
//==============================================================================
@ -59,7 +59,7 @@ public:
Component* getComponentUnderMouse() const
{
return componentUnderMouse != 0 ? const_cast<Component*> (componentUnderMouse->getComponent()) : 0;
return const_cast<Component*> (static_cast <const Component*> (componentUnderMouse));
}
const ModifierKeys getCurrentModifiers() const
@ -144,7 +144,7 @@ public:
if (newComponent != current)
{
ScopedPointer<ComponentDeletionWatcher> newCompWatcher (newComponent != 0 ? new ComponentDeletionWatcher (newComponent) : 0);
Component::SafePointer<Component> safeNewComp (newComponent);
const ModifierKeys originalButtonState (buttonState);
if (current != 0)
@ -154,9 +154,8 @@ public:
buttonState = originalButtonState;
}
componentUnderMouse = newCompWatcher;
componentUnderMouse = safeNewComp;
current = getComponentUnderMouse();
Component::componentUnderMouse = current;
if (current != 0)
current->internalMouseEnter (source, current->globalPositionToRelative (screenPos), time);
@ -406,7 +405,7 @@ public:
private:
MouseInputSource& source;
ScopedPointer<ComponentDeletionWatcher> componentUnderMouse;
Component::SafePointer<Component> componentUnderMouse;
ComponentPeer* lastPeer;
Point<int> unboundedMouseOffset;

View file

@ -31,8 +31,8 @@ BEGIN_JUCE_NAMESPACE
#include "../../graphics/imaging/juce_ImageCache.h"
#include "../../graphics/imaging/juce_ImageConvolutionKernel.h"
#include "../../graphics/imaging/juce_Image.h"
#include "../juce_ComponentDeletionWatcher.h"
#include "../juce_Desktop.h"
#include "../windows/juce_ComponentPeer.h"
//==============================================================================

View file

@ -29,6 +29,7 @@ BEGIN_JUCE_NAMESPACE
#include "juce_MagnifierComponent.h"
#include "../../graphics/imaging/juce_Image.h"
#include "../windows/juce_ComponentPeer.h"
//==============================================================================

View file

@ -30,6 +30,7 @@
BEGIN_JUCE_NAMESPACE
#include "juce_OpenGLComponent.h"
#include "../windows/juce_ComponentPeer.h"
#include "../layout/juce_ComponentMovementWatcher.h"
#include "../../../threads/juce_ScopedLock.h"

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"

View file

@ -69,10 +69,10 @@ BEGIN_JUCE_NAMESPACE
#include "../gui/components/special/juce_WebBrowserComponent.h"
#include "../gui/components/keyboard/juce_KeyPress.h"
#include "../utilities/juce_SystemClipboard.h"
#include "../gui/components/windows/juce_ComponentPeer.h"
#include "../gui/components/windows/juce_AlertWindow.h"
#include "../gui/components/special/juce_OpenGLComponent.h"
#include "../gui/components/juce_Desktop.h"
#include "../gui/components/juce_ComponentDeletionWatcher.h"
#include "../gui/graphics/geometry/juce_RectangleList.h"
#include "../gui/graphics/imaging/juce_ImageFileFormat.h"
#include "../gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h"

View file

@ -54,6 +54,7 @@ BEGIN_JUCE_NAMESPACE
#include "../gui/graphics/imaging/juce_ImageFileFormat.h"
#include "../gui/graphics/imaging/juce_CameraDevice.h"
#include "../gui/components/windows/juce_AlertWindow.h"
#include "../gui/components/windows/juce_ComponentPeer.h"
#include "../gui/components/juce_Desktop.h"
#include "../gui/components/menus/juce_MenuBarModel.h"
#include "../gui/components/special/juce_OpenGLComponent.h"

View file

@ -57,6 +57,7 @@ BEGIN_JUCE_NAMESPACE
#include "../gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.h"
#include "../gui/graphics/imaging/juce_ImageFileFormat.h"
#include "../gui/graphics/imaging/juce_CameraDevice.h"
#include "../gui/components/windows/juce_ComponentPeer.h"
#include "../gui/components/windows/juce_AlertWindow.h"
#include "../gui/components/juce_Desktop.h"
#include "../gui/components/menus/juce_MenuBarModel.h"

View file

@ -535,7 +535,7 @@ public:
if (windowH != 0)
{
const ComponentDeletionWatcher deletionChecker (component);
Component::SafePointer<Component> deletionChecker (component);
wx = x;
wy = y;
@ -566,7 +566,7 @@ public:
wx - windowBorder.getLeft(),
wy - windowBorder.getTop(), ww, wh);
if (! deletionChecker.hasBeenDeleted())
if (deletionChecker != 0)
{
updateBorderSize();
handleMovedOrResized();

View file

@ -563,7 +563,7 @@ public:
if (fullScreen != shouldBeFullScreen)
{
fullScreen = shouldBeFullScreen;
const ComponentDeletionWatcher deletionChecker (component);
const Component::SafePointer deletionChecker (component);
if (! fullScreen)
{
@ -589,7 +589,7 @@ public:
SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
}
if (! deletionChecker.hasBeenDeleted())
if (deletionChecker != 0)
handleMovedOrResized();
}
}