From 5ee22707c2e2e264c9e7dd0ae4d17197782eee06 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Wed, 24 Feb 2010 06:08:26 +0000 Subject: Avoid casting warnings from GCC. --- win32/PlatWin.cxx | 66 ++++++++++++++++++++++++++--------------- win32/ScintillaWin.cxx | 80 ++++++++++++++++++++++++++------------------------ 2 files changed, 83 insertions(+), 63 deletions(-) diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 71a968541..65e05f9db 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -617,6 +617,18 @@ static void AllFour(DWORD *pixels, int width, int height, int x, int y, DWORD va #define AC_SRC_ALPHA 0x01 #endif +static DWORD dwordFromBGRA(byte b, byte g, byte r, byte a) { + union { + byte pixVal[4]; + DWORD val; + } converter; + converter.pixVal[0] = b; + converter.pixVal[1] = g; + converter.pixVal[2] = r; + converter.pixVal[3] = a; + return converter.val; +} + void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated fill, int alphaFill, ColourAllocated outline, int alphaOutline, int /* flags*/ ) { if (AlphaBlendFn && rc.Width() > 0) { @@ -632,18 +644,17 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, ColourAllocated HBITMAP hbmOld = SelectBitmap(hMemDC, hbmMem); - byte pixVal[4] = {0}; - DWORD valEmpty = *(reinterpret_cast(pixVal)); - pixVal[0] = static_cast(GetBValue(fill.AsLong()) * alphaFill / 255); - pixVal[1] = static_cast(GetGValue(fill.AsLong()) * alphaFill / 255); - pixVal[2] = static_cast(GetRValue(fill.AsLong()) * alphaFill / 255); - pixVal[3] = static_cast(alphaFill); - DWORD valFill = *(reinterpret_cast(pixVal)); - pixVal[0] = static_cast(GetBValue(outline.AsLong()) * alphaOutline / 255); - pixVal[1] = static_cast(GetGValue(outline.AsLong()) * alphaOutline / 255); - pixVal[2] = static_cast(GetRValue(outline.AsLong()) * alphaOutline / 255); - pixVal[3] = static_cast(alphaOutline); - DWORD valOutline = *(reinterpret_cast(pixVal)); + DWORD valEmpty = dwordFromBGRA(0,0,0,0); + DWORD valFill = dwordFromBGRA( + static_cast(GetBValue(fill.AsLong()) * alphaFill / 255), + static_cast(GetGValue(fill.AsLong()) * alphaFill / 255), + static_cast(GetRValue(fill.AsLong()) * alphaFill / 255), + static_cast(alphaFill)); + DWORD valOutline = dwordFromBGRA( + static_cast(GetBValue(outline.AsLong()) * alphaOutline / 255), + static_cast(GetGValue(outline.AsLong()) * alphaOutline / 255), + static_cast(GetRValue(outline.AsLong()) * alphaOutline / 255), + static_cast(alphaOutline)); DWORD *pixels = reinterpret_cast(image); for (int y=0; y(lParam); - *reinterpret_cast(&minMax->ptMaxTrackSize) = MaxTrackSize(); - *reinterpret_cast(&minMax->ptMinTrackSize) = MinTrackSize(); + minMax->ptMaxTrackSize = MaxTrackSize(); + minMax->ptMinTrackSize = MinTrackSize(); } break; @@ -2115,8 +2128,13 @@ public: // Use GetProcAddress to get a pointer to the relevant function. virtual Function FindFunction(const char *name) { if (h != NULL) { - return static_cast( - (void *)(::GetProcAddress(h, name))); + // C++ standard doesn't like casts betwen function pointers and void pointers so use a union + union { + FARPROC fp; + Function f; + } fnConv; + fnConv.fp = ::GetProcAddress(h, name); + return fnConv.f; } else return NULL; } diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 8cdf00507..3e83990b1 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -106,11 +106,13 @@ using namespace Scintilla; class ScintillaWin; // Forward declaration for COM interface subobjects +typedef void VFunction(void); + /** */ class FormatEnumerator { public: - void **vtbl; + VFunction **vtbl; int ref; int pos; CLIPFORMAT formats[2]; @@ -122,7 +124,7 @@ public: */ class DropSource { public: - void **vtbl; + VFunction **vtbl; ScintillaWin *sci; DropSource(); }; @@ -131,7 +133,7 @@ public: */ class DataObject { public: - void **vtbl; + VFunction **vtbl; ScintillaWin *sci; DataObject(); }; @@ -140,7 +142,7 @@ public: */ class DropTarget { public: - void **vtbl; + VFunction **vtbl; ScintillaWin *sci; DropTarget(); }; @@ -1584,14 +1586,14 @@ STDMETHODIMP FormatEnumerator_Clone(FormatEnumerator *fe, IEnumFORMATETC **ppenu reinterpret_cast(ppenum)); } -static void *vtFormatEnumerator[] = { - (void *)(FormatEnumerator_QueryInterface), - (void *)(FormatEnumerator_AddRef), - (void *)(FormatEnumerator_Release), - (void *)(FormatEnumerator_Next), - (void *)(FormatEnumerator_Skip), - (void *)(FormatEnumerator_Reset), - (void *)(FormatEnumerator_Clone) +static VFunction *vtFormatEnumerator[] = { + (VFunction *)(FormatEnumerator_QueryInterface), + (VFunction *)(FormatEnumerator_AddRef), + (VFunction *)(FormatEnumerator_Release), + (VFunction *)(FormatEnumerator_Next), + (VFunction *)(FormatEnumerator_Skip), + (VFunction *)(FormatEnumerator_Reset), + (VFunction *)(FormatEnumerator_Clone) }; FormatEnumerator::FormatEnumerator(int pos_, CLIPFORMAT formats_[], int formatsLen_) { @@ -1627,12 +1629,12 @@ STDMETHODIMP DropSource_GiveFeedback(DropSource *, DWORD) { return DRAGDROP_S_USEDEFAULTCURSORS; } -static void *vtDropSource[] = { - (void *)(DropSource_QueryInterface), - (void *)(DropSource_AddRef), - (void *)(DropSource_Release), - (void *)(DropSource_QueryContinueDrag), - (void *)(DropSource_GiveFeedback) +static VFunction *vtDropSource[] = { + (VFunction *)(DropSource_QueryInterface), + (VFunction *)(DropSource_AddRef), + (VFunction *)(DropSource_Release), + (VFunction *)(DropSource_QueryContinueDrag), + (VFunction *)(DropSource_GiveFeedback) }; DropSource::DropSource() { @@ -1746,19 +1748,19 @@ STDMETHODIMP DataObject_EnumDAdvise(DataObject *, IEnumSTATDATA **) { return E_FAIL; } -static void *vtDataObject[] = { - (void *)(DataObject_QueryInterface), - (void *)(DataObject_AddRef), - (void *)(DataObject_Release), - (void *)(DataObject_GetData), - (void *)(DataObject_GetDataHere), - (void *)(DataObject_QueryGetData), - (void *)(DataObject_GetCanonicalFormatEtc), - (void *)(DataObject_SetData), - (void *)(DataObject_EnumFormatEtc), - (void *)(DataObject_DAdvise), - (void *)(DataObject_DUnadvise), - (void *)(DataObject_EnumDAdvise) +static VFunction *vtDataObject[] = { + (VFunction *)(DataObject_QueryInterface), + (VFunction *)(DataObject_AddRef), + (VFunction *)(DataObject_Release), + (VFunction *)(DataObject_GetData), + (VFunction *)(DataObject_GetDataHere), + (VFunction *)(DataObject_QueryGetData), + (VFunction *)(DataObject_GetCanonicalFormatEtc), + (VFunction *)(DataObject_SetData), + (VFunction *)(DataObject_EnumFormatEtc), + (VFunction *)(DataObject_DAdvise), + (VFunction *)(DataObject_DUnadvise), + (VFunction *)(DataObject_EnumDAdvise) }; DataObject::DataObject() { @@ -1814,14 +1816,14 @@ STDMETHODIMP DropTarget_Drop(DropTarget *dt, LPDATAOBJECT pIDataSource, DWORD gr return E_FAIL; } -static void *vtDropTarget[] = { - (void *)(DropTarget_QueryInterface), - (void *)(DropTarget_AddRef), - (void *)(DropTarget_Release), - (void *)(DropTarget_DragEnter), - (void *)(DropTarget_DragOver), - (void *)(DropTarget_DragLeave), - (void *)(DropTarget_Drop) +static VFunction *vtDropTarget[] = { + (VFunction *)(DropTarget_QueryInterface), + (VFunction *)(DropTarget_AddRef), + (VFunction *)(DropTarget_Release), + (VFunction *)(DropTarget_DragEnter), + (VFunction *)(DropTarget_DragOver), + (VFunction *)(DropTarget_DragLeave), + (VFunction *)(DropTarget_Drop) }; DropTarget::DropTarget() { -- cgit v1.2.3