isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Philip Vallone

Hello,

I am passing different types of data to NSData (NSString, NSArray, UIImage).  I 
am trying to find out what kind of data t is so I know how to handle the NSData 
when I receive it.  The below code is an example of how I am trying to do this 
but its always returning null. What am I doing wrong?

NSString *somedata = [[NSString alloc] initWithString:@"Some string"];  
NSData * set = [NSKeyedArchiver archivedDataWithRootObject:[somedata 
dataUsingEncoding:NSASCIIStringEncoding]];
NSData * unset = [NSKeyedUnarchiver unarchiveObjectWithData:set];
NSLog(@"Class Type %@", [unset isKindOfClass:[NSKeyedUnarchiver 
class]]);
[somedata release];

Thanks,

Phil

___

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: isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Alexander Spohr

Am 27.05.2010 um 11:21 schrieb Philip Vallone:

> 
> Hello,
> 
> I am passing different types of data to NSData (NSString, NSArray, UIImage).  
> I am trying to find out what kind of data t is so I know how to handle the 
> NSData when I receive it.  The below code is an example of how I am trying to 
> do this but its always returning null. What am I doing wrong?
> 
>   NSString *somedata = [[NSString alloc] initWithString:@"Some string"];  
>   NSData * set = [NSKeyedArchiver archivedDataWithRootObject:[somedata 
> dataUsingEncoding:NSASCIIStringEncoding]];
>   NSData * unset = [NSKeyedUnarchiver unarchiveObjectWithData:set];

Unset is not a pointer to NSData, it is an id. Did you read the docs?

>   NSLog(@"Class Type %@", [unset isKindOfClass:[NSKeyedUnarchiver 
> class]]);

You ask if unset’s class is NSKeyedUnarchiver. That returns a BOOL (and always 
NO) but you tell NSLog to receive a pointer to an object. So you see a (null).

Try asking unset for its class...

atze


___

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


Problem getting correct file URL in NSTask process

2010-05-27 Thread Antonio Nunes
Hi,

I have a daemon that spawns NSTasks on request. A task is passed a number of 
paths to process. These paths are pased correctly to the task, and in the task 
I can correctly extract the path string from optarg. When I try to turn the 
path into a file url however, the resulting URL is not correct.

For instance: I create a string from the argument:
NSString *path = [[[NSString alloc] initWithBytes:(UInt8 *)optarg 
length:strlen(optarg) encoding:NSMacOSRomanStringEncoding] 
stringByExpandingTildeInPath];

At this point path is 
"/Volumes/MyDisk/Users/sonata/Desktop/Stash/BPSystemStartup.pdf"

When I subsequently call [NSURL fileURLWithPath:path] the result is  
"%20%22/Volumes/MyDisk/Users/sonata/Desktop/Stash/BPSystemStartup.pdf%22 -- 
/Volumes/MyDisk/Users/sonata/Documents/Xcode Projects/builds/Debug/"

The task launched by NSTask is a command line app that works just fine when run 
on its own (e.g. from the terminal). The issue only happens when launching the 
command line app through NSTask. Any pointers to why this happens?

António

---
Don't believe everything you think
---




___

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: Get controller from nib

2010-05-27 Thread Reinhard Segeler

Hi James,

today I read your mail:

I ran into a problem with the reference some time ago. I have solved  
it by posting/observing a notification with the reference as the only  
object in the userInfo dict.. That works fine and assures, that the  
reference can be determined exactly. The only problem can be, to send  
it at the correct time, but that's solvable.


Your problem with the tableView/array controller: I strongly recommend  
to read the book of Aaraon Hillegass Programming MacOS X, where the  
handling of tableView/array controllers etc. is fairly good  
explained!!! I could send you a project, that I created from the book,  
but it's only helpful, if you have a certain unterstanding of the  
basics.


-- Reinhard 

Am 20.05.2010 um 19:32 schrieb James Maxwell:

So, I decided to get rid of the NSArrayController, since it was  
driving me slightly crazy, and just do this manually. I've got the  
table **appearing** as I'd like it to, but I can't change the  
selection. There are 3 columns: 1) string, 2) NSPopUpButtonCell for  
MIDI ports, and 3) NSPopUpButtonCell for MIDI channels. Basically,  
nothing can be changed. It comes up as 1) "default" (set in the init  
of MIDIInstrument), 2) as item 2 in column 2's popup, and 3) as item  
2 in column 3's popup.


I don't know if maybe I have the functions of these two methods  
reversed somehow, or what. The naming of the methods is a bit  
unclear. I'm assuming that "objectValueForTableColumn" would mean  
what I want to "give" to the table for display, whereas  
"setObjectValue:forTableColumn" would be what I want to "give" to my  
object, from the table. Mind you, the latter would be clearer as  
"setObjectValue:fromTableColumn", if that was the case... dunno...


Here's my manual code for updating the table:

- (id) tableView:(NSTableView *)tv objectValueForTableColumn: 
(NSTableColumn *)tc row:(NSInteger)row

{
if(tv == midiInstrumentsTable)
{
id inst = [[self instrumentLibrary] objectAtIndex:row];
if(inst == nil)
return nil;
if(tc == midiInstNamesColumn)
{
// give the name for the associated MIDIInstrument
return [inst MIDI_Inst_Name];
}
else if(tc == midiPortsColumn)
{
// list the ports for the associated MIDIInstrument
NSPopUpButtonCell* ports = [tc dataCell];
[ports removeAllItems];
int i;
for(i=0;i < [[inst MIDI_Inst_Ports] count];i++)
[ports addItemWithTitle:[[inst MIDI_Inst_Ports] 
objectAtIndex:i]];
return ports;
}
else if(tc == midiChannelsColumn)
{
			// list the channels for the associated MIDIInstrument (just 16  
numbers)

NSPopUpButtonCell* channels = [tc dataCell];
[channels removeAllItems];
int i;
for(i=0;i < 16;i++)
[channels addItemWithTitle:[NSString stringWithFormat:@"%i", i 
+1]];

return channels;
}
}
return nil;
}

- (void) tableView:(NSTableView *)tv setObjectValue:(id)v  
forTableColumn:(NSTableColumn *)tc row:(NSInteger)row	

{
if (tv == midiInstrumentsTable) 
{
id inst = [[self instrumentLibrary] objectAtIndex:row];
if(inst == nil)
return;
if (tc == midiInstNamesColumn)  
{
// set the given name
[inst setMIDI_Inst_Name:[[tc dataCell] title]];
}
else if(tc == midiPortsColumn)
{
// set the selected port
[inst setMIDI_Inst_Port:[[[tc dataCell] selectedItem] 
title]];
}
else if(tc == midiChannelsColumn)
{
// set the selected channel
			[inst setMIDI_Inst_Channel:[NSNumber numberWithInt:tc  
dataCell] selectedItem] title] integerValue]]];

}
}
}

Any help very much appreciated.

J.


On 2010-05-19, at 2:19 PM, James Maxwell wrote:

okay, going slightly nuts. I've implemented my  
MIDI_Instrument_Controller object, and hooked it up to my table  
view, but it's complaining about implementing  
numberOrRowsInTableView and  
tableView:objectValueForTableColumn:row:. Fine, except that I very  
definitely have implemented them. I tried cleaning, and reloading  
classes in IB, to no avail. Has anyone seen this? Any solutions?


J.



On 2010-05-18, at 6:27 PM, Mark Ritchie wrote:


Hey James!

On 18/May/2010, at 5:42 PM, James Maxwell wrote:
Okay, getting a bit deeper into this, I realize I'm still "in the  
woods",

Re: isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Ken Thomases
On May 27, 2010, at 4:21 AM, Philip Vallone wrote:

> I am passing different types of data to NSData (NSString, NSArray, UIImage).  
> I am trying to find out what kind of data t is so I know how to handle the 
> NSData when I receive it.

NSData is just a byte sequence.  It doesn't have any knowledge about the 
semantic meaning of those bytes.

I'm not even sure what you mean by "passing different types of data to NSData". 
 You don't pass strings, arrays, or images to NSData.  You can ask some of 
those objects for data, but that's not the same thing.


>   NSString *somedata = [[NSString alloc] initWithString:@"Some string"];  

The above is a warning sign.  I see it a lot with new Cocoa programmers.  The 
expression

@"Some string"

is already a full-fledged string object.  You can send it messages and 
everything.  There's no reason to "turn it into a string object" or "make a 
string object from it" or anything like that.  Creating a new string from it, 
as you've done with +alloc and -initWithString: accomplishes nothing but a bit 
of waste.

I only point it out because it indicates a weakness in your understanding of 
the language and framework.

Also, calling a string "somedata" is just going to confuse you and anybody else 
reading your code.  A string object is not a data object.

>   NSData * set = [NSKeyedArchiver archivedDataWithRootObject:[somedata 
> dataUsingEncoding:NSASCIIStringEncoding]];

I don't think this is doing what you want.  The expression "[somedata 
dataUsingEncoding:NSASCIIStringEncoding]" asks the string to create a byte 
sequence by encoding its contents into ASCII.  It puts the byte sequence into a 
data object and returns it to you.  Once again, the data object knows nothing 
about the semantics of the byte sequence.  You can't query it and ask, "were 
you originally a string?"  It doesn't have the slightest clue.

Then, you create another data object by key-archiving the data object with the 
ASCII byte sequence.  That second data object also doesn't know that it's a 
keyed archive containing a data object (which happens to contain an ASCII byte 
sequence of a string).

However, it does have internal structure so that an NSKeyedUnarchiver can 
rediscover that it was a data object.  But that still doesn't imbue the 
unarchived data object with knowledge that it originally came from a string.

The question is, why did you ASCII-encode the string into a data object if you 
were then going to archive that data object into another data object.  I think 
you probably want to simply archive the string, directly:

NSData* set = [NSKeyedArchiver archivedDataWithRootObject:somedata];

Again, calling a data object a "set" is just confusing.

>   NSData * unset = [NSKeyedUnarchiver unarchiveObjectWithData:set];

With your original code, unset would now point to a data object which contains 
the ASCII byte sequence obtained from the string.  Still, though, this data 
object has no way of knowing that its contents are ASCII-encoded characters or 
that it came from a string.

>   NSLog(@"Class Type %@", [unset isKindOfClass:[NSKeyedUnarchiver 
> class]]);

Alexander has already pointed out the problems with this line.  But, more 
fundamentally, there's no amount of querying of the unarchived data object that 
will reveal what it once was.  It doesn't know.  You'll only learn that it is a 
data object.

If you had originally archived the string object instead of a data object 
obtained by asking the string to encode itself, then you would have gotten back 
an equivalent string object.  You could usefully ask that string object about 
its class using -isKindOfClass:.

To summarize, perhaps this does what you're looking for:

NSString* somestring = @"Some string";
NSData* archive = [NSKeyedArchiver 
archivedDataWithRootObject:somestring];
// ... later ...
id obj = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
if ([obj isKindOfClass:[NSString class]])
// ... use 'obj' as a string
else if ([obj isKindOfClass:[NSArray class]])
// ... use 'obj' as an array
// ... etc. ...

(Note that I don't release somestring because I don't own it, by the memory 
management rules.  You were correct to release yours, though, since your code 
did own its.)

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: Problem getting correct file URL in NSTask process

2010-05-27 Thread Ken Thomases
On May 27, 2010, at 4:33 AM, Antonio Nunes wrote:

> I have a daemon that spawns NSTasks on request. A task is passed a number of 
> paths to process. These paths are pased correctly to the task, and in the 
> task I can correctly extract the path string from optarg.

No, they aren't and no you can't, according to what you write below.

> When I try to turn the path into a file url however, the resulting URL is not 
> correct.
> 
> For instance: I create a string from the argument:
>   NSString *path = [[[NSString alloc] initWithBytes:(UInt8 *)optarg 
> length:strlen(optarg) encoding:NSMacOSRomanStringEncoding] 
> stringByExpandingTildeInPath];

Why do you think the string is in Mac Roman encoding?  It probably isn't.  In 
fact, I happen to know that NSTask converts all of its arguments to "file 
system representation".  Even if I didn't know that, that's the only correct 
thing to assume.  So, you should use the following to construct an NSString 
from optarg:

NSString* path = [[NSFileManager defaultManager] 
stringWithFileSystemRepresentation:optarg length:strlen(optarg)];


> At this point path is 
> "/Volumes/MyDisk/Users/sonata/Desktop/Stash/BPSystemStartup.pdf"

Well, this is ambiguous as you're about to see...

> When I subsequently call [NSURL fileURLWithPath:path] the result is  
> "%20%22/Volumes/MyDisk/Users/sonata/Desktop/Stash/BPSystemStartup.pdf%22 -- 
> /Volumes/MyDisk/Users/sonata/Documents/Xcode Projects/builds/Debug/"

The percent-escape sequences in there show that path didn't contain what you 
thought it did.  It starts with a space character (the %20).  Plus the file 
path has actual, literal quote characters (the %22s) in it.

So, it would be more accurate to says that path is " 
\"/Volumes/MyDisk/Users/sonata/Desktop/Stash/BPSystemStartup.pdf\"", as it 
might be expressed as a C literal.


> The task launched by NSTask is a command line app that works just fine when 
> run on its own (e.g. from the terminal). The issue only happens when 
> launching the command line app through NSTask. Any pointers to why this 
> happens?

You are almost certainly confused about the need to quote and escape things for 
the shell.  The shell needs to take what it receives as a single command string 
and break it up into its component parts.  That's what introduces the need to 
quote whitespace and escape special characters  when working in the shell.

By contrast, NSTask is handed its arguments already neatly separated out into 
individual elements.  Plus, it doesn't have any special characters -- it just 
treats all of its arguments literally.  Thus, it does not require that its 
arguments be quoted or escaped.  Indeed, if you try to do so, those characters 
are just passed along to the new process.

So, I guess that you have taken a file path string in the parent process and, 
while attempting to pass it through to a subprocess verbatim, you've done 
exactly the wrong thing.  You've modified it, putting quote marks around it 
and, apparently, a space before it.  If you had done nothing with the string 
but pass it in as one of the task's arguments, _that_ would have gotten it to 
the subprocess verbatim.

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: subclass overwriting superclass ivar

2010-05-27 Thread jonat...@mugginsoft.com


On 26 May 2010, at 20:00, Greg Parker wrote:
>> 
> 
> Mac or iPhone?
> iPhone device or iPhone simulator?
> 32-bit Mac or 64-bit Mac?
> 
Sorry for the vagueness. 32 bit mac.

> My guess is that (1) you're running on iPhone Simulator or 32-bit Mac, and 
> (2) you recently added an ivar to MGS_A but did not recompile all code that 
> uses MGS_B. In that case, any MGS_B code that was compiled with the old 
> declaration of MGS_A will think MGS_A is smaller than it actually is, and 
> write its ivar values to the wrong place.
> 
> Try a clean rebuild of everything. If the above is the problem, a clean build 
> should fix it.
A clean build does sort it out.

I am astonished that I don't fall over this simple issue every day.

MGS_A and MGS_B exist in the same module (a private framework).
If I add an ivar to MGS_A and build my app then MGS_B succumbs to the fragile 
ivar syndrome.
I have to touch MGS_B and rebuild in order to update its ivar offsets.
I always presumed that as MGS_B is a subclass of MGS_A it would get built too.

Is there no build support to help with these sorts of class dependencies?
Or have I borked my build settings somewhere?

> 
> You can also check ivar offsets that the runtime expects. These two values 
> should be different:
>#include 
>printf("tempFilePath %zu, stderrData %zu\n",
>   
> (size_t)ivar_getOffset(class_getInstanceVariable(objc_getClass("MGS_A"), 
> "tempFilePath")),
>   
> (size_t)ivar_getOffset(class_getInstanceVariable(objc_getClass("MGS_B"), 
> "stderrData")));
> 
This does indeed confirm the offsets. Thanks.

> 
> iPhone device and 64-bit Mac should not have this problem. The compiler and 
> runtime cooperate to allow the runtime to move the subclass's ivars out of 
> the way if the superclass grows.
> http://sealiesoftware.com/blog/archive/2009/01/27/objc_explain_Non-fragile_ivars.html
> 
I presume that 32 cannot not get this bit of TLC for backwards compatibility 
reasons.

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.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: Problem getting correct file URL in NSTask process

2010-05-27 Thread Antonio Nunes
On 27 May 2010, at 11:52, Ken Thomases wrote:

>> I have a daemon that spawns NSTasks on request. A task is passed a number of 
>> paths to process. These paths are pased correctly to the task, and in the 
>> task I can correctly extract the path string from optarg.
> 
> No, they aren't and no you can't, according to what you write below.

Thanks so much for the elaborate and pertinent answer Ken. You are right. I was 
not passing the arguments correctly to the task.

I was creating the arguments like this:

[args addObject:[NSString stringWithFormat:@"-f \"%...@\"", 
[[sourceDirectoryURL path] stringByAppendingPathComponent:sourceFileName]]];

Whereas, I now understand (hopefully correctly), I should have been creating 
them like this:

[args addObject:[NSString stringWithFormat:@"-f%@", [[sourceDirectoryURL 
path] stringByAppendingPathComponent:sourceFileName]]];

> Why do you think the string is in Mac Roman encoding?  It probably isn't.  In 
> fact, I happen to know that NSTask converts all of its arguments to "file 
> system representation".  Even if I didn't know that, that's the only correct 
> thing to assume.  So, you should use the following to construct an NSString 
> from optarg:
> 
>   NSString* path = [[NSFileManager 
> defaultManager]stringWithFileSystemRepresentation:optarg 
> length:strlen(optarg)];

It's been a while since I wrote the original code for this, but if memory 
serves me correctly, I modelled this after some sample code, and since it 
worked, I did not question it. I have adjusted the path extraction to use the 
more correct stringWithFileSystemRepresentation: call instead. 

> You are almost certainly confused about the need to quote and escape things 
> for the shell.  The shell needs to take what it receives as a single command 
> string and break it up into its component parts.  That's what introduces the 
> need to quote whitespace and escape special characters  when working in the 
> shell.
> 
> By contrast, NSTask is handed its arguments already neatly separated out into 
> individual elements.  Plus, it doesn't have any special characters -- it just 
> treats all of its arguments literally. Thus, it does not require that its 
> arguments be quoted or escaped.  Indeed, if you try to do so, those 
> characters are just passed along to the new process.

Confused I was indeed (although I did not know it). This is new territory for 
me, so I'm not surprised I stumble a bit as I plod through it. :-)

> So, I guess that you have taken a file path string in the parent process and, 
> while attempting to pass it through to a subprocess verbatim, you've done 
> exactly the wrong thing.  You've modified it, putting quote marks around it 
> and, apparently, a space before it.  If you had done nothing with the string 
> but pass it in as one of the task's arguments, _that_ would have gotten it to 
> the subprocess verbatim.

Yes. Now that I pass the option's identifier with its parameter appended snugly 
to it (without quotes and separating space char) the URL is created correctly.

Kind regards,
António



Disapprove of sin but not of the sinner



___

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


Logging in ad-hoc builds

2010-05-27 Thread Nava Carmon
Hi,

I have a problem with NSURLConnection in my ad-hoc build and I'd like to log 
the problematic url. In debug version i can just output it to console. The 
question is how do i track it in ad-hoc? It's not about crashing, so crash logs 
will not help. Any ideas? 

Thanks in advance



Nava Carmon
ncar...@mac.com

"Think good and it will be good!"

___

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: Logging in ad-hoc builds

2010-05-27 Thread Roland King
Ad hoc. Are you talking about iPhone development? If so then log it to  
the console and grab the console logs afterwards through Xcode.  
Remember to take all that stuff out at the end, no point carrying all  
that log in your phone.




On 27-May-2010, at 19:57, Nava Carmon  wrote:


Hi,

I have a problem with NSURLConnection in my ad-hoc build and I'd  
like to log the problematic url. In debug version i can just output  
it to console. The question is how do i track it in ad-hoc? It's not  
about crashing, so crash logs will not help. Any ideas?


Thanks in advance



Nava Carmon
ncar...@mac.com

"Think good and it will be good!"

___

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/rols%40rols.org

This email sent to r...@rols.org

___

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: Problem getting correct file URL in NSTask process

2010-05-27 Thread Ken Thomases
On May 27, 2010, at 6:55 AM, Antonio Nunes wrote:

> Thanks so much for the elaborate and pertinent answer Ken. You are right. I 
> was not passing the arguments correctly to the task.

You're welcome.  Glad I could help.

> I was creating the arguments like this:
> 
>[args addObject:[NSString stringWithFormat:@"-f \"%...@\"", 
> [[sourceDirectoryURL path] stringByAppendingPathComponent:sourceFileName]]];
> 
> Whereas, I now understand (hopefully correctly), I should have been creating 
> them like this:
> 
>[args addObject:[NSString stringWithFormat:@"-f%@", [[sourceDirectoryURL 
> path] stringByAppendingPathComponent:sourceFileName]]];

> Yes. Now that I pass the option's identifier with its parameter appended 
> snugly to it (without quotes and separating space char) the URL is created 
> correctly.


Well, that works, but I want to clarify something...

If, in a shell, you were to invoke a command like:

/path/to/some/command -f /path/to/file

Then the program would receive "-f" and "/path/to/file" as separate arguments.  
To achieve the same thing with NSTask, you'd pass @"-f" and @"/path/to/file" as 
two separate elements of the argument array.

You've now switched to the equivalent of:

/path/to/some/command -f/path/to/file

That works in this case, but relies on the program you're invoking parsing 
apart the option switch from its value.  Apparently, that assumption holds for 
the program in question.  I just wanted to make sure you understood how to 
replicate the original form using NSTask.

Cheers,
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: Problem getting correct file URL in NSTask process

2010-05-27 Thread Antonio Nunes
On 27 May 2010, at 13:15, Ken Thomases wrote:

> If, in a shell, you were to invoke a command like:
> 
> /path/to/some/command -f /path/to/file
> 
> Then the program would receive "-f" and "/path/to/file" as separate 
> arguments.  To achieve the same thing with NSTask, you'd pass @"-f" and 
> @"/path/to/file" as two separate elements of the argument array.
> 
> You've now switched to the equivalent of:
> 
> /path/to/some/command -f/path/to/file
> 
> That works in this case, but relies on the program you're invoking parsing 
> apart the option switch from its value.  Apparently, that assumption holds 
> for the program in question.  I just wanted to make sure you understood how 
> to replicate the original form using NSTask.

Thanks,

I wondered about that actually, but had not tried sending the arguments 
separately yet. I'll make these changes, as you have made it clear that that is 
a more robust way to pass the arguments.

Best,
António


Disapprove of sin but not of the sinner



___

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: isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Philip Vallone
Ken & Alexander,

Thank you so much for your help. Your explanations are extremely helpful. 

Best regards, 

Phil

On May 27, 2010, at 6:36 AM, Ken Thomases  wrote:

> On May 27, 2010, at 4:21 AM, Philip Vallone wrote:
> 
>> I am passing different types of data to NSData (NSString, NSArray, UIImage). 
>>  I am trying to find out what kind of data t is so I know how to handle the 
>> NSData when I receive it.
> 
> NSData is just a byte sequence.  It doesn't have any knowledge about the 
> semantic meaning of those bytes.
> 
> I'm not even sure what you mean by "passing different types of data to 
> NSData".  You don't pass strings, arrays, or images to NSData.  You can ask 
> some of those objects for data, but that's not the same thing.
> 
> 
>>NSString *somedata = [[NSString alloc] initWithString:@"Some string"];
> 
> The above is a warning sign.  I see it a lot with new Cocoa programmers.  The 
> expression
> 
>@"Some string"
> 
> is already a full-fledged string object.  You can send it messages and 
> everything.  There's no reason to "turn it into a string object" or "make a 
> string object from it" or anything like that.  Creating a new string from it, 
> as you've done with +alloc and -initWithString: accomplishes nothing but a 
> bit of waste.
> 
> I only point it out because it indicates a weakness in your understanding of 
> the language and framework.
> 
> Also, calling a string "somedata" is just going to confuse you and anybody 
> else reading your code.  A string object is not a data object.
> 
>>NSData * set = [NSKeyedArchiver archivedDataWithRootObject:[somedata 
>> dataUsingEncoding:NSASCIIStringEncoding]];
> 
> I don't think this is doing what you want.  The expression "[somedata 
> dataUsingEncoding:NSASCIIStringEncoding]" asks the string to create a byte 
> sequence by encoding its contents into ASCII.  It puts the byte sequence into 
> a data object and returns it to you.  Once again, the data object knows 
> nothing about the semantics of the byte sequence.  You can't query it and 
> ask, "were you originally a string?"  It doesn't have the slightest clue.
> 
> Then, you create another data object by key-archiving the data object with 
> the ASCII byte sequence.  That second data object also doesn't know that it's 
> a keyed archive containing a data object (which happens to contain an ASCII 
> byte sequence of a string).
> 
> However, it does have internal structure so that an NSKeyedUnarchiver can 
> rediscover that it was a data object.  But that still doesn't imbue the 
> unarchived data object with knowledge that it originally came from a string.
> 
> The question is, why did you ASCII-encode the string into a data object if 
> you were then going to archive that data object into another data object.  I 
> think you probably want to simply archive the string, directly:
> 
>NSData* set = [NSKeyedArchiver archivedDataWithRootObject:somedata];
> 
> Again, calling a data object a "set" is just confusing.
> 
>>NSData * unset = [NSKeyedUnarchiver unarchiveObjectWithData:set];
> 
> With your original code, unset would now point to a data object which 
> contains the ASCII byte sequence obtained from the string.  Still, though, 
> this data object has no way of knowing that its contents are ASCII-encoded 
> characters or that it came from a string.
> 
>>NSLog(@"Class Type %@", [unset isKindOfClass:[NSKeyedUnarchiver class]]);
> 
> Alexander has already pointed out the problems with this line.  But, more 
> fundamentally, there's no amount of querying of the unarchived data object 
> that will reveal what it once was.  It doesn't know.  You'll only learn that 
> it is a data object.
> 
> If you had originally archived the string object instead of a data object 
> obtained by asking the string to encode itself, then you would have gotten 
> back an equivalent string object.  You could usefully ask that string object 
> about its class using -isKindOfClass:.
> 
> To summarize, perhaps this does what you're looking for:
> 
>NSString* somestring = @"Some string";
>NSData* archive = [NSKeyedArchiver archivedDataWithRootObject:somestring];
>// ... later ...
>id obj = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
>if ([obj isKindOfClass:[NSString class]])
>// ... use 'obj' as a string
>else if ([obj isKindOfClass:[NSArray class]])
>// ... use 'obj' as an array
>// ... etc. ...
> 
> (Note that I don't release somestring because I don't own it, by the memory 
> management rules.  You were correct to release yours, though, since your code 
> did own its.)
> 
> 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

Activating application raises windows meant to be invisible

2010-05-27 Thread David Reitter
How can I keep invisible windows invisible when my application is raised?

My application can end up with only one NSWindow "A" that is invisible 
([NSWindow orderOut]).  This window is the key window.  The application may 
also have other windows ("B") that are iconified.

I find that when switching back to the application, window A is always made 
visible (provided I am on the same Space as the window).  How do I control that?
I would get my application to de-iconify B instead.

Window A is raised even before my 
applicationShouldHandleReopen:hasVisibleWindows: are 
applicationDidBecomeActive: are sent.  I have also unsuccessfully tried to 
implement [NSWindow orderFront] to override the behavior.

How would I got about keeping the window hidden?

Thanks for your help.___

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: subclass overwriting superclass ivar

2010-05-27 Thread Mike Abdullah

On 27 May 2010, at 12:53, jonat...@mugginsoft.com wrote:

>> 
>> iPhone device and 64-bit Mac should not have this problem. The compiler and 
>> runtime cooperate to allow the runtime to move the subclass's ivars out of 
>> the way if the superclass grows.
>> http://sealiesoftware.com/blog/archive/2009/01/27/objc_explain_Non-fragile_ivars.html
>> 
> I presume that 32 cannot not get this bit of TLC for backwards compatibility 
> reasons.

Correct.___

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


behavior of -copy

2010-05-27 Thread Ariel Feinerman
Hi,

if i understand, -copy message implement via -retain for true immutable
objects like NSNumber, via -alloc, -init thus make true copy for mutable
objects like NSMutableArray, my question is: what does -copy for immutable
variant of immutable/mutable objects, for instance NSArray *arrayCopy =
[array copy]; returns true copy or retains one? Or what does happen if
object itself is immutable and has not setters, but it instance variables is
mutable and can be changed?
NSDictionary instance has NSMutableDictionary values


-- 
best regards
Ariel
___

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: behavior of -copy

2010-05-27 Thread Mike Abdullah

On 27 May 2010, at 13:59, Ariel Feinerman wrote:

> Hi,
> 
> if i understand, -copy message implement via -retain for true immutable
> objects like NSNumber, via -alloc, -init thus make true copy for mutable
> objects like NSMutableArray, my question is: what does -copy for immutable
> variant of immutable/mutable objects, for instance NSArray *arrayCopy =
> [array copy]; returns true copy or retains one? Or what does happen if
> object itself is immutable and has not setters, but it instance variables is
> mutable and can be changed?
> NSDictionary instance has NSMutableDictionary values

Container classes make shallow copies of themselves. If you've got a dictionary 
containing mutable dictionary values, you either:

A) NSDictionary *copy = [[NSDictionary alloc] initWithDictionary:myDict 
copyItems:YES];

B) Look again at your code and think that it would probably be better to create 
model classes rather than nested dictionaries.


> 
> 
> -- 
> best regards
> Ariel
> ___
> 
> 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/cocoadev%40mikeabdullah.net
> 
> This email sent to cocoa...@mikeabdullah.net

___

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: subclass overwriting superclass ivar

2010-05-27 Thread Jean-Daniel Dupas

Le 27 mai 2010 à 13:53, jonat...@mugginsoft.com a écrit :

> 
> 
> On 26 May 2010, at 20:00, Greg Parker wrote:
>>> 
>> 
>> Mac or iPhone?
>> iPhone device or iPhone simulator?
>> 32-bit Mac or 64-bit Mac?
>> 
> Sorry for the vagueness. 32 bit mac.
> 
>> My guess is that (1) you're running on iPhone Simulator or 32-bit Mac, and 
>> (2) you recently added an ivar to MGS_A but did not recompile all code that 
>> uses MGS_B. In that case, any MGS_B code that was compiled with the old 
>> declaration of MGS_A will think MGS_A is smaller than it actually is, and 
>> write its ivar values to the wrong place.
>> 
>> Try a clean rebuild of everything. If the above is the problem, a clean 
>> build should fix it.
> A clean build does sort it out.
> 
> I am astonished that I don't fall over this simple issue every day.
> 
> MGS_A and MGS_B exist in the same module (a private framework).
> If I add an ivar to MGS_A and build my app then MGS_B succumbs to the fragile 
> ivar syndrome.
> I have to touch MGS_B and rebuild in order to update its ivar offsets.
> I always presumed that as MGS_B is a subclass of MGS_A it would get built too.
> 
> Is there no build support to help with these sorts of class dependencies?
> Or have I borked my build settings somewhere?


If MGS_B is a subclass of MGS_A , it must import the MGS_A header file (else 
the compiler will complain).
If you touch a header file, all files that include it should be automatically 
rebuild on the next build, else this is a bug in Xcode that failed to properly 
resolve file dependencies.

If you manage to reproduce the issue, fill a radar.

WFIW, a known case where Xcode failed to properly compute dependencies is when 
you import your header using a macro

#define MYHEADER(header) 

#include MYHEADER(MGS_A.h)


-- Jean-Daniel




___

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: subclass overwriting superclass ivar

2010-05-27 Thread jonat...@mugginsoft.com

On 27 May 2010, at 14:42, Jean-Daniel Dupas wrote:
>> 
>> 
>> Is there no build support to help with these sorts of class dependencies?
>> Or have I borked my build settings somewhere?
> 
> 
> If MGS_B is a subclass of MGS_A , it must import the MGS_A header file (else 
> the compiler will complain).
> If you touch a header file, all files that include it should be automatically 
> rebuild on the next build, else this is a bug in Xcode that failed to 
> properly resolve file dependencies.
> 
> If you manage to reproduce the issue, fill a radar.
> 
> WFIW, a known case where Xcode failed to properly compute dependencies is 
> when you import your header using a macro
> 
> #define MYHEADER(header) 
> 
> #include MYHEADER(MGS_A.h)
> 
This was the source of the problem.

While refactoring I had inserted the import statement for MGS_A in a 
convenience header along with several others.
This convenience header was then imported into MGS_B.h.
The compiler did not complain but it obviously affected the build system as 
MGS_B did not get rebuilt.

Importing  the subclass header directly into MGS_B.h gives the desired 
behaviour.

Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.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


How to filter the NSOpenPanel with "Recommended Applications"

2010-05-27 Thread appleBoy chen
Hi All,

I want to show the Panel like Finder's "Choose Application" to let user
slect one application to open with  the file.
Follow is my code:

NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanChooseFiles:YES];
[openPanel setAllowsMultipleSelection:NO];
if([openPanel runModalForTypes:[NSArray arrayWithObjects:@"app",nil]] ==
NSOKButton)
{
 ...
}

And, I want to only show the supported application for the associated file.
Like Finder's "Choose Application" Panel, it can set Eanble to "Recommended
Applications" to filter the applications.  the NSOpenPanel can support it?
or i must usr another solution. thanks for any reply.

best regards
Kakaxi
___

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: behavior of -copy

2010-05-27 Thread Quincey Morris
On May 27, 2010, at 05:59, Ariel Feinerman wrote:

> my question is: what does -copy for immutable
> variant of immutable/mutable objects, for instance NSArray *arrayCopy =
> [array copy]; returns true copy or retains one?

The class of the variable 'arrayCopy' is irrelevant. If the instance being 
copied is a (subclass of) NSMutableArray, then it will use NSMutableArray's 
'copy' implementation, which makes a "true" copy.

If the instance being copied is a (immutable subclass of) NSArray, then it will 
use NSArray's 'copy' implementation, which returns a retained reference to the 
original object.

Note that both of these behaviors are implementation details which are *not* 
guaranteed by the API.

> Or what does happen if
> object itself is immutable and has not setters, but it instance variables is
> mutable and can be changed?

There's no built-in behavior that applies to every class. It's up to each class 
to provide an implementation of 'copy:' (well, actually 'copyWithZone:') if it 
wants to conform to the NSCopying protocol. The current behavior of the Cocoa 
collection classes is as described above. The 'copy' behavior of other objects 
can only be described on a case-by-case basis.

You should take a look at the NSCopying Protocol Reference:


http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Protocols/NSCopying_Protocol/Reference/Reference.html

for a more detailed answer to your question.


___

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: How to filter the NSOpenPanel with "Recommended Applications"

2010-05-27 Thread Quincey Morris
On May 26, 2010, at 19:55, appleBoy chen wrote:

> if([openPanel runModalForTypes:[NSArray arrayWithObjects:@"app",nil]] ==
> NSOKButton)
> {
> ...
> }
> 
> And, I want to only show the supported application for the associated file.
> Like Finder's "Choose Application" Panel, it can set Eanble to "Recommended
> Applications" to filter the applications.  the NSOpenPanel can support it?

Yes, use a delegate. 

To enable or disable items, in 10.5 or earlier, use the 
'panel:shouldShowFilename:' delegate method (documented in the superclass, 
NSSavePanel). In 10.6, use the 'panel:shouldEnableURL:' delegate method, 
documented in the NSOpenSavePanelDelegate protocol.

To determine whether an application is to be enabled or not, you'll need to to 
use Launch Services. There was a thread about this a couple of days ago.


___

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: How to filter the NSOpenPanel with "Recommended Applications"

2010-05-27 Thread Sean McBride
On Thu, 27 May 2010 10:55:51 +0800, appleBoy chen said:

>I want to show the Panel like Finder's "Choose Application" to let user
>slect one application to open with  the file.
>Follow is my code:
>
>NSOpenPanel *openPanel = [NSOpenPanel openPanel];
>[openPanel setCanChooseDirectories:NO];
>[openPanel setCanChooseFiles:YES];
>[openPanel setAllowsMultipleSelection:NO];
>if([openPanel runModalForTypes:[NSArray arrayWithObjects:@"app",nil]] ==
>NSOKButton)
>{
> ...
>}
>
>And, I want to only show the supported application for the associated file.
>Like Finder's "Choose Application" Panel, it can set Eanble to "Recommended
>Applications" to filter the applications.  the NSOpenPanel can support it?
>or i must usr another solution. thanks for any reply.

There is nothing built-in to do exactly that.  You'll need to filter
items yourself, see the docs for NSOpenSavePanelDelegate.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

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: selecting a row of a UITableView programatically

2010-05-27 Thread Alejandro Marcos Aragón
Thanks for answering to my message Luke. I'll try selecting the row in the 
viewDidLoad method.
Regards,

aa

On May 26, 2010, at 7:34 PM, Luke the Hiesterman wrote:

> Since nibs are loaded lazily, controller.unitTableView is probably nil when 
> you call selectRowAtIndexPath:.
> 
> Luke
> 
> On May 26, 2010, at 5:24 PM, Alejandro Marcos Aragón wrote:
> 
>> Hi all,
>> 
>> Can someone tell me why the following code doesn't work?
>> 
>> 
>> - (void) showInfo {
>> 
>>  FlipsideViewController *controller = [[FlipsideViewController alloc] 
>> initWithNibName:@"FlipsideView" bundle:nil];
>>  controller.delegate = self;
>> 
>>  NSUInteger indexes[2] = {0,3};
>>  NSIndexPath * indexPath = [[NSIndexPath alloc] initWithIndexes:indexes 
>> length:2];
>>  [controller.unitTableView selectRowAtIndexPath:indexPath animated:YES 
>> scrollPosition:UITableViewScrollPositionNone];
>>  
>>  UINavigationController *navController = [[UINavigationController alloc] 
>> initWithRootViewController:controller];
>>  [controller release];
>>  
>>  navController.modalTransitionStyle = 
>> UIModalTransitionStyleFlipHorizontal;
>>  [self presentModalViewController:navController animated:YES];
>>  
>>  [navController release];
>>  
>> }
>> 
>> 
>> The unitTableView is part of the FlipsideViewController and it is created in 
>> the first line. Everything is fine, but the row is not selected. What am I 
>> missing??? Thank you all,
>> 
>> aa___
>> 
>> 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/luketheh%40apple.com
>> 
>> This email sent to luket...@apple.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


PMSessionGetCurrentPrinter issue

2010-05-27 Thread Shilpi Aggarwal
On Mac printing, I am facing an issue with getting the current printer name for 
the session.
The recommended call to do the same is 
PMSessionGetCurrentPrinter,
 but this call is always returning me the default printer set in the System 
preferences.

I have even tried using the following code snippet:

PMSessionSetCurrentPMPrinter(session, printer);
PMSessionGetCurrentPrinter(session, &printer);

No matter whatever printer I set during 
PMSessionSetCurrentPMPrinter
 call, it always returns the default printer in PMSessionGetCurrentPrinter call.

Any ideas if I am missing something here?

Thanks,
-Shilpi
___

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: Suppressing visibility in the Dock

2010-05-27 Thread Michael Diehr

On May 24, 2010, at 9:19 AM, Ben Haller wrote:

> On 24-May-10, at 12:30 AM, Ben Haller wrote:
> 
>> On 24-May-10, at 12:12 AM, Ken Thomases wrote:
>> 
>>> I think you can also get away with using LSBackgroundOnly or LSUIElement 
>>> and then, when you want it to be a foreground GUI app, use 
>>> TransformProcessType() to make it one.
>> 
>> This seems pretty plausible.  Somebody else suggested the same thing 
>> off-list.  I'll give it a go and report back once I've got results.
> 
>  For the list: this worked very nicely.  Very easy to set up.  These pages 
> were useful:
> 
> http://www.cocoadev.com/index.pl?TransformProcessType
> http://www.cocoadev.com/index.pl?LSUIElement
> http://www.cocoadev.com/index.pl?LSBackgroundOnly

I use a similar technique and have found it works well, only issue is on 10.4 
it's a bit wonky (if memory serves, LEUIElement doesn't work so you have to use 
LSBackgroundOnly, but then when you TransformProcessTYpe() the dock icon is 
missing the "active app" indicator.   Do test on 10.4 if that's a supported 
platform for you.___

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


removeObjectAtArrangedObjectIndexPath EXC_BAD_ACCESS

2010-05-27 Thread Tony Romano
Below is some code that handles mount and unmount notifications for volumes.  
During an unmount, I want to remove the item from the NSTreeController's 
arrangedObjects list.  The mount sections works fine, it appends to the tree 
any new volumes added.  When I want to unmount it, I go through the process of 
finding which NSTreeNode represents my object, get the index path to the tree 
node and call removeObjectAtArrangedIndexPath:tn .  This is where it access 
faults.  My debug output gives a valid row and the correct IndexPath.  I also 
verified via gdb console that the treenode is the correct item that contains my 
object that represents the volume.  Here is the call stack and the code.  Any 
ideas as to why it is crashing here?

Platform:
Mac OS X10.6.3, XCode 3.2.2

TIA,
-Tony Romano

call stack;
#0  0x7fff87392160 in objc_msgSend_vtable2 ()
#1  0x7fff81c2e4fd in __NSFastEnumerationMutationHandler ()
#2  0x0001316e in -[AppController workspaceNoticationHandler:] 
(self=0x100138d80, _cmd=0x100013844, notification=0x100547650) at 
AppController.m:176
#3  0x7fff82bfd86e in _nsnote_callback ()
#4  0x7fff81b7eaea in __CFXNotificationPost ()
#5  0x7fff81b6b098 in _CFXNotificationPostNotification ()
#6  0x7fff82bf47d8 in -[NSNotificationCenter 
postNotificationName:object:userInfo:] ()
#7  0x7fff828f77ad in volumeObserverCallback ()
#8  0x7fff85adb113 in _FSVolumeObserverCallback ()
#9  0x7fff81b9ac2e in __CFMachPortPerform ()
#10 0x7fff81b73201 in __CFRunLoopRun ()
#11 0x7fff81b718df in CFRunLoopRunSpecific ()
#12 0x7fff8147cada in RunCurrentEventLoopInMode ()
#13 0x7fff8147c8df in ReceiveNextEventCommon ()
#14 0x7fff8147c798 in BlockUntilNextEventMatchingListInMode ()
#15 0x7fff8223aa2a in _DPSNextEvent ()
#16 0x7fff8223a379 in -[NSApplication 
nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#17 0x7fff8220005b in -[NSApplication run] ()
#18 0x7fff821f8d7c in NSApplicationMain ()
#19 0x00011b75 in main (argc=3, argv=0x7fff5fbff7d0) at main.m:13


// Handle mount/unmount volumes
if ([notifyName compare: @"NSWorkspaceDidMountNotification"] == 
NSOrderedSame) {
id volume = [userInfo objectForKey:@"NSWorkspaceVolumeURLKey"];

// create a new node and add it to the volume object then 
append to the content array
Node * volumeMapEntry = [volumeNodes createAndAddNodeFor:volume 
isVol:YES];
NSArray *childNodes = [[outlineController arrangedObjects] 
childNodes];
NSIndexPath * path = [NSIndexPath 
indexPathWithIndex:[childNodes count]];
[outlineController insertObject:volumeMapEntry 
atArrangedObjectIndexPath:path];
}

else if ([notifyName compare: @"NSWorkspaceDidUnmountNotification"] == 
NSOrderedSame) {
id key = [userInfo objectForKey:@"NSWorkspaceVolumeURLKey"];
NSString *volumeName = [[userInfo 
objectForKey:@"NSWorkspaceVolumeURLKey"] absoluteString];

NSArray *childNodes = [[outlineController arrangedObjects] 
childNodes];

for (NSTreeNode *tn in childNodes) {
NSString *nodeName = [[[tn representedObject] nodeURL] 
absoluteString];

if ([nodeName compare:volumeName] == NSOrderedSame) {
NSUInteger row = [[outlineViewController 
outlineView] rowForItem:tn]; //for debug output
NSIndexPath *path = [tn indexPath];
NSLog(@"Row:%d, IndexPath:%@", row, path);
[outlineController 
removeObjectAtArrangedObjectIndexPath:path];
}
}
}

-Tony

___

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: removeObjectAtArrangedObjectIndexPath EXC_BAD_ACCESS

2010-05-27 Thread Nick Zitzmann

On May 27, 2010, at 2:58 PM, Tony Romano wrote:

> Below is some code that handles mount and unmount notifications for volumes.  
> During an unmount, I want to remove the item from the NSTreeController's 
> arrangedObjects list.  The mount sections works fine, it appends to the tree 
> any new volumes added.  When I want to unmount it, I go through the process 
> of finding which NSTreeNode represents my object, get the index path to the 
> tree node and call removeObjectAtArrangedIndexPath:tn .  This is where it 
> access faults.  My debug output gives a valid row and the correct IndexPath.  
> I also verified via gdb console that the treenode is the correct item that 
> contains my object that represents the volume.  Here is the call stack and 
> the code.  Any ideas as to why it is crashing here?

I do:

>   NSArray *childNodes = [[outlineController arrangedObjects] 
> childNodes];
>   
>   for (NSTreeNode *tn in childNodes) {
[...]
>   [outlineController 
> removeObjectAtArrangedObjectIndexPath:path];
>   }
>   }

If you're going to do something like that, then you need to work on a copy of 
the enumerated array. You cannot mutate collection objects that are being 
enumerated.

Nick Zitzmann


___

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


Exit( ) necessary? (oalTouch sample project)

2010-05-27 Thread Philip Mobley
I have a question about the oalTouch example project.

Specifically the sample code uses the exit( ) function after encountering an 
error such as in the sample code below.  

I looked up the OpenAL documentation for alGetError( ) and no where does the 
OpenAL documentation for alGetError( ) mention that an error returned is 
considered fatal and the program must exit.

So what I am wondering is if this is simply a "lazy" example from Apple 
(without any "nice" UI warning errors), and should not actually affect the 
performance of the app.  Obviously if there is an error loading the sound 
resource, the sound cannot play.  

But I am asking this here anyways in the case that there is actually an issue 
where exit( ) is required.



 Excerpt from oalTouch sample 
project
- (void) initBuffer
{
   ALenum  error = AL_NO_ERROR;
   ALenum  format;
   ALsizei size;
   ALsizei freq;

   NSBundle*   bundle = [NSBundle mainBundle];

   // get some audio data from a wave file
   CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle 
pathForResource:@"sound" ofType:@"caf"]] retain];

   if (fileURL)
   {   
   data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
   CFRelease(fileURL);

   if((error = alGetError()) != AL_NO_ERROR) {
   NSLog(@"error loading sound: %x\n", error);
   exit(1);
   }

   // use the static buffer data API
   alBufferDataStaticProc(buffer, format, data, size, freq);

   if((error = alGetError()) != AL_NO_ERROR) {
   NSLog(@"error attaching audio to buffer: %x\n", error);
   }   
   }
   else
   NSLog(@"Could not find file!\n");
}___

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: Exit( ) necessary? (oalTouch sample project)

2010-05-27 Thread Luke the Hiesterman
That is most likely there for simplicity of the code example. Since Touch is in 
the name, I'm assuming this example is for iPhoneOS? If so, please remember 
that exit() should never be called in an iPhone program. Only the user should 
exit your program.

Luke

On May 27, 2010, at 2:37 PM, Philip Mobley wrote:

> I have a question about the oalTouch example project.
> 
> Specifically the sample code uses the exit( ) function after encountering an 
> error such as in the sample code below.  
> 
> I looked up the OpenAL documentation for alGetError( ) and no where does the 
> OpenAL documentation for alGetError( ) mention that an error returned is 
> considered fatal and the program must exit.
> 
> So what I am wondering is if this is simply a "lazy" example from Apple 
> (without any "nice" UI warning errors), and should not actually affect the 
> performance of the app.  Obviously if there is an error loading the sound 
> resource, the sound cannot play.  
> 
> But I am asking this here anyways in the case that there is actually an issue 
> where exit( ) is required.
> 
> 
> 
>  Excerpt from oalTouch sample 
> project
> - (void) initBuffer
> {
>   ALenum  error = AL_NO_ERROR;
>   ALenum  format;
>   ALsizei size;
>   ALsizei freq;
> 
>   NSBundle*   bundle = [NSBundle mainBundle];
> 
>   // get some audio data from a wave file
>   CFURLRef fileURL = (CFURLRef)[[NSURL fileURLWithPath:[bundle 
> pathForResource:@"sound" ofType:@"caf"]] retain];
> 
>   if (fileURL)
>   {   
>   data = MyGetOpenALAudioData(fileURL, &size, &format, &freq);
>   CFRelease(fileURL);
> 
>   if((error = alGetError()) != AL_NO_ERROR) {
>   NSLog(@"error loading sound: %x\n", error);
>   exit(1);
>   }
> 
>   // use the static buffer data API
>   alBufferDataStaticProc(buffer, format, data, size, freq);
> 
>   if((error = alGetError()) != AL_NO_ERROR) {
>   NSLog(@"error attaching audio to buffer: %x\n", error);
>   }   
>   }
>   else
>   NSLog(@"Could not find file!\n");
> }___
> 
> 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/luketheh%40apple.com
> 
> This email sent to luket...@apple.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: Exit( ) necessary? (oalTouch sample project)

2010-05-27 Thread Philip Mobley
On May 27, 2010, at 2:40 PM, Luke the Hiesterman wrote:

> That is most likely there for simplicity of the code example. Since Touch is 
> in the name, I'm assuming this example is for iPhoneOS? If so, please 
> remember that exit() should never be called in an iPhone program. Only the 
> user should exit your program.

Yes, it is for the iPhone, and oalTouch is the only sample project that I am 
aware of to demonstrate OpenAL for iPhone.

___

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: removeObjectAtArrangedObjectIndexPath EXC_BAD_ACCESS

2010-05-27 Thread Tony Romano
Thanks Nick.
On May 27, 2010, at 2:21 PM, Nick Zitzmann wrote:

> 
> On May 27, 2010, at 2:58 PM, Tony Romano wrote:
> 
>> Below is some code that handles mount and unmount notifications for volumes. 
>>  During an unmount, I want to remove the item from the NSTreeController's 
>> arrangedObjects list.  The mount sections works fine, it appends to the tree 
>> any new volumes added.  When I want to unmount it, I go through the process 
>> of finding which NSTreeNode represents my object, get the index path to the 
>> tree node and call removeObjectAtArrangedIndexPath:tn .  This is where it 
>> access faults.  My debug output gives a valid row and the correct IndexPath. 
>>  I also verified via gdb console that the treenode is the correct item that 
>> contains my object that represents the volume.  Here is the call stack and 
>> the code.  Any ideas as to why it is crashing here?
> 
> I do:
> 
>>  NSArray *childNodes = [[outlineController arrangedObjects] 
>> childNodes];
>>  
>>  for (NSTreeNode *tn in childNodes) {
> [...]
>>  [outlineController 
>> removeObjectAtArrangedObjectIndexPath:path];
>>  }
>>  }
> 
> If you're going to do something like that, then you need to work on a copy of 
> the enumerated array. You cannot mutate collection objects that are being 
> enumerated.
> 
> Nick Zitzmann
> 
> 
> 

-Tony

___

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: isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Graham Cox

On 27/05/2010, at 8:36 PM, Ken Thomases wrote:

>   if ([obj isKindOfClass:[NSString class]])
>   // ... use 'obj' as a string
>   else if ([obj isKindOfClass:[NSArray class]])
>   // ... use 'obj' as an array
>   // ... etc. ...


It might also be worth pointing out that writing code structured in this way is 
highly indicative of a failure of design (and I say that obviously realising 
that Ken was only trying to illustrate how to discover an object's type in the 
context of the example, not how best to handle the situation as a whole).

You need to design your code so that if its type is important you can easily 
encode and decode a type indicator along with the data itself, but even then 
it's a bit of a code smell. Perhaps you just need to archive a data structure 
at a higher level so that what pops out when you dearchive is fully formed and 
ready to go, instead of needing to be sorted by type and handled accordingly?


--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: isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Philip Vallone
Hi Graham,

I think Ken's response was exactly what I was looking for. The code snippet I 
posted was just a small example to illustrate my question and ken's was as well.

> Perhaps you just need to archive a data structure at a higher level so that 
> what pops out when you dearchive is fully formed and ready to go, instead of 
> needing to be sorted by type and handled accordingly

This is a relative question, which depends on how the data is coming and going. 
My question comes from the following situation. Suppose I have a GKSession that 
is passing information via Bluetooth. The sender can send any type of 
information (NSString, UIImage etc...). The receiver needs to know how to 
handle this data. If there is a better way... Then how?

I appreciate the feed back and help,

Phil 

 

Regards,

Philip Vallone

On May 27, 2010, at 8:12 PM, Graham Cox  wrote:

> 
> On 27/05/2010, at 8:36 PM, Ken Thomases wrote:
> 
>>  if ([obj isKindOfClass:[NSString class]])
>>  // ... use 'obj' as a string
>>  else if ([obj isKindOfClass:[NSArray class]])
>>  // ... use 'obj' as an array
>>  // ... etc. ...
> 
> 
> It might also be worth pointing out that writing code structured in this way 
> is highly indicative of a failure of design (and I say that obviously 
> realising that Ken was only trying to illustrate how to discover an object's 
> type in the context of the example, not how best to handle the situation as a 
> whole).
> 
> You need to design your code so that if its type is important you can easily 
> encode and decode a type indicator along with the data itself, but even then 
> it's a bit of a code smell. Perhaps you just need to archive a data structure 
> at a higher level so that what pops out when you dearchive is fully formed 
> and ready to go, instead of needing to be sorted by type and handled 
> accordingly?
> 
> 
> --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: isKindofClass with NSData and NSKeyUnarchiver

2010-05-27 Thread Graham Cox

On 28/05/2010, at 10:25 AM, Philip Vallone wrote:

> The sender can send any type of information (NSString, UIImage etc...). The 
> receiver needs to know how to handle this data. If there is a better way... 
> Then how?


If there is an object that already is able to handle the data in whatever form 
it is passed in, you could archive and dearchive that object instead? In other 
words, work at a higher level.

--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: How to filter the NSOpenPanel with "Recommended Applications"

2010-05-27 Thread Tony Romano
Adding to what others have said.

1. Determine a list of applications that can work with the file type.  Use 
Launch Services (LSGetApplicationURLs for URLs).
2. In the your open panel delegate, implement: shouldEnableURL and return YES 
if the application is on the list
3.  You may also have an application that is not listed in the directory that 
is currently showing, therefore, you should consider enabling all the 
directories as well so the user can navigate to the app under the correct 
directory.


-Tony

On May 26, 2010, at 7:55 PM, appleBoy chen wrote:

> Hi All,
> 
> I want to show the Panel like Finder's "Choose Application" to let user
> slect one application to open with  the file.
> Follow is my code:
> 
> NSOpenPanel *openPanel = [NSOpenPanel openPanel];
> [openPanel setCanChooseDirectories:NO];
> [openPanel setCanChooseFiles:YES];
> [openPanel setAllowsMultipleSelection:NO];
> if([openPanel runModalForTypes:[NSArray arrayWithObjects:@"app",nil]] ==
> NSOKButton)
> {
> ...
> }
> 
> And, I want to only show the supported application for the associated file.
> Like Finder's "Choose Application" Panel, it can set Eanble to "Recommended
> Applications" to filter the applications.  the NSOpenPanel can support it?
> or i must usr another solution. thanks for any reply.
> 
> best regards
> Kakaxi
> ___
> 
> 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/tonyrom%40hotmail.com
> 
> This email sent to tony...@hotmail.com
> 

-Tony

___

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


Generating PDF images

2010-05-27 Thread Graham Cox
What's the current recommended practice for generating a pdf image without 
reference to any view or existing context? (Has to work on 10.5+)

The situation is that I have an object that can return a preview image of 
itself which it currently does by rendering into a bitmap graphics context 
associated with a NSBitMapImageRep, both of which I create on the fly. This is 
then put into an NSImage and returned.

This approach forces me to choose a resolution up front which is a bit daft 
because the object itself is a vector graphic, and then the resulting image 
(which ends up getting used for a variety of purposes such as creating an icon 
and a QuickLook preview) has a fixed res and is much larger than it needs to be.

So much better if I could just return a PDF image, but Cocoa appears to make 
this unnecessarily hard.

Can I not create a PDF context, associate that with a NSPDFImageRep instead? It 
appears I'm forced to use NSPrintOperation to do this which is slightly weird 
as this has nothing to do with printing, nor do I have a view readily available 
to attach to the NSPrintOperation. Surely there's a more straightforward way 
than going round the houses like this?

Pointers to what I should be looking at greatly appreciated.

--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: Generating PDF images

2010-05-27 Thread Kyle Sluder

On May 27, 2010, at 6:20 PM, Graham Cox  wrote:

Can I not create a PDF context, associate that with a NSPDFImageRep  
instead? It appears I'm forced to use NSPrintOperation to do this  
which is slightly weird as this has nothing to do with printing, nor  
do I have a view readily available to attach to the  
NSPrintOperation. Surely there's a more straightforward way than  
going round the houses like this?


I believe we create a PDF CGContext, wrap it in an NSGraphicsVontext,  
and use +setContext: to get our nice vectory goodness.


But I'm going from memory here, and I didn't write that code.

--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: Generating PDF images (+followup question)

2010-05-27 Thread Graham Cox
Thanks Kyle, that seems to look like a fruitful approach. I'm doing the 
following, which appears to be enough, i.e. it works. But should I be doing 
anything else?


NSSize size = [self bounds].size;
NSRect destRect = NSZeroRect;

destRect.size = size;

NSMutableData* pdfData = [NSMutableData data];
CGDataConsumerRef consumer = 
CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData );
CGRect mediaBox = CGRectMake( 0, 0, size.width, size.height );
CGContextRef pdfContext = CGPDFContextCreate( consumer, &mediaBox, NULL 
);
CGDataConsumerRelease( consumer );

NSGraphicsContext* newGC = [NSGraphicsContext 
graphicsContextWithGraphicsPort:pdfContext flipped:YES];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:newGC];

CGPDFContextBeginPage( pdfContext, NULL );

[self drawContentInRect:destRect fromRect:NSZeroRect withStyle:nil];

CGPDFContextEndPage( pdfContext );

[NSGraphicsContext restoreGraphicsState];

CGPDFContextClose( pdfContext );
CGContextRelease( pdfContext );

return pdfData;


This leads me on to a further question about correctly handling flippedness, 
which quite honestly has me really confused.

The objects I'm drawing generally assume a flipped context, i.e. my view is 
flipped and so is my entire coordinate system all the way down. I have not run 
into any problems with that anywhere, it all works fine. But when I come to 
generate the PDF above, I do have some flipping confusion.

I flip the context to match the expectation of the object itself. Thus text 
draws relatively the right way up and in the right place.

If I take that (flipped) PDF data, use it to create an NSPDFImageRep and add it 
to an NSImage, should the image be flipped or not? (Bear in mind this needs to 
work on 10.5, so the newer flipped stuff is unavailable to help sort this 
confusion out).

If I take the resulting image and display it in a cell, what should the cell do 
about flipping? For example, if I put the image into NSImageView, it works 
correctly and displays right way up. If I write the image to disk it is 
imported into Preview right way up. But I have a couple of custom cells that 
draw images that show the image wrong way up. What are these cells doing wrong 
that I'm not getting? Should they do anything - maybe just leaving flippedness 
of the image alone rather than try an match it to the control's context 
flippedness is right? I just don't know. I've tried all combos I can think of 
and none of them quite nails it.

--Graham







On 28/05/2010, at 11:24 AM, Kyle Sluder wrote:

> On May 27, 2010, at 6:20 PM, Graham Cox  wrote:
> 
>> Can I not create a PDF context, associate that with a NSPDFImageRep instead? 
>> It appears I'm forced to use NSPrintOperation to do this which is slightly 
>> weird as this has nothing to do with printing, nor do I have a view readily 
>> available to attach to the NSPrintOperation. Surely there's a more 
>> straightforward way than going round the houses like this?
> 
> I believe we create a PDF CGContext, wrap it in an NSGraphicsVontext, and use 
> +setContext: to get our nice vectory goodness.
> 
> But I'm going from memory here, and I didn't write that code.
> 
> --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: Activating application raises windows meant to be invisible

2010-05-27 Thread Peter Ammon
If a window is ordered out, AppKit will not order it back in when the app is 
activated.  Is it possible that a different window is created, or that the 
window was not ordered out to begin with?

I'm confused when you say that an ordered-out window is the key window.  That 
should not be possible.

Is it possible that one of the windows is set to hide on deactivate?  The 
visibility of hideOnDeactivate windows is controlled by the window server.  A 
window that is hideOnDeactivate does not get ordered out when the app is 
deactivated: it is merely hidden.

Hope this helps,
-Peter

On May 27, 2010, at 5:44 AM, David Reitter wrote:

> How can I keep invisible windows invisible when my application is raised?
> 
> My application can end up with only one NSWindow "A" that is invisible 
> ([NSWindow orderOut]).  This window is the key window.  The application may 
> also have other windows ("B") that are iconified.
> 
> I find that when switching back to the application, window A is always made 
> visible (provided I am on the same Space as the window).  How do I control 
> that?
> I would get my application to de-iconify B instead.
> 
> Window A is raised even before my 
> applicationShouldHandleReopen:hasVisibleWindows: are 
> applicationDidBecomeActive: are sent.  I have also unsuccessfully tried to 
> implement [NSWindow orderFront] to override the behavior.
> 
> How would I got about keeping the window hidden?
> 
> Thanks for your help.___
> 
> 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/pammon%40apple.com
> 
> This email sent to pam...@apple.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: Generating PDF images (+followup question)

2010-05-27 Thread Ken Ferry
On Thu, May 27, 2010 at 8:40 PM, Graham Cox  wrote:

> Thanks Kyle, that seems to look like a fruitful approach. I'm doing the
> following, which appears to be enough, i.e. it works. But should I be doing
> anything else?
>
>
>NSSize size = [self bounds].size;
>NSRect destRect = NSZeroRect;
>
>destRect.size = size;
>
>NSMutableData* pdfData = [NSMutableData data];
>CGDataConsumerRef consumer =
> CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData );
>CGRect mediaBox = CGRectMake( 0, 0, size.width, size.height );
>CGContextRef pdfContext = CGPDFContextCreate( consumer, &mediaBox,
> NULL );
>CGDataConsumerRelease( consumer );
>
>NSGraphicsContext* newGC = [NSGraphicsContext
> graphicsContextWithGraphicsPort:pdfContext flipped:YES];
>[NSGraphicsContext saveGraphicsState];
>[NSGraphicsContext setCurrentContext:newGC];
>
>CGPDFContextBeginPage( pdfContext, NULL );
>
>[self drawContentInRect:destRect fromRect:NSZeroRect withStyle:nil];
>
>CGPDFContextEndPage( pdfContext );
>
>[NSGraphicsContext restoreGraphicsState];
>
>CGPDFContextClose( pdfContext );
>CGContextRelease( pdfContext );
>
>return pdfData;
>
>
> This leads me on to a further question about correctly handling
> flippedness, which quite honestly has me really confused.
>
> The objects I'm drawing generally assume a flipped context, i.e. my view is
> flipped and so is my entire coordinate system all the way down. I have not
> run into any problems with that anywhere, it all works fine. But when I come
> to generate the PDF above, I do have some flipping confusion.
>
> I flip the context to match the expectation of the object itself. Thus text
> draws relatively the right way up and in the right place.
>
> If I take that (flipped) PDF data, use it to create an NSPDFImageRep and
> add it to an NSImage, should the image be flipped or not? (Bear in mind this
> needs to work on 10.5, so the newer flipped stuff is unavailable to help
> sort this confusion out).
>

Hi Graham,

(First, for those following along, flipped images are deprecated in 10.6
along with -[NSImage setFlipped:].)

I agree, flipped images are confusing, and you can more or less think of
them as deprecated prior to 10.6 as well.  This weblog post does a nice job
of explaining what everything means and what to do about it: <
http://www.noodlesoft.com/blog/2009/02/02/understanding-flipped-coordinate-systems/>.
 This material is also covered in depth in the WWDC 2007 talk, Cocoa Drawing
Techniques.

The only reason I can think of off the top of my head to call -setFlipped:
on an NSImage is if you plan to lockFocus on the image and you want the
context to be a flipped context during drawing.  This use case is addressed
in 10.6 by the addition of -[NSImage lockFocusFlipped:] which gives you a
flipped context without doing anything to the internal state of the image.

-Ken
Cocoa Frameworks



> If I take the resulting image and display it in a cell, what should the
> cell do about flipping? For example, if I put the image into NSImageView, it
> works correctly and displays right way up. If I write the image to disk it
> is imported into Preview right way up. But I have a couple of custom cells
> that draw images that show the image wrong way up. What are these cells
> doing wrong that I'm not getting? Should they do anything - maybe just
> leaving flippedness of the image alone rather than try an match it to the
> control's context flippedness is right? I just don't know. I've tried all
> combos I can think of and none of them quite nails it.
>
> --Graham
>
>
>
>
>
>
>
> On 28/05/2010, at 11:24 AM, Kyle Sluder wrote:
>
> > On May 27, 2010, at 6:20 PM, Graham Cox  wrote:
> >
> >> Can I not create a PDF context, associate that with a NSPDFImageRep
> instead? It appears I'm forced to use NSPrintOperation to do this which is
> slightly weird as this has nothing to do with printing, nor do I have a view
> readily available to attach to the NSPrintOperation. Surely there's a more
> straightforward way than going round the houses like this?
> >
> > I believe we create a PDF CGContext, wrap it in an NSGraphicsVontext, and
> use +setContext: to get our nice vectory goodness.
> >
> > But I'm going from memory here, and I didn't write that code.
> >
> > --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/kenferry%40gmail.com
>
> This email sent to kenfe...@gmail.com
>
___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderator

Stealing settings from Mail.app

2010-05-27 Thread Chris Idou


I've got an app that needs to send out emails. I'm trying to import mail 
settings from Mail.app. For some reason my keychain has passwords for 
smtp.gmail.com, but not for smtp.me.com. Does anyone know where Mail.app stores 
other passwords? Or why my keychain has smtp.gmail.com passwords, but not 
passwords for other smtp servers I have setup in Mail.app?


 
___

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: Generating PDF images (+followup question)

2010-05-27 Thread Graham Cox
Thanks for the link Ken, though confusion still persists.

Seems to be saying don't use -setFlipped: unless you really know what you're 
doing. That concurs with your own advice about not using setFlipped unless 
you're locking focus on the image to get a flipped context for drawing. I'm 
not, since I generate my PDF in a context I create for the purpose, THEN add 
the image rep to an image.

So on the basis that I don't know what I'm doing, I've removed all calls to 
[NSImage setFlipped:] anywhere. In the PDF generating code quoted, I do pass 
YES for flipped because the object itself expects a flipped coordinate system, 
by which I simply mean that when I draw something  BELOW something else, it has 
a GREATER Y coordinate value.

Having no flipping anywhere now, unfortunately it's still all over the place.

First, if I ask the NSPDFImageRep created using the data generated below for 
its -PDFRepresentation, and write it to disk as a PDF file, it's now inverted. 
Objects are placed in the correct positions relative to one-another, but the 
entire image is upside-down, including any text.

So, I try setting the image to flipped when I add the single PDF image rep to 
it:

NSPDFImageRep* rep = [NSPDFImageRep imageRepWithData:[self 
pdf]];
[image addRepresentation:rep];
[image setFlipped:YES];

Now this image appears right-side up in NSImageView, but still writes an 
inverted PDF file and comes into Preview inverted. I can't really see how this 
is possible, since raw PDF data doesn't have any concept of 'flipped', does it? 
That surely means that the original PDF generation is wrong, but if I pass NO 
for flipped, not only is everything still upside-down but text is screwed as 
well, with each glyph individually inverted (which means that if the whole 
image is turned right-way up, any text is inverted).

I've read all the documentation on flipped coordinates and now the blog post as 
well. I'm afraid I'm just as confused as ever. What I need is a clear way 
through this mess. Turning off all flippedness seemed to be that but isn't. Now 
I have no idea what I need to flip and when.

--Graham



On 28/05/2010, at 3:20 PM, Ken Ferry wrote:

> On Thu, May 27, 2010 at 8:40 PM, Graham Cox  wrote:

>NSSize size = [self bounds].size;
>NSRect destRect = NSZeroRect;
> 
>destRect.size = size;
> 
>NSMutableData* pdfData = [NSMutableData data];
>CGDataConsumerRef consumer = 
> CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData );
>CGRect mediaBox = CGRectMake( 0, 0, size.width, size.height );
>CGContextRef pdfContext = CGPDFContextCreate( consumer, &mediaBox, 
> NULL );
>CGDataConsumerRelease( consumer );
> 
>NSGraphicsContext* newGC = [NSGraphicsContext 
> graphicsContextWithGraphicsPort:pdfContext flipped:YES];
>[NSGraphicsContext saveGraphicsState];
>[NSGraphicsContext setCurrentContext:newGC];
> 
>CGPDFContextBeginPage( pdfContext, NULL );
> 
>[self drawContentInRect:destRect fromRect:NSZeroRect withStyle:nil];
> 
>CGPDFContextEndPage( pdfContext );
> 
>[NSGraphicsContext restoreGraphicsState];
> 
>CGPDFContextClose( pdfContext );
>CGContextRelease( pdfContext );
> 
>return pdfData;
> 
> 
> Hi Graham,
> 
> (First, for those following along, flipped images are deprecated in 10.6 
> along with -[NSImage setFlipped:].) 
> 
> I agree, flipped images are confusing, and you can more or less think of them 
> as deprecated prior to 10.6 as well.  This weblog post does a nice job of 
> explaining what everything means and what to do about it: 
> .
>   This material is also covered in depth in the WWDC 2007 talk, Cocoa Drawing 
> Techniques.
> 
> The only reason I can think of off the top of my head to call -setFlipped: on 
> an NSImage is if you plan to lockFocus on the image and you want the context 
> to be a flipped context during drawing.  This use case is addressed in 10.6 
> by the addition of -[NSImage lockFocusFlipped:] which gives you a flipped 
> context without doing anything to the internal state of the image.  
> 
> -Ken
> Cocoa Frameworks

___

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: Generating PDF images (+followup question)

2010-05-27 Thread Ken Ferry
Did you read the explanation of flipped contexts vs flipped images, and how
to draw an image right side up into a flipped context?

Flipped contexts are not deprecated.

Do you have or can you obtain access to the 2007 WWDC videos? :-)

-Ken

On Thu, May 27, 2010 at 11:11 PM, Graham Cox  wrote:

> Thanks for the link Ken, though confusion still persists.
>
> Seems to be saying don't use -setFlipped: unless you really know what
> you're doing. That concurs with your own advice about not using setFlipped
> unless you're locking focus on the image to get a flipped context for
> drawing. I'm not, since I generate my PDF in a context I create for the
> purpose, THEN add the image rep to an image.
>
> So on the basis that I don't know what I'm doing, I've removed all calls to
> [NSImage setFlipped:] anywhere. In the PDF generating code quoted, I do pass
> YES for flipped because the object itself expects a flipped coordinate
> system, by which I simply mean that when I draw something  BELOW something
> else, it has a GREATER Y coordinate value.
>
> Having no flipping anywhere now, unfortunately it's still all over the
> place.
>
> First, if I ask the NSPDFImageRep created using the data generated below
> for its -PDFRepresentation, and write it to disk as a PDF file, it's now
> inverted. Objects are placed in the correct positions relative to
> one-another, but the entire image is upside-down, including any text.
>
> So, I try setting the image to flipped when I add the single PDF image rep
> to it:
>
>NSPDFImageRep* rep = [NSPDFImageRep imageRepWithData:[self
> pdf]];
>[image addRepresentation:rep];
>[image setFlipped:YES];
>
> Now this image appears right-side up in NSImageView, but still writes an
> inverted PDF file and comes into Preview inverted. I can't really see how
> this is possible, since raw PDF data doesn't have any concept of 'flipped',
> does it? That surely means that the original PDF generation is wrong, but if
> I pass NO for flipped, not only is everything still upside-down but text is
> screwed as well, with each glyph individually inverted (which means that if
> the whole image is turned right-way up, any text is inverted).
>
> I've read all the documentation on flipped coordinates and now the blog
> post as well. I'm afraid I'm just as confused as ever. What I need is a
> clear way through this mess. Turning off all flippedness seemed to be that
> but isn't. Now I have no idea what I need to flip and when.
>
> --Graham
>
>
>
> On 28/05/2010, at 3:20 PM, Ken Ferry wrote:
>
> > On Thu, May 27, 2010 at 8:40 PM, Graham Cox 
> wrote:
>
> >NSSize size = [self bounds].size;
> >NSRect destRect = NSZeroRect;
> >
> >destRect.size = size;
> >
> >NSMutableData* pdfData = [NSMutableData data];
> >CGDataConsumerRef consumer =
> CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData );
> >CGRect mediaBox = CGRectMake( 0, 0, size.width, size.height );
> >CGContextRef pdfContext = CGPDFContextCreate( consumer, &mediaBox,
> NULL );
> >CGDataConsumerRelease( consumer );
> >
> >NSGraphicsContext* newGC = [NSGraphicsContext
> graphicsContextWithGraphicsPort:pdfContext flipped:YES];
> >[NSGraphicsContext saveGraphicsState];
> >[NSGraphicsContext setCurrentContext:newGC];
> >
> >CGPDFContextBeginPage( pdfContext, NULL );
> >
> >[self drawContentInRect:destRect fromRect:NSZeroRect
> withStyle:nil];
> >
> >CGPDFContextEndPage( pdfContext );
> >
> >[NSGraphicsContext restoreGraphicsState];
> >
> >CGPDFContextClose( pdfContext );
> >CGContextRelease( pdfContext );
> >
> >return pdfData;
> >
> >
> > Hi Graham,
> >
> > (First, for those following along, flipped images are deprecated in 10.6
> along with -[NSImage setFlipped:].)
> >
> > I agree, flipped images are confusing, and you can more or less think of
> them as deprecated prior to 10.6 as well.  This weblog post does a nice job
> of explaining what everything means and what to do about it: <
> http://www.noodlesoft.com/blog/2009/02/02/understanding-flipped-coordinate-systems/>.
>  This material is also covered in depth in the WWDC 2007 talk, Cocoa Drawing
> Techniques.
> >
> > The only reason I can think of off the top of my head to call
> -setFlipped: on an NSImage is if you plan to lockFocus on the image and you
> want the context to be a flipped context during drawing.  This use case is
> addressed in 10.6 by the addition of -[NSImage lockFocusFlipped:] which
> gives you a flipped context without doing anything to the internal state of
> the image.
> >
> > -Ken
> > Cocoa Frameworks
>
>
___

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://list

Re: Generating PDF images (+followup question)

2010-05-27 Thread Ken Ferry
(Also, again for others following along, on 10.6 you just pass YES for
respectFlipped in -[NSImage
drawInRect:fromRect:operation:fraction:respectFlipped:hints:].  The
implementation is quite similar to the method Paul gives in the post.)

On Thu, May 27, 2010 at 11:17 PM, Ken Ferry  wrote:

> Did you read the explanation of flipped contexts vs flipped images, and how
> to draw an image right side up into a flipped context?
>
> Flipped contexts are not deprecated.
>
> Do you have or can you obtain access to the 2007 WWDC videos? :-)
>
> -Ken
>
>
> On Thu, May 27, 2010 at 11:11 PM, Graham Cox wrote:
>
>> Thanks for the link Ken, though confusion still persists.
>>
>> Seems to be saying don't use -setFlipped: unless you really know what
>> you're doing. That concurs with your own advice about not using setFlipped
>> unless you're locking focus on the image to get a flipped context for
>> drawing. I'm not, since I generate my PDF in a context I create for the
>> purpose, THEN add the image rep to an image.
>>
>> So on the basis that I don't know what I'm doing, I've removed all calls
>> to [NSImage setFlipped:] anywhere. In the PDF generating code quoted, I do
>> pass YES for flipped because the object itself expects a flipped coordinate
>> system, by which I simply mean that when I draw something  BELOW something
>> else, it has a GREATER Y coordinate value.
>>
>> Having no flipping anywhere now, unfortunately it's still all over the
>> place.
>>
>> First, if I ask the NSPDFImageRep created using the data generated below
>> for its -PDFRepresentation, and write it to disk as a PDF file, it's now
>> inverted. Objects are placed in the correct positions relative to
>> one-another, but the entire image is upside-down, including any text.
>>
>> So, I try setting the image to flipped when I add the single PDF image rep
>> to it:
>>
>>NSPDFImageRep* rep = [NSPDFImageRep imageRepWithData:[self
>> pdf]];
>>[image addRepresentation:rep];
>>[image setFlipped:YES];
>>
>> Now this image appears right-side up in NSImageView, but still writes an
>> inverted PDF file and comes into Preview inverted. I can't really see how
>> this is possible, since raw PDF data doesn't have any concept of 'flipped',
>> does it? That surely means that the original PDF generation is wrong, but if
>> I pass NO for flipped, not only is everything still upside-down but text is
>> screwed as well, with each glyph individually inverted (which means that if
>> the whole image is turned right-way up, any text is inverted).
>>
>> I've read all the documentation on flipped coordinates and now the blog
>> post as well. I'm afraid I'm just as confused as ever. What I need is a
>> clear way through this mess. Turning off all flippedness seemed to be that
>> but isn't. Now I have no idea what I need to flip and when.
>>
>> --Graham
>>
>>
>>
>> On 28/05/2010, at 3:20 PM, Ken Ferry wrote:
>>
>> > On Thu, May 27, 2010 at 8:40 PM, Graham Cox 
>> wrote:
>>
>> >NSSize size = [self bounds].size;
>> >NSRect destRect = NSZeroRect;
>> >
>> >destRect.size = size;
>> >
>> >NSMutableData* pdfData = [NSMutableData data];
>> >CGDataConsumerRef consumer =
>> CGDataConsumerCreateWithCFData((CFMutableDataRef) pdfData );
>> >CGRect mediaBox = CGRectMake( 0, 0, size.width, size.height );
>> >CGContextRef pdfContext = CGPDFContextCreate( consumer,
>> &mediaBox, NULL );
>> >CGDataConsumerRelease( consumer );
>> >
>> >NSGraphicsContext* newGC = [NSGraphicsContext
>> graphicsContextWithGraphicsPort:pdfContext flipped:YES];
>> >[NSGraphicsContext saveGraphicsState];
>> >[NSGraphicsContext setCurrentContext:newGC];
>> >
>> >CGPDFContextBeginPage( pdfContext, NULL );
>> >
>> >[self drawContentInRect:destRect fromRect:NSZeroRect
>> withStyle:nil];
>> >
>> >CGPDFContextEndPage( pdfContext );
>> >
>> >[NSGraphicsContext restoreGraphicsState];
>> >
>> >CGPDFContextClose( pdfContext );
>> >CGContextRelease( pdfContext );
>> >
>> >return pdfData;
>> >
>> >
>> > Hi Graham,
>> >
>> > (First, for those following along, flipped images are deprecated in 10.6
>> along with -[NSImage setFlipped:].)
>> >
>> > I agree, flipped images are confusing, and you can more or less think of
>> them as deprecated prior to 10.6 as well.  This weblog post does a nice job
>> of explaining what everything means and what to do about it: <
>> http://www.noodlesoft.com/blog/2009/02/02/understanding-flipped-coordinate-systems/>.
>>  This material is also covered in depth in the WWDC 2007 talk, Cocoa Drawing
>> Techniques.
>> >
>> > The only reason I can think of off the top of my head to call
>> -setFlipped: on an NSImage is if you plan to lockFocus on the image and you
>> want the context to be a flipped context during drawing.  This use case is
>> addressed in 10.6 by the addition of -[NSImage lockFocusFlipped:] which
>> gi

six things I wasn't able to do with Cocoa

2010-05-27 Thread Bill Appleton
hi all,


I just ported a huge code base to Cocoa, Core Graphics, Core Audio, and
QuickTime. Basically I had a good experience, but there were some things i
noticed that i couldn't do easily in Cocoa or any other 64 bit OSX API.

So just in case anyone knows a way to do the things listed below please let
me know:


*1) I can't hide a file, or test if a file is hidden*

I had to resort to FSGetCatalogInfo -- there is no way to do it through
NSFileManager, etc. Right?


*2)** **I **can't **get the current caret blink rate in milliseconds*

I used to call GetCaretTime, but now I just use 500 milliseconds. Eeek!
Where is the current blink rate? Please don't tell me I don't need it, we
implement our own scripting engine, etc.


*3)** **I **can't get t**he right dimensions for a QuickTime movie or poster
*

I used to call GetMovieBox, so I tried using [QTMovie posterImage] but the
NSImage reported a width and height of 100, and then my movie poster was
really pixelated. How do I get a decent looking movie poster? How do I get
the original dimensions for movie playback?


*4)** **I **can't call the printing code*

I know, the printing code calls me. But other platforms don't work like
this. I eventually used Core Printing and the Cocoa dialogs by sub-classing
and faking out NSPrintPanel. Is there a better way?


*5)** **I **can't create a simple list*

I did it the only way I could -- with a table that has one column, etc. Man
that was painful for a simple list. Is there a better way?


*6)** **I **can't get the height of some wrapped text*

I had to use the layout manager and some major rocket science to get this to
work right. I'm not saying Text Edit was great, but at least it knows how
tall the text field is.




Thanks!


Bill Appleton
___

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: Generating PDF images (+followup question)

2010-05-27 Thread Graham Cox

On 28/05/2010, at 4:17 PM, Ken Ferry wrote:

> Did you read the explanation of flipped contexts vs flipped images, and how 
> to draw an image right side up into a flipped context?
> 
> Flipped contexts are not deprecated.

I understand that contexts can (still) be flipped.

Let's break this down a bit, since I'm fighting two problems simultaneously 
here. First, PDF File generation.

Using the code I quoted, I generate PDF data in a flipped context. The flipped 
context matches the coordinate system that drawn objects expect. As such, 
objects and text are all positioned in the correct relative locations.

If I write the PDF data immediately to a file, no NSImage or rep involved, 
result is an upside down PDF file when it's opened in Preview.

If I generate the PDF data in a non-flipped context, the PDF File is still 
upside down, with the added problem that text glyphs are inverted individually.

So at no point have I done anything with this image like draw it anywhere. How 
can it even be possible for PDF data in a file to be inverted? The problem 
appears to be with the PDF generation, so what's wrong there?


> Do you have or can you obtain access to the 2007 WWDC videos? :-)
> 


Not sure - will try to find them. So far a search on ADC brings up just one 
result and it's in Japanese...

--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


Where is zlib located?

2010-05-27 Thread Tito Ciuro
Hello,

I'm trying to incorporate zip-framework 
(http://code.google.com/p/zip-framework/) in my project. When I compile the 
sources in Xcode I see this error:

> "inflate", referenced from:
> -readFromEntry:buffer:length: in ZipArchive.o
> 
> "inflateInit2", referenced from: -entryNamed: in ZipArchive.o
> 
> ld: symbol(s) not found collect2: ld returned 1 exit status

The sources import zlib.h, so I guess I need to add zlib to my project, but I 
cannot find it. Where is it located?

Thanks,

-- Tito
___

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: Where is zlib located?

2010-05-27 Thread Roland King
libz.dylib

it's the last thing listed in the list if I go 'add framework' -> 'existing 
frameworks'. 


On 28-May-2010, at 2:40 PM, Tito Ciuro wrote:

> Hello,
> 
> I'm trying to incorporate zip-framework 
> (http://code.google.com/p/zip-framework/) in my project. When I compile the 
> sources in Xcode I see this error:
> 
>> "inflate", referenced from:
>> -readFromEntry:buffer:length: in ZipArchive.o
>> 
>> "inflateInit2", referenced from: -entryNamed: in ZipArchive.o
>> 
>> ld: symbol(s) not found collect2: ld returned 1 exit status
> 
> The sources import zlib.h, so I guess I need to add zlib to my project, but I 
> cannot find it. Where is it located?
> 
> Thanks,
> 
> -- Tito
> ___
> 
> 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/rols%40rols.org
> 
> This email sent to r...@rols.org

___

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