NSStatusBar

2011-04-04 Thread Dean Krueger
Hello,
I am developing a finder Menubar app, and am having one mysterious crash. I 
build the standard menu options when the app launches. Then in a 
NSOperationQueue I make a network connection and get some data to build out the 
dynamic data in the menu. If the user clicks on the menubar and displays the 
standard menu options the main thread will crash displaying this? 
HIStandardMenuView::GetItemWidth, if the menubar isn't clicked on, everything 
works great. Any idea's? 

Do I need to lock the StatusBar some how while updating the dynamic elements?

Thanks
Dean

___

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

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

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

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


Re: Book for expert programmer about cocoa and Objective-C

2011-04-04 Thread Saurabh Garg
Sorry if this is tangential to the topic at hand, but I was wondering if there 
are any recommendations for an 'expert' level reference for graphics 
programming on both AppKit and UIKit. So far I have tried Bill Dudney's and 
Marcus Zarra's Core Animation books, but feel that there's more to it than I am 
seeing in the books. I guess what I am looking for is one comprehensive 
reference that goes all the way from beginners to expert and addresses views, 
layers, core animation and OpenGL in one guide, explaining what approach is 
better in what circumstances. Does such a thing exist?

Thanks!
Saurabh

On Apr 1, 2011, at 9:40 PM, Rodrigo Zanatta Silva wrote:

> Hi. I need to have a good book in my side to program with Objective-C using
> the cocoa. I read the beginner books like "... for absolute beginner",
> "starting to program with...".
> 
> But now, I need a book for professional. Book that is BIG, DIFFICULT and is
> HARDCORE about anything for cocoa and objective-c. That show a really lot of
> thing. That will be my book for years.. You understand, right?
> 
> Anyone can give-me an idea?
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/ios%40gargs.com
> 
> This email sent to i...@gargs.com

___

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

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

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

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


Textfield in navigation controller not responding to user taps

2011-04-04 Thread Symadept
Hi,

I am having a strange problem in implementing UITextField as a part of
leftBarItem of NavigationController.

my leftBarItem customview, UIView has UIButton and UITextFields as subViews.


{
UIButton *theButton = [UIButton buttonWithType:UIButtonTypeCustom];
[theButton setImage:[UIImage imageNamed:@"button.png"]
forState:UIControlStateNormal];
[theButton setImageEdgeInsets:UIEdgeInsetsMake(0.0f, 6.0f, 0.0f,
0.0f)];

theButton.frame = CGRectMake(26+15.0f, 0.0f, 26.0f, 20.0f);

[theButton addTarget:self action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
theButton.tag = eOVSBItemButton;

}

CustomSearchBar *searchBar = [[CustomSearchBar alloc] init];
searchBar.tag = eOVSBSearchBar;
searchBar.delegate = self;
searchBar.frame = CGRectMake(26+15+26+15.0f, -5.0f, 134, 26.0f);
[leftButtonView addSubview:searchBar];
[searchBar release];

UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc]
initWithCustomView:leftButtonView];
rootNavController.navigationBar.topItem.leftBarButtonItem = leftBarButton;

Button responds properly but on Tap SearchBar wont gets activated. If I
implement the same searchbar in anyother view, on tap cursor starts
blinking. What am I missing here?

Regards
symadept
___

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

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

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

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


[MEET] Toronto Cocoaheads / tacow - April 12

2011-04-04 Thread Karl Moskowski
tacow's next quarterly meeting is scheduled for 6:30 PM on Tuesday, April 12, 
2011 in meeting room 304 of Metro Hall - click for agenda and location info. 
Note that this meeting marks tacow's 5th anniversary.

Additional details can be found at 
.

All are welcome, and we look forward to seeing you there.


Karl Moskowski 
Voodoo Ergonomics Inc. 



smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

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

Re: NSStatusBar

2011-04-04 Thread Nick Zitzmann

On Apr 2, 2011, at 8:04 AM, Dean Krueger wrote:

> Hello,
> I am developing a finder Menubar app, and am having one mysterious crash. I 
> build the standard menu options when the app launches. Then in a 
> NSOperationQueue I make a network connection and get some data to build out 
> the dynamic data in the menu. If the user clicks on the menubar and displays 
> the standard menu options the main thread will crash displaying this? 
> HIStandardMenuView::GetItemWidth, if the menubar isn't clicked on, everything 
> works great. Any idea's? 
> 
> Do I need to lock the StatusBar some how while updating the dynamic elements?

Are you sure you're doing all of your AppKit operations on the main thread 
using -performSelectorOnMainThread:...? With a few documented exceptions, 
AppKit classes aren't thread-safe.

Nick Zitzmann


___

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

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

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

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


Trying to subclass UISwitch

2011-04-04 Thread Philip Ershler
Hi,
After beating my head against the wall trying to subclass UISwitch, so 
that I might change the "text" for the two states, I finally noticed that there 
is a statement in the docs that UISwitch cannot be subclassed. (Please no wise 
cracks that I should have seen that straight away, I get to claim old eyes). So 
now I have come to realize that UISwitch is just a special case of UISlider.
I see that it is possible to set images for all the different parts of 
a UISlider. I'd like to make a UISlider look just like a UISwitch. Is there an 
easy way to get the UIImage specs so that I can build a UISlider that looks 
just like a UISwitch just with different ON and OFF "text". I'm sorry if this 
is a real naive question.

Thanks, Phil

Philip R. Ershler Ph.D.
University of Utah
Cardiovascular Research and Training Institute
95 South 2000 East
Salt Lake City, UT 84112-5000

phone: (801) 230-8771
alt ph: (801) 587-9528
fax: (801) 581-3128
e-mail: ersh...@cvrti.utah.edu


___

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

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

Help/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: Trying to subclass UISwitch

2011-04-04 Thread Roger Dalal
Phil:

Try http://osiris.laya.com/projects/rcswitch/ by Sascha Hoehne and Robert Chin. 
It is well done.

Roger Dalal
Assembled Apps




On Apr 4, 2011, at 12:20 PM, Philip Ershler wrote:

> Hi,
>   After beating my head against the wall trying to subclass UISwitch, so 
> that I might change the "text" for the two states, I finally noticed that 
> there is a statement in the docs that UISwitch cannot be subclassed. (Please 
> no wise cracks that I should have seen that straight away, I get to claim old 
> eyes). So now I have come to realize that UISwitch is just a special case of 
> UISlider.
>   I see that it is possible to set images for all the different parts of 
> a UISlider. I'd like to make a UISlider look just like a UISwitch. Is there 
> an easy way to get the UIImage specs so that I can build a UISlider that 
> looks just like a UISwitch just with different ON and OFF "text". I'm sorry 
> if this is a real naive question.
> 
> Thanks, Phil
> 
> Philip R. Ershler Ph.D.
> University of Utah
> Cardiovascular Research and Training Institute
> 95 South 2000 East
> Salt Lake City, UT 84112-5000
> 
> phone: (801) 230-8771
> alt ph: (801) 587-9528
> fax: (801) 581-3128
> e-mail: ersh...@cvrti.utah.edu
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/roger.dalal%40gmail.com
> 
> This email sent to roger.da...@gmail.com

___

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

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

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

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


Re: Trying to subclass UISwitch

2011-04-04 Thread Philip Ershler
Outstanding, thank you very much!

Phil

On Apr 4, 2011, at 10:28 AM, Roger Dalal wrote:

> Phil:
> 
> Try http://osiris.laya.com/projects/rcswitch/ by Sascha Hoehne and Robert 
> Chin. It is well done.
> 
> Roger Dalal
> Assembled Apps
> 
> 
> 
> 
> On Apr 4, 2011, at 12:20 PM, Philip Ershler wrote:
> 
>> Hi,
>>  After beating my head against the wall trying to subclass UISwitch, so 
>> that I might change the "text" for the two states, I finally noticed that 
>> there is a statement in the docs that UISwitch cannot be subclassed. (Please 
>> no wise cracks that I should have seen that straight away, I get to claim 
>> old eyes). So now I have come to realize that UISwitch is just a special 
>> case of UISlider.
>>  I see that it is possible to set images for all the different parts of 
>> a UISlider. I'd like to make a UISlider look just like a UISwitch. Is there 
>> an easy way to get the UIImage specs so that I can build a UISlider that 
>> looks just like a UISwitch just with different ON and OFF "text". I'm sorry 
>> if this is a real naive question.
>> 
>> Thanks, Phil
>> 
>> Philip R. Ershler Ph.D.
>> University of Utah
>> Cardiovascular Research and Training Institute
>> 95 South 2000 East
>> Salt Lake City, UT 84112-5000
>> 
>> phone: (801) 230-8771
>> alt ph: (801) 587-9528
>> fax: (801) 581-3128
>> e-mail: ersh...@cvrti.utah.edu
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>> 
>> Help/Unsubscribe/Update your Subscription:
>> http://lists.apple.com/mailman/options/cocoa-dev/roger.dalal%40gmail.com
>> 
>> This email sent to roger.da...@gmail.com
> 

Philip R. Ershler Ph.D.
University of Utah
Cardiovascular Research and Training Institute
95 South 2000 East
Salt Lake City, UT 84112-5000

phone: (801) 230-8771
alt ph: (801) 587-9528
fax: (801) 581-3128
e-mail: ersh...@cvrti.utah.edu


___

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

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

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

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


Odd NSCache Eviction Behaviour

2011-04-04 Thread Dalmazio Brisinda
Hi all,

I've been using an NSCache to store items that should be cached for performance 
reasons, since they are rather expensive to recreate. Understanding NSCache 
behaviour is giving me some headaches though.

I initialize my NSCache as follows:

_cellCache = [[NSCache alloc] init];
[_cellCache setDelegate:self];
[_cellCache setEvictsObjectsWithDiscardedContent:NO];   // never evict 
cells

The objects held in the cache implement the NSDiscardableContent protocol. Now 
my problem is the NSCache class does not seem to be working correctly in a 
couple of instances.


1) First the smaller issue. NSCache's setCountLimit: states that:

"Setting the count limit to a number less than or equal to 0 will have no 
effect on the maximum size of the cache."

Can someone shed some light on what does this means? I.e., that the NSCache is 
maximal, and will issue discardContentIfPossible messages only when memory is  
required elsewhere? Or that the NSCache is minimal, and it will issue 
discardContentIfPossible messages immediately? 

The former makes more sense, but testing seems to indicate that the later is 
what is happening. If I log calls to the discardContentIfPossible method in my 
cached object, I see that it is being called almost immediately -- after only a 
2-3 dozen items have been added to the cache (each less than 0.5 MB).

Okay. So I try then to set a large count limit -- way more than I will ever 
need -- by adding the following line:

[_cellCache setCountLimit:1000];

Then the discardContentIfPossible messages are no longer sent almost 
immediately. I have to load a lot more content into the cache and use it for a 
while before these message start occurring which makes more sense.

So what is the intended behaviour here?


2) The larger issue. The documentation states:

"By default, NSDiscardableContent objects in the cache are automatically 
removed from the cache if their content is discarded, although this automatic 
removal policy can be changed. If an NSDiscardableContent object is put into 
the cache, the cache calls discardContentIfPossible on it upon its removal."

So I set the eviction policy to NO (above) so objects are never evicted. 
Instead, when discardContentIfPossible is called, I clear and release the 
internal data of the cached object according to special criteria. That is, I 
may decide not to actually clear and discard the data under certain 
circumstances (for example if the item has been very recently used). In such a 
scenario, I simply return from the discardContentIfPossible method not having 
discarded anything. The idea is that some other object that isn't recently used 
will get the message at some point, and it can discard it's content instead.

Now, interestingly, all seems to work great for a while of heavy use. Loading 
lots of content, placing and accessing objects in the cache, etc. After some 
time though, when I try to access an arbitrary object in the NSCache it's 
literally not there! Somehow it appears it has been removed -- even though I 
specifically set the eviction policy to NO.

Okay. So implementing the delegate method cache:willEvictObject: shows it never 
gets called. Which means the object is not actually getting evicted. But it's 
mysteriously disappearing from the NSCache since it can't be found on future 
lookups -- or somehow the key it was associated with is is no longer mapped to 
the original object. But how can that happen?

BTW, the key object that I'm associating with my value objects (CALayer's) is 
an NSURL container/wrapper, since I can't use NSURL's directly as NSCache 
doesn't copy keys -- only retains them, and a later NSURL key used for lookup 
might not be the *exact* original object (only the same URL string) that was 
initially used to load the cache with that object. Whereas with an NSURL 
wrapper/container, I can ensure it is the exact original key object that was 
used to add the original value object to the NSCache.

Can anyone shed some light on this?

Best,
Dalmazio







smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

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

Re: Trying to subclass UISwitch

2011-04-04 Thread WT
On Apr 4, 2011, at 1:20 PM, Philip Ershler wrote:

> Hi,
>   After beating my head against the wall trying to subclass UISwitch, so 
> that I might change the "text" for the two states, I finally noticed that 
> there is a statement in the docs that UISwitch cannot be subclassed. (Please 
> no wise cracks that I should have seen that straight away, I get to claim old 
> eyes). So now I have come to realize that UISwitch is just a special case of 
> UISlider.
>   I see that it is possible to set images for all the different parts of 
> a UISlider. I'd like to make a UISlider look just like a UISwitch. Is there 
> an easy way to get the UIImage specs so that I can build a UISlider that 
> looks just like a UISwitch just with different ON and OFF "text". I'm sorry 
> if this is a real naive question.
> 
> Thanks, Phil

Hi Phil,

I filed a request to Apple's bug system precisely for this functionality some 2 
years ago, and got a reply back saying that it was a duplicate of bug ID# 
5792695. I'm still waiting, but I suppose Apple is going to get to it at some 
point and offer a customizable UISwitch.

Back then, my solution was to use a UISegmentedControl with two tabs but I see 
now that RCSwitch looks awesome and is probably a better alternative.

Regards,
WT___

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

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

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

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


textField - setIntegerValue

2011-04-04 Thread JAMES ROGERS
I am feeling really stupid. I have a simple textField set up in IB, nothing 
else, just a window with a textField.  I have connected the textField to the 
outlet.

In appdelegate,h
IBOutlet NSTextField *textField;

in appdelegate.m

[textField setIntegerValue:10]

Nothing is displayed in the textField. In another project, I have a textField 
and a stepper together, when I increment/decrement using the stepper connected 
to the textField, the steppers value is displayed (using "setIntegerValue"). 
  

JIM ROGERS
jimrogers_w4...@me.com
http://web.me.com/jimrogers_w4atk

___

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

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

Help/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: Odd NSCache Eviction Behaviour

2011-04-04 Thread Ken Thomases
On Apr 4, 2011, at 11:34 AM, Dalmazio Brisinda wrote:

> 2) The larger issue. The documentation states:
> 
> "By default, NSDiscardableContent objects in the cache are automatically 
> removed from the cache if their content is discarded, although this automatic 
> removal policy can be changed. If an NSDiscardableContent object is put into 
> the cache, the cache calls discardContentIfPossible on it upon its removal."
> 
> So I set the eviction policy to NO (above) so objects are never evicted.

I don't think that's what that means.  Setting it to YES (or leaving it at its 
default), means that the NSCache will more-or-less-immediately evict 
NSDiscardableContent objects whose contents are discarded, without regard for 
memory pressure (or count or cost).  Setting it to NO, does not mean that 
objects are not evicted.  It simply means that NSCache isn't "eager" about 
evicting NSDiscardableContent objects whose content have been discarded.  It 
will let them stick around until the normal eviction process is provoked.

Put another way, NSDiscardableContent and NSCache are independent.  They can be 
used separately from one another.  NSDiscardableContent objects merely support 
the notion of discarding their contents, whether or not they are in an NSCache. 
 (NSPurgeableData is one type of discardable object, and it coordinates with 
the OS to discard its contents under memory pressure.  For custom classes 
adopting NSDiscardableContent, you'd have to make your own arrangements for 
content to be discarded.)  NSCache will evict its content whether or not they 
are discardable.  However, NSCache is aware of NSDiscardableContent and will, 
as an optional optimization, eagerly evict discarded objects.

I don't know that there's a real good solution for something like NSCache but 
for which you can prevent it from evicting stuff.  I suppose, you can put stuff 
in it, but also keep it retained elsewhere.  Then, you can use the delegate 
method to learn when NSCache believes there's reason to evict things.  That 
will give you some visibility into the system's mechanism for tracking memory 
pressure.  However, that won't actually let you prevent the item from being 
evicted from the cache.  It just means the eviction will not lead to the 
deallocation of the item.  (An alternative approach would be to retain the 
object within the delegate method if you want to keep it.)

The problem is, once the item is evicted from the cache, you'd like to re-add 
it to make sure the cache has a true representation of what you're keeping 
around.  But if you re-add it immediately, that might cause NSCache to 
immediately re-evict it.  (Also, it's not legal to re-add it from the delegate 
callback.)


> Okay. So implementing the delegate method cache:willEvictObject: shows it 
> never gets called. Which means the object is not actually getting evicted.

Another explanation is that you may have a typo in your definition of that 
method, such that NSCache is not finding it via respondsToSelector:.  (Why that 
delegate protocol method is @optional is beyond me.  Had it been @required, 
such bugs would not be possible.)

It's also possible that was due to NSCache believing that the items were 
discarded.  Maybe for those, it feels free to evict without calling the 
delegate.  On the other hand, it may just be a bug.  You might look into 
libcache/cache.h, which is the low-level API for the same sort of 
functionality.  That might avoid any bug that NSCache might have in this 
respect.

Regards,
Ken

___

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

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

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

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


Programming Context Menu

2011-04-04 Thread Bing Li
Dear all,

I am now learning programming on Cocoa following the book, Cocoa Programming
Developers Handbook.

When programming Context Menus (Page 237), I got a problem. Although the
context menu can be shown, it is weird that all of the items in the context
menu are disabled. However, when running the sample provided by the book,
the items are enabled. I think I follow the book restrictedly. I could NOT
get the solution. The major code is as follows, which is completely from the
book. Could you please give me a hint?

Thanks so much!
LB

import "ContextMenuView.h"

static NSMenu *defaultMenu;

@implementation ContextMenuView
+ (NSMenu*)defaultMenu
{
if (nil == defaultMenu)
{
@synchronized(self)
{
if (nil == defaultMenu)
{
defaultMenu = [NSMenu new];
[defaultMenu addItemWithTitle: @"Copy"

action: @selector(copy:)

 keyEquivalent: @"c"];
[defaultMenu addItemWithTitle: @"Paste"

action: @selector(paste:)

 keyEquivalent: @"v"];
}
}
}
return defaultMenu;
}
static BOOL addItemsToMenuFromMenu(NSMenu *menu, NSMenu *template)
{
for (NSMenuItem *item in [template itemArray])
{
NSMenuItem *itemCopy = [item copy];
[menu addItem: itemCopy];
[itemCopy release];
}
return [menu numberOfItems] > 0;
}
- (NSMenu*)menuForEvent: (NSEvent*)theEvent
{
NSPoint click = [self convertPoint: [theEvent locationInWindow]
  fromView: nil];

NSMenuItem *locationMenuItem =
[[NSMenuItem alloc] initWithTitle: NSStringFromPoint(click)
   action: NULL
keyEquivalent: @""];
[locationMenuItem setEnabled: NO];
NSMenu *menu = [NSMenu new];
[menu addItem: locationMenuItem];
[locationMenuItem release];
[menu addItem: [NSMenuItem separatorItem]];
if (addItemsToMenuFromMenu(menu, [self menu]))
{
[menu addItem: [NSMenuItem separatorItem]];
}
addItemsToMenuFromMenu(menu, [[self class] defaultMenu]);
return [menu autorelease];
}
@end
___

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

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

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

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


Re: Trying to subclass UISwitch

2011-04-04 Thread Philip Ershler

On Apr 4, 2011, at 12:29 PM, WT wrote:

> On Apr 4, 2011, at 1:20 PM, Philip Ershler wrote:
> 
>> Hi,
>>  After beating my head against the wall trying to subclass UISwitch, so 
>> that I might change the "text" for the two states, I finally noticed that 
>> there is a statement in the docs that UISwitch cannot be subclassed. (Please 
>> no wise cracks that I should have seen that straight away, I get to claim 
>> old eyes). So now I have come to realize that UISwitch is just a special 
>> case of UISlider.
>>  I see that it is possible to set images for all the different parts of 
>> a UISlider. I'd like to make a UISlider look just like a UISwitch. Is there 
>> an easy way to get the UIImage specs so that I can build a UISlider that 
>> looks just like a UISwitch just with different ON and OFF "text". I'm sorry 
>> if this is a real naive question.
>> 
>> Thanks, Phil
> 
> Hi Phil,
> 
> I filed a request to Apple's bug system precisely for this functionality some 
> 2 years ago, and got a reply back saying that it was a duplicate of bug ID# 
> 5792695. I'm still waiting, but I suppose Apple is going to get to it at some 
> point and offer a customizable UISwitch.
> 
> Back then, my solution was to use a UISegmentedControl with two tabs but I 
> see now that RCSwitch looks awesome and is probably a better alternative.
> 
> Regards,
> WT


Yeah the link Roger Dalal pointed me to gets you the project to build any sort 
of Switch with any text and any colors you may wish. It also faults to a 
standard looking switch. It's great!

Phil

___

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

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

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

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


Re: textField - setIntegerValue

2011-04-04 Thread Fritz Anderson
On 4 Apr 2011, at 1:53 PM, JAMES ROGERS wrote:

> I have a simple textField set up in IB, nothing else, just a window with a 
> textField. I have connected the textField to the outlet.
> 
> In appdelegate,h
>   IBOutlet NSTextField *textField;
> 
> in appdelegate.m
> 
>   [textField setIntegerValue:10]
> 
> Nothing is displayed in the textField. In another project, I have a textField 
> and a stepper together, when I increment/decrement using the stepper 
> connected to the textField, the steppers value is displayed (using 
> "setIntegerValue"). 


Set a breakpoint in appdelegate.m, at the setIntegerValue: message, and see 
whether textField is set.

* Is outlet connected in the XIB?

* Are you making the setting before -awakeFromNib, which is the first moment at 
which you can be sure the NIB is loaded, and outlet is connected?

73 de WT9T,
— F

___

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

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

Help/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: textField - setIntegerValue

2011-04-04 Thread Carlos Eduardo Mello

On Apr 4, 2011, at 3:53 PM, JAMES ROGERS wrote:

I am feeling really stupid. I have a simple textField set up in IB,  
nothing else, just a window with a textField.  I have connected the  
textField to the outlet.


I am new to this but, (just in case...) have you, by any chance, named  
a function in your delegate as a setter for your outlet  
(setTextField:)? I fell into that trap a little while ago:  - 
awakeFromNib is called before the outlet is connected and it never  
gets wired to the nib.



In appdelegate,h
IBOutlet NSTextField *textField;

in appdelegate.m

[textField setIntegerValue:10]

Nothing is displayed in the textField. In another project, I have a  
textField and a stepper together, when I increment/decrement using  
the stepper connected to the textField, the steppers value is  
displayed (using "setIntegerValue").




___

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

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

Help/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: Trying to subclass UISwitch

2011-04-04 Thread Jeffrey Walton
On Mon, Apr 4, 2011 at 12:20 PM, Philip Ershler  wrote:
> Hi,
>        After beating my head against the wall trying to subclass UISwitch, so 
> that I might change the "text" for the two states, I finally noticed that 
> there is a statement in the docs that UISwitch cannot be subclassed. (Please 
> no wise cracks that I should have seen that straight away, I get to claim old 
> eyes).
Prohibiting subclassing is *not* mentioned here:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UISwitch_Class/Reference/Reference.html

Jeff
___

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

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

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

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


Re: Trying to subclass UISwitch

2011-04-04 Thread Luke the Hiesterman
"The UISwitch class is not customizable."

And what he really wanted to do was customize the appearance.

Luke

On Apr 4, 2011, at 3:02 PM, Jeffrey Walton wrote:

> On Mon, Apr 4, 2011 at 12:20 PM, Philip Ershler  
> wrote:
>> Hi,
>>After beating my head against the wall trying to subclass UISwitch, 
>> so that I might change the "text" for the two states, I finally noticed that 
>> there is a statement in the docs that UISwitch cannot be subclassed. (Please 
>> no wise cracks that I should have seen that straight away, I get to claim 
>> old eyes).
> Prohibiting subclassing is *not* mentioned here:
> http://developer.apple.com/library/ios/#documentation/uikit/reference/UISwitch_Class/Reference/Reference.html
> 
> Jeff
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com
> 
> This email sent to luket...@apple.com

___

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

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

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

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


Re: textField - setIntegerValue

2011-04-04 Thread Kyle Sluder
On Mon, Apr 4, 2011 at 2:26 PM, Carlos Eduardo Mello
 wrote:
> I am new to this but, (just in case...) have you, by any chance, named a
> function in your delegate as a setter for your outlet (setTextField:)? I
> fell into that trap a little while ago:  -awakeFromNib is called before the
> outlet is connected and it never gets wired to the nib.

o_O -awakeFromNib is called after all the outlets are hooked up.
That's its entire purpose.

--Kyle Sluder
___

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

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

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

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


Re: applicationWillTerminate not received

2011-04-04 Thread Jeffrey Walton
On Sat, Apr 2, 2011 at 9:53 PM, Quincey Morris
 wrote:
> On Apr 2, 2011, at 18:01, Jeffrey Walton wrote:
>
>> I planned on saving some state when the applicationWillTerminate was
>> invoked. Are things working as expected? Should I abandon my plans to
>> save state during termination?
>
> No, you should save the state, but it's explained here:
>
>        
> http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/CoreApplication/CoreApplication.html
>
> (search for all occurrences of "applicationWillTerminate", since the 
> information you need is spread out) that you don't get the notification in 
> the circumstances you describe.
>
> I think you'll need to force a low-memory termination to test the code path 
> through 'applicationWillTerminate:'. I couldn't see an easier way to make it 
> happen with an iOS 4.0 backgroundable multitasking-aware app.
>
Thanks Quincey. I do see where iOS will terminate the application
(SIGKILL) rather than calling applicationWillTerminate (the two
paragraphs under "Responding to Application Termination" coupled with
foreground/background/suspend state).

It sure would be nice if we could count on applicationWillTerminate
all the time. A SIGKILL without applicationWillTerminate seems kind of
rude :(

Jeff
___

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

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

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

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


Re: Trying to subclass UISwitch

2011-04-04 Thread Laurent Daudelin
I think there is a difference between "customizable" and "not subclassable". 
The question I guess would be: did he try to subclass?

-Laurent.
-- 
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin 
http://www.nemesys-soft.com/
Logiciels Nemesys Software  
laur...@nemesys-soft.com

On Apr 4, 2011, at 15:04, Luke the Hiesterman wrote:

> "The UISwitch class is not customizable."
> 
> And what he really wanted to do was customize the appearance.
> 
> Luke
> 
> On Apr 4, 2011, at 3:02 PM, Jeffrey Walton wrote:
> 
>> On Mon, Apr 4, 2011 at 12:20 PM, Philip Ershler  
>> wrote:
>>> Hi,
>>>   After beating my head against the wall trying to subclass UISwitch, 
>>> so that I might change the "text" for the two states, I finally noticed 
>>> that there is a statement in the docs that UISwitch cannot be subclassed. 
>>> (Please no wise cracks that I should have seen that straight away, I get to 
>>> claim old eyes).
>> Prohibiting subclassing is *not* mentioned here:
>> http://developer.apple.com/library/ios/#documentation/uikit/reference/UISwitch_Class/Reference/Reference.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: textField - setIntegerValue

2011-04-04 Thread Graham Cox

On 05/04/2011, at 7:26 AM, Carlos Eduardo Mello wrote:

> I am new to this but, (just in case...) have you, by any chance, named a 
> function in your delegate as a setter for your outlet (setTextField:)? I fell 
> into that trap a little while ago:  -awakeFromNib is called before the outlet 
> is connected and it never gets wired to the nib.

That's not what was happening, but you may be on to something.

If you name an outlet 'textField', then the nib loading machinery will look for 
a method called -setTextField: in order to wire the outlet. That's probably 
going to fail in quite a few cases because the name is far too generic and it's 
not unlikely that a method called -setTextField: exists that has nothing to do 
with said outlet. The wiring up will fail if that method does not in fact 
simply assign the outlet.

It's a really good idea to name your outlets in some fashion that indicates 
both their type and their function. If nothing else it makes identifying them 
in IB easier, for example, a good name might be  'mCountOfWidgetsTextField'.

This name tells you a) that it's a data member of the class - 'm' for member, 
b) that it represents 'countOfWidgets' and c) that it is expected to be a text 
field. It also means that accidentally misleading the nib loader is far less 
likely.

It's certainly worth trying a better, less generic name and see if that fixes 
your issue.


--Graham


___

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

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

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

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


Re: textField - setIntegerValue

2011-04-04 Thread Carlos Eduardo Mello


On Apr 4, 2011, at 7:09 PM, Kyle Sluder wrote:


On Mon, Apr 4, 2011 at 2:26 PM, Carlos Eduardo Mello
 wrote:
I am new to this but, (just in case...) have you, by any chance,  
named a
function in your delegate as a setter for your outlet  
(setTextField:)? I
fell into that trap a little while ago:  -awakeFromNib is called  
before the

outlet is connected and it never gets wired to the nib.


o_O -awakeFromNib is called after all the outlets are hooked up.
That's its entire purpose.


Sorry, I meant  'windowControllerDidLoadNib', but that obviously only  
makes sense in a document based app, which is where I saw it.


Still, if you look at this little test app (public link to Google  
Docs), you'll see what I mean. There is an AppController class, (which  
was made the window's delegate) with an outlet connected to a text  
field and a button in the window. The button calls an Action called  
'setTextField', but the 'textField' outlet is never available when the  
button is clicked. The outlet wasn't wired, even though it is  
correctly connected in IB. Now if you change the button's action name  
to fillTextField (or anything other than setTextField), everything  
works ok -- the field is there waiting to be accessed.


https://docs.google.com/leaf?id=0B5t9N8FvFoJIOTk3NTY4ODItYzg4NS00ZmFmLWE3MzYtZjllYmIwY2ZiY2Q4&hl=en&authkey=CIzbnLIG

So I really learned that lesson: never give an accessor name to  
anything that is not meant to be an accessor.

___

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

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

Help/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: textField - setIntegerValue

2011-04-04 Thread Graham Cox

On 05/04/2011, at 10:48 AM, Carlos Eduardo Mello wrote:

> Still, if you look at this little test app (public link to Google Docs), 
> you'll see what I mean. There is an AppController class, (which was made the 
> window's delegate) with an outlet connected to a text field and a button in 
> the window. The button calls an Action called 'setTextField', but the 
> 'textField' outlet is never available when the button is clicked. The outlet 
> wasn't wired, even though it is correctly connected in IB. Now if you change 
> the button's action name to fillTextField (or anything other than 
> setTextField), everything works ok -- the field is there waiting to be 
> accessed.


On a general note, you need to know who you're writing code for. A compiler is 
happy with all sorts of stupidly named stuff (notwithstanding the possibility 
of confusion caused by naming conventions that have a semantic meaning beyond 
their face value, as here). But humans are not compilers. You need to write 
code for humans.

So what's wrong with naming an action 'blahblahblahAction'? It TELLS you it's 
an action. The compiler doesn't need that extra hint, but you'll be glad of it 
in all sorts of situations, especially years from now when you long since 
forgot what you were thinking when you wrote it.

If you write a method set, it had jolly well better be a setter, and 
NOT an action. (This is one of those naming conventions that goes beyond face 
value anyway).

I've recently done quite a bit of code porting and it's astonishing how little 
effort people put into making code self-documenting, even when the code is 
open-source and therefore intended to be seen by others, and even when there is 
no conventional documentation (which appears to be the norm, and something I'm 
very bad at myself). Making code self-documenting by a better choice of 
variable and parameter names, with a sprinkling of consistent conventions, is 
very little effort up front, and saves literally hours and hours of work later 
on.


--Graham

___

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

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

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

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


Re: Trying to subclass UISwitch

2011-04-04 Thread Philip Ershler
The first thing I tried to do was to subclass the UISwitch. But when one looks 
at the docs for the UISwitch there are no Properties or Instance Methods that 
one can override to change the "text" on the switch. And when one looks at the 
origins of the UISwitch, there is nothing to be overridden to change the text 
(or actually the images that contain text) either.

Inherits from   
UIControl : UIView : UIResponder : NSObject
Conforms to 
NSCoding
NSCoding (UIView)
NSObject (NSObject)
So when I hit The UISwitch class is not customizable. I threw in the towel.

Phil

On Apr 4, 2011, at 6:20 PM, Laurent Daudelin wrote:

> I think there is a difference between "customizable" and "not subclassable". 
> The question I guess would be: did he try to subclass?
> 
> -Laurent.
> -- 
> Laurent Daudelin
> AIM/iChat/Skype:LaurentDaudelin   
> http://www.nemesys-soft.com/
> Logiciels Nemesys Software
> laur...@nemesys-soft.com
> 
> On Apr 4, 2011, at 15:04, Luke the Hiesterman wrote:
> 
>> "The UISwitch class is not customizable."
>> 
>> And what he really wanted to do was customize the appearance.
>> 
>> Luke
>> 
>> On Apr 4, 2011, at 3:02 PM, Jeffrey Walton wrote:
>> 
>>> On Mon, Apr 4, 2011 at 12:20 PM, Philip Ershler  
>>> wrote:
 Hi,
  After beating my head against the wall trying to subclass UISwitch, 
 so that I might change the "text" for the two states, I finally noticed 
 that there is a statement in the docs that UISwitch cannot be subclassed. 
 (Please no wise cracks that I should have seen that straight away, I get 
 to claim old eyes).
>>> Prohibiting subclassing is *not* mentioned here:
>>> http://developer.apple.com/library/ios/#documentation/uikit/reference/UISwitch_Class/Reference/Reference.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/ershler%40cvrti.utah.edu
> 
> This email sent to ersh...@cvrti.utah.edu

Philip R. Ershler Ph.D.
University of Utah
Cardiovascular Research and Training Institute
95 South 2000 East
Salt Lake City, UT 84112-5000

phone: (801) 230-8771
alt ph: (801) 587-9528
fax: (801) 581-3128
e-mail: ersh...@cvrti.utah.edu


___

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

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

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

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


NSString, stringByAppendingPathComponent, and Canonicalization

2011-04-04 Thread Jeffrey Walton
Hi All,

I need to accept a filename from the user. Given the user supplied
filename, I form a fully qualified name:

NSString* pathName = [NSHomeDirectory(),
stringByAppendingPathComponent:@"Documents"];
NSString* fullPathName = [pathName  stringByAppendingPathComponent:filename];

How do I canonicalize the the resulting fullPathName to verify there
was no directory traversal goodness in the filename? In case its
relevant, the platform is iOS.

Jeff
___

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

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

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

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


Re: NSString, stringByAppendingPathComponent, and Canonicalization

2011-04-04 Thread Stephen J. Butler
On Mon, Apr 4, 2011 at 10:08 PM, Jeffrey Walton  wrote:
> I need to accept a filename from the user. Given the user supplied
> filename, I form a fully qualified name:
>
> NSString* pathName = [NSHomeDirectory(),
> stringByAppendingPathComponent:@"Documents"];
> NSString* fullPathName = [pathName  stringByAppendingPathComponent:filename];

First, you should be getting the path to the documents folder via
NSSearchPathForDirectoriesInDomains():



> How do I canonicalize the the resulting fullPathName to verify there
> was no directory traversal goodness in the filename? In case its
> relevant, the platform is iOS.

I can't remember if there's a Cocoa version, but the standard Unix way
to do this is realpath (man realpath). Make sure to use -[NSString
fileSystemRepresentation] to get the char* version.

But I'm not sure directory traversals are a huge concern in iOS.
Everything is so sandboxed anyway...
___

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

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

Help/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: NSString, stringByAppendingPathComponent, and Canonicalization

2011-04-04 Thread Ken Thomases
On Apr 4, 2011, at 10:08 PM, Jeffrey Walton wrote:

> I need to accept a filename from the user. Given the user supplied
> filename, I form a fully qualified name:
> 
> NSString* pathName = [NSHomeDirectory(),
> stringByAppendingPathComponent:@"Documents"];
> NSString* fullPathName = [pathName  stringByAppendingPathComponent:filename];
> 
> How do I canonicalize the the resulting fullPathName to verify there
> was no directory traversal goodness in the filename?

NSString* fullPathName = [pathName  stringByAppendingPathComponent:[filename 
lastPathComponent]];

Cheers,
Ken

___

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

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

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

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


Re: Programming Context Menu

2011-04-04 Thread Bing Li
Dear Volker,

I noticed that no IBAction/IBOutlet is available for the items in the code.
Should I make some connections for them?

I just connect the context menu with the class of ContextMenuView and
connect the NSView in the Window with ContextMenuView.

Thanks,
LB


On Tue, Apr 5, 2011 at 4:06 AM, Volker in Lists wrote:

> Hi,
>
> have you connected the menu items in interface builder with their commands?
> Then they will get active, if the responder is also available.
>
> volker
> Am 04.04.2011 um 21:38 schrieb Bing Li:
>
> > Dear all,
> >
> > I am now learning programming on Cocoa following the book, Cocoa
> Programming
> > Developers Handbook.
> >
> > When programming Context Menus (Page 237), I got a problem. Although the
> > context menu can be shown, it is weird that all of the items in the
> context
> > menu are disabled. However, when running the sample provided by the book,
> > the items are enabled. I think I follow the book restrictedly. I could
> NOT
> > get the solution. The major code is as follows, which is completely from
> the
> > book. Could you please give me a hint?
> >
> > Thanks so much!
> > LB
> >
> > import "ContextMenuView.h"
> >
> > static NSMenu *defaultMenu;
> >
> > @implementation ContextMenuView
> > + (NSMenu*)defaultMenu
> > {
> >if (nil == defaultMenu)
> >{
> >@synchronized(self)
> >{
> >if (nil == defaultMenu)
> >{
> >defaultMenu = [NSMenu new];
> >[defaultMenu addItemWithTitle: @"Copy"
> >
> > action: @selector(copy:)
> >
> > keyEquivalent: @"c"];
> >[defaultMenu addItemWithTitle: @"Paste"
> >
> > action: @selector(paste:)
> >
> > keyEquivalent: @"v"];
> >}
> >}
> >}
> >return defaultMenu;
> > }
> > static BOOL addItemsToMenuFromMenu(NSMenu *menu, NSMenu *template)
> > {
> >for (NSMenuItem *item in [template itemArray])
> >{
> >NSMenuItem *itemCopy = [item copy];
> >[menu addItem: itemCopy];
> >[itemCopy release];
> >}
> >return [menu numberOfItems] > 0;
> > }
> > - (NSMenu*)menuForEvent: (NSEvent*)theEvent
> > {
> >NSPoint click = [self convertPoint: [theEvent locationInWindow]
> >  fromView: nil];
> >
> >NSMenuItem *locationMenuItem =
> >[[NSMenuItem alloc] initWithTitle: NSStringFromPoint(click)
> >   action: NULL
> >keyEquivalent: @""];
> >[locationMenuItem setEnabled: NO];
> >NSMenu *menu = [NSMenu new];
> >[menu addItem: locationMenuItem];
> >[locationMenuItem release];
> >[menu addItem: [NSMenuItem separatorItem]];
> >if (addItemsToMenuFromMenu(menu, [self menu]))
> >{
> >[menu addItem: [NSMenuItem separatorItem]];
> >}
> >addItemsToMenuFromMenu(menu, [[self class] defaultMenu]);
> >return [menu autorelease];
> > }
> > @end
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post admin requests or moderator comments to the list.
> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> >
> > Help/Unsubscribe/Update your Subscription:
> >
> http://lists.apple.com/mailman/options/cocoa-dev/volker_lists%40ecoobs.de
> >
> > This email sent to volker_li...@ecoobs.de
>
>
___

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

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

Help/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 a 'usro' resource

2011-04-04 Thread Gerriet M. Denkmann

On 4 Apr 2011, at 23:38, "Gerriet M. Denkmann"  wrote:

> I want to make certain files to be opended by default by my own editor.
> These files might contain all sort of file extentions.
> In Finder.app I could do: File â∫‚ Always open with..., but I want to do this 
> programmatically.
> 
> I guess I have to add a 'usro' Resource (see:  
> ).
> 
> But I have great difficulties finding and understanding the relevant 
> documentation.
> 
> Also: I cannot find the 'usro' string in any header file (and Xcode does not 
> give any information either).
> 
> So, does anybody has some code snippets to share which can read, modify, 
> write a 'usro' resource?
> 

The code below seems to work - but looks like a really bad hack. (All error 
handling removed for brevity).
Maybe someone has a better solution?


+ (NSString *)openerForFsRef: (FSRef *)fsRef; 
{
NSString *opener = nil;
SInt16 file = FSOpenResFile( fsRef, fsRdPerm );

//  The total number of unique resource types in the current 
resource file.
ResourceCount typesCount = Count1Types(); 

for( short typeIndex = 1; typeIndex <= typesCount; typeIndex++ )
//  iterate over all types
{
ResType theType;
Get1IndType( &theType, typeIndex );

//  The total number of resources of a given type in the 
current resource file.
ResourceCount rsrcCount = Count1Resources( theType );   

for( int rsrcIndex = 1; rsrcIndex <= rsrcCount; rsrcIndex++ )   
//  iterate over resources for current type
{
Handle rsrcHandle = Get1IndResource( theType, rsrcIndex 
);  

if ( theType == NSHFSTypeCodeFromFileType( @"'usro'" ) )
{
//  this probably is a bad hack - what if 
there are more than 255 chars in the opener string?
const unsigned char *bytes = *rsrcHandle;
NSUInteger lenn = bytes[0] - 1;
NSData *daa = [ NSData dataWithBytes: &bytes[4] 
length: lenn ];
opener  = [ [ NSString alloc ] initWithData: 
daa encoding: NSUTF8StringEncoding ];
[ opener autorelease ];
};  
};
};

CloseResFile( file );

return opener;
}

___

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

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

Help/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: Programming Context Menu

2011-04-04 Thread Chris Hanson
On Apr 4, 2011, at 12:38 PM, Bing Li  wrote:

>if (nil == defaultMenu)
>{
>@synchronized(self)
>{
>if (nil == defaultMenu)

Don't do this. I don't mean just in Cocoa either, I mean don't do it ever. It's 
an anti-pattern called "double-checked locking" and it's fatally broken under 
most languages' memory models.

If you want to initialize a value once-and-only-once, use dispatch_once or (if 
you need to support an OS version without GCD) use pthread_once.

  -- Chris

___

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

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

Help/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: Programming Context Menu

2011-04-04 Thread Stephen J. Butler
On Tue, Apr 5, 2011 at 12:10 AM, Chris Hanson  wrote:
> On Apr 4, 2011, at 12:38 PM, Bing Li  wrote:
>
>>        if (nil == defaultMenu)
>>        {
>>                @synchronized(self)
>>                {
>>                        if (nil == defaultMenu)
>
> Don't do this. I don't mean just in Cocoa either, I mean don't do it ever. 
> It's an anti-pattern called "double-checked locking" and it's fatally broken 
> under most languages' memory models.
>
> If you want to initialize a value once-and-only-once, use dispatch_once or 
> (if you need to support an OS version without GCD) use pthread_once.

It's also worth pointing out that NSMenu is not thread safe, and
should never be accessed off the main thread. So the locking is
pointless anyway!
___

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

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

Help/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: Programming Context Menu

2011-04-04 Thread Eli Bach

On Apr 4, 2011, at 1:38 PM, Bing Li wrote:

> - (NSMenu*)menuForEvent: (NSEvent*)theEvent
> {
>NSPoint click = [self convertPoint: [theEvent locationInWindow]
>  fromView: nil];
> 
>NSMenuItem *locationMenuItem =
>[[NSMenuItem alloc] initWithTitle: NSStringFromPoint(click)
>   action: NULL
>keyEquivalent: @""];

It COULD be this line (as setEnabled:NO ) should disable the menu item.  You 
could try changing it to YES.

>[locationMenuItem setEnabled: NO];
>NSMenu *menu = [NSMenu new];
>[menu addItem: locationMenuItem];
>[locationMenuItem release];
>[menu addItem: [NSMenuItem separatorItem]];
>if (addItemsToMenuFromMenu(menu, [self menu]))
>{
>[menu addItem: [NSMenuItem separatorItem]];
>}
>addItemsToMenuFromMenu(menu, [[self class] defaultMenu]);
>return [menu autorelease];
> }

It COULD also be that the menu items are supposed to be auto-enabled by the 
responder chain [which according to 

 is different for contextual menus than it is for the menu bar.
I don't know if your example code uses it, but it probably does since by 
default NSMenu setAutoenablesItems defaults to YES.

Eli

___

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

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

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

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


Re: Programming Context Menu

2011-04-04 Thread Graham Cox

On 05/04/2011, at 1:37 PM, Bing Li wrote:

> I noticed that no IBAction/IBOutlet is available for the items in the code.
> Should I make some connections for them?

Yes, but the outlets aren't visible to code because 'IBOutlet' is an IB thing.

You need to call -setTarget: on the menu items with the view that is the target 
for the command. If you don't the target by default is nil i.e. 'First 
Responder'. That is usually not what you want for contextual menus which should 
be operable without becoming first responder.

You still may find that the items aren't enabled, depending on whether 
-validateMenuItem: or -validateUserInterfaceItem: is implemented and if so, 
whether it takes steps to enable the items.

There's plenty of info about this in the relevant docs.

--Graham


___

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

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

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

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


Passing an object to a custom sheet

2011-04-04 Thread Torsten Geise
I successfully created a dialog by following the custom sheet examples. But I 
still have trouble passing arguments to the dialog. I'll explain my problem 
based on a simple test app:

- Main.xib contains a window and a button "show dialog". 
- AppDelegate has an IBAction for the "show dialog button".
- Dialog.xib contains a window which has a NSTextField "message" and an OK 
button.
- DialogController is of type NSObject and acts a the File's Owner of 
Dialog.xib.
- DialogController contains an outlet for the NSTextfield and an IBAction for 
the OK button. In addition, it has a function that brings up the dialog.
- AppDelegate has a property of type DialogController.

The DialogController interface is defined as follows:

@interface DialogController : NSObject {
@private

NSTextField *messageTextfield;
NSButton *okButton;
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSButton *okButton;
@property (assign) IBOutlet NSTextField *messageTextfield;

- (IBAction)onOkButtonPressed:(id)sender;

-(void)showDialog:(NSWindow*)parent;

@end


When one clicks the "show dialog" button, the 
DialogController:showDialogInParent is called, which looks as follows:

-(void)showDialog:(NSWindow*)parent {

if (!window) {
[NSBundle loadNibNamed:@"Dialog" owner:self];
}

[NSApp beginSheet:window
   modalForWindow:parent
modalDelegate:self 
   didEndSelector:@selector(didEndSheet:returnCode:contextInfo:) 
  contextInfo:nil];
}

When OK button of the Dialog is clicked, the following function is called:

- (IBAction)onOkButtonPressed:(id)sender {
[NSApp endSheet:window returnCode:NSOKButton];
}

This finally calls the didEndSheet function earlier defined in the 
NSApp:beginSheet function:

- (void)didEndSheet:(NSWindow *)aSheet returnCode:(NSInteger)returnCode 
contextInfo:(void *)contextInfo
{
[aSheet orderOut:self];
}

This all works fine. The dialog shows up attached to the parent window, and 
once the OK button is clicked, it disappears. 

So far, so good. My problem starts with passing objects to the dialog or 
passing the content of the NSTextfield back to the caller. In the showDialog 
function, I already have an instance to DialogController (instance 1). When the 
NIB file gets loaded, it creates a second instance of DialogController 
(instance 2) but containing the same instance of "window". 

When I want to use an Object in the "onOkButtonPressed" function, how can I set 
this object in instance #2? [NSBundle loadNibNamed:@"Dialog" owner:self] does 
not return a pointer to the instance. In opposite, when "didEndSheet" is 
called, I'm back in instance#1 without any knowledge about the value of 
NSTextfield of instance#2.

As I'm trying to get this running for many hours and couldn't find any hints 
neither in the net nor in Apple's documentation, I'm asking myself whether this 
is the correct approach at all? 

Simple said, I want to have a dialog similar to FileOpenDialog, which returns 
some values selected in the dialog to the caller, like this:

NSOpenPanel* openPanel = [NSOpenPanel openPanel];
...set some properties of the panel...
if ([openPanel runModal] == NSFileHandlingPanelOKButton) {
NSArray* selectedFiles = [openPanel filenames];
...
}

Thanks,
Torsten
___

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

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

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

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