Taupie
Tiny Analyser for Universal Purpose Integration & Exploration
Chargement...
Recherche...
Aucune correspondance
TaupieGUI.c
Aller à la documentation de ce fichier.
1
9
10
11
12
13#include <sys/stat.h>
14#include <stdio.h>
15#include <locale.h>
16#include <ctype.h>
17#include <time.h>
18#include <math.h>
19#include <stdint.h>
20#include <wchar.h>
21
22#include <_mingw.h>
23#include <ole2.h>
24#include <windows.h>
25#include <winreg.h>
26#include <windowsx.h>
27#include <uxtheme.h>
28#include <shlobj.h>
29#include <commctrl.h>
30
31#include "../_TkT2/Defines.h"
32
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"
48
49#include "../_TkT2/ManageSQLite.h"
50#include "../_TkT2/ManageSQLite_Win32.h"
51
52#include "locales.h"
53#include "TaupieGUI.h"
54
55#include "extra.h"
56
57#include "resource.h"
58
59
60
61
62static HWND hMainDataView;
63static HWND hMainProjectTree;
64static HWND hMainStatusBar;
65
66static HWND hMainQueryError;
67static HWND hMainQueryEdit;
69
70static RECT rProjectTree;
71static RECT rDataView;
72
73#define SCROLL_TIMER_ID 1
74#define SCROLL_IDLE_MS 100
75static UINT_PTR scrollingTimer;
76
77//static UINT_PTR countingTimer;
78
79static wchar_t *currentCommand;
80static wchar_t *originalCommand;
81
82static sqlite3 *currentDataBase;
83static wchar_t *currentDataBaseName;
84static wchar_t *currentSelectedTable;
85
86static HTREEITEM hActualSelectedTableItem;
87static LVHITTESTINFO selectedCellInfo;
88
89static HFONT mainVariableFont;
90static HFONT mainFixedFont;
91static HFONT mainFixedBlackFont;
92
93static int xTableView;
94static int xQueryEdit;
95
96static wchar_t *sqlError;
97
98static int freezeDataView;
99
100#define DATAVIEW_MAXROWS 100000000
101static int dataViewPage;
102static int64_t dataViewNbRows;
103
104
113void SetVisibility(int project, int table, int query __attribute__((unused)))
114{
115 if (project == HIDE)
116 {
117 ShowWindow(hMainProjectTree, SW_HIDE);
118 }
119 else if (project == SHOW)
120 {
121 ShowWindow(hMainProjectTree, SW_SHOW);
122 }
123
124 if (table == HIDE)
125 {
126 ShowWindow(hMainDataView, SW_HIDE);
127 }
128 else if (table == SHOW)
129 {
130 ShowWindow(hMainDataView, SW_SHOW);
131 //AutosizeColumns(hMainDataView, 0);
132 }
133
134 if (query == HIDE)
135 {
136 ShowWindow(hMainQueryError, SW_HIDE);
137 ShowWindow(hMainQueryEdit, SW_HIDE);
138 ShowWindow(hMainQueryExecute, SW_HIDE);
139 }
140 else if (query == SHOW)
141 {
142 ShowWindow(hMainQueryError, SW_SHOW);
143 ShowWindow(hMainQueryEdit, SW_SHOW);
144 ShowWindow(hMainQueryExecute, SW_SHOW);
145 }
146}
147
148
158int ProjectTree_SelectTableByName(const wchar_t *tableName)
159{
160 int result = -1;
161
162 if (tableName && tableName[0])
163 {
164 HTREEITEM hitem = TreeView_GetRoot(hMainProjectTree);
165
166 hitem = TreeView_GetChild(hMainProjectTree, hitem);
167
168 TV_ITEM item;
169
170 if (hitem)
171 {
172 wchar_t text[0x100];
173
174 do
175 {
176 while (1)
177 {
178 item.mask = TVIF_PARAM | TVIF_TEXT;
179 item.lParam = 0;
180 item.pszText = text;
181 item.cchTextMax = _countof(text);
182 item.hItem = hitem;
183
184 if (TreeView_GetItem(hMainProjectTree, &item) == TRUE)
185 {
186 if (item.lParam == PROJECTTREE_TABLELIST)
187 {
188 hitem = TreeView_GetChild(hMainProjectTree, hitem);
189 continue;
190 }
191 }
192
193 break;
194 }
195
196 if (!wcsicmp(tableName, text))
197 {
198 TreeView_SelectItem(hMainProjectTree, hitem);
199 result = 0;
200 break;
201 }
202 }
203 while ((hitem = TreeView_GetNextSibling(hMainProjectTree, hitem)));
204 }
205 }
206
207 return result;
208}
209
210
219int64_t ProjectTree_Update(HWND hwnd)
220{
221 int64_t nbItems = -1;
222
224 {
225 int result = SQLITE_OK;
226
227 if (!currentDataBase)
228 {
229 result = OpenSQLiteDB(&currentDataBase, currentDataBaseName, FALSE);
230 }
231
232 if (result == SQLITE_OK)
233 {
234 const wchar_t *name = GetStrictFileName(currentDataBaseName);
235 nbItems = FillATreeView_Win32(hwnd, &hMainProjectTree, name, currentDataBase);
236
238 {
239 //ApplyDarkMode(hMainProjectTree, L"DarkMode_Explorer");
240
241 SetWindowRedraw(hMainProjectTree, FALSE);
242
243 SetWindowPos(hMainProjectTree,
244 HWND_TOP,
245 rProjectTree.left,
246 rProjectTree.top,
247 rProjectTree.right - rProjectTree.left,
248 rProjectTree.bottom - rProjectTree.top,
249 0);
250
252
253 SetWindowRedraw(hMainProjectTree, TRUE);
254
256 }
257 }
258 }
259
260 return nbItems;
261}
262
263
271void StatusBar_Update(const wchar_t *tableName, int64_t records)
272{
273 if (tableName)
274 {
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));
279
280 SetWindowText(hMainStatusBar, buffer);
281 }
282 else
283 {
284 SetWindowText(hMainStatusBar, L"");
285 }
286}
287
288
293void Clean(void)
294{
295 DeleteLocalFile(SOFT_NAMEW, L"temp\\" LISTE_FICHIERS);
296 DeleteLocalFile(SOFT_NAMEW, L"temp\\old" LISTE_FICHIERS);
297
298 DeleteLocalFile(SOFT_NAMEW, ARCHIVE_INFO);
299 DeleteLocalDirectory(SOFT_NAMEW, ARCHIVE_FOLDER);
300
301 DeleteLocalDirectory(SOFT_NAMEW, L"temp");
302}
303
304
313void Main_OnPaint(HWND hwnd)
314{
315 PAINTSTRUCT ps;
316 HDC hdc = BeginPaint(hwnd, &ps);
317
318 RECT rect = {0};
319
320 if (!hMainProjectTree)
321 {
322 GetClientRect(hwnd, &rect);
323 }
324 else if (!hMainDataView)
325 {
326 rect = rDataView;
327 }
328
329 RECT rPaint;
330
331 if (IntersectRect(&rPaint, &rect, &ps.rcPaint))
332 {
333 FillRect(hdc, &rPaint, GetSysColorBrush(COLOR_BTNFACE));
334 }
335
336 EndPaint(hwnd, &ps);
337}
338
339
349void Main_OnSize(HWND hwnd,
350 UINT state __attribute__((unused)),
351 UINT x,
352 UINT y)
353{
354 UINT width = 120;
355
356 RECT rectSB;
357 GetClientRect(hMainStatusBar, &rectSB);
358 SetWindowPos(hMainStatusBar, HWND_TOP, 0, 0, 0, 0, 0);
359
360 HTREEITEM hitem = TreeView_GetFirstVisible(hMainProjectTree);
361
362 if (hitem)
363 {
364 do
365 {
366 RECT rect;
367
368 if (TreeView_GetItemRect(hMainProjectTree, hitem, &rect, TRUE) == TRUE)
369 {
370 if ((UINT)rect.right > width)
371 {
372 width = rect.right;
373 }
374 }
375 }
376 while ((hitem = TreeView_GetNextVisible(hMainProjectTree, hitem)));
377 }
378
379 width += 32;
380
381 int bottom = y - rectSB.bottom;
382
383 if (width > (x / 3))
384 {
385 width = x / 3;
386 }
387
388 rProjectTree.left = 0;
389 rProjectTree.top = 0;
390 rProjectTree.right = width;
391 rProjectTree.bottom = bottom * 9 / 10;
392
393 SetWindowPos(hMainProjectTree,
394 HWND_TOP,
395 0,
396 0,
397 width,
398 bottom * 9 / 10,
399 0);
400
401 rDataView.left = width;
402 rDataView.top = 0;
403 rDataView.right = x;
404 rDataView.bottom = bottom * 9 / 10;
405
406 SetWindowPos(hMainDataView,
407 HWND_TOP,
408 width,
409 0,
410 x - width,
411 bottom * 9 / 10,
412 0);
413
414 int queryHeight = bottom * 1 / 10;
415
416 SetWindowPos(hMainQueryError,
417 HWND_TOP,
418 0,
419 bottom - queryHeight,
420 x / 3,
421 queryHeight,
422 0);
423
424 SetWindowPos(hMainQueryEdit,
425 HWND_TOP,
426 x / 3,
427 bottom - queryHeight,
428 (x * 2 / 3) - BUTTON_SIZE,
429 queryHeight,
430 0);
431
432 InvalidateRect(hwnd, NULL, TRUE);
433 UpdateWindow(hwnd);
434}
435
436
444void QueryBar_Update(const wchar_t *errorMsg, const wchar_t *request)
445{
446 if (errorMsg)
447 {
448 RF_ReplaceText(hMainQueryError, errorMsg);
449 }
450
451 if (request)
452 {
453 RF_ReplaceText(hMainQueryEdit, request);
454 }
455}
456
457
469LRESULT CALLBACK QueryExecute_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
470 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
471{
472 static HFONT hFont;
473
474 switch (uMsg)
475 {
476 case WM_SHOWWINDOW :
477 {
478 RecreateDialogFont(hwnd, &hFont, VARIABLE_FONT, SIZE_OF_FONT * 2);
479 ApplyFontToChildren(hwnd, hFont);
480
481 break;
482 }
483
484 case WM_NCDESTROY :
485 {
486 if (hFont)
487 {
488 DeleteObject(hFont);
489 }
490
491 RemoveWindowSubclass(hwnd, QueryExecute_Procedure, uIdSubclass);
492
493 break;
494 }
495
496 default :
497 {
498 break;
499 }
500 }
501
502 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
503}
504
505
517LRESULT CALLBACK QueryEdit_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
518 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
519{
520 switch (uMsg)
521 {
522 case WM_WINDOWPOSCHANGING :
523 {
524 RestartScrollingTimer(GetParent(hwnd));
525
526 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
527
528 if (!(wp->flags & (SWP_NOSIZE/* | SWP_NOMOVE*/)))
529 {
530 RECT r, rSB;
531 GetClientRect(GetParent(hwnd), &r);
532 GetClientRect(hMainStatusBar, &rSB);
533
534 int bottom = r.bottom - rSB.bottom;
535
536 if ((wp->x + wp->cx) != (r.right - BUTTON_SIZE))
537 {
538 wp->cx = (r.right - BUTTON_SIZE) - wp->x;
539 }
540
541 if (wp->y > (bottom - BUTTON_SIZE))
542 {
543 wp->y = bottom - BUTTON_SIZE;
544 }
545
546 wp->cy = bottom - wp->y;
547
548 xQueryEdit = wp->x;
549 SetWindowPos(hMainQueryError, 0, 0, wp->y, wp->x, wp->cy, SWP_NOSENDCHANGING);
550 SetWindowPos(hMainQueryExecute, 0, (r.right - BUTTON_SIZE), wp->y, BUTTON_SIZE, wp->cy, SWP_NOSENDCHANGING);
551
552 SetWindowPos(hMainDataView, 0, xTableView, 0, r.right - xTableView, bottom - wp->cy, SWP_NOSENDCHANGING);
553
554 rDataView.left = xTableView;
555 rDataView.top = 0;
556 rDataView.right = r.right;
557 rDataView.bottom = bottom - wp->cy;
558
559 SetWindowPos(hMainProjectTree, 0, 0, 0, xTableView, bottom - wp->cy, SWP_NOSENDCHANGING);
560
561 rProjectTree.left = 0;
562 rProjectTree.top = 0;
563 rProjectTree.right = xTableView;
564 rProjectTree.bottom = bottom - wp->cy;
565
566 return 0;
567 }
568
569 break;
570 }
571
572 case WM_NCDESTROY:
573 {
574 RemoveWindowSubclass(hwnd, QueryEdit_Procedure, uIdSubclass);
575 break;
576 }
577
578 default :
579 {
580 break;
581 }
582 }
583
584 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
585}
586
587
599LRESULT CALLBACK QueryError_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
600 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
601{
602 switch (uMsg)
603 {
604 case WM_WINDOWPOSCHANGING :
605 {
606 RestartScrollingTimer(GetParent(hwnd));
607
608 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
609
610 if (!(wp->flags & (SWP_NOSIZE/* | SWP_NOMOVE*/)))
611 {
612 RECT r, rSB;
613 GetClientRect(GetParent(hwnd), &r);
614 GetClientRect(hMainStatusBar, &rSB);
615
616 int bottom = r.bottom - rSB.bottom;
617
618 //RECT rT;
619 //GetWindowRect(hMainDataView, &rT);
620
621 if (wp->x > 0)
622 {
623 wp->cx += wp->x;
624 wp->x = 0;
625 }
626
627 if (wp->cx > (r.right - BUTTON_SIZE))
628 {
629 wp->cx = r.right - BUTTON_SIZE;
630 }
631
632 if (wp->y > (bottom - BUTTON_SIZE))
633 {
634 wp->y = bottom - BUTTON_SIZE;
635 }
636
637 wp->cy = bottom - wp->y;
638
639 xQueryEdit = wp->cx;
640 SetWindowPos(hMainQueryEdit, 0, wp->cx, wp->y, (r.right - BUTTON_SIZE) - wp->cx, wp->cy, SWP_NOSENDCHANGING);
641 SetWindowPos(hMainQueryExecute, 0, (r.right - BUTTON_SIZE), wp->y, BUTTON_SIZE, wp->cy, SWP_NOSENDCHANGING);
642
643 SetWindowPos(hMainDataView, 0, xTableView, 0, r.right - xTableView, bottom - wp->cy, SWP_NOSENDCHANGING);
644
645 rDataView.left = xTableView;
646 rDataView.top = 0;
647 rDataView.right = r.right;
648 rDataView.bottom = bottom - wp->cy;
649
650 SetWindowPos(hMainProjectTree, 0, 0, 0, xTableView, bottom - wp->cy, SWP_NOSENDCHANGING);
651
652 rProjectTree.left = 0;
653 rProjectTree.top = 0;
654 rProjectTree.right = xTableView;
655 rProjectTree.bottom = bottom - wp->cy;
656
657 return 0;
658 }
659
660 break;
661 }
662
663 case WM_NCDESTROY:
664 {
665 RemoveWindowSubclass(hwnd, QueryError_Procedure, uIdSubclass);
666 break;
667 }
668
669 default :
670 {
671 break;
672 }
673 }
674
675 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
676}
677
678
685void QueryBar_Create(HWND hwnd)
686{
687 hMainQueryEdit = CreateWindowEx(0, CURRENT_RICHEDITW, TEXT(EMPTY_STRING),
688 WS_CHILD | WS_VSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | WS_THICKFRAME,
689 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
690
692
693 //ApplyDarkMode(hMainQueryEdit, L"DarkMode_Explorer");
694
695
696 hMainQueryExecute = CreateWindowEx(0, L"BUTTON", L"\u26A1",//L"\U0001F3B2",//L"\u2935",//L"\u2713",//L"\u23F5",//
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);
699
700 SetWindowSubclass(hMainQueryExecute, QueryExecute_Procedure, SUBCLASS_QUERYEXECUTE_ID, (DWORD_PTR)NULL);
701
702 ApplyDarkMode(hMainQueryExecute, L"DarkMode_Explorer");
703
704
705 hMainQueryError = CreateWindowEx(0, CURRENT_RICHEDITW, TEXT(EMPTY_STRING),
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);
708
710
711 //ApplyDarkMode(hMainQueryError, L"DarkMode_Explorer");
712}
713
714
726BOOL Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
727{
728 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT);
729
730 setlocale(LC_ALL, "French_France.1252");
731
732 //SetCursor(LoadCursor(NULL, IDC_ARROW));
733
734 srand(time(0));
735
736 // application de l'icone
737
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));
740
741 // création de la barre de statut
742
743 hMainStatusBar = CreateWindowEx(0, STATUSCLASSNAME, TEXT(EMPTY_STRING),
744 WS_CHILD | WS_VISIBLE,
745 0, 0, 0, 0, hwnd, 0, (HINSTANCE)GetWindowInstance(hwnd), NULL);
746
747 StatusBar_Update(NULL, 0);
748
749 // création des répertoires locaux
750
751 wchar_t *appDir = GetLocalFile(SOFT_NAMEW, NULL);
752
753 if (appDir)
754 {
755 _wmkdir(appDir);
756 free(appDir);
757 }
758
759 wchar_t *tmpDir = GetLocalFile(SOFT_NAMEW, L"temp");
760
761 if (tmpDir)
762 {
763 _wmkdir(tmpDir);
764 free(tmpDir);
765 }
766
767 CreateInitFile(SOFT_NAMEW);
768
769 QueryBar_Create(hwnd);
770
771
772 HMENU hMenu = GetMenu(hwnd);
773 HMENU hSubMenu = GetSubMenuByID(hMenu, IDP_HELP);
774 SetSubMenuIcon(hSubMenu, IDM_ABOUT, L"mainIcon");
775
776 ModifyMenu(hMenu, IDM_PROJECT_NEW, MF_BYCOMMAND, IDM_PROJECT_NEW, L"\U0001F4C4 " MENU_NEW);
777 ModifyMenu(hMenu, IDM_PROJECT_CLOSE, MF_BYCOMMAND, IDM_PROJECT_CLOSE, L"\U00002716 " MENU_CLOSE);
778
779 ModifyMenu(hMenu, IDM_OPTIONS, MF_BYCOMMAND | MF_STRING, IDM_OPTIONS, L"\U0001F527 " MENU_OPTIONS);
780 ModifyMenu(hMenu, IDM_HELP, MF_BYCOMMAND | MF_STRING, IDM_HELP, L"\U00002753 " MENU_HELP);
781
782 DrawMenuBar(hwnd);
783
784
785 ExtraInit(hwnd, lpCreateStruct);
786
787
788 RecreateDialogFont(hwnd, &mainVariableFont, VARIABLE_FONT, SIZE_OF_FONT);
789
790 // affiche le projet courant éventuel (s'il n'a pas été fermé lors de la précédente fermeture de l'application).
791 PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDM_INIT, 0), (LPARAM) NULL);
792
793 return TRUE;
794}
795
796
803void Main_OnClose(HWND hwnd)
804{
805 //if (MessageBoxA(hwnd, "\n Voulez-vous quitter ? \n", "Arrêt", MB_YESNO | MB_ICONQUESTION) == IDYES)
806 {
807 ShowWindow(hwnd, SW_HIDE);
808
809 CloseSQLiteDB(&currentDataBase);
810
811 Clean();
812 PostQuitMessage(0);
813
815 {
816 DeleteObject(mainVariableFont);
817 mainVariableFont = NULL;
818 }
819
820 if (mainFixedFont)
821 {
822 DeleteObject(mainFixedFont);
823 mainFixedFont = NULL;
824 }
825
827 {
828 DeleteObject(mainFixedBlackFont);
829 mainFixedBlackFont = NULL;
830 }
831 }
832}
833
834
840{
841 int width = 120;
842
843 HTREEITEM hitem = TreeView_GetFirstVisible(hMainProjectTree);
844 if (hitem)
845 {
846 do
847 {
848 RECT rect;
849
850 if (TreeView_GetItemRect(hMainProjectTree, hitem, &rect, TRUE) == TRUE)
851 {
852 if (rect.right > width)
853 {
854 width = rect.right;
855 }
856 }
857 }
858 while ((hitem = TreeView_GetNextVisible(hMainProjectTree, hitem)));
859 }
860
861 width += 32;
862
863 RECT r;
864 GetWindowRect(hMainProjectTree, &r);
865
866 SetWindowPos(hMainProjectTree, HWND_TOP, 0, 0, width, r.bottom - r.top, SWP_DRAWFRAME);
867}
868
869
876void ProjectTree_Close(HWND hwnd)
877{
878 SaveOption(SOFT_NAMEW, SOFT_NAMEW, OPTION_CURRENTPROJECT, NULL);
879
881 StatusBar_Update(NULL, 0);
882
883 dataViewNbRows = 0;
884
885 CloseSQLiteDB(&currentDataBase);
886
887 if (hMainDataView)
888 {
889 DestroyWindow(hMainDataView);
890 hMainDataView = NULL;
891 }
892
894 {
895 DestroyWindow(hMainProjectTree);
896 hMainProjectTree = NULL;
897 }
898
899 HMENU hMenu = GetSubMenuByID(GetMenu(hwnd), IDM_PROJECT);
900 if (hMenu)
901 {
902 EnableMenuItem(hMenu, IDM_PROJECT_UPDATE, MF_GRAYED);
903 EnableMenuItem(hMenu, IDM_PROJECT_OPTIMIZE, MF_GRAYED);
904 EnableMenuItem(hMenu, IDM_PROJECT_LOG_IMPORT, MF_GRAYED);
905 EnableMenuItem(hMenu, IDM_PROJECT_LOG_COMMAND, MF_GRAYED);
906 EnableMenuItem(hMenu, IDM_PROJECT_CLOSE, MF_GRAYED);
907 }
908
909 EnableMenuItem(GetMenu(hwnd), IDM_DATA, MF_GRAYED);
910 EnableMenuItem(GetMenu(hwnd), IDM_SQL, MF_GRAYED);
911
912 DrawMenuBar(hwnd);
913
914 InvalidateRect(hwnd, NULL, TRUE);
915 UpdateWindow(hwnd);
916}
917
918
926void ProjectTree_Open(HWND hwnd, int option)
927{
928 // récupération du nom du dernier projet ouvert
929
930 wchar_t *projectName = calloc(FILENAMELENGTH_MAX, sizeof(wchar_t));
931
932 if (projectName)
933 {
934 LoadOption(SOFT_NAMEW, SOFT_NAMEW, OPTION_CURRENTPROJECT, projectName, FILENAMELENGTH_MAX);
935
936 // sauf initialisation, demande à l'utilisateur la base à utiliser
937
938 BOOL testOK = FALSE;
939
940 if ((option == IDM_INIT) || (option == IDM_PROJECT_CONVERT))
941 {
942 testOK = TRUE;
943 }
944 else
945 {
946 wchar_t *newProjectName = (option == IDM_PROJECT_NEW)
947 ? FileOutChooserWithInit(TEXT(NEW_PROJECT), hwnd, TEXT(FILETYPE_PROJECT), projectName, FALSE)
948 : FileInChooserWithInit(TEXT(OPEN_PROJECT), hwnd, TEXT(FILETYPE_ANY) TEXT(FILETYPE_PROJECT), projectName);
949
950 // OK, si un nom de base valide est choisi, il est enregistré comme base courante.
951
952 if (newProjectName)
953 {
954 testOK = TRUE;
955
956 DataView_Close(hwnd);
957 QueryBar_Update(L"", L"");
958 ProjectTree_Close(hwnd);
959
960 SaveOption(SOFT_NAMEW, SOFT_NAMEW, OPTION_CURRENTPROJECT, newProjectName);
961 swprintf(projectName, FILENAMELENGTH_MAX, L"%ls", newProjectName);
962 free(newProjectName);
963 }
964 }
965
966 // si le projet courant est nouveau ou accessible en lecture/écriture, alors ouvre / crée le projet.
967
968 if (testOK)
969 {
970 dataViewNbRows = 0;
971
972 if ((option == IDM_PROJECT_NEW) || (!_waccess(projectName, R_OK | W_OK)))
973 {
974 int result = SQLITE_OK;
975
976 CloseSQLiteDB(&currentDataBase);
977 NullFree(currentDataBaseName);
978
979 result = OpenSQLiteDB(&currentDataBase, projectName, FALSE);
980
981 if (result == SQLITE_OK)
982 {
983 currentDataBaseName = projectName;
984 projectName = NULL;
985
986 if ((option == IDM_PROJECT_NEW) || (option == IDM_PROJECT_CONVERT))
987 {
988 CreateTableInDB(currentDataBase, APP_FILES,
989 TEXT(FIELD_TABLENAME) L" TEXT, "
990 TEXT(FIELD_IMPORTDATE) L" DATE, " TEXT(FIELD_IMPORTTIME) L" TIME, "
991 TEXT(FIELD_FILEPATH) L" TEXT, " TEXT(FIELD_FILENAME) L" TEXT, "
992 TEXT(FIELD_FILESIZE) L" INT, "
993 TEXT(FIELD_FILEDATE) L" DATE, " TEXT(FIELD_FILETIME) L" TIME"
994 );
995
996 CreateTableInDB(currentDataBase, APP_HISTORY,
997 TEXT(FIELD_RUNDATE) L" DATE, " TEXT(FIELD_RUNTIME) L" TIME, "
998 TEXT(FIELD_ACTION) L" TEXT, "
999 TEXT(FIELD_DOTCOMMAND) L" TEXT, "
1000 TEXT(FIELD_SQL) L" TEXT, "
1001 TEXT(FIELD_ERROR) L" TEXT"
1002 );
1003
1004 if (option == IDM_PROJECT_NEW)
1005 {
1006 int sizeDotCommand = wcslen(L".open --new ''") + wcslen(GetStrictFileName(currentDataBaseName)) + 1;
1007 wchar_t *dotCommand = calloc(sizeDotCommand, sizeof(wchar_t));
1008 if (dotCommand)
1009 {
1010 swprintf(dotCommand, sizeDotCommand, L".open --new \"%ls\"", GetStrictFileName(currentDataBaseName));
1011 RecordExecutedAction(TEXT(LOG_TEXTCREATEPROJECT), dotCommand, NULL, NULL);
1012 }
1013 }
1014 }
1015
1016 ProjectTree_Update(hwnd);
1018
1019 HMENU hMenu = GetSubMenuByID(GetMenu(hwnd), IDM_PROJECT);
1020 if (hMenu)
1021 {
1022 EnableMenuItem(hMenu, IDM_PROJECT_UPDATE, MF_ENABLED);
1023 EnableMenuItem(hMenu, IDM_PROJECT_OPTIMIZE, MF_ENABLED);
1024 EnableMenuItem(hMenu, IDM_PROJECT_LOG_IMPORT, MF_ENABLED);
1025 EnableMenuItem(hMenu, IDM_PROJECT_LOG_COMMAND, MF_ENABLED);
1026 EnableMenuItem(hMenu, IDM_PROJECT_CLOSE, MF_ENABLED);
1027 }
1028
1029 EnableMenuItem(GetMenu(hwnd), IDM_DATA, MF_ENABLED);
1030 EnableMenuItem(GetMenu(hwnd), IDM_SQL, MF_ENABLED);
1031
1032 DrawMenuBar(hwnd);
1033 }
1034 }
1035 else
1036 {
1037 ProjectTree_Close(hwnd);
1038 }
1039 }
1040
1041 if (projectName)
1042 {
1043 free(projectName);
1044 }
1045 }
1046}
1047
1048
1055void DataView_Close(HWND hwnd __attribute__((unused)))
1056{
1057 SetVisibility(0, HIDE, 0);
1058 StatusBar_Update(NULL, 0);
1059
1060 if (hMainDataView)
1061 {
1062 DestroyWindow(hMainDataView);
1063 hMainDataView = NULL;
1064 }
1065}
1066
1067
1077int64_t ExecuteSQLScript(HWND hwnd, const wchar_t *fileName)
1078{
1079 int64_t nbRows = -1;
1080
1081 wchar_t *command = NULL;
1082
1083 NullFree(originalCommand);
1084 NullFree(currentCommand);
1085
1086 HANDLE hProgressBar = StartProgressBar(L"Ex\351cution du script SQL", -1);
1087 nbRows = DataView_UpdateWithAFile(hwnd, &hMainDataView, &rDataView, &currentDataBase, &command, fileName);
1088 StopProgressBar(hProgressBar);
1089
1090 currentCommand = _wcsdup(command ? command : L"");
1091
1092 if (nbRows >= 0)
1093 {
1096
1097 SetWindowSubclass(hMainDataView, DataView_Procedure, SUBCLASS_TABLE_ID, 0);
1098
1100
1101 SetVisibility(0, SHOW, 0);
1102 StatusBar_Update((nbRows != INT32_MAX) ? L"" : NULL, nbRows);
1103 }
1104 else
1105 {
1108
1109 NullFree(currentCommand);
1110
1111 DataView_Close(hwnd);
1112 }
1113
1114 InvalidateRect(hwnd, NULL, TRUE);
1115 UpdateWindow(hwnd);
1116
1117 ShowWindow(hMainDataView, SW_SHOWNA);
1118
1119 return nbRows;
1120}
1121
1122
1131int64_t ExecuteCustomSQLQuery(HWND hwnd)
1132{
1133 int64_t nbRows = -1;
1134
1135 int length = GetWindowTextLength(hMainQueryEdit);
1136 wchar_t *command = calloc(length + 1, sizeof(wchar_t));
1137
1138 if (command)
1139 {
1140 GetWindowText(hMainQueryEdit, command, length + 1);
1141
1142 NullFree(originalCommand);
1143 NullFree(currentCommand);
1144 currentCommand = _wcsdup(command);
1145
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;
1149
1150 if ((useTmp & USE_NO_TEMP) && wcsnicmp(firstLetters, L"PRAGMA", 6))
1151 {
1152 // ce n'est pas une requête de sélection ni un PRAGMA -> rien à afficher
1153 nbRows = RequestInDBwithError(currentDataBase, command, &sqlError);
1154 }
1155 else
1156 {
1157 nbRows = DataView_Update(hwnd, &hMainDataView, &rDataView, &currentDataBase, command, useTmp);
1158 }
1159
1160 StopProgressBar(hProgressBar);
1161
1162 if (nbRows >= 0)
1163 {
1166
1167 SetWindowSubclass(hMainDataView, DataView_Procedure, SUBCLASS_TABLE_ID, 0);
1168
1170
1171 SetVisibility(0, SHOW, 0);
1172 StatusBar_Update((nbRows != INT32_MAX) ? L"" : NULL, nbRows);
1173 }
1174 else
1175 {
1178
1179 NullFree(currentCommand);
1180
1181 DataView_Close(hwnd);
1182 }
1183
1184 InvalidateRect(hwnd, NULL, TRUE);
1185 UpdateWindow(hwnd);
1186
1187 ShowWindow(hMainDataView, SW_SHOWNA);
1188
1189 free(command);
1190 }
1191
1192 return nbRows;
1193}
1194
1195
1204int64_t CreateCSVFromView(HWND hwnd)
1205{
1206 int64_t nbRows = -1;
1207
1208 static exportation_table_type options;
1209
1210 int okExport = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L"DialogExport", hwnd,
1211 (DLGPROC)(void *)ProcedureExport, (LPARAM) &options);
1212
1213 SetForegroundWindow(hwnd);
1214
1215 if (okExport)
1216 {
1217 wchar_t *fileName = FileOutChooserWithInit(L"Exporter vers un fichier CSV ...", hwnd,
1218 L"Fichier CSV (*.csv)\0*.csv\0", currentSelectedTable, TRUE);
1219
1220 if (fileName)
1221 {
1222 FILE *fileOut = _wfopen(fileName, L"wt");
1223
1224 if (fileOut)
1225 {
1226 char *separator = (char *)&options.separateur;
1227 char *quote = (char *)&options.delimiteur;
1228
1229 HANDLE hProgressBar = StartProgressBar(L"Enregistrement des donn\351es", -1);
1230 ExportDataToCSV(currentDataBase, currentCommand, separator, quote, fileOut);
1231 StopProgressBar(hProgressBar);
1232
1233 fclose(fileOut);
1234 }
1235
1236 free(fileName);
1237 }
1238 }
1239
1240 return nbRows;
1241}
1242
1243
1253{
1254 int result = -1;
1255
1256 freezeDataView = TRUE;
1257
1258 wchar_t *tableName = calloc(MIN_BUF, sizeof(wchar_t));
1259
1260 if (tableName)
1261 {
1262 swprintf(tableName, MIN_BUF, L"%ls_%ls", TEXT(TABLE_DEFAULTNAME), TimeStamp());
1263
1264 wchar_t *stringHub[4] = { tableName, TEXT(DIALOG_TEXT_ASKFORTABLE), TEXT(TEXT_TABLENAME) L" :", NULL};
1265
1266 int okTable = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L"DialogGetInformation", hwnd,
1267 (DLGPROC)(void *)ProcedureGetInformation, (LPARAM)stringHub);
1268
1269 if (okTable == 0)
1270 {
1271 size_t length = wcslen(tableName) + sizeof("CREATE TABLE \"_\" AS SELECT * FROM_") + wcslen(APP_VIEWTABLE);
1272 wchar_t *query = calloc(length, sizeof(wchar_t));
1273
1274 if (query)
1275 {
1276 swprintf(query, length, L"CREATE TABLE \"%ls\" AS SELECT * FROM %ls", tableName, APP_VIEWTABLE);
1277
1278 result = RequestInDBwithError(currentDataBase, query, &sqlError);
1279
1281 (result == SQLITE_OK) ? NULL : sqlError);
1282
1283 QueryBar_Update(L"", L"");
1284 DataView_Close(hwnd);
1285 ProjectTree_Update(hwnd);
1286
1287 free(query);
1288 }
1289 }
1290
1291 if (result == SQLITE_OK)
1292 {
1294 {
1296 }
1297
1298 currentSelectedTable = tableName;
1299 }
1300 else
1301 {
1302 free(tableName);
1303 }
1304 }
1305
1306 freezeDataView = FALSE;
1307
1308 return result;
1309}
1310
1311
1322int RecordImportedFile(const wchar_t *tableName, const wchar_t *fileName, int pathLevel)
1323{
1324 int result = -1;
1325
1326 if (tableName && tableName[0] && fileName && fileName[0])
1327 {
1328 // Ouvre le fichier
1329
1330 HANDLE hFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1331
1332 if (hFile != INVALID_HANDLE_VALUE)
1333 {
1334 // Obtient les caractéristiques du fichier
1335
1336 BY_HANDLE_FILE_INFORMATION fileInfo;
1337
1338 if (GetFileInformationByHandle(hFile, &fileInfo))
1339 {
1340 // récupération du chemin sur le niveau ad hoc
1341
1342 wchar_t path[MAX_BUF] = L"";
1343 wchar_t *pathPtr = path;
1344
1345 if (pathLevel)
1346 {
1347 int level = abs(pathLevel);
1348
1349 swprintf(path, sizeof(path) / sizeof(path[0]), L"%ls", fileName);
1350 pathPtr = wcsrchr(path, L'\\');
1351 while (pathPtr && level)
1352 {
1353 level --;
1354 pathPtr[0] = L'\0';
1355 pathPtr = wcsrchr(path, L'\\');
1356 }
1357 }
1358
1359 // récupération de la date et heure actuelle
1360
1361 wchar_t nowDate[sizeof("YYYY-MM-DD")] = L"";
1362 wchar_t nowTime[sizeof("HH:MM:SS")] = L"";
1363
1364 time_t dateTime = time(NULL);
1365
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));
1368
1369 // récupération de la date et heure du fichier
1370
1371 SYSTEMTIME systemTime;
1372 FileTimeToSystemTime(&fileInfo.ftLastWriteTime, &systemTime);
1373
1374 wchar_t *wRecord = calloc(MAX_BUF, sizeof(wchar_t));
1375
1376 if (wRecord)
1377 {
1378 swprintf(wRecord, MAX_BUF,
1379 L"INSERT INTO " APP_FILES L" VALUES ("
1380 L"'%ls',"
1381 L"'%ls'," L"'%ls',"
1382 L"'%ls'," L"'%ls',"
1383 L"%lld,"
1384 L"'%04d-%02d-%02d',"
1385 L"'%02d:%02d:%02d'"
1386 L")",
1387 tableName,
1388 nowDate, nowTime,
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);
1393
1394 // enregistre les informations
1395
1396 result = RequestInDB(currentDataBase, wRecord);
1397
1398 free(wRecord);
1399 }
1400 }
1401
1402
1403 // Ferme le fichier
1404
1405 CloseHandle(hFile);
1406 }
1407 }
1408
1409 return result;
1410}
1411
1412
1424int RecordExecutedAction(const wchar_t *action, const wchar_t *dotCommand, const wchar_t *query, const wchar_t *error)
1425{
1426 int result = -1;
1427
1428 if (action && action[0])
1429 {
1430 // récupération de la date et heure actuelle
1431
1432 wchar_t nowDate[sizeof("YYYY-MM-DD")] = L"";
1433 wchar_t nowTime[sizeof("HH:MM:SS")] = L"";
1434
1435 time_t dateTime = time(NULL);
1436
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));
1439
1440 wchar_t *wRecord = calloc(MAX_BUF, sizeof(wchar_t));
1441
1442 if (wRecord)
1443 {
1444 wchar_t *mAction = (wchar_t *)action;
1445 WReplaceInStringNoFree(&mAction, L"'", L"''");
1446
1447 wchar_t *mDotCommand = (wchar_t *)dotCommand;
1448 WReplaceInStringNoFree(&mDotCommand, L"'", L"''");
1449
1450 wchar_t *mQuery = (wchar_t *)query;
1451 WReplaceInStringNoFree(&mQuery, L"'", L"''");
1452
1453 wchar_t *mError = (wchar_t *)error;
1454 WReplaceInStringNoFree(&mError, L"'", L"''");
1455
1456 swprintf(wRecord, MAX_BUF,
1457 L"INSERT INTO " APP_HISTORY L" VALUES ("
1458 L"'%ls'," L"'%ls',"
1459 L"'%ls',"
1460 L"'%ls',"
1461 L"'%ls',"
1462 L"'%ls'"
1463 L")",
1464 nowDate, nowTime,
1465 mAction ? mAction : L"",
1466 mDotCommand ? mDotCommand : L"",
1467 mQuery ? mQuery : L"",
1468 mError ? mError : L"");
1469
1470 if (mAction != action)
1471 {
1472 free(mAction);
1473 }
1474
1475 if (mDotCommand != dotCommand)
1476 {
1477 free(mDotCommand);
1478 }
1479
1480 if (mQuery != query)
1481 {
1482 free(mQuery);
1483 }
1484
1485 if (mError != error)
1486 {
1487 free(mError);
1488 }
1489
1490 // enregistre les informations
1491
1492 result = RequestInDB(currentDataBase, wRecord);
1493
1494 free(wRecord);
1495 }
1496 }
1497
1498 return result;
1499}
1500
1501
1514int64_t CreateTableFromCSV(HWND hwnd)
1515{
1516 int64_t nbRows = -1;
1517
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");
1521
1522 if (fileName)
1523 {
1524 HANDLE hPB = StartProgressBar(L"Test du fichier ...", -1);
1525 int type = typefil(fileName, FIL_TAB_DEL);
1526 StopProgressBar(hPB);
1527
1528 if (type & FIL_ERR)
1529 {
1530 MessageBox(hwnd, L"\n Probl\350me de fichier ! \n", L"Erreur !", MB_ICONINFORMATION);
1531 }
1532
1533
1534 else if (!(type & FIL_TAB))
1535 {
1536 MessageBox(hwnd,
1537 L"\n Ce fichier n'est pas reconnu comme une table par " SOFT_NAMEW L" ! \n",
1538 L"Erreur !",
1539 MB_ICONINFORMATION);
1540 }
1541
1542 else
1543 {
1544 BOOL resultat = 1;
1545
1546 if (type & FIL_NON & FIL_TAB_DEL)
1547 {
1548 if (!DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd),
1549 L"DialogDELTableStructure", hwnd,
1550 (DLGPROC)(void *)ProcedureDELTableStructure,
1551 (LPARAM)fileName))
1552 {
1553 resultat = 0;
1554 }
1555
1556 SetForegroundWindow(hwnd);
1557 }
1558
1559 if (resultat)
1560 {
1561 TAB *table = fileopen_TAB(fileName, type);
1562
1563 if (table)
1564 {
1565 wchar_t *tableName = calloc(MIN_BUF, sizeof(wchar_t));
1566
1567 if (tableName)
1568 {
1569 swprintf(tableName, MIN_BUF, L"%ls", GetStrictFileName(fileName));
1570
1571 wchar_t *stringHub[4] = { tableName, TEXT(DIALOG_TEXT_ASKFORTABLE), TEXT(TEXT_TABLENAME) L" :", NULL};
1572
1573 int okTable = DialogBoxParam((HINSTANCE)GetWindowInstance(hwnd), L"DialogGetInformation", hwnd,
1574 (DLGPROC)(void *)ProcedureGetInformation, (LPARAM)stringHub);
1575
1576 if (okTable == 0)
1577 {
1578 WReplaceInString(&tableName, L"'", L"''");
1579
1580 wchar_t *query = calloc(FILENAMELENGTH_MAX, sizeof(wchar_t));
1581
1582 if (query)
1583 {
1584 wchar_t *fields = calloc(FILENAMELENGTH_MAX, sizeof(wchar_t));
1585
1586 if (fields)
1587 {
1588 hPB = StartProgressBar(L"Import des donn\351es CSV ...", -1);
1589
1590 StartTransactionInDB(currentDataBase);
1591
1592 swprintf(query, FILENAMELENGTH_MAX,
1593 L"CREATE TABLE \"%ls\" ( '%ls' )", tableName, APP_FIELD);
1594
1595 RequestInDB(currentDataBase, query);
1596
1597 // création de la table avec les champs identifiés et typés
1598
1599 for (UINT column = 0; column < table->nb_champs; ++ column)
1600 {
1601 const wchar_t *fieldType = DATA_TEXT;
1602
1603 if (table->champ[column].type == L'D')
1604 {
1605 fieldType = DATA_DATETIME;
1606 }
1607
1608 if (table->champ[column].type == L'N')
1609 {
1610 if (table->champ[column].decimales == 0)
1611 {
1612 fieldType = DATA_INTEGER;
1613 }
1614 else
1615 {
1616 fieldType = DATA_REAL;
1617 }
1618 }
1619
1620 wchar_t *fieldName = table->champ[column].nom;
1621 WReplaceInStringNoFree(&fieldName, L"'", L"''");
1622 WReplaceInString(&fieldName, L"\"", L"\"\"");
1623
1624 if (fieldName)
1625 {
1626 swprintf(query, FILENAMELENGTH_MAX,
1627 L"ALTER TABLE \"%ls\" ADD \"%ls\" %ls",
1628 tableName, fieldName, fieldType);
1629
1630 RequestInDB(currentDataBase, query);
1631
1632 swprintf(&fields[wcslen(fields)], FILENAMELENGTH_MAX - wcslen(fields),
1633 L"%ls \"%ls\"", column ? L"," : L"", fieldName);
1634
1635 free(fieldName);
1636 }
1637 }
1638
1639 swprintf(query, FILENAMELENGTH_MAX,
1640 L"ALTER TABLE \"%ls\" DROP COLUMN \"%ls\"", tableName, APP_FIELD);
1641
1642 RequestInDB(currentDataBase, query);
1643
1644 EndTransactionInDB(currentDataBase);
1645
1646 // ajoute les enregistrements
1647
1648 nbRows = 0;
1649
1650 swprintf(query, FILENAMELENGTH_MAX,
1651 L"INSERT INTO \"%ls\" ( %ls ) VALUES ( ", tableName, fields);
1652
1653 size_t initQuery = wcslen(query);
1654
1655 while (fileread_TAB(1, table) == 1)
1656 {
1657 if (!(nbRows % 100000))
1658 {
1659 if (nbRows)
1660 {
1661 EndTransactionInDB(currentDataBase);
1662 }
1663
1664 StartTransactionInDB(currentDataBase);
1665 }
1666
1667 if (ProgressBarStopped())
1668 {
1669 break;
1670 }
1671
1672 nbRows ++;
1673
1674 wchar_t *ptr = table->reg;
1675
1676 for (UINT column = 0; column < table->nb_champs; ++ column)
1677 {
1678 wchar_t *value = (wchar_t *)&ptr[table->champ[column].pos];
1679 WReplaceInStringNoFree(&value, L"'", L"''");
1680 WReplaceInString(&value, L"\"", L"\"\"");
1681
1682 if (value)
1683 {
1684 if ((table->champ[column].type == L'N') && (table->champ[column].decimales > 0))
1685 {
1686 Replace(value, L',', L'.');
1687 }
1688
1689 swprintf(&query[wcslen(query)], FILENAMELENGTH_MAX - wcslen(query),
1690 L"%ls '%ls'", column ? L"," : L"", value);
1691
1692 free(value);
1693 }
1694 }
1695
1696 swprintf(&query[wcslen(query)], FILENAMELENGTH_MAX - wcslen(query), L" )");
1697 /*int okQuery = */RequestInDB(currentDataBase, query);
1698 query[initQuery] = L'\0';
1699
1700 SetProgressBarTextNum(L"Lignes import\351es", &nbRows);
1701 }
1702
1703 if (nbRows)
1704 {
1705 EndTransactionInDB(currentDataBase);
1706 }
1707
1708 StopProgressBar(hPB);
1709
1710 free(fields);
1711 }
1712
1713 free(query);
1714 }
1715 }
1716
1717 if (nbRows != -1)
1718 {
1720 {
1722 }
1723
1724 currentSelectedTable = tableName;
1725 RecordImportedFile(tableName, fileName, 0);
1726 }
1727 else
1728 {
1729 free(tableName);
1730 }
1731 }
1732
1733 fileclose_TAB(table);
1734 }
1735 }
1736 }
1737
1738 free(fileName);
1739 }
1740
1741 return nbRows;
1742}
1743
1744
1754int64_t ProjectTree_ViewAppTable(HWND hwnd, int id)
1755{
1756 int64_t nbRows = -1;
1757
1758 const wchar_t *command = L"";
1759
1760 switch (id)
1761 {
1762 case APP_FILES_ID :
1763 {
1764 command = L"SELECT * FROM " APP_FILES;
1765 break;
1766 }
1767
1768 case APP_HISTORY_ID :
1769 {
1770 command = L"SELECT * FROM " APP_HISTORY;
1771 break;
1772 }
1773
1774 default :
1775 {
1776 break;
1777 }
1778 }
1779
1780
1781 NullFree(originalCommand);
1782 NullFree(currentCommand);
1783 currentCommand = _wcsdup(command);
1784
1785 HANDLE hProgressBar = StartProgressBar(L"Lecture de la table", -1);
1786 nbRows = DataView_Update(hwnd, &hMainDataView, &rDataView, &currentDataBase, command, USE_TEMP_VIEW);
1787 StopProgressBar(hProgressBar);
1788
1789 if (nbRows >= 0)
1790 {
1791 QueryBar_Update(L"", L"");
1792
1793 SetWindowSubclass(hMainDataView, DataView_Procedure, SUBCLASS_TABLE_ID, 0);
1794
1795 originalCommand = _wcsdup(command);
1796
1797 SetVisibility(0, SHOW, 0);
1798 StatusBar_Update((nbRows != INT32_MAX) ? L"" : NULL, nbRows);
1799 }
1800 else
1801 {
1803
1804 NullFree(currentCommand);
1805
1806 DataView_Close(hwnd);
1807 }
1808
1809 InvalidateRect(hwnd, NULL, TRUE);
1810 UpdateWindow(hwnd);
1811
1812 ShowWindow(hMainDataView, SW_SHOWNA);
1813
1814 return nbRows;
1815}
1816
1817
1828const wchar_t *GetCellValue(int64_t line, int column)
1829{
1830 const wchar_t *result = NULL;
1831
1832 line = (dataViewPage * DATAVIEW_MAXROWS) + line;
1833
1834 if (column == 0)
1835 {
1836 static wchar_t number[INT_MAXSIZE + 1];
1837 swprintf(number, _countof(number), L"%lld", line + 1);
1838 result = number;
1839 }
1840 else if (column > 0)
1841 {
1842 result = ReadInTableFromSQLiteDB(currentDataBase,
1843 L"SELECT * FROM \"" APP_VIEWTABLE L"\"",
1844 line, column - 1, 0);
1845 }
1846
1847 return result;
1848}
1849
1850
1861int ProjectTree_RenameTable(HWND hwnd, const wchar_t *oldTableName, const wchar_t *newTableName)
1862{
1863 int result = 0;
1864
1865 freezeDataView = TRUE;
1866
1867 HTREEITEM hSelectedTableItem = TreeView_GetSelection(hMainProjectTree);
1868
1869 if (hSelectedTableItem)
1870 {
1871 TV_ITEM item = {0};
1872 item.mask = TVIF_PARAM;
1873 item.hItem = hSelectedTableItem;
1874
1875 if ((TreeView_GetItem(hMainProjectTree, &item) == TRUE)
1876 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
1877 {
1878 if (_wcsicmp(oldTableName, newTableName))
1879 {
1880 int renameTable = MessageBox(hwnd, TEXT(MESSAGE_QUESTION_RENAMETABLE),
1881 TEXT(MESSAGE_TITLE_WARNING), MB_YESNO | MB_ICONQUESTION);
1882
1883 if (renameTable == IDYES)
1884 {
1885 int length = MAX_BUF;
1886 wchar_t *query = calloc(length, sizeof(wchar_t));
1887
1888 if (query)
1889 {
1890 swprintf(query, length, L"ALTER TABLE \"%ls\" RENAME TO \"%ls\"", oldTableName, newTableName);
1891 int okRename = RequestInDBwithError(currentDataBase, query, &sqlError);
1892
1893 RecordExecutedAction(TEXT(LOG_TEXTRENAMETABLE), NULL, query, (okRename == SQLITE_OK) ? NULL : sqlError);
1894
1895 QueryBar_Update(L"", L"");
1896 DataView_Close(hwnd);
1897 ProjectTree_Update(hwnd);
1898
1899 free(query);
1900 }
1901 }
1902 }
1903 }
1904 }
1905
1906 freezeDataView = FALSE;
1907
1908 return result;
1909}
1910
1911
1921{
1922 int result = 0;
1923
1924 freezeDataView = TRUE;
1925
1926 HTREEITEM hSelectedTableItem = TreeView_GetSelection(hMainProjectTree);
1927
1928 if (hSelectedTableItem)
1929 {
1930 wchar_t *tableName = calloc(MIN_BUF, sizeof(wchar_t));
1931
1932 if (tableName)
1933 {
1934 TV_ITEM item = {0};
1935
1936 item.mask = TVIF_TEXT | TVIF_PARAM;
1937 item.pszText = tableName;
1938 item.cchTextMax = MIN_BUF;
1939 item.hItem = hSelectedTableItem;
1940
1941 if ((TreeView_GetItem(hMainProjectTree, &item) == TRUE)
1942 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
1943 {
1944 int deleteTable = MessageBox(hwnd, TEXT(MESSAGE_QUESTION_DROPTABLE),
1945 TEXT(MESSAGE_TITLE_WARNING), MB_YESNO | MB_ICONQUESTION);
1946
1947 if (deleteTable == IDYES)
1948 {
1949 int length = MAX_BUF;
1950 wchar_t *query = calloc(length, sizeof(wchar_t));
1951
1952 if (query)
1953 {
1954 swprintf(query, length, L"DROP TABLE \"%ls\"", tableName);
1955 int okDelete = RequestInDBwithError(currentDataBase, query, &sqlError);
1956
1957 RecordExecutedAction(TEXT(LOG_TEXTDELETETABLE), NULL, query,
1958 (okDelete == SQLITE_OK) ? NULL : sqlError);
1959
1960 if (okDelete != SQLITE_OK)
1961 {
1962 swprintf(query, length, L"DROP VIEW \"%ls\"", tableName);
1963 okDelete = RequestInDBwithError(currentDataBase, query, &sqlError);
1964
1965 RecordExecutedAction(TEXT(LOG_TEXTDELETETABLE), NULL, query,
1966 (okDelete == SQLITE_OK) ? NULL : sqlError);
1967 }
1968
1969 QueryBar_Update(L"", L"");
1970 DataView_Close(hwnd);
1971 ProjectTree_Update(hwnd);
1972
1973 free(query);
1974 }
1975 }
1976 }
1977
1978 free(tableName);
1979 }
1980 }
1981
1982 freezeDataView = FALSE;
1983
1984 return result;
1985}
1986
1987
1997void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
1998{
1999 switch (id)
2000 {
2001 case IDM_HELP :
2002 {
2003 RunHelp(hwnd);
2004 break;
2005 }
2006
2007 case IDM_ABOUT :
2008 {
2009 ShowAboutBox(hwnd);
2010 break;
2011 }
2012
2013 case IDM_OPTIONS :
2014 {
2015 DialogBox((HINSTANCE)GetWindowInstance(hwnd), L"DialogOptions", hwnd, (DLGPROC)(void *)ProcedureOptions);
2016 break;
2017 }
2018
2019 case IDM_PAGE_PREVIOUS :
2020 {
2021 if (dataViewPage > 0)
2022 {
2023 -- dataViewPage;
2024
2025 int64_t remainingRows = dataViewNbRows - (dataViewPage * DATAVIEW_MAXROWS);
2026 ListView_SetItemCountEx(hMainDataView, (remainingRows > DATAVIEW_MAXROWS) ? DATAVIEW_MAXROWS : remainingRows,
2027 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2028 }
2029 break;
2030 }
2031
2032 case IDM_PAGE_NEXT :
2033 {
2034 if (dataViewPage < 40)
2035 {
2036 ++ dataViewPage;
2037
2038 int64_t remainingRows = dataViewNbRows - (dataViewPage * DATAVIEW_MAXROWS);
2039
2040 if (remainingRows < 0)
2041 {
2042 -- dataViewPage;
2043 }
2044 else
2045 {
2046 ListView_SetItemCountEx(hMainDataView, (remainingRows > DATAVIEW_MAXROWS) ? DATAVIEW_MAXROWS : remainingRows,
2047 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2048 }
2049 }
2050 break;
2051 }
2052
2053 case IDM_DATA_COPYVALUE:
2054 {
2055 int64_t line = selectedCellInfo.iItem;
2056 int column = selectedCellInfo.iSubItem;
2057
2058 const wchar_t *text = GetCellValue(line, column);
2059
2060 if (text)
2061 {
2062 CopyInClipBoard(hwnd, text);
2063 }
2064
2065 break;
2066 }
2067
2068 case IDM_PROJECT_CONVERT :
2069 {
2070 if (MessageBox(hwnd, TEXT(CONVERT_PROJECT), L"", MB_OKCANCEL) == IDOK)
2071 {
2072 ProjectTree_Open(hwnd, id);
2073 }
2074
2075 PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDM_PROJECT_OPTIMIZE, 0), 0);
2076 break;
2077 }
2078
2079 case IDM_INIT :
2080 case IDM_PROJECT_NEW :
2081 case IDM_PROJECT_OPEN :
2082 {
2083 ProjectTree_Open(hwnd, id);
2084 break;
2085 }
2086
2087 case IDM_DATA_IMPORT :
2088 {
2089 int newLines = CreateTableFromCSV(hwnd);
2090
2091 if (newLines >= 0)
2092 {
2093 ProjectTree_Update(hwnd);
2095 }
2096
2097 SetForegroundWindow(hwnd);
2098
2099 break;
2100 }
2101
2103 {
2104 CreateCSVFromView(hwnd);
2105 break;
2106 }
2107
2109 {
2110 int noTable = CreateTableFromView(hwnd);
2111
2112 if (!noTable)
2113 {
2114 ProjectTree_Update(hwnd);
2116 }
2117
2118 SetForegroundWindow(hwnd);
2119
2120 break;
2121 }
2122
2123 case IDM_TABLE_EXPORT :
2124 case IDM_TABLE_RENAME :
2125 {
2126 HTREEITEM hSelectedTableItem = TreeView_GetSelection(hMainProjectTree);
2127
2128 if (hSelectedTableItem)
2129 {
2130 TV_ITEM item = {0};
2131 item.mask = TVIF_PARAM;
2132 item.hItem = hSelectedTableItem;
2133
2134 if ((TreeView_GetItem(hMainProjectTree, &item) == TRUE)
2135 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2136 {
2137 if (id == IDM_TABLE_RENAME)
2138 {
2139 SetFocus(hMainProjectTree);
2140 TreeView_EditLabel(hMainProjectTree, hSelectedTableItem);
2141 }
2142 else if (id == IDM_TABLE_EXPORT)
2143 {
2144 ProjectTree_ViewSelectedTable(hwnd, hSelectedTableItem);
2145 CreateCSVFromView(hwnd);
2146 }
2147 }
2148 }
2149
2150 break;
2151 }
2152
2153 case IDM_TABLE_DELETE :
2154 {
2156 break;
2157 }
2158
2159 case IDM_DATA_CLOSE :
2160 {
2161 DataView_Close(hwnd);
2162 ProjectTree_Update(hwnd);
2163 break;
2164 }
2165
2166 case IDM_PROJECT_UPDATE :
2167 {
2168 ProjectTree_Update(hwnd);
2169 break;
2170 }
2171
2173 {
2174 HANDLE hPb = StartProgressBar(L"Optimisation en cours ...", -2);
2175 RequestInDB(currentDataBase, L"ANALYSE;");
2176 StopProgressBar(hPb);
2177 break;
2178 }
2179
2181 {
2183 break;
2184 }
2185
2187 {
2189 break;
2190 }
2191
2192 case IDM_SQL_FILE :
2193 {
2194 ExecuteSQLScript(hwnd, NULL);
2195 ProjectTree_Update(hwnd);
2196 break;
2197 }
2198
2199 case IDM_SQL_QUERY :
2200 {
2202 ProjectTree_Update(hwnd);
2203 break;
2204 }
2205
2206 case IDM_PROJECT_CLOSE :
2207 {
2208 ProjectTree_Close(hwnd);
2209 break;
2210 }
2211
2212 default :
2213 {
2214 Main_OnExtraCommand(hwnd, id, hwndCtl, codeNotify);
2215 break;
2216 }
2217 }
2218}
2219
2220
2230void Main_OnContextMenu(HWND hwnd, HWND hwndContext, short int xPos, short int yPos)
2231{
2232 HMENU hMenu = NULL;
2233
2234 freezeDataView = TRUE;
2235
2236 POINT pt = {xPos, yPos};
2237 ScreenToClient(hwndContext, &pt);
2238
2239 if (hwndContext == hMainDataView)
2240 {
2241 ZeroMemory(&selectedCellInfo, sizeof(selectedCellInfo));
2242 selectedCellInfo.pt = pt;
2243
2244 ListView_SubItemHitTest(hwndContext, &selectedCellInfo);
2245
2246 hMenu = LoadMenu((HINSTANCE)GetWindowInstance(hwnd), L"ViewMenu");
2247 }
2248 else if (hwndContext == hMainProjectTree)
2249 {
2250 TVHITTESTINFO tvhti = {0};
2251 tvhti.pt = pt;
2252
2253 TreeView_HitTest(hwndContext, &tvhti);
2254
2255 if (tvhti.flags & TVHT_ONITEM)
2256 {
2257 TV_ITEM item = {0};
2258
2259 item.mask = TVIF_PARAM;
2260 item.hItem = tvhti.hItem;
2261
2262 if ((TreeView_GetItem(hMainProjectTree, &item) == TRUE)
2263 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2264 {
2265 // avant d'éditer, récupère la sélection courante
2266 hActualSelectedTableItem = TreeView_GetSelection(hMainProjectTree);
2267
2268 TreeView_SelectItem(hwndContext, tvhti.hItem);
2269 hMenu = LoadMenu((HINSTANCE)GetWindowInstance(hwnd), L"TreeMenu");
2270 }
2271 }
2272 }
2273 else if (hwndContext == hMainQueryEdit)
2274 {
2275 RF_ContextMenu(hwnd, hwndContext, xPos, yPos, 1);
2276 }
2277 else if (hwndContext == hMainQueryError)
2278 {
2279 RF_ContextMenu(hwnd, hwndContext, xPos, yPos, 0);
2280 }
2281
2282 if (hMenu)
2283 {
2284 static HMENU hPopMenu;
2285 hPopMenu = GetSubMenu(hMenu, 0);
2286
2287 TrackPopupMenuEx(hPopMenu, 0, xPos, yPos, hwnd, NULL);
2288 DestroyMenu(hMenu);
2289 }
2290
2291 freezeDataView = FALSE;
2292}
2293
2294
2302void ProjectTree_ViewSelectedTable(HWND hwnd, HTREEITEM hItem)
2303{
2304 QueryBar_Update(L"", L"");
2305 DataView_Close(hwnd);
2306
2307 if (hItem)
2308 {
2309 TV_ITEM item;
2310
2311 wchar_t *tableName = calloc(MIN_BUF, sizeof(wchar_t));
2312
2313 if (tableName)
2314 {
2316 {
2318 }
2319
2320 currentSelectedTable = tableName;
2321
2322 item.mask = TVIF_TEXT | TVIF_PARAM;
2323 item.lParam = 0;
2324 item.pszText = tableName;
2325 item.cchTextMax = MIN_BUF;
2326 item.hItem = hItem;
2327
2328 if ((TreeView_GetItem(hMainProjectTree, &item) == TRUE)
2329 && ((item.lParam == PROJECTTREE_TABLE) || (item.lParam == PROJECTTREE_APPTABLE)))
2330 {
2331 size_t length = wcslen(tableName) + sizeof("SELECT * FROM \"\"");
2332 wchar_t *command = calloc(length, sizeof(wchar_t));
2333
2334 if (command)
2335 {
2336 swprintf(command, length, L"SELECT * FROM \"%ls\"", tableName);
2337
2338 NullFree(originalCommand);
2339 NullFree(currentCommand);
2340 currentCommand = command;
2341
2342 int nbRows = DataView_Update(hwnd, &hMainDataView, &rDataView, &currentDataBase, command, USE_TEMP_VIEW | ACTUAL_TABLE);
2343
2345
2346 if (nbRows >= 0)
2347 {
2348 SetWindowSubclass(hMainDataView, DataView_Procedure, SUBCLASS_TABLE_ID, 0);
2349
2350 originalCommand = _wcsdup(command);
2351
2352 SetVisibility(0, SHOW, 0);
2353 StatusBar_Update((nbRows != INT32_MAX) ? tableName : NULL, nbRows);
2354 }
2355 else
2356 {
2357 currentCommand = NULL;
2358 free(command);
2359 }
2360 }
2361 }
2362 }
2363 }
2364}
2365
2366
2376int Main_OnNotify_DrawDataView(HWND hwnd, LPNMLVCUSTOMDRAW lplvcd)
2377{
2378 static int clrText;
2379 static int clrTextBk;
2380
2381 switch (lplvcd->nmcd.dwDrawStage)
2382 {
2383 case CDDS_PREPAINT :
2384 {
2385 return CDRF_NOTIFYITEMDRAW;
2386 }
2387
2388 case CDDS_ITEMPREPAINT :
2389 {
2390 clrText = lplvcd->clrText;
2391 clrTextBk = lplvcd->clrTextBk;
2392
2393 return CDRF_NOTIFYSUBITEMDRAW;
2394 }
2395
2396 case CDDS_SUBITEM | CDDS_ITEMPREPAINT :
2397 {
2398 /*(lplvcd->iSubItem == 3)*/ // cible le numéro de colonne
2399 /*(lplvcd->nmcd.dwItemSpec == 2)*/ // cible le numéro de ligne
2400 /*(lplvcd->nmcd.lItemlParam == <valeur perso>)*/ // cible le paramètre optionnel de l'item (ligne)
2401
2402 switch (lplvcd->iSubItem)
2403 {
2404 case 0 :
2405 {
2406 if (!mainFixedBlackFont)
2407 {
2408 UINT dpi = GetWindowDpi(hwnd);
2409 mainFixedBlackFont = CreateFontForDPI(FIXED_FONT, FW_BLACK, SIZE_OF_FONT, dpi);
2410 }
2411
2413 {
2414 SelectObject(lplvcd->nmcd.hdc, mainFixedBlackFont);
2415 }
2416
2417 lplvcd->clrText = clrText;
2418 lplvcd->clrTextBk = GetSysColor(COLOR_BTNFACE);
2419
2420 break;
2421 }
2422
2423 default :
2424 {
2425 if (!mainFixedFont)
2426 {
2427 UINT dpi = GetWindowDpi(hwnd);
2428 mainFixedFont = CreateFontForDPI(FIXED_FONT, FW_THIN, SIZE_OF_FONT, dpi);
2429 }
2430
2431 if (mainFixedFont)
2432 {
2433 SelectObject(lplvcd->nmcd.hdc, mainFixedFont);
2434 }
2435
2436 lplvcd->clrText = clrText;
2437 lplvcd->clrTextBk = clrTextBk;
2438
2439 break;
2440 }
2441 }
2442
2443 return CDRF_NEWFONT;
2444 }
2445
2446 default :
2447 {
2448 return CDRF_DODEFAULT;
2449 }
2450 }
2451}
2452
2453
2461void Main_OnNotify_ApplyFilter(HWND hwnd, HWND hHeader)
2462{
2463 if (hHeader && currentCommand)
2464 {
2465 int length = wcslen(originalCommand) + MAX_BUF;
2466 wchar_t *query = calloc(length, sizeof(wchar_t));
2467
2468 if (query)
2469 {
2470 dataViewPage = 0;
2471 dataViewNbRows = 0;
2472
2473 swprintf(query, length, L"SELECT * FROM (%ls)", originalCommand);
2474
2475 int nbColumns = Header_GetItemCount(hHeader);
2476
2477 int testColumn = 0;
2478
2479 for (int column = 1; column < nbColumns; ++ column)
2480 {
2481 wchar_t columnFilter[MIN_BUF] = {0};
2482 wchar_t columnName[MIN_BUF] = {0};
2483
2484 HD_ITEM hdi = {0};
2485 HD_TEXTFILTER htf = {0};
2486
2487 hdi.mask = HDI_FILTER | HDI_TEXT;
2488
2489 hdi.pszText = columnName;
2490 hdi.cchTextMax = _countof(columnName) - 1;
2491
2492 hdi.type = HDFT_ISSTRING;
2493 //hdi.type = HDFT_ISNUMBER;
2494 //hdi.type = HDFT_ISDATE;
2495 hdi.pvFilter = &htf;
2496
2497 htf.pszText = columnFilter;
2498 htf.cchTextMax = _countof(columnFilter) - 1;
2499
2500 Header_GetItem(hHeader, column, &hdi);
2501
2502 if (columnFilter[0])
2503 {
2504 swprintf(&query[wcslen(query)], length - wcslen(query),
2505 L" %ls \"%ls\" LIKE '%ls'",
2506 (!testColumn) ? L"WHERE" : L"AND", columnName, columnFilter);
2507
2508 ++ testColumn;
2509 }
2510 }
2511
2512 SetWindowRedraw(hMainDataView, FALSE);
2513 ListView_DeleteAllItems(hMainDataView);
2514
2515 currentCommand = query;
2516
2517 int nbRows = FillAListView_Win32(hwnd, hMainDataView, currentDataBase, currentDataBaseName, query, &sqlError, USE_TEMP_TABLE, NULL);
2518
2520
2521 if (nbRows >= 0)
2522 {
2523 StatusBar_Update((nbRows != INT32_MAX) ? L"" : NULL, nbRows);
2524 dataViewNbRows = nbRows;
2525 }
2526 else
2527 {
2528 NullFree(currentCommand);
2530 }
2531
2532 SetVisibility(0, SHOW, 0);
2533
2534 SetWindowRedraw(hMainDataView, TRUE);
2535 }
2536 }
2537}
2538
2539
2547{
2548 if (scrollingTimer)
2549 {
2550 KillTimer(hwnd, scrollingTimer);
2551 }
2552
2553 scrollingTimer = SetTimer(hwnd, SCROLL_TIMER_ID, SCROLL_IDLE_MS, NULL);
2554}
2555
2556
2564int Main_OnNotify_FillDataView(HWND hwnd __attribute__((unused)),
2565 LPNMLVDISPINFOW lplvdi)
2566{
2567 int result = FALSE;
2568
2569 if (lplvdi->item.mask & LVIF_TEXT)
2570 {
2571 int64_t line = (dataViewPage * DATAVIEW_MAXROWS) + lplvdi->item.iItem;
2572 int column = lplvdi->item.iSubItem;
2573
2574 result = TRUE;
2575
2576 if ((!scrollingTimer || !column) && (line >= 0))
2577 {
2578 static wchar_t *text;
2579 NullFree(text);
2580
2581 if (column == 0)
2582 {
2583 static wchar_t number[INT_MAXSIZE + 1];
2584 swprintf(number, _countof(number), L"%lld", line + 1);
2585 text = _wcsdup(number);
2586 }
2587 else if (column > 0)
2588 {
2589 text = _wcsdup(ReadInTableFromSQLiteDB(currentDataBase, L"SELECT * FROM \"" APP_VIEWTABLE L"\"", line, column - 1, 0));
2590 Replace(text, L'\n', L' ');
2591 }
2592 else
2593 {
2594 text = NULL;
2595 }
2596
2597 // la chaîne copiée ne doit pas dépasser la longueur maximale acceptable (NUL final inclus)
2598
2599 if (lplvdi->item.cchTextMax && text && (wcslen(text) >= (size_t)lplvdi->item.cchTextMax))
2600 {
2601 text[lplvdi->item.cchTextMax - 1] = L'\0';
2602 }
2603
2604 lplvdi->item.pszText = text ? text : L"";
2605
2606 // redimensionnement de la colonne
2607 if (1)
2608 {
2609 int textWidth = EstimateTextWidthWithFont(hMainDataView, text, mainFixedFont);
2610 int columnWidth = ListView_GetColumnWidth(hMainDataView, column);
2611
2612 const int padding = 16;
2613 if (textWidth + padding > columnWidth)
2614 {
2615 ListView_SetColumnWidth(hMainDataView, column, textWidth + padding);
2616 InvalidateRect(hMainDataView, NULL, TRUE);
2617 }
2618 }
2619 }
2620 else
2621 {
2622 lplvdi->item.pszText = L"\267\267\267";
2623 }
2624 }
2625
2626 return result;
2627}
2628
2629
2638BOOL Main_OnNotify(HWND hwnd,
2639 int idCtrl __attribute__((unused)),
2640 LPNMHDR pnmh)
2641{
2642 int result = FALSE;
2643
2644 static wchar_t oldItemText[MIN_BUF];
2645
2646 switch (pnmh->code)
2647 {
2648 // message de sélection d'un item du ProjectView
2649
2650 case TVN_SELCHANGED :
2651 {
2652 if (pnmh->hwndFrom == hMainProjectTree)
2653 {
2654 if (!freezeDataView)
2655 {
2656 HTREEITEM hItem = TreeView_GetSelection(hMainProjectTree);
2657 ProjectTree_ViewSelectedTable(hwnd, hItem);
2658 }
2659 }
2660
2661 break;
2662 }
2663
2664
2665 case TVN_BEGINLABELEDIT :
2666 {
2667 if (pnmh->hwndFrom == hMainProjectTree)
2668 {
2669 LPNMTVDISPINFO pdi = (LPNMTVDISPINFO)pnmh;
2670 swprintf(oldItemText, MIN_BUF, L"%ls", (pdi->item.pszText) ? pdi->item.pszText : L"");
2671 }
2672
2673 break;
2674 }
2675
2676 case TVN_ENDLABELEDIT :
2677 {
2678 if (pnmh->hwndFrom == hMainProjectTree)
2679 {
2680 LPNMTVDISPINFO pdi = (LPNMTVDISPINFO)pnmh;
2681
2682 if (pdi->item.pszText)
2683 {
2684 TV_ITEM tvi = {0};
2685
2686 tvi.mask = TVIF_TEXT;
2687 tvi.hItem = pdi->item.hItem;
2688 tvi.pszText = pdi->item.pszText;
2689
2690 TreeView_SetItem(hMainProjectTree, &tvi);
2691
2692 ProjectTree_RenameTable(hwnd, oldItemText, pdi->item.pszText);
2693 }
2694 }
2695
2696 break;
2697 }
2698
2699
2700 // gère l'aspect et la mise en forme du ListView (polices, couleurs, ...)
2701
2702 case NM_CUSTOMDRAW :
2703 {
2704 if (pnmh->hwndFrom == hMainDataView)
2705 {
2706 LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pnmh;
2707 result = Main_OnNotify_DrawDataView(hwnd, lplvcd);
2708 }
2709
2710 break;
2711 }
2712
2713
2714 case LVN_BEGINSCROLL:
2715 case LVN_ENDSCROLL:
2716 {
2717 if (pnmh->hwndFrom == hMainDataView)
2718 {
2720 }
2721
2722 break;
2723 }
2724
2725
2726 // message indiquant la partie de la table à placer en cache
2727
2728 case LVN_ODCACHEHINT :
2729 {
2730 if ((pnmh->hwndFrom == hMainDataView) && !scrollingTimer)
2731 {
2732 LPNMLVCACHEHINT lplvch = (LPNMLVCACHEHINT)pnmh;
2733
2734 int64_t line = (dataViewPage * DATAVIEW_MAXROWS) + lplvch->iFrom;
2735 int number = (lplvch->iTo - lplvch->iFrom) + 1;
2736
2737 ReadInTableFromSQLiteDB(currentDataBase, L"SELECT * FROM \"" APP_VIEWTABLE L"\"", line, 0, number);
2738 }
2739
2740 break;
2741 }
2742
2743
2744 // alimente le DataView en données à la demande
2745
2746 case LVN_GETDISPINFO :
2747 {
2748 if (pnmh->hwndFrom == hMainDataView)
2749 {
2750 LPNMLVDISPINFOW lplvdi = (LPNMLVDISPINFOW)pnmh;
2751 result = Main_OnNotify_FillDataView(hwnd, lplvdi);
2752 }
2753
2754 break;
2755 }
2756
2757
2758 // gère la recherche d'un item particulier
2759
2760 case LVN_ODFINDITEM :
2761 {
2762 return -1;
2763 }
2764
2765
2766 // gère une demande de filtrage sur clic du bouton de filtre
2767
2768 case HDN_FILTERBTNCLICK :
2769 {
2770 LPNMHDFILTERBTNCLICK lphdfi = (LPNMHDFILTERBTNCLICK)pnmh;
2771
2772 HWND hHeader = lphdfi->hdr.hwndFrom;
2773 Main_OnNotify_ApplyFilter(hwnd, hHeader);
2774
2775 break;
2776 }
2777
2778
2779 // gère une demande de filtrage automatique
2780
2781 case HDN_FILTERCHANGE :
2782 {
2783 /*LPNMHEADER lphead = (LPNMHEADER)pnmh;
2784
2785 HWND hHeader = pnmh->hwndFrom;
2786 Main_OnNotify_ApplyFilter(hwnd, hHeader);*/
2787
2788 break;
2789 }
2790
2791
2792 case LVN_COLUMNCLICK :
2793 {
2794 HWND hListView = pnmh->hwndFrom;
2795 LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh;
2796
2797 int column = pnmv->iSubItem;
2798 ListView_SetSelectedColumn(hListView, column);
2799
2800 break;
2801 }
2802
2803
2804 case NM_DBLCLK :
2805 {
2806 if (pnmh->hwndFrom == hMainDataView)
2807 {
2808 LPNMLISTVIEW pnmv = (LPNMLISTVIEW)pnmh;
2809
2810 int64_t line = pnmv->iItem;
2811 int column = pnmv->iSubItem;
2812
2813 const wchar_t *value = GetCellValue(line, column);
2814
2815 if (value)
2816 {
2817 static wchar_t *text;
2818 NullFree(text);
2819
2820 text = _wcsdup(value);
2821
2822 if (text)
2823 {
2824 HD_ITEM hdi = {0};
2825 HD_TEXTFILTER htf = {0};
2826
2827 hdi.mask = HDI_FILTER;
2828 hdi.pvFilter = &htf;
2829 htf.pszText = text;
2830
2831 HWND hHeader = ListView_GetHeader(pnmh->hwndFrom);
2832 Header_SetItem(hHeader, column, &hdi);
2833 }
2834 }
2835 }
2836
2837 break;
2838 }
2839
2840
2841 default :
2842 {
2843 break;
2844 }
2845 }
2846
2847 return result;
2848}
2849
2850
2860LRESULT CALLBACK Main_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2861{
2862 switch (uMsg)
2863 {
2864 HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate);
2865 HANDLE_MSG(hwnd, WM_CLOSE, Main_OnClose);
2866 HANDLE_MSG(hwnd, WM_DESTROY, Main_OnClose);
2867 HANDLE_MSG(hwnd, WM_PAINT, Main_OnPaint);
2868 HANDLE_MSG(hwnd, WM_SIZE, Main_OnSize);
2869 HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
2870 HANDLE_MSG(hwnd, WM_CONTEXTMENU, Main_OnContextMenu);
2871 HANDLE_MSG(hwnd, WM_NOTIFY, Main_OnNotify);
2872
2873 case WM_ERASEBKGND :
2874 {
2875 HDC hdc = (HDC)wParam;
2876
2877 RECT rect;
2878
2879 if (!hMainProjectTree)
2880 {
2881 GetClientRect(hwnd, &rect);
2882 FillRect(hdc, &rect, GetSysColorBrush(COLOR_BTNFACE));
2883 }
2884 else if (!hMainDataView)
2885 {
2886 FillRect(hdc, &rDataView, GetSysColorBrush(COLOR_BTNFACE));
2887 }
2888
2889 return TRUE;
2890 }
2891
2892 case WM_TIMER :
2893 {
2894 // temporisation du relâchement de la barre de scroll
2895 // celle-ci peut être vue à tort comme relachée, un tempo permet de gérer
2896 if (wParam == SCROLL_TIMER_ID)
2897 {
2898 KillTimer(hwnd, SCROLL_TIMER_ID);
2899 scrollingTimer = 0;
2900
2901 InvalidateRect(hMainDataView, NULL, TRUE);
2902 UpdateWindow(hMainDataView);
2903 }
2904
2905 if (wParam == NBROWS_TIMER_ID)
2906 {
2907 int64_t nbRows = VerifierTermine(NULL);
2908
2909 if (nbRows != -1)
2910 {
2911 KillTimer(hwnd, NBROWS_TIMER_ID);
2912 dataViewNbRows = nbRows;
2913 ListView_SetItemCountEx(hMainDataView, (nbRows > DATAVIEW_MAXROWS) ? DATAVIEW_MAXROWS : nbRows,
2914 LVSICF_NOINVALIDATEALL | LVSICF_NOSCROLL);
2915 StatusBar_Update((nbRows != INT32_MAX) ? L"" : NULL, nbRows);
2916 }
2917 }
2918
2919 break;
2920 }
2921
2922 default :
2923 {
2924 return DefWindowProc(hwnd, uMsg, wParam, lParam);
2925 }
2926 }
2927
2928 return FALSE;
2929}
2930
2931
2943LRESULT CALLBACK ProjectTree_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
2944 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
2945{
2946 switch (uMsg)
2947 {
2948 case WM_WINDOWPOSCHANGING :
2949 {
2950 RestartScrollingTimer(GetParent(hwnd));
2951
2952 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
2953
2954 if (!(wp->flags & (SWP_NOSIZE/* | SWP_NOMOVE*/)))
2955 {
2956 rProjectTree.left = wp->x;
2957 rProjectTree.top = wp->y;
2958 rProjectTree.right = wp->x + wp->cx;
2959 rProjectTree.bottom = wp->y + wp->cy;
2960
2961 RECT r;
2962 GetClientRect(GetParent(hwnd), &r);
2963
2964 RECT rSB;
2965 GetClientRect(hMainStatusBar, &rSB);
2966
2967 int bottom = r.bottom - rSB.bottom;
2968
2969 if (wp->x > 0)
2970 {
2971 wp->cx += wp->x;
2972 wp->x = 0;
2973 }
2974
2975 if (wp->y > 0)
2976 {
2977 wp->cy += wp->y;
2978 wp->y = 0;
2979 }
2980
2981 if (wp->cy > (bottom - BUTTON_SIZE))
2982 {
2983 wp->cy = bottom - BUTTON_SIZE;
2984 }
2985
2986 xTableView = wp->cx;
2987 SetWindowPos(hMainDataView, 0, wp->cx, 0, r.right - wp->cx, wp->cy, SWP_NOSENDCHANGING);
2988
2989 rDataView.left = wp->cx;
2990 rDataView.top = 0;
2991 rDataView.right = r.right;
2992 rDataView.bottom = wp->cy;
2993
2994 SetWindowPos(hMainQueryError, 0, 0, wp->cy, xQueryEdit, bottom - wp->cy, SWP_NOSENDCHANGING);
2995 SetWindowPos(hMainQueryEdit, 0, xQueryEdit, wp->cy, (r.right - BUTTON_SIZE) - xQueryEdit, bottom - wp->cy, SWP_NOSENDCHANGING);
2996 SetWindowPos(hMainQueryExecute, 0, (r.right - BUTTON_SIZE), wp->cy, BUTTON_SIZE, bottom - wp->cy, SWP_NOSENDCHANGING);
2997
2998 return 0;
2999 }
3000
3001 break;
3002 }
3003
3004 case WM_NCDESTROY:
3005 {
3006 RemoveWindowSubclass(hwnd, ProjectTree_Procedure, uIdSubclass);
3007 break;
3008 }
3009
3010 default :
3011 {
3012 break;
3013 }
3014 }
3015
3016 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
3017}
3018
3019
3031LRESULT CALLBACK DataView_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
3032 UINT_PTR uIdSubclass, DWORD_PTR dwRefData __attribute__((unused)))
3033{
3034 switch (uMsg)
3035 {
3036 case WM_WINDOWPOSCHANGING :
3037 {
3038 RestartScrollingTimer(GetParent(hwnd));
3039
3040 WINDOWPOS *wp = (LPWINDOWPOS) lParam;
3041
3042 if (!(wp->flags & (SWP_NOSIZE/* | SWP_NOMOVE*/)))
3043 {
3044 rDataView.left = wp->x;
3045 rDataView.top = wp->y;
3046 rDataView.right = wp->x + wp->cx;
3047 rDataView.bottom = wp->y + wp->cy;
3048
3049 RECT rParent;
3050 GetClientRect(GetParent(hwnd), &rParent);
3051
3052 RECT rSB;
3053 GetClientRect(hMainStatusBar, &rSB);
3054
3055 int bottom = rParent.bottom - rSB.bottom;
3056
3057 if ((wp->x + wp->cx) < rParent.right)
3058 {
3059 wp->cx = rParent.right - wp->x;
3060 }
3061
3062 if (wp->y > 0)
3063 {
3064 wp->cy += wp->y;
3065 wp->y = 0;
3066 }
3067
3068 if (wp->cy > (bottom - BUTTON_SIZE))
3069 {
3070 wp->cy = bottom - BUTTON_SIZE;
3071 }
3072
3073 xTableView = wp->x;
3074 SetWindowPos(hMainProjectTree, 0, 0, 0, wp->x, wp->cy, SWP_NOSENDCHANGING);
3075
3076 rProjectTree.left = 0;
3077 rProjectTree.top = 0;
3078 rProjectTree.right = wp->cx;
3079 rProjectTree.bottom = wp->cy;
3080
3081 SetWindowPos(hMainQueryEdit, 0, xQueryEdit, wp->cy, (rParent.right - BUTTON_SIZE) - xQueryEdit, bottom - wp->cy, SWP_NOSENDCHANGING);
3082 SetWindowPos(hMainQueryError, 0, 0, wp->cy, xQueryEdit, bottom - wp->cy, SWP_NOSENDCHANGING);
3083 SetWindowPos(hMainQueryExecute, 0, (rParent.right - BUTTON_SIZE), wp->cy, BUTTON_SIZE, bottom - wp->cy, SWP_NOSENDCHANGING);
3084
3085 return 0;
3086 }
3087
3088 break;
3089 }
3090
3091 case WM_NCDESTROY:
3092 {
3093 RemoveWindowSubclass(hwnd, DataView_Procedure, uIdSubclass);
3094 break;
3095 }
3096
3097 default :
3098 {
3099 break;
3100 }
3101 }
3102
3103 return DefSubclassProc(hwnd, uMsg, wParam, lParam);
3104}
3105
3106
3120int64_t DataView_Update(HWND hwnd, HWND * pListView, RECT * rListView, sqlite3 **db, const wchar_t *command, int useTmp)
3121{
3122 int64_t nbRows = -1;
3123
3124 dataViewPage = 0;
3125 dataViewNbRows = 0;
3126
3127 if (db && command && command[0])
3128 {
3129 // Ouverture ou création de la base SQLite courante si besoin
3130
3131 int result = SQLITE_OK;
3132
3133 if (!db[0])
3134 {
3135 result = OpenSQLiteDB(db, currentDataBaseName, FALSE);
3136 }
3137
3138 if (result == SQLITE_OK)
3139 {
3140 // Destruction du ListView précédent
3141
3142 if (pListView[0])
3143 {
3144 DestroyWindow(pListView[0]);
3145 }
3146
3147 // crée un nouveau ListView
3148
3149 int virtualListView = (useTmp & USE_NO_TEMP) ? 0 : LVS_OWNERDATA;
3150 int listView_styles = LVS_REPORT/* | LVS_NOSORTHEADER*/;
3151 int window_styles = WS_CHILD | WS_THICKFRAME | WS_CLIPSIBLINGS;
3152
3153 // c'est le WS_THICKFRAME qui pose le petit problème de largeur de la dernière colonne et de hauteur de la dernière ligne
3154 // mais sans cette option, le ListView n'a plus de bordure de redimensionnement
3155
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);
3159
3160 HWND hListView = pListView[0];
3161
3162 if (hListView)
3163 {
3164 ListView_SetExtendedListViewStyleEx(hListView,
3165 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_DOUBLEBUFFER
3166 | /*LVS_EX_HEADERDRAGDROP | */LVS_EX_LABELTIP,
3167 LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_DOUBLEBUFFER
3168 | LVS_EX_HEADERDRAGDROP | LVS_EX_LABELTIP);
3169
3170 //ApplyDarkMode(hListView, L"DarkMode_Explorer");
3171
3172 SetWindowPos(hListView,
3173 HWND_TOP,
3174 rListView->left,
3175 rListView->top,
3176 rListView->right - rListView->left,
3177 rListView->bottom - rListView->top,
3178 0);
3179
3180 nbRows = FillAListView_Win32(hwnd, hListView, db[0], currentDataBaseName, command, &sqlError, useTmp,
3181 (useTmp & USE_NO_TEMP) ? DataView_UpdateAll : DataView_UpdateHeader);
3182
3183 if (nbRows < 0)
3184 {
3185 // Destruction du ListView en cas d'échec
3186
3187 DestroyWindow(hListView);
3188 pListView[0] = NULL;
3189 }
3190 else
3191 {
3192 dataViewNbRows = nbRows;
3193 /*if (!(useTmp & ACTUAL_TABLE) || (nbRows == INT32_MAX))
3194 {
3195 KillTimer(hwnd, NBROWS_TIMER_ID);
3196 SetTimer(hwnd, NBROWS_TIMER_ID, NBROWS_IDLE_MS, NULL);
3197 }*/
3198 }
3199 }
3200 }
3201 }
3202
3203 return nbRows;
3204}
3205
3206
3219int64_t DataView_UpdateWithAFile(HWND hwnd, HWND * pListView, RECT * rListView, sqlite3 **db, wchar_t **command, const wchar_t *fileName)
3220{
3221 int64_t nbRows = -1;
3222 wchar_t *newFileName = NULL;
3223
3224 if (db)
3225 {
3226 if (!fileName)
3227 {
3228 newFileName = FileInChooser(L"Lancer un script SQL", hwnd, L"Script SQL (*.sql)\0*.sql\0");
3229 }
3230
3231 FILE *fileIn = OpenTextFileIn(SOFT_NAMEW, fileName ? fileName : newFileName);
3232
3233 if (fileIn)
3234 {
3235 _fseeki64(fileIn, 0L, SEEK_END);
3236 _off64_t fileSize = _ftelli64(fileIn);
3237 _fseeki64(fileIn, 0L, SEEK_SET);
3238
3239 wchar_t *sql = calloc(fileSize + 1, sizeof(wchar_t));
3240
3241 if (sql)
3242 {
3243 fread(sql, sizeof(wchar_t), fileSize, fileIn);
3244
3245 // Ouverture ou création de la base SQLite courante si besoin
3246
3247 int result = SQLITE_OK;
3248
3249 if (!db[0])
3250 {
3251 wchar_t *projectName = calloc(FILENAMELENGTH_MAX, sizeof(wchar_t));
3252 if (projectName)
3253 {
3254 LoadOption(SOFT_NAMEW, SOFT_NAMEW, OPTION_CURRENTPROJECT, projectName, FILENAMELENGTH_MAX);
3255 result = OpenSQLiteDB(db, projectName, FALSE);
3256 free(projectName);
3257 }
3258 }
3259
3260 if (result == SQLITE_OK)
3261 {
3262 const wchar_t *lastSql = ScriptInDBwithAnswer(db[0], sql);
3263
3264 if (command && lastSql && lastSql[0])
3265 {
3266 NullFree(command[0]);
3267 command[0] = _wcsdup(lastSql);
3268 nbRows = DataView_Update(hwnd, pListView, rListView, db, lastSql, USE_NO_TEMP);
3269 }
3270 }
3271
3272 free(sql);
3273 }
3274
3275 fclose(fileIn);
3276 }
3277 }
3278
3279 if (newFileName)
3280 {
3281 free(newFileName);
3282 }
3283
3284 return nbRows;
3285}
3286
3287
3297LRESULT CALLBACK ProcedureOptions(HWND hwnd,
3298 UINT uMsg,
3299 WPARAM wParam,
3300 LPARAM lParam __attribute__((unused)))
3301{
3302 static HFONT hFont;
3303
3304 switch (uMsg)
3305 {
3306 case WM_INITDIALOG :
3307 {
3308
3309
3310 RecreateDialogFont(hwnd, &hFont, VARIABLE_FONT, SIZE_OF_FONT);
3311
3312 return TRUE;
3313 }
3314
3315 case WM_COMMAND :
3316 {
3317 switch (LOWORD(wParam))
3318 {
3319 case IDOK :
3320 {
3321 EndDialog(hwnd, 1);
3322
3323 if (hFont)
3324 {
3325 DeleteObject(hFont);
3326 hFont = NULL;
3327 }
3328
3329 return TRUE;
3330 }
3331
3332 case IDCANCEL :
3333 {
3334 EndDialog(hwnd, 0);
3335
3336 if (hFont)
3337 {
3338 DeleteObject(hFont);
3339 hFont = NULL;
3340 }
3341
3342 return TRUE;
3343 }
3344
3345 default :
3346 {
3347 return TRUE;
3348 }
3349 }
3350 break;
3351 }
3352
3353 default :
3354 {
3355 break;
3356 }
3357 }
3358
3359 return FALSE;
3360}
#define APP_FILES_ID
Définition Defines.h:38
#define APP_HISTORY_ID
Définition Defines.h:35
#define APP_FILES
Définition Defines.h:39
#define APP_FIELD
Définition Defines.h:33
#define OPTION_CURRENTPROJECT
définitions relatives au fichier des options
Définition Defines.h:44
#define APP_VIEWTABLE
définitions spéciales propres à Taupie
Définition Defines.h:31
#define APP_HISTORY
Définition Defines.h:36
void Main_OnContextMenu(HWND hwnd, HWND hwndContext, short int xPos, short int yPos)
Gestion du menu contextuel.
Définition TaupieGUI.c:2230
static int dataViewPage
Définition TaupieGUI.c:101
int Main_OnNotify_DrawDataView(HWND hwnd, LPNMLVCUSTOMDRAW lplvcd)
Redessine sur demande le listview (police, couleur, fond).
Définition TaupieGUI.c:2376
static LVHITTESTINFO selectedCellInfo
Définition TaupieGUI.c:87
#define DATAVIEW_MAXROWS
Définition TaupieGUI.c:100
int64_t ProjectTree_Update(HWND hwnd)
Crée un TreeView à partir du contenu de la base courante, et l'affiche aux bonnes dimensions.
Définition TaupieGUI.c:219
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.
Définition TaupieGUI.c:3120
static HWND hMainStatusBar
Définition TaupieGUI.c:64
static int64_t dataViewNbRows
Définition TaupieGUI.c:102
void Main_OnClose(HWND hwnd)
Supprime les fichiers temporaires et ferme l'application.
Définition TaupieGUI.c:803
#define SCROLL_TIMER_ID
Définition TaupieGUI.c:73
static int xQueryEdit
Définition TaupieGUI.c:94
const wchar_t * GetCellValue(int64_t line, int column)
Fonction permettant de récupérer le texte d'une cellule sélectionnée.
Définition TaupieGUI.c:1828
void Main_OnSize(HWND hwnd, UINT state, UINT x, UINT y)
Gestion d'un changement de taille de la fenêtre principale.
Définition TaupieGUI.c:349
static wchar_t * currentDataBaseName
Définition TaupieGUI.c:83
void QueryBar_Update(const wchar_t *errorMsg, const wchar_t *request)
Définit le contenu de la QueryBar.
Définition TaupieGUI.c:444
static HFONT mainFixedBlackFont
Définition TaupieGUI.c:91
#define SCROLL_IDLE_MS
Définition TaupieGUI.c:74
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.
Définition TaupieGUI.c:1424
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.
Définition TaupieGUI.c:517
BOOL Main_OnNotify(HWND hwnd, int idCtrl, LPNMHDR pnmh)
Gestion des notifications des composants de la fenêtre principale.
Définition TaupieGUI.c:2638
static HTREEITEM hActualSelectedTableItem
Définition TaupieGUI.c:86
static wchar_t * originalCommand
Définition TaupieGUI.c:80
int Main_OnNotify_FillDataView(HWND hwnd, LPNMLVDISPINFOW lplvdi)
remplissage des items du DataView à la demande.
Définition TaupieGUI.c:2564
void QueryBar_Create(HWND hwnd)
Création de l'espace de saisie des requêtes.
Définition TaupieGUI.c:685
void ProjectTree_Open(HWND hwnd, int option)
Ouvre/crée un projet Taupie.
Définition TaupieGUI.c:926
LRESULT CALLBACK Main_Procedure(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure de la fenêtre principale.
Définition TaupieGUI.c:2860
static wchar_t * sqlError
Définition TaupieGUI.c:96
static wchar_t * currentSelectedTable
Définition TaupieGUI.c:84
void ProjectTree_Close(HWND hwnd)
Ferme le projet courant Taupie.
Définition TaupieGUI.c:876
void DataView_Close(HWND hwnd)
Ferme la table sélectionnée dans le ProjectTree.
Définition TaupieGUI.c:1055
void ProjectTree_Enlarge(void)
redimensionne en largeur le ProjectTree.
Définition TaupieGUI.c:839
int64_t ExecuteCustomSQLQuery(HWND hwnd)
Exécute une requête demandée par l'utilisateur.
Définition TaupieGUI.c:1131
int64_t ExecuteSQLScript(HWND hwnd, const wchar_t *fileName)
Exécute une requête demandée par l'utilisateur.
Définition TaupieGUI.c:1077
static HWND hMainQueryExecute
Définition TaupieGUI.c:68
void RestartScrollingTimer(HWND hwnd)
Relance la temporisation du DataView.
Définition TaupieGUI.c:2546
BOOL Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
Initialisation de la fenêtre principale.
Définition TaupieGUI.c:726
int64_t CreateCSVFromView(HWND hwnd)
Crée un fichier CSV à partir de la vue courante.
Définition TaupieGUI.c:1204
void Main_OnPaint(HWND hwnd)
redessine la boîte de dialogue.
Définition TaupieGUI.c:313
void Clean(void)
Supprime les fichiers temporaires de l'application.
Définition TaupieGUI.c:293
int CreateTableFromView(HWND hwnd)
Crée une table dans la base à partir de la vue courante.
Définition TaupieGUI.c:1252
int ProjectTree_DeleteTable(HWND hwnd)
Supprime une table dans l'arbre du projet.
Définition TaupieGUI.c:1920
static HWND hMainProjectTree
Définition TaupieGUI.c:63
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...
Définition TaupieGUI.c:158
int64_t ProjectTree_ViewAppTable(HWND hwnd, int id)
Affiche une table "système", non présente dans l'arbre du projet.
Définition TaupieGUI.c:1754
void SetVisibility(int project, int table, int query)
définit la visibilité des trois composants de l'écran.
Définition TaupieGUI.c:113
static HWND hMainQueryEdit
Définition TaupieGUI.c:67
int64_t DataView_UpdateWithAFile(HWND hwnd, HWND *pListView, RECT *rListView, sqlite3 **db, wchar_t **command, const wchar_t *fileName)
Définition TaupieGUI.c:3219
static int freezeDataView
Définition TaupieGUI.c:98
static RECT rProjectTree
Définition TaupieGUI.c:70
static int xTableView
Définition TaupieGUI.c:93
LRESULT CALLBACK ProcedureOptions(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
procédure du dialogue des options de ModuleTicket.
Définition TaupieGUI.c:3297
static HFONT mainFixedFont
Définition TaupieGUI.c:90
int ProjectTree_RenameTable(HWND hwnd, const wchar_t *oldTableName, const wchar_t *newTableName)
Renomme une table dans l'arbre du projet.
Définition TaupieGUI.c:1861
static wchar_t * currentCommand
Définition TaupieGUI.c:79
void StatusBar_Update(const wchar_t *tableName, int64_t records)
Définit le contenu de la barre de statut principale.
Définition TaupieGUI.c:271
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.
Définition TaupieGUI.c:469
static UINT_PTR scrollingTimer
Définition TaupieGUI.c:75
static HWND hMainQueryError
Définition TaupieGUI.c:66
static sqlite3 * currentDataBase
Définition TaupieGUI.c:82
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).
Définition TaupieGUI.c:3031
static RECT rDataView
Définition TaupieGUI.c:71
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).
Définition TaupieGUI.c:2943
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
Gère les commandes de l'application.
Définition TaupieGUI.c:1997
void Main_OnNotify_ApplyFilter(HWND hwnd, HWND hHeader)
Application du filtre courant à la vue courante des données.
Définition TaupieGUI.c:2461
void ProjectTree_ViewSelectedTable(HWND hwnd, HTREEITEM hItem)
Gère la sélection d'une table dans l'arbre du projet.
Définition TaupieGUI.c:2302
static HWND hMainDataView
Définition TaupieGUI.c:62
int64_t CreateTableFromCSV(HWND hwnd)
Crée une table dans la base courante à partir d'un fichier CSV.
Définition TaupieGUI.c:1514
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.
Définition TaupieGUI.c:599
int RecordImportedFile(const wchar_t *tableName, const wchar_t *fileName, int pathLevel)
Enregistrement des caractéristiques d'un fichier importé comme table.
Définition TaupieGUI.c:1322
static HFONT mainVariableFont
Définition TaupieGUI.c:89
Déclaration des fonctions de l'interface graphique de Taupie.
#define SUBCLASS_PROJECT_ID
Définition TaupieGUI.h:22
#define SUBCLASS_QUERYEDIT_ID
Définition TaupieGUI.h:24
#define HIDE
Définition TaupieGUI.h:28
#define SUBCLASS_TABLE_ID
Définition TaupieGUI.h:23
#define SUBCLASS_QUERYERROR_ID
Définition TaupieGUI.h:25
#define SHOW
Définition TaupieGUI.h:29
#define SUBCLASS_QUERYEXECUTE_ID
Définition TaupieGUI.h:26
#define BUTTON_SIZE
Définition TaupieGUI.h:20
#define FILETYPE_PROJECT
Définition en_locale.h:95
#define FIELD_FILESIZE
Définition en_locale.h:163
#define OPEN_PROJECT
Définition en_locale.h:85
#define NEW_PROJECT
Définition en_locale.h:83
#define FIELD_RUNDATE
Définition en_locale.h:168
#define LOG_TEXTDELETETABLE
Définition en_locale.h:181
#define MESSAGE_INFO_FAILURE
Définition en_locale.h:133
#define FIELD_FILETIME
Définition en_locale.h:165
#define DIALOG_TEXT_ASKFORTABLE
Définition en_locale.h:151
#define MENU_CLOSE
Définition en_locale.h:101
#define LOG_TEXTCREATEPROJECT
Définition en_locale.h:178
#define EMPTY_STRING
Définition en_locale.h:81
#define MENU_OPTIONS
Définition en_locale.h:122
#define CONVERT_PROJECT
Définition en_locale.h:84
#define MESSAGE_QUESTION_DROPTABLE
Définition en_locale.h:136
#define FIELD_ACTION
Définition en_locale.h:167
#define FIELD_IMPORTTIME
Définition en_locale.h:160
#define TEXT_TABLENAME
Définition en_locale.h:153
#define MENU_NEW
Définition en_locale.h:98
#define FIELD_SQL
Définition en_locale.h:171
#define FIELD_RUNTIME
Définition en_locale.h:169
#define FIELD_ERROR
Définition en_locale.h:172
#define LOG_TEXTCONVERTTOTABLE
Définition en_locale.h:182
#define FIELD_FILEPATH
Définition en_locale.h:161
#define MENU_HELP
Définition en_locale.h:123
#define MESSAGE_TITLE_WARNING
Définition en_locale.h:129
#define FIELD_FILEDATE
Définition en_locale.h:164
#define TABLE_DEFAULTNAME
Définition en_locale.h:155
#define LOG_TEXTRENAMETABLE
Définition en_locale.h:180
#define FIELD_DOTCOMMAND
Définition en_locale.h:170
#define MESSAGE_QUESTION_RENAMETABLE
Définition en_locale.h:135
#define FIELD_IMPORTDATE
Définition en_locale.h:159
#define FILETYPE_ANY
Définition en_locale.h:93
#define FIELD_FILENAME
Définition en_locale.h:162
#define FIELD_TABLENAME
Définition en_locale.h:158
#define LOG_TEXTRUNSQL
Définition en_locale.h:179
void ExtraInit(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
Initialisation de la fenêtre principale.
Définition extra.c:31
void Main_OnExtraCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
Gère les commandes spécifiques de l'application.
Définition extra.c:47
Déclaration de fonctions communes mais spécifiques hors Taupie. Ces fonctions peuvent être déclinées ...
Définitions et macros pour la localisation.
#define IDP_HELP
Définition resource.h:64
#define IDM_PROJECT_LOG_IMPORT
Définition resource.h:31
#define IDM_DATA_IMPORT
Définition resource.h:40
#define IDM_TABLE_EXPORT
Définition resource.h:49
#define IDM_DATA_CONVERT_TO_TABLE
Définition resource.h:42
#define IDM_PROJECT_LOG_COMMAND
Définition resource.h:32
#define IDM_DATA_COPYVALUE
Définition resource.h:44
#define IDM_SQL_QUERY
Définition resource.h:59
#define IDM_OPTIONS
Définition resource.h:65
#define IDM_DATA_CLOSE
Définition resource.h:39
#define IDM_TABLE_DELETE
Définition resource.h:48
#define IDM_PAGE_PREVIOUS
Définition resource.h:51
#define IDM_PROJECT
Définition resource.h:23
#define IDM_PROJECT_NEW
Définition resource.h:25
#define IDM_PROJECT_CLOSE
Définition resource.h:27
#define IDM_PROJECT_CONVERT
Définition resource.h:28
#define IDM_SQL_FILE
Définition resource.h:58
#define IDM_PROJECT_OPTIMIZE
Définition resource.h:30
#define IDM_PROJECT_OPEN
Définition resource.h:26
#define IDM_PROJECT_UPDATE
Définition resource.h:29
#define IDM_TABLE_RENAME
Définition resource.h:47
#define IDM_DATA
Définition resource.h:37
#define IDM_SQL
Définition resource.h:57
#define IDM_DATA_EXPORT_TO_FILE
Définition resource.h:41
#define IDM_PAGE_NEXT
Définition resource.h:52
#define IDM_INIT
Définition resource.h:22
#define CURRENT_RICHEDITW
Définition version.h:37
#define SOFT_NAMEW
Définition version.h:26