home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cfe.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  49.9 KB  |  1,509 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. #include "stdafx.h"
  19. #include "msgcom.h"
  20.  
  21. #include "cxabstra.h"
  22.  
  23. #include "xp_thrmo.h"
  24. #include "libi18n.h"    // International function 
  25. #include "template.h"
  26. #include "mainfrm.h"
  27. #include "timer.h"
  28. #include "feselect.h"
  29. #ifdef MOZ_MAIL_NEWS
  30. #include "compfrm.h"
  31. #endif /* MOZ_MAIL_NEWS */
  32. #include "prefapi.h"
  33. #include "fmabstra.h"
  34.  
  35. #ifdef DEBUG_WHITEBOX
  36. #include "qa.h"
  37. #define IS_MAIL_READER(pMWContext)          (pMWContext->type == MWContextMail)
  38. #endif
  39.  
  40. #define IS_MESSAGE_COMPOSE(pMWContext)      (pMWContext->type == MWContextMessageComposition)
  41.  
  42. /* implemented in fenet.cpp */
  43. void FE_DeleteDNSList(MWContext * currentContext);
  44.  
  45. //  All common front end functions.
  46. //  Those needing specific optimizations, should do so here depending upon
  47. //      the type of context.
  48. //  As you will notice below, all functions call a virtual member of the abstract class.
  49. //      These map to the appropriate class implementations at run time.
  50. //  05-01-95    created GAB
  51.  
  52. void CFE_Alert(MWContext *pContext, const char *pMessage)    {
  53.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  54.         //    Don't allow this to happen if the context has been destroyed...
  55.         TRACE("Context %p Destroyed :: Alert Blocking\n", pContext);
  56.         return;
  57.     }
  58.     else if(pMessage)   {
  59.         char *pWinMessage = FE_Windowsify(pMessage);
  60.         if(pWinMessage) {
  61.             //    If the context has ncapi data, have it pass off this information to
  62.             //        external applications first, and see if we pass it on from here.
  63.             BOOL bWeAlert = TRUE;
  64.             if(ABSTRACTCX(pContext)->m_pNcapiUrlData != NULL)    {
  65.                 if(ABSTRACTCX(pContext)->m_pNcapiUrlData->Alert(pWinMessage) != 0)    {
  66.                     bWeAlert = FALSE;
  67.                 }
  68.             }
  69.  
  70.             if(bWeAlert == TRUE)    {
  71.                 ABSTRACTCX(pContext)->Alert(pContext, pWinMessage);
  72.             }
  73.             XP_FREE(pWinMessage);
  74.         }
  75.     }
  76. }
  77.  
  78. void CFE_AllConnectionsComplete(MWContext *pContext)    {
  79.  
  80.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  81.         //    Don't allow this to happen if the context has been destroyed...
  82.         TRACE("Context %p Destroyed :: AllConnectionsComplete Blocking\n", pContext);
  83.         return;
  84.     }
  85.  
  86. #ifdef MOZ_MAIL_NEWS
  87.     if (IS_MESSAGE_COMPOSE(pContext)) {
  88.         MSG_Pane *pPane = MSG_FindPane( pContext, MSG_COMPOSITIONPANE );
  89.         ASSERT( pPane );
  90.         MSG_MailCompositionAllConnectionsComplete ( pPane );
  91.     }
  92.  
  93.     if (NET_IsOffline()) {
  94.         FE_Progress(pContext, szLoadString(IDS_STATUS_OFFLINE));
  95.     } else 
  96. #endif   
  97.     {
  98.         //    Set the progress to be complete.
  99.         FE_Progress(pContext, szLoadString(IDS_DOC_DONE));
  100.     }
  101.  
  102.     ABSTRACTCX(pContext)->AllConnectionsComplete(pContext);
  103.     FE_DeleteDNSList(pContext);
  104.  
  105. #ifdef EDITOR
  106. #ifdef XP_WIN16    
  107.     if( EDT_IS_EDITOR(pContext) ){
  108.         // For some bizzare reason, we don't get proper focus 
  109.         //   when starting an Edit frame+View in Win16
  110.         // This fixes that
  111.         ::SetFocus(PANECX(pContext)->GetPane());
  112.     }
  113. #endif
  114. #endif
  115.  
  116. #ifdef DEBUG_WHITEBOX
  117.     // AfxMessageBox("cfe.cpp: Try Again?");
  118.     if (IS_MAIL_READER(pContext)) {
  119.         if (QATestCaseStarted == FALSE) {
  120.             QADoDeleteMessageEventHandler();
  121.         }
  122.     }
  123. #endif
  124. }
  125.  
  126. void CFE_UpdateStopState(MWContext *pContext)    {
  127.     TRACE("CFE_UpdateStopState(%p)\n", pContext);
  128.  
  129.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  130.         //    Don't allow this to happen if the context has been destroyed...
  131.         TRACE("Context %p Destroyed :: UpdateStopState Blocking\n", pContext);
  132.         return;
  133.     }
  134.     ABSTRACTCX(pContext)->UpdateStopState(pContext);
  135. #ifdef EDITOR
  136. #ifdef XP_WIN16    
  137.     if( EDT_IS_EDITOR(pContext) ){
  138.         // For some bizzare reason, we don't get proper focus 
  139.         //   when starting an Edit frame+View in Win16
  140.         // This fixes that
  141.         ::SetFocus(PANECX(pContext)->GetPane());
  142.     }
  143. #endif
  144. #endif
  145. }
  146.  
  147. void CFE_BeginPreSection(MWContext *pContext)    {
  148.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  149.         //    Don't allow this to happen if the context has been destroyed...
  150.         TRACE("Context %p Destroyed :: BeginPreSection Blocking\n", pContext);
  151.         return;
  152.     }
  153.  
  154.     ABSTRACTCX(pContext)->BeginPreSection(pContext);
  155. }
  156.  
  157. void CFE_SetCallNetlibAllTheTime(MWContext *pContext)
  158. {
  159.     XP_ASSERT(0);  // depricated
  160. }
  161. void XP_SetCallNetlibAllTheTime(MWContext *pContext)
  162. {
  163.     XP_ASSERT(0);  // depricated
  164. }
  165.  
  166. void CFE_ClearCallNetlibAllTheTime(MWContext *pContext)
  167. {
  168.     XP_ASSERT(0);  // depricated
  169. }
  170. void XP_ClearCallNetlibAllTheTime(MWContext *pContext)
  171. {
  172.     XP_ASSERT(0);  // depricated
  173. }
  174.  
  175. void CFE_ClearView(MWContext *pContext, int iView)    {
  176.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  177.         //    Don't allow this to happen if the context has been destroyed...
  178.         TRACE("Context %p Destroyed :: ClearView Blocking\n", pContext);
  179.         return;
  180.     }
  181.  
  182.     ABSTRACTCX(pContext)->ClearView(pContext, iView);
  183. }
  184.  
  185. XP_Bool CFE_Confirm(MWContext *pContext, const char *pConfirmMessage)    {
  186.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  187.         //    Don't allow this to happen if the context has been destroyed...
  188.         TRACE("Context %p Destroyed :: Confirm Blocking\n", pContext);
  189.         return(FALSE);
  190.     }
  191.  
  192.     char *pWinConfirmMessage = FE_Windowsify(pConfirmMessage);
  193.  
  194.     //    If the context has ncapi data, have it pass off this information to
  195.     //        external applications first, and see if we pass it on from here.
  196.     BOOL bWeConfirm = TRUE;
  197.     XP_Bool bReturn;
  198.     if(ABSTRACTCX(pContext)->m_pNcapiUrlData != NULL)    {
  199.         bReturn = ABSTRACTCX(pContext)->m_pNcapiUrlData->Confirm(pWinConfirmMessage);
  200.         if(bReturn == TRUE || bReturn == FALSE)    {
  201.             bWeConfirm = FALSE;
  202.         }
  203.     }
  204.  
  205.     if(bWeConfirm == TRUE)    {
  206.         bReturn = ABSTRACTCX(pContext)->Confirm(pContext, pWinConfirmMessage);
  207.     }
  208.  
  209.     XP_FREE(pWinConfirmMessage);
  210.     return(bReturn);
  211. }
  212.  
  213. MWContext *CFE_CreateNewDocWindow(MWContext *pContext, URL_Struct *pURL)    {
  214.     if(pContext != NULL)    {
  215.         if(ABSTRACTCX(pContext)->IsDestroyed())    {
  216.             TRACE("Context %p Destroyed :: CreateNewDocWindow Blocking\n", pContext);
  217.             //    Don't allow this to happen if the context has been destroyed...
  218.             return(NULL);
  219.         }
  220.  
  221.         MWContext *pRetval = ABSTRACTCX(pContext)->CreateNewDocWindow(pContext, pURL);
  222.         if(pRetval != NULL)    {
  223.             return(pRetval);
  224.         }
  225.     }
  226.  
  227.     //    Regardless of the type of context we currently are, we are going to
  228.     //        create a new CMainFrame.
  229.     //    The contexts can do whatever they want in the derived class, but this is
  230.     //        the base implementation.  If they return a context, then we won't do this.
  231.  
  232.     //    Cause a frame to open.
  233.     if(NULL == theApp.m_ViewTmplate->OpenDocumentFile(NULL))    {
  234.         return(NULL);
  235.     }
  236.  
  237.     //    The new frame will be the last one in the application's frame list.
  238.     CMainFrame *pFrame;
  239.     CGenericFrame *pGenFrame;
  240.     for(pGenFrame = theApp.m_pFrameList; pGenFrame->m_pNext; pGenFrame = pGenFrame->m_pNext) {
  241.         /* No Body */;
  242.     }
  243.     
  244.     pFrame = (CMainFrame *) pGenFrame;
  245.     MWContext *pNewContext = pFrame->GetMainContext()->GetContext();
  246.  
  247.     //    Appropriate assignment of options/prefs can only happen if we are also
  248.     //        owned by a CMainFrame, check.
  249.     if(pContext != NULL) {
  250.         if (ABSTRACTCX(pContext)->IsFrameContext() && pContext->type == MWContextBrowser)    {
  251.         //    Assign over our options.
  252.  
  253.         //    Toolbars...
  254.             LPNSTOOLBAR pIToolBar = NULL;
  255.             pFrame->GetChrome()->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  256.             if ( pIToolBar ) {
  257.                 pIToolBar->Release();
  258.             }
  259.  
  260.             //    Directory buttons and location box and Default Encoding.
  261.             pFrame->GetChrome()->ShowToolbar(ID_LOCATION_TOOLBAR, pFrame->m_bLocationBar );
  262.             pFrame->m_iCSID = INTL_DefaultDocCharSetID(pContext);
  263.         }
  264.  
  265.         //    Set the miscellaneous XP context properties.
  266.  
  267.         pNewContext->fancyFTP = pContext->fancyFTP;    
  268.         pNewContext->fancyNews = pContext->fancyNews;
  269.  
  270.         //    Copy the session history over ONLY if called from a Browser
  271.         if(pContext->type == MWContextBrowser && !EDT_IS_EDITOR(pContext))  {
  272.             SHIST_CopySession(pNewContext, pContext);
  273.         }
  274.     }
  275.  
  276.     //    If there was no URL specified to load, load what's in the history.
  277.     //    Only take URLs from a browser window.
  278.     if(pURL == NULL)    {
  279.         //  Make sure we're coming from a context we understand, otherwise get out now.
  280.         if(pContext == NULL || EDT_IS_EDITOR(pContext) || pContext->type != MWContextBrowser)   {
  281.             //  In this case, load the home page.
  282.             pFrame->OnLoadHomePage();
  283.         }
  284.         else    {
  285.             //    Load the oldest thing in it's history (most likely the home page).
  286.             //  This current entry was set above, all we have to do is go through
  287.             //      the motions of a reload.
  288.             ABSTRACTCX(pNewContext)->Reload();
  289.         }
  290.     }
  291.     else if(pURL != NULL)    {
  292.         //    Load the URL passed into this function.
  293.         ABSTRACTCX(pNewContext)->GetUrl(pURL, FO_CACHE_AND_PRESENT);
  294.     }
  295.  
  296.     //    New frame window up, and filled out appropriately.
  297.     return(pNewContext);
  298. }
  299.  
  300. #ifdef EDITOR
  301. MWContext *FE_CreateNewEditWindow(MWContext *pContext, URL_Struct *pURL)    {
  302.     if(pContext != NULL)    {
  303.         if(ABSTRACTCX(pContext)->IsDestroyed())    {
  304.             TRACE("Context %p Destroyed :: CreateNewDocWindow Blocking\n", pContext);
  305.             //    Don't allow this to happen if the context has been destroyed...
  306.             return(NULL);
  307.         }
  308.  
  309.         MWContext *pRetval = ABSTRACTCX(pContext)->CreateNewDocWindow(pContext, pURL);
  310.         if(pRetval != NULL)    {
  311.             return(pRetval);
  312.         }
  313.     }
  314.  
  315.     //    Regardless of the type of context we currently are, we are going to
  316.     //        create a new CMainFrame.
  317.     //    The contexts can do whatever they want in the derived class, but this is
  318.     //        the base implementation.  If they return a context, then we won't do this.
  319.  
  320.     //    Cause a frame to open.
  321.     if(NULL == theApp.m_EditTmplate->OpenDocumentFile(NULL))    {
  322.         return(NULL);
  323.     }
  324.  
  325.     //    The new frame will be the last one in the application's frame list.
  326.     CMainFrame *pFrame;
  327.     CGenericFrame *pGenFrame;
  328.     for(pGenFrame = theApp.m_pFrameList; pGenFrame->m_pNext; pGenFrame = pGenFrame->m_pNext) {
  329.         /* No Body */;
  330.     }
  331.     
  332.     pFrame = (CMainFrame *) pGenFrame;
  333.     MWContext *pNewContext = pFrame->GetMainContext()->GetContext();
  334.  
  335.     //    Appropriate assignment of options/prefs can only happen if we are also
  336.     //        owned by a CMainFrame, check.
  337.     if(pContext != NULL && ABSTRACTCX(pContext)->IsFrameContext() && 
  338.        pContext->type == MWContextBrowser){
  339.         pFrame->m_iCSID = INTL_DefaultDocCharSetID(pContext);
  340.     }
  341.  
  342.     //    Set the miscellaneous XP context properties.
  343.     if(pContext != NULL)    {
  344.         pNewContext->fancyFTP = pContext->fancyFTP;    
  345.         pNewContext->fancyNews = pContext->fancyNews;
  346.  
  347.         //    Copy the session history over.
  348.         SHIST_CopySession(pNewContext, pContext);
  349.     }
  350.  
  351.     //    If there was no URL specified to load, load what's in the history.
  352.     //    Only take URLs from a browser window.
  353.     if(pURL == NULL)    {
  354.         //    Load the oldest thing in it's history (most likely the home page).
  355.         XP_List *pOldest = SHIST_GetList(pNewContext);
  356.         History_entry *pEntry = (History_entry *)XP_ListNextObject(pOldest);
  357.         if(pEntry == NULL)    {
  358.             //    Nothing to load, we're done.
  359.             return(pNewContext);
  360.         }
  361.  
  362.         //    don't load from non browser windows.
  363.         if(pContext == NULL || pContext->type == MWContextBrowser || pContext->type == MWContextPane)    {
  364.             URL_Struct *pUrl = SHIST_CreateURLStructFromHistoryEntry(pContext ? pContext : pNewContext, pEntry);
  365.             if(pUrl == NULL)    {
  366.                 //    Nothing to load?  we're done.
  367.                 return(pNewContext);
  368.             }
  369.  
  370.             //    Set the current session history for the new context.
  371.             SHIST_SetCurrent(&(pNewContext->hist), 0);
  372.  
  373.             //    finally Load it.
  374.             ABSTRACTCX(pNewContext)->GetUrl(pUrl, FO_CACHE_AND_EDIT);
  375.         }
  376.     }
  377.     else if(pURL != NULL)    {
  378.         //    Load the URL passed into this function.
  379.         ABSTRACTCX(pNewContext)->GetUrl(pURL, FO_CACHE_AND_EDIT);
  380.     }
  381.  
  382.     //    New frame window up, and filled out appropriately.
  383.     return(pNewContext);
  384. }
  385.  
  386. #endif    //EDITOR
  387.  
  388. void CFE_DisplayBullet(MWContext *pContext, int iLocation, LO_BullettStruct *pBullet)    {
  389.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  390.         //    Don't allow this to happen if the context has been destroyed...
  391.         TRACE("Context %p Destroyed :: DisplayBullet Blocking\n", pContext);
  392.         return;
  393.     }
  394.  
  395.     ABSTRACTCX(pContext)->DisplayBullet(pContext, iLocation, pBullet);
  396. }
  397.  
  398. void CFE_DisplayEdge(MWContext *pContext, int iLocation, LO_EdgeStruct *pEdge)    {
  399.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  400.         //    Don't allow this to happen if the context has been destroyed...
  401.         TRACE("Context %p Destroyed :: DisplayEdge Blocking\n", pContext);
  402.         return;
  403.     }
  404.  
  405.     ABSTRACTCX(pContext)->DisplayEdge(pContext, iLocation, pEdge);
  406. }
  407.  
  408. void CFE_DisplayEmbed(MWContext *pContext, int iLocation, LO_EmbedStruct *pEmbed)    {
  409.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  410.         //    Don't allow this to happen if the context has been destroyed...
  411.         TRACE("Context %p Destroyed :: DisplayEmbed Blocking\n", pContext);
  412.         return;
  413.     }
  414.  
  415.     ABSTRACTCX(pContext)->DisplayEmbed(pContext, iLocation, pEmbed);
  416. }
  417.  
  418. void CFE_DisplayFormElement(MWContext *pContext, int iLocation, LO_FormElementStruct *pFormElement)    {
  419.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  420.         //    Don't allow this to happen if the context has been destroyed...
  421.         TRACE("Context %p Destroyed :: DisplayFormElement Blocking\n", pContext);
  422.         return;
  423.     }
  424.  
  425.     ABSTRACTCX(pContext)->DisplayFormElement(pContext, iLocation, pFormElement);
  426. }
  427.  
  428. void CFE_DisplayBorder(MWContext *pContext, int iLocation, int x, int y, int width, int height, int bw, LO_Color *color, LO_LineStyle style)    {
  429.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  430.         //    Don't allow this to happen if the context has been destroyed...
  431.         TRACE("Context %p Destroyed :: DisplayBorder Blocking\n", pContext);
  432.         return;
  433.     }
  434.  
  435.     ABSTRACTCX(pContext)->DisplayBorder(pContext, iLocation, x, y, width, height, bw, color, style);
  436. }
  437.  
  438. void CFE_DisplayFeedback(MWContext *pContext, int iLocation, LO_Element *pElement)    {
  439.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  440.         //    Don't allow this to happen if the context has been destroyed...
  441.         TRACE("Context %p Destroyed :: DisplayFeedback Blocking\n", pContext);
  442.         return;
  443.     }
  444.  
  445.     ABSTRACTCX(pContext)->DisplayFeedback(pContext, iLocation, pElement);
  446. }
  447.  
  448. void CFE_DisplayHR(MWContext *pContext, int iLocation, LO_HorizRuleStruct *pHorizRule)    {
  449.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  450.         TRACE("Context %p Destroyed :: DisplayHR Blocking\n", pContext);
  451.         //    Don't allow this to happen if the context has been destroyed...
  452.         return;
  453.     }
  454.  
  455.     ABSTRACTCX(pContext)->DisplayHR(pContext, iLocation, pHorizRule);
  456. }
  457. void CFE_DisplayJavaApp(MWContext *pContext, int iLocation, LO_JavaAppStruct *pJava)    {
  458.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  459.         TRACE("Context %p Destroyed :: DisplayJavaApp Blocking\n", pContext);
  460.         return;
  461.     }
  462.  
  463.     ABSTRACTCX(pContext)->DisplayJavaApp(pContext, iLocation, pJava);
  464. }
  465.  
  466. void CFE_DisplayLineFeed(MWContext *pContext, int iLocation, LO_LinefeedStruct *pLineFeed, XP_Bool iClear)    {
  467.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  468.         //    Don't allow this to happen if the context has been destroyed...
  469.         TRACE("Context %p Destroyed :: DisplayLineFeed Blocking\n", pContext);
  470.         return;
  471.     }
  472.  
  473.     ABSTRACTCX(pContext)->DisplayLineFeed(pContext, iLocation, pLineFeed, iClear);
  474. }
  475.  
  476. void CFE_DisplaySubDoc(MWContext *pContext, int iLocation, LO_SubDocStruct *pSubDoc)    {
  477.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  478.         //    Don't allow this to happen if the context has been destroyed...
  479.         TRACE("Context %p Destroyed :: DisplaySubDoc Blocking\n", pContext);
  480.         return;
  481.     }
  482.  
  483.     ABSTRACTCX(pContext)->DisplaySubDoc(pContext, iLocation, pSubDoc);
  484. }
  485.  
  486. void CFE_DisplayCell(MWContext *pContext, int iLocation, LO_CellStruct *pCell)    {
  487.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  488.         //    Don't allow this to happen if the context has been destroyed...
  489.         TRACE("Context %p Destroyed :: DisplayCell Blocking\n", pContext);
  490.         return;
  491.     }
  492.  
  493.     ABSTRACTCX(pContext)->DisplayCell(pContext, iLocation, pCell);
  494. }
  495. void CFE_DisplaySubtext(MWContext *pContext, int iLocation, LO_TextStruct *pText, int32 lStartPos, int32 lEndPos, XP_Bool iClear)    {
  496.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  497.         //    Don't allow this to happen if the context has been destroyed...
  498.         TRACE("Context %p Destroyed :: DisplaySubtext Blocking\n", pContext);
  499.         return;
  500.     }
  501.  
  502.     ABSTRACTCX(pContext)->DisplaySubtext(pContext, iLocation, pText, lStartPos, lEndPos, iClear);
  503. }
  504.  
  505. void CFE_DisplayTable(MWContext *pContext, int iLocation, LO_TableStruct *pTable)    {
  506.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  507.         //    Don't allow this to happen if the context has been destroyed...
  508.         TRACE("Context %p Destroyed :: DisplayTable Blocking\n", pContext);
  509.         return;
  510.     }
  511.  
  512.     ABSTRACTCX(pContext)->DisplayTable(pContext, iLocation, pTable);
  513. }
  514.  
  515. void CFE_DisplayText(MWContext *pContext, int iLocation, LO_TextStruct *pText, XP_Bool iClear)   {
  516.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  517.         //    Don't allow this to happen if the context has been destroyed...
  518.         TRACE("Context %p Destroyed :: DisplayText Blocking\n", pContext);
  519.         return;
  520.     }
  521.  
  522.     ABSTRACTCX(pContext)->DisplayText(pContext, iLocation, pText, iClear);
  523. }
  524.  
  525. void CFE_EnableClicking(MWContext *pContext)    {
  526.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  527.         //    Don't allow this to happen if the context has been destroyed...
  528.         TRACE("Context %p Destroyed :: EnableClicking Blocking\n", pContext);
  529.         return;
  530.     }
  531.  
  532.     //    Enable clicking now.
  533.     if(pContext->waitingMode)   {
  534.         pContext->waitingMode = FALSE;
  535.  
  536.         ABSTRACTCX(pContext)->EnableClicking(pContext);
  537.     }
  538. }
  539.  
  540. void CFE_EndPreSection(MWContext *pContext)    {
  541.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  542.         //    Don't allow this to happen if the context has been destroyed...
  543.         TRACE("Context %p Destroyed :: EndPreSection Blocking\n", pContext);
  544.         return;
  545.     }
  546.  
  547.     ABSTRACTCX(pContext)->EndPreSection(pContext);
  548. }
  549.  
  550. #ifdef LAYERS
  551. void CFE_EraseBackground(MWContext *pContext, int iLocation, int32 x, int32 y, uint32 width, uint32 height, LO_Color *pColor)    {
  552.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  553.         //    Don't allow this to happen if the context has been destroyed...
  554.         TRACE("Context %p Destroyed :: EraseBackground Blocking\n", pContext);
  555.         return;
  556.     }
  557.  
  558.     ABSTRACTCX(pContext)->EraseBackground(pContext, iLocation, x, y, width, height, pColor);
  559. }
  560. void CFE_SetDrawable(MWContext *pContext, CL_Drawable *drawable)
  561. {
  562.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  563.     //    Don't allow this to happen if the context has been destroyed...
  564.     TRACE("Context %p Destroyed :: SetDrawable Blocking\n", pContext);
  565.     return;
  566.     }
  567.  
  568.     ABSTRACTCX(pContext)->SetDrawable(pContext, drawable);
  569. }
  570. #endif
  571.  
  572. /* java specific functions to allow delayed window creation and transparency */
  573. void CFE_HandleClippingView(MWContext *pContext, LJAppletData *appletD, int x, int y, int width, int height) {
  574.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  575.         //    Don't allow this to happen if the context has been destroyed...
  576.         TRACE("Context %p Destroyed :: HandleClippingView Blocking\n", pContext);
  577.         return;
  578.     }
  579.  
  580.     WINCX(pContext)->HandleClippingView(pContext, appletD, x, y, width, height);
  581. }
  582.  
  583. void CFE_DrawJavaApp(MWContext *pContext, int iLocation, LO_JavaAppStruct *pJava) {
  584.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  585.     //    Don't allow this to happen if the context has been destroyed...
  586.     TRACE("Context %p Destroyed :: DrawJavaApp Blocking\n", pContext);
  587.     return;
  588.     }
  589.  
  590.     WINCX(pContext)->DrawJavaApp(pContext, iLocation, pJava);
  591. }
  592.  
  593. int CFE_FileSortMethod(MWContext *pContext)    {
  594.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  595.         //    Don't allow this to happen if the context has been destroyed...
  596.         TRACE("Context %p Destroyed :: FileSortMethod Blocking\n", pContext);
  597.         return(-1);
  598.     }
  599.  
  600.     return(ABSTRACTCX(pContext)->FileSortMethod(pContext));
  601. }
  602.  
  603. extern char *EDT_NEW_DOC_NAME;
  604.  
  605. void CFE_FinishedLayout(MWContext *pContext)    {
  606.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  607.         //    Don't allow this to happen if the context has been destroyed...
  608.         TRACE("Context %p Destroyed :: FinishedLayout Blocking\n", pContext);
  609.         return;
  610.     }
  611.  
  612.     //    Let the image library no that the page is no longer loading.
  613. //    IL_EndPage(pContext);
  614.     ABSTRACTCX(pContext)->FinishedLayout(pContext);
  615.  
  616.     //    See if the history title has been set yet.
  617.     History_entry *pHist = SHIST_GetCurrent(&(pContext->hist));
  618.  
  619.     // Message compose window title is set by msglib. We don't want to overwrite
  620.     // it here. - kamal
  621.     if (pHist != NULL && pHist->title == NULL && 
  622.        ( pContext->type == MWContextBrowser || pContext->type == MWContextEditor || pContext->type == MWContextPane) )    {
  623.         //    Make the URL the window title if there was none supplied.
  624.         //  unless its a new document -- leave that one blank
  625.         if(pContext->title == NULL)    {
  626. #ifdef EDITOR
  627.             if ( EDT_IS_EDITOR( pContext ) && 
  628.                  _stricmp(pHist->address, EDT_NEW_DOC_NAME) != 0 ){
  629.                 // Let CWinCX::SetDocTitle() do name condensing for display,
  630.                 //  so editor can detect cases where Title = Address
  631.                 FE_SetDocTitle(pContext, pHist->address);
  632.                 return;
  633.             }
  634. #endif //EDITOR
  635.             CString csTitle = pHist->address;
  636.             WFE_CondenseURL(csTitle, 50, FALSE);
  637.             FE_SetDocTitle(pContext, (char *)(const char *)csTitle);
  638.         }
  639.     }
  640. }
  641.  
  642. void CFE_FormTextIsSubmit(MWContext *pContext, LO_FormElementStruct *pFormElement)    {
  643.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  644.         //    Don't allow this to happen if the context has been destroyed...
  645.         TRACE("Context %p Destroyed :: FormTextIsSubmit Blocking\n", pContext);
  646.         return;
  647.     }
  648.  
  649.     ABSTRACTCX(pContext)->FormTextIsSubmit(pContext, pFormElement);
  650. }
  651.  
  652. void CFE_FreeEdgeElement(MWContext *pContext, LO_EdgeStruct *pEdge)    {
  653.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  654.         //    Don't allow this to happen if the context has been destroyed...
  655.         TRACE("Context %p Destroyed :: FreeEdgeElement Blocking\n", pContext);
  656.         return;
  657.     }
  658.  
  659.     ABSTRACTCX(pContext)->FreeEdgeElement(pContext, pEdge);
  660. }
  661.  
  662. void
  663. CFE_CreateEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp) {
  664.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  665.         //    Don't allow this to happen if the context has been destroyed...
  666.         TRACE("Context %p Destroyed :: CreateEmbedWindow Blocking\n", pContext);
  667.         return;
  668.     }
  669.  
  670.     ABSTRACTCX(pContext)->CreateEmbedWindow(pContext, pApp);
  671. }
  672.  
  673. void
  674. CFE_SaveEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp) {
  675.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  676.         //    Don't allow this to happen if the context has been destroyed...
  677.         TRACE("Context %p Destroyed :: SaveEmbedWindow Blocking\n", pContext);
  678.         return;
  679.     }
  680.  
  681.     ABSTRACTCX(pContext)->SaveEmbedWindow(pContext, pApp);
  682. }
  683.  
  684. void
  685. CFE_RestoreEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp) {
  686.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  687.         //    Don't allow this to happen if the context has been destroyed...
  688.         TRACE("Context %p Destroyed :: RestoreEmbedWindow Blocking\n", pContext);
  689.         return;
  690.     }
  691.  
  692.     ABSTRACTCX(pContext)->RestoreEmbedWindow(pContext, pApp);
  693. }
  694.  
  695. void
  696. CFE_DestroyEmbedWindow(MWContext *pContext, NPEmbeddedApp *pApp) {
  697.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  698.         //    Don't allow this to happen if the context has been destroyed...
  699.         TRACE("Context %p Destroyed :: DestroyEmbedWindow Blocking\n", pContext);
  700.         return;
  701.     }
  702.  
  703.     ABSTRACTCX(pContext)->DestroyEmbedWindow(pContext, pApp);
  704. }
  705.  
  706. void CFE_FreeEmbedElement(MWContext *pContext, LO_EmbedStruct *pEmbed)    {
  707.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  708.         //    Don't allow this to happen if the context has been destroyed...
  709.         TRACE("Context %p Destroyed :: FreeEmbedElement Blocking\n", pContext);
  710.         return;
  711.     }
  712.  
  713.     ABSTRACTCX(pContext)->FreeEmbedElement(pContext, pEmbed);
  714. }
  715.  
  716. extern "C" void 
  717. FE_FreeFormElement(MWContext *pContext, LO_FormElementData *pFormElement)    
  718. {
  719.     //    Get our front end form element, and have it do it's thang.
  720.     CFormElement *pFormClass = CFormElement::GetFormElement(NULL, pFormElement);
  721.     if(pFormClass != NULL)
  722.         pFormClass->FreeFormElement(pFormElement);
  723. }
  724.  
  725. extern "C" void 
  726. FE_ReleaseTextAttrFeData(MWContext * pContext, LO_TextAttr *attr)
  727. {
  728.     if( attr )
  729.         attr->FE_Data = NULL;       // cached fonts are released through m_cplCachedFontList
  730. }
  731.  
  732. void CFE_FreeJavaAppElement(MWContext *pContext, LJAppletData *appletD)    {
  733.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  734.         //    Don't allow this to happen if the context has been destroyed...
  735.         TRACE("Context %p Destroyed :: FreeJavaAppElement Blocking\n", pContext);
  736.         return;
  737.     }
  738.  
  739.     WINCX(pContext)->FreeJavaAppElement(pContext, appletD);
  740. }
  741.  
  742. void CFE_HideJavaAppElement(MWContext *pContext, LJAppletData *pJava)    {
  743.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  744.         //    Don't allow this to happen if the context has been destroyed...
  745.         TRACE("Context %p Destroyed :: HideJavaAppElement Blocking\n", pContext);
  746.         return;
  747.     }
  748.  
  749.     WINCX(pContext)->HideJavaAppElement(pContext, pJava);
  750. }
  751.  
  752. void CFE_GetEmbedSize(MWContext *pContext, LO_EmbedStruct *pEmbed, NET_ReloadMethod bReload)    {
  753.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  754.         //    Don't allow this to happen if the context has been destroyed...
  755.         TRACE("Context %p Destroyed :: GetEmbedSize Blocking\n", pContext);
  756.         return;
  757.     }
  758.  
  759.     ABSTRACTCX(pContext)->GetEmbedSize(pContext, pEmbed, bReload);
  760. }
  761.  
  762. void CFE_GetFormElementInfo(MWContext *pContext, LO_FormElementStruct *pFormElement)    {
  763.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  764.         //    Don't allow this to happen if the context has been destroyed...
  765.         TRACE("Context %p Destroyed :: GetFormElementInfo Blocking\n", pContext);
  766.         return;
  767.     }
  768.  
  769.     ABSTRACTCX(pContext)->GetFormElementInfo(pContext, pFormElement);
  770. }
  771.  
  772. void CFE_GetFormElementValue(MWContext *pContext, LO_FormElementStruct *pFormElement, XP_Bool bHidden)    {
  773.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  774.         //    Don't allow this to happen if the context has been destroyed...
  775.         TRACE("Context %p Destroyed :: GetFormElementValue Blocking\n", pContext);
  776.         return;
  777.     }
  778.  
  779.     ABSTRACTCX(pContext)->GetFormElementValue(pContext, pFormElement, bHidden);
  780. }
  781.  
  782. void CFE_GetJavaAppSize(MWContext *pContext, LO_JavaAppStruct *pJava, NET_ReloadMethod bReload)    {
  783.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  784.         //    Don't allow this to happen if the context has been destroyed...
  785.         TRACE("Context %p Destroyed :: GetJavaAppSize Blocking\n", pContext);
  786.         return;
  787.     }
  788.  
  789.     ABSTRACTCX(pContext)->GetJavaAppSize(pContext, pJava, bReload);
  790. }
  791.  
  792. #ifdef LAYERS
  793. void CFE_GetTextFrame(MWContext *pContext, LO_TextStruct *pText,
  794.               int32 start, int32 end, XP_Rect *frame)   {
  795.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  796.         //    Don't allow this to happen if the context has been destroyed...
  797.         TRACE("Context %p Destroyed :: GetTextFrame Blocking\n", pContext);
  798.         return;
  799.     }
  800.  
  801.     ABSTRACTCX(pContext)->GetTextFrame(pContext, pText, start, end, frame);
  802. }
  803. #endif
  804.  
  805. int CFE_GetTextInfo(MWContext *pContext, LO_TextStruct *pText, LO_TextInfo *pTextInfo)    {
  806.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  807.         //    Don't allow this to happen if the context has been destroyed...
  808.         TRACE("Context %p Destroyed :: GetTextInfo Blocking\n", pContext);
  809.         return(-1);
  810.     }
  811.  
  812.     return(ABSTRACTCX(pContext)->GetTextInfo(pContext, pText, pTextInfo));
  813. }
  814.  
  815. void CFE_GraphProgress(MWContext *pContext, URL_Struct *pURL, int32 lBytesReceived, int32 lBytesSinceLastTime, int32 lContentLength)    {
  816.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  817.         //    Don't allow this to happen if the context has been destroyed...
  818.         TRACE("Context %p Destroyed :: GraphProgress Blocking\n", pContext);
  819.         return;
  820.     }
  821.  
  822.     ABSTRACTCX(pContext)->GraphProgress(pContext, pURL, lBytesReceived, lBytesSinceLastTime, lContentLength);
  823.  
  824.     time_t ttCurTime = theApp.GetTime();
  825.     if(ABSTRACTCX(pContext)->ProgressReady(ttCurTime) == TRUE)    {
  826.         const char *pProgress = XP_ProgressText(lContentLength, lBytesReceived, 1, ABSTRACTCX(pContext)->GetElapsedSeconds(ttCurTime) + 1);
  827.         if(pProgress != NULL)    {
  828.             FE_Progress(pContext, pProgress);
  829.  
  830.             //    If the context has ncapi data, have it pass off this information to
  831.             //        external applications too.
  832.             if(ABSTRACTCX(pContext)->m_pNcapiUrlData != NULL)    {
  833.                 ABSTRACTCX(pContext)->m_pNcapiUrlData->MakingProgress(pProgress, CASTINT(lContentLength != 0 ? (lBytesReceived * 100 / lContentLength) % 100 : 0));
  834.             }
  835.         }
  836.     }
  837. }
  838.  
  839. void CFE_GraphProgressDestroy(MWContext *pContext, URL_Struct *pURL, int32 lContentLength, int32 lTotalBytesRead)    {
  840.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  841.         //    Don't allow this to happen if the context has been destroyed...
  842.         TRACE("Context %p Destroyed :: GraphProgressDestroy Blocking\n", pContext);
  843.         return;
  844.     }
  845.  
  846.     ABSTRACTCX(pContext)->GraphProgressDestroy(pContext, pURL, lContentLength, lTotalBytesRead);
  847. }
  848.  
  849. void CFE_GraphProgressInit(MWContext *pContext, URL_Struct *pURL, int32 lContentLength)    {
  850.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  851.         //    Don't allow this to happen if the context has been destroyed...
  852.         TRACE("Context %p Destroyed :: GraphProgressInit Blocking\n", pContext);
  853.         return;
  854.     }
  855.  
  856.     ABSTRACTCX(pContext)->ResetStopwatch();
  857.     ABSTRACTCX(pContext)->GraphProgressInit(pContext, pURL, lContentLength);
  858.  
  859.     //    If the context has ncapi data, have it pass off this information to
  860.     //        external applications too.
  861.     //    Get the data from the URL if available, then from the context....
  862.     CNcapiUrlData *pNcapi = NULL;
  863.     if(pURL != NULL)    {
  864.         pNcapi = NCAPIDATA(pURL);
  865.     }
  866.     if(pContext != NULL && pNcapi == NULL)    {
  867.         pNcapi = ABSTRACTCX(pContext)->m_pNcapiUrlData;
  868.     }
  869.     if(pNcapi != NULL)    {
  870.         pNcapi->InitializeProgress();
  871.     }
  872. }
  873.  
  874. void CFE_LayoutNewDocument(MWContext *pContext, URL_Struct *pURL, int32 *pWidth, int32 *pHeight, int32 *pmWidth, int32 *pmHeight)    {
  875.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  876.         //    Don't allow this to happen if the context has been destroyed...
  877.         TRACE("Context %p Destroyed :: LayoutNewDocument Blocking\n", pContext);
  878.         return;
  879.     }
  880.  
  881.     //    Remove any previous document title.
  882.     if(pContext->title != NULL)    {
  883.         XP_FREE(pContext->title);
  884.         pContext->title = NULL;
  885.     }
  886.  
  887.     //    Remove the default status.
  888.     if(pContext->defaultStatus != NULL)    {
  889.         XP_FREE(pContext->defaultStatus);
  890.         pContext->defaultStatus = NULL;
  891.     }
  892.  
  893.     //  Reset state reported by image context.
  894.     ABSTRACTCX(pContext)->SetImagesLoading(FALSE);
  895.     ABSTRACTCX(pContext)->SetImagesLooping(FALSE);
  896.     ABSTRACTCX(pContext)->SetImagesDelayed(FALSE);
  897.  
  898.     // Reset state reported by mocha image context.
  899.     ABSTRACTCX(pContext)->SetMochaImagesLoading(FALSE);
  900.     ABSTRACTCX(pContext)->SetMochaImagesLooping(FALSE);
  901.     ABSTRACTCX(pContext)->SetMochaImagesDelayed(FALSE);
  902.  
  903.     //    Add the document to the context session history.
  904.     SHIST_AddDocument(pContext, SHIST_CreateHistoryEntry(pURL, NULL));
  905.  
  906.     ABSTRACTCX(pContext)->LayoutNewDocument(pContext, pURL, pWidth, pHeight, pmWidth, pmHeight);
  907.  
  908.     //    Allow clicking now.
  909.     FE_EnableClicking(pContext);
  910. }
  911.  
  912. /* Only call this function from OnMouseMove().  This caches the last
  913.  * message from anywhere but a mouse movement and displays the
  914.  * last message sent whenever it is cleared from the mouse movement.
  915.  */
  916.  
  917. void wfe_Progress(MWContext *pContext, const char *pMessage)    {
  918.     if(pMessage == NULL || *pMessage == '\0')    {
  919.         if(pContext->defaultStatus)    {
  920.             FE_Progress(pContext, pContext->defaultStatus);
  921.         }
  922.         else    {
  923.             FE_Progress(pContext, ABSTRACTCX(pContext)->m_pLastStatus);
  924.         }
  925.     }
  926.     else    {
  927.         ABSTRACTCX(pContext)->Progress(pContext,pMessage);
  928.     }
  929. }
  930.  
  931. void CFE_Progress(MWContext *pContext, const char *pMessage)    {
  932.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  933.         //    Don't allow this to happen if the context has been destroyed...
  934.         TRACE("Context %p Destroyed :: Progress Blocking\n", pContext);
  935.         return;
  936.     }
  937.     
  938.     //  Only allocate a last status if we're not simply passing in the
  939.     //      same last status.
  940.     if (pMessage != ABSTRACTCX(pContext)->m_pLastStatus) {
  941.         //  Free off the old last status.
  942.         if (ABSTRACTCX(pContext)->m_pLastStatus)    {
  943.             XP_FREE(ABSTRACTCX(pContext)->m_pLastStatus);
  944.         }
  945.  
  946.         //  Determine what the last status is depending on the message.
  947.         if (pMessage && *pMessage)   {
  948.             //  Make a copy of the message into last status.
  949.             ABSTRACTCX(pContext)->m_pLastStatus = XP_STRDUP(pMessage);
  950.         }
  951.         else    {
  952.             //  No last status.
  953.             ABSTRACTCX(pContext)->m_pLastStatus = NULL;
  954.         }
  955.     }
  956.  
  957.     //    We may be changing what we show if pMessage is NULL or has no context.
  958.     if(pMessage == NULL || *pMessage == '\0')    {
  959.         //  There is no message string (missing).
  960.         //    If the context has a default string we should show, do that instead.
  961.         if(pContext->defaultStatus && *(pContext->defaultStatus))    {
  962.             FE_Progress(pContext, pContext->defaultStatus);
  963.         }
  964.         else {
  965.             // There was no message text and no default text so it looks like
  966.             //   someone wants the text cleared altogether.
  967.             ABSTRACTCX(pContext)->Progress(pContext, " ");
  968.         }
  969.     }
  970.     else    {
  971.         //  Display the message if present.
  972.         ABSTRACTCX(pContext)->Progress(pContext, pMessage);
  973.     }
  974. }
  975.  
  976. char *CFE_Prompt(MWContext *pContext, const char *pPrompt, const char *pDefault)    {
  977.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  978.         //    Don't allow this to happen if the context has been destroyed...
  979.         TRACE("Context %p Destroyed :: Prompt Blocking\n", pContext);
  980.         return(NULL);
  981.     }
  982.  
  983.     char *pWinPrompt = FE_Windowsify(pPrompt);
  984.     char *pWinDefault = FE_Windowsify(pDefault);
  985.     char *pReturn = ABSTRACTCX(pContext)->Prompt(pContext, pWinPrompt, pWinDefault);
  986.     XP_FREE(pWinPrompt);
  987.     if (pWinDefault)
  988.         XP_FREE(pWinDefault);
  989.     return(pReturn);
  990. }
  991.  
  992. char *CFE_PromptWithCaption(MWContext *pContext, const char *pCaption, const char *pPrompt, const char *pDefault)    {
  993.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  994.         //    Don't allow this to happen if the context has been destroyed...
  995.         TRACE("Context %p Destroyed :: Prompt Blocking\n", pContext);
  996.         return(NULL);
  997.     }
  998.  
  999.     char *pWinPrompt = FE_Windowsify(pPrompt);
  1000.     char *pWinDefault = FE_Windowsify(pDefault);
  1001.     char *pWinCaption = FE_Windowsify(pCaption);
  1002.     char *pReturn = ABSTRACTCX(pContext)->PromptWithCaption(pContext, pWinCaption, pWinPrompt, pWinDefault);
  1003.     XP_FREE(pWinPrompt);
  1004.     if (pWinDefault)
  1005.         XP_FREE(pWinDefault);
  1006.     return(pReturn);
  1007. }
  1008.  
  1009. char *CFE_PromptPassword(MWContext *pContext, const char *pMessage)    {
  1010.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1011.         //    Don't allow this to happen if the context has been destroyed...
  1012.         TRACE("Context %p Destroyed :: PromptPassword Blocking\n", pContext);
  1013.         return(NULL);
  1014.     }
  1015.  
  1016.     char *pWinMessage = FE_Windowsify(pMessage);
  1017.     char *pReturn = ABSTRACTCX(pContext)->PromptPassword(pContext, pWinMessage);
  1018.     XP_FREE(pWinMessage);
  1019.     return(pReturn);
  1020. }
  1021.  
  1022. XP_Bool CFE_PromptUsernameAndPassword(MWContext *pContext, const char *pMessage, char **ppUsername, char **ppPassword)    {
  1023.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1024.         //    Don't allow this to happen if the context has been destroyed...
  1025.         TRACE("Context %p Destroyed :: PromptUsernameAndPassword Blocking\n", pContext);
  1026.         return(FALSE);
  1027.     }
  1028.  
  1029.     char *pWinMessage = FE_Windowsify(pMessage);
  1030.     XP_Bool bReturn = ABSTRACTCX(pContext)->PromptUsernameAndPassword(pContext, pWinMessage, ppUsername, ppPassword);
  1031.     XP_FREE(pWinMessage);
  1032.     return(bReturn);
  1033. }
  1034.  
  1035. void CFE_ResetFormElement(MWContext *pContext, LO_FormElementStruct *pFormElement)    {
  1036.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1037.         //    Don't allow this to happen if the context has been destroyed...
  1038.         TRACE("Context %p Destroyed :: ResetFormElement Blocking\n", pContext);
  1039.         return;
  1040.     }
  1041.  
  1042.     ABSTRACTCX(pContext)->ResetFormElement(pContext, pFormElement);
  1043. }
  1044.  
  1045. void CFE_SetBackgroundColor(MWContext *pContext, uint8 cRed, uint8 cGreen, uint8 cBlue)    {
  1046.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1047.         //    Don't allow this to happen if the context has been destroyed...
  1048.         TRACE("Context %p Destroyed :: SetBackgroundColor Blocking\n", pContext);
  1049.         return;
  1050.     }
  1051.  
  1052.     ABSTRACTCX(pContext)->SetBackgroundColor(pContext, cRed, cGreen, cBlue);
  1053. }
  1054.  
  1055. void CFE_SetDocDimension(MWContext *pContext, int iLocation, int32 lWidth, int32 lLength)    {
  1056.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1057.         //    Don't allow this to happen if the context has been destroyed...
  1058.         TRACE("Context %p Destroyed :: SetDocDimension Blocking\n", pContext);
  1059.         return;
  1060.     }
  1061.  
  1062.     ABSTRACTCX(pContext)->SetDocDimension(pContext, iLocation, lWidth, lLength);
  1063. }
  1064.  
  1065. void CFE_SetDocPosition(MWContext *pContext, int iLocation, int32 lX, int32 lY)    {
  1066.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1067.         //    Don't allow this to happen if the context has been destroyed...
  1068.         TRACE("Context %p Destroyed :: SetDocPosition Blocking\n", pContext);
  1069.         return;
  1070.     }
  1071.  
  1072.     ABSTRACTCX(pContext)->SetDocPosition(pContext, iLocation, lX, lY);
  1073. }
  1074.  
  1075. void CFE_SetDocTitle(MWContext *pContext, char *pTitle)    {
  1076.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1077.         //    Don't allow this to happen if the context has been destroyed...
  1078.         TRACE("Context %p Destroyed :: SetDocTitle Blocking\n", pContext);
  1079.         return;
  1080.     }
  1081.  
  1082.     //    Default implementation allocs a string to put into the context.
  1083.     if(pContext->title != NULL)    {
  1084.         XP_FREE(pContext->title);
  1085.         pContext->title = NULL;
  1086.     }
  1087.  
  1088.     if(pTitle != NULL)    {
  1089.         pContext->title = XP_STRDUP(pTitle);
  1090.     }
  1091.  
  1092.     ABSTRACTCX(pContext)->SetDocTitle(pContext, pTitle);
  1093.  
  1094.     //    Update the session history after calling context class, they may have
  1095.     //        munged the title.
  1096.     SHIST_SetTitleOfCurrentDoc( pContext );
  1097. }
  1098.  
  1099. void CFE_SetFormElementToggle(MWContext *pContext, LO_FormElementStruct *pFormElement, XP_Bool bToggle)    {
  1100.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1101.         //    Don't allow this to happen if the context has been destroyed...
  1102.         TRACE("Context %p Destroyed :: SetFormElementToggle Blocking\n", pContext);
  1103.         return;
  1104.     }
  1105.  
  1106.     ABSTRACTCX(pContext)->SetFormElementToggle(pContext, pFormElement, bToggle);
  1107. }
  1108.  
  1109. void CFE_SetProgressBarPercent(MWContext *pContext, int32 lPercent)    {
  1110.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1111.         //    Don't allow this to happen if the context has been destroyed...
  1112.         TRACE("Context %p Destroyed :: SetProgressBarPercent Blocking\n", pContext);
  1113.         return;
  1114.     }
  1115.  
  1116.     ABSTRACTCX(pContext)->SetProgressBarPercent(pContext, lPercent);
  1117. }
  1118.  
  1119. XP_Bool CFE_ShowAllNewsArticles(MWContext *pContext)    {
  1120.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1121.         //    Don't allow this to happen if the context has been destroyed...
  1122.         TRACE("Context %p Destroyed :: ShowAllNewsArticles Blocking\n", pContext);
  1123.         return(FALSE);
  1124.     }
  1125.  
  1126.     return(ABSTRACTCX(pContext)->ShowAllNewsArticles(pContext));
  1127. }
  1128.  
  1129. char *CFE_TranslateISOText(MWContext *pContext, int iCharset, char *pISOText)
  1130. {
  1131.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1132.         //    Don't allow this to happen if the context has been destroyed...
  1133.         //    Just return what's passed in.
  1134.         TRACE("Context %p Destroyed :: TranslateISOText Blocking\n", pContext);
  1135.         return(pISOText);
  1136.     }
  1137.  
  1138.     return(ABSTRACTCX(pContext)->TranslateISOText(pContext, iCharset, pISOText));
  1139. }
  1140.  
  1141. XP_Bool CFE_UseFancyFTP(MWContext *pContext)    {
  1142.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1143.         //    Don't allow this to happen if the context has been destroyed...
  1144.         TRACE("Context %p Destroyed :: UseFancyFTP Blocking\n", pContext);
  1145.         return(FALSE);
  1146.     }
  1147.  
  1148.     return(ABSTRACTCX(pContext)->UseFancyFTP(pContext));
  1149. }
  1150.  
  1151. XP_Bool CFE_UseFancyNewsgroupListing(MWContext *pContext)    {
  1152.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1153.         //    Don't allow this to happen if the context has been destroyed...
  1154.         TRACE("Context %p Destroyed :: UseFancyNewsgroupListing Blocking\n", pContext);
  1155.         return(FALSE);
  1156.     }
  1157.  
  1158.     return(ABSTRACTCX(pContext)->UseFancyNewsgroupListing(pContext));
  1159. }
  1160.  
  1161. //  Get URL exit routines.
  1162. void CFE_GetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext)  {
  1163.     //    Enable clicking now.
  1164.     FE_EnableClicking(pContext);
  1165.  
  1166.     //    Report any error.
  1167.     if(iStatus < 0 && pUrl->error_msg != NULL)    {
  1168.         FE_Alert(pContext, pUrl->error_msg);
  1169.     }
  1170.  
  1171.     // Make sure the context is still valid. It's possible it's been deleted
  1172.     // out from under us while we were displaying the modal dialog box (and in
  1173.     // a sub-dispatch message loop)
  1174.     if (!XP_IsContextInList(pContext)) {
  1175.         return;
  1176.     }
  1177.  
  1178. #ifdef EDITOR
  1179.     // Do stuff specific to the editor
  1180.     FE_EditorGetUrlExitRoutine(pUrl, iStatus, pContext);
  1181.  
  1182. #ifdef MOZ_MAIL_NEWS
  1183.     if (IS_MESSAGE_COMPOSE(pContext))
  1184.     {
  1185.         CGenericFrame * pFrame = wfe_FrameFromXPContext(pContext);
  1186.         if (pFrame)
  1187.         {
  1188.             CComposeFrame * pCompose = (CComposeFrame*)pFrame;
  1189.             if (pCompose->UseHtml() && !pCompose->Initialized())
  1190.                 pCompose->GoldDoneLoading();
  1191.         }
  1192.     }
  1193. #endif // MOZ_MAIL_NEWS
  1194. #endif //EDITOR
  1195.  
  1196.     ABSTRACTCX(pContext)->GetUrlExitRoutine(pUrl, iStatus, pContext);
  1197.  
  1198.     if(iStatus != MK_CHANGING_CONTEXT)    {
  1199.         //    We autoproduce a title for those contexts which have none.
  1200.         //  Message compose window title is set by msglib. We don't want to overwrite 
  1201.         //  it here. - kamal
  1202.         if(pContext->title == NULL && pUrl->address != NULL &&
  1203.            (pContext->type == MWContextBrowser || pContext->type == MWContextPane) && !EDT_IS_EDITOR(pContext) )    {
  1204.  
  1205.             //    Limit the automatically set titles to 50 chars.
  1206.             CString csTitle = pUrl->address;
  1207.             WFE_CondenseURL(csTitle, 50, FALSE);
  1208.             FE_SetDocTitle(pContext, (char *)(const char *)csTitle);
  1209.         }
  1210.  
  1211.         //    Since a page was loaded, go through all internal contexts and update their
  1212.         //        anchors so that we can have an updated display on all relevant windows.
  1213.         XP_RefreshAnchors();
  1214.  
  1215.         //    If the url has ncapi data, have it pass off this information to
  1216.         //        external applications too (must happen before URL struct is
  1217.         //        freed off (all connections complete).
  1218.         if(NCAPIDATA(pUrl) != NULL)    {
  1219.             NCAPIDATA(pUrl)->EndProgress();
  1220.         }
  1221.  
  1222.         //    Make sure the NCAPI Url data will let us free off the URL.
  1223.         if(NCAPIDATA(pUrl) == NULL || NCAPIDATA(pUrl)->CanFreeUrl() == TRUE)    {
  1224.             FEU_DeleteUrlData(pUrl, NULL);
  1225.             NET_FreeURLStruct(pUrl);
  1226.         }
  1227.     }
  1228. }
  1229.  
  1230. //  Get URL exit routines.
  1231. void CFE_SimpleGetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext)  {
  1232.     if(iStatus != MK_CHANGING_CONTEXT)    {
  1233.         NET_FreeURLStruct(pUrl);
  1234.     }
  1235. }
  1236.  
  1237. void CFE_TextTranslationExitRoutine(PrintSetup *pTextFE)    {
  1238.     //    Enable clicking now.
  1239.     FE_EnableClicking(VOID2CX(pTextFE->carg, CAbstractCX)->GetContext());
  1240.  
  1241.     VOID2CX(pTextFE->carg, CAbstractCX)->TextTranslationExitRoutine(pTextFE);
  1242.  
  1243.     //  Clean up what the CAbstractCX was responsible for allocating.
  1244.     XP_FREE(pTextFE->prefix);
  1245.     XP_FREE(pTextFE->filename);
  1246.     fclose(pTextFE->out);
  1247.  
  1248.     //  Don't remove the print setup.
  1249.     //    It is freed elsewhere by other
  1250.     //        code (TextFE stuff).
  1251. }
  1252.  
  1253. void CFE_GetDocPosition(MWContext * pContext, int iLoc, int32 * pX, int32 * pY)
  1254. {
  1255.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1256.         //    Don't allow this to happen if the context has been destroyed...
  1257.         TRACE("Context %p Destroyed :: GetDocPosition Blocking\n", pContext);
  1258.         return;
  1259.     }
  1260.  
  1261.     ABSTRACTCX(pContext)->GetDocPosition(pContext, iLoc, pX, pY);
  1262. }
  1263.  
  1264. #ifdef LAYERS
  1265. PRBool FE_HandleLayerEvent(MWContext * pContext, CL_Layer * pLayer,
  1266.                CL_Event * pEvent)
  1267. {
  1268.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1269.         //    Don't allow this to happen if the context has been destroyed...
  1270.         TRACE("Context %p Destroyed :: HandleLayerEvent Blocking\n", pContext);
  1271.         return PR_FALSE;
  1272.     }
  1273.  
  1274.     return (PRBool)ABSTRACTCX(pContext)->HandleLayerEvent(pLayer, pEvent);
  1275. }
  1276.  
  1277. PRBool FE_HandleEmbedEvent(MWContext * pContext, LO_EmbedStruct *embed,
  1278.                CL_Event * pEvent)
  1279. {
  1280.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1281.         //    Don't allow this to happen if the context has been destroyed...
  1282.         TRACE("Context %p Destroyed :: HandleEmbedEvent Blocking\n", pContext);
  1283.         return PR_FALSE;
  1284.     }
  1285.  
  1286.     return (PRBool)ABSTRACTCX(pContext)->HandleEmbedEvent(embed, pEvent);
  1287. }
  1288. #endif
  1289. //
  1290. // Scroll the document so the given X, Y coordinate is in view.  Actually
  1291. //   call the scrolling routines here so that we are sure that the form elements
  1292. //   get moved too.
  1293. //
  1294. extern "C" void 
  1295. FE_ScrollDocTo(MWContext * pContext, int iLoc, int32 X, int32 Y)
  1296. {
  1297.     //  Map this directly to SetDocPosition.
  1298.     FE_SetDocPosition(pContext, iLoc, X<0?0:X, Y<0?0:Y);
  1299. }
  1300.  
  1301.     //
  1302. // Scroll the document so the given X, Y coordinate is in view.  Actually
  1303. //   call the scrolling routines here so that we are sure that the form elements
  1304. //   get moved too.
  1305. //
  1306. extern "C" void 
  1307. FE_ScrollDocBy(MWContext * pContext, int iLoc, int32 X, int32 Y)
  1308. {
  1309.     int32 pX, pY;
  1310.  
  1311.     FE_GetDocPosition(pContext, iLoc, &pX, &pY);
  1312.     pX +=X;
  1313.     pY +=Y;
  1314.     
  1315.     FE_SetDocPosition(pContext, iLoc, pX<0?0:pX, pY<0?0:pY);
  1316. }
  1317.  
  1318. extern "C" void
  1319. FE_BackCommand(MWContext *pContext)
  1320. {
  1321.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1322.         //    Don't allow this to happen if the context has been destroyed...
  1323.         TRACE("Context %p Destroyed :: BackCommand Blocking\n", pContext);
  1324.         return;
  1325.     }
  1326.  
  1327.     ABSTRACTCX(pContext)->AllBack();
  1328. }
  1329.  
  1330. extern "C" void
  1331. FE_ForwardCommand(MWContext *pContext)
  1332. {
  1333.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1334.         //    Don't allow this to happen if the context has been destroyed...
  1335.         TRACE("Context %p Destroyed :: ForwardCommand Blocking\n", pContext);
  1336.         return;
  1337.     }
  1338.  
  1339.     ABSTRACTCX(pContext)->AllForward();
  1340. }
  1341.  
  1342. extern "C" void 
  1343. FE_HomeCommand (MWContext *pContext)
  1344. {
  1345.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1346.         //    Don't allow this to happen if the context has been destroyed...
  1347.         TRACE("Context %p Destroyed :: HomeCommand Blocking\n", pContext);
  1348.         return;
  1349.     }
  1350.  
  1351.     ABSTRACTCX(pContext)->GoHome();
  1352. }
  1353.  
  1354. extern "C" void 
  1355. FE_PrintCommand(MWContext *pContext)
  1356. {
  1357.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1358.         //    Don't allow this to happen if the context has been destroyed...
  1359.         TRACE("Context %p Destroyed :: PrintCommand Blocking\n", pContext);
  1360.         return;
  1361.     }
  1362.  
  1363.     ABSTRACTCX(pContext)->PrintContext();
  1364. }
  1365.  
  1366. XP_Bool 
  1367. FE_FindCommand(MWContext *pContext, char* szName, XP_Bool bCaseSensitive, XP_Bool bBackwards,
  1368.                     XP_Bool bWrap)
  1369. {
  1370.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1371.         //    Don't allow this to happen if the context has been destroyed...
  1372.         TRACE("Context %p Destroyed :: FindCommand Blocking\n", pContext);
  1373.         return FALSE;
  1374.     }
  1375.  
  1376.     if (szName)
  1377.         return ABSTRACTCX(pContext)->DoFind(NULL, (const char *)szName, bCaseSensitive, 
  1378.                 !bBackwards, FALSE);
  1379.     else 
  1380.         ABSTRACTCX(pContext)->AllFind(pContext);
  1381.         return FALSE;
  1382.  
  1383. }
  1384.  
  1385. extern "C" void 
  1386. FE_GetWindowOffset(MWContext *pContext, int32 *sx, int32 *sy)
  1387. {
  1388.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1389.         //    Don't allow this to happen if the context has been destroyed...
  1390.         TRACE("Context %p Destroyed :: WindowToScreenXY Blocking\n", pContext);
  1391.         return;
  1392.     }
  1393.  
  1394.     ABSTRACTCX(pContext)->GetWindowOffset(sx, sy);
  1395. }
  1396.  
  1397. extern "C" void FE_Alert(MWContext *pContext, const char *pMsg)
  1398. {
  1399.     if(pContext != NULL)    {
  1400.  
  1401.         // we NEVER want biff to put up an alert
  1402.         if (pContext->type == MWContextBiff)
  1403.             return;
  1404.         if (IS_MESSAGE_COMPOSE(pContext)) {
  1405.             CGenericFrame * pFrame = wfe_FrameFromXPContext(pContext);
  1406.             pFrame->GetChrome()->StopAnimation();
  1407.         }
  1408.         pContext->funcs->Alert(pContext, pMsg);
  1409.     } else    {
  1410.         MessageBox(NULL, pMsg, "Netscape", MB_OK);
  1411.     }
  1412. }
  1413.  
  1414. extern "C" int32 FE_GetContextID(MWContext *pContext)
  1415. {
  1416.     CAbstractCX *pCX = ABSTRACTCX(pContext);
  1417.  
  1418.     if(pCX != NULL)    {
  1419.         return((int32)pCX->GetContextID());
  1420.     }
  1421.     else    {
  1422.         return(XP_DOCID(pContext));
  1423.     }
  1424. }
  1425.  
  1426. extern "C" void FE_UrlChangedContext(URL_Struct *pUrl, MWContext *pOldContext, MWContext *pNewContext)    {
  1427.     //    A Url has changed context.
  1428.     //    We need to mark it in the new context if it has ncapi_data (which we use
  1429.     //        to track such things under windows).
  1430.     if(pUrl->ncapi_data != NULL)    {
  1431.         //    Tell it about the change.
  1432.         CNcapiUrlData *pUrlData = (CNcapiUrlData *)pUrl->ncapi_data;
  1433.         pUrlData->ChangeContext(ABSTRACTCX(pNewContext));
  1434.     }
  1435. }
  1436.  
  1437. extern "C" void FE_UpdateStopState(MWContext *pContext)    {
  1438.  
  1439.     if(ABSTRACTCX(pContext)->IsDestroyed())    {
  1440.         //    Don't allow this to happen if the context has been destroyed...
  1441.         TRACE("Context %p Destroyed :: UpdateStopState Blocking\n", pContext);
  1442.         return;
  1443.     }
  1444.  
  1445.     ABSTRACTCX(pContext)->UpdateStopState(pContext);
  1446. }
  1447.  
  1448. // Called by the security library to indicate that the user has choosen
  1449. // when-to-ask-for-password preferences
  1450. //
  1451. // XXX - jsw - remove me
  1452. void FE_SetPasswordAskPrefs(MWContext *context, int askPW, int timeout)
  1453. {
  1454. }
  1455.  
  1456. static char fixFont[12] = "Courier New";
  1457. static char    propFont[6] = "Arial";
  1458. extern "C" XP_Bool FE_CheckFormTextAttributes(MWContext *context,
  1459.                 LO_TextAttr *oldAttr, LO_TextAttr *newAttr, int32 type)
  1460. {
  1461.     if (oldAttr && newAttr && !oldAttr->font_face)  {
  1462.         memcpy(newAttr,oldAttr, sizeof(LO_TextAttr)); 
  1463.     // setup the text attribute here.
  1464.  
  1465.         CDCCX *pDCCX = CXDC(context);
  1466.         int csid = INTL_DefaultWinCharSetID(context);
  1467.  
  1468.         if (oldAttr->fontmask & LO_FONT_FIXED) {
  1469.             if (csid == CS_LATIN1)  {
  1470.                 newAttr->font_face = fixFont;
  1471.             }
  1472.             else {
  1473.                 newAttr->font_face = (char*)IntlGetUIFixFaceName(csid);
  1474.             }
  1475.         }
  1476.         else {
  1477.             if (csid == CS_LATIN1)  {
  1478.                 // this is a hack, so default Arial font for form element will not look so
  1479.                 // big.
  1480.                 if (newAttr->size > 1);
  1481.                     newAttr->size -=1;
  1482.                 newAttr->font_face = propFont;
  1483.             }
  1484.             else    {
  1485.                 newAttr->font_face = (char*)IntlGetUIPropFaceName(csid);
  1486.             }
  1487.  
  1488.         }
  1489.         newAttr->font_weight = FW_NORMAL;  /* 100, 200, ... 900 */
  1490.         newAttr->FE_Data = NULL;     /* For the front end to store font IDs */
  1491.     return TRUE;
  1492.     }
  1493.     else
  1494.         return FALSE;
  1495.     
  1496. }
  1497.  
  1498. extern "C" XP_Bool FE_IsNetcasterInstalled(void) {
  1499.     return FEU_IsNetcasterAvailable();
  1500. }
  1501.  
  1502. extern "C" void FE_RunNetcaster(MWContext *context) {
  1503.     FEU_OpenNetcaster();
  1504. }
  1505.  
  1506. extern "C" MWContext *FE_IsNetcasterRunning(void) {
  1507.     return theApp.m_pNetcasterWindow;
  1508. }
  1509.