Removed carriage returns.

This commit is contained in:
Pietro Gagliardi 2018-05-29 20:26:48 -04:00
parent 32a83241cb
commit a7fe45b8a5
2 changed files with 311 additions and 311 deletions

View File

@ -1,31 +1,31 @@
#include "uipriv_windows.hpp" #include "uipriv_windows.hpp"
// stubbed out windows image list implementation. // stubbed out windows image list implementation.
// Required for uiTable control, but windows implemenation // Required for uiTable control, but windows implemenation
// doesn't currently have image support. // doesn't currently have image support.
struct uiImage { struct uiImage {
double width; double width;
double height; double height;
// HIMAGELIST images; // HIMAGELIST images;
}; };
uiImage *uiNewImage(double width, double height) uiImage *uiNewImage(double width, double height)
{ {
uiImage *i; uiImage *i;
i = uiprivNew(uiImage); i = uiprivNew(uiImage);
i->width = width; i->width = width;
i->height = height; i->height = height;
return i; return i;
} }
void uiFreeImage(uiImage *i) void uiFreeImage(uiImage *i)
{ {
uiprivFree(i); uiprivFree(i);
} }
void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride) void uiImageAppend(uiImage *i, void *pixels, int pixelWidth, int pixelHeight, int pixelStride)
{ {
// not implemented // not implemented
} }

View File

@ -1,280 +1,280 @@
#include "uipriv_windows.hpp" #include "uipriv_windows.hpp"
struct uiTableModel { struct uiTableModel {
uiTableModelHandler *mh; uiTableModelHandler *mh;
std::vector<uiTable *> tables; std::vector<uiTable *> tables;
}; };
struct uiTableColumn { struct uiTableColumn {
uiTable *t; uiTable *t;
WCHAR *name; WCHAR *name;
// don't really support parts (but this would part=>column mappings if we did) // don't really support parts (but this would part=>column mappings if we did)
int modelColumn; // -1 = none int modelColumn; // -1 = none
}; };
struct uiTable { 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) void *uiTableModelStrdup(const char *str)
{ {
return strdup(str); return strdup(str);
} }
void *uiTableModelGiveColor(double r, double g, double b, double a) void *uiTableModelGiveColor(double r, double g, double b, double a)
{ {
return 0; // not implemented return 0; // not implemented
} }
uiTableModel *uiNewTableModel(uiTableModelHandler *mh) uiTableModel *uiNewTableModel(uiTableModelHandler *mh)
{ {
uiTableModel *m; uiTableModel *m;
m = new uiTableModel(); m = new uiTableModel();
m->mh = mh; m->mh = mh;
return m; return m;
} }
void uiFreeTableModel(uiTableModel *m) void uiFreeTableModel(uiTableModel *m)
{ {
delete m; delete m;
} }
void uiTableModelRowInserted(uiTableModel *m, int newIndex) void uiTableModelRowInserted(uiTableModel *m, int newIndex)
{ {
LVITEMW item; LVITEMW item;
ZeroMemory(&item, sizeof (LVITEMW)); ZeroMemory(&item, sizeof (LVITEMW));
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()");
} }
void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand) void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand)
{ {
uiTable *t = c->t; uiTable *t = c->t;
int lvIndex = 0; int lvIndex = 0;
LVCOLUMNW lvc; LVCOLUMNW lvc;
if (c->modelColumn >= 0) if (c->modelColumn >= 0)
return; // multiple parts not implemented return; // multiple parts not implemented
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)
lvIndex++; lvIndex++;
} }
ZeroMemory(&lvc, sizeof (LVCOLUMNW)); ZeroMemory(&lvc, sizeof (LVCOLUMNW));
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; /* | LVCF_SUBITEM; */ lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT; /* | LVCF_SUBITEM; */
lvc.fmt = LVCFMT_LEFT; lvc.fmt = LVCFMT_LEFT;
lvc.cx = 120; // TODO lvc.cx = 120; // TODO
lvc.pszText = c->name; lvc.pszText = c->name;
if (SendMessageW(c->t->hwnd, LVM_INSERTCOLUMN, (WPARAM) lvIndex, (LPARAM) (&lvc)) == (LRESULT) (-1)) if (SendMessageW(c->t->hwnd, LVM_INSERTCOLUMN, (WPARAM) lvIndex, (LPARAM) (&lvc)) == (LRESULT) (-1))
logLastError(L"error calling LVM_INSERTCOLUMN in uiTableColumnPartSetTextPart()"); logLastError(L"error calling LVM_INSERTCOLUMN in uiTableColumnPartSetTextPart()");
} }
void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand) void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand)
{ {
// not implemented // not implemented
} }
void uiTableColumnAppendButtonPart(uiTableColumn *c, int modelColumn, int expand) void uiTableColumnAppendButtonPart(uiTableColumn *c, int modelColumn, int expand)
{ {
// not implemented // not implemented
} }
void uiTableColumnAppendCheckboxPart(uiTableColumn *c, int modelColumn, int expand) void uiTableColumnAppendCheckboxPart(uiTableColumn *c, int modelColumn, int expand)
{ {
// not implemented // not implemented
} }
void uiTableColumnAppendProgressBarPart(uiTableColumn *c, int modelColumn, int expand) void uiTableColumnAppendProgressBarPart(uiTableColumn *c, int modelColumn, int expand)
{ {
// not implemented // not implemented
} }
void uiTableColumnPartSetEditable(uiTableColumn *c, int part, int editable) void uiTableColumnPartSetEditable(uiTableColumn *c, int part, int editable)
{ {
// TODO // TODO
} }
void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn) void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn)
{ {
// not implemented // not implemented
} }
// uiTable implementation // uiTable implementation
uiWindowsControlAllDefaultsExceptDestroy(uiTable) uiWindowsControlAllDefaultsExceptDestroy(uiTable)
uiTableColumn *uiTableAppendColumn(uiTable *t, const char *name) uiTableColumn *uiTableAppendColumn(uiTable *t, const char *name)
{ {
uiTableColumn *c; uiTableColumn *c;
c = uiprivNew(uiTableColumn); c = uiprivNew(uiTableColumn);
c->name = toUTF16(name); c->name = toUTF16(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;
} }
void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn) void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn)
{ {
// not implemented // not implemented
} }
static void uiTableDestroy(uiControl *c) static void uiTableDestroy(uiControl *c)
{ {
uiTable *t = uiTable(c); uiTable *t = uiTable(c);
uiTableModel *model = t->model; uiTableModel *model = t->model;
std::vector<uiTable *>::iterator it; std::vector<uiTable *>::iterator it;
uiWindowsUnregisterWM_NOTIFYHandler(t->hwnd); uiWindowsUnregisterWM_NOTIFYHandler(t->hwnd);
uiWindowsEnsureDestroyWindow(t->hwnd); uiWindowsEnsureDestroyWindow(t->hwnd);
// detach table from model // detach table from model
for (it = model->tables.begin(); it != model->tables.end(); it++) { for (it = model->tables.begin(); it != model->tables.end(); it++) {
if (*it == t) { if (*it == t) {
model->tables.erase(it); model->tables.erase(it);
break; break;
} }
} }
// 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) t->columns.~vector<uiTableColumn *>(); // (created with placement new, so just call dtor directly)
uiFreeControl(uiControl(t)); uiFreeControl(uiControl(t));
} }
// suggested listview sizing from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing: // suggested listview sizing from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing:
// "columns widths that avoid truncated data x an integral number of items" // "columns widths that avoid truncated data x an integral number of items"
// Don't think that'll cut it when some cells have overlong data (eg // Don't think that'll cut it when some cells have overlong data (eg
// stupidly long URLs). So for now, just hardcode a minimum. // stupidly long URLs). So for now, just hardcode a minimum.
// TODO: Investigate using LVM_GETHEADER/HDM_LAYOUT here... // TODO: Investigate using LVM_GETHEADER/HDM_LAYOUT here...
#define tableMinWidth 107 /* in line with other controls */ #define tableMinWidth 107 /* in line with other controls */
#define tableMinHeight (14*3) /* header + 2 lines (roughly) */ #define tableMinHeight (14*3) /* header + 2 lines (roughly) */
static void uiTableMinimumSize(uiWindowsControl *c, int *width, int *height) static void uiTableMinimumSize(uiWindowsControl *c, int *width, int *height)
{ {
uiTable *t = uiTable(c); uiTable *t = uiTable(c);
uiWindowsSizing sizing; uiWindowsSizing sizing;
int x, y; int x, y;
x = tableMinWidth; x = tableMinWidth;
y = tableMinHeight; y = tableMinHeight;
uiWindowsGetSizing(t->hwnd, &sizing); uiWindowsGetSizing(t->hwnd, &sizing);
uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y); uiWindowsSizingDlgUnitsToPixels(&sizing, &x, &y);
*width = x; *width = x;
*height = y; *height = y;
} }
static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult) static BOOL onWM_NOTIFY(uiControl *c, HWND hwnd, NMHDR *nmhdr, LRESULT *lResult)
{ {
uiTable *t = uiTable(c); uiTable *t = uiTable(c);
uiTableModelHandler *mh = t->model->mh; uiTableModelHandler *mh = t->model->mh;
BOOL ret = FALSE; BOOL ret = FALSE;
switch (nmhdr->code) { switch (nmhdr->code) {
case LVN_GETDISPINFO: case LVN_GETDISPINFO:
{ {
NMLVDISPINFOW *di; NMLVDISPINFOW *di;
LVITEMW *item; LVITEMW *item;
int row, col; int row, col;
uiTableColumn *tc; uiTableColumn *tc;
int mcol; int mcol;
uiTableModelColumnType typ; uiTableModelColumnType typ;
di = (NMLVDISPINFOW *)nmhdr; di = (NMLVDISPINFOW *)nmhdr;
item = &(di->item); item = &(di->item);
if (!(item->mask & LVIF_TEXT)) if (!(item->mask & LVIF_TEXT))
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[col];
mcol = tc->modelColumn; mcol = tc->modelColumn;
typ = (*mh->ColumnType)(mh, t->model, mcol); typ = (*mh->ColumnType)(mh, t->model, mcol);
if (typ == uiTableModelColumnString) { if (typ == uiTableModelColumnString) {
void* data; void* data;
int n; int n;
data = (*(mh->CellValue))(mh, t->model, row, mcol); data = (*(mh->CellValue))(mh, t->model, row, mcol);
n = MultiByteToWideChar(CP_UTF8, 0, (const char *)data, -1, item->pszText, item->cchTextMax); n = MultiByteToWideChar(CP_UTF8, 0, (const char *)data, -1, item->pszText, item->cchTextMax);
// make sure clipped strings are nul-terminated // make sure clipped strings are nul-terminated
if (n >= item->cchTextMax) if (n >= item->cchTextMax)
item->pszText[item->cchTextMax-1] = L'\0'; item->pszText[item->cchTextMax-1] = L'\0';
} else if (typ == uiTableModelColumnInt) { } else if (typ == uiTableModelColumnInt) {
char buf[32]; char buf[32];
intptr_t data; intptr_t data;
int n; int n;
data = (intptr_t)(*(mh->CellValue))(mh, t->model, row, mcol); data = (intptr_t)(*(mh->CellValue))(mh, t->model, row, mcol);
sprintf(buf, "%d", (int)data); sprintf(buf, "%d", (int)data);
n = MultiByteToWideChar(CP_UTF8, 0, buf, -1, item->pszText, item->cchTextMax); n = MultiByteToWideChar(CP_UTF8, 0, buf, -1, item->pszText, item->cchTextMax);
// make sure clipped strings are nul-terminated // make sure clipped strings are nul-terminated
if (n >= item->cchTextMax) if (n >= item->cchTextMax)
item->pszText[item->cchTextMax-1] = L'\0'; item->pszText[item->cchTextMax-1] = L'\0';
} else } else
item->pszText[0] = L'\0'; item->pszText[0] = L'\0';
break; break;
} }
} }
*lResult = 0; *lResult = 0;
return ret; return ret;
} }
uiTable *uiNewTable(uiTableModel *model) uiTable *uiNewTable(uiTableModel *model)
{ {
uiTable *t; uiTable *t;
int n; int n;
uiWindowsNewControl(uiTable, t); uiWindowsNewControl(uiTable, t);
new(&t->columns) std::vector<uiTableColumn *>(); // (initialising in place) new(&t->columns) std::vector<uiTableColumn *>(); // (initialising in place)
t->model = model; t->model = model;
t->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE, t->hwnd = uiWindowsEnsureCreateControlHWND(WS_EX_CLIENTEDGE,
WC_LISTVIEW, L"", WC_LISTVIEW, L"",
LVS_REPORT | LVS_OWNERDATA | LVS_SINGLESEL | WS_TABSTOP | WS_HSCROLL | WS_VSCROLL, LVS_REPORT | LVS_OWNERDATA | LVS_SINGLESEL | WS_TABSTOP | WS_HSCROLL | WS_VSCROLL,
hInstance, NULL, hInstance, NULL,
TRUE); TRUE);
model->tables.push_back(t); model->tables.push_back(t);
uiWindowsRegisterWM_NOTIFYHandler(t->hwnd, onWM_NOTIFY, uiControl(t)); uiWindowsRegisterWM_NOTIFYHandler(t->hwnd, onWM_NOTIFY, uiControl(t));
// TODO: try LVS_EX_AUTOSIZECOLUMNS // TODO: try LVS_EX_AUTOSIZECOLUMNS
SendMessageW(t->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, SendMessageW(t->hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE,
(WPARAM) (LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP), (WPARAM) (LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP),
(LPARAM) (LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP)); (LPARAM) (LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP));
n = (*(model->mh->NumRows))(model->mh, model); n = (*(model->mh->NumRows))(model->mh, model);
if (SendMessageW(t->hwnd, LVM_SETITEMCOUNT, (WPARAM) n, 0) == 0) if (SendMessageW(t->hwnd, LVM_SETITEMCOUNT, (WPARAM) n, 0) == 0)
logLastError(L"error calling LVM_SETITEMCOUNT in uiNewTable()"); logLastError(L"error calling LVM_SETITEMCOUNT in uiNewTable()");
return t; return t;
} }