X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fplat%2FWin32.cc;fp=src%2Forg%2Fxwt%2Fplat%2FWin32.cc;h=fda911b60c55d0be4d1c2f5a7c88b6767f569efd;hp=1b3ccea082078bf7d0e94940294db889edd27ddb;hb=3591b88b94a6bb378af3d4abe6eb5233ce583104;hpb=de378041d5ca2aca1a2b5a31ef15ae90a86c977f diff --git a/src/org/xwt/plat/Win32.cc b/src/org/ibex/plat/Win32.cc similarity index 82% rename from src/org/xwt/plat/Win32.cc rename to src/org/ibex/plat/Win32.cc index 1b3ccea..fda911b 100644 --- a/src/org/xwt/plat/Win32.cc +++ b/src/org/ibex/plat/Win32.cc @@ -5,8 +5,8 @@ #define INT32 WIN32_INT32 // this has to precede the others so we don't get collisions on min/max -#include -#include +#include +#include #include #include @@ -23,17 +23,17 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // for debugging #include @@ -50,8 +50,8 @@ // Callbacks //////////////////////////////////////////////////////////////////// LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { - org::xwt::plat::Win32$Win32Surface* surface = - (org::xwt::plat::Win32$Win32Surface*)org::xwt::plat::Win32::hwndToWin32SurfaceMap->get(new java::lang::Integer((jint)hwnd)); + org::ibex::plat::Win32$Win32Surface* surface = + (org::ibex::plat::Win32$Win32Surface*)org::ibex::plat::Win32::hwndToWin32SurfaceMap->get(new java::lang::Integer((jint)hwnd)); if (surface != NULL) { return (LRESULT)surface->WndProc((jint)hwnd, (jint)iMsg, (jint)wParam, (jint)lParam); @@ -67,7 +67,7 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { static int window_class_counter = 0; -jstring org::xwt::plat::Win32::getTempPath() { +jstring org::ibex::plat::Win32::getTempPath() { char buf[1024]; DWORD ret = GetTempPath(1024, buf); if (ret == 0) criticalAbort(JvNewStringLatin1("GetTempPath() failed")); @@ -146,30 +146,30 @@ static unsigned char hand_cursor_and[32 * 4] = { 0xFF, 0xFF, 0xFF, 0xFF }; -void org::xwt::plat::Win32::natPreInit() { - if (org::xwt::util::Log::verbose) { +void org::ibex::plat::Win32::natPreInit() { + if (org::ibex::util::Log::verbose) { AllocConsole(); freopen("CONOUT$", "w+t", stderr); } } -void org::xwt::plat::Win32::natInit() { +void org::ibex::plat::Win32::natInit() { // grab desktop dc/handle desktop_handle = (jint)GetDesktopWindow(); desktop_dc = (jint)GetDC((HWND)desktop_handle); // create cursors - org::xwt::plat::Win32::wait_cursor = (jint)LoadCursor(NULL, IDC_WAIT); - org::xwt::plat::Win32::default_cursor = (jint)LoadCursor(NULL, IDC_ARROW); - org::xwt::plat::Win32::crosshair_cursor = (jint)LoadCursor(NULL, IDC_CROSS); - org::xwt::plat::Win32::text_cursor = (jint)LoadCursor(NULL, IDC_IBEAM); - org::xwt::plat::Win32::move_cursor = (jint)LoadCursor(NULL, IDC_SIZEALL); - org::xwt::plat::Win32::sizenesw_cursor = (jint)LoadCursor(NULL, IDC_SIZENESW); - org::xwt::plat::Win32::sizens_cursor = (jint)LoadCursor(NULL, IDC_SIZENS); - org::xwt::plat::Win32::sizenwse_cursor = (jint)LoadCursor(NULL, IDC_SIZENWSE); - org::xwt::plat::Win32::sizewe_cursor = (jint)LoadCursor(NULL, IDC_SIZEWE); - org::xwt::plat::Win32::hand_cursor = (jint)CreateCursor(GetModuleHandle(NULL), 14, 1, 32, 32, hand_cursor_and, hand_cursor_xor); + org::ibex::plat::Win32::wait_cursor = (jint)LoadCursor(NULL, IDC_WAIT); + org::ibex::plat::Win32::default_cursor = (jint)LoadCursor(NULL, IDC_ARROW); + org::ibex::plat::Win32::crosshair_cursor = (jint)LoadCursor(NULL, IDC_CROSS); + org::ibex::plat::Win32::text_cursor = (jint)LoadCursor(NULL, IDC_IBEAM); + org::ibex::plat::Win32::move_cursor = (jint)LoadCursor(NULL, IDC_SIZEALL); + org::ibex::plat::Win32::sizenesw_cursor = (jint)LoadCursor(NULL, IDC_SIZENESW); + org::ibex::plat::Win32::sizens_cursor = (jint)LoadCursor(NULL, IDC_SIZENS); + org::ibex::plat::Win32::sizenwse_cursor = (jint)LoadCursor(NULL, IDC_SIZENWSE); + org::ibex::plat::Win32::sizewe_cursor = (jint)LoadCursor(NULL, IDC_SIZEWE); + org::ibex::plat::Win32::hand_cursor = (jint)CreateCursor(GetModuleHandle(NULL), 14, 1, 32, 32, hand_cursor_and, hand_cursor_xor); messagePumpThread = (jint)GetCurrentThreadId(); messagePumpStarted->release(); @@ -178,12 +178,12 @@ void org::xwt::plat::Win32::natInit() { while(GetMessage(&msg, (HWND)NULL, 0, 0) > 0) { if (msg.message == WM_USER_CREATEWINDOW) { - org::xwt::plat::Win32$Win32Surface *surface = (org::xwt::plat::Win32$Win32Surface*)msg.lParam; + org::ibex::plat::Win32$Win32Surface *surface = (org::ibex::plat::Win32$Win32Surface*)msg.lParam; // we must create a unique window class name for each // window so that minimization icons can be set independantly char buf[255]; - sprintf(buf, "XWT_WINDOW_CLASS_%i", window_class_counter++); + sprintf(buf, "Ibex_WINDOW_CLASS_%i", window_class_counter++); WNDCLASSEX wc; wc.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW; @@ -227,7 +227,7 @@ void org::xwt::plat::Win32::natInit() { // Platform Methods /////////////////////////////////////////////////////////////////// -jstring org::xwt::plat::Win32::_getEnv(jstring key) { +jstring org::ibex::plat::Win32::_getEnv(jstring key) { int len = JvGetStringUTFLength(key); char buf[len + 1]; JvGetStringUTFRegion(key, 0, len, buf); @@ -238,7 +238,7 @@ jstring org::xwt::plat::Win32::_getEnv(jstring key) { return NULL; } -jstring org::xwt::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean write) { +jstring org::ibex::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean write) { char buf[1024]; OPENFILENAME ofn; @@ -260,7 +260,7 @@ jstring org::xwt::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean w return ret == 0 ? NULL : JvNewStringLatin1(buf); } -void org::xwt::plat::Win32::__detectProxy(JArray* container) { +void org::ibex::plat::Win32::__detectProxy(JArray* container) { HKEY hkey; char buf[1024]; @@ -295,7 +295,7 @@ void org::xwt::plat::Win32::__detectProxy(JArray* container) { elements(container)[1] = JvNewStringLatin1(buf); } -jstring org::xwt::plat::Win32::_getClipBoard() { +jstring org::ibex::plat::Win32::_getClipBoard() { OpenClipboard((HWND)desktop_handle); HGLOBAL hmem = GetClipboardData(CF_TEXT); if (hmem == NULL) return NULL; @@ -307,7 +307,7 @@ jstring org::xwt::plat::Win32::_getClipBoard() { return ret; } -void org::xwt::plat::Win32::_setClipBoard(jstring s) { +void org::ibex::plat::Win32::_setClipBoard(jstring s) { OpenClipboard((HWND)desktop_handle); HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, JvGetStringUTFLength(s) + 1); if (hmem == NULL) return; @@ -320,27 +320,27 @@ void org::xwt::plat::Win32::_setClipBoard(jstring s) { CloseClipboard(); } -void org::xwt::plat::Win32::_criticalAbort(jstring message) { +void org::ibex::plat::Win32::_criticalAbort(jstring message) { char buf[JvGetStringUTFLength(message) + 1]; buf[JvGetStringUTFLength(message)] = '\0'; JvGetStringUTFRegion(message, 0, JvGetStringUTFLength(message), buf); - MessageBox (NULL, buf, "XWT Cannot Continue", MB_OK | MB_ICONSTOP | MB_TASKMODAL | MB_SETFOREGROUND); + MessageBox (NULL, buf, "Ibex Cannot Continue", MB_OK | MB_ICONSTOP | MB_TASKMODAL | MB_SETFOREGROUND); java::lang::System::exit(-1); } -jint org::xwt::plat::Win32::_getScreenWidth() { +jint org::ibex::plat::Win32::_getScreenWidth() { RECT rect; SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); return rect.right - rect.left; } -jint org::xwt::plat::Win32::_getScreenHeight() { +jint org::ibex::plat::Win32::_getScreenHeight() { RECT rect; SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0); return rect.bottom - rect.top; } -jboolean org::xwt::plat::Win32::_newBrowserWindow_(jstring url) { +jboolean org::ibex::plat::Win32::_newBrowserWindow_(jstring url) { int len = min(2048, JvGetStringUTFLength(url)); char buf[len + 1]; @@ -372,11 +372,11 @@ static jint scratch_h = 0; #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) -void org::xwt::plat::Win32$Win32PixelBuffer::drawPicture(org::xwt::Picture* source0, +void org::ibex::plat::Win32$Win32PixelBuffer::drawPicture(org::ibex::Picture* source0, jint dx, jint dy, jint cx1, jint cy1, jint cx2, jint cy2, jint rgb, jboolean alphaOnly) { - org::xwt::plat::Win32$Win32Picture* source = (org::xwt::plat::Win32$Win32Picture*)source0; + org::ibex::plat::Win32$Win32Picture* source = (org::ibex::plat::Win32$Win32Picture*)source0; cx1 = max(dx, cx1); cy1 = max(dy, cy1); @@ -403,7 +403,7 @@ void org::xwt::plat::Win32$Win32PixelBuffer::drawPicture(org::xwt::Picture* sour // create section DIB scratch = CreateDIBSection(NULL, &bitmapinfo, DIB_RGB_COLORS, (void**)&scratch_bits, NULL, 0); - scratch_dc = CreateCompatibleDC((HDC)org::xwt::plat::Win32::desktop_dc); + scratch_dc = CreateCompatibleDC((HDC)org::ibex::plat::Win32::desktop_dc); SelectObject(scratch_dc, scratch); } @@ -443,7 +443,7 @@ void org::xwt::plat::Win32$Win32PixelBuffer::drawPicture(org::xwt::Picture* sour } -void org::xwt::plat::Win32$Win32PixelBuffer::fillRect(jint x, jint y, jint x2, jint y2, jint color) { +void org::ibex::plat::Win32$Win32PixelBuffer::fillRect(jint x, jint y, jint x2, jint y2, jint color) { jint w = x2 - x; jint h = y2 - y; @@ -455,20 +455,20 @@ void org::xwt::plat::Win32$Win32PixelBuffer::fillRect(jint x, jint y, jint x2, j DeleteObject(brush); } -void org::xwt::plat::Win32$Win32Surface::blit(org::xwt::PixelBuffer* s, jint sx, jint sy, jint dx, jint dy, jint dx2, jint dy2) { +void org::ibex::plat::Win32$Win32Surface::blit(org::ibex::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); + BitBlt((HDC)hdc, dx, dy, dx2 - dx, dy2 - dy, (HDC)(((org::ibex::plat::Win32$Win32PixelBuffer*)s)->hdc), sx, sy, SRCCOPY); } -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); +void org::ibex::plat::Win32$Win32PixelBuffer::natInit() { + hbitmap = (jint)CreateCompatibleBitmap((HDC)org::ibex::plat::Win32::desktop_dc, w, h); + hdc = (jint)CreateCompatibleDC((HDC)org::ibex::plat::Win32::desktop_dc); SetBkMode((HDC)hdc, TRANSPARENT); SelectObject((HDC)hdc, (HBITMAP)hbitmap); } -void org::xwt::plat::Win32$Win32PixelBuffer::finalize() { +void org::ibex::plat::Win32$Win32PixelBuffer::finalize() { DeleteObject((void*)hdc); DeleteObject((void*)hbitmap); } @@ -477,7 +477,7 @@ void org::xwt::plat::Win32$Win32PixelBuffer::finalize() { // Win32Picture ///////////////////////////////////////////////////////////////////////// -void org::xwt::plat::Win32$Win32Picture::natInit() { +void org::ibex::plat::Win32$Win32Picture::natInit() { BITMAPINFO bitmapinfo; memset(&bitmapinfo, 0, sizeof(BITMAPINFO)); @@ -488,8 +488,8 @@ void org::xwt::plat::Win32$Win32Picture::natInit() { bitmapinfo.bmiHeader.biBitCount = 32; bitmapinfo.bmiHeader.biCompression = BI_RGB; - hbitmap = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, width, height); - hdc = (jint)CreateCompatibleDC((HDC)org::xwt::plat::Win32::desktop_dc); + hbitmap = (jint)CreateCompatibleBitmap((HDC)org::ibex::plat::Win32::desktop_dc, width, height); + hdc = (jint)CreateCompatibleDC((HDC)org::ibex::plat::Win32::desktop_dc); SelectObject((HDC)hdc, (HBITMAP)hbitmap); uint32_t* dat = (uint32_t*)elements(data); for(int i=0; ilength; i++) if ((dat[i] & 0xFF000000) == 0x00000000) dat[i] = 0x00000000; @@ -518,7 +518,7 @@ void org::xwt::plat::Win32$Win32Picture::natInit() { } // hmask = (jint)CreateBitmap(w, h, 1, 1, NULL); - hmask = (jint)CreateCompatibleBitmap((HDC)org::xwt::plat::Win32::desktop_dc, width, height); + hmask = (jint)CreateCompatibleBitmap((HDC)org::ibex::plat::Win32::desktop_dc, width, height); maskdc = (jint)CreateCompatibleDC(NULL); SelectObject((HDC)maskdc, (HBITMAP)hmask); StretchDIBits((HDC)maskdc, 0, 0, width, height, 0, 0, width, height, copy, &bitmapinfo, DIB_RGB_COLORS, SRCCOPY); @@ -529,10 +529,10 @@ void org::xwt::plat::Win32$Win32Picture::natInit() { // Win32Surface ///////////////////////////////////////////////////////////////////////////// -void org::xwt::plat::Win32$Win32Surface::natInit(jboolean framed) { +void org::ibex::plat::Win32$Win32Surface::natInit(jboolean framed) { // Ask the message-handling thread to create a window for us - PostThreadMessage((DWORD)org::xwt::plat::Win32::messagePumpThread, WM_USER + 2, (WPARAM)framed, (LPARAM)this); + PostThreadMessage((DWORD)org::ibex::plat::Win32::messagePumpThread, WM_USER + 2, (WPARAM)framed, (LPARAM)this); hwndCreated->block(); // turn on incremental GC now that we have a user-visible interface @@ -542,16 +542,16 @@ void org::xwt::plat::Win32$Win32Surface::natInit(jboolean framed) { ShowWindow ((HWND)hwnd, SW_SHOWDEFAULT); } -void org::xwt::plat::Win32$Win32Surface::finalize() { /* DeleteObject((void*)hwnd); */ } -void org::xwt::plat::Win32$Win32Surface::toFront() { BringWindowToTop((HWND)hwnd); } -void org::xwt::plat::Win32$Win32Surface::toBack() { SetWindowPos((HWND)hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } -void org::xwt::plat::Win32$Win32Surface::_dispose() { PostMessage((HWND)hwnd, WM_USER_DISPOSE, 0, 0); } -void org::xwt::plat::Win32$Win32Surface::setInvisible(jboolean h) { ShowWindow((HWND)hwnd, h ? SW_HIDE : SW_SHOWNORMAL); } -void org::xwt::plat::Win32$Win32Surface::_setMinimized(jboolean m) { ShowWindow((HWND)hwnd, m ? SW_SHOWMINIMIZED : SW_SHOWNORMAL); } -void org::xwt::plat::Win32$Win32Surface::_setMaximized(jboolean m) { ShowWindow((HWND)hwnd, m ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL); } -void org::xwt::plat::Win32$Win32Surface::postCursorChange() { PostMessage((HWND)hwnd, WM_USER_SETCURSOR, 0, 0); } +void org::ibex::plat::Win32$Win32Surface::finalize() { /* DeleteObject((void*)hwnd); */ } +void org::ibex::plat::Win32$Win32Surface::toFront() { BringWindowToTop((HWND)hwnd); } +void org::ibex::plat::Win32$Win32Surface::toBack() { SetWindowPos((HWND)hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE); } +void org::ibex::plat::Win32$Win32Surface::_dispose() { PostMessage((HWND)hwnd, WM_USER_DISPOSE, 0, 0); } +void org::ibex::plat::Win32$Win32Surface::setInvisible(jboolean h) { ShowWindow((HWND)hwnd, h ? SW_HIDE : SW_SHOWNORMAL); } +void org::ibex::plat::Win32$Win32Surface::_setMinimized(jboolean m) { ShowWindow((HWND)hwnd, m ? SW_SHOWMINIMIZED : SW_SHOWNORMAL); } +void org::ibex::plat::Win32$Win32Surface::_setMaximized(jboolean m) { ShowWindow((HWND)hwnd, m ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL); } +void org::ibex::plat::Win32$Win32Surface::postCursorChange() { PostMessage((HWND)hwnd, WM_USER_SETCURSOR, 0, 0); } -void org::xwt::plat::Win32$Win32Surface::setLocation() { +void org::ibex::plat::Win32$Win32Surface::setLocation() { POINT point; RECT rect; point.x = 0; @@ -561,7 +561,7 @@ void org::xwt::plat::Win32$Win32Surface::setLocation() { SetWindowPos((HWND)hwnd, NULL, root->x - (point.x - rect.left), root->y - (point.y - rect.top), 0, 0, SWP_NOZORDER | SWP_NOSIZE); } -void org::xwt::plat::Win32$Win32Surface::_setSize(jint w, jint h) { +void org::ibex::plat::Win32$Win32Surface::_setSize(jint w, jint h) { RECT client_rect, window_rect; GetClientRect((HWND)hwnd, &client_rect); GetWindowRect((HWND)hwnd, &window_rect); @@ -570,7 +570,7 @@ void org::xwt::plat::Win32$Win32Surface::_setSize(jint w, jint h) { SetWindowPos((HWND)hwnd, NULL, 0, 0, width, height, SWP_NOZORDER | SWP_NOMOVE); } -void org::xwt::plat::Win32$Win32Surface::setTitleBarText(java::lang::String* title) { +void org::ibex::plat::Win32$Win32Surface::setTitleBarText(java::lang::String* title) { int len = min(1024, JvGetStringUTFLength(title)); char buf[len + 1]; buf[len] = '\0'; @@ -578,9 +578,9 @@ void org::xwt::plat::Win32$Win32Surface::setTitleBarText(java::lang::String* tit SetWindowText((HWND)hwnd, buf); } -void org::xwt::plat::Win32$Win32Surface::setIcon(org::xwt::Picture* p0) { +void org::ibex::plat::Win32$Win32Surface::setIcon(org::ibex::Picture* p0) { - org::xwt::plat::Win32$Win32Picture* p = (org::xwt::plat::Win32$Win32Picture*)p0; + org::ibex::plat::Win32$Win32Picture* p = (org::ibex::plat::Win32$Win32Picture*)p0; int icon_width = GetSystemMetrics(SM_CXSMICON); int icon_height = GetSystemMetrics(SM_CYSMICON); @@ -616,7 +616,7 @@ void org::xwt::plat::Win32$Win32Surface::setIcon(org::xwt::Picture* p0) { } static jstring keyToString(WPARAM wParam); -jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _wParam, jint _lParam) { +jint org::ibex::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _wParam, jint _lParam) { UINT iMsg = (UINT)_iMsg; WPARAM wParam = (WPARAM)_wParam; @@ -746,15 +746,15 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w mmi->ptMinTrackSize.x = ((uint32_t)root->minwidth) + addwidth; mmi->ptMinTrackSize.y = ((uint32_t)root->minheight) + addheight; resizable = !((root->minwidth == root->maxwidth) && (root->minheight == root->maxheight)); - mmi->ptMaxTrackSize.x = resizable ? org::xwt::plat::Win32::getScreenWidth() : mmi->ptMinTrackSize.x; - mmi->ptMaxTrackSize.y = resizable ? org::xwt::plat::Win32::getScreenHeight() : mmi->ptMinTrackSize.y; + mmi->ptMaxTrackSize.x = resizable ? org::ibex::plat::Win32::getScreenWidth() : mmi->ptMinTrackSize.x; + mmi->ptMaxTrackSize.y = resizable ? org::ibex::plat::Win32::getScreenHeight() : mmi->ptMinTrackSize.y; return 0; case WM_PAINT: PAINTSTRUCT ps; - BeginPaint((HWND)org::xwt::plat::Win32$Win32Surface::hwnd, &ps); + BeginPaint((HWND)org::ibex::plat::Win32$Win32Surface::hwnd, &ps); Dirty(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top); - EndPaint((HWND)org::xwt::plat::Win32$Win32Surface::hwnd, &ps); + EndPaint((HWND)org::ibex::plat::Win32$Win32Surface::hwnd, &ps); return 0; default: break;