The R Project SVN R-packages

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
568 iacus 1
#import "RDeviceView.h"
2
#import "RQuartz.h"
3
#import "RController.h"
4
 
5
#include <Defn.h>
6
 
7
#include <R.h>
8
#include <R_ext/Boolean.h>
9
#include <R_ext/Rdynload.h>
10
#include <Rdefines.h>
11
#include <Rinternals.h>
12
 
13
#include <R_ext/Parse.h>
14
 
15
#include <Graphics.h>
16
#include <Rdevices.h>
17
 
18
extern void RQuartz_DiplayGList(RDeviceView * devView);
19
 
20
#define POOL NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]
21
@implementation RDeviceView
22
 
23
- (id)initWithFrame:(NSRect)frameRect
24
{
25
	if ((self = [super initWithFrame:frameRect]) != nil) {
26
		// Add initialization code here
27
		devTextStorage = [[NSTextStorage alloc] initWithString:@"text"];
28
		devLayoutManager = [[NSLayoutManager alloc] init];
29
		devTextContainer = [[NSTextContainer alloc] init];
30
		[devLayoutManager addTextContainer:devTextContainer];
31
		[devTextStorage addLayoutManager:devLayoutManager];
32
	}
33
	return self;
34
}
35
 
36
- (void) setPDFDrawing: (BOOL)flag
37
{
38
	PDFDrawing = flag;
39
}
40
- (BOOL) isPDFDrawing
41
{
42
	return PDFDrawing;
43
}
44
 
45
- (void) setDevNum: (int)dnum
46
{
47
	deviceNum = dnum;
48
}
49
 
50
- (int) getDevNum
51
{
52
	return deviceNum;
53
}
54
 
55
- (BOOL)isFlipped { return YES; }
56
 
57
 
58
- (void) dealloc
59
{
60
	[devLayoutManager release];
61
	[devTextStorage release];
62
	[devTextContainer release];
63
	[super dealloc];
64
}
65
 
66
 
67
 
68
static void drawStringInRect(NSRect rect, NSString *str, int fontSize)
69
{
70
    NSDictionary *dict = [NSDictionary
71
                          dictionaryWithObject: [NSFont boldSystemFontOfSize: fontSize]
72
                                        forKey: NSFontAttributeName];
73
    NSAttributedString *astr = [[NSAttributedString alloc]
74
                                initWithString: str
75
                                    attributes: dict];
76
    NSSize strSize = [astr size];
77
    NSPoint pt = NSMakePoint((rect.size.width - strSize.width) / 2,
78
                             (rect.size.height - strSize.height) / 2);
79
 
80
    // clear the rect
81
    rect.origin.x = 0;
82
    rect.origin.y = 0;
83
    [[NSColor whiteColor] set];
84
    NSRectFill(rect);
85
 
86
    // draw the string
87
    [astr drawAtPoint:pt];
88
 
89
    [astr release];
90
}
91
 
92
/*	FIXME: zoom, minimize don't work. With grid, it waits for event before rewriting, it
93
	essentialy blocks R
94
*/	
95
- (void)viewDidEndLiveResize
96
{
97
    [super viewDidEndLiveResize];
98
	[[RController getRController] handleBusy: YES];
99
	[self lockFocus];
100
 	RQuartz_DiplayGList(self);
101
	[deviceWindow flushWindow];
102
	[self unlockFocus];
103
	[[RController getRController] handleBusy: NO];
104
 
105
    // could do something here if needed
106
}
107
 
108
- (void)drawRect:(NSRect)aRect
109
{
110
    NSRect		frame = [self frame];
111
 
112
    if ([self inLiveResize])
113
    {
114
        NSString *str = [NSString stringWithFormat: @"Resizing to %g x %g",
115
                                                    frame.size.width, frame.size.height];
116
        drawStringInRect(frame, str, 20);
117
        return;
118
    }
119
 
120
	if(PDFDrawing){
121
		RQuartz_DiplayGList(self);
122
		PDFDrawing = NO;
123
	}
124
}
125
 
126
- (NSTextStorage *)getDevTextStorage
127
{
128
	return devTextStorage;
129
}
130
 
131
- (NSLayoutManager *)getDevLayoutManager
132
{
133
	return devLayoutManager;
134
}
135
 
136
- (NSTextContainer *)getDevTextContainer
137
{
138
	return devTextContainer;
139
}
140
 
141
 
142
 @end
143