Re: Audio APIs [Carbon is C++?]

2010-03-01 Thread Paul Bruneau

On Mar 1, 2010, at 12:22 PM, Jens Alfke wrote:

IMHO the worst problem with CoreAudio isn't what language it's in,  
but that the APIs don't form a coherent framework, rather a  
patchwork of complex procedural interfaces plus a pile of  
undocumented, mostly-unsupported and poorly-structured wrapper  
classes. Languages aren't a big deal — you should already be trying  
to learn a new language every year just to keep your mind flexible :)


This actually makes me feel a lot better about my total inability to  
do anything at all in CoreAudio without relying almost completely upon  
the sample code. Thank you.___


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

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

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

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


Re: Carbon is C++?

2010-02-28 Thread Paul Bruneau
On Feb 28, 2010, at 1:20 AM, Ian Joyner wrote:

 Carbon was originally Pascal based, at least as far as the APIs. It does not 
 essentially matter what it is written in, just what APIs it supports. If it 
 has been rewritten in C++ (are they mad?), that should make no difference to 
 whatever developer language is used, and would not be an argument to write in 
 C++.
 
 Should you write any high-level applications in C++ - probably not. If you 
 are just writing Cocoa apps - don't use it. Just stick to Objective-C.
 
 The idea of Objective-C++ is really to port things from other platforms more 
 easily, or perhaps do cross-platform development.

Or if you want to do a bunch of audio stuff in the iPhone, then you can enjoy 
the experience of learning C++ even though all you want to do is obj-c. 
Depressing.

___

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

Please do not post admin requests or moderator comments to the list.
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: Carbon is C++?

2010-02-28 Thread Paul Bruneau
That is excellent and I really like the sound of it. Someone please inform the 
authors of Apple's iPhone sample code so that I won't have to deal with C++ 
anymore! (I'm looking at YOU, SpeakHere!)

On Feb 28, 2010, at 10:24 PM, Erik Buck wrote:

 I disagree.  I have written very low latency device drivers in Objective-C.  
 Why do you think Objective-C has too much latency for audio?  When properly 
 used, Objective-C programs are no more likely to be preempted than any other 
 kind of program.  Message dispatch generally has constant time and is only 
 2.5 times the cost of a C function call.  There aren't many function calls or 
 messages sent in audio processing anyway.  Signal processing routines tend to 
 be long loops.  Objective-C _IS_ C which means it is likely usable in any 
 situation where C is usable.
___

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

Please do not post admin requests or moderator comments to the list.
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: Application Menu - Preferences

2010-02-24 Thread Paul Bruneau


On Feb 24, 2010, at 3:28 PM, David Blanton wrote:

In an NSDocument app where should or how should the Application  
Preferences menu item be connected?


This is kind of old, and its main focus is bindings, but it gives you  
everything you need I think


http://developer.apple.com/cocoa/cocoabindings.html

___

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

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

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

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


Re: Application Menu - Preferences

2010-02-24 Thread Paul Bruneau

On Feb 24, 2010, at 3:58 PM, David Blanton wrote:


Good Tip.  Thanks.

What I was really getting at is how to set the target / action for  
when the item is selected.  Here is what I did,  so if this is way  
off base please let me know.


I sub-classed NSMenuItem and set the Preferences menu item to this  
class.


In the awakeFromNib I set the target and action.

Am I doing too much?  Is there a 'less code' approach?


Yes  yes. The page I linked for you has it. Scroll down to Figure 9.  
All you need to do is control-drag from the Preferences menu item down  
to your pref panel as shown.


No subclassing, no code


http://developer.apple.com/cocoa/cocoabindings.html


___

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

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

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

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


Re: View Handling

2010-01-23 Thread Paul Bruneau
I used this method on the app I'm currently working with and it is great.

I can offer two tips. The first is make the tabs be visible in IB because then 
it's so much easier to switch between them in IB. Then in awakeFromNib you can 
make the tabs be invisible.

The first tip is that I found that the contents of the views did shift some 
number of pixels so I had to fiddle with it to make things line up correctly in 
the app. Maybe this is a result of my using that first tip, but it's worth it.

On Jan 22, 2010, at 6:50 PM, David Blanton wrote:

 NSTabView w/o tabs ... yeah that's the ticket!
 
 Thanks.
 
 -db
___

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

Please do not post admin requests or moderator comments to the list.
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: NSDictionary trouble

2010-01-19 Thread Paul Bruneau


On Jan 19, 2010, at 11:53 AM, Shawn Rutledge wrote:


I wish NSDictionary (NSMutableDictionary actually) could handle
arbitrary mappings of one type of object to another, without copying
the keys.  A string makes a good key most of the time but what about
the case where you want to do the reverse mapping, to find the string
which you have associated with a particular object?


When I want to find the key(s) for a given object, I use the - 
allKeysForObject method

___

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

Please do not post admin requests or moderator comments to the list.
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 statement causing 32 Byte leak?

2010-01-09 Thread Paul Bruneau
-new is the equivalent of an -alloc and -init, so you already own the  
object at that point. Then you retain it, so I think that's more  
retaining than you want to do.


That's my guess

Sent from my iPhone--typos caused by auto-correct

On Jan 9, 2010, at 8:15 PM, Mr. Gecko grmrge...@gmail.com wrote:

Hello, I'm going through leak checking and it seems that a if  
statement is causing a leak that's 32 Bytes  big. My if statement is


if (connections==nil) {
   connections = [[NSMutableArray new] retain];
}

It says that if (connections==nil) is leaking 32 bytes which I have  
no idea how that could be possible. Yes I'm releasing connections  
after I'm done using it.

Should I just ignore this? Thanks,
Mr. Gecko

___

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

Please do not post admin requests or moderator comments to the list.
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: iPhone: validate a NSString for US zipcode

2010-01-07 Thread Paul Bruneau
I'm a little unclear what you are asking, but I'll tell what I know.  
You just want to know if a 5 digit zip code is a valid one? Or do you  
want to compare it to the list of valid city names that are assigned  
to it? (yes it can be more than one, ugh)


They are (from a non-USPS point of view) arbitrarily assigned by the  
post office and there are currently 42,305 or so assigned (out of a  
theoretical maximum of 100,000 of course)


So assuming you just want to know if it's a valid zip (and don't care  
about if they got the city right), the only way to validate it solely  
from within your app as a valid zip code would be to have a list of  
them in your app.


You could load them from a plist or straight text I guess into an  
NSArray or NSSet and then check to see if the zip is valid as needed.


You can get the list from a third party service like http://www.zipcodeworld.com/ 
 or maybe from some free source.


The value of this might be questionable, since a zip code with a typo  
still has roughly a 50% chance of being a valid one. Plus the USPS is  
always adding new ones, so will you risk telling your user that his  
zip code doesn't exist when he is standing in it?


So I guess the answer is there is no Cocoa technology that can help  
with this--unless you are asking something completely different, in  
which case let's all have a good chuckle at my poor comprehension  
skills :)


On Jan 7, 2010, at 11:11 AM, Eric E. Dolecki wrote:


I've been googling but haven't seen yet how to best validate a 5-digit
zipcode for use in the US (without using a webservice).

I have the NSString, I just need to validate it. I know zero RegExp,  
is

there a formatter I can use?

___

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

Please do not post admin requests or moderator comments to the list.
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: iPhone: validate a NSString for US zipcode

2010-01-07 Thread Paul Bruneau

On Jan 7, 2010, at 12:29 PM, David Duncan wrote:

Given that you would likely want to do this test with a binary  
search I don't see any reason why it should be slow (effectively you  
can do the entire search with about 17*k compares).


To help make this thread more Cocoa-y, I would like to ask: Do the  
NSSet and NSArray methods like -containsObject perform in a fashion  
comparable to a home-rolled binary search? I greatly prefer to use the  
Cocoa stuff rather than try to remember/learn how to properly code  
such things.


Plus, the theory of premature-optimazation-is-bad would say just use  
the Cocoa stuff and only if performance is proven to be a problem,  
then look at optimizing, wouldn't 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: Why is [NSArray arrayWithObjects:] failing for me?

2010-01-04 Thread Paul Bruneau


On Jan 4, 2010, at 7:58 AM, Charles Jenkins wrote:


On 2010-01-03 00:08, Eric Smith wrote:
Correct, do not release the array.  If you don't create it with  
init, or retain it, then you should not release it.


Eric, thank you for stating that rule. It should be easy enough to  
remember and help me avoid this problem in the future.


That rule isn't complete. Just read the published memory management  
docs that someone else linked for you--several times.


In my defense, there seems to be a bug in the latest XCode, which  
make strings stored in NSArrays look like garbage when inspected  
during debugging. So the elements of pnl appeared to be trashed  
immediately upon creation. That's why I was looking for the bug in  
the wrong place.


Does anyone else find XCode extremely buggy? I have to continually  
close and reopen my editing window because the code display gets  
trashed and appears to scramble my code. It doesn't really change  
the source code file; it just makes it look as if I've randomly gone  
through the file deleting stuff, and when I see that happen, I  
immediately save, close, and reopen the window, and everything is  
fine.


Mac software is usually first class, stable, and beautiful. How do  
folks write such great software when they're stuck with such a sub- 
par IDE? :-)


I don't find it buggy. I find it first class, stable and beautiful.
___

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

Please do not post admin requests or moderator comments to the list.
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: button cell - selection change timing

2009-12-27 Thread Paul Bruneau
On Dec 27, 2009, at 9:00 PM, Rainer Standke wrote:

 Hello all,
 
 I have a table view with a column that holds a button cell. When the user 
 clicks the button I need to open a web browser with an URL that is stored in 
 the object represented by the table view's row. All of this is in a Core Data 
 app.
 
 When the button is clicked in a row that is already selected everything works 
 as expected.
 
 When the user clicks a button in a row that is currently not selected, then I 
 get the URL for the row that's in the process of being de-selected, because 
 the method targeted by the button runs before the selection has changed to 
 the new row.
 
 What can I do about this?

Can we see the code in the method targeted by the button? It is good to show 
some code when asking for help.

Although it might not be necessary--I suspect you are using -selectedRow 
instead of -clickedRow to get the row the user clicked. Try 
-clickedRow.___

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

Please do not post admin requests or moderator comments to the list.
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: button cell - selection change timing

2009-12-27 Thread Paul Bruneau

On Dec 27, 2009, at 9:21 PM, Rainer Standke wrote:

 Sure. Here is what happens in the method targeted by the button. From the 
 tableview ( = sender) it gets the first column, from that it gets the array 
 controller behind the column, from that it gets the selection and finally it 
 gets the string I am after. All of this is in a core data app, and I am not 
 using a data source per se. The problem seems to be the timing of it all, 
 rather than how the method works, because when the selection doesn't change 
 in the button click, everything is fine.
 
   //get 1st column in sender:
   NSTableColumn *tableColumn = [[sender tableColumns] objectAtIndex:0];
   // get bound-to array controller
   NSArrayController *arrayController = [[tableColumn 
 infoForBinding:@value] valueForKey:@NSObservedObject];
   // get selected object's URL:
   NSString *selectedPersonPage = [[arrayController selection] 
 valueForKey:@URLFragment];
   NSLog(@selectedPersonPage: %@, selectedPersonPage);

I must admit some ignorance of core data apps, but maybe that won't matter 
much. From what you said, sender is the tableview, so that is the same thing I 
would expect in a non-core-data app that I have more experience with.

You concern me with this statement of yours:

 The problem seems to be the timing of it all, rather than how the method 
 works, because when the selection doesn't change in the button click, 
 everything is fine.

It's not that everything is fine. It's that in your test case (where the 
selected row equals the clicked row), the thing that you are looking at (the 
selected row) just happens to be the same as what you want (the clicked row). 

So if you will accept that what you want is the clicked row, and you don't 
really care about the selected row(s), see what happens if you use [sender 
clickedRow] to get the clicked row, then from there to get your URL. Maybe 
-clickedColumn can help you too (your code has lost me a bit so I can't say for 
sure)

Hopefully my ignorance of core data isn't wasting your time. If it wasn't a 
holiday weekend (or even week) here in the states, I'd probably lurk this one 
out.___

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

Please do not post admin requests or moderator comments to the list.
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: Adding sub menus programatically

2009-12-24 Thread Paul Bruneau

On Dec 24, 2009, at 4:25 AM, Michael Davey wrote:

 Hi,
 
 I have googled around but have found nothing that can help me with this... I 
 have a menu in my application that I wish to add sub items to 
 programatically. I have the Menu itself connected up and I can add 
 NSMenuItems to it just fine, but seem at a loss to be able to add a sub menu 
 and the sub itmes to that menu.
 
 I suspect my answer lies in this function:
 
 - (void)setSubmenu:(NSMenu *)aMenu forItem:(NSMenuItem *)anItem
 
 But I do not understand what the forItem part of the method is for. Further, 
 I can retrieve a menu item from the menu, but am also at a loss as to how to 
 retrieve my submenu at a stage in the future.  I have a feeling that there is 
 something very simple that I am not understanding here, and would be very 
 grateful if someone could point me in the right direction.
 
 And Merry Christmas to everyone!!!

anItem is a pointer to the menu item to which you wish to connect the submenu.

I was working on code to do this yesterday, and I saw this method, but I 
preferred instead to just use the -setSubmenu method of my menu items. What you 
might not be understanding is that you attach a menu to the submenu property of 
a menu item. You don't add a submenu to a menu as you seem to have put it above.

In either case, in the future, when you want to get the submenu, you can send 
the -submenu message to your menu item that has the submenu attached to it in 
order to retrieve the submenu.

If you don't know which menu item has a particular submenu that you are 
interested in, you can search through them, or you could set the tag of the 
menu item of interest and find the item that has that tag at some later time 
using NSMenu's  –itemWithTag: method.

Definitely read the menu programming guide and and NSMenu and NSMenuItem class 
descriptions and I think you'll find that menus are one of the most 
straightforward parts of Cocoa to 
understand.___

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

Please do not post admin requests or moderator comments to the list.
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


Dependent values that are not iVars

2009-12-18 Thread Paul Bruneau
I would like to know the correct way to implement a non-stored value  
that is dependent on members of a collection.


I am setting up the object that holds the dependent value as an  
observer of the individual members of the collection like this:


[theFrameModule addObserver:self forKeyPath:kOverallWidth  
options:NSKeyValueObservingOptionNew context:NULL];


And I use the following to see when one of the items in the collection  
has changed:


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object  
change:(NSDictionary *)change  context:(void *)context

{
if ([keyPath isEqualToString:kOverallWidth]) {
NSLog(@got notification that overallwidth changed: %@, 
object);
}
}


This works just fine. I get notified of the changes to the members of  
the collection.


But my question is this:

I want my dependent value to exist very simply as a method. I don't  
need or want it to be an ivar of its object. So something like this:


-(NSInteger)overallWidth;
{
NSInteger overallWidthSubtotal = 0;
for ( SLFrameModule * theModule in [self frameModules] )
{
overallWidthSubtotal += [theModule overallWidth];
}

return overallWidthSubtotal;
}

My problem is that when I use overallWidth in a binding, the value  
does not get updated. There is some tickle that is not occurring.


I have replaced my -overallWidth method above with an iVar, and that  
does work, but I would rather have it exist solely as the method  
above. Is there any way to put something in my - 
observeValueForKeyPath: method that will tell the KVO system that  
overallWidth would be a different value if checked?


Thank you
___

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

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

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

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


Re: Dependent values that are not iVars

2009-12-18 Thread Paul Bruneau

On Dec 18, 2009, at 2:08 PM, Quincey Morris wrote:

This is a situation where you use willChangeValueForKey:/ 
didChangeValueForKey:


	- (void)observeValueForKeyPath:(NSString *)keyPath ofObject: 
(id)object change:(NSDictionary *)change  context:(void *)context

{
   if ([keyPath isEqualToString:kOverallWidth]) {
[self willChangeValueForKey:@overallWidth];
NSLog(@got notification that overallwidth changed: 
%@, object);
[self didChangeValueForKey:@overallWidth];
   }
}



Ahh, of course, thank you Quincey!


A couple of things I notice:

1. You have 2 identically named properties (overallWidth) in  
related objects. My experience has been that if there's ever  
anything wrong with (say) your bindings, it gets incredibly  
confusing working out from logged error messages *which* property  
has the problem. You can save yourself some grief by renaming (say)  
your dependent property to (say) overallWidthSubtotal.


OK I see what you are saying. I will rename one or both of them.

2. Your observer method is stripped down, right? You are really  
using a unique value for the context parameter, right? It's not  
really safe to just not care.


No, I'm not using context. My feeling was that since I am checking for  
the keypath, that is all I needed to care about. Can you elaborate  
about the unsafeness of that? Thank you.


3. Your dependent property is *also* dependent on the array itself.  
You will also put the willChange/didChange invocations in the  
place(s) where you add/remove/replace objects in the underlying  
array, yes?


Yes, thanks for the note on that. I had already noticed that I needed  
that for when objects in the collection get added or removed.


4. The use of willChange/didChange in the observer method causes a  
nested KVO notification. (It triggers at the didChange invocation.)  
In general, you have to be a little careful that your observer  
method puts your object in an internally consistent state before  
triggering the notification, and that you don't cause any infinite  
notification loops. This is likely not a problem if this is all your  
code, but it's something to keep in mind. (Actually, it's a  
potential issue anywhere you trigger a nested notification, such as  
when you set a property inside a different property setter method.)


I think I have a vague understanding of what you are saying. I *think*  
I'm OK in this area but I will watch out for problems.


Thanks again!
___

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

Please do not post admin requests or moderator comments to the list.
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: Dependent values that are not iVars

2009-12-18 Thread Paul Bruneau


On Dec 18, 2009, at 2:28 PM, Kyle Sluder wrote:


On Fri, Dec 18, 2009 at 11:18 AM, Paul Bruneau
paul_brun...@special-lite.com wrote:

  if ([keyPath isEqualToString:kOverallWidth]) {
   [self willChangeValueForKey:@overallWidth];
   NSLog(@got notification that overallwidth  
changed:

%@, object);
  [self didChangeValueForKey:@overallWidth];
 }


Please note that it is not correct to call -will/didChangeValueForKey:
without actually changing the value. The KVO mechanism might just
simply not send a notification at all. (Well, I guess it's valid, but
you might see fewer observation notifications than you would expect.)
This is difficult to get right with derived properties.

Also don't have the first inclination I had, which is to use
-keyPathsForValuesAffectingValueForKey:. As described in the
documentation, it will not work.


Ugh, so I guess you are saying that derived properties are not  
trustworthy in this usage?


I like them so much because then I never have to worry about the  
stored value being out of date (which admittedly, if I do everything  
exactly right, I guess it will never be out of date, but I like not  
having to worry about it).


It's also a bummer because so far it is working fabulously with  
willChange/didChange.


I might live dangerously and leave it in until it bites me.

Thanks for the warning, I'll make note of 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: Dependent values that are not iVars

2009-12-18 Thread Paul Bruneau


On Dec 18, 2009, at 2:56 PM, Kyle Sluder wrote:


On Fri, Dec 18, 2009 at 11:48 AM, Paul Bruneau
paul_brun...@special-lite.com wrote:
Ugh, so I guess you are saying that derived properties are not  
trustworthy

in this usage?


No, just that if you don't actually change the value, KVO might not
bother notifying listeners. The actual values are fine, just wanted to
address this issue in case you see fewer change notifications than you
expect in the course of your debugging.


Oh, OK. In my case, I don't need (or even want) a notification if the  
value doesn't change, so even if the KVO system doesn't notify my  
listeners in case of an unchanged derived value, I won't mind.


Thank you
___

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

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

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

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


Re: Best way to hook into the run loop?

2009-12-06 Thread Paul Bruneau

On Dec 6, 2009, at 5:53 AM, Graham Cox wrote:

 
 On 06/12/2009, at 8:12 PM, Uli Kusterer wrote:
 
 I thought that was what undo groups were for? Open a group at the start of 
 the drag manually, close it at the end, and everything in between gets 
 lumped into one big action at the end. It may get replayed internally, but 
 will all be triggered by one Cmd-Z.
 
 
 Indeed, undo groups are great. Unfortunately, NSUndoManager has a bug where 
 if you open a group (on mouse down, say), do nothing (no drag), and close it 
 again (on mouse up), an empty Undo task appears in the Undo menu. It's 
 harmless, in that it does nothing, but it's also a nuisance, since the user 
 doesn't expect this and reports it as a bug with your app. It's working 
 around this bug that is horrible and surprisingly complicated (for two 
 reasons - one, you can't peek at the top of the undo stack to see what's 
 there and two, even if you could there's no way to tell whether the task 
 there is empty, because the 'tasks' are all private classes. Therefore you 
 have to come up with another way either to detect this case, or to prevent it 
 from happening. Either way, it's a complicated and nasty hack). Incidentally 
 I have reported this bug but it came back as a dupe. It's been there since I 
 started with Cocoa, on 10.2.

I ran into the same problem and my bug was also flagged as a duplicate. Here is 
my submission which includes my workaround:

 14-Aug-2008 09:31 AM Paul Bruneau:
 * SUMMARY
 When trying to utilize undo grouping using what seems to be the most 
 straightforward way, the undo group can be empty with no actions in it, yet 
 the system will still put this empty group into the undo stack.
 
 * STEPS TO REPRODUCE
 In my case, I am dealing with user actions in an NSView subclass. I use 
 -mouseDown, -mouseDragged, and -mouseUp.
 
 The way that seemed at first to be best is to initiate an undo group in 
 -mouseDown, create undo actions during -mouseDragged, and finally to 
 terminate the undo grouping in -mouseUp. The user clicks objects in the view 
 and drags them around. This results in many operations over the course of the 
 dragging, all of which I want to be in one undo group.
 
 But if I implement my grouping code in mouseDown and mouseUp, I have the 
 problem where if the user just clicks on one of my objects without moving it, 
 the undo group is empty, containing no actions. 
 
 
 * RESULTS
 The results of this are that the empty undo group is put on the stack, and 
 the user can Undo it, but nothing happens (because there was no action to 
 undo).
 
 What I would like to see, is if an undo group has no actions in it, it should 
 be discarded. Surely this is what Cocoa does when it is doing its normal 
 event loop based grouping. It doesn't put an empty undo group into the 
 stack with every pass of the event loop--why does it put my empty undo group 
 into the stack?
 
 Or perhaps consider this a documentation enhancement request. Maybe there is 
 an easy solution for me that I don't know about.
 
 
 * NOTES
 In my particular case, I was able to perform a workaround by implementing the 
 -beginUndoGrouping message in my -mouseDragged method. 
 
 By doing it this way, I am assured that the user is actually dragging around 
 one of the objects in my view rather that just clicking on one, or clicking a 
 blank area of the view.
 
 But it is kind of kludgy because -mouseDragged is repeatedly called while the 
 user is dragging. So I had to test to see if an undo group already exists 
 like so:
 
 - (void)mouseDragged:(NSEvent *)event
 {
   if ( dragging == YES ) 
   {   
   if ( [[myUndoManager] groupingLevel] == 0 )
   {
   //start custom undo grouping
   [[myUndoManager] setGroupsByEvent:NO];
   [[myUndoManager] beginUndoGrouping];
 
   }
 ...
 
 But I don't find this optimal. It would get a lot more complex if I did any 
 nested groups I think.

___

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

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

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

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


Re: NSPopUpButton questions

2009-12-06 Thread Paul Bruneau

On Dec 6, 2009, at 12:29 PM, Andy Lee wrote:

 On Dec 6, 2009, at 11:34 AM, Matt Neuburg wrote:
 On Sat, 5 Dec 2009 20:29:25 -0500, timm...@gmail.com timm...@gmail.com
 said:
 The Apple docs for NSPopUpButtons says to avoid accessing it's NSMenu 
 directly
 because it may need to do housekeeping.
 
 Where do the Apple docs say that? I'm thinking there might be some
 misunderstanding lurking here. m.
 
 Indeed, there are a few methods where the docs specifically recommend 
 accessing the menu directly, e.g.:
 
 http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPopUpButton_Class/Reference/Reference.html#//apple_ref/occ/instm/NSPopUpButton/insertItemWithTitle:atIndex:
 Since this method searches for duplicate items, it should not be used if you 
 are adding an item to an already populated menu with more than a few hundred 
 items. Add items directly to the receiver's menu instead.

Yeah, but the OP is right, the Application Menu and Pop-up List Programming 
Topics for Cocoa says this:

 To implement its menu, the button cell contains an NSMenu object, which in 
 turn contains several NSMenuItem objects, one for each item in the menu. 
 Avoid invoking methods on the NSMenu object directly, but instead invoke 
 methods on theNSPopUpButton instance, which may need to do some housekeeping 
 before invoking the appropriate methods on the menu. However, you can 
 retrieve the menu with the NSPopUpButton method menu. The NSPopUpButton 
 methods you use most often are the methods that tell you which item is 
 selected.

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/MenuList/Articles/HowMenusWork.html

I have to say this has never stopped me from molesting the menu directly. But I 
disagree with the HIG on popup menus so I'm often on the wrong side of the law 
regarding this topic.___

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

Please do not post admin requests or moderator comments to the list.
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


Drawing: The Right place to keep bounds

2009-11-25 Thread Paul Bruneau
I'm really trying to do things correctly with my app but I'm at a  
place where I can't figure out what correct is, and all my best  
examples do it wrong (I think).


I am working on the drawing parts of my app. In my last app I most  
definitely did things Wrong but they work fine and there's just one  
user and it was my first Cocoa app so I didn't beat myself up too much.


It's document-based, non-core-data, and aimed at 10.5.

For reference, I am using Sketch, and Cocoa Design Patterns by Buck  
and Yacktman. I also am referring to my memory of several helpful  
posts to this list by Buck over the past couple years that I have been  
watching for them.


I think I recognize, and I am pretty sure I have read that Sketch does  
things Wrong. I see that the shape objects keep their own bounds (and  
frame?) information. It seems clear to me that this is Wrong. What  
does Sketch do if it ever can have two views of the same objects?


I am also pretty sure that Cocoa Design Patterns does it wrong because  
it admits such:


The model in this example is deliberately kept simple to preserve  
the focus on the Controller
subsystem. In most applications, properties like rectangles and  
colors are user interface concerns that
don’t belong in the Model subsystem. However, in this case,  
MYShapeDraw is a drawing program.


This seems like a common problem that I have had with various Cocoa  
information over the years. Everything is kept simple for the sake of  
the example, and I am left clueless about the correct way to do it (or  
I am too dumb to see it). In the quote above, I have learned that the  
rectangles don't belong in the Model subsystem. OK that's a good  
start! Now, where do they belong?


I have a window controller, which is the file's owner of a nib that  
contains the window. In the window is my custom view. My custom view  
contains the skeletal beginning of a category for the drawing code of  
the model objects that are displayed in it (as explained by Buck,  
around page 257). This part I feel I understand pretty well and it  
works.


But where to put the rectangle and other data that each object needs  
in order to be kept track of (for clicking on, etc) and drawn?


Thank you for any insight!___

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

Please do not post admin requests or moderator comments to the list.
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: The Right place to keep bounds

2009-11-25 Thread Paul Bruneau
OK, I see what you are saying, and to that I respond, why does every  
example that I have ever found of how to draw objects in a custom view  
happen to be a drawing program? :)


And I'm not sure I buy what you are saying, because, just like I  
mentioned for the Sketch example, what does his program do when the  
user makes a new window with the same view in it and that view has a  
different zoom factor, or is scrolled to a different position?


My question remains: where should I keep this information? Surely  
people draw objects in apps other than drawing programs that are  
limited to a single view.


I do thank you for your response!

On Nov 25, 2009, at 11:00 AM, David Hirsch wrote:

I think you are missing the point of the quote, which is that  
drawing programs are an exception to the typical rule that view data  
must be strictly separated from the model (However, in this  
case).  When the model data is all about visual information  
(drawing), then you have no choice but to violate the rule.


On Nov 25, 2009, at 7:27 AM, Paul Bruneau wrote:

I am also pretty sure that Cocoa Design Patterns does it wrong  
because it admits such:


The model in this example is deliberately kept simple to preserve  
the focus on the Controller
subsystem. In most applications, properties like rectangles and  
colors are user interface concerns that
don’t belong in the Model subsystem. However, in this case,  
MYShapeDraw is a drawing program.


This seems like a common problem that I have had with various Cocoa  
information over the years. Everything is kept simple for the sake  
of the example, and I am left clueless about the correct way to do  
it (or I am too dumb to see it). In the quote above, I have learned  
that the rectangles don't belong in the Model subsystem. OK that's  
a good start! Now, where do they belong?

___

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

Please do not post admin requests or moderator comments to the list.
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: The Right place to keep bounds

2009-11-25 Thread Paul Bruneau

On Nov 25, 2009, at 11:24 AM, Jens Alfke wrote:


On Nov 25, 2009, at 7:27 AM, Paul Bruneau wrote:

I think I recognize, and I am pretty sure I have read that Sketch  
does things Wrong. I see that the shape objects keep their own  
bounds (and frame?) information. It seems clear to me that this is  
Wrong. What does Sketch do if it ever can have two views of the  
same objects?


The bounding box is an intrinsic property of a geometric object,  
independent of how it's viewed.


Unless you're talking about something like a bounding box  
transformed into view coordinates; I'm not familiar with the Sketch  
code. That would definitely be part of the view, not the model. That  
sort of design is often done by having a parallel per-view model  
that's been transformed for use in the view, and code that keeps the  
per-view model synced with changes to the master. Core Animation  
uses this sort of design.


Thank you, I was thinking of the bounding box as dependent on the  
view. For example, I think of a zoom value for a view--that affects  
the bounding box, doesn't it? Or do I use a sort of natural bounding  
box for my objects that is then modified by the view's zoom?


I guess this is what you mean by a bounding box transformed into view  
coordinates. Yes, that is the way I am thinking of it, so that I can  
do things like hit-testing in however many views my user might have  
open. So OK I will start thinking about a parallel per-view model.


Thanks!
___

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

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

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

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


Re: NSValueTransformer problem with NSTextField update

2009-11-10 Thread Paul Bruneau
If anyone is interested in seeing this issue with NSValueTransformer  
and how it performs in a table vs in a text field, I had filed a bug  
(7268704) on it and was asked to provide an example. So I thought I'd  
share my example:


http://ethicalpaul.com/share/transformer_sample_code.zip

It's based on the WithBindings sample code from mmalc.

When you run the project you'll see the familiar WithBindings  
interface. I have added a new instance variable to the document type  
which is an NSInteger called numberOf32nds.


On the interface, I have added a new column to the table (marked  
Inches) and in the detail view below the table I have added a text  
field also marked Inches. I have bound them to the numberOf32nds  
instance variable using my transformer called  
ThirtySecondsToInchesTransformer.


First, create a new Bookmark and edit its Inches value in the table.  
Try entering something like: 32 3/4 You will see upon pressing Return  
that the value is cleaned up by being sent into the transformer and  
then back out again. It comes out: 32-3/4.


You will see this value also gets updated in the Text field below  
thanks to the Bindings system. (You can also use a shorthand data  
entry method of inches.32nds such as entering 32.5 and it will get  
transformed to 32-5/32)


Now, go down below to the edit field and try the same thing. You will  
see that the entered value does not get cleaned up, but remains how  
you entered it. Of course, the cleaned up version does get updated  
in the table (again, thanks Bindings).


It seems like other people would have had issues with this, but  
sometimes I do things differently than other people :)


On Sep 17, 2009, at 2:15 PM, Paul Bruneau wrote:


Greetings-

I have written a subclass of NSValueTransformer which converts an  
NSString from something like 1-1/2 to an NSNumber with a value of  
48 for my model to store (converts inches and fractions to number of  
32nds). It also does the reverse transformation.


This is working perfectly for columns in an NSTableView that I have  
bound to NSInteger properties in a model object. If I enter: 1 1/2  
and press return, it will store the correct number, and it will even  
instantly update the cell to contain the cleaned up version of the  
fraction which would be: 1-1/2 (which I find very desirable). So  
it's like the the transformer is working in the normal direction to  
store the correct value, then the reverse transformer is also  
getting called and updating the text cell.


So then I had need to use this transformer for a few NSTextFields on  
the same window as the table and here is the weirdness:


When I enter the text (say 1 1/2) and press return, the correct  
value is getting set in model BUT the field content is not getting  
updated like it does in the NSTableView. It will select the text,  
but it will not replace it with its cleaned up content which  
should be: 1-1/2


If I choose Undo (and also Redo), then the cleaned up text  
appears. Or if I close the window, and then re-open it, then the  
cleaned up text is correctly displayed (ditto for the document).


Does anyone have any idea why I am seeing this difference between  
the table columns and the text fields?


Is it normal for a transformer to do that nice clean up after  
return is hit that I am seeing in my table, or is that being caused  
by some lucky accident in my case?


Thank you


___

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

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

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

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


Re: Best pattern for similar objects with differences

2009-11-09 Thread Paul Bruneau

Thanks all for your help-

I wasn't clear enough, I agree, and sorry about that, but there was a  
hint hidden in my text:
 (I'm going to have categories to handle drawing, material takeoff,  
pricing, etc for each door type).


We manufacture entrances (and many doors). The users of this app enter  
data from customer orders and my app generates pricing and build  
information. The users do need to be able to change the type of door  
(because often the customer will change it during the process). It's  
extra nice not to lose any data during these changes (although some  
properties get reset during a type change).


I think the direction I'm going to go is to put all the properties of  
all the door types into the base class, but still have subclasses so  
that I can separate out all the various methods and categories that  
are going to be specific to each door type.


I'm sorry if this was borderline not cocoa (and more obj-c or data  
structure theory or something), but I definitely want to utilize  
patterns that are most compatible with Cocoa so I felt it was  
reasonable that it be asked here.


Thank you all again, I have read each of your responses 5 times :)

On Nov 4, 2009, at 1:47 PM, Paul Bruneau wrote:


Hi-

I'm in early development of an app (non-core data, NSDocument app)  
that will deal with a lot of doors. I have created a door object,  
SLDoor, which currently contains all of the properties that might be  
used by any of the several types of doors.


There is a doorType property which is what determines which of the  
types of doors a particular instance is.


This means that if you choose a door type, many properties that are  
only used by any of the other types will go unused. On the other  
hand, it's very good for if the user wants to change the door type-- 
the properties are all there ready and waiting.


But I did have the idea that I should make SLDoor a superclass of  
new classes, one for each type of door. So I would have  an  
SLFlushDoor, an SLMonumentalDoor, and an SLPlankDoor for example,  
all subclasses of SLDoor.


In this way, I can really separate out all kinds of code and  
properties that are specific to a certain type of door, while  
keeping in the superclass all the properties that are shared among  
several or all of the types of door (I'm going to have categories to  
handle drawing, material takeoff, pricing, etc for each door type).


So this is very attractive, but I keep worrying about how I would  
change a door from one type to another if I utilize these  
subclasses. Any ideas the best pattern to use? I can't figure out  
how I would take an existing object of say SLFlushDoor and convert  
it to an SLMonumentalDoor (and possibly back again) with anything  
close to the ease that I currently do it with the doorType property  
(but I shudder to think of all the if() statements I would have  
strewn through all my code if I stick with this pattern.)


Thank you

___

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

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

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

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


Best pattern for similar objects with differences

2009-11-04 Thread Paul Bruneau

Hi-

I'm in early development of an app (non-core data, NSDocument app)  
that will deal with a lot of doors. I have created a door object,  
SLDoor, which currently contains all of the properties that might be  
used by any of the several types of doors.


There is a doorType property which is what determines which of the  
types of doors a particular instance is.


This means that if you choose a door type, many properties that are  
only used by any of the other types will go unused. On the other hand,  
it's very good for if the user wants to change the door type--the  
properties are all there ready and waiting.


But I did have the idea that I should make SLDoor a superclass of new  
classes, one for each type of door. So I would have  an SLFlushDoor,  
an SLMonumentalDoor, and an SLPlankDoor for example, all subclasses of  
SLDoor.


In this way, I can really separate out all kinds of code and  
properties that are specific to a certain type of door, while keeping  
in the superclass all the properties that are shared among several or  
all of the types of door (I'm going to have categories to handle  
drawing, material takeoff, pricing, etc for each door type).


So this is very attractive, but I keep worrying about how I would  
change a door from one type to another if I utilize these subclasses.  
Any ideas the best pattern to use? I can't figure out how I would take  
an existing object of say SLFlushDoor and convert it to an  
SLMonumentalDoor (and possibly back again) with anything close to the  
ease that I currently do it with the doorType property (but I shudder  
to think of all the if() statements I would have strewn through all my  
code if I stick with this pattern.)


Thank you

___

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

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

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

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


Bindings, am I doing right by MVC?

2009-10-23 Thread Paul Bruneau
I'm trying to do things correctly in my new app that I am writing, so  
I wanted to ask this question because I'm not sure if I am.


I have a window for a door object in my document (NSDocument based  
app). It's a good thing I don't work for a window company or things  
would be really confusing.


In the window I have a lot of UI elements.

First, I feel I'm doing things correctly with my table bindings. I  
have array controllers and I bind like:


Bind to: Cutouts (the array controller)
Controller key: Arranged Objects
Model Key Path: cutoutWidth  (an ivar of the object in the array)

(this information is made annoying to get because the IB Inspector  
window disappears when I click in Mail. Not helpful!!!)



But I wonder about my edit fields. They are bound like:

Bind to: File's owner (a NSWindowController subclass)
Controller Key: blank
Model Key Path: door.backset (door is an ivar of the window  
controller--it's the door that the window controller is for. backset  
is just an ivar of the door object)


Does that look ok, or am I skipping another controller that should be  
in there? Skipping controllers is probably one of my most serious bad  
habits that I'm trying to break.


Thanks for any insight,
Paul
___

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

Please do not post admin requests or moderator comments to the list.
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: Binding hidden attribute

2009-10-12 Thread Paul Bruneau
Yes, I have recently learned how to do this for my under development  
app.


Here is the IB part, pretty straightforward (File's Owner (a  
controller class) has a door object with a derived fake ivar called  
isMonumental:


inline: pastedGraphic.png




The tricky part in your case (and mine) is because your ivar is not  
an ivar but a derived value returned by a method, you need to tell the  
KVO system that. Here is my method:


+ (NSSet *)keyPathsForValuesAffectingIsMonumental;
{
return [NSSet setWithObjects:kTypeKey, nil];
}

In your case, you have more than one dependent key, which is fine, try  
this (10.5 and later--there's another way for pre 10.5):


+ (NSSet *)keyPathsForValuesAffectingSchemaIsHidden;
{
return [NSSet setWithObjects:@query, @source, nil];
}

So now if either of those keys changes, KVO will do something like  
notify everyone watching schemaIsHidden (what actually happens is  
beyond my knowledge). If you had a real BOOL ivar, it would Just  
Work without this extra stuff.


You can read all about it here:
https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/KeyValueObserving/Concepts/DependentKeys.html 
#//apple_ref/doc/uid/20002179


Based on history, there is a good chance I messed something up in this  
answer, so I hope someone will correct me if necessary.


On Oct 11, 2009, at 8:34 PM, BareFeet wrote:


OK, let me put this another way:

Has anyone successfully bound the hidden attribute of an Interface  
object, so that it hides and shows when the ivar changes? If so, how?


Thanks,
Tom
BareFeet


From: BareFeet list.develo...@tandb.com.au
Date: 9 October 2009 12:18:38 AM AEDT
To: Cocoa Dev Cocoa-dev@lists.apple.com
Subject: Binding hidden attribute

Hi all,

I'm trying to hide a tab view item according to the value returned  
an accessor in my model.


My accessor simply returns YES or NO, as per:

- (BOOL) schemaIsHidden {
	return ([type isEqualToString: @query] || [type isEqualToString:  
@source]);

}

In interface builder, in my document nib, I selected the view  
belonging to my Schema tab view item, set its Hidden attribute to:


Bind to: My Array Controller
Controller key:  selection
Model Key Path:  schemaIsHidden

It compiles OK, but when I run it, I get an error in the log:

Cannot create attributed string from object null of class NSNull

What does this mean?

Do I have the correct class (BOOL) returned by my accessor?

My other bindings to this same model and controller work fine.

Thanks,
Tom
BareFeet


___

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

Please do not post admin requests or moderator comments to the list.
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: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau

Hi again-

I got no responses to my query, which probably means I asked something  
poorly, but I needed to write another NSValueTransformer for my  
project (to convert dollars into pennies and back) and I saw the same  
behavior so I thought I'd ask again.


To summarize: When I use my NSValueTransformers in a cell of an  
NSTableView, the entered value gets transformed twice--once going in  
to my model, then it comes back out to the view--which is good because  
it cleans up the entered value and makes it be optimal (as outlined in  
my original question below).


But when I use the transformer on a regular NSTextField, I don't get  
that benefit. It properly transforms the value and the correct value  
gets stored in my model, but the reverse transformation doesn't fire  
like it does when used in the table view.


In tableview:
1. type: 1 1/2
2. press return
3. 1-1/2 is now displayed (the cleaned up, doubly-transformed string)

In textfield:
1. type: 1 1/2
2. press return
3. 1 1/2 is displayed (no change)
4. press undo
5. press redo
6. 1-1/2 is displayed (the cleaned up, doubly-transformed string)

Any help appreciated

On Sep 17, 2009, at 2:15 PM, Paul Bruneau wrote:


Greetings-

I have written a subclass of NSValueTransformer which converts an  
NSString from something like 1-1/2 to an NSNumber with a value of  
48 for my model to store (converts inches and fractions to number of  
32nds). It also does the reverse transformation.


This is working perfectly for columns in an NSTableView that I have  
bound to NSInteger properties in a model object. If I enter: 1 1/2  
and press return, it will store the correct number, and it will even  
instantly update the cell to contain the cleaned up version of the  
fraction which would be: 1-1/2 (which I find very desirable). So  
it's like the the transformer is working in the normal direction to  
store the correct value, then the reverse transformer is also  
getting called and updating the text cell.


So then I had need to use this transformer for a few NSTextFields on  
the same window as the table and here is the weirdness:


When I enter the text (say 1 1/2) and press return, the correct  
value is getting set in model BUT the field content is not getting  
updated like it does in the NSTableView. It will select the text,  
but it will not replace it with its cleaned up content which  
should be: 1-1/2


If I choose Undo (and also Redo), then the cleaned up text  
appears. Or if I close the window, and then re-open it, then the  
cleaned up text is correctly displayed (ditto for the document).


Does anyone have any idea why I am seeing this difference between  
the table columns and the text fields?


Is it normal for a transformer to do that nice clean up after  
return is hit that I am seeing in my table, or is that being caused  
by some lucky accident in my case?


Thank you


___

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

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

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

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


Re: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau

On Oct 1, 2009, at 9:47 AM, Graham Cox wrote:

I don't have a definitive answer for you, but I've observed similar  
behaviour in some of my text fields. As long as you're typing, what  
you type is what the field will display. On enter/return, the value  
is sent to the data model, through the transformer if necessary. The  
question is what happens then?


exactly!

For fields that are updated via KVO, I find that the reverse  
transformation will be applied and the field gets updated. That  
makes sense because there is a notification coming back from the  
data model that updates the UI. For fields where I just have a one- 
way type of situation (plain target-action, say), the field doesn't  
get updated - again for obvious reasons.


Everything you say here makes sense. This would apply to bindings  
also, wouldn't it?


So I'd be looking at the data model -- view data path for the  
solution to this, not the other way around.


Not sure if this is any help, but you don't state how your UI and  
data model connect - target/action, KVO or bindings.


Thank you, Graham-

Sorry, I should have stated my connection mechanism. I am using  
bindings.


Initially, I was using KVO in the table, and I thought maybe that  
difference had something to do with it, but since that time, I have  
converted everything in the table to bindings, removed all the glue  
code, and I still see the same behavior (I have an NSPopUpButtonCell  
in one of the columns, and in the beginning I had that wired up with  
KVO, but I later learned how I could use it with bindings, hence the  
change).


Additionally, I just tested on a new NSTableView with nothing but  
bindings, and it shows the same behavior as the original table view  
(the NSTextFieldCell gets updated)


And finally, I just tried binding to the NSTextFieldCell of an  
NSTextField and I saw the same behavior as binding to the field itself  
(I was testing if there was something about NSTextFieldCell that made  
the bindings do the update, but it seems that's not it).


At this point, I would settle for an ugly workaround to make my text  
fields do the same update as my table views' cells. Does anyone know a  
way?

___

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

Please do not post admin requests or moderator comments to the list.
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: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau

On Oct 1, 2009, at 10:45 AM, I. Savant wrote:

Have you tried turning on the text field's value binding's  
continuously updates value option? Maybe even the validates  
immediately option? I imagine the wrong combination of these  
(including off) could have something to do with it.


Thanks for the suggestion, IS. I had in fact tried those and I tried  
them again just now (in all combinations), no change.

___

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

Please do not post admin requests or moderator comments to the list.
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: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau

On Oct 1, 2009, at 11:10 AM, I. Savant wrote:


On Oct 1, 2009, at 10:58 AM, Paul Bruneau wrote:

Thanks for the suggestion, IS. I had in fact tried those and I  
tried them again just now (in all combinations), no change.


 Hmmm ... This (figure 2):

http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Conceptual/CocoaBindings/Concepts/MessageFlow.html#/ 
/apple_ref/doc/uid/TP40002149


 ... seems to make no promise that anything in the view will be  
changed / updated in this scenario, regardless of a transformer.


Well if you look at Figure 2, step #23, it says Updated value now  
stored in model object. Key-value observing notifications are sent to  
observers of this model property.


So due to the binding, the text field would get updated by this  
mechanism, wouldn't it?


And promise or no, it is occurring in the table view...it's mysterious.


This seems more like a job for an NSFormatter ...


I am pretty ignorant of the differences, but in converting from a  
fraction to a number of 32nds, I picked NSValueTransformer. It does  
work great :) I'm just seeing this inconsistency between cells in a  
table, and text fields in a window.


Thanks again, still listening
___

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

Please do not post admin requests or moderator comments to the list.
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: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau


On Oct 1, 2009, at 1:23 PM, I. Savant wrote:

As Quincey mentioned, it's probably because the data cell for that  
column (the prototype that's reused to draw that column's value for  
each row) is being updated per row, which involves reading that  
value and setting it as the cell's object value. I agree: this seems  
the most likely reason for this behavior.


Thanks again IS and thanks Quincey (and Graham). I will look at  
validation, which I have never used before. I do shudder a little bit  
to have to copy/paste a validate method for each of the 20 or so  
properties that I'm dealing with (especially when it works so nice in  
tables just for free!!)


I also like Quincey's explanation of why it works in a table, makes  
sense.


In my initial tests of a validatekey method, it is receiving the  
value AFTER my transformer has transformed it to a number of 32nds  
(I'm not getting the original fraction string).


I think I'm in trouble, because if I don't modify the value coming  
into the validator, then it doesn't fire the field update. If I modify  
it, though, then yes, the field gets updated:


// this method will cause the field to get updated upon pressing Return
-(BOOL)validateTopClearance:(id *)ioValue
  error:(NSError **)outError
{
if (*ioValue == nil) {
return YES;
}
//add 1 to my number just to force it to update as a test   
	NSNumber * newValue = [NSNumber numberWithInteger:[*ioValue  
integerValue] + 1];

*ioValue = newValue;

return YES;
}

So apparently, the validator is noticing if I alter the value, and it  
does nothing (to my eyes) if the value is untouched. I am back at the  
beginning :)



___

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

Please do not post admin requests or moderator comments to the list.
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: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau

On Oct 1, 2009, at 2:16 PM, Quincey Morris wrote:

What was the number you tried this with? Some NSNumber values are  
singleton objects, so returning a new NSNumber with the same value  
might really return the original object. :) Or maybe just equality  
of value matters.


It occurs to me that the singleton-ness of the underlying NSNumber  
objects may have something to do with why the text fields didn't  
behave as you expected to begin with. Or the equality.


I like the way you think :) But I just went back and tried a wide  
variety of ridiculous numbers with no change. It seems to be based on  
the equality.


Maybe the lesson of all of this is that using a value transformer to  
control formatting (that is, when the transformed string has a  
preferred but not unique form) is not such a good idea.


Well I'm not really controlling formatting with it (more below). I  
just make sure the formatting looks the way I want it to in my reverse  
transform.


I can't remember now -- was there a reason why a NSFormatter  
subclass wasn't a viable option instead of a value transformer?


Yes, because I want the user to be able to enter something like '1  
1/2' but I want to store the number of 32nds (my base unit of  
measure). (I also allow a type of shorthand where the user enters  
number of inches.number of 32nds and my transformer deals with  
this as well). We work a lot with linear dimensions here.


The other way to approach this is to add a second set of properties  
-- the formatted string values of your numeric properties -- that  
are dependent on the numeric ones, and bind to the string properties  
instead. It's a PITA to code it all, but it puts the formatting all  
in your hands.


hmm, but will my users be able to make changes to text fields that are  
bound to dependent string values like that?


I just thought of something IS said earlier:

Thing is, aside from transformed values, the value that makes it to  
the model layer is usually a direct reflection of what was just set  
in the view. :-) In 99% of cases, this would seem a waste of CPU  
cycles to go back and make sure the view reflects the value it  
itself just claimed to have set.


The key thing you said, IS, was aside from transformed values which  
of course is exactly the case I am interested in. I am a little  
surprised that more developers haven't wanted their text fields to  
update to the reverse-transformed value after the user commits the  
change. It seems that Cocoa could easily look to see if a transformer  
is on the field, and do a reverse transform after entry.


I continue to be surprised that no one else has been bothered by this  
difference in behavior between these common UI types. Maybe  
transformers are very rarely used?


I'll keep thinking on it. Thanks again all.
___

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

Please do not post admin requests or moderator comments to the list.
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: NSValueTransformer problem with NSTextField update

2009-10-01 Thread Paul Bruneau

On Oct 1, 2009, at 3:34 PM, I. Savant wrote:

 The problem is, I think, that most developers aren't overloading  
the input as you are. :-)


I knew this would come up! :)

But in actuality, this same problem would occur regardless of whether  
I was overloading the input. Even in the very simplest case there  
would be this annoying difference between the two interface types that  
would manifest any time the user did not enter the value in exactly  
the same way the reverse transformer creates it.


 You're allowing (if I'm counting correctly) three different modes  
of input into the same text field with no indication, aside from the  
formatting of the text, which format the user is inputting.


 How about this (IMO) cleaner UI solution?

1 - Keep your base unit of measurement behind the scenes.
2 - Add a control that sets and shows (NSSegmentedControl, perhaps?)  
the input format. Place it beside or below the text field.
3 - Use an NSFormatter (one for each input mode, swapped out when  
the mode is changed) to format the input as required for that mode.
4 - Likewise, use an NSValueTransformer (one for each input mode,  
swapped on mode change) to convert the currently-selected mode's  
input to the base unit of measurement.


 It might be slightly less-convenient in that you can't type in just  
anything and have it magically formatted, but it ensures proper  
input and, if done right, demonstrates to the user the expected  
input format. It also frees you writing what is likely some very  
error-prone parsing code.


 Compare this to Apple's rocky love affair with natural language  
date input in NSDateFormatter.


I do have 20ish edit fields to contend with on my main window. I could  
set up a preference to let the user select his preferred entry method  
(there are just 2), but I still think I would still have the trouble  
with the inconsistent updating behavior between text fields and table  
views which is the reason for this thread. Plus it works so very very  
well and my users are all trained from 10 years of using the Classic  
and then Carbon versions of this app :)


But I thank you sir!

On Oct 1, 2009, at 3:47 PM, Quincey Morris wrote:

Now that you mention it, I've done exactly what you are trying to  
do, except I was using formatted time codes instead of fractions. I  
want to say that it was working correctly, but I can't swear to it.  
I'll have to go back to that app and see if it really does prettify  
the string representation when the underlying value doesn't change.


I would appreciate that. That scenario does sound very similar to  
mine. Thanks! 
___


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

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

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

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


Re: Best way to implement drag and drop for multiple types of nstableview

2009-09-28 Thread Paul Bruneau

On Sep 25, 2009, at 12:19 PM, I. Savant wrote:


Paul:

 Unless I'm missing something, why not add properties to your array  
controller class that keeps track of the desired types? If you use  
multiple tables for the same array controller instance, you could  
get even fancier and keep an association between provided and  
accepted types for each table.


Thank you IS-

That is the nudge I was looking for. I see now that I can just make  
the new properties, wire them up in IB to my tables and be able to  
keep track of everything.


Not all of the properties in each instance will have tables wired to  
them because not all the tables are in the same windows of course, but  
that should just result in nil settings for those outlets.


Thanks!
___

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

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

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

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


Best way to implement drag and drop for multiple types of nstableview

2009-09-25 Thread Paul Bruneau

Hi-

I have used mmalc's DNDArrayController class from his Bookmarks  
example code to implement drag and drop for one of my NSTableViews. Of  
course it works great.


But now I would like to set up a couple other table views with other  
types of data.


I can re-use my DNDArrayController, but then the interface thinks a  
user can drag between two tables with totally different types of data  
in them.


I can copy the class files and set up the new drag types in the  
copies, but I feel the urge to resist having multiple nearly identical  
classes of DNDArrayController lying around.


I guess I could subclass DNDArrayController and have a method that  
returns the data types for that particular subclass. That one doesn't  
sound too evil.


Can anyone provide some guidance on the correct way to set up these  
multiple NSTableViews with drag and drop?


Thanks
___

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

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

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

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


NSValueTransformer problem with NSTextField update

2009-09-17 Thread Paul Bruneau

Greetings-

I have written a subclass of NSValueTransformer which converts an  
NSString from something like 1-1/2 to an NSNumber with a value of 48  
for my model to store (converts inches and fractions to number of  
32nds). It also does the reverse transformation.


This is working perfectly for columns in an NSTableView that I have  
bound to NSInteger properties in a model object. If I enter: 1 1/2 and  
press return, it will store the correct number, and it will even  
instantly update the cell to contain the cleaned up version of the  
fraction which would be: 1-1/2 (which I find very desirable). So it's  
like the the transformer is working in the normal direction to store  
the correct value, then the reverse transformer is also getting called  
and updating the text cell.


So then I had need to use this transformer for a few NSTextFields on  
the same window as the table and here is the weirdness:


When I enter the text (say 1 1/2) and press return, the correct value  
is getting set in model BUT the field content is not getting updated  
like it does in the NSTableView. It will select the text, but it will  
not replace it with its cleaned up content which should be: 1-1/2


If I choose Undo (and also Redo), then the cleaned up text appears.  
Or if I close the window, and then re-open it, then the cleaned up  
text is correctly displayed (ditto for the document).


Does anyone have any idea why I am seeing this difference between the  
table columns and the text fields?


Is it normal for a transformer to do that nice clean up after return  
is hit that I am seeing in my table, or is that being caused by some  
lucky accident in my case?


Thank you
___

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

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

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

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


Re: Mac Mini or iMac for Cocoa Development?

2009-09-13 Thread Paul Bruneau
The iMac is so much prettier plus can drive a second display. Refurb  
store = $999 or even sometimes $849 ones show up.


On Sep 13, 2009, at 3:53 PM, Michael Rogers wrote:


Hi, All:

I've been given a short deadline for choosing between a Mac Mini or  
iMac for Cocoa development (especially iPhone apps) at a university  
that will remain nameless unless you read my signature :-)


I am leaning towards iMacs, because these computers will serve as  
ambassadors as well as development machines;  I want to double-check  
that if we have to go to Mac Minis, say with 4 GB of RAM, we won't  
be waiting forever to compile a simple program.

___

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

Please do not post admin requests or moderator comments to the list.
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


Model objects to NSUndoManager--am I doing it right?

2009-08-20 Thread Paul Bruneau

Hi all-

I'm just starting my first real document-based Cocoa app. My other app  
was non-document based and the undo system was quite different (plus I  
know I did some things wrong MVC-wise in that app).


The documentation I have read tells me that I should implement undo in  
the Setter methods of my model objects' properties. And I have done so  
for some of my objects (so far).


My question is, what is the best way to make all my model objects be  
able to find their document's undo manager?


Here is an early shot of part of my interface:

inline: pastedGraphic.png




To get the document to where these Entrances can see it, I had to  
subclass NSArrayController, add an IBOutlet for  
myWindowController (which in turn of course knows the document) and  
wire it to File's Owner in its NIB.


I have the New Entrance button bound to the add: method of my  
EntranceArrayController (which I overrode as below):


-(void)add:(id)sender;
{
SLEntrance * newSLEntrance = [[SLEntrance alloc] init];
newSLEntrance.myDocument = myWindowController.document; 
//I need to let this new entrance know its document

//now add this new entrance to the entrance array
[self addObject:newSLEntrance]; 

//generate invocation to tell the Undo system we have something to undo
	[[[myWindowController.document undoManager]  
prepareWithInvocationTarget:self] removeObject:newSLEntrance];
	[[myWindowController.document undoManager] setActionName:@create new  
Entrance];

}

In summary, it seemed like a Long Way to Go just to let my new  
Entrance objects know who their document is. In my future is the fact  
that Entrances will have FrameModules, which may contain a Door, which  
will contain an array of Cutouts and so I am looking at 3-4 more  
generations of Model object types, each of which must a similar way to  
get to the Document's Undo Manager.


Is this the right way?

Thank you___

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

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

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

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

Re: Advice on building a complex user custom control

2009-03-02 Thread Paul Bruneau

On Mar 1, 2009, at 8:22 PM, Oliver Charles wrote:


At the moment, I have a main MapView control, which creates vertices
in an NSArrayController. I have 2 ways of viewing these vertices - one
is to handle rendering them directly in the MapView, and another
approach creates a new VertexView for each vertex, and adds it as a
subview of the MapView. From what I've read online, this is not going
to scale beyond maybe 50 vertices, so I don't think this is an
approach. However, handling *everything* in the MapView itself feels
like it drastically reduces the cohesion of the control.


I'm not sure what you mean by this. What could be more cohesive than  
handling all your drawing and manipulation in MapView? Maybe cohesive  
wasn't the word you were looking for or maybe I am misunderstanding.


You can have your vertices contain their own drawing code (you will  
make them know how to draw themselves), but many will say that is a  
violation of MVC practices. But Erik Buck once told me a way that I  
really like: If you are worried about adding drawing code to a  
Model object, add the drawing code in a category of your model's  
class and maintain the category implementation in the View  
subsystem.


Then you can have things such as [aVertex draw] or [aVertex  
drawWithHighlight] etc, called from the drawRect: method of your view.

___

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

Please do not post admin requests or moderator comments to the list.
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: NSCaledarDate's deprecation

2009-01-24 Thread Paul Bruneau

Please excuse this possibly dumb question but here it is:

Why spend so much time and effort to remove some code that is going to  
keep running fine for years?


The class isn't even deprecated yet. It's in this weird going to be  
deprecated limbo. How many years does it take between when something  
is deprecated and when it actually breaks? (not a rhetorical question)

___

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

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

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

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


Re: Dealing with exceptions in a drawing stack

2009-01-19 Thread Paul Bruneau

On Jan 19, 2009, at 2:49 AM, Kyle Sluder wrote:


3) You've over-architected your drawing code.  Typically the fewer
objects that are responsible for drawing (i.e. view objects) the
better.  Situations like the one you're describing often arise from
making model objects responsible for their own drawing.


I was a little disappointed that Graham didn't address this point.

I'm confused by it, since I have been directed in the past by people  
who know that The Cocoa Way is to have objects know how to draw  
themselves--via a category if desired.


Is there differing opinion on this? (apparently there is...)

I am going to be starting a large app that will have many assemblies  
and sub-assemblies that I want to draw. I had planned on the objects  
drawing themselves. Should I revisit my thinking?

___

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

Please do not post admin requests or moderator comments to the list.
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: Dealing with exceptions in a drawing stack

2009-01-19 Thread Paul Bruneau

On Jan 19, 2009, at 2:08 PM, Quincey Morris wrote:

I don't get this at all (not just the quoted comments, but going all  
the way back to Graham's original statement).


-- If a failure in the drawing code destroys the *data model*  
(thereby preventing it from being saved) then there's something  
terribly wrong with the drawing code's design. (Surely, being  
*drawing* code it only needs read-only access to the data model. Or,  
if it has drawing-related status to update in the data model, it  
shouldn't be making structural alterations to the data model whose  
failure could leave the model in an un-savable state.)


In this case, the location of the drawing is irrelevant. Its design  
is dangerous to the data model no matter where it's implemented.


-- If a failure in the drawing code doesn't hurt the data model, but  
leads to an unending cascade of exceptions from the inconsistent  
drawing state, then the problem is more about suppressing exceptions  
so that the document can be saved before the application crashes.


I assumed that Graham meant that if his user is creating stuff, then  
during a draw the graphics get hosed to the point where the user can't  
save, he will lose the data that he as created in that session.


When I worked in graphics, this type of problem was all too common in  
Illustrator 5.0 I can assure you.

___

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

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

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

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


Re: create custom control same as multiple monitor control that manages monitors windows

2009-01-12 Thread Paul Bruneau

On Jan 12, 2009, at 12:19 AM, Gami Ravi wrote:


Hi All,

I want to create custom control that looks like a multiple monitor  
control that manages monitors on Mac. The custom control should  
allow the rectangle dragging and resizing same way we are moving  
monitor rectangle can be moved. If there are two rectangles then  
custom control should not allow overlapping of two rectangles?


What is the efficient way to design such control?

Any help would be appreciated.


The way I did a similar thing (and I think this is the standard way)  
was to create a custom NSView subclass to draw the control.


Keep track of the location and size of your monitor rectangles  
somewhere. Maybe you have an object for each monitor? Or maybe you  
just have instance variables in a controller class.


Override the -drawRect method of NSView to draw your rectangles, etc.

Override the -mouseDown method that NSView inherits from NSResponder  
to see if the user clicked on one of the rectangles.


Override the -mouseDragged method that NSView inherits from  
NSResponder to see where the user is dragging the rectangle. Only  
allow the user to drag it where it is possible to drag it (according  
to your rules)


Override the -mouseUp method to see where the user ended up leaving it.


This view programming guide should tell you everything you need to  
know about drawing and responding to user events in custom views:


http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaViewsGuide/Introduction/chapter_1_section_1.html

Good luck!
___

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

Please do not post admin requests or moderator comments to the list.
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: create custom control same as multiple monitor control that manages monitors windows

2009-01-12 Thread Paul Bruneau

On Jan 12, 2009, at 10:54 AM, I. Savant wrote:


On Mon, Jan 12, 2009 at 10:48 AM, Paul Bruneau
paul_brun...@special-lite.com wrote:

The way I did a similar thing (and I think this is the standard  
way) was to

create a custom NSView subclass to draw the control.


 Well ... the *standard* way is to use the control/cell system, but
the *easier* way is sometimes to simply use a custom NSView subclass
as you said. :-)

http://developer.apple.com/documentation/Cocoa/Conceptual/ControlCell/ControlCell.html

 NSControl gives you a lot of freebies that you'd have to implement
yourself (especially support for things such as accessibility
features, etc.) but at the cost of having to get your hands dirtier
with creating a custom cell. It's a bit more involved but usually more
appropriate if it's an interactive UI widget (ie, a control and not
simply a view).


You know, it's funny, when I first started my first Cocoa project as a  
total Cocoa newb I wanted to use controls/cells for my rectangles but  
I was strongly advised against it by very highly regarded Cocoa gurus.


Maybe it's because my project could have hundreds of rectangles in a  
single view and the gurus were concerned about all the overhead?

___

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

Please do not post admin requests or moderator comments to the list.
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


Date Formatter year input without year display

2008-12-10 Thread Paul Bruneau

Hi-

I ran into a problem with my production scheduling application as the  
new year approached.


In IB I am using a 10.0 date formatter bound to NSDate properties of a  
model object.


I used: %1m/%1d, %1I:%M%p

which gave me something like: 12/23, 12:30PM

This was used mostly for display, but the user is also able to type  
into the edit field in order to change the value.


As the new year came into play, he might have changed 12/23 to 1/5. My  
thinking was that if he entered just 1/5 it would assume the current  
year, which seems to be correct.


But I thought if he entered 1/5/2009, then Cocoa would help me out and  
do the right thing.


In fact, even when entering the year explicitly, the formatter still  
made the data be 1/5/2008.


I had to add the year to the formatter string to make it accept the  
year as input.


Is this expected? Is there a good way to only display the month and  
day, and yet allow the year to be entered if desired?


Thank you
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: a newbie question

2008-11-11 Thread Paul Bruneau

On Nov 11, 2008, at 3:16 PM, Etienne Guérard wrote:


Maybe it's an illustrative example, not a real one.
Anyway you'd better stick to NSObject.
Object is used to implement the metaclass class hierachy inside the  
ObjC runtime.

You normally don't play with it. ;)


It is a real example, but it is from the section that is teaching  
straight ObjC. Cocoa doesn't really get introduced into that book  
until chapter 14 Introduction to the Foundation Framework.


On page 313 he says In all the programs up to this point, you used  
the root object Object. The Foundation framework uses a different root  
object called NSObject. You'll get there soon.


So original poster, probably the Obj-C mailing list might be a better  
place to ask about Kochan examples until you get to chapter 14.


Good luck, it's a fine book. I was in your shoes 1.5 years ago. Read  
Hillegass next.___


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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Path handling routines

2008-10-29 Thread Paul Bruneau


On Oct 29, 2008, at 9:01 AM, Daniel Luis dos Santos wrote:


Hello,

Are there in the Foundation framework (or anywhere else on the Cocoa  
platform) path handling routines (directory extraction, path  
decomposition) ?


Cheers


There are a group of methods in NSString for working with paths.

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html

And scroll down to Working with Paths
___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: what do you use to make icons and similar?

2008-10-19 Thread Paul Bruneau

On Oct 19, 2008, at 12:09 PM, Ricky Sharp wrote:

I will disagree here.  It was so worth the effort to move all my  
bitmapped images to vector-based artwork.  I got beautiful scaling  
from 0.5 to 3.0x to include non-integral scaling factors.


In terms of the statement cannot vectorize a raster image... Adobe  
Illustrator can do such a task.


Illustrator has what used to be Streamline built into it, but it  
really is only good for stuff that should have been vector-based when  
it was created anyway. For instance, photographic bitmaps can't be  
vectorized in this way, or is there some magic new tool that I don't  
know about?

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Strategy for naming support folder

2008-10-11 Thread Paul Bruneau

On Oct 10, 2008, at 3:31 AM, Graham Cox [EMAIL PROTECTED] wrote:

Why is anyone poking around in there? (Not a rhetorical question,  
I'm interested in knowing what people do visit that folder for)


Since you ask, in my one-user, non-document-based scheduling app, I  
keep the data file in there plus the 100 most recent saved versions of  
same.


The user doesn't go in there ever, but I go in there sometimes in a  
support role if he needs something undone. If he were a more advanced  
or daring user he could very well be going in there.

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Cocoa Programming for Mac OsX Third Edition eBook search

2008-10-05 Thread Paul Bruneau

On Oct 5, 2008, at 5:51 AM, Howard Oakley wrote:


On 05/10/2008 02:25, David Orriss Jr wrote:


I ran into the same thing.  Probably one of my biggest complaints
about Addison is that the ebooks they do are digitally signed and  
that

the ONE platform Acrobat reader doesn't support for digitally signed
ebooks (aside from a beta reader if you dig around) is the Mac.
Rather ironic given the subject matter of the book.


Has anyone tried reading it with Adobe Digital Editions
http://www.adobe.com/products/digitaleditions/? Despite ill-informed
rumour saying that it is beta, it is actually now in version 1.6  
and works
perfectly well here for such DRMed titles, under Leopard, in Windows  
form

under VMware, and on a suitably authorised Sony Reader...


I used it not for Hillegass' book, but for the Angush, Buck, Yacktman  
Cocoa Programming book because I couldn't find a hard copy for less  
than $100. I was at first disappointed that it used Digital Editions,  
but over the 1200 or so pages of the book I grew pretty comfortable  
with it.


But the OP wanted to use it in an ebook. Does this format work in  
ebooks?

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Object change to NSView update

2008-08-25 Thread Paul Bruneau

On Aug 22, 2008, at 9:44 PM, Graham Cox wrote:

Keep all of the tree stuff in your data model. When you need to  
refresh any given item, flag that to your parent item, which flags  
that to its parent item and so on back to the root. The root object  
could have one or more controllers which in turn handle the  
connections to the views. (Or it could just broadcast  
notifications). The root can inform the controller something quite  
abstract such as item 234 needs update! and the controller can  
then pass that on to its view.


Thank you, I feel I am almost there. We are right at the edge of my  
ignorance.


I plan to re-read the KVO programming guide with the plan in mind to  
set up my controller as an observer to the currently-selected order  
(which is the one that is displayed in the custom view)


If the view handles layout it will know how to figure out where item  
234 is placed, and mark that area for update. When the view's - 
drawRect: method is called, it can discover the items that intersect  
the update region, then ask the controller to fetch them from the  
data model. The view then draws them however it pleases.


Yes, very good. In this case, the NSView subclass is so simple and  
only cares about the currently-selected order, so I just draw the  
entire rect upon update.


Ideally, the data model only concerns itself with business logic -  
i.e. the relationships between the various entities that you're  
modelling. The view(s) could be concerned with layout - so for  
example you might have a tree layout view, or a list view. The  
controller(s) sit in between and act as a go-between between the  
two, so that it can fetch relevant objects from the data model on  
behalf of the view, and receive notifications about changes to the  
data model and update the view. There's no hard and fast rule about  
where the exact dividing lines between the various bits of logic  
should go, but in your case I'm thinking that the views should  
handle layout which leaves the controllers as a fairly thin layer  
that just glues the views and data model together. Note that a  
NSTableView (view, performing layout) and its dataSource  
(controller, fetching data from the model to pass to the view) are a  
prime example of this.


Ken pointed you to the documentation on MVC - this is really key to  
getting this working elegantly. If you can expunge all code to do  
with drawing or positioning items from your Data Model, and turn it  
into a black box, you'll be well on the way to MVC nirvana ;-)


Thanks again to all

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Object change to NSView update

2008-08-22 Thread Paul Bruneau
I feel I can nearly grasp what I need to do, but not quite. I know  
what I shouldn't be doing--which is what I am doing and I feel I'm a  
little in the weeds. I seek a nudge in the right direction if someone  
can help.


I have a master-detail setup with a normal table displaying a list of  
orders. Below it is my subclass of NSView which draws a tree diagram  
of the selected order and its descendent order steps, each of which  
might have its own descendants. In fact, here it is:

http://special-lite.com/satellite/Picture%204.png

I am forcing the view to update after a change to one of the order  
step objects in what I am sure is The Wrong Way™ by basically chucking  
setNeedsDisplay into areas of my code such as the contextual menu  
handling code, etc. This works great for GUI-driven changes even  
though it's wrong, but it falls apart of course when changes occur due  
to Applescript.


What I think I understand that I need is that when an object belonging  
to the current selection of the table is modified, that a controller  
is notified and it tells the view to update. Or perhaps I can  
programmatically bind the view to the table's selection.


I think I could maybe (maybe!) figure out how do this for the order  
(the table's selection), but I am totally lost as to how I would do it  
for the order's great-grandchildren order steps.


If someone could give me a short breakdown of the idea of how to do  
it, I will happily go read hours of documentation and examples to  
learn the details.


Thank you___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Object change to NSView update

2008-08-22 Thread Paul Bruneau

On Aug 22, 2008, at 11:09 AM, Jonathan del Strother wrote:


How about having the object post an NSNotification whenever it's
changed?  Your controller can observe the notification  call
setNeedsDisplay accordingly.
If you're posting a lot of notifications at the same time, you might
look at coalescing them
(http://developer.apple.com/documentation/Cocoa/Conceptual/Notifications/Articles/NotificationQueues.html 
)


I like the suggestion. My concern would be that there would be a lot  
of extraneous notifications (but maybe it doesn't matter). The orders  
are in this table while they are being built but then once they are  
scheduled they join a few hundred friends where lots of edits to the  
order steps occur, but no longer does that concern the view that is  
the subject of this thread.


But I could always have the objects check to see if they are still in  
that order entry array and not send the notifications if they  
aren't. I'm sure that violates MVC or something but at this point I'm  
not sure I'm too concerned.


Thanks!
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Object change to NSView update

2008-08-22 Thread Paul Bruneau

On Aug 22, 2008, at 12:09 PM, Kyle Sluder wrote:


On Fri, Aug 22, 2008 at 10:58 AM, Paul Bruneau
[EMAIL PROTECTED] wrote:
I am forcing the view to update after a change to one of the order  
step

objects in what I am sure is The Wrong Way™ by basically chucking
setNeedsDisplay into areas of my code such as the contextual menu  
handling
code, etc. This works great for GUI-driven changes even though it's  
wrong,

but it falls apart of course when changes occur due to Applescript.


Are you saying that when some GUI event occurs (like clicking a
button), you are calling -setNeedsDisplay: on your custom view?


Pretty much, yes, I'm sorry to say. There are no buttons, but you have  
the idea. In that screenshot you see the contextual menu. I can set  
some things from there, and one of the items in the menu makes a sheet  
for some other choices. When the sheet is finished


Where's is your controller object?


It's in my nib! But which controller do you mean? I have an array  
controller for the array that holds these orders and it is the  
datasource of the table and is bound to the columns of the table.



All of your model changes should
be going through a controller, and this controller would know to
update the other views.


Yes I think we agree on that part! The problem I am trying to  
communicate is where do I learn to make my model changes go through a  
controller, and how do I teach this controller to know to update the  
other views? As I said, I think I could get my way through this if the  
properties were in the order objects, but they can be in the children  
of the children of the order objects.___


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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Object change to NSView update

2008-08-22 Thread Paul Bruneau

On Aug 22, 2008, at 11:19 AM, Graham Cox wrote:


On 23 Aug 2008, at 12:58 am, Paul Bruneau wrote:

I think I could maybe (maybe!) figure out how do this for the order  
(the table's selection), but I am totally lost as to how I would do  
it for the order's great-grandchildren order steps.



Data structure?

Does an order keep a list of its children? And those objects keep a  
list of their children and so on? Then just propagate needs  
display change to the children, then they'll do the same, and so  
on. Usually these will all be objects of the same class, or share  
some common subclass, or at least have certain methods in common.  
You have to arrange all of this.


snip code


Now assuming that these objects are all linked together correctly in  
a nice tree structure, sending -flagChanged to the root object will  
propagate that change down to every child and every child's child,  
and so on.


This is very conceptual, but may help - does it?

Note that this assumes that if you are modelling something that is  
structured as a tree or hierarchy in real life, you've implemented  
it as a tree or hierarchy in your code. Normally this is what you  
would do!


Thank you Graham. Yes, sorry I failed to say, but yes, the root  
order object has an NSArray of its nextSteps and each order step  
object also has an array of its nextSteps.


But I am not so much worried about propagating down to the children,  
for it is the children who are getting changed without the root  
object's knowledge.


However, I do also have a previousStep pointer in each order step  
that points back up to its parent that I could utilize.


But similar to the other suggestion, I would have to be doing this  
every time anything changed about any order step, then I would have to  
communicate from the parent (order) object to this view directly?  
Which makes bells go off in my head that the model isn't supposed to  
be sending stuff to the view?


But I do like your suggestion because it is a way that I might come up  
with, but I'm nervous that it isn't the Right Way.

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Separating elements in an NSView subclass

2008-08-08 Thread Paul Bruneau

Hi-

Some time ago I got some great advice to help me optimize the refresh  
rate of my NSView subclass (the answer is, just draw the minimum that  
you need to).


So I am working to do this, but I am having some trouble with the  
inter-dependence of various elements that appear in my view.


Here is the screenshot of it:
http://special-lite.com/satellite/Schedule.pdf

Currently, everything is a single NSView subclass that does too much  
(the docs refer to such a view as monolithic and I'm sure mine  
qualifies). I believe this is making it hard for me to draw the minimum.


The elements consist of:
- the order steps (all those colorful rectangles)
- the list of workcenters on the left
- the grid drawn behind the order steps (including the pink grid  
rectangles indicating off-line time)

- The timeline along the bottom
- lines that connect order steps to sibling order steps (you can see  
an example of this on the right side--when a particular order is  
selected, it is highlighted green with connecting lines)


I have started by creating a new view that has the workcenters, the  
timeline, and the grid, and a second view with just the order steps on  
it.


The problem that I think I have is that if the user moves an order  
step, it reveals some of the background view below it. This will  
then cause the background view to be redrawn, which, if I understand  
things, is going to force the order step view to be completely  
redrawn.


This would not help me any, since I am redrawing everything on every  
update now.


I think I have read enough about CALayer to think that it could help  
me with caching that it does, but I am writing for 10.4.


I'm hopeful that I am missing something, or thinking about this  
incorrectly and that someone can point me in the right direction. If  
you look in the lower left corner, you can see that with the increased  
number of orders we have during our busy season, I am down to an  
abysmal 1.2 fps.


Thank you all for you help, past and future.

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Separating elements in an NSView subclass

2008-08-08 Thread Paul Bruneau

On Aug 8, 2008, at 8:54 AM, Graham Cox wrote:

Are you checking the view's -needsToDrawRect: when you actually  
iterate through your rectangles? For a view like this it will be  
essential to avoid drawing anything that doesn't need drawing - even  
checking thousands of rects for intersection with the update area is  
much faster than actually drawing the same rects.


And the flip-side of that is, are you ensuring that when an  
individual rectangle is moved or its contents changed, you just  
invalidate that rectangle and not the whole view?


These two together should sort out your framerate problems - the  
screen shot is busy but it's not unreasonable - I wouldn't expect  
1.2 fps even with this many rects as long as you are doing the two  
key things above.


Dear Graham: Thank you for the reply. The way you worded the above  
kind of snapped me out of a thinking too much situation that I must  
have been in, because I scrapped my 2nd view idea and implemented the  
above and now I'm at 12 fps which is fantastic for my one user :)


Throwing a backing layer at the problem isn't going to magically fix  
it if there's a basic problem with drawing too much.


Ultimately it doesn't matter that everything is drawn in the same  
view. It might make sense to break it down just to keep the code  
sensible, but it won't automatically fix up drawing speed problems -  
after all, you're blitting into the same pixel buffer whoever draws  
them.


Thanks for this too. I was under the mistaken impression that I had to  
make this separation in order to move forward.


You mention a background view - is that really a separate view, or  
just a term you're using for your grid graphics?


In my original design, it was just a term, but I was starting to split  
it into its own view due to my misunderstanding of what I had to do.


Either way, if you decide to invalidate the whole view at any point  
you are going to stuff yourself. There's rarely a reason to ever  
invalidate a whole view (except for maybe the first time it's drawn,  
and that's handled by Cocoa, not you). The grid doesn't need to be  
repainted in its entirety for every change for example - again, just  
draw the little piece revealed by the update event. Doing that is  
actually less work for you to code than not doing it - when  
drawRect: is called it's already clipped to the update region, so  
just repaint the grid - pixels outside the clip region are not drawn  
so do not impose a drag on the drawing speed (cache the grid path  
also to avoid recalculating it every time). The key is never to call  
setNeedsDisplay:, but ALWAYS use setNeedsDisplayInRect:. Search your  
code for uses of -setNeedsDisplay: and change it.


Perfect. Even though I had read the view guide several times, I didn't  
have it solidified in my mind that when you use - 
setNeedsDisplayInRect: that Quartz (if that is the correct term here)  
clips any drawing that occurs outside of the collection of dirty  
rects. Now I can see it in action.


I am also testing each of my rects now to see if it is within the area  
needing drawing (I am using -needsToDrawRect:). All the rest of the  
elements I just go ahead and draw since they always drew very fast  
anyway.


Incidentally, this looks like an ideal project to use my own DrawKit  
framework for, if you'll permit me the shameless plug. I just tried  
drawing about 460 small rects with text in them similar to yours and  
on my lowly MacBook 1st gen I get no framerate problems moving them  
around. Dragging a semi-transparent selection rect over them is a  
little stuttery, but usable. I also have a full-view grid behind  
everything (much more complex than yours too) so it's doable. I'm  
not doing any CALayer backing (incidentally on 10.4 you have CGLayer  
which provides similar functionality though much more basic). If you  
want to look at DrawKit, you can d/l it here: http://apptree.net/drawkitmain.htm 
. Even if you don't want to use the framework you may find the code  
worth a look to see how I draw stuff quickly without any tricky stuff.


I have downloaded your framework and I am amazed at how much is in  
there and how neatly coded it looks! I think for this project it would  
take me too long to learn enough about your framework and to implement  
it into my (currently working) app. My user is going to be thrilled  
with 12fps and for that I am very thankful to you and the others who  
helped me before.

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: cocoa mentoring (was Re: Bypassing Interface Builder)

2008-05-15 Thread Paul Bruneau

On May 15, 2008, at 9:36 AM, Torsten Curdt wrote:

I have been thinking about BigNerdRanch. It would have been a great  
start   ...but I guess now I would be more interested in advanced  
topics.


Although Big Nerd Ranch's Cocoa Bootcamp is great for people just  
starting in Cocoa, it does have sections on Bindings, Core Data,  
Applescript-enabling your app, custom views, and other advanced  
topics. I can tell you that your head is chock full when you leave. In  
my experience, even though I had already read Kochan's Obj-C book and  
Aaron's book before I went to his Boot Camp, the camp very much set  
in place the ideas of Cocoa in my head in a way that I can't imagine  
a book doing. It was an amazing week.

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Getting line numbers from an NSString

2008-04-11 Thread Paul Bruneau

On Apr 11, 2008, at 1:23 PM, allan greenier wrote:

Greetings,

Have I missed this somewhere in the Cocoa - Foundation api?

If I have an NSString that is multi lined (say in contains \n  
characters)
is there an api call so I can get line 0, line 1, ect? Or should I  
just code that myself?


Hi there-

Yes you missed componentsSeparatedByString: in NSString I think.
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Garbage collection - was Beginner with Cocoa

2008-03-25 Thread Paul Bruneau

On Mar 25, 2008, at 6:01 PM, Jack Repenning wrote:


On Mar 25, 2008, at 2:06 PM, Scott Ribe wrote:
There's a *very* simple set of rules to follow regarding retain/ 
release.



Yes, but where are they documented?  Or, if they're so simple, can  
you quote them here?


Not to sound querulous, but what I know of these very simple rules I  
picked up from multiple conversations like this on, where the  
experts seem to say it's so simple three to five times for every  
one time they let leak one of these simple rules.  And I've never  
managed to locate these simple rules in any dox.  There's a good,  
multipage memory-management doc, but that's a bit more than a  
*very* simple set of rules.


My favorite summary is here:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/MemoryManagementRules.html

I re-found it by googling cocoa memory management rules

I learned them when I started programming Cocoa about 6 months ago and  
I am so comfortable with them now that I don't even feel the urge to  
learn the new GC stuff.

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: NSSpeechSynthesizer/UKSpeechSynthesizer speechSynthesizer:didFinishSpeaking: called immediarely

2008-03-13 Thread Paul Bruneau

On Mar 13, 2008, at 5:27 AM, Ben Lachman wrote:


According to the NSSpeechSynthesizer docs:

speechSynthesizer:didFinishSpeaking: is invoked when the speaking of  
the string ends. The second parameter of this method indicates  
whether the text was entirely spoken or was disrupted (as might  
happen if the user dismisses a spoken alert).


This make me think that I should get my delegate method called when  
the speech stops in the users perception.  However in my code I have  
it speak fairly long strings and the didFinishSpeaking: delegate  
method gets called back almost immediately.  Is this correct  
behavior?   I tried Uli's UKSpeechSynthesizer replacement for  
NSSpeechSynthesizer, but it seems to have the same issues.  If this  
is the correct behavior, is there a way to figure out when the  
speech is actually done form the user's perspective (ie the audio  
output actually stops)?   I'm trying to get a slide show type  
animation synced with speaking text and if I can't find out when the  
speech is done I'm not sure how I'm going to advance the animation  
at the correct time.


Thanks,

-Ben


Hi-

I don't see the behavior you are reporting. Aaron's book has a famous  
example that uses -didFinishSpeaking to disable a Stop button on an  
interface when the current speech completes, and it gets called  
exactly when the speech stops speaking.


You can download his code and try it:
http://bignerdranch.com/products/cocoa1.shtml

Look for the solutions to the exercises link. The example I looked at  
is in the 05_HelperObjects folder and is called SpeakLine_D



___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]


Re: Finding a relative date

2008-02-26 Thread Paul Bruneau
I am sympathetic to using NSCalendar. At his Boot Camp, Aaron told me  
that NSCalendarDate was falling out of favor because it's not a good  
player regarding calendars other than Gregorian. I understand this.


However, the documentation really doesn't provide any direction as to  
this for a new developer. You might want to file a bug to make the  
documentation push us new developers in the good direction.


Nowhere in the NSCalendarDate docs does it say don't use this or  
even try not to use this.


In the very first paragraph of the Dates and Times Programming Topics  
for Cocoa guide, it says:


A Gregorian date object, a special type of date object, is useful for  
representing dates users do see. It adds methods for converting dates  
to strings, converting strings to dates, and retrieving elements from  
dates (such as hours, minutes, and the day of the week). This is  
implemented by NSCalendarDate in Objective-C and by  
com.apple.cocoa.foundation.NSGregorianDate in Java.


( file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/DatesAndTimes/index.html 
#//apple_ref/doc/uid/1039i )


Not exactly a warning against its use.

I did find myself still using NSCalendarDate because I wanted its - 
dayOfYear method. I wasn't worried about localization because my  
application is used by exactly one user in the middle of a cornfield  
in SW Michigan. But if someone knows, what is the way to get this with  
NSCalendar? I found I could use NSCalendar to get all the other useful  
date pieces (such as -dayOfMonth, -dayOfWeek) I needed except this  
one. Hmm, I just thought of: computing the first day of the year and  
get the interval between the first day and the target day? I was  
blinded to that idea I think by the ease of -dayOfYear!


Maybe in addition to battling for localization with all of us, you  
have to battle with the internal folks too, I don't know. I wish you  
the best in your battles :)


On Feb 25, 2008, at 6:49 PM, Deborah Goldsmith wrote:

Please don't use NSCalendarDate, as it only supports the Gregorian  
calendar. Please use NSCalendar instead, unless you still need to  
run on 10.3.x.


Deborah Goldsmith
Apple Inc.
[EMAIL PROTECTED]

On Feb 25, 2008, at 11:39 AM, Nir Soffer wrote:



On Feb 25, 2008, at 21:27, Randall Meadows wrote:

Given a specific NSDate, I need to be able to find, say, the  
Sunday before that date, or the Saturday after that date.  I was  
hoping to be able to use +dateWithNaturalLanguage with something  
like Sunday before [myDate description], but that just returns  
myDate.


I know I can brute-force it, by figuring out the myDate's day,  
then walking backward and/or forward, but is there an easier way?   
One more tried and true, less error-prone, that's calendar-savvy  
(not that I'm going to need to go as far back as Oct 1582...)?


Check NSCalendarDate -dayOfWeek and - 
dateByAddingYears:months:days:hours:minutes:seconds:


Best Regards,

Nir Soffer

___

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

Please do not post admin requests or moderator comments to the list.
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 [EMAIL PROTECTED]