2002/05/28 18:30:30
[org.ibex.core.git] / src / org / xwt / plat / Win32.cc
index c99ec19..e03526c 100644 (file)
 #include <windows.h>
 #include <mmsystem.h>
 #undef STRICT
+#undef MAX_PRIORITY
+#undef MIN_PRIORITY
+#undef NORM_PRIORITY
 
 #include <gcj/cni.h>
 
 #include <java/lang/Integer.h>
-#include <org/xwt/util/Hash.h>
+#include <java/util/Hashtable.h>
 #include <org/xwt/Box.h>
 #include <org/xwt/Surface.h>
 #include <org/xwt/DoubleBuffer.h>
 #include <org/xwt/Picture.h>
+#include <org/xwt/ByteStream.h>
 #include <org/xwt/Platform.h>
 #include <org/xwt/Platform$ParsedFont.h>
 #include <org/xwt/plat/Win32.h>
@@ -29,6 +33,7 @@
 #include <org/xwt/plat/Win32$Win32Surface.h>
 #include <org/xwt/plat/Win32$Win32DoubleBuffer.h>
 #include <org/xwt/plat/Win32$Win32Picture.h>
+#include <org/xwt/util/Log.h>
 #include <org/xwt/util/Semaphore.h>
 
 // for debugging
@@ -161,6 +166,7 @@ static unsigned char hand_cursor_and[32 * 4] = {
   0xFF, 0xFF, 0xFF, 0xFF
 };
 
+
 void org::xwt::plat::Win32::natInit() {
 
     // grab desktop dc/handle
@@ -233,6 +239,64 @@ void org::xwt::plat::Win32::natInit() {
 
 // Platform Methods ///////////////////////////////////////////////////////////////////
 
+jstring org::xwt::plat::Win32::_fileDialog(jstring suggestedFileName, jboolean write) {
+
+    char buf[1024];
+    OPENFILENAME ofn;
+    memset(buf, 0, 1024);
+    memset(&ofn, 0, sizeof(OPENFILENAME));
+
+    if (suggestedFileName != NULL)
+        JvGetStringUTFRegion(suggestedFileName, 0, min(1023, JvGetStringUTFLength(suggestedFileName)), buf);
+    
+    ofn.lStructSize = sizeof(OPENFILENAME);
+    ofn.nMaxCustFilter = 0;
+    ofn.lpstrFile = buf;
+    ofn.nMaxFile = 1024;
+
+    if (write) ofn.Flags |= OFN_OVERWRITEPROMPT;
+    ofn.Flags |= OFN_NOCHANGEDIR;
+    ofn.Flags |= OFN_HIDEREADONLY;
+
+    int ret = write ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn);
+    return ret == 0 ? NULL : JvNewStringLatin1(buf);
+}
+
+void org::xwt::plat::Win32::__detectProxy(JArray<jstring>* container) {
+
+    HKEY hkey;
+    char buf[1024];
+    DWORD buflen = 1024;
+    DWORD type;
+    LONG result = RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &hkey);
+    if (result != ERROR_SUCCESS) return;
+    
+    buf[0] = '\0';
+    type = REG_SZ;
+    buflen = 1024;
+    result = RegQueryValueEx(hkey, "AutoConfigURL", NULL, &type, (LPBYTE)buf, &buflen);
+    buf[buflen] = '\0';
+    if (result == ERROR_SUCCESS) elements(container)[2] = JvNewStringLatin1(buf);
+
+    buf[0] = '\0';
+    type = REG_BINARY;
+    RegQueryValueEx(hkey, "ProxyEnable", NULL, &type, (LPBYTE)buf, &buflen);
+    if (buf[0] != 1) return;
+
+    buf[0] = '\0';
+    type = REG_SZ;
+    buflen = 1024;
+    RegQueryValueEx(hkey, "ProxyServer", NULL, &type, (LPBYTE)buf, &buflen);
+    buf[buflen] = '\0';
+    elements(container)[0] = JvNewStringLatin1(buf);
+
+    buf[0] = '\0';
+    buflen = 1024;
+    RegQueryValueEx(hkey, "ProxyOverride", NULL, &type, (LPBYTE)buf, &buflen);
+    buf[buflen] = '\0';
+    elements(container)[1] = JvNewStringLatin1(buf);
+}
+
 jstring org::xwt::plat::Win32::_getClipBoard() {
     OpenClipboard((HWND)desktop_handle);
     HGLOBAL hmem = GetClipboardData(CF_TEXT);
@@ -322,6 +386,23 @@ jint org::xwt::plat::Win32::_stringWidth(jstring font, jstring text) {
     return size.cx;
 }
 
+jboolean org::xwt::plat::Win32::_newBrowserWindow_(jstring url) {
+
+    int len = min(2048, JvGetStringUTFLength(url));
+    char buf[len + 1];
+    JvGetStringUTFRegion(url, 0, len, buf);
+    buf[len] = '\0';
+
+    SHELLEXECUTEINFO ei;
+    memset(&ei, 0, sizeof(ei));
+    ei.cbSize = sizeof(ei);
+    ei.lpVerb = "open";
+    ei.lpFile = buf;
+    ei.fMask  = SEE_MASK_NOCLOSEPROCESS;
+    ei.nShow  = SW_SHOWDEFAULT;
+    return (ShellExecuteEx(&ei) == 0);
+
+}
 
 
 // Win32DoubleBuffer /////////////////////////////////////////////////////////////////////////
@@ -525,7 +606,7 @@ void org::xwt::plat::Win32$Win32Surface::natInit(jboolean framed) {
     hdc = (jint)GetDC((HWND)hwnd);
 }
 
-void org::xwt::plat::Win32$Win32Surface::finalize() { DeleteObject((void*)hwnd); }
+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); }
@@ -601,6 +682,7 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w
     UINT iMsg = (UINT)_iMsg;
     WPARAM wParam = (WPARAM)_wParam;
     LPARAM lParam = (LPARAM)_lParam;
+
     int oldmousex, oldmousey;
     MINMAXINFO* mmi;
     POINT point;
@@ -726,7 +808,6 @@ jint org::xwt::plat::Win32$Win32Surface::WndProc(jint _hwnd, jint _iMsg, jint _w
         PAINTSTRUCT ps;
         BeginPaint((HWND)org::xwt::plat::Win32$Win32Surface::hwnd, &ps);
         Dirty(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left, ps.rcPaint.bottom - ps.rcPaint.top);
-        Refresh();
         EndPaint((HWND)org::xwt::plat::Win32$Win32Surface::hwnd, &ps);
         return 0;
 
@@ -834,11 +915,10 @@ using namespace std;
 
 #define CLSID_STRING_SIZE 39
 
-const char XWT_friendlyName[] = "XWT ActiveX Control (Hydrogen)";
+const char XWT_friendlyName[] = "XWT ActiveX Control (build " BUILDID ")";
 const char XWT_versionIndependantProgramID[] = "XWT.ActiveX";
-const char XWT_programID[] = "XWT.ActiveX.Hydrogen";
-extern "C" const CLSID XWT_clsid = { 0xc60d6d23, 0x3a7d, 0x11d6, { 0x82, 0xf9, 0x0, 0x50, 0x56, 0xca, 0x92, 0x50 } };
-
+const char XWT_programID[] = "XWT.ActiveX (build " BUILDID ")";
+extern "C" const CLSID XWT_clsid = CLSID_STRUCT;
 static HMODULE g_hModule = NULL;    //DLL handle
 
 
@@ -1027,13 +1107,18 @@ class ShoeHorn : public IShoeHorn {
             which[0] = '0' + i;
             which[1] = '\0';
             result = RegQueryValueEx(hkey, which, NULL, &type, (BYTE*)buf, &buflen);
-            check(result == ERROR_SUCCESS, "RegQueryValueEx() failed in ShoeHorn::Load()");
+            if (result != ERROR_SUCCESS)
+                if (i == 0) {
+                    check(0, "RegQueryValueEx() failed in ShoeHorn::Load()");
+                } else {
+                    break;
+                }
             buf[buflen] = '\0';
             
             char cmdline[200];
             for(int i=0; i<200; i++) cmdline[i] = '\0';
             strncpy(cmdline, buf, 200);
-            strncpy(cmdline + strlen(cmdline), "\\xwt.exe", 200 - strlen(cmdline));
+            strncpy(cmdline + strlen(cmdline), "\\xwt-" BUILDID ".exe", 200 - strlen(cmdline));
             strncpy(cmdline + strlen(cmdline), " ", 200 - strlen(cmdline));
             strncpy(cmdline + strlen(cmdline), url, 200 - strlen(cmdline));
             
@@ -1054,7 +1139,7 @@ class ShoeHorn : public IShoeHorn {
             if (b) return S_OK;
         }
 
-        check(0, "unable to locate xwt.exe in ActiveX cache folders");
+        check(0, "unable to locate xwt-" BUILDID ".exe in ActiveX cache folders");
     }
 
     ShoeHorn() : m_cRef(1) { };