|
From: <set...@us...> - 2006-04-24 20:03:16
|
Revision: 1328 Author: sethdill Date: 2006-04-24 13:02:59 -0700 (Mon, 24 Apr 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1328&view=rev Log Message: ----------- Frontier is now a COM client. - call initCOM() before using any COM interfaces - a thread global keeps track of whether or not COM has already been initialized for the current thread (so it won't happen more than once) - disposeglobals closes down the COM connection The table of character sets at string.charsets is now for informational purposes only. The item names are the internet names, and the value is a 'display name' for the character set. The string.convertCharset verb now takes internet names instead of code page ID's. New verb string.isCharsetAvailabe(). Give it an internet name, it returns a boolean. All changes for Windows only. Two platforms are mostly in sync now, but for a couple tweaks still lacking on the mac. Modified Paths: -------------- Frontier/trunk/Common/SystemHeaders/standard.h Frontier/trunk/Common/headers/frontierdefs.h Frontier/trunk/Common/headers/osincludes.h Frontier/trunk/Common/headers/processinternal.h Frontier/trunk/Common/headers/strings.h Frontier/trunk/Common/resources/Win32/kernelverbs.rc Frontier/trunk/Common/source/FrontierWinMain.c Frontier/trunk/Common/source/lang.c Frontier/trunk/Common/source/langstartup.c Frontier/trunk/Common/source/process.c Frontier/trunk/Common/source/shell.c Frontier/trunk/Common/source/strings.c Modified: Frontier/trunk/Common/SystemHeaders/standard.h =================================================================== --- Frontier/trunk/Common/SystemHeaders/standard.h 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/SystemHeaders/standard.h 2006-04-24 20:02:59 UTC (rev 1328) @@ -437,6 +437,10 @@ #define quickdrawglobal(x) qd.x +extern boolean flcominitialized; /* set up in lang.c */ +extern boolean initCOM( void ); /* see FrontierWinMain.c */ +extern void shutdownCOM( void ); + #endif #endif Modified: Frontier/trunk/Common/headers/frontierdefs.h =================================================================== --- Frontier/trunk/Common/headers/frontierdefs.h 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/headers/frontierdefs.h 2006-04-24 20:02:59 UTC (rev 1328) @@ -35,11 +35,13 @@ #ifdef WIN95VERSION #define FRONTIERCOM 1 -#ifndef OPMLEDITOR - #define FRONTIERWEB 0 -#else //OPMLEDITOR - #define FRONTIERWEB 1 /* 2006-02-05 aradke: enable HTML display in main window background */ -#endif // OPMLEDITOR + + #ifndef OPMLEDITOR + #define FRONTIERWEB 0 + #else //OPMLEDITOR + #define FRONTIERWEB 1 /* 2006-02-05 aradke: enable HTML display in main window background */ + #endif // OPMLEDITOR + #undef winhybrid #define fljustpacking 0 #undef flcomponent Modified: Frontier/trunk/Common/headers/osincludes.h =================================================================== --- Frontier/trunk/Common/headers/osincludes.h 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/headers/osincludes.h 2006-04-24 20:02:59 UTC (rev 1328) @@ -37,6 +37,8 @@ #ifdef WIN95VERSION #define WIN32_LEAN_AND_MEAN 1 + #define _WIN32_DCOM 1 + #define CINTERFACE 1 #include <windows.h> @@ -55,6 +57,10 @@ #include <winsock2.h> #include <mswsock.h> + #undef __cplusplus + #include <objbase.h> + #include <mlang.h> + #endif /* WIN95VERSION */ Modified: Frontier/trunk/Common/headers/processinternal.h =================================================================== --- Frontier/trunk/Common/headers/processinternal.h 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/headers/processinternal.h 2006-04-24 20:02:59 UTC (rev 1328) @@ -195,6 +195,9 @@ ThreadEntryUPP threadEntryCallbackUPP; #endif + + boolean flcominitialized; + } tythreadglobals, *ptrthreadglobals, **hdlthreadglobals; Modified: Frontier/trunk/Common/headers/strings.h =================================================================== --- Frontier/trunk/Common/headers/strings.h 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/headers/strings.h 2006-04-24 20:02:59 UTC (rev 1328) @@ -161,6 +161,7 @@ extern void copyctopstring (const char *, bigstring); #ifdef WIN95VERSION +extern boolean copyWideToPString (const wchar_t *, bigstring); extern void copyrezstring (const bigstring, bigstring); #endif @@ -266,9 +267,9 @@ extern boolean utf8tomacroman (Handle, Handle); /* 2006-02-25 creedon */ -extern boolean convertCharset( Handle, Handle, const bigstring, const bigstring ); +extern boolean convertCharset( Handle, Handle, bigstring, bigstring ); -extern boolean isTextEncodingAvailable( const bigstring ); /* 2006-04-23 smd */ +extern boolean isTextEncodingAvailable( bigstring ); /* 2006-04-23 smd */ #endif Modified: Frontier/trunk/Common/resources/Win32/kernelverbs.rc =================================================================== --- Frontier/trunk/Common/resources/Win32/kernelverbs.rc 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/resources/Win32/kernelverbs.rc 2006-04-24 20:02:59 UTC (rev 1328) @@ -514,7 +514,7 @@ 1, //Number of "blocks" in this resource "string\0", //Function Processor Name false, //Window required - 59, //Count of verbs + 60, //Count of verbs "delete\0", "insert\0", "popleading\0", @@ -573,7 +573,8 @@ "multiplereplaceall\0", "macromantoutf8\0", // 2006-02-25 creedon "utf8tomacroman\0", // 2006-02-25 creedon - "convertcharset\0" /* 2006-04-16 smd */ + "convertcharset\0", /* 2006-04-16 smd */ + "ischarsetavailable\0" /* 2006-04-24 smd */ END Modified: Frontier/trunk/Common/source/FrontierWinMain.c =================================================================== --- Frontier/trunk/Common/source/FrontierWinMain.c 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/source/FrontierWinMain.c 2006-04-24 20:02:59 UTC (rev 1328) @@ -2974,8 +2974,38 @@ } /*COMSYSModule*/ +boolean initCOM () +{ + if ( !flcominitialized ) + { + LPVOID reserved = NULL; + HRESULT err; + + err = CoInitialize( reserved ); + + if ( SUCCEEDED( err ) ) + { + flcominitialized = true; + return (true); + } + else + return (false); + } + + return (true); +} + +void shutdownCOM () +{ + CoUninitialize(); + flcominitialized = false; +} + + Handle COMStartup () { + initCOM(); + gcomServerInfo.hCOMModule = LoadLibrary ("COMDLL.DLL"); if (gcomServerInfo.hCOMModule == NULL) @@ -2991,7 +3021,7 @@ if ((gcomServerInfo.cominit != NULL) && (gcomServerInfo.comclear != NULL)) { fillcalltable(&gcomServerInfo.calltable); - + (*(gcomServerInfo.cominit)) (gcomServerInfo.hInstance, gcomServerInfo.hPrevInstance, gcomServerInfo.lpCmdLine, gcomServerInfo.nCmdShow, &gcomServerInfo.calltable); } } @@ -3000,6 +3030,8 @@ } /*COMStartup*/ boolean COMShutdown () { + shutdownCOM(); + if ((gcomServerInfo.cominit != NULL) && (gcomServerInfo.comclear != NULL)) (*(gcomServerInfo.comclear)) (); @@ -3009,6 +3041,7 @@ gcomServerInfo.cominit = NULL; gcomServerInfo.comclear = NULL; gcomServerInfo.hCOMModule = NULL; + return (true); } /*COMShutdown*/ Modified: Frontier/trunk/Common/source/lang.c =================================================================== --- Frontier/trunk/Common/source/lang.c 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/source/lang.c 2006-04-24 20:02:59 UTC (rev 1328) @@ -81,7 +81,10 @@ tylangcallbacks langcallbacks; /*routines that wire the language into environment*/ +boolean flcominitialized = false; + + static short ctrootchains = 0; /*number of hashtable chains that include the root*/ static boolean flevaluateglobalwith = false; /*dmb 4.1b12 - new flag for langcard support*/ Modified: Frontier/trunk/Common/source/langstartup.c =================================================================== --- Frontier/trunk/Common/source/langstartup.c 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/source/langstartup.c 2006-04-24 20:02:59 UTC (rev 1328) @@ -426,6 +426,7 @@ static boolean initCharsetsTable (hdlhashtable cSetsTable) { +#if 1 #if MACVERSION OSStatus err; ItemCount ct, actual_ct, i; @@ -469,49 +470,59 @@ #endif #if WIN95VERSION - langassignlongvalue( cSetsTable, "\x05" "ASCII", 20127 ); - langassignlongvalue( cSetsTable, "\x08" "US-ASCII", 20127 ); /* alias for ASCII */ + HRESULT err; + IMultiLanguage2 * pMultiLanguage; + IEnumCodePage * pEnumCodePage; + UINT i, cnum = 0; + MIMECPINFO cpInfo; + long ccpInfo; + bigstring ianaName, displayName; + + initCOM(); + + err = CoCreateInstance( + &CLSID_CMultiLanguage, + NULL, + CLSCTX_INPROC_SERVER, + &IID_IMultiLanguage2, + (void **) &pMultiLanguage ); + + if ( FAILED( err ) ) + goto done; + + err = pMultiLanguage->lpVtbl->EnumCodePages( + pMultiLanguage, + 0, // MIMECONTF_MAILNEWS | MIMECONTF_BROWSER | MIMECONTF_VALID | MIMECONTF_MIME_LATEST + 9, /* LANGID. I'm totally guessing that 0 means "all", here. -- smd */ + (IEnumCodePage **) &pEnumCodePage ); - langassignlongvalue( cSetsTable, "\x09" "MACINTOSH", 10000 ); - langassignlongvalue( cSetsTable, "\x08" "MacRoman", 10000 ); /* alias for MACINTOSH */ + if ( FAILED( err ) ) + goto done; + + pMultiLanguage->lpVtbl->GetNumberOfCodePageInfo( pMultiLanguage, &cnum ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-1", 28591 ); - langassignlongvalue( cSetsTable, "\x0b" "iso-latin-1", 28591 ); /* alias for iso-8859-1 */ - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-2", 28592 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-3", 28593 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-4", 28594 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-5", 28595 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-6", 28596 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-7", 28597 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-8", 28598 ); - langassignlongvalue( cSetsTable, "\x0a" "iso-8859-9", 28599 ); - langassignlongvalue( cSetsTable, "\x0b" "iso-8859-10", 28592 ); - - langassignlongvalue( cSetsTable, "\x0c" "windows-1250", 1250 ); - langassignlongvalue( cSetsTable, "\x0f" "windows-latin-2", 1250 ); /* code page 1250, Central Europe */ - - langassignlongvalue( cSetsTable, "\x0c" "windows-1251", 1251 ); /* code page 1251, Slavic Cyrillic */ - - langassignlongvalue( cSetsTable, "\x0c" "windows-1252", 1252 ); - langassignlongvalue( cSetsTable, "\x0f" "windows-latin-1", 1252 ); - - langassignlongvalue( cSetsTable, "\x0c" "windows-1253", 1253 ); /* code page 1253 */ - langassignlongvalue( cSetsTable, "\x0c" "windows-1254", 1254 ); /* code page 1254, Turkish */ - langassignlongvalue( cSetsTable, "\x0c" "windows-1255", 1255 ); /* code page 1255 */ - langassignlongvalue( cSetsTable, "\x0c" "windows-1256", 1256 ); /* code page 1256 */ - langassignlongvalue( cSetsTable, "\x0c" "windows-1257", 1257 ); /* code page 1257 */ - langassignlongvalue( cSetsTable, "\x0c" "windows-1258", 1258 ); /* code page 1258 */ - langassignlongvalue( cSetsTable, "\x0c" "windows-1361", 1361 ); /* code page 1361, for Windows NT */ - - langassignlongvalue( cSetsTable, "\x05" "UTF-7", 65000 ); - langassignlongvalue( cSetsTable, "\x05" "UTF-8", 65001 ); - - langassignlongvalue( cSetsTable, "\x06" "UTF-16", 0 ); /* not a real code page. 0 for special case handling in Frontier */ - - langassignlongvalue( cSetsTable, "\x08" "UTF-16le", 1200 ); - langassignlongvalue( cSetsTable, "\x08" "UTF-16be", 1201 ); + // pcpInfo = (PMIMECPINFO)CoTaskMemAlloc( sizeof(MIMECPINFO) ); + + for ( i = 0; i < cnum; i++ ) + { + err = pEnumCodePage->lpVtbl->Next( pEnumCodePage, 1, &cpInfo, &ccpInfo ); + + if ( SUCCEEDED( err ) && ( ccpInfo != 0 ) ) + { + if ( copyWideToPString( cpInfo.wszWebCharset, ianaName ) + && copyWideToPString( cpInfo.wszDescription, displayName ) ) + langassignstringvalue( cSetsTable, ianaName, displayName ); + //langassignlongvalue( cSetsTable, ianaName, cpInfo.uiCodePage ); + } + } + + pEnumCodePage->lpVtbl->Release( pEnumCodePage ); + pMultiLanguage->lpVtbl->Release( pMultiLanguage ); + // CoTaskMemFree( (LPVOID) pcpInfo ); + #endif - +#endif +done: return (true); } /* initCharsetsTable */ Modified: Frontier/trunk/Common/source/process.c =================================================================== --- Frontier/trunk/Common/source/process.c 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/source/process.c 2006-04-24 20:02:59 UTC (rev 1328) @@ -1387,6 +1387,11 @@ listunlink ((hdllinkedlist) processthreadlist, (hdllinkedlist) hg); if (hg == hthreadglobals) { + + #ifdef WIN95VERSION + if ( flcominitialized ) + shutdownCOM(); + #endif disposehandle ((Handle) hashtablestack); @@ -1451,6 +1456,12 @@ (**hg).timesliceticks = processonehottimeslice; + /* + 2006-04-24 smd + has COM been initialized in this thread? + */ + (**hg).flcominitialized = false; + #ifdef landinclude id = getprocesscreator (); @@ -1580,6 +1591,12 @@ (**hg).tryerror = tryerror; (**hg).tryerrorstack = tryerrorstack; + + /* + 2006-04-24 smd + has COM been initialized in this thread? + */ + (**hg).flcominitialized = flcominitialized; } (**hg).langcallbacks = langcallbacks; Modified: Frontier/trunk/Common/source/shell.c =================================================================== --- Frontier/trunk/Common/source/shell.c 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/source/shell.c 2006-04-24 20:02:59 UTC (rev 1328) @@ -256,7 +256,7 @@ fileshutdown(); UnregisterAppearanceClient(); #endif - + exittooperatingsystem (); /*doesn't return*/ return (true); /*satisfy the compiler -- not a void function*/ Modified: Frontier/trunk/Common/source/strings.c =================================================================== --- Frontier/trunk/Common/source/strings.c 2006-04-24 01:03:36 UTC (rev 1327) +++ Frontier/trunk/Common/source/strings.c 2006-04-24 20:02:59 UTC (rev 1328) @@ -27,6 +27,7 @@ #include "frontier.h" #include "standard.h" +#include "FrontierWinMain.h" #include "font.h" #include "memory.h" @@ -59,7 +60,7 @@ /* declarations */ static boolean converttextencoding( Handle, Handle, const long, const long ); -static boolean getTextEncodingID( const bigstring, long * ); +static boolean getTextEncodingID( bigstring, long * ); #ifdef WIN95VERSION static HRESULT UnicodeToAnsi(Handle, Handle, unsigned long); @@ -1678,6 +1679,42 @@ } /*parsenumberstring*/ + +#ifdef WIN95VERSION +boolean copyWideToPString( const wchar_t * inString, bigstring bs ) +{ + HRESULT err; + size_t lenOut; + + err = wcstombs_s( &lenOut, bs, 255, inString, _TRUNCATE ); + + if ( FAILED( err ) ) + return (false); + + convertcstring( bs ); + + return (true); +} /* copyWideToPString */ + +boolean copyPStringToWide( bigstring bs, long * lenResult, wchar_t * outString ) +{ + HRESULT err; + size_t lenOut; + + convertpstring( bs ); + + err = mbstowcs_s( &lenOut, outString, 255, (const char *) bs, _TRUNCATE ); + + if ( SUCCEEDED( err ) ) + { + *lenResult = (long) lenOut; + return (true); + } + else + return (false); +} +#endif + void convertpstring (bigstring bs) { /* @@ -2278,14 +2315,14 @@ ULONG cbAnsi, cCharacters; long lentext; - cCharacters = wcslen((const unsigned short*) *h)+1; + cCharacters = wcslen((wchar_t *) *h)+1; cbAnsi = cCharacters * 2; sethandlesize (hresult, cbAnsi); // Convert to ANSI. - lentext = WideCharToMultiByte(encoding, 0,(const unsigned short*) *h, -1, *hresult, + lentext = WideCharToMultiByte( encoding, 0,(wchar_t *) *h, -1, *hresult, cbAnsi, NULL, NULL); sethandlesize (hresult, lentext - 1); @@ -2298,13 +2335,16 @@ { /* - 7.0b42 PBS: convert from Unicode to Ansi. Borrowed from Microsoft sample code. + 7.0b42 PBS: convert from ANSI to Unicode. Borrowed from Microsoft sample code. + + 2006-04-24 smd: + fixed the description in the previous comment line + rewrote most of the function */ ULONG cbUni, cCharacters; long lentext; - unsigned long ix; - char lastch = ' '; + // unsigned long ix; cCharacters = gethandlesize (h); @@ -2316,35 +2356,15 @@ sethandlesize (hresult, cbUni); // Convert to ANSI. - lentext = MultiByteToWideChar (encoding, 0, *h, -1, (unsigned short*) *hresult, cbUni); + lentext = MultiByteToWideChar (encoding, 0, *h, cCharacters, (wchar_t *) *hresult, cbUni); - ix = 0; + if ( lentext > 0 ) /* FIXME: what should we do if lentext is 0, which is an error condition? */ + { + sethandlesize( hresult, ( lentext + 1 ) * 2 ); + ((wchar_t *)(*hresult))[lentext] = L'\0'; + } - while (true) { /*find terminator*/ - - char ch = (*hresult) [ix]; - - if (ch == '\0') { - - if ((*hresult) [ix + 1] == '\0') { - - sethandlesize (hresult, ix + 2); - - break; - } /* if */ - - } /*if*/ - - ix += 2; - - if (ix > cbUni) - break; - - lastch = ch; - } /*while*/ - return NOERROR; - } #endif /*end Windows character conversion routines*/ @@ -2352,7 +2372,7 @@ /* convert an "internet name" for an encoding into a platform-specific id for the character set */ -static boolean getTextEncodingID( const bigstring bsEncodingName, long * encodingId ) { +static boolean getTextEncodingID( bigstring bsEncodingName, long * encodingId ) { #ifdef MACVERSION @@ -2367,6 +2387,48 @@ *encodingId = (long) oneEncoding; #endif + +#ifdef WIN95VERSION + + HRESULT err; + IMultiLanguage2 * pMultiLanguage; + MIMECSETINFO setInfo; + wchar_t ianaName[ 512 ]; + long lenIanaName; + + lowertext( (ptrbyte) (bsEncodingName + 1), (long) bsEncodingName[ 0 ] ); + + if ( equalstrings( bsEncodingName, BIGSTRING ("\x06" "utf-16") ) ) + { + *encodingId = 0; + return (true); + } + + initCOM(); + + err = CoCreateInstance( + &CLSID_CMultiLanguage, + NULL, + CLSCTX_INPROC_SERVER, + &IID_IMultiLanguage2, + (void **) &pMultiLanguage ); + + if ( FAILED( err ) ) + return (false); + + copyPStringToWide( bsEncodingName, &lenIanaName, ianaName ); + + // pSetInfo = (PMIMECSETINFO)CoTaskMemAlloc( sizeof(MIMECSETINFO) ); + + err = pMultiLanguage->lpVtbl->GetCharsetInfo( pMultiLanguage, ianaName, &setInfo ); + if ( FAILED( err ) ) + return (false); + + *encodingId = (long)(setInfo.uiInternetEncoding); + + pMultiLanguage->lpVtbl->Release( pMultiLanguage ); + +#endif return (true); } @@ -2375,20 +2437,14 @@ determine if the specified character set is recognized by the OS bsEncodingName is an IANA-friendly name like "utf-8" , "macintosh", or "iso-8859-1" */ -boolean isTextEncodingAvailable( const bigstring bsEncodingName ) +boolean isTextEncodingAvailable( bigstring bsEncodingName ) { long encodingId; - boolean fl; - fl = getTextEncodingID( bsEncodingName, &encodingId ); - - if ( ! fl ) + if ( ! getTextEncodingID( bsEncodingName, &encodingId ) ) return (false); - if ( encodingId < 0 ) - return (false); - - return (true); + return ( encodingId >= 0 ); } static boolean converttextencoding( Handle h, Handle hresult, const long inputcharset, const long outputcharset) { @@ -2478,14 +2534,15 @@ if ((*h) [0] == '\xFF') pullfromhandle (hresult,0, 1, NULL); /* Pop off the BOM */ + return (true); + default: { lentext = gethandlesize (h); switch ( outputcharset ) { case 0: /* unicode with BOM, not handled as a code page. I Sitll Hatesk Windows (and rrrabbits) */ - if (AnsiToUnicode (h, hresult, inputcharset)) - return (false); + return (!AnsiToUnicode (h, hresult, inputcharset)); default: { Handle htemp; @@ -2524,12 +2581,22 @@ } /*converttextencoding*/ -boolean convertCharset( Handle hString, Handle hresult, const bigstring charsetIn, const bigstring charsetOut ) +boolean convertCharset( Handle hString, Handle hresult, bigstring charsetIn, bigstring charsetOut ) { #ifdef MACVERSION TextEncoding teInputSet, teOutputSet; - + +#endif + +#ifdef WIN95VERSION + + long teInputSet, teOutputSet; + + initCOM(); + +#endif + if ( ! getTextEncodingID( charsetIn, (long *) &teInputSet ) ) { // FIXME: generate error, encoding not available @@ -2542,13 +2609,7 @@ return (false); } - return converttextencoding( hString, hresult, (long) teInputSet, (long) teOutputSet ); - -#endif - -#ifdef WIN95VERSION - -#endif + return ( converttextencoding( hString, hresult, (long) teInputSet, (long) teOutputSet ) ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |