X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2Fplat%2FWin32.cc;h=06c51954dd123d83729050bdb7c10c814a50e9cb;hb=c6069948906645d974f46bdb96617a9a6a504636;hp=195171b0d0b007e06193d88cfe33b5b73cdea628;hpb=08d17efa5da5c70c82b5eeef5e376e49c38d180f;p=org.ibex.core.git diff --git a/src/org/xwt/plat/Win32.cc b/src/org/xwt/plat/Win32.cc index 195171b..06c5195 100644 --- a/src/org/xwt/plat/Win32.cc +++ b/src/org/xwt/plat/Win32.cc @@ -1,4 +1,8 @@ // Copyright 2002 Adam Megacz, see the COPYING file for licensing [LGPL] +#include "GCJ.cc" + +// we have to do this because the jpeg libraries use the symbol 'INT32' +#define INT32 WIN32_INT32 // this has to precede the others so we don't get collisions on min/max #include @@ -20,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -28,7 +32,7 @@ #include #include #include -#include +#include #include #include #include @@ -236,6 +240,17 @@ void org::xwt::plat::Win32::natInit() { // Platform Methods /////////////////////////////////////////////////////////////////// +jstring org::xwt::plat::Win32::_getEnv(jstring key) { + int len = JvGetStringUTFLength(key); + char buf[len + 1]; + JvGetStringUTFRegion(key, 0, len, buf); + buf[len] = '\0'; + char buf2[1024]; + DWORD ret = GetEnvironmentVariable(buf, buf2, 1024); + if (ret > 0 && ret < 1024) return JvNewStringLatin1(buf2); + return NULL; +} + jstring org::xwt::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean write) { char buf[1024]; @@ -401,7 +416,7 @@ jboolean org::xwt::plat::Win32::_newBrowserWindow_(jstring url) { } -// Win32DoubleBuffer ///////////////////////////////////////////////////////////////////////// +// Win32PixelBuffer ///////////////////////////////////////////////////////////////////////// // This is a scratch area; when blitting a translucent image, we copy the underlying data here first. // Since all drawing operations are single-threaded, it's safe to use a global here. @@ -417,10 +432,9 @@ static jint scratch_h = 0; else \ StretchBlt(dest, dx1, dy1, dx2 - dx1, dy2 - dy1, src, sx1, sy1, sx2 - sx1, sy2 - sy1, op); -void org::xwt::plat::Win32$Win32DoubleBuffer::drawPicture(org::xwt::Picture* source0, +void org::xwt::plat::Win32$Win32PixelBuffer::drawPicture(org::xwt::Picture* source0, jint dx1, jint dy1, jint dx2, jint dy2, jint sx1, jint sy1, jint sx2, jint sy2) { - org::xwt::plat::Win32$Win32Picture* source = (org::xwt::plat::Win32$Win32Picture*)source0; if (source->hasalpha) { @@ -480,7 +494,7 @@ void org::xwt::plat::Win32$Win32DoubleBuffer::drawPicture(org::xwt::Picture* sou } -void org::xwt::plat::Win32$Win32DoubleBuffer::drawString(jstring font, jstring text, jint x, jint y, jint color) { +void org::xwt::plat::Win32$Win32PixelBuffer::drawString(jstring font, jstring text, jint x, jint y, jint color) { org::xwt::plat::Win32$Win32Font* wf = org::xwt::plat::Win32::getFont(font); SelectObject((HDC)hdc, (HFONT)(wf->hfont)); @@ -497,7 +511,7 @@ void org::xwt::plat::Win32$Win32DoubleBuffer::drawString(jstring font, jstring t TextOut((HDC)hdc, x, y, buf, len); } -void org::xwt::plat::Win32$Win32DoubleBuffer::fillRect(jint x, jint y, jint x2, jint y2, jint color) { +void org::xwt::plat::Win32$Win32PixelBuffer::fillRect(jint x, jint y, jint x2, jint y2, jint color) { jint w = x2 - x; jint h = y2 - y; @@ -509,25 +523,27 @@ void org::xwt::plat::Win32$Win32DoubleBuffer::fillRect(jint x, jint y, jint x2, DeleteObject(brush); } -void org::xwt::plat::Win32$Win32Surface::blit(org::xwt::DoubleBuffer* s, jint sx, jint sy, jint dx, jint dy, jint dx2, jint dy2) { - BitBlt((HDC)hdc, dx, dy, dx2 - dx, dy2 - dy, (HDC)(((org::xwt::plat::Win32$Win32DoubleBuffer*)s)->hdc), sx, sy, SRCCOPY); +void org::xwt::plat::Win32$Win32Surface::blit(org::xwt::PixelBuffer* s, jint sx, jint sy, jint dx, jint dy, jint dx2, jint dy2) { + // we create the DC lazily to get around some strange race condition in WinXP + if (hdc == 0) hdc = (jint)GetDC((HWND)hwnd); + BitBlt((HDC)hdc, dx, dy, dx2 - dx, dy2 - dy, (HDC)(((org::xwt::plat::Win32$Win32PixelBuffer*)s)->hdc), sx, sy, SRCCOPY); } -void org::xwt::plat::Win32$Win32DoubleBuffer::natInit() { +void org::xwt::plat::Win32$Win32PixelBuffer::natInit() { hbitmap = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, w, h); hdc = (jint)CreateCompatibleDC((HDC)org::xwt::plat::Win32::desktop_dc); SetBkMode((HDC)hdc, TRANSPARENT); SelectObject((HDC)hdc, (HBITMAP)hbitmap); } -void org::xwt::plat::Win32$Win32DoubleBuffer::setClip(jint x, jint y, jint x2, jint y2) { +void org::xwt::plat::Win32$Win32PixelBuffer::setClip(jint x, jint y, jint x2, jint y2) { clipx1 = x; clipx2 = x2; clipy1 = y; clipy2 = y2; HRGN hrgn = CreateRectRgn(x, y, x2, y2); SelectClipRgn((HDC)hdc, hrgn); DeleteObject(hrgn); } -void org::xwt::plat::Win32$Win32DoubleBuffer::finalize() { +void org::xwt::plat::Win32$Win32PixelBuffer::finalize() { DeleteObject((void*)hdc); DeleteObject((void*)hbitmap); } @@ -599,7 +615,6 @@ void org::xwt::plat::Win32$Win32Surface::natInit(jboolean framed) { // GC_enable_incremental(); ShowWindow ((HWND)hwnd, SW_SHOWDEFAULT); - hdc = (jint)GetDC((HWND)hwnd); } void org::xwt::plat::Win32$Win32Surface::finalize() { /* DeleteObject((void*)hwnd); */ } @@ -625,9 +640,9 @@ void org::xwt::plat::Win32$Win32Surface::setSize(jint w, jint h) { RECT client_rect, window_rect; GetClientRect((HWND)hwnd, &client_rect); GetWindowRect((HWND)hwnd, &window_rect); - int addwidth = (window_rect.right - window_rect.left) - (client_rect.right - client_rect.left); - int addheight = (window_rect.bottom - window_rect.top) - (client_rect.bottom - client_rect.top); - SetWindowPos((HWND)hwnd, NULL, 0, 0, w + addwidth, h + addheight, SWP_NOZORDER | SWP_NOMOVE); + int width = (window_rect.right - window_rect.left) - (client_rect.right - client_rect.left) + w; + int height = (window_rect.bottom - window_rect.top) - (client_rect.bottom - client_rect.top) + h; + SetWindowPos((HWND)hwnd, NULL, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE); } void org::xwt::plat::Win32$Win32Surface::setTitleBarText(java::lang::String* title) { @@ -644,6 +659,9 @@ void org::xwt::plat::Win32$Win32Surface::setIcon(org::xwt::Picture* p0) { int icon_width = GetSystemMetrics(SM_CXSMICON); int icon_height = GetSystemMetrics(SM_CYSMICON); + // we create the DC lazily to get around some strange race condition in WinXP + if (hdc == 0) hdc = (jint)GetDC((HWND)hwnd); + // create the bitmap HBITMAP bit = CreateCompatibleBitmap((HDC)hdc, icon_width, icon_height); HDC memdc = CreateCompatibleDC((HDC)hdc); @@ -684,9 +702,11 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w POINT point; HWND hwnd2; RECT rect, rect2; + RECT client_rect, window_rect; jboolean newinside; int16_t mouse_x; int16_t mouse_y; + int addwidth, addheight; switch(iMsg) { case WM_DEVMODECHANGE: break; // FEATURE: color depth changed @@ -793,11 +813,15 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w return 0; case WM_GETMINMAXINFO: + GetClientRect((HWND)hwnd, &client_rect); + GetWindowRect((HWND)hwnd, &window_rect); + addwidth = (window_rect.right - window_rect.left) - (client_rect.right - client_rect.left); + addheight = (window_rect.bottom - window_rect.top) - (client_rect.bottom - client_rect.top); mmi = (MINMAXINFO*)lParam; - mmi->ptMinTrackSize.x = root->dmin(0); - mmi->ptMinTrackSize.y = root->dmin(1); - mmi->ptMaxTrackSize.x = root->dmax(0); - mmi->ptMaxTrackSize.y = root->dmax(1); + mmi->ptMinTrackSize.x = ((uint32_t)root->minwidth) + addwidth; + mmi->ptMinTrackSize.y = ((uint32_t)root->minheight) + addheight; + mmi->ptMaxTrackSize.x = min(org::xwt::plat::Win32::getScreenWidth(), ((uint32_t)root->maxwidth) + addwidth); + mmi->ptMaxTrackSize.y = min(org::xwt::plat::Win32::getScreenHeight(), ((uint32_t)root->maxheight) + addheight); return 0; case WM_PAINT: