File: vtkCarbonRenderWindowInteractor.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (716 lines) | stat: -rw-r--r-- 22,609 bytes parent folder | download | duplicates (3)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkCarbonRenderWindowInteractor.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include <stdio.h>
#include <cstdlib>
#include <string.h>
#include <math.h>

#include "vtkActor.h"
#include "vtkCarbonRenderWindow.h"
#include "vtkCarbonRenderWindowInteractor.h"
#include "vtkCommand.h"
#include "vtkInteractorStyle.h"
#include "vtkObjectFactory.h"

#ifdef VTK_USE_TDX
#include "vtkTDxMacDevice.h"
#endif

vtkStandardNewMacro(vtkCarbonRenderWindowInteractor);

void (*vtkCarbonRenderWindowInteractor::ClassExitMethod)(void *)
  = (void (*)(void *))NULL;
void *vtkCarbonRenderWindowInteractor::ClassExitMethodArg = (void *)NULL;
void (*vtkCarbonRenderWindowInteractor::ClassExitMethodArgDelete)(void *)
  = (void (*)(void *))NULL;

//--------------------------------------------------------------------------
// Translate a char to the Tk equivalent keysym for compatibility
static const char *vtkMacCharCodeToKeySymTable[128] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  "space", "exclam", "quotedbl", "numbersign",
  "dollar", "percent", "ampersand", "quoteright",
  "parenleft", "parenright", "asterisk", "plus",
  "comma", "minus", "period", "slash",
  "0", "1", "2", "3", "4", "5", "6", "7",
  "8", "9", "colon", "semicolon", "less", "equal", "greater", "question",
  "at", "A", "B", "C", "D", "E", "F", "G",
  "H", "I", "J", "K", "L", "M", "N", "O",
  "P", "Q", "R", "S", "T", "U", "V", "W",
  "X", "Y", "Z", "bracketleft",
  "backslash", "bracketright", "asciicircum", "underscore",
  "quoteleft", "a", "b", "c", "d", "e", "f", "g",
  "h", "i", "j", "k", "l", "m", "n", "o",
  "p", "q", "r", "s", "t", "u", "v", "w",
  "x", "y", "z", "braceleft", "bar", "braceright", "asciitilde", "Delete",
};

//--------------------------------------------------------------------------
// Translate a virtual keycode to the Tk equivalent keysym for compatibility
static const char *vtkMacKeyCodeToKeySymTable[128] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, "Return", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  "Tab", 0, 0, "Backspace", 0, "Escape", 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0,
  0, "period", 0, "asterisk", 0, "plus", 0, "Clear",
  0, 0, 0, "slash", "KP_Enter", 0, "minus", 0,
  0, 0, "KP_0", "KP_1", "KP_2", "KP_3", "KP_4", "KP_5",
  "KP_6", "KP_7", 0, "KP_8", "KP_9", 0, 0, 0,
  "F5", "F6", "F7", "F3", "F8", 0, 0, 0,
  0, "Snapshot", 0, 0, 0, 0, 0, 0,
  0, 0, "Help", "Home", "Prior", "Delete", "F4", "End",
  "F2", "Next", "F1", "Left", "Right", "Down", "Up", 0,
};

//--------------------------------------------------------------------------
// callback routine to handle all window-related events
// The WindowPtr of the associated window is passed in userData
static pascal OSStatus myWinEvtHndlr(EventHandlerCallRef,
                                     EventRef event, void* userData)
{
  OSStatus                         result = eventNotHandledErr;
  HIPoint                          mouseLoc;
  vtkCarbonRenderWindow            *ren;
  vtkCarbonRenderWindowInteractor  *me;
  UInt32                           eventClass = GetEventClass(event);
  UInt32                           eventKind = GetEventKind (event);

  ren = (vtkCarbonRenderWindow *)userData;

  if (NULL == ren)
    {
    return 0;
    }

  me = (vtkCarbonRenderWindowInteractor *)ren->GetInteractor();
  if (NULL == me)
    {
    return 0;
    }

  UInt32 modifierKeys;
  GetEventParameter(event, kEventParamKeyModifiers,typeUInt32, NULL,
                    sizeof(modifierKeys), NULL, &modifierKeys);
  int controlDown = ((modifierKeys & (controlKey | cmdKey)) != 0);
  int shiftDown = ((modifierKeys & shiftKey) != 0);
  int altDown = ((modifierKeys & optionKey) != 0);

  // Capture mouse position for non-mouse events.  Carbon itself does
  // not provide mouse positions for these events, but VTK expects them.
  int deltaX, deltaY;
  CGGetLastMouseDelta(&deltaX, &deltaY);
  if (eventClass != kEventClassMouse)
    {
    int mousePos[2], lastDelta[2];
    me->GetEventPosition(mousePos);
    me->GetLastMouseDelta(lastDelta);
    mousePos[0] += lastDelta[0] + deltaX;
    mousePos[1] += lastDelta[1] - deltaY;
    me->SetEventPosition(mousePos);
    // This must be called after every SetEventPosition/SetEventInformation
    // in order to reliably couple the Delta with the EventPosition.
    me->SetLastMouseDelta(0, 0);
    }

  switch (eventClass)
    {
    case kEventClassControl:
      {
      switch (eventKind)
        {
        case kEventControlDraw:
          {
          ren->Render();
          result = noErr;
          break;
          }
        case kEventControlBoundsChanged:
          {
          if(ren->GetWindowId())
            {
            HIRect viewBounds;
            HIViewGetBounds(ren->GetWindowId(), &viewBounds);
            me->UpdateSize(int(viewBounds.size.width),
                           int(viewBounds.size.height));
            if (me->GetEnabled())
              {
              me->InvokeEvent(vtkCommand::ConfigureEvent,NULL);
              }
            result = noErr;
            }
          break;
          }
        }
      break;
      }

    case kEventClassKeyboard:
      {
      const char *keySym = NULL;
      char charCode = '\0';

      UInt32 macKeyCode;
      GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL,
                        sizeof(macKeyCode), NULL, &macKeyCode);

      if (macKeyCode < 128)
        {
        keySym = vtkMacKeyCodeToKeySymTable[macKeyCode];
        }

      SInt8 macCharCode;
      GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL,
                        sizeof(macCharCode), NULL, &macCharCode);

      charCode = static_cast<char>(macCharCode);
      if (keySym == NULL && static_cast<unsigned char>(macCharCode) < 128)
        {
        keySym = vtkMacCharCodeToKeySymTable[macCharCode];
        }
      if (keySym == NULL)
        {
        keySym = "None";
        }

      switch (GetEventKind(event))
        {
        case kEventRawKeyDown:
          {
          me->SetKeyEventInformation(controlDown, shiftDown,
                                     charCode, 1, keySym);
          me->SetAltKey(altDown);
          me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);
          if (charCode)
            {
            me->InvokeEvent(vtkCommand::CharEvent, NULL);
            }
          result = noErr;
          break;
          }
        case kEventRawKeyRepeat:
          {
          me->SetKeyEventInformation(controlDown, shiftDown,
                                     charCode, 1, keySym);
          me->SetAltKey(altDown);
          me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);
          if (charCode)
            {
            me->InvokeEvent(vtkCommand::CharEvent, NULL);
            }
          result = noErr;
          break;
          }
        case kEventRawKeyUp:
          {
          me->SetKeyEventInformation(controlDown, shiftDown,
                                     charCode, 1, keySym);
          me->SetAltKey(altDown);
          me->InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
          result = noErr;
          break;
          }
        case kEventRawKeyModifiersChanged:
          {
          int oldControlDown = me->GetControlKey();
          int oldShiftDown = me->GetShiftKey();
          int oldAltDown = me->GetAltKey();

          int keyPress = 0;
          charCode = '\0';
          if (controlDown != oldControlDown)
            {
            keySym = "Control_L";
            keyPress = oldControlDown = controlDown;
            }
          else if (shiftDown != oldShiftDown)
            {
            keySym = "Shift_L";
            keyPress = oldShiftDown = shiftDown;
            }
          else if (altDown != oldAltDown)
            {
            keySym = "Alt_L";
            keyPress = oldAltDown = altDown;
            }
          else
            {
            break;
            }

          me->SetKeyEventInformation(oldControlDown, oldShiftDown,
                                     charCode, 1, keySym);
          me->SetAltKey(oldAltDown);

          if (keyPress)
            {
            me->InvokeEvent(vtkCommand::KeyPressEvent, NULL);
            }
          else
            {
            me->InvokeEvent(vtkCommand::KeyReleaseEvent, NULL);
            }
          result = noErr;
          break;
          }
        }
      break;
      }

    case kEventClassMouse:
      {
      // see if the event is for this view
      HIViewRef view_for_mouse;
      HIViewRef root_window = HIViewGetRoot(ren->GetRootWindow());
      HIViewGetViewForMouseEvent(root_window, event, &view_for_mouse);

      GetEventParameter(event, kEventParamWindowMouseLocation, typeHIPoint,
                        NULL, sizeof(HIPoint), NULL, &mouseLoc);

      HIViewConvertPoint(&mouseLoc, root_window, ren->GetWindowId());

      UInt16 buttonNumber;
      GetEventParameter(event, kEventParamMouseButton, typeMouseButton, NULL,
                        sizeof(buttonNumber), NULL, &buttonNumber);

      UInt32 clickCount;
      GetEventParameter(event, kEventParamClickCount, typeUInt32, NULL,
                        sizeof(clickCount), NULL, &clickCount);
      int repeatCount = clickCount > 1 ? clickCount - 1 : 0;

      me->SetEventInformationFlipY(int(mouseLoc.x), int(mouseLoc.y),
                                   controlDown, shiftDown,
                                   0, repeatCount);
      me->SetLastMouseDelta(0, 0);
      me->SetAltKey(altDown);

      // look for enter/leave
      if (view_for_mouse != ren->GetWindowId())
        {
        // never handle "mouse down" events outside the window rect
        if (GetEventKind(event) == kEventMouseDown ||
            !me->GetMouseButtonDown())
          {
          return eventNotHandledErr;
          }
        }
      else if (!me->GetMouseInsideWindow())
        {
        me->SetMouseInsideWindow(1);
        // This will fix the LastEventPosition
        me->SetEventPositionFlipY(int(mouseLoc.x), int(mouseLoc.y));
        me->SetLastMouseDelta(0, 0);
        me->InvokeEvent(vtkCommand::EnterEvent,NULL);
        }

      switch (GetEventKind(event))
        {
        case kEventMouseDown:
          {
          me->SetMouseButtonDown(1);
          switch (buttonNumber)
            {
            case 1:
              {
              me->InvokeEvent(vtkCommand::LeftButtonPressEvent,NULL);
              break;
              }
            case 2:
              {
              me->InvokeEvent(vtkCommand::RightButtonPressEvent,NULL);
              break;
              }
            case 3:
              {
              me->InvokeEvent(vtkCommand::MiddleButtonPressEvent,NULL);
              break;
              }
            }
          result = noErr;
          break;
          }
        case kEventMouseUp:
          {
          me->SetMouseButtonDown(0);
          switch (buttonNumber)
            {
            case 1:
              {
              me->InvokeEvent(vtkCommand::LeftButtonReleaseEvent,NULL);
              break;
              }
            case 2:
              {
              me->InvokeEvent(vtkCommand::RightButtonReleaseEvent,NULL);
              break;
              }
            case 3:
              {
              me->InvokeEvent(vtkCommand::MiddleButtonReleaseEvent,NULL);
              break;
              }
            }
          result = noErr;
          break;
          }
        case kEventMouseMoved:
          {
          me->InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
          result = noErr;
          break;
          }
        case kEventMouseDragged:
          {
          me->InvokeEvent(vtkCommand::MouseMoveEvent, NULL);
          result = noErr;
          break;
          }
        case kEventMouseWheelMoved:
          {
          EventMouseWheelAxis axis;
          SInt32 delta;
          GetEventParameter( event, kEventParamMouseWheelAxis,
                         typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis );
          GetEventParameter( event, kEventParamMouseWheelDelta,
                          typeLongInteger, NULL, sizeof(delta), NULL, &delta );
          if ( axis == kEventMouseWheelAxisY )
            {
             if( delta > 0)
              {
              me->InvokeEvent(vtkCommand::MouseWheelForwardEvent, NULL);
              }
            else
              {
              me->InvokeEvent(vtkCommand::MouseWheelBackwardEvent, NULL);
              }
            }
          result = noErr;
          break;
          }
        default:
          {
          }
        }
      }
    }

  return result;
}

//--------------------------------------------------------------------------
// Construct object so that light follows camera motion.
vtkCarbonRenderWindowInteractor::vtkCarbonRenderWindowInteractor()
{
  this->ViewProcUPP        = NULL;
  this->WindowProcUPP      = NULL;
  this->MouseInsideWindow  = 0;
  this->MouseButtonDown    = 0;
  this->LeaveCheckId       = 0;
  this->LastMouseDelta[0]  = 0;
  this->LastMouseDelta[1]  = 0;

#ifdef VTK_USE_TDX
  this->Device=vtkTDxMacDevice::New();
#endif
}

//--------------------------------------------------------------------------
vtkCarbonRenderWindowInteractor::~vtkCarbonRenderWindowInteractor()
{
  this->Enabled = 0;
#ifdef VTK_USE_TDX
  this->Device->Delete();
#endif
}

//--------------------------------------------------------------------------
void  vtkCarbonRenderWindowInteractor::StartEventLoop()
{
  // Call Carbon API method that starts the loop.
  RunApplicationEventLoop();
}

//--------------------------------------------------------------------------
// Fill in some local variables (most of this routine could probably go)
void vtkCarbonRenderWindowInteractor::Initialize()
{
  vtkCarbonRenderWindow *ren;
  int *size;

  // make sure we have a RenderWindow and camera
  if ( ! this->RenderWindow)
    {
    vtkErrorMacro(<<"No renderer defined!");
    return;
    }
  if (this->Initialized)
    {
    return;
    }
  this->Initialized = 1;
  // get the info we need from the RenderingWindow
  ren = static_cast<vtkCarbonRenderWindow *>(this->RenderWindow);

  ren->Start();
  size    = ren->GetSize();
  ren->GetPosition();
  this->Enable();
  this->Size[0] = size[0];
  this->Size[1] = size[1];
}

//--------------------------------------------------------------------------
// A timer for checking when mouse leaves window
pascal void vtkCarbonLeaveCheck(EventLoopTimerRef vtkNotUsed(platformTimerId),
                                void *userData)
{
  if (NULL != userData)
    {
    vtkCarbonRenderWindowInteractor *me =
      static_cast<vtkCarbonRenderWindowInteractor *>(userData);
    vtkRenderWindow *win = me->GetRenderWindow();
    int deltaX, deltaY;
    CGGetLastMouseDelta(&deltaX, &deltaY);
    int delta[2];
    me->GetLastMouseDelta(delta);
    delta[0] += deltaX;
    delta[1] -= deltaY;
    int *size = win->GetSize();
    int *pos = me->GetEventPosition();
    int x = pos[0] + delta[0];
    int y = pos[1] + delta[1];
    if (me->GetMouseInsideWindow() && !me->GetMouseButtonDown() &&
        (x < 0 || x >= size[0] || y < 0 || y >= size[1]))
      {
      me->SetMouseInsideWindow(0);
      me->SetEventPosition(x, y);
      me->SetLastMouseDelta(0, 0);
      me->InvokeEvent(vtkCommand::LeaveEvent,NULL);
      }
    else
      {
      me->SetLastMouseDelta(delta[0], delta[1]);
      }
    }
}

//--------------------------------------------------------------------------
void vtkCarbonRenderWindowInteractor::Enable()
{
  if (this->Enabled)
    {
    return;
    }

  // set up the event handling
  // specify which events we want to hear about
  OSStatus   err = noErr;
  EventTypeSpec viewEventList[] = {
    { kEventClassControl, kEventControlDraw },
    { kEventClassControl, kEventControlBoundsChanged },
  };

  EventTypeSpec windowEventList[] = {
    { kEventClassMouse, kEventMouseDown },
    { kEventClassMouse, kEventMouseUp },
    { kEventClassMouse, kEventMouseMoved },
    { kEventClassMouse, kEventMouseDragged },
    { kEventClassMouse, kEventMouseWheelMoved },
    { kEventClassKeyboard, kEventRawKeyDown },
    { kEventClassKeyboard, kEventRawKeyRepeat },
    { kEventClassKeyboard, kEventRawKeyUp },
    { kEventClassKeyboard, kEventRawKeyModifiersChanged },
  };

  this->WindowProcUPP = NewEventHandlerUPP(myWinEvtHndlr);
  this->ViewProcUPP = NewEventHandlerUPP(myWinEvtHndlr);
  if (!this->WindowProcUPP || !ViewProcUPP)
    {
    err = memFullErr;
    }

  if (!err)
    {
    vtkCarbonRenderWindow* renWin =
      static_cast<vtkCarbonRenderWindow*>(this->RenderWindow);

    err = InstallControlEventHandler(
      renWin->GetWindowId(), this->ViewProcUPP,
      GetEventTypeCount(viewEventList), viewEventList, renWin, NULL);

    err = InstallWindowEventHandler(
      renWin->GetRootWindow(), this->WindowProcUPP,
      GetEventTypeCount(windowEventList), windowEventList, renWin, NULL);
    }

  // Create a timer for checking when mouse is outside window
  this->LastMouseDelta[0] = 0;
  this->LastMouseDelta[1] = 0;
  this->MouseInsideWindow = 0;
  this->MouseButtonDown    = 0;
  EventLoopRef       mainLoop = GetMainEventLoop();
  EventLoopTimerUPP  timerUPP = NewEventLoopTimerUPP(vtkCarbonLeaveCheck);
  InstallEventLoopTimer(mainLoop,
                        100*kEventDurationMillisecond,
                        100*kEventDurationMillisecond,
                        timerUPP,
                        this,
                        (EventLoopTimerRef *)&this->LeaveCheckId);

#ifdef VTK_USE_TDX
  if(this->UseTDx)
    {
    this->Device->SetInteractor(this);
    this->Device->Initialize();
    }
#endif

  this->Enabled = 1;
  this->Modified();
}

//--------------------------------------------------------------------------
void vtkCarbonRenderWindowInteractor::Disable()
{
  if (!this->Enabled)
    {
    return;
    }

#ifdef VTK_USE_TDX
  if(this->Device->GetInitialized())
    {
    this->Device->Close();
    }
#endif

  if (this->LeaveCheckId)
    {
    RemoveEventLoopTimer((EventLoopTimerRef)this->LeaveCheckId);
    this->LeaveCheckId = 0;
    }
  this->Enabled = 0;
  this->Modified();
}

//--------------------------------------------------------------------------
void vtkCarbonRenderWindowInteractor::TerminateApp(void)
{
  QuitApplicationEventLoop();
}

//--------------------------------------------------------------------------
pascal void vtkCarbonTimerAction(EventLoopTimerRef platformTimerId,
                                 void* userData)
{
  if (NULL != userData)
    {
    vtkCarbonRenderWindowInteractor *rwi =
      static_cast<vtkCarbonRenderWindowInteractor *>(userData);
    int timerId = rwi->GetVTKTimerId((int)platformTimerId);
    rwi->InvokeEvent(vtkCommand::TimerEvent, (void *)&timerId);
    }
}

//--------------------------------------------------------------------------
int vtkCarbonRenderWindowInteractor::InternalCreateTimer(
  int vtkNotUsed(timerId), int timerType, unsigned long duration)
{
  EventLoopTimerRef  platformTimerId;
  EventLoopRef       mainLoop = GetMainEventLoop();
  EventLoopTimerUPP  timerUPP = NewEventLoopTimerUPP(vtkCarbonTimerAction);
  EventTimerInterval interval = 0;

  // Carbon's InstallEventLoopTimer can create either one-shot or repeating
  // timers... interval == 0 indicates a one-shot timer.

  if (RepeatingTimer == timerType)
    {
    interval = duration*kEventDurationMillisecond;
    }

  InstallEventLoopTimer(mainLoop,
                        duration*kEventDurationMillisecond,
                        interval,
                        timerUPP,
                        this,
                        &platformTimerId);

  return (int) platformTimerId;
}

//--------------------------------------------------------------------------
int vtkCarbonRenderWindowInteractor::InternalDestroyTimer(int platformTimerId)
{
  RemoveEventLoopTimer((EventLoopTimerRef) platformTimerId);
  return 1;
}

//--------------------------------------------------------------------------
// Specify the default function to be called when an interactor needs to exit.
// This callback is overridden by an instance ExitMethod that is defined.
void vtkCarbonRenderWindowInteractor::SetClassExitMethod(void (*f)(void *),
                                                         void *arg)
{
  if (f != vtkCarbonRenderWindowInteractor::ClassExitMethod
      || arg != vtkCarbonRenderWindowInteractor::ClassExitMethodArg)
    {
    // delete the current arg if there is a delete method
    if ((vtkCarbonRenderWindowInteractor::ClassExitMethodArg) &&
        (vtkCarbonRenderWindowInteractor::ClassExitMethodArgDelete))
      {
      (*vtkCarbonRenderWindowInteractor::ClassExitMethodArgDelete)
        (vtkCarbonRenderWindowInteractor::ClassExitMethodArg);
      }
    vtkCarbonRenderWindowInteractor::ClassExitMethod = f;
    vtkCarbonRenderWindowInteractor::ClassExitMethodArg = arg;

    // no call to this->Modified() since this is a class member function
    }
}

//--------------------------------------------------------------------------
// Set the arg delete method.  This is used to free user memory.
void
vtkCarbonRenderWindowInteractor::SetClassExitMethodArgDelete(void (*f)(void *))
{
  if (f != vtkCarbonRenderWindowInteractor::ClassExitMethodArgDelete)
    {
    vtkCarbonRenderWindowInteractor::ClassExitMethodArgDelete = f;

    // no call to this->Modified() since this is a class member function
    }
}

//--------------------------------------------------------------------------
void vtkCarbonRenderWindowInteractor::PrintSelf(ostream& os, vtkIndent indent)
{
  vtkRenderWindowInteractor::PrintSelf(os,indent);
}

//--------------------------------------------------------------------------
void vtkCarbonRenderWindowInteractor::ExitCallback()
{
  if (this->HasObserver(vtkCommand::ExitEvent))
    {
    this->InvokeEvent(vtkCommand::ExitEvent,NULL);
    }
  else if (this->ClassExitMethod)
    {
    (*this->ClassExitMethod)(this->ClassExitMethodArg);
    }
  this->TerminateApp();
}