home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / feorphan.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  20.1 KB  |  840 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20.  
  21. #include "prefapi.h"
  22.  
  23. #include "netsdoc.h"
  24. #include "template.h"
  25. #ifdef MOZ_LDAP
  26. #include "dirprefs.h"
  27. #endif
  28. #ifdef MOZ_MAIL_NEWS
  29. #include "compfrm.h"
  30. #endif
  31. #ifdef EDITOR
  32. //#include "edview.h"
  33. #endif
  34.  
  35. #ifdef NSPR20
  36. #include "private/prpriv.h"
  37. #endif
  38.  
  39. // This is the NSPR priority of the main GUI thread (ie. mozilla)
  40.  
  41. #ifndef NSPR20
  42. #ifdef XP_WIN32
  43. #define MOZILLA_THREAD_PRIORITY 15
  44. #else
  45. #define MOZILLA_THREAD_PRIORITY 2
  46. #endif
  47. #else
  48. #ifdef XP_WIN32
  49. #define MOZILLA_THREAD_PRIORITY PR_PRIORITY_NORMAL
  50. #else
  51. #define MOZILLA_THREAD_PRIORITY PR_PRIORITY_LOW
  52. #endif
  53. #endif
  54.  
  55. #if defined(JAVA) || defined(MOCHA)
  56.  
  57. #ifndef XP_PC
  58. #define XP_PC
  59. #endif
  60. #ifdef XP_WIN32
  61. #ifndef HW_THREADS
  62. #define HW_THREADS
  63. #endif
  64. #else
  65. #ifndef SW_THREADS
  66. #define SW_THREADS
  67. #endif
  68. #endif
  69.  
  70. #ifndef X386
  71. #define X386
  72. #endif
  73.  
  74. #include "nspr.h"
  75. #include "java.h"
  76. #endif /* JAVA || MOCHA */
  77.  
  78. #if defined(XP_PC) && !defined(_WIN32)
  79. #ifdef JAVA
  80. extern "C" PR_PUBLIC_API(void) SuspendAllJavaThreads(void);
  81. #endif
  82. #endif
  83.  
  84. // Shared event queue used to pass messages between the java threads and
  85. // the main navigator thread...
  86. extern "C" {
  87. PREventQueue *mozilla_event_queue;
  88. PRThread     *mozilla_thread;
  89. };
  90.  
  91.  
  92. //
  93. // Call layout with the red green and blue values of the current COLORREF
  94. //
  95. MODULE_PRIVATE void
  96. wfe_SetLayoutColor(int type, COLORREF color)
  97. {
  98.  
  99.     uint8 red   = GetRValue(color);
  100.     uint8 green    = GetGValue(color);
  101.     uint8 blue  = GetBValue(color);
  102.  
  103.     LO_SetDefaultColor(type, red, green, blue);
  104.  
  105. }
  106.  
  107. void OpenDraftExit (URL_Struct *url_struct, int/*status*/,MWContext *pContext)
  108. {
  109.     XP_ASSERT (url_struct && pContext);
  110.  
  111.     if (!url_struct) return;
  112.  
  113.     NET_FreeURLStruct ( url_struct );
  114. }
  115.  
  116. #ifdef MOZ_LDAP
  117. // This function handles callbacks for all of the *bad* things which we
  118. // are caching in netscape.h...In general, we should try to move these but
  119. // the mnprefs.cpp & mnwizard.cpp are such a mess that I am punting for now
  120. int PR_CALLBACK
  121. DirServerListChanged(const char *pref, void *data)
  122. {
  123.     CString msg = "abook.nab";
  124.  
  125.     DIR_GetServerPreferences(&theApp.m_directories, msg);
  126.     return TRUE;
  127. }
  128. #endif // MOZ_LDAP
  129.  
  130. // This function handles callbacks for all of the *bad* things which we
  131. // are caching in netscape.h...In general, we should try to move these but
  132. // the mnprefs.cpp & mnwizard.cpp are such a mess that I am punting for now
  133. int PR_CALLBACK
  134. WinFEPrefChangedFunc(const char *pref, void *data)
  135. {
  136.         if (!strcmpi(pref,"browser.startup.homepage")) {
  137.         LPSTR    lpszHomePage = NULL;
  138.  
  139.                 PREF_CopyCharPref("browser.startup.homepage", &lpszHomePage);
  140.         theApp.m_pHomePage = lpszHomePage;
  141.         if (lpszHomePage)
  142.             XP_FREE(lpszHomePage);
  143.  
  144.         } else if (!strcmpi(pref,"browser.cache.directory")) {
  145.         LPSTR    lpszCacheDir;
  146.  
  147.                 PREF_CopyCharPref("browser.cache.directory",&lpszCacheDir);
  148.         theApp.m_pCacheDir = lpszCacheDir;
  149.         if (lpszCacheDir)
  150.             XP_FREE(lpszCacheDir);
  151.         } else if (!strcmpi(pref,"browser.bookmark_location")) {
  152.         LPSTR    lpszPref;
  153.  
  154.                 PREF_CopyCharPref("browser.bookmark_location",&lpszPref);
  155.         theApp.m_pBookmarkFile = lpszPref;
  156.         if (lpszPref)
  157.             XP_FREE(lpszPref);
  158.         }
  159.         else if (!strcmpi(pref,"mime.types.all_defined")) { //Begin CRN_MIME
  160.             fe_UpdateMControlMimeTypes();                
  161.         }//End CRN_MIME
  162.  
  163.     return PREF_NOERROR;
  164. };
  165.  
  166. #ifdef XP_WIN16
  167. /////////////////////////////////////////////////////////////////////////////
  168. // 16-bit RTL helper functions
  169. //
  170. // These functions are used by NSPR to access RTL functions that are
  171. // not available from 16-bit DLLs...  They provide the necessary
  172. // "mov DS, SS" entry prolog to fix "DS == SS" which is assumed
  173. // by the MS RTL...
  174. //
  175. #ifdef DEBUG
  176. extern "C" int _heapchk();
  177. extern "C" {
  178.     extern unsigned long hcCount;
  179.     extern unsigned long hcMallocCount;
  180.     extern unsigned long hcFreeCount;
  181.     extern unsigned long hcLimit;
  182. }
  183.  
  184. static void chk()
  185. {
  186.     static unsigned long checkCount;
  187.  
  188.     if (_heapchk() != _HEAPOK)
  189.         __asm { int 3 }
  190.     hcCount += 1;
  191.     if (hcCount >= hcLimit)
  192.         __asm { int 3 }
  193. }
  194.  
  195. extern "C" static void aFchkstk(void)
  196. {
  197. }
  198.  
  199. #endif
  200.  
  201. #if defined(XP_WIN16)
  202. //  Only used when debug build on win16.
  203. BOOL PR_CALLBACK DefaultBlockingHook(void) {
  204.      MSG msg;
  205.     BOOL ret = FALSE;
  206.  
  207.     /*
  208.      * Only dispatch messages if the current thread is mozilla...
  209.      */
  210.     if (mozilla_thread == PR_CurrentThread()) {
  211.     /* get the next message if any */
  212.     ret = (BOOL)PeekMessage(&msg,NULL,0,0,PM_NOREMOVE);
  213.     /* if we got one, process it */
  214.     if (ret) {
  215.         ret = theApp.NSPumpMessage();
  216.     }
  217.     }
  218.      /* TRUE if we got a message */
  219.      return ret;
  220. }
  221. #endif
  222.  
  223. #ifdef MOZ_USE_MS_MALLOC
  224. /*--------------------------------------------------------------------------*/
  225. /* 32-bit aligned memory management routines                    */
  226. /*--------------------------------------------------------------------------*/
  227. /*                                        */
  228. /* The strategy for aligning memory to 32-bit boundaries is to allocate an  */
  229. /* extra 32-bits for each allocation - A 16-bit header and a 16-bit padding */
  230. /*                                        */
  231. /* If the memory returned from    _fmalloc() is not 32-bit aligned, then the  */
  232. /* pointer is adjusted forward by 2 bytes to correctly align the memory.    */
  233. /* The resulting 2-byte header is initialized to PR_NON_ALIGNED_HEADER.     */
  234. /* There is also an "extra" 2 byte padding at the end of the block which    */
  235. /* are unused.                                    */
  236. /*                                        */
  237. /* If the memory returned from _fmalloc() is already 32-aligned, then the   */
  238. /* pointer is adjusted forward by 4 bytes to maintain alignment.  The first */
  239. /* 2 bytes are filled with a pad value in DEBUG mode and the next 2 bytes   */
  240. /* are initialized to PR_ALIGNED_HEADER                     */
  241. /*                                        */
  242. /*--------------------------------------------------------------------------*/
  243.  
  244. #define PR_HEADER_SIZE        4
  245. #define PR_ALIGNED_PAD        0xDEAD
  246. #define PR_ALIGNED_HEADER    0xAD04
  247. #define PR_NONALIGNED_HEADER    0xAD02
  248.  
  249. #define PR_IS_ALIGNED(p)    ( !(OFFSETOF(p) & 0x03) )
  250. #define PR_GET_HEADER_WORD(p)    ( *((WORD*)(((char *)(p))-2)) )
  251. #define PR_GET_HEADER_PAD(p)    ( *((WORD*)(((char *)(p))-4)) )
  252. #define PR_GET_ROOT(p)        ( (void *)(((unsigned long)(p)) - (unsigned long)(PR_GET_HEADER_WORD(p) & 0x000F)) )
  253.  
  254. //
  255. // This macro verifies that a memory block is 32-bit aligned and contains
  256. // the proper header values...
  257. //
  258. #ifdef DEBUG
  259. #define PR_VALIDATE_BLOCK(p)    ASSERT( PR_IS_ALIGNED(p) );                     \
  260.                 if (p) {                             \
  261.                     if (PR_GET_HEADER_WORD(p) == PR_ALIGNED_HEADER) {         \
  262.                     ASSERT( PR_GET_HEADER_PAD(p) == PR_ALIGNED_PAD );     \
  263.                     } else {                             \
  264.                     ASSERT( PR_GET_HEADER_WORD(p) == PR_NONALIGNED_HEADER ); \
  265.                     }                                 \
  266.                 }
  267. #else
  268. #define PR_VALIDATE_BLOCK(p)
  269. #endif
  270.  
  271. void * malloc(size_t size) {
  272.     char *p;
  273.     /* allocate a 16-bit aligned block of memory */
  274.     p = (char *)_fmalloc(size + PR_HEADER_SIZE);
  275.  
  276.     /* Memory is already 32-bit aligned */
  277.     if ( PR_IS_ALIGNED(p) ) {
  278. #ifdef DEBUG
  279.     *((WORD *)p) = PR_ALIGNED_PAD;
  280. #endif
  281.     p  = ((char *)p) + 2;
  282.     *((WORD *)p) = PR_ALIGNED_HEADER;
  283.  
  284.     }
  285.     /* Align memory to 32-bit boundary */
  286.     else {
  287.     *((WORD *)p) = PR_NONALIGNED_HEADER;
  288.     }
  289.     p  = ((char *)p) + 2;
  290.  
  291.     PR_VALIDATE_BLOCK(p);
  292.     return (void *)p;
  293.  
  294. }
  295.  
  296. void free(void *p) {
  297.     void *h;
  298.  
  299.     if (p) {
  300.     PR_VALIDATE_BLOCK(p);
  301.  
  302.     h = PR_GET_ROOT(p);
  303.     ASSERT( (OFFSETOF(p) - OFFSETOF(h)) <= PR_HEADER_SIZE );
  304.     } else {
  305.     h = NULL;
  306.     }
  307.     _ffree(h);
  308. }
  309.  
  310. void * realloc(void *p, size_t size) {
  311.     size_t old_size;
  312.     void *new_block;
  313.     void *h;
  314.  
  315.     if (p) {
  316.     PR_VALIDATE_BLOCK(p);
  317.  
  318.     h     = PR_GET_ROOT(p);
  319.     old_size = _fmsize(h) - (PR_GET_HEADER_WORD(p) == PR_ALIGNED_HEADER ? 4 : 2);
  320.     ASSERT( (OFFSETOF(p) - OFFSETOF(h)) <= PR_HEADER_SIZE );
  321.     } else {
  322.     h     = NULL;
  323.     old_size = 0;
  324.     }
  325.  
  326.  
  327.     /* allocate a 32-bit aligned block of memory */
  328.     new_block = malloc(size);
  329.  
  330.     if (p && new_block) {
  331.     /* copy the original data into the new block of memory */
  332.     memcpy(new_block, p, (old_size < size ? old_size : size));
  333.     /* free the old block of memory */
  334.     _ffree(h);
  335.     }
  336.  
  337.     p = new_block;
  338.  
  339.     PR_VALIDATE_BLOCK(p);
  340.     return p;
  341. }
  342.  
  343. void * calloc(size_t size, size_t number) {
  344.     void *p;
  345.     long bytes;
  346.  
  347.     bytes = (long)size * (long)number;
  348.     ASSERT(bytes < 0xFFF0L);
  349.  
  350.     /* allocate a 32-bit aligned block of memory */
  351.     p = malloc((size_t)bytes);
  352.  
  353.     if (p) {
  354.     memset(p, 0x00, (size_t)bytes);
  355.     }
  356.     PR_VALIDATE_BLOCK(p);
  357.     return p;
  358. }
  359. #endif
  360. /*--------------------------------------------------------------------------*/
  361.  
  362.  
  363. void * PR_CALLBACK __ns_malloc(size_t size) {
  364.     return malloc(size);
  365. }
  366.  
  367. void PR_CALLBACK __ns_free(void *p) {
  368.     free(p);
  369. }
  370.  
  371. void* PR_CALLBACK __ns_realloc(void *p, size_t size) {
  372.     return realloc(p, size);
  373. }
  374.  
  375. void* PR_CALLBACK __ns_calloc(size_t size, size_t number) {
  376.     return calloc(size, number);
  377. }
  378.  
  379. int PR_CALLBACK __ns_gethostname(char * name, int namelen) {
  380.     return gethostname(name, namelen);
  381. }
  382.  
  383. struct hostent * PR_CALLBACK __ns_gethostbyname(const char * name) {
  384.     return gethostbyname(name);
  385. }
  386.  
  387. struct hostent * PR_CALLBACK __ns_gethostbyaddr(const char * addr, int len, int type) {
  388.     return gethostbyaddr(addr, len, type);
  389. }
  390.  
  391. char* PR_CALLBACK __ns_getenv(const char *varname)
  392. {
  393.     return getenv(varname);
  394. }
  395.  
  396. int PR_CALLBACK __ns_putenv(const char *varname)
  397. {
  398.     return putenv(varname);
  399. }
  400.  
  401. int PR_CALLBACK __ns_auxOutput(const char *string)
  402. {
  403. #ifdef DEBUG
  404.     ::OutputDebugString(string);
  405. #endif
  406.     return 0;
  407. }
  408.  
  409. void PR_CALLBACK __ns_exit(int exitCode)
  410. {
  411.     ASSERT(0);
  412.     exit(exitCode);
  413. }
  414.  
  415. size_t PR_CALLBACK __ns_strftime(char *s, size_t len, const char *fmt, const struct tm *p)
  416. {
  417.     return strftime(s, len, fmt, p);
  418. }
  419.  
  420.  
  421. u_long    PR_CALLBACK __ns_ntohl(u_long netlong)
  422. {
  423.     return ntohl(netlong);
  424. }
  425.  
  426. u_short PR_CALLBACK __ns_ntohs(u_short netshort)
  427. {
  428.     return ntohs(netshort);
  429. }
  430.  
  431. int PR_CALLBACK __ns_closesocket(SOCKET s)
  432. {
  433.     return closesocket(s);
  434. }
  435.  
  436. int PR_CALLBACK __ns_setsockopt(SOCKET s, int level, int optname, const char FAR * optval, int optlen)
  437. {
  438.     return setsockopt(s, level, optname, optval, optlen);
  439. }
  440.  
  441. SOCKET    PR_CALLBACK __ns_socket(int af, int type, int protocol)
  442. {
  443.     return socket(af, type, protocol);
  444. }
  445.  
  446. int PR_CALLBACK __ns_getsockname(SOCKET s, struct sockaddr FAR *name, int FAR * namelen)
  447. {
  448.     return getsockname(s, name, namelen);
  449. }
  450.  
  451. u_long    PR_CALLBACK __ns_htonl(u_long hostlong)
  452. {
  453.     return htonl(hostlong);
  454. }
  455.  
  456. u_short PR_CALLBACK __ns_htons(u_short hostshort)
  457. {
  458.     return htons(hostshort);
  459. }
  460.  
  461. unsigned long PR_CALLBACK __ns_inet_addr(const char FAR * cp)
  462. {
  463.     return inet_addr(cp);
  464. }
  465.  
  466. int PR_CALLBACK __ns_WSAGetLastError(void)
  467. {
  468.     return WSAGetLastError();
  469. }
  470.  
  471. int PR_CALLBACK __ns_connect(SOCKET s, const struct sockaddr FAR *name, int namelen)
  472. {
  473.     return connect(s, name, namelen);
  474. }
  475.  
  476. int PR_CALLBACK __ns_recv(SOCKET s, char FAR * buf, int len, int flags)
  477. {
  478.     return recv(s, buf, len, flags);
  479. }
  480.  
  481. int PR_CALLBACK __ns_ioctlsocket(SOCKET s, long cmd, u_long FAR *argp)
  482. {
  483.     return ioctlsocket(s, cmd, argp);
  484. }
  485.  
  486. int PR_CALLBACK __ns_recvfrom(SOCKET s, char FAR * buf, int len, int flags, struct sockaddr FAR *from, int FAR * fromlen)
  487. {
  488.     return recvfrom(s, buf, len, flags, from, fromlen);
  489. }
  490.  
  491. int PR_CALLBACK __ns_send(SOCKET s, const char FAR * buf, int len, int flags)
  492. {
  493.     return send(s, buf, len, flags);
  494. }
  495.  
  496. int PR_CALLBACK __ns_sendto(SOCKET s, const char FAR * buf, int len, int flags, const struct sockaddr FAR *to, int tolen)
  497. {
  498.     return sendto(s, buf, len, flags, to, tolen);
  499. }
  500.  
  501. SOCKET PR_CALLBACK __ns_accept(SOCKET s, struct sockaddr FAR *addr, int FAR *addrlen)
  502. {
  503.     return accept(s, addr, addrlen);
  504. }
  505.  
  506. int PR_CALLBACK __ns_listen(SOCKET s, int backlog)
  507. {
  508.     return listen(s, backlog);
  509. }
  510.  
  511. int PR_CALLBACK __ns_bind(SOCKET s, const struct sockaddr FAR *addr, int namelen)
  512. {
  513.     return bind(s, addr, namelen);
  514. }
  515.  
  516. int PR_CALLBACK __ns_select(int nfds, fd_set FAR *readfds, fd_set FAR *writefds, fd_set FAR *exceptfds, const struct timeval FAR *timeout)
  517. {
  518.     return select(nfds, readfds, writefds, exceptfds, timeout);
  519. }
  520.  
  521. int PR_CALLBACK __ns_getsockopt(SOCKET s, int level, int optname, char FAR * optval, int FAR *optlen)
  522. {
  523.     return getsockopt(s, level, optname, optval, optlen);
  524. }
  525.  
  526. struct protoent * PR_CALLBACK __ns_getprotobyname(const char FAR * name)
  527. {
  528.     return getprotobyname(name);
  529. }
  530.  
  531. int PR_CALLBACK __ns_WSAAsyncSelect(SOCKET s, HWND hWnd, u_int wMsg,
  532.                                     long lEvent)
  533. {
  534.     return WSAAsyncSelect(s, hWnd, wMsg, lEvent);
  535. }
  536.  
  537.  
  538. void PR_CALLBACK __ns_WSASetLastError(int iError)
  539. {
  540.     WSASetLastError(iError);
  541. }
  542.  
  543. int PR_CALLBACK MozillaNonblockingNetTicklerCallback(void)
  544. {
  545. //    We need to tickle the network and the UI if we
  546. //    are stuck in java networking code.
  547.  
  548.     MSG msg;
  549.  
  550.     if (PR_CurrentThread() == mozilla_thread) {
  551.         /* get the next message if any */
  552.     if (PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) {
  553.         (void) theApp.NSPumpMessage();
  554.             return FALSE;
  555.     }
  556.     }
  557.     return TRUE;
  558. }
  559.  
  560. #endif /* XP_WIN16 */
  561.  
  562. void fe_InitJava()
  563. {
  564. }
  565.  
  566. void fe_InitNSPR(void* stackBase)
  567. {
  568. #ifdef XP_WIN16
  569. #if !defined(NSPR20)
  570. //
  571. // The 16-bit MS RTL prohibits 16-bit DLLs from calling some RTL functions.
  572. //   ie.
  573. //     malloc/free
  574. //     strftime
  575. //     sscanf
  576. //     etc...
  577. // To fix this limitation, function pointers are passed to NSPR which
  578. // route the RTL functions "into the EXE" where the actual RTL function
  579. // is available.  (Oh what a tangled web we weave :-( )
  580. //
  581. static struct PRMethodCallbackStr DLLCallbacks = {
  582.     __ns_malloc,
  583.     __ns_realloc,
  584.     __ns_calloc,
  585.     __ns_free,
  586.     __ns_gethostname,
  587.     __ns_gethostbyname,
  588.     __ns_gethostbyaddr,
  589.     __ns_getenv,
  590.     __ns_putenv,
  591.     __ns_auxOutput,
  592.     __ns_exit,
  593.     __ns_strftime,
  594.  
  595.     __ns_ntohl,
  596.     __ns_ntohs,
  597.     __ns_closesocket,
  598.     __ns_setsockopt,
  599.     __ns_socket,
  600.     __ns_getsockname,
  601.     __ns_htonl,
  602.     __ns_htons,
  603.     __ns_inet_addr,
  604.     __ns_WSAGetLastError,
  605.     __ns_connect,
  606.     __ns_recv,
  607.     __ns_ioctlsocket,
  608.     __ns_recvfrom,
  609.     __ns_send,
  610.     __ns_sendto,
  611.     __ns_accept,
  612.     __ns_listen,
  613.     __ns_bind,
  614.     __ns_select,
  615.     __ns_getsockopt,
  616.     __ns_getprotobyname,
  617.     __ns_WSAAsyncSelect,
  618.     __ns_WSASetLastError
  619.     };
  620.  
  621.     // Perform the 16-bit ONLY callback initialization...
  622.     PR_MDInit(&DLLCallbacks);
  623. #endif    /* NSPR20 */
  624. #endif /* XP_WIN16 */
  625.  
  626. #if defined(JAVA) || defined(MOCHA)
  627. #ifndef NSPR20
  628.     // Initialize the NSPR library
  629.     PR_Init( "mozilla", MOZILLA_THREAD_PRIORITY, 1, stackBase);
  630.  
  631.     mozilla_thread = PR_CurrentThread();
  632. #else
  633.     PR_STDIO_INIT()
  634.     mozilla_thread = PR_CurrentThread();
  635.     PR_SetThreadGCAble();
  636.     PR_SetThreadPriority(mozilla_thread, MOZILLA_THREAD_PRIORITY);
  637.     PL_InitializeEventsLib("mozilla");
  638. #endif
  639. #endif /* JAVA || MOCHA */
  640. }
  641.  
  642. BOOL fe_ShutdownJava()
  643. {
  644.     BOOL bRetval = TRUE;
  645.  
  646. #ifdef JAVA
  647.     bRetval = (LJ_ShutdownJava() == LJJavaStatus_Enabled);
  648. #if defined(XP_PC) && !defined(_WIN32)
  649.     SuspendAllJavaThreads();
  650. #endif
  651. #endif
  652.  
  653.     return(bRetval);
  654. }
  655.  
  656. //
  657. // Register our document icons
  658. //
  659. static const CString strMARKUP_KEY = "NetscapeMarkup";
  660.  
  661. BOOL fe_RegisterOLEIcon ( LPSTR szCLSIDObject,     // Class ID of the Object
  662.                LPSTR szObjectName,    // Human Readable Object Name
  663.                LPSTR szIconPath )     // Path and Index of Icon
  664. {
  665.     HKEY hKey;
  666.     LONG lRes = 0L;
  667.  
  668.     char lpszCLSID[]       = "CLSID";         // OLE Class ID Section of eg DB
  669.     char lpszDefIcon[]     = "\\DefaultIcon"; // Default Icon Subkey
  670.     char lpBuffer[64];                  // Working buffer
  671.  
  672.     // Open the reg db for the "CLSID" key, this top-level key
  673.     // is where OLE2 and other OLE aware apps will look for
  674.     // this information.
  675.  
  676.     lRes = RegOpenKey(HKEY_CLASSES_ROOT, lpszCLSID, &hKey);
  677.  
  678.     if (ERROR_SUCCESS != lRes)
  679.       {
  680.       TRACE("RegOpenKey failed.\n");
  681.       return FALSE;
  682.       }
  683.  
  684.     // Register the Object
  685.  
  686.     // Set the value of the CLSID Entry to the Human Readable
  687.     // name of the Object
  688.  
  689.     lRes = RegSetValue( hKey,
  690.             szCLSIDObject,
  691.             REG_SZ,
  692.             szObjectName,
  693.             lstrlen(szObjectName)
  694.               );
  695.  
  696.     if (ERROR_SUCCESS != lRes)    // bail on failure
  697.       {
  698.       RegCloseKey(hKey);
  699.       return FALSE;
  700.       }
  701.  
  702.     // Build "defaulticon" subkey string  "{ <class id> }\\DefaultIcon"
  703.     lstrcpy (lpBuffer, szCLSIDObject);
  704.     lstrcat (lpBuffer, lpszDefIcon);
  705.  
  706.     // Set Object's default icon entry to point to the
  707.     // default icon for the object
  708.  
  709.     lRes = RegSetValue( hKey,
  710.             lpBuffer,
  711.             REG_SZ,
  712.             szIconPath,
  713.             lstrlen(szIconPath)
  714.               );
  715.  
  716.     if (ERROR_SUCCESS != lRes)    // bail on failure
  717.       {
  718.       RegCloseKey(hKey);
  719.       return FALSE;
  720.       }
  721.  
  722.     // Close the reg db
  723.  
  724.     RegCloseKey(hKey);
  725.  
  726.  
  727. //
  728. //
  729. //
  730.  
  731.     lRes = RegOpenKey(HKEY_CLASSES_ROOT, (const char*)strMARKUP_KEY, &hKey);
  732.  
  733.     if (ERROR_SUCCESS != lRes)
  734.       {
  735.       TRACE("RegOpenKey failed.\n");
  736.       return FALSE;
  737.       }
  738.  
  739.     // Set Object's default icon entry to point to the
  740.     // default icon for the object
  741.  
  742.     lRes = RegSetValue( hKey,
  743.             lpszCLSID,
  744.             REG_SZ,
  745.             szCLSIDObject,
  746.             lstrlen(szCLSIDObject)
  747.               );
  748.  
  749.     if (ERROR_SUCCESS != lRes)    // bail on failure
  750.       {
  751.       RegCloseKey(hKey);
  752.       return FALSE;
  753.       }
  754.  
  755.  
  756.     // Set Object's default icon entry to point to the
  757.     // default icon for the object
  758.  
  759.     lRes = RegSetValue( hKey,
  760.                         "DefaultIcon",
  761.             REG_SZ,
  762.             szIconPath,
  763.             lstrlen(szIconPath)
  764.               );
  765.  
  766.     if (ERROR_SUCCESS != lRes)    // bail on failure
  767.       {
  768.       RegCloseKey(hKey);
  769.       return FALSE;
  770.       }
  771.  
  772.     // Close the reg db
  773.  
  774.     RegCloseKey(hKey);
  775.  
  776.  
  777.  
  778.     return TRUE;
  779. }
  780.  
  781. #if defined(XP_WIN16)
  782. /****************************************************************************/
  783. /*                                        */
  784. /* BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE!  */
  785. /*                                        */
  786. /* The following code is duplicated from ns\modules\applet\src\lj_embed.c   */
  787. /* It is ONLY required for 16-bit until JAVA becomes integrated into the    */
  788. /* build!                                    */
  789. /*                                        */
  790. /* BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE! BEWARE!  */
  791. /*                                        */
  792. /****************************************************************************/
  793. #if defined(MOCHA) && !defined(JAVA)
  794. #include "prevent.h"
  795. #include "prlog.h"
  796.  
  797. PR_LOG_DEFINE(Event);
  798.  
  799. /*
  800.  * There is currently a race between which thread destroys synchronous
  801.  *   events.  See bug 32832 for a full description.
  802.  */
  803. void
  804. LJ_ProcessEvent()
  805. {
  806.     PREvent* event;
  807.  
  808.     for (;;) {
  809.         PR_LOG_BEGIN(Event, debug, ("$$$ getting event\n"));
  810.  
  811.     event = PR_GetEvent(mozilla_event_queue);
  812.     if (event == NULL) {
  813.         return;
  814.     }
  815.  
  816.     if(event->synchronousResult) {
  817.         PR_HandleEvent(event);
  818.             PR_LOG_END(Event, debug, ("$$$ done with sync event\n"));
  819.     }
  820.     else {
  821.         PR_HandleEvent(event);
  822.             PR_LOG_END(Event, debug, ("$$$ done with async event\n"));
  823.         PR_DestroyEvent(event);
  824.     }
  825.  
  826.     }
  827. }
  828. #endif    // MOCHA && !JAVA
  829. #endif    // XP_WIN16
  830.  
  831. #ifdef XP_WIN16
  832. #if defined(NSPR20)
  833. #include "private\prpriv.h"
  834. #endif
  835. void fe_yield(void)
  836. {
  837.     PR_Sleep(PR_INTERVAL_NO_WAIT);
  838. }
  839. #endif
  840.