~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Plugins/Cocoa/TMView.mm

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2009-04-26 19:35:14 UTC
  • mfrom: (1.1.10 upstream) (4.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090426193514-9yo3oggdslgdls4b
Tags: 1:1.0.7.2-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* texmacs crashes if /usr/share/texmacs/TeXmacs/misc/pixmaps/unknown.ps
  is not present. Do not remove it. (Closes: #484073, #497021)
* update patches 03_mupad.dpatch, 04_axiom.dpatch, 11-desktop-file.dpatch
* fix the mime problem in gnome. Thanks to Andrea Gamba for the fix.
[kohda]
* Refined a fix for the mime problem in gnome a bit.
* Try to fix /bin/sh problem (debian/fixsh) but it is not complete fix yet.
* Try to fix hard coded settings for ipa fonts(patches/09_ipa.dpatch), 
  especially for Debian where no ipa fonts exist yet.
* Fixed obsolete Build-Depends: changed libltdl3-dev to 
  libltdl-dev | libltdl7-dev (the latter for Ubuntu?)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
******************************************************************************/
12
11
 
13
12
#import "TMView.h"
14
13
#include "converter.hpp"
15
14
#include "message.hpp"
16
15
#include "aqua_renderer.h"
 
16
#include "aqua_gui.h"
17
17
 
18
18
#define PIXEL 256
19
19
 
 
20
extern bool aqua_update_flag;
 
21
extern int time_credit;
 
22
extern int timeout_time;
 
23
 
20
24
hashmap<int,string> nskeymap(NULL);
21
25
 
22
26
inline void scale (NSPoint &point)
54
58
- (NSRect)rect { return rect; }
55
59
@end
56
60
 
57
 
@interface TMSimpleView (Private)
 
61
 
 
62
@interface TMView (Private)
58
63
- (void)setNeedsDisplayInTMRect:(TMRect*)r;
59
 
@end
60
 
 
61
 
@implementation TMSimpleView
62
 
- (id)initWithFrame:(NSRect)frame {
63
 
        self = [super initWithFrame:frame];
64
 
        if (self) {
65
 
                // Initialization code here.
66
 
                wid = NULL;
67
 
        }
68
 
        return self;
69
 
}
70
 
 
71
 
- (void)setWidget:(widget_rep*) w
72
 
{
73
 
        wid = (simple_widget_rep*)w;
74
 
}
75
 
 
76
 
- (widget_rep*)widget
77
 
{
78
 
        return  (widget_rep*)wid;
79
 
}
80
 
 
81
 
 
82
 
- (void)setNeedsDisplayInTMRect:(TMRect*)r
83
 
{
84
 
        [self setNeedsDisplayInRect:[r rect]];
85
 
}
86
 
 
87
 
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
88
 
{
89
 
        // query widget preferred size
90
 
        SI w,h;
91
 
        wid->handle_get_size_hint (w,h);
92
 
  NSSize s = NSMakeSize(w,h);
93
 
        unscaleSize(s);
94
 
        [self setFrameSize:s];
95
 
}
96
 
 
97
 
 
98
 
- (void)drawRect:(NSRect)rect 
99
 
{
100
 
//  cout << "SIMPLE DRAWING : " << rect.origin.x << ","<< rect.origin.x << ","<< rect.size.width<< "," << rect.size.height <<  "\n";
101
 
  NSRect bounds = [self bounds];
102
 
        
103
 
        
104
 
        
105
 
        if (1) {
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";
116
 
                }
117
 
        }
118
 
        //cout << "END SIMPLE DRAWING" << "\n";
119
 
        
120
 
        
121
 
}
122
 
 
123
 
 
124
 
@end
 
64
- (void)delayedUpdate;
 
65
@end
 
66
 
 
67
 
 
68
 
125
69
 
126
70
@implementation TMView
127
71
 
128
72
 
129
 
static void map(int code, string name)
 
73
inline void map(int code, string name)
130
74
{
131
75
  nskeymap(code) = name;
132
76
}
133
77
 
134
 
+(void)initialize
 
78
void initkeymap()
135
79
{
136
80
  map(0x0d,"return");
137
81
  map(0x09,"tab");
220
164
  self = [super initWithFrame:frame];
221
165
  if (self) {
222
166
    // Initialization code here.
 
167
    wid = NULL;
223
168
    processingCompose = NO;
224
169
    workingText = nil;
 
170
    delayed_rects = [[NSMutableArray arrayWithCapacity:100] retain];
225
171
  }
226
172
  return self;
227
173
}
228
174
 
 
175
-(void) dealloc
 
176
{
 
177
  [delayed_rects release];
 
178
  [self deleteWorkingText];
 
179
  [super dealloc];
 
180
}
 
181
 
 
182
- (void) setWidget:(widget_rep*) w
 
183
{
 
184
        wid = (simple_widget_rep*)w;
 
185
}
 
186
 
 
187
- (widget_rep*)widget
 
188
{
 
189
        return  (widget_rep*)wid;
 
190
}
 
191
 
 
192
- (void)setNeedsDisplayInTMRect:(TMRect*)r
 
193
{
 
194
  [self setNeedsDisplayInRect:[r rect]];
 
195
}
 
196
 
 
197
- (void)viewWillMoveToWindow:(NSWindow *)newWindow
 
198
{
 
199
  // query widget preferred size
 
200
  SI w,h;
 
201
  wid->handle_get_size_hint (w,h);
 
202
  NSSize s = NSMakeSize(w,h);
 
203
  unscaleSize(s);
 
204
  [self setFrameSize:s];
 
205
}
 
206
 
 
207
- (void)delayedUpdate
 
208
{
 
209
  NSMutableArray *arr = delayed_rects;
 
210
  NSEnumerator *enumerator = [arr objectEnumerator];
 
211
  TMRect *anObject;
 
212
  delayed_rects = [[NSMutableArray arrayWithCapacity:10] retain];
 
213
  while ((anObject = [enumerator nextObject])) {
 
214
    [self displayRect:[anObject rect]];
 
215
  }
 
216
  [arr release];
 
217
}
 
218
 
 
219
 
 
220
 
229
221
- (void)drawRect:(NSRect)rect 
230
222
{
 
223
  if (aqua_update_flag) {
 
224
    [delayed_rects addObject:[[[TMRect alloc] initWithRect:rect] autorelease]];
 
225
    return;
 
226
  }
 
227
    
231
228
        // Drawing code here.
232
 
  if ([self inLiveResize])
233
 
  {
234
 
    NSRect bounds = [self bounds];
 
229
        if ([self inLiveResize])
 
230
        {
 
231
                NSRect bounds = [self bounds];
235
232
                [[NSColor blackColor] set];
236
 
    [NSBezierPath strokeRect:NSInsetRect(bounds,1,1)];
 
233
                [NSBezierPath strokeRect:NSInsetRect(bounds,1,1)];
237
234
                //    return;
 
235
        }
 
236
//      cout << "DRAWING : " << rect.origin.x << ","<< rect.origin.x << ","<< rect.size.width<< "," << rect.size.height <<  "\n";
 
237
//      NSRect bounds = [self bounds];
 
238
        
 
239
  {
 
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;
 
245
    
 
246
    r -> begin([NSGraphicsContext currentContext]);
 
247
  //  r -> set_origin(0,0);
 
248
    r -> encode (x1,y1);
 
249
    r -> encode (x2,y2);
 
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);
 
253
                r->end();
 
254
    if (r->interrupted())
 
255
      aqua_update_flag= true;
 
256
        }
 
257
//      cout << "END DRAWING" << "\n";
 
258
 
 
259
  if (aqua_update_flag) {
 
260
    if (DEBUG_EVENTS)
 
261
      cout << "Postponed redrawing\n"; 
 
262
    [self performSelector:@selector(delayedUpdate) withObject: nil afterDelay: 10];
238
263
  }
239
 
  cout << "DRAWING : " << rect.origin.x << ","<< rect.origin.x << ","<< rect.size.width<< "," << rect.size.height <<  "\n";
240
 
  NSRect bounds = [self bounds];
241
 
        
242
 
        
243
 
        
244
 
        if (0) { // clear redrawing area
245
 
                [[NSColor whiteColor] set];
246
 
                [NSBezierPath fillRect:rect];
247
 
        }
248
 
        
249
 
        if (1) {
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";
260
 
                }
261
 
        }
262
 
        else
263
 
        {
264
 
                renderer ren = the_aqua_renderer();
265
 
                const NSRect *rects;
266
 
                int count;
267
 
                [self getRectsBeingDrawn:&rects count:&count];
268
 
                for(int i = 0; i < count; i++) {
269
 
                        NSRect rect = rects[i];
270
 
                        {
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];
281
 
                        }
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";
286
 
                        }
287
 
                }               
288
 
        }
289
 
  cout << "END DRAWING" << "\n";
290
 
        
291
 
        
 
264
  
292
265
}
293
266
 
294
267
 
304
277
    unsigned int mods = [theEvent modifierFlags];
305
278
    
306
279
    
307
 
 
 
280
    
308
281
    if (([nss length]==1)&& (!processingCompose))
309
 
 
 
282
      
310
283
    {
311
284
      int key = [nss characterAtIndex:0];
312
285
      if (nskeymap->contains(key)) {
356
329
- (void)keyDown:(NSEvent *)theEvent
357
330
{
358
331
  if (!wid) return;
 
332
 
 
333
  time_credit= 25;
 
334
  timeout_time= texmacs_time () + time_credit;
 
335
  static bool fInit = false;
 
336
  if (!fInit) {
 
337
    if (DEBUG_EVENTS)
 
338
      cout << "Initializing keymap\n";
 
339
    initkeymap();
 
340
    fInit= true;
 
341
  }
359
342
  
360
343
  {
361
 
   // char str[256];
 
344
    // char str[256];
362
345
    string r;
363
346
    NSString *nss = [theEvent charactersIgnoringModifiers];
364
347
    unsigned int mods = [theEvent modifierFlags];
366
349
    string modstr;
367
350
    
368
351
    if (mods & NSControlKeyMask ) modstr= "C-" * modstr;
369
 
//    if (mods & NSAlternateKeyMask) modstr= "Mod1-" * modstr;
 
352
    //    if (mods & NSAlternateKeyMask) modstr= "Mod1-" * modstr;
370
353
    if (mods & NSCommandKeyMask) modstr= "Mod1-" * modstr;
371
354
    //   if (mods & NSNumericPadKeyMask) s= "Mod3-" * s;
372
355
    if (mods & NSHelpKeyMask) modstr= "Mod4-" * modstr;
373
356
    
374
 
//    if (!processingCompose)
 
357
    //    if (!processingCompose)
375
358
    {
376
359
      if ([nss length]>0) {
377
360
        int key = [nss characterAtIndex:0];
393
376
          cout << "modified  key press: " << s << LF;
394
377
          [self deleteWorkingText];
395
378
          wid -> handle_keypress (s, texmacs_time());    
 
379
          the_gui->update (); // FIXME: remove this line when
 
380
          // edit_typeset_rep::get_env_value will be faster
 
381
 
396
382
          return;
397
383
        }
398
384
      }
399
385
    }
400
 
 
 
386
    
401
387
    processingCompose = YES;
402
388
    static NSMutableArray *nsEvArray = nil;
403
389
    if (nsEvArray == nil)
408
394
    [nsEvArray removeObject: theEvent];
409
395
  }
410
396
}
411
 
 
 
397
 
412
398
#endif
413
399
 
414
400
- (void)mouseDown:(NSEvent *)theEvent
485
471
        return YES;
486
472
}
487
473
 
488
 
- (void) dealloc
489
 
{
490
 
  [self deleteWorkingText];
491
 
  [super dealloc];
492
 
}
493
 
 
494
474
- (void) deleteWorkingText
495
475
496
476
  if (workingText == nil)
498
478
  [workingText release];
499
479
  workingText = nil;
500
480
  processingCompose = NO;
501
 
 
 
481
  
502
482
  
503
483
}
504
484
 
510
490
{
511
491
  processingCompose = NO;
512
492
  NSLog(@"insertText: <%@>",aString);
513
 
 
 
493
  
514
494
  NSString *str = [aString respondsToSelector: @selector(string)] ?
515
495
  [aString string] : aString;
516
496
  
533
513
{
534
514
  NSString *str = [aString respondsToSelector: @selector(string)] ?
535
515
  [aString string] : aString;
536
 
 
 
516
  
537
517
  if (workingText != nil)
538
518
    [self deleteWorkingText];
539
519
  if ([str length] == 0)
551
531
- (BOOL) hasMarkedText
552
532
{
553
533
  return workingText != nil;
554
 
 
 
534
  
555
535
}
556
536
- (NSInteger) conversationIdentifier
557
537
{
581
561
 */
582
562
- (NSRange) selectedRange
583
563
{
584
 
return NSMakeRange(NSNotFound, 0);
 
564
  return NSMakeRange(NSNotFound, 0);
585
565
}
586
566
/* This method returns the first frame of rects for theRange in screen coordindate system.
587
567
 */