diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-10-19 19:23:59 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-10-19 19:23:59 +0200 |
| commit | 450248d20e8827665a901a02c344ad435aea336d (patch) | |
| tree | 63d6f5e92523cf7e5eb1c8bce4d4b95edf59744e /src/Fl_Grid.cxx | |
| parent | 0fc3f7cd9245ac12f3cd2ad93e339d82f52a2413 (diff) | |
Check that a widget is a child of its Fl_Grid parent
... when assigning it to a cell. This is required for consistency.
Diffstat (limited to 'src/Fl_Grid.cxx')
| -rw-r--r-- | src/Fl_Grid.cxx | 10 |
1 files changed, 9 insertions, 1 deletions
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_) |
