Check that a widget is a child of its Fl_Grid parent

... when assigning it to a cell. This is required for consistency.
This commit is contained in:
Albrecht Schlosser 2023-10-19 19:23:59 +02:00
parent 0fc3f7cd92
commit 450248d20e
1 changed files with 9 additions and 1 deletions

View File

@ -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_)