Browse Source

Improved always-on-top window detection. Cleaned up some old obj-C code.

tags/2021-05-28
jules 12 years ago
parent
commit
d0629ab14e
4 changed files with 37 additions and 83 deletions
  1. +18
    -54
      modules/juce_audio_devices/native/juce_mac_AudioCDBurner.mm
  2. +3
    -2
      modules/juce_events/native/juce_mac_MessageManager.mm
  3. +4
    -11
      modules/juce_graphics/native/juce_mac_Fonts.mm
  4. +12
    -16
      modules/juce_gui_basics/native/juce_mac_Windowing.mm

+ 18
- 54
modules/juce_audio_devices/native/juce_mac_AudioCDBurner.mm View File

@@ -48,8 +48,8 @@ struct AudioTrackProducerClass : public ObjCClass <NSObject>
struct AudioSourceHolder
{
AudioSourceHolder (AudioSource* source_, int numFrames)
: source (source_), readPosition (0), lengthInFrames (numFrames)
AudioSourceHolder (AudioSource* s, int numFrames)
: source (s), readPosition (0), lengthInFrames (numFrames)
{
}
@@ -125,15 +125,9 @@ private:
source->source->getNextAudioBlock (info);
typedef AudioData::Pointer <AudioData::Int16,
AudioData::LittleEndian,
AudioData::Interleaved,
AudioData::NonConst> CDSampleFormat;
typedef AudioData::Pointer <AudioData::Int16, AudioData::LittleEndian, AudioData::Interleaved, AudioData::NonConst> CDSampleFormat;
typedef AudioData::Pointer <AudioData::Float32, AudioData::NativeEndian, AudioData::NonInterleaved, AudioData::Const> SourceSampleFormat;
typedef AudioData::Pointer <AudioData::Float32,
AudioData::NativeEndian,
AudioData::NonInterleaved,
AudioData::Const> SourceSampleFormat;
CDSampleFormat left (buffer, 2);
left.convertSamples (SourceSampleFormat (tempBuffer.getSampleData (0)), numSamples);
CDSampleFormat right (buffer + 2, 2);
@@ -166,8 +160,8 @@ private:
struct OpenDiskDevice
{
OpenDiskDevice (DRDevice* device_)
: device (device_),
OpenDiskDevice (DRDevice* d)
: device (d),
tracks ([[NSMutableArray alloc] init]),
underrunProtection (true)
{
@@ -254,9 +248,8 @@ struct OpenDiskDevice
NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
objectForKey: DRErrorStatusErrorStringKey];
if ([err length] > 0)
return CharPointer_UTF8 ([err UTF8String]);
return nsStringToJuce (err);
}
[device releaseMediaReservation];
@@ -273,12 +266,9 @@ struct OpenDiskDevice
class AudioCDBurner::Pimpl : public Timer
{
public:
Pimpl (AudioCDBurner& owner_, const int deviceIndex)
: device (0), owner (owner_)
Pimpl (AudioCDBurner& b, int deviceIndex) : owner (b)
{
DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
if (dev != nil)
if (DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex])
{
device = new OpenDiskDevice (dev);
lastState = getDiskState();
@@ -307,7 +297,6 @@ public:
if ([device->device isValid])
{
NSDictionary* status = [device->device status];
NSString* state = [status objectForKey: DRDeviceMediaStateKey];
if ([state isEqualTo: DRDeviceMediaStateNone])
@@ -322,8 +311,8 @@ public:
{
if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
return writableDiskPresent;
else
return readOnlyDiskPresent;
return readOnlyDiskPresent;
}
}
@@ -337,14 +326,8 @@ public:
Array<int> results;
if ([device->device isValid])
{
NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
for (unsigned int i = 0; i < [speeds count]; ++i)
{
const int kbPerSec = [[speeds objectAtIndex: i] intValue];
results.add (kbPerSec / kilobytesPerSecond1x);
}
}
for (id kbPerSec in [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey])
results.add ([kbPerSec intValue] / kilobytesPerSecond1x);
return results;
}
@@ -385,40 +368,21 @@ AudioCDBurner::~AudioCDBurner()
AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
{
ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
if (b->pimpl->device == nil)
b = 0;
b = nullptr;
return b.release();
}
namespace
{
NSArray* findDiskBurnerDevices()
{
NSMutableArray* results = [NSMutableArray array];
NSArray* devs = [DRDevice devices];
for (int i = 0; i < [devs count]; ++i)
{
NSDictionary* dic = [[devs objectAtIndex: i] info];
NSString* name = [dic valueForKey: DRDeviceProductNameKey];
if (name != nil)
[results addObject: name];
}
return results;
}
}
StringArray AudioCDBurner::findAvailableDevices()
{
NSArray* names = findDiskBurnerDevices();
StringArray s;
for (unsigned int i = 0; i < [names count]; ++i)
s.add (CharPointer_UTF8 ([[names objectAtIndex: i] UTF8String]));
for (NSDictionary* dic in [DRDevice devices])
if (NSString* name = [dic valueForKey: DRDeviceProductNameKey])
s.add (nsStringToJuce (name));
return s;
}


+ 3
- 2
modules/juce_events/native/juce_mac_MessageManager.mm View File

@@ -150,8 +150,9 @@ private:
if (JUCEApplicationBase* const app = JUCEApplicationBase::getInstance())
{
StringArray files;
for (unsigned int i = 0; i < [filenames count]; ++i)
files.add (quotedIfContainsSpaces ((NSString*) [filenames objectAtIndex: i]));
for (NSString* f in filenames)
files.add (quotedIfContainsSpaces (f));
if (files.size() > 0)
app->anotherInstanceStarted (files.joinIntoString (" "));


+ 4
- 11
modules/juce_graphics/native/juce_mac_Fonts.mm View File

@@ -1114,13 +1114,11 @@ StringArray Font::findAllTypefaceNames()
JUCE_AUTORELEASEPOOL
{
#if JUCE_IOS
NSArray* fonts = [UIFont familyNames];
for (NSString* name in [UIFont familyNames])
#else
NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
for (NSString* name in [[NSFontManager sharedFontManager] availableFontFamilies])
#endif
for (unsigned int i = 0; i < [fonts count]; ++i)
names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
names.add (nsStringToJuce (name));
names.sort (true);
}
@@ -1137,13 +1135,8 @@ StringArray Font::findAllTypefaceStyles (const String& family)
JUCE_AUTORELEASEPOOL
{
NSArray* styles = [[NSFontManager sharedFontManager] availableMembersOfFontFamily: juceStringToNS (family)];
for (unsigned int i = 0; i < [styles count]; ++i)
{
NSArray* style = [styles objectAtIndex: i];
for (NSArray* style in [[NSFontManager sharedFontManager] availableMembersOfFontFamily: juceStringToNS (family)])
results.add (nsStringToJuce ((NSString*) [style objectAtIndex: 1]));
}
}
return results;


+ 12
- 16
modules/juce_gui_basics/native/juce_mac_Windowing.mm View File

@@ -360,17 +360,21 @@ void Desktop::Displays::findDisplays (const float masterScale)
{
DisplaySettingsChangeCallback::getInstance();
NSArray* screens = [NSScreen screens];
const CGFloat mainScreenBottom = [[screens objectAtIndex: 0] frame].size.height;
CGFloat mainScreenBottom = 0;
for (unsigned int i = 0; i < [screens count]; ++i)
for (NSScreen* s in [NSScreen screens])
{
NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
Display d;
d.isMain = false;
if (mainScreenBottom == 0)
{
mainScreenBottom = [s frame].size.height;
d.isMain = true;
}
d.userArea = convertDisplayRect ([s visibleFrame], mainScreenBottom) / masterScale;
d.totalArea = convertDisplayRect ([s frame], mainScreenBottom) / masterScale;
d.isMain = (i == 0);
d.scale = masterScale;
#if defined (MAC_OS_X_VERSION_10_7) && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7)
@@ -389,17 +393,9 @@ void Desktop::Displays::findDisplays (const float masterScale)
//==============================================================================
bool juce_areThereAnyAlwaysOnTopWindows()
{
NSArray* windows = [NSApp windows];
for (unsigned int i = 0; i < [windows count]; ++i)
{
const NSInteger level = [((NSWindow*) [windows objectAtIndex: i]) level];
if (level == NSFloatingWindowLevel
|| level == NSStatusWindowLevel
|| level == NSModalPanelWindowLevel)
for (NSWindow* window in [NSApp windows])
if ([window level] > NSNormalWindowLevel)
return true;
}
return false;
}


Loading…
Cancel
Save