Left: | ||
Right: |
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 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
964 if (it != s_threadInstances.end()) | 964 if (it != s_threadInstances.end()) |
965 { | 965 { |
966 tab = it->second->m_tab; | 966 tab = it->second->m_tab; |
967 } | 967 } |
968 } | 968 } |
969 s_criticalSectionLocal.Unlock(); | 969 s_criticalSectionLocal.Unlock(); |
970 | 970 |
971 return tab; | 971 return tab; |
972 } | 972 } |
973 | 973 |
974 | 974 // Entry point |
975 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) | 975 STDMETHODIMP CPluginClass::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds, O LECMD prgCmds[], OLECMDTEXT* pCmdText) |
976 { | 976 { |
977 if (cCmds == 0) return E_INVALIDARG; | 977 try |
978 if (prgCmds == 0) return E_POINTER; | 978 { |
979 if (cCmds == 0) return E_INVALIDARG; | |
980 if (prgCmds == 0) return E_POINTER; | |
979 | 981 |
980 prgCmds[0].cmdf = OLECMDF_ENABLED; | 982 prgCmds[0].cmdf = OLECMDF_ENABLED; |
981 | 983 } |
984 catch (...) | |
985 { | |
986 return E_FAIL; | |
987 } | |
982 return S_OK; | 988 return S_OK; |
983 } | 989 } |
984 | 990 |
985 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) | 991 HMENU CPluginClass::CreatePluginMenu(const std::wstring& url) |
986 { | 992 { |
987 DEBUG_GENERAL("CreatePluginMenu"); | 993 DEBUG_GENERAL("CreatePluginMenu"); |
988 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); | 994 HINSTANCE hInstance = _AtlBaseModule.GetModuleInstance(); |
989 | 995 |
990 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); | 996 HMENU hMenu = ::LoadMenu(hInstance, MAKEINTRESOURCE(IDR_MENU1)); |
991 | 997 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1173 ctext = dictionary->Lookup("menu", "menu-settings"); | 1179 ctext = dictionary->Lookup("menu", "menu-settings"); |
1174 fmii.fMask = MIIM_STATE | MIIM_STRING; | 1180 fmii.fMask = MIIM_STATE | MIIM_STRING; |
1175 fmii.fState = MFS_ENABLED; | 1181 fmii.fState = MFS_ENABLED; |
1176 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); | 1182 fmii.dwTypeData = const_cast<LPWSTR>(ctext.c_str()); |
1177 fmii.cch = static_cast<UINT>(ctext.size()); | 1183 fmii.cch = static_cast<UINT>(ctext.size()); |
1178 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); | 1184 ::SetMenuItemInfoW(hMenu, ID_MENU_SETTINGS, FALSE, &fmii); |
1179 | 1185 |
1180 return true; | 1186 return true; |
1181 } | 1187 } |
1182 | 1188 |
1183 | 1189 // Entry point |
1184 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) | 1190 STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V ARIANTARG*) |
1185 { | 1191 { |
1186 HWND hBrowserWnd = GetBrowserHWND(); | 1192 try |
1187 if (!hBrowserWnd) | |
1188 { | 1193 { |
1189 return E_FAIL; | 1194 HWND hBrowserWnd = GetBrowserHWND(); |
1190 } | 1195 if (!hBrowserWnd) |
1196 { | |
1197 return E_FAIL; | |
1198 } | |
1191 | 1199 |
1192 // Create menu | 1200 // Create menu |
1193 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); | 1201 HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl()); |
1194 if (!hMenu) | 1202 if (!hMenu) |
1195 { | 1203 { |
1196 return E_FAIL; | 1204 return E_FAIL; |
1197 } | 1205 } |
1198 | 1206 |
1199 // Check if button in toolbar was pressed | 1207 // Check if button in toolbar was pressed |
1200 int nIDCommand = -1; | 1208 int nIDCommand = -1; |
1201 BOOL bRightAlign = FALSE; | 1209 BOOL bRightAlign = FALSE; |
1202 | 1210 |
1203 POINT pt; | 1211 POINT pt; |
1204 GetCursorPos(&pt); | 1212 GetCursorPos(&pt); |
1205 | 1213 |
1206 HWND hWndToolBar = ::WindowFromPoint(pt); | 1214 HWND hWndToolBar = ::WindowFromPoint(pt); |
1207 | 1215 |
1208 DWORD nProcessId; | 1216 DWORD nProcessId; |
1209 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); | 1217 ::GetWindowThreadProcessId(hWndToolBar, &nProcessId); |
1210 | 1218 |
1211 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) | 1219 if (hWndToolBar && ::GetCurrentProcessId() == nProcessId) |
1212 { | 1220 { |
1213 ::ScreenToClient(hWndToolBar, &pt); | 1221 ::ScreenToClient(hWndToolBar, &pt); |
1214 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); | 1222 int nButton = (int)::SendMessage(hWndToolBar, TB_HITTEST, 0, (LPARAM)&pt); |
1215 | 1223 |
1216 if (nButton > 0) | 1224 if (nButton > 0) |
1217 { | 1225 { |
1218 TBBUTTON pTBBtn = {}; | 1226 TBBUTTON pTBBtn = {}; |
1219 | 1227 |
1220 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) | 1228 if (SendMessage(hWndToolBar, TB_GETBUTTON, nButton, (LPARAM)&pTBBtn)) |
1221 { | 1229 { |
1222 RECT rcButton; | 1230 RECT rcButton; |
1223 nIDCommand = pTBBtn.idCommand; | 1231 nIDCommand = pTBBtn.idCommand; |
1224 | 1232 |
1225 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton)) | 1233 if (SendMessage(hWndToolBar, TB_GETRECT, nIDCommand, (LPARAM)&rcButton )) |
1226 { | |
1227 pt.x = rcButton.left; | |
1228 pt.y = rcButton.bottom; | |
1229 ClientToScreen(hWndToolBar, &pt); | |
1230 | |
1231 RECT rcWorkArea; | |
1232 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1233 if (rcWorkArea.right - pt.x < 150) | |
1234 { | 1234 { |
1235 bRightAlign = TRUE; | 1235 pt.x = rcButton.left; |
1236 pt.x = rcButton.right; | |
1237 pt.y = rcButton.bottom; | 1236 pt.y = rcButton.bottom; |
1238 ClientToScreen(hWndToolBar, &pt); | 1237 ClientToScreen(hWndToolBar, &pt); |
1238 | |
1239 RECT rcWorkArea; | |
1240 SystemParametersInfo(SPI_GETWORKAREA, 0, (LPVOID)&rcWorkArea, 0); | |
1241 if (rcWorkArea.right - pt.x < 150) | |
1242 { | |
1243 bRightAlign = TRUE; | |
1244 pt.x = rcButton.right; | |
1245 pt.y = rcButton.bottom; | |
1246 ClientToScreen(hWndToolBar, &pt); | |
1247 } | |
1239 } | 1248 } |
1240 } | 1249 } |
1241 } | 1250 } |
1251 else | |
1252 { | |
1253 GetCursorPos(&pt); | |
1254 } | |
1255 } | |
1256 | |
1257 // Display menu | |
1258 UINT nFlags = 0; | |
1259 if (bRightAlign) | |
1260 { | |
1261 nFlags |= TPM_RIGHTALIGN; | |
1242 } | 1262 } |
1243 else | 1263 else |
1244 { | 1264 { |
1245 GetCursorPos(&pt); | 1265 nFlags |= TPM_LEFTALIGN; |
1246 } | 1266 } |
1267 | |
1268 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
1247 } | 1269 } |
1248 | 1270 catch (...) |
1249 // Display menu | |
1250 UINT nFlags = 0; | |
1251 if (bRightAlign) | |
1252 { | 1271 { |
1253 nFlags |= TPM_RIGHTALIGN; | 1272 return E_FAIL; // Suppress exceptions, should log |
Oleksandr
2016/01/05 02:06:38
Not really following the comment. Does this mean t
Eric
2016/01/05 15:59:43
The only logging we have is in Debug builds. I wou
| |
1254 } | 1273 } |
1255 else | |
1256 { | |
1257 nFlags |= TPM_LEFTALIGN; | |
1258 } | |
1259 | |
1260 DisplayPluginMenu(hMenu, nIDCommand, pt, nFlags); | |
1261 | 1274 |
1262 return S_OK; | 1275 return S_OK; |
1263 } | 1276 } |
1264 | 1277 |
1265 ///////////////////////////////////////////////////////////////////////////// | 1278 // Entry point |
1266 // Window procedures | |
1267 | |
1268 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) | 1279 LRESULT CALLBACK CPluginClass::NewStatusProc(HWND hWnd, UINT message, WPARAM wPa ram, LPARAM lParam) |
1269 { | 1280 { |
1270 // Find tab | 1281 CPluginClass *pClass; |
1271 CPluginClass *pClass = FindInstance(hWnd); | 1282 try |
1272 if (!pClass) | |
1273 { | 1283 { |
1274 return DefWindowProc(hWnd, message, wParam, lParam); | 1284 // Find tab |
1275 } | 1285 pClass = FindInstance(hWnd); |
1286 if (!pClass) | |
1287 { | |
1288 /* | |
1289 * Race condition if reached. | |
1290 * We did not unhook the window procedure for the status bar when the last BHO instance using it terminated. | |
1291 * The next best thing is to call the system default window function. | |
1292 */ | |
1293 return DefWindowProc(hWnd, message, wParam, lParam); | |
1294 } | |
1276 | 1295 |
1277 // Process message | 1296 // Process message |
1278 switch (message) | 1297 switch (message) |
1279 { | |
1280 case SB_SIMPLE: | |
1281 { | 1298 { |
1282 ShowWindow(pClass->m_hPaneWnd, !wParam); | 1299 case SB_SIMPLE: |
1300 { | |
1301 ShowWindow(pClass->m_hPaneWnd, !wParam); | |
1302 break; | |
1303 } | |
1304 | |
1305 case WM_SYSCOLORCHANGE: | |
1306 { | |
1307 pClass->UpdateTheme(); | |
1308 break; | |
1309 } | |
1310 | |
1311 case SB_SETPARTS: | |
1312 { | |
1313 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1314 { | |
1315 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam); | |
1316 } | |
1317 | |
1318 WPARAM nParts = wParam; | |
1319 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1320 { | |
1321 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lParam); | |
1322 } | |
1323 | |
1324 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts + 1)); | |
1325 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1326 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1327 | |
1328 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1329 { | |
1330 lpParts[i] -= pClass->m_nPaneWidth; | |
1331 } | |
1332 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, w Param, (LPARAM)lpParts); | |
1333 | |
1334 AdblockPlus::Rectangle rcPane; | |
1335 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1336 | |
1337 AdblockPlus::Rectangle rcClient; | |
1338 ::GetClientRect(hWnd, &rcClient); | |
1339 | |
1340 ::MoveWindow( | |
1341 pClass->m_hPaneWnd, | |
1342 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1343 0, | |
1344 pClass->m_nPaneWidth, | |
1345 rcClient.Height(), | |
1346 TRUE); | |
1347 | |
1348 ::LocalFree(hLocal); | |
1349 return hRet; | |
1350 } | |
1351 | |
1352 default: | |
1283 break; | 1353 break; |
1284 } | 1354 } |
1285 | |
1286 case WM_SYSCOLORCHANGE: | |
1287 { | |
1288 pClass->UpdateTheme(); | |
1289 break; | |
1290 } | |
1291 | |
1292 case SB_SETPARTS: | |
1293 { | |
1294 if (!lParam || !wParam || wParam > 30 || !IsWindow(pClass->m_hPaneWnd)) | |
1295 { | |
1296 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param); | |
1297 } | |
1298 | |
1299 WPARAM nParts = wParam; | |
1300 if (STATUSBAR_PANE_NUMBER >= nParts) | |
1301 { | |
1302 return CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, l Param); | |
1303 } | |
1304 | |
1305 HLOCAL hLocal = LocalAlloc(LHND, sizeof(int) * (nParts+1)); | |
1306 LPINT lpParts = (LPINT)LocalLock(hLocal); | |
1307 memcpy(lpParts, (void*)lParam, wParam*sizeof(int)); | |
1308 | |
1309 for (unsigned i = 0; i < STATUSBAR_PANE_NUMBER; i++) | |
1310 { | |
1311 lpParts[i] -= pClass->m_nPaneWidth; | |
1312 } | |
1313 LRESULT hRet = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPa ram, (LPARAM)lpParts); | |
1314 | |
1315 AdblockPlus::Rectangle rcPane; | |
1316 ::SendMessage(hWnd, SB_GETRECT, STATUSBAR_PANE_NUMBER, (LPARAM)&rcPane); | |
1317 | |
1318 AdblockPlus::Rectangle rcClient; | |
1319 ::GetClientRect(hWnd, &rcClient); | |
1320 | |
1321 ::MoveWindow( | |
1322 pClass->m_hPaneWnd, | |
1323 lpParts[STATUSBAR_PANE_NUMBER] - pClass->m_nPaneWidth, | |
1324 0, | |
1325 pClass->m_nPaneWidth, | |
1326 rcClient.Height(), | |
1327 TRUE); | |
1328 | |
1329 ::LocalFree(hLocal); | |
1330 | |
1331 | |
1332 return hRet; | |
1333 } | |
1334 | |
1335 default: | |
1336 break; | |
1337 } | 1355 } |
1338 | 1356 catch (...) |
1339 LRESULT result = CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wPara m, lParam); | 1357 { |
1340 | 1358 // Suppress exception. Fall through to default handler. |
Oleksandr
2016/01/05 02:06:38
Empty catch blocks always look awry to me. Maybe w
| |
1341 | 1359 } |
1342 return result; | 1360 return ::CallWindowProc(pClass->m_pWndProcStatus, hWnd, message, wParam, lPara m); |
1343 | |
1344 } | 1361 } |
1345 | 1362 |
1346 | 1363 |
1347 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) | 1364 HICON CPluginClass::GetStatusBarIcon(const std::wstring& url) |
1348 { | 1365 { |
1349 // use the disable icon as defualt, if the client doesn't exists | 1366 // use the disable icon as defualt, if the client doesn't exists |
1350 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); | 1367 HICON hIcon = GetIcon(ICON_PLUGIN_DEACTIVATED); |
1351 | 1368 |
1352 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | 1369 CPluginTab* tab = GetTab(::GetCurrentThreadId()); |
1353 if (tab) | 1370 if (tab) |
1354 { | 1371 { |
1355 CPluginClient* client = CPluginClient::GetInstance(); | 1372 CPluginClient* client = CPluginClient::GetInstance(); |
1356 if (CPluginSettings::GetInstance()->IsPluginEnabled()) | 1373 if (CPluginSettings::GetInstance()->IsPluginEnabled()) |
1357 { | 1374 { |
1358 if (client->IsWhitelistedUrl(url)) | 1375 if (client->IsWhitelistedUrl(url)) |
1359 { | 1376 { |
1360 hIcon = GetIcon(ICON_PLUGIN_DISABLED); | 1377 hIcon = GetIcon(ICON_PLUGIN_DISABLED); |
1361 } | 1378 } |
1362 else | 1379 else |
1363 { | 1380 { |
1364 CPluginSettings* settings = CPluginSettings::GetInstance(); | 1381 CPluginSettings* settings = CPluginSettings::GetInstance(); |
1365 hIcon = GetIcon(ICON_PLUGIN_ENABLED); | 1382 hIcon = GetIcon(ICON_PLUGIN_ENABLED); |
1366 } | 1383 } |
1367 } | 1384 } |
1368 } | 1385 } |
1369 return hIcon; | 1386 return hIcon; |
1370 } | 1387 } |
1371 | 1388 |
1372 | 1389 // Entry point |
1373 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) | 1390 LRESULT CALLBACK CPluginClass::PaneWindowProc(HWND hWnd, UINT message, WPARAM wP aram, LPARAM lParam) |
1374 { | 1391 { |
1375 // Find tab | 1392 try |
1376 CPluginClass *pClass = FindInstance(GetParent(hWnd)); | |
1377 if (!pClass) | |
1378 { | 1393 { |
1379 return ::DefWindowProc(hWnd, message, wParam, lParam); | 1394 // Find tab |
1380 } | 1395 CPluginClass *pClass = FindInstance(GetParent(hWnd)); |
1381 | 1396 if (!pClass) |
1382 // Process message | |
1383 switch (message) | |
1384 { | |
1385 | |
1386 case WM_SETCURSOR: | |
1387 { | 1397 { |
1388 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); | 1398 return ::DefWindowProc(hWnd, message, wParam, lParam); |
1389 return TRUE; | |
1390 } | 1399 } |
1391 case WM_PAINT: | 1400 |
1401 // Process message | |
1402 switch (message) | |
1392 { | 1403 { |
1393 PAINTSTRUCT ps; | 1404 case WM_SETCURSOR: |
1394 HDC hDC = ::BeginPaint(hWnd, &ps); | 1405 { |
1395 | 1406 ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); |
1396 AdblockPlus::Rectangle rcClient; | 1407 return TRUE; |
1397 ::GetClientRect(hWnd, &rcClient); | 1408 } |
1398 | 1409 case WM_PAINT: |
1399 int nDrawEdge = 0; | 1410 { |
1400 | 1411 PAINTSTRUCT ps; |
1401 // Old Windows background drawing | 1412 HDC hDC = ::BeginPaint(hWnd, &ps); |
1402 if (pClass->m_hTheme == NULL) | 1413 |
1403 { | 1414 AdblockPlus::Rectangle rcClient; |
1404 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); | 1415 ::GetClientRect(hWnd, &rcClient); |
1405 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); | 1416 |
1406 | 1417 int nDrawEdge = 0; |
1407 nDrawEdge = 3; | 1418 |
1408 rcClient.left += 3; | 1419 // Old Windows background drawing |
1409 | 1420 if (pClass->m_hTheme == NULL) |
1410 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); | 1421 { |
1411 } | 1422 ::FillRect(hDC, &rcClient, (HBRUSH)(COLOR_BTNFACE + 1)); |
1412 // Themed background drawing | 1423 ::DrawEdge(hDC, &rcClient, BDR_RAISEDINNER, BF_LEFT); |
1413 else | 1424 |
1414 { | 1425 nDrawEdge = 3; |
1415 // Draw background | 1426 rcClient.left += 3; |
1416 if (pfnDrawThemeBackground) | 1427 |
1417 { | 1428 ::DrawEdge(hDC, &rcClient, BDR_SUNKENOUTER, BF_RECT); |
1418 AdblockPlus::Rectangle rc = rcClient; | 1429 } |
1419 rc.right -= 2; | 1430 // Themed background drawing |
1420 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); | 1431 else |
1421 } | 1432 { |
1422 | 1433 // Draw background |
1423 // Copy separator picture to left side | 1434 if (pfnDrawThemeBackground) |
1424 int nHeight = rcClient.Height(); | |
1425 int nWidth = rcClient.Width() - 2; | |
1426 | |
1427 for (int i = 0; i < 2; i++) | |
1428 { | |
1429 for (int j = 0; j < nHeight; j++) | |
1430 { | 1435 { |
1431 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); | 1436 AdblockPlus::Rectangle rc = rcClient; |
1432 | 1437 rc.right -= 2; |
1433 // Ignore black boxes (if source is obscured by other windows) | 1438 pfnDrawThemeBackground(pClass->m_hTheme, hDC, 0, 0, &rc, NULL); |
1434 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetBVa lue(clr) > 8)) | 1439 } |
1440 | |
1441 // Copy separator picture to left side | |
1442 int nHeight = rcClient.Height(); | |
1443 int nWidth = rcClient.Width() - 2; | |
1444 | |
1445 for (int i = 0; i < 2; i++) | |
1446 { | |
1447 for (int j = 0; j < nHeight; j++) | |
1435 { | 1448 { |
1436 ::SetPixel(hDC, i, j, clr); | 1449 COLORREF clr = ::GetPixel(hDC, i + nWidth, j); |
1450 | |
1451 // Ignore black boxes (if source is obscured by other windows) | |
1452 if (clr != -1 && (GetRValue(clr) > 8 || GetGValue(clr) > 8 || GetB Value(clr) > 8)) | |
1453 { | |
1454 ::SetPixel(hDC, i, j, clr); | |
1455 } | |
1437 } | 1456 } |
1438 } | 1457 } |
1439 } | 1458 } |
1440 } | 1459 |
1441 | 1460 // Draw icon |
1442 // Draw icon | 1461 if (CPluginClient::GetInstance()) |
1443 if (CPluginClient::GetInstance()) | 1462 { |
1444 { | 1463 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); |
1445 HICON hIcon = GetStatusBarIcon(pClass->GetTab()->GetDocumentUrl()); | 1464 |
1446 | 1465 int offx = nDrawEdge; |
1447 int offx = nDrawEdge; | 1466 if (hIcon) |
1448 if (hIcon) | 1467 { |
1449 { | 1468 //Get the RECT for the leftmost pane (the status text pane) |
1450 //Get the RECT for the leftmost pane (the status text pane) | 1469 RECT rect; |
1470 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, (LPARAM)&rect); | |
1471 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, ico nWidth, iconHeight, NULL, NULL, DI_NORMAL); | |
1472 offx += iconWidth; | |
1473 } | |
1474 #ifdef _DEBUG | |
1475 // Display version | |
1476 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT , 0, 0); | |
1477 HGDIOBJ hOldFont = ::SelectObject(hDC, hFont); | |
1478 | |
1479 AdblockPlus::Rectangle rcText = rcClient; | |
1480 rcText.left += offx; | |
1481 ::SetBkMode(hDC, TRANSPARENT); | |
1482 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS | DT_ LEFT | DT_SINGLELINE | DT_VCENTER); | |
1483 | |
1484 ::SelectObject(hDC, hOldFont); | |
1485 #endif // _DEBUG | |
1486 } | |
1487 | |
1488 // Done! | |
1489 EndPaint(hWnd, &ps); | |
1490 | |
1491 return 0; | |
1492 } | |
1493 | |
1494 case WM_LBUTTONUP: | |
1495 case WM_RBUTTONUP: | |
1496 { | |
1497 std::wstring url = pClass->GetBrowserUrl(); | |
1498 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1499 { | |
1500 pClass->GetTab()->SetDocumentUrl(url); | |
1501 } | |
1502 | |
1503 // Create menu | |
1504 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1505 if (!hMenu) | |
1506 { | |
1507 return 0; | |
1508 } | |
1509 | |
1510 // Display menu | |
1511 POINT pt; | |
1512 ::GetCursorPos(&pt); | |
1513 | |
1514 RECT rc; | |
1515 ::GetWindowRect(hWnd, &rc); | |
1516 | |
1517 if (rc.left >= 0 && rc.top >= 0) | |
1518 { | |
1519 pt.x = rc.left; | |
1520 pt.y = rc.top; | |
1521 } | |
1522 | |
1523 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN | TPM_BOTTOMALIGN ); | |
1524 break; | |
1525 } | |
1526 case WM_DESTROY: | |
1527 break; | |
1528 case SC_CLOSE: | |
1529 break; | |
1530 | |
1531 case WM_UPDATEUISTATE: | |
1532 { | |
1533 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | |
1534 if (tab) | |
1535 { | |
1536 tab->OnActivate(); | |
1451 RECT rect; | 1537 RECT rect; |
1452 BOOL rectRes = ::SendMessage(pClass->m_hStatusBarWnd, SB_GETRECT, 0, ( LPARAM)&rect); | 1538 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1453 ::DrawIconEx(hDC, 0, rect.bottom - rect.top - iconHeight, hIcon, iconW idth, iconHeight, NULL, NULL, DI_NORMAL); | 1539 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); |
1454 offx += iconWidth; | 1540 } |
1455 } | 1541 if (LOWORD(wParam) == UIS_CLEAR) |
1456 #ifdef _DEBUG | 1542 { |
1457 // Display version | 1543 pClass->notificationMessage.Hide(); |
1458 HFONT hFont = (HFONT)::SendMessage(pClass->m_hStatusBarWnd, WM_GETFONT, 0, 0); | 1544 } |
1459 HGDIOBJ hOldFont = ::SelectObject(hDC,hFont); | 1545 break; |
1460 | 1546 } |
1461 AdblockPlus::Rectangle rcText = rcClient; | 1547 case WM_WINDOWPOSCHANGING: |
1462 rcText.left += offx; | 1548 { |
1463 ::SetBkMode(hDC, TRANSPARENT); | |
1464 ::DrawTextW(hDC, IEPLUGIN_VERSION, -1, &rcText, DT_WORD_ELLIPSIS|DT_LEFT |DT_SINGLELINE|DT_VCENTER); | |
1465 | |
1466 ::SelectObject(hDC, hOldFont); | |
1467 #endif // _DEBUG | |
1468 } | |
1469 | |
1470 // Done! | |
1471 EndPaint(hWnd, &ps); | |
1472 | |
1473 return 0; | |
1474 } | |
1475 | |
1476 case WM_LBUTTONUP: | |
1477 case WM_RBUTTONUP: | |
1478 { | |
1479 std::wstring url = pClass->GetBrowserUrl(); | |
1480 if (url != pClass->GetTab()->GetDocumentUrl()) | |
1481 { | |
1482 pClass->GetTab()->SetDocumentUrl(url); | |
1483 } | |
1484 | |
1485 // Create menu | |
1486 HMENU hMenu = pClass->CreatePluginMenu(url); | |
1487 if (!hMenu) | |
1488 { | |
1489 return 0; | |
1490 } | |
1491 | |
1492 // Display menu | |
1493 POINT pt; | |
1494 ::GetCursorPos(&pt); | |
1495 | |
1496 RECT rc; | |
1497 ::GetWindowRect(hWnd, &rc); | |
1498 | |
1499 if (rc.left >= 0 && rc.top >= 0) | |
1500 { | |
1501 pt.x = rc.left; | |
1502 pt.y = rc.top; | |
1503 } | |
1504 | |
1505 pClass->DisplayPluginMenu(hMenu, -1, pt, TPM_LEFTALIGN|TPM_BOTTOMALIGN); | |
1506 } | |
1507 break; | |
1508 case WM_DESTROY: | |
1509 break; | |
1510 case SC_CLOSE: | |
1511 break; | |
1512 | |
1513 case WM_UPDATEUISTATE: | |
1514 { | |
1515 CPluginTab* tab = GetTab(::GetCurrentThreadId()); | |
1516 if (tab) | |
1517 { | |
1518 tab->OnActivate(); | |
1519 RECT rect; | 1549 RECT rect; |
1520 GetWindowRect(pClass->m_hPaneWnd, &rect); | 1550 GetWindowRect(pClass->m_hPaneWnd, &rect); |
1521 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); | 1551 if (pClass->notificationMessage.IsVisible()) |
1522 } | 1552 { |
1523 if (LOWORD(wParam) == UIS_CLEAR) | 1553 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); |
1524 { | 1554 } |
1525 pClass->notificationMessage.Hide(); | 1555 break; |
1556 } | |
1557 case WM_WINDOWPOSCHANGED: | |
1558 { | |
1559 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | |
1560 if (wndPos->flags & SWP_HIDEWINDOW) | |
1561 { | |
1562 pClass->notificationMessage.Hide(); | |
1563 } | |
1564 break; | |
1565 } | |
1566 case WM_ALREADY_UP_TO_DATE: | |
1567 { | |
1568 Dictionary* dictionary = Dictionary::GetInstance(); | |
1569 std::wstring upToDateText = dictionary->Lookup("updater", "update-alread y-up-to-date-text"); | |
1570 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-alrea dy-up-to-date-title"); | |
1571 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TTI_INFO); | |
1572 break; | |
1573 } | |
1574 case WM_UPDATE_CHECK_ERROR: | |
1575 { | |
1576 Dictionary* dictionary = Dictionary::GetInstance(); | |
1577 std::wstring errorText = dictionary->Lookup("updater", "update-error-tex t"); | |
1578 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-ti tle"); | |
1579 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERR OR); | |
1580 break; | |
1581 } | |
1582 case WM_DOWNLOADING_UPDATE: | |
1583 { | |
1584 Dictionary* dictionary = Dictionary::GetInstance(); | |
1585 std::wstring downloadingText = dictionary->Lookup("updater", "downloadin g-update-text"); | |
1586 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloadi ng-update-title"); | |
1587 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingT itle, TTI_INFO); | |
1588 break; | |
1526 } | 1589 } |
1527 } | 1590 } |
1528 break; | |
1529 case WM_WINDOWPOSCHANGING: | |
1530 { | |
1531 RECT rect; | |
1532 GetWindowRect(pClass->m_hPaneWnd, &rect); | |
1533 if (pClass->notificationMessage.IsVisible()) | |
1534 { | |
1535 pClass->notificationMessage.Move(rect.left + (rect.right - rect.left) / 2, rect.top + (rect.bottom - rect.top) / 2); | |
1536 } | |
1537 } | |
1538 break; | |
1539 case WM_WINDOWPOSCHANGED: | |
1540 { | |
1541 WINDOWPOS* wndPos = reinterpret_cast<WINDOWPOS*>(lParam); | |
1542 if (wndPos->flags & SWP_HIDEWINDOW) | |
1543 { | |
1544 pClass->notificationMessage.Hide(); | |
1545 } | |
1546 } | |
1547 break; | |
1548 case WM_ALREADY_UP_TO_DATE: | |
1549 { | |
1550 Dictionary* dictionary = Dictionary::GetInstance(); | |
1551 std::wstring upToDateText = dictionary->Lookup("updater", "update-already- up-to-date-text"); | |
1552 std::wstring upToDateTitle = dictionary->Lookup("updater", "update-already -up-to-date-title"); | |
1553 pClass->notificationMessage.SetTextAndIcon(upToDateText, upToDateTitle, TT I_INFO); | |
1554 } | |
1555 break; | |
1556 case WM_UPDATE_CHECK_ERROR: | |
1557 { | |
1558 Dictionary* dictionary = Dictionary::GetInstance(); | |
1559 std::wstring errorText = dictionary->Lookup("updater", "update-error-text" ); | |
1560 std::wstring errorTitle = dictionary->Lookup("updater", "update-error-titl e"); | |
1561 pClass->notificationMessage.SetTextAndIcon(errorText, errorText, TTI_ERROR ); | |
1562 } | |
1563 break; | |
1564 case WM_DOWNLOADING_UPDATE: | |
1565 { | |
1566 Dictionary* dictionary = Dictionary::GetInstance(); | |
1567 std::wstring downloadingText = dictionary->Lookup("updater", "downloading- update-text"); | |
1568 std::wstring downloadingTitle = dictionary->Lookup("updater", "downloading -update-title"); | |
1569 pClass->notificationMessage.SetTextAndIcon(downloadingText, downloadingTit le, TTI_INFO); | |
1570 } | |
1571 break; | |
1572 } | 1591 } |
1573 | 1592 catch (...) |
1574 return DefWindowProc(hWnd, message, wParam, lParam); | 1593 { |
1594 // Suppress exception. Fall through to default handler. | |
1595 } | |
1596 return ::DefWindowProc(hWnd, message, wParam, lParam); | |
1575 } | 1597 } |
1576 | 1598 |
1577 | 1599 |
1578 void CPluginClass::UpdateStatusBar() | 1600 void CPluginClass::UpdateStatusBar() |
1579 { | 1601 { |
1580 DEBUG_GENERAL("*** Updating statusbar") | 1602 DEBUG_GENERAL("*** Updating statusbar") |
1581 if (m_hPaneWnd == NULL) | 1603 if (m_hPaneWnd == NULL) |
1582 { | 1604 { |
1583 CreateStatusBarPane(); | 1605 CreateStatusBarPane(); |
1584 } | 1606 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1633 s_criticalSectionLocal.Unlock(); | 1655 s_criticalSectionLocal.Unlock(); |
1634 | 1656 |
1635 return icon; | 1657 return icon; |
1636 } | 1658 } |
1637 | 1659 |
1638 ATOM CPluginClass::GetAtomPaneClass() | 1660 ATOM CPluginClass::GetAtomPaneClass() |
1639 { | 1661 { |
1640 return s_atomPaneClass; | 1662 return s_atomPaneClass; |
1641 } | 1663 } |
1642 | 1664 |
OLD | NEW |