1
0

spage_feedback.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. #define APSTUDIO_READONLY_SYMBOLS
  2. #include "main.h"
  3. #include "./spage_feedback.h"
  4. #include "./setup_resource.h"
  5. #include "../nu/ns_wc.h"
  6. #include "../nu/AutoChar.h"
  7. #include "../nu/AutoWide.h"
  8. #include "./langutil.h"
  9. #define FF_ALLOWFEEDBACK 0x0001
  10. #define FF_ANNOUNCEMENTS 0x0010
  11. #define FF_STATISTICS 0x0020
  12. #define GENDER_UNKNOWN 0
  13. #define GENDER_MALE 1
  14. #define GENDER_FEMALE 2
  15. setup_page_feedback::setup_page_feedback() : ref(1), hwnd(NULL)
  16. {
  17. szEmail[0] = 0x00;
  18. szCountry[0] = 0x00;
  19. gender = GENDER_UNKNOWN;
  20. flags = FF_ALLOWFEEDBACK | FF_ANNOUNCEMENTS | FF_STATISTICS;
  21. }
  22. setup_page_feedback::~setup_page_feedback()
  23. {
  24. }
  25. size_t setup_page_feedback::AddRef()
  26. {
  27. return ++ref;
  28. }
  29. size_t setup_page_feedback::Release()
  30. {
  31. if (1 == ref)
  32. {
  33. delete(this);
  34. return 0;
  35. }
  36. return --ref;
  37. }
  38. HRESULT setup_page_feedback::GetName(bool bShort, const wchar_t **pszName)
  39. {
  40. if (bShort)
  41. {
  42. static wchar_t szShortName[32] = {0};
  43. *pszName = (*szShortName) ? szShortName : getStringW(IDS_PAGE_FEEDBACK, szShortName, sizeof(szShortName)/sizeof(wchar_t));
  44. }
  45. else
  46. {
  47. static wchar_t szLongName[64] = {0};
  48. *pszName = (*szLongName) ? szLongName : getStringW(IDS_PAGE_FEEDBACK_LONG, szLongName, sizeof(szLongName)/sizeof(wchar_t));
  49. }
  50. return S_OK;
  51. }
  52. HRESULT setup_page_feedback::Save(HWND hwndText)
  53. {
  54. HRESULT hr(S_OK);
  55. int r, s;
  56. char data[8192] = {0};
  57. char str[32] = {0};
  58. if (FF_ALLOWFEEDBACK & flags)
  59. {
  60. s = GetPrivateProfileIntW(L"WinampReg", L"RegDataLen", 0, INI_FILE);
  61. if (s > 0) GetPrivateProfileStructA("WinampReg", "RegData2", data, s, INI_FILEA);
  62. if (!SetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_EMAIL), szEmail, -1)) hr = E_UNEXPECTED;
  63. if (!SetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_COUNTRY), szCountry, lstrlenW(szCountry)*sizeof(wchar_t))) hr = E_UNEXPECTED;
  64. if (!SetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_GENDER), &gender, sizeof(gender))) hr = E_UNEXPECTED;
  65. r = (FF_ANNOUNCEMENTS == (FF_ANNOUNCEMENTS & flags));
  66. if (!SetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_ANNOUNCEMENTS), &r, sizeof(r))) hr = E_UNEXPECTED;
  67. config_newverchk2 = (FF_STATISTICS == (FF_STATISTICS & flags));
  68. }
  69. else config_newverchk2 = 0;
  70. WritePrivateProfileStringW(AutoWide(app_name), L"newverchk2", (config_newverchk2) ? L"1" : L"0", INI_FILE);
  71. s = GetMetricsSize(data);
  72. StringCchPrintfA(str, 32, "%d", s);
  73. WritePrivateProfileStringA("WinampReg", "RegDataLen", (s) ? str : NULL, INI_FILEA);
  74. WritePrivateProfileStructA("WinampReg", "RegData2", (s) ? data : NULL, s, INI_FILEA);
  75. if (hwnd) UpdateUI();
  76. return hr;
  77. }
  78. HRESULT setup_page_feedback::Revert(void)
  79. {
  80. HRESULT hr(S_OK);
  81. char data[8192] = {0, };
  82. DWORD sendinfo;
  83. flags = FF_ALLOWFEEDBACK;
  84. if (config_newverchk2) flags |= FF_STATISTICS;
  85. int s = GetPrivateProfileIntW(L"WinampReg", L"RegDataLen", 0, INI_FILE);
  86. if (s > 0) GetPrivateProfileStructA("WinampReg", "RegData2", data, s, INI_FILEA);
  87. GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_EMAIL), szEmail, sizeof(szEmail));
  88. GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_COUNTRY), szCountry, sizeof(szCountry));
  89. GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_GENDER), &gender, sizeof(gender));
  90. GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_ANNOUNCEMENTS), &sendinfo, sizeof(sendinfo));
  91. if (sendinfo) flags |= FF_ANNOUNCEMENTS;
  92. if (hwnd) UpdateUI();
  93. return hr;
  94. }
  95. HRESULT setup_page_feedback::IsDirty(void)
  96. {
  97. char data[8192] = {0};
  98. wchar_t szTest[256] = {0};
  99. int r;
  100. DWORD lcid;
  101. lcid = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
  102. if (0 != (FF_STATISTICS & flags) != !!config_newverchk2) return S_OK;
  103. int s = GetPrivateProfileIntW(L"WinampReg", L"RegDataLen", 0, INI_FILE);
  104. if (s > 0) GetPrivateProfileStructA("WinampReg", "RegData2", data, s, INI_FILEA);
  105. if (!GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_EMAIL), szTest, sizeof(szTest))) return E_UNEXPECTED;
  106. r = CompareStringW(lcid, NORM_IGNORECASE, szTest, -1, szEmail, -1);
  107. if (0 == r) return E_UNEXPECTED;
  108. if (CSTR_EQUAL != r) return S_OK;
  109. if (!GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_COUNTRY), szTest, sizeof(szTest))) return E_UNEXPECTED;
  110. r = CompareStringW(lcid, NORM_IGNORECASE, szTest, -1, szCountry, -1);
  111. if (0 == r) return E_UNEXPECTED;
  112. if (CSTR_EQUAL != r) return S_OK;
  113. r = 0;
  114. if (!GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_GENDER), &r, sizeof(r))) return E_UNEXPECTED;
  115. if (r != gender) return S_OK;
  116. r = 0;
  117. if (!GetMetricsValueW(data, MAKEINTRESOURCEA(METRICS_ANNOUNCEMENTS), &r, sizeof(r))) return E_UNEXPECTED;
  118. if (r != (FF_ANNOUNCEMENTS == (FF_ANNOUNCEMENTS & flags))) return S_OK;
  119. return S_FALSE;
  120. }
  121. HRESULT setup_page_feedback::Validate(void)
  122. {
  123. wchar_t *p;
  124. if (0 == (FF_ALLOWFEEDBACK & flags) || !*szEmail) return S_OK;
  125. for (p = szEmail; *p != 0x00 && *p != L'@'; p = CharNextW(p));
  126. if (L'@' != *p || 0x00 == *CharNextW(p))
  127. {
  128. WCHAR szTitle[128] = {0};
  129. HWND hwndTop, hwndTest;
  130. hwndTop = hwnd;
  131. while(NULL != (hwndTest = GetParent(hwndTop))) hwndTop = hwndTest;
  132. GetWindowTextW(hwndTop, szTitle, sizeof(szTitle)/sizeof(WCHAR));
  133. if (hwndTop)
  134. {
  135. MessageBoxW(hwndTop, getStringW(IDS_PAGE_INCORRECT_EMAIL_ADDRESS, NULL, 0),
  136. szTitle, MB_OK | MB_ICONERROR);
  137. return S_FALSE;
  138. }
  139. }
  140. return S_OK;
  141. }
  142. HRESULT setup_page_feedback::CreateView(HWND hwndParent, HWND *phwnd)
  143. {
  144. *phwnd = WACreateDialogParam(MAKEINTRESOURCEW(IDD_SETUP_PAGE_FEEDBACK), hwndParent, ::DialogProc, (LPARAM)this);
  145. return S_OK;
  146. }
  147. void setup_page_feedback::UpdateUI(void)
  148. {
  149. HWND hwndCB;
  150. if (!hwnd || !IsWindow(hwnd)) return;
  151. CheckDlgButton(hwnd, IDC_CHK_ANNOUNCEMENTS, (FF_ANNOUNCEMENTS & flags) ? BST_CHECKED : BST_UNCHECKED);
  152. CheckDlgButton(hwnd, IDC_CHK_STATISTICS, (FF_STATISTICS & flags) ? BST_CHECKED : BST_UNCHECKED);
  153. SetDlgItemTextW(hwnd, IDC_EDT_EMAIL, szEmail);
  154. SetDlgItemTextW(hwnd, IDC_EDT_COUNTRY, szCountry);
  155. hwndCB = GetDlgItem(hwnd, IDC_CB_GENDER);
  156. if (hwndCB)
  157. {
  158. INT count = (INT)SendMessageW(hwndCB, CB_GETCOUNT, 0, 0L);
  159. if (count > 0)
  160. {
  161. INT i;
  162. for (i = 0; i < count && gender != (INT)SendMessageW(hwndCB, CB_GETITEMDATA, i, 0L); i++);
  163. if (i != count) SendMessageW(hwndCB, CB_SETCURSEL, i, 0L);
  164. }
  165. }
  166. }
  167. void setup_page_feedback::ComboBox_OnSelChange(HWND hwndCtrl)
  168. {
  169. INT index;
  170. index = (INT)SendMessageW(hwndCtrl, CB_GETCURSEL, 0, 0L);
  171. if (CB_ERR == index) return;
  172. gender = (INT)SendMessageW(hwndCtrl, CB_GETITEMDATA, index, 0L);
  173. }
  174. INT_PTR setup_page_feedback::OnInitDialog(HWND hwndFocus, LPARAM lParam)
  175. {
  176. HWND hwndCB;
  177. SendDlgItemMessageW(hwnd, IDC_EDT_EMAIL, EM_LIMITTEXT, sizeof(szEmail)/sizeof(wchar_t), 0);
  178. SendDlgItemMessageW(hwnd, IDC_EDT_COUNTRY, EM_LIMITTEXT, sizeof(szCountry)/sizeof(wchar_t), 0);
  179. hwndCB = GetDlgItem(hwnd, IDC_CB_GENDER);
  180. if (hwndCB)
  181. {
  182. UINT genderStrID[] = {IDS_GENDER_UNKNOWN, IDS_GENDER_FEMALE, IDS_GENDER_MALE, };
  183. INT genderVal[] = {GENDER_UNKNOWN, GENDER_FEMALE, GENDER_MALE, };
  184. for(int i = 0; i < sizeof(genderStrID)/sizeof(UINT); i++)
  185. {
  186. INT index = (INT)SendMessageW(hwndCB, CB_ADDSTRING,0, (LPARAM)getStringW(genderStrID[i], NULL, 0));
  187. if (CB_ERR != index) SendMessageW(hwndCB, CB_SETITEMDATA, index, (LPARAM)genderVal[i]);
  188. }
  189. }
  190. UpdateUI();
  191. return 0;
  192. }
  193. void setup_page_feedback::OnSize(UINT nType, INT cx, INT cy)
  194. {
  195. INT ctrlList[] = { IDC_LBL_HEADER, IDC_CHK_ANNOUNCEMENTS, IDC_CHK_STATISTICS,
  196. IDC_EDT_EMAIL, IDC_EDT_COUNTRY, IDC_CB_GENDER, };
  197. HWND hwndCtrl;
  198. HDWP hdwp;
  199. RECT rw;
  200. INT width, ox;
  201. hwndCtrl = GetDlgItem(hwnd, IDC_LBL_EMAIL);
  202. GetWindowRect(hwndCtrl, &rw);
  203. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rw, 2);
  204. ox = rw.left;
  205. hdwp = BeginDeferWindowPos(sizeof(ctrlList)/sizeof(INT));
  206. if (!hdwp) return;
  207. for (int i = 0; i < sizeof(ctrlList)/sizeof(INT); i++)
  208. {
  209. hwndCtrl = GetDlgItem(hwnd, ctrlList[i]);
  210. if (hwndCtrl)
  211. {
  212. GetWindowRect(hwndCtrl, &rw);
  213. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rw, 2);
  214. switch(ctrlList[i])
  215. {
  216. case IDC_EDT_EMAIL:
  217. case IDC_EDT_COUNTRY:
  218. case IDC_CB_GENDER:
  219. width = cx - rw.left - ox;
  220. break;
  221. default:
  222. width = cx - rw.left*2;
  223. break;
  224. }
  225. hdwp = DeferWindowPos(hdwp, hwndCtrl, NULL, 0, 0, width, rw.bottom - rw.top,
  226. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
  227. }
  228. }
  229. if (hdwp) EndDeferWindowPos(hdwp);
  230. }
  231. void setup_page_feedback::OnCommand(INT nCtrlID, INT nEvntID, HWND hwndCtrl)
  232. {
  233. switch(nCtrlID)
  234. {
  235. case IDC_EDT_EMAIL:
  236. switch(nEvntID)
  237. {
  238. case EN_CHANGE:
  239. {
  240. GetWindowTextW(hwndCtrl, szEmail, sizeof(szEmail)/sizeof(wchar_t));
  241. HWND hwndChk = GetDlgItem(hwnd, IDC_CHK_ANNOUNCEMENTS);
  242. if (IsWindow(hwndChk))
  243. {
  244. BOOL bEnabled = IsWindowEnabled(hwndChk);
  245. if (bEnabled != (0x00 != *szEmail))
  246. {
  247. CheckDlgButton(hwnd, IDC_CHK_ANNOUNCEMENTS, (0x00 != *szEmail) ? BST_CHECKED : BST_UNCHECKED);
  248. EnableWindow(GetDlgItem(hwnd, IDC_CHK_ANNOUNCEMENTS), 0x00 != *szEmail);
  249. PostMessageW(hwnd, WM_COMMAND, MAKEWPARAM(IDC_CHK_ANNOUNCEMENTS, BN_CLICKED), (LPARAM)GetDlgItem(hwnd, IDC_CHK_ANNOUNCEMENTS));
  250. }
  251. }
  252. }
  253. break;
  254. }
  255. break;
  256. case IDC_EDT_COUNTRY:
  257. switch(nEvntID)
  258. {
  259. case EN_CHANGE:
  260. GetWindowTextW(hwndCtrl, szCountry, sizeof(szCountry)/sizeof(wchar_t));
  261. break;
  262. }
  263. break;
  264. case IDC_CHK_ANNOUNCEMENTS:
  265. switch(nEvntID)
  266. {
  267. case BN_CLICKED:
  268. if (BST_CHECKED & (INT)SendMessageW(hwndCtrl, BM_GETSTATE, 0, 0L)) flags |= FF_ANNOUNCEMENTS;
  269. else flags &= ~FF_ANNOUNCEMENTS;
  270. break;
  271. }
  272. break;
  273. case IDC_CHK_STATISTICS:
  274. switch(nEvntID)
  275. {
  276. case BN_CLICKED:
  277. if (BST_CHECKED & (INT)SendMessageW(hwndCtrl, BM_GETSTATE, 0, 0L)) flags |= FF_STATISTICS;
  278. else flags &= ~FF_STATISTICS;
  279. break;
  280. }
  281. break;
  282. case IDC_CB_GENDER:
  283. switch(nEvntID)
  284. {
  285. case CBN_SELCHANGE: ComboBox_OnSelChange(hwndCtrl); break;
  286. }
  287. break;
  288. }
  289. }
  290. INT_PTR setup_page_feedback::PageDlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
  291. {
  292. switch(uMsg)
  293. {
  294. case WM_INITDIALOG: return OnInitDialog((HWND)wParam, lParam);
  295. case WM_DESTROY: break;
  296. case WM_SIZE: OnSize((UINT)wParam, LOWORD(lParam), HIWORD(lParam)); break;
  297. case WM_COMMAND: OnCommand(LOWORD(wParam), HIWORD(wParam), (HWND)lParam); break;
  298. }
  299. return 0;
  300. }
  301. static INT_PTR WINAPI DialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  302. {
  303. setup_page_feedback *pInst = (setup_page_feedback*)GetPropW(hwnd, L"SETUPPAGE");
  304. switch(uMsg)
  305. {
  306. case WM_INITDIALOG:
  307. pInst = (setup_page_feedback*)lParam;
  308. if (pInst)
  309. {
  310. pInst->hwnd = hwnd;
  311. SetPropW(hwnd, L"SETUPPAGE", pInst);
  312. }
  313. break;
  314. case WM_DESTROY:
  315. if (pInst)
  316. {
  317. pInst->PageDlgProc(uMsg, wParam, lParam);
  318. RemovePropW(hwnd, L"SETUPPAGE");
  319. pInst = NULL;
  320. }
  321. break;
  322. }
  323. return (pInst) ? pInst->PageDlgProc(uMsg, wParam, lParam) : 0;
  324. }
  325. #ifdef CBCLASS
  326. #undef CBCLASS
  327. #endif
  328. #define CBCLASS setup_page_feedback
  329. START_DISPATCH
  330. CB(ADDREF, AddRef)
  331. CB(RELEASE, Release)
  332. CB(API_SETUPPAGE_GET_NAME, GetName)
  333. CB(API_SETUPPAGE_CREATEVIEW, CreateView)
  334. CB(API_SETUPPAGE_SAVE, Save)
  335. CB(API_SETUPPAGE_REVERT, Revert)
  336. CB(API_SETUPPAGE_ISDIRTY, IsDirty)
  337. CB(API_SETUPPAGE_VALIDATE, Validate)
  338. END_DISPATCH
  339. #undef CBCLASS