1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

Cleaned up some obj-C autorelease code.

This commit is contained in:
Julian Storer 2011-04-16 22:09:19 +01:00
parent 6f0740d466
commit dd22093526
21 changed files with 83 additions and 91 deletions

View file

@ -86,7 +86,7 @@ void MessageManager::stopDispatchLoop()
bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
jassert (isThisTheMessageThread()); // must only be called by the message thread
uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
@ -94,7 +94,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
while (! quitMessagePosted)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
beforeDate: endDate];
@ -165,7 +165,7 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* call
// call your function..
jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
CallbackMessagePayload cmp;
cmp.function = callback;

View file

@ -138,7 +138,7 @@ public:
int getResult()
{
jassert (callback == nullptr);
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
while (! alert.hidden && alert.superview != nil)
[[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
@ -186,7 +186,7 @@ void JUCE_CALLTYPE NativeMessageBox::showMessageBox (AlertWindow::AlertIconType
const String& title, const String& message,
Component* associatedComponent)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
iOSMessageBox mb (title, message, @"OK", nil, nil, 0, false);
(void) mb.getResult();
}
@ -195,7 +195,7 @@ void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIcon
const String& title, const String& message,
Component* associatedComponent)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
new iOSMessageBox (title, message, @"OK", nil, nil, 0, true);
}

View file

@ -996,7 +996,7 @@ Desktop::DisplayOrientation Desktop::getCurrentOrientation() const
void Desktop::getCurrentMonitorPositions (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
monitorCoords.clear();
CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]

View file

@ -571,7 +571,7 @@ const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressLis
void AudioCDReader::ejectDisk()
{
const ScopedAutoReleasePool p;
JUCE_AUTORELEASEPOOL
[[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
}

View file

@ -68,7 +68,7 @@ class QTCameraDeviceInteral
public:
QTCameraDeviceInteral (CameraDevice* owner, int index)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
session = [[QTCaptureSession alloc] init];
@ -239,7 +239,7 @@ END_JUCE_NAMESPACE
{
if (internal->listeners.size() > 0)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
CVPixelBufferGetWidth (videoFrame),
@ -253,11 +253,11 @@ END_JUCE_NAMESPACE
{
const Time now (Time::getCurrentTime());
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
#else
#else
NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
#endif
#endif
int64 presentationTime = (hosttime != nil)
? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
@ -285,7 +285,7 @@ class QTCaptureViewerComp : public NSViewComponent
public:
QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
captureView = [[QTCaptureView alloc] init];
[captureView setCaptureSession: internal->session];
@ -400,7 +400,7 @@ void CameraDevice::removeListener (Listener* listenerToRemove)
//==============================================================================
const StringArray CameraDevice::getAvailableDevices()
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
StringArray results;
NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];

View file

@ -111,7 +111,7 @@ public:
#if JUCE_MAC
static NSImage* createNSImage (const Image& image)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSImage* im = [[NSImage alloc] init];
[im setSize: NSMakeSize (image.getWidth(), image.getHeight())];

View file

@ -91,7 +91,7 @@ void FileChooser::showPlatformDialog (Array<File>& results,
bool selectMultipleFiles,
FilePreviewComponent* /*extraInfoComponent*/)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
StringArray* filters = new StringArray();
filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
@ -168,7 +168,7 @@ void FileChooser::showPlatformDialog (Array<File>& results,
bool selectMultipleFiles,
FilePreviewComponent* extraInfoComponent)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
jassertfalse; //xxx to do
}

View file

@ -35,7 +35,7 @@
//==============================================================================
bool File::copyInternal (const File& dest) const
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSFileManager* fm = [NSFileManager defaultManager];
return [fm fileExistsAtPath: juceStringToNS (fullPath)]
@ -78,7 +78,7 @@ namespace FileHelpers
bool isHiddenFile (const String& path)
{
#if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_6
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSNumber* hidden = nil;
NSError* err = nil;
@ -143,10 +143,10 @@ bool File::isOnHardDisk() const
bool File::isOnRemovableDrive() const
{
#if JUCE_IOS
#if JUCE_IOS
return false; // xxx is this possible?
#else
const ScopedAutoReleasePool pool;
#else
JUCE_AUTORELEASEPOOL
BOOL removable = false;
[[NSWorkspace sharedWorkspace]
@ -158,7 +158,7 @@ bool File::isOnRemovableDrive() const
type: nil];
return removable;
#endif
#endif
}
bool File::isHidden() const
@ -171,8 +171,7 @@ const char* juce_Argv0 = nullptr; // referenced from juce_Application.cpp
const File File::getSpecialLocation (const SpecialLocationType type)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
String resultPath;
switch (type)
@ -254,7 +253,7 @@ const File File::getSpecialLocation (const SpecialLocationType type)
//==============================================================================
const String File::getVersion() const
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
String result;
NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
@ -301,7 +300,7 @@ bool File::moveToTrash() const
#if JUCE_IOS
return deleteFile(); //xxx is there a trashcan on the iPhone?
#else
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSString* p = juceStringToNS (getFullPathName());
@ -323,7 +322,7 @@ public:
wildCard (wildCard_),
enumerator (nil)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
enumerator = [[[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory.getFullPathName())] retain];
}
@ -337,7 +336,7 @@ public:
bool* const isDir, bool* const isHidden, int64* const fileSize,
Time* const modTime, Time* const creationTime, bool* const isReadOnly)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
const char* wildcardUTF8 = nullptr;
for (;;)
@ -395,7 +394,7 @@ bool PlatformUtilities::openDocument (const String& fileName, const String& para
#if JUCE_IOS
return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
#else
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
if (parameters.isEmpty())
{
@ -460,26 +459,26 @@ const String PlatformUtilities::makePathFromFSRef (FSRef* file)
//==============================================================================
OSType PlatformUtilities::getTypeOfFile (const String& filename)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
#if JUCE_IOS || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_5)
#if JUCE_IOS || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MIN_ALLOWED >= MAC_OS_X_VERSION_10_5)
NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
#else
#else
// (the cast here avoids a deprecation warning)
NSDictionary* fileDict = [((id) [NSFileManager defaultManager]) fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
#endif
#endif
return [fileDict fileHFSTypeCode];
}
bool PlatformUtilities::isBundle (const String& filename)
{
#if JUCE_IOS
#if JUCE_IOS
return false; // xxx can't find a sensible way to do this without trying to open the bundle..
#else
const ScopedAutoReleasePool pool;
#else
JUCE_AUTORELEASEPOOL
return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
#endif
#endif
}
#endif

View file

@ -50,7 +50,7 @@ public:
MacTypeface (const Font& font)
: Typeface (font.getTypefaceName())
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
renderingTransform = CGAffineTransformIdentity;
bool needsItalicTransform = false;
@ -129,7 +129,7 @@ public:
renderingTransform.c = 0.15f;
}
#if SUPPORT_ONLY_10_4_FONTS
#if SUPPORT_ONLY_10_4_FONTS
ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
if (atsFont == 0)
@ -140,7 +140,7 @@ public:
const float totalHeight = std::abs ([nsFont ascender]) + std::abs ([nsFont descender]);
unitsToHeightScaleFactor = 1.0f / totalHeight;
fontHeightToCGSizeFactor = 1024.0f / totalHeight;
#else
#else
#if SUPPORT_10_4_FONTS
if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
{
@ -164,7 +164,7 @@ public:
unitsToHeightScaleFactor = 1.0f / totalHeight;
fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
}
#endif
#endif
#endif
}
@ -310,7 +310,7 @@ public:
// we might need to apply a transform to the path, so it mustn't have anything else in it
jassert (path.isEmpty());
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSBezierPath* bez = [NSBezierPath bezierPath];
[bez moveToPoint: NSMakePoint (0, 0)];
@ -492,7 +492,7 @@ const StringArray Font::findAllTypefaceNames()
{
StringArray names;
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
#if JUCE_IOS
NSArray* fonts = [UIFont familyNames];

View file

@ -498,7 +498,7 @@ namespace MainMenuHelpers
if (JUCEApplication::getInstance() != nullptr)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
@ -522,7 +522,7 @@ void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
{
if (getMacMainMenu() != newMenuBarModel)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
if (newMenuBarModel == nullptr)
{

View file

@ -295,7 +295,7 @@ void MessageManager::runDispatchLoop()
{
if (! quitMessagePosted) // check that the quit message wasn't already posted..
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
// must only be called by the message thread!
jassert (isThisTheMessageThread());
@ -424,7 +424,7 @@ bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
while (! quitMessagePosted)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
@ -498,7 +498,7 @@ void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* call
// call your function..
jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
AppDelegateRedirector::CallbackMessagePayload cmp;
cmp.function = callback;

View file

@ -91,7 +91,7 @@ public:
int getResult() const
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSInteger r = getRawResult();
return r == NSAlertDefaultReturn ? 1 : (r == NSAlertOtherReturn ? 2 : 0);
}
@ -195,7 +195,7 @@ bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& fi
return false;
}
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSView* view = (NSView*) sourceComp->getWindowHandle();
@ -243,7 +243,7 @@ bool Desktop::canUseSemiTransparentWindows() noexcept
const Point<int> MouseInputSource::getCurrentMousePosition()
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
const NSPoint p ([NSEvent mouseLocation]);
return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
}
@ -364,7 +364,7 @@ juce_ImplementSingleton_SingleThreaded (DisplaySettingsChangeCallback);
void Desktop::getCurrentMonitorPositions (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
DisplaySettingsChangeCallback::getInstance();

View file

@ -64,7 +64,7 @@ void* MouseCursor::createMouseCursorFromImage (const Image& image, int hotspotX,
void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSCursor* c = nil;
switch (type)

View file

@ -980,7 +980,7 @@ void NSViewComponentPeer::setVisible (bool shouldBeVisible)
void NSViewComponentPeer::setTitle (const String& title)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
if (! isSharedWindow)
[window setTitle: juceStringToNS (title)];
@ -1774,7 +1774,7 @@ ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
//==============================================================================
const Image juce_createIconForFile (const File& file)
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];

View file

@ -165,7 +165,7 @@ private:
if (nextMessage == nullptr)
return false;
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
MessageManager::getInstance()->deliverMessage (nextMessage);
return true;
}

View file

@ -60,12 +60,12 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd
const String& bodyText,
const StringArray& filesToAttach)
{
#if JUCE_IOS
#if JUCE_IOS
//xxx probably need to use MFMailComposeViewController
jassertfalse;
return false;
#else
const ScopedAutoReleasePool pool;
#else
JUCE_AUTORELEASEPOOL
String script;
script << "tell application \"Mail\"\r\n"
@ -93,14 +93,13 @@ bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAdd
script << "end tell\r\n"
"end tell\r\n";
NSAppleScript* s = [[NSAppleScript alloc]
initWithSource: juceStringToNS (script)];
NSAppleScript* s = [[NSAppleScript alloc] initWithSource: juceStringToNS (script)];
NSDictionary* error = nil;
const bool ok = [s executeAndReturnError: &error] != nil;
[s release];
return ok;
#endif
#endif
}
//==============================================================================
@ -160,7 +159,7 @@ public:
while (! threadShouldExit())
{
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
}
}

View file

@ -525,7 +525,7 @@ private:
OpenGLContext* OpenGLComponent::createContext()
{
ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
if (peer != nullptr)

View file

@ -64,7 +64,7 @@ CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
{
#if JUCE_IOS
const ScopedAutoReleasePool pool;
JUCE_AUTORELEASEPOOL
return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
#else
UnicodeMapping map;

View file

@ -36,11 +36,11 @@
//==============================================================================
bool Process::isForegroundProcess()
{
#if JUCE_MAC
#if JUCE_MAC
return [NSApp isActive];
#else
#else
return true; // xxx change this if more than one app is ever possible on the iPhone!
#endif
#endif
}
void Process::raisePrivilege()

View file

@ -40,7 +40,7 @@ static double hiResTicksScaleFactor;
//==============================================================================
#if JUCE_USE_INTRINSICS
#if JUCE_USE_INTRINSICS || JUCE_64BIT
// CPU info functions using intrinsics...
@ -69,9 +69,6 @@ static void juce_getCpuVendor (char* const v)
{
int vendor[4] = { 0 };
#if JUCE_64BIT
/// xxx todo
#else
#ifndef __MINGW32__
__try
#endif
@ -96,7 +93,6 @@ static void juce_getCpuVendor (char* const v)
*v = 0;
}
#endif
#endif
memcpy (v, vendor, 16);
}