Drop mixing of C and C++ class allocations, including placement new. This is the easiest change I can make to the Windows table code for now...

This commit is contained in:
Pietro Gagliardi 2018-06-07 22:54:01 -04:00
parent 7a40bdfb3f
commit 0adad7743a
1 changed files with 17 additions and 24 deletions

View File

@ -2,7 +2,7 @@
struct uiTableModel { struct uiTableModel {
uiTableModelHandler *mh; uiTableModelHandler *mh;
std::vector<uiTable *> tables; std::vector<uiTable *> *tables;
}; };
struct uiTableColumn { struct uiTableColumn {
@ -16,31 +16,23 @@ struct uiTable {
uiWindowsControl c; uiWindowsControl c;
uiTableModel *model; uiTableModel *model;
HWND hwnd; HWND hwnd;
std::vector<uiTableColumn *> columns; std::vector<uiTableColumn *> *columns;
}; };
void *uiTableModelStrdup(const char *str)
{
return strdup(str);
}
void *uiTableModelGiveColor(double r, double g, double b, double a)
{
return 0; // not implemented
}
uiTableModel *uiNewTableModel(uiTableModelHandler *mh) uiTableModel *uiNewTableModel(uiTableModelHandler *mh)
{ {
uiTableModel *m; uiTableModel *m;
m = new uiTableModel(); m = uiprivNew(uiTableModel);
m->mh = mh; m->mh = mh;
m->tables = new std::vector<uiTable *>;
return m; return m;
} }
void uiFreeTableModel(uiTableModel *m) void uiFreeTableModel(uiTableModel *m)
{ {
delete m; delete m->tables;
uiprivFree(m);
} }
void uiTableModelRowInserted(uiTableModel *m, int newIndex) void uiTableModelRowInserted(uiTableModel *m, int newIndex)
@ -51,21 +43,21 @@ void uiTableModelRowInserted(uiTableModel *m, int newIndex)
item.mask = 0; item.mask = 0;
item.iItem = newIndex; item.iItem = newIndex;
item.iSubItem = 0; item.iSubItem = 0;
for (auto t : m->tables) for (auto t : *(m->tables))
if (SendMessageW(t->hwnd, LVM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1)) if (SendMessageW(t->hwnd, LVM_INSERTITEM, 0, (LPARAM) (&item)) == (LRESULT) (-1))
logLastError(L"error calling LVM_INSERTITEM in uiTableModelRowInserted()"); logLastError(L"error calling LVM_INSERTITEM in uiTableModelRowInserted()");
} }
void uiTableModelRowChanged(uiTableModel *m, int index) void uiTableModelRowChanged(uiTableModel *m, int index)
{ {
for (auto t : m->tables) for (auto t : *(m->tables))
if (SendMessageW(t->hwnd, LVM_UPDATE, (WPARAM) index, 0) == (LRESULT) (-1)) if (SendMessageW(t->hwnd, LVM_UPDATE, (WPARAM) index, 0) == (LRESULT) (-1))
logLastError(L"error calling LVM_UPDATE in uiTableModelRowChanged()"); logLastError(L"error calling LVM_UPDATE in uiTableModelRowChanged()");
} }
void uiTableModelRowDeleted(uiTableModel *m, int oldIndex) void uiTableModelRowDeleted(uiTableModel *m, int oldIndex)
{ {
for (auto t : m->tables) for (auto t : *(m->tables))
if (SendMessageW(t->hwnd, LVM_DELETEITEM, (WPARAM) oldIndex, 0) == (LRESULT) (-1)) if (SendMessageW(t->hwnd, LVM_DELETEITEM, (WPARAM) oldIndex, 0) == (LRESULT) (-1))
logLastError(L"error calling LVM_DELETEITEM in uiTableModelRowDeleted()"); logLastError(L"error calling LVM_DELETEITEM in uiTableModelRowDeleted()");
} }
@ -81,7 +73,7 @@ void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand)
c->modelColumn = modelColumn; c->modelColumn = modelColumn;
// work out appropriate listview index for the column // work out appropriate listview index for the column
for (auto candidate : t->columns) { for (auto candidate : *(t->columns)) {
if (candidate == c) if (candidate == c)
break; break;
if (candidate->modelColumn >= 0) if (candidate->modelColumn >= 0)
@ -140,7 +132,7 @@ uiTableColumn *uiTableAppendColumn(uiTable *t, const char *name)
c->t = t; c->t = t;
c->modelColumn = -1; // -1 = unassigned c->modelColumn = -1; // -1 = unassigned
// we defer the actual ListView_InsertColumn call until a part is added... // we defer the actual ListView_InsertColumn call until a part is added...
t->columns.push_back(c); t->columns->push_back(c);
return c; return c;
} }
@ -165,11 +157,11 @@ static void uiTableDestroy(uiControl *c)
} }
} }
// free the columns // free the columns
for (auto col : t->columns) { for (auto col : *(t->columns)) {
uiprivFree(col->name); uiprivFree(col->name);
uiprivFree(col); uiprivFree(col);
} }
t->columns.~vector<uiTableColumn *>(); // (created with placement new, so just call dtor directly) delete t->columns;
uiFreeControl(uiControl(t)); uiFreeControl(uiControl(t));
} }
@ -217,9 +209,9 @@ static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
break; break;
row = item->iItem; row = item->iItem;
col = item->iSubItem; col = item->iSubItem;
if (col < 0 || col >= (int)t->columns.size()) if (col < 0 || col >= (int)t->columns->size())
break; break;
tc = (uiTableColumn *)t->columns[col]; tc = (uiTableColumn *)t->columns->at(col);
mcol = tc->modelColumn; mcol = tc->modelColumn;
typ = (*mh->ColumnType)(mh, t->model, mcol); typ = (*mh->ColumnType)(mh, t->model, mcol);
@ -247,7 +239,8 @@ uiTable *uiNewTable(uiTableModel *model)
int n; int n;
uiWindowsNewControl(uiTable, t); uiWindowsNewControl(uiTable, t);
new(&t->columns) std::vector<uiTableColumn *>(); // (initialising in place)
t->columns = new std::vector<uiTableColumn *>;
t->model = model; t->model = model;
t->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, t->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
WC_LISTVIEW, L"", WC_LISTVIEW, L"",