Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread Dave DeLong
This is a truly strange question. If you interpret a singleton to be "one and 
only one", then it doesnt make much sense to ask about subclassing it, because 
that would imply that you could instantiate one of the base type and one of the 
sub type, thus making it not fit the definition of a singleton. 

However, if we put philosophical discussions aside and simply ask for a maximum 
of one instance per class, then I'd probably do something like this: instead of 
using a single static variable to hold your singleton, use a mutable dictionary 
instead. The keys of the dictionary would be the name of the class, and the 
corresponding values would be e singleton objects. Override +allocWithZone: to 
either return the appropriate and existing object, or capture the call to super 
and save it in the dictionary before returning it. Of course, this would 
preclude any of the subclasses doing [self release] and returning a new object, 
but that's probably an adequate compromise.

Dave

Sent from my iPad

On Apr 16, 2011, at 10:20 PM, WT  wrote:

> how would you implement a *true* singleton class that supports subclassing?
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread Thomas Davie

On 16 Apr 2011, at 13:44, eveningnick eveningnick wrote:

> Basically i need this, to make my application look as similar as
> possible to my Windows version.

A truely terrible idea!

Why on earth do you think Mac users use Macs?  Don't you think if they wanted 
everything to look and behave like windows they would just use windows?

Bob

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: renaming directories and moving files into them (NSFileManager)

2011-04-16 Thread Andy Lee
I tried to reproduce your problem by creating directories ~/wtf/FromHere and 
~/wtf/ToHere, with three files in FromHere named 1, 2, and 3. I switch over to 
using "ToHere-NEW" when it detects a file whose name is >= "2".

My test code renamed the directory and switched over to it just fine:

- (void)test
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fromDir = [@"~/wtf/FromHere" stringByStandardizingPath];
NSString *originalToDir = [@"~/wtf/ToHere" stringByStandardizingPath];
NSString *toDir = originalToDir;
NSError *error = nil;
NSArray *filesToCopy = [[fileManager contentsOfDirectoryAtPath:fromDir 
error:&error]

sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

for (NSString *fileName in filesToCopy)
{
// Rename the destination directory if necessary.
if ([fileName intValue] >= 2)
{
NSLog(@"File name is %@; will rename directory if necessary.", 
fileName);

NSString *newToDir = [originalToDir 
stringByAppendingString:@"-NEW"];

if (![fileManager fileExistsAtPath:newToDir])
{
if ([fileManager moveItemAtPath:toDir toPath:newToDir 
error:&error])
{
NSLog(@"...SUCCESS: Renamed %@ to %@.", toDir, newToDir);
}
else
{
NSLog(@"...ERROR: Failed to rename %@ to %@ -- %@.", toDir, 
newToDir, error);
abort();
}

toDir = newToDir;
}
else
{
NSLog(@"...%@ already exists; no need to rename.", newToDir);
}
}

// Move the file to the directory at shootPath.
NSString *oldFilePath = [fromDir 
stringByAppendingPathComponent:fileName];
NSString *newFilePath = [toDir stringByAppendingPathComponent:fileName];

if ([fileManager copyItemAtPath:oldFilePath toPath:newFilePath 
error:&error])
{
NSLog(@"Copied file %@ to %@.", oldFilePath, newFilePath);
}
else
{
NSLog(@"...ERROR: Failed to copy %@ to %@ -- %@.", oldFilePath, 
newFilePath, error);
abort();
}
}
}

2011-04-17 01:46:41.013 Scratcho[2630:a0f] Copied file 
/Users/alee/wtf/FromHere/1 to /Users/alee/wtf/ToHere/1.
2011-04-17 01:46:41.014 Scratcho[2630:a0f] File name is 2; will rename 
directory if necessary.
2011-04-17 01:46:41.069 Scratcho[2630:a0f] ...SUCCESS: Renamed 
/Users/alee/wtf/ToHere to /Users/alee/wtf/ToHere-NEW.
2011-04-17 01:46:44.712 Scratcho[2630:a0f] Copied file 
/Users/alee/wtf/FromHere/2 to /Users/alee/wtf/ToHere-NEW/2.
2011-04-17 01:46:44.712 Scratcho[2630:a0f] File name is 3; will rename 
directory if necessary.
2011-04-17 01:46:44.713 Scratcho[2630:a0f] .../Users/alee/wtf/ToHere-NEW 
already exists; no need to rename.
2011-04-17 01:46:46.934 Scratcho[2630:a0f] Copied file 
/Users/alee/wtf/FromHere/3 to /Users/alee/wtf/ToHere-NEW/3.

--Andy

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread Ken Thomases
On Apr 17, 2011, at 12:20 AM, WT wrote:

> On Apr 17, 2011, at 12:31 AM, Kyle Sluder wrote:
> 
>>>   self class] alloc] init] autorelease];
>> 
>> You are in a class method. self == [self class], so no need to call +class 
>> here.
> 
> What if I'm trying to subclass this singleton?

What about it?  'self' identifies the actual, dynamic object receiving the 
message -- in this case, a class.  It is not of the static type of the 
@implementation block it occurs within.  Put another way, [self class] is no 
more dynamic than [self alloc].


>>> + (id) allocWithZone: (NSZone*) zone;
>>> {
>>>   dispatch_once(&stAllocWithZoneInvoked,
>>>   ^{
>>>   NSLog(@"+allocWithZone: block entered");
>>> 
>>>   stSharedInstance = [super allocWithZone: zone];
>>> 
>>>   NSLog(@"+allocWithZone: block exited");
>>>   });
>>> 
>>>   return stSharedInstance;
>> 
>> Of course this means you can't subclass this class.
> 
> Why not? As long as the subclass doesn't override +allocWithZone:, this 
> shouldn't be a problem, no?

How many stSharedInstance variables are there?  How many stAllocWithZoneInvoked 
dispatch_once predicates are there?


> About these two, once again it all came from Apple's implementation in one of 
> the docs. I read it, it made sense to me at the time, so I used it often. 
> Now, I wanted to replace the use of @synchronized but didn't think of 
> changing anything I didn't absolutely have to change.

Apple's guide for creating singletons has, historically, been much criticized 
and then subsequently much revised.  If you based your implementation on that, 
you might consider the criticisms as well as the revisions.  One critique, as 
an example: http://boredzo.org/blog/archives/2009-06-17/doing-it-wrong

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: renaming directories and moving files into them (NSFileManager)

2011-04-16 Thread Andy Lee
On Apr 15, 2011, at 1:47 AM, Scott Anguish wrote:
> if (foundRange.location > 0) { // should be comparing to 
> NSNotFound, but that failed miserably.
> newShootPath=[shootPath stringByAppendingString:@“-APPL”];
> // make sure I’ve not already done this
> if (![self directoryExists:newShootPath]) {
> 
> success=[fileManager moveItemAtPath:shootPath 
> toPath:newShootPath error:&theError];
> NSLog(@"should be moving - %d",success);
> //success is true!
> 
> // make the newShootPath, the shootPath for other files
> [shootPath autorelease];
> shootPath=[newShootPath retain];

This looks odd to me. Isn't shootPath going to become /tmp/boo/Friday-APPL, 
then /tmp/boo/Friday-APPL-APPL, etc.?

--Andy

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread WT
Hi Kyle, thanks for replying.

On Apr 17, 2011, at 12:31 AM, Kyle Sluder wrote:

> Do you really need a singleton, or just a default instance?

A singleton.


>> static MySingleton* stSharedInstance = nil;
>> 
>> static dispatch_once_t  stSharedInstanceInvoked;
>> static dispatch_once_t  stAllocWithZoneInvoked;
>> static dispatch_once_t  stInitInvoked;
> 
> All of these could be made static variables within the method body,
> increasing readability and reducing pollution of the global scope
> without affecting storage longevity.

It's the coding style I'm used to, listing the statically allocated variables 
at the top. I don't see how declaring them inside the methods that use them 
helps to reduce pollution of the global scope, since they have to be visible to 
different methods in the same compilation unit anyway.


>> + (MySingleton*) sharedInstance;
>> {
>>dispatch_once(&stSharedInstanceInvoked,
>>^{
>>NSLog(@"+sharedInstance block entered");
>> 
>>// Assignment done in +allocWithZone:.
>>// The autorelease message is sent to prevent XCode's
>>// static analyzer from issuing a warning about a possible
>>// memory leak. There is no leak, since the singleton is
>>// not meant to be deallocated, and the autorelease message
>>// does nothing, as per its overridden implementation below.
> 
> Rather than relying on -allocWithZone: to return the shared instance,
> why not assign to stSharedInstance here?

No reason other than that this implementation is based on the singleton 
implementation I saw in some Apple documentation.


>>self class] alloc] init] autorelease];
> 
> You are in a class method. self == [self class], so no need to call +class 
> here.

What if I'm trying to subclass this singleton?


>> + (id) allocWithZone: (NSZone*) zone;
>> {
>>dispatch_once(&stAllocWithZoneInvoked,
>>^{
>>NSLog(@"+allocWithZone: block entered");
>> 
>>stSharedInstance = [super allocWithZone: zone];
>> 
>>NSLog(@"+allocWithZone: block exited");
>>});
>> 
>>return stSharedInstance;
> 
> Of course this means you can't subclass this class.

Why not? As long as the subclass doesn't override +allocWithZone:, this 
shouldn't be a problem, no?


>> - (id) init;
>> {
>>__block id tempSelf = self;
> 
> Because the block is not going to be copied, you do not need to worry
> about creating a __block version of self here. And since this is a
> singleton, even if the block *were* copied (and thus self retained),
> you still wouldn't care.
> 
>> 
>>dispatch_once(&stInitInvoked,
>>^{
>>NSLog(@"-init block entered");
>> 
>>tempSelf = [super init];
>> 
>>if (tempSelf)
>>{
>>someInteger_ = random() % 1000;
>>NSLog(@"Instance initialized");
>>}
>> 
>>NSLog(@"-init block exited");
>>});
>> 
>>self = tempSelf;
>>return self;
>> }

My first attempt was simply 

>> - (id) init;
>> {
>>dispatch_once(&stInitInvoked,
>>^{
>>NSLog(@"-init block entered");
>> 
>>self = [super init];
>> 
>>if (self)
>>{
>>someInteger_ = random() % 1000;
>>NSLog(@"Instance initialized");
>>}
>> 
>>NSLog(@"-init block exited");
>>});
>> 
>>return self;
>> }

but the compiler complained that self is read-only within the scope of the 
block. I needed a way to write to self and I couldn't redeclare self, hence a 
writable tempSelf.


>> - (id) copyWithZone: (NSZone*) zone;
>> {
>>return self;
> 
> By virtue of this implementation, you can't implement NSCopying in a
> subclass. But you can't subclass this class anyway because of
> +allocWithZone:.
> 
>> }

I can see why that might cause some problems but, then, semantically, a 
singleton shouldn't be something that you can duplicate anyway.


>> - (unsigned) retainCount;
>> {
>>return UINT_MAX; // Denotes an object that cannot be released.
> 
> Why bother? All this will do is mask any bugs where your singleton disappears.
> 
>> }
>> 
>> 
>> - (void) release;
>> {
>>/* do nothing */
> 
> Don't do this. As above, you're just masking cases where you
> accidentally over-release your singleton.
> 
>> }

About these two, once again it all came from Apple's implementation in one of 
the docs. I read it, it made sense to me at the time, so I used it often. Now, 
I wanted to replace the use of @synchronized but didn't think of changing 
anything I didn't absolutely have to change.


>> - (id) autorelease;
>> {
>>return self;
>> }
> 
> Look, you're going to great lengths to ensure you never create more
> than one instance of this class. Is any of it really necessary?

Well, it is if I need a true singleton and sometimes I do. In fact, I kinda 
often do. I tend to break down my code into classes with very well defined, and 
typically few, responsibilities. Often times, making them singletons simplifies 
my code.

For

Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread WT
Hi Dave, thanks for replying.

On Apr 17, 2011, at 12:18 AM, Dave DeLong wrote:

> There are a whole bunch of ways to make singletons.  Some are much more work 
> than others...  

The amount of work is of little concern for me in this case because the 
singleton class will become a template like its @synchronized version already 
is, so I only have to do the work once.

> //if we overrode -init, then you could run into issues if you ever tried to 
> alloc/init a MySingleton multiple times

True.

> It's a lot shorter, because you don't have to worry about overriding all of 
> the  memory management methods.  As long as you correctly retain 
> and release this object, it will never cease to exist.

The only reason why I have that particular implementation is that I've seen it 
done that way (but with @synchronized rather than dispatch_once()) in Apple's 
docs. Where exactly escapes me right now.

Thanks again.
WT

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread Ken Thomases
On Apr 16, 2011, at 4:57 PM, eveningnick eveningnick wrote:

> Could you give me a hint how did QuickTime Player developers manage to
> display a window the way it looks now? Specifically i can't
> understand, how they made the "Movie control" toolbar, that floats
> only within the "movie window"?

At a guess, they are using Core Animation layers.  They are probably manually 
repositioning the movie control's layer (or layer-backed view) manually in 
response to the mouse-dragging events, just as you would to reposition the 
window.


> Reading through NSOpenGLView documentation, i found the note that this
> view can't contain subviews. Though i am pretty sure the "movie view"
> is NSOpenGLView (am i wrong here?). Do they display an another
> "control" window somehow in an "always on top of the NSOpenGLView"
> manner?

Core Animation layers can contain OpenGL rendering while still permitting other 
layers on top.  For example, see the LayerBackedOpenGLView sample code:
http://developer.apple.com/library/mac/#samplecode/LayerBackedOpenGLView/

Alternatively, you can use a non-NSOpenGLView-derived view, backed by a 
CAOpenGLLayer (or hosting a layer hierarchy that includes one).  See the 
CALayerEssentials sample code:
http://developer.apple.com/library/mac/#samplecode/CALayerEssentials/


> I am wondering, why is NSOpenGLView considered to be the preferred way
> to display a set of images? Why is every image operation revolving
> around OpenGL? I understand that eventually it all comes through the
> videoadapter, but what if i just display an RGB picture that i have in
> an RGB buffer (CVImageBufferRef). Will OpenGL give me some benefits
> just for rendering it on the view against drawing image onto something
> like "NSImageView"?

This is outside my area of expertise, but I'm not sure it's entirely true that 
OpenGL is _the_ preferred way to display sequences of images.  I imagine that 
QTKit can do the same sort of thing quite handily. ;)  And, of course, for 
simple animations, regular old Cocoa image drawing may suffice.  (That doesn't 
necessarily imply the use of NSImageView.  You can draw an NSImage from within 
the -drawRect: of any custom NSView class, for example.)

The advantage of OpenGL is presumably performance gained from asynchrony -- 
being able to prepare a next frame for display while the GPU is working on 
displaying the current frame.

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread Kyle Sluder
Blah, typos.

On Sat, Apr 16, 2011 at 8:31 PM, Kyle Sluder  wrote:
>  dispatch_once(&once, ^{ sharedInstance = [[self alloc] init]; });

Should be [[[self alloc] init] autorelease].

> Rather than relying on -allocWithZone: to return the shared instance,

Of course it's +allocWithZone:.

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread Kyle Sluder
On Sat, Apr 16, 2011 at 8:04 PM, WT  wrote:
> From the testing I've done - creating several threads, each invoking either 
> [MySingleton sharedInstance] or [[MySingleton alloc] init] after a randomly 
> selected sleep time, and running the test anew several times - it appears to 
> behave correctly, that is, the same instance is used in every thread, it's 
> always properly initialized (all "instances" have the same value for 
> someInteger), and each of the three dispatch_once() blocks is executed 
> exactly once, no matter how many threads were created.

Do you really need a singleton, or just a default instance? For
example, NSFileManager has a default instance, but you can still
alloc/init your own if you want.

If all you need is a shared instance, then this will work just dandy
for any class:

+ (id)sharedInstance {
  static id sharedInstance;
  static dispatch_once_t once;
  dispatch_once(&once, ^{ sharedInstance = [[self alloc] init]; });
  return sharedInstance;
}

As for your code:

> // MySingleton.h:
>
> #import 
>
> @interface MySingleton: NSObject
> {
>    NSUInteger someInteger_;
> }
>
> @property (readwrite, nonatomic, assign) NSUInteger someInteger;
>
> + (MySingleton*) sharedInstance;
>
> @end
>
> // MySingleton.m:
>
> #import 
> #import "MySingleton.h"
> #import 
> #import 
>

> static MySingleton*     stSharedInstance = nil;
>
> static dispatch_once_t  stSharedInstanceInvoked;
> static dispatch_once_t  stAllocWithZoneInvoked;
> static dispatch_once_t  stInitInvoked;

All of these could be made static variables within the method body,
increasing readability and reducing pollution of the global scope
without affecting storage longevity.

>
> @implementation MySingleton
>
> @synthesize someInteger = someInteger_;
>
>
> + (MySingleton*) sharedInstance;
> {
>    dispatch_once(&stSharedInstanceInvoked,
>    ^{
>        NSLog(@"+sharedInstance block entered");
>
>        // Assignment done in +allocWithZone:.
>        // The autorelease message is sent to prevent XCode's
>        // static analyzer from issuing a warning about a possible
>        // memory leak. There is no leak, since the singleton is
>        // not meant to be deallocated, and the autorelease message
>        // does nothing, as per its overridden implementation below.

Rather than relying on -allocWithZone: to return the shared instance,
why not assign to stSharedInstance here?

>
>        self class] alloc] init] autorelease];

You are in a class method. self == [self class], so no need to call +class here.

>
>        NSLog(@"+sharedInstance block exited");
>    });
>
>    return stSharedInstance;
> }
>
>
> + (id) allocWithZone: (NSZone*) zone;
> {
>    dispatch_once(&stAllocWithZoneInvoked,
>    ^{
>        NSLog(@"+allocWithZone: block entered");
>
>        stSharedInstance = [super allocWithZone: zone];
>
>        NSLog(@"+allocWithZone: block exited");
>    });
>
>    return stSharedInstance;

Of course this means you can't subclass this class.

> }
>
>
> - (id) init;
> {
>    __block id tempSelf = self;

Because the block is not going to be copied, you do not need to worry
about creating a __block version of self here. And since this is a
singleton, even if the block *were* copied (and thus self retained),
you still wouldn't care.

>
>    dispatch_once(&stInitInvoked,
>    ^{
>        NSLog(@"-init block entered");
>
>        tempSelf = [super init];
>
>        if (tempSelf)
>        {
>            someInteger_ = random() % 1000;
>            NSLog(@"Instance initialized");
>        }
>
>        NSLog(@"-init block exited");
>    });
>
>    self = tempSelf;
>    return self;
> }
>
>
> - (id) copyWithZone: (NSZone*) zone;
> {
>    return self;

By virtue of this implementation, you can't implement NSCopying in a
subclass. But you can't subclass this class anyway because of
+allocWithZone:.

> }
>
>
> - (id) retain;
> {
>    return self;
> }
>
>
> - (unsigned) retainCount;
> {
>    return UINT_MAX; // Denotes an object that cannot be released.

Why bother? All this will do is mask any bugs where your singleton disappears.

> }
>
>
> - (void) release;
> {
>    /* do nothing */

Don't do this. As above, you're just masking cases where you
accidentally over-release your singleton.

> }
>
>
> - (id) autorelease;
> {
>    return self;
> }

Look, you're going to great lengths to ensure you never create more
than one instance of this class. Is any of it really necessary?

--Kyle Sluder
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Proper way to create a singleton without @synchronized ?

2011-04-16 Thread Dave DeLong
There are a whole bunch of ways to make singletons.  Some are much more work 
than others...  Here's how I would modify your code:

// MySingleton.h:

#import 

@interface MySingleton: NSObject {
NSUInteger someInteger_;
}

@property (nonatomic) NSUInteger someInteger;

+ (MySingleton*) sharedInstance;

@end

// MySingleton.m:

#import 
#import "MySingleton.h"

static MySingleton *stSharedInstance = nil;

@implementation MySingleton

@synthesize someInteger = someInteger_;

+ (MySingleton*) sharedInstance;
{
dispatch_once(&stSharedInstanceInvoked, ^{
//use [super alloc] because [self alloc] would try to return the 
singleton
//use _privateInit so we don't have to override -init
//by assigning into the static variable here, we don't have to worry 
about the analyzer reporting a leak
stSharedInstance = [[super alloc] _privateInit];
});
return stSharedInstance;
}


+ (id) allocWithZone: (NSZone*) zone {
//return the shared instance, but retained, since +alloc calls return owned 
objects
return [stSharedInstance retain];
}

- (id)_privateInit {
//this is the actual initializer. as long as you don't invoke this 
externally, you're good
self = [super init];
if (self) {
someInteger_ = random() % 1000;
}
return self;
}

//if we overrode -init, then you could run into issues if you ever tried to 
alloc/init a MySingleton multiple times

@end

It's a lot shorter, because you don't have to worry about overriding all of the 
 memory management methods.  As long as you correctly retain and 
release this object, it will never cease to exist.

Cheers,

Dave
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Proper way to create a singleton without @synchronized ?

2011-04-16 Thread WT
After David Duncan explained dispatch_once() more clearly than the available 
documentation, I thought I'd give it a second look. Among other things, I 
wanted to replace my usage of @synchronized singletons, and dispatch_once() 
seemed the perfect mechanism for that.

So, I put together the class at the end of this message.

>From the testing I've done - creating several threads, each invoking either 
>[MySingleton sharedInstance] or [[MySingleton alloc] init] after a randomly 
>selected sleep time, and running the test anew several times - it appears to 
>behave correctly, that is, the same instance is used in every thread, it's 
>always properly initialized (all "instances" have the same value for 
>someInteger), and each of the three dispatch_once() blocks is executed exactly 
>once, no matter how many threads were created.

My question for you all is then whether this is indeed correct, or whether I'm 
missing something that my testing may not have revealed.

Thanks in advance.
WT

===

// MySingleton.h:

#import 

@interface MySingleton: NSObject
{
NSUInteger someInteger_;
}

@property (readwrite, nonatomic, assign) NSUInteger someInteger;

+ (MySingleton*) sharedInstance;

@end

// MySingleton.m:

#import 
#import "MySingleton.h"
#import 
#import 

static MySingleton* stSharedInstance = nil;

static dispatch_once_t  stSharedInstanceInvoked;
static dispatch_once_t  stAllocWithZoneInvoked;
static dispatch_once_t  stInitInvoked;

@implementation MySingleton

@synthesize someInteger = someInteger_;


+ (MySingleton*) sharedInstance;
{
dispatch_once(&stSharedInstanceInvoked,
^{
NSLog(@"+sharedInstance block entered");

// Assignment done in +allocWithZone:.
// The autorelease message is sent to prevent XCode's
// static analyzer from issuing a warning about a possible
// memory leak. There is no leak, since the singleton is
// not meant to be deallocated, and the autorelease message
// does nothing, as per its overridden implementation below.

self class] alloc] init] autorelease];

NSLog(@"+sharedInstance block exited");
});

return stSharedInstance;
}


+ (id) allocWithZone: (NSZone*) zone;
{
dispatch_once(&stAllocWithZoneInvoked,
^{
NSLog(@"+allocWithZone: block entered");

stSharedInstance = [super allocWithZone: zone];

NSLog(@"+allocWithZone: block exited");
});

return stSharedInstance;
}


- (id) init;
{
__block id tempSelf = self;

dispatch_once(&stInitInvoked,
^{
NSLog(@"-init block entered");

tempSelf = [super init];

if (tempSelf)
{
someInteger_ = random() % 1000;
NSLog(@"Instance initialized");
}

NSLog(@"-init block exited");
});

self = tempSelf;
return self;
}


- (id) copyWithZone: (NSZone*) zone;
{
return self;
}


- (id) retain;
{
return self;
}


- (unsigned) retainCount;
{
return UINT_MAX; // Denotes an object that cannot be released.
}


- (void) release;
{
/* do nothing */
}


- (id) autorelease;
{
return self;
}


@end

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread Graham Cox

On 16/04/2011, at 10:44 PM, eveningnick eveningnick wrote:

> Basically i need this, to make my application look as similar as
> possible to my Windows version.


Windows users use Windows. Mac users use Mac. And rarely the twain shall meet.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Global Shortcuts

2011-04-16 Thread Dave DeLong

On Apr 16, 2011, at 2:57 PM, Bavarious wrote:

> On 16 Apr 2011, at 13:02, Eric Schlegel wrote:
>> On Apr 16, 2011, at 2:59 AM, Florian Pilz wrote:
>> 
>>> However the Carbon API for global shortcuts (RegisterEventHotKey) is
>>> marked as 'Legacy'. I am not sure if thats the same as 'deprecated' in
>>> Apple terms
>> 
>> It's not.
>> 
>>> So my question is: Is the Carbon API still the way to go?
>> 
>> It is.
> 
> You may want to check Dave DeLong’s Cocoa wrapper for RegisterEventHotKey(), 
> including block callbacks:
> 
> https://github.com/davedelong/DDHotKey

+1  :)___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Global Shortcuts

2011-04-16 Thread Bavarious
On 16 Apr 2011, at 13:02, Eric Schlegel wrote:
> On Apr 16, 2011, at 2:59 AM, Florian Pilz wrote:
> 
>> However the Carbon API for global shortcuts (RegisterEventHotKey) is
>> marked as 'Legacy'. I am not sure if thats the same as 'deprecated' in
>> Apple terms
> 
> It's not.
> 
>> So my question is: Is the Carbon API still the way to go?
> 
> It is.

You may want to check Dave DeLong’s Cocoa wrapper for RegisterEventHotKey(), 
including block callbacks:

https://github.com/davedelong/DDHotKey


-- bavarious___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread eveningnick eveningnick
Hi Ken,
first thank you for answering this question and previous times. I am
just very unfamiliar about what can i do and what i can't drowning in
documentation that's why i'm asking so many times. I managed to
display the "funky window", but the events were my problem. Thanks a
lot for the links.

May i bother you once again with my questions?. :-)
Could you give me a hint how did QuickTime Player developers manage to
display a window the way it looks now? Specifically i can't
understand, how they made the "Movie control" toolbar, that floats
only within the "movie window"?

Reading through NSOpenGLView documentation, i found the note that this
view can't contain subviews. Though i am pretty sure the "movie view"
is NSOpenGLView (am i wrong here?). Do they display an another
"control" window somehow in an "always on top of the NSOpenGLView"
manner?

And one more question. Maybe i should ask that in OpenGL mailing list?
Although i guess it sounds so "basic" that developers there won't even
answer it...
I am wondering, why is NSOpenGLView considered to be the preferred way
to display a set of images? Why is every image operation revolving
around OpenGL? I understand that eventually it all comes through the
videoadapter, but what if i just display an RGB picture that i have in
an RGB buffer (CVImageBufferRef). Will OpenGL give me some benefits
just for rendering it on the view against drawing image onto something
like "NSImageView"?

Sorry if the questions seem like i haven't read anything. I have, just
now trying to put it all together in one big picture.

Thanks!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: SimpleTextInput sample code - caretRect not calculated correctly at times

2011-04-16 Thread Malayil George
I meant issue with CTFrameGetLineOrigins :)


George


On Sat, Apr 16, 2011 at 5:40 PM, Malayil George  wrote:

> Seems to be an issue with CTLineGetTypographicBounds when calling it for a
> single line.
>
> Changing the code to below seems to fix the issue.
> CGPoint origin[numberOfLines];
>
> CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
> CTFrameGetLineOrigins(_frame, CFRangeMake(0, 0), origin);
>
> I filed a bug report bug ID 9295523
>
>
> Thanks
> George
>
>
>
> On Mon, Apr 11, 2011 at 11:22 PM, Malayil George wrote:
>
>> Hi,
>>I'm trying to follow the SimpleTextInput example project at
>> http://developer.apple.com/library/ios/#samplecode/SimpleTextInput/Introduction/Intro.html
>>
>> For the most part, it works fine, but, for some reason the following
>> results in a wierd result drawing the caretRect.
>>   1. Type in a few lines (about 7-8 lines in the Simulator (about
>> 10 characters each line followed by a newline)
>>   2. Click on some random point in the text in the last couple of
>> lines. The caretRect is updated properly to the new location.
>>   3. Click on some random point in the first or second line. The
>> caret rect isn't drawn correctly and is way larger than usual - If there is
>> a place I can post a screen shot that is acceptable to the thread, please
>> let me know and I'd be happy to paste it :-)
>>
>>
>>   In an effort at debugging this, it looks like the ascent and descent
>> values in caretRectForIndex function changes mid-call. I added a couple of
>> NSLog statements to the relevant section ( I apologize for the lengthy code
>> post here). The function is identical to Apple's except for the added NSLog
>> statements.
>> - (CGRect)caretRectForIndex:(int)index
>> {
>> NSArray *lines = (NSArray *) CTFrameGetLines(_frame);
>>
>> // Special case, no text
>> if (_text.length == 0) {
>> CGPoint origin = CGPointMake(CGRectGetMinX(self.bounds),
>> CGRectGetMaxY(self.bounds) - self.font.leading);
>> // Note: using fabs() for typically negative descender from fonts
>> return CGRectMake(origin.x, origin.y - fabs(self.font.descender),
>> 3, self.font.ascender + fabs(self.font.descender));
>> }
>>
>> // Special case, insertion point at final position in text after
>> newline
>> if (index == _text.length && [_text characterAtIndex:(index - 1)] ==
>> '\n') {
>> CTLineRef line = (CTLineRef) [lines lastObject];
>> CFRange range = CTLineGetStringRange(line);
>> CGFloat xPos = CTLineGetOffsetForStringIndex(line, range.location,
>> NULL);
>> CGPoint origin;
>> CGFloat ascent, descent;
>> CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
>> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
>> CTFrameGetLineOrigins(_frame, CFRangeMake(lines.count - 1, 0),
>> &origin);
>> // Place point after last line, including any font leading spacing
>> if applicable
>> origin.y -= self.font.leading;
>> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
>> return CGRectMake(xPos, origin.y - descent, 3, ascent +
>> descent);
>> }
>>
>> // Regular case, caret somewhere within our text content range
>> for (int i = 0; i < [lines count]; i++) {
>> CTLineRef line = (CTLineRef) [lines objectAtIndex:i];
>> CFRange range = CTLineGetStringRange(line);
>> NSInteger localIndex = index - range.location;
>> if (localIndex >= 0 && localIndex <= range.length) {
>> // index is in the range for this line
>> CGFloat xPos = CTLineGetOffsetForStringIndex(line, index,
>> NULL);
>> CGPoint origin;
>> CGFloat ascent, descent;
>> CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
>> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
>> CTFrameGetLineOrigins(_frame, CFRangeMake(i, 0), &origin);
>> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
>> // Make a small "caret" rect at the index position
>> return CGRectMake(xPos, origin.y - descent, 3, ascent +
>> descent);
>> }
>> }
>>
>> return CGRectNull;
>> }
>>
>> The output from the above method when I click on the first couple of lines
>> is something like
>> 2011-04-11 23:09:02.670 SimpleTextInput[33460:207] Ascent, Descent:
>> 13.860352, 4.139648
>> 2011-04-11 23:09:02.670 SimpleTextInput[33460:207] Ascent, Descent:
>> 237.339645, 0.00
>>
>>The call to CTLineGetTypographicBounds seems to be working fine as
>> evidenced by the low expected values of ascent and descent. But, for some
>> reason, after CTFrameGetLineOrigins it is changing. I'm at a loss as to why
>> these values are changing as there doesn't seem to be anything in the code
>> modifying ascent and descent between the two NSLog statements.
>>   I've tried synchronizing the caretRect method body on self  (but, it
>> d

Re: SimpleTextInput sample code - caretRect not calculated correctly at times

2011-04-16 Thread Malayil George
Seems to be an issue with CTLineGetTypographicBounds when calling it for a
single line.

Changing the code to below seems to fix the issue.
CGPoint origin[numberOfLines];
CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
CTFrameGetLineOrigins(_frame, CFRangeMake(0, 0), origin);

I filed a bug report bug ID 9295523


Thanks
George


On Mon, Apr 11, 2011 at 11:22 PM, Malayil George  wrote:

> Hi,
>I'm trying to follow the SimpleTextInput example project at
> http://developer.apple.com/library/ios/#samplecode/SimpleTextInput/Introduction/Intro.html
>
> For the most part, it works fine, but, for some reason the following
> results in a wierd result drawing the caretRect.
>   1. Type in a few lines (about 7-8 lines in the Simulator (about
> 10 characters each line followed by a newline)
>   2. Click on some random point in the text in the last couple of
> lines. The caretRect is updated properly to the new location.
>   3. Click on some random point in the first or second line. The
> caret rect isn't drawn correctly and is way larger than usual - If there is
> a place I can post a screen shot that is acceptable to the thread, please
> let me know and I'd be happy to paste it :-)
>
>
>   In an effort at debugging this, it looks like the ascent and descent
> values in caretRectForIndex function changes mid-call. I added a couple of
> NSLog statements to the relevant section ( I apologize for the lengthy code
> post here). The function is identical to Apple's except for the added NSLog
> statements.
> - (CGRect)caretRectForIndex:(int)index
> {
> NSArray *lines = (NSArray *) CTFrameGetLines(_frame);
>
> // Special case, no text
> if (_text.length == 0) {
> CGPoint origin = CGPointMake(CGRectGetMinX(self.bounds),
> CGRectGetMaxY(self.bounds) - self.font.leading);
> // Note: using fabs() for typically negative descender from fonts
> return CGRectMake(origin.x, origin.y - fabs(self.font.descender),
> 3, self.font.ascender + fabs(self.font.descender));
> }
>
> // Special case, insertion point at final position in text after
> newline
> if (index == _text.length && [_text characterAtIndex:(index - 1)] ==
> '\n') {
> CTLineRef line = (CTLineRef) [lines lastObject];
> CFRange range = CTLineGetStringRange(line);
> CGFloat xPos = CTLineGetOffsetForStringIndex(line, range.location,
> NULL);
> CGPoint origin;
> CGFloat ascent, descent;
> CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
> CTFrameGetLineOrigins(_frame, CFRangeMake(lines.count - 1, 0),
> &origin);
> // Place point after last line, including any font leading spacing
> if applicable
> origin.y -= self.font.leading;
> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
> return CGRectMake(xPos, origin.y - descent, 3, ascent +
> descent);
> }
>
> // Regular case, caret somewhere within our text content range
> for (int i = 0; i < [lines count]; i++) {
> CTLineRef line = (CTLineRef) [lines objectAtIndex:i];
> CFRange range = CTLineGetStringRange(line);
> NSInteger localIndex = index - range.location;
> if (localIndex >= 0 && localIndex <= range.length) {
> // index is in the range for this line
> CGFloat xPos = CTLineGetOffsetForStringIndex(line, index,
> NULL);
> CGPoint origin;
> CGFloat ascent, descent;
> CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
> CTFrameGetLineOrigins(_frame, CFRangeMake(i, 0), &origin);
> NSLog(@"Ascent, Descent: %f, %f", ascent, descent);
> // Make a small "caret" rect at the index position
> return CGRectMake(xPos, origin.y - descent, 3, ascent +
> descent);
> }
> }
>
> return CGRectNull;
> }
>
> The output from the above method when I click on the first couple of lines
> is something like
> 2011-04-11 23:09:02.670 SimpleTextInput[33460:207] Ascent, Descent:
> 13.860352, 4.139648
> 2011-04-11 23:09:02.670 SimpleTextInput[33460:207] Ascent, Descent:
> 237.339645, 0.00
>
>The call to CTLineGetTypographicBounds seems to be working fine as
> evidenced by the low expected values of ascent and descent. But, for some
> reason, after CTFrameGetLineOrigins it is changing. I'm at a loss as to why
> these values are changing as there doesn't seem to be anything in the code
> modifying ascent and descent between the two NSLog statements.
>   I've tried synchronizing the caretRect method body on self  (but, it
> doesn't look like there are other threads that are modifying these values
> either).
>
>   Any pointers on why ascent and descent is changing would be much
> appreciated :)
>
>
> Thanks
> George
>
>
>

Re: A very customized window

2011-04-16 Thread eveningnick eveningnick
>While what you are asking for does not sound patently unreasonable, this last 
>sentence should >almost never be the reason to make a particular design 
>decision, especially when it comes to >deciding to implement non-standard 
>controls, etc.

Your statement made me think about redesigning some elements. Surely i
will try to make it the less irritating possible for the Mac users :-)
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Jeffrey Walton
On Sat, Apr 16, 2011 at 2:19 PM, Eli Bach  wrote:
>
> On Apr 16, 2011, at 11:35 AM, Jeffrey Walton wrote:
>
>> Format: ACV0 Media, 640x480, Millions, AAC (Protected), 2 channels, 44100 HZ
>
> I'm 90% sure that it's the "(Protected)" part that prevents it from playing 
> in non-Apple created video players.
Thanks Eli. 0 hits for AAC (Protected) in the developer area [1]. I
suppose we are left to guess and conjecture.

Apple states the following in quite a few documents: "iPhone supports
the ability to play back video files directly from your application"
(no strings attached). Is MPMoviePlayerController (and
MPMoviePlayerViewController) considered non-Apple? Neither the
MPMoviePlayerController Class Reference [2], Using Video [3], nor
Audio & Video Coding How-To's [4] mentions anything about protected
content or DRM.

Jeff

[1] http://developer.apple.com/library/ios/search/?q=%22AAC+%28Protected%29%22
[2] 
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/Reference/Reference.html
[3] 
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingVideo/UsingVideo.html
[4] 
http://developer.apple.com/library/ios/#codinghowtos/AudioAndVideo/_index.html
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Jeffrey Walton
On Sat, Apr 16, 2011 at 12:39 PM, Matt Neuburg  wrote:
>
> On Apr 16, 2011, at 9:00 AM, Jeffrey Walton wrote:
>
>>
>> For what its worth, Apple's sample [1] is broken - it can't even play
>> the movie it supplies with its sample.
>>
>> Jeff
>>
>> [1] 
>> http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
>
> That's a well-known bug in the example. It has nothing to do with the movie. 
> In fact, I used that same movie in the tests for my book (you can see in the 
> screen shots in the discussion of MPMoviePlayerController).
>
> The history appears to be that this was a Mac OS X example and was then made 
> available for iOS, and the example has forgotten to compensate. The code says 
> [self.moviePlayer play], but they've forgotten the most important step: add 
> the MPMoviePlayerController's view to the interface. So in fact the movie 
> *is* playing - you just can't see it because it isn't in the interface. (On 
> Mac OS X I think the movie played in a different window, but of course there 
> is no "different window" on iOS.)
>
> It's easy to fix:
>
> -(IBAction)playMovieButtonPressed:(id)sender
> {
>    MoviePlayerAppDelegate *appDelegate =
>        (MoviePlayerAppDelegate *)[[UIApplication sharedApplication] delegate];
>    [appDelegate initAndPlayMovie:[self localMovieURL]];
>    UIView* v = [appDelegate moviePlayer].view;
>    appDelegate.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
>    v.frame = CGRectMake(54,39,205,135);
>    [[sender superview] addSubview:v];
>    return;
> }
>
Hi Doctor,

With your changes, and the changes below, I was able to crash Xcode
(but the movie never played).

Apple appears to have serious problems with its MediaPlayer library
and its accompanying documentation. Its amazing it made t through QA
and was released for general consumption.

Jeff

// return a URL for the movie file in our bundle
-(NSURL *)localMovieURL
{
if (self.movieURL == nil)
{
// NSString *moviePath = [bundle pathForResource:@"Movie" 
ofType:@"m4v"];
NSString* path = [NSHomeDirectory()
stringByAppendingPathComponent:@"Documents"];
if(path)
{
NSString* moviePath = [path 
stringByAppendingPathComponent:@"02
Lost Verizon.m4v"];
if (moviePath)
{
self.movieURL = [NSURL 
fileURLWithPath:moviePath];
}
}
}

return self.movieURL;
}
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Eli Bach

On Apr 16, 2011, at 11:35 AM, Jeffrey Walton wrote:

> Format: ACV0 Media, 640x480, Millions, AAC (Protected), 2 channels, 44100 HZ

I'm 90% sure that it's the "(Protected)" part that prevents it from playing in 
non-Apple created video players.

Eli

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread Conrad Shultz
On Apr 16, 2011, at 5:44, eveningnick eveningnick  wrote:

> How could i do it, if it's possible at all? And if not, maybe i could
> implement something very close using Cocoa facilities?
> Basically i need this, to make my application look as similar as
> possible to my Windows version.

While what you are asking for does not sound patently unreasonable, this last 
sentence should almost never be the reason to make a particular design 
decision, especially when it comes to deciding to implement non-standard 
controls, etc. 

OS X has its way of doing things that should be heeded when possible in your 
application. Again, I'm not saying that having a fully resizable window isn't 
the best thing for your application, but please decide based on a careful and 
informed human interface assessment.

--
Conrad Shultz
www.synthetiqsolutions.com___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Jeffrey Walton
On Sat, Apr 16, 2011 at 11:44 AM, Matt Neuburg  wrote:
> On Thu, 14 Apr 2011 14:58:06 -0400, Jeffrey Walton  said:
>>The problem appears to be with the size of the M4V
>
> I had trouble with this too, the first time I tried to use 
> MPMoviePlayerController. Consult the specs for the hardware first. For 
> example, here are the specs for an iPad 2:
>
> http://www.apple.com/ipad/specs/
>
>> Video formats supported: H.264 video up to 720p, 30 frames per second, Main 
>> Profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in 
>> .m4v, .mp4, and .mov file formats; MPEG-4 video, up to 2.5 Mbps, 640 by 480 
>> pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 
>> Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;
>
> I'm betting we can stop right there: your movie bitrate is probably too high, 
> or the pixel dimensions are too great. Use QTAmateur to convert the video to 
> something your device can play. m.
>
>From QuickTime's Movie Inspector (I'm not sure what the 'millions' is):

Format: ACV0 Media, 640x480, Millions, AAC (Protected), 2 channels, 44100 HZ
FPS: 29.97
Data Size: 254.9 MB
Data Rate: 1560.66 kbit/s
Current Size: 640x480 (Actual)

Apple uses 1000*1000 as a MB (and not the customary 1024*1024), so the
reported size is not quite accurate. But I don't expect it to make a
difference.

Jeff
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Jeffrey Walton
On Sat, Apr 16, 2011 at 12:39 PM, Matt Neuburg  wrote:
>
> On Apr 16, 2011, at 9:00 AM, Jeffrey Walton wrote:
>
>>
>> For what its worth, Apple's sample [1] is broken - it can't even play
>> the movie it supplies with its sample.
>>
>> Jeff
>>
>> [1] 
>> http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
>
> That's a well-known bug in the example. It has nothing to do with the movie. 
> In fact, I used that same movie in the tests for my book (you can see in the 
> screen shots in the discussion of MPMoviePlayerController).
Out of curiosity, did you test your book's code against a movie
acquired from iTunes? In my naiveness, I thought the combination of an
iTunes movie on authorized Apple hardware would work out of the box.
(I have not ruled out DRM at this point).

> The history appears to be that this was a Mac OS X example and was then made 
> available for iOS, and the example has forgotten to compensate. The code says 
> [self.moviePlayer play], but they've forgotten the most important step: add 
> the MPMoviePlayerController's view to the interface. So in fact the movie 
> *is* playing - you just can't see it because it isn't in the interface. (On 
> Mac OS X I think the movie played in a different window, but of course there 
> is no "different window" on iOS.)
>
> It's easy to fix:
>
> -(IBAction)playMovieButtonPressed:(id)sender
> {
>    MoviePlayerAppDelegate *appDelegate =
>        (MoviePlayerAppDelegate *)[[UIApplication sharedApplication] delegate];
>    [appDelegate initAndPlayMovie:[self localMovieURL]];
>    UIView* v = [appDelegate moviePlayer].view;
>    appDelegate.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
>    v.frame = CGRectMake(54,39,205,135);
>    [[sender superview] addSubview:v];
>    return;
> }
This looks similar to other examples I've seen. There is a noted
difference - the player appears to be part of the Application's
delegate rather than a modally presented view.

> You could easily have found this out with Google; explanations of how to fix 
> this example are plastered all over the Internet.
Perhaps my expectations are too high - I expect examples from the
vendor should work, without the need for an easter egg hunt. I think
its a reasonable expectation.

> PS. And of course, the chapter in my book about MPMoviePlayerController lays 
> a lot of stress on your responsibility to put the darned view into the 
> interface! :)
OK. I look forward to the day it goes to press (I've got it preordered
via Amazon).

Jeff
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Matt Neuburg

On Apr 16, 2011, at 9:00 AM, Jeffrey Walton wrote:

> 
> For what its worth, Apple's sample [1] is broken - it can't even play
> the movie it supplies with its sample.
> 
> Jeff
> 
> [1] 
> http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html

That's a well-known bug in the example. It has nothing to do with the movie. In 
fact, I used that same movie in the tests for my book (you can see in the 
screen shots in the discussion of MPMoviePlayerController).

The history appears to be that this was a Mac OS X example and was then made 
available for iOS, and the example has forgotten to compensate. The code says 
[self.moviePlayer play], but they've forgotten the most important step: add the 
MPMoviePlayerController's view to the interface. So in fact the movie *is* 
playing - you just can't see it because it isn't in the interface. (On Mac OS X 
I think the movie played in a different window, but of course there is no 
"different window" on iOS.)

It's easy to fix:

-(IBAction)playMovieButtonPressed:(id)sender
{
MoviePlayerAppDelegate *appDelegate = 
(MoviePlayerAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate initAndPlayMovie:[self localMovieURL]];
UIView* v = [appDelegate moviePlayer].view;
appDelegate.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
v.frame = CGRectMake(54,39,205,135);
[[sender superview] addSubview:v];
return;
}

You could easily have found this out with Google; explanations of how to fix 
this example are plastered all over the Internet. 

m.

PS. And of course, the chapter in my book about MPMoviePlayerController lays a 
lot of stress on your responsibility to put the darned view into the interface! 
:)

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
Programming iOS 4! http://www.apeth.net/matt/default.html#iosbook
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Global Shortcuts

2011-04-16 Thread Eric Schlegel

On Apr 16, 2011, at 2:59 AM, Florian Pilz wrote:

> However the Carbon API for global shortcuts (RegisterEventHotKey) is
> marked as 'Legacy'. I am not sure if thats the same as 'deprecated' in
> Apple terms

It's not.

> So my question is: Is the Carbon API still the way to go?

It is.

-eric

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Jeffrey Walton
On Sat, Apr 16, 2011 at 11:44 AM, Matt Neuburg  wrote:
> On Thu, 14 Apr 2011 14:58:06 -0400, Jeffrey Walton  said:
>>The problem appears to be with the size of the M4V
>
> I had trouble with this too, the first time I tried to use 
> MPMoviePlayerController. Consult the specs for the hardware first. For 
> example, here are the specs for an iPad 2:
>
> http://www.apple.com/ipad/specs/
>
>> Video formats supported: H.264 video up to 720p, 30 frames per second, Main 
>> Profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in 
>> .m4v, .mp4, and .mov file formats; MPEG-4 video, up to 2.5 Mbps, 640 by 480 
>> pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 
>> Kbps per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;
>
> I'm betting we can stop right there: your movie bitrate is probably too high, 
> or the pixel dimensions are too great. Use QTAmateur to convert the video to 
> something your device can play. m.
>
Hi Doctor,

I'll check the movie's specification and report back to the group (I'd
bet others will suffer in the future).

For what its worth, Apple's sample [1] is broken - it can't even play
the movie it supplies with its sample.

Jeff

[1] 
http://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: MPMoviePlayerController

2011-04-16 Thread Matt Neuburg
On Thu, 14 Apr 2011 14:58:06 -0400, Jeffrey Walton  said:
>The problem appears to be with the size of the M4V

I had trouble with this too, the first time I tried to use 
MPMoviePlayerController. Consult the specs for the hardware first. For example, 
here are the specs for an iPad 2:

http://www.apple.com/ipad/specs/

> Video formats supported: H.264 video up to 720p, 30 frames per second, Main 
> Profile level 3.1 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in 
> .m4v, .mp4, and .mov file formats; MPEG-4 video, up to 2.5 Mbps, 640 by 480 
> pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps 
> per channel, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats;

I'm betting we can stop right there: your movie bitrate is probably too high, 
or the pixel dimensions are too great. Use QTAmateur to convert the video to 
something your device can play. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: A very customized window

2011-04-16 Thread Ken Thomases
On Apr 16, 2011, at 7:44 AM, eveningnick eveningnick wrote:

> Is it possible to resize a "custom" title-less window using any of
> it's 4 corners?
> 
> I want to display a window with a hole inside (A window which looks
> like a frame), and let the user to resize this frame using any of the
> 4 boundaries of such a frame.
> 
> Also i am wondering, if i could let the user drag such a "title-less"
> window clicking on the 'fake' title bar?

Sure.  Just handle the mouseDown:, mouseDragged:, and mouseUp: messages, 
adjusting the frame as appropriate.  NSWindow inherits from NSResponder.  See 
the discussion of these techniques in the documentation:
http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/HandlingMouseEvents/HandlingMouseEvents.html#//apple_ref/doc/uid/1060i-CH6-SW18

See Apple's RoundTransparentWindow sample code for an example.
http://developer.apple.com/library/mac/#samplecode/RoundTransparentWindow/

Also the FunkyOverlayWindow sample code:
http://developer.apple.com/library/mac/#samplecode/FunkyOverlayWindow/


> When the user clicks "in the hole" of the window - inside the frame,
> the click "goes" to the desktop or another window which happened to be
> below?

Yes.  You've asked this repeatedly and been given the answer.  Create a 
borderless window with a transparent interior.  The same samples illustrate 
this, too.

Regards,
Ken

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


A very customized window

2011-04-16 Thread eveningnick eveningnick
Hi
Is it possible to resize a "custom" title-less window using any of
it's 4 corners?

I want to display a window with a hole inside (A window which looks
like a frame), and let the user to resize this frame using any of the
4 boundaries of such a frame.

Also i am wondering, if i could let the user drag such a "title-less"
window clicking on the 'fake' title bar?

When the user clicks "in the hole" of the window - inside the frame,
the click "goes" to the desktop or another window which happened to be
below?

How could i do it, if it's possible at all? And if not, maybe i could
implement something very close using Cocoa facilities?
Basically i need this, to make my application look as similar as
possible to my Windows version.
Thanks a lot!
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Global Shortcuts

2011-04-16 Thread Florian Pilz
I am searching for the 'modern' way to define global shortcuts. I
searched for it and found all over the web, that the old Carbon API
should be used, because it's way more convenient than using NSEvent.

However the Carbon API for global shortcuts (RegisterEventHotKey) is
marked as 'Legacy'. I am not sure if thats the same as 'deprecated' in
Apple terms, since all people on the web say the Carbon API should be
used as long as it is not marked as deprecated. So my question is: Is
the Carbon API still the way to go? If not, is there a better way
rather using NSEvent where I must handle (and filter) any event thrown
by the system?

Best wishes
Florian
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Appending CGPath to CGPath

2011-04-16 Thread Graham Cox

On 16/04/2011, at 4:40 PM, Roland King wrote:

> Where I'm getting the most time spent is in CGPathAddArc(), and this 
> particular shape has a lot of them. My assumption here is that CGPathAddArc, 
> which takes two angles, is having to calculate a bunch of trig functions of 
> those and figure out which bezier paths to add to approximate it. Once I have 
> the path calculated once, yes to rotate and translate it I'll have to iterate 
> over the points and multiply each of them by the transformation, but that's a 
> quicker operation  than recalculating each one of those arcs all over again 
> from basics.

Yes, calculating arc-to-bezier is quite complicated (I just implemented this 
for importing SVG 'A' commands). If the arcs have common angles but there are 
many of them you could re-use the calculated arc segment using transforms to 
speed that up.

For joining paths in the way you describe, you have to use CGPathApply.

--Graham


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com