comparison libgui/graphics/Figure.cc @ 31757:02f6b7e64ac8

protect against dereferencing null pointer in Qt graphics Figure class * Figure.cc: Check pointer to Canvas object before use.
author John W. Eaton <jwe@octave.org>
date Wed, 18 Jan 2023 16:07:10 -0500
parents 6973fe71f6c5
children 21f9b34eb893
comparison
equal deleted inserted replaced
31756:eb32cf98eed1 31757:02f6b7e64ac8
158 158
159 // Figure title 159 // Figure title
160 update (figure::properties::ID_NUMBERTITLE); 160 update (figure::properties::ID_NUMBERTITLE);
161 161
162 // Decide what keyboard events we listen to 162 // Decide what keyboard events we listen to
163 m_container->canvas (m_handle)->setEventMask (0); 163 Canvas *canvas = m_container->canvas (m_handle);
164 if (canvas)
165 canvas->setEventMask (0);
164 update (figure::properties::ID_KEYPRESSFCN); 166 update (figure::properties::ID_KEYPRESSFCN);
165 update (figure::properties::ID_KEYRELEASEFCN); 167 update (figure::properties::ID_KEYRELEASEFCN);
166 168
167 // modal style 169 // modal style
168 update (figure::properties::ID_WINDOWSTYLE); 170 update (figure::properties::ID_WINDOWSTYLE);
438 else // "auto" 440 else // "auto"
439 showFigureStatusBar (fp.menubar_is ("figure")); 441 showFigureStatusBar (fp.menubar_is ("figure"));
440 break; 442 break;
441 443
442 case figure::properties::ID_KEYPRESSFCN: 444 case figure::properties::ID_KEYPRESSFCN:
443 if (fp.get_keypressfcn ().isempty ()) 445 {
444 m_container->canvas (m_handle)->clearEventMask (Canvas::KeyPress); 446 Canvas *canvas = m_container->canvas (m_handle);
445 else 447
446 m_container->canvas (m_handle)->addEventMask (Canvas::KeyPress); 448 if (canvas)
447 // Signal the change to uipanels as well 449 {
448 for (auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ()) 450 if (fp.get_keypressfcn ().isempty ())
449 { 451 canvas->clearEventMask (Canvas::KeyPress);
450 if (qobj->objectName () == "UIPanel") 452 else
451 { 453 canvas->addEventMask (Canvas::KeyPress);
452 Object *obj = Object::fromQObject (qobj); 454 }
453 455
454 if (obj) 456 // Signal the change to uipanels as well
455 { 457 for (auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
456 if (fp.get_keypressfcn ().isempty ()) 458 {
457 obj->innerContainer ()->canvas (m_handle)-> 459 if (qobj->objectName () == "UIPanel")
458 clearEventMask (Canvas::KeyPress); 460 {
459 else 461 Object *obj = Object::fromQObject (qobj);
460 obj->innerContainer ()->canvas (m_handle)-> 462
461 addEventMask (Canvas::KeyPress); 463 if (obj)
462 } 464 {
463 } 465 if (fp.get_keypressfcn ().isempty ())
464 } 466 obj->innerContainer ()->canvas (m_handle)->
467 clearEventMask (Canvas::KeyPress);
468 else
469 obj->innerContainer ()->canvas (m_handle)->
470 addEventMask (Canvas::KeyPress);
471 }
472 }
473 }
474 }
465 break; 475 break;
466 476
467 case figure::properties::ID_KEYRELEASEFCN: 477 case figure::properties::ID_KEYRELEASEFCN:
468 if (fp.get_keyreleasefcn ().isempty ()) 478 {
469 m_container->canvas (m_handle)->clearEventMask (Canvas::KeyRelease); 479 Canvas *canvas = m_container->canvas (m_handle);
470 else 480
471 m_container->canvas (m_handle)->addEventMask (Canvas::KeyRelease); 481 if (canvas)
472 break; 482 {
473 // Signal the change to uipanels as well 483 if (fp.get_keyreleasefcn ().isempty ())
474 for (auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ()) 484 canvas->clearEventMask (Canvas::KeyRelease);
475 { 485 else
476 if (qobj->objectName () == "UIPanel") 486 canvas->addEventMask (Canvas::KeyRelease);
477 { 487 }
478 Object *obj = Object::fromQObject (qobj); 488 break;
479 489 // Signal the change to uipanels as well
480 if (obj) 490 for (auto *qobj : qWidget<QWidget> ()->findChildren<QObject *> ())
481 { 491 {
482 if (fp.get_keypressfcn ().isempty ()) 492 if (qobj->objectName () == "UIPanel")
483 obj->innerContainer ()->canvas (m_handle)-> 493 {
484 clearEventMask (Canvas::KeyRelease); 494 Object *obj = Object::fromQObject (qobj);
485 else 495
486 obj->innerContainer ()->canvas (m_handle)-> 496 if (obj)
487 addEventMask (Canvas::KeyRelease); 497 {
488 } 498 if (fp.get_keypressfcn ().isempty ())
489 } 499 obj->innerContainer ()->canvas (m_handle)->
490 } 500 clearEventMask (Canvas::KeyRelease);
501 else
502 obj->innerContainer ()->canvas (m_handle)->
503 addEventMask (Canvas::KeyRelease);
504 }
505 }
506 }
507 }
491 break; 508 break;
492 509
493 case figure::properties::ID_WINDOWSTYLE: 510 case figure::properties::ID_WINDOWSTYLE:
494 if (fp.windowstyle_is ("modal")) 511 if (fp.windowstyle_is ("modal"))
495 { 512 {
517 534
518 case figure::properties::ID_POINTER: 535 case figure::properties::ID_POINTER:
519 case figure::properties::ID_POINTERSHAPEHOTSPOT: 536 case figure::properties::ID_POINTERSHAPEHOTSPOT:
520 case figure::properties::ID___MOUSE_MODE__: 537 case figure::properties::ID___MOUSE_MODE__:
521 case figure::properties::ID___ZOOM_MODE__: 538 case figure::properties::ID___ZOOM_MODE__:
522 m_container->canvas (m_handle)->setCursor (mouseMode (), 539 {
523 fp.get_pointer (), 540 Canvas *canvas = m_container->canvas (m_handle);
524 m_pointer_cdata, 541
525 fp.get_pointershapehotspot () 542 if (canvas)
526 .matrix_value()); 543 canvas->setCursor (mouseMode (), fp.get_pointer (),
544 m_pointer_cdata,
545 fp.get_pointershapehotspot ().matrix_value());
546 }
527 break; 547 break;
528 548
529 default: 549 default:
530 break; 550 break;
531 } 551 }
888 void 908 void
889 Figure::enableMouseTracking (void) 909 Figure::enableMouseTracking (void)
890 { 910 {
891 // Enable mouse tracking on every widgets 911 // Enable mouse tracking on every widgets
892 m_container->setMouseTracking (true); 912 m_container->setMouseTracking (true);
893 m_container->canvas (m_handle)->qWidget ()->setMouseTracking (true); 913
914 Canvas *canvas = m_container->canvas (m_handle);
915
916 if (canvas)
917 canvas->qWidget ()->setMouseTracking (true);
918
894 for (auto *w : m_container->findChildren<QWidget *> ()) 919 for (auto *w : m_container->findChildren<QWidget *> ())
895 w->setMouseTracking (true); 920 w->setMouseTracking (true);
896 } 921 }
897 922
898 OCTAVE_END_NAMESPACE(octave) 923 OCTAVE_END_NAMESPACE(octave)