Address cpplint issue "Using C-style cast. Use reinterpret_cast<BYTE*>(...) instead [readability/casting] [4]"

This commit is contained in:
Ales Pergl 2017-04-05 11:53:37 +02:00
parent 91cff2e6c7
commit 9b7fbd4d22
4 changed files with 41 additions and 26 deletions

View file

@ -31,9 +31,11 @@ struct ScreenMetrics {
ScreenMetrics() { ScreenMetrics() {
typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*);
auto GetDpiForMonitor =
(GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>(
"GetDpiForMonitor"); GetProcAddress(GetModuleHandle(TEXT("shcore")),
"GetDpiForMonitor"));
if (GetDpiForMonitor) { if (GetDpiForMonitor) {
auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY);
if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK)

View file

@ -174,7 +174,9 @@ void DesktopNotificationController::AnimateAll() {
POINT origin = { workArea.right, POINT origin = { workArea.right,
workArea.bottom - metrics.Y(toast_margin_<int>) }; workArea.bottom - metrics.Y(toast_margin_<int>) };
auto hdwp = BeginDeferWindowPos((int)instances_.size()); auto hdwp =
BeginDeferWindowPos(static_cast<int>(instances_.size()));
for (auto&& inst : instances_) { for (auto&& inst : instances_) {
if (!inst.hwnd) continue; if (!inst.hwnd) continue;
@ -183,6 +185,7 @@ void DesktopNotificationController::AnimateAll() {
if (!hdwp) break; if (!hdwp) break;
keepAnimating |= notification->IsAnimationActive(); keepAnimating |= notification->IsAnimationActive();
} }
if (hdwp) EndDeferWindowPos(hdwp); if (hdwp) EndDeferWindowPos(hdwp);
} }
} }

View file

@ -24,7 +24,7 @@ static COLORREF GetAccentColor() {
DWORD type, size; DWORD type, size;
if (RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, if (RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr,
&type, &type,
(BYTE*)&color, reinterpret_cast<BYTE*>(&color),
&(size = sizeof(color))) == ERROR_SUCCESS && &(size = sizeof(color))) == ERROR_SUCCESS &&
type == REG_DWORD) { type == REG_DWORD) {
// convert from RGBA // convert from RGBA
@ -36,7 +36,7 @@ static COLORREF GetAccentColor() {
else if ( else if (
RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr,
&type, &type,
(BYTE*)&color, reinterpret_cast<BYTE*>(&color),
&(size = sizeof(color))) == ERROR_SUCCESS && &(size = sizeof(color))) == ERROR_SUCCESS &&
type == REG_DWORD) { type == REG_DWORD) {
// convert from BGRA // convert from BGRA
@ -82,26 +82,32 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) {
bmi.biCompression = BI_RGB; bmi.biCompression = BI_RGB;
void* alphaSrcBits; void* alphaSrcBits;
alphaSrcBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, alphaSrcBitmap = CreateDIBSection(NULL,
reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS, &alphaSrcBits, DIB_RGB_COLORS, &alphaSrcBits,
NULL, 0); NULL, 0);
if (alphaSrcBitmap) { if (alphaSrcBitmap) {
if (GetDIBits(hdcScreen, bitmap, 0, 0, 0, if (GetDIBits(hdcScreen, bitmap, 0, 0, 0,
(BITMAPINFO*)&bmi, DIB_RGB_COLORS) && reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS) &&
bmi.biSizeImage > 0 && bmi.biSizeImage > 0 &&
(bmi.biSizeImage % 4) == 0) { (bmi.biSizeImage % 4) == 0) {
auto buf = (BYTE*)_aligned_malloc(bmi.biSizeImage, auto buf = reinterpret_cast<BYTE*>(
sizeof(DWORD)); _aligned_malloc(bmi.biSizeImage, sizeof(DWORD)));
if (buf) { if (buf) {
GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf,
(BITMAPINFO*)&bmi, DIB_RGB_COLORS); reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS);
BYTE* dest = (BYTE*)alphaSrcBits; const DWORD *src = reinterpret_cast<DWORD*>(buf);
for (const DWORD *src = (DWORD*)buf, const DWORD *end =
*end = (DWORD*)(buf + bmi.biSizeImage); reinterpret_cast<DWORD*>(buf + bmi.biSizeImage);
src != end;
++src, ++dest) { BYTE* dest = reinterpret_cast<BYTE*>(alphaSrcBits);
for (; src != end; ++src, ++dest) {
BYTE a = *src >> 24; BYTE a = *src >> 24;
*dest++ = a; *dest++ = a;
*dest++ = a; *dest++ = a;
@ -123,12 +129,14 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) {
bmi.biCompression = BI_RGB; bmi.biCompression = BI_RGB;
void* colorBits; void* colorBits;
auto colorBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, auto colorBitmap = CreateDIBSection(NULL,
reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS, &colorBits, DIB_RGB_COLORS, &colorBits,
NULL, 0); NULL, 0);
void* alphaBits; void* alphaBits;
auto alphaBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, auto alphaBitmap = CreateDIBSection(NULL,
reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS, &alphaBits, DIB_RGB_COLORS, &alphaBits,
NULL, 0); NULL, 0);
@ -156,8 +164,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) {
GdiFlush(); GdiFlush();
// apply the alpha channel // apply the alpha channel
auto dest = (BYTE*)colorBits; auto dest = reinterpret_cast<BYTE*>(colorBits);
auto src = (const BYTE*)alphaBits; auto src = reinterpret_cast<const BYTE*>(alphaBits);
auto end = src + (width * height * 4); auto end = src + (width * height * 4);
while (src != end) { while (src != end) {
dest[3] = src[0]; dest[3] = src[0];
@ -167,7 +175,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) {
// create the resulting bitmap // create the resulting bitmap
resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT,
colorBits, (BITMAPINFO*)&bmi, colorBits,
reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS); DIB_RGB_COLORS);
} }
@ -657,8 +666,8 @@ void DesktopNotificationController::Toast::SetVerticalPosition(int y) {
return; return;
// Make sure the new animation's origin is at the current position // Make sure the new animation's origin is at the current position
vertical_pos_ += vertical_pos_ += static_cast<int>(
(int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); (vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_);
// Set new target position and start the animation // Set new target position and start the animation
vertical_pos_target_ = y; vertical_pos_target_ = y;
@ -699,11 +708,11 @@ HDWP DesktopNotificationController::Toast::Animate(
auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos; auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos;
size.cx = (int)(toast_size_.cx * easeInPos); size.cx = static_cast<int>(toast_size_.cx * easeInPos);
size.cy = toast_size_.cy; size.cy = toast_size_.cy;
pt.x = origin.x - size.cx; pt.x = origin.x - size.cx;
pt.y = (int)(origin.y - vertical_pos_ - yOffset - size.cy); pt.y = static_cast<int>(origin.y - vertical_pos_ - yOffset - size.cy);
ulw.pptDst = &pt; ulw.pptDst = &pt;
ulw.psize = &size; ulw.psize = &size;

View file

@ -27,7 +27,8 @@ void Win32Notification::Show(
HDC hdcScreen = GetDC(NULL); HDC hdcScreen = GetDC(NULL);
image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(),
(BITMAPINFO*)&bmi, DIB_RGB_COLORS); reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS);
ReleaseDC(NULL, hdcScreen); ReleaseDC(NULL, hdcScreen);
icon.unlockPixels(); icon.unlockPixels();