Re: How to get tiff from clipboard and convert to bmp?

2010-04-02 Thread zhiy xue

Thanks Ken, I have tried it and it works well for me.


On Apr 2, 2010, at 1:15 PM, Ken Ferry wrote:

On Thu, Apr 1, 2010 at 8:44 PM, Kyle Sluder   
wrote:

On Thu, Apr 1, 2010 at 7:35 PM, zhiy xue  wrote:
> I want to support get *.tiff data from clipboard, and convert it  
to bmp

> format. Below is my code, but it will crash in
> GetGraphicsImporterForDataRef. Could you please help? Many thanks  
for your

> help.

You shouldn't be using any of this QuickTime stuff. Use ImageIO.

ImageIO is fine, but you can do this operation with Cocoa APIs.   
It's the same thing under the hood.


Not tested:

NSBitmapImageRep *bitmap = [[[NSBitmapImageRep alloc]  
initWithData:tiffData] autorelease];
NSData *bmpData = [bitmap representationUsingType:NSBMPFileType  
properties:props];



And this would not be the appropriate list for help with either
QuickTime or ImageIO.

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


Alternative startup for application

2010-04-02 Thread Gideon King
Hi,

I would like to have an application I am working on to be able to start up in 
the normal way from the finder, but also have an alternative startup that users 
can access in some way, where I will display a panel that most users wouldn't 
normally want to see.

Issues I am having with this are:

1. I'm not sure what keyboard or mouse options could be used for this, since 
all the character keys change the selection in Finder, and all the normal 
modifier keys are used for special functions. So first question is how I can 
differentiate this special mode open from a normal open?

2. If the application is started up in this special way, how would I be able to 
detect it, seeing as there is no current event to query?

...or is there some other mechanism I could be using instead?

Thanks

Gideon




___

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


NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-02 Thread David Hoerl

Objects:
 - NSManagedObject *item - some managaged object
 - NSArray *attributes - an array of the item's attributes

Desired Result:
 - a possibly smaller array of attribites where [item valueForKey:attribute>] != nil.


In code, I can simply iterate over the keys, perform the valueForKey, 
and skip nil values. I played around with expressions and predicates to 
solve this, to no avail.


I completely understand that the code solution is probably the way to go 
- however, I'd be interested to know if a solution using NSArray's 
filteredArrayWithPredicate and/or some combination of predicates and 
expressions could provide the answer - as an academic exercise.


David
___

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: NSDocument and the dreaded "The location of the document XXX cannot be determined"

2010-04-02 Thread Jerry Krinock
On 2010 Apr 01, at 13:50, Martin Wierschin wrote:

> I should say that I've overridden my NSDocument's save methods

Indeed, you're playing with a highly crafted system there.  After adding a 
"Save As Move" command to an application, I was getting a different but related 
warning, something like "Document has been moved, do you really want to save it 
to a new location?"  The solution was to sprinkle in an extra invocation of 
saveToURL:ofType:forSaveOperation:error: immediately after setFileURL:.

> Any help on this would be much appreciated.

If you've not done so already, pull up the "Document-Based Applications 
Overview" and read "Message Flow in the Document Architecture".  It might help. 
 You could maybe set some breakpoints.

If you figure it out, please post the answer for the list archives.  I may need 
it someday :)

___

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: NSDocument and the dreaded "The location of the document XXX cannot be determined"

2010-04-02 Thread Joar Wingfors

On 1 apr 2010, at 13.50, Martin Wierschin wrote:

> Any help on this would be much appreciated; I've spent way too long on this 
> silly thing already.


Please file a bug report where you outline what you're trying to do:



j o a r


___

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: Alternative startup for application

2010-04-02 Thread Jens Alfke

On Apr 2, 2010, at 1:45 AM, Gideon King wrote:

> 1. I'm not sure what keyboard or mouse options could be used for this, since 
> all the character keys change the selection in Finder, and all the normal 
> modifier keys are used for special functions. So first question is how I can 
> differentiate this special mode open from a normal open?

The Option key is the usual thing. iTunes and iPhoto recognize it at startup, 
for example.

> 2. If the application is started up in this special way, how would I be able 
> to detect it, seeing as there is no current event to query?

I would have said GetKeys(), but it seems to have been deprecated and removed 
in the eyeblink [read: decade] since I last used Carbon. There must be some 
modern equivalent for reading the current state of the keyboard?

—Jens___

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: Alternative startup for application

2010-04-02 Thread Ashley Clark
On Apr 2, 2010, at 10:30 AM, Jens Alfke wrote:

> On Apr 2, 2010, at 1:45 AM, Gideon King wrote:
> 
>> 1. I'm not sure what keyboard or mouse options could be used for this, since 
>> all the character keys change the selection in Finder, and all the normal 
>> modifier keys are used for special functions. So first question is how I can 
>> differentiate this special mode open from a normal open?
> 
> The Option key is the usual thing. iTunes and iPhoto recognize it at startup, 
> for example.
> 
>> 2. If the application is started up in this special way, how would I be able 
>> to detect it, seeing as there is no current event to query?
> 
> I would have said GetKeys(), but it seems to have been deprecated and removed 
> in the eyeblink [read: decade] since I last used Carbon. There must be some 
> modern equivalent for reading the current state of the keyboard?


This works in Snow Leopard and Leopard (I believe).


- (void)applicationDidFinishLaunching:(NSNotification *)notif {
CGEventRef event = CGEventCreate(NULL);
CGEventFlags modifiers = CGEventGetFlags(event);
CFRelease(event);

CGEventFlags flags = (kCGEventFlagMaskAlternate | kCGEventFlagMaskControl);
if ((modifiers & flags) == flags)
[self doSomethingSpecial];
}


Ashley



___

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: Creating WebView in code

2010-04-02 Thread Nick Zitzmann

On Apr 1, 2010, at 8:17 PM, Jenny M wrote:

> Great, I'm testing that method now. I get everything built alright,
> but during the print operation (while the print panel is shown), the
> program crashes with the following message in the console:
> 
> -
> Debugger() was called!
> The Debugger has exited due to signal 2 (SIGINT).The Debugger has
> exited due to signal 2 (SIGINT).
> -

That's most likely Flash Player at work, since it's been known to do this. To 
work around it, install a dummy SIGINT handler function that does nothing. See 
the signal man page for details.

> Now, when the print panel IS shown, the preview is blank, so I know
> it's not loading but I can't tell where. Here's the code I'm using..
> --
> NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
> NSSize pageSize = [printInfo paperSize];
> NSRect frame = NSMakeRect(0.0, 0.0, pageSize.width, pageSize.height);
> WebView *myWebView = [[WebView alloc] initWithFrame:frame
> frameName:@"Test Frame" groupName:nil];
> [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL
> URLWithString:@"http://nytimes.com";]]];
> NSView *printView = [[[myWebView mainFrame] frameView] documentView];

You must place the WebView in a window or else it won't render. It's a dumb but 
necessary requirement. So you'll need to also create an NSWindow and add the 
WebView as a subview of its content view, and that ought to work.

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


Re: NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-02 Thread Dave DeLong
I can't think of a way to do this without iterating over the entire array.  It 
*might* be possible using key-value coding and fancy keypaths and whatnot, but 
iteration is going to be far simpler to implement and understand.

Dave

On Apr 2, 2010, at 8:27 AM, David Hoerl wrote:

> Objects:
> - NSManagedObject *item - some managaged object
> - NSArray *attributes - an array of the item's attributes
> 
> Desired Result:
> - a possibly smaller array of attribites where [item valueForKey: attribute>] != nil.
> 
> In code, I can simply iterate over the keys, perform the valueForKey, and 
> skip nil values. I played around with expressions and predicates to solve 
> this, to no avail.
> 
> I completely understand that the code solution is probably the way to go - 
> however, I'd be interested to know if a solution using NSArray's 
> filteredArrayWithPredicate and/or some combination of predicates and 
> expressions could provide the answer - as an academic exercise.
> 
> David


smime.p7s
Description: S/MIME cryptographic signature
___

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: Alternative startup for application

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 08:30, Jens Alfke wrote:

> I would have said GetKeys(), but it seems to have been deprecated and removed 
> in the eyeblink [read: decade] since I last used Carbon. There must be some 
> modern equivalent for reading the current state of the keyboard?

For completeness:

The non-deprecated-but-hard-to-find-documentation-for status of GetKeys () was 
discussed fairly recently in this thread:


http://www.cocoabuilder.com/archive/cocoa/281840-high-level-toolkit-is-it-obsolete-or-not.html

The "modern" (Snow Leopard) equivalent for finding the state of the Option key 
would be +[NSEvent modifierFlags].


___

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


CIFilter - output image format

2010-04-02 Thread paul morel

Hi,I have a problem with the output image of my custom CIFilter. Let's say I 
have a 16 bits image at the input I would like to keep a 16bits image in 
output.How can I do that? Because so far I have a 8 bits image at the output. 
Thanks ,Paul  
_
Hotmail: Free, trusted and rich email service.
https://signup.live.com/signup.aspx?id=60969___

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: NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-02 Thread Ben Trumbull
> Objects:
>  - NSManagedObject *item - some managaged object
>  - NSArray *attributes - an array of the item's attributes
> 
> Desired Result:
>  - a possibly smaller array of attribites where [item valueForKey: attribute>] != nil.
> 
> In code, I can simply iterate over the keys, perform the valueForKey, 
> and skip nil values. I played around with expressions and predicates to 
> solve this, to no avail.

Having the array of attributes unrolled separately is a little odd.  Do you 
mean you have an array of attribute names from, say the entity, and you want to 
ask a MO for all its non-nil attribute values and get back an array of matching 
attribute names for those non-nil values?

- Ben



___

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


MutableArray losing contents

2010-04-02 Thread Dean Pulsifer
I have looked through the forums, but don't think I have the problems that
were described.

I have a Cocoa app with a main window and a secondary window.  I have a
single controller.  I don't have a model or a document because I am reading
info from the OS and displaying it.

In the controller, I have an NSMutableArray that holds a list of names that
I queried from the OS when an entry in the primary window is selected.  The
secondary window contains an NSBrowser.  The controller is a delegate for
the NSBrowser.

When the entry in the primary window is selected, the OS is queried for that
object and a list of 9 strings is obtained and stored in the NSMutableArray
(shows up as NSCFArray * after I have added stuff to it).

The first NSBrowser delegate to get hit is numberOfRowsInColumn.  At this
point, the array in the controller still contains the 9 strings.  (It is
also the same self address for the controller from when the strings were
added).

The second NSBrowser delegate to get hit is willDisplayCell:atRow:column:
When I get to this call, the array has 0 objects.  The self pointer is still
the same.

I thought I had a retain issue, so I checked the retain count before and
after adding the strings to the array.  It is 1 before and 2 after as you
would expect.

Any suggestions on where to look for the problem?   I tried to set a
watchpoint on the array, but since it still exists, it doesn't seem to get
hit.  How can I detect when the objects are getting deleted in Xcode?

Both the primary and secondary windows are connected to the controller in
Interface Builder.

Thanks In Advance,
Dean
___

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: Detecting which MKAnnotation Detail Disclosure was touched

2010-04-02 Thread Roger Dalal
Help All (please)!

I have approximately 80 map annotations on a typical MapKit mapview. I have 
initialized the annotations with an array generated from a SQLlite database. I 
need to push a detail view controller once the user touches the annotation 
Detail Disclosure button on the annotation's Callout, but I can not figure out 
how to detect which annotation was touched. Any help or advise will be greatly 
appreciated.

Roger Dalal
Stuart, Florida

___

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 save and restore NSScrollView scroll position?

2010-04-02 Thread James Walker
I have an NSScrollView containing an NSTableView whose content is 
managed by an NSArrayController.  I have a situation where I need to 
temporarily set the array controller's content to nil, mess with the 
content, and then hand it back to the array controller, and I'd like to 
preserve the scrolling position.  I thought I could just get the value 
of the NSScroller before, and set it back after, but that results in the 
scroll bar being out of sync with the actual scrolling state of the 
table.  How can I do it?

--
  James W. Walker, Innoventive Software LLC
  
___

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: Creating WebView in code

2010-04-02 Thread Jenny M
On Fri, Apr 2, 2010 at 9:40 AM, Nick Zitzmann  wrote:
> That's most likely Flash Player at work, since it's been known to do this. To 
> work around it, install a dummy SIGINT handler function that does nothing. 
> See the signal man page for details.
>

Yup, you're right. That was just something I saw in an example; I
changed it to load a plain test html file, and that seems to work fine
(aka it doesn't crash).


> You must place the WebView in a window or else it won't render. It's a dumb 
> but necessary requirement. So you'll need to also create an NSWindow and add 
> the WebView as a subview of its content view, and that ought to work.
>

D'oh, you told me that before and I completely forgot. So I tried
that, but the page still appears blank. I don't want the page to be
visible so I didn't set makeKeyOrderFront.


NSRect frame = NSMakeRect(0.0, 0.0, pageSize.width, pageSize.height);
NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
defer:NO];

WebView *myWebView = [[WebView alloc] initWithFrame:frame
frameName:@"Test Frame" groupName:nil];
[[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL
URLWithString:@"http://www.jenstechs.net/test/testpage.html";]]];

[window setContentView:myWebView];


I also tried setting the content view before loading the request, but
both still result in blank pages


Sorry for not quite getting this yet, but I do hope this discussion is
useful for someone besides myself!

Thanks,
Jenny
___

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: NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-02 Thread David Hoerl

Having the array of attributes unrolled separately is a little odd.  Do you 
mean you have an array of attribute names from, say the entity, and you want to 
ask a MO for all its non-nil attribute values and get back an array of matching 
attribute names for those non-nil values?

- Ben


Specifically, here is what I'm trying to do:

I have a NSManagedObject "Address" (and no treecontroller) that has 
properties - lets say name, homePhone, and workPhone. workPhone is optional.


So, one Address record has obj.name = "Joe Blow", obj.homePhone = 
"555-1212" and obj.workPhone = nil


I put the Address object's property keys in an NSArray *attributes = { 
@"name", @"homePhone", @"workPhone" )


The exercise is to reduce the attribute array to just the set of keys 
that when applied to the object result in a value - that is, not nil.


I know this is quite easy to do in code (I'm doing it now) - but I tried 
and tried to construct some bizarre looking NSExpressions and Predicates 
to fit into this:


attributes = [attributes filteredArrayWithPredicate:[some predicate]];

The problem is constructing a predicate where the "target" is really the 
base object, and the keys are applied one by one against this target 
(think a NSExpression using a keyPath], and the result is a smaller array.


I suspect it can be done but have not figured out how to do it yet. The 
stumbling block is that the target for most expressions will be the 
keys, one at a time, where it would be best if instead of a target, it 
was a parameter.


Again, this is an intellectual exercise.

David
___

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: MutableArray losing contents

2010-04-02 Thread Jens Alfke


On Apr 1, 2010, at 8:05 PM, Dean Pulsifer wrote:

The second NSBrowser delegate to get hit is  
willDisplayCell:atRow:column:
When I get to this call, the array has 0 objects.  The self pointer  
is still

the same.


Is the array pointer nil? Sending any message to a nil pointer returns  
zero (or its equivalent).
If not, is the array pointer still the same value as it was before  
when it had stuff in it?


And just to clarify the obvious, the array pointer is an instance  
variable of your controller, right?


—Jens___

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: MutableArray losing contents

2010-04-02 Thread Quincey Morris
On Apr 1, 2010, at 20:05, Dean Pulsifer wrote:

> The second NSBrowser delegate to get hit is willDisplayCell:atRow:column:
> When I get to this call, the array has 0 objects.  The self pointer is still
> the same.

It's a side issue, but did you check whether the mutable array instance 
variable was nil at this point? That's always worth knowing if some method 
unexpectedly produced a 0/nil result (because sending a message to a nil object 
pointer produces a binary 0 return value -- in most cases).

> Both the primary and secondary windows are connected to the controller in
> Interface Builder.

What does this mean? What outlets are connected to the controller? What is the 
class of your controller object? A NSWindowController subclass?

More fundamentally, what NIB file organization are you using? Are there 
separate XIB/NIB files for each window? What's File's Owner for each NIB file? 
What is the *window* delegate for each of your windows?


___

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 save and restore NSScrollView scroll position?

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 13:15, James Walker wrote:

> I have an NSScrollView containing an NSTableView whose content is managed by 
> an NSArrayController.  I have a situation where I need to temporarily set the 
> array controller's content to nil, mess with the content, and then hand it 
> back to the array controller, and I'd like to preserve the scrolling 
> position.  I thought I could just get the value of the NSScroller before, and 
> set it back after, but that results in the scroll bar being out of sync with 
> the actual scrolling state of the table.  How can I do it?

Maybe something like this (typed in Mail):

clipOrigin = tableView.enclosingScrollView.contentView.bounds.origin;

... change the table then put it back again ...

[tableView.enclosingScrollView.contentView scrollToPoint: clipOrigin];

This first line is kind of a guess, based on the documentation for 
'scrollToPoint:'.


___

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


Implied use of Properties

2010-04-02 Thread Dave

Hi All,

I came across this code and was wondering if this is normal practice  
and/or considered good coding style.


Given two classes ClassX and ClassY:

@interface ClassX
{
ClassY  mClassY;
}

@property (nonatomic,retain,readonly)   ClassY* mClassY
@end

@interface ClassY
{
int mClassYValue;
}

@property (nonatomic,retain,readonly)   ClassY* mClassY

@end

@implementation ClassX

-(ClassY*) mClassY
{
if (mClassY == nil)
{
mClassY [[ClassY alloc] initWithData:someData]:
}
return mClassY;
}


Then later in another method of ClassX, I found the following code:

self.mClassY. mClassYValue = someValue;

Before this statement is executed, self. mClassY is nil. When it is  
executed it causes the "mClassY" method to be called which allocates  
the Class and sets the Variable.


Is this normal? Looking at the code it seems hard to see what is  
going on, Surely it would be better practice to have an init method  
that does this? e.g.


self.mClassY = [[alloc] initWithData: initWithData:someData]

Just trying to figure out the best approach for something like this.

Thanks in Advance
Dave













@end



___

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

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

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

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


Re: MutableArray losing contents

2010-04-02 Thread Dean Pulsifer
The array pointer is not null and it has the same value as when it was full.

Yes, it is a member of the controller class.



On Fri, Apr 2, 2010 at 4:30 PM, Jens Alfke  wrote:

>
> On Apr 1, 2010, at 8:05 PM, Dean Pulsifer wrote:
>
>  The second NSBrowser delegate to get hit is willDisplayCell:atRow:column:
>> When I get to this call, the array has 0 objects.  The self pointer is
>> still
>> the same.
>>
>
> Is the array pointer nil? Sending any message to a nil pointer returns zero
> (or its equivalent).
> If not, is the array pointer still the same value as it was before when it
> had stuff in it?
>
> And just to clarify the obvious, the array pointer is an instance variable
> of your controller, right?
>
> —Jens
___

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: MutableArray losing contents

2010-04-02 Thread Dean Pulsifer
The project is based on some Apple sample code.  I took the existing
MainMenu.xib with its main window and added another window that included an
NSBrowser view.

The File's Owner didn't have an obvious link to anything else.  I am not
using a document.  Does this matter?

The class of the controller is PMPrinterTestController (from the sample
code).

The delegate for both windows is my main controller.

My secondary window is actually an NSPanel.  Does this make a difference?

I connected the controller directly to the NSBrowser view rather than the
NSPanel that contains it.

Thanks,
Dean

On Fri, Apr 2, 2010 at 4:36 PM, Quincey Morris
wrote:

> On Apr 1, 2010, at 20:05, Dean Pulsifer wrote:
>
> > The second NSBrowser delegate to get hit is willDisplayCell:atRow:column:
> > When I get to this call, the array has 0 objects.  The self pointer is
> still
> > the same.
>
> It's a side issue, but did you check whether the mutable array instance
> variable was nil at this point? That's always worth knowing if some method
> unexpectedly produced a 0/nil result (because sending a message to a nil
> object pointer produces a binary 0 return value -- in most cases).
>
> > Both the primary and secondary windows are connected to the controller in
> > Interface Builder.
>
> What does this mean? What outlets are connected to the controller? What is
> the class of your controller object? A NSWindowController subclass?
>
> More fundamentally, what NIB file organization are you using? Are there
> separate XIB/NIB files for each window? What's File's Owner for each NIB
> file? What is the *window* delegate for each of your windows?
>
>
> ___
>
> 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/dean.pulsifer%40gmail.com
>
> This email sent to dean.pulsi...@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 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: Creating WebView in code

2010-04-02 Thread Nick Zitzmann

On Apr 2, 2010, at 2:19 PM, Jenny M wrote:

> D'oh, you told me that before and I completely forgot. So I tried
> that, but the page still appears blank. I don't want the page to be
> visible so I didn't set makeKeyOrderFront.
> 
> 
> NSRect frame = NSMakeRect(0.0, 0.0, pageSize.width, pageSize.height);
> NSWindow *window = [[NSWindow alloc] initWithContentRect:frame
> styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered
> defer:NO];
> 
> WebView *myWebView = [[WebView alloc] initWithFrame:frame
> frameName:@"Test Frame" groupName:nil];
> [[myWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL
> URLWithString:@"http://www.jenstechs.net/test/testpage.html";]]];
> 
> [window setContentView:myWebView];
> 
> 
> I also tried setting the content view before loading the request, but
> both still result in blank pages

There's one more thing. WebView loads requests asynchronously, so you need to 
block while it is loading the request and laying out the page while taking some 
time out to run the run loop. So do something like this:

while ([myWebView isLoading])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[myWebView setNeedsDisplay:NO];
[NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate 
dateWithTimeIntervalSinceNow:1.0] inMode:NSDefaultRunLoopMode dequeue:YES];
[pool drain];
}
[webView setNeedsDisplay:YES];

When this loop is done, any print operation you perform on the web view ought 
to work.

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


Re: Implied use of Properties

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 13:48, Dave wrote:

> Is this normal? Looking at the code it seems hard to see what is going on, 
> Surely it would be better practice to have an init method that does this? e.g.
> 
> self.mClassY = [[alloc] initWithData: initWithData:someData]

It's perfectly normal for a class to defer creating the contents of an instance 
variable until it's needed. (There's no way an client of the class can tell the 
difference.) However, there's not much point in doing so *unless* creating it 
is so expensive in terms of memory or performance that there's an actual 
benefit in doing the deferring.

Incidentally, your suggested line of code above doesn't follow current best 
practices (aside from the typo in the 'alloc' invocation). It would be placed 
in ClassX's -init method, and the current fashion (for good technical reasons) 
in an -init method is *typically* to set the instance variable directly:

mClassY = [[ClassY alloc] initWithData: initWithData:someData];

instead of using the setter as you proposed. Also, your version would produce a 
memory leak.


___

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: Implied use of Properties

2010-04-02 Thread Klaus Backert

Hi, Dave

On 2 Apr 2010, at 22:48, Dave wrote:


Hi All,

I came across this code and was wondering if this is normal practice  
and/or considered good coding style.


Given two classes ClassX and ClassY:

@interface ClassX
{
ClassY  mClassY;
}

@property (nonatomic,retain,readonly)   ClassY* mClassY
@end

@interface ClassY
{
int mClassYValue;
}

@property (nonatomic,retain,readonly)   ClassY* mClassY

@end

@implementation ClassX

-(ClassY*) mClassY
{
if (mClassY == nil)
{
mClassY [[ClassY alloc] initWithData:someData]:
}
return mClassY;
}


Then later in another method of ClassX, I found the following code:

self.mClassY. mClassYValue = someValue;

Before this statement is executed, self. mClassY is nil. When it is  
executed it causes the "mClassY" method to be called which allocates  
the Class and sets the Variable.


There are some typing errors in this code, I think, but anyway, this  
might be a case of lazy creation of an object inside a getter of  
another object. You will find the same e.g. in Apple's code examples  
about OpenGL, where the OpenGL context is an instance variable of the  
OpenGL view. Accessing the context is managed by a getter method or  
property, respectively, of the view, where, in the case of the  
instance variable being nil, the context is created, stored in the  
instance variable, and eventually returned. I call the creation  
"lazy", because it is done at the latest point during execution,  
immediately before it is needed. For me this practice is normal.


But, may be, I don't understand your question correctly.

regards
Klaus

___

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: MutableArray losing contents

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 14:03, Dean Pulsifer wrote:

> The project is based on some Apple sample code.  I took the existing 
> MainMenu.xib with its main window and added another window that included an 
> NSBrowser view.
> 
> The File's Owner didn't have an obvious link to anything else.  I am not 
> using a document.  Does this matter?  
> 
> The class of the controller is PMPrinterTestController (from the sample code).
> 
> The delegate for both windows is my main controller.
> 
> My secondary window is actually an NSPanel.  Does this make a difference?
> 
> I connected the controller directly to the NSBrowser view rather than the 
> NSPanel that contains it.

In what method of your controller is the mutable array created? I'm guessing 
that you're somehow getting there twice, causing the original array with its 9 
elements to be replaced by a new empty array. You could check that easily by 
setting a breakpoint on the line that creates the array, and see if you get 
there twice.

If nothing in your code is clobbering the array, then I'd suspect the NSBrowser 
is doing something to its content. If so, I have no help to offer -- NSBrowser 
is one of a handful of nightmare object classes in the frameworks, and I'm 
still in therapy from the one time I tried to use it. :)



___

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


C typedef for NS ptrs?

2010-04-02 Thread Andy O'Meara

Hey folks, quick question...

A have a couple vanilla NS object ptrs (e.g. NSWindow*) that I have to pass 
through some cross-plaform C++ code until it ends up in a .mm file where where 
the NS object is accessed.  The problem is that in the .cpp code, there's no 
obvious way to declare a NSWindow ptr so that thinks will link without 
complaint.  If, for example, in a key header I use:

#ifdef __OBJC__
#define NSWindowPtr   NSWindow*
#else
#define NSWindowPtr   void*
#endif

then everything of course compiles, but nothing links (since all the .cpp 
object files are looking for proc arguments with void* while the .mm object 
files are are declared with the real deal).

So, what can I replace that second macro with such that it meshes with ObjC's 
typedef mangling scheme?

Thanks in advance,
Andy
 ___

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

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

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

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


Re: NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-02 Thread Ben Trumbull

On Apr 2, 2010, at 1:30 PM, David Hoerl wrote:

>> Having the array of attributes unrolled separately is a little odd.  Do you 
>> mean you have an array of attribute names from, say the entity, and you want 
>> to ask a MO for all its non-nil attribute values and get back an array of 
>> matching attribute names for those non-nil values?
> 
> Specifically, here is what I'm trying to do:
> I have a NSManagedObject "Address" (and no treecontroller) that has 
> properties - lets say name, homePhone, and workPhone. workPhone is optional.
> So, one Address record has obj.name = "Joe Blow", obj.homePhone = "555-1212" 
> and obj.workPhone = nil
> I put the Address object's property keys in an NSArray *attributes = { 
> @"name", @"homePhone", @"workPhone" )
> The exercise is to reduce the attribute array to just the set of keys that 
> when applied to the object result in a value - that is, not nil.


Two approaches:

NSDictionary* obj = [NSDictionary dictionaryWithObjectsAndKeys:@"Joe 
Blow", @"name", @"555-1212", @"homePhone", nil];
NSArray* keys = [NSArray arrayWithObjects:@"name", @"homePhone", 
@"workPhone", nil];
NSPredicate* pred = [NSPredicate predicateWithFormat:@"%...@.self != 
nil", obj];
NSLog(@"filtered array results = %@", [keys 
filteredArrayUsingPredicate:pred]);

NSComparisonPredicate* exprPred = (NSComparisonPredicate*)[NSPredicate 
predicateWithFormat:@"SUBQUERY(self, $key, %...@.$key != nil) == 0", obj];
NSExpression* expr = [exprPred leftExpression];
NSLog(@"expression subquery results = %@", [expr 
expressionValueWithObject:keys context:nil]);

- Ben



___

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: NSPredicate/NSExpression - can they solve this Core Data problem?

2010-04-02 Thread Dave DeLong
Is the use of SUBQUERY() documented anywhere?  The only mention I've seen of it 
is in the reserved keywords section of the Predicate Format String Syntax guide.

Dave

On Apr 2, 2010, at 3:42 PM, Ben Trumbull wrote:

>   NSComparisonPredicate* exprPred = (NSComparisonPredicate*)[NSPredicate 
> predicateWithFormat:@"SUBQUERY(self, $key, %...@.$key != nil) == 0", obj];
>   NSExpression* expr = [exprPred leftExpression];
>   NSLog(@"expression subquery results = %@", [expr 
> expressionValueWithObject:keys context:nil]);


smime.p7s
Description: S/MIME cryptographic signature
___

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: C typedef for NS ptrs?

2010-04-02 Thread Greg Parker
On Apr 2, 2010, at 2:38 PM, Andy O'Meara wrote:
> Hey folks, quick question...
> 
> A have a couple vanilla NS object ptrs (e.g. NSWindow*) that I have to pass 
> through some cross-plaform C++ code until it ends up in a .mm file where 
> where the NS object is accessed.  The problem is that in the .cpp code, 
> there's no obvious way to declare a NSWindow ptr so that thinks will link 
> without complaint.  If, for example, in a key header I use:
> 
> #ifdef __OBJC__
>#define NSWindowPtr   NSWindow*
> #else
>#define NSWindowPtr   void*
> #endif
> 
> then everything of course compiles, but nothing links (since all the .cpp 
> object files are looking for proc arguments with void* while the .mm object 
> files are are declared with the real deal).
> 
> So, what can I replace that second macro with such that it meshes with ObjC's 
> typedef mangling scheme?

You can't fool C++ name mangling using typedefs or macros. But you can tell C++ 
that NSWindow is an opaque struct. Then you can use `NSWindow *` or `typedef 
NSWindow* NSWindowPtr` on both sides without trouble. 

#ifdef __OBJC__
# include 
#else
struct NSWindow;
#endif


-- 
Greg Parker gpar...@apple.com Runtime Wrangler


___

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 save and restore NSScrollView scroll position?

2010-04-02 Thread James Walker

On 4/2/2010 1:47 PM, Quincey Morris wrote:

On Apr 2, 2010, at 13:15, James Walker wrote:


I have an NSScrollView containing an NSTableView whose content is
managed by an NSArrayController. I have a situation where I need to
temporarily set the array controller's content to nil, mess with the
content, and then hand it back to the array controller, and I'd like to
preserve the scrolling position. I thought I could just get the value of
the NSScroller before, and set it back after, but that results in the
scroll bar being out of sync with the actual scrolling state of the
table. How can I do it?


Maybe something like this (typed in Mail):

clipOrigin = tableView.enclosingScrollView.contentView.bounds.origin;

... change the table then put it back again ...

[tableView.enclosingScrollView.contentView scrollToPoint: clipOrigin];

This first line is kind of a guess, based on the documentation for 
'scrollToPoint:'.



When I tried that, the table was in the right position, but the scroll 
bar was wrong.  If I do BOTH your trick and what I originally tried with 
the NSScroller value, then it seems to work.  Thanks.

--
  James W. Walker, Innoventive Software LLC
  
___

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: Alternative startup for application

2010-04-02 Thread Gideon King
Excellent, I like the new way of doing it using NSEvent directly, but I do need 
to support Leopard.

If you launch from Finder holding the Option key, Finder closes the window you 
launched from, but I can tell people to put it in the dock and launch from 
there to avoid that.

Here's what I'm doing, which appears to work fine (haven't tested on Leopard 
yet, but have tested the CG code in Snow Leopard and that worked).:

- (void)applicationWillFinishLaunching:(NSNotification*)aNotification {
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_5) {
if (([NSEvent modifierFlags] & 
NSDeviceIndependentModifierFlagsMask) == NSAlternateKeyMask) {
[self doSpecialStartup];
}   
} else {
CGEventRef event = CGEventCreate(NULL);
CGEventFlags modifiers = CGEventGetFlags(event);
CFRelease(event);

if ((modifiers & kCGEventFlagMaskAlternate) == 
kCGEventFlagMaskAlternate) {
[self doSpecialStartup];
}
}
...
}

Thanks again for the help.

Gideon

> The "modern" (Snow Leopard) equivalent for finding the state of the Option 
> key would be +[NSEvent modifierFlags].

___

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: Creating WebView in code

2010-04-02 Thread Jenny M
On Fri, Apr 2, 2010 at 2:08 PM, Nick Zitzmann  wrote:
> There's one more thing. WebView loads requests asynchronously, so you need to 
> block while it is loading the request and laying out the page while taking 
> some time out to run the run loop. So do something like this:
>

AHA! Thank you, it worked like a charm!! I even got pagination on it,
so it looks fine. Now I can print a lot of things, table views and web
views alike!  (I had a problem when I tested creating a PDFView but
I'll save that question for another time if I need it...)

Thanks so much,
Jenny
___

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: NSDocument and the dreaded "The location of the document XXX cannot be determined"

2010-04-02 Thread Martin Wierschin

Hi Jerry,

After adding a "Save As Move" command to an application, I was  
getting a different but related warning, something like "Document  
has been moved, do you really want to save it to a new location?"   
The solution was to sprinkle in an extra invocation of  
saveToURL:ofType:forSaveOperation:error: immediately after  
setFileURL:.


I don't care for that solution, as it means -writeToURL:etc will be  
invoked twice. For my documents, that's a heavy penalty. But I do  
remember the warning you quoted appearing too often, even after a user  
confirmed an external move/rename. My workaround was to add this after  
the file is saved successfully:


[self performSelectorIfResponds:@selector(_resetMoveAndRenameSensing)];

It's an undocumented method, so all the usual warnings apply.

If you figure it out, please post the answer for the list archives.   
I may need it someday :)


haha.. I did end up with a solution that works for my situation. In my  
NSDocument overrides, rather than invoking -writeSafelyToURL:etc I can  
call -saveToURL:ofType:forSaveOperation:error: to do the work. The  
latter appears to call the former, and properly manages the file  
location tracking without generating the erroneous prompts. I don't  
know how I earlier missed this obvious solution.


Thanks!
~Martin

___

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: Creating WebView in code

2010-04-02 Thread Adam R. Maxwell

On Apr 2, 2010, at 2:08 PM, Nick Zitzmann wrote:

> 
> On Apr 2, 2010, at 2:19 PM, Jenny M wrote:
> 
>> D'oh, you told me that before and I completely forgot. So I tried
>> that, but the page still appears blank. I don't want the page to be
>> visible so I didn't set makeKeyOrderFront.

FWIW, I'm able to draw WebView content to a bitmap without involving an 
offscreen window at all, so I'm not sure what problem Nick ran into with that.  
One thing that's bitten me is that you need to force layout if you send 
setAllowsScrolling:NO to the WebFrameView.

> There's one more thing. WebView loads requests asynchronously, so you need to 
> block while it is loading the request and laying out the page while taking 
> some time out to run the run loop. So do something like this:
> 
> while ([myWebView isLoading])
> {
>   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>   
>   [myWebView setNeedsDisplay:NO];
>   [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate 
> dateWithTimeIntervalSinceNow:1.0] inMode:NSDefaultRunLoopMode dequeue:YES];
>   [pool drain];
> }
> [webView setNeedsDisplay:YES];
> 
> When this loop is done, any print operation you perform on the web view ought 
> to work.

Just be careful if you use this with any redirects, since -isLoading will 
return NO, then a moment later return YES again.  That shouldn't matter loading 
from a file, but it was very tedious to deal with for creating thumbnails from 
web pages (you have to track redirected frames manually).

--
Adam


___

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 save and restore NSScrollView scroll position?

2010-04-02 Thread Ashley Clark
On Apr 2, 2010, at 5:33 PM, James Walker wrote:

> On 4/2/2010 1:47 PM, Quincey Morris wrote:
>> On Apr 2, 2010, at 13:15, James Walker wrote:
>> 
>>> I have an NSScrollView containing an NSTableView whose content is
>>> managed by an NSArrayController. I have a situation where I need to
>>> temporarily set the array controller's content to nil, mess with the
>>> content, and then hand it back to the array controller, and I'd like to
>>> preserve the scrolling position. I thought I could just get the value of
>>> the NSScroller before, and set it back after, but that results in the
>>> scroll bar being out of sync with the actual scrolling state of the
>>> table. How can I do it?
>> 
>> Maybe something like this (typed in Mail):
>> 
>>  clipOrigin = tableView.enclosingScrollView.contentView.bounds.origin;
>> 
>>  ... change the table then put it back again ...
>> 
>>  [tableView.enclosingScrollView.contentView scrollToPoint: clipOrigin];
>> 
>> This first line is kind of a guess, based on the documentation for 
>> 'scrollToPoint:'.
> 
> 
> When I tried that, the table was in the right position, but the scroll bar 
> was wrong.  If I do BOTH your trick and what I originally tried with the 
> NSScroller value, then it seems to work.  Thanks.

You can manually update the scrollers position but there's a method on 
NSScrollView that will do it for you based on the content view's origin.

- (void)reflectScrolledClipView:(NSClipView *)aClipView

so, [[tableView enclosingScrollView] reflectScrolledClipView:[[tableView 
enclosingScrollView] contentView]]


Ashley



___

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: Alternative startup for application

2010-04-02 Thread Klaus Backert


On 3 Apr 2010, at 01:15, Gideon King wrote:

Excellent, I like the new way of doing it using NSEvent directly,  
but I do need to support Leopard.


- (NSUInteger)modifierFlags

Available in Mac OS X v10.0 and later.

NSAlternateKeyMask
Set if Option or Alternate key is pressed.

Available in Mac OS X v10.0 and later.


etc.

Klaus

___

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: Alternative startup for application

2010-04-02 Thread Gideon King
That's the instance method. New in 10.6 is the class method of the same name, 
which is what I need in this case, since I don't have an event to work with.

On 03/04/2010, at 12:09 PM, Klaus Backert wrote:

> 
> On 3 Apr 2010, at 01:15, Gideon King wrote:
> 
>> Excellent, I like the new way of doing it using NSEvent directly, but I do 
>> need to support Leopard.
> 
> - (NSUInteger)modifierFlags
> 
> Available in Mac OS X v10.0 and later.
> 

___

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: Terminating subtasks reliably

2010-04-02 Thread Michael Ash
On Thu, Apr 1, 2010 at 7:19 PM, Dave Keck  wrote:
>>> Look like a race condition. The man page says getppid() will not fail, but
>>> not what happens after the parent dies. I will test this.
>>
>> If the parent dies, the process becomes the child of launchd. For a quick
>> fix I checked for the parent PID greater than 1.
>>
>> A better fix, the parent process passed its PID to the child process as an
>> argument. In the child process, if getppid() does not return the PID from
>> the parent process, exit.
>
> Another problem is if the parent dies after the getppid(), and another
> process starts with the same PID as the old parent, all before the
> call to kevent(). In this scenario you'll now be waiting for an
> unrelated process to die. This situation is likely impossible
> currently with incrementing PIDs, but there's been mention of PID
> randomization on darwin-dev:
>
>    http://lists.apple.com/archives/darwin-dev/2009/Oct/msg00056.html
>
> I only mention this because I use this kevent method to detect a
> parent's death, and have been looking for a better technique that
> also doesn't require the parent's cooperation...

Call getppid, set up the kevent listener, then before you actually
block in kevent, call getppid *again*. If the answer matches the first
call, then you can go ahead and call kevent. If the answer doesn't
match, you've hit the race condition you outline here, your parent is
dead, and you can exit immediately. If the parent quits after the
second getppid but before the call to kevent, you should still get the
exit notification because you registered it before the parent quit.

Mike
___

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: Alternative startup for application

2010-04-02 Thread Michael Nickerson

On Apr 02, 2010, at 10:12 PM, Gideon King wrote:

> That's the instance method. New in 10.6 is the class method of the same name, 
> which is what I need in this case, since I don't have an event to work with.
> 
> On 03/04/2010, at 12:09 PM, Klaus Backert wrote:
> 
>> 
>> On 3 Apr 2010, at 01:15, Gideon King wrote:
>> 
>>> Excellent, I like the new way of doing it using NSEvent directly, but I do 
>>> need to support Leopard.
>> 
>> - (NSUInteger)modifierFlags
>> 
>> Available in Mac OS X v10.0 and later.
>> 
> 


You can use CGEventSourceKeyState( kCGEventSourceStateCombinedSessionState, 
0x3A ).  That function will get the key down state at the time of the call, and 
0x3A is the key code for the option key.


--
Darkshadow
(aka Michael Nickerson)
http://www.nightproductions.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


Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Jerry Krinock
I have a table bound to an array controller containing Foo objects and wanted 
to enable a "Perform Foo" button whenever there is a non-nil selection.  Not 
trusting those pesky proxy objects you get from an array controller's 
-selection, I wrote a -selectedFoo method which will return either the first 
selected Foo or nil if there is no selection, and bound my button's 'enabled' 
binding to it via NSIsNotNil value transformer. 

Now, NSArrayController has five methods which give the selection in some form, 
and they are all documented to be "observable using key-value observing".  So 
to make this work I implemented a +keyPathsForValuesAffectingSelectedFoo which 
returned the path to one of these keys, but when that didn't work I put in all 
five.

But I never could get it to work.  By logging, I determined the problem:  None 
of these five observers are firing the -selectedFoo getter when the array and 
table controller's selection changes.  When I added, as a test, some other 
object's key path to keyPathsForValuesAffectingKey, and changed its value, the 
-selectedAgent method was invoked and updated the enabled state of my button as 
desired.  So the problem seems to be that "observeable using key-value 
observing" doesn't mean what I think it means.  Where am I going wrong?

I solved the problem by eliminating all this code and binding my button's 
'enabled' binding instead to the array controller's 'selection' and, to my 
surprise, it worked.  My surprise is because, according to superclass 
NSObjectController documentation, 'selection' returns NSNoSelectionMarker when 
there is no selection, not nil which is what my NSIsNotNil value transformer 
would expect.

So, what should work does not work and what should not work does work.

Thanks,

Jerry Krinock

// fooArrayController is an IBOutlet

+ (NSSet*)keyPathsForValuesAffectingSelectedFoo {
return [NSSet setWithObjects:
// Shotgun approach.  Try 'em all!!
@"fooArrayController.selectedObjects",
@"fooArrayController.selectionIndex",
@"fooArrayController.selection",
@"fooArrayController.selectionIndexes",
@"fooArrayController.selectedObjects",
nil] ;
}

- (Foo*)selectedFoo {
NSArray* selectedFoos = [fooArrayController selectedObjects] ;
if ([selectedFoos count] > 0) {
return [selectedFoos objectAtIndex:0] ;
}

return nil ;
}


___

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


iPhone CoreData TableView not updating

2010-04-02 Thread Arnold Nefkens
Hello List, 

I'm a newbie on iPhone Programming, so please bear with me.

I did the first 7 chapters of "More iPhone 3 Development, tackling iPhone SDK3" 
from Apress regarding the use of CoreData. In these 7 chapters a lot is 
explained and finally a series of classes and categories are being build that 
one can use as a Generic Controller for editing data stored in CoreData.

So I bult a new application where I inserted these classes, and created a new 
viewController for my specific needs. Almost everything works, except that the 
tableView is not updated when I create a new item for in the DB, The item is 
however created, but only visible if I quit the App and start it again. 
Apparently something is not right.

I double checked the 4 NSFetechedResult delegates, but it just does not work. I 
tried to insert [self.tableView reloadData] on a number of places, but to no 
avail.

Can someone of you check my ViewController code? And point me in the right 
direction where I'm missing the ball?

I'll send you the code off-list

Your help and effort is much appreciated.

Kind regards, 

Arnold Nefkens


___

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


Invalidated managed objects

2010-04-02 Thread Gideon King
When I create a document, save it, then save as, then save as again, it 
duplicates the persistent store, so the managed objects I have been using in my 
application are all invalidated. 

Now there are a whole lot of places in my application where I have KVO set up 
on properties of the managed objects, and some places where I have the managed 
objects set as instance variables of my objects. I was not expecting them to be 
invalidated by the save as operation. 

I have created a mini project that reproduces this problem with a simple atomic 
store and a data model with one entity.

I presume my KVOs should be OK, since they are looked up at runtime based on 
key paths, but the instance variables throughout my application would 
presumably all have to be re-fetched. 

Anyway, I found that there is a notification that tells you when the objects 
are invalidated, so I put the following in my init method of my 
NSPersistentDocument subclass:

[[NSNotificationCenter defaultCenter] addObserver:self 
selector:@selector(managedObjectsChanged:) 
name:NSManagedObjectContextObjectsDidChangeNotification object:[self 
managedObjectContext]];


And created a method to refresh my data:


- (void)managedObjectsChanged:(NSNotification *)notification {
if ([[notification userInfo] objectForKey:NSInvalidatedObjectsKey]) {
NSSet *objects = [[notification userInfo] 
objectForKey:NSInvalidatedObjectsKey];
for (NSManagedObject *obj in objects) {
[[self managedObjectContext] refreshObject:obj 
mergeChanges:YES];
}
} else if ([[notification userInfo] 
objectForKey:NSInvalidatedAllObjectsKey]) {
for (NSManagedObject *obj in [[self managedObjectContext] 
registeredObjects]) {
[[self managedObjectContext] refreshObject:obj 
mergeChanges:YES];
}
}
}

I have confirmed that this is called in the save/save as/save as scenario, with 
the NSInvalidatedAllObjectsKey, and my object is getting sent the refreshObject 
message...But when I go to access my data, it still tells me that it has been 
invalidated. Am I doing something wrong here? The fact that the error is that 
the object is invalid rather than trying to message a released object makes me 
thing that the actual pointer to the object doesn't change, but that the data 
should be reloaded...but it's not. Any clues or suggestions?

Thanks

Gideon




___

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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 20:25, Jerry Krinock wrote:

> Now, NSArrayController has five methods which give the selection in some 
> form, and they are all documented to be "observable using key-value 
> observing".  So to make this work I implemented a 
> +keyPathsForValuesAffectingSelectedFoo which returned the path to one of 
> these keys, but when that didn't work I put in all five.

I only see 4 distinct keys in your list below, since one of them is duplicated.

> But I never could get it to work.  By logging, I determined the problem:  
> None of these five observers are firing the -selectedFoo getter when the 
> array and table controller's selection changes.  When I added, as a test, 
> some other object's key path to keyPathsForValuesAffectingKey, and changed 
> its value, the -selectedAgent method was invoked and updated the enabled 
> state of my button as desired.  So the problem seems to be that "observeable 
> using key-value observing" doesn't mean what I think it means.  Where am I 
> going wrong?

I'm suspicious of the "fooArrayController" part. Is it *just* an instance 
variable? If so, then it gets to be a property only by virtue 
'accessInstanceVariablesDirectly' being YES (which is bad magic, but a 
different story). If so, then it's not KVO compliant, though the only scenario 
I can think of where this would cause keyPathsForValuesAffecting... to fail is 
if something was already observing "selectedFoo" before the nib file containing 
it was loaded.

TBH, if I had a reason to want to observe the selection 
(keyPathsForValuesAffecting... being a special case of that), I'd create a real 
NSIndexSet* selectedItemIndexes property of my own, bind the array controller's 
"selectionIndexes" binding to that (so that the array controller maintains the 
real property for me), and then observe the real property, leaving all 
reference to the array controller itself out of my code.

> I solved the problem by eliminating all this code and binding my button's 
> 'enabled' binding instead to the array controller's 'selection' and, to my 
> surprise, it worked.  My surprise is because, according to superclass 
> NSObjectController documentation, 'selection' returns NSNoSelectionMarker 
> when there is no selection, not nil which is what my NSIsNotNil value 
> transformer would expect.

I think the answer is that it works because it's a frameworks binding, and 
frameworks bindings are very clever in ways we aren't actually told about. It 
probably knows whether it's allowed to pass on the marker value, or if it must 
convert the marker to some kind of "real" object first -- hence nil. Or perhaps 
passing NSNoSelectionMarker to the value transformer is simply special-cased 
somewhere.


___

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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Kyle Sluder
On Fri, Apr 2, 2010 at 8:25 PM, Jerry Krinock  wrote:
> But I never could get it to work.  By logging, I determined the problem:  
> None of these five observers are firing the -selectedFoo getter when the 
> array and table controller's selection changes.  When I added, as a test, 
> some other object's key path to keyPathsForValuesAffectingKey, and changed 
> its value, the -selectedAgent method was invoked and updated the enabled 
> state of my button as desired.  So the problem seems to be that "observeable 
> using key-value observing" doesn't mean what I think it means.  Where am I 
> going wrong?

Because +keyPathsForValuesAffectingValueForKey relies on
NSKeyValueObservingOptionPrior, which NSArrayController doesn't
support.

File a bug. It'll get dup'ed, but do it anyway.

--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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Kyle Sluder
On Fri, Apr 2, 2010 at 8:25 PM, Jerry Krinock  wrote:
> + (NSSet*)keyPathsForValuesAffectingSelectedFoo {
>    return [NSSet setWithObjects:
>        // Shotgun approach.  Try 'em all!!
>        @"fooArrayController.selectedObjects",
>        @"fooArrayController.selectionIndex",
>        @"fooArrayController.selection",
>        @"fooArrayController.selectionIndexes",
>        @"fooArrayController.selectedObjects",
>        nil] ;
> }

Oh, and also the documentation is quite clear that you can't bind
through a to-many property. So even if NSArrayController did support
prior-value notification, this wouldn't work. From the Key-Value
Technology Compliance section of the Model Object Implementation
Guide:

"Important: Note that you cannot set up dependencies on to-many
relationships. For example, suppose you have an Order object with a
to-many relationship (orderItems) to a collection of OrderItem
objects, and OrderItem objects have a price attribute. You might want
the Order object have a totalPrice attribute that is dependent upon
the prices of all the OrderItem objects in the relationship. You can
not do this by implementing keyPathsForValuesAffectingValueForKey: and
returning orderItems.price as the keypath for totalPrice. You must
observe the price attribute of each of the OrderItem objects in the
orderItems collection and respond to changes in their values by
updating totalPrice yourself."

--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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 21:42, Kyle Sluder wrote:

>> + (NSSet*)keyPathsForValuesAffectingSelectedFoo {
>>return [NSSet setWithObjects:
>>// Shotgun approach.  Try 'em all!!
>>@"fooArrayController.selectedObjects",
>>@"fooArrayController.selectionIndex",
>>@"fooArrayController.selection",
>>@"fooArrayController.selectionIndexes",
>>@"fooArrayController.selectedObjects",
>>nil] ;
>> }
> 
> Oh, and also the documentation is quite clear that you can't bind
> through a to-many property.

Wait, where is the to-many property being bound through?


___

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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Kyle Sluder
On Fri, Apr 2, 2010 at 10:05 PM, Quincey Morris
 wrote:
> On Apr 2, 2010, at 21:42, Kyle Sluder wrote:
>> Oh, and also the documentation is quite clear that you can't bind
>> through a to-many property.
>
> Wait, where is the to-many property being bound through?

Ugh, that's not what I meant to say. I meant that you can't use the
automatic notifications mechanism with to-many properties. Sorry!

--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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Kyle Sluder
On Fri, Apr 2, 2010 at 10:05 PM, Quincey Morris
 wrote:
> Wait, where is the to-many property being bound through?

Oh, I see what you're saying. It's not being observed *through*, it's
being observed *to*. Which would be okay, I guess, if
NSArrayController weren't a bad KVO citizen.

Way too much coffee, way to little sleep, way too excited about tomorrow. :)

--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: Detecting which MKAnnotation Detail Disclosure was touched

2010-04-02 Thread John Baldwin
You can use

view.annotation

in 

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
calloutAccessoryControlTapped:(UIControl *)control

John

On Thursday Apr 1  6:16 PM, at 6:16 PM, Roger Dalal wrote:

> Help All (please)!
> 
> I have approximately 80 map annotations on a typical MapKit mapview. I have 
> initialized the annotations with an array generated from a SQLlite database. 
> I need to push a detail view controller once the user touches the annotation 
> Detail Disclosure button on the annotation's Callout, but I can not figure 
> out how to detect which annotation was touched. Any help or advise will be 
> greatly appreciated.
> 
> Roger Dalal
> Stuart, Florida
> 
> ___
> 
> 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/johnbaldwincocoa%40gmail.com
> 
> This email sent to johnbaldwinco...@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 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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Jerry Krinock

On 2010 Apr 02, Quincey Morris wrote:

> I only see 4 distinct keys in your list below, since one of them is 
> duplicated.

Yes, you're correct.  There are only 4.

> I'm suspicious of the "fooArrayController" part. Is it *just* an instance 
> variable?

It's an IBOutlet, and also there is a getter which returns the IBOutlet.

> If so, then it gets to be a property only by virtue 
> 'accessInstanceVariablesDirectly' being YES (which is bad magic, but a 
> different story). If so, then it's not KVO compliant, though the only 
> scenario I can think of where this would cause keyPathsForValuesAffecting... 
> to fail is if something was already observing "selectedFoo" before the nib 
> file containing it was loaded.

There is something else observing "selectedFoo", and it is in the nib, another 
"detail" array controller, to which is bound a table which displays the 'bars', 
shall we say, of the 'selectedFoo'.

So you're telling me that all of the keys in a key path must be KVO-compliant.  
I hadn't thought so, because in the key path "fooArrayController.selection", 
the fooArrayController is hard-wired to an IBOutlet and never changes.  But now 
I see a possible explanation is that the Cocoa Bindings Wizard created its 
observer before the fooArrayController got wired to its outlet.

On 2010 Apr 02, Kyle Sluder wrote:

> Because +keyPathsForValuesAffectingValueForKey relies on 
> NSKeyValueObservingOptionPrior, which NSArrayController doesn't support.

That would explain the problem also.

So the answer is either Quincey's explanation, or this bug, or both.

> File a bug. It'll get dup'ed, but do it anyway.

If I don't hear more from you on this, Kyle, I'll test and file a bug tomorrow.


Other Details...

On 2010 Apr 02, Quincey Morris wrote:

> TBH, if I had a reason to want to observe the selection 
> (keyPathsForValuesAffecting... being a special case of that), I'd create a 
> real NSIndexSet* selectedItemIndexes property of my own, bind the array 
> controller's "selectionIndexes" binding to that (so that the array controller 
> maintains the real property for me), and then observe the real property, 
> leaving all reference to the array controller itself out of my code.

Yes, that seems like it would work.

>> I solved the problem by eliminating all this code and binding my button's 
>> 'enabled' binding instead to the array controller's 'selection' and, to my 
>> surprise, it worked.  My surprise is because, according to superclass 
>> NSObjectController documentation, 'selection' returns NSNoSelectionMarker 
>> when there is no selection, not nil which is what my NSIsNotNil value 
>> transformer would expect.
> 
> I think the answer is that it works because it's a frameworks binding, and 
> frameworks bindings are very clever in ways we aren't actually told about. It 
> probably knows whether it's allowed to pass on the marker value, or if it 
> must convert the marker to some kind of "real" object first -- hence nil. Or 
> perhaps passing NSNoSelectionMarker to the value transformer is simply 
> special-cased somewhere.

That's what I was afraid of.

___

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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Quincey Morris
On Apr 2, 2010, at 22:17, Jerry Krinock wrote:

> So you're telling me that all of the keys in a key path must be 
> KVO-compliant.  I hadn't thought so, because in the key path 
> "fooArrayController.selection", the fooArrayController is hard-wired to an 
> IBOutlet and never changes.  But now I see a possible explanation is that the 
> Cocoa Bindings Wizard created its observer before the fooArrayController got 
> wired to its outlet.

No, KVO compliance isn't required for a bound-to key that never changes.

The issue I had in mind is that that the "fooArrayController" key *does* change 
-- when the nib is loaded to changes from nil to its correct value. Thus, 
anything that tries to observe it before nib loading is going to be observing a 
nil object and will never know any different. Things that observe it after the 
outlet is set during nib loading will be fine.

However, I think this is a false trail. Kyle had the correct answer.


___

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: Why doesn't -[NSArrayController selection] et al fire keyPathsForValuesAffectingKey?

2010-04-02 Thread Kyle Sluder
On Fri, Apr 2, 2010 at 8:25 PM, Jerry Krinock  wrote:
> I solved the problem by eliminating all this code and binding my button's 
> 'enabled' binding instead to the array controller's 'selection' and, to my 
> surprise, it worked.  My surprise is because, according to superclass 
> NSObjectController documentation, 'selection' returns NSNoSelectionMarker 
> when there is no selection, not nil which is what my NSIsNotNil value 
> transformer would expect.

While this works (I imagine that -[NSButtonCell setObjectValue:]
treats NSNoSelectionMarker specially) I would think that the "right"
thing to do would be to subclass NSArrayController and write a
-canPerformFoo method. But you would need to self-observe the
selection property, which is perilous because
-removeObserver:forKeyPath: doesn't take a context argument (another
bug every Cocoa developer should file a duplicate of). So you could
use MAKVONotificationCenter (or OFBinding, our analogue) to
self-observe. Perhaps it would be easier to instead put the
-canPerformFoo method on your window controller.

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