Re: NSSecureCoding with containers (or, is NSArray lying?)

2015-07-17 Thread Tony Parker
Hi André,

The way that NSSecureCoding works is by creating a stack of allowed classes. 
When a class calls decodeObjectOfClasses:forKey:, the classes argument is 
pushed onto the stack. If it calls decodeObjectForKey:, then nothing is pushed 
onto the stack. When decoding, the decoder looks at the top item on the stack 
to see what is allowed.

NSArray (and other collections) use the second mechanism (not pushing on the 
stack). This means that the set of allowed classes is whatever the decoder of 
the NSArray instance set up when calling decodeObjectOfClasses:forKey:. This 
usually means that when decoding an array you want to specify the union of the 
NSArray class and the expected classes of the array.

If you have a class like NSError, which supports secure coding and also has a 
user info dictionary which can contain arbitrary classes, then you can use the 
-allowedClasses method on the coder to find the current item on the top of the 
stack, make a new set with those classes + classes you want to make sure the 
user info can contain (for e.g. your own contents), then use the 
decodeObjectOfClasses:forKey: method.

As to the purpose of secure coding, the main purpose is to avoid calling +alloc 
or -initWithCoder: on an arbitrary class. The unarchiver would not call an 
arbitrary selector when decoding in the first place.

Hope this helps,
- Tony

 On Jul 17, 2015, at 6:03 AM, André Francisco andre.frate...@hotmail.com 
 wrote:
 
 Hm. I was specifically thinking of unrecognised selector exceptions, although 
 I might have came up with a much more dangerous scenario: recognised 
 selectors.  What happens if the instantiated class *does* recognise the 
 selector, but it doesn't quite do what you think it does. Say, -open, or 
 -unlock. How dangerous is it to call such a selector on an instance of 
 unknown type? Quite, I think. And it might lead to exploits. I guess that 
 it's not safe to assume that without type checking the contained instances 
 you'll be safe from exploits. But definitely the most immediate threat is 
 just crashing the app.
 Cheers.
 
 Subject: Re: NSSecureCoding with containers (or, is NSArray lying?)
 From: graham@bigpond.com
 Date: Fri, 17 Jul 2015 09:52:33 +1000
 CC: r...@rols.org; cocoa-dev@lists.apple.com
 To: andre.frate...@hotmail.com
 
 
 On 16 Jul 2015, at 12:17 pm, André Francisco andre.frate...@hotmail.com 
 wrote:
 
 This can easily crash an app if I get a type that I'm not expecting, even 
 if it implements NSSecureCoding.
 
 
 Actually, probably not. It will likely start throwing exceptions all over 
 the place, which *may* cause termination, but it won’t crash in a way that 
 could lead to an exploit.
 
 —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:
 https://lists.apple.com/mailman/options/cocoa-dev/anthony.parker%40apple.com
 
 This email sent to anthony.par...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: NSCoding vs NSSecureCoding

2014-06-18 Thread Tony Parker
Hi Sean,

 On Jun 18, 2014, at 9:42 AM, Sean McBride s...@rogue-research.com wrote:
 
 On Tue, 17 Jun 2014 08:22:40 -0700, Tony Parker said:
 
 NSKeyedArchiver and NSKeyedUnarchiver also support secure coding as of 10.9.
 
 Tony,
 
 Thanks for the details.  Are there any issues in creating an archive on 10.9 
 and then decoding it on 10.8 or older?
 

Nope, this should work fine. The archive itself does not contain anything 
different. The reason that keyed archiver allows you to set secure coding is 
simply to perform an additional check when encoding that all classes you’re 
putting in the archive adopt the NSSecureCoding protocol. So in other words, 
the secure decoding is an option that can be applied to any keyed archive.

- Tony

 Cheers,
 
 --
 
 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: NSCoding vs NSSecureCoding

2014-06-17 Thread Tony Parker
 On Jun 17, 2014, at 8:00 AM, Mike Abdullah mabdul...@karelia.com wrote:
 
 
 On 17 Jun 2014, at 15:50, Sean McBride s...@rogue-research.com wrote:
 
 On Tue, 17 Jun 2014 09:17:46 +0100, Mike Abdullah said:
 
 I suspect the rationale might be “NSColor and NSImage live in AppKit,
 not Foundation, and the AppKit engineers aren’t so bothered about secure
 coding
 
 That's a good theory.  So I just looked through Foundation and found 
 numerous other clases that only conform to NSCoding and not NSSecureCoding 
 like NSAffineTransform, NSAttributedString, NSCharacterSet, etc.
 
 I guess I should conclude that NSSecureCoding is not a general replacement 
 for NSCoding and only really meant for XPC, and that Apple hasn't found much 
 use for sending those kinds of objects between processes.
 
 Ah, it was a nice theory, but no more than a theory then. Oh well! I think 
 your analysis about it coming down to XPC is probably nearer the mark.
 
 

The main purpose for secure coding is for NSXPCConnection, but NSKeyedArchiver 
and NSKeyedUnarchiver also support secure coding as of 10.9.

In “regular” coding, the name of the class that is created is stored in the 
archive and the unarchiver trusts it when it goes to allocate it during 
decoding. In secure coding, the name of the class is in the archive, but since 
the decoder also specifies a class as an argument (to 
-decodeObjectOfClass:forKey:), the decoder can double-check that the class in 
the archive is something that the caller expects. There is actually series of 
checks performed here.

By adopting the NSSecureCoding protocol, a class is declaring that not only has 
it switched to specifying classes when it decodes (again, with 
-decodeObjectOfClass:forKey:) but that the initWithCoder: method has been 
audited for other kinds of security risks as well. So we didn’t automatically 
upgrade all NSCoding classes to NSSecureCoding because we wanted to make sure 
that they were (a) appropriate for sending across a security boundary in the 
first place and (b) safe to do so. The framework in which a class lives is not 
really a factor in determining if it should adopt NSSecureCoding or not.

If you run into a class which you wish adopted secure coding, then please file 
a bug. We do already have plenty of requests for NSColor, NSImage, and 
NSAttributedString. 

- 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

preventing launch

2013-09-01 Thread Tony Giaccone


Is there a programatic way to prevent the launch of a particular application? I 
want to prevent certain applications under particular situations from starting 
up. 


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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: archiving report

2013-02-27 Thread Tony Parker
Hi Gerriet,

On Feb 26, 2013, at 10:56 AM, Gerriet M. Denkmann gerr...@mdenkmann.de wrote:

 
 On 27 Feb 2013, at 01:00, Gwynne Raskind gwy...@darkrainfall.org wrote:
 
 On Feb 26, 2013, at 12:47 PM, Gerriet M. Denkmann gerr...@mdenkmann.de 
 wrote:
 My investigations regarding archiving on OS X:
 
 1. NSArchiver stores all strings in Utf-8.
 This is inefficient for strings which contain mainly non-european 
 characters (e.g. Chinese or Thai) as one character will use 3 bytes (Utf-16 
 would use only 2).
 Corollary: It cannot store strings which contain illegal Unicode chars.
 
 And then in UTF-16, strings which contain mostly ASCII/European characters 
 are wasting 2x space. Six of one, half dozen of the other. This is a very 
 old debate and I'm grateful that Apple chose UTF-8 for storage, as UTF-16 
 makes things much more complicated.
 
 Or one could (as NSKeyedArchiver seems to do) choose the shortest 
 representation,
 
 
 2. NSKeyedArchiver seems to be ok.
 But it does create unnecessary data. E.g. in the case of an array 
 containing identical objects, like:
 NSArray *a = @[ @a, @a, , @a];
 With 1 000 000 items it creates 10,000,395 bytes - my version creates 
 only 1 000 332 bytes 
 and the output is still readable by NSKeyedUnarchiver.
 
 Are you sure this is happening? NSKeyedArchiver is documented as doing 
 deduplication of objects. If this is true, it's definitely a bug and there 
 is no reason Apple wouldn't want it fixed.
 
 Just try it yourself:
   #define NBR 100
   NSMutableArray *m = [ NSMutableArray array ];
   for ( NSUInteger i = 0; i  NBR; i++ ) [ m addObject: @a ];
   NSData *dataKeyed = [ NSKeyedArchiver 
 archivedDataWithRootObject: m ];
   NSLog(@%s NSKeyedArchiver created %10lu bytes , __FUNCTION__, 
 [dataKeyed length]);
 Then change NBR to 101 and compare.
 

Out of curiosity, what do you expect to happen if your string is @“ab” or 
something even longer, but repeated 1 million times? Your test implies that the 
answer is 2,000,000 but in fact the answer is that it only grows one more byte. 
The string is being de-duplicated but there is overhead associated with each 
object in the archive. The amount seems egregious for an object that is so 
small, (a string with one character), but real world archives are rarely 
1-character strings repeated 1 million times. Could the overhead be improved? 
Probably, but there are many tradeoffs to make. For example, keyed archives are 
used for nib files, which are read far more often than they are written. So 
we’ve made a decision to prefer read performance over write performance, when 
we have to choose between them. Regardless, I will look at the bug you filed 
and see if there are some improvements that can be made for this case without 
unduly impacting other, more common use cases.

 
 3, NSKeyedUnarchiver has several bugs.
 The string $null is converted to nil. 
 Very harmful if this string is part of a collection (like array, set or 
 dictionary).
 
 It should have already been mangled by NSKeyedArchiver.
 
 Strings (other than keys) do NOT get mangled by NSKeyedArchiver. 
 
 
 If the key in: encodeXXX:forKey: starts with an $ NSKeyedArchiver 
 correctly mangles this by prefixing
 another $. But NSKeyedUnarchiver does not find these mangled keys and 
 returns nil or 0.
 
 You can, as a workaround, consider keys prefixed by $ as reserved, however 
 this is certainly a bug. The fact that no one has reported it/gotten it 
 fixed in so much time shows that it's probably not a major issue, though.
 
 I have not reported these bugs, as I am convinced that Apple has no 
 interest in fixing these problems.
 
 This is the exact attitude that causes Apple to be perceived as not having 
 interest. Please file the bugs - the engineers reading this list can't give 
 high priority to things that developers don't report, as much as they'd 
 probably like to.
 
 I have filed the $null bug. Got back as duplicate with a very low id-number. 
 Meaning: this bug is known to Apple since several years. Still no fix.
 
 Gerriet.
 

Thank you for your bug reports. Yes, we do get them and we do listen to them.

- 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

PackageMaker Unable to Change Content Permission

2012-08-13 Thread Tony S. Wu
Hi,

I am trying to use PackageMaker to create a package for my application. This is 
the first time I opened up PackageMaker in Mountain Lion. I am running into a 
problem where the content permission cannot be changed to anyone else but me. I 
don't see any other users populated in the drop-down menu like it used to show 
up before. Wondering if anyone has any advice.

Please see screenshot here:
http://dl.dropbox.com/u/8901595/s3.png

Thanks,

- T
___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: JSON validator for Xcode

2012-03-06 Thread Tony Parker
Hi Alex,

On Mar 6, 2012, at 8:38 AM, Alex Zavatone z...@mac.com wrote:

 I'm in the middle of converting some data to JSON and have successfully run 
 my files through the JSONLint validator (http://jsonlint.com/).
 
 However, when trying to convert these files into serialized JSON in Xcode, 
 the JSON does not pass the isValidJSONObject test, returning NO.
 

It sounds like you're trying to do something like this:

NSString *s = @ … JSON here …;
BOOL valid = [NSJSONSerialization isValidJSONObject:s];

Which will return 0. Because an NSString by itself is not valid JSON (unless 
reading using the allow fragments option). The purpose of isValidJSONObject: is 
to take a Foundation object graph (e.g., NSDictionary objects, NSArray objects, 
etc) and see if it will work when given to the 
dataWithJSONObject:options:error: method.

If I'm misunderstanding what you're asking, please post a more complete code 
sample.

Thanks,
- Tony

 Of course I can plow through the data structure by hand, but I was wondering 
 if there is a way to get more data on just what the reason is why this data 
 fails or if there is an OC friendly JSON validator out there in the wilds 
 somwhere.
 
 
 TIA, 
 - Alex Zavatone
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/anthony.parker%40apple.com
 
 This email sent to anthony.par...@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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: boundingRectWithSize problem?

2012-02-07 Thread Tony Pollard
Using a temporary Text container/storage/layout seems to fix the problem.  See:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Tasks/StringHeight.html

The NS(Attributed)String+Geometrics category by Jerry Krinock is also handy:
 https://github.com/jerrykrinock/CategoriesObjC.git

Cheers!

Tony Pollard

On 27 Jan 2012, at 11:26 am, Tony Pollard wrote:

 Good thought Tim,  but for some reason it doesn't work in this case (both on 
 10.6  10.7).
 
 As you would expect, it is size/font sensitive so I can get the same failure 
 result (for the sample text given) with Times-Roman 11 point.  Of the various 
 text samples, it's only 1 in 10,000 or so that don't get their height 
 calculated correctly.
 
 Tony
 
 
 On 26 Jan 2012, at 6:59 pm, Tim Schröder wrote:
 
 I had exactly the same problem and solved it by using the 
 NSStringDrawingUsesDeviceMetrics option instead of 
 NSStringDrawingDisableScreenFontSubstitution.
 
 Tim
 
 Am 25.01.2012 um 16:26 schrieb Tony Pollard:
 
 Hi folks,
 
 I'm having a strange problem with NSAttributedString boundingRectWithSize 
 in getting the needed height for a fixed width.  It works 99% of the time, 
 but it consistently underestimates the height for certain text (by 
 approximately one line).  There doesn't appear to be a pattern for the text 
 that works and the text that fails  (tested on 10.6 and 10.7).
 
 The code is:
 
 NSRect textRect = [attrString boundingRectWithSize:NSMakeSize(300.0, 0.0)   
 // Width 300, any height (max height also 
 fails)
 
 options: NSStringDrawingUsesLineFragmentOrigin |// Needed 
 for multi-line
 
 NSStringDrawingDisableScreenFontSubstitution];
 
 The attributed strings are built from data sources.  Here's one that fails:
 
 Printing description of attrString:
 n. {
  CdctPhraseType = Grammer;
  NSColor = NSCalibratedRGBColorSpace 0.878431 0.0980392 0.160784 1;
  NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
 }A hopper is a device shaped like a large funnel, in which substances such 
 as grain, coal, animal food, or sand can be stored.{
  CdctPhraseType = Transition;
  NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1;
  NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
 }
 {
 }F.ex: Large trailers came along and tipped it into a big hopper.{
  CdctPhraseType = Transition;
  NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1;
  NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
 }
 
 The resulting Rect is too short by about 9 pixels.  Anyone had the same 
 problem?
 
 Tony Pollard
 
 
 
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/tim%40timschroeder.net
 
 This email sent to t...@timschroeder.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:
 https://lists.apple.com/mailman/options/cocoa-dev/tonyp%40neutral.co.uk
 
 This email sent to to...@neutral.co.uk


___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: boundingRectWithSize problem?

2012-01-27 Thread Tony Pollard
Good thought Tim,  but for some reason it doesn't work in this case (both on 
10.6  10.7).

As you would expect, it is size/font sensitive so I can get the same failure 
result (for the sample text given) with Times-Roman 11 point.  Of the various 
text samples, it's only 1 in 10,000 or so that don't get their height 
calculated correctly.

Tony


On 26 Jan 2012, at 6:59 pm, Tim Schröder wrote:

 I had exactly the same problem and solved it by using the 
 NSStringDrawingUsesDeviceMetrics option instead of 
 NSStringDrawingDisableScreenFontSubstitution.
 
 Tim
 
 Am 25.01.2012 um 16:26 schrieb Tony Pollard:
 
 Hi folks,
 
 I'm having a strange problem with NSAttributedString boundingRectWithSize in 
 getting the needed height for a fixed width.  It works 99% of the time, but 
 it consistently underestimates the height for certain text (by approximately 
 one line).  There doesn't appear to be a pattern for the text that works and 
 the text that fails  (tested on 10.6 and 10.7).
 
 The code is:
 
 NSRect textRect = [attrString boundingRectWithSize:NSMakeSize(300.0, 0.0)
 // Width 300, any height (max height also 
 fails)
  
 options: NSStringDrawingUsesLineFragmentOrigin |// Needed 
 for multi-line
  
 NSStringDrawingDisableScreenFontSubstitution];
 
 The attributed strings are built from data sources.  Here's one that fails:
 
 Printing description of attrString:
 n. {
   CdctPhraseType = Grammer;
   NSColor = NSCalibratedRGBColorSpace 0.878431 0.0980392 0.160784 1;
   NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
 }A hopper is a device shaped like a large funnel, in which substances such 
 as grain, coal, animal food, or sand can be stored.{
   CdctPhraseType = Transition;
   NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1;
   NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
 }
 {
 }F.ex: Large trailers came along and tipped it into a big hopper.{
   CdctPhraseType = Transition;
   NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1;
   NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
 }
 
 The resulting Rect is too short by about 9 pixels.  Anyone had the same 
 problem?
 
 Tony Pollard
 
 
 
 
 ___
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/tim%40timschroeder.net
 
 This email sent to t...@timschroeder.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

boundingRectWithSize problem?

2012-01-25 Thread Tony Pollard
Hi folks,

I'm having a strange problem with NSAttributedString boundingRectWithSize in 
getting the needed height for a fixed width.  It works 99% of the time, but it 
consistently underestimates the height for certain text (by approximately one 
line).  There doesn't appear to be a pattern for the text that works and the 
text that fails  (tested on 10.6 and 10.7).

The code is:

NSRect textRect = [attrString boundingRectWithSize:NSMakeSize(300.0, 0.0)   
// Width 300, any height (max height also fails)

options: NSStringDrawingUsesLineFragmentOrigin |// Needed for 
multi-line

NSStringDrawingDisableScreenFontSubstitution];

The attributed strings are built from data sources.  Here's one that fails:

Printing description of attrString:
n. {
CdctPhraseType = Grammer;
NSColor = NSCalibratedRGBColorSpace 0.878431 0.0980392 0.160784 1;
NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
}A hopper is a device shaped like a large funnel, in which substances such as 
grain, coal, animal food, or sand can be stored.{
CdctPhraseType = Transition;
NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1;
NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
}
{
}F.ex: Large trailers came along and tipped it into a big hopper.{
CdctPhraseType = Transition;
NSColor = NSCalibratedRGBColorSpace 0.227451 0.54902 0.258824 1;
NSFont = LucidaGrande 9.00 pt. P [] (0x50bbd0) fobj=0x50b7b0, spc=2.85;
}

The resulting Rect is too short by about 9 pixels.  Anyone had the same problem?

Tony Pollard




___

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: checking if directory is writable

2012-01-12 Thread Tony Arnold
Hi Rick,

On 10/01/2012, at 7:49 PM, Rick C. wrote:

 Just looking for confirmation, I can use NSFileManager isWritableAtPath: if I 
 want to check if a directory can be written to correct?  Or do I have to use 
 attributesOfItemAtPath:error:?  I don't need to change permissions just to 
 see if it's writable.  Thanks!

I was of the understanding that Apple's recommendation was just to try the 
operation you wanted to perform, and handle the error if there is one. This is 
taken from the NSFileManager header, directly above the isWriteableAtPath: 
declaration:

The following methods are of limited utility. Attempting to predicate behavior 
based on the current state of the filesystem or a particular file on the 
filesystem is encouraging odd behavior in the face of filesystem race 
conditions. It's far better to attempt an operation (like loading a file or 
creating a directory) and handle the error gracefully than it is to try to 
figure out ahead of time whether the operation will succeed.

(Sorry for the resend — my original reply only went to Rick, not the entire 
list)

all the best,


Tony




--
Tony Arnold
http://thecocoabots.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: Does anyone else dislike Xcode 4?

2011-07-24 Thread Tony
Yep, only if it felt as good as VS 2010 IDE, we would be having discussions 
on Cocoa and not the IDE.

-tony


-Original Message- 
From: Gary L. Wade

Sent: Sunday, July 24, 2011 11:13 AM
To: Julie Seif
Cc: cocoa-dev@lists.apple.com
Subject: Re: Does anyone else dislike Xcode 4?

Yes, Xcode 4 feels like a Windows app, not a Mac app. The idiotic modality 
it creates when all you want to do is create one file after another and 
leave each open to edit each as you do so, but instead it closes the one 
just opened prior, requiring you to go through unnecessary steps to reopen 
all the previously opened files precipitated both a bug and lots of emails 
to Apple executives and management. I suggest you do the same.


It's almost as if the development team believes all developers use 11 Airs 
rather than the two-monitor 27 setup many prefer.


- Gary L. Wade (Sent from my iPhone)

On Jul 24, 2011, at 10:57 AM, Julie Seif juliethech...@gmail.com wrote:


Hi, all,

I really do not like Xcode 4. I feel like I'm a beginner all over again in
Xcode 4... I was just so comfortable to the Xcode 3 and previous releases 
of

Xcode interface.

I found a rather handy post on how to uninstall Xcode 4. But my thing is, 
I
won't be able to build apps that run on the latest version of the OS 
right?


http://www.touch-code-magazine.com/uninstalling-xcode-4/

Everything I build in 4 seems to crash... but Xcode 3 it all works fine. I
almost feel like Xcode 4 is like Windows Vista. in terms of badness.

Thoughts, Recommendations, Suggestions?

Julie.

___

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 


___

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


finder eject images

2011-07-04 Thread Tony Romano
Not quite a cocoa questionŠ

By chance, does somewhere know where the images are for the eject button in
finder.  I looked in /system/library/coreservices/finder and they are not
bundled with it. I'd prefer the Mac OS X versions and not some 3rd party.
Thanks in advance.

Tony Romano





___

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: finder eject images

2011-07-04 Thread Tony Romano
Lee Ann and Patrick, thank you!

I suspect the one from ../coreservices/menu extras/Eject.menu uses the
character set one as well.  They converted to a pdf for displaying as an
image. Again, thank you.

Tony Romano

On 7/4/11 12:52 PM, Lee Ann Rucker lruc...@vmware.com wrote:


That's not the Finder sidebar icon, though. I'm not sure I've seen
anything use that one.

Also I think Apple frowns on copying their icons into your apps. Only the
ones you can get through imageNamed: or iconForFileType: are fair game.

- Original Message -
From: Patrick Robertson robertson.patr...@gmail.com
To: Cocoa-dev@lists.apple.com
Sent: Monday, July 4, 2011 12:24:20 PM
Subject: Re: finder eject images

Lots of system icons are stored in

/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/

EjectMediaIcon.icns is in there :)

On 4 July 2011 20:21, Lee Ann Rucker lruc...@vmware.com wrote:

 Unicode eject symbol 23CF, possibly in Apple Symbols font: ⏏

 - Original Message -
 From: Tony Romano tony...@hotmail.com
 To: List Cocoa Developer cocoa-dev@lists.apple.com
 Sent: Monday, July 4, 2011 12:16:02 PM
 Subject: finder eject images

 Not quite a cocoa questionŠ

 By chance, does somewhere know where the images are for the eject
button in
 finder.  I looked in /system/library/coreservices/finder and they are
not
 bundled with it. I'd prefer the Mac OS X versions and not some 3rd
party.
 Thanks in advance.

 Tony Romano





 ___

 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/lrucker%40vmware.com

 This email sent to lruc...@vmware.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/robertson.patrick%40gmai
l.com

 This email sent to robertson.patr...@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/lrucker%40vmware.com

This email sent to lruc...@vmware.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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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


Finder context menu behavior

2011-06-24 Thread Tony Romano
I'm trying to figure out what logic is being used to determine when the
version number is displayed along with the application name and icon in the
Finder Context Menu, 'Open With'.  Sometimes for a given application listed
like Word, Xcode, .etc.  you will see a version number in parenthesis,
(3.0.2).  Select a different file, right click it and select 'Open With' and
the same application listed will not have it's version number.  I'm using
LSCopyApplicationURLsForURL to get the list of applications,
LSCopyDisplayNameForURL to get the display name(Note: This api returns the
correct name(i.e. the one finder/spotlight displays) and can be different
than the one in the Info.plist) and using the key CFBundleShortVersionString
to obtain the version number.

The question is what determines when to show the version number.  Anyone
have insight on this?  Hopefully my explanation is clear enough.
 
Thanks,
Tony Romano





___

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: If No Memory Leaks, Is It Good Enough for Memory Management?

2011-06-20 Thread Tony Romano
Well, a loose definition for a leak is memory not being referenced anymore
and not returned to the heap manager.  However, you can still have large
consumptions of memory while being referenced and it's not considered a
leak by the Leaks tool.  BUT, you still have a problem due to your memory
consumption to increase until you run out of virtual space.  You need to
use Allocations and use the heap shot Analysis to determine what actions
in your application are causing the heap to grow and track down where the
memory is not being returned to the heap manager.

I'd do a search in Google for Heapshot analysis.
Tony Romano











On 6/20/11 12:28 AM, Bing Li lbl...@gmail.com wrote:

Dear all,

I am still a new programmer of Cocoa. In my program, at least right now,
there are no memory leaks according to Instruments. Is it good enough for
memory management?

What I designed is a TCP server which receives TCP messages. When I tested
it, 200,000 XML were sent to it with a loop without any delays. Each XML
had
800 bytes. In this case, no any memory leaks when testing it with
Instruments. However, according to Activity Monitor, the consumed memory
was
increased from 17.9M to more than 400M. Immediately after the sending, the
consumed memory started to be lowered until it was stopped to 100M. Was it
normal? Why wasn't it 17.9M eventually?

Thanks so much for your help!

Best,
greatfree
___

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



___

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: Automatically mirroring folders

2011-06-20 Thread Tony Romano
You coded your application to tell you when the directory has changed and
it's doing exactly that.  I'm not sure what changes you are interested in
knowing or ignoring(I.e. File added, file modified, file deleted).  In all
cases, you will need to track something so you have a reference, get a
notification that something has changed, decide what action you need to
take and then act on it.

Depending on what changes you are interested in, you may only need to
track the last time something changed, when you get a notification,
anything past this time needs an update. Or maybe you need to track all
the files in the directory, get a notification, and decide the difference
and act accordingly.  You can scale up or down as needed.

For example, the project I'm working on, I have a difference engine to
determine files added, deleted, or modified based on a reference I am
looking at in memory.  I am able to surgically modify my internal
structure and UI to match the changes happening on some external storage.
I think if you start playing around with turning notifications on or off,
or ignoring them at certain times, it may lead to errors.  This is just a
hunch on my part and it could totally work just fine.  I'd prefer to
process the notification and decide what to do.  From a performance
perspective, since you are using FSEvents, you have to do a read on the
directory no matter what and that is probably the biggest cost, setting up
a diff engine on a 10, 100, 1000, 1 files is fast.  Also remember that
FSEvent will coalesce multiple event on a directory, so block changes will
come across as one event and the diff engine will find all the changes on
one pass through the engine.

This is one aspect on OS X I find to be weak, notifications on files.
Sure, the are Kqueues, but they have limits.  Not as robust as I've seen
elsewhere.

HTH,
Tony Romano

On 6/20/11 12:53 AM, Matt Gough devlists...@gmail.com wrote:


Can you not make use of:

kFSEventStreamCreateFlagIgnoreSelf
Ignore events generated by this client. For example, an application
might want to watch for changes to a file so that it can reread it, but
should not needlessly reread it if the change to the file was caused by
the application itself writing out changes.

Matt

On 19 Jun 2011, at 17:48:32, Leonardo wrote:

 Problem: I have to automatically mirror 2 folders, /A and /B, such a way
 they contains the same files and folders.
 
 - So I FSEventStreamCreate with kFSEventStreamEventIdSinceNow,
 kFSEventStreamCreateFlagWatchRoot and a 2 seconds latency time.
 
 - I get a notification: there is a new file to copy from /A to /B. I
copy
 the file, but I quickly get a new notification that there is a new file
in
 B. Well, this notification is useless to me. I copied that file.
Therefore I
 don't need to copy it again.
 
 - So, before I copy the file, I thought, I stop and invalidate the
stream,
 then I copy the file, then I turn the stream on again. But here I get 2
 problems:
 
 1) At the end of the copyFile, I turn the stream on again, and the
Finder, a
 couple of seconds later (but it could even be shorter or longer)
updates the
 /B/.DS_Store file so I get a new notification. How to force the Finder
to
 update the .DS_Store file immediately after the copy? Or should I use a
 longer latency time? How long?
 
 2) During the period of time the stream is off, if some new files arrive
 within the folder /A, I lose the notification to copy it.
 
 How to workaround that?
 
 
 Regards
 -- Leonardo
 
 
 ___
 
 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/devlists.mg%40googlemail
.com
 
 This email sent to devlists...@googlemail.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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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


This code is leaking...

2011-06-19 Thread Tony Cate

- (NSImage *)illustration
{
if ( illustrationData != nil ){
NSImage* thisImage = [NSImage new];
NSBitmapImageRep* bitmapImageRep = [[NSBitmapImageRep alloc] 
initWithData:illustrationData];
NSPICTImageRep* pictImageRep = [[NSPICTImageRep alloc] 
initWithData:illustrationData];


if ( bitmapImageRep != nil ){
NSLog(@bitmapImageRep retainCount, [bitmapImageRep 
retainCount]);

[thisImage addRepresentation:bitmapImageRep];
NSLog(@bitmapImageRep retainCount, [bitmapImageRep 
retainCount]);

[bitmapImageRep release];
NSLog(@bitmapImageRep retainCount, [bitmapImageRep 
retainCount]);

}
if ( pictImageRep != nil ){
[thisImage addRepresentation:pictImageRep];
[pictImageRep release];
}
return thisImage;
}
return nil;
}

The logs look like this:

2011-06-19 09:42:49.817 MyTestApp[92772:903] thisBitmapImageRep 
retainCount: 2
2011-06-19 09:42:49.820 MyTestApp[92772:903] thisBitmapImageRep 
retainCount: 3
2011-06-19 09:42:49.822 MyTestApp[92772:903] thisBitmapImageRep 
retainCount: 2


bitmapImageRep is leaking. Why is the retain count 2 after the 
initWithData:? Should I file a bug?


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: Synthesised properties and additional actions

2011-06-19 Thread Tony Romano
Of course they are not designed for atomic operations, you have to add all
the critical sections to make it so. If you argue that you don't need the
multi threaded robustness, then you could argue the value hooking the
setter diminishes the benefit of using the synthesis feature since you are
writing the setter anyways.

Tony Romano

On 6/19/11 11:02 AM, Dave DeLong davedel...@me.com wrote:



On Jun 19, 2011, at 11:01 AM, Matt Neuburg wrote:

 I provide a good (I think) technique for doing this in my book (p. 275,
example 12-5 Overriding synthesized accessors). You can also download
sample code here:
 
 
https://github.com/mattneub/Programming-iOS-4-Book-Examples/tree/master/p
275b_overrideSynthesizedAccessors

Ha, that's quite clever.  I like it.  :)

Dave
___

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

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

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

This email sent to tony...@hotmail.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: Weird behavior of -URLByAppendingPathComponent:

2011-06-19 Thread Tony Romano
I can repro that as well, and I'd say it's a bug.  I also tried this as
well:


Using:  NSURL *baseURL = [NSURL URLWithString:@http://129.0.0.1/;];

(gdb) po [baseURL URLByAppendingPathComponent: @/foo]
http://129.0.0.1//foo



according to the discussion for URLAppendingPathComponent:

If the original URL does not end with a forward slash and pathComponent
does not begin with a forward slash, a forward slash is inserted between
the two parts of the returned URL, unless the original URL is the empty
string.

It puts the slash in.


Tony Romano



On 6/19/11 9:14 PM, Jens Alfke j...@mooseyard.com wrote:

Something seems wrong with -[NSURL URLByAppendingPathComponent:] --

(gdb) po baseURL
http://127.0.0.1:5984/
(gdb) po [baseURL URLByAppendingPathComponent: @foo]
http://127.0.0.1:5984/foo
(gdb) po [baseURL URLByAppendingPathComponent: @foo/]
http://127.0.0.1:5984/foo//

Why the doubled slash at the end, in the third result? There should only
be one. I¹m not sure if doubled slashes are actually illegal in URL
paths, but they¹re certainly weird, and I¹m pretty sure they¹d confuse a
lot of websites. I¹m guessing this is a CF bug.

[This is on OS X 10.6.7.]

And yes, I know about +URLWithString:relativeToURL: Š but that method
doesn¹t do the same thing. It only appends the string if the original URL
ends with a ³/³, otherwise it replaces the last path component. (Which is
correct behavior for interpreting relative paths, just not what I want.)

‹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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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: Drawing focus rings

2011-06-18 Thread Tony Romano
You will need this as well.

- (BOOL) resignFirstResponder
{
 ...
 // Invalidate the area around the focus ring
 [self setKeyboardFocusRingNeedsDisplayInRect:[self bounds]];
 ...
}


Tony Romano



On 6/18/11 10:19 AM, Lee Ann Rucker lruc...@vmware.com wrote:

From the sample code in ClockControl.m :

 // If we have focus, draw a focus ring around the entire cellFrame
(inset it a little so it looks nice).
if ([self showsFirstResponder]) {
// showsFirstResponder is set for us by the NSControl that is drawing
us.
NSRect focusRingFrame = clockRect;
focusRingFrame.size.height -= 2.0;
[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSBezierPath bezierPathWithRect: NSInsetRect(focusRingFrame,4,4)]
fill];
[NSGraphicsContext restoreGraphicsState];
}

- Original Message -
From: Peter Hudson peter.hud...@mac.com
To: cocoa-dev@lists.apple.com
Sent: Saturday, June 18, 2011 3:32:49 AM
Subject: Drawing focus rings

I need to draw a focus ring ( or something that looks like a focus
ring ) around a group of rows in an NSTableView.

Drawing a rectangle with NSBezierPath  works fine - how do I make it
look like a focus ring ?

Peter
___

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/lrucker%40vmware.com

This email sent to lruc...@vmware.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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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: FSEvents - handling kFSEventStreamEventFlagRootChanged flag

2011-06-16 Thread Tony Romano
The way to handle adding a new directory is to basically tear down the
stream and recreate it adding the new directory.  You won't lose any
events while your recreating the stream due to the caching done behind the
scenes.

When I stop a stream, I do the following:

-(void) streamDestroy
{

FSEventStreamStop(eventStream);  // This will prevent your event handler
from being called

Snip... // do anything else you need to do.

NSRunLoop * mainLoop = [NSRunLoop mainRunLoop]; // remove it from the run
loop and 
FSEventStreamUnscheduleFromRunLoop(eventStream, [mainLoop getCFRunLoop],
kCFRunLoopDefaultMode);
FSEventStreamInvalidate(eventStream); // Tear down the stream.
FSEventStreamRelease(eventStream);
eventStream = NULL;

}

Once the stream is destroyed, just recreate the stream with the new
directories you are interested in listening to.  I am able to add and
remove directories at will.




HTH,
Tony Romano

On 6/16/11 3:33 AM, Ajay Sabhaney co...@mothercreative.com wrote:


Hello,

I have setup an FSEventStream so that I can monitor a directory for file
changes. If the root directory that is being watched is moved/renamed, I
want to be able to keep monitoring the directory.  I am able to get the
new path of the root directory, however I am unsure of how to monitor the
new path. If I try to stop monitoring the watched directory (so I can
subsequently monitor the new root directory path), the following error
message is logged to my console:

(CarbonCore.framework) process_dir_events: watch_path: error trying to
add kqueue for fd 5 (/Users/path/to/orig/dir; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_path: error removing fd
6 from kqueue (Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error
trying to add kqueue for fd 6 (/Users/path/to/orig; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error
trying to add kqueue for fd 7 (/Users/path/to; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error
trying to add kqueue for fd 8 (/Users/path; Bad file descriptor)
(CarbonCore.framework) process_dir_events: watch_all_parents: error
trying to add kqueue for fd 9 (/Users; Bad file descriptor)

I'd appreciate if someone can suggest a way to monitor the new directory
path (and stop monitoring the original location) when receiving a
kFSEventStreamEventFlagRootChanged flag.  If invalidating and stopping
the stream (then restarting it) is the way to go, perhaps someone could
shed some light as to why I'm receiving the error mentioned above.

A similar question has been asked (but not yet solved) in the following
thread:
http://lists.apple.com/archives/filesystem-dev/2010/May/msg7.html

Ajay
___

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



___

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: After Autoreleasing Still Getting Leaked

2011-06-16 Thread Tony Romano
No,  I meant to use packet since I was speaking in terms at the protocol
level.  In either case, your explanation is helpful to Bing but I fear he
is new to socket level programming and will stumble with other issues as
well.  Your advice to use some framework is what he should follow.

Tony Romano


On 6/16/11 12:29 PM, Jens Alfke j...@mooseyard.com wrote:


On Jun 15, 2011, at 7:01 PM, Tony Romano wrote:

 TCP does NOT guarantee you will get the WHOLE PACKET on one receive
call.
 BEFORE you PROCESS any data, you need to know that you have ALL the
data.
 It may work MOST of the TIME, but there are times when it won't and your
 code WILL FAIL.

You¹re correct, but your point is a little confusing because you¹re using
the word ³packet² to mean an application-level message. Since Œpacket¹
already has a very specific meaning in IP networking, it¹s best to use a
different word like ³message² or ³chunk² or ³blob² or something.

So to rephrase: Just because you sent a chunk of bytes together in one
TCP write, the recipient is not guaranteed to receive the same chunk of
bytes in a single read. It¹s quite likely that this chunk will be
combined with bytes written in other write calls, or split in half across
two reads. TCP is taking the data you give it and shoving it into buffers
in the kernel, and those buffers get split up and sent out as IP packets
according to the kernel¹s whim and some complicated windowing algorithms.
There¹s absolutely no relation between the groups of bytes you write, the
IP packets that get sent, and the groups of bytes the client reads.

If I can once again plug my MYNetwork framework
http://bitbucket.org/snej/mynetwork, it includes a protocol called BLIP
that supports sending application-level messages, which can also include
metadata (key/value pairs like HTTP headers). It even supports
multiplexing multiple messages at the same time, so one huge message
won¹t clog up the socket and block others till it finishes. This stuff is
a pain in the ass to get right and I recommend using someone¹s
already-tested implementation over writing your own. (Or in other words,
³I suffered for my art so you wouldn¹t have to² :)

‹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: NSDragOperation for operationNotAllowedCursor !!

2011-06-15 Thread Tony Romano
Return this NSDragOperationNone is validateDrop:

Tony Romano











On 6/15/11 7:48 AM, Naresh Kongara nkong...@apple.com wrote:

Hi,

I'm working on a cocoa application, which is like a file browser similar
to finder.  In this application we implemented drag and drop of
files/folder. we succeeded in displaying copy and link cursors for
respective drag operations. As in finder how can we display a
OperationNotAllwedCursor when user tries to drag a folder onto itself.  I
mean which drag operation displays such kind of cursor.  I tried
returning all NSDragOperations from validateDrop: methods, but none of
the operation displays such kind of cursor.  Do we need to implement any
thing special for this . Pls do let me know if you have any idea.


Thanks,
nkongara___

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



___

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: After Autoreleasing Still Getting Leaked

2011-06-15 Thread Tony Romano
I state a point slightly different to Bing about the TCP issue.

TCP does NOT guarantee you will get the WHOLE PACKET on one receive call.
BEFORE you PROCESS any data, you need to know that you have ALL the data.
It may work MOST of the TIME, but there are times when it won't and your
code WILL FAIL.

When you code at the socket level, you need to be robust and know 2 Major
pieces of data.

1. Is this packet for you?  Anyone can send you data on that socket but
you need to make sure the packet is something you understand.  The classic
way is to wrap the data with a header with some magic number unique to
you.  Checking for the magic number helps signal your code, this is
something you can understand.

2. You need to know how many bytes any particular packet contains.
Usually there is some operation code pair with the number of byte to
expect for the operation.  These two additional pieces of information tell
you how much more you need to read and what operation to do on that data.

Once you have a good packet, then you can process it correctly.  There are
other things you need to do to make it robust, but these are the basics.

Note, if you have only type of data between your clients, you may not need
the operation code.

I have no idea if your run method is in a thread(you better figure out how
select works). If it is, the method notifyMessage, is a black box and I
have no idea what happens to the string there.  Is it retained, released,
ignored, no clue.  Your leak is not in the run method.  As I and others
have said before, countless times. DON¹T USE LEAKS!  It's like calling the
fire dept and saying there is a fire and NOT telling them where it is.

I'm not trying to be harsh, countless people are trying to help and they
are not convinced you are listening :-).
Tony Romano



On 6/15/11 2:20 PM, Scott Ribe scott_r...@elevated-dev.com wrote:

On Jun 15, 2011, at 2:30 PM, Jens Alfke wrote:

 On Jun 15, 2011, at 1:26 PM, Bing Li wrote:
 
 Actually, I attempt to design P2P system using Cocoa. Meanwhile, the
peer on Mac OS X must communicate with some Java systems. So I need to
use sockets and transmit XML.
 
 Sorry to be blunt, but it¹s clear from this answer (and others) that
you¹re not reading the suggestions people are giving you. All you
responded to here was one minor question at the end of Conrad¹s message,
not the numbered list of five major issues.

Not 100% sure, but I believe he may already have been told that he
doesn't need to use low-level sockets just because he's communicating
with Java...

Anyway, to Bing, my last advice:

- You have to follow proper memory management everywhere, not just where
you're originally allocating objects. As has been pointed out to you
multiple times now, your leak is not coming in the code snippet you
posted. It's happening elsewhere, in code that uses the return value, so
that's what you have to look at, what the consumers of that returned
value do with it.

- Given that you had two stack-smashing bugs in one small snippet of C,
and other oddities in the code, I think you really need to read a basic
introductory text on C.

- You also don't seem to really understand how sockets work. Perhaps I'm
wrong here, and your receivedMessage method does everything it would need
to do in terms of assembling message fragments, if only you weren't
potentially messing up strings because of boundary issues before you ever
called it. (In other words, if you just appended to NSData or some such
until you had a whole message.) But from the overall sense of your code
and your questions, I really doubt it. So an introductory text on network
programming is also in order (Stevens is the classic on this subject). Or
you could use higher-level network APIs, to which I believe you were
referred a long time ago: CFSocket, maybe NSURL depending on the
structure of the messages you're exchanging with Java.


-- 
Scott Ribe
scott_r...@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice




___

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



___

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: Memory Management for an Array

2011-06-13 Thread Tony Romano
Leaks is telling the line that allocated the memory.  The problem maybe
what you are doing with the object allocated some where else in the code.
I would suggest you use heapshot to figure out how much your application
is growing by calling this function and looking at the code paths that
could affect the growth. In order to make the problem simpler, you may
need to create smaller actions to isolate methods that allocate memory or
you maybe looking at several candidates at once making the investigative
work more difficult.  Also, remember that it take time for memory to
settle back down, it doesn't happen instantly in many cases to avoid
thrashing in heap allocations.  Again, heapshot is your friend here. After
seeing a memory growth due to an action.  Take a few other heapshots after
sometime(with doing any other actions) to see if the memory is trending
down.  If it doesn't, you have a bona-fide growth.

Tony Romano













On 6/13/11 7:31 AM, Bing Li lbl...@gmail.com wrote:

Dear Tito, Scott and all,

Thanks so much for your replies!

I think the memory management in my system is much better. I just used
Instruments to check potential leaks. To my surprise, I was still notified
that the following method got memory-leaking although the amount was
small.
Could you please tell me how to fix this problem? Maybe I just ignore it?

+ (NSString *)read:(NSString *)xml Path:(NSString *)xPath
{
// The Instruments indicated the following line got memory leaks.
The amount of leaked memory was not large (about 400KB)
NSXMLDocument *xmlDoc = [[NSXMLDocument alloc]
initWithXMLString:xml
options:NSXMLDocumentTidyXML error:NULL];

NSArray *nodes = [xmlDoc nodesForXPath:xPath error:NULL];
[xmlDoc release];
if ([nodes count]  0)
{
return [[nodes objectAtIndex:0] stringValue];
}
else
{
return @;
}
}


Best regards,
Bing Li



 On Mon, Jun 13, 2011 at 3:07 AM, Scott Ribe
scott_r...@elevated-dev.comwrote:

 On Jun 12, 2011, at 12:29 PM, Bing Li wrote:

  Do you think the below method is a correct solution to manage
memory? I
 am
  not sure if the array, nodes, could leak?

 Really, follow the memory management rules as written and as pointed
out
 to you before. That is how you know you're writing correct code.

 --
 Scott Ribe
 scott_r...@elevated-dev.com
 http://www.elevated-dev.com/
 (303) 722-0567 voice






___

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



___

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


NSFileHandle and Data Integrity

2011-06-10 Thread Tony S. Wu
Hi,

I have a simple client-server application. I use NSFileHandle to handle the 
communication between client and server. However, NSFileHandle doesn't seem to 
have any sort of guarantee on data integrity because when I try to send large 
amount of data over the network, packets will get dropped resulting in damaged 
data. What would be an ideal way to stop this from happening? I'd appreciate 
any recommendation.

Thanks.

Tony S. Wu
tonyswu@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: Archiving / Unarchiving Question

2011-06-02 Thread Tony S. Wu
Thanks for all the suggestions. Dave was right, the class was not included in 
the server target (bang my head). Using XML, however, does seem to make more 
sense, so I will look into that as well.

Thanks a lot,

Tony S. Wu
tonyswu@gmail.com




On Jun 2, 2011, at 12:26 AM, Jens Alfke wrote:

 
 On Jun 2, 2011, at 12:09 AM, Kyle Sluder wrote:
 
 Which is a good reason why you should not use archiving as a representation 
 of your data.
 
 Well, I think archiving can make sense as long as the producer and consumer 
 are the same application, and you know that the file/data format will never 
 need to be made open, and no external apps will ever need to read or write 
 the data. In that case the ease of implementation can be worth it.
 
 But if you have different apps involved, or the format needs to be 
 documented, it’s clearly the wrong way to go. 
 
 Use an implementation-agnostic serialization format like XML or even 
 property lists for data whose existence is not inextricably tied to your 
 class hierarchy.
 
 For something with property-list semantics I’d be more inclined to use JSON 
 than Foundation’s XML encoding. JSON is much more lightweight to parse, often 
 more compact, and more readable for debugging. (Of course there’s 
 unfortunately no built-in JSON API, but there are several good Cocoa ones 
 like json-framework aka SBJSON.)
 
 Avoid the temptation to use the binary property-list encoding over a network. 
 Yes it’s smaller and faster than XML, but I’ve still gotten no assurances 
 that the parser is robust enough to handle bad data (corrupt or maliciously 
 hacked) safely. Back in the day it was possible for bad binary-plist data to 
 crash the parser.  If that’s still the case, then reading binary plists from 
 an untrusted source like a socket is a potential security vulnerability.
 
 —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/tonyswu.mailinglist%40gmail.com
 
 This email sent to tonyswu.mailingl...@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


Archiving / Unarchiving Question

2011-06-01 Thread Tony S. Wu
Hi,

I've been beating my head against the monitor for the past 2 hours trying to 
figure this out. I would really appreciate it if someone can give me some 
guidelines.

I have a server - client application, and I need to archive an object so that I 
can send the data back and forth between the client and the server. Here is 
what the archiving methods in the object look like, property1 being a NSString:

- (void)encodeWithCoder:(NSCoder *)coder {
//  [super encodeWithCoder:coder];

[coder encodeObject:property1 forKey:@Property1];
}

- (id)initWithCoder:(NSCoder *)coder {
//self = [super initWithCoder:coder];
self = [super init];

property1 = [[coder decodeObjectForKey:@Property1] retain];
return self;
}

My problem is that I can archive and unarchive this object just fine on the 
client, but once I send the data over the network to the server, attempting to 
unarchive the object then results in an exception being thrown. I tried to 
compare the byte and length of the data before and after sending it over the 
network, and they appears to be identical. I tried to send a simple archived 
NSArray, and it works fine. So I must've missed something really important in 
my code.

I would appreciate any help.

Thanks,

Tony S. Wu
tonyswu@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: Archiving / Unarchiving Question

2011-06-01 Thread Tony S. Wu
Hi,

It's NSInvalidUnarchiveOperationException, reason is *** -[NSKeyedUnarchiver 
decodeObjectForKey:]: cannot decode object of class (DataObject)

Tony S. Wu
tonyswu@gmail.com




On Jun 1, 2011, at 6:28 PM, Roland King wrote:

 
 
 
 
 On Jun 2, 2011, at 9:23, Tony S. Wu tonyswu.mailingl...@gmail.com wrote:
 
 can archive and unarchive this object just fine on the client, but once I 
 send the data over the network to the server, attempting to unarchive the 
 object then results in an exception being thrown. 
 
 What's the exception?
 
 
 
 ___
 
 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


Synthesize getter in a NSThread

2011-05-21 Thread Tony Romano
I am running into an issue using a synthesized getter in a thread.
Observing memory consumed by the application in Activity Monitor, memory
continues to grow ~200k per sample until the OS gives an Out Of Memory
warning.  If I code my own getter, the app behaves as expected.  I have
striped it down to basically one call as follows:

-(void) process:(LeakyThreadAppDelegate *) myDelegate

{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Extract the object that contains the thread object

SomeClass *obj = [myDelegate myClass];

NSLog(@Thread Starting);

// Simplified to illustrate the problem

while (1) {



if ([[obj thread] isCancelled] == YES) {

break; 

}

}

NSLog(@Thread Cancelled);

[pool release];

}


Any clues as to what is wrong?  Thanks In Advance.

I have created a complete sample and pushed it up to GitHub:
git://github.com/tonyrom/Leaky-Getter-Sample-Code.git

-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: Synthesize getter in a NSThread

2011-05-21 Thread Tony Romano
Unless I misread the documentation on drain, adding a [pool drain]will
cause the pool to be deallocated.  I tried it anyways, and I get a couple
of emits in the console.

// This message emits when a call to the getter is made
2011-05-21 20:23:39.515 LeakyThread[5947:5707] ***
__NSAutoreleaseNoPool(): Object 0x10011d720 of class NSCFString
autoreleased with no pool in place - just leaking

// This message emits when a call to pool drain is called.
2011-05-21 20:23:39.515 LeakyThread[5947:5707] *** -[NSAutoreleasePool
drain]: This pool has already been drained, do not release it (double
release).


Still not sure what the problem is.
Tony Romano



On 5/21/11 6:58 PM, Ken Thomases k...@codeweavers.com wrote:

On May 21, 2011, at 3:27 PM, Tony Romano wrote:

 I am running into an issue using a synthesized getter in a thread.
 Observing memory consumed by the application in Activity Monitor, memory
 continues to grow ~200k per sample until the OS gives an Out Of Memory
 warning.  If I code my own getter, the app behaves as expected.  I have
 striped it down to basically one call as follows:
 
 -(void) process:(LeakyThreadAppDelegate *) myDelegate
 
 {
 
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
 // Extract the object that contains the thread object
 
 SomeClass *obj = [myDelegate myClass];
 
 NSLog(@Thread Starting);
 
 // Simplified to illustrate the problem
 
 while (1) {
 
 
 
 if ([[obj thread] isCancelled] == YES) {
 
 break; 
 
 }
 
 }
 
 NSLog(@Thread Cancelled);
 
 [pool release];
 
 }
 
 
 Any clues as to what is wrong?  Thanks In Advance.

A synthesized getter is entitled to put objects into the autorelease
pool.  The above code does not drain the pool until after the thread is
cancelled.  Everything autoreleased before then just accumulates.  Try
draining the pool each iteration of the loop.

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: Synthesize getter in a NSThread

2011-05-21 Thread Tony Romano
Yes, allocating the pool in the loop in conjunction with the drain did the
trick. It wont be too bad in the actual code because my thread is not free
running with a while(1), I use a condition lock.

Thanks for the help guys.

Tony Romano


On 5/21/11 8:31 PM, Roland King r...@rols.org wrote:

both allocate a new pool AND drain it each iteration of the loop

while( 1 )
{
pool = [ [ NSAutoReleasePool alloc ] init ];

// do stuff

[ pool drain ];
}

On 22-May-2011, at 11:28 AM, Tony Romano wrote:

 Unless I misread the documentation on drain, adding a [pool drain]will
 cause the pool to be deallocated.  I tried it anyways, and I get a
couple
 of emits in the console.
 
 // This message emits when a call to the getter is made
 2011-05-21 20:23:39.515 LeakyThread[5947:5707] ***
 __NSAutoreleaseNoPool(): Object 0x10011d720 of class NSCFString
 autoreleased with no pool in place - just leaking
 
 // This message emits when a call to pool drain is called.
 2011-05-21 20:23:39.515 LeakyThread[5947:5707] *** -[NSAutoreleasePool
 drain]: This pool has already been drained, do not release it (double
 release).
 
 
 Still not sure what the problem is.
 Tony Romano
 
 
 
 On 5/21/11 6:58 PM, Ken Thomases k...@codeweavers.com wrote:
 
 On May 21, 2011, at 3:27 PM, Tony Romano wrote:
 
 I am running into an issue using a synthesized getter in a thread.
 Observing memory consumed by the application in Activity Monitor,
memory
 continues to grow ~200k per sample until the OS gives an Out Of Memory
 warning.  If I code my own getter, the app behaves as expected.  I
have
 striped it down to basically one call as follows:
 
 -(void) process:(LeakyThreadAppDelegate *) myDelegate
 
 {
 
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
 // Extract the object that contains the thread object
 
 SomeClass *obj = [myDelegate myClass];
 
 NSLog(@Thread Starting);
 
 // Simplified to illustrate the problem
 
 while (1) {
 
 
 
 if ([[obj thread] isCancelled] == YES) {
 
 break; 
 
 }
 
 }
 
 NSLog(@Thread Cancelled);
 
 [pool release];
 
 }
 
 
 Any clues as to what is wrong?  Thanks In Advance.
 
 A synthesized getter is entitled to put objects into the autorelease
 pool.  The above code does not drain the pool until after the thread is
 cancelled.  Everything autoreleased before then just accumulates.  Try
 draining the pool each iteration of the loop.
 
 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/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


[NSMenu _enableItem} crash

2011-05-04 Thread Tony Cate

Reliably:

Launch project and get first document window.
Close document
Main Menu file open second document.
Close document
Click anywhere on the main menu and the project crashes.

Most of the time the stack ends with:

0 objc_msgSend
1 stub helpers
2 [NSMenu _enableItem]

Occasionally it consists of
0 objc_msgSend
1 ??? (or a reasonable facsimile)

After reading through some threads on this I thought my validation stuff 
may be an issue, so I commented it out. It made no difference. Because 
the crash occurs no matter where on the menu I click, I wondered if I 
was accidentally releasing the mainMenu. I'm not.


Any help with this problem would be greatly appreciated.

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: Debugging a sleepless Mac

2011-03-16 Thread Tony Romano
Not sure if it was mentioned, but did you look at the
/var/log/DiagnosticMessages log, it should have all the sleep activity
messages. 
Tony Romano












On 3/16/11 11:36 AM, Michael Nickerson darkshado...@mac.com wrote:


On Mar 16, 2011, at 8:37 AM, Matt Gough wrote:

 I've just been adding code to support NSWorkspaceWillSleepNotification.
Having lowered my Computer sleep time right down and left the Mac
untouched for several minutes, my code never fires and the Mac doesn't
actually go to sleep. Even without my app running and leaving the Mac
for several hours I notice that it still won't sleep.
 
 So it seems that something else is preventing idle sleep, but I've no
idea how to find the culprit. Is there some defaults setting I can use
that will log what the OS wants to do at sleep time and what is blocking
it?
 
 

I don't know of a way to log what might be blocking it, but I ran some
tests a while back that showed the system has to be idle for 10 minutes
before it will sleep.  Or, at least the disk has to be idle for 10
minutes, otherwise sleep is deferred.  I ran into this with one of my
applications that is long running.  It (can) access the disk frequently
to open and read files.  It turned out that was causing my Mac not to
sleep - definitely not something I wanted to happen.

What I ended up doing was writing a method that fires via a timer every
minute, and checks the sleep time - if I'm within 10 minutes of it, I
stop my application from reading anymore.  This stopped the problem, so
far as my own application was concerned, though as others have pointed
out there's plenty of other things that can keep the system from sleeping
that you might not have control of.

So, here's a short version of the code I'm using to do this (typed in
Mail):

#import IOKit/pwr_mgt/IOPMLib.h
#import IOKit/pwr_mgt/IOPM.h

- (void)checkIdleTime:(NSTimer *)timer
{
unsigned long mins = 0, systemIdleMinutes = 0;
CFTimeInterval idleSeconds = CGEventSourceSecondsSinceLastEventType(
kCGEventSourceStateCombinedSessionState, kCGAnyInputEventType );
static CFTimeInterval lastSeconds = 0.0;

systemIdleMinutes = lrint(idleSeconds / 60.0); /* Gives minutes of
inactivity */

if ( lastSeconds  idleSeconds ) {
/* User activity has occurred since last check, if you disabled
anything you can re-enable it here. */
}

lastSeconds = idleSeconds;

/* No need to check this if the system isn't idle. */
if ( systemIdleMinutes ) {
mach_port_t master_device_port;
io_connect_t fb = 0;
kern_return_t kr = kIOReturnSuccess;
IOReturn err = kIOReturnSuccess;

kr = IOMasterPort( bootstrap_port, master_device_port );
if ( kr == kIOReturnSuccess ) {
fb = IOPMFindPowerManagement( master_device_port );
if ( fb ) {
err = IOPMGetAggressiveness( fb, kPMMinutesToSleep, mins
);
if ( (err == kIOReturnSuccess)  (mins  0)  ((mins -
systemIdleMinutes) = 10) ) {
/* Do whatever you want to notify your app it should
stop disk access here */
}
/* If you want to find out how long until the screen
dims, you can do the same as above but use kPMMinutesToDim instead. */
IOServiceClose( fb );
}
}
}
}


Do note one limitation of this as is: if the system is set to sleep in 10
minutes or less, it will fire the condition as soon as the timer is hit
and there has been no user activity for at least a minute.  This is
something I've been meaning to look into but haven't as yet.


--
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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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:[Solution] Preventing a window from moving while dragging a view.

2010-10-07 Thread Tony Romano
I found what I needed to do.

Implement  in the custom view:

- (BOOL)mouseDownCanMoveWindow
{
return NO;  
}

Tony Romano
http://www.cocoaegghead.com




On Oct 6, 2010, at 11:13 AM, Tony Romano wrote:

I have a NSPanel with a NSToolbar and a tabless NSTabView to create an 
inspector.  The NSToolbarItems for the NSToolbar use a custom view.  This all 
works as expected.

I am trying to implement drag/drop to move toolbar items to/from different 
Inspector Panels to allow the user to customize their inspectors.  I've added 
the needed mouseDown and mouseDragged method in addition to the 
draggingSourceOperationMaskForLocal:.  When the drag operation begin during the 
mouseDragged: event, the NSPanel window is moving as well.  I am not calling 
the super implementation.

Question:  How do I prevent the Panel from moving during the drag operation?  
Do I need to use a modal loop?

Thanks!

Tony Romano
http://www.cocoaegghead.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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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


Preventing a window from moving while dragging a view.

2010-10-06 Thread Tony Romano
I have a NSPanel with a NSToolbar and a tabless NSTabView to create an 
inspector.  The NSToolbarItems for the NSToolbar use a custom view.  This all 
works as expected.

I am trying to implement drag/drop to move toolbar items to/from different 
Inspector Panels to allow the user to customize their inspectors.  I've added 
the needed mouseDown and mouseDragged method in addition to the 
draggingSourceOperationMaskForLocal:.  When the drag operation begin during the 
mouseDragged: event, the NSPanel window is moving as well.  I am not calling 
the super implementation.

Question:  How do I prevent the Panel from moving during the drag operation?  
Do I need to use a modal loop?

Thanks!

Tony Romano
http://www.cocoaegghead.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


Crash in NSBinder

2010-09-30 Thread Cate Tony
I just received two crash reports from a beta tester. Here's the common 
back-trace:

Thread 0 Crashed:
0   libobjc.A.dylib 0x937de688 objc_msgSend + 24
1   com.apple.AppKit0x9625a7b9 -[_NSBindingInfo dealloc] + 
128
2   com.apple.CoreFoundation0x91f4e38a CFRelease + 90
3   com.apple.CoreFoundation0x91edd3cd __CFArrayReleaseValues + 221
4   com.apple.CoreFoundation0x91f4e538 _CFRelease + 216
5   com.apple.AppKit0x96216025 -[NSBinder _dealloc] + 63
6   com.apple.AppKit0x96215fbe -[NSBinder dealloc] + 83
7   com.apple.Foundation0x9799244f NSPopAutoreleasePool + 431
8   com.apple.AppKit0x96048026 -[NSApplication run] + 930
9   com.apple.AppKit0x960151d8 NSApplicationMain + 574
10  com.3caam.A Cook's Books0x21f2 main + 24
11  com.3caam.A Cook's Books0x21ae start + 54

I don't use bindings. Perhaps in the future, but bindings are still magic to 
me. 

In one case, user was quitting the program. In the second case, she had just 
finished printing. 

I don't have a clue how to recreate this, let alone debug it. Has anyone seen 
this or have an idea what could be going on?

Tony
3 Cats And A Mouse
http://www.3caam.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: NSOutlineView

2010-09-09 Thread Tony Romano
What he is referring to is using a NSTreeController.  You bind the controller 
to the NSOutlineView and provide KVC compliant methods to enumerate the 
children and it can optionally create nodes for you as well.  Check out the 
sample SourceView from Apple.

Tony Romano
http://www.cocoaegghead.com




On Sep 9, 2010, at 7:59 AM, k...@highrolls.net wrote:

It is my understanding that an NSOutlineView is only 'populated' by using its 
Delegate Methods.

My manager (a Windows guy with no Cocoa) claims the NSOutlineView can be 
directly manipulated as in add root, add child etc.

Comments please before I pull my hair out.

-koko
___

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


___

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


recalling the original view height

2010-09-07 Thread Tony Romano
I have a NSWindow and a view.  The view is defined in a nib with a given height 
and width.  I am resizing the window to a new size and then optionally 
returning it to the original size and the view changes accordingly.  Is there a 
way of obtaining the original view height as defined in the nib or do I simply 
cache the value? I get worried with cached values because of some special 
situations that are dynamic.  However, I think the original value is gone once 
I resize it.  I tried search for this answer but its tough to refine the search 
on this one.  Thanks so much.

Tony Romano
http://www.cocoaegghead.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: recalling the original view height

2010-09-07 Thread Tony Romano
Thanks, this is what I suspected.
Tony Romano
http://www.cocoaegghead.com




On Sep 7, 2010, at 2:03 PM, John C. Randolph wrote:

Views have no storage for previous frame or bounds rectangles.  If you want to 
remember them, you'll need to save them yourself.

-jcr




___

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: iTunes 10 UI

2010-09-02 Thread Tony Romano
The controls used in the title bar are NSThemeWidgets and not your standard 
button.  It appears that many functions are overridden to control behavior.  
Your best best is to hide the standard controls and place your own buttons 
there.  This is what I have done for my Inspector Panel.
Tony Romano
http://www.cocoaegghead.com




On Sep 2, 2010, at 12:07 AM, Iceberg-Dev wrote:


On Sep 2, 2010, at 5:28 AM, John C. Randolph wrote:

 
 On Sep 1, 2010, at 8:15 PM, Eric E. Dolecki wrote:
 
 Top left, the traffic lights have been turned to the vertical. Is this
 something new or was this easy to do before? Is it just a custom
 implementation, or?
 
 It's pretty easy to implement that kind of thing.  NSWindow has a 
 -standardWindowButton: method that will give you a close button, zoom button, 
 etc.

It's not easy.

1. If you retrieve a NSButton with the official API, you will not be able to 
get the mouse over effect. This is a bug since Mac OS X 10.4 and it has still 
not been fixed in Mac OS X.

2. The NSButton Apple uses for NSWindow buttons are not simple NSButtons. And 
you can not display the mouse over version of the button rendering (as far as 
I've tried and Apple's DTS was not able to provide a solution either).



___

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


___

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: Making an NSMethodInvocation from the current method

2010-08-21 Thread Tony Romano
Use GCD.

   dispatch_sync(dispatch_get_main_queue(), ^{
// Call your function here
MyFunction (param 1, param2, ...);
});

Tony Romano
http://www.cocoaegghead.com




On Aug 21, 2010, at 10:03 PM, Roland King wrote:

Is there a built-in function to make an NSMethodInvocation from 'the current 
method I'm in with all current parameters', or does anyone have any code 
they've written to do this? 

Motivation, I'm writing a display class which can get updated from a background 
thread, it has a whole load of methods, some of which don't lend themselves to 
performSelectorOnMainThread (some take more than two arguments, some take 
primitives and I don't really want to wrap and unwrap into NSNumbers all over 
the place). What I really would like is in each method to be able to write 
something like

if( ![ NSThread isMainThread ] )
[ NSMagicFunctionReturningAnInvocationForThisCurrentFunction() 
performSelectorOnMainThread:@selector( invoke ) withObject:nil waitUntilDone:NO 
];
else
{
// method performing code here
}

but there is of course no such function I'm aware of nor can I easily think how 
I'd write such a thing. 

I have a current solution for those methods which are properties using 
forwarding because forwardInvocation: is the only function I know of which 
gives me a pre-packaged invocation object but I find it a bit inelegant and it 
only works for properties. That method briefly works as follows, if I want a 
property 'foo', I declare it, then use @dynamic to suppress the compiler 
warnings. In the class continuation I declare the same property prepended with 
an given prefix (I'm using TS_ for threadsafe) and implement it. I then 
override forwardInvocation: and methodSignatureForSelector: to check for the 
existance of a method TS_called selector and if it exists I switch the 
selector in the NSInvocation forwardInvocation: gives me and invoke it if I'm 
on the main thread or forward it to the main thread if I'm not. 

eg setFoo:123 is not implemented so methodSignatureForSelector: is called for 
setFoo: and I return the signature for TS_setFoo:. Then forwardInvocation: is 
called with a prepacked NSInvocation, I switch the selector to that for 
TS_setFoo: and invoke it. 

This only works for properties because I can only use @dynamic to suppress the 
warnings on those, other declared methods in the interface need to be 
implemented (or is there a way to suppress that warning) and the whole TS_ 
prefix thing seems a bit hokey to me so I was looking for a more direct way to 
make an NSInvocation. ___

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


___

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

2010-08-16 Thread Tony Romano
I assume you are letting the control actually highlight the selected rows?  If 
you are, then all the highlight/un-highlights are handled automatically.  Are u 
doing any sort of mouse tracking and highlighting code to determine which items 
are selected? Can you provide more info like just the code for section that 
implement the drag/drop parts and any mouse overrides?

-Tony


On Aug 16, 2010, at 6:28 PM, Erik Buck wrote:

 I have never seen the specific problem reported, but I have some suggestions:
 
 1) Are you using a retained or non-retain window as opposed to a buffered 
 window?  You want a buffered window.
 2) Is the view layer backed?  I don't know ifthat could cause the problem, 
 but I is a path to investigate.
 3) Have you turned on Quartz Debugging to see which areas of the window are 
 being redrawn?  If so, where the highlighted areas redrawn or not?
 4) Are you recursively causing displays?  That doesn't work, so don't do it.  
 Have you tried [outlineView performSelector:@selector(display) withObject:nil 
 afterDelay:0.0f] instead of calling display again as the side effect of a 
 display message?
 
 --- On Mon, 8/16/10, k...@highrolls.net k...@highrolls.net wrote:
 
 From: k...@highrolls.net k...@highrolls.net
 Subject: concludeDragOperation
 To: Cocoa-Dev Cocoa-Dev cocoa-dev@lists.apple.com
 Date: Monday, August 16, 2010, 6:02 PM
 
 The docs say:
 
 Invoked when the dragging operation is complete, signaling the receiver to 
 perform any necessary clean-up.
 
 My question is how does one clean up all highlight artifacts in an 
 NSOutlineView such as these:
 
 http://highrolls.net/high_light_issue/page.html
 
 I have tried -display , -reloadItem and reloadData all to no avail.
 
 Steve Jobs was stumped and suggested this list might be helpful.
 
 Was he right?
 
 -koko
 ___
 
 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/erik.buck%40sbcglobal.net
 
 This email sent to erik.b...@sbcglobal.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/tonyrom%40hotmail.com
 
 This email sent to tony...@hotmail.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


SMTP Framework for Cocoa

2010-08-13 Thread Tony S. Wu
Hi,

Is there a easy to use framework for sending email via SMTP authentication? I 
did a some searchings and found MailCore, Pantomime, EdMessage, but they all 
seem quite out-dated to me. Thanks.

Tony S. Wu
tonyswu@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


NStoolbarItem, custom view, setAction:

2010-08-09 Thread Tony Romano
I'm trying to add a toolbar item that has a custom view.  I suspect there is a 
bug with the NSToolbarItem setAction: method if I choose to use a basic custom 
view(derived from NSView). In my mouse down, calling [NSApp 
sendAction:[_toolbarItem1 action] to:[_toolbarItem1 target] from:_toolbarItem1] 
has no effect, the action selector is nil;  The item draws fine, so the view 
appears to be wired up correctly. (_toolbarItem1 is the correct pointer, fyi).

Overview:

Scenario 1 -If I set the NSToolbarItem's view to a custom view that is derived 
from an NSControll(most of the ones from the Input and Values controls), then 
calling set action/target works and in my mouseDown, the action selector is 
valid and the action gets invoked.

Scenario 2 -If I set the NSToolbarItem's view to a custom view that is derived 
from NSView(from the layout view such as the basic Custom View), then calling 
set action/target has NO effect, i.e. the action selector in nil.

According to the documentation, I can use ANY custom view that is derived from 
NSView.

The procedure for adding a custom view item is very similar to that for a 
custom image item. (“Custom” in this context means any object from the 
Interface Builder library as well as instances of a custom NSView subclass.) 
Just drag any view object from the library onto the Allowed Toolbar Items area. 
Click the item once and press Command-1 to display the Attributes pane for the 
object as a toolbar item; click again to edit the attributes of the item as 
itself. You should modify the size of the custom view item in the Size pane of 
the inspector, not directly. If you drag a Custom View object into the 
allowed-items set, click it twice and set the name of the custom NSView class 
in the Identity pane of the inspector (Command-6).


Looking at the documentation for NSToolbarItem setAction:, it has a little 
note: For a custom view item, this method calls setAction: on the view if it 
responds..   Which I infer to mean, that the basic Custom View should work.  
What really interesting is NSToolbarItem is derived from NSObject(which is a 
whole other discussion on this design), so the setAction and setTarget need to 
get stored somewhere, there are no apparent private variables to store these 
items. Looking at the toolbar item in the debugger, the object knows that the 
view doesn't support set/get action because they set some bits on creation and 
look at the bit setting instead of calling respondsToSelector every time.

 Anyone have any ideas as to why I can't use a custom view derived from NSView?

Thanks,
-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: NStoolbarItem, custom view, setAction:

2010-08-09 Thread Tony Romano
That's the conclusion I came to but wanted to make sure I didn't miss something 
obvious.  The documentation is omitted this detail.  I'll file a bug for this.  

For the life of me, I cannot understand why NSToolbarItem contains the view and 
is not derived from a view, it just adds more work on the developer to do 
custom work.  I wanted to do some work and need to track the mouse messages.  
It would have been much simpler if it was derived from the view and I could 
over-ride the methods.

Thanks for confirming this Peter,
-Tony

On Aug 9, 2010, at 5:51 PM, Peter Ammon wrote:

 
 On Aug 9, 2010, at 5:37 PM, Tony Romano wrote:
 
 [...]
 
 
 Looking at the documentation for NSToolbarItem setAction:, it has a little 
 note: For a custom view item, this method calls setAction: on the view if 
 it responds..   Which I infer to mean, that the basic Custom View should 
 work.  What really interesting is NSToolbarItem is derived from 
 NSObject(which is a whole other discussion on this design), so the setAction 
 and setTarget need to get stored somewhere, there are no apparent private 
 variables to store these items. Looking at the toolbar item in the debugger, 
 the object knows that the view doesn't support set/get action because they 
 set some bits on creation and look at the bit setting instead of calling 
 respondsToSelector every time.
 
 Anyone have any ideas as to why I can't use a custom view derived from 
 NSView?
 
 You can set any custom view you want.  However, NSToolbarItem delegates its 
 target/action entirely to its view, and has no storage for these properties.  
 If your view does not implement -target or -action, then the toolbar item's 
 target and action will both be NULL.
 
 Hope this helps,
 -Peter
 

-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


NStoolbaritem and a custom view

2010-08-06 Thread Tony Romano
For NSToolbarItem and a custom view, do you need to call the selector for the 
action or is that handled automatically?  I think it's not handled 
automatically because I have to handle the mouse events to update the drawing 
so I assume by calling super, it won't invoke the action because I changed the 
view in the item.  At least this is what I am observing.  Someone please 
confirm.

Thanks,
-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: NSPanel, changing the look of the min button

2010-08-03 Thread Tony Romano
Thanks Uli, couldn't see the forest through the trees!  This is how I 
implemented it and it seems to work quite well.

- (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)windowStyle 
  backing:(NSBackingStoreType)bufferingType 
defer:(BOOL)deferCreation
{
self = [super initWithContentRect:contentRect styleMask:windowStyle 
backing:bufferingType defer:deferCreation];

// Hide the standard minimize and zoom buttons
NSButton *button = [self standardWindowButton:NSWindowZoomButton];
[button setHidden:YES];
button = [self standardWindowButton:NSWindowMiniaturizeButton];
[button setHidden:YES];

// Determine where the old min button was located and make that the 
location for the triangle
// At this point, the toolbar has not been added to the frame, update 
the frame in awakeFromNib
NSRect minFrame = [button frame];
NSView *superView = [button superview];

// Create the new disclosure triangle button
disclosureTriangle = [[NSButton alloc] initWithFrame:minFrame]; 

// Set the style
[disclosureTriangle setBezelStyle:NSDisclosureBezelStyle];
[disclosureTriangle setButtonType:NSOnOffButton];
[disclosureTriangle setBordered:YES];

// Make sure title is an empty string to show the triangle properly
[disclosureTriangle setTitle:@];

// Setup Target=First Responder / Action
[disclosureTriangle setAction:@selector(showOrHideInspector:)];
[disclosureTriangle setTarget:nil];

// Finally add it to the view hierarchy.  Need to leave the old min 
button there because the theme frame expects it be there.
[superView addSubview:disclosureTriangle]; 
[disclosureTriangle release];

return self;
}

-(void) awakeFromNib
{
NSButton *button = [self 
standardWindowButton:NSWindowMiniaturizeButton];
NSRect minFrame = [button frame];
minFrame.origin.y +=1;
[disclosureTriangle setFrame:minFrame];
}


-Tony

On Aug 3, 2010, at 6:46 AM, Uli Kusterer wrote:

 Am 03.08.2010 um 00:31 schrieb Tony Romano:
 Changing the argument to the correct flag gets me the button, however, 
 setting the style doesn't have any effect.  I moved the code to 
 initWithContentRect: post the call to super, still no change.  I 
 introspected the view with F-Script and it has the bezel style I set but the 
 window still draws the standard widget.  Any other ideas?
 
 Have you tried hiding that button and creating your own button to put in its 
 place?
 
 -- Uli Kusterer
 The Witnesses of TeachText are everywhere...
 
 
 
 

-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


NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
I have an NSPanel and I want to change the look of the min button and 
completely hide the resize button.  The min button I want to make into a bezel 
style of a disclosure triangle.  I am using this line of code to access the min 
button but it returns nil in my controllers' windowDidLoad.  

NSButton *minButton = [[self window] 
standardWindowButton:NSMiniaturizableWindowMask];

Just as a test, I changed to style mask to NSClosableWindowMask and it does 
return the correct theme widget.  Not sure why the min mask is not returning 
the correct widget.  Also, any comment on the approach or should I be looking 
at a completely different path?  I know one alternatively is to completely 
write my own header and draw things the way I want. 

The second question is, how do I completely hide the resize button, it's 
disabled via IB, but the button still shows(albeit disabled).

Thanks,
-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: NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
Im not trying to disregard the HIG.  The panel is the basis for an inspector(s) 
for properties for a drawing application.  Looking at other well known 
applications, it seemed there is precedence.  If that precedence is wrong, I 
won't follow it.  Please advise.

-Tony

On Aug 2, 2010, at 2:58 PM, John Joyce wrote:

 
 On Aug 2, 2010, at 4:47 PM, Tony Romano wrote:
 
 I have an NSPanel and I want to change the look of the min button and 
 completely hide the resize button.  The min button I want to make into a 
 bezel style of a disclosure triangle.  I am using this line of code to 
 access the min button but it returns nil in my controllers' windowDidLoad.  
 
 NSButton *minButton = [[self window] 
 standardWindowButton:NSMiniaturizableWindowMask];
 
 Just as a test, I changed to style mask to NSClosableWindowMask and it does 
 return the correct theme widget.  Not sure why the min mask is not returning 
 the correct widget.  Also, any comment on the approach or should I be 
 looking at a completely different path?  I know one alternatively is to 
 completely write my own header and draw things the way I want. 
 
 The second question is, how do I completely hide the resize button, it's 
 disabled via IB, but the button still shows(albeit disabled).
 
 Thanks,
 -Tony
 Please avoid confusing users if at all possible by adhering to the Human 
 Interface Guidelines.
 Make sure your app really has valid reasons to 
 One reason this is not easy to do is so that we don't end up with crazy 
 thoughtless interfaces as often as other platforms do.
 
 The reason these appear but are disabled is that standard window and panel 
 behavior includes this and the user needs to see it is grayed out to 
 understand intuitively that that button is currently disabled.
 
 That said, check out the sample code for Core Data Stickies to see how to 
 build your own window styling.
 
 Again, read the HIG, adhere to it and common Mac application paradigms or 
 users will just hate your application.
 
 One business case for HIG adherence is reduced support costs  because your 
 users will intuit the interface more...
 
 

-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: NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
Thanks, I totally misread that.  

Changing the argument to the correct flag gets me the button, however, setting 
the style doesn't have any effect.  I moved the code to initWithContentRect: 
post the call to super, still no change.  I introspected the view with F-Script 
and it has the bezel style I set but the window still draws the standard 
widget.  Any other ideas?

-Tony

On Aug 2, 2010, at 2:53 PM, Kyle Sluder wrote:

 On Aug 2, 2010, at 2:47 PM, Tony Romano tony...@hotmail.com wrote:
 
 NSButton *minButton = [[self window] 
 standardWindowButton:NSMiniaturizableWindowMask];
 
 You're using the wrong flag here. You want one of the NSWindowButton flags. 
 See the documentation for -standardWindowButton:.
 
 
 
 The second question is, how do I completely hide the resize button, it's 
 disabled via IB, but the button still shows(albeit disabled).
 
 You don't hide this button as that violates the HIG.
 
 --Kyle Sluder

-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: NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
All the buttons are really called WSThemeWidgets which supports your suspect of 
custom draw code.  So using the zoom button won't make a difference( I tried it 
as well).  I'm trying to change the minimize button to a disclosure triangle 
that will show/hide the inspector currently being displayed without hiding the 
panel.  I have this functionality via menu/keybindings but wanted to add a 
widget on the panel as another method.

-Tony

On Aug 2, 2010, at 3:36 PM, Kyle Sluder wrote:

 On Mon, Aug 2, 2010 at 3:31 PM, Tony Romano tony...@hotmail.com wrote:
 Changing the argument to the correct flag gets me the button, however, 
 setting the style doesn't have any effect.  I moved the code to 
 initWithContentRect: post the call to super, still no change.  I 
 introspected the view with F-Script and it has the bezel style I set but the 
 window still draws the standard widget.  Any other ideas?
 
 I believe the buttons are actually private subclasses of NSButton
 whose drawing methods completely ignore most of the button flags.
 
 How are you trying to change the minimize button? Would it be better
 to instead change the behavior of the zoom button? Panels aren't
 supposed to have (enabled) minimize buttons as per the HIG.
 
 --Kyle Sluder
 

-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: NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
Honestly guys, I have no devious motives here ! :-)  I am not trying to take 
any shortcuts, I am just trying to learn the correct way to do things.  There 
are programs such as Photoshop, OmniGraphSketcher that do similar things.  For 
this UI, I am trying to follow precedence.  I know the Omni code is completely 
custom drawn.  I know Photoshop doesn't use cocoa as of CS4 so it must be 
custom as well.  

Right now I have 4 inspectors, it may go to 5 but thats about it.  I can easily 
put the disclosure triangle on the content view and be done with it.  
Unfortunately, I still don't understand what I need to do to make my original 
proposal work short of creating my own Inspector Panel class.  Is it possible 
using NSPanel as it stands or do I need to do a bunch of custom code.

By using a tab-less NSTabView, NSTabViewItems and a NSToolBar combined with the 
NSPanel, I get like 80% of the functionality of nice inspectors.  I can make 
the inspector show/hide while keep the Panel toolbar visible and other cool 
stuff.  I realize that last 20% can consume a lot more time then I spent on the 
first 80% and, as you say, it may not be worth it. 

I really appreciate the feedback!
-Tony
On Aug 2, 2010, at 3:51 PM, Quincey Morris wrote:

 On Aug 2, 2010, at 15:31, Tony Romano wrote:
 
 Changing the argument to the correct flag gets me the button, however, 
 setting the style doesn't have any effect.  I moved the code to 
 initWithContentRect: post the call to super, still no change.  I 
 introspected the view with F-Script and it has the bezel style I set but the 
 window still draws the standard widget. Any other ideas?
 
 Yes -- don't do that. :)
 
 You're trying to take a shortcut by trying to get NSPanel to provide 
 inspector behavior that it doesn't have. This is not a great idea, not least 
 for the reason that it risks breaking when panels or the standard buttons are 
 implemented differently.
 
 How many of these inspectors do you have? Unless you have a *lot*, it 
 probably isn't worth spending your time to do it this way -- leave the panel 
 title bar alone and put your disclosure triangle at the top of the panel 
 content view.
 
 The behavior you're trying to imitate here (say, Photoshop's) is designed to 
 deal with having lots and lots of inspectors, has a fairly complex 
 implementation that doesn't entirely depend on standard NSWindow or NSPanel 
 behavior (AFAIK), and goes hand in hand with lots of other sophistication, 
 such as docking of palettes, draggable palette tabs, which are even more work 
 that might not be appropriate for your app.
 
 Why not do the obvious thing (if you haven't already), and waste the 
 height of the NSPanel title bar (put the disclosure triangle in the panel 
 content view), and see who complains about it -- and, far more importantly, 
 *what* they complain about. Maybe your real problem will be that you have too 
 many inspectors, not that the individual inspectors are too big vertically.
 
 It seems to me that (unless you've gone through all of these factors already) 
 you're indulging yourself in something similar to premature optimization.
 
 
 ___
 
 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


Re: NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
Thanks Kyle, I've reviewed the inspector code.

I've thought about the toolbar viz button and wondered how hot the flames would 
be under my feet for changing the way a standard button behaves  :-)  That's 
one thing I admire about Apple, consistency is the high order bit.  At least my 
original idea was to change the way the button looks and give it a new behavior.

-Tony

On Aug 2, 2010, at 4:22 PM, Kyle Sluder wrote:

 On Mon, Aug 2, 2010 at 4:16 PM, Tony Romano tony...@hotmail.com wrote:
 Honestly guys, I have no devious motives here ! :-)  I am not trying to take 
 any shortcuts, I am just trying to learn the correct way to do things.  
 There are programs such as Photoshop, OmniGraphSketcher that do similar 
 things.  For this UI, I am trying to follow precedence.  I know the Omni 
 code is completely custom drawn.  I know Photoshop doesn't use cocoa as of 
 CS4 so it must be custom as well.
 
 Yes, our inspectors are custom drawn. You're more than welcome to help
 yourself to our code at
 http://github.com/omnigroup/OmniGroup/tree/master/Frameworks/OmniInspector/
 (provided you follow the license, of course!).
 
 Barring that, have you thought about using the toolbar visibility
 button for this instead, and just retargeting its action?
 
 --Kyle Sluder
 

-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: NSPanel, changing the look of the min button

2010-08-02 Thread Tony Romano
Ok, seems like there is no middle ground between using straight cocoa and a 
custom titlebar.   

Not sure if I can picture a solution using a NSOutlineView, seems orthogonal to 
what I am trying to achieve.  If you go to Omni website and install the trial 
version of OmniGraphSketch and look at their inspectors, that will give you 
what I am trying to achieve(yeah, their code is Open Sourced and I am free to 
use it).  The disclosure triangle hides/shows the panel.  When hidden, you get 
just the title bar and the tool button bar showing.

Maybe the disclosure triangle in the custom view won't be so bad.  I need to 
try that.  It avoids the proximity issue with the standard button.

Sorry on the confusion with Precedence/Precedents.  I need slow down.

Again, super thanks for the feedback.

-Tony
On Aug 2, 2010, at 4:43 PM, Quincey Morris wrote:

 On Aug 2, 2010, at 16:16, Tony Romano wrote:
 
 Honestly guys, I have no devious motives here ! :-)  I am not trying to take 
 any shortcuts, I am just trying to learn the correct way to do things.  
 There are programs such as Photoshop, OmniGraphSketcher that do similar 
 things.  For this UI, I am trying to follow precedence.  I know the Omni 
 code is completely custom drawn.  I know Photoshop doesn't use cocoa as of 
 CS4 so it must be custom as well.  
 
 Oh, I just got it. You've been saying precedence and I just realized you 
 meant precedents. (I thought you meant something like behavior inheritance.)
 
 Before you use Photoshop or OmniGraphSketcher or anything else that has a 
 similar palette system as a precedent, you need to be sure that you're trying 
 to solve the same problem that those systems were designed to solve. That's 
 what I was trying to direct your attention towards.
 
 Right now I have 4 inspectors, it may go to 5 but thats about it.  I can 
 easily put the disclosure triangle on the content view and be done with it. 
 Unfortunately, I still don't understand what I need to do to make my 
 original proposal work short of creating my own Inspector Panel class.  Is 
 it possible using NSPanel as it stands or do I need to do a bunch of custom 
 code.
 
 The reason I ... er ... accused you of using a shortcut is that your proposed 
 solution isn't really repurposing the minimize button (and, it could be 
 strongly argued, shouldn't repurpose it). The shortcut comes from not paying 
 to attention to the *accidental* geographic similarity between the minimize 
 button and the control you had in mind.
 
 If you chose to implement this with custom code, then you'd have to deal with 
 only the following:
 
 1. Suppressing the NSPanel title bar (possibly not hard).
 
 2. Handling dragging of a window with no title bar (not hard).
 
 3. Drawing an alternate gradient to look like a title bar (not hard).
 
 4. Providing an alternate close control implementation (not hard, and quite 
 possibly shouldn't be the traffic-light-style red button anyway)
 
 5. Providing your disclosure control (not hard).
 
 6. Resizing the window when the disclosure control action is triggered (not 
 hard).
 
 Well, that's all I can think of. If you really wanted to have this behavior, 
 it doesn't seem hard to implement in a way that is only a few lines of code 
 and doesn't abuse the frameworks. In fact, I'd start by looking into using 
 NSOutlineView to get the collapsing appearance and behavior for almost free.
 
 But, really, be sure you know what problem you're trying to solve before 
 putting a lot of effort into solving 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/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


Re: drawingRectForBounds not being called

2010-07-31 Thread Tony Romano
Here is one additional thing I discovered.  I have an outlet to the NSTextField 
that contains the cell so I can write text to it.  This is the only connection 
to my application.  If I remove the outlet, the drawingRectForBounds: is 
called.  If I add it back, it won't get called. Why should having an outlet to 
the control have any affect on this method getting called.  Something weird is 
going on.

-Tony

On Jul 30, 2010, at 4:05 PM, Tony Romano wrote:

 @interface ViewStatusTextCell : NSTextFieldCell
 
 - (NSRect)drawingRectForBounds:(NSRect)theRect;
 
 @end
 
 - (NSRect)drawingRectForBounds:(NSRect)theRect
 {
   NSRect rect = [super drawingRectForBounds:theRect];
   NSSize textSize = [self cellSizeForBounds:theRect];
   
   NSUInteger heightDelta = rect.size.height - textSize.height;
   if (heightDelta  0) {
   rect.size.height -= heightDelta;
   rect.origin.y += heightDelta/2;
   }
   
   return rect;
 }
 
 On Jul 30, 2010, at 4:03 PM, Kyle Sluder wrote:
 
 On Fri, Jul 30, 2010 at 3:38 PM, Tony Romano tony...@hotmail.com wrote:
 I have an NSTextTextField in my nib that is using a custom NSTextFieldCell 
 (set in IB) class that has only one method over-riden, 
 drawingRectForBounds.  The method is not being called.  This is what I have 
 done.
 
 1. Set  a break point to verify it is not being called.
 2. Using F-Script, verified that the instance of NSTextField is using my 
 custom cell.  I can invoke my method via F-Script as well.
 3. Verified the correct spelling and signature of the method.
 
 Are you certain? The method is named -drawingRectForBounds:. Since you
 omitted the colon above, I am wondering if you have in fact misspelled
 the method.
 
 Please post your code.
 
 --Kyle Sluder
 
 
 -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/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


drawingRectForBounds not being called

2010-07-30 Thread Tony Romano
I have an NSTextTextField in my nib that is using a custom NSTextFieldCell (set 
in IB) class that has only one method over-riden, drawingRectForBounds.  The 
method is not being called.  This is what I have done.

1. Set  a break point to verify it is not being called.
2. Using F-Script, verified that the instance of NSTextField is using my custom 
cell.  I can invoke my method via F-Script as well.
3. Verified the correct spelling and signature of the method.

Anyone have other ideas as to what I am overlooking?

Thanks,
-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: drawingRectForBounds not being called

2010-07-30 Thread Tony Romano
@interface ViewStatusTextCell : NSTextFieldCell

- (NSRect)drawingRectForBounds:(NSRect)theRect;

@end

- (NSRect)drawingRectForBounds:(NSRect)theRect
{
NSRect rect = [super drawingRectForBounds:theRect];
NSSize textSize = [self cellSizeForBounds:theRect];

NSUInteger heightDelta = rect.size.height - textSize.height;
if (heightDelta  0) {
rect.size.height -= heightDelta;
rect.origin.y += heightDelta/2;
}

return rect;
}

On Jul 30, 2010, at 4:03 PM, Kyle Sluder wrote:

 On Fri, Jul 30, 2010 at 3:38 PM, Tony Romano tony...@hotmail.com wrote:
 I have an NSTextTextField in my nib that is using a custom NSTextFieldCell 
 (set in IB) class that has only one method over-riden, drawingRectForBounds. 
  The method is not being called.  This is what I have done.
 
 1. Set  a break point to verify it is not being called.
 2. Using F-Script, verified that the instance of NSTextField is using my 
 custom cell.  I can invoke my method via F-Script as well.
 3. Verified the correct spelling and signature of the method.
 
 Are you certain? The method is named -drawingRectForBounds:. Since you
 omitted the colon above, I am wondering if you have in fact misspelled
 the method.
 
 Please post your code.
 
 --Kyle Sluder
 

-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


redraw problem

2010-07-29 Thread Tony Romano
I have a document based Cocoa App and I am trying to understand what is causing 
these residual lines to happen.  Attached is a link to what I am referring to.  
The solid blue lines are the new lines after they have moved.  The greyish 
lines are what's being left behind. http://dl.dropbox.com/u/5614061/Screen shot 
2010-07-29 at 1.08.36 PM.png.  Notice they look like borders from the old lines.

The Class structure is(as seen by FScript):

NSThemeFrame
NSView (ContentView)
MyView


I am setting the ContentView's window to setBackgroundColor: clearColor and 
setOpaque:NO.  And in the .png, the opacity is 0.0.  If I set the opacity to 
1.0, the greyish lines are hidden but adjusting to 0.0 will cause them to be 
revealed(the same one. i.e. I only change the opacity and not move the lines).  
I am getting the drawRect calls due to me calling setNeedsDisplay:YES during 
observing the keypath changes to grid values.


Not sure what other information is needed.  Please let me know, 

Thanks in advance,
-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: redraw problem

2010-07-29 Thread Tony Romano
Moved the code to here. http://dl.dropbox.com/u/5614061/snippet.txt

The drawRect redraws the entire view.  So, in a sense, I am drawing over 
everything in that view.  What's interesting, is the lines are left from the 
first time I adjust the blue lines, any additional adjustments to the blue line 
don't leave any residuals. 

Changing the setLineWidth prior to any drawing doesn't have any affect on the 
problem.  Didn't think it would as I understand the attributes are not 
applied until the stroke happens.  I'll look into Quartz debug.

On Jul 29, 2010, at 3:54 PM, Tony Romano wrote:

 The drawRect redraws the entire view.  So, in a sense, I am drawing over 
 everything in that view.  What's interesting, is the lines are left from the 
 first time I adjust the blue lines, any additional adjustments to the blue 
 line don't leave any residuals. 
 
 Changing the setLineWidth prior to any drawing doesn't have any affect on the 
 problem.  Didn't think it would as I understand the attributes are not 
 applied until the stroke happens.  I'll look into Quartz debug.
 
 -Tony
 
 On Jul 29, 2010, at 2:48 PM, Michael Dautermann wrote:
 
 Here's something else I noticed in your code.
 
 You set the stroke width near the bottom of the drawGrid function, which 
 happens AFTER you do the first draw of the lines.  Try moving the 
 setLineWidth method call up to the top of your drawGrid and see if that 
 makes any difference.
 
 On Jul 29, 2010, at 2:01 PM, Tony Romano wrote:
 
 The drawRect redraws the entire view.  So, in a sense, I am drawing over 
 everything in that view.  What's interesting, is the lines are left from 
 the first time I adjust the blue lines, any additional adjustments to the 
 blue line don't leave any residuals. 
 
 -Tony
 

-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: redraw problem

2010-07-29 Thread Tony Romano
That was it Michael.  Thank you.
On Jul 29, 2010, at 9:19 PM, Michael Ash wrote:

 On Thu, Jul 29, 2010 at 4:26 PM, Tony Romano tony...@hotmail.com wrote:
 I have a document based Cocoa App and I am trying to understand what is 
 causing these residual lines to happen.  Attached is a link to what I am 
 referring to.  The solid blue lines are the new lines after they have moved. 
  The greyish lines are what's being left behind. 
 http://dl.dropbox.com/u/5614061/Screen shot 2010-07-29 at 1.08.36 PM.png.  
 Notice they look like borders from the old lines.
 
 It looks like you're changing the filled region of an
 irregularly-shaped window. This is perfectly fine, but note that
 NSWindow will *not* automatically update the window's shadow when you
 do so. Your artifacts look like leftover shadow to me, so I'd guess
 that this is what's happening.
 
 If I'm right, you can simply do [window invalidateShadow] any time you
 change the filled region to force the window to regenerate the shadow.
 
 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/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


UIImage Color Overlay

2010-07-21 Thread Tony S . Wu
Hi,

I have a UIView with a UIImage as background, and I would like to overlay the 
UIImage with different colors according to user preferences. Right now I draw 
the image over the background, and apply the color overlay:

UIImage *backgroundImage = [UIImage imageNamed:@background.png];
[backgroundImage drawInRect:CGRectMake(0.0, 0.0, self.bounds.size.width, 
self.bounds.size.height)];
CGRect bounds = [self bounds];
[[UIColor blueColor] set];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClipToMask(context, bounds, [backgroundImage CGImage]);
CGContextFillRect(context, bounds);

And that works just fine. However, it's come to a point that I would like to 
approach this from another angle. I would like to apply the color overlay over 
the background image, and use the resulting image to draw over the view. I have 
my code as:

UIImage *backgroundImage = [UIImage imageNamed:@background.png];
CGSize size = backgroundImage.size;
CGRect rect = CGRectMake(0.0, 0.0, size.width, size.height);
UIColor *color = [UIColor blueColor];

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, backgroundImage.CGImage);
CGContextSetBlendMode (context, kCGBlendModeColor); 
CGContextClipToMask(context, rect, backgroundImage.CGImage); 
CGContextSetFillColor(context, CGColorGetComponents(color.CGColor));
CGContextFillRect (context, rect);
CGImageRef imageMasked = CGBitmapContextCreateImage(context);
CGContextRestoreGState(context);
UIImage *image = [UIImage imageWithCGImage:imageMasked];
[image drawInRect:CGRectMake(0.0, 0.0, self.bounds.size.width, 
self.bounds.size.height)];

But when I do this, the result aren't quite the same, and the image only draws 
over part of the view. Any idea? Thanks.

Tony S. Wu
tonyswu.mailingl...@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: Debugger hangs?

2010-07-21 Thread Tony Romano
There is an issue the XCode front end has accessing variables for display.  The 
formatters are used not only for the variable window but also others areas such 
as tool-tips.  I filed a bug against this a few weeks ago(Bug# 8128556) 

To me the wrong approach is to turn off the formatters, this makes the tool 
less useful.  File a bug against the issue so Apple fixes it.  Make sure you 
submit a debugger trace log.

Here are the steps incase you don't remember.
1. Goto Preferences/Debug.
2. Check GDB Log and give it meaningful name and location(~/desktop/trace.log)
3. Load your project, get it to access violate.  Submit that log with a bug.

HTH,
-Tony

On Jul 21, 2010, at 1:12 PM, Charlie Dickman wrote:

 I have turned the data formatters off and the debugger continues to get 
 EXC_BAD_ACCESS while stepping through code. It then times out fetching data 
 and everything is hosed.
 
 On Jul 21, 2010, at 12:03 PM, Nick Zitzmann wrote:
 
 
 On Jul 21, 2010, at 4:43 AM, sebi wrote:
 
 every few times I want to step through my code with Xcode's debugger it 
 eventually refuses to work. I click on the Step Over button and then 
 nothing happens. The variable window becomes empty and the three step 
 buttons become greyed out. The Pause button reacts on clicks but doesn't 
 do anything. Stop and restart still work. The Debugger Console doesn't show 
 any output.  It's really annoying when I'm hunting a bug several functions 
 deep and then I have to start all over again because the debugger just 
 stops working. All I can do is to set the breakpoint a bit later, try again 
 and hope for the best.
 Does anyone else experience this behavior? Is there anything I can do?
 
 1. This is a list for Cocoa, not Xcode. Next time, please ask Xcode 
 questions on the Xcode list.
 
 2. That said, this is almost always caused by data formatters. If you turn 
 them off in the Debug menu, the problem should go away.
 
 Nick Zitzmann
 http://www.chronosnet.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/3tothe4th%40comcast.net
 
 This email sent to 3tothe...@comcast.net
 
 Charlie Dickman
 3tothe...@comcast.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/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


NSUserDefaultsController and a document app.

2010-07-15 Thread Tony Romano
I have a document based cocoa app.  I am using a 
NSUserDefaultsController to bind the properties of the document to 
defaults values.  This all works.  Since the controller defaults are 
'shared', one side effect is every document window inherits the defaults 
even though the object for each document window is unique.  One approach 
I thought of is to have a section in the plist for each document window, 
since they appear to be unique.  Any other thoughts on how this may be 
accomplished?


Thanks,
-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: NSTextView retain count and HICocoaView problems

2010-07-15 Thread Tony Romano
The reason dealloc is not being called is because you still have a 
retain count  0.  In cases like this, personally, I always assume my 
code is at fault.  Once I have exhausted all known techniques trying to 
resolve the discrepancy then I escalate it.


Your best bet is to use Instruments, force the leak, then examine how 
the retains/released paired up.  You'll find it.   Instruments is a very 
nice tool.


-Tony
On 7/15/10 3:30 PM, Ryan Joseph wrote:

On Jul 15, 2010, at 4:25 PM, Kyle Sluder wrote:

   

On Wed, Jul 14, 2010 at 9:39 AM, Ryan Josephr...@thealchemistguild.org  wrote:
 

1) The retainCount from the newly created NSTextView returns 4 and goes up to 7 
after I call HICocoaViewCreate on the NSTextView instance. I tried calling 
release on the NSTextView and DisposeControl on the HICocoaView but neither 
actually dispose of the instance because dealloc is never invoked. I suspect 
this is because of the retain count being what it is.
   

Do not look at -retainCount. It gives you no useful information. If
you want to make sure you're correctly balancing retains and releases,
use the static analyzer and Instruments.
 

Ok, others said this also so the system must be retaining it elsewhere for 
various reasons. The fact dealloc is never called after DisposeControl is 
confusing though since other NSView's worked just fine...

   
 

2) I have a Carbon event handler for mouse moved events installed on the 
application target which after the NSTextView is created stops working, 
probably because the NSTextView was never really deallocated it's consuming the 
mouse events.
   

That's not an accurate description of how the event dispatch works.
 


The how does it work? My observation is simple: when the NSTextView is created 
and focused the mouse handler does not receive events. After I call 
DisposeControl on the HICocoaView the view is removed (no longer visible) but 
the mouse handler continues to not receive events. They must be connected some 
how.

Regards,
Ryan Joseph
thealchemistguild.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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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


NSResizableWindowMask and view update

2010-07-12 Thread Tony Romano
I have a document based cocoa app with each document window having it's own 
window controller and view(the view is flipped).  I have an option to turn 
on/off the resize grip and I set the mask using setStyleMask.  All this works 
fine.

During the setStyleMask, the view is sent a drawRect message which is expected. 
 But the values in the rect are not flipped and are not the view bounds.

Here is some debug output.

2010-07-12 16:33:52.509 MacDoodle[21253:903] {{399, 511}, {15, 15}}  - This 
draw was due to the mask changing.
2010-07-12 16:33:52.512 MacDoodle[21253:903] Resize State: 0 - my internal 
state
2010-07-12 16:33:52.525 MacDoodle[21253:903] {{0, 0}, {414, 526}} - I added a 
setNeedsDisplay to get another output of the rect. 

By me adding a setNeedsDisplay as an experiment, you can see I get the correct 
values of my view rect.  The first output show the coordinates not flipped and 
not the same as my view bounds.  I don't want to leave the additional 
setNeedsDisplay because it flickers.  

Anyone know why this is? If more info is needed, please let me know.

TIA,
-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: NSResizableWindowMask and view update

2010-07-12 Thread Tony Romano
Yep, overlooked that the drawRect will give me the dirty rect.  Because the 
sizing handle is diagonal to the origin (0,0),  it looked like it wasn't 
flipped.  Fix the problem by one missing multiply in a calculation.  Thanks and 
it's time to call it day!

-Tony

On Jul 12, 2010, at 4:54 PM, Kyle Sluder wrote:

 On Mon, Jul 12, 2010 at 4:41 PM, Tony Romano tony...@hotmail.com wrote:
 During the setStyleMask, the view is sent a drawRect message which is 
 expected.  But the values in the rect are not flipped and are not the view 
 bounds.
 
 So? The rect argument to -drawRect: is not the size of your view. It
 is a rectangle that includes all the regions of the view that need to
 be drawn.
 
 --Kyle Sluder
 

-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: Finder-like conversion of a fileURL to 'user-friendly' path

2010-07-01 Thread Tony Romano
NSFileManager's  mountedVolumeURLsIncludingResourceValuesForKeys:options 
will give you the names of the  volumes.  Use this plus the path to 
build your own version of the a display string.  Remember to use the 
localized names.  However, as Mike suggested, if you are displaying this 
in the UI, use the NSPathControl.


-Tony


On 7/1/10 10:58 AM, Rainer Standke wrote:

That helps, to get rid of the 'file://localhost' part. What about the addition 
of the drive name?

Thanks,

Rainer

On Jul 1, 2010, at 10:33 , Kevin Wojniak wrote:

   

Use -[NSURL path] to get the unix-style path format.


On Jul 1, 2010, at 10:29 AM, Rainer Standke wrote:

 

At the bottom of each finder window there is a 'path' display that indicates the path 
to the directory represented by the window. I'd like to be able to convert a path like 
this one: 'file://localhost/Users/rainer/Desktop/SS%20material/hidden/' to some 
like: 'MacHD/Users/rainer/Desktop/SS material/hidden'.

I have pieced some things together myself, but the whole thing is a mess. Is 
there a way to access the same mechanism the Finder is obviously using?

Thanks,

Rainer___

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/kainjow%40kainjow.com

This email sent to kain...@kainjow.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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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


Using NSImage to render the view

2010-07-01 Thread Tony Romano
I have a view who's bounding rectangle has been normalize to make 
drawing a grid easier.  It' bounds is set to ~1x1.  Currently I can draw 
the grid and what ever curve I want just fine.  What I am trying to do 
is draw into a NSImage and render it in the view and cache the image so 
I can also save the image to disk later.  In my test example I am 
drawing a curve and to see if the curve renders prior to unlockFocus(i.e 
post the last stroke method) I make a call to:


NSRect br = [bp controlPointBounds];
NSLog(@Path Bounding Box: origin.x:%1.5f origin.y:%1.5f 
size.width:%1.5f size.height:%1.5f, br.origin.x, br.origin.y, 
br.size.width, br.size.height);


The Output I get is: Path Bounding Box: origin.x:0.0 
origin.y:0.0 size.width:1.0 size.height:1.0.  Looks like the 
path is drawn just fine.


The documents look pretty straight forward but it looks like I am only 
getting a 1x1 view of my data(i.e. the  pixel(s) at 0,0) and losing the 
scaling factor of the frame.  I am assuming the same trick to normalize 
a view to 1x1 should also work??  Again, if I just draw to the view and 
not to the image, it all draws perfectly.


This is what I am doing.

- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
viewBounds = NSMakeRect(-0.1, -0.1, 1.2, 1.2);
[self setBounds:viewBounds];
}
return self;
}

-(void) setFrameSize:(NSSize)newSize
{
[super setFrameSize:newSize];
[self setBounds:viewBounds];
}

- (void)drawRect:(NSRect)dirtyRect
{

// Set the image size to the bounding rect
NSImage* anImage = [[NSImage alloc] initWithSize:viewBounds];
[anImage lockFocus];

// Draw a bunch of stuff



// Unlock and draw the image
[anImage unlockFocus];
[anImage drawAtPoint:NSMakePoint(0, 0)
fromRect: NSZeroRect
   operation: NSCompositeSourceOver
fraction: 1.0];

 [anImage release];  // for now.
}

Thanks people,
-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: Using NSImage to render the view

2010-07-01 Thread Tony Romano

Thanks for the tip.

I figured it was too good to be true that the image would scale.  
Thinking about it, the class hierarchy only shows NSObject, I should 
have looked there to know for sure.  I'm not tied to this method, it 
just works nicely.  I'll covert the coordinates to the view's bounding 
rectangle and not rely on scaling. Thanks for the detailed reply Graham.


-Tony

On 7/1/10 6:55 PM, Graham Cox wrote:

On 02/07/2010, at 11:29 AM, Tony Romano wrote:

   

I have a view who's bounding rectangle has been normalize to make drawing a 
grid easier.  It' bounds is set to ~1x1. Currently I can draw the grid and what 
ever curve I want just fine.  What I am trying to do is draw into a NSImage and 
render it in the view and cache the image so I can also save the image to disk 
later.  In my test example I am drawing a curve and to see if the curve renders 
prior to unlockFocus(i.e post the last stroke method) I make a call to:

NSRect br = [bp controlPointBounds];
NSLog(@Path Bounding Box: origin.x:%1.5f origin.y:%1.5f size.width:%1.5f 
size.height:%1.5f, br.origin.x, br.origin.y, br.size.width, br.size.height);
 

Tip: check out NSStringFromRect()

   

The Output I get is: Path Bounding Box: origin.x:0.0 origin.y:0.0 
size.width:1.0 size.height:1.0. Looks like the path is drawn just fine.

The documents look pretty straight forward but it looks like I am only getting 
a 1x1 view of my data(i.e. the pixel(s) at 0,0) and losing the scaling factor 
of the frame.
 



   

I am assuming the same trick to normalize a view to 1x1 should also work??  
Again, if I just draw to the view and not to the image, it all draws perfectly.
 


You are assuming wrong. You create an image with size 1,1 and draw into it data 
with bounds 1,1. You therefore have a 1x1 pixel image with all the complexity 
and nuance that implies.

The reason the trick works with a view is that the view incorporates a 
transform that scales between the bounds and the frame rect, so the data you draw to the 
1,1 bounds is scaled up to fill the n,m frame. The scaled path is stroked on the fly to 
fill the resulting part of the screen. NSImage has no similar automatic transformations.

To my mind your approach is flawed, I'm not sure why you think having a 1,1 
view is needed or why that's any advantage over doing things conventionally, 
but if you want to persist with it, you need to make the image the size of your 
frame and set up a suitable transform yourself when you lock focus on the image 
to scale the data up the same way the view is.

--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: inference of block return type

2010-06-28 Thread Tony Romano
Did you happen to read this link?  It's clearly documented in the 
section Declaring and Using a Block.  HTH.


http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Blocks/Articles/00_Introduction.html

-Tony



On 6/28/10 9:51 AM, Matt Neuburg wrote:

I'm curious about the inference of a block literal's return type, but I'm
not sure what my question is. :) It all started with something like this
(reduced to a very very silly example, but it's the form that is important,
not the content):

[[NSArray array] indexesOfObjectsPassingTest:
 ^ (id object, NSUInteger idx, BOOL* stop) {
 return 1 == 1;
}]]; // compile error:  expected 'BOOL...

My first problem was that I didn't know *how* to specify that this block
returns a BOOL. After much experimentation I discovered this syntax:

[[NSArray array] indexesOfObjectsPassingTest:
 ^ BOOL (id object, NSUInteger idx, BOOL* stop) {
 return 1 == 1;
}]];

I never expected the BOOL to come *after* the caret, and I can't find this
documented anywhere by Apple! Yet it does seem to silence the compiler, so I
must be doing something right.

Alternatively I can cast the result:

[[NSArray array] indexesOfObjectsPassingTest:
 ^ (id object, NSUInteger idx, BOOL* stop) {
 return (BOOL)(1 == 1);
}]];

As I say, I'm not sure what my question is, but I wondered if anyone had any
words of wisdom. And should I file a bug against the docs for failing to
tell me about the syntax in the second example? m.

   


___

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: inference of block return type

2010-06-28 Thread Tony Romano
The syntax that Bill posted is not in the document.  I hate the 
complexities in this syntax, there is no reason that I can think of to 
have multiple syntax to represent this object.  Even talking to the GCD 
engineers at the show, they agrees it's overly complex for no apparent 
good reason.


The syntax below to me seems inconsistent with the analogy the docs 
claim the block syntax came from (declaring C function ptrs) or at least 
I don't remember it ever using it in that form.   (return type) 
(^blockname) (parameters) seems sufficient imo.  The whole idea was to 
stick to a format that had precedence but use the new symbol ^(only 
remaining operator that is not overloadable in C++) instead of *(btw, 
that wasn't a block with a void return type :-).


Anyhows,  I no longer think this is a cocoa question...
-Tony

On 6/28/10 2:41 PM, Michael Ash wrote:

On Mon, Jun 28, 2010 at 4:48 PM, Bill Bumgarnerb...@mac.com  wrote:
   

On Jun 28, 2010, at 1:45 PM, Michael Ash wrote:

 

But I was unable to find any discussion of HOW you explicitly declare
the return value of a block expression.
   

^return-type  (arg-list) {code};
 

Sure, but is this documented in Apple's docs? The link to Blocks
Programming Topics posted by Tony Romano doesn't seem to include it,
although it alludes to its existence. That page does link to Apple's
submission to the standard committee which does show that syntax, but
it seems like the sort of thing that ought to be on apple.com too. Did
we miss it?

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/tonyrom%40hotmail.com

This email sent to tony...@hotmail.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: C arrays as __block variables

2010-06-27 Thread Tony Romano
- (void)_copyOrMoveURLs:(SEL) s opMove:(BOOL)op src:(NSDictionary *)URLs 
completionHandler:(void (^)(NSDictionary *newURLs, NSError 
*error))handler
{

__block char array1[5];
array1[0] = 'W';


NSBlockOperation * foo = [NSBlockOperation 
blockOperationWithBlock:^{
array1[1] = array1[0];
char b = array1[0];
NSLog(@char %c %c %c, array1[0], 
array1[1], b);

}];
}

Works fine using 3.2.2  prints out char W W W

-Tony

On Jun 26, 2010, at 9:19 PM, Bill Bumgarner wrote:

 
 On Jun 26, 2010, at 9:14 PM, Tony Romano wrote:
 
 That's why I asked for an example of what the op question is
 
 http://lists.apple.com/archives/cocoa-dev/2010/Jun/msg01040.html
 
 This would seem to imply that a __block variable *can* be a *fixed* length
 array. But when I try to write into such an array inside a block, I get a
 compile error, cannot access __block variable of array type inside block.
 
 void foo() {
__block char barfy[100];
 
^() {
char b = barfy[0];   error: cannot access __block variable of 
 array type inside block
b = b;
};
 }
 
 void bar() {
__block struct angus {
char barfy[100];
} kangus;
 
^() {
char b = kangus.barfy[0];  // compiles fine
b = b;
};
 }
 
 The reason being that a Block_copy() or [block copy] will cause the __block 
 variables to be moved to the heap and, thus, the compiler must know the exact 
 size of all variables to be copied when emitting the copy helper.
 
 b.bum
 

-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: C arrays as __block variables

2010-06-27 Thread Tony Romano
The reason for the __block specifier is to allow the variable to be written to. 
 If the variable remains a const, then the complier can optimize how the block 
is stored.  If the data is changed, much of the optimization is lost.

-Tony

On Jun 26, 2010, at 8:56 PM, Kyle Sluder wrote:

 On Sat, Jun 26, 2010 at 8:51 PM, Tony Romano tony...@hotmail.com wrote:
 OP posted: This would seem to imply that a __block variable *can* be a 
 *fixed* length
 array. But when I try to write into such an array inside a block, I get a
 compile error, cannot access __block variable of array type inside block.
 
 In the example I listed below, I have a __block variable inside a block that 
 is fixed length array and I can access it via  NSLog(@char %c, array1[0]);
 
 Putting __block variables inside of blocks is completely pointless.
 The purpose of the __block qualifier is to mark variables in the
 enclosing scope to be copied into the block.
 
 --Kyle Sluder
 

-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: C arrays as __block variables

2010-06-26 Thread Tony Romano
hmmm.  Your saying this doesn't work?

NSBlockOperation * foo = [NSBlockOperation 
blockOperationWithBlock:^{
__block char array1[5];

array1[0] = 'T';
}];


It works fine for me.  Are you saying something different?

-Tony

On Jun 26, 2010, at 7:16 PM, Bill Bumgarner wrote:

 
 On Jun 26, 2010, at 6:38 PM, Matt Neuburg wrote:
 
 The docs say: There are two further restrictions on __block variables: they
 cannot be variable length arrays, and cannot be structures that contain C99
 variable-length arrays.
 
 This would seem to imply that a __block variable *can* be a *fixed* length
 array. But when I try to write into such an array inside a block, I get a
 compile error, cannot access __block variable of array type inside block.
 
 Who's mistaken, the compiler or the docs? Thx - m.
 
 Neither.   The issue is that a block array in C is, technically, sorta-kinda 
 variable length unless you do something to make it fixed length. I don't 
 remember the exact details beyond that it is a subtle edge case.
 
 That something is typically to encapsulate it into a Struct.
 
 This:
 
 void foo() {
char barfy[100];
 
^() {
char b = barfy[0];  error: cannot access copied-in variable of 
 array type inside block
b = b;
};
 }
 
 This compiles just fine:
 
 void bar() {
struct angus {
char barfy[100];
} kangus;
 
^() {
char b = kangus.barfy[0];
b = b;
};
 }
 
 b.bum
 
 
 
 
 
 
 ___
 
 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


Re: C arrays as __block variables

2010-06-26 Thread Tony Romano
I understand all that.  I was providing an example to seek clarity in his 
question.  But I understand what he is asking now, thanks.

-Tony

On Jun 26, 2010, at 7:50 PM, Dave DeLong wrote:

 That's going to create a new copy of the array every time the block is 
 executed, and the array is not accessible outside of the scope of the block.  
 Matt was asking about:
 
 __block char array1[5];
 NSBlockOperation * foo = [NSBlockOperation blockOperationWithBlock:^{
  array1[0] = 'T';
 }
 
 Dave
 
 On Jun 26, 2010, at 8:48 PM, Tony Romano wrote:
 
 hmmm.  Your saying this doesn't work?
 
  NSBlockOperation * foo = [NSBlockOperation 
 blockOperationWithBlock:^{
  __block char array1[5];
 
  array1[0] = 'T';
  }];
 
 
 It works fine for me.  Are you saying something different?
 
 -Tony

-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: C arrays as __block variables

2010-06-26 Thread Tony Romano
Actually, I read this again.

OP posted: This would seem to imply that a __block variable *can* be a *fixed* 
length
array. But when I try to write into such an array inside a block, I get a
compile error, cannot access __block variable of array type inside block.

In the example I listed below, I have a __block variable inside a block that is 
fixed length array and I can access it via  NSLog(@char %c, array1[0]);

Please post the example you are having problems with.

Thanks,
-Tony

On Jun 26, 2010, at 8:16 PM, Bill Bumgarner wrote:

 
 On Jun 26, 2010, at 7:48 PM, Tony Romano wrote:
 
 hmmm.  Your saying this doesn't work?
 
  NSBlockOperation * foo = [NSBlockOperation 
 blockOperationWithBlock:^{
  __block char array1[5];
 
  array1[0] = 'T';
  }];
 
 
 It works fine for me.  Are you saying something different?
 
 No -- that works fine.  That is a different expression than the one OP posted.
 
 b.bum

-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: C arrays as __block variables

2010-06-26 Thread Tony Romano
That's why I asked for an example of what the op question is

Sent from my phone, Thanks Tony

On Jun 26, 2010, at 8:56 PM, Kyle Sluder kyle.slu...@gmail.com wrote:

 On Sat, Jun 26, 2010 at 8:51 PM, Tony Romano tony...@hotmail.com wrote:
 OP posted: This would seem to imply that a __block variable *can* be a 
 *fixed* length
 array. But when I try to write into such an array inside a block, I get a
 compile error, cannot access __block variable of array type inside block.
 
 In the example I listed below, I have a __block variable inside a block that 
 is fixed length array and I can access it via  NSLog(@char %c, array1[0]);
 
 Putting __block variables inside of blocks is completely pointless.
 The purpose of the __block qualifier is to mark variables in the
 enclosing scope to be copied into the block.
 
 --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: NSMenuDelegate menuDidClose called before NSMenuItem's action?

2010-06-25 Thread Tony Romano
What I do is create an object that represents the data you need for your 
action.  During menuNeedsUpdate, instantiate an instance of the object that 
will be used later and then call [menuItemName 
setRepresentedObject:objectYouCreated] where menuItemName is the menuItem 
object you need to associate the object with and objectYouCreate in the entity 
object storing the data to be used later.  This item will live for the life of 
the menu which includes the target handler.  In the target handler, the 
parameter you get is the menu item. Just make a call to [sender 
representedObject] and you get your object back.  Ref counting should be 
straight forward.


HTH,
-Tony
 
On Jun 25, 2010, at 4:16 PM, Peter Ammon wrote:

 Unfortunately this isn't as easy as it should be.  Since the menu action can 
 do anything, including trigger menu tracking again, it really does need to 
 happen last.
 
 I think your best option is to use performSelector:afterDelay: from within 
 menuDidClose:.
 
 Another possibility is to tie the lifetime of your resources to the menu 
 items themselves (e.g. set them as the represented object of the menu item).  
 In SnowLeopard, we support the scenario of an NSMenuItem being removed from 
 the menu after the item is selected by the user, but before the item's action 
 fires.  This allows you to tear down the menu (for example, in 
 NSMenuDidEndTrackingNotification): the NSMenuItem will be retained until its 
 action fires.  However, this does not work in Leopard and earlier.
 
 -Peter
 
 On Jun 25, 2010, at 3:41 PM, augusto callejas wrote:
 
 peter-
 
 actually i wanted to be notified before the menu is closed,
 because i'm freeing some resources when the menu is closed,
 but i'm depending on those resources to be around when it
 comes time to execute the menu item's action.  perhaps
 i can't free those resources and need to take care of that
 somewhere else?
 
 thanks,
 augusto.
 
 On Jun 25, 2010, at 3:26 PM, Peter Ammon wrote:
 
 
 On Jun 25, 2010, at 2:58 PM, augusto callejas wrote:
 
 hi-
 
 i'm constructing an NSMenu with a delegate to handle menuDidClose.
 that menu has an NSMenuItem that had an action to handle when its selected.
 when i select the menu item from the menu, it calls menuDidClose, and then
 the action of the NSMenuItem.  i would expect the other order, but the 
 documentation
 doesn't state what order these messages are sent.  is there a way to 
 specify what
 order these messages are sent?
 
 thanks,
 augusto.___
 
 Hi Augusto,
 
 The menu always closes before the action is sent.  Imagine the user 
 choosing File-Open:  if the action were sent before the menu was closed, 
 the File menu would remain open until the Open panel is dismissed.
 
 If you want to be notified after the action is sent, perhaps you want 
 NSMenuDidSendActionNotification.
 
 Hope this helps,
 -Peter
 
 
 ___
 
 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


Re: raising NSException between Controllers

2010-06-20 Thread Tony Romano
What does the code for this look like, [controller2 
haltBgCalculationThread:withStatus];?  Are both your threads, thread safe?
Are the controllers your controllers or a Cocoa derived one from (NSController, 
.etc)?

-Tony


On Jun 19, 2010, at 3:35 PM, John Love wrote:

 I am having inconsistent problems when I call from Controller #1 one of 1's 
 methods which looks like:
 
 - (void ) exitBgCalculationThread:(int)withStatus {
   [controller2 haltBgCalculationThread:withStatus];
 }
 
 Controller #2's haltBgCalculationThread:withStatus eventually calls:
 
   itsException = [NSException exceptionWithName:newErrorName
  reason:newErrorReason
userInfo:nil];
   [itsException raise];   // stops here and long jumps to 
 try-catch-finally Handler
   // within EC's -calculateWorksheetRow:
 
 The call to -raise enters the @catch block of a try-catch-finally Handler 
 within Controller #2 (the only such Handler anywhere).  The only statement 
 within this @catch block is a call to NSLog.  After this, the NSLog call 
 falls thru to the @finally portion which returns the correct error code.  
 Controller #2's calculation for loop immediately exits and through a 
 call-back routine sends a message back to Controller #1 which displays the 
 appropriate error message in the active window.
 
 The correct error message is displayed; however, in seemingly random 
 instances, the above NSLog is never seen.
 
 Whenever, I call Controller #2's -haltBgCalculationThread: from Controller 
 #2, everything works dandy; the lack of calling NSLog in random instances 
 occurs only when I call Controller #2's -haltBgCalculationThread: from 
 Controller #1.
 
 Maybe?? it is because I am bouncing between separate Controllers and am 
 causing mayhem.
 
 Any psychic premonitions would be welcomed.
 
 John Love
 
 
 ___
 
 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


Re: NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-19 Thread Tony Romano
Maybe I am missing the big picture here

Something has to change in order to trigger the sequence of events.  The UI is 
the outlineview, the controller is NSTreeController, and the store is the file 
system.  The treecontroller stores objects that I have created to represent 
items in the store.  Through bindings, the treecontroller asks for 2 things, my 
arranged list of items and getter/setter to respond from requests from the 
controller to update a child list.

The scenario this thread is about is the user decides via a context menu to add 
a node. I tried both case where I add the folder to the file system first then 
called insertObject or called insertObject then add the folder to the file 
system.  In both cases, both the setter and the getter are called.  There is no 
direct binding to the filesystem.

 insertObject:atArrangedObjectIndexPath: requires I give it an object and an 
index path. So at a minimum, I have to create a blank node with some pertinent 
data .  The object I created is a single node, not bound to anything at this 
point, just a pointer to a blob.  When I make the call to insertObject, I 
expect two things to happen.  

1. It adds this object to my arrangedObjects and then calls my setter telling 
me, Hey there has been a change, here is the new child list.
2. Add it to the NSOutlineView. since they are bound to each other.

The controller does both of these.  The problem is it ALSO calls the getter on 
the parent node of the indexPath provided and tells me to enumerate this node. 
If I updated the file system prior to calling insertObject, I would enumerate 
it and give the list back to the controller. Then, the insertObject code would 
proceed to add the newly created node, hence added twice in the child list.   
It seems like the controller lost track of the child list for this node and 
requested it again and perhaps this is where the  problem is.  I know for a 
fact it tracks child list otherwise the controller would enumerate the nodes 
every time the user opens a folder that had been previously opened.

I guess the scenario the controller is trying to protect itself from the user 
adding a new node to a child that has not been enumerated(makes perfect sense). 
 In this case the node doesn't not have a child list and it would have to ask 
for it first.  But it shouldn't call the setter in this case. Under all 
conditions it calls both, this is a bug.

Sorry for all the details.
-Tony

On Jun 19, 2010, at 6:22 AM, Clark S. Cox III wrote:

 You should only need add your object to your model (which needs to me KVO 
 compliant). The tree controller will then notice, in response to the KVO 
 notification that a new item was added.
 
 You should rarely, if ever, be direcly adding objects to the controller layer 
 like this. 
 
 Sent from my iPhone
 
 On Jun 18, 2010, at 18:53, Tony Romano tony...@hotmail.com wrote:
 
 Scenario:  Adding a new node to a NSOutlineView backed by a NSTreeController.
 
 1. Create a new internal object add add it to the data store(file system).  
 This will be my representedObject in the treecontroller
 2. Compute the path and call insertObject:atArrangedObjectIndexPath:
 
 the treecontroller does 2 things during the call to insertObject:
 
 1. It calls my getter, children, and asks me for all the children under the 
 parent node I have added the new node to.  I give it the list INCLUDING the 
 newly created node since it is now in the store.
 2. Then it calls the setter, setChildren,  and gives me the newChildren 
 list.  Which now has an additional copy of the new node, one from the getter 
 call and one from the insertAt call. I know this for a fact because I 
 purposely added some data to the newly created node for the insert to 
 distinguish them.
 
 From the UI, the outlineview is correct, but my internal child list has the 
 extra node.  It's not displayed because the treecontroller optimizes when to 
 ask me for a childlist.  I have a work around which I don't like to 
 basically lock out the getter method and just return the current child 
 list(i.e the previous child list which doesn't have the new node added from 
 the file system).  Anyone experience this before and have a recommendation?
 
 TIA,
 -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/clarkcox3%40gmail.com
 
 This email sent to clarkc...@gmail.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

Re: autorelease: how does this work!? (if at all)

2010-06-18 Thread Tony Romano
First, the objects are retained by dispatch_async as others have mentioned.  
Second, I'm not sure why you used 2 queues for the tasks in your code, seems 
overly complex.  Async queues are serialized, which means that you can continue 
to add to the queue and the jobs will be done in order which they were added. 
The next job will not start until the previous one in the queue is completed.   

-Tony

On Jun 18, 2010, at 8:36 AM, Julien Jalon wrote:

 Is the compiler/runtime being clever enough to retain it because it is
 going to be needed in the inner block (if so: very clever!)?
 
 Yes, it is very clever.
 
 When creating the block, the ObjC compiler also specifies the Object stored
 into the block metadata. When the block is copied (which is done as soon as
 you call dispatch_async), the copied block retains these objects.
 
 Note that it only works for blocks and ObjectiveC objects with some
 (logical) special cases (ivars, __block).
 
 See:
 http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Blocks/Articles/bxVariables.html
 
 -- 
 Julien
 
 On Fri, Jun 18, 2010 at 5:00 PM, Jonny Taylor j.m.tay...@durham.ac.ukwrote:
 
 I've just been looking back at some code that has been working fine for me
 for a while, and as far as I can see it shouldn't actually work! I'd be
 interested for peoples' comments. The code is as follows:
 
 dispatch_async(queue1,
 ^{
   NSImage *theImage = [frame GetNSImage];
   NSData *tiffRep = [theImage TIFFRepresentation];
   dispatch_async(queue2,
   ^{
   [tiffRep writeToFile:[NSString stringWithFormat:@
 %...@%d.tif,
   [[frame Camera] ExportFilePrefix],
 [frame FrameNumber]]
   atomically:YES];
   });
   [theImage release];
 });
 
 Work running on serial queue queue1 calculates a TIFF representation for
 an image, and then schedules work on serial queue queue2 to write that
 data to disk. What I can't work out is why tiffrep isn't autoreleased as
 soon as the outer block completes. Is the compiler/runtime being clever
 enough to retain it because it is going to be needed in the inner block (if
 so: very clever!)? If not, am I just getting lucky here with exactly
 when/how grand central does its autorelease cleanup? Or maybe the TIFF
 representation and/or my frame data is still being retained elsewhere for a
 while (possible, depending on how the thread timings work out...).
 
 I'm pretty new to Cocoa so I'm keen to understand this properly - I'd be
 interested to hear peoples thoughts on this: is what I am doing ok, or do I
 need to add some explicit retain/releasing of tiffRep?
 
 Cheers
 Jonny___
 
 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/jjalon%40gmail.com
 
 This email sent to jja...@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/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


Re: autorelease: how does this work!? (if at all)

2010-06-18 Thread Tony Romano
I did notice the inner block was running on a second q, that's what my comment 
is about.  I guess the first block what's really in questioned, how big is the 
images??  If it will block, then put it in the same block as the write.  I'm 
assuming you want he image transformed prior to the write.

-Tony

On Jun 18, 2010, at 12:20 PM, Jonny Taylor wrote:

 First, the objects are retained by dispatch_async as others have mentioned.  
 Second, I'm not sure why you used 2 queues for the tasks in your code, seems 
 overly complex.  Async queues are serialized, which means that you can 
 continue to add to the queue and the jobs will be done in order which they 
 were added. The next job will not start until the previous one in the queue 
 is completed.   
 Possibly overly complex, but notice that the nested block is running on *a 
 different queue* to the block that spawns it. My intention is that the 
 write queue (running the nested block) can have a write outstanding at all 
 times, maximizing the rate at which data can be written to disk. To be fair 
 the outer block does not strictly require a dedicated queue - it could 
 probably run equally well on the global concurrent queue - but I don't think 
 that's what you're commenting on is it?

-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: autorelease: how does this work!? (if at all)

2010-06-18 Thread Tony Romano
Because you make 2 queues, doesn't mean internally they will operate on 
separate cores/threads.  GCD may coalesce these based on system resources.  I 
agree with the best practice you outlined; however, the example in this email 
thread has 2 queues within the same subsystem.  So there must be some trick I 
am not groc'ing within the snippet of code.  Anyhow, I think the OP got the 
answer to his original question.

-Tony

On Jun 18, 2010, at 12:34 PM, Bill Bumgarner wrote:

 
 On Jun 18, 2010, at 12:09 PM, Tony Romano wrote:
 
 First, the objects are retained by dispatch_async as others have mentioned.  
 Second, I'm not sure why you used 2 queues for the tasks in your code, seems 
 overly complex.  Async queues are serialized, which means that you can 
 continue to add to the queue and the jobs will be done in order which they 
 were added. The next job will not start until the previous one in the queue 
 is completed.   
 
 To be precise, it is the Blocks runtime that takes care of memory management, 
 triggered by dispatch_async()s copying of the block passed to it.
 
 As for their being two queues, that pattern is actually pretty common.  A 
 best practice is to subdivide your application into subsystems and then have 
 one (or more, depending on concurrency used) queue per subsystem.The 
 queues both allow the application to do work across many cores simultaneously 
 while also providing a natural lock-less exclusion primitive per subsystem.
 
 The trick is to keep the object graphs being acted upon within the subsystems 
 relatively isolated from each other (with the points of contention being 
 carefully considered).
 
 b.bum
 
 

-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


NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-18 Thread Tony Romano
Scenario:  Adding a new node to a NSOutlineView backed by a NSTreeController.

1. Create a new internal object add add it to the data store(file system).  
This will be my representedObject in the treecontroller
2. Compute the path and call insertObject:atArrangedObjectIndexPath:

the treecontroller does 2 things during the call to insertObject:

1. It calls my getter, children, and asks me for all the children under the 
parent node I have added the new node to.  I give it the list INCLUDING the 
newly created node since it is now in the store.
2. Then it calls the setter, setChildren,  and gives me the newChildren list.  
Which now has an additional copy of the new node, one from the getter call and 
one from the insertAt call. I know this for a fact because I purposely added 
some data to the newly created node for the insert to distinguish them.

From the UI, the outlineview is correct, but my internal child list has the 
extra node.  It's not displayed because the treecontroller optimizes when to 
ask me for a childlist.  I have a work around which I don't like to basically 
lock out the getter method and just return the current child list(i.e the 
previous child list which doesn't have the new node added from the file 
system).  Anyone experience this before and have a recommendation?

TIA,
-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: NSTreeController and insertObject:atArrangedObjectIndexPath:

2010-06-18 Thread Tony Romano
I solved this my not adding the file to the store until after the insert is 
completed in the controller.  The side effect is if the file system operation 
fails, I have to back out the node inserted into the tree which seems 
counterintuitive(i.e. I should only add the node if the model successfully has 
the data). It still calls both the getter and the setter within this one call.  
This has to be is a bug and I will file it.  It should only call the setter.

-Tony

On Jun 18, 2010, at 3:53 PM, Tony Romano wrote:

 Scenario:  Adding a new node to a NSOutlineView backed by a NSTreeController.
 
 1. Create a new internal object add add it to the data store(file system).  
 This will be my representedObject in the treecontroller
 2. Compute the path and call insertObject:atArrangedObjectIndexPath:
 
 the treecontroller does 2 things during the call to insertObject:
 
 1. It calls my getter, children, and asks me for all the children under the 
 parent node I have added the new node to.  I give it the list INCLUDING the 
 newly created node since it is now in the store.
 2. Then it calls the setter, setChildren,  and gives me the newChildren list. 
  Which now has an additional copy of the new node, one from the getter call 
 and one from the insertAt call. I know this for a fact because I purposely 
 added some data to the newly created node for the insert to distinguish them.
 
 From the UI, the outlineview is correct, but my internal child list has the 
 extra node.  It's not displayed because the treecontroller optimizes when to 
 ask me for a childlist.  I have a work around which I don't like to basically 
 lock out the getter method and just return the current child list(i.e the 
 previous child list which doesn't have the new node added from the file 
 system).  Anyone experience this before and have a recommendation?
 
 TIA,
 -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/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


Re: DnD International No symbol

2010-06-17 Thread Tony Romano
Gotta Love Corbin, works as advertised.  

What's inconsistent here though is the copy operation changes the icon so you 
would think the NSDragOperationNone(or better yet the non-existent 
NSDragOperationNotAllowed) would change it as well. OR the return operation 
would not change any of them and then the user knows to use NSCursor through 
clear documentation outlining DnD and cursor management.  LOL, i'm not sure 
where to file a enhancement request.

Anyways, thanks

-Tony

On Jun 17, 2010, at 3:48 PM, Corbin Dunn wrote:

 
 On Jun 16, 2010, at 7:19 PM, Tony Romano wrote:
 
 Hmm...  I'm returning the NSDragOperationNone now, all I get is an image of 
 what is being dragged no other symbol and the outlineview won't accept the 
 drop which is correct.  When I have a valid selection, I get the other 
 symbol for copy(green circle with plus sign), or for Move, the outlineview 
 highlights the drop point.
 
 Call:
  [[NSCursor operationNotAllowedCursor] set];
 before returning NSDragOperationNone.
 
 corbin
 
 

-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: DnD International No symbol

2010-06-17 Thread Tony Romano
By 'where' I meant, Cocoa APIs or Documentation.  Sorry should have been more 
clear about that.  The docs definitely need an update on the new cursor, the 
text description is there but the cursor is missing from the table which you 
may think there aren't anymore defined other that what's in the table.  That's 
a clear doc bug which I will file.

-Tony

On Jun 17, 2010, at 9:01 PM, Andrew Merenbach wrote:

 I think one possible explanation for the lack of cursor changing with 
 NSDragOperationNone is that [NSCursor operationNotAllowedCursor] appears to 
 have been introduced in 10.6 (Snow Leopard), so this was not a possibility in 
 the paradigm contained in prior versions of the API.
 
 To file an enhancement request, you can go to: http://bugreport.apple.com.  
 Unless you know that already, and just meant how to phrase it--in that case, 
 I'm unsure as to the best way and should probably leave it to other 
 CocoaDevvers to assist you.
 
 Cheers,
   Andrew
 
 On Jun 17, 2010, at 5:27 PM, Tony Romano wrote:
 
 Gotta Love Corbin, works as advertised.  
 
 What's inconsistent here though is the copy operation changes the icon so 
 you would think the NSDragOperationNone(or better yet the non-existent 
 NSDragOperationNotAllowed) would change it as well. OR the return operation 
 would not change any of them and then the user knows to use NSCursor through 
 clear documentation outlining DnD and cursor management.  LOL, i'm not sure 
 where to file a enhancement request.
 
 Anyways, thanks
 
 -Tony
 
 On Jun 17, 2010, at 3:48 PM, Corbin Dunn wrote:
 
 
 On Jun 16, 2010, at 7:19 PM, Tony Romano wrote:
 
 Hmm...  I'm returning the NSDragOperationNone now, all I get is an image 
 of what is being dragged no other symbol and the outlineview won't accept 
 the drop which is correct.  When I have a valid selection, I get the other 
 symbol for copy(green circle with plus sign), or for Move, the outlineview 
 highlights the drop point.
 
 Call:
 [[NSCursor operationNotAllowedCursor] set];
 before returning NSDragOperationNone.
 
 corbin
 
 
 
 -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/merenbach%40ucla.edu
 
 This email sent to merenb...@ucla.edu
 
 

-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: Where to noteHeightOfRowsWithIndexesChanged

2010-06-16 Thread Tony P

Thanks for all the responses folks.

On 15 Jun 2010, at 7:22 pm, Corbin Dunn wrote:

Do the height calculations in the bounds change, and then call the  
noteHeight.. method all in the same run loop stack; that will  
probably fix your problem.


Beautiful, works like a dream. Many, many thanks for that, you're a  
superstar!


Even though it is fast, however, a table with 200,000 rows is  
excessive. There is no way a user can realistically use all those  
rows without some sort of filtering/searching. I would consider re- 
doing your UI to have a more results button, akin to the Finder  
spotlight search results.


It does have a search, and I would agree, but arbitrary browsing is  
required (even from the search which just scrolls to the results).  
Unfortunately it's a PC-Mac port and you'll have to drag me through  
hot coals before I'll be happy with a Mac version that seems somehow  
inferior to the PC version. It's an iPhone version next though, so  
I'll definitely have to re-think the UI for that.


Thanks again,

Tony Pollard


On 15 Jun 2010, at 7:22 pm, Corbin Dunn wrote:



On Jun 15, 2010, at 10:55 AM, Jens Alfke wrote:



On Jun 15, 2010, at 10:51 AM, Jerry Krinock wrote:


I send noteHeightOfRowsWithIndexesChanged: after updating the  
contents of the array controller to which a table is bound, but I  
still see little artifacts sometimes.  It's in a rarely-used  
utility view so I've let it slide. But under the conditions you've  
mentioned,


If you can reproduce this, please log a bug.



There are usually about 200,000 rows, so calculating the actual  
height for all rows is not an option (since it takes about 19  
seconds).


you may have exceeded the capabilities of NSTableView's variable  
heights


I agree. Variable row heights were a late addition to NSTableView  
(added in 10.3 or 10.4?) and I wouldn’t be surprised if they’re not  
optimized for huge numbers of rows.


The table view is optimized for a huge number of rows -- the  
implementation in 10.3-10.6 uses a sparse array of row heights, and  
attempts to lump together equal row heights into a single bucket.  
This makes it quite fast at computations. Having a lot of non-equal  
row heights will be more expensive (there is no way around that) as  
each rowRect computation needs to figure out where to be.


Even though it is fast, however, a table with 200,000 rows is  
excessive. There is no way a user can realistically use all those  
rows without some sort of filtering/searching. I would consider re- 
doing your UI to have a more results button, akin to the Finder  
spotlight search results.


With respect to:

The tableview has variable height rows, and because of a relatively  
slow data source, resizing and user control of fonts, etc, I don't  
know the row height in advance. I'm caching the row height, and  
returning a single-line height if the row is not visible (and the  
height is not yet known). If the row is visible I calculate the  
actual height and return that (via the NSTableView heightOfRow  
delegate).


This almost works, but I've not found a good place to put  
noteHeightOfRowsWithIndexesChanged. I get either overlapping rows  
or some blank rows during scroll. I've tried  
NSViewBoundsDidChangeNotification. I've even tried putting it in  
the heightOfRow delegate (which I know must be wrong), with some re- 
entrancy control which has given the best results so far (but still  
displays blank rows sometimes). There are usually about 200,000  
rows, so calculating the actual height for all rows is not an  
option (since it takes about 1


You need to always return the *same* height until you call  
noteHeightOfRowsWithIndexesChanged. After calling that method, the  
said indexes can return a new height. Not doing this will cause the  
types of problems that you see, as the table may (or may not) cache  
every row height, and expects the same result to be returned for the  
same row every time (until it was told it changed).


Sending the node in some sort of bounds changed notification should  
be fine -- the problem you are encountering is probably because you  
are breaking the above rule mentioned. Do the height calculations in  
the bounds change, and then call the noteHeight.. method all in  
the same run loop stack; that will probably fix your problem.


corbin

___

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/tonyp%40neutral.co.uk

This email sent to to...@neutral.co.uk


___

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

Re: Where to noteHeightOfRowsWithIndexesChanged

2010-06-16 Thread Tony Romano
You can't be cavalier about the UI.  The Windows version of the application 
could be in an enterprise setting where lots of users are already accustom to 
how it works today.  Good or bad, consistency outweighs uniqueness.  Changing 
something on an enterprise scale needs to go through a methodical process to 
get all the people in sync or it could cost you money/downtime.  

-Tony


On Jun 16, 2010, at 9:25 AM, Kyle Sluder wrote:

 On Jun 16, 2010, at 8:17 AM, Tony P to...@neutral.co.uk wrote:
 
 Thanks for all the responses folks.
 
 On 15 Jun 2010, at 7:22 pm, Corbin Dunn wrote:
 
 Do the height calculations in the bounds change, and then call the 
 noteHeight.. method all in the same run loop stack; that will probably 
 fix your problem.
 
 Beautiful, works like a dream. Many, many thanks for that, you're a 
 superstar!
 
 Even though it is fast, however, a table with 200,000 rows is excessive. 
 There is no way a user can realistically use all those rows without some 
 sort of filtering/searching. I would consider re-doing your UI to have a 
 more results button, akin to the Finder spotlight search results.
 
 It does have a search, and I would agree, but arbitrary browsing is required 
 (even from the search which just scrolls to the results). Unfortunately it's 
 a PC-Mac port and you'll have to drag me through hot coals before I'll be 
 happy with a Mac version that seems somehow inferior to the PC version. It's 
 an iPhone version next though, so I'll definitely have to re-think the UI 
 for that.
 
 “Inferior” does not mean “fewer things on the screen.” Now is your 
 opportunity to exploit the Mac's less-is-more conventions to better the 
 experience and produce a superior product. This might in turn inform the 
 Windows side of the product, and so forth.
 
 --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/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


DnD International No symbol

2010-06-16 Thread Tony Romano
Briefly, in a DnD operation all the nodes selected need to be siblings of each 
other.  During validateDrop I check for this and it calculates it just fine.  
However, I need to set the DnD image to something indicating this is not 
allowed, I thought using the International NO symbol made sense but it is not 
defined as one of the NSDragOperation... flags.  So I am thinking either this 
is not HIG compliant or it is and I just need to supply my own.  I know I have 
seen other apps do it but it's doesn't been it's HIG compliant.

Thoughts/Comments?

Thanks!
-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: DnD International No symbol

2010-06-16 Thread Tony Romano
Hmm...  I'm returning the NSDragOperationNone now, all I get is an image of 
what is being dragged no other symbol and the outlineview won't accept the drop 
which is correct.  When I have a valid selection, I get the other symbol for 
copy(green circle with plus sign), or for Move, the outlineview highlights the 
drop point.

-Tony

On Jun 16, 2010, at 7:11 PM, Kyle Sluder wrote:

 On Wed, Jun 16, 2010 at 6:55 PM, Tony Romano tony...@hotmail.com wrote:
 Briefly, in a DnD operation all the nodes selected need to be siblings of 
 each other.  During validateDrop I check for this and it calculates it just 
 fine.  However, I need to set the DnD image to something indicating this is 
 not allowed, I thought using the International NO symbol made sense but it 
 is not defined as one of the NSDragOperation... flags.  So I am thinking 
 either this is not HIG compliant or it is and I just need to supply my own.  
 I know I have seen other apps do it but it's doesn't been it's HIG compliant.
 
 I believe that's a Carbon thing; there is also no standard not
 allowed cursor. Just return NSDragOperationNone and let the
 slide-back animation do its job.
 
 If you want to explain to the user why they can't drag, maybe you
 could use a tooltip? Query the draggingInfo in -draggingUpdated: and
 use it to position a borderless window that describes why the
 operation can't be done.
 
 --Kyle Sluder
 

-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


Where to noteHeightOfRowsWithIndexesChanged

2010-06-15 Thread Tony P
Where's the best place to put noteHeightOfRowsWithIndexesChanged to  
keep a tableview display correct whilst scrolling?


The tableview has variable height rows, and because of a relatively  
slow data source, resizing and user control of fonts, etc, I don't  
know the row height in advance. I'm caching the row height, and  
returning a single-line height if the row is not visible (and the  
height is not yet known). If the row is visible I calculate the actual  
height and return that (via the NSTableView heightOfRow delegate).


This almost works, but I've not found a good place to put  
noteHeightOfRowsWithIndexesChanged. I get either overlapping rows or  
some blank rows during scroll. I've tried  
NSViewBoundsDidChangeNotification. I've even tried putting it in the  
heightOfRow delegate (which I know must be wrong), with some re- 
entrancy control which has given the best results so far (but still  
displays blank rows sometimes). There are usually about 200,000 rows,  
so calculating the actual height for all rows is not an option (since  
it takes about 19 seconds).


Any ideas anyone?

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


Menu item binding hidden

2010-06-13 Thread Tony Romano
Binding a menuitem's hidden attribute to the selection doesn't work in the case 
of a context menu because the selection happens as it changes and before the 
menu is displayed.  There is no state.  Other than adding an ivar and binding 
the hidden state to it, is there another way?  Can't seem to find anything via 
a search.

TIA,
-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: Menu item binding hidden

2010-06-13 Thread Tony Romano
Ok thanks Kyle and Gideon, I wanted to make sure there wasn't another way with 
a binding that I was over looking. 

-Tony

On Jun 13, 2010, at 7:21 PM, Gideon King wrote:

 You might like to check out doing it using validateUserInterfaceItem: or 
 validateMenuItem:
 
 HTH
 
 Gideon
 
 On 14/06/2010, at 11:23 AM, Tony Romano wrote:
 
 Binding a menuitem's hidden attribute to the selection doesn't work in the 
 case of a context menu because the selection happens as it changes and 
 before the menu is displayed.  There is no state.  Other than adding an ivar 
 and binding the hidden state to it, is there another way?  Can't seem to 
 find anything via a search.
 
 TIA,
 -Tony
 
 
 

-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: NSOutlineView drag and drop problem

2010-06-11 Thread Tony Romano
I guess I don't understand.  Validating the drop to me is different then the 
type of drop action.  Both in the validate and the accept, the user decides 
the type of drop action(copy/move) .  The validate method decides if the user 
is allowed with the operation which is what is determined by you app and 
provides the feedback to the user. If the drop is valid, the same operation 
code will be preset in the accept method unless the user cancels the action(i.e 
and mask keys are still active or you get the full op code).  Factoring into 
one function the common stuff makes perfect sense.

-Tony
 

On Jun 10, 2010, at 10:24 PM, Graham Cox wrote:

 Thanks, but this is not the case.
 
 The validateDrop method returns a NSDragOperation value that I compute. That 
 is not the same value that the [draggingInfo draggingSourceOperationMask] 
 returns, though that is certainly one of the many inputs I use when working 
 out the validation.
 
 The two methods do much the same work so there's a good opportunity to factor 
 the code as Jens suggests, but locally saving the return value from 
 validation works OK and appears to be all I can do.
 
 --Graham
 
 
 
 
 On 11/06/2010, at 6:27 AM, Tony Romano wrote:
 
 It does.  Making a call to draggingSourceOperationMask in your acceptDrop 
 method  will give you the operation that is active.  No need to cache it.
 
 -Tony
 
 
 On Jun 10, 2010, at 11:12 AM, Jens Alfke wrote:
 
 
 On Jun 9, 2010, at 11:12 PM, Graham Cox wrote:
 
 In –outlineView:acceptDrop:item:childIndex: I can work out much the same 
 set of conditions as above and mostly do the right thing, but since a move 
 or a copy is equally likely, I need a way to determine what the last drag 
 operation returned during validation actually was. There doesn't seem to 
 be a way to do this by requesting it from any of the parameters passed to 
 that method.
 
 Well, since acceptDrop takes the same parameters as validateDrop, it seems 
 you should be able to work out the same operation that validateDrop arrived 
 at. I often end up writing a subroutine that takes the dragging info and 
 items and works out the operation and other useful stuff, and then have 
 both of those methods call 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


Re: NSOutlineView drag and drop problem

2010-06-10 Thread Tony Romano
It does.  Making a call to draggingSourceOperationMask in your acceptDrop 
method  will give you the operation that is active.  No need to cache it.

-Tony
 

On Jun 10, 2010, at 11:12 AM, Jens Alfke wrote:

 
 On Jun 9, 2010, at 11:12 PM, Graham Cox wrote:
 
 In –outlineView:acceptDrop:item:childIndex: I can work out much the same set 
 of conditions as above and mostly do the right thing, but since a move or a 
 copy is equally likely, I need a way to determine what the last drag 
 operation returned during validation actually was. There doesn't seem to be 
 a way to do this by requesting it from any of the parameters passed to that 
 method.
 
 Well, since acceptDrop takes the same parameters as validateDrop, it seems 
 you should be able to work out the same operation that validateDrop arrived 
 at. I often end up writing a subroutine that takes the dragging info and 
 items and works out the operation and other useful stuff, and then have both 
 of those methods call it.
 
 —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/tonyrom%40hotmail.com
 
 This email sent to tony...@hotmail.com
 
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


NSTreeController method removeObjectAtArrangedObjectIndexPath

2010-06-02 Thread Tony Romano
Overview:

I am implementing DnD using the NSOutlineview as my UI and the NSTreeController 
as my store front to the file system. If none of the files exist at the drop 
target both move and copy operations work fine. The case where there is a file 
in the target that conflicts with one of the files in the source, I need to 
remove both the file and the node in the controller.  All the file operations 
are happening on a another thread.  Once I have determine which node needs to 
be removed, I am doing a performSelectorOnMainThread to instruct the 
treecontroller to remove the node.  Note:  The copy and move work this way as 
well.  The scenario I have outlined is really a special case in a move 
operation that will remove the node at the target and continues as if it were a 
simple move.
 
The issue is this, most of the time, removeObjectAtArrangedObjectIndexPath, 
will NOT remove the code and I wind up with a duplicate in the tree at the 
target drop point. The files in the filesystem are correct.

Here are some snippets of code:

// File Operations are complete at this time
if (rr == kReplaced_MacFileMoveOrCopy) 
{
// We are doing a move and the target was both in the file system AND 
the outlineview.
// At this point, the file got moved but we now need to remove it from 
the tree so we can 
// continue with a normal MOVE operation
// The node to remove will be under the targetItem in the treecontroller
NSMutableArray *targetItemChildren = [targetItem mutableChildNodes];

// I have also done this as well instead of the line directly above.
// NSArray * targetItemChildren = [targetItem childNodes];
// NSMutableArray * tc = [targetItemChildren copy];


// Create a temporary URL to retarget the URL we want to move, to have 
the path of the destination node
NSURL * u = [[[targetItem representedObject] nodeURL] 
URLByStandardizingPath];
NSURL * lookingForURL = [u URLByAppendingPathComponent:[[node nodeURL] 
lastPathComponent]];
NSURL * lookingAtURL = nil;

for(NSTreeNode * childTn in targetItemChildren) {
lookingAtURL = [[childTn representedObject] nodeURL]

if ([lookingAtURL isEqual:lookingForURL] == YES) {

[self performSelectorOnMainThread: 
@selector(removeNode:) 
withObject:childTn waitUntilDone:YES];

break; // found it, we're done.
}
}

[targetItemChildren release];
}



// This function is call on the main thread
-(void)removeNode:(NSTreeNode *)tn
{
NSLog(@Main Thread RemoveNode(%d), [NSThread isMainThread]);
NSIndexPath *objPath = [tn indexPath];
[treeController removeObjectAtArrangedObjectIndexPath:objPath];
}

Does anyone have experience using an NSTreeController with an NSOutlineview in 
this fashion and can shed some light on this?  I've spent the better part of 
the day looking at this.  In all cases my internal nodes are correct by looking 
at them from the debugger.

TIA,
-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: Monster memory leak and I can't figure out why

2010-06-01 Thread Tony Romano
Hi Ken,

This code by itself should not be causing a leak.  Couple of questions:

1.  How do you know you have a memory leak?  Sound like a silly question but 
you didn't tell us anything about what you are using to detect leaks.
2.  Who is calling this code, how many times?  If you are passing the image to 
something else in the sections you have commented out and you are calling this 
many times, your memory usage may grow senza any cache'ing that maybe happening.

I would suggest putting a NSLog statement at the beginning and look at your 
output window to make sure the code is not called more than you think. 

-Tony Romano

On May 31, 2010, at 6:41 PM, Ken Tozier wrote:

 Hi
 
 I'm trying to write a thumbnailer class that takes a path to a photo and 
 creates a thumbnail at a user specified size. The code creates the thumbnails 
 OK, but there's this monster memory leak, to the tune of about 100 MB every 
 3-4 seconds, that seems to be related to NSImage.
 
 What's happening is that if I comment out the line that initializes a new 
 image, the memory leak disappears. I've tried forcibly releasing the images, 
 tried autoreleasing them, tried creating a fixed size buffer into which all 
 the images are read, nothing seems to work.
 
 I'm using garbage collection, so that along with the deliberate releasing of 
 the images, makes me wonder why the collector isn't getting the hint, that 
 it's ok to release the memory for these photos. Could someone point out what 
 I'm doing in the following code that prevents the images from getting 
 released?
 
 Thanks for any help
 
 - (NSString *) createJPEGThumbnail:(NSString *) inPath
   site:(NSString *) inSite
 {
   NSDictionary*siteRecord,
   *pubRecord;
   
   NSString*sourceName = 
 [inPath lastPathComponent],
   *sourceRoot 
 = [sourceName stringByDeletingPathExtension],
   *destName   
 = [[sourceRoot stringByAddingPercentEscapesUsingEncoding: 
 NSUTF8StringEncoding] stringByAppendingPathExtension: @jpg],
   *pubCode
 = [self pubCodeFromPath: inPath],
   *thumbPath;
 
   NSFileManager   *manager= 
 [NSFileManager defaultManager];
   
   siteRecord  = [thumbDirectories 
 objectForKey: inSite];
   pubRecord   = [[siteRecord objectForKey: 
 @publications] objectForKey: pubCode];
   
   if (pubRecord == nil)
   pubRecord   = [[siteRecord objectForKey: 
 @publications] objectForKey: @~MISCELLANEOUS];
   
   thumbPath   = [[pubRecord objectForKey: 
 @thumb_path] stringByAppendingPathComponent: destName];
   
   if (![manager fileExistsAtPath: thumbPath])
   {
   // I've tried both of these, didn't make the slightest 
 difference.
   // Both leaked memory at a furious pace
   
   // Option 1:
   NSImage *image  
 = [[[NSImage alloc] initWithContentsOfFile: inPath] autorelease];
   
   /* do some stuff */
   
   
   // Option 2
   NSImage *image  
 = [[NSImage alloc] initWithContentsOfFile: inPath];
   
   /* do some stuff */
   
   [image release];
   }
   
   // make sure it worked
   if ([manager fileExistsAtPath: thumbPath])
   return thumbPath;
   else
   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/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


  1   2   >