-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrintView.m
97 lines (82 loc) · 2.23 KB
/
PrintView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// PrintView.m
// SubnetCalc
//
// Created by Julien Mulot on 02/02/11.
// Copyright 2011 mulot.net. All rights reserved.
//
#import "PrintView.h"
@implementation PrintView
-initWithSubnet:(NSTableView *)table printInfo:(NSPrintInfo *)pi
{
NSRect frame;
NSSize paperSize;
entryPerPage = 30;
pages = [subnetsTable numberOfRows] / entryPerPage;
if (([subnetsTable numberOfRows] % entryPerPage) != 0)
{
pages = pages + 1;
}
paperSize = [pi paperSize];
frame.origin = NSMakePoint(0,0);
frame.size.width = paperSize.width;
frame.size.height = paperSize.height * pages;
self = [super initWithFrame:frame];
rectHeight = paperSize.height / entryPerPage;
return self;
}
-(BOOL)knowsPageRange:(NSRange *)range;
{
range->location = 1;
range->length = pages;
return YES;
}
-(NSRect)rectForSubnet:(int)index
{
NSRect result;
NSRect bounds;
bounds = [self bounds];
result.origin.x = bounds.origin.x;
result.size.width = bounds.size.width;
result.origin.y = NSMaxY(bounds) -((index + 1) * rectHeight);
result.size.height = rectHeight;
return (result);
}
-(NSRect)rectForPage:(NSInteger)pageNum
{
NSRect result;
result.size.width = [self bounds].size.width;
result.size.height = rectHeight * entryPerPage;
result.origin.x = [self bounds].origin.x;
result.origin.y = NSMaxY([self bounds]) - (pageNum * result.size.height);
return (result);
}
-(void)drawRect:(NSRect)rect
{
int i;
NSRect aRect;
NSMutableDictionary *attributes;
NSString *printString;
attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:[NSFont fontWithName:@"Helvetica" size:14] forKey: NSFontAttributeName];
[attributes setObject:[NSColor blackColor] forKey:NSForegroundColorAttributeName];
for (i = 1; i <= [subnetsTable numberOfRows]; i++)
{
aRect = [self rectForSubnet:i];
if (NSIntersectsRect(aRect, rect))
{
aRect.origin.x = aRect.origin.x + 50;
aRect.size.width = aRect.size.width - 400;
//NSLog(@"PrintLine %d %@\n",i, [subnetsTable tableView:
printString = [NSString stringWithFormat: @"%d %@ %@ %@",
i, @"toto", @"tata", @"titi"
];
//[[Subnets objectAtIndex:i] stringValue]];
[printString drawInRect:aRect withAttributes:attributes];
}
}
}
-(void)dealloc
{
}
@end