diff --git a/uppsrc/GridCtrl/GridBase.cpp b/uppsrc/GridCtrl/GridBase.cpp index fdcc40daf..b326538ba 100644 --- a/uppsrc/GridCtrl/GridBase.cpp +++ b/uppsrc/GridCtrl/GridBase.cpp @@ -7,13 +7,15 @@ int GridCtrl::ItemRect::sortMode; /*---------------------------------------------------*/ -void GridCtrl::Item::SetCtrl(Ctrl& c) +void GridCtrl::Item::SetCtrl(Ctrl& c, bool owned) { ctrl = &c; ctrl->Hide(); ctrl->SetFrame(NullFrame()); ctrl->WantFocus(); - ctrl_flag = IC_MANUAL | IC_INIT; + ctrl_flag = IC_INIT | IC_MANUAL; + if(owned) + ctrl_flag |= IC_OWNED; } void GridCtrl::Item::ClearCtrl() diff --git a/uppsrc/GridCtrl/GridCtrl.cpp b/uppsrc/GridCtrl/GridCtrl.cpp index a394d36d3..f0b0f8914 100644 --- a/uppsrc/GridCtrl/GridCtrl.cpp +++ b/uppsrc/GridCtrl/GridCtrl.cpp @@ -2690,8 +2690,36 @@ void GridCtrl::Set(const Vector &v, int data_offset /* = 0*/, int column_ void GridCtrl::SetCtrl(int r, int c, Ctrl& ctrl) { - GetItem(r + fixed_rows, c + fixed_cols).SetCtrl(ctrl); + r += fixed_rows; + c += fixed_cols; + GetItem(r, c).SetCtrl(ctrl, false); ++genr_ctrls; + SyncCtrls(r, c); +} + +void GridCtrl::SetCtrl(int r, int c, Ctrl* ctrl) +{ + r += fixed_rows; + c += fixed_cols; + GetItem(r, c).SetCtrl(*ctrl, true); + ++genr_ctrls; + SyncCtrls(r, c); +} + +void GridCtrl::SetCtrl(int c, Ctrl& ctrl) +{ + c += fixed_cols; + GetItem(rowidx, c).SetCtrl(ctrl, false); + ++genr_ctrls; + SyncCtrls(rowidx, c); +} + +void GridCtrl::SetCtrl(int c, Ctrl* ctrl) +{ + c += fixed_cols; + GetItem(rowidx, c).SetCtrl(*ctrl, true); + ++genr_ctrls; + SyncCtrls(rowidx, c); } void GridCtrl::ClearCtrl(int r, int c) @@ -4658,15 +4686,18 @@ void GridCtrl::UpdateCtrls(int opt /*= UC_CHECK_VIS | UC_SHOW | UC_CURSOR | UC_F popup.Close(); } -void GridCtrl::SyncCtrls(int row) +void GridCtrl::SyncCtrls(int row, int col) { - if(!genr_ctrls) + if(!genr_ctrls || !ready) return; Size sz = GetSize(); int js = row < 0 ? 0 : row; int je = row < 0 ? total_rows : row + 1; + + int is = col < 0 ? 1 : col; + int ie = col < 0 ? total_cols : col + 1; for(int j = js; j < je; j++) { @@ -4674,7 +4705,7 @@ void GridCtrl::SyncCtrls(int row) bool fixed_row = j < fixed_rows; bool create_row = !fixed_row && vitems[j].editable; - for(int i = 1; i < total_cols; i++) + for(int i = is; i < ie; i++) { bool fixed_col = i < fixed_cols; bool create_col = !fixed_col && hitems[i].editable; @@ -4696,7 +4727,7 @@ void GridCtrl::SyncCtrls(int row) One newctrl; edits[idx].factory(newctrl); it->ctrl = newctrl.Detach(); - it->ctrl_flag = IC_FACTORY | IC_INIT; + it->ctrl_flag = IC_FACTORY | IC_INIT | IC_OWNED; } if(it->ctrl && (it->ctrl_flag & IC_INIT)) diff --git a/uppsrc/GridCtrl/GridCtrl.h b/uppsrc/GridCtrl/GridCtrl.h index 4f3e9f15f..051bde9ac 100644 --- a/uppsrc/GridCtrl/GridCtrl.h +++ b/uppsrc/GridCtrl/GridCtrl.h @@ -347,7 +347,8 @@ class GridCtrl : public Ctrl { IC_INIT = BIT(1), IC_MANUAL = BIT(2), - IC_FACTORY = BIT(3) + IC_FACTORY = BIT(3), + IC_OWNED = BIT(4) }; struct CurState @@ -420,11 +421,11 @@ class GridCtrl : public Ctrl } ~Item() { - if(!(ctrl_flag & IC_MANUAL)) + if(ctrl_flag & IC_OWNED) delete ctrl; } - void SetCtrl(Ctrl& ctrl); + void SetCtrl(Ctrl& ctrl, bool owned); void ClearCtrl(); void SetDisplay(GridDisplay& display); @@ -1239,6 +1240,10 @@ class GridCtrl : public Ctrl void Set(const Vector &v, int data_offset = 0, int column_offset = 0); void SetCtrl(int r, int c, Ctrl& ctrl); + void SetCtrl(int r, int c, Ctrl* ctrl); + void SetCtrl(int c, Ctrl& ctrl); + void SetCtrl(int c, Ctrl* ctrl); + void ClearCtrl(int r, int c); void SetCtrlValue(int r, int c, const Value &val); void SetCtrlValue(int c, const Value &val); @@ -1606,7 +1611,7 @@ class GridCtrl : public Ctrl bool ShowNextCtrl(); bool ShowPrevCtrl(); public: - void SyncCtrls(int r = -1); + void SyncCtrls(int r = -1, int c = -1); private: void UpdateCtrls(int opt = UC_CHECK_VIS | UC_SHOW | UC_CURSOR | UC_FOCUS); void SyncSummary();