UpdateWindow.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. #include "Main.h"
  2. #include "Browser.h"
  3. #include "./api.h"
  4. #include "../nu/ns_wc.h"
  5. #include "menuv5.h"
  6. #include "ExternalCOM.h"
  7. #include "wa_dlg.h"
  8. #include "./updateService.h"
  9. UpdateBrowser *updateBrowser=0;
  10. static WNDPROC oldUpdateProc = 0;
  11. static BOOL fUnicode = FALSE;
  12. static void CALLBACK UpdateBrowser_TimerProc(HWND hwnd, UINT uMsg, UINT_PTR eventId, DWORD elapsed)
  13. {
  14. KillTimer(hwnd, eventId);
  15. if (0 == (WS_VISIBLE & GetWindowLongPtrW(hwnd, GWL_STYLE)))
  16. {
  17. ShowWindow(hwnd, SW_SHOW);
  18. }
  19. embedWindowState *state = (embedWindowState*)(ULONG_PTR)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
  20. if(NULL != state)
  21. {
  22. if (NULL != state->wasabi_window)
  23. {
  24. state->wasabi_window->activate();
  25. return;
  26. }
  27. else if (NULL != g_dialog_box_parent)
  28. {
  29. SetTimer(hwnd, eventId, 200, UpdateBrowser_TimerProc);
  30. return;
  31. }
  32. }
  33. HWND hFrame = hwnd;
  34. while (NULL != hFrame && 0 != (WS_CHILD & GetWindowLongPtrW(hFrame, GWL_STYLE)))
  35. hFrame = GetAncestor(hFrame, GA_PARENT);
  36. if (NULL != hFrame && (g_dialog_box_parent == hFrame || hMainWindow == hFrame))
  37. hFrame = NULL;
  38. if (NULL == hFrame) hFrame = hwnd;
  39. SetWindowPos(hFrame, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  40. SetForegroundWindow(hFrame);
  41. }
  42. HRESULT UpdateWindow_Show(LPCSTR pszUrl)
  43. {
  44. if (0 != _strnicmp(pszUrl, "http://client.winamp.com", 21))
  45. return E_UNEXPECTED;
  46. UpdateService *service;
  47. if (SUCCEEDED(UpdateService::CreateInstance(pszUrl, &service)))
  48. {
  49. HRESULT hr = service->Show();
  50. service->Release();
  51. if (SUCCEEDED(hr))
  52. return hr;
  53. }
  54. updateBrowser = new UpdateBrowser;
  55. updateBrowser->CreateHWND();
  56. updateBrowser->setVisible(TRUE);
  57. updateBrowser->NavigateToName((LPCTSTR)pszUrl);
  58. SetTimer(updateBrowser->m_hwnd, 1980, 1000, UpdateBrowser_TimerProc);
  59. return S_OK;
  60. }
  61. static LRESULT WINAPI BrowserSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  62. {
  63. switch (msg)
  64. {
  65. case WM_PAINT:
  66. {
  67. HDC out = GetDC(hwnd);
  68. RECT r;
  69. GetClientRect(hwnd, &r);
  70. r.left=11;
  71. r.top=20;
  72. r.right-=8;
  73. r.bottom-=14;
  74. HBRUSH b = CreateSolidBrush(WADlg_getColor(WADLG_WNDBG));
  75. FillRect(out, &r, b);
  76. DeleteObject(b);
  77. ValidateRect(hwnd, &r);
  78. }
  79. break;
  80. case WM_USER+0x102:
  81. {
  82. if (wParam == 1)
  83. {
  84. ShowWindow(updateBrowser->m_hwnd, SW_SHOW);
  85. }
  86. else
  87. {
  88. ShowWindow(updateBrowser->m_hwnd, SW_HIDE);
  89. }
  90. }
  91. break;
  92. case WM_USER + 101:
  93. {
  94. //updateBrowser->setVisible(FALSE);
  95. ShowWindow(hwnd, SW_HIDE);
  96. ShowWindow(updateBrowser->m_hwnd, SW_HIDE);
  97. return 0;
  98. }
  99. break;
  100. case WM_NCDESTROY:
  101. case WM_DESTROY:
  102. updateBrowser->m_hwnd = 0;
  103. return 0;
  104. break;
  105. }
  106. if (oldUpdateProc)
  107. return (fUnicode) ? CallWindowProcW(oldUpdateProc, hwnd, msg, wParam, lParam) : CallWindowProcA(oldUpdateProc, hwnd, msg, wParam, lParam);
  108. else
  109. return (fUnicode) ? DefWindowProcW(hwnd, msg, wParam, lParam) : DefWindowProcA(hwnd, msg, wParam, lParam);
  110. }
  111. HWND UpdateBrowser::CreateHWND()
  112. {
  113. if (!m_hwnd)
  114. {
  115. state.flags = EMBED_FLAGS_NOWINDOWMENU;
  116. state.me = 0;
  117. state.r.left = config_wx;
  118. state.r.right = config_wx+300;
  119. state.r.top = config_wy;
  120. state.r.bottom = config_wy+200;
  121. HWND owner = (HWND) SendMessageW(hMainWindow, WM_WA_IPC, (WPARAM) & state, IPC_GET_EMBEDIF);
  122. m_hwnd = owner;
  123. setLocation(11,20, 300-19, 200-34);
  124. fUnicode = IsWindowUnicode(owner);
  125. oldUpdateProc = (WNDPROC) ((fUnicode) ? SetWindowLongPtrW(owner, GWLP_WNDPROC, (LONG_PTR)BrowserSubclassProc) :
  126. SetWindowLongPtrA(owner, GWLP_WNDPROC, (LONG_PTR)BrowserSubclassProc));
  127. SetWindowTextW(owner, getStringW(IDS_WINAMP_UPDATE, NULL, 0));
  128. }
  129. return m_hwnd;
  130. }
  131. // ---------------------------------------------------------------
  132. void UpdateBrowser::NavigateToName(LPCTSTR pszUrl)
  133. {
  134. if (!m_pweb) return ;
  135. DWORD dwChars = lstrlen (pszUrl) + 1;
  136. LPWSTR pwszUrl = (LPWSTR)LocalAlloc (LPTR, dwChars * sizeof (WCHAR));
  137. long moptions = navNoReadFromCache | navNoWriteToCache | navNoHistory;
  138. VARIANT options;
  139. memset( (void*)&options, 0, sizeof(VARIANT));
  140. V_VT(&options) = VT_I4;
  141. V_I4(&options) = moptions;
  142. if (pwszUrl)
  143. {
  144. MultiByteToWideCharSZ(CP_ACP, 0, (LPCSTR)pszUrl, -1, pwszUrl, dwChars);
  145. m_pweb->Navigate (pwszUrl, &options , 0, 0, 0);
  146. LocalFree (pwszUrl);
  147. }
  148. }
  149. #define VIDEO_GENFF_SIZEREQUEST (WM_USER+2048)
  150. void UpdateBrowser::Resized(unsigned long width, unsigned long height)
  151. {
  152. updateBrowser->setLocation(11,20, width, height);
  153. if (GetParent(m_hwnd))
  154. SendMessageW(GetParent(m_hwnd), VIDEO_GENFF_SIZEREQUEST, width, height);
  155. else
  156. SetWindowPos(m_hwnd, 0, 0, 0, width + 19, height + 34, SWP_NOMOVE|SWP_ASYNCWINDOWPOS);
  157. InvalidateRect(m_hwnd, NULL, TRUE);
  158. }
  159. HRESULT UpdateBrowser::GetExternal(IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
  160. {
  161. if (NULL == ppDispatch)
  162. return E_POINTER;
  163. ExternalCOM *external;
  164. HRESULT hr = JSAPI1_GetExternal(&external);
  165. if (FAILED(hr)) external = NULL;
  166. *ppDispatch = (IDispatch*) external;
  167. return S_OK;
  168. }
  169. void UpdateBrowser::OnNavigateComplete()
  170. {
  171. setVisible(TRUE);
  172. RECT r;
  173. GetClientRect(m_hwnd, &r);
  174. setLocation(11,20, r.right-19, r.bottom-34);
  175. }