4
4
* DESCRIPTION: Main TeXmacs view
5
5
* COPYRIGHT : (C) 2007 Massimiliano Gubinelli
6
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7
* This software falls under the GNU general public license version 3 or later.
8
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
11
10
******************************************************************************/
14
13
#include "converter.hpp"
15
14
#include "message.hpp"
16
15
#include "aqua_renderer.h"
20
extern bool aqua_update_flag;
21
extern int time_credit;
22
extern int timeout_time;
20
24
hashmap<int,string> nskeymap(NULL);
22
26
inline void scale (NSPoint &point)
54
58
- (NSRect)rect { return rect; }
57
@interface TMSimpleView (Private)
62
@interface TMView (Private)
58
63
- (void)setNeedsDisplayInTMRect:(TMRect*)r;
61
@implementation TMSimpleView
62
- (id)initWithFrame:(NSRect)frame {
63
self = [super initWithFrame:frame];
65
// Initialization code here.
71
- (void)setWidget:(widget_rep*) w
73
wid = (simple_widget_rep*)w;
78
return (widget_rep*)wid;
82
- (void)setNeedsDisplayInTMRect:(TMRect*)r
84
[self setNeedsDisplayInRect:[r rect]];
87
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
89
// query widget preferred size
91
wid->handle_get_size_hint (w,h);
92
NSSize s = NSMakeSize(w,h);
94
[self setFrameSize:s];
98
- (void)drawRect:(NSRect)rect
100
// cout << "SIMPLE DRAWING : " << rect.origin.x << ","<< rect.origin.x << ","<< rect.size.width<< "," << rect.size.height << "\n";
101
NSRect bounds = [self bounds];
106
the_aqua_renderer()->set_clipping (rect.origin.x*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL,
107
(rect.origin.x+rect.size.width)*PIXEL, -rect.origin.y*PIXEL);
108
// the_aqua_renderer()->set_clipping(bounds.origin.x*PIXEL, - bounds.origin.y*PIXEL, (bounds.origin.x+bounds.size.width)*PIXEL,- (bounds.origin.y+bounds.size.height)*PIXEL);
109
wid->handle_repaint (rect.origin.x*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL,
110
(rect.origin.x+rect.size.width)*PIXEL, -rect.origin.y*PIXEL);
111
//wid->handle_repaint(bounds.origin.x*PIXEL, bounds.origin.y*PIXEL, (bounds.origin.x+bounds.size.width)*PIXEL, (bounds.origin.y+bounds.size.height)*PIXEL);
112
if ( the_aqua_renderer()->interrupted()) {
113
// [self setNeedsDisplayInRect:rect];
114
[self performSelector:@selector(setNeedsDisplayInTMRect:) withObject:[[[TMRect alloc] initWithRect:rect] autorelease] afterDelay:0.0];
115
// cout << "reinstantiating rect\n";
118
//cout << "END SIMPLE DRAWING" << "\n";
64
- (void)delayedUpdate;
126
70
@implementation TMView
129
static void map(int code, string name)
73
inline void map(int code, string name)
131
75
nskeymap(code) = name;
136
80
map(0x0d,"return");
220
164
self = [super initWithFrame:frame];
222
166
// Initialization code here.
223
168
processingCompose = NO;
224
169
workingText = nil;
170
delayed_rects = [[NSMutableArray arrayWithCapacity:100] retain];
177
[delayed_rects release];
178
[self deleteWorkingText];
182
- (void) setWidget:(widget_rep*) w
184
wid = (simple_widget_rep*)w;
187
- (widget_rep*)widget
189
return (widget_rep*)wid;
192
- (void)setNeedsDisplayInTMRect:(TMRect*)r
194
[self setNeedsDisplayInRect:[r rect]];
197
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
199
// query widget preferred size
201
wid->handle_get_size_hint (w,h);
202
NSSize s = NSMakeSize(w,h);
204
[self setFrameSize:s];
207
- (void)delayedUpdate
209
NSMutableArray *arr = delayed_rects;
210
NSEnumerator *enumerator = [arr objectEnumerator];
212
delayed_rects = [[NSMutableArray arrayWithCapacity:10] retain];
213
while ((anObject = [enumerator nextObject])) {
214
[self displayRect:[anObject rect]];
229
221
- (void)drawRect:(NSRect)rect
223
if (aqua_update_flag) {
224
[delayed_rects addObject:[[[TMRect alloc] initWithRect:rect] autorelease]];
231
228
// Drawing code here.
232
if ([self inLiveResize])
234
NSRect bounds = [self bounds];
229
if ([self inLiveResize])
231
NSRect bounds = [self bounds];
235
232
[[NSColor blackColor] set];
236
[NSBezierPath strokeRect:NSInsetRect(bounds,1,1)];
233
[NSBezierPath strokeRect:NSInsetRect(bounds,1,1)];
236
// cout << "DRAWING : " << rect.origin.x << ","<< rect.origin.x << ","<< rect.size.width<< "," << rect.size.height << "\n";
237
// NSRect bounds = [self bounds];
240
basic_renderer r = the_aqua_renderer();
241
int x1 = rect.origin.x;
242
int y1 = rect.origin.y+rect.size.height;
243
int x2 = rect.origin.x+rect.size.width;
244
int y2 = rect.origin.y;
246
r -> begin([NSGraphicsContext currentContext]);
247
// r -> set_origin(0,0);
250
// cout << "DRAWING RECT " << x1 << "," << y1 << "," << x2 << "," << y2 << LF;
251
r -> set_clipping (x1,y1,x2,y2);
252
wid->handle_repaint (x1,y1,x2,y2);
254
if (r->interrupted())
255
aqua_update_flag= true;
257
// cout << "END DRAWING" << "\n";
259
if (aqua_update_flag) {
261
cout << "Postponed redrawing\n";
262
[self performSelector:@selector(delayedUpdate) withObject: nil afterDelay: 10];
239
cout << "DRAWING : " << rect.origin.x << ","<< rect.origin.x << ","<< rect.size.width<< "," << rect.size.height << "\n";
240
NSRect bounds = [self bounds];
244
if (0) { // clear redrawing area
245
[[NSColor whiteColor] set];
246
[NSBezierPath fillRect:rect];
250
the_aqua_renderer()->set_clipping (rect.origin.x*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL,
251
(rect.origin.x+rect.size.width)*PIXEL, -rect.origin.y*PIXEL);
252
// the_aqua_renderer()->set_clipping(bounds.origin.x*PIXEL, - bounds.origin.y*PIXEL, (bounds.origin.x+bounds.size.width)*PIXEL,- (bounds.origin.y+bounds.size.height)*PIXEL);
253
wid->handle_repaint (rect.origin.x*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL,
254
(rect.origin.x+rect.size.width)*PIXEL, -rect.origin.y*PIXEL);
255
//wid->handle_repaint(bounds.origin.x*PIXEL, bounds.origin.y*PIXEL, (bounds.origin.x+bounds.size.width)*PIXEL, (bounds.origin.y+bounds.size.height)*PIXEL);
256
if ( the_aqua_renderer()->interrupted()) {
257
// [self setNeedsDisplayInRect:rect];
258
[self performSelector:@selector(setNeedsDisplayInTMRect:) withObject:[[[TMRect alloc] initWithRect:rect] autorelease] afterDelay:0.0];
259
cout << "reinstantiating rect\n";
264
renderer ren = the_aqua_renderer();
267
[self getRectsBeingDrawn:&rects count:&count];
268
for(int i = 0; i < count; i++) {
269
NSRect rect = rects[i];
271
cout << "\n-------------------\nstarted drqwing one rect\n";
272
[NSGraphicsContext saveGraphicsState];
273
ren->set_clipping (rect.origin.x*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL,
274
(rect.origin.x+rect.size.width)*PIXEL, -rect.origin.y*PIXEL);
275
// ren->set_clipping(rect.origin.x*PIXEL, -rect.origin.y*PIXEL, (rect.origin.x+rect.size.width)*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL);
276
wid->handle_repaint (rect.origin.x*PIXEL, -(rect.origin.y+rect.size.height)*PIXEL,
277
(rect.origin.x+rect.size.width)*PIXEL, -rect.origin.y*PIXEL);
278
cout << "finished drqwing one rect\n";
279
// wid->handle_repaint(rect.origin.x*PIXEL, rect.origin.y*PIXEL, (rect.origin.x+rect.size.width)*PIXEL, (rect.origin.y+rect.size.height)*PIXEL);
280
[NSGraphicsContext restoreGraphicsState];
282
if (ren->interrupted()) {
283
// [self setNeedsDisplayInRect:rect];
284
[self performSelector:@selector(setNeedsDisplayInTMRect:) withObject:[[[TMRect alloc] initWithRect:rect] autorelease] afterDelay:0.0];
285
cout << "reinstantiating rect\n";
289
cout << "END DRAWING" << "\n";