1
0

pageEmpty.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "./pageEmpty.h"
  2. #include "./loginBox.h"
  3. #include "./common.h"
  4. #include "../resource.h"
  5. static HRESULT CALLBACK LoginPageEmpty_CreateInstance(HWND hwnd, HWND hLoginbox, LoginPage **instance)
  6. {
  7. if (NULL == instance) return E_POINTER;
  8. if (NULL == hwnd || NULL == hLoginbox) return E_INVALIDARG;
  9. *instance = new LoginPageEmpty(hwnd, hLoginbox);
  10. if (NULL == instance) return E_OUTOFMEMORY;
  11. return S_OK;
  12. }
  13. LoginPageEmpty::LoginPageEmpty(HWND hwnd, HWND hLoginbox)
  14. : LoginPage(hwnd, hLoginbox)
  15. {
  16. }
  17. LoginPageEmpty::~LoginPageEmpty()
  18. {
  19. }
  20. HWND LoginPageEmpty::CreatePage(HWND hLoginbox, HWND hParent)
  21. {
  22. return LoginPage::CreatePage(hLoginbox, MAKEINTRESOURCE(IDD_PAGE_EMPTY),
  23. hParent, NULL, LoginPageEmpty_CreateInstance);
  24. }
  25. BOOL LoginPageEmpty::OnInitDialog(HWND hFocus, LPARAM param)
  26. {
  27. if (NULL != hLoginbox)
  28. {
  29. BOOL updateActive = LoginBox_GetUpdateState(hLoginbox);
  30. EnableCheckButton(FALSE == updateActive);
  31. }
  32. LoginPage::OnInitDialog(hFocus, param);
  33. return FALSE;
  34. }
  35. void LoginPageEmpty::OnCommand(UINT commandId, UINT eventType, HWND hControl)
  36. {
  37. switch(commandId)
  38. {
  39. case IDC_CHECKNOW:
  40. if (BN_CLICKED == eventType && NULL != hLoginbox)
  41. LoginBox_UpdateProviders(hLoginbox, TRUE);
  42. break;
  43. }
  44. LoginPage::OnCommand(commandId, eventType, hControl);
  45. }
  46. void LoginPageEmpty::UpdateLayout(BOOL fRedraw)
  47. {
  48. LoginPage::UpdateLayout(fRedraw);
  49. RECT clientRect;
  50. GetClientRect(hwnd, &clientRect);
  51. RECT offsetRect;
  52. SetRect(&offsetRect, 2, 4, 4, 22);
  53. MapDialogRect(hwnd, &offsetRect);
  54. clientRect.left += offsetRect.left;
  55. clientRect.top += offsetRect.top;
  56. clientRect.right -= offsetRect.right;
  57. clientRect.bottom -= offsetRect.bottom;
  58. UINT flags = SWP_NOACTIVATE | SWP_NOZORDER;
  59. if (FALSE == fRedraw) flags |= SWP_NOREDRAW;
  60. const INT szControls[] = { IDC_MESSAGE, IDC_CHECKNOW, IDC_CHECK_STATUS};
  61. HDWP hdwp = BeginDeferWindowPos(ARRAYSIZE(szControls));
  62. RECT rect;
  63. LONG clientTop = clientRect.top;
  64. LONG left, top = clientRect.top;
  65. for (INT i = 0; i < ARRAYSIZE(szControls); i++)
  66. {
  67. HWND hControl = GetDlgItem(hwnd, szControls[i]);
  68. if (NULL == hControl || FALSE == GetWindowRect(hControl, &rect)) continue;
  69. MapWindowPoints(HWND_DESKTOP, hwnd, (POINT*)&rect, 2);
  70. switch(szControls[i])
  71. {
  72. case IDC_MESSAGE:
  73. top = clientRect.top + ((clientRect.bottom - clientRect.top) - (rect.bottom - rect.top))/2;
  74. left = clientRect.left + ((clientRect.right - clientRect.left) - (rect.right - rect.left))/2;
  75. OffsetRect(&rect, left - rect.left, top - rect.top);
  76. clientTop = rect.bottom;
  77. break;
  78. case IDC_CHECKNOW:
  79. top = clientTop + 2*offsetRect.top;
  80. left = clientRect.left + ((clientRect.right - clientRect.left) - (rect.right - rect.left))/2;
  81. OffsetRect(&rect, left - rect.left, top - rect.top);
  82. break;
  83. case IDC_CHECK_STATUS:
  84. top = clientTop + offsetRect.top;
  85. left = clientRect.left + ((clientRect.right - clientRect.left) - (rect.right - rect.left))/2;
  86. OffsetRect(&rect, left - rect.left, top - rect.top);
  87. break;
  88. }
  89. hdwp = DeferWindowPos(hdwp, hControl, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, flags);
  90. if (NULL == hdwp) break;
  91. }
  92. if (NULL != hdwp)
  93. EndDeferWindowPos(hdwp);
  94. }
  95. HBRUSH LoginPageEmpty::OnGetStaticColor(HDC hdc, HWND hControl)
  96. {
  97. INT_PTR controlId = (INT_PTR)GetWindowLongPtr(hControl, GWLP_ID);
  98. switch(controlId)
  99. {
  100. case IDC_MESSAGE:
  101. case IDC_CHECK_STATUS:
  102. SetTextColor(hdc, rgbSecondaryText);
  103. SetBkColor(hdc, rgbBack);
  104. return hbrBack;
  105. }
  106. return LoginPage::OnGetStaticColor(hdc, hControl);
  107. }
  108. BOOL LoginPageEmpty::OnGetLoginData(LoginData **ppLoginData)
  109. {
  110. return FALSE;
  111. }
  112. void LoginPageEmpty::OnUpdateStateChange(BOOL updateActive)
  113. {
  114. EnableCheckButton(FALSE == updateActive);
  115. }
  116. void LoginPageEmpty::EnableCheckButton(BOOL fEnable)
  117. {
  118. HWND hButton = GetDlgItem(hwnd, IDC_CHECKNOW);
  119. HWND hStatus = GetDlgItem(hwnd, IDC_CHECK_STATUS);
  120. if (FALSE != fEnable)
  121. {
  122. if (NULL != hStatus)
  123. ShowWindow(hStatus, SW_HIDE);
  124. if (NULL != hButton)
  125. {
  126. EnableWindow(hButton, TRUE);
  127. ShowWindow(hButton, SW_SHOWNA);
  128. }
  129. }
  130. else
  131. {
  132. if (NULL != hButton)
  133. {
  134. if (NULL != hStatus)
  135. ShowWindow(hButton, SW_HIDE);
  136. EnableWindow(hButton, FALSE);
  137. }
  138. if (NULL != hStatus)
  139. ShowWindow(hStatus, SW_SHOWNA);
  140. }
  141. }