~ubuntu-branches/ubuntu/karmic/fltk1.1/karmic

« back to all changes in this revision

Viewing changes to src/Fl.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-05-22 13:57:06 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050522135706-mchag24yf42lu7bu
Tags: 1.1.6-5
* Revert previous change, which seems to have been ineffective for some
  reason, in favor of commenting out the problematic Makefile rule
  altogether.  (Closes: #310151.)
* debian/control: Go back to specifying the URL as part of the
  description rather than via a non-standard field that doesn't seem to
  have caught on.  (Closes: #310240.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
// "$Id: Fl.cxx,v 1.24.2.41.2.62 2004/04/11 04:38:56 easysw Exp $"
 
2
// "$Id: Fl.cxx,v 1.24.2.41.2.71 2004/11/23 19:50:58 easysw Exp $"
3
3
//
4
4
// Main event handling code for the Fast Light Tool Kit (FLTK).
5
5
//
23
23
// Please report all bugs and problems to "fltk-bugs@fltk.org".
24
24
//
25
25
 
 
26
// warning: the Apple Quartz version still uses some Quickdraw calls,
 
27
//          mostly to get around the single active context in QD and 
 
28
//          to implement clipping. This should be changed into pure
 
29
//          Quartz calls in the near future.
 
30
 
26
31
#include <FL/Fl.H>
27
32
#include <FL/Fl_Window.H>
28
33
#include <FL/x.H>
31
36
#include <stdlib.h>
32
37
#include "flstring.h"
33
38
 
 
39
#ifdef DEBUG
 
40
#  include <stdio.h>
 
41
#endif // DEBUG
 
42
 
34
43
 
35
44
//
36
45
// Globals...
227
236
static char in_idle;
228
237
 
229
238
double Fl::wait(double time_to_wait) {
 
239
  do_widget_deletion();
 
240
 
230
241
  if (first_timeout) {
231
242
    elapse_timeouts();
232
243
    Timeout *t;
317
328
Fl_Window* fl_find(Window xid) {
318
329
  Fl_X *window;
319
330
  for (Fl_X **pp = &Fl_X::first; (window = *pp); pp = &window->next)
320
 
#ifdef __APPLE__
 
331
#ifdef __APPLE_QD__
 
332
    if (window->xid == xid && !window->w->window()) {
 
333
#elif defined(__APPLE_QUARTZ__)
321
334
    if (window->xid == xid && !window->w->window()) {
322
335
#else
323
336
    if (window->xid == xid) {
368
381
 
369
382
#ifdef WIN32
370
383
  GdiFlush();
371
 
#elif defined (__APPLE__)
372
 
  GrafPtr port; GetPort( &port );
373
 
  if ( port ) 
374
 
  {
 
384
#elif defined(__APPLE_QD__)
 
385
  GrafPtr port;
 
386
  GetPort( &port );
 
387
  if ( port )
375
388
    QDFlushPortBuffer( port, 0 );
376
 
  }
 
389
#elif defined (__APPLE_QUARTZ__)
 
390
  if (fl_gc)
 
391
    CGContextFlush(fl_gc);
377
392
#else
378
393
  if (fl_display) XFlush(fl_display);
379
394
#endif
473
488
// X says the focus or mouse window have changed.
474
489
 
475
490
void fl_fix_focus() {
 
491
#ifdef DEBUG
 
492
  puts("fl_fix_focus();");
 
493
#endif // DEBUG
476
494
 
477
495
  if (Fl::grab()) return; // don't do anything while grab is on.
478
496
 
526
544
// desirable behavior and caused flwm to crash.
527
545
 
528
546
void fl_throw_focus(Fl_Widget *o) {
 
547
#ifdef DEBUG
 
548
  printf("fl_throw_focus(o=%p)\n", o);
 
549
#endif // DEBUG
 
550
 
529
551
  if (o->contains(Fl::pushed())) Fl::pushed_ = 0;
530
552
#ifndef WIN32
531
553
  if (o->contains(fl_selection_requestor)) fl_selection_requestor = 0;
585
607
    return 1;
586
608
 
587
609
  case FL_PUSH:
 
610
#ifdef DEBUG
 
611
    printf("Fl::handle(e=%d, window=%p);\n", e, window);
 
612
#endif // DEBUG
 
613
 
588
614
    if (grab()) wi = grab();
589
615
    else if (modal() && wi != modal()) return 0;
590
616
    pushed_ = wi;
622
648
    if (grab()) wi = grab();
623
649
    {Fl_Widget* pbm = belowmouse();
624
650
    int ret = (wi && send(e, wi, window));
625
 
    if (pbm != belowmouse()) Fl_Tooltip::enter(belowmouse());
 
651
    if (pbm != belowmouse()) {
 
652
#ifdef DEBUG
 
653
      printf("Fl::handle(e=%d, window=%p);\n", e, window);
 
654
#endif // DEBUG
 
655
      Fl_Tooltip::enter(belowmouse());
 
656
    }
626
657
    return ret;}
627
658
 
628
659
  case FL_RELEASE: {
648
679
    return 1;
649
680
 
650
681
  case FL_KEYBOARD:
 
682
#ifdef DEBUG
 
683
    printf("Fl::handle(e=%d, window=%p);\n", e, window);
 
684
#endif // DEBUG
 
685
 
651
686
    Fl_Tooltip::enter((Fl_Widget*)0);
652
687
 
653
688
    fl_xfocus = window; // this should not happen!  But maybe it does:
686
721
    return 0;
687
722
 
688
723
  case FL_ENTER:
 
724
#ifdef DEBUG
 
725
    printf("Fl::handle(e=%d, window=%p);\n", e, window);
 
726
#endif // DEBUG
 
727
 
689
728
    fl_xmousewin = window;
690
729
    fl_fix_focus();
691
730
    Fl_Tooltip::enter(belowmouse());
692
731
    return 1;
693
732
 
694
733
  case FL_LEAVE:
 
734
#ifdef DEBUG
 
735
    printf("Fl::handle(e=%d, window=%p);\n", e, window);
 
736
#endif // DEBUG
 
737
 
695
738
    if (!pushed_) {
696
739
      belowmouse(0);
697
740
      Fl_Tooltip::enter(0);
734
777
  for (; *pp != ip; pp = &(*pp)->next) if (!*pp) return;
735
778
  *pp = ip->next;
736
779
 
737
 
#ifdef __APPLE__
 
780
#ifdef __APPLE_QD__
738
781
  // remove all childwindow links
739
782
  for ( Fl_X *pc = Fl_X::first; pc; pc = pc->next )
740
783
  { 
741
784
    if ( pc->xidNext == ip ) pc->xidNext = ip->xidNext;
742
785
    if ( pc->xidChildren == ip ) pc->xidChildren = ip->xidNext;   
743
786
  }
 
787
#elif defined(__APPLE_QUARTZ__)
 
788
  // remove all childwindow links
 
789
  for ( Fl_X *pc = Fl_X::first; pc; pc = pc->next )
 
790
  {
 
791
    if ( pc->xidNext == ip ) pc->xidNext = ip->xidNext;
 
792
    if ( pc->xidChildren == ip ) pc->xidChildren = ip->xidNext;
 
793
  }
744
794
#endif // __APPLE__
745
795
 
746
796
  i = 0;
773
823
    fl_window = (HWND)-1;
774
824
    fl_gc = 0;
775
825
  }
776
 
#elif defined(__APPLE__)
 
826
#elif defined(__APPLE_QD__)
 
827
  if ( ip->xid == fl_window )
 
828
    fl_window = 0;
 
829
#elif defined(__APPLE_QUARTZ__)
 
830
  Fl_X::q_release_context(ip);
777
831
  if ( ip->xid == fl_window )
778
832
    fl_window = 0;
779
833
#else
780
834
  if (ip->region) XDestroyRegion(ip->region);
781
835
#endif
782
836
 
783
 
#ifdef __APPLE__
 
837
#ifdef __APPLE_QD__
 
838
  if ( !parent() ) // don't destroy shared windows!
 
839
  {
 
840
    //+ RemoveTrackingHandler( dndTrackingHandler, ip->xid );
 
841
    //+ RemoveReceiveHandler( dndReceiveHandler, ip->xid );
 
842
    XDestroyWindow(fl_display, ip->xid);
 
843
  }
 
844
#elif defined(__APPLE_QUARTZ__)
784
845
  if ( !parent() ) // don't destroy shared windows!
785
846
  {
786
847
    //+ RemoveTrackingHandler( dndTrackingHandler, ip->xid );
835
896
         Fl_Widget* p = parent(); for (;p->visible();p = p->parent()) {}
836
897
         if (p->type() >= FL_WINDOW) break; // don't do the unmap
837
898
        }
838
 
#ifdef __APPLE__
 
899
#ifdef __APPLE_QD__
839
900
        hide();
840
901
        set_visible();
 
902
#elif defined(__APPLE_QUARTZ__)
 
903
        hide();
 
904
        set_visible();
841
905
#else
842
906
        XUnmapWindow(fl_display, fl_xid(this));
843
907
#endif // __APPLE__
936
1000
  Fl_X* i = Fl_X::i((Fl_Window*)wi);
937
1001
  if (!i) return; // window not mapped, so ignore it
938
1002
 
939
 
  if (X<=0 && Y<=0 && W>=wi->w() && H>=wi->h()) {
940
 
    // if damage covers entire window delete region:
941
 
    wi->damage(fl);
942
 
    return;
943
 
  }
944
 
 
945
1003
  // clip the damage to the window and quit if none:
946
1004
  if (X < 0) {W += X; X = 0;}
947
1005
  if (Y < 0) {H += Y; Y = 0;}
949
1007
  if (H > wi->h()-Y) H = wi->h()-Y;
950
1008
  if (W <= 0 || H <= 0) return;
951
1009
 
 
1010
  if (!X && !Y && W==wi->w() && H==wi->h()) {
 
1011
    // if damage covers entire window delete region:
 
1012
    wi->damage(fl);
 
1013
    return;
 
1014
  }
 
1015
 
952
1016
  if (wi->damage()) {
953
1017
    // if we already have damage we must merge with existing region:
954
1018
    if (i->region) {
956
1020
      Fl_Region R = XRectangleRegion(X, Y, W, H);
957
1021
      CombineRgn(i->region, i->region, R, RGN_OR);
958
1022
      XDestroyRegion(R);
959
 
#elif defined(__APPLE__)
 
1023
#elif defined(__APPLE_QD__)
960
1024
      Fl_Region R = NewRgn(); 
961
1025
      SetRectRgn(R, X, Y, X+W, Y+H);
962
1026
      UnionRgn(R, i->region, i->region);
963
1027
      DisposeRgn(R);
 
1028
#elif defined(__APPLE_QUARTZ__)
 
1029
      Fl_Region R = NewRgn();
 
1030
      SetRectRgn(R, X, Y, X+W, Y+H);
 
1031
      UnionRgn(R, i->region, i->region);
 
1032
      DisposeRgn(R);
964
1033
#else
965
1034
      XRectangle R;
966
1035
      R.x = X; R.y = Y; R.width = W; R.height = H;
984
1053
  draw();
985
1054
}
986
1055
 
987
 
//
988
 
// End of "$Id: Fl.cxx,v 1.24.2.41.2.62 2004/04/11 04:38:56 easysw Exp $".
 
1056
 
 
1057
//
 
1058
// The following methods allow callbacks to schedule the deletion of
 
1059
// widgets at "safe" times.
 
1060
//
 
1061
 
 
1062
static int              num_dwidgets = 0, alloc_dwidgets = 0;
 
1063
static Fl_Widget        **dwidgets = 0;
 
1064
 
 
1065
void
 
1066
Fl::delete_widget(Fl_Widget *w) {
 
1067
  if (!w) return;
 
1068
 
 
1069
  if (num_dwidgets >= alloc_dwidgets) {
 
1070
    Fl_Widget   **temp;
 
1071
 
 
1072
    temp = new Fl_Widget *[alloc_dwidgets + 10];
 
1073
    if (alloc_dwidgets) {
 
1074
      memcpy(temp, dwidgets, alloc_dwidgets * sizeof(Fl_Widget *));
 
1075
      delete[] dwidgets;
 
1076
    }
 
1077
 
 
1078
    dwidgets = temp;
 
1079
    alloc_dwidgets += 10;
 
1080
  }
 
1081
 
 
1082
  dwidgets[num_dwidgets] = w;
 
1083
  num_dwidgets ++;
 
1084
}
 
1085
 
 
1086
 
 
1087
void
 
1088
Fl::do_widget_deletion() {
 
1089
  if (!num_dwidgets) return;
 
1090
 
 
1091
  for (int i = 0; i < num_dwidgets; i ++)
 
1092
    delete dwidgets[i];
 
1093
 
 
1094
  num_dwidgets = 0;
 
1095
}
 
1096
 
 
1097
 
 
1098
//
 
1099
// End of "$Id: Fl.cxx,v 1.24.2.41.2.71 2004/11/23 19:50:58 easysw Exp $".
989
1100
//