FROM : Guy Meyer
DATE : Tue Oct 08 18:03:33 2002
Hi
Application/Dock communication is done through a dictionary passed
between the two.
There are some NSApplication private method which are responsible for
the creation of the dictionary.
- (struct __CFArray*) _createDockMenu: (char);
- (struct __CFArray*) _flattenMenu: (id);
- (struct __CFDictionary*) _flattenMenuItem: (id);
Each menu item is defined by a dictionary. Each key in the dictionary
represents a property.
Some of the keys are: name, mark, enabled, command, separator,
system-icon.
The dictionary is recreated every time the dock tile is pressed.
Manipulating these keys enables customization and dynamism.
It so easy, it makes you wonder why Apple has not completed the
implementation of the dock menu for so long.
Here are the steps in order to add checkmark to the dock menu
a) Subclass NSApplication (otherwise you will not be able to call
super). Name the subclass MyApplication.
b) MyApplication.h should be as follows:
#import <Cocoa/Cocoa.h>
@interface MyApplication : NSApplication { } @end
c) MyApplication.m should be as follows:
#import "MyApplication.h"
// As we are dealing with a private method, we have to add this
protocol otherwise the compiler will complain
@interface NSApplication (AppKitWorkaround)
- (struct __CFDictionary*) _flattenMenuItem: (NSMenuItem *) aMenu;
@end
@implementation MyApplication
- (struct __CFDictionary*) _flattenMenuItem: (NSMenuItem *) aMenu
{
int marker=0;
NSMutableDictionary * aDictionary=(NSMutableDictionary*)[super
_flattenMenuItem:aMenu];
if([aMenu state]==NSOnState) marker =1;
else if ([aMenu state]== NSMixedState) marker =2;
if (i) [aDictionary setObject:[NSNumber numberWithInt: marker]
forKey:@"mark"];
return (struct __CFDictionary*) aDictionary;
}
@end
d) Finally, you have to set MyApplication as the principal class
(Target -> Info.plist Entries -> Cocoa Specific), otherwise
MyApplication will not be instantiated.
Enjoy
Guy Meyer
<http://homepage.mac.com/rominar/net.html>
DATE : Tue Oct 08 18:03:33 2002
Hi
Application/Dock communication is done through a dictionary passed
between the two.
There are some NSApplication private method which are responsible for
the creation of the dictionary.
- (struct __CFArray*) _createDockMenu: (char);
- (struct __CFArray*) _flattenMenu: (id);
- (struct __CFDictionary*) _flattenMenuItem: (id);
Each menu item is defined by a dictionary. Each key in the dictionary
represents a property.
Some of the keys are: name, mark, enabled, command, separator,
system-icon.
The dictionary is recreated every time the dock tile is pressed.
Manipulating these keys enables customization and dynamism.
It so easy, it makes you wonder why Apple has not completed the
implementation of the dock menu for so long.
Here are the steps in order to add checkmark to the dock menu
a) Subclass NSApplication (otherwise you will not be able to call
super). Name the subclass MyApplication.
b) MyApplication.h should be as follows:
#import <Cocoa/Cocoa.h>
@interface MyApplication : NSApplication { } @end
c) MyApplication.m should be as follows:
#import "MyApplication.h"
// As we are dealing with a private method, we have to add this
protocol otherwise the compiler will complain
@interface NSApplication (AppKitWorkaround)
- (struct __CFDictionary*) _flattenMenuItem: (NSMenuItem *) aMenu;
@end
@implementation MyApplication
- (struct __CFDictionary*) _flattenMenuItem: (NSMenuItem *) aMenu
{
int marker=0;
NSMutableDictionary * aDictionary=(NSMutableDictionary*)[super
_flattenMenuItem:aMenu];
if([aMenu state]==NSOnState) marker =1;
else if ([aMenu state]== NSMixedState) marker =2;
if (i) [aDictionary setObject:[NSNumber numberWithInt: marker]
forKey:@"mark"];
return (struct __CFDictionary*) aDictionary;
}
@end
d) Finally, you have to set MyApplication as the principal class
(Target -> Info.plist Entries -> Cocoa Specific), otherwise
MyApplication will not be instantiated.
Enjoy
Guy Meyer
<http://homepage.mac.com/rominar/net.html>
| Related mails | Author | Date |
|---|---|---|
| No related mails found. | ||






Cocoa mail archive

