Mercurial > hg > octave-nkf
comparison src/DLD-FUNCTIONS/fltk_backend.cc @ 10517:9cdd6c8c05a4
[mq]: fltk_cb
author | Shai Ayal <shaiay@users.sourceforge.net> |
---|---|
date | Tue, 13 Apr 2010 20:26:08 +0300 |
parents | 65d5776379c3 |
children | f88e3d5d88e2 |
comparison
equal
deleted
inserted
replaced
10516:f0266ee4aabe | 10517:9cdd6c8c05a4 |
---|---|
216 | 216 |
217 class plot_window : public Fl_Window | 217 class plot_window : public Fl_Window |
218 { | 218 { |
219 public: | 219 public: |
220 plot_window (int _x, int _y, int _w, int _h, figure::properties& _fp) | 220 plot_window (int _x, int _y, int _w, int _h, figure::properties& _fp) |
221 : Fl_Window (_x, _y, _w, _h, "octave"), fp (_fp) | 221 : Fl_Window (_x, _y, _w, _h, "octave"), fp (_fp), shift (0) |
222 { | 222 { |
223 callback (window_close, static_cast<void*> (this)); | 223 callback (window_close, static_cast<void*> (this)); |
224 | 224 |
225 begin (); | 225 begin (); |
226 { | 226 { |
321 private: | 321 private: |
322 // window name -- this must exists for the duration of the window's | 322 // window name -- this must exists for the duration of the window's |
323 // life | 323 // life |
324 std::string window_label; | 324 std::string window_label; |
325 | 325 |
326 // Mod keys status | |
327 int shift; | |
328 | |
326 // Figure properties. | 329 // Figure properties. |
327 figure::properties& fp; | 330 figure::properties& fp; |
328 | 331 |
329 // Status area height. | 332 // Status area height. |
330 static const int status_h = 20; | 333 static const int status_h = 20; |
447 | 450 |
448 status->value (cbuf.str ().c_str ()); | 451 status->value (cbuf.str ().c_str ()); |
449 status->redraw (); | 452 status->redraw (); |
450 } | 453 } |
451 | 454 |
455 void set_currentpoint (int px, int py) | |
456 { | |
457 Matrix pos (1,2,0); | |
458 pos(0) = px; | |
459 pos(1) = h () - status_h - py; | |
460 fp.set_currentpoint (pos); | |
461 } | |
462 | |
463 void set_axes_currentpoint (graphics_object ax, int px, int py) | |
464 { | |
465 axes::properties& ap = | |
466 dynamic_cast<axes::properties&> (ax.get_properties ()); | |
467 | |
468 double x, y; | |
469 pixel2pos (ax, px, py, x, y); | |
470 | |
471 Matrix pos (2,3,0); | |
472 pos(0,0) = x; | |
473 pos(1,0) = y; | |
474 pos(0,1) = x; | |
475 pos(1,1) = y; | |
476 | |
477 ap.set_currentpoint (pos); | |
478 } | |
479 | |
480 int key2shift (int key) | |
481 { | |
482 if (key == FL_Shift_L || key == FL_Shift_R) | |
483 return FL_SHIFT; | |
484 | |
485 if (key == FL_Control_L || key == FL_Control_R) | |
486 return FL_CTRL; | |
487 | |
488 if (key == FL_Alt_L || key == FL_Alt_R) | |
489 return FL_ALT; | |
490 | |
491 if (key == FL_Meta_L || key == FL_Meta_R) | |
492 return FL_META; | |
493 | |
494 return 0; | |
495 } | |
496 | |
497 int key2ascii (int key) | |
498 { | |
499 if (key < 256) return key; | |
500 if (key == FL_Tab) return '\t'; | |
501 if (key == FL_Enter) return 0x0a; | |
502 if (key == FL_BackSpace) return 0x08; | |
503 if (key == FL_Escape) return 0x1b; | |
504 | |
505 return 0; | |
506 } | |
507 | |
508 Cell modifier2cell () | |
509 { | |
510 string_vector mod; | |
511 | |
512 if (shift & FL_SHIFT) | |
513 mod.append (std::string ("shift")); | |
514 if (shift & FL_CTRL) | |
515 mod.append (std::string ("control")); | |
516 if (shift & FL_ALT || shift & FL_META) | |
517 mod.append (std::string ("alt")); | |
518 | |
519 return Cell (mod); | |
520 } | |
521 | |
452 void resize (int _x,int _y,int _w,int _h) | 522 void resize (int _x,int _y,int _w,int _h) |
453 { | 523 { |
454 Fl_Window::resize (_x, _y, _w, _h); | 524 Fl_Window::resize (_x, _y, _w, _h); |
455 | 525 |
456 Matrix pos (1,4,0); | 526 Matrix pos (1,4,0); |
473 int handle (int event) | 543 int handle (int event) |
474 { | 544 { |
475 static int px0,py0; | 545 static int px0,py0; |
476 static graphics_object ax0; | 546 static graphics_object ax0; |
477 | 547 |
478 | |
479 int retval = Fl_Window::handle (event); | 548 int retval = Fl_Window::handle (event); |
480 | 549 |
481 // We only handle events which are in the canvas area. | 550 // We only handle events which are in the canvas area. |
482 if (Fl::event_y () >= h() - status_h) | 551 if (Fl::event_y () >= h() - status_h) |
483 return retval; | 552 return retval; |
484 | 553 |
485 switch (event) | 554 switch (event) |
486 { | 555 { |
487 case FL_KEYDOWN: | 556 case FL_KEYDOWN: |
488 switch(Fl::event_key ()) | 557 { |
489 { | 558 int key = Fl::event_key (); |
490 case 'a': | 559 |
491 case 'A': | 560 shift |= key2shift (key); |
492 axis_auto (); | 561 int key_a = key2ascii (key); |
562 if (key_a && fp.get_keypressfcn ().is_defined ()) | |
563 { | |
564 Octave_map evt; | |
565 evt.assign ("Character", octave_value (key_a)); | |
566 evt.assign ("Key", octave_value (std::tolower (key_a))); | |
567 evt.assign ("Modifier", octave_value (modifier2cell ())); | |
568 fp.execute_keypressfcn (evt); | |
569 } | |
570 switch (key) | |
571 { | |
572 case 'a': | |
573 case 'A': | |
574 axis_auto (); | |
493 break; | 575 break; |
494 | 576 |
495 case 'g': | 577 case 'g': |
496 case 'G': | 578 case 'G': |
497 toggle_grid (); | 579 toggle_grid (); |
498 break; | 580 break; |
499 } | 581 } |
582 } | |
583 break; | |
584 | |
585 case FL_KEYUP: | |
586 { | |
587 int key = Fl::event_key (); | |
588 | |
589 shift &= (~key2shift (key)); | |
590 int key_a = key2ascii (key); | |
591 if (key_a && fp.get_keyreleasefcn ().is_defined ()) | |
592 { | |
593 Octave_map evt; | |
594 evt.assign ("Character", octave_value (key_a)); | |
595 evt.assign ("Key", octave_value (std::tolower (key_a))); | |
596 evt.assign ("Modifier", octave_value (modifier2cell ())); | |
597 fp.execute_keyreleasefcn (evt); | |
598 } | |
599 } | |
500 break; | 600 break; |
501 | 601 |
502 case FL_MOVE: | 602 case FL_MOVE: |
503 pixel2status (pixel2axes_or_ca (Fl::event_x (), Fl::event_y ()), | 603 pixel2status (pixel2axes_or_ca (Fl::event_x (), Fl::event_y ()), |
504 Fl::event_x (), Fl::event_y ()); | 604 Fl::event_x (), Fl::event_y ()); |
505 break; | 605 break; |
506 | 606 |
507 case FL_PUSH: | 607 case FL_PUSH: |
608 px0 = Fl::event_x (); | |
609 py0 = Fl::event_y (); | |
610 ax0 = gh_manager::get_object (pixel2axes_or_ca (px0, py0)); | |
611 | |
612 set_currentpoint (Fl::event_x (), Fl::event_y ()); | |
613 set_axes_currentpoint (ax0, px0, py0); | |
614 fp.execute_windowbuttondownfcn (); | |
615 | |
616 | |
508 if (Fl::event_button () == 1 || Fl::event_button () == 3) | 617 if (Fl::event_button () == 1 || Fl::event_button () == 3) |
509 { | 618 return 1; |
510 px0 = Fl::event_x (); | |
511 py0 = Fl::event_y (); | |
512 ax0 = gh_manager::get_object (pixel2axes_or_ca (px0, py0)); | |
513 return 1; | |
514 } | |
515 break; | 619 break; |
516 | 620 |
517 case FL_DRAG: | 621 case FL_DRAG: |
518 pixel2status (ax0, px0, py0, Fl::event_x (), Fl::event_y ()); | 622 pixel2status (ax0, px0, py0, Fl::event_x (), Fl::event_y ()); |
623 if (fp.get_windowbuttonmotionfcn ().is_defined ()) | |
624 { | |
625 set_currentpoint (Fl::event_x (), Fl::event_y ()); | |
626 fp.execute_windowbuttonmotionfcn (); | |
627 } | |
628 | |
519 if (Fl::event_button () == 1) | 629 if (Fl::event_button () == 1) |
520 { | 630 { |
521 if (ax0 && ax0.isa ("axes")) | 631 if (ax0 && ax0.isa ("axes")) |
522 { | 632 { |
523 axes::properties& ap = | 633 axes::properties& ap = |
571 } | 681 } |
572 } | 682 } |
573 return 1; | 683 return 1; |
574 | 684 |
575 case FL_RELEASE: | 685 case FL_RELEASE: |
686 if (fp.get_windowbuttonupfcn ().is_defined ()) | |
687 { | |
688 set_currentpoint (Fl::event_x (), Fl::event_y ()); | |
689 fp.execute_windowbuttonupfcn (); | |
690 } | |
691 | |
576 if (Fl::event_button () == 1) | 692 if (Fl::event_button () == 1) |
577 { | 693 { |
578 if ( Fl::event_clicks () == 1) | 694 if ( Fl::event_clicks () == 1) |
579 { | 695 { |
580 if (ax0 && ax0.isa ("axes")) | 696 if (ax0 && ax0.isa ("axes")) |