31#include "../_TkT2/Defines.h"
33#include "../_TkT2/EasyErrors.h"
34#include "../_TkT2/EasyWin32.h"
35#include "../_TkT2/EasyFiles.h"
36#include "../_TkT2/FormatNumber.h"
37#include "../_TkT2/ProgressBar.h"
38#include "../_TkT2/ReadArchive.h"
39#include "../_TkT2/EasyDecode.h"
40#include "../_TkT2/EasyListView.h"
41#include "../_TkT2/EasyAbout.h"
42#include "../_TkT2/EasyDPI.h"
43#include "../_TkT2/EasyCSV.h"
44#include "../_TkT2/ReadFile.h"
45#include "../_TkT2/EasyString.h"
46#include "../_TkT2/EasyDialog.h"
47#include "../_TkT2/EasyRichEdit.h"
49#include "../_TkT2/ManageSQLite.h"
50#include "../_TkT2/ManageSQLite_Win32.h"
73#define SCROLL_TIMER_ID 1
74#define SCROLL_IDLE_MS 100
100#define DATAVIEW_MAXROWS 100000000
113void SetVisibility(
int project,
int table,
int query __attribute__((unused)))
119 else if (project ==
SHOW)
128 else if (table ==
SHOW)
140 else if (query ==
SHOW)
162 if (tableName && tableName[0])
178 item.mask = TVIF_PARAM | TVIF_TEXT;
181 item.cchTextMax = _countof(text);
186 if (item.lParam == PROJECTTREE_TABLELIST)
196 if (!wcsicmp(tableName, text))
221 int64_t nbItems = -1;
225 int result = SQLITE_OK;
232 if (result == SQLITE_OK)
275 wchar_t buffer[MAX_BUF] = L
"";
276 swprintf(buffer, _countof(buffer), L
"%ls%ls%ls",
277 tableName, tableName[0] ? L
" : " : L
"",
278 formater_nombre(0, records, L
' ', 0, 0));
295 DeleteLocalFile(
SOFT_NAMEW, L
"temp\\" LISTE_FICHIERS);
296 DeleteLocalFile(
SOFT_NAMEW, L
"temp\\old" LISTE_FICHIERS);
299 DeleteLocalDirectory(
SOFT_NAMEW, ARCHIVE_FOLDER);
316 HDC hdc = BeginPaint(hwnd, &ps);
322 GetClientRect(hwnd, &rect);
331 if (IntersectRect(&rPaint, &rect, &ps.rcPaint))
333 FillRect(hdc, &rPaint, GetSysColorBrush(COLOR_BTNFACE));
350 UINT state __attribute__((unused)),
370 if ((UINT)rect.right > width)
381 int bottom = y - rectSB.bottom;
414 int queryHeight = bottom * 1 / 10;
419 bottom - queryHeight,
427 bottom - queryHeight,
432 InvalidateRect(hwnd, NULL, TRUE);
470 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
478 RecreateDialogFont(hwnd, &hFont, VARIABLE_FONT, SIZE_OF_FONT * 2);
479 ApplyFontToChildren(hwnd, hFont);
502 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
518 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
522 case WM_WINDOWPOSCHANGING :
526 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
528 if (!(wp->flags & (SWP_NOSIZE)))
531 GetClientRect(GetParent(hwnd), &r);
534 int bottom = r.bottom - rSB.bottom;
546 wp->cy = bottom - wp->y;
549 SetWindowPos(
hMainQueryError, 0, 0, wp->y, wp->x, wp->cy, SWP_NOSENDCHANGING);
584 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
600 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
604 case WM_WINDOWPOSCHANGING :
608 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
610 if (!(wp->flags & (SWP_NOSIZE)))
613 GetClientRect(GetParent(hwnd), &r);
616 int bottom = r.bottom - rSB.bottom;
637 wp->cy = bottom - wp->y;
675 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
688 WS_CHILD | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | WS_THICKFRAME,
689 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
697 WS_CHILD | WS_BORDER | BS_PUSHBUTTON | BS_TEXT,
698 0, 0, 0, 0, hwnd, (HMENU)
IDM_SQL_QUERY, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
706 WS_CHILD | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY | WS_THICKFRAME,
707 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
728 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT);
730 setlocale(LC_ALL,
"French_France.1252");
738 SetClassLongPtr(hwnd, GCLP_HICON, (LONG_PTR)LoadIcon((HINSTANCE)GetModuleHandle(NULL), L
"mainIcon"));
739 SendMessage(hwnd, WM_SETICON, (WPARAM)LoadIcon((HINSTANCE)GetModuleHandle(NULL), L
"mainIcon"), MAKELPARAM(FALSE, 0));
744 WS_CHILD | WS_VISIBLE,
745 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowInstance(hwnd), NULL);
751 wchar_t *appDir = GetLocalFile(
SOFT_NAMEW, NULL);
759 wchar_t *tmpDir = GetLocalFile(
SOFT_NAMEW, L
"temp");
772 HMENU hMenu = GetMenu(hwnd);
773 HMENU hSubMenu = GetSubMenuByID(hMenu,
IDP_HELP);
774 SetSubMenuIcon(hSubMenu, IDM_ABOUT, L
"mainIcon");
780 ModifyMenu(hMenu, IDM_HELP, MF_BYCOMMAND | MF_STRING, IDM_HELP, L
"\U00002753 " MENU_HELP);
791 PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(
IDM_INIT, 0), (LPARAM) NULL);
807 ShowWindow(hwnd, SW_HIDE);
852 if (rect.right > width)
866 SetWindowPos(
hMainProjectTree, HWND_TOP, 0, 0, width, r.bottom - r.top, SWP_DRAWFRAME);
899 HMENU hMenu = GetSubMenuByID(GetMenu(hwnd),
IDM_PROJECT);
909 EnableMenuItem(GetMenu(hwnd),
IDM_DATA, MF_GRAYED);
910 EnableMenuItem(GetMenu(hwnd),
IDM_SQL, MF_GRAYED);
914 InvalidateRect(hwnd, NULL, TRUE);
930 wchar_t *projectName = calloc(FILENAMELENGTH_MAX,
sizeof(
wchar_t));
961 swprintf(projectName, FILENAMELENGTH_MAX, L
"%ls", newProjectName);
962 free(newProjectName);
972 if ((option ==
IDM_PROJECT_NEW) || (!_waccess(projectName, R_OK | W_OK)))
974 int result = SQLITE_OK;
981 if (result == SQLITE_OK)
1006 int sizeDotCommand = wcslen(L
".open --new ''") + wcslen(GetStrictFileName(
currentDataBaseName)) + 1;
1007 wchar_t *dotCommand = calloc(sizeDotCommand,
sizeof(
wchar_t));
1010 swprintf(dotCommand, sizeDotCommand, L
".open --new \"%ls\"", GetStrictFileName(
currentDataBaseName));
1019 HMENU hMenu = GetSubMenuByID(GetMenu(hwnd),
IDM_PROJECT);
1029 EnableMenuItem(GetMenu(hwnd),
IDM_DATA, MF_ENABLED);
1030 EnableMenuItem(GetMenu(hwnd),
IDM_SQL, MF_ENABLED);
1079 int64_t nbRows = -1;
1081 wchar_t *command = NULL;
1086 HANDLE hProgressBar = StartProgressBar(L
"Ex\351cution du script SQL", -1);
1088 StopProgressBar(hProgressBar);
1114 InvalidateRect(hwnd, NULL, TRUE);
1133 int64_t nbRows = -1;
1136 wchar_t *command = calloc(length + 1,
sizeof(
wchar_t));
1146 HANDLE hProgressBar = StartProgressBar(L
"Ex\351cution de la requ\350te", -1);
1147 wchar_t *firstLetters = AllTrim(command, L
" \t\r\n", TRUE, FALSE, FALSE);
1148 int useTmp = wcsnicmp(firstLetters, L
"SELECT", 6) ? USE_NO_TEMP : USE_TEMP_TABLE;
1150 if ((useTmp & USE_NO_TEMP) && wcsnicmp(firstLetters, L
"PRAGMA", 6))
1160 StopProgressBar(hProgressBar);
1184 InvalidateRect(hwnd, NULL, TRUE);
1206 int64_t nbRows = -1;
1208 static exportation_table_type options;
1210 int okExport = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L
"DialogExport", hwnd,
1211 (DLGPROC)(
void *)ProcedureExport, (LPARAM) &options);
1213 SetForegroundWindow(hwnd);
1217 wchar_t *fileName = FileOutChooserWithInit(L
"Exporter vers un fichier CSV ...", hwnd,
1222 FILE *fileOut = _wfopen(fileName, L
"wt");
1226 char *separator = (
char *)&options.separateur;
1227 char *quote = (
char *)&options.delimiteur;
1229 HANDLE hProgressBar = StartProgressBar(L
"Enregistrement des donn\351es", -1);
1231 StopProgressBar(hProgressBar);
1258 wchar_t *tableName = calloc(MIN_BUF,
sizeof(
wchar_t));
1266 int okTable = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L
"DialogGetInformation", hwnd,
1267 (DLGPROC)(
void *)ProcedureGetInformation, (LPARAM)stringHub);
1271 size_t length = wcslen(tableName) +
sizeof(
"CREATE TABLE \"_\" AS SELECT * FROM_") + wcslen(
APP_VIEWTABLE);
1272 wchar_t *query = calloc(length,
sizeof(
wchar_t));
1276 swprintf(query, length, L
"CREATE TABLE \"%ls\" AS SELECT * FROM %ls", tableName,
APP_VIEWTABLE);
1281 (result == SQLITE_OK) ? NULL :
sqlError);
1291 if (result == SQLITE_OK)
1326 if (tableName && tableName[0] && fileName && fileName[0])
1330 HANDLE hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1332 if (hFile != INVALID_HANDLE_VALUE)
1336 BY_HANDLE_FILE_INFORMATION fileInfo;
1338 if (GetFileInformationByHandle(hFile, &fileInfo))
1342 wchar_t path[MAX_BUF] = L
"";
1343 wchar_t *pathPtr = path;
1347 int level = abs(pathLevel);
1349 swprintf(path,
sizeof(path) /
sizeof(path[0]), L
"%ls", fileName);
1350 pathPtr = wcsrchr(path, L
'\\');
1351 while (pathPtr && level)
1355 pathPtr = wcsrchr(path, L
'\\');
1361 wchar_t nowDate[
sizeof(
"YYYY-MM-DD")] = L
"";
1362 wchar_t nowTime[
sizeof(
"HH:MM:SS")] = L
"";
1364 time_t dateTime = time(NULL);
1366 wcsftime(nowDate,
sizeof(nowDate) /
sizeof(
wchar_t), L
"%Y-%m-%d", localtime(&dateTime));
1367 wcsftime(nowTime,
sizeof(nowTime) /
sizeof(
wchar_t), L
"%H:%M:%S", localtime(&dateTime));
1371 SYSTEMTIME systemTime;
1372 FileTimeToSystemTime(&fileInfo.ftLastWriteTime, &systemTime);
1374 wchar_t *wRecord = calloc(MAX_BUF,
sizeof(
wchar_t));
1378 swprintf(wRecord, MAX_BUF,
1384 L
"'%04d-%02d-%02d',"
1389 pathPtr ? &pathPtr[1] : L
"", GetFileName(fileName),
1390 fileInfo.nFileSizeLow + ((LONGLONG)fileInfo.nFileSizeHigh << 32),
1391 systemTime.wYear, systemTime.wMonth, systemTime.wDay,
1392 systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
1424int RecordExecutedAction(
const wchar_t *action,
const wchar_t *dotCommand,
const wchar_t *query,
const wchar_t *error)
1428 if (action && action[0])
1432 wchar_t nowDate[
sizeof(
"YYYY-MM-DD")] = L
"";
1433 wchar_t nowTime[
sizeof(
"HH:MM:SS")] = L
"";
1435 time_t dateTime = time(NULL);
1437 wcsftime(nowDate,
sizeof(nowDate) /
sizeof(
wchar_t), L
"%Y-%m-%d", localtime(&dateTime));
1438 wcsftime(nowTime,
sizeof(nowTime) /
sizeof(
wchar_t), L
"%H:%M:%S", localtime(&dateTime));
1440 wchar_t *wRecord = calloc(MAX_BUF,
sizeof(
wchar_t));
1444 wchar_t *mAction = (
wchar_t *)action;
1445 WReplaceInStringNoFree(&mAction, L
"'", L
"''");
1447 wchar_t *mDotCommand = (
wchar_t *)dotCommand;
1448 WReplaceInStringNoFree(&mDotCommand, L
"'", L
"''");
1450 wchar_t *mQuery = (
wchar_t *)query;
1451 WReplaceInStringNoFree(&mQuery, L
"'", L
"''");
1453 wchar_t *mError = (
wchar_t *)error;
1454 WReplaceInStringNoFree(&mError, L
"'", L
"''");
1456 swprintf(wRecord, MAX_BUF,
1465 mAction ? mAction : L
"",
1466 mDotCommand ? mDotCommand : L
"",
1467 mQuery ? mQuery : L
"",
1468 mError ? mError : L
"");
1470 if (mAction != action)
1475 if (mDotCommand != dotCommand)
1480 if (mQuery != query)
1485 if (mError != error)
1516 int64_t nbRows = -1;
1518 wchar_t *fileName = FileInChooser(L
"Importer des donn\351es CSV ...", hwnd,
1519 L
"Fichier d\351limit\351 (*.csv;*.tsv;*.del;*.txt)\0*.csv;*.tsv;*.del;*.txt\0"
1520 L
"Tout fichier (*.*)\0*.*\0");
1524 HANDLE hPB = StartProgressBar(L
"Test du fichier ...", -1);
1525 int type = typefil(fileName, FIL_TAB_DEL);
1526 StopProgressBar(hPB);
1530 MessageBox(hwnd, L
"\n Probl\350me de fichier ! \n", L
"Erreur !", MB_ICONINFORMATION);
1534 else if (!(type & FIL_TAB))
1537 L
"\n Ce fichier n'est pas reconnu comme une table par " SOFT_NAMEW L
" ! \n",
1539 MB_ICONINFORMATION);
1546 if (type & FIL_NON & FIL_TAB_DEL)
1548 if (!DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd),
1549 L
"DialogDELTableStructure", hwnd,
1550 (DLGPROC)(
void *)ProcedureDELTableStructure,
1556 SetForegroundWindow(hwnd);
1561 TAB *table = fileopen_TAB(fileName, type);
1565 wchar_t *tableName = calloc(MIN_BUF,
sizeof(
wchar_t));
1569 swprintf(tableName, MIN_BUF, L
"%ls", GetStrictFileName(fileName));
1573 int okTable = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L
"DialogGetInformation", hwnd,
1574 (DLGPROC)(
void *)ProcedureGetInformation, (LPARAM)stringHub);
1578 WReplaceInString(&tableName, L
"'", L
"''");
1580 wchar_t *query = calloc(FILENAMELENGTH_MAX,
sizeof(
wchar_t));
1584 wchar_t *fields = calloc(FILENAMELENGTH_MAX,
sizeof(
wchar_t));
1588 hPB = StartProgressBar(L
"Import des donn\351es CSV ...", -1);
1592 swprintf(query, FILENAMELENGTH_MAX,
1593 L
"CREATE TABLE \"%ls\" ( '%ls' )", tableName,
APP_FIELD);
1599 for (UINT column = 0; column < table->nb_champs; ++ column)
1601 const wchar_t *fieldType = DATA_TEXT;
1603 if (table->champ[column].type == L
'D')
1605 fieldType = DATA_DATETIME;
1608 if (table->champ[column].type == L
'N')
1610 if (table->champ[column].decimales == 0)
1612 fieldType = DATA_INTEGER;
1616 fieldType = DATA_REAL;
1620 wchar_t *fieldName = table->champ[column].nom;
1621 WReplaceInStringNoFree(&fieldName, L
"'", L
"''");
1622 WReplaceInString(&fieldName, L
"\"", L
"\"\"");
1626 swprintf(query, FILENAMELENGTH_MAX,
1627 L
"ALTER TABLE \"%ls\" ADD \"%ls\" %ls",
1628 tableName, fieldName, fieldType);
1632 swprintf(&fields[wcslen(fields)], FILENAMELENGTH_MAX - wcslen(fields),
1633 L
"%ls \"%ls\"", column ? L
"," : L
"", fieldName);
1639 swprintf(query, FILENAMELENGTH_MAX,
1640 L
"ALTER TABLE \"%ls\" DROP COLUMN \"%ls\"", tableName,
APP_FIELD);
1650 swprintf(query, FILENAMELENGTH_MAX,
1651 L
"INSERT INTO \"%ls\" ( %ls ) VALUES ( ", tableName, fields);
1653 size_t initQuery = wcslen(query);
1655 while (fileread_TAB(1, table) == 1)
1657 if (!(nbRows % 100000))
1667 if (ProgressBarStopped())
1674 wchar_t *ptr = table->reg;
1676 for (UINT column = 0; column < table->nb_champs; ++ column)
1678 wchar_t *value = (
wchar_t *)&ptr[table->champ[column].pos];
1679 WReplaceInStringNoFree(&value, L
"'", L
"''");
1680 WReplaceInString(&value, L
"\"", L
"\"\"");
1684 if ((table->champ[column].type == L
'N') && (table->champ[column].decimales > 0))
1686 Replace(value, L
',', L
'.');
1689 swprintf(&query[wcslen(query)], FILENAMELENGTH_MAX - wcslen(query),
1690 L
"%ls '%ls'", column ? L
"," : L
"", value);
1696 swprintf(&query[wcslen(query)], FILENAMELENGTH_MAX - wcslen(query), L
" )");
1698 query[initQuery] = L
'\0';
1700 SetProgressBarTextNum(L
"Lignes import\351es", &nbRows);
1708 StopProgressBar(hPB);
1733 fileclose_TAB(table);
1756 int64_t nbRows = -1;
1758 const wchar_t *command = L
"";
1785 HANDLE hProgressBar = StartProgressBar(L
"Lecture de la table", -1);
1787 StopProgressBar(hProgressBar);
1809 InvalidateRect(hwnd, NULL, TRUE);
1830 const wchar_t *result = NULL;
1836 static wchar_t number[INT_MAXSIZE + 1];
1837 swprintf(number, _countof(number), L
"%lld", line + 1);
1840 else if (column > 0)
1844 line, column - 1, 0);
1869 if (hSelectedTableItem)
1872 item.mask = TVIF_PARAM;
1873 item.hItem = hSelectedTableItem;
1876 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
1878 if (_wcsicmp(oldTableName, newTableName))
1883 if (renameTable == IDYES)
1885 int length = MAX_BUF;
1886 wchar_t *query = calloc(length,
sizeof(
wchar_t));
1890 swprintf(query, length, L
"ALTER TABLE \"%ls\" RENAME TO \"%ls\"", oldTableName, newTableName);
1928 if (hSelectedTableItem)
1930 wchar_t *tableName = calloc(MIN_BUF,
sizeof(
wchar_t));
1936 item.mask = TVIF_TEXT | TVIF_PARAM;
1937 item.pszText = tableName;
1938 item.cchTextMax = MIN_BUF;
1939 item.hItem = hSelectedTableItem;
1942 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
1947 if (deleteTable == IDYES)
1949 int length = MAX_BUF;
1950 wchar_t *query = calloc(length,
sizeof(
wchar_t));
1954 swprintf(query, length, L
"DROP TABLE \"%ls\"", tableName);
1958 (okDelete == SQLITE_OK) ? NULL :
sqlError);
1960 if (okDelete != SQLITE_OK)
1962 swprintf(query, length, L
"DROP VIEW \"%ls\"", tableName);
1966 (okDelete == SQLITE_OK) ? NULL :
sqlError);
2015 DialogBox((HINSTANCE)GetWindowInstance(hwnd), L
"DialogOptions", hwnd, (DLGPROC)(
void *)
ProcedureOptions);
2027 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2040 if (remainingRows < 0)
2047 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2062 CopyInClipBoard(hwnd, text);
2070 if (MessageBox(hwnd, TEXT(
CONVERT_PROJECT), L
"", MB_OKCANCEL) == IDOK)
2097 SetForegroundWindow(hwnd);
2118 SetForegroundWindow(hwnd);
2128 if (hSelectedTableItem)
2131 item.mask = TVIF_PARAM;
2132 item.hItem = hSelectedTableItem;
2135 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2174 HANDLE hPb = StartProgressBar(L
"Optimisation en cours ...", -2);
2176 StopProgressBar(hPb);
2236 POINT pt = {xPos, yPos};
2237 ScreenToClient(hwndContext, &pt);
2246 hMenu = LoadMenu((HINSTANCE)GetWindowInstance(hwnd), L
"ViewMenu");
2250 TVHITTESTINFO tvhti = {0};
2253 TreeView_HitTest(hwndContext, &tvhti);
2255 if (tvhti.flags & TVHT_ONITEM)
2259 item.mask = TVIF_PARAM;
2260 item.hItem = tvhti.hItem;
2263 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2268 TreeView_SelectItem(hwndContext, tvhti.hItem);
2269 hMenu = LoadMenu((HINSTANCE)GetWindowInstance(hwnd), L
"TreeMenu");
2275 RF_ContextMenu(hwnd, hwndContext, xPos, yPos, 1);
2279 RF_ContextMenu(hwnd, hwndContext, xPos, yPos, 0);
2284 static HMENU hPopMenu;
2285 hPopMenu = GetSubMenu(hMenu, 0);
2287 TrackPopupMenuEx(hPopMenu, 0, xPos, yPos, hwnd, NULL);
2311 wchar_t *tableName = calloc(MIN_BUF,
sizeof(
wchar_t));
2322 item.mask = TVIF_TEXT | TVIF_PARAM;
2324 item.pszText = tableName;
2325 item.cchTextMax = MIN_BUF;
2329 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2331 size_t length = wcslen(tableName) +
sizeof(
"SELECT * FROM \"\"");
2332 wchar_t *command = calloc(length,
sizeof(
wchar_t));
2336 swprintf(command, length, L
"SELECT * FROM \"%ls\"", tableName);
2379 static int clrTextBk;
2381 switch (lplvcd->nmcd.dwDrawStage)
2383 case CDDS_PREPAINT :
2385 return CDRF_NOTIFYITEMDRAW;
2388 case CDDS_ITEMPREPAINT :
2390 clrText = lplvcd->clrText;
2391 clrTextBk = lplvcd->clrTextBk;
2393 return CDRF_NOTIFYSUBITEMDRAW;
2396 case CDDS_SUBITEM | CDDS_ITEMPREPAINT :
2402 switch (lplvcd->iSubItem)
2408 UINT dpi = GetWindowDpi(hwnd);
2417 lplvcd->clrText = clrText;
2418 lplvcd->clrTextBk = GetSysColor(COLOR_BTNFACE);
2427 UINT dpi = GetWindowDpi(hwnd);
2428 mainFixedFont = CreateFontForDPI(FIXED_FONT, FW_THIN, SIZE_OF_FONT, dpi);
2436 lplvcd->clrText = clrText;
2437 lplvcd->clrTextBk = clrTextBk;
2443 return CDRF_NEWFONT;
2448 return CDRF_DODEFAULT;
2466 wchar_t *query = calloc(length,
sizeof(
wchar_t));
2475 int nbColumns = Header_GetItemCount(hHeader);
2479 for (
int column = 1; column < nbColumns; ++ column)
2481 wchar_t columnFilter[MIN_BUF] = {0};
2482 wchar_t columnName[MIN_BUF] = {0};
2485 HD_TEXTFILTER htf = {0};
2487 hdi.mask = HDI_FILTER | HDI_TEXT;
2489 hdi.pszText = columnName;
2490 hdi.cchTextMax = _countof(columnName) - 1;
2492 hdi.type = HDFT_ISSTRING;
2495 hdi.pvFilter = &htf;
2497 htf.pszText = columnFilter;
2498 htf.cchTextMax = _countof(columnFilter) - 1;
2500 Header_GetItem(hHeader, column, &hdi);
2502 if (columnFilter[0])
2504 swprintf(&query[wcslen(query)], length - wcslen(query),
2505 L
" %ls \"%ls\" LIKE '%ls'",
2506 (!testColumn) ? L
"WHERE" : L
"AND", columnName, columnFilter);
2565 LPNMLVDISPINFOW lplvdi)
2569 if (lplvdi->item.mask & LVIF_TEXT)
2572 int column = lplvdi->item.iSubItem;
2578 static wchar_t *text;
2583 static wchar_t number[INT_MAXSIZE + 1];
2584 swprintf(number, _countof(number), L
"%lld", line + 1);
2585 text = _wcsdup(number);
2587 else if (column > 0)
2590 Replace(text, L
'\n', L
' ');
2599 if (lplvdi->item.cchTextMax && text && (wcslen(text) >= (
size_t)lplvdi->item.cchTextMax))
2601 text[lplvdi->item.cchTextMax - 1] = L
'\0';
2604 lplvdi->item.pszText = text ? text : L
"";
2610 int columnWidth = ListView_GetColumnWidth(
hMainDataView, column);
2612 const int padding = 16;
2613 if (textWidth + padding > columnWidth)
2615 ListView_SetColumnWidth(
hMainDataView, column, textWidth + padding);
2622 lplvdi->item.pszText = L
"\267\267\267";
2639 int idCtrl __attribute__((unused)),
2644 static wchar_t oldItemText[MIN_BUF];
2650 case TVN_SELCHANGED :
2665 case TVN_BEGINLABELEDIT :
2669 LPNMTVDISPINFO pdi = (LPNMTVDISPINFO)pnmh;
2670 swprintf(oldItemText, MIN_BUF, L
"%ls", (pdi->item.pszText) ? pdi->item.pszText : L
"");
2676 case TVN_ENDLABELEDIT :
2680 LPNMTVDISPINFO pdi = (LPNMTVDISPINFO)pnmh;
2682 if (pdi->item.pszText)
2686 tvi.mask = TVIF_TEXT;
2687 tvi.hItem = pdi->item.hItem;
2688 tvi.pszText = pdi->item.pszText;
2702 case NM_CUSTOMDRAW :
2706 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pnmh;
2714 case LVN_BEGINSCROLL:
2728 case LVN_ODCACHEHINT :
2732 LPNMLVCACHEHINT lplvch = (LPNMLVCACHEHINT)pnmh;
2735 int number = (lplvch->iTo - lplvch->iFrom) + 1;
2746 case LVN_GETDISPINFO :
2750 LPNMLVDISPINFOW lplvdi = (LPNMLVDISPINFOW)pnmh;
2760 case LVN_ODFINDITEM :
2768 case HDN_FILTERBTNCLICK :
2770 LPNMHDFILTERBTNCLICK lphdfi = (LPNMHDFILTERBTNCLICK)pnmh;
2772 HWND hHeader = lphdfi->hdr.hwndFrom;
2781 case HDN_FILTERCHANGE :
2792 case LVN_COLUMNCLICK :
2794 HWND hListView = pnmh->hwndFrom;
2795 LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh;
2797 int column = pnmv->iSubItem;
2798 ListView_SetSelectedColumn(hListView, column);
2808 LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh;
2810 int64_t line = pnmv->iItem;
2811 int column = pnmv->iSubItem;
2817 static wchar_t *text;
2820 text = _wcsdup(value);
2825 HD_TEXTFILTER htf = {0};
2827 hdi.mask = HDI_FILTER;
2828 hdi.pvFilter = &htf;
2831 HWND hHeader = ListView_GetHeader(pnmh->hwndFrom);
2832 Header_SetItem(hHeader, column, &hdi);
2873 case WM_ERASEBKGND :
2875 HDC hdc = (HDC)wParam;
2881 GetClientRect(hwnd, &rect);
2882 FillRect(hdc, &rect, GetSysColorBrush(COLOR_BTNFACE));
2886 FillRect(hdc, &
rDataView, GetSysColorBrush(COLOR_BTNFACE));
2905 if (wParam == NBROWS_TIMER_ID)
2907 int64_t nbRows = VerifierTermine(NULL);
2911 KillTimer(hwnd, NBROWS_TIMER_ID);
2914 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2924 return DefWindowProc(hwnd, uMsg, wParam, lParam);
2944 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
2948 case WM_WINDOWPOSCHANGING :
2952 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
2954 if (!(wp->flags & (SWP_NOSIZE)))
2962 GetClientRect(GetParent(hwnd), &r);
2967 int bottom = r.bottom - rSB.bottom;
2987 SetWindowPos(
hMainDataView, 0, wp->cx, 0, r.right - wp->cx, wp->cy, SWP_NOSENDCHANGING);
3016 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
3032 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
3036 case WM_WINDOWPOSCHANGING :
3040 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
3042 if (!(wp->flags & (SWP_NOSIZE)))
3050 GetClientRect(GetParent(hwnd), &rParent);
3055 int bottom = rParent.bottom - rSB.bottom;
3057 if ((wp->x + wp->cx) < rParent.right)
3059 wp->cx = rParent.right - wp->x;
3074 SetWindowPos(
hMainProjectTree, 0, 0, 0, wp->x, wp->cy, SWP_NOSENDCHANGING);
3103 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
3120int64_t
DataView_Update(HWND hwnd, HWND * pListView, RECT * rListView, sqlite3 **db,
const wchar_t *command,
int useTmp)
3122 int64_t nbRows = -1;
3127 if (db && command && command[0])
3131 int result = SQLITE_OK;
3138 if (result == SQLITE_OK)
3144 DestroyWindow(pListView[0]);
3149 int virtualListView = (useTmp & USE_NO_TEMP) ? 0 : LVS_OWNERDATA;
3150 int listView_styles = LVS_REPORT;
3151 int window_styles = WS_CHILD | WS_THICKFRAME | WS_CLIPSIBLINGS;
3156 pListView[0] = CreateWindowEx(0, WC_LISTVIEW, L
"",
3157 virtualListView | listView_styles | window_styles,
3158 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowInstance(hwnd), NULL);
3160 HWND hListView = pListView[0];
3164 ListView_SetExtendedListViewStyleEx(hListView,
3165 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_DOUBLEBUFFER
3167 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_DOUBLEBUFFER
3168 | LVS_EX_HEADERDRAGDROP | LVS_EX_LABELTIP);
3172 SetWindowPos(hListView,
3176 rListView->right - rListView->left,
3177 rListView->bottom - rListView->top,
3181 (useTmp & USE_NO_TEMP) ? DataView_UpdateAll : DataView_UpdateHeader);
3187 DestroyWindow(hListView);
3188 pListView[0] = NULL;
3219int64_t
DataView_UpdateWithAFile(HWND hwnd, HWND * pListView, RECT * rListView, sqlite3 **db,
wchar_t **command,
const wchar_t *fileName)
3221 int64_t nbRows = -1;
3222 wchar_t *newFileName = NULL;
3228 newFileName = FileInChooser(L
"Lancer un script SQL", hwnd, L
"Script SQL (*.sql)\0*.sql\0");
3231 FILE *fileIn = OpenTextFileIn(
SOFT_NAMEW, fileName ? fileName : newFileName);
3235 _fseeki64(fileIn, 0L, SEEK_END);
3236 _off64_t fileSize = _ftelli64(fileIn);
3237 _fseeki64(fileIn, 0L, SEEK_SET);
3239 wchar_t *sql = calloc(fileSize + 1,
sizeof(
wchar_t));
3243 fread(sql,
sizeof(
wchar_t), fileSize, fileIn);
3247 int result = SQLITE_OK;
3251 wchar_t *projectName = calloc(FILENAMELENGTH_MAX,
sizeof(
wchar_t));
3255 result = OpenSQLiteDB(db, projectName, FALSE);
3260 if (result == SQLITE_OK)
3262 const wchar_t *lastSql = ScriptInDBwithAnswer(db[0], sql);
3264 if (command && lastSql && lastSql[0])
3266 NullFree(command[0]);
3267 command[0] = _wcsdup(lastSql);
3268 nbRows =
DataView_Update(hwnd, pListView, rListView, db, lastSql, USE_NO_TEMP);
3300 LPARAM lParam __attribute__((unused)))
3306 case WM_INITDIALOG :
3310 RecreateDialogFont(hwnd, &hFont, VARIABLE_FONT, SIZE_OF_FONT);
3317 switch (LOWORD(wParam))
3325 DeleteObject(hFont);
3338 DeleteObject(hFont);
#define OPTION_CURRENTPROJECT
définitions relatives au fichier des options
#define APP_VIEWTABLE
définitions spéciales propres à Taupie
void Main_OnContextMenu(HWND hwnd, HWND hwndContext, short int xPos, short int yPos)
Gestion du menu contextuel.
int Main_OnNotify_DrawDataView(HWND hwnd, LPNMLVCUSTOMDRAW lplvcd)
Redessine sur demande le listview (police, couleur, fond).
static LVHITTESTINFO selectedCellInfo
int64_t ProjectTree_Update(HWND hwnd)
Crée un TreeView à partir du contenu de la base courante, et l'affiche aux bonnes dimensions.
int64_t DataView_Update(HWND hwnd, HWND *pListView, RECT *rListView, sqlite3 **db, const wchar_t *command, int useTmp)
Crée un ListView à partir d'une commande SQL, et l'affiche aux bonnes dimensions.
static HWND hMainStatusBar
static int64_t dataViewNbRows
void Main_OnClose(HWND hwnd)
Supprime les fichiers temporaires et ferme l'application.
const wchar_t * GetCellValue(int64_t line, int column)
Fonction permettant de récupérer le texte d'une cellule sélectionnée.
void Main_OnSize(HWND hwnd, UINT state, UINT x, UINT y)
Gestion d'un changement de taille de la fenêtre principale.
static wchar_t * currentDataBaseName
void QueryBar_Update(const wchar_t *errorMsg, const wchar_t *request)
Définit le contenu de la QueryBar.
static HFONT mainFixedBlackFont
int RecordExecutedAction(const wchar_t *action, const wchar_t *dotCommand, const wchar_t *query, const wchar_t *error)
Enregistrement dans l'historique d'une action de l'utilisateur.
LRESULT CALLBACK QueryEdit_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
sous-procédure spécifique de la fenêtre d'écriture de requête.
BOOL Main_OnNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
Gestion des notifications des composants de la fenêtre principale.
static HTREEITEM hActualSelectedTableItem
static wchar_t * originalCommand
int Main_OnNotify_FillDataView(HWND hwnd, LPNMLVDISPINFOW lplvdi)
remplissage des items du DataView à la demande.
void QueryBar_Create(HWND hwnd)
Création de l'espace de saisie des requêtes.
void ProjectTree_Open(HWND hwnd, int option)
Ouvre/crée un projet Taupie.
LRESULT CALLBACK Main_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure de la fenêtre principale.
static wchar_t * sqlError
static wchar_t * currentSelectedTable
void ProjectTree_Close(HWND hwnd)
Ferme le projet courant Taupie.
void DataView_Close(HWND hwnd)
Ferme la table sélectionnée dans le ProjectTree.
void ProjectTree_Enlarge(void)
redimensionne en largeur le ProjectTree.
int64_t ExecuteCustomSQLQuery(HWND hwnd)
Exécute une requête demandée par l'utilisateur.
int64_t ExecuteSQLScript(HWND hwnd, const wchar_t *fileName)
Exécute une requête demandée par l'utilisateur.
static HWND hMainQueryExecute
void RestartScrollingTimer(HWND hwnd)
Relance la temporisation du DataView.
BOOL Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
Initialisation de la fenêtre principale.
int64_t CreateCSVFromView(HWND hwnd)
Crée un fichier CSV à partir de la vue courante.
void Main_OnPaint(HWND hwnd)
redessine la boîte de dialogue.
void Clean(void)
Supprime les fichiers temporaires de l'application.
int CreateTableFromView(HWND hwnd)
Crée une table dans la base à partir de la vue courante.
int ProjectTree_DeleteTable(HWND hwnd)
Supprime une table dans l'arbre du projet.
static HWND hMainProjectTree
int ProjectTree_SelectTableByName(const wchar_t *tableName)
Recherche et sélectionne dans l'arbre du projet une table identifiée par son nom. Limite la recherche...
int64_t ProjectTree_ViewAppTable(HWND hwnd, int id)
Affiche une table "système", non présente dans l'arbre du projet.
void SetVisibility(int project, int table, int query)
définit la visibilité des trois composants de l'écran.
static HWND hMainQueryEdit
int64_t DataView_UpdateWithAFile(HWND hwnd, HWND *pListView, RECT *rListView, sqlite3 **db, wchar_t **command, const wchar_t *fileName)
static int freezeDataView
LRESULT CALLBACK ProcedureOptions(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure du dialogue des options de ModuleTicket.
static HFONT mainFixedFont
int ProjectTree_RenameTable(HWND hwnd, const wchar_t *oldTableName, const wchar_t *newTableName)
Renomme une table dans l'arbre du projet.
static wchar_t * currentCommand
void StatusBar_Update(const wchar_t *tableName, int64_t records)
Définit le contenu de la barre de statut principale.
LRESULT CALLBACK QueryExecute_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
sous-procédure spécifique du bouton de lancement de la requête.
static UINT_PTR scrollingTimer
static HWND hMainQueryError
static sqlite3 * currentDataBase
LRESULT CALLBACK DataView_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
sous-procédure spécifique de la vue des données (DataView).
LRESULT CALLBACK ProjectTree_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
sous-procédure spécifique de la vue du projet (TreeView).
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
Gère les commandes de l'application.
void Main_OnNotify_ApplyFilter(HWND hwnd, HWND hHeader)
Application du filtre courant à la vue courante des données.
void ProjectTree_ViewSelectedTable(HWND hwnd, HTREEITEM hItem)
Gère la sélection d'une table dans l'arbre du projet.
static HWND hMainDataView
int64_t CreateTableFromCSV(HWND hwnd)
Crée une table dans la base courante à partir d'un fichier CSV.
LRESULT CALLBACK QueryError_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
sous-procédure spécifique de la fenêtre d'affichage de requête.
int RecordImportedFile(const wchar_t *tableName, const wchar_t *fileName, int pathLevel)
Enregistrement des caractéristiques d'un fichier importé comme table.
static HFONT mainVariableFont
Déclaration des fonctions de l'interface graphique de Taupie.
#define SUBCLASS_PROJECT_ID
#define SUBCLASS_QUERYEDIT_ID
#define SUBCLASS_TABLE_ID
#define SUBCLASS_QUERYERROR_ID
#define SUBCLASS_QUERYEXECUTE_ID
#define LOG_TEXTDELETETABLE
#define MESSAGE_INFO_FAILURE
#define DIALOG_TEXT_ASKFORTABLE
#define LOG_TEXTCREATEPROJECT
#define MESSAGE_QUESTION_DROPTABLE
#define LOG_TEXTCONVERTTOTABLE
#define MESSAGE_TITLE_WARNING
#define TABLE_DEFAULTNAME
#define LOG_TEXTRENAMETABLE
#define MESSAGE_QUESTION_RENAMETABLE
Définitions et macros pour la localisation.
#define IDM_PROJECT_LOG_IMPORT
#define IDM_DATA_CONVERT_TO_TABLE
#define IDM_PROJECT_LOG_COMMAND
#define IDM_DATA_COPYVALUE
#define IDM_PAGE_PREVIOUS
#define IDM_PROJECT_CLOSE
#define IDM_PROJECT_CONVERT
#define IDM_PROJECT_OPTIMIZE
#define IDM_PROJECT_UPDATE
#define IDM_DATA_EXPORT_TO_FILE
#define CURRENT_RICHEDITW