Skip to content

Commit 82971e3

Browse files
committed
0.10.0.33: Type hinting in Schema Explorer table editor
1 parent d51ee31 commit 82971e3

3 files changed

Lines changed: 53 additions & 14 deletions

File tree

src/sqlite-ce-edit/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ BOOL WINAPI GetSaveFileNameW(CE_OPENFILENAME*);
8787
** Version
8888
**============================================================================*/
8989

90-
#define SQLITECEDIT_VERSION L"0.10.0.31"
90+
#define SQLITECEDIT_VERSION L"0.10.0.33"
9191

9292
/*============================================================================
9393
** Menu IDs

src/sqlite-ce-edit/grid.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,10 +353,43 @@ void GridFindNext(void) {
353353
MessageBoxW(g_hwndMain, L"Text not found.", L"Find", MB_OK);
354354
}
355355

356+
/* Build placeholder hint for column: (auto), (TYPE null), (TYPE req), (TYPE) */
357+
static void GetPlaceholderHint(int col, wchar_t *buf, int buflen) {
358+
ColumnMeta *cm;
359+
const char *t;
360+
wchar_t *p = buf;
361+
wchar_t *end = buf + buflen - 1;
362+
363+
if (col >= g_colMetaCount) { buf[0] = '\0'; return; }
364+
cm = &g_colMeta[col];
365+
366+
if (cm->isAutoInc) {
367+
lstrcpyW(buf, L"(auto)");
368+
return;
369+
}
370+
371+
*p++ = '(';
372+
t = cm->type;
373+
/* Shorten INTEGER to INT */
374+
if (t[0]=='I' && t[1]=='N' && t[2]=='T' && t[3]=='E' && t[4]=='G' && t[5]=='E' && t[6]=='R' && t[7]=='\0') {
375+
*p++ = 'I'; *p++ = 'N'; *p++ = 'T';
376+
} else {
377+
while (*t && p < end - 6) *p++ = (wchar_t)*t++;
378+
}
379+
/* Add null/req suffix */
380+
if (!cm->notNull) {
381+
*p++ = ' '; *p++ = 'n'; *p++ = 'u'; *p++ = 'l'; *p++ = 'l';
382+
} else if (!cm->hasDefault) {
383+
*p++ = ' '; *p++ = 'r'; *p++ = 'e'; *p++ = 'q';
384+
}
385+
*p++ = ')'; *p = '\0';
386+
}
387+
356388
void OnGridGetDispInfo(NMLVDISPINFOW *pdi) {
357389
int row, dataRow, col, dataCol;
358390
char *val;
359391
static wchar_t wbuf[256];
392+
static wchar_t hintbuf[32];
360393
int numDisplayCols;
361394

362395
if (!(pdi->item.mask & LVIF_TEXT)) return;
@@ -380,18 +413,9 @@ void OnGridGetDispInfo(NMLVDISPINFOW *pdi) {
380413
MultiByteToWideChar(CP_ACP, 0, g_pendingValues[col], -1, wbuf, 256);
381414
pdi->item.pszText = wbuf;
382415
}
383-
} else if (col < g_colMetaCount) {
384-
ColumnMeta *cm = &g_colMeta[col];
385-
if (cm->isAutoInc) {
386-
pdi->item.pszText = L"(auto)";
387-
} else if (!cm->notNull && !cm->hasDefault) {
388-
/* Nullable without default - will be NULL if not filled */
389-
pdi->item.pszText = L"(null)";
390-
} else {
391-
pdi->item.pszText = L"";
392-
}
393416
} else {
394-
pdi->item.pszText = L"";
417+
GetPlaceholderHint(col, hintbuf, 32);
418+
pdi->item.pszText = hintbuf;
395419
}
396420
return;
397421
}
@@ -509,8 +533,8 @@ void PopulateGrid(void) {
509533
if (hdc) {
510534
SIZE sz;
511535
int hintWidth, curWidth;
512-
const wchar_t *hint = g_colMeta[j].isAutoInc ? L"(auto)" :
513-
(!g_colMeta[j].notNull ? L"(null)" : L"");
536+
wchar_t hint[32];
537+
GetPlaceholderHint(j, hint, 32);
514538
GetTextExtentPoint32W(hdc, hint, lstrlenW(hint), &sz);
515539
hintWidth = sz.cx + 12; /* padding */
516540
curWidth = ListView_GetColumnWidth(g_hwndGrid, j);

src/sqlite-ce-edit/main.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,21 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
483483
OnGridDoubleClick(pnmlv->iItem, pnmlv->iSubItem);
484484
return 0;
485485
}
486+
/* Custom draw for placeholder row grey text */
487+
if (pnm->hwndFrom == g_hwndGrid && pnm->code == NM_CUSTOMDRAW) {
488+
NMLVCUSTOMDRAW *pcd = (NMLVCUSTOMDRAW*)lParam;
489+
switch (pcd->nmcd.dwDrawStage) {
490+
case CDDS_PREPAINT:
491+
return CDRF_NOTIFYITEMDRAW;
492+
case CDDS_ITEMPREPAINT:
493+
/* Grey text for placeholder row */
494+
if (g_editMode && (int)pcd->nmcd.dwItemSpec == g_lastResultRows) {
495+
pcd->clrText = GetSysColor(COLOR_GRAYTEXT);
496+
}
497+
return CDRF_DODEFAULT;
498+
}
499+
return CDRF_DODEFAULT;
500+
}
486501
/* Header double-click to auto-size column */
487502
if (pnm->code == HDN_ITEMDBLCLICKW || pnm->code == HDN_ITEMDBLCLICKA) {
488503
NMHEADERW *phdr = (NMHEADERW*)lParam;

0 commit comments

Comments
 (0)