fix some MinGW compiling errors

This commit is contained in:
Jinhao 2015-05-03 17:38:58 +08:00
parent 766b9a1e24
commit ad0dcc0bcf
3 changed files with 34 additions and 49 deletions

View File

@ -550,7 +550,7 @@ namespace detail
::ScreenToClient(reinterpret_cast<HWND>(wd->root), &point);
arg.upwards = (pmdec.mouse.button.wheel_delta >= 0);
arg.distance = std::abs(pmdec.mouse.button.wheel_delta);
arg.distance = static_cast<unsigned>(arg.upwards ? pmdec.mouse.button.wheel_delta : -pmdec.mouse.button.wheel_delta);
arg.pos.x = static_cast<int>(point.x) - wd->pos_root.x;
arg.pos.y = static_cast<int>(point.y) - wd->pos_root.y;

View File

@ -23,6 +23,7 @@
#include <nana/internationalization.hpp>
#include <nana/gui/filebox.hpp>
#include <functional>
#include <cstdlib> //include std::abs
#if defined(NANA_WINDOWS)
#include <windows.h>
#elif defined(NANA_X11)

View File

@ -59,7 +59,6 @@ namespace nana{ namespace system{
HDC hDC = ::GetDC(NULL);
if (::GetDIBits(hDC, (HBITMAP)g.pixmap(), 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS) == 0) {
assert(false);
int err = ::GetLastError();
::ReleaseDC(NULL, hDC);
return false;
}
@ -72,41 +71,26 @@ namespace nana{ namespace system{
// Bitmaps are huge, so to avoid unnegligible extra copy, this routine does not use private _m_set method.
HGLOBAL h_gmem = ::GlobalAlloc(GHND | GMEM_SHARE, header_size + bitmap_bytes);
void * gmem = ::GlobalLock(h_gmem);
if (!gmem) {
assert(false);
goto Label_GlobalFree;
if (gmem) {
char* p = (char*)gmem;
// Fix BITMAPINFOHEADER obtained from GetDIBits WinAPI
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = ::abs(bmi.bmiHeader.biHeight);
memcpy(p, &bmi, header_size);
p += header_size;
// many programs do not support bottom-up DIB, so reversing row order is needed.
for (int y=0; y<bmi.bmiHeader.biHeight; ++y) {
memcpy(p, pbuffer.raw_ptr(bmi.bmiHeader.biHeight - 1 - y), bytes_per_line);
p += bytes_per_line;
}
if (::GlobalUnlock(h_gmem) || GetLastError() == NO_ERROR)
if (::OpenClipboard(::GetFocus()))
if (::EmptyClipboard())
if (::SetClipboardData(CF_DIB, h_gmem))
if (::CloseClipboard())
return true;
}
char* p = (char*)gmem;
// Fix BITMAPINFOHEADER obtained from GetDIBits WinAPI
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biHeight = ::abs(bmi.bmiHeader.biHeight);
memcpy(p, &bmi, header_size);
p += header_size;
// many programs do not support bottom-up DIB, so reversing row order is needed.
for (int y=0; y<bmi.bmiHeader.biHeight; ++y) {
memcpy(p, pbuffer.raw_ptr(bmi.bmiHeader.biHeight - 1 - y), bytes_per_line);
p += bytes_per_line;
}
if (!::GlobalUnlock(h_gmem) && GetLastError() != NO_ERROR) {
assert(false);
goto Label_GlobalFree;
}
if (!::OpenClipboard(::GetFocus())) {
goto Label_GlobalFree;
}
if (!::EmptyClipboard()) {
goto Label_GlobalFree;
}
if (!::SetClipboardData(CF_DIB, h_gmem)) {
goto Label_GlobalFree;
}
if (!::CloseClipboard()) {
// really?
return false;
}
return true;
Label_GlobalFree:
assert(false);
::GlobalFree(h_gmem);
return false;