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,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;
}