diff options
-rw-r--r-- | win32/PlatWin.cxx | 66 | ||||
-rw-r--r-- | 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<DWORD *>(pixVal)); - pixVal[0] = static_cast<byte>(GetBValue(fill.AsLong()) * alphaFill / 255); - pixVal[1] = static_cast<byte>(GetGValue(fill.AsLong()) * alphaFill / 255); - pixVal[2] = static_cast<byte>(GetRValue(fill.AsLong()) * alphaFill / 255); - pixVal[3] = static_cast<byte>(alphaFill); - DWORD valFill = *(reinterpret_cast<DWORD *>(pixVal)); - pixVal[0] = static_cast<byte>(GetBValue(outline.AsLong()) * alphaOutline / 255); - pixVal[1] = static_cast<byte>(GetGValue(outline.AsLong()) * alphaOutline / 255); - pixVal[2] = static_cast<byte>(GetRValue(outline.AsLong()) * alphaOutline / 255); - pixVal[3] = static_cast<byte>(alphaOutline); - DWORD valOutline = *(reinterpret_cast<DWORD *>(pixVal)); + DWORD valEmpty = dwordFromBGRA(0,0,0,0); + DWORD valFill = dwordFromBGRA( + static_cast<byte>(GetBValue(fill.AsLong()) * alphaFill / 255), + static_cast<byte>(GetGValue(fill.AsLong()) * alphaFill / 255), + static_cast<byte>(GetRValue(fill.AsLong()) * alphaFill / 255), + static_cast<byte>(alphaFill)); + DWORD valOutline = dwordFromBGRA( + static_cast<byte>(GetBValue(outline.AsLong()) * alphaOutline / 255), + static_cast<byte>(GetGValue(outline.AsLong()) * alphaOutline / 255), + static_cast<byte>(GetRValue(outline.AsLong()) * alphaOutline / 255), + static_cast<byte>(alphaOutline)); DWORD *pixels = reinterpret_cast<DWORD *>(image); for (int y=0; y<height; y++) { for (int x=0; x<width; x++) { @@ -1283,8 +1294,8 @@ class ListBoxX : public ListBox { int MinClientWidth() const; int TextOffset() const; Point GetClientExtent() const; - Point MinTrackSize() const; - Point MaxTrackSize() const; + POINT MinTrackSize() const; + POINT MaxTrackSize() const; void SetRedraw(bool on); void OnDoubleClick(); void ResizeToCursor(); @@ -1630,19 +1641,21 @@ int ListBoxX::MinClientWidth() const { return 12 * (aveCharWidth+aveCharWidth/3); } -Point ListBoxX::MinTrackSize() const { +POINT ListBoxX::MinTrackSize() const { PRectangle rc(0, 0, MinClientWidth(), ItemHeight()); AdjustWindowRect(&rc); - return Point(rc.Width(), rc.Height()); + POINT ret = {rc.Width(), rc.Height()}; + return ret; } -Point ListBoxX::MaxTrackSize() const { +POINT ListBoxX::MaxTrackSize() const { PRectangle rc(0, 0, maxCharWidth * maxItemCharacters + TextInset.x * 2 + TextOffset() + ::GetSystemMetrics(SM_CXVSCROLL), ItemHeight() * lti.Count()); AdjustWindowRect(&rc); - return Point(rc.Width(), rc.Height()); + POINT ret = {rc.Width(), rc.Height()}; + return ret; } void ListBoxX::SetRedraw(bool on) { @@ -1689,8 +1702,8 @@ void ListBoxX::ResizeToCursor() { break; } - Point ptMin = MinTrackSize(); - Point ptMax = MaxTrackSize(); + POINT ptMin = MinTrackSize(); + POINT ptMax = MaxTrackSize(); // We don't allow the left edge to move at present, but just in case rc.left = Platform::Maximum(Platform::Minimum(rc.left, rcPreSize.right - ptMin.x), rcPreSize.right - ptMax.x); rc.top = Platform::Maximum(Platform::Minimum(rc.top, rcPreSize.bottom - ptMin.y), rcPreSize.bottom - ptMax.y); @@ -1950,8 +1963,8 @@ LRESULT ListBoxX::WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam case WM_GETMINMAXINFO: { MINMAXINFO *minMax = reinterpret_cast<MINMAXINFO*>(lParam); - *reinterpret_cast<Point*>(&minMax->ptMaxTrackSize) = MaxTrackSize(); - *reinterpret_cast<Point*>(&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<Function>( - (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<void **>(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() { |