From 450248d20e8827665a901a02c344ad435aea336d Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 19 Oct 2023 19:23:59 +0200 Subject: Check that a widget is a child of its Fl_Grid parent ... when assigning it to a cell. This is required for consistency. --- src/Fl_Grid.cxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Fl_Grid.cxx b/src/Fl_Grid.cxx index 66991345d..2952badc3 100644 --- a/src/Fl_Grid.cxx +++ b/src/Fl_Grid.cxx @@ -773,6 +773,9 @@ Fl_Grid::Cell *Fl_Grid::widget(Fl_Widget *wi, int row, int col, Fl_Grid_Align al assigned to another widget that widget is deassigned but kept as a child of the group. + Before you can assign a widget to a cell it must have been created as + a child of the Fl_Grid widget (i.e. its Fl_Group). + \param[in] wi widget to be assigned to the cell \param[in] row row \param[in] col column @@ -781,10 +784,15 @@ Fl_Grid::Cell *Fl_Grid::widget(Fl_Widget *wi, int row, int col, Fl_Grid_Align al \param[in] align widget alignment inside the cell \return assigned cell - \retval NULL if \p row or \p col is out of bounds + \retval NULL if \p row or \p col is out of bounds or \p wi is not a child */ Fl_Grid::Cell *Fl_Grid::widget(Fl_Widget *wi, int row, int col, int rowspan, int colspan, Fl_Grid_Align align) { + int child = Fl_Group::find(wi); // is this widget one of our children? + if (child >= children()) { + // fprintf(stderr, "Fl_Grid::widget(): can't assign widget %p to cell (%d, %d): not a child!\n", wi, row, col); + return 0; + } if (row < 0 || row > rows_) return 0; if (col < 0 || col > cols_) -- cgit v1.2.3