OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 if (it != s_threadInstances.end()) | 991 if (it != s_threadInstances.end()) |
992 { | 992 { |
993 tab = it->second->m_tab; | 993 tab = it->second->m_tab; |
994 } | 994 } |
995 } | 995 } |
996 s_criticalSectionLocal.Unlock(); | 996 s_criticalSectionLocal.Unlock(); |
997 | 997 |
998 return tab; | 998 return tab; |
999 } | 999 } |
1000 | 1000 |
1001 | 1001 // Entry point |
1002 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) | 1002 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O
LECMD prgCmds[], OLECMDTEXT* pCmdText) |
1003 { | 1003 { |
1004 if (cCmds == 0) return E_INVALIDARG; | 1004 try |
1005 if (prgCmds == 0) return E_POINTER; | 1005 { |
| 1006 if (cCmds == 0) return E_INVALIDARG; |
| 1007 if (prgCmds == 0) return E_POINTER; |
1006 | 1008 |
1007 prgCmds[0].cmdf = OLECMDF_ENABLED; | 1009 prgCmds[0].cmdf = OLECMDF_ENABLED; |
1008 | 1010 } |
| 1011 catch (...) |
| 1012 { |
| 1013 DEBUG_GENERAL(L"CPluginClass::QueryStatus - exception"); |
| 1014 return E_FAIL; |
| 1015 } |
1009 return S_OK; | 1016 return S_OK; |
1010 } | 1017 } |
1011 | 1018 |
1012 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) | 1019 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
1013 { | 1020 { |
1014 DEBUG_GENERAL("CreatePluginMenu"); | 1021 DEBUG_GENERAL("CreatePluginMenu"); |
1015 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 1022 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
1016 | 1023 |
1017 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 1024 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
1018 | 1025 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 ctext = dictionary->Lookup("menu", "menu-settings"); | 1207 ctext = dictionary->Lookup("menu", "menu-settings"); |
1201 fmii.fMask = MIIM_STATE | MIIM_STRING; | 1208 fmii.fMask = MIIM_STATE | MIIM_STRING; |
1202 fmii.fState = MFS_ENABLED; | 1209 fmii.fState = MFS_ENABLED; |
1203 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1210 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1204 fmii.cch = static_cast<UINT>(ctext.size()); | 1211 fmii.cch = static_cast<UINT>(ctext.size()); |
1205 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); | 1212 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); |
1206 | 1213 |
1207 return true; | 1214 return true; |
1208 } | 1215 } |
1209 | 1216 |
1210 | 1217 // Entry point |
1211 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) | 1218 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
ARIANTARG*) |
1212 { | 1219 { |
1213 HWND hBrowserWnd = GetBrowserHWND(); | 1220 try |
1214 if (!hBrowserWnd) | |
1215 { | 1221 { |
1216 return E_FAIL; | 1222 HWND hBrowserWnd = GetBrowserHWND(); |
1217 } | 1223 if (!hBrowserWnd) |
| 1224 { |
| 1225 return E_FAIL; |
| 1226 } |
1218 | 1227 |
1219 // Create menu | 1228 // Create menu |
1220 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | 1229 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); |
1221 if (!hMenu) | 1230 if (!hMenu) |
1222 { | 1231 { |
1223 return E_FAIL; | 1232 return E_FAIL; |
1224 } | 1233 } |
1225 | 1234 |
1226 // Check if button in toolbar was pressed | 1235 // Check if button in toolbar was pressed |
1227 int nIDCommand = -1; | 1236 int nIDCommand = -1; |
1228 BOOL bRightAlign = FALSE; | 1237 BOOL bRightAlign = FALSE; |
1229 | 1238 |
1230 POINT pt; | 1239 POINT pt; |
1231 GetCursorPos(&pt); | 1240 GetCursorPos(&pt); |
1232 | 1241 |
1233 HWND hWndToolBar = ::WindowFromPoint(pt); | 1242 HWND hWndToolBar = ::WindowFromPoint(pt); |
1234 | 1243 |
1235 DWORD nProcessId; | 1244 DWORD nProcessId; |
1236 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 1245 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
1237 | 1246 |
1238 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 1247 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
1239 { | 1248 { |
1240 ::ScreenToClient(hWndToolBar, &pt); | 1249 ::ScreenToClient(hWndToolBar, &pt); |
1241 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 1250 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
1242 | 1251 |
1243 if (nButton > 0) | 1252 if (nButton > 0) |
1244 { | 1253 { |
1245 TBBUTTON pTBBtn = {}; | 1254 TBBUTTON pTBBtn = {}; |
1246 | 1255 |
1247 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1256 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
1248 { | 1257 { |
1249 RECT rcButton; | 1258 RECT rcButton; |
1250 nIDCommand = pTBBtn.idCommand; | 1259 nIDCommand = pTBBtn.idCommand; |
1251 | 1260 |
1252 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | 1261 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton
)) |
1253 { | |
1254 pt.x = rcButton.left; | |
1255 pt.y = rcButton.bottom; | |
1256 ClientToScreen(hWndToolBar, &pt); | |
1257 | |
1258 RECT rcWorkArea; | |
1259 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1260 if (rcWorkArea.right - pt.x < 150) | |
1261 { | 1262 { |
1262 bRightAlign = TRUE; | 1263 pt.x = rcButton.left; |
1263 pt.x = rcButton.right; | |
1264 pt.y = rcButton.bottom; | 1264 pt.y = rcButton.bottom; |
1265 ClientToScreen(hWndToolBar, &pt); | 1265 ClientToScreen(hWndToolBar, &pt); |
| 1266 |
| 1267 RECT rcWorkArea; |
| 1268 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); |
| 1269 if (rcWorkArea.right - pt.x < 150) |
| 1270 { |
| 1271 bRightAlign = TRUE; |
| 1272 pt.x = rcButton.right; |
| 1273 pt.y = rcButton.bottom; |
| 1274 ClientToScreen(hWndToolBar, &pt); |
| 1275 } |
1266 } | 1276 } |
1267 } | 1277 } |
1268 } | 1278 } |
| 1279 else |
| 1280 { |
| 1281 GetCursorPos(&pt); |
| 1282 } |
| 1283 } |
| 1284 |
| 1285 // Display menu |
| 1286 UINT nFlags = 0; |
| 1287 if (bRightAlign) |
| 1288 { |
| 1289 nFlags |= TPM_RIGHTALIGN; |
1269 } | 1290 } |
1270 else | 1291 else |
1271 { | 1292 { |
1272 GetCursorPos(&pt); | 1293 nFlags |= TPM_LEFTALIGN; |
1273 } | 1294 } |
| 1295 |
| 1296 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); |
1274 } | 1297 } |
1275 | 1298 catch (...) |
1276 // Display menu | |
1277 UINT nFlags = 0; | |
1278 if (bRightAlign) | |
1279 { | 1299 { |
1280 nFlags |= TPM_RIGHTALIGN; | 1300 // Suppress exception, log only |
| 1301 DEBUG_GENERAL(L"CPluginClass::Exec - exception"); |
| 1302 return E_FAIL; |
1281 } | 1303 } |
1282 else | |
1283 { | |
1284 nFlags |= TPM_LEFTALIGN; | |
1285 } | |
1286 | |
1287 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
1288 | 1304 |
1289 return S_OK; | 1305 return S_OK; |
1290 } | 1306 } |
1291 | 1307 |
1292 ///////////////////////////////////////////////////////////////////////////// | 1308 // Entry point |
1293 // Window procedures | |
1294 | |
1295 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) | 1309 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa
ram, LPARAM lParam) |
1296 { | 1310 { |
1297 // Find tab | 1311 CPluginClass *pClass; |
1298 CPluginClass *pClass = FindInstance(hWnd); | 1312 try |
1299 if (!pClass) | |
1300 { | 1313 { |
1301 return DefWindowProc(hWnd, message, wParam, lParam); | 1314 // Find tab |
1302 } | 1315 pClass = FindInstance(hWnd); |
| 1316 if (!pClass) |
| 1317 { |
| 1318 /* |
| 1319 * Race condition if reached. |
| 1320 * We did not unhook the window procedure for the status bar when the last
BHO instance using it terminated. |
| 1321 * The next best thing is to call the system default window function. |
| 1322 */ |
| 1323 return DefWindowProc(hWnd, message, wParam, lParam); |
| 1324 } |
1303 | 1325 |
1304 // Process message | 1326 // Process message |
1305 switch (message) | 1327 switch (message) |
1306 { | |
1307 case SB_SIMPLE: | |
1308 { | 1328 { |
1309 ShowWindow(pClass->m_hPaneWnd, !wParam); | 1329 case SB_SIMPLE: |
| 1330 { |
| 1331 ShowWindow(pClass->m_hPaneWnd, !wParam); |
| 1332 break; |
| 1333 } |
| 1334 |
| 1335 case WM_SYSCOLORCHANGE: |
| 1336 { |
| 1337 pClass->UpdateTheme(); |
| 1338 break; |
| 1339 } |
| 1340 |
| 1341 case SB_SETPARTS: |
| 1342 { |
| 1343 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) |
| 1344 { |
| 1345 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam,
lParam); |
| 1346 } |
| 1347 |
| 1348 WPARAM nParts = wParam; |
| 1349 if (STATUSBAR_PANE_NUMBER >= nParts) |
| 1350 { |
| 1351 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam,
lParam); |
| 1352 } |
| 1353 |
| 1354 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1)); |
| 1355 LPINT lpParts = (LPINT)LocalLock(hLocal); |
| 1356 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); |
| 1357 |
| 1358 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) |
| 1359 { |
| 1360 lpParts[i] -= pClass->m_nPaneWidth; |
| 1361 } |
| 1362 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w
Param, (LPARAM)lpParts); |
| 1363 |
| 1364 AdblockPlus::Rectangle rcPane; |
| 1365 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); |
| 1366 |
| 1367 AdblockPlus::Rectangle rcClient; |
| 1368 ::GetClientRect(hWnd, &rcClient); |
| 1369 |
| 1370 ::MoveWindow( |
| 1371 pClass->m_hPaneWnd, |
| 1372 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, |
| 1373 0, |
| 1374 pClass->m_nPaneWidth, |
| 1375 rcClient.Height(), |
| 1376 TRUE); |
| 1377 |
| 1378 ::LocalFree(hLocal); |
| 1379 return hRet; |
| 1380 } |
| 1381 |
| 1382 default: |
1310 break; | 1383 break; |
1311 } | 1384 } |
1312 | |
1313 case WM_SYSCOLORCHANGE: | |
1314 { | |
1315 pClass->UpdateTheme(); | |
1316 break; | |
1317 } | |
1318 | |
1319 case SB_SETPARTS: | |
1320 { | |
1321 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1322 { | |
1323 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l
Param); | |
1324 } | |
1325 | |
1326 WPARAM nParts = wParam; | |
1327 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1328 { | |
1329 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l
Param); | |
1330 } | |
1331 | |
1332 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); | |
1333 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1334 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1335 | |
1336 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1337 { | |
1338 lpParts[i] -= pClass->m_nPaneWidth; | |
1339 } | |
1340 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa
ram, (LPARAM)lpParts); | |
1341 | |
1342 AdblockPlus::Rectangle rcPane; | |
1343 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1344 | |
1345 AdblockPlus::Rectangle rcClient; | |
1346 ::GetClientRect(hWnd, &rcClient); | |
1347 | |
1348 ::MoveWindow( | |
1349 pClass->m_hPaneWnd, | |
1350 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1351 0, | |
1352 pClass->m_nPaneWidth, | |
1353 rcClient.Height(), | |
1354 TRUE); | |
1355 | |
1356 ::LocalFree(hLocal); | |
1357 | |
1358 | |
1359 return hRet; | |
1360 } | |
1361 | |
1362 default: | |
1363 break; | |
1364 } | 1385 } |
1365 | 1386 catch (...) |
1366 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara
m, lParam); | 1387 { |
1367 | 1388 // Suppress exception. Fall through to default handler. |
1368 | 1389 DEBUG_GENERAL(L"CPluginClass::NewStatusProc - exception"); |
1369 return result; | 1390 } |
1370 | 1391 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara
m); |
1371 } | 1392 } |
1372 | 1393 |
1373 | 1394 |
1374 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 1395 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1375 { | 1396 { |
1376 // use the disable icon as defualt, if the client doesn't exists | 1397 // use the disable icon as defualt, if the client doesn't exists |
1377 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1398 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1378 | 1399 |
1379 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1400 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
1380 if (tab) | 1401 if (tab) |
1381 { | 1402 { |
1382 CPluginClient* client = CPluginClient::GetInstance(); | 1403 CPluginClient* client = CPluginClient::GetInstance(); |
1383 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1404 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1384 { | 1405 { |
1385 if (client->IsWhitelistedUrl(url)) | 1406 if (client->IsWhitelistedUrl(url)) |
1386 { | 1407 { |
1387 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1408 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1388 } | 1409 } |
1389 else | 1410 else |
1390 { | 1411 { |
1391 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1412 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1392 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1413 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1393 } | 1414 } |
1394 } | 1415 } |
1395 } | 1416 } |
1396 return hIcon; | 1417 return hIcon; |
1397 } | 1418 } |
1398 | 1419 |
1399 | 1420 // Entry point |
1400 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP
aram, LPARAM lParam) | 1421 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP
aram, LPARAM lParam) |
1401 { | 1422 { |
1402 // Find tab | 1423 try |
1403 CPluginClass *pClass = FindInstance(GetParent(hWnd)); | |
1404 if (!pClass) | |
1405 { | 1424 { |
1406 return ::DefWindowProc(hWnd, message, wParam, lParam); | 1425 // Find tab |
1407 } | 1426 CPluginClass *pClass = FindInstance(GetParent(hWnd)); |
1408 | 1427 if (!pClass) |
1409 // Process message | |
1410 switch (message) | |
1411 { | |
1412 | |
1413 case WM_SETCURSOR: | |
1414 { | 1428 { |
1415 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); | 1429 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1416 return TRUE; | |
1417 } | 1430 } |
1418 case WM_PAINT: | 1431 |
| 1432 // Process message |
| 1433 switch (message) |
1419 { | 1434 { |
1420 PAINTSTRUCT ps; | 1435 case WM_SETCURSOR: |
1421 HDC hDC = ::BeginPaint(hWnd, &ps); | 1436 { |
1422 | 1437 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); |
1423 AdblockPlus::Rectangle rcClient; | 1438 return TRUE; |
1424 ::GetClientRect(hWnd, &rcClient); | 1439 } |
1425 | 1440 case WM_PAINT: |
1426 int nDrawEdge = 0; | 1441 { |
1427 | 1442 PAINTSTRUCT ps; |
1428 // Old Windows background drawing | 1443 HDC hDC = ::BeginPaint(hWnd, &ps); |
1429 if (pClass->m_hTheme == NULL) | 1444 |
1430 { | 1445 AdblockPlus::Rectangle rcClient; |
1431 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); | 1446 ::GetClientRect(hWnd, &rcClient); |
1432 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); | 1447 |
1433 | 1448 int nDrawEdge = 0; |
1434 nDrawEdge = 3; | 1449 |
1435 rcClient.left += 3; | 1450 // Old Windows background drawing |
1436 | 1451 if (pClass->m_hTheme == NULL) |
1437 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); | 1452 { |
1438 } | 1453 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); |
1439 // Themed background drawing | 1454 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); |
1440 else | 1455 |
1441 { | 1456 nDrawEdge = 3; |
1442 // Draw background | 1457 rcClient.left += 3; |
1443 if (pfnDrawThemeBackground) | 1458 |
1444 { | 1459 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); |
1445 AdblockPlus::Rectangle rc = rcClient; | 1460 } |
1446 rc.right -= 2; | 1461 // Themed background drawing |
1447 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); | 1462 else |
1448 } | 1463 { |
1449 | 1464 // Draw background |
1450 // Copy separator picture to left side | 1465 if (pfnDrawThemeBackground) |
1451 int nHeight = rcClient.Height(); | |
1452 int nWidth = rcClient.Width() - 2; | |
1453 | |
1454 for (int i = 0; i < 2; i++) | |
1455 { | |
1456 for (int j = 0; j < nHeight; j++) | |
1457 { | 1466 { |
1458 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); | 1467 AdblockPlus::Rectangle rc = rcClient; |
1459 | 1468 rc.right -= 2; |
1460 // Ignore black boxes (if source is obscured by other windows) | 1469 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); |
1461 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa
lue(clr) > 8)) | 1470 } |
| 1471 |
| 1472 // Copy separator picture to left side |
| 1473 int nHeight = rcClient.Height(); |
| 1474 int nWidth = rcClient.Width() - 2; |
| 1475 |
| 1476 for (int i = 0; i < 2; i++) |
| 1477 { |
| 1478 for (int j = 0; j < nHeight; j++) |
1462 { | 1479 { |
1463 ::SetPixel(hDC, i, j, clr); | 1480 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); |
| 1481 |
| 1482 // Ignore black boxes (if source is obscured by other windows) |
| 1483 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB
Value(clr) > 8)) |
| 1484 { |
| 1485 ::SetPixel(hDC, i, j, clr); |
| 1486 } |
1464 } | 1487 } |
1465 } | 1488 } |
1466 } | 1489 } |
1467 } | 1490 |
1468 | 1491 // Draw icon |
1469 // Draw icon | 1492 if (CPluginClient::GetInstance()) |
1470 if (CPluginClient::GetInstance()) | 1493 { |
1471 { | 1494 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1472 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); | 1495 |
1473 | 1496 int offx = nDrawEdge; |
1474 int offx = nDrawEdge; | 1497 if (hIcon) |
1475 if (hIcon) | 1498 { |
1476 { | 1499 //Get the RECT for the leftmost pane (the status text pane) |
1477 //Get the RECT for the leftmost pane (the status text pane) | 1500 RECT rect; |
| 1501 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0,
(LPARAM)&rect); |
| 1502 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico
nWidth, iconHeight, NULL, NULL, DI_NORMAL); |
| 1503 offx += iconWidth; |
| 1504 } |
| 1505 #ifdef _DEBUG |
| 1506 // Display version |
| 1507 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT
, 0, 0); |
| 1508 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont); |
| 1509 |
| 1510 AdblockPlus::Rectangle rcText = rcClient; |
| 1511 rcText.left += offx; |
| 1512 ::SetBkMode(hDC, TRANSPARENT); |
| 1513 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_
LEFT | DT_SINGLELINE | DT_VCENTER); |
| 1514 |
| 1515 ::SelectObject(hDC, hOldFont); |
| 1516 #endif // _DEBUG |
| 1517 } |
| 1518 |
| 1519 // Done! |
| 1520 EndPaint(hWnd, &ps); |
| 1521 |
| 1522 return 0; |
| 1523 } |
| 1524 |
| 1525 case WM_LBUTTONUP: |
| 1526 case WM_RBUTTONUP: |
| 1527 { |
| 1528 std::wstring url = pClass->GetBrowserUrl(); |
| 1529 if (url != pClass->GetTab()->GetDocumentUrl()) |
| 1530 { |
| 1531 pClass->GetTab()->SetDocumentUrl(url); |
| 1532 } |
| 1533 |
| 1534 // Create menu |
| 1535 HMENU hMenu = pClass->CreatePluginMenu(url); |
| 1536 if (!hMenu) |
| 1537 { |
| 1538 return 0; |
| 1539 } |
| 1540 |
| 1541 // Display menu |
| 1542 POINT pt; |
| 1543 ::GetCursorPos(&pt); |
| 1544 |
| 1545 RECT rc; |
| 1546 ::GetWindowRect(hWnd, &rc); |
| 1547 |
| 1548 if (rc.left >= 0 && rc.top >= 0) |
| 1549 { |
| 1550 pt.x = rc.left; |
| 1551 pt.y = rc.top; |
| 1552 } |
| 1553 |
| 1554 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN
); |
| 1555 break; |
| 1556 } |
| 1557 case WM_DESTROY: |
| 1558 break; |
| 1559 case SC_CLOSE: |
| 1560 break; |
| 1561 |
| 1562 case WM_UPDATEUISTATE: |
| 1563 { |
| 1564 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
| 1565 if (tab) |
| 1566 { |
| 1567 tab->OnActivate(); |
1478 RECT rect; | 1568 RECT rect; |
1479 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (
LPARAM)&rect); | 1569 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1480 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW
idth, iconHeight, NULL, NULL, DI_NORMAL); | 1570 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left)
/ 2, rect.top + (rect.bottom - rect.top) / 2); |
1481 offx += iconWidth; | 1571 } |
1482 } | 1572 if (LOWORD(wParam) == UIS_CLEAR) |
1483 #ifdef _DEBUG | 1573 { |
1484 // Display version | 1574 pClass->notificationMessage.Hide(); |
1485 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT,
0, 0); | 1575 } |
1486 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1576 break; |
1487 | 1577 } |
1488 AdblockPlus::Rectangle rcText = rcClient; | 1578 case WM_WINDOWPOSCHANGING: |
1489 rcText.left += offx; | 1579 { |
1490 ::SetBkMode(hDC, TRANSPARENT); | |
1491 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT
|DT_SINGLELINE|DT_VCENTER); | |
1492 | |
1493 ::SelectObject(hDC, hOldFont); | |
1494 #endif // _DEBUG | |
1495 } | |
1496 | |
1497 // Done! | |
1498 EndPaint(hWnd, &ps); | |
1499 | |
1500 return 0; | |
1501 } | |
1502 | |
1503 case WM_LBUTTONUP: | |
1504 case WM_RBUTTONUP: | |
1505 { | |
1506 std::wstring url = pClass->GetBrowserUrl(); | |
1507 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1508 { | |
1509 pClass->GetTab()->SetDocumentUrl(url); | |
1510 } | |
1511 | |
1512 // Create menu | |
1513 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1514 if (!hMenu) | |
1515 { | |
1516 return 0; | |
1517 } | |
1518 | |
1519 // Display menu | |
1520 POINT pt; | |
1521 ::GetCursorPos(&pt); | |
1522 | |
1523 RECT rc; | |
1524 ::GetWindowRect(hWnd, &rc); | |
1525 | |
1526 if (rc.left >= 0 && rc.top >= 0) | |
1527 { | |
1528 pt.x = rc.left; | |
1529 pt.y = rc.top; | |
1530 } | |
1531 | |
1532 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN); | |
1533 } | |
1534 break; | |
1535 case WM_DESTROY: | |
1536 break; | |
1537 case SC_CLOSE: | |
1538 break; | |
1539 | |
1540 case WM_UPDATEUISTATE: | |
1541 { | |
1542 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | |
1543 if (tab) | |
1544 { | |
1545 tab->OnActivate(); | |
1546 RECT rect; | 1580 RECT rect; |
1547 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1581 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1548 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) /
2, rect.top + (rect.bottom - rect.top) / 2); | 1582 if (pClass->notificationMessage.IsVisible()) |
1549 } | 1583 { |
1550 if (LOWORD(wParam) == UIS_CLEAR) | 1584 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left)
/ 2, rect.top + (rect.bottom - rect.top) / 2); |
1551 { | 1585 } |
1552 pClass->notificationMessage.Hide(); | 1586 break; |
| 1587 } |
| 1588 case WM_WINDOWPOSCHANGED: |
| 1589 { |
| 1590 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); |
| 1591 if (wndPos->flags & SWP_HIDEWINDOW) |
| 1592 { |
| 1593 pClass->notificationMessage.Hide(); |
| 1594 } |
| 1595 break; |
| 1596 } |
| 1597 case WM_ALREADY_UP_TO_DATE: |
| 1598 { |
| 1599 Dictionary* dictionary = Dictionary::GetInstance(); |
| 1600 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread
y-up-to-date-text"); |
| 1601 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea
dy-up-to-date-title"); |
| 1602 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle,
TTI_INFO); |
| 1603 break; |
| 1604 } |
| 1605 case WM_UPDATE_CHECK_ERROR: |
| 1606 { |
| 1607 Dictionary* dictionary = Dictionary::GetInstance(); |
| 1608 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex
t"); |
| 1609 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti
tle"); |
| 1610 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERR
OR); |
| 1611 break; |
| 1612 } |
| 1613 case WM_DOWNLOADING_UPDATE: |
| 1614 { |
| 1615 Dictionary* dictionary = Dictionary::GetInstance(); |
| 1616 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin
g-update-text"); |
| 1617 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi
ng-update-title"); |
| 1618 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT
itle, TTI_INFO); |
| 1619 break; |
1553 } | 1620 } |
1554 } | 1621 } |
1555 break; | |
1556 case WM_WINDOWPOSCHANGING: | |
1557 { | |
1558 RECT rect; | |
1559 GetWindowRect(pClass->m_hPaneWnd, &rect); | |
1560 if (pClass->notificationMessage.IsVisible()) | |
1561 { | |
1562 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) /
2, rect.top + (rect.bottom - rect.top) / 2); | |
1563 } | |
1564 } | |
1565 break; | |
1566 case WM_WINDOWPOSCHANGED: | |
1567 { | |
1568 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | |
1569 if (wndPos->flags & SWP_HIDEWINDOW) | |
1570 { | |
1571 pClass->notificationMessage.Hide(); | |
1572 } | |
1573 } | |
1574 break; | |
1575 case WM_ALREADY_UP_TO_DATE: | |
1576 { | |
1577 Dictionary* dictionary = Dictionary::GetInstance(); | |
1578 std::wstring upToDateText = dictionary->Lookup("updater", "update-already-
up-to-date-text"); | |
1579 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already
-up-to-date-title"); | |
1580 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT
I_INFO); | |
1581 } | |
1582 break; | |
1583 case WM_UPDATE_CHECK_ERROR: | |
1584 { | |
1585 Dictionary* dictionary = Dictionary::GetInstance(); | |
1586 std::wstring errorText = dictionary->Lookup("updater", "update-error-text"
); | |
1587 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl
e"); | |
1588 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR
); | |
1589 } | |
1590 break; | |
1591 case WM_DOWNLOADING_UPDATE: | |
1592 { | |
1593 Dictionary* dictionary = Dictionary::GetInstance(); | |
1594 std::wstring downloadingText = dictionary->Lookup("updater", "downloading-
update-text"); | |
1595 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading
-update-title"); | |
1596 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit
le, TTI_INFO); | |
1597 } | |
1598 break; | |
1599 } | 1622 } |
1600 | 1623 catch (...) |
1601 return DefWindowProc(hWnd, message, wParam, lParam); | 1624 { |
| 1625 // Suppress exception. Fall through to default handler. |
| 1626 DEBUG_GENERAL(L"CPluginClass::PaneWindowProc - exception"); |
| 1627 } |
| 1628 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1602 } | 1629 } |
1603 | 1630 |
1604 | 1631 |
1605 void CPluginClass::UpdateStatusBar() | 1632 void CPluginClass::UpdateStatusBar() |
1606 { | 1633 { |
1607 DEBUG_GENERAL("*** Updating statusbar") | 1634 DEBUG_GENERAL("*** Updating statusbar") |
1608 if (m_hPaneWnd == NULL) | 1635 if (m_hPaneWnd == NULL) |
1609 { | 1636 { |
1610 CreateStatusBarPane(); | 1637 CreateStatusBarPane(); |
1611 } | 1638 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 s_criticalSectionLocal.Unlock(); | 1687 s_criticalSectionLocal.Unlock(); |
1661 | 1688 |
1662 return icon; | 1689 return icon; |
1663 } | 1690 } |
1664 | 1691 |
1665 ATOM CPluginClass::GetAtomPaneClass() | 1692 ATOM CPluginClass::GetAtomPaneClass() |
1666 { | 1693 { |
1667 return s_atomPaneClass; | 1694 return s_atomPaneClass; |
1668 } | 1695 } |
1669 | 1696 |
OLD | NEW |