1
0

editquery.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. #include "main.h"
  2. #include "ml_local.h"
  3. #include <windowsx.h>
  4. #include "editquery.h"
  5. #include "../nde/NDE.h"
  6. #include "resource.h"
  7. #include "..\..\General\gen_ml/gaystring.h"
  8. #include "time.h"
  9. #include "../Agave/Language/api_language.h"
  10. #include "../replicant/nu/AutoChar.h"
  11. #define ListBox_GetTextLenW(hwndCtl, index) ((int)(DWORD)SendMessageW((hwndCtl), LB_GETTEXTLEN, (WPARAM)(int)(index), 0L))
  12. #define ListBox_GetTextW(hwndCtl, index, lpszBuffer) ((int)(DWORD)SendMessageW((hwndCtl), LB_GETTEXT, (WPARAM)(int)(index), (LPARAM)(LPCWSTR)(lpszBuffer)))
  13. int myatoi(wchar_t *p, int len) {
  14. wchar_t *w = (wchar_t *)calloc((len+1), sizeof(wchar_t));
  15. if (w)
  16. {
  17. wcsncpy(w, p, len);
  18. w[len] = 0;
  19. int a = _wtoi(w);
  20. free(w);
  21. return a;
  22. }
  23. return 0;
  24. }
  25. static wchar_t *monthtable[12] = {L"January", L"February", L"March", L"April", L"May", L"June", L"July", L"August", L"September", L"October", L"November", L"December" };
  26. INT_PTR CALLBACK editQueryDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  27. INT_PTR CALLBACK editDateTimeDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  28. static wchar_t *qe_field = NULL;
  29. static GayStringW qe_curquery;
  30. static GayStringW qe_curexpr;
  31. static GayStringW qe_origquery;
  32. static GayStringW qe_curorigin;
  33. static GayStringW qe_curdate;
  34. void qe_freeStuff() {
  35. qe_curquery.Set(L"");
  36. qe_curquery.Compact();
  37. qe_curexpr.Set(L"");
  38. qe_curexpr.Compact();
  39. qe_curorigin.Set(L"");
  40. qe_curorigin.Compact();
  41. qe_origquery.Set(L"");
  42. qe_origquery.Compact();
  43. }
  44. static GayStringW te_ret;
  45. static GayStringW te_result;
  46. int te_cur_selected_month=0;
  47. const wchar_t *editTime(HWND wnd, const wchar_t *curfield) {
  48. te_ret.Set(curfield);
  49. TimeParse tp;
  50. NDE_Time_ApplyConversion(0, curfield, &tp);
  51. if (tp.relative_day == -2 || tp.relative_kwday != -1) {
  52. wchar_t titleStr[64] = {0};
  53. int r = MessageBoxW(wnd, WASABI_API_LNGSTRINGW(IDS_DATE_TIME_IS_TOO_COMPLEX),
  54. WASABI_API_LNGSTRINGW_BUF(IDS_DATE_TIME_EDITOR_QUESTION,titleStr,64), MB_YESNO);
  55. if (r == IDNO) {
  56. return curfield;
  57. }
  58. }
  59. INT_PTR r = WASABI_API_DIALOGBOXW(IDD_TIMEEDITOR, wnd, editDateTimeDialogProc);
  60. if (r == IDOK) {
  61. te_ret.Set(te_result.Get());
  62. return te_ret.Get();
  63. }
  64. return NULL;
  65. }
  66. const wchar_t *editQuery(HWND wnd, const wchar_t *curquery, wchar_t *newQuery, size_t len)
  67. {
  68. qe_field = NULL;
  69. qe_curquery.Set(curquery);
  70. qe_origquery.Set(curquery);
  71. INT_PTR r = WASABI_API_DIALOGBOXW(IDD_EDIT_QUERY, wnd, editQueryDialogProc);
  72. if (qe_field) free(qe_field);
  73. if (r == IDOK)
  74. {
  75. lstrcpynW(newQuery, qe_curquery.Get(), len);
  76. qe_freeStuff();
  77. return newQuery;
  78. }
  79. qe_freeStuff();
  80. return NULL;
  81. }
  82. static bool FillListProc(Record *record, Field *entry, void *context)
  83. {
  84. HWND hwndDlg = (HWND)context;
  85. SendMessage(hwndDlg, LB_ADDSTRING, 0, (LPARAM)NDE_ColumnField_GetFieldName((nde_field_t)entry));
  86. return true;
  87. }
  88. void qe_fillFieldsList( HWND hwndDlg )
  89. {
  90. ListBox_ResetContent( hwndDlg );
  91. Record *cr = ( (Table *)g_table )->GetColumns(); // TODO: don't use C++ NDE API
  92. if ( cr )
  93. {
  94. cr->WalkFields( FillListProc, (void *)hwndDlg );
  95. }
  96. int len = ListBox_GetTextLenW( hwndDlg, 0 );
  97. if ( qe_field != NULL )
  98. free( qe_field );
  99. qe_field = (wchar_t *)calloc( ( len + 1 ), sizeof( wchar_t ) );
  100. ListBox_GetTextW( hwndDlg, 0, qe_field );
  101. qe_field[ len ] = 0;
  102. ListBox_SetCurSel( hwndDlg, 0 );
  103. }
  104. void qe_doEnableDisable( HWND hwndDlg, int *n, int num, int how )
  105. {
  106. for ( int i = 0; i < num; i++ )
  107. EnableWindow( GetDlgItem( hwndDlg, n[ i ] ), how );
  108. }
  109. void qe_enableDisableItem( HWND hwndDlg, int id, int tf )
  110. {
  111. EnableWindow( GetDlgItem( hwndDlg, id ), tf );
  112. }
  113. void qe_fallback( HWND hwndDlg, int disabling, int enabled )
  114. {
  115. if ( IsDlgButtonChecked( hwndDlg, disabling ) )
  116. {
  117. CheckDlgButton( hwndDlg, disabling, BST_UNCHECKED );
  118. CheckDlgButton( hwndDlg, enabled, BST_CHECKED );
  119. }
  120. }
  121. int ctrls_datetime[] = {IDC_STATIC_DATETIME, IDC_EDIT_DATETIME, IDC_BUTTON_EDITDATETIME, IDC_STATIC_CURDATETIME};
  122. int ctrls_datetime_base[] = {IDC_STATIC_DATETIME, IDC_CHECK_ABSOLUTE, IDC_CHECK_RELATIVE};
  123. int ctrls_datetime_relative[] = {IDC_CHECK_SELECTIVE, IDC_CHECK_TIMEAGO, IDC_STATIC_QUERYTIME, IDC_STATIC_RESULT};
  124. int ctrls_datetime_relative_ago[] = {IDC_STATIC_TIMEAGO, IDC_EDIT_TIMEAGO, IDC_RADIO_TIMEAGO_Y,
  125. IDC_RADIO_TIMEAGO_H, IDC_RADIO_TIMEAGO_M, IDC_RADIO_TIMEAGO_MIN, IDC_RADIO_TIMEAGO_W, IDC_RADIO_TIMEAGO_S,
  126. IDC_RADIO_TIMEAGO_D};
  127. int ctrls_datetime_relative_ago_direction[] = {IDC_STATIC_DIRECTION, IDC_RADIO_AFTER, IDC_RADIO_BEFORE};
  128. int ctrls_datetime_relative_selective[] = {IDC_STATIC_SELECTIVE, IDC_STATIC_YEAR, IDC_RADIO_THISYEAR,
  129. IDC_RADIO_YEAR, IDC_EDIT_YEAR, IDC_STATIC_MONTH, IDC_RADIO_THISMONTH, IDC_RADIO_MONTH, IDC_BUTTON_MONTH,
  130. IDC_STATIC_DAY, IDC_RADIO_THISDAY, IDC_RADIO_DAY, IDC_EDIT_DAY, IDC_STATIC_TIME, IDC_RADIO_THISTIME,
  131. IDC_RADIO_TIME, IDC_RADIO_NOON, IDC_RADIO_MIDNIGHT, IDC_BUTTON_NOW, IDC_BUTTON_PICK, IDC_DATETIMEPICKER2};
  132. int ctrls_datetime_absolute[] = {IDC_STATIC_ABSOLUTE, IDC_DATETIMEPICKER, IDC_DATETIMEPICKER1, IDC_STATIC_RELATIVE};
  133. int ctrls_string_ops[] = {IDC_RADIO_ISLIKE, IDC_RADIO_BEGINS, IDC_RADIO_ENDS, IDC_RADIO_CONTAINS};
  134. int ctrls_string[] = {IDC_STATIC_STRING, IDC_EDIT_STRING};
  135. void qe_showHideOperators(HWND hwndDlg) {
  136. if (!qe_curquery.Get() || !*qe_curquery.Get()) {
  137. ShowWindow(GetDlgItem(hwndDlg, IDC_BUTTON_AND), SW_HIDE);
  138. ShowWindow(GetDlgItem(hwndDlg, IDC_BUTTON_OR), SW_HIDE);
  139. ShowWindow(GetDlgItem(hwndDlg, ID_BUTTON_SENDTOQUERY), SW_SHOW);
  140. } else {
  141. ShowWindow(GetDlgItem(hwndDlg, IDC_BUTTON_AND), SW_SHOW);
  142. ShowWindow(GetDlgItem(hwndDlg, IDC_BUTTON_OR), SW_SHOW);
  143. ShowWindow(GetDlgItem(hwndDlg, ID_BUTTON_SENDTOQUERY), SW_HIDE);
  144. }
  145. }
  146. void qe_updateResultingDate(HWND hwndDlg) {
  147. if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_EDIT_DATETIME)) && !IsDlgButtonChecked(hwndDlg, IDC_RADIO_ISEMPTY)) {
  148. time_t t = NDE_Time_ApplyConversion(0, qe_curdate.Get(), 0);
  149. struct tm *ts = localtime(&t);
  150. wchar_t qe_tempstr[4096] = {0};
  151. if (ts)
  152. wsprintfW(qe_tempstr, L"%02d/%d/%04d %02d:%02d:%02d", ts->tm_mon+1, ts->tm_mday, ts->tm_year+1900, ts->tm_hour, ts->tm_min, ts->tm_sec);
  153. else
  154. wcsncpy(qe_tempstr, L"DATE_OUTOFRANGE", 4096);
  155. SetDlgItemTextW(hwndDlg, IDC_STATIC_CURDATETIME, qe_tempstr);
  156. } else {
  157. SetDlgItemTextW(hwndDlg, IDC_STATIC_CURDATETIME, L"N/A");
  158. }
  159. }
  160. void te_updateResultingDate(HWND hwndDlg) {
  161. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RELATIVE)) {
  162. time_t t = NDE_Time_ApplyConversion(0, qe_curorigin.Get(), 0);
  163. struct tm *ts = localtime(&t);
  164. wchar_t qe_tempstr[4096] = {0};
  165. if (ts)
  166. wsprintfW(qe_tempstr, L"%02d/%d/%04d %02d:%02d:%02d", ts->tm_mon+1, ts->tm_mday, ts->tm_year+1900, ts->tm_hour, ts->tm_min, ts->tm_sec);
  167. else
  168. wcsncpy(qe_tempstr, L"DATE_OUTOFRANGE", 4096);
  169. SetDlgItemTextW(hwndDlg, IDC_STATIC_QUERYTIME, qe_tempstr);
  170. } else {
  171. SetDlgItemTextW(hwndDlg, IDC_STATIC_QUERYTIME, L"N/A");
  172. }
  173. }
  174. void qe_enableDisable(HWND hwndDlg) {
  175. if (!*qe_field) return;
  176. nde_field_t field = NDE_Table_GetColumnByName(g_table, AutoChar(qe_field));
  177. if (!field) return;
  178. int type = NDE_ColumnField_GetDataType(field);
  179. qe_showHideOperators(hwndDlg);
  180. switch (type) {
  181. case FIELD_DATETIME: {
  182. qe_fallback(hwndDlg, IDC_RADIO_ISLIKE, IDC_RADIO_EQUAL);
  183. qe_fallback(hwndDlg, IDC_RADIO_BEGINS, IDC_RADIO_EQUAL);
  184. qe_fallback(hwndDlg, IDC_RADIO_ENDS, IDC_RADIO_EQUAL);
  185. qe_fallback(hwndDlg, IDC_RADIO_CONTAINS, IDC_RADIO_EQUAL);
  186. qe_doEnableDisable(hwndDlg, ctrls_string, sizeof(ctrls_string)/sizeof(int), 0);
  187. qe_doEnableDisable(hwndDlg, ctrls_string_ops, sizeof(ctrls_string_ops)/sizeof(int), 0);
  188. SetDlgItemTextW(hwndDlg,IDC_STATIC_STRING,WASABI_API_LNGSTRINGW(IDS_COMPARE_TO_STRING));
  189. qe_doEnableDisable(hwndDlg, ctrls_datetime, sizeof(ctrls_datetime)/sizeof(int), 1);
  190. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVE, WASABI_API_LNGSTRINGW(IDS_AFTER));
  191. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOW, WASABI_API_LNGSTRINGW(IDS_BEFORE));
  192. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVEOREQUAL, WASABI_API_LNGSTRINGW(IDS_SINCE));
  193. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOWOREQUAL, WASABI_API_LNGSTRINGW(IDS_UNTIL));
  194. break;
  195. }
  196. case FIELD_LENGTH: {
  197. qe_fallback(hwndDlg, IDC_RADIO_ISLIKE, IDC_RADIO_EQUAL);
  198. qe_fallback(hwndDlg, IDC_RADIO_BEGINS, IDC_RADIO_EQUAL);
  199. qe_fallback(hwndDlg, IDC_RADIO_ENDS, IDC_RADIO_EQUAL);
  200. qe_fallback(hwndDlg, IDC_RADIO_CONTAINS, IDC_RADIO_EQUAL);
  201. qe_doEnableDisable(hwndDlg, ctrls_string, sizeof(ctrls_string)/sizeof(int), 1);
  202. qe_doEnableDisable(hwndDlg, ctrls_string_ops, sizeof(ctrls_string_ops)/sizeof(int), 0);
  203. SetDlgItemTextW(hwndDlg,IDC_STATIC_STRING,WASABI_API_LNGSTRINGW(IDS_COMPARE_TO_LENGTH));
  204. qe_doEnableDisable(hwndDlg, ctrls_datetime, sizeof(ctrls_datetime)/sizeof(int), 0);
  205. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVE, WASABI_API_LNGSTRINGW(IDS_ABOVE));
  206. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOW, WASABI_API_LNGSTRINGW(IDS_BELOW));
  207. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVEOREQUAL, WASABI_API_LNGSTRINGW(IDS_ABOVE_OR_EQUAL));
  208. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOWOREQUAL, WASABI_API_LNGSTRINGW(IDS_BELOW_OR_EQUAL));
  209. break;
  210. }
  211. case FIELD_FILENAME:
  212. case FIELD_STRING: {
  213. qe_doEnableDisable(hwndDlg, ctrls_string, sizeof(ctrls_string)/sizeof(int), 1);
  214. qe_doEnableDisable(hwndDlg, ctrls_string_ops, sizeof(ctrls_string_ops)/sizeof(int), 1);
  215. SetDlgItemTextW(hwndDlg,IDC_STATIC_STRING,WASABI_API_LNGSTRINGW(IDS_COMPARE_TO_STRING));
  216. qe_doEnableDisable(hwndDlg, ctrls_datetime, sizeof(ctrls_datetime)/sizeof(int), 0);
  217. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVE, WASABI_API_LNGSTRINGW(IDS_ABOVE));
  218. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOW, WASABI_API_LNGSTRINGW(IDS_BELOW));
  219. SetDlgItemTextW(hwndDlg,IDC_RADIO_ABOVEOREQUAL, WASABI_API_LNGSTRINGW(IDS_ABOVE_OR_EQUAL));
  220. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOWOREQUAL, WASABI_API_LNGSTRINGW(IDS_BELOW_OR_EQUAL));
  221. break;
  222. }
  223. case FIELD_INTEGER: {
  224. qe_fallback(hwndDlg, IDC_RADIO_ISLIKE, IDC_RADIO_EQUAL);
  225. qe_fallback(hwndDlg, IDC_RADIO_BEGINS, IDC_RADIO_EQUAL);
  226. qe_fallback(hwndDlg, IDC_RADIO_ENDS, IDC_RADIO_EQUAL);
  227. qe_fallback(hwndDlg, IDC_RADIO_CONTAINS, IDC_RADIO_EQUAL);
  228. SetDlgItemTextW(hwndDlg,IDC_STATIC_STRING,WASABI_API_LNGSTRINGW(IDS_COMPARE_TO_NUMBER));
  229. qe_doEnableDisable(hwndDlg, ctrls_string, sizeof(ctrls_string)/sizeof(int), 1);
  230. qe_doEnableDisable(hwndDlg, ctrls_string_ops, sizeof(ctrls_string_ops)/sizeof(int), 0);
  231. qe_doEnableDisable(hwndDlg, ctrls_datetime, sizeof(ctrls_datetime)/sizeof(int), 0);
  232. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVE, WASABI_API_LNGSTRINGW(IDS_ABOVE));
  233. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOW, WASABI_API_LNGSTRINGW(IDS_BELOW));
  234. SetDlgItemTextW(hwndDlg, IDC_RADIO_ABOVEOREQUAL, WASABI_API_LNGSTRINGW(IDS_ABOVE_OR_EQUAL));
  235. SetDlgItemTextW(hwndDlg, IDC_RADIO_BELOWOREQUAL, WASABI_API_LNGSTRINGW(IDS_BELOW_OR_EQUAL));
  236. break;
  237. }
  238. }
  239. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ISEMPTY)) {
  240. qe_doEnableDisable(hwndDlg, ctrls_string, sizeof(ctrls_string)/sizeof(int), 0);
  241. qe_doEnableDisable(hwndDlg, ctrls_datetime, sizeof(ctrls_datetime)/sizeof(int), 0);
  242. return;
  243. }
  244. }
  245. void te_enableDisable(HWND hwndDlg) {
  246. qe_doEnableDisable(hwndDlg, ctrls_datetime_relative, sizeof(ctrls_datetime_relative)/sizeof(int), IsDlgButtonChecked(hwndDlg, IDC_CHECK_RELATIVE));
  247. qe_doEnableDisable(hwndDlg, ctrls_datetime_absolute, sizeof(ctrls_datetime_absolute)/sizeof(int), IsDlgButtonChecked(hwndDlg, IDC_CHECK_ABSOLUTE));
  248. qe_doEnableDisable(hwndDlg, ctrls_datetime_relative_ago, sizeof(ctrls_datetime_relative_ago)/sizeof(int), IsDlgButtonChecked(hwndDlg, IDC_CHECK_RELATIVE) && IsDlgButtonChecked(hwndDlg, IDC_CHECK_TIMEAGO));
  249. qe_doEnableDisable(hwndDlg, ctrls_datetime_relative_ago_direction, sizeof(ctrls_datetime_relative_ago_direction)/sizeof(int), !IsDlgButtonChecked(hwndDlg, IDC_CHECK_ABSOLUTE) && IsDlgButtonChecked(hwndDlg, IDC_CHECK_SELECTIVE) && IsDlgButtonChecked(hwndDlg, IDC_CHECK_TIMEAGO));
  250. qe_doEnableDisable(hwndDlg, ctrls_datetime_relative_selective, sizeof(ctrls_datetime_relative_selective)/sizeof(int), IsDlgButtonChecked(hwndDlg, IDC_CHECK_RELATIVE) && IsDlgButtonChecked(hwndDlg, IDC_CHECK_SELECTIVE));
  251. int origin = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SELECTIVE) && IsDlgButtonChecked(hwndDlg, IDC_CHECK_RELATIVE);
  252. qe_enableDisableItem(hwndDlg, IDC_EDIT_YEAR, origin && IsDlgButtonChecked(hwndDlg, IDC_RADIO_YEAR));
  253. qe_enableDisableItem(hwndDlg, IDC_BUTTON_MONTH, origin && IsDlgButtonChecked(hwndDlg, IDC_RADIO_MONTH));
  254. qe_enableDisableItem(hwndDlg, IDC_EDIT_DAY, origin && IsDlgButtonChecked(hwndDlg, IDC_RADIO_DAY));
  255. qe_enableDisableItem(hwndDlg, IDC_DATETIMEPICKER2, origin && IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIME));
  256. SetDlgItemTextW(hwndDlg, IDC_CHECK_TIMEAGO, WASABI_API_LNGSTRINGW((IsDlgButtonChecked(hwndDlg, IDC_CHECK_SELECTIVE) ? IDS_OFFSET_BY : IDS_TIME_AGO)));
  257. SetWindowTextW(GetDlgItem(hwndDlg, IDC_BUTTON_MONTH), monthtable[te_cur_selected_month]);
  258. InvalidateRect(GetDlgItem(hwndDlg, IDC_CHECK_ABSOLUTE), NULL, TRUE);
  259. InvalidateRect(GetDlgItem(hwndDlg, IDC_CHECK_RELATIVE), NULL, TRUE);
  260. InvalidateRect(GetDlgItem(hwndDlg, IDC_CHECK_TIMEAGO), NULL, TRUE);
  261. InvalidateRect(GetDlgItem(hwndDlg, IDC_CHECK_SELECTIVE), NULL, TRUE);
  262. InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_DIRECTION), NULL, TRUE);
  263. }
  264. const wchar_t *te_getDateTime(HWND hwndDlg) {
  265. static GayStringW str;
  266. wchar_t qe_tempstr[4096] = {0};
  267. str.Set(L"");
  268. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_ABSOLUTE)) {
  269. GayStringW sd;
  270. SYSTEMTIME st={0,0,0,0,0,0,0,0};
  271. DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), &st);
  272. if (st.wYear != 0) {
  273. wsprintfW(qe_tempstr, L"%02d/%d/%02d", st.wMonth, st.wDay, st.wYear);
  274. sd.Append(qe_tempstr);
  275. }
  276. SYSTEMTIME stt={0,0,0,0,0,0,0,0};
  277. DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER1), &stt);
  278. if (stt.wYear != 0) {
  279. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  280. wsprintfW(qe_tempstr, L"%02d:%02d:%02d", stt.wHour, stt.wMinute, stt.wSecond);
  281. sd.Append(qe_tempstr);
  282. }
  283. if (sd.Get() && *sd.Get()) {
  284. str.Set(sd.Get());
  285. return str.Get();
  286. }
  287. } else if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_RELATIVE)) {
  288. GayStringW sd;
  289. int gotshit = 0;
  290. int gotmonth = 0;
  291. int gotthismonth = 0;
  292. int gotday = 0;
  293. int lgotthistime = 0;
  294. int lgotthisday = 0;
  295. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_TIMEAGO)) {
  296. int v = GetDlgItemInt(hwndDlg, IDC_EDIT_TIMEAGO, NULL, TRUE);
  297. wsprintfW(qe_tempstr, L"%d", v);
  298. sd.Append(qe_tempstr);
  299. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_Y)) { sd.Append(L" year"); if (v > 1) sd.Append(L"s"); }
  300. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_M)) { sd.Append(L" month"); if (v > 1) sd.Append(L"s"); }
  301. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_W)) { sd.Append(L" week"); if (v > 1) sd.Append(L"s"); }
  302. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_D)) { sd.Append(L" day"); if (v > 1) sd.Append(L"s"); }
  303. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_H)) sd.Append(L" h");
  304. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_MIN)) sd.Append(L" mn");
  305. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIMEAGO_S)) sd.Append(L" s");
  306. }
  307. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_SELECTIVE)) {
  308. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_TIMEAGO) && IsDlgButtonChecked(hwndDlg, IDC_RADIO_AFTER)) sd.Append(L" after");
  309. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_TIMEAGO) && IsDlgButtonChecked(hwndDlg, IDC_RADIO_BEFORE)) sd.Append(L" before");
  310. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISDAY) &&
  311. IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH)) {
  312. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  313. int v = GetDlgItemInt(hwndDlg, IDC_EDIT_DAY, NULL, TRUE);
  314. wsprintfW(qe_tempstr, L"%s%d", !gotmonth ? L"the " : L"", v);
  315. int u = (v - ((int)((double)v/10.0)) * 10);
  316. if (v < 1 || v > 31) {
  317. sd.Append(L"DAY_OUTOFRANGE");
  318. gotshit = 1;
  319. } else {
  320. sd.Append(qe_tempstr);
  321. switch (u) {
  322. case 1: sd.Append(L"st"); gotshit = 1; break;
  323. case 2: sd.Append(L"nd"); gotshit = 1; break;
  324. case 3: sd.Append(L"rd"); gotshit = 1; break;
  325. default: sd.Append(L"th"); gotshit = 1; break;
  326. }
  327. }
  328. if (!gotthismonth && IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH)) {
  329. sd.Append(L" of this month");
  330. gotthismonth = 1;
  331. }
  332. gotshit = 1;
  333. gotday = 1;
  334. }
  335. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISYEAR) &&
  336. IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH) &&
  337. IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISDAY) &&
  338. IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISTIME)) {
  339. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  340. sd.Append(L"now");
  341. gotshit = 1;
  342. } else {
  343. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISYEAR) &&
  344. IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH) &&
  345. IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISDAY)) {
  346. if (gotshit) sd.Append(L",");
  347. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  348. sd.Append(L"this date");
  349. gotshit = 1;
  350. } else {
  351. if (!gotthismonth && IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH) && !IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISYEAR)) {
  352. if (gotshit) sd.Append(L",");
  353. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  354. sd.Append(L"this month");
  355. gotthismonth = 1;
  356. gotshit = 1;
  357. }
  358. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISDAY)) {
  359. if (gotshit) sd.Append(L",");
  360. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  361. sd.Append(L"this day");
  362. lgotthisday = 1;
  363. gotshit = 1;
  364. }
  365. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISTIME)) {
  366. if (gotshit) sd.Append(L",");
  367. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  368. sd.Append(L"this time");
  369. lgotthistime = 1;
  370. lgotthisday = 0;
  371. gotshit = 1;
  372. }
  373. }
  374. }
  375. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH)) {
  376. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  377. if (lgotthistime) {
  378. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISDAY))
  379. sd.Append(L"on ");
  380. else {
  381. sd.Append(L"in ");
  382. }
  383. } else if (lgotthisday) sd.Append(L"of ");
  384. switch (te_cur_selected_month) {
  385. case 0: sd.Append(L"Jan"); gotshit = 1; gotmonth = 1; break;
  386. case 1: sd.Append(L"Feb"); gotshit = 1; gotmonth = 1; break;
  387. case 2: sd.Append(L"Mar"); gotshit = 1; gotmonth = 1; break;
  388. case 3: sd.Append(L"Apr"); gotshit = 1; gotmonth = 1; break;
  389. case 4: sd.Append(L"May"); gotshit = 1; gotmonth = 1; break;
  390. case 5: sd.Append(L"Jun"); gotshit = 1; gotmonth = 1; break;
  391. case 6: sd.Append(L"Jul"); gotshit = 1; gotmonth = 1; break;
  392. case 7: sd.Append(L"Aug"); gotshit = 1; gotmonth = 1; break;
  393. case 8: sd.Append(L"Sep"); gotshit = 1; gotmonth = 1; break;
  394. case 9: sd.Append(L"Oct"); gotshit = 1; gotmonth = 1; break;
  395. case 10: sd.Append(L"Nov"); gotshit = 1; gotmonth = 1; break;
  396. case 11: sd.Append(L"Dec"); gotshit = 1; gotmonth = 1; break;
  397. default: sd.Append(L"MONTH_OUTOFRANGE"); gotshit = 1; gotmonth = 1; break;
  398. }
  399. }
  400. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISDAY) &&
  401. !IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH)) {
  402. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  403. int v = GetDlgItemInt(hwndDlg, IDC_EDIT_DAY, NULL, TRUE);
  404. wsprintfW(qe_tempstr, L"%s%d", !gotmonth ? L"the " : L"", v);
  405. int u = (v - ((int)((double)v/10.0)) * 10);
  406. if (v < 1 || v > 31) {
  407. sd.Append(L"DAY_OUTOFRANGE");
  408. gotshit = 1;
  409. } else {
  410. sd.Append(qe_tempstr);
  411. switch (u) {
  412. case 1: sd.Append(L"st"); gotshit = 1; break;
  413. case 2: sd.Append(L"nd"); gotshit = 1; break;
  414. case 3: sd.Append(L"rd"); gotshit = 1; break;
  415. default: sd.Append(L"th"); gotshit = 1; break;
  416. }
  417. }
  418. if (!gotthismonth && IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISMONTH)) {
  419. sd.Append(L" of this month");
  420. }
  421. gotthismonth = 1;
  422. gotshit = 1;
  423. gotday = 1;
  424. }
  425. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISYEAR)) {
  426. if ((gotshit || gotday) && !gotmonth) {
  427. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  428. sd.Append(L"in ");
  429. } else if (gotmonth && gotday) sd.Append(L", ");
  430. else if (sd.Get() && *sd.Get()) sd.Append(L" ");
  431. int v = GetDlgItemInt(hwndDlg, IDC_EDIT_YEAR, NULL, TRUE);
  432. if (v <= 69) v += 2000;
  433. else if (v > 69 && v < 100) v += 1900;
  434. if (v <= 1969 || v >= 2038)
  435. wcsncpy(qe_tempstr, L"YEAR_OUTOFRANGE", 4096);
  436. else
  437. wsprintfW(qe_tempstr, L"%d", v);
  438. sd.Append(qe_tempstr);
  439. gotshit = 1;
  440. }
  441. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISTIME)) {
  442. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_NOON)) {
  443. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  444. if (gotshit) sd.Append(L"at ");
  445. sd.Append(L"noon");
  446. } else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_MIDNIGHT)) {
  447. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  448. if (gotshit) sd.Append(L"at ");
  449. sd.Append(L"midnight");
  450. } else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_TIME)) {
  451. if (sd.Get() && *sd.Get()) sd.Append(L" ");
  452. if (gotshit) sd.Append(L"at ");
  453. SYSTEMTIME stt={0,0,0,0,0,0,0,0};
  454. DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER2), &stt);
  455. wsprintfW(qe_tempstr, L"%02d:%02d:%02d", stt.wHour, stt.wMinute, stt.wSecond);
  456. sd.Append(qe_tempstr);
  457. gotshit = 1;
  458. }
  459. }
  460. } else {
  461. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_TIMEAGO))
  462. sd.Append(L" ago");
  463. }
  464. qe_curorigin.Set(sd.Get());
  465. if (sd.Get() && *sd.Get()) {
  466. str.Set(sd.Get());
  467. return str.Get();
  468. }
  469. }
  470. return NULL;
  471. }
  472. void qe_updateQuery(HWND hwndDlg) {
  473. if (!*qe_field) return;
  474. wchar_t qe_tempstr[4096] = {0};
  475. nde_field_t field = NDE_Table_GetColumnByName(g_table, AutoChar(qe_field));
  476. if (!field) return;
  477. int type =NDE_ColumnField_GetDataType(field);
  478. *qe_tempstr = NULL;
  479. GayStringW str;
  480. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOT))
  481. str.Append(L"!(");
  482. str.Append(qe_field);
  483. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_EQUAL))
  484. str.Append(L" ==");
  485. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ABOVE))
  486. str.Append(L" >");
  487. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_BELOW))
  488. str.Append(L" <");
  489. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ABOVEOREQUAL))
  490. str.Append(L" >=");
  491. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_BELOWOREQUAL))
  492. str.Append(L" <=");
  493. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ISLIKE))
  494. str.Append(L" like");
  495. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ISEMPTY))
  496. str.Append(L" isempty");
  497. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_BEGINS))
  498. str.Append(L" begins");
  499. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_ENDS))
  500. str.Append(L" ends");
  501. if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_CONTAINS))
  502. str.Append(L" has");
  503. if (!IsDlgButtonChecked(hwndDlg, IDC_RADIO_ISEMPTY)) {
  504. switch(type) {
  505. case FIELD_DATETIME: {
  506. str.Append(L" [");
  507. GetDlgItemTextW(hwndDlg, IDC_EDIT_DATETIME, qe_tempstr, 4096);
  508. qe_curdate.Set(qe_tempstr);
  509. str.Append(qe_curdate.Get());
  510. str.Append(L"]");
  511. }
  512. break;
  513. case FIELD_INTEGER: {
  514. wsprintfW(qe_tempstr, L" %d", GetDlgItemInt(hwndDlg, IDC_EDIT_STRING, NULL, 1));
  515. str.Append(qe_tempstr);
  516. }
  517. break;
  518. case FIELD_FILENAME:
  519. case FIELD_STRING: {
  520. GetDlgItemTextW(hwndDlg, IDC_EDIT_STRING, qe_tempstr, 4096);
  521. str.Append(L" \"");
  522. GayStringW escaped;
  523. queryStrEscape(qe_tempstr, escaped);
  524. str.Append(escaped.Get());
  525. str.Append(L"\"");
  526. }
  527. break;
  528. case FIELD_LENGTH: {
  529. GetDlgItemTextW(hwndDlg, IDC_EDIT_STRING, qe_tempstr, 4096);
  530. wchar_t *z = wcschr(qe_tempstr, L':');
  531. if (z) {
  532. wchar_t *zz = wcschr(z+1, L':');
  533. int a, b, c=0,v=0;
  534. a = myatoi(qe_tempstr, z-qe_tempstr);
  535. if (zz) { b = myatoi(z+1, zz-(z+1)); c = _wtoi(zz+1); v = a * 3600 + b * 60 + c; }
  536. else { b = _wtoi(z+1); v = a * 60 + b; }
  537. if (v < 60)
  538. wsprintfW(qe_tempstr,L"%d",v);
  539. else if (v < 60*60)
  540. wsprintfW(qe_tempstr,L"%d:%02d",v/60,v%60);
  541. else
  542. wsprintfW(qe_tempstr,L"%d:%02d:%02d",v/60/60,(v/60)%60,v%60);
  543. str.Append(qe_tempstr);
  544. } else {
  545. wsprintfW(qe_tempstr, L" %d", GetDlgItemInt(hwndDlg, IDC_EDIT_STRING, NULL, 1));
  546. str.Append(qe_tempstr);
  547. }
  548. }
  549. break;
  550. }
  551. }
  552. if (IsDlgButtonChecked(hwndDlg, IDC_CHECK_NOT))
  553. str.Append(L")");
  554. qe_curexpr.Set(str.Get());
  555. SetDlgItemTextW(hwndDlg, IDC_EDIT_RESULT, str.Get());
  556. SetDlgItemTextW(hwndDlg, IDC_EDIT_QUERY, qe_curquery.Get());
  557. qe_updateResultingDate(hwndDlg);
  558. }
  559. void qe_update(HWND hwndDlg) {
  560. qe_enableDisable(hwndDlg);
  561. qe_updateQuery(hwndDlg);
  562. }
  563. void te_updateResult(HWND hwndDlg) {
  564. const wchar_t *s = te_getDateTime(hwndDlg);
  565. te_result.Set(s == NULL ? L"":s);
  566. SetDlgItemTextW(hwndDlg, IDC_EDIT_RESULT, te_result.Get());
  567. }
  568. void te_update(HWND hwndDlg) {
  569. te_enableDisable(hwndDlg);
  570. te_updateResult(hwndDlg);
  571. }
  572. void qe_pushExpression(HWND hwndDlg, const wchar_t *op) {
  573. GayStringW newq;
  574. if (op && qe_curquery.Get() && *qe_curquery.Get()) {
  575. newq.Append(L"(");
  576. newq.Append(qe_curquery.Get());
  577. newq.Append(L") ");
  578. newq.Append(op);
  579. newq.Append(L" (");
  580. newq.Append(qe_curexpr.Get());
  581. newq.Append(L")");
  582. qe_curquery.Set(newq.Get());
  583. } else {
  584. qe_curquery.Set(qe_curexpr.Get());
  585. }
  586. qe_update(hwndDlg);
  587. }
  588. SYSTEMTIME pickedtime;
  589. SYSTEMTIME pickeddate;
  590. INT_PTR CALLBACK pickDateTimeDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  591. switch(uMsg) {
  592. case WM_INITDIALOG: {
  593. return TRUE;
  594. }
  595. case WM_COMMAND: {
  596. switch (LOWORD(wParam)) {
  597. case IDOK:
  598. memset(&pickedtime, 0, sizeof(pickedtime));
  599. memset(&pickeddate, 0, sizeof(pickeddate));
  600. DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), &pickeddate);
  601. DateTime_GetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER1), &pickedtime);
  602. EndDialog(hwndDlg, IDOK);
  603. break;
  604. case IDCANCEL:
  605. EndDialog(hwndDlg, IDCANCEL);
  606. break;
  607. }
  608. }
  609. break;
  610. }
  611. return FALSE;
  612. }
  613. INT_PTR CALLBACK editDateTimeDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) {
  614. switch(uMsg) {
  615. case WM_INITDIALOG: {
  616. const wchar_t *p = te_ret.Get();
  617. while (p) {
  618. if (*p != L' ') break;
  619. p++;
  620. }
  621. int empty = (p && *p == 0);
  622. TimeParse tp;
  623. NDE_Time_ApplyConversion(0, te_ret.Get(), &tp);
  624. if (!empty) {
  625. CheckDlgButton(hwndDlg, IDC_RADIO_THISYEAR, tp.relative_year == -1 ? BST_CHECKED : BST_UNCHECKED);
  626. CheckDlgButton(hwndDlg, IDC_RADIO_YEAR, tp.relative_year != -1 ? BST_CHECKED : BST_UNCHECKED);
  627. CheckDlgButton(hwndDlg, IDC_RADIO_THISMONTH, tp.relative_month == -1 ? BST_CHECKED : BST_UNCHECKED);
  628. CheckDlgButton(hwndDlg, IDC_RADIO_MONTH, tp.relative_month != -1 ? BST_CHECKED : BST_UNCHECKED);
  629. CheckDlgButton(hwndDlg, IDC_RADIO_THISDAY, tp.relative_day == -1 ? BST_CHECKED : BST_UNCHECKED);
  630. CheckDlgButton(hwndDlg, IDC_RADIO_DAY, tp.relative_day != -1 ? BST_CHECKED : BST_UNCHECKED);
  631. CheckDlgButton(hwndDlg, IDC_RADIO_THISTIME, tp.relative_hour == -1 ? BST_CHECKED : BST_UNCHECKED);
  632. CheckDlgButton(hwndDlg, IDC_RADIO_NOON, (tp.relative_hour == 12 && tp.relative_min == 0 && tp.relative_sec == 0) ? BST_CHECKED : BST_UNCHECKED);
  633. CheckDlgButton(hwndDlg, IDC_RADIO_MIDNIGHT, (tp.relative_hour == 0 && tp.relative_min == 0 && tp.relative_sec == 0) ? BST_CHECKED : BST_UNCHECKED);
  634. int timeyet = IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISTIME);
  635. timeyet |= IsDlgButtonChecked(hwndDlg, IDC_RADIO_NOON);
  636. timeyet |= IsDlgButtonChecked(hwndDlg, IDC_RADIO_MIDNIGHT);
  637. CheckDlgButton(hwndDlg, IDC_RADIO_TIME, !timeyet ? BST_CHECKED : BST_UNCHECKED);
  638. CheckDlgButton(hwndDlg, IDC_CHECK_RELATIVE, tp.is_relative ? BST_CHECKED : BST_UNCHECKED);
  639. CheckDlgButton(hwndDlg, IDC_CHECK_ABSOLUTE, !tp.is_relative ? BST_CHECKED : BST_UNCHECKED);
  640. CheckDlgButton(hwndDlg, IDC_RADIO_BEFORE, tp.offset_whence == 1 ? BST_CHECKED : BST_UNCHECKED);
  641. CheckDlgButton(hwndDlg, IDC_RADIO_AFTER, tp.offset_whence == 0 ? BST_CHECKED : BST_UNCHECKED);
  642. CheckDlgButton(hwndDlg, IDC_CHECK_TIMEAGO, tp.offset_used == 1 ? BST_CHECKED : BST_UNCHECKED);
  643. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_Y, tp.offset_what == 0 ? BST_CHECKED : BST_UNCHECKED);
  644. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_M, tp.offset_what == 1 ? BST_CHECKED : BST_UNCHECKED);
  645. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_W, tp.offset_what == 2 ? BST_CHECKED : BST_UNCHECKED);
  646. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_D, tp.offset_what == 3 ? BST_CHECKED : BST_UNCHECKED);
  647. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_H, tp.offset_what == 4 ? BST_CHECKED : BST_UNCHECKED);
  648. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_MIN, tp.offset_what == 5 ? BST_CHECKED : BST_UNCHECKED);
  649. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_S, tp.offset_what == 6 ? BST_CHECKED : BST_UNCHECKED);
  650. if (tp.is_relative && (tp.relative_year != -1 || tp.relative_month != -1 || tp.relative_day != -1 || tp.relative_hour != -1 || tp.relative_min != -1 || tp.relative_sec != -1))
  651. CheckDlgButton(hwndDlg, IDC_CHECK_SELECTIVE, BST_CHECKED);
  652. else
  653. CheckDlgButton(hwndDlg, IDC_CHECK_SELECTIVE, BST_UNCHECKED);
  654. }
  655. wchar_t t[64] = {0};
  656. wsprintfW(t, L"%d", tp.offset_value);
  657. SetDlgItemTextW(hwndDlg, IDC_EDIT_TIMEAGO, t);
  658. SetDlgItemTextW(hwndDlg, IDC_EDIT_RESULT, te_ret.Get());
  659. {
  660. wchar_t qe_tempstr[4096] = {0};
  661. time_t now;
  662. time(&now);
  663. struct tm *ts = localtime(&now);
  664. wsprintfW(qe_tempstr, L"%d", tp.relative_year != -1 ? tp.relative_year : ts->tm_year+1900);
  665. SetDlgItemTextW(hwndDlg, IDC_EDIT_YEAR, qe_tempstr);
  666. wsprintfW(qe_tempstr, L"%d", tp.relative_day != -1 ? tp.relative_day : ts->tm_mday);
  667. SetDlgItemTextW(hwndDlg, IDC_EDIT_DAY, qe_tempstr);
  668. te_cur_selected_month = tp.relative_month != -1 ? tp.relative_month : ts->tm_mon;
  669. }
  670. if (!empty && !IsDlgButtonChecked(hwndDlg, IDC_RADIO_THISTIME) && !IsDlgButtonChecked(hwndDlg, IDC_RADIO_NOON) && !IsDlgButtonChecked(hwndDlg, IDC_RADIO_MIDNIGHT)) {
  671. SYSTEMTIME st={0};
  672. st.wHour = (WORD)tp.relative_hour;
  673. st.wMinute = (WORD)tp.relative_min;
  674. st.wSecond = (WORD)tp.relative_sec;
  675. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER2), GDT_VALID, &st);
  676. }
  677. if (!empty && !tp.is_relative) {
  678. time_t o = tp.absolute_datetime;
  679. struct tm *t = localtime(&o);
  680. if (t) {
  681. if (!tp.absolute_hasdate)
  682. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), GDT_NONE, NULL);
  683. else {
  684. SYSTEMTIME st={0};
  685. st.wYear = (WORD)t->tm_year;
  686. st.wDay = (WORD)t->tm_mday;
  687. st.wMonth = (WORD)t->tm_mon;
  688. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER), GDT_VALID, &st);
  689. }
  690. if (!tp.absolute_hastime)
  691. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER1), GDT_NONE, NULL);
  692. else {
  693. SYSTEMTIME st2={0};
  694. GetSystemTime(&st2);
  695. st2.wHour = (WORD)t->tm_hour;
  696. st2.wMinute = (WORD)t->tm_min;
  697. st2.wSecond = (WORD)t->tm_sec;
  698. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER1), GDT_VALID, &st2);
  699. }
  700. }
  701. CheckDlgButton(hwndDlg, IDC_CHECK_TIMEAGO, 1);
  702. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_W, 1);
  703. SetDlgItemText(hwndDlg, IDC_EDIT_TIMEAGO, L"1");
  704. CheckDlgButton(hwndDlg, IDC_RADIO_BEFORE, 1);
  705. } else if (!empty) {
  706. if (!IsDlgButtonChecked(hwndDlg, IDC_CHECK_SELECTIVE)) {
  707. CheckDlgButton(hwndDlg, IDC_RADIO_THISYEAR, 1);
  708. CheckDlgButton(hwndDlg, IDC_RADIO_THISMONTH, 1);
  709. CheckDlgButton(hwndDlg, IDC_RADIO_THISDAY, 1);
  710. CheckDlgButton(hwndDlg, IDC_RADIO_THISTIME, 1);
  711. }
  712. } else if (empty) {
  713. CheckDlgButton(hwndDlg, IDC_CHECK_TIMEAGO, 1);
  714. CheckDlgButton(hwndDlg, IDC_RADIO_TIMEAGO_W, 1);
  715. SetDlgItemText(hwndDlg, IDC_EDIT_TIMEAGO, L"1");
  716. CheckDlgButton(hwndDlg, IDC_RADIO_BEFORE, 1);
  717. CheckDlgButton(hwndDlg, IDC_RADIO_THISYEAR, 1);
  718. CheckDlgButton(hwndDlg, IDC_RADIO_THISMONTH, 1);
  719. CheckDlgButton(hwndDlg, IDC_RADIO_THISDAY, 1);
  720. CheckDlgButton(hwndDlg, IDC_RADIO_THISTIME, 1);
  721. CheckDlgButton(hwndDlg, IDC_CHECK_RELATIVE, 1);
  722. }
  723. te_enableDisable(hwndDlg);
  724. SetTimer(hwndDlg, 0, 1000, NULL);
  725. }
  726. return 1;
  727. case WM_COMMAND: {
  728. switch (LOWORD(wParam)) {
  729. case IDOK: EndDialog(hwndDlg, IDOK); break;
  730. case IDCANCEL: EndDialog(hwndDlg, IDCANCEL); break;
  731. case IDC_EDIT_TIMEAGO:
  732. case IDC_EDIT_YEAR:
  733. case IDC_EDIT_DAY:
  734. if (HIWORD(wParam) != EN_CHANGE) break;
  735. case IDC_CHECK_ABSOLUTE:
  736. case IDC_CHECK_RELATIVE:
  737. case IDC_CHECK_TIMEAGO:
  738. case IDC_CHECK_SELECTIVE:
  739. case IDC_RADIO_THISYEAR:
  740. case IDC_RADIO_THISMONTH:
  741. case IDC_RADIO_THISDAY:
  742. case IDC_RADIO_THISTIME:
  743. case IDC_RADIO_YEAR:
  744. case IDC_RADIO_MONTH:
  745. case IDC_RADIO_DAY:
  746. case IDC_RADIO_TIME:
  747. case IDC_RADIO_NOON:
  748. case IDC_RADIO_MIDNIGHT:
  749. case IDC_RADIO_EQUAL:
  750. case IDC_RADIO_ABOVE:
  751. case IDC_RADIO_ABOVEOREQUAL:
  752. case IDC_RADIO_BELOW:
  753. case IDC_RADIO_BELOWOREQUAL:
  754. case IDC_RADIO_ISLIKE:
  755. case IDC_RADIO_ISEMPTY:
  756. case IDC_RADIO_BEGINS:
  757. case IDC_RADIO_ENDS:
  758. case IDC_RADIO_CONTAINS:
  759. case IDC_CHECK_NOT:
  760. case IDC_RADIO_TIMEAGO_Y:
  761. case IDC_RADIO_TIMEAGO_M:
  762. case IDC_RADIO_TIMEAGO_D:
  763. case IDC_RADIO_TIMEAGO_H:
  764. case IDC_RADIO_TIMEAGO_MIN:
  765. case IDC_RADIO_TIMEAGO_S:
  766. case IDC_RADIO_TIMEAGO_W:
  767. case IDC_RADIO_AFTER:
  768. case IDC_RADIO_BEFORE:
  769. te_update(hwndDlg);
  770. return 0;
  771. case IDC_BUTTON_PICK: {
  772. INT_PTR r = WASABI_API_DIALOGBOXW(IDD_EDIT_QUERY_PICK, hwndDlg, pickDateTimeDialogProc);
  773. if (r == IDOK) {
  774. if (pickeddate.wYear != 0) {
  775. SetDlgItemInt(hwndDlg, IDC_EDIT_YEAR, pickeddate.wYear, 0);
  776. te_cur_selected_month = pickeddate.wMonth-1;
  777. SetDlgItemInt(hwndDlg, IDC_EDIT_DAY, pickeddate.wDay, 0);
  778. CheckDlgButton(hwndDlg, IDC_RADIO_THISYEAR, BST_UNCHECKED);
  779. CheckDlgButton(hwndDlg, IDC_RADIO_YEAR, BST_CHECKED);
  780. CheckDlgButton(hwndDlg, IDC_RADIO_THISMONTH, BST_UNCHECKED);
  781. CheckDlgButton(hwndDlg, IDC_RADIO_MONTH, BST_CHECKED);
  782. CheckDlgButton(hwndDlg, IDC_RADIO_THISDAY, BST_UNCHECKED);
  783. CheckDlgButton(hwndDlg, IDC_RADIO_DAY, BST_CHECKED);
  784. }
  785. if (pickedtime.wYear != 0) {
  786. DateTime_SetSystemtime(GetDlgItem(hwndDlg, IDC_DATETIMEPICKER2), GDT_VALID, &pickedtime);
  787. CheckDlgButton(hwndDlg, IDC_RADIO_THISTIME, BST_UNCHECKED);
  788. CheckDlgButton(hwndDlg, IDC_RADIO_TIME, BST_CHECKED);
  789. }
  790. te_update(hwndDlg);
  791. }
  792. }
  793. break;
  794. case IDC_BUTTON_NOW:
  795. CheckDlgButton(hwndDlg, IDC_RADIO_THISYEAR, BST_CHECKED);
  796. CheckDlgButton(hwndDlg, IDC_RADIO_YEAR, BST_UNCHECKED);
  797. CheckDlgButton(hwndDlg, IDC_RADIO_THISMONTH, BST_CHECKED);
  798. CheckDlgButton(hwndDlg, IDC_RADIO_MONTH, BST_UNCHECKED);
  799. CheckDlgButton(hwndDlg, IDC_RADIO_THISDAY, BST_CHECKED);
  800. CheckDlgButton(hwndDlg, IDC_RADIO_DAY, BST_UNCHECKED);
  801. CheckDlgButton(hwndDlg, IDC_RADIO_THISTIME, BST_CHECKED);
  802. CheckDlgButton(hwndDlg, IDC_RADIO_TIME, BST_UNCHECKED);
  803. CheckDlgButton(hwndDlg, IDC_RADIO_NOON, BST_UNCHECKED);
  804. CheckDlgButton(hwndDlg, IDC_RADIO_MIDNIGHT, BST_UNCHECKED);
  805. te_update(hwndDlg);
  806. return 0;
  807. case IDC_BUTTON_MONTH: {
  808. HMENU menu = CreatePopupMenu();
  809. for (int i=0;i<12;i++)
  810. AppendMenuW(menu, MF_STRING|(te_cur_selected_month==i)?MF_CHECKED:MF_UNCHECKED, i+1, monthtable[i]);
  811. POINT pt;
  812. GetCursorPos(&pt);
  813. int r = TrackPopupMenuEx(menu, TPM_LEFTALIGN|TPM_BOTTOMALIGN|TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pt.x, pt.y, hwndDlg, NULL);
  814. if (r)
  815. {
  816. te_cur_selected_month = r-1;
  817. te_update(hwndDlg);
  818. }
  819. break;
  820. }
  821. }
  822. }
  823. case WM_TIMER: {
  824. te_updateResultingDate(hwndDlg);
  825. return 0;
  826. }
  827. case WM_NOTIFY: {
  828. int idCtrl = (int)wParam;
  829. NMHDR *hdr = (NMHDR*)lParam;
  830. switch (idCtrl) {
  831. case IDC_DATETIMEPICKER:
  832. case IDC_DATETIMEPICKER1:
  833. case IDC_DATETIMEPICKER2:
  834. if (hdr->code == DTN_DATETIMECHANGE)
  835. te_update(hwndDlg);
  836. break;
  837. }
  838. }
  839. break;
  840. }
  841. return 0;
  842. }
  843. INT_PTR CALLBACK editQueryDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  844. {
  845. switch ( uMsg )
  846. {
  847. case WM_INITDIALOG:
  848. {
  849. qe_fillFieldsList( GetDlgItem( hwndDlg, IDC_LIST_FIELDS ) );
  850. SetDlgItemTextW( hwndDlg, IDC_EDIT_RESULT, qe_curquery.Get() );
  851. CheckDlgButton( hwndDlg, IDC_RADIO_EQUAL, MF_CHECKED );
  852. qe_update( hwndDlg );
  853. SetTimer( hwndDlg, 0, 1000, NULL );
  854. return 1;
  855. }
  856. case WM_TIMER:
  857. {
  858. qe_updateResultingDate( hwndDlg );
  859. return 0;
  860. }
  861. case WM_COMMAND:
  862. {
  863. switch ( LOWORD( wParam ) )
  864. {
  865. case IDOK:
  866. if ( !qe_curquery.Get() || !*qe_curquery.Get() && qe_curexpr.Get() && *qe_curexpr.Get() )
  867. {
  868. wchar_t titleStr[ 32 ] = { 0 };
  869. int r = MessageBoxW( hwndDlg, WASABI_API_LNGSTRINGW( IDS_QUERY_FIELD_IS_EMPTY ),
  870. WASABI_API_LNGSTRINGW_BUF( IDS_EMPTY_QUERY, titleStr, 32 ), MB_YESNOCANCEL );
  871. if ( r == IDYES )
  872. qe_curquery.Set( qe_curexpr.Get() );
  873. else if ( r == IDCANCEL ) break;
  874. }
  875. if ( qe_origquery.Get() && *qe_origquery.Get() && qe_curquery.Get() || *qe_curquery.Get() && qe_curexpr.Get() && *qe_curexpr.Get() )
  876. {
  877. if ( !wcscmp( qe_curquery.Get(), qe_origquery.Get() ) )
  878. {
  879. wchar_t titleStr[ 32 ] = { 0 };
  880. int r = MessageBoxW( hwndDlg, WASABI_API_LNGSTRINGW( IDS_NO_CHANGES_MADE_TO_QUERY ),
  881. WASABI_API_LNGSTRINGW_BUF( IDS_QUERY_NOT_CHANGED, titleStr, 32 ), MB_YESNOCANCEL );
  882. if ( r == IDYES )
  883. qe_curquery.Set( qe_curexpr.Get() );
  884. else if ( r == IDCANCEL ) break;
  885. }
  886. }
  887. EndDialog( hwndDlg, IDOK );
  888. break;
  889. case IDCANCEL: EndDialog( hwndDlg, IDCANCEL ); break;
  890. case IDC_EDIT_STRING:
  891. case IDC_EDIT_DATETIME:
  892. if ( HIWORD( wParam ) != EN_CHANGE ) break;
  893. case IDC_RADIO_EQUAL:
  894. case IDC_RADIO_ABOVE:
  895. case IDC_RADIO_ABOVEOREQUAL:
  896. case IDC_RADIO_BELOW:
  897. case IDC_RADIO_BELOWOREQUAL:
  898. case IDC_RADIO_ISLIKE:
  899. case IDC_RADIO_ISEMPTY:
  900. case IDC_RADIO_BEGINS:
  901. case IDC_RADIO_ENDS:
  902. case IDC_RADIO_CONTAINS:
  903. case IDC_CHECK_NOT:
  904. qe_update( hwndDlg );
  905. return 0;
  906. case IDC_LIST_FIELDS:
  907. if ( HIWORD( wParam ) == CBN_SELCHANGE )
  908. {
  909. HWND wnd = GetDlgItem( hwndDlg, IDC_LIST_FIELDS );
  910. int idx = ListBox_GetCurSel( wnd );
  911. int len = ListBox_GetTextLenW( wnd, idx );
  912. if ( qe_field != NULL ) free( qe_field );
  913. qe_field = (wchar_t *)calloc( ( len + 1 ), sizeof( wchar_t ) );
  914. ListBox_GetTextW( wnd, idx, qe_field );
  915. qe_field[ len ] = 0;
  916. qe_update( hwndDlg );
  917. }
  918. break;
  919. case IDC_BUTTON_AND:
  920. qe_pushExpression( hwndDlg, L"AND" );
  921. break;
  922. case IDC_BUTTON_OR:
  923. qe_pushExpression( hwndDlg, L"OR" );
  924. break;
  925. case ID_BUTTON_SENDTOQUERY:
  926. qe_pushExpression( hwndDlg, NULL );
  927. break;
  928. case IDC_BUTTON_EDITDATETIME:
  929. {
  930. const wchar_t *res = editTime( hwndDlg, qe_curdate.Get() );
  931. if ( res != NULL )
  932. {
  933. SetDlgItemTextW( hwndDlg, IDC_EDIT_DATETIME, res );
  934. qe_curdate.Set( res );
  935. }
  936. qe_update( hwndDlg );
  937. break;
  938. }
  939. case IDC_EDIT_QUERY:
  940. if ( HIWORD( wParam ) == EN_CHANGE )
  941. {
  942. wchar_t qe_tempstr[ 4096 ] = { 0 };
  943. GetDlgItemTextW( hwndDlg, IDC_EDIT_QUERY, qe_tempstr, 4096 );
  944. qe_curquery.Set( qe_tempstr );
  945. qe_showHideOperators( hwndDlg );
  946. }
  947. break;
  948. }
  949. }
  950. break;
  951. }
  952. return FALSE;
  953. }