~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/arch/unix/macosx/cocoa/view/driveview.m

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.1.7 upstream) (9.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090331003715-i5yisvcfv7mgz3eh
Tags: 2.1.dfsg-1
* New major upstream release (closes: #495937).
* Add desktop files (closes: #501181).

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#import "driveview.h"
29
29
#import "vicenotifications.h"
30
30
#import "viceapplication.h"
 
31
#import "viceappcontroller.h"
 
32
 
 
33
static const char *button_texts[] = {
 
34
     "\xe2\x8f\x8f",  /* eject */
 
35
     "\xe2\x8f\x8e"   /* attach */
 
36
};
 
37
 
 
38
static NSString *help_texts[] = {
 
39
    @"Eject Disk Image",
 
40
    @"Attach Disk Image"
 
41
};
31
42
 
32
43
@implementation DriveView
33
44
 
46
57
    float fw = NSWidth(frame);
47
58
    float fh = NSHeight(frame);
48
59
    
49
 
    float ledH = fh / 2.0;
50
 
    float ledW = ledH * 2.0;
51
 
 
52
 
    NSRect trackRect = NSMakeRect(0,0,fw - ledW,ledH);
53
 
    NSRect ledRect   = NSMakeRect(fw-ledW,0,ledW,ledH);
54
 
    NSRect imageRect = NSMakeRect(0,ledH,fw,ledH);
 
60
    float bw = fh / 2.0;
 
61
 
 
62
    NSRect trackRect = NSMakeRect(0,0,fw - bw * 3,bw);
 
63
    NSRect ledRect   = NSMakeRect(fw-bw,0,bw,bw);
 
64
    NSRect imageRect = NSMakeRect(0,bw-4,fw,bw);
 
65
 
 
66
    NSFont *font = [NSFont labelFontOfSize:10];
55
67
    
56
68
    // text box for track display
57
69
    trackText = [[NSTextField alloc] initWithFrame:trackRect];
66
78
    driveLed = [[NSColorWell alloc] initWithFrame:ledRect];
67
79
    [driveLed setEnabled:NO];
68
80
    [driveLed setBordered:YES];
69
 
    [driveLed setAutoresizingMask:NSViewMinXMargin];
70
81
    [self addSubview:driveLed];
71
82
 
 
83
    // buttons
 
84
    int i;
 
85
    float x = fw - bw * 3;
 
86
    for(i=0;i<2;i++) {
 
87
        buttons[i] = [[NSButton alloc] initWithFrame:NSMakeRect(x,0,bw,bw)];
 
88
        [buttons[i] setFont:[NSFont fontWithName:@"Apple Symbols" size:14]];    
 
89
        [buttons[i] setTag:i];
 
90
        [buttons[i] setTitle:
 
91
            [NSString stringWithCString:button_texts[i]   
 
92
                encoding:NSUTF8StringEncoding]];
 
93
        [buttons[i] setToolTip:help_texts[i]];
 
94
    
 
95
        [buttons[i] setTarget:self];
 
96
        [buttons[i] setAction:@selector(buttonPressed:)];    
 
97
        [self addSubview:buttons[i]];
 
98
 
 
99
        x += bw;
 
100
    }
 
101
 
72
102
    // image name text field
73
103
    imageText = [[NSTextField alloc] initWithFrame:imageRect];
 
104
    [imageText setFont:font];
74
105
    [imageText setDrawsBackground:NO];
75
106
    [imageText setAutoresizingMask:NSViewWidthSizable];
76
107
    [imageText setEditable:NO];
98
129
                                                 name:VICEDisplayDriveTrackNotification
99
130
                                               object:nil];
100
131
 
 
132
    [self updateImage:@""];
101
133
    return self;
102
134
}
103
135
 
138
170
    }
139
171
}
140
172
 
 
173
- (void)updateImage:(NSString *)image
 
174
{
 
175
    if([image length]==0) {
 
176
        [imageText setStringValue:@"<no disk image>"];
 
177
        // toggle eject button
 
178
        [buttons[0] setEnabled:NO];
 
179
    } else {
 
180
        [imageText setStringValue:image];
 
181
        // toggle eject button
 
182
        [buttons[0] setEnabled:YES];
 
183
    }    
 
184
}
 
185
 
141
186
- (void)displayImage:(NSNotification*)notification
142
187
{
143
188
    NSDictionary * dict = [notification userInfo];
145
190
    
146
191
    if (drive == driveNumber) {
147
192
        NSString *image = [dict objectForKey:@"image"];
148
 
        [image retain];
149
 
        [imageText setStringValue:image];
 
193
        [self updateImage:image];
150
194
    }
151
195
}
152
196
 
167
211
    }
168
212
}
169
213
 
170
 
 
171
 
#if 0
172
 
- (void)driveMenuChanged:(NSNotification*)notification
173
 
{
174
 
    NSDictionary * dict = [notification userInfo];
175
 
    int drive = [[dict objectForKey:@"drive"] intValue];
176
 
 
177
 
    if (drive == driveNumber)
178
 
        [self setMenu:[dict objectForKey:@"menu"]];
179
 
}
180
 
 
181
 
- (void)mouseDown:(NSEvent*)event
182
 
{
183
 
    [NSMenu popUpContextMenu:[self menu] withEvent:event forView:self];
184
 
}
185
 
#endif
 
214
- (void)buttonPressed:(id)sender
 
215
{
 
216
    int command = [sender tag];
 
217
    if(command==0) {
 
218
        // eject disk image
 
219
        [[VICEApplication theAppController] detachDiskImage:self];
 
220
    } else if(command==1) {
 
221
        // attach disk image
 
222
        [[VICEApplication theAppController] attachDiskImage:self];
 
223
    }
 
224
}
 
225
 
 
226
- (int)tag
 
227
{
 
228
    // callback from button pressed
 
229
    return driveNumber + driveBase;
 
230
}
186
231
 
187
232
// ----- Drag & Drop -----
188
233