diff --git a/extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h b/extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h index f753efe56d..a8d0ea2fdb 100644 --- a/extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h +++ b/extras/audio plugins/wrapper/RTAS/juce_RTAS_DigiCode_Header.h @@ -40,6 +40,7 @@ #define kNoViews 0 #define kUseDSPCodeDecode 0 + #define WIN32 1 #define WINDOWS_VERSION 1 #define PLUGIN_SDK_BUILD 1 #define PLUGIN_SDK_DIRECTMIDI 1 diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index fbb938a132..717f1ecb7b 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -912,7 +912,8 @@ FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirector { #if JUCE_MAC File logFile ("~/Library/Logs"); - logFile = logFile.getChildFile (logFileName); + logFile = logFile.getChildFile (logFileSubDirectoryName) + .getChildFile (logFileName); #else File logFile (File::getSpecialLocation (File::userApplicationDataDirectory)); @@ -12637,7 +12638,7 @@ bool StringArray::operator== (const StringArray& other) const throw() return false; for (int i = size(); --i >= 0;) - if (*other.strings.getUnchecked(i) != *strings.getUnchecked(i)) + if (other.strings.getReference(i) != strings.getReference(i)) return false; return true; @@ -12656,20 +12657,20 @@ void StringArray::clear() throw() const String& StringArray::operator[] (const int index) const throw() { if (((unsigned int) index) < (unsigned int) strings.size()) - return *strings.getUnchecked (index); + return strings.getReference (index); return String::empty; } void StringArray::add (const String& newString) throw() { - strings.add (new String (newString)); + strings.add (newString); } void StringArray::insert (const int index, const String& newString) throw() { - strings.insert (index, new String (newString)); + strings.insert (index, newString); } void StringArray::addIfNotAlreadyThere (const String& newString, @@ -12693,18 +12694,13 @@ void StringArray::addArray (const StringArray& otherArray, numElementsToAdd = otherArray.size() - startIndex; while (--numElementsToAdd >= 0) - strings.add (new String (*otherArray.strings.getUnchecked (startIndex++))); + strings.add (otherArray.strings.getReference (startIndex++)); } void StringArray::set (const int index, const String& newString) throw() { - String* const s = strings [index]; - - if (s != 0) - *s = newString; - else if (index >= 0) - add (newString); + strings.set (index, newString); } bool StringArray::contains (const String& stringToLookFor, @@ -12713,13 +12709,13 @@ bool StringArray::contains (const String& stringToLookFor, if (ignoreCase) { for (int i = size(); --i >= 0;) - if (strings.getUnchecked(i)->equalsIgnoreCase (stringToLookFor)) + if (strings.getReference(i).equalsIgnoreCase (stringToLookFor)) return true; } else { for (int i = size(); --i >= 0;) - if (stringToLookFor == *strings.getUnchecked(i)) + if (stringToLookFor == strings.getReference(i)) return true; } @@ -12739,7 +12735,7 @@ int StringArray::indexOf (const String& stringToLookFor, { while (i < numElements) { - if (strings.getUnchecked(i)->equalsIgnoreCase (stringToLookFor)) + if (strings.getReference(i).equalsIgnoreCase (stringToLookFor)) return i; ++i; @@ -12749,7 +12745,7 @@ int StringArray::indexOf (const String& stringToLookFor, { while (i < numElements) { - if (stringToLookFor == *strings.getUnchecked (i)) + if (stringToLookFor == strings.getReference (i)) return i; ++i; @@ -12770,13 +12766,13 @@ void StringArray::removeString (const String& stringToRemove, if (ignoreCase) { for (int i = size(); --i >= 0;) - if (strings.getUnchecked(i)->equalsIgnoreCase (stringToRemove)) + if (strings.getReference(i).equalsIgnoreCase (stringToRemove)) strings.remove (i); } else { for (int i = size(); --i >= 0;) - if (stringToRemove == *strings.getUnchecked (i)) + if (stringToRemove == strings.getReference (i)) strings.remove (i); } } @@ -12786,13 +12782,13 @@ void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings) throw( if (removeWhitespaceStrings) { for (int i = size(); --i >= 0;) - if (! strings.getUnchecked(i)->containsNonWhitespaceChars()) + if (! strings.getReference(i).containsNonWhitespaceChars()) strings.remove (i); } else { for (int i = size(); --i >= 0;) - if (strings.getUnchecked(i)->isEmpty()) + if (strings.getReference(i).isEmpty()) strings.remove (i); } } @@ -12801,39 +12797,33 @@ void StringArray::trim() throw() { for (int i = size(); --i >= 0;) { - String& s = *strings.getUnchecked(i); + String& s = strings.getReference(i); s = s.trim(); } } -class InternalStringArrayComparator +class InternalStringArrayComparator_CaseSensitive { public: - static int compareElements (void* const first, void* const second) throw() - { - return ((const String*) first)->compare (*(const String*) second); - } + static int compareElements (String& first, String& second) { return first.compare (second); } }; -class InsensitiveInternalStringArrayComparator +class InternalStringArrayComparator_CaseInsensitive { public: - static int compareElements (void* const first, void* const second) throw() - { - return ((const String*) first)->compareIgnoreCase (*(const String*) second); - } + static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); } }; void StringArray::sort (const bool ignoreCase) throw() { if (ignoreCase) { - InsensitiveInternalStringArrayComparator comp; + InternalStringArrayComparator_CaseInsensitive comp; strings.sort (comp); } else { - InternalStringArrayComparator comp; + InternalStringArrayComparator_CaseSensitive comp; strings.sort (comp); } } @@ -12857,13 +12847,13 @@ const String StringArray::joinIntoString (const String& separator, return String::empty; if (start == last - 1) - return *strings.getUnchecked (start); + return strings.getReference (start); const int separatorLen = separator.length(); int charsNeeded = separatorLen * (last - start - 1); for (int i = start; i < last; ++i) - charsNeeded += strings.getUnchecked(i)->length(); + charsNeeded += strings.getReference(i).length(); String result; result.preallocateStorage (charsNeeded); @@ -12872,7 +12862,7 @@ const String StringArray::joinIntoString (const String& separator, while (start < last) { - const String& s = *strings.getUnchecked (start); + const String& s = strings.getReference (start); const int len = s.length(); if (len > 0) @@ -13037,7 +13027,7 @@ void StringArray::removeDuplicates (const bool ignoreCase) throw() { for (int i = 0; i < size() - 1; ++i) { - const String& s = *strings.getUnchecked(i); + const String s (strings.getReference(i)); int nextIndex = i + 1; @@ -13060,7 +13050,7 @@ void StringArray::appendNumbersToDuplicates (const bool ignoreCase, { for (int i = 0; i < size() - 1; ++i) { - String& s = *strings.getUnchecked(i); + String& s = strings.getReference(i); int nextIndex = indexOf (s, ignoreCase, i + 1); @@ -88248,8 +88238,7 @@ void Path::clear() throw() void Path::swapWithPath (Path& other) { - swapVariables (data.numAllocated, other.data.numAllocated); - swapVariables (data.elements, other.data.elements); + data.swapWith (other.data); swapVariables (numElements, other.numElements); swapVariables (pathXMin, other.pathXMin); swapVariables (pathXMax, other.pathXMax); @@ -233360,7 +233349,11 @@ private: void timerCallback() { - if (! regionsNeedingRepaint.isEmpty() && shmCompletedDrawing) +#if JUCE_USE_XSHM + if (! shmCompletedDrawing) + return; +#endif + if (! regionsNeedingRepaint.isEmpty()) { stopTimer(); performAnyPendingRepaintsNow(); @@ -233382,13 +233375,23 @@ private: void performAnyPendingRepaintsNow() { + if (! shmCompletedDrawing) + { + startTimer (repaintTimerPeriod); + return; + } + peer->clearMaskedRegion(); - const Rectangle totalArea (regionsNeedingRepaint.getBounds()); + RectangleList originalRepaintRegion (regionsNeedingRepaint); + regionsNeedingRepaint.clear(); + const Rectangle totalArea (originalRepaintRegion.getBounds()); if (! totalArea.isEmpty()) { +#if JUCE_USE_XSHM shmCompletedDrawing = false; +#endif if (image == 0 || image->getWidth() < totalArea.getWidth() || image->getHeight() < totalArea.getHeight()) @@ -233411,13 +233414,13 @@ private: context.setOrigin (-totalArea.getX(), -totalArea.getY()); - if (context.clipToRectangleList (regionsNeedingRepaint)) + if (context.clipToRectangleList (originalRepaintRegion)) peer->handlePaint (context); if (! peer->maskedRegion.isEmpty()) - regionsNeedingRepaint.subtract (peer->maskedRegion); + originalRepaintRegion.subtract (peer->maskedRegion); - for (RectangleList::Iterator i (regionsNeedingRepaint); i.next();) + for (RectangleList::Iterator i (originalRepaintRegion); i.next();) { const Rectangle& r = *i.getRectangle(); @@ -233427,17 +233430,12 @@ private: } } - regionsNeedingRepaint.clear(); - lastTimeImageUsed = Time::getApproximateMillisecondCounter(); startTimer (repaintTimerPeriod); } #if JUCE_USE_XSHM - void notifyPaintCompleted() - { - shmCompletedDrawing = true; - } + void notifyPaintCompleted() { shmCompletedDrawing = true; } #endif private: @@ -233447,8 +233445,7 @@ private: RectangleList regionsNeedingRepaint; #if JUCE_USE_XSHM - bool useARGBImagesForRendering; - bool shmCompletedDrawing; + bool useARGBImagesForRendering, shmCompletedDrawing; #endif LinuxRepaintManager (const LinuxRepaintManager&); const LinuxRepaintManager& operator= (const LinuxRepaintManager&); @@ -245366,7 +245363,7 @@ public: NSWindow* window; JuceNSView* view; - bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics; + bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall; }; END_JUCE_NAMESPACE @@ -245814,10 +245811,11 @@ NSViewComponentPeer::NSViewComponentPeer (Component* const component_, fullScreen (false), insideDrawRect (false), #if USE_COREGRAPHICS_RENDERING - usingCoreGraphics (true) + usingCoreGraphics (true), #else - usingCoreGraphics (false) + usingCoreGraphics (false), #endif + recursiveToFrontCall (false) { NSRect r; r.origin.x = 0; @@ -246178,7 +246176,12 @@ void NSViewComponentPeer::toFront (bool makeActiveWindow) else [window orderFront: nil]; - handleBroughtToFront(); + if (! recursiveToFrontCall) + { + recursiveToFrontCall = true; + handleBroughtToFront(); + recursiveToFrontCall = false; + } } } diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 9e1f6b2df0..f0e432f124 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -1463,62 +1463,148 @@ BEGIN_JUCE_NAMESPACE #ifndef __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__ #define __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__ +/********* Start of inlined file: juce_HeapBlock.h *********/ +#ifndef __JUCE_HEAPBLOCK_JUCEHEADER__ +#define __JUCE_HEAPBLOCK_JUCEHEADER__ + +template +class HeapBlock +{ +public: + + HeapBlock() : data (0) + { + } + + HeapBlock (const size_t numElements) + : data ((ElementType*) ::juce_malloc (numElements * sizeof (ElementType))) + { + } + + ~HeapBlock() + { + ::juce_free (data); + } + + inline operator ElementType*() const { return data; } + + inline operator void*() const { return (void*) data; } + + inline ElementType* operator->() const { return data; } + + template + inline operator CastType*() const { return (CastType*) data; } + + template + inline ElementType& operator[] (IndexType index) const { return data [index]; } + + template + inline ElementType* operator+ (IndexType index) const { return data + index; } + + inline ElementType** operator&() const { return (ElementType**) &data; } + + inline bool operator== (const ElementType* const otherPointer) const { return otherPointer == data; } + + inline bool operator!= (const ElementType* const otherPointer) const { return otherPointer != data; } + + void malloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) + { + ::juce_free (data); + data = (ElementType*) ::juce_malloc (newNumElements * elementSize); + } + + void calloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) + { + ::juce_free (data); + data = (ElementType*) ::juce_calloc (newNumElements * elementSize); + } + + void allocate (const size_t newNumElements, const bool initialiseToZero) + { + ::juce_free (data); + + if (initialiseToZero) + data = (ElementType*) ::juce_calloc (newNumElements * sizeof (ElementType)); + else + data = (ElementType*) ::juce_malloc (newNumElements * sizeof (ElementType)); + } + + void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) + { + if (data == 0) + data = (ElementType*) ::juce_malloc (newNumElements * elementSize); + else + data = (ElementType*) ::juce_realloc (data, newNumElements * elementSize); + } + + void free() + { + ::juce_free (data); + data = 0; + } + + void swapWith (HeapBlock & other) + { + swapVariables (data, other.data); + } + +private: + + ElementType* data; + + HeapBlock (const HeapBlock&); + const HeapBlock& operator= (const HeapBlock&); +}; + +#endif // __JUCE_HEAPBLOCK_JUCEHEADER__ +/********* End of inlined file: juce_HeapBlock.h *********/ + template class ArrayAllocationBase { public: ArrayAllocationBase() throw() - : elements (0), - numAllocated (0) + : numAllocated (0) { } ~ArrayAllocationBase() { - delete[] elements; } - void setAllocatedSize (const int numElements) throw() + void setAllocatedSize (const int numElements) { if (numAllocated != numElements) { if (numElements > 0) - { - ElementType* const newElements = new ElementType [numElements]; - - const int itemsToRetain = jmin (numElements, numAllocated); - - for (int i = 0; i < itemsToRetain; ++i) - newElements[i] = elements[i]; - - delete[] elements; - elements = newElements; - - } + elements.realloc (numElements); else - { - delete[] elements; - elements = 0; - } + elements.free(); numAllocated = numElements; } } - void ensureAllocatedSize (int minNumElements) throw() + void ensureAllocatedSize (int minNumElements) { if (minNumElements > numAllocated) setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7); } - void shrinkToNoMoreThan (int maxNumElements) throw() + void shrinkToNoMoreThan (int maxNumElements) { if (maxNumElements < numAllocated) setAllocatedSize (maxNumElements); } - ElementType* elements; + void swapWith (ArrayAllocationBase & other) + { + elements.swapWith (other.elements); + swapVariables (numAllocated, other.numAllocated); + } + + HeapBlock elements; int numAllocated; private: @@ -1800,7 +1886,10 @@ public: other.lockArray(); numUsed = other.numUsed; data.setAllocatedSize (other.numUsed); - memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); + + for (int i = 0; i < numUsed; ++i) + new (data.elements + i) ElementType (other.data.elements[i]); + other.unlockArray(); } @@ -1815,11 +1904,15 @@ public: : numUsed (numValues) { data.setAllocatedSize (numValues); - memcpy (data.elements, values, numValues * sizeof (ElementType)); + + for (int i = 0; i < numValues; ++i) + new (data.elements + i) ElementType (values[i]); } ~Array() throw() { + for (int i = 0; i < numUsed; ++i) + data.elements[i].~ElementType(); } const Array & operator= (const Array & other) throw() @@ -1829,10 +1922,27 @@ public: other.lockArray(); lock.enter(); - data.ensureAllocatedSize (other.size()); - numUsed = other.numUsed; - memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); - minimiseStorageOverheads(); + if (other.size() > numUsed) + { + data.ensureAllocatedSize (other.size()); + + int i = 0; + for (; i < numUsed; ++i) + data.elements[i] = other.data.elements[i]; + + numUsed = other.size(); + for (; i < numUsed; ++i) + new (data.elements + i) ElementType (other.data.elements[i]); + } + else + { + numUsed = other.size(); + + for (int i = 0; i < numUsed; ++i) + data.elements[i] = other.data.elements[i]; + + minimiseStorageOverheads(); + } lock.exit(); other.unlockArray(); @@ -1874,6 +1984,10 @@ public: void clear() throw() { lock.enter(); + + for (int i = 0; i < numUsed; ++i) + data.elements[i].~ElementType(); + data.setAllocatedSize (0); numUsed = 0; lock.exit(); @@ -1882,6 +1996,10 @@ public: void clearQuick() throw() { lock.enter(); + + for (int i = 0; i < numUsed; ++i) + data.elements[i].~ElementType(); + numUsed = 0; lock.exit(); } @@ -2005,7 +2123,7 @@ public: { lock.enter(); data.ensureAllocatedSize (numUsed + 1); - data.elements [numUsed++] = newElement; + new (data.elements + numUsed++) ElementType (newElement); lock.exit(); } @@ -2022,12 +2140,12 @@ public: if (numberToMove > 0) memmove (insertPos + 1, insertPos, numberToMove * sizeof (ElementType)); - *insertPos = newElement; + new (insertPos) ElementType (newElement); ++numUsed; } else { - data.elements [numUsed++] = newElement; + new (data.elements + numUsed++) ElementType (newElement); } lock.exit(); @@ -2040,24 +2158,24 @@ public: { lock.enter(); data.ensureAllocatedSize (numUsed + numberOfTimesToInsertIt); + ElementType* insertPos; if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) { - ElementType* insertPos = data.elements + indexToInsertAt; + insertPos = data.elements + indexToInsertAt; const int numberToMove = numUsed - indexToInsertAt; - memmove (insertPos + numberOfTimesToInsertIt, insertPos, numberToMove * sizeof (ElementType)); - numUsed += numberOfTimesToInsertIt; - - while (--numberOfTimesToInsertIt >= 0) - *insertPos++ = newElement; } else { - while (--numberOfTimesToInsertIt >= 0) - data.elements [numUsed++] = newElement; + insertPos = data.elements + numUsed; } + numUsed += numberOfTimesToInsertIt; + + while (--numberOfTimesToInsertIt >= 0) + new (insertPos++) ElementType (newElement); + lock.exit(); } } @@ -2070,24 +2188,24 @@ public: { lock.enter(); data.ensureAllocatedSize (numUsed + numberOfElements); + ElementType* insertPos; if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) { - ElementType* insertPos = data.elements + indexToInsertAt; + insertPos = data.elements + indexToInsertAt; const int numberToMove = numUsed - indexToInsertAt; - memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ElementType)); - numUsed += numberOfElements; - - while (--numberOfElements >= 0) - *insertPos++ = *newElements++; } else { - while (--numberOfElements >= 0) - data.elements [numUsed++] = *newElements++; + insertPos = data.elements + numUsed; } + numUsed += numberOfElements; + + while (--numberOfElements >= 0) + new (insertPos++) ElementType (*newElements++); + lock.exit(); } } @@ -2107,22 +2225,19 @@ public: { jassert (indexToChange >= 0); - if (indexToChange >= 0) + lock.enter(); + + if (((unsigned int) indexToChange) < (unsigned int) numUsed) { - lock.enter(); - - if (indexToChange < numUsed) - { - data.elements [indexToChange] = newValue; - } - else - { - data.ensureAllocatedSize (numUsed + 1); - data.elements [numUsed++] = newValue; - } - - lock.exit(); + data.elements [indexToChange] = newValue; } + else if (indexToChange >= 0) + { + data.ensureAllocatedSize (numUsed + 1); + new (data.elements + numUsed++) ElementType (newValue); + } + + lock.exit(); } void setUnchecked (const int indexToChange, @@ -2144,20 +2259,18 @@ public: data.ensureAllocatedSize (numUsed + numElementsToAdd); while (--numElementsToAdd >= 0) - data.elements [numUsed++] = *elementsToAdd++; + new (data.elements + numUsed++) ElementType (*elementsToAdd++); } lock.exit(); } - template - void swapWithArray (OtherArrayType& otherArray) throw() + void swapWithArray (Array & otherArray) throw() { lock.enter(); otherArray.lock.enter(); - swapVariables (numUsed, otherArray.numUsed); - swapVariables (data.elements, otherArray.data.elements); - swapVariables (data.numAllocated, otherArray.data.numAllocated); + data.swapWith (otherArray.data); + swapVariables (numUsed, otherArray.numUsed); otherArray.lock.exit(); lock.exit(); } @@ -2191,7 +2304,7 @@ public: const ElementType newElement) throw() { lock.enter(); - insert (findInsertIndexInSortedArray (comparator, data.elements, newElement, 0, numUsed), newElement); + insert (findInsertIndexInSortedArray (comparator, (ElementType*) data.elements, newElement, 0, numUsed), newElement); lock.exit(); } @@ -2244,7 +2357,8 @@ public: --numUsed; ElementType* const e = data.elements + indexToRemove; - ElementType const removed = *e; + ElementType removed (*e); + e->~ElementType(); const int numberToShift = numUsed - indexToRemove; if (numberToShift > 0) @@ -2283,7 +2397,7 @@ public: } void removeRange (int startIndex, - const int numberToRemove) throw() + int numberToRemove) throw() { lock.enter(); const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); @@ -2291,16 +2405,17 @@ public: if (endIndex > startIndex) { - const int rangeSize = endIndex - startIndex; ElementType* e = data.elements + startIndex; - int numToShift = numUsed - endIndex; - numUsed -= rangeSize; - while (--numToShift >= 0) - { - *e = e [rangeSize]; - ++e; - } + numberToRemove = endIndex - startIndex; + for (int i = 0; i < numberToRemove; ++i) + e[i].~ElementType(); + + const int numToShift = numUsed - endIndex; + if (numToShift > 0) + memmove (e, e + numberToRemove, numToShift * sizeof (ElementType)); + + numUsed -= numberToRemove; if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); @@ -2309,10 +2424,17 @@ public: lock.exit(); } - void removeLast (const int howManyToRemove = 1) throw() + void removeLast (int howManyToRemove = 1) throw() { lock.enter(); - numUsed = jmax (0, numUsed - howManyToRemove); + + if (howManyToRemove > numUsed) + howManyToRemove = numUsed; + + for (int i = 0; i < howManyToRemove; ++i) + data.elements [numUsed - i].~ElementType(); + + numUsed -= howManyToRemove; if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); @@ -2395,7 +2517,8 @@ public: if (((unsigned int) newIndex) >= (unsigned int) numUsed) newIndex = numUsed - 1; - const ElementType value = data.elements [currentIndex]; + char tempCopy [sizeof (ElementType)]; + memcpy (tempCopy, data.elements + currentIndex, sizeof (ElementType)); if (newIndex > currentIndex) { @@ -2410,7 +2533,7 @@ public: (currentIndex - newIndex) * sizeof (ElementType)); } - data.elements [newIndex] = value; + memcpy (data.elements + newIndex, tempCopy, sizeof (ElementType)); } lock.exit(); @@ -2438,7 +2561,7 @@ public: (void) comparator; // if you pass in an object with a static compareElements() method, this // avoids getting warning messages about the parameter being unused lock.enter(); - sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); + sortArray (comparator, (ElementType*) data.elements, 0, size() - 1, retainOrderOfEquivalentItems); lock.exit(); } @@ -2473,102 +2596,6 @@ private: #ifndef __JUCE_BITARRAY_JUCEHEADER__ #define __JUCE_BITARRAY_JUCEHEADER__ -/********* Start of inlined file: juce_HeapBlock.h *********/ -#ifndef __JUCE_HEAPBLOCK_JUCEHEADER__ -#define __JUCE_HEAPBLOCK_JUCEHEADER__ - -template -class HeapBlock -{ -public: - - HeapBlock() : data (0) - { - } - - HeapBlock (const size_t numElements) - : data ((ElementType*) ::juce_malloc (numElements * sizeof (ElementType))) - { - } - - ~HeapBlock() - { - ::juce_free (data); - } - - inline operator ElementType*() const { return data; } - - inline operator void*() const { return (void*) data; } - - inline ElementType* operator->() const { return data; } - - template - inline operator CastType*() const { return (CastType*) data; } - - template - inline ElementType& operator[] (IndexType index) const { return data [index]; } - - template - inline ElementType* operator+ (IndexType index) const { return data + index; } - - inline ElementType** operator&() const { return (ElementType**) &data; } - - inline bool operator== (const ElementType* const otherPointer) const { return otherPointer == data; } - - inline bool operator!= (const ElementType* const otherPointer) const { return otherPointer != data; } - - void malloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) - { - ::juce_free (data); - data = (ElementType*) ::juce_malloc (newNumElements * elementSize); - } - - void calloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) - { - ::juce_free (data); - data = (ElementType*) ::juce_calloc (newNumElements * elementSize); - } - - void allocate (const size_t newNumElements, const bool initialiseToZero) - { - ::juce_free (data); - - if (initialiseToZero) - data = (ElementType*) ::juce_calloc (newNumElements * sizeof (ElementType)); - else - data = (ElementType*) ::juce_malloc (newNumElements * sizeof (ElementType)); - } - - void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) - { - if (data == 0) - data = (ElementType*) ::juce_malloc (newNumElements * elementSize); - else - data = (ElementType*) ::juce_realloc (data, newNumElements * elementSize); - } - - void free() - { - ::juce_free (data); - data = 0; - } - - void swapWith (HeapBlock & other) - { - swapVariables (data, other.data); - } - -private: - - ElementType* data; - - HeapBlock (const HeapBlock&); - const HeapBlock& operator= (const HeapBlock&); -}; - -#endif // __JUCE_HEAPBLOCK_JUCEHEADER__ -/********* End of inlined file: juce_HeapBlock.h *********/ - class MemoryBlock; class JUCE_API BitArray @@ -3098,7 +3125,7 @@ public: (void) comparator; // if you pass in an object with a static compareElements() method, this // avoids getting warning messages about the parameter being unused lock.enter(); - insert (findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed), newObject); + insert (findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed), newObject); lock.exit(); } @@ -3292,14 +3319,12 @@ public: } } - template - void swapWithArray (OtherArrayType& otherArray) throw() + void swapWithArray (OwnedArray & otherArray) throw() { lock.enter(); otherArray.lock.enter(); - swapVariables (numUsed, otherArray.numUsed); - swapVariables (data.elements, otherArray.data.elements); - swapVariables (data.numAllocated, otherArray.data.numAllocated); + data.swapWith (otherArray.data); + swapVariables (numUsed, otherArray.numUsed); otherArray.lock.exit(); lock.exit(); } @@ -3326,7 +3351,7 @@ public: // avoids getting warning messages about the parameter being unused lock.enter(); - sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); + sortArray (comparator, (ObjectClass**) data.elements, 0, size() - 1, retainOrderOfEquivalentItems); lock.exit(); } @@ -3468,7 +3493,7 @@ public: juce_UseDebuggingNewOperator private: - OwnedArray strings; + Array strings; }; #endif // __JUCE_STRINGARRAY_JUCEHEADER__ @@ -4956,7 +4981,7 @@ public: ObjectClass* newObject) throw() { lock.enter(); - insert (findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed), newObject); + insert (findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed), newObject); lock.exit(); } @@ -4965,7 +4990,7 @@ public: ObjectClass* newObject) throw() { lock.enter(); - const int index = findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed); + const int index = findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed); if (index > 0 && comparator.compareElements (newObject, data.elements [index - 1]) == 0) set (index - 1, newObject); // replace an existing object that matches @@ -5144,7 +5169,7 @@ public: // avoids getting warning messages about the parameter being unused lock.enter(); - sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); + sortArray (comparator, (ObjectClass*) data.elements, 0, size() - 1, retainOrderOfEquivalentItems); lock.exit(); } diff --git a/src/containers/juce_Array.h b/src/containers/juce_Array.h index 93c2d59864..d33f71e8fe 100644 --- a/src/containers/juce_Array.h +++ b/src/containers/juce_Array.h @@ -70,7 +70,10 @@ public: other.lockArray(); numUsed = other.numUsed; data.setAllocatedSize (other.numUsed); - memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); + + for (int i = 0; i < numUsed; ++i) + new (data.elements + i) ElementType (other.data.elements[i]); + other.unlockArray(); } @@ -94,12 +97,16 @@ public: : numUsed (numValues) { data.setAllocatedSize (numValues); - memcpy (data.elements, values, numValues * sizeof (ElementType)); + + for (int i = 0; i < numValues; ++i) + new (data.elements + i) ElementType (values[i]); } /** Destructor. */ ~Array() throw() { + for (int i = 0; i < numUsed; ++i) + data.elements[i].~ElementType(); } /** Copies another array. @@ -112,10 +119,27 @@ public: other.lockArray(); lock.enter(); - data.ensureAllocatedSize (other.size()); - numUsed = other.numUsed; - memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); - minimiseStorageOverheads(); + if (other.size() > numUsed) + { + data.ensureAllocatedSize (other.size()); + + int i = 0; + for (; i < numUsed; ++i) + data.elements[i] = other.data.elements[i]; + + numUsed = other.size(); + for (; i < numUsed; ++i) + new (data.elements + i) ElementType (other.data.elements[i]); + } + else + { + numUsed = other.size(); + + for (int i = 0; i < numUsed; ++i) + data.elements[i] = other.data.elements[i]; + + minimiseStorageOverheads(); + } lock.exit(); other.unlockArray(); @@ -176,6 +200,10 @@ public: void clear() throw() { lock.enter(); + + for (int i = 0; i < numUsed; ++i) + data.elements[i].~ElementType(); + data.setAllocatedSize (0); numUsed = 0; lock.exit(); @@ -188,6 +216,10 @@ public: void clearQuick() throw() { lock.enter(); + + for (int i = 0; i < numUsed; ++i) + data.elements[i].~ElementType(); + numUsed = 0; lock.exit(); } @@ -370,7 +402,7 @@ public: { lock.enter(); data.ensureAllocatedSize (numUsed + 1); - data.elements [numUsed++] = newElement; + new (data.elements + numUsed++) ElementType (newElement); lock.exit(); } @@ -399,12 +431,12 @@ public: if (numberToMove > 0) memmove (insertPos + 1, insertPos, numberToMove * sizeof (ElementType)); - *insertPos = newElement; + new (insertPos) ElementType (newElement); ++numUsed; } else { - data.elements [numUsed++] = newElement; + new (data.elements + numUsed++) ElementType (newElement); } lock.exit(); @@ -429,24 +461,24 @@ public: { lock.enter(); data.ensureAllocatedSize (numUsed + numberOfTimesToInsertIt); - + ElementType* insertPos; + if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) { - ElementType* insertPos = data.elements + indexToInsertAt; + insertPos = data.elements + indexToInsertAt; const int numberToMove = numUsed - indexToInsertAt; - memmove (insertPos + numberOfTimesToInsertIt, insertPos, numberToMove * sizeof (ElementType)); - numUsed += numberOfTimesToInsertIt; - - while (--numberOfTimesToInsertIt >= 0) - *insertPos++ = newElement; } else { - while (--numberOfTimesToInsertIt >= 0) - data.elements [numUsed++] = newElement; + insertPos = data.elements + numUsed; } + numUsed += numberOfTimesToInsertIt; + + while (--numberOfTimesToInsertIt >= 0) + new (insertPos++) ElementType (newElement); + lock.exit(); } } @@ -471,24 +503,24 @@ public: { lock.enter(); data.ensureAllocatedSize (numUsed + numberOfElements); + ElementType* insertPos; if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) { - ElementType* insertPos = data.elements + indexToInsertAt; + insertPos = data.elements + indexToInsertAt; const int numberToMove = numUsed - indexToInsertAt; - memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ElementType)); - numUsed += numberOfElements; - - while (--numberOfElements >= 0) - *insertPos++ = *newElements++; } else { - while (--numberOfElements >= 0) - data.elements [numUsed++] = *newElements++; + insertPos = data.elements + numUsed; } + numUsed += numberOfElements; + + while (--numberOfElements >= 0) + new (insertPos++) ElementType (*newElements++); + lock.exit(); } } @@ -525,22 +557,19 @@ public: { jassert (indexToChange >= 0); - if (indexToChange >= 0) + lock.enter(); + + if (((unsigned int) indexToChange) < (unsigned int) numUsed) { - lock.enter(); - - if (indexToChange < numUsed) - { - data.elements [indexToChange] = newValue; - } - else - { - data.ensureAllocatedSize (numUsed + 1); - data.elements [numUsed++] = newValue; - } - - lock.exit(); + data.elements [indexToChange] = newValue; } + else if (indexToChange >= 0) + { + data.ensureAllocatedSize (numUsed + 1); + new (data.elements + numUsed++) ElementType (newValue); + } + + lock.exit(); } /** Replaces an element with a new value without doing any bounds-checking. @@ -577,7 +606,7 @@ public: data.ensureAllocatedSize (numUsed + numElementsToAdd); while (--numElementsToAdd >= 0) - data.elements [numUsed++] = *elementsToAdd++; + new (data.elements + numUsed++) ElementType (*elementsToAdd++); } lock.exit(); @@ -588,14 +617,12 @@ public: If you need to exchange two arrays, this is vastly quicker than using copy-by-value because it just swaps their internal pointers. */ - template - void swapWithArray (OtherArrayType& otherArray) throw() + void swapWithArray (Array & otherArray) throw() { lock.enter(); otherArray.lock.enter(); - swapVariables (numUsed, otherArray.numUsed); - swapVariables (data.elements, otherArray.data.elements); - swapVariables (data.numAllocated, otherArray.data.numAllocated); + data.swapWith (otherArray.data); + swapVariables (numUsed, otherArray.numUsed); otherArray.lock.exit(); lock.exit(); } @@ -649,7 +676,7 @@ public: const ElementType newElement) throw() { lock.enter(); - insert (findInsertIndexInSortedArray (comparator, data.elements, newElement, 0, numUsed), newElement); + insert (findInsertIndexInSortedArray (comparator, (ElementType*) data.elements, newElement, 0, numUsed), newElement); lock.exit(); } @@ -725,7 +752,8 @@ public: --numUsed; ElementType* const e = data.elements + indexToRemove; - ElementType const removed = *e; + ElementType removed (*e); + e->~ElementType(); const int numberToShift = numUsed - indexToRemove; if (numberToShift > 0) @@ -784,7 +812,7 @@ public: @see remove, removeValue */ void removeRange (int startIndex, - const int numberToRemove) throw() + int numberToRemove) throw() { lock.enter(); const int endIndex = jlimit (0, numUsed, startIndex + numberToRemove); @@ -792,16 +820,17 @@ public: if (endIndex > startIndex) { - const int rangeSize = endIndex - startIndex; ElementType* e = data.elements + startIndex; - int numToShift = numUsed - endIndex; - numUsed -= rangeSize; - while (--numToShift >= 0) - { - *e = e [rangeSize]; - ++e; - } + numberToRemove = endIndex - startIndex; + for (int i = 0; i < numberToRemove; ++i) + e[i].~ElementType(); + + const int numToShift = numUsed - endIndex; + if (numToShift > 0) + memmove (e, e + numberToRemove, numToShift * sizeof (ElementType)); + + numUsed -= numberToRemove; if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); @@ -815,10 +844,17 @@ public: @param howManyToRemove how many elements to remove from the end of the array @see remove, removeValue, removeRange */ - void removeLast (const int howManyToRemove = 1) throw() + void removeLast (int howManyToRemove = 1) throw() { lock.enter(); - numUsed = jmax (0, numUsed - howManyToRemove); + + if (howManyToRemove > numUsed) + howManyToRemove = numUsed; + + for (int i = 0; i < howManyToRemove; ++i) + data.elements [numUsed - i].~ElementType(); + + numUsed -= howManyToRemove; if ((numUsed << 1) < data.numAllocated) minimiseStorageOverheads(); @@ -935,7 +971,8 @@ public: if (((unsigned int) newIndex) >= (unsigned int) numUsed) newIndex = numUsed - 1; - const ElementType value = data.elements [currentIndex]; + char tempCopy [sizeof (ElementType)]; + memcpy (tempCopy, data.elements + currentIndex, sizeof (ElementType)); if (newIndex > currentIndex) { @@ -950,7 +987,7 @@ public: (currentIndex - newIndex) * sizeof (ElementType)); } - data.elements [newIndex] = value; + memcpy (data.elements + newIndex, tempCopy, sizeof (ElementType)); } lock.exit(); @@ -1018,7 +1055,7 @@ public: (void) comparator; // if you pass in an object with a static compareElements() method, this // avoids getting warning messages about the parameter being unused lock.enter(); - sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); + sortArray (comparator, (ElementType*) data.elements, 0, size() - 1, retainOrderOfEquivalentItems); lock.exit(); } diff --git a/src/containers/juce_ArrayAllocationBase.h b/src/containers/juce_ArrayAllocationBase.h index 1ed5250b68..fdd7550dab 100644 --- a/src/containers/juce_ArrayAllocationBase.h +++ b/src/containers/juce_ArrayAllocationBase.h @@ -26,6 +26,8 @@ #ifndef __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__ #define __JUCE_ARRAYALLOCATIONBASE_JUCEHEADER__ +#include "juce_HeapBlock.h" + //============================================================================== /** @@ -43,15 +45,13 @@ public: //============================================================================== /** Creates an empty array. */ ArrayAllocationBase() throw() - : elements (0), - numAllocated (0) + : numAllocated (0) { } /** Destructor. */ ~ArrayAllocationBase() { - delete[] elements; } //============================================================================== @@ -62,28 +62,14 @@ public: @param numElements the number of elements that are needed */ - void setAllocatedSize (const int numElements) throw() + void setAllocatedSize (const int numElements) { if (numAllocated != numElements) { if (numElements > 0) - { - ElementType* const newElements = new ElementType [numElements]; - - const int itemsToRetain = jmin (numElements, numAllocated); - - for (int i = 0; i < itemsToRetain; ++i) - newElements[i] = elements[i]; - - delete[] elements; - elements = newElements; - - } + elements.realloc (numElements); else - { - delete[] elements; - elements = 0; - } + elements.free(); numAllocated = numElements; } @@ -97,7 +83,7 @@ public: @param minNumElements the minimum number of elements that are needed */ - void ensureAllocatedSize (int minNumElements) throw() + void ensureAllocatedSize (int minNumElements) { if (minNumElements > numAllocated) setAllocatedSize ((minNumElements + minNumElements / 2 + 8) & ~7); @@ -106,14 +92,21 @@ public: /** Minimises the amount of storage allocated so that it's no more than the given number of elements. */ - void shrinkToNoMoreThan (int maxNumElements) throw() + void shrinkToNoMoreThan (int maxNumElements) { if (maxNumElements < numAllocated) setAllocatedSize (maxNumElements); } + + /** Swap the contents of two objects. */ + void swapWith (ArrayAllocationBase & other) + { + elements.swapWith (other.elements); + swapVariables (numAllocated, other.numAllocated); + } //============================================================================== - ElementType* elements; + HeapBlock elements; int numAllocated; private: diff --git a/src/containers/juce_OwnedArray.h b/src/containers/juce_OwnedArray.h index 1bf749a711..8692a2e0c1 100644 --- a/src/containers/juce_OwnedArray.h +++ b/src/containers/juce_OwnedArray.h @@ -379,7 +379,7 @@ public: (void) comparator; // if you pass in an object with a static compareElements() method, this // avoids getting warning messages about the parameter being unused lock.enter(); - insert (findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed), newObject); + insert (findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed), newObject); lock.exit(); } @@ -646,14 +646,12 @@ public: If you need to exchange two arrays, this is vastly quicker than using copy-by-value because it just swaps their internal pointers. */ - template - void swapWithArray (OtherArrayType& otherArray) throw() + void swapWithArray (OwnedArray & otherArray) throw() { lock.enter(); otherArray.lock.enter(); - swapVariables (numUsed, otherArray.numUsed); - swapVariables (data.elements, otherArray.data.elements); - swapVariables (data.numAllocated, otherArray.data.numAllocated); + data.swapWith (otherArray.data); + swapVariables (numUsed, otherArray.numUsed); otherArray.lock.exit(); lock.exit(); } @@ -719,7 +717,7 @@ public: // avoids getting warning messages about the parameter being unused lock.enter(); - sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); + sortArray (comparator, (ObjectClass**) data.elements, 0, size() - 1, retainOrderOfEquivalentItems); lock.exit(); } diff --git a/src/containers/juce_ReferenceCountedArray.h b/src/containers/juce_ReferenceCountedArray.h index ec153ead10..ebe1d693a3 100644 --- a/src/containers/juce_ReferenceCountedArray.h +++ b/src/containers/juce_ReferenceCountedArray.h @@ -424,7 +424,7 @@ public: ObjectClass* newObject) throw() { lock.enter(); - insert (findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed), newObject); + insert (findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed), newObject); lock.exit(); } @@ -438,7 +438,7 @@ public: ObjectClass* newObject) throw() { lock.enter(); - const int index = findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed); + const int index = findInsertIndexInSortedArray (comparator, (ObjectClass**) data.elements, newObject, 0, numUsed); if (index > 0 && comparator.compareElements (newObject, data.elements [index - 1]) == 0) set (index - 1, newObject); // replace an existing object that matches @@ -716,7 +716,7 @@ public: // avoids getting warning messages about the parameter being unused lock.enter(); - sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); + sortArray (comparator, (ObjectClass*) data.elements, 0, size() - 1, retainOrderOfEquivalentItems); lock.exit(); } diff --git a/src/core/juce_FileLogger.cpp b/src/core/juce_FileLogger.cpp index ecd3b7cfd0..de69a3dbc6 100644 --- a/src/core/juce_FileLogger.cpp +++ b/src/core/juce_FileLogger.cpp @@ -134,7 +134,8 @@ FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirector { #if JUCE_MAC File logFile ("~/Library/Logs"); - logFile = logFile.getChildFile (logFileName); + logFile = logFile.getChildFile (logFileSubDirectoryName) + .getChildFile (logFileName); #else File logFile (File::getSpecialLocation (File::userApplicationDataDirectory)); diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index 52f1151a32..d090296b26 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -108,8 +108,7 @@ void Path::clear() throw() void Path::swapWithPath (Path& other) { - swapVariables (data.numAllocated, other.data.numAllocated); - swapVariables (data.elements, other.data.elements); + data.swapWith (other.data); swapVariables (numElements, other.numElements); swapVariables (pathXMin, other.pathXMin); swapVariables (pathXMax, other.pathXMax); diff --git a/src/native/linux/juce_linux_Windowing.cpp b/src/native/linux/juce_linux_Windowing.cpp index dd5090f1c9..e6252c7d4e 100644 --- a/src/native/linux/juce_linux_Windowing.cpp +++ b/src/native/linux/juce_linux_Windowing.cpp @@ -1738,7 +1738,11 @@ private: void timerCallback() { - if (! regionsNeedingRepaint.isEmpty() && shmCompletedDrawing) +#if JUCE_USE_XSHM + if (! shmCompletedDrawing) + return; +#endif + if (! regionsNeedingRepaint.isEmpty()) { stopTimer(); performAnyPendingRepaintsNow(); @@ -1760,13 +1764,23 @@ private: void performAnyPendingRepaintsNow() { + if (! shmCompletedDrawing) + { + startTimer (repaintTimerPeriod); + return; + } + peer->clearMaskedRegion(); - const Rectangle totalArea (regionsNeedingRepaint.getBounds()); + RectangleList originalRepaintRegion (regionsNeedingRepaint); + regionsNeedingRepaint.clear(); + const Rectangle totalArea (originalRepaintRegion.getBounds()); if (! totalArea.isEmpty()) { +#if JUCE_USE_XSHM shmCompletedDrawing = false; +#endif if (image == 0 || image->getWidth() < totalArea.getWidth() || image->getHeight() < totalArea.getHeight()) @@ -1789,13 +1803,13 @@ private: context.setOrigin (-totalArea.getX(), -totalArea.getY()); - if (context.clipToRectangleList (regionsNeedingRepaint)) + if (context.clipToRectangleList (originalRepaintRegion)) peer->handlePaint (context); if (! peer->maskedRegion.isEmpty()) - regionsNeedingRepaint.subtract (peer->maskedRegion); + originalRepaintRegion.subtract (peer->maskedRegion); - for (RectangleList::Iterator i (regionsNeedingRepaint); i.next();) + for (RectangleList::Iterator i (originalRepaintRegion); i.next();) { const Rectangle& r = *i.getRectangle(); @@ -1805,17 +1819,12 @@ private: } } - regionsNeedingRepaint.clear(); - lastTimeImageUsed = Time::getApproximateMillisecondCounter(); startTimer (repaintTimerPeriod); } #if JUCE_USE_XSHM - void notifyPaintCompleted() - { - shmCompletedDrawing = true; - } + void notifyPaintCompleted() { shmCompletedDrawing = true; } #endif private: @@ -1825,8 +1834,7 @@ private: RectangleList regionsNeedingRepaint; #if JUCE_USE_XSHM - bool useARGBImagesForRendering; - bool shmCompletedDrawing; + bool useARGBImagesForRendering, shmCompletedDrawing; #endif LinuxRepaintManager (const LinuxRepaintManager&); const LinuxRepaintManager& operator= (const LinuxRepaintManager&); diff --git a/src/native/mac/juce_mac_NSViewComponentPeer.mm b/src/native/mac/juce_mac_NSViewComponentPeer.mm index 6076a2de69..68d1bf50a4 100644 --- a/src/native/mac/juce_mac_NSViewComponentPeer.mm +++ b/src/native/mac/juce_mac_NSViewComponentPeer.mm @@ -210,7 +210,7 @@ public: NSWindow* window; JuceNSView* view; - bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics; + bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall; }; //============================================================================== @@ -668,10 +668,11 @@ NSViewComponentPeer::NSViewComponentPeer (Component* const component_, fullScreen (false), insideDrawRect (false), #if USE_COREGRAPHICS_RENDERING - usingCoreGraphics (true) + usingCoreGraphics (true), #else - usingCoreGraphics (false) + usingCoreGraphics (false), #endif + recursiveToFrontCall (false) { NSRect r; r.origin.x = 0; @@ -1033,7 +1034,12 @@ void NSViewComponentPeer::toFront (bool makeActiveWindow) else [window orderFront: nil]; - handleBroughtToFront(); + if (! recursiveToFrontCall) + { + recursiveToFrontCall = true; + handleBroughtToFront(); + recursiveToFrontCall = false; + } } } diff --git a/src/text/juce_StringArray.cpp b/src/text/juce_StringArray.cpp index 4b8ae6ddbb..a65044cae9 100644 --- a/src/text/juce_StringArray.cpp +++ b/src/text/juce_StringArray.cpp @@ -93,7 +93,7 @@ bool StringArray::operator== (const StringArray& other) const throw() return false; for (int i = size(); --i >= 0;) - if (*other.strings.getUnchecked(i) != *strings.getUnchecked(i)) + if (other.strings.getReference(i) != strings.getReference(i)) return false; return true; @@ -112,20 +112,20 @@ void StringArray::clear() throw() const String& StringArray::operator[] (const int index) const throw() { if (((unsigned int) index) < (unsigned int) strings.size()) - return *strings.getUnchecked (index); + return strings.getReference (index); return String::empty; } void StringArray::add (const String& newString) throw() { - strings.add (new String (newString)); + strings.add (newString); } void StringArray::insert (const int index, const String& newString) throw() { - strings.insert (index, new String (newString)); + strings.insert (index, newString); } void StringArray::addIfNotAlreadyThere (const String& newString, @@ -149,18 +149,13 @@ void StringArray::addArray (const StringArray& otherArray, numElementsToAdd = otherArray.size() - startIndex; while (--numElementsToAdd >= 0) - strings.add (new String (*otherArray.strings.getUnchecked (startIndex++))); + strings.add (otherArray.strings.getReference (startIndex++)); } void StringArray::set (const int index, const String& newString) throw() { - String* const s = strings [index]; - - if (s != 0) - *s = newString; - else if (index >= 0) - add (newString); + strings.set (index, newString); } bool StringArray::contains (const String& stringToLookFor, @@ -169,13 +164,13 @@ bool StringArray::contains (const String& stringToLookFor, if (ignoreCase) { for (int i = size(); --i >= 0;) - if (strings.getUnchecked(i)->equalsIgnoreCase (stringToLookFor)) + if (strings.getReference(i).equalsIgnoreCase (stringToLookFor)) return true; } else { for (int i = size(); --i >= 0;) - if (stringToLookFor == *strings.getUnchecked(i)) + if (stringToLookFor == strings.getReference(i)) return true; } @@ -195,7 +190,7 @@ int StringArray::indexOf (const String& stringToLookFor, { while (i < numElements) { - if (strings.getUnchecked(i)->equalsIgnoreCase (stringToLookFor)) + if (strings.getReference(i).equalsIgnoreCase (stringToLookFor)) return i; ++i; @@ -205,7 +200,7 @@ int StringArray::indexOf (const String& stringToLookFor, { while (i < numElements) { - if (stringToLookFor == *strings.getUnchecked (i)) + if (stringToLookFor == strings.getReference (i)) return i; ++i; @@ -227,13 +222,13 @@ void StringArray::removeString (const String& stringToRemove, if (ignoreCase) { for (int i = size(); --i >= 0;) - if (strings.getUnchecked(i)->equalsIgnoreCase (stringToRemove)) + if (strings.getReference(i).equalsIgnoreCase (stringToRemove)) strings.remove (i); } else { for (int i = size(); --i >= 0;) - if (stringToRemove == *strings.getUnchecked (i)) + if (stringToRemove == strings.getReference (i)) strings.remove (i); } } @@ -244,13 +239,13 @@ void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings) throw( if (removeWhitespaceStrings) { for (int i = size(); --i >= 0;) - if (! strings.getUnchecked(i)->containsNonWhitespaceChars()) + if (! strings.getReference(i).containsNonWhitespaceChars()) strings.remove (i); } else { for (int i = size(); --i >= 0;) - if (strings.getUnchecked(i)->isEmpty()) + if (strings.getReference(i).isEmpty()) strings.remove (i); } } @@ -259,40 +254,34 @@ void StringArray::trim() throw() { for (int i = size(); --i >= 0;) { - String& s = *strings.getUnchecked(i); + String& s = strings.getReference(i); s = s.trim(); } } //============================================================================== -class InternalStringArrayComparator +class InternalStringArrayComparator_CaseSensitive { public: - static int compareElements (void* const first, void* const second) throw() - { - return ((const String*) first)->compare (*(const String*) second); - } + static int compareElements (String& first, String& second) { return first.compare (second); } }; -class InsensitiveInternalStringArrayComparator +class InternalStringArrayComparator_CaseInsensitive { public: - static int compareElements (void* const first, void* const second) throw() - { - return ((const String*) first)->compareIgnoreCase (*(const String*) second); - } + static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); } }; void StringArray::sort (const bool ignoreCase) throw() { if (ignoreCase) { - InsensitiveInternalStringArrayComparator comp; + InternalStringArrayComparator_CaseInsensitive comp; strings.sort (comp); } else { - InternalStringArrayComparator comp; + InternalStringArrayComparator_CaseSensitive comp; strings.sort (comp); } } @@ -318,13 +307,13 @@ const String StringArray::joinIntoString (const String& separator, return String::empty; if (start == last - 1) - return *strings.getUnchecked (start); + return strings.getReference (start); const int separatorLen = separator.length(); int charsNeeded = separatorLen * (last - start - 1); for (int i = start; i < last; ++i) - charsNeeded += strings.getUnchecked(i)->length(); + charsNeeded += strings.getReference(i).length(); String result; result.preallocateStorage (charsNeeded); @@ -333,7 +322,7 @@ const String StringArray::joinIntoString (const String& separator, while (start < last) { - const String& s = *strings.getUnchecked (start); + const String& s = strings.getReference (start); const int len = s.length(); if (len > 0) @@ -499,7 +488,7 @@ void StringArray::removeDuplicates (const bool ignoreCase) throw() { for (int i = 0; i < size() - 1; ++i) { - const String& s = *strings.getUnchecked(i); + const String s (strings.getReference(i)); int nextIndex = i + 1; @@ -522,7 +511,7 @@ void StringArray::appendNumbersToDuplicates (const bool ignoreCase, { for (int i = 0; i < size() - 1; ++i) { - String& s = *strings.getUnchecked(i); + String& s = strings.getReference(i); int nextIndex = indexOf (s, ignoreCase, i + 1); diff --git a/src/text/juce_StringArray.h b/src/text/juce_StringArray.h index 191e7f938c..1abbe36cd1 100644 --- a/src/text/juce_StringArray.h +++ b/src/text/juce_StringArray.h @@ -27,7 +27,7 @@ #define __JUCE_STRINGARRAY_JUCEHEADER__ #include "juce_String.h" -#include "../containers/juce_OwnedArray.h" +#include "../containers/juce_Array.h" #ifndef DOXYGEN // (used in StringArray::appendNumbersToDuplicates) @@ -325,7 +325,7 @@ public: juce_UseDebuggingNewOperator private: - OwnedArray strings; + Array strings; };