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"
47#include "../_TkT2/ManageSQLite.h"
48#include "../_TkT2/ManageSQLite_Win32.h"
71#define SCROLL_TIMER_ID 1
72#define SCROLL_IDLE_MS 100
75#define NBROWS_TIMER_ID 2
76#define NBROWS_IDLE_MS 1000
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");
785 PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(
IDM_INIT, 0), (LPARAM) NULL);
801 ShowWindow(hwnd, SW_HIDE);
846 if (rect.right > width)
860 SetWindowPos(
hMainProjectTree, HWND_TOP, 0, 0, width, r.bottom - r.top, SWP_DRAWFRAME);
893 HMENU hMenu = GetSubMenuByID(GetMenu(hwnd),
IDM_PROJECT);
903 EnableMenuItem(GetMenu(hwnd),
IDM_DATA, MF_GRAYED);
904 EnableMenuItem(GetMenu(hwnd),
IDM_SQL, MF_GRAYED);
908 InvalidateRect(hwnd, NULL, TRUE);
924 wchar_t *projectName = calloc(FILENAMELENGTH_MAX,
sizeof(
wchar_t));
955 swprintf(projectName, FILENAMELENGTH_MAX, L
"%ls", newProjectName);
956 free(newProjectName);
966 if ((option ==
IDM_PROJECT_NEW) || (!_waccess(projectName, R_OK | W_OK)))
968 int result = SQLITE_OK;
975 if (result == SQLITE_OK)
1000 int sizeDotCommand = wcslen(L
".open --new ''") + wcslen(GetStrictFileName(
currentDataBaseName)) + 1;
1001 wchar_t *dotCommand = calloc(sizeDotCommand,
sizeof(
wchar_t));
1004 swprintf(dotCommand, sizeDotCommand, L
".open --new \"%ls\"", GetStrictFileName(
currentDataBaseName));
1013 HMENU hMenu = GetSubMenuByID(GetMenu(hwnd),
IDM_PROJECT);
1023 EnableMenuItem(GetMenu(hwnd),
IDM_DATA, MF_ENABLED);
1024 EnableMenuItem(GetMenu(hwnd),
IDM_SQL, MF_ENABLED);
1073 int64_t nbRows = -1;
1075 wchar_t *command = NULL;
1080 HANDLE hProgressBar = StartProgressBar(L
"Ex\351cution du script SQL", -1);
1082 StopProgressBar(hProgressBar);
1108 InvalidateRect(hwnd, NULL, TRUE);
1127 int64_t nbRows = -1;
1130 wchar_t *command = calloc(length + 1,
sizeof(
wchar_t));
1140 HANDLE hProgressBar = StartProgressBar(L
"Ex\351cution de la requ\350te", -1);
1141 wchar_t *firstLetters = AllTrim(command, L
" \t\r\n", TRUE, FALSE, FALSE);
1142 int useTmp = wcsnicmp(firstLetters, L
"SELECT", 6) ? USE_NO_TEMP : USE_TEMP_TABLE;
1145 StopProgressBar(hProgressBar);
1169 InvalidateRect(hwnd, NULL, TRUE);
1191 int64_t nbRows = -1;
1193 static exportation_table_type options;
1195 int okExport = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L
"DialogExport", hwnd,
1196 (DLGPROC)(
void *)ProcedureExport, (LPARAM) &options);
1198 SetForegroundWindow(hwnd);
1202 wchar_t *fileName = FileOutChooserWithInit(L
"Exporter vers un fichier CSV ...", hwnd,
1207 FILE *fileOut = _wfopen(fileName, L
"wt");
1211 char *separator = (
char *)&options.separateur;
1212 char *quote = (
char *)&options.delimiteur;
1214 HANDLE hProgressBar = StartProgressBar(L
"Enregistrement des donn\351es", -1);
1216 StopProgressBar(hProgressBar);
1243 if (tableName && tableName[0] && fileName && fileName[0])
1247 HANDLE hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1249 if (hFile != INVALID_HANDLE_VALUE)
1253 BY_HANDLE_FILE_INFORMATION fileInfo;
1255 if (GetFileInformationByHandle(hFile, &fileInfo))
1259 wchar_t path[MAX_BUF] = L
"";
1260 wchar_t *pathPtr = path;
1264 int level = abs(pathLevel);
1266 swprintf(path,
sizeof(path) /
sizeof(path[0]), L
"%ls", fileName);
1267 pathPtr = wcsrchr(path, L
'\\');
1268 while (pathPtr && level)
1272 pathPtr = wcsrchr(path, L
'\\');
1278 wchar_t nowDate[
sizeof(
"YYYY-MM-DD")] = L
"";
1279 wchar_t nowTime[
sizeof(
"HH:MM:SS")] = L
"";
1281 time_t dateTime = time(NULL);
1283 wcsftime(nowDate,
sizeof(nowDate) /
sizeof(
wchar_t), L
"%Y-%m-%d", localtime(&dateTime));
1284 wcsftime(nowTime,
sizeof(nowTime) /
sizeof(
wchar_t), L
"%H:%M:%S", localtime(&dateTime));
1288 SYSTEMTIME systemTime;
1289 FileTimeToSystemTime(&fileInfo.ftLastWriteTime, &systemTime);
1291 wchar_t *wRecord = calloc(MAX_BUF,
sizeof(
wchar_t));
1295 swprintf(wRecord, MAX_BUF,
1301 L
"'%04d-%02d-%02d',"
1306 pathPtr ? &pathPtr[1] : L
"", GetFileName(fileName),
1307 fileInfo.nFileSizeLow + ((LONGLONG)fileInfo.nFileSizeHigh << 32),
1308 systemTime.wYear, systemTime.wMonth, systemTime.wDay,
1309 systemTime.wHour, systemTime.wMinute, systemTime.wSecond);
1341int RecordExecutedAction(
const wchar_t *action,
const wchar_t *dotCommand,
const wchar_t *query,
const wchar_t *error)
1345 if (action && action[0])
1349 wchar_t nowDate[
sizeof(
"YYYY-MM-DD")] = L
"";
1350 wchar_t nowTime[
sizeof(
"HH:MM:SS")] = L
"";
1352 time_t dateTime = time(NULL);
1354 wcsftime(nowDate,
sizeof(nowDate) /
sizeof(
wchar_t), L
"%Y-%m-%d", localtime(&dateTime));
1355 wcsftime(nowTime,
sizeof(nowTime) /
sizeof(
wchar_t), L
"%H:%M:%S", localtime(&dateTime));
1357 wchar_t *wRecord = calloc(MAX_BUF,
sizeof(
wchar_t));
1361 wchar_t *mAction = (
wchar_t *)action;
1362 WReplaceInStringNoFree(&mAction, L
"'", L
"''");
1364 wchar_t *mDotCommand = (
wchar_t *)dotCommand;
1365 WReplaceInStringNoFree(&mDotCommand, L
"'", L
"''");
1367 wchar_t *mQuery = (
wchar_t *)query;
1368 WReplaceInStringNoFree(&mQuery, L
"'", L
"''");
1370 wchar_t *mError = (
wchar_t *)error;
1371 WReplaceInStringNoFree(&mError, L
"'", L
"''");
1373 swprintf(wRecord, MAX_BUF,
1382 mAction ? mAction : L
"",
1383 mDotCommand ? mDotCommand : L
"",
1384 mQuery ? mQuery : L
"",
1385 mError ? mError : L
"");
1387 if (mAction != action)
1392 if (mDotCommand != dotCommand)
1397 if (mQuery != query)
1402 if (mError != error)
1433 int64_t nbRows = -1;
1435 wchar_t *fileName = FileInChooser(L
"Importer des donn\351es CSV ...", hwnd,
1436 L
"Fichier d\351limit\351 (*.csv;*.tsv;*.del;*.txt)\0*.csv;*.tsv;*.del;*.txt\0"
1437 L
"Tout fichier (*.*)\0*.*\0");
1441 HANDLE hPB = StartProgressBar(L
"Test du fichier ...", -1);
1442 int type = typefil(fileName, FIL_TAB_DEL);
1443 StopProgressBar(hPB);
1447 MessageBox(hwnd, L
"\n Probl\350me de fichier ! \n", L
"Erreur !", MB_ICONINFORMATION);
1451 else if (!(type & FIL_TAB))
1454 L
"\n Ce fichier n'est pas reconnu comme une table par " SOFT_NAMEW L
" ! \n",
1456 MB_ICONINFORMATION);
1463 if (type & FIL_NON & FIL_TAB_DEL)
1465 if (!DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd),
1466 L
"DialogDELTableStructure", hwnd,
1467 (DLGPROC)(
void *)ProcedureDELTableStructure,
1473 SetForegroundWindow(hwnd);
1479 TAB *table = fileopen_TAB(fileName, type);
1483 hPB = StartProgressBar(L
"Import des donn\351es CSV ...", -1);
1484 wchar_t *tableName = _wcsdup(GetStrictFileName(fileName));
1488 wchar_t *query = calloc(MAX_BUF,
sizeof(
wchar_t));
1494 for (UINT column = 0; column < table->nb_champs; ++ column)
1496 const wchar_t *fieldType = DATA_TEXT;
1498 if (table->champ[column].type == L
'D')
1500 fieldType = DATA_DATETIME;
1503 if (table->champ[column].type == L
'N')
1505 if (table->champ[column].decimales == 0)
1507 fieldType = DATA_INTEGER;
1511 fieldType = DATA_REAL;
1515 wchar_t *fieldName = _wcsdup(table->champ[column].nom);
1519 WReplaceInString(&fieldName, L
"'", L
"''");
1521 swprintf(query, MAX_BUF, L
"%ls TABLE \"%ls\" %ls \"%ls\" %ls %ls",
1522 column ? L
"ALTER" : L
"CREATE",
1524 column ? L
"ADD" : L
"(",
1540 while (fileread_TAB(1, table) == 1)
1542 if (!(nbRows % 1000))
1552 if (ProgressBarStopped())
1559 wchar_t *ptr = table->reg;
1563 for (UINT column = 0; column < table->nb_champs; ++ column)
1565 const wchar_t *fieldName = table->champ[column].nom;
1567 wchar_t *value = wcsdup(&ptr[table->champ[column].pos]);
1571 if (table->champ[column].type == L
'N')
1573 Replace(value, L
',', L
'.');
1582 SetProgressBarTextNum(L
"Lignes import\351es", &nbRows);
1602 fileclose_TAB(table);
1604 SetProgressBarTextNumText(L
"Lignes import\351es", &nbRows, L
"Optimisation de la base");
1607 StopProgressBar(hPB);
1615 SetForegroundWindow(hwnd);
1632 int64_t nbRows = -1;
1634 const wchar_t *command = L
"";
1661 HANDLE hProgressBar = StartProgressBar(L
"Lecture de la table", -1);
1663 StopProgressBar(hProgressBar);
1685 InvalidateRect(hwnd, NULL, TRUE);
1705 const wchar_t *result = NULL;
1708 int column = hti.iSubItem;
1712 static wchar_t number[INT_MAXSIZE + 1];
1713 swprintf(number, _countof(number), L
"%lld", line + 1);
1716 else if (column > 0)
1720 line, column - 1, 0);
1745 if (hSelectedTableItem)
1748 item.mask = TVIF_PARAM;
1749 item.hItem = hSelectedTableItem;
1752 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
1754 if (_wcsicmp(oldTableName, newTableName))
1759 if (renameTable == IDYES)
1761 int length = MAX_BUF;
1762 wchar_t *query = calloc(length,
sizeof(
wchar_t));
1766 swprintf(query, length, L
"ALTER TABLE \"%ls\" RENAME TO \"%ls\"", oldTableName, newTableName);
1804 if (hSelectedTableItem)
1806 wchar_t *tableName = calloc(MIN_BUF,
sizeof(
wchar_t));
1812 item.mask = TVIF_TEXT | TVIF_PARAM;
1813 item.pszText = tableName;
1814 item.cchTextMax = MIN_BUF;
1815 item.hItem = hSelectedTableItem;
1818 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
1823 if (deleteTable == IDYES)
1825 int length = MAX_BUF;
1826 wchar_t *query = calloc(length,
sizeof(
wchar_t));
1830 swprintf(query, length, L
"DROP TABLE \"%ls\"", tableName);
1834 (okDelete == SQLITE_OK) ? NULL :
sqlError);
1836 if (okDelete != SQLITE_OK)
1838 swprintf(query, length, L
"DROP VIEW \"%ls\"", tableName);
1842 (okDelete == SQLITE_OK) ? NULL :
sqlError);
1891 DialogBox((HINSTANCE)GetWindowInstance(hwnd), L
"DialogOptions", hwnd, (DLGPROC)(
void *)
Options_Procedure);
1903 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
1916 if (remainingRows < 0)
1923 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
1935 CopyInClipBoard(hwnd, text);
1943 if (MessageBox(hwnd, TEXT(
CONVERT_PROJECT), L
"", MB_OKCANCEL) == IDOK)
1979 if (hSelectedTableItem)
1982 item.mask = TVIF_PARAM;
1983 item.hItem = hSelectedTableItem;
1986 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2025 HANDLE hPb = StartProgressBar(L
"Optimisation en cours ...", -2);
2027 StopProgressBar(hPb);
2087 POINT pt = {xPos, yPos};
2088 ScreenToClient(hwndContext, &pt);
2097 hMenu = LoadMenu((HINSTANCE)GetWindowInstance(hwnd), L
"ViewMenu");
2101 TVHITTESTINFO tvhti = {0};
2104 TreeView_HitTest(hwndContext, &tvhti);
2106 if (tvhti.flags & TVHT_ONITEM)
2110 item.mask = TVIF_PARAM;
2111 item.hItem = tvhti.hItem;
2114 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2119 TreeView_SelectItem(hwndContext, tvhti.hItem);
2120 hMenu = LoadMenu((HINSTANCE)GetWindowInstance(hwnd), L
"TreeMenu");
2127 static HMENU hPopMenu = NULL;
2128 hPopMenu = GetSubMenu(hMenu, 0);
2130 TrackPopupMenuEx(hPopMenu, 0, xPos, yPos, hwnd, NULL);
2154 wchar_t *tableName = calloc(MIN_BUF,
sizeof(
wchar_t));
2165 item.mask = TVIF_TEXT | TVIF_PARAM;
2167 item.pszText = tableName;
2168 item.cchTextMax = MIN_BUF;
2172 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2174 size_t length = wcslen(tableName) +
sizeof(
"SELECT * FROM \"\"");
2175 wchar_t *command = calloc(length,
sizeof(
wchar_t));
2179 swprintf(command, length, L
"SELECT * FROM \"%ls\"", tableName);
2222 static int clrTextBk;
2224 switch (lplvcd->nmcd.dwDrawStage)
2226 case CDDS_PREPAINT :
2228 return CDRF_NOTIFYITEMDRAW;
2231 case CDDS_ITEMPREPAINT :
2233 clrText = lplvcd->clrText;
2234 clrTextBk = lplvcd->clrTextBk;
2236 return CDRF_NOTIFYSUBITEMDRAW;
2239 case CDDS_SUBITEM | CDDS_ITEMPREPAINT :
2245 switch (lplvcd->iSubItem)
2251 UINT dpi = GetWindowDpi(hwnd);
2260 lplvcd->clrText = clrText;
2261 lplvcd->clrTextBk = GetSysColor(COLOR_BTNFACE);
2270 UINT dpi = GetWindowDpi(hwnd);
2271 mainFixedFont = CreateFontForDPI(FIXED_FONT, FW_THIN, SIZE_OF_FONT, dpi);
2279 lplvcd->clrText = clrText;
2280 lplvcd->clrTextBk = clrTextBk;
2286 return CDRF_NEWFONT;
2291 return CDRF_DODEFAULT;
2308 wchar_t *query = calloc(length,
sizeof(
wchar_t));
2317 int nbColumns = Header_GetItemCount(hHeader);
2321 for (
int column = 1; column < nbColumns; ++ column)
2323 wchar_t columnFilter[MIN_BUF] = {0};
2324 wchar_t columnName[MIN_BUF] = {0};
2327 HD_TEXTFILTER htf = {0};
2329 hdi.mask = HDI_FILTER | HDI_TEXT;
2331 hdi.pszText = columnName;
2332 hdi.cchTextMax = _countof(columnName) - 1;
2334 hdi.type = HDFT_ISSTRING;
2337 hdi.pvFilter = &htf;
2339 htf.pszText = columnFilter;
2340 htf.cchTextMax = _countof(columnFilter) - 1;
2342 Header_GetItem(hHeader, column, &hdi);
2344 if (columnFilter[0])
2346 swprintf(&query[wcslen(query)], length - wcslen(query),
2347 L
" %ls \"%ls\" LIKE '%ls'",
2348 (!testColumn) ? L
"WHERE" : L
"AND", columnName, columnFilter);
2409 if (lplvdi->item.mask & LVIF_TEXT)
2412 int column = lplvdi->item.iSubItem;
2418 static wchar_t *text;
2422 static wchar_t number[INT_MAXSIZE + 1];
2423 swprintf(number, _countof(number), L
"%lld", line + 1);
2426 else if (column > 0)
2437 if (lplvdi->item.cchTextMax && text && (wcslen(text) >= (
size_t)lplvdi->item.cchTextMax))
2439 text[lplvdi->item.cchTextMax - 1] = L
'\0';
2442 lplvdi->item.pszText = text ? text : L
"";
2448 int columnWidth = ListView_GetColumnWidth(
hMainDataView, column);
2450 const int padding = 16;
2451 if (textWidth + padding > columnWidth)
2453 ListView_SetColumnWidth(
hMainDataView, column, textWidth + padding);
2460 lplvdi->item.pszText = L
"\267\267\267";
2477 int idCtrl __attribute__((unused)),
2482 static wchar_t oldItemText[MIN_BUF];
2488 case TVN_SELCHANGED :
2503 case TVN_BEGINLABELEDIT :
2507 LPNMTVDISPINFO pdi = (LPNMTVDISPINFO)pnmh;
2508 swprintf(oldItemText, MIN_BUF, L
"%ls", (pdi->item.pszText) ? pdi->item.pszText : L
"");
2514 case TVN_ENDLABELEDIT :
2518 LPNMTVDISPINFO pdi = (LPNMTVDISPINFO)pnmh;
2520 if (pdi->item.pszText)
2524 tvi.mask = TVIF_TEXT;
2525 tvi.hItem = pdi->item.hItem;
2526 tvi.pszText = pdi->item.pszText;
2540 case NM_CUSTOMDRAW :
2544 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pnmh;
2552 case LVN_BEGINSCROLL:
2566 case LVN_ODCACHEHINT :
2570 LPNMLVCACHEHINT lplvch = (LPNMLVCACHEHINT)pnmh;
2573 int number = (lplvch->iTo - lplvch->iFrom) + 1;
2584 case LVN_GETDISPINFO :
2588 LPNMLVDISPINFOW lplvdi = (LPNMLVDISPINFOW)pnmh;
2598 case LVN_ODFINDITEM :
2606 case HDN_FILTERBTNCLICK :
2608 LPNMHDFILTERBTNCLICK lphdfi = (LPNMHDFILTERBTNCLICK)pnmh;
2610 HWND hHeader = lphdfi->hdr.hwndFrom;
2619 case HDN_FILTERCHANGE :
2630 case LVN_COLUMNCLICK :
2632 HWND hListView = pnmh->hwndFrom;
2633 LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh;
2635 int numColumn = pnmv->iSubItem;
2636 ListView_SetSelectedColumn(hListView, numColumn);
2674 case WM_ERASEBKGND :
2676 HDC hdc = (HDC)wParam;
2682 GetClientRect(hwnd, &rect);
2683 FillRect(hdc, &rect, GetSysColorBrush(COLOR_BTNFACE));
2687 FillRect(hdc, &
rDataView, GetSysColorBrush(COLOR_BTNFACE));
2708 int64_t nbRows = VerifierTermine(NULL);
2715 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2725 return DefWindowProc(hwnd, uMsg, wParam, lParam);
2745 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
2749 case WM_WINDOWPOSCHANGING :
2753 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
2755 if (!(wp->flags & (SWP_NOSIZE)))
2763 GetClientRect(GetParent(hwnd), &r);
2768 int bottom = r.bottom - rSB.bottom;
2788 SetWindowPos(
hMainDataView, 0, wp->cx, 0, r.right - wp->cx, wp->cy, SWP_NOSENDCHANGING);
2817 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2833 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
2837 case WM_WINDOWPOSCHANGING :
2841 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
2843 if (!(wp->flags & (SWP_NOSIZE)))
2851 GetClientRect(GetParent(hwnd), &rParent);
2856 int bottom = rParent.bottom - rSB.bottom;
2858 if ((wp->x + wp->cx) < rParent.right)
2860 wp->cx = rParent.right - wp->x;
2875 SetWindowPos(
hMainProjectTree, 0, 0, 0, wp->x, wp->cy, SWP_NOSENDCHANGING);
2904 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
2921int64_t
DataView_Update(HWND hwnd, HWND * pListView, RECT * rListView, sqlite3 **db,
const wchar_t *command,
int useTmp)
2923 int64_t nbRows = -1;
2928 if (db && command && command[0])
2932 int result = SQLITE_OK;
2939 if (result == SQLITE_OK)
2945 DestroyWindow(pListView[0]);
2950 int virtualListView = (useTmp & USE_NO_TEMP) ? 0 : LVS_OWNERDATA;
2951 int listView_styles = LVS_REPORT;
2952 int window_styles = WS_CHILD | WS_THICKFRAME | WS_CLIPSIBLINGS;
2957 pListView[0] = CreateWindowEx(0, WC_LISTVIEW, L
"",
2958 virtualListView | listView_styles | window_styles,
2959 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowInstance(hwnd), NULL);
2961 HWND hListView = pListView[0];
2965 ListView_SetExtendedListViewStyleEx(hListView,
2966 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_DOUBLEBUFFER
2968 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_DOUBLEBUFFER
2969 | LVS_EX_HEADERDRAGDROP | LVS_EX_LABELTIP);
2973 SetWindowPos(hListView,
2977 rListView->right - rListView->left,
2978 rListView->bottom - rListView->top,
2982 (useTmp & USE_NO_TEMP) ? DataView_UpdateAll : DataView_UpdateHeader);
2988 DestroyWindow(hListView);
2989 pListView[0] = NULL;
2994 if (!(useTmp & ACTUAL_TABLE) || (nbRows == INT32_MAX))
3020int64_t
DataView_UpdateWithAFile(HWND hwnd, HWND * pListView, RECT * rListView, sqlite3 **db,
wchar_t **command,
const wchar_t *fileName)
3022 int64_t nbRows = -1;
3023 wchar_t *newFileName = NULL;
3029 newFileName = FileInChooser(L
"Lancer un script SQL", hwnd, L
"Script SQL (*.sql)\0*.sql\0");
3032 FILE *fileIn = OpenTextFileIn(
SOFT_NAMEW, fileName ? fileName : newFileName);
3036 _fseeki64(fileIn, 0L, SEEK_END);
3037 _off64_t fileSize = _ftelli64(fileIn);
3038 _fseeki64(fileIn, 0L, SEEK_SET);
3040 wchar_t *sql = calloc(fileSize + 1,
sizeof(
wchar_t));
3044 fread(sql,
sizeof(
wchar_t), fileSize, fileIn);
3048 int result = SQLITE_OK;
3052 wchar_t *projectName = calloc(FILENAMELENGTH_MAX,
sizeof(
wchar_t));
3056 result = OpenSQLiteDB(db, projectName, FALSE);
3061 if (result == SQLITE_OK)
3063 const wchar_t *lastSql = ScriptInDBwithAnswer(db[0], sql);
3065 if (command && lastSql && lastSql[0])
3067 NullFree(command[0]);
3068 command[0] = _wcsdup(lastSql);
3069 nbRows =
DataView_Update(hwnd, pListView, rListView, db, lastSql, USE_NO_TEMP);
3101 LPARAM lParam __attribute__((unused)))
3107 case WM_INITDIALOG :
3111 RecreateDialogFont(hwnd, &hFont, VARIABLE_FONT, SIZE_OF_FONT);
3118 switch (LOWORD(wParam))
3126 DeleteObject(hFont);
3139 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.
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
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
void Main_OnNotify_ApplyFilter(HWND hHeader)
Application du filtre courant à la vue courante des données.
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 une table dans la base courante à partir d'un fichier CSV.
void Main_OnPaint(HWND hwnd)
redessine la boîte de dialogue.
void Clean(void)
Supprime les fichiers temporaires de l'application.
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.
int Main_OnNotify_FillDataView(LPNMLVDISPINFOW lplvdi)
remplissage des items du DataView à la demande.
void SetVisibility(int project, int table, int query)
définit la visibilité des trois composants de l'écran.
LRESULT CALLBACK Options_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure du dialogue des options de ModuleTicket.
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
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
const wchar_t * GetCellValue(LVHITTESTINFO hti)
Fonction permettant de récupérer le texte d'une cellule sélectionnée.
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 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 LOG_TEXTCREATEPROJECT
#define MESSAGE_QUESTION_DROPTABLE
#define MESSAGE_TITLE_WARNING
#define LOG_TEXTRENAMETABLE
#define MESSAGE_QUESTION_RENAMETABLE
Définitions et macros pour la localisation.
#define IDM_PROJECT_LOG_IMPORT
#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