@@ -435,45 +435,42 @@ | |||||
#pragma warning (pop) | #pragma warning (pop) | ||||
#endif | #endif | ||||
template <class T> | |||||
template <class ComClass> | |||||
class ComSmartPtr | class ComSmartPtr | ||||
{ | { | ||||
public: | public: | ||||
ComSmartPtr() throw() : p (0) {} | |||||
ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); } | |||||
ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); } | |||||
~ComSmartPtr() { if (p != 0) p->Release(); } | |||||
ComSmartPtr() throw() : p (0) {} | |||||
ComSmartPtr (ComClass* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); } | |||||
ComSmartPtr (const ComSmartPtr<ComClass>& p_) : p (p_.p) { if (p != 0) p->AddRef(); } | |||||
~ComSmartPtr() { if (p != 0) p->Release(); } | |||||
operator T*() const throw() { return p; } | |||||
T& operator*() const throw() { return *p; } | |||||
T** operator&() throw() { return &p; } | |||||
T* operator->() const throw() { return p; } | |||||
operator ComClass*() const throw() { return p; } | |||||
ComClass& operator*() const throw() { return *p; } | |||||
ComClass** operator&() throw() { return &p; } | |||||
ComClass* operator->() const throw() { return p; } | |||||
T* operator= (T* const newP) | |||||
ComClass* operator= (ComClass* const newP) | |||||
{ | { | ||||
if (newP != 0) | |||||
newP->AddRef(); | |||||
if (p != 0) | |||||
p->Release(); | |||||
if (newP != 0) newP->AddRef(); | |||||
if (p != 0) p->Release(); | |||||
p = newP; | p = newP; | ||||
return newP; | return newP; | ||||
} | } | ||||
T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); } | |||||
ComClass* operator= (const ComSmartPtr<ComClass>& newP) { return operator= (newP.p); } | |||||
HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext) | |||||
HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext = CLSCTX_INPROC_SERVER) | |||||
{ | { | ||||
#ifndef __MINGW32__ | #ifndef __MINGW32__ | ||||
operator= (0); | operator= (0); | ||||
return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p); | |||||
return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof (ComClass), (void**) &p); | |||||
#else | #else | ||||
return S_FALSE; | return S_FALSE; | ||||
#endif | #endif | ||||
} | } | ||||
T* p; | |||||
private: | |||||
ComClass* p; | |||||
}; | }; | ||||
template <class ComClass> | template <class ComClass> | ||||
@@ -12155,6 +12152,12 @@ const String& StringArray::operator[] (const int index) const throw() | |||||
return String::empty; | return String::empty; | ||||
} | } | ||||
String& StringArray::getReference (const int index) throw() | |||||
{ | |||||
jassert (((unsigned int) index) < (unsigned int) strings.size()); | |||||
return strings.getReference (index); | |||||
} | |||||
void StringArray::add (const String& newString) | void StringArray::add (const String& newString) | ||||
{ | { | ||||
strings.add (newString); | strings.add (newString); | ||||
@@ -46807,7 +46810,7 @@ public: | |||||
{ | { | ||||
if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | ||||
{ | { | ||||
const SparseSet <int> selectedRows (owner.getSelectedRows()); | |||||
const SparseSet<int> selectedRows (owner.getSelectedRows()); | |||||
if (selectedRows.size() > 0) | if (selectedRows.size() > 0) | ||||
{ | { | ||||
@@ -47097,7 +47100,7 @@ void ListBox::updateContent() | |||||
if (selected [selected.size() - 1] >= totalItems) | if (selected [selected.size() - 1] >= totalItems) | ||||
{ | { | ||||
selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems); | |||||
selected.removeRange (Range <int> (totalItems, std::numeric_limits<int>::max())); | |||||
lastRowSelected = getSelectedRow (0); | lastRowSelected = getSelectedRow (0); | ||||
selectionChanged = true; | selectionChanged = true; | ||||
} | } | ||||
@@ -47132,7 +47135,7 @@ void ListBox::selectRowInternal (const int row, | |||||
if (deselectOthersFirst) | if (deselectOthersFirst) | ||||
selected.clear(); | selected.clear(); | ||||
selected.addRange (row, 1); | |||||
selected.addRange (Range<int> (row, row + 1)); | |||||
if (getHeight() == 0 || getWidth() == 0) | if (getHeight() == 0 || getWidth() == 0) | ||||
dontScroll = true; | dontScroll = true; | ||||
@@ -47181,7 +47184,7 @@ void ListBox::deselectRow (const int row) | |||||
{ | { | ||||
if (selected.contains (row)) | if (selected.contains (row)) | ||||
{ | { | ||||
selected.removeRange (row, 1); | |||||
selected.removeRange (Range <int> (row, row + 1)); | |||||
if (row == lastRowSelected) | if (row == lastRowSelected) | ||||
lastRowSelected = getSelectedRow (0); | lastRowSelected = getSelectedRow (0); | ||||
@@ -47195,7 +47198,7 @@ void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected, | |||||
const bool sendNotificationEventToModel) | const bool sendNotificationEventToModel) | ||||
{ | { | ||||
selected = setOfRowsToBeSelected; | selected = setOfRowsToBeSelected; | ||||
selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems); | |||||
selected.removeRange (Range <int> (totalItems, std::numeric_limits<int>::max())); | |||||
if (! isRowSelected (lastRowSelected)) | if (! isRowSelected (lastRowSelected)) | ||||
lastRowSelected = getSelectedRow (0); | lastRowSelected = getSelectedRow (0); | ||||
@@ -47219,10 +47222,10 @@ void ListBox::selectRangeOfRows (int firstRow, int lastRow) | |||||
firstRow = jlimit (0, jmax (0, numRows), firstRow); | firstRow = jlimit (0, jmax (0, numRows), firstRow); | ||||
lastRow = jlimit (0, jmax (0, numRows), lastRow); | lastRow = jlimit (0, jmax (0, numRows), lastRow); | ||||
selected.addRange (jmin (firstRow, lastRow), | |||||
abs (firstRow - lastRow) + 1); | |||||
selected.addRange (Range <int> (jmin (firstRow, lastRow), | |||||
jmax (firstRow, lastRow) + 1)); | |||||
selected.removeRange (lastRow, 1); | |||||
selected.removeRange (Range <int> (lastRow, lastRow + 1)); | |||||
} | } | ||||
selectRowInternal (lastRow, false, false, true); | selectRowInternal (lastRow, false, false, true); | ||||
@@ -50202,7 +50205,7 @@ public: | |||||
{ | { | ||||
if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | ||||
{ | { | ||||
const SparseSet <int> selectedRows (owner.getSelectedRows()); | |||||
const SparseSet<int> selectedRows (owner.getSelectedRows()); | |||||
if (selectedRows.size() > 0) | if (selectedRows.size() > 0) | ||||
{ | { | ||||
@@ -90835,7 +90838,7 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
if (hasAlphaChannel()) | if (hasAlphaChannel()) | ||||
{ | { | ||||
const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f)); | const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f)); | ||||
SparseSet <int> pixelsOnRow; | |||||
SparseSet<int> pixelsOnRow; | |||||
const BitmapData srcData (*this, 0, 0, getWidth(), getHeight()); | const BitmapData srcData (*this, 0, 0, getWidth(), getHeight()); | ||||
@@ -90849,7 +90852,7 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
for (int x = 0; x < imageWidth; ++x) | for (int x = 0; x < imageWidth; ++x) | ||||
{ | { | ||||
if (((const PixelARGB*) lineData)->getAlpha() >= threshold) | if (((const PixelARGB*) lineData)->getAlpha() >= threshold) | ||||
pixelsOnRow.addRange (x, 1); | |||||
pixelsOnRow.addRange (Range<int> (x, x + 1)); | |||||
lineData += srcData.pixelStride; | lineData += srcData.pixelStride; | ||||
} | } | ||||
@@ -90859,7 +90862,7 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
for (int x = 0; x < imageWidth; ++x) | for (int x = 0; x < imageWidth; ++x) | ||||
{ | { | ||||
if (*lineData >= threshold) | if (*lineData >= threshold) | ||||
pixelsOnRow.addRange (x, 1); | |||||
pixelsOnRow.addRange (Range<int> (x, x + 1)); | |||||
lineData += srcData.pixelStride; | lineData += srcData.pixelStride; | ||||
} | } | ||||
@@ -90867,10 +90870,8 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i) | for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i) | ||||
{ | { | ||||
int x, w; | |||||
if (pixelsOnRow.getRange (i, x, w)) | |||||
result.add (Rectangle<int> (x, y, w, 1)); | |||||
const Range<int> range (pixelsOnRow.getRange (i)); | |||||
result.add (Rectangle<int> (range.getStart(), y, range.getLength(), 1)); | |||||
} | } | ||||
result.consolidate(); | result.consolidate(); | ||||
@@ -212224,7 +212225,7 @@ const File File::getLinkedTarget() const | |||||
return result; | return result; | ||||
ComSmartPtr <IShellLink> shellLink; | ComSmartPtr <IShellLink> shellLink; | ||||
if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER))) | |||||
if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink))) | |||||
{ | { | ||||
ComSmartPtr <IPersistFile> persistFile; | ComSmartPtr <IPersistFile> persistFile; | ||||
if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile))) | if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile))) | ||||
@@ -226110,7 +226111,7 @@ private: | |||||
bool createDevices() | bool createDevices() | ||||
{ | { | ||||
ComSmartPtr <IMMDeviceEnumerator> enumerator; | ComSmartPtr <IMMDeviceEnumerator> enumerator; | ||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER))) | |||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator)))) | |||||
return false; | return false; | ||||
ComSmartPtr <IMMDeviceCollection> deviceCollection; | ComSmartPtr <IMMDeviceCollection> deviceCollection; | ||||
@@ -226170,7 +226171,7 @@ public: | |||||
inputDeviceIds.clear(); | inputDeviceIds.clear(); | ||||
ComSmartPtr <IMMDeviceEnumerator> enumerator; | ComSmartPtr <IMMDeviceEnumerator> enumerator; | ||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER))) | |||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator)))) | |||||
return; | return; | ||||
const String defaultRenderer = getDefaultEndpoint (enumerator, false); | const String defaultRenderer = getDefaultEndpoint (enumerator, false); | ||||
@@ -226352,7 +226353,7 @@ public: | |||||
activeImage (0), | activeImage (0), | ||||
loadingImage (0) | loadingImage (0) | ||||
{ | { | ||||
HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC); | |||||
HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph); | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
@@ -226383,7 +226384,7 @@ public: | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER); | |||||
hr = smartTee.CoCreateInstance (CLSID_SmartTee); | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
@@ -226395,7 +226396,7 @@ public: | |||||
return; | return; | ||||
ComSmartPtr <IBaseFilter> sampleGrabberBase; | ComSmartPtr <IBaseFilter> sampleGrabberBase; | ||||
hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER); | |||||
hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber); | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
@@ -226434,7 +226435,7 @@ public: | |||||
height = pVih->bmiHeader.biHeight; | height = pVih->bmiHeader.biHeight; | ||||
ComSmartPtr <IBaseFilter> nullFilter; | ComSmartPtr <IBaseFilter> nullFilter; | ||||
hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER); | |||||
hr = nullFilter.CoCreateInstance (CLSID_NullRenderer); | |||||
hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer")); | hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer")); | ||||
if (connectFilters (sampleGrabberBase, nullFilter) | if (connectFilters (sampleGrabberBase, nullFilter) | ||||
@@ -226562,7 +226563,7 @@ public: | |||||
firstRecordedTime = Time(); | firstRecordedTime = Time(); | ||||
recordNextFrameTime = true; | recordNextFrameTime = true; | ||||
HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER); | |||||
HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter); | |||||
if (SUCCEEDED (hr)) | if (SUCCEEDED (hr)) | ||||
{ | { | ||||
@@ -227029,7 +227030,7 @@ static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names, | |||||
ComSmartPtr <IBaseFilter> result; | ComSmartPtr <IBaseFilter> result; | ||||
ComSmartPtr <ICreateDevEnum> pDevEnum; | ComSmartPtr <ICreateDevEnum> pDevEnum; | ||||
HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC); | |||||
HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum); | |||||
if (SUCCEEDED (hr)) | if (SUCCEEDED (hr)) | ||||
{ | { | ||||
@@ -227100,7 +227101,7 @@ CameraDevice* CameraDevice::openDevice (int index, | |||||
int maxWidth, int maxHeight) | int maxWidth, int maxHeight) | ||||
{ | { | ||||
ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder; | ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder; | ||||
HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC); | |||||
HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2); | |||||
if (SUCCEEDED (hr)) | if (SUCCEEDED (hr)) | ||||
{ | { | ||||
@@ -1868,7 +1868,7 @@ private: | |||||
public: | public: | ||||
static int compareElements (ParameterType first, ParameterType second) | static int compareElements (ParameterType first, ParameterType second) | ||||
{ | { | ||||
return (first < second) ? -1 : ((first < second) ? 1 : 0); | |||||
return (first < second) ? -1 : ((second < first) ? 1 : 0); | |||||
} | } | ||||
}; | }; | ||||
@@ -3997,6 +3997,8 @@ public: | |||||
const String& operator[] (int index) const throw(); | const String& operator[] (int index) const throw(); | ||||
String& getReference (int index) throw(); | |||||
bool contains (const String& stringToLookFor, | bool contains (const String& stringToLookFor, | ||||
bool ignoreCase = false) const; | bool ignoreCase = false) const; | ||||
@@ -4886,7 +4888,7 @@ public: | |||||
void setStart (const ValueType newStart) throw() | void setStart (const ValueType newStart) throw() | ||||
{ | { | ||||
start = newStart; | start = newStart; | ||||
if (newStart > end) | |||||
if (end < newStart) | |||||
end = newStart; | end = newStart; | ||||
} | } | ||||
@@ -4956,7 +4958,7 @@ public: | |||||
bool contains (const ValueType position) const throw() | bool contains (const ValueType position) const throw() | ||||
{ | { | ||||
return position >= start && position < end; | |||||
return start <= position && position < end; | |||||
} | } | ||||
ValueType clipValue (const ValueType value) const throw() | ValueType clipValue (const ValueType value) const throw() | ||||
@@ -4966,7 +4968,7 @@ public: | |||||
bool intersects (const Range& other) const throw() | bool intersects (const Range& other) const throw() | ||||
{ | { | ||||
return other.start < end && other.end > start; | |||||
return other.start < end && start < other.end; | |||||
} | } | ||||
const Range getIntersectionWith (const Range& other) const throw() | const Range getIntersectionWith (const Range& other) const throw() | ||||
@@ -4984,7 +4986,7 @@ public: | |||||
const Range constrainRange (const Range& rangeToConstrain) const throw() | const Range constrainRange (const Range& rangeToConstrain) const throw() | ||||
{ | { | ||||
const ValueType otherLen = rangeToConstrain.getLength(); | const ValueType otherLen = rangeToConstrain.getLength(); | ||||
return otherLen >= getLength() | |||||
return getLength() <= otherLen | |||||
? *this | ? *this | ||||
: rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart())); | : rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart())); | ||||
} | } | ||||
@@ -5802,20 +5804,20 @@ class SparseSet | |||||
{ | { | ||||
public: | public: | ||||
SparseSet() throw() | |||||
SparseSet() | |||||
{ | { | ||||
} | } | ||||
SparseSet (const SparseSet<Type>& other) throw() | |||||
SparseSet (const SparseSet<Type>& other) | |||||
: values (other.values) | : values (other.values) | ||||
{ | { | ||||
} | } | ||||
~SparseSet() throw() | |||||
~SparseSet() | |||||
{ | { | ||||
} | } | ||||
void clear() throw() | |||||
void clear() | |||||
{ | { | ||||
values.clear(); | values.clear(); | ||||
} | } | ||||
@@ -5825,43 +5827,37 @@ public: | |||||
return values.size() == 0; | return values.size() == 0; | ||||
} | } | ||||
Type size() const throw() | |||||
Type size() const | |||||
{ | { | ||||
Type num = 0; | |||||
Type total (0); | |||||
for (int i = 0; i < values.size(); i += 2) | for (int i = 0; i < values.size(); i += 2) | ||||
num += values[i + 1] - values[i]; | |||||
total += values.getUnchecked (i + 1) - values.getUnchecked (i); | |||||
return num; | |||||
return total; | |||||
} | } | ||||
Type operator[] (int index) const throw() | |||||
Type operator[] (Type index) const | |||||
{ | { | ||||
for (int i = 0; i < values.size(); i += 2) | for (int i = 0; i < values.size(); i += 2) | ||||
{ | { | ||||
const Type s = values.getUnchecked(i); | |||||
const Type e = values.getUnchecked(i + 1); | |||||
const Type start (values.getUnchecked (i)); | |||||
const Type len (values.getUnchecked (i + 1) - start); | |||||
if (index < e - s) | |||||
return s + index; | |||||
if (index < len) | |||||
return start + index; | |||||
index -= e - s; | |||||
index -= len; | |||||
} | } | ||||
return (Type) 0; | |||||
return Type (0); | |||||
} | } | ||||
bool contains (const Type valueToLookFor) const throw() | |||||
bool contains (const Type valueToLookFor) const | |||||
{ | { | ||||
bool on = false; | |||||
for (int i = 0; i < values.size(); ++i) | for (int i = 0; i < values.size(); ++i) | ||||
{ | |||||
if (values.getUnchecked(i) > valueToLookFor) | |||||
return on; | |||||
on = ! on; | |||||
} | |||||
if (valueToLookFor < values.getUnchecked(i)) | |||||
return (i & 1) != 0; | |||||
return false; | return false; | ||||
} | } | ||||
@@ -5871,67 +5867,64 @@ public: | |||||
return values.size() >> 1; | return values.size() >> 1; | ||||
} | } | ||||
bool getRange (const int rangeIndex, | |||||
Type& startValue, | |||||
Type& numValues) const throw() | |||||
const Range<Type> getRange (const int rangeIndex) const | |||||
{ | { | ||||
if (((unsigned int) rangeIndex) < (unsigned int) getNumRanges()) | if (((unsigned int) rangeIndex) < (unsigned int) getNumRanges()) | ||||
{ | |||||
startValue = values [rangeIndex << 1]; | |||||
numValues = values [(rangeIndex << 1) + 1] - startValue; | |||||
return true; | |||||
} | |||||
return false; | |||||
return Range<Type> (values.getUnchecked (rangeIndex << 1), | |||||
values.getUnchecked ((rangeIndex << 1) + 1)); | |||||
else | |||||
return Range<Type>(); | |||||
} | } | ||||
bool getTotalRange (Type& lowestValue, | |||||
Type& highestValue) const throw() | |||||
const Range<Type> getTotalRange() const | |||||
{ | { | ||||
if (values.size() > 0) | if (values.size() > 0) | ||||
{ | { | ||||
lowestValue = values.getUnchecked (0); | |||||
highestValue = values.getUnchecked (values.size() - 1); | |||||
return true; | |||||
jassert ((values.size() & 1) == 0); | |||||
return Range<Type> (values.getUnchecked (0), | |||||
values.getUnchecked (values.size() - 1)); | |||||
} | } | ||||
return false; | |||||
return Range<Type>(); | |||||
} | } | ||||
void addRange (const Type firstValue, | |||||
const Type numValuesToAdd) throw() | |||||
void addRange (const Range<Type>& range) | |||||
{ | { | ||||
jassert (numValuesToAdd >= 0); | |||||
if (numValuesToAdd > 0) | |||||
jassert (range.getLength() >= 0); | |||||
if (range.getLength() > 0) | |||||
{ | { | ||||
removeRange (firstValue, numValuesToAdd); | |||||
removeRange (range); | |||||
values.addUsingDefaultSort (firstValue); | |||||
values.addUsingDefaultSort (firstValue + numValuesToAdd); | |||||
values.addUsingDefaultSort (range.getStart()); | |||||
values.addUsingDefaultSort (range.getEnd()); | |||||
simplify(); | simplify(); | ||||
} | } | ||||
String s; | |||||
for (int i = 0; i < values.size(); ++i) | |||||
s << values[i] << " "; | |||||
DBG (s); | |||||
} | } | ||||
void removeRange (const Type firstValue, | |||||
const Type numValuesToRemove) throw() | |||||
void removeRange (const Range<Type>& rangeToRemove) | |||||
{ | { | ||||
jassert (numValuesToRemove >= 0); | |||||
jassert (rangeToRemove.getLength() >= 0); | |||||
if (numValuesToRemove >= 0 | |||||
&& firstValue < values.getLast()) | |||||
if (rangeToRemove.getLength() > 0 | |||||
&& values.size() > 0 | |||||
&& rangeToRemove.getStart() < values.getUnchecked (values.size() - 1) | |||||
&& values.getUnchecked(0) < rangeToRemove.getEnd()) | |||||
{ | { | ||||
const bool onAtStart = contains (firstValue - 1); | |||||
const Type lastValue = firstValue + jmin (numValuesToRemove, values.getLast() - firstValue); | |||||
const bool onAtStart = contains (rangeToRemove.getStart() - 1); | |||||
const Type lastValue (jmin (rangeToRemove.getEnd(), values.getLast())); | |||||
const bool onAtEnd = contains (lastValue); | const bool onAtEnd = contains (lastValue); | ||||
for (int i = values.size(); --i >= 0;) | for (int i = values.size(); --i >= 0;) | ||||
{ | { | ||||
if (values.getUnchecked(i) <= lastValue) | if (values.getUnchecked(i) <= lastValue) | ||||
{ | { | ||||
while (values.getUnchecked(i) >= firstValue) | |||||
while (values.getUnchecked(i) >= rangeToRemove.getStart()) | |||||
{ | { | ||||
values.remove (i); | values.remove (i); | ||||
@@ -5943,55 +5936,38 @@ public: | |||||
} | } | ||||
} | } | ||||
if (onAtStart) | |||||
values.addUsingDefaultSort (firstValue); | |||||
if (onAtEnd) | |||||
values.addUsingDefaultSort (lastValue); | |||||
if (onAtStart) values.addUsingDefaultSort (rangeToRemove.getStart()); | |||||
if (onAtEnd) values.addUsingDefaultSort (lastValue); | |||||
simplify(); | simplify(); | ||||
} | } | ||||
} | } | ||||
void invertRange (const Type firstValue, | |||||
const Type numValues) | |||||
void invertRange (const Range<Type>& range) | |||||
{ | { | ||||
SparseSet newItems; | SparseSet newItems; | ||||
newItems.addRange (firstValue, numValues); | |||||
newItems.addRange (range); | |||||
int i; | int i; | ||||
for (i = getNumRanges(); --i >= 0;) | for (i = getNumRanges(); --i >= 0;) | ||||
{ | |||||
const int start = values [i << 1]; | |||||
const int end = values [(i << 1) + 1]; | |||||
newItems.removeRange (getRange (i)); | |||||
newItems.removeRange (start, end); | |||||
} | |||||
removeRange (firstValue, numValues); | |||||
removeRange (range); | |||||
for (i = newItems.getNumRanges(); --i >= 0;) | for (i = newItems.getNumRanges(); --i >= 0;) | ||||
{ | |||||
const int start = newItems.values [i << 1]; | |||||
const int end = newItems.values [(i << 1) + 1]; | |||||
addRange (start, end); | |||||
} | |||||
addRange (newItems.getRange(i)); | |||||
} | } | ||||
bool overlapsRange (const Type firstValue, | |||||
const Type numValues) throw() | |||||
bool overlapsRange (const Range<Type>& range) | |||||
{ | { | ||||
jassert (numValues >= 0); | |||||
if (numValues > 0) | |||||
if (range.getLength() > 0) | |||||
{ | { | ||||
for (int i = getNumRanges(); --i >= 0;) | for (int i = getNumRanges(); --i >= 0;) | ||||
{ | { | ||||
if (firstValue >= values.getUnchecked ((i << 1) + 1)) | |||||
if (values.getUnchecked ((i << 1) + 1) <= range.getStart()) | |||||
return false; | return false; | ||||
if (firstValue + numValues > values.getUnchecked (i << 1)) | |||||
if (values.getUnchecked (i << 1) < range.getEnd()) | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
@@ -5999,20 +5975,17 @@ public: | |||||
return false; | return false; | ||||
} | } | ||||
bool containsRange (const Type firstValue, | |||||
const Type numValues) throw() | |||||
bool containsRange (const Range<Type>& range) | |||||
{ | { | ||||
jassert (numValues >= 0); | |||||
if (numValues > 0) | |||||
if (range.getLength() > 0) | |||||
{ | { | ||||
for (int i = getNumRanges(); --i >= 0;) | for (int i = getNumRanges(); --i >= 0;) | ||||
{ | { | ||||
if (firstValue >= values.getUnchecked ((i << 1) + 1)) | |||||
if (values.getUnchecked ((i << 1) + 1) <= range.getStart()) | |||||
return false; | return false; | ||||
if (firstValue >= values.getUnchecked (i << 1) | |||||
&& firstValue + numValues <= values.getUnchecked ((i << 1) + 1)) | |||||
if (values.getUnchecked (i << 1) <= range.getStart() | |||||
&& range.getEnd() <= values.getUnchecked ((i << 1) + 1)) | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
@@ -6036,13 +6009,13 @@ private: | |||||
// alternating start/end values of ranges of values that are present. | // alternating start/end values of ranges of values that are present. | ||||
Array<Type, DummyCriticalSection> values; | Array<Type, DummyCriticalSection> values; | ||||
void simplify() throw() | |||||
void simplify() | |||||
{ | { | ||||
jassert ((values.size() & 1) == 0); | jassert ((values.size() & 1) == 0); | ||||
for (int i = values.size(); --i > 0;) | for (int i = values.size(); --i > 0;) | ||||
if (values.getUnchecked(i) == values.getUnchecked (i - 1)) | if (values.getUnchecked(i) == values.getUnchecked (i - 1)) | ||||
values.removeRange (i - 1, 2); | |||||
values.removeRange (--i, 2); | |||||
} | } | ||||
}; | }; | ||||
@@ -279,7 +279,7 @@ private: | |||||
public: | public: | ||||
static int compareElements (ParameterType first, ParameterType second) | static int compareElements (ParameterType first, ParameterType second) | ||||
{ | { | ||||
return (first < second) ? -1 : ((first < second) ? 1 : 0); | |||||
return (first < second) ? -1 : ((second < first) ? 1 : 0); | |||||
} | } | ||||
}; | }; | ||||
@@ -104,7 +104,7 @@ public: | |||||
void setStart (const ValueType newStart) throw() | void setStart (const ValueType newStart) throw() | ||||
{ | { | ||||
start = newStart; | start = newStart; | ||||
if (newStart > end) | |||||
if (end < newStart) | |||||
end = newStart; | end = newStart; | ||||
} | } | ||||
@@ -204,7 +204,7 @@ public: | |||||
/** Returns true if the given position lies inside this range. */ | /** Returns true if the given position lies inside this range. */ | ||||
bool contains (const ValueType position) const throw() | bool contains (const ValueType position) const throw() | ||||
{ | { | ||||
return position >= start && position < end; | |||||
return start <= position && position < end; | |||||
} | } | ||||
/** Returns the nearest value to the one supplied, which lies within the range. */ | /** Returns the nearest value to the one supplied, which lies within the range. */ | ||||
@@ -216,7 +216,7 @@ public: | |||||
/** Returns true if the given range intersects this one. */ | /** Returns true if the given range intersects this one. */ | ||||
bool intersects (const Range& other) const throw() | bool intersects (const Range& other) const throw() | ||||
{ | { | ||||
return other.start < end && other.end > start; | |||||
return other.start < end && start < other.end; | |||||
} | } | ||||
/** Returns the range that is the intersection of the two ranges, or an empty range | /** Returns the range that is the intersection of the two ranges, or an empty range | ||||
@@ -247,7 +247,7 @@ public: | |||||
const Range constrainRange (const Range& rangeToConstrain) const throw() | const Range constrainRange (const Range& rangeToConstrain) const throw() | ||||
{ | { | ||||
const ValueType otherLen = rangeToConstrain.getLength(); | const ValueType otherLen = rangeToConstrain.getLength(); | ||||
return otherLen >= getLength() | |||||
return getLength() <= otherLen | |||||
? *this | ? *this | ||||
: rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart())); | : rangeToConstrain.movedToStartAt (jlimit (start, end - otherLen, rangeToConstrain.getStart())); | ||||
} | } | ||||
@@ -27,6 +27,7 @@ | |||||
#define __JUCE_SPARSESET_JUCEHEADER__ | #define __JUCE_SPARSESET_JUCEHEADER__ | ||||
#include "juce_ArrayAllocationBase.h" | #include "juce_ArrayAllocationBase.h" | ||||
#include "juce_Range.h" | |||||
#include "../threads/juce_CriticalSection.h" | #include "../threads/juce_CriticalSection.h" | ||||
@@ -47,24 +48,24 @@ class SparseSet | |||||
public: | public: | ||||
//============================================================================== | //============================================================================== | ||||
/** Creates a new empty set. */ | /** Creates a new empty set. */ | ||||
SparseSet() throw() | |||||
SparseSet() | |||||
{ | { | ||||
} | } | ||||
/** Creates a copy of another SparseSet. */ | /** Creates a copy of another SparseSet. */ | ||||
SparseSet (const SparseSet<Type>& other) throw() | |||||
SparseSet (const SparseSet<Type>& other) | |||||
: values (other.values) | : values (other.values) | ||||
{ | { | ||||
} | } | ||||
/** Destructor. */ | /** Destructor. */ | ||||
~SparseSet() throw() | |||||
~SparseSet() | |||||
{ | { | ||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
/** Clears the set. */ | /** Clears the set. */ | ||||
void clear() throw() | |||||
void clear() | |||||
{ | { | ||||
values.clear(); | values.clear(); | ||||
} | } | ||||
@@ -84,14 +85,14 @@ public: | |||||
are a lot of items in the set. Use isEmpty() for a quick test of whether there | are a lot of items in the set. Use isEmpty() for a quick test of whether there | ||||
are any items. | are any items. | ||||
*/ | */ | ||||
Type size() const throw() | |||||
Type size() const | |||||
{ | { | ||||
Type num = 0; | |||||
Type total (0); | |||||
for (int i = 0; i < values.size(); i += 2) | for (int i = 0; i < values.size(); i += 2) | ||||
num += values[i + 1] - values[i]; | |||||
total += values.getUnchecked (i + 1) - values.getUnchecked (i); | |||||
return num; | |||||
return total; | |||||
} | } | ||||
/** Returns one of the values in the set. | /** Returns one of the values in the set. | ||||
@@ -99,41 +100,34 @@ public: | |||||
@param index the index of the value to retrieve, in the range 0 to (size() - 1). | @param index the index of the value to retrieve, in the range 0 to (size() - 1). | ||||
@returns the value at this index, or 0 if it's out-of-range | @returns the value at this index, or 0 if it's out-of-range | ||||
*/ | */ | ||||
Type operator[] (int index) const throw() | |||||
Type operator[] (Type index) const | |||||
{ | { | ||||
for (int i = 0; i < values.size(); i += 2) | for (int i = 0; i < values.size(); i += 2) | ||||
{ | { | ||||
const Type s = values.getUnchecked(i); | |||||
const Type e = values.getUnchecked(i + 1); | |||||
const Type start (values.getUnchecked (i)); | |||||
const Type len (values.getUnchecked (i + 1) - start); | |||||
if (index < e - s) | |||||
return s + index; | |||||
if (index < len) | |||||
return start + index; | |||||
index -= e - s; | |||||
index -= len; | |||||
} | } | ||||
return (Type) 0; | |||||
return Type (0); | |||||
} | } | ||||
/** Checks whether a particular value is in the set. */ | /** Checks whether a particular value is in the set. */ | ||||
bool contains (const Type valueToLookFor) const throw() | |||||
bool contains (const Type valueToLookFor) const | |||||
{ | { | ||||
bool on = false; | |||||
for (int i = 0; i < values.size(); ++i) | for (int i = 0; i < values.size(); ++i) | ||||
{ | |||||
if (values.getUnchecked(i) > valueToLookFor) | |||||
return on; | |||||
on = ! on; | |||||
} | |||||
if (valueToLookFor < values.getUnchecked(i)) | |||||
return (i & 1) != 0; | |||||
return false; | return false; | ||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
/** Returns the number of contiguous blocks of values. | /** Returns the number of contiguous blocks of values. | ||||
@see getRange | @see getRange | ||||
*/ | */ | ||||
int getNumRanges() const throw() | int getNumRanges() const throw() | ||||
@@ -142,94 +136,78 @@ public: | |||||
} | } | ||||
/** Returns one of the contiguous ranges of values stored. | /** Returns one of the contiguous ranges of values stored. | ||||
@param rangeIndex the index of the range to look up, between 0 | @param rangeIndex the index of the range to look up, between 0 | ||||
and (getNumRanges() - 1) | and (getNumRanges() - 1) | ||||
@param startValue on return, the value at the start of the range | |||||
@param numValues on return, the number of values in the range | |||||
@see getTotalRange | @see getTotalRange | ||||
*/ | */ | ||||
bool getRange (const int rangeIndex, | |||||
Type& startValue, | |||||
Type& numValues) const throw() | |||||
const Range<Type> getRange (const int rangeIndex) const | |||||
{ | { | ||||
if (((unsigned int) rangeIndex) < (unsigned int) getNumRanges()) | if (((unsigned int) rangeIndex) < (unsigned int) getNumRanges()) | ||||
{ | |||||
startValue = values [rangeIndex << 1]; | |||||
numValues = values [(rangeIndex << 1) + 1] - startValue; | |||||
return true; | |||||
} | |||||
return false; | |||||
return Range<Type> (values.getUnchecked (rangeIndex << 1), | |||||
values.getUnchecked ((rangeIndex << 1) + 1)); | |||||
else | |||||
return Range<Type>(); | |||||
} | } | ||||
/** Returns the lowest and highest values in the set. | |||||
/** Returns the range between the lowest and highest values in the set. | |||||
@see getRange | @see getRange | ||||
*/ | */ | ||||
bool getTotalRange (Type& lowestValue, | |||||
Type& highestValue) const throw() | |||||
const Range<Type> getTotalRange() const | |||||
{ | { | ||||
if (values.size() > 0) | if (values.size() > 0) | ||||
{ | { | ||||
lowestValue = values.getUnchecked (0); | |||||
highestValue = values.getUnchecked (values.size() - 1); | |||||
return true; | |||||
jassert ((values.size() & 1) == 0); | |||||
return Range<Type> (values.getUnchecked (0), | |||||
values.getUnchecked (values.size() - 1)); | |||||
} | } | ||||
return false; | |||||
return Range<Type>(); | |||||
} | } | ||||
//============================================================================== | //============================================================================== | ||||
/** Adds a range of contiguous values to the set. | /** Adds a range of contiguous values to the set. | ||||
e.g. addRange (10, 4) will add (10, 11, 12, 13) to the set. | |||||
@param firstValue the start of the range of values to add | |||||
@param numValuesToAdd how many values to add | |||||
e.g. addRange (Range \<int\> (10, 14)) will add (10, 11, 12, 13) to the set. | |||||
*/ | */ | ||||
void addRange (const Type firstValue, | |||||
const Type numValuesToAdd) throw() | |||||
void addRange (const Range<Type>& range) | |||||
{ | { | ||||
jassert (numValuesToAdd >= 0); | |||||
if (numValuesToAdd > 0) | |||||
jassert (range.getLength() >= 0); | |||||
if (range.getLength() > 0) | |||||
{ | { | ||||
removeRange (firstValue, numValuesToAdd); | |||||
removeRange (range); | |||||
values.addUsingDefaultSort (firstValue); | |||||
values.addUsingDefaultSort (firstValue + numValuesToAdd); | |||||
values.addUsingDefaultSort (range.getStart()); | |||||
values.addUsingDefaultSort (range.getEnd()); | |||||
simplify(); | simplify(); | ||||
} | } | ||||
String s; | |||||
for (int i = 0; i < values.size(); ++i) | |||||
s << values[i] << " "; | |||||
DBG (s); | |||||
} | } | ||||
/** Removes a range of values from the set. | /** Removes a range of values from the set. | ||||
e.g. removeRange (10, 4) will remove (10, 11, 12, 13) from the set. | |||||
@param firstValue the start of the range of values to remove | |||||
@param numValuesToRemove how many values to remove | |||||
e.g. removeRange (Range\<int\> (10, 14)) will remove (10, 11, 12, 13) from the set. | |||||
*/ | */ | ||||
void removeRange (const Type firstValue, | |||||
const Type numValuesToRemove) throw() | |||||
void removeRange (const Range<Type>& rangeToRemove) | |||||
{ | { | ||||
jassert (numValuesToRemove >= 0); | |||||
jassert (rangeToRemove.getLength() >= 0); | |||||
if (numValuesToRemove >= 0 | |||||
&& firstValue < values.getLast()) | |||||
if (rangeToRemove.getLength() > 0 | |||||
&& values.size() > 0 | |||||
&& rangeToRemove.getStart() < values.getUnchecked (values.size() - 1) | |||||
&& values.getUnchecked(0) < rangeToRemove.getEnd()) | |||||
{ | { | ||||
const bool onAtStart = contains (firstValue - 1); | |||||
const Type lastValue = firstValue + jmin (numValuesToRemove, values.getLast() - firstValue); | |||||
const bool onAtStart = contains (rangeToRemove.getStart() - 1); | |||||
const Type lastValue (jmin (rangeToRemove.getEnd(), values.getLast())); | |||||
const bool onAtEnd = contains (lastValue); | const bool onAtEnd = contains (lastValue); | ||||
for (int i = values.size(); --i >= 0;) | for (int i = values.size(); --i >= 0;) | ||||
{ | { | ||||
if (values.getUnchecked(i) <= lastValue) | if (values.getUnchecked(i) <= lastValue) | ||||
{ | { | ||||
while (values.getUnchecked(i) >= firstValue) | |||||
while (values.getUnchecked(i) >= rangeToRemove.getStart()) | |||||
{ | { | ||||
values.remove (i); | values.remove (i); | ||||
@@ -241,57 +219,40 @@ public: | |||||
} | } | ||||
} | } | ||||
if (onAtStart) | |||||
values.addUsingDefaultSort (firstValue); | |||||
if (onAtEnd) | |||||
values.addUsingDefaultSort (lastValue); | |||||
if (onAtStart) values.addUsingDefaultSort (rangeToRemove.getStart()); | |||||
if (onAtEnd) values.addUsingDefaultSort (lastValue); | |||||
simplify(); | simplify(); | ||||
} | } | ||||
} | } | ||||
/** Does an XOR of the values in a given range. */ | /** Does an XOR of the values in a given range. */ | ||||
void invertRange (const Type firstValue, | |||||
const Type numValues) | |||||
void invertRange (const Range<Type>& range) | |||||
{ | { | ||||
SparseSet newItems; | SparseSet newItems; | ||||
newItems.addRange (firstValue, numValues); | |||||
newItems.addRange (range); | |||||
int i; | int i; | ||||
for (i = getNumRanges(); --i >= 0;) | for (i = getNumRanges(); --i >= 0;) | ||||
{ | |||||
const int start = values [i << 1]; | |||||
const int end = values [(i << 1) + 1]; | |||||
newItems.removeRange (getRange (i)); | |||||
newItems.removeRange (start, end); | |||||
} | |||||
removeRange (firstValue, numValues); | |||||
removeRange (range); | |||||
for (i = newItems.getNumRanges(); --i >= 0;) | for (i = newItems.getNumRanges(); --i >= 0;) | ||||
{ | |||||
const int start = newItems.values [i << 1]; | |||||
const int end = newItems.values [(i << 1) + 1]; | |||||
addRange (start, end); | |||||
} | |||||
addRange (newItems.getRange(i)); | |||||
} | } | ||||
/** Checks whether any part of a given range overlaps any part of this one. */ | |||||
bool overlapsRange (const Type firstValue, | |||||
const Type numValues) throw() | |||||
/** Checks whether any part of a given range overlaps any part of this set. */ | |||||
bool overlapsRange (const Range<Type>& range) | |||||
{ | { | ||||
jassert (numValues >= 0); | |||||
if (numValues > 0) | |||||
if (range.getLength() > 0) | |||||
{ | { | ||||
for (int i = getNumRanges(); --i >= 0;) | for (int i = getNumRanges(); --i >= 0;) | ||||
{ | { | ||||
if (firstValue >= values.getUnchecked ((i << 1) + 1)) | |||||
if (values.getUnchecked ((i << 1) + 1) <= range.getStart()) | |||||
return false; | return false; | ||||
if (firstValue + numValues > values.getUnchecked (i << 1)) | |||||
if (values.getUnchecked (i << 1) < range.getEnd()) | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
@@ -300,20 +261,17 @@ public: | |||||
} | } | ||||
/** Checks whether the whole of a given range is contained within this one. */ | /** Checks whether the whole of a given range is contained within this one. */ | ||||
bool containsRange (const Type firstValue, | |||||
const Type numValues) throw() | |||||
bool containsRange (const Range<Type>& range) | |||||
{ | { | ||||
jassert (numValues >= 0); | |||||
if (numValues > 0) | |||||
if (range.getLength() > 0) | |||||
{ | { | ||||
for (int i = getNumRanges(); --i >= 0;) | for (int i = getNumRanges(); --i >= 0;) | ||||
{ | { | ||||
if (firstValue >= values.getUnchecked ((i << 1) + 1)) | |||||
if (values.getUnchecked ((i << 1) + 1) <= range.getStart()) | |||||
return false; | return false; | ||||
if (firstValue >= values.getUnchecked (i << 1) | |||||
&& firstValue + numValues <= values.getUnchecked ((i << 1) + 1)) | |||||
if (values.getUnchecked (i << 1) <= range.getStart() | |||||
&& range.getEnd() <= values.getUnchecked ((i << 1) + 1)) | |||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
@@ -339,13 +297,13 @@ private: | |||||
// alternating start/end values of ranges of values that are present. | // alternating start/end values of ranges of values that are present. | ||||
Array<Type, DummyCriticalSection> values; | Array<Type, DummyCriticalSection> values; | ||||
void simplify() throw() | |||||
void simplify() | |||||
{ | { | ||||
jassert ((values.size() & 1) == 0); | jassert ((values.size() & 1) == 0); | ||||
for (int i = values.size(); --i > 0;) | for (int i = values.size(); --i > 0;) | ||||
if (values.getUnchecked(i) == values.getUnchecked (i - 1)) | if (values.getUnchecked(i) == values.getUnchecked (i - 1)) | ||||
values.removeRange (i - 1, 2); | |||||
values.removeRange (--i, 2); | |||||
} | } | ||||
}; | }; | ||||
@@ -128,7 +128,7 @@ public: | |||||
{ | { | ||||
if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | ||||
{ | { | ||||
const SparseSet <int> selectedRows (owner.getSelectedRows()); | |||||
const SparseSet<int> selectedRows (owner.getSelectedRows()); | |||||
if (selectedRows.size() > 0) | if (selectedRows.size() > 0) | ||||
{ | { | ||||
@@ -426,7 +426,7 @@ void ListBox::updateContent() | |||||
if (selected [selected.size() - 1] >= totalItems) | if (selected [selected.size() - 1] >= totalItems) | ||||
{ | { | ||||
selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems); | |||||
selected.removeRange (Range <int> (totalItems, std::numeric_limits<int>::max())); | |||||
lastRowSelected = getSelectedRow (0); | lastRowSelected = getSelectedRow (0); | ||||
selectionChanged = true; | selectionChanged = true; | ||||
} | } | ||||
@@ -462,7 +462,7 @@ void ListBox::selectRowInternal (const int row, | |||||
if (deselectOthersFirst) | if (deselectOthersFirst) | ||||
selected.clear(); | selected.clear(); | ||||
selected.addRange (row, 1); | |||||
selected.addRange (Range<int> (row, row + 1)); | |||||
if (getHeight() == 0 || getWidth() == 0) | if (getHeight() == 0 || getWidth() == 0) | ||||
dontScroll = true; | dontScroll = true; | ||||
@@ -511,7 +511,7 @@ void ListBox::deselectRow (const int row) | |||||
{ | { | ||||
if (selected.contains (row)) | if (selected.contains (row)) | ||||
{ | { | ||||
selected.removeRange (row, 1); | |||||
selected.removeRange (Range <int> (row, row + 1)); | |||||
if (row == lastRowSelected) | if (row == lastRowSelected) | ||||
lastRowSelected = getSelectedRow (0); | lastRowSelected = getSelectedRow (0); | ||||
@@ -525,7 +525,7 @@ void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected, | |||||
const bool sendNotificationEventToModel) | const bool sendNotificationEventToModel) | ||||
{ | { | ||||
selected = setOfRowsToBeSelected; | selected = setOfRowsToBeSelected; | ||||
selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems); | |||||
selected.removeRange (Range <int> (totalItems, std::numeric_limits<int>::max())); | |||||
if (! isRowSelected (lastRowSelected)) | if (! isRowSelected (lastRowSelected)) | ||||
lastRowSelected = getSelectedRow (0); | lastRowSelected = getSelectedRow (0); | ||||
@@ -549,10 +549,10 @@ void ListBox::selectRangeOfRows (int firstRow, int lastRow) | |||||
firstRow = jlimit (0, jmax (0, numRows), firstRow); | firstRow = jlimit (0, jmax (0, numRows), firstRow); | ||||
lastRow = jlimit (0, jmax (0, numRows), lastRow); | lastRow = jlimit (0, jmax (0, numRows), lastRow); | ||||
selected.addRange (jmin (firstRow, lastRow), | |||||
abs (firstRow - lastRow) + 1); | |||||
selected.addRange (Range <int> (jmin (firstRow, lastRow), | |||||
jmax (firstRow, lastRow) + 1)); | |||||
selected.removeRange (lastRow, 1); | |||||
selected.removeRange (Range <int> (lastRow, lastRow + 1)); | |||||
} | } | ||||
selectRowInternal (lastRow, false, false, true); | selectRowInternal (lastRow, false, false, true); | ||||
@@ -191,7 +191,7 @@ public: | |||||
{ | { | ||||
if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging)) | ||||
{ | { | ||||
const SparseSet <int> selectedRows (owner.getSelectedRows()); | |||||
const SparseSet<int> selectedRows (owner.getSelectedRows()); | |||||
if (selectedRows.size() > 0) | if (selectedRows.size() > 0) | ||||
{ | { | ||||
@@ -372,7 +372,7 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
if (hasAlphaChannel()) | if (hasAlphaChannel()) | ||||
{ | { | ||||
const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f)); | const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f)); | ||||
SparseSet <int> pixelsOnRow; | |||||
SparseSet<int> pixelsOnRow; | |||||
const BitmapData srcData (*this, 0, 0, getWidth(), getHeight()); | const BitmapData srcData (*this, 0, 0, getWidth(), getHeight()); | ||||
@@ -386,7 +386,7 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
for (int x = 0; x < imageWidth; ++x) | for (int x = 0; x < imageWidth; ++x) | ||||
{ | { | ||||
if (((const PixelARGB*) lineData)->getAlpha() >= threshold) | if (((const PixelARGB*) lineData)->getAlpha() >= threshold) | ||||
pixelsOnRow.addRange (x, 1); | |||||
pixelsOnRow.addRange (Range<int> (x, x + 1)); | |||||
lineData += srcData.pixelStride; | lineData += srcData.pixelStride; | ||||
} | } | ||||
@@ -396,7 +396,7 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
for (int x = 0; x < imageWidth; ++x) | for (int x = 0; x < imageWidth; ++x) | ||||
{ | { | ||||
if (*lineData >= threshold) | if (*lineData >= threshold) | ||||
pixelsOnRow.addRange (x, 1); | |||||
pixelsOnRow.addRange (Range<int> (x, x + 1)); | |||||
lineData += srcData.pixelStride; | lineData += srcData.pixelStride; | ||||
} | } | ||||
@@ -404,10 +404,8 @@ void Image::createSolidAreaMask (RectangleList& result, const float alphaThresho | |||||
for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i) | for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i) | ||||
{ | { | ||||
int x, w; | |||||
if (pixelsOnRow.getRange (i, x, w)) | |||||
result.add (Rectangle<int> (x, y, w, 1)); | |||||
const Range<int> range (pixelsOnRow.getRange (i)); | |||||
result.add (Rectangle<int> (range.getStart(), y, range.getLength(), 1)); | |||||
} | } | ||||
result.consolidate(); | result.consolidate(); | ||||
@@ -49,7 +49,7 @@ public: | |||||
activeImage (0), | activeImage (0), | ||||
loadingImage (0) | loadingImage (0) | ||||
{ | { | ||||
HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC); | |||||
HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph); | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
@@ -80,7 +80,7 @@ public: | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER); | |||||
hr = smartTee.CoCreateInstance (CLSID_SmartTee); | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
@@ -92,7 +92,7 @@ public: | |||||
return; | return; | ||||
ComSmartPtr <IBaseFilter> sampleGrabberBase; | ComSmartPtr <IBaseFilter> sampleGrabberBase; | ||||
hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER); | |||||
hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber); | |||||
if (FAILED (hr)) | if (FAILED (hr)) | ||||
return; | return; | ||||
@@ -131,7 +131,7 @@ public: | |||||
height = pVih->bmiHeader.biHeight; | height = pVih->bmiHeader.biHeight; | ||||
ComSmartPtr <IBaseFilter> nullFilter; | ComSmartPtr <IBaseFilter> nullFilter; | ||||
hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER); | |||||
hr = nullFilter.CoCreateInstance (CLSID_NullRenderer); | |||||
hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer")); | hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer")); | ||||
if (connectFilters (sampleGrabberBase, nullFilter) | if (connectFilters (sampleGrabberBase, nullFilter) | ||||
@@ -259,7 +259,7 @@ public: | |||||
firstRecordedTime = Time(); | firstRecordedTime = Time(); | ||||
recordNextFrameTime = true; | recordNextFrameTime = true; | ||||
HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER); | |||||
HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter); | |||||
if (SUCCEEDED (hr)) | if (SUCCEEDED (hr)) | ||||
{ | { | ||||
@@ -737,7 +737,7 @@ static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names, | |||||
ComSmartPtr <IBaseFilter> result; | ComSmartPtr <IBaseFilter> result; | ||||
ComSmartPtr <ICreateDevEnum> pDevEnum; | ComSmartPtr <ICreateDevEnum> pDevEnum; | ||||
HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC); | |||||
HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum); | |||||
if (SUCCEEDED (hr)) | if (SUCCEEDED (hr)) | ||||
{ | { | ||||
@@ -808,7 +808,7 @@ CameraDevice* CameraDevice::openDevice (int index, | |||||
int maxWidth, int maxHeight) | int maxWidth, int maxHeight) | ||||
{ | { | ||||
ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder; | ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder; | ||||
HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC); | |||||
HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2); | |||||
if (SUCCEEDED (hr)) | if (SUCCEEDED (hr)) | ||||
{ | { | ||||
@@ -502,7 +502,7 @@ const File File::getLinkedTarget() const | |||||
return result; | return result; | ||||
ComSmartPtr <IShellLink> shellLink; | ComSmartPtr <IShellLink> shellLink; | ||||
if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER))) | |||||
if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink))) | |||||
{ | { | ||||
ComSmartPtr <IPersistFile> persistFile; | ComSmartPtr <IPersistFile> persistFile; | ||||
if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile))) | if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile))) | ||||
@@ -187,48 +187,47 @@ | |||||
/** A simple COM smart pointer. | /** A simple COM smart pointer. | ||||
Avoids having to include ATL just to get one of these. | Avoids having to include ATL just to get one of these. | ||||
*/ | */ | ||||
template <class T> | |||||
template <class ComClass> | |||||
class ComSmartPtr | class ComSmartPtr | ||||
{ | { | ||||
public: | public: | ||||
ComSmartPtr() throw() : p (0) {} | |||||
ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); } | |||||
ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); } | |||||
~ComSmartPtr() { if (p != 0) p->Release(); } | |||||
ComSmartPtr() throw() : p (0) {} | |||||
ComSmartPtr (ComClass* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); } | |||||
ComSmartPtr (const ComSmartPtr<ComClass>& p_) : p (p_.p) { if (p != 0) p->AddRef(); } | |||||
~ComSmartPtr() { if (p != 0) p->Release(); } | |||||
operator T*() const throw() { return p; } | |||||
T& operator*() const throw() { return *p; } | |||||
T** operator&() throw() { return &p; } | |||||
T* operator->() const throw() { return p; } | |||||
operator ComClass*() const throw() { return p; } | |||||
ComClass& operator*() const throw() { return *p; } | |||||
ComClass** operator&() throw() { return &p; } | |||||
ComClass* operator->() const throw() { return p; } | |||||
T* operator= (T* const newP) | |||||
ComClass* operator= (ComClass* const newP) | |||||
{ | { | ||||
if (newP != 0) | |||||
newP->AddRef(); | |||||
if (p != 0) | |||||
p->Release(); | |||||
if (newP != 0) newP->AddRef(); | |||||
if (p != 0) p->Release(); | |||||
p = newP; | p = newP; | ||||
return newP; | return newP; | ||||
} | } | ||||
T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); } | |||||
ComClass* operator= (const ComSmartPtr<ComClass>& newP) { return operator= (newP.p); } | |||||
HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext) | |||||
HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext = CLSCTX_INPROC_SERVER) | |||||
{ | { | ||||
#ifndef __MINGW32__ | #ifndef __MINGW32__ | ||||
operator= (0); | operator= (0); | ||||
return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p); | |||||
return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof (ComClass), (void**) &p); | |||||
#else | #else | ||||
return S_FALSE; | return S_FALSE; | ||||
#endif | #endif | ||||
} | } | ||||
T* p; | |||||
private: | |||||
ComClass* p; | |||||
}; | }; | ||||
//============================================================================== | //============================================================================== | ||||
/** Handy base class for writing COM objects, providing ref-counting and a basic QueryInterface method. | |||||
*/ | |||||
template <class ComClass> | template <class ComClass> | ||||
class ComBaseClassHelper : public ComClass | class ComBaseClassHelper : public ComClass | ||||
{ | { | ||||
@@ -912,7 +912,7 @@ private: | |||||
bool createDevices() | bool createDevices() | ||||
{ | { | ||||
ComSmartPtr <IMMDeviceEnumerator> enumerator; | ComSmartPtr <IMMDeviceEnumerator> enumerator; | ||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER))) | |||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator)))) | |||||
return false; | return false; | ||||
ComSmartPtr <IMMDeviceCollection> deviceCollection; | ComSmartPtr <IMMDeviceCollection> deviceCollection; | ||||
@@ -976,7 +976,7 @@ public: | |||||
inputDeviceIds.clear(); | inputDeviceIds.clear(); | ||||
ComSmartPtr <IMMDeviceEnumerator> enumerator; | ComSmartPtr <IMMDeviceEnumerator> enumerator; | ||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER))) | |||||
if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator)))) | |||||
return; | return; | ||||
const String defaultRenderer = getDefaultEndpoint (enumerator, false); | const String defaultRenderer = getDefaultEndpoint (enumerator, false); | ||||
@@ -116,6 +116,12 @@ const String& StringArray::operator[] (const int index) const throw() | |||||
return String::empty; | return String::empty; | ||||
} | } | ||||
String& StringArray::getReference (const int index) throw() | |||||
{ | |||||
jassert (((unsigned int) index) < (unsigned int) strings.size()); | |||||
return strings.getReference (index); | |||||
} | |||||
void StringArray::add (const String& newString) | void StringArray::add (const String& newString) | ||||
{ | { | ||||
strings.add (newString); | strings.add (newString); | ||||
@@ -108,6 +108,12 @@ public: | |||||
*/ | */ | ||||
const String& operator[] (int index) const throw(); | const String& operator[] (int index) const throw(); | ||||
/** Returns a reference to one of the strings in the array. | |||||
This lets you modify a string in-place in the array, but you must be sure that | |||||
the index is in-range. | |||||
*/ | |||||
String& getReference (int index) throw(); | |||||
/** Searches for a string in the array. | /** Searches for a string in the array. | ||||
The comparison will be case-insensitive if the ignoreCase parameter is true. | The comparison will be case-insensitive if the ignoreCase parameter is true. | ||||