macos: update AFS prefs pane
[openafs.git] / src / platform / DARWIN / AFSPreference / AFSBackgrounder / AFSMenuExtraView.m
1 //
2 //  AFSMenuExtraView.m
3 //  AFSCommander
4 //
5 //  Created by Claudio Bisegni on 11/07/07.
6 //  Copyright 2007 INFN - National Institute of Nuclear Physics. All rights reserved.
7 //
8
9 #import "AFSMenuExtraView.h"
10 #import "AFSPropertyManager.h"
11 #import "global.h"
12
13 @implementation AFSMenuExtraView
14
15 - initWithFrame:(NSRect)myRect 
16    backgrounder:(AFSBackgrounderDelegate*)backgrounder  
17                    menu:(NSMenu*)menu{
18         
19         // Have super init
20         self = [super initWithFrame:myRect];
21         if(!self) {
22                 return nil;
23         }
24         
25         // Store our extra
26         backgrounderDelegator = backgrounder;
27         statusItem = [backgrounderDelegator statusItem];
28         statusItemMenu = menu;
29         isMenuVisible = NO;
30     return self;
31         
32 } // initWithFrame
33
34 - (void)dealloc {
35         
36     [super dealloc];
37         
38 } // dealloc
39
40 - (void)drawRect:(NSRect)rect 
41 {
42         NSImage *image = nil;
43         int fontHeight = 0;
44         NSAttributedString *kerberosStringIndicator = nil;
45         
46         //check if we need to simulate the background menu clicked
47         [statusItem drawStatusBarBackgroundInRect:[self bounds] 
48                                                                 withHighlight:isMenuVisible];
49         image = [backgrounderDelegator imageToRender];
50     if (image) {
51                 // Live updating even when menu is down handled by making the extra
52                 // draw the background if needed.               
53                 [image compositeToPoint:NSMakePoint(0, 0) operation:NSCompositeSourceOver];
54         }
55         //Draw, if necessary, the kerberos indicator for aklog usage for get token
56         if([backgrounderDelegator useAklogPrefValue] == NSOnState) {
57                 kerberosStringIndicator = [[self makeKerberosIndicator:&fontHeight] autorelease];
58                 if(kerberosStringIndicator) [kerberosStringIndicator drawAtPoint:NSMakePoint(0, kMenuBarHeight-fontHeight)];
59         }
60 }
61
62 /*!
63     @method     makeKerberosIndicator
64     @abstract   Make the kerberos indicator
65     @discussion Make a letter to render in menu view to inform the user if is enable aklog use
66 */
67 - (NSAttributedString*) makeKerberosIndicator:(int*)fontHeight  {
68         NSFont *font = [NSFont systemFontOfSize:9.0];
69         NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font
70                                                                                                                                 forKey:NSFontAttributeName];
71         NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"K"
72                                                                                                                                          attributes:attrsDictionary];
73         *fontHeight = [attrString size].height;
74         return attrString;
75 }
76
77 -(void)mouseDown:(NSEvent *)event {
78         [statusItemMenu setDelegate:self];
79         [statusItem popUpStatusItemMenu:statusItemMenu];
80         [self setNeedsDisplay:YES];
81 }
82
83 - (void)menuWillOpen:(NSMenu *)menu {
84     isMenuVisible = YES;
85     [self setNeedsDisplay:YES];
86 }
87
88 - (void)menuDidClose:(NSMenu *)menu {
89     isMenuVisible = NO;
90     [statusItemMenu setDelegate:nil];    
91     [self setNeedsDisplay:YES];
92 }
93
94 // -------------------------------------------------------------------------------
95 //  - (void)menuNeedsUpdate:(NSMenu *)menu
96 // -------------------------------------------------------------------------------
97 - (void)menuNeedsUpdate:(NSMenu *)menu {
98         [backgrounderDelegator menuNeedsUpdate:menu];
99 }
100 @end