home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CNSContext.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  38.1 KB  |  1,253 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. //    CNSContext.cp
  20.  
  21.  
  22. #include "CNSContext.h"
  23. #include "CNSContextCallbacks.h"
  24. #include "CHTMLView.h"
  25. #ifndef NSPR20
  26. #include "CNetwork.h"
  27. #endif
  28. #include "UStdDialogs.h"
  29. #include "CURLEditField.h"
  30. #include "CMochaHacks.h"
  31.  
  32. #include <LString.h>
  33.  
  34. #include "earlmgr.h"
  35. #include "uprefd.h"
  36. #include "xp.h"
  37. #include "xp_thrmo.h"
  38. #include "shist.h"
  39. #include "glhist.h"
  40. #include "libimg.h"
  41. #include "np.h"
  42. #include "libmime.h"
  43. #include "libi18n.h"
  44. #include "mimages.h"
  45. #include "ufilemgr.h"
  46. #include "java.h"
  47. #include "layers.h"
  48. #include "libevent.h"
  49. #include "uerrmgr.h"
  50. #include "resgui.h"
  51. #include "uapp.h" // for CFrontApp::sHRes and CFrontApp::sVRes
  52. #include "intl_csi.h"
  53.  
  54. #include "mkhelp.h"
  55.  
  56. // FIX ME -- write a CopyAlloc like function that takes a CString
  57. #include "macutil.h"
  58.  
  59. UInt32 CNSContext::sNSCWindowID = 1;        // Unique ID, incremented for each context
  60.  
  61. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  62. //
  63. #pragma mark --- CONSTRUCTION / DESTRUCTION ---
  64. //
  65. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  66.  
  67. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  68. //    Ñ    
  69. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  70.  
  71. CNSContext::CNSContext(MWContextType inType)
  72. :    mLoadRefCount(0)
  73.  
  74. {
  75.     ::memset(&mContext, 0, sizeof(MWContext));
  76.  
  77.     mContext.type = inType;
  78.     mContext.convertPixX = 1;
  79.     mContext.convertPixY = 1;
  80.     
  81.         // ÑÑÑ OK, here's the skinny on this preference.
  82.         // apparently, there *was* this preference for changing
  83.         // the way FTP sites are displayed, but no one can remember
  84.         // there being an actual UI for setting and changing it.
  85.         // and so, there *may* be people out there who are seeing FTP sites
  86.         // in different ways.  For Dogbert, we think the right behavior is
  87.         // to show FTP sites 'fancy' always, and not carry the old value into
  88.         // the new version.
  89.         //
  90.         // ideally we'd like to remove all references to this now defunct
  91.         // preference from all the code, but that's a bit too much work for
  92.         // beta 2 and beyond, so simply setting this value to true is the short
  93.         // term solution.
  94.         //
  95.         // deeje 97-02-07
  96.     mContext.fancyFTP = true;        // CPrefs::GetBoolean(CPrefs::UseFancyFTP);
  97.     
  98.     mContext.fancyNews = CPrefs::GetBoolean(CPrefs::UseFancyNews);
  99.  
  100.     CNSContextCallbacks* theCallbacks = CNSContextCallbacks::GetContextCallbacks();
  101.     Assert_(theCallbacks != NULL);
  102.     mContext.funcs = &(theCallbacks->GetInternalCallbacks());
  103.     
  104.     mContext.fe.realContext = NULL;
  105.     mContext.fe.view = NULL;
  106.     mContext.fe.newContext = this;
  107.     mContext.fe.newView = NULL;
  108.  
  109.     mContext.pHelpInfo = NULL;
  110.  
  111. //    mLoadImagesOverride = false;
  112. //    mDelayImages =     CPrefs::GetBoolean( CPrefs::DelayImages );
  113. //    mIsRepaginating = false;
  114. //    mIsRepaginationPending = false;
  115.     mRequiresClone = false;
  116.     mProgress = NULL;
  117.     
  118.     // Allocate a private i18n record
  119.     mContext.INTL_CSIInfo = INTL_CSICreate();
  120.  
  121.     // 97-09-17 pchen -- Call XP_InitializeContext function
  122.     XP_InitializeContext(&mContext);
  123.     
  124.     // FIX ME!!! need to add unique identifier
  125.     // So why doesn't it work the way it is? (cth)
  126.     fNSCWindowID = sNSCWindowID++;
  127.  
  128.     XP_AddContextToList(&mContext);
  129. //    SHIST_InitSession(&mContext);
  130.     
  131.     // 97-05-09 pkc -- initialize new MWContext field
  132.     mContext.fontScalingPercentage = 1.0;
  133.     
  134.     InitDefaultCSID();
  135.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(&mContext);
  136.     INTL_SetCSIDocCSID(csi, INTL_DefaultDocCharSetID(&mContext));
  137.     INTL_SetCSIWinCSID(csi, INTL_DocToWinCharSetID(INTL_GetCSIDocCSID(csi)));
  138.  
  139.     // 97-05-12 pkc -- initialize XpixelsPerPoint and YpixelsPerPoint
  140.     mContext.XpixelsPerPoint = CFrontApp::sHRes / 72.0;
  141.     mContext.YpixelsPerPoint = CFrontApp::sVRes / 72.0;
  142.     
  143.     NET_CheckForTimeBomb(&mContext);
  144. }
  145.  
  146. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  147. //    Ñ    
  148. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  149.  
  150. // this is a shallow copy.  child contexts are not duplicated.
  151. CNSContext::CNSContext(const CNSContext& inOriginal)
  152. :    mLoadRefCount(0)
  153. {
  154.     ::memset(&mContext, 0, sizeof(MWContext));
  155.  
  156.     mContext.type = inOriginal.mContext.type;
  157.     mContext.convertPixX = inOriginal.mContext.convertPixX;
  158.     mContext.convertPixY = inOriginal.mContext.convertPixY;
  159.     mContext.fancyFTP = inOriginal.mContext.fancyFTP;
  160.     mContext.fancyNews = inOriginal.mContext.fancyNews;
  161.  
  162.     CNSContextCallbacks* theCallbacks = CNSContextCallbacks::GetContextCallbacks();
  163.     Assert_(theCallbacks != NULL);
  164.     mContext.funcs = &(theCallbacks->GetInternalCallbacks());
  165.  
  166.     mContext.fe.realContext = NULL;
  167.     mContext.fe.view = NULL;
  168.     mContext.fe.newContext = this;
  169.     mContext.fe.newView = NULL;
  170.  
  171.     mContext.pHelpInfo = NULL;
  172.  
  173.     // Allocate a private i18n record
  174.     mContext.INTL_CSIInfo = INTL_CSICreate();
  175.  
  176.     // 97-09-17 pchen -- Call XP_InitializeContext function
  177.     XP_InitializeContext(&mContext);
  178.  
  179. //    mLoadImagesOverride = inOriginal.IsLoadImagesOverride();
  180. //    mDelayImages =     inOriginal.IsImageLoadingDelayed();
  181. //    mIsRepaginating = inOriginal.IsRepaginating();
  182. //    mIsRepaginationPending = inOriginal.IsRepagintaitonPending();
  183.  
  184.     mProgress = inOriginal.mProgress;
  185.     if (mProgress != NULL)
  186.         mProgress->AddUser(this);
  187.  
  188.     mRequiresClone = false;
  189. // FIX ME!!! need to make sure all things inited in the default ctor are done here
  190.  
  191.     // 97-05-14 pkc -- whoops, forgot to initialize this here.
  192.     mContext.fontScalingPercentage = inOriginal.mContext.fontScalingPercentage;
  193.  
  194.     // 97-05-12 pkc -- initialize XpixelsPerPoint and YpixelsPerPoint
  195.     mContext.XpixelsPerPoint = inOriginal.mContext.XpixelsPerPoint;
  196.     mContext.YpixelsPerPoint = inOriginal.mContext.YpixelsPerPoint;
  197.  
  198.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(&mContext);
  199.     mDefaultCSID = inOriginal.GetDefaultCSID();
  200.     INTL_SetCSIDocCSID(csi, inOriginal.GetDocCSID());
  201.     INTL_SetCSIWinCSID(csi, inOriginal.GetWinCSID());
  202.     SHIST_InitSession(&mContext);
  203. }
  204.  
  205. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  206. //    Ñ    
  207. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  208.  
  209. static void MochaDone ( CNSContext * context )
  210. {
  211.     delete context;
  212. }
  213.  
  214. CNSContext::~CNSContext()
  215. {        
  216.     CMochaHacks::RemoveReferenceToMouseOverElementContext(&mContext);
  217.     
  218.     // 97-06-06 mjc - remove the context from the global list in NoMoreUsers before calling mocha.
  219.     //XP_RemoveContextFromList(&mContext);
  220.     if (mContext.name != NULL)
  221.         {
  222.         XP_FREE(mContext.name);
  223.         mContext.name = NULL;
  224.         }
  225.         
  226.  
  227.     /* EA: Remove any help information associated with this context */    
  228.      if ((HelpInfoStruct *) mContext.pHelpInfo != NULL) {
  229.          if (((HelpInfoStruct *) mContext.pHelpInfo)->topicURL != NULL) {
  230.              XP_FREE(((HelpInfoStruct *) mContext.pHelpInfo)->topicURL);
  231.              ((HelpInfoStruct *) mContext.pHelpInfo)->topicURL = NULL;
  232.          }
  233.  
  234.           XP_FREE(mContext.pHelpInfo);
  235.           mContext.pHelpInfo = NULL;
  236.      }
  237.  
  238.     if (mContext.INTL_CSIInfo != NULL)
  239.         XP_FREE(mContext.INTL_CSIInfo);
  240.  
  241.     if (CFrontApp::GetApplication()->GetNetcasterContext() == &mContext) {
  242.         CFrontApp::GetApplication()->SetNetcasterContext(NULL);
  243.     }    
  244. }
  245.  
  246. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  247. //    Ñ    
  248. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  249.  
  250. void CNSContext::NoMoreUsers(void)
  251. {
  252.     // 97-06-13 mjc - Make sure applets are destroyed so they don't continue to post events to the mozilla event queue.
  253.     // This must be called before SHIST_EndSession, so java can find the applet context
  254.     // with which to destroy applets. Placing in the same sequence as on Windows.
  255.     LJ_DiscardEventsForContext(&mContext);
  256.     // We would rather to do this here instead of in the destruction 
  257.     // sequence because this call will probably reuslt in some callbacks.
  258.     XP_InterruptContext(&mContext);
  259.     
  260.     // Do most of the work the destructor used to then call mocha to kill itself
  261.     if (mContext.defaultStatus != NULL)
  262.         XP_FREE(mContext.defaultStatus);
  263.     mContext.defaultStatus = NULL;
  264.     
  265.     LO_DiscardDocument(&mContext);
  266.     DestroyImageContext(&mContext);
  267.     SHIST_EndSession(&mContext);
  268.     
  269.     //     Yikes.  Before we dispose of the context, MAKE
  270.     //    SURE THAT IT IS SCOURED.  This uncovered a bug
  271.     //    in grids... disposing of grid contexts did not
  272.     //    remove their entry from the colormap associated
  273.     //    with them.  This never allowed the reference count
  274.     //    on the colormap to go to zero.
  275.     
  276.     //    dkc    1/18/96
  277.  
  278.     FM_SetFlushable(&mContext, FALSE );
  279. #ifdef MOZ_MAIL_NEWS
  280.     MimeDestroyContextData(&mContext);
  281. #endif // MOZ_MAIL_NEWS
  282.  
  283. #if 0 // was: #ifdef LAYERS but the compositor is partly owned by CHTMLView, and so
  284.         // it's now sharable
  285.     if (mContext.compositor != NULL)
  286.         {
  287.         CL_DestroyCompositor(mContext.compositor);
  288.         mContext.compositor = NULL;
  289.         }        
  290. #endif
  291.     // 97-06-06 mjc - remove ourself from the global context list before calling mocha,
  292.     // or else mocha may try to access a partially destroyed context.
  293.     XP_RemoveContextFromList(&mContext);
  294.     // We'll do the deletion in MochaDone(), called back from here.
  295.     ET_RemoveWindowContext( &mContext, (ETVoidPtrFunc) MochaDone, this );
  296. }
  297.  
  298. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  299. //    Ñ    This is another useless banner that takes up space, but this one has text, at least.
  300. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  301.  
  302. void CNSContext::EnsureContextProgress()
  303. {
  304.     if (mProgress == NULL)
  305.     {
  306.         mProgress = new CContextProgress;
  307.         mProgress->AddUser(this);
  308.     }
  309. }
  310.  
  311. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  312. //    Ñ    
  313. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  314.  
  315. CContextProgress* CNSContext::GetContextProgress(void)
  316. {
  317.     return mProgress;
  318. }
  319.  
  320. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  321. //    Ñ    
  322. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  323.  
  324. void CNSContext::SetContextProgress(CContextProgress* inProgress)
  325. {
  326.     Assert_(mProgress == NULL);
  327.     mProgress = inProgress;
  328.     mProgress->AddUser(this);
  329. }
  330.  
  331. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  332. //    Ñ    
  333. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  334.  
  335. cstring CNSContext::GetDescriptor(void) const
  336. {
  337.     cstring theName;
  338.     if (mContext.name != NULL)
  339.         theName = mContext.name;
  340.         
  341.     return theName;
  342. }
  343.  
  344. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  345. //    Ñ    
  346. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  347.  
  348. void CNSContext::SetDescriptor(const char* inDescriptor)
  349. {
  350.     if (mContext.name != NULL)
  351.         XP_FREE(mContext.name);
  352.         
  353.     mContext.name = XP_STRDUP(inDescriptor);
  354.     ThrowIfNULL_(mContext.name);
  355. }
  356.  
  357. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  358. //    Ñ    
  359. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  360.  
  361. void CNSContext::SetRequiresClone(Boolean inClone)
  362. {
  363.     mRequiresClone = inClone;
  364. }
  365.  
  366. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  367. //    Ñ    
  368. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  369.  
  370. Boolean CNSContext::IsCloneRequired(void) const
  371. {
  372.     return mRequiresClone;
  373. }
  374.  
  375. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  376. //    Ñ    
  377. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  378.  
  379. CContextProgress* CNSContext::GetCurrentProgressStats(void)
  380. {
  381.     return mProgress;
  382. }
  383.  
  384. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  385. //    Ñ    
  386. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  387.  
  388. void CNSContext::UpdateCurrentProgressStats(void)
  389. {
  390.     // You shouldn't be calling this when we're not processing something
  391.     Assert_(mProgress != NULL);
  392.     BroadcastMessage(msg_NSCProgressUpdate, mProgress);
  393. }
  394.  
  395. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  396. //
  397. #pragma mark --- CHARACTER SET ACCESSORS ---
  398. //
  399. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  400.  
  401. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  402. //    Ñ    
  403. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  404. extern Int16 DefaultDocCharSetIDFromFrontWindow();
  405.  
  406. void CNSContext::InitDefaultCSID(void)
  407. {
  408.     mDefaultCSID = DefaultDocCharSetIDFromFrontWindow();
  409.     if(0 == mDefaultCSID )
  410.         mDefaultCSID = INTL_DefaultDocCharSetID(0);
  411. }
  412.  
  413. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  414. //    Ñ    
  415. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  416.  
  417. void CNSContext::SetDefaultCSID(Int16 inDefaultCSID)
  418. {
  419.     mDefaultCSID = inDefaultCSID;
  420. }
  421.  
  422. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  423. //    Ñ    
  424. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  425.  
  426. Int16 CNSContext::GetDefaultCSID(void) const
  427. {
  428.     return mDefaultCSID;
  429. }
  430.  
  431. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  432. //    Ñ    
  433. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  434.  
  435. Int16 CNSContext::GetDocCSID(void) const
  436. {
  437.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo((MWContext *)&mContext);
  438.     return INTL_GetCSIDocCSID(csi);
  439. }
  440.  
  441. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  442. //    Ñ    
  443. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  444.  
  445. void CNSContext::SetWinCSID(Int16 inWinCSID)
  446. {
  447.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(&mContext);
  448.     INTL_SetCSIWinCSID(csi, inWinCSID);
  449. }
  450. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  451. //    Ñ    
  452. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  453.  
  454. void CNSContext::SetDocCSID(Int16 inDocCSID)
  455. {
  456.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(&mContext);
  457.     INTL_SetCSIDocCSID (csi, inDocCSID);
  458. }
  459.  
  460.  
  461. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  462. //    Ñ    
  463. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  464.  
  465. Int16 CNSContext::GetWinCSID(void) const
  466. {
  467.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo((MWContext *)&mContext);
  468.     return INTL_GetCSIWinCSID(csi);
  469. }
  470.  
  471. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  472. //    Ñ    
  473. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  474.  
  475. Int16 CNSContext::GetWCSIDFromDocCSID(
  476.     Int16            inDocCSID)
  477. {
  478.     if (inDocCSID == CS_DEFAULT)
  479.         inDocCSID = mDefaultCSID;
  480.         
  481.     return INTL_DocToWinCharSetID(inDocCSID);
  482. }
  483.  
  484. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  485. //
  486. #pragma mark --- STATUS ---
  487. //
  488. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  489.  
  490. const char* CNSContext::GetDefaultStatus(void) const
  491. {
  492.     return mContext.defaultStatus;
  493. }
  494.  
  495. void CNSContext::ClearDefaultStatus()
  496. {
  497.     if (mContext.defaultStatus)
  498.         XP_FREE(mContext.defaultStatus);
  499.     mContext.defaultStatus = NULL;
  500. }
  501.  
  502. void CNSContext::SetStatus(const char* inStatus)
  503. {
  504.     Progress(inStatus);
  505. }
  506.  
  507. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  508. //
  509. #pragma mark --- URL MANIPULATION ---
  510. //
  511. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  512.  
  513. cstring CNSContext::GetCurrentURL(void)
  514. {
  515.     cstring theCurrentURL;
  516.     
  517.     History_entry* theCurrentHist = SHIST_GetCurrent(&mContext.hist);
  518.     if (theCurrentHist != NULL)
  519.         theCurrentURL = theCurrentHist->address;
  520.  
  521.     return theCurrentURL;
  522. }
  523.  
  524. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  525. //    Ñ    
  526. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  527. // PLEASE NOTE THAT THIS ROUTINE FREES THE URL_STRUCT!!!
  528.  
  529. void CNSContext::SwitchLoadURL(
  530.     URL_Struct*                inURL,
  531.     FO_Present_Types        inOutputFormat)
  532. {
  533.     if ((inURL->address != NULL) && XP_STRCMP(inURL->address, "about:document") != 0 /*&& XP_IsContextBusy( this->fHContext ) */)
  534.         XP_InterruptContext(&mContext);
  535.  
  536.     // Don't broadcast the notification that a copy of one or more messages
  537.     // will take place: just forward it to the EarlManager... If we broadcast
  538.     // it through the front-end, the Netscape icon doesn't stop spinning
  539.     // because we receive one more GetURL events than AllConnectionsComplete events.
  540.     if (XP_STRCMP(inURL->address, "mailbox:copymessages") == 0)
  541.     {
  542.         EarlManager::StartLoadURL(inURL, &mContext, inOutputFormat);
  543.         return;
  544.     }
  545.  
  546.     // This is a notification in which all clients are warned that a new URL is
  547.     // going to be loaded.  Any client can nullify the load request by zeroing the ioParam.
  548.     Boolean bAllClientsHappy = true;
  549.     BroadcastMessage(msg_NSCConfirmLoadNewURL, &bAllClientsHappy);
  550.     if (!bAllClientsHappy)
  551.     {
  552.         NET_FreeURLStruct(inURL);
  553.         return;
  554.     }
  555.         
  556.     // Ok, no clients of this context objected to the load request.  We will now
  557.     // notify them that a new load is about to take place.
  558.  
  559.     EnsureContextProgress();
  560.  
  561.     // There are listeners that listen to several contexts (eg, spinning N in mail windows).
  562.     // This works by reference counting, and such listeners assume calls to
  563.     // SwitchLoadURL and AllConnectionsComplete are balanced.  Each context must
  564.     // therefore ensure that they are, even if it is done artificially.
  565.     mLoadRefCount++;
  566.  
  567.     BroadcastMessage(msg_NSCStartLoadURL, inURL);
  568.     
  569.     // if we are going to named anchor, do not load from the net
  570.     Int32 theXPos, theYPos;
  571.     History_entry* theHist = SHIST_GetCurrent(&mContext.hist);
  572.     if ((theHist != NULL)                                                     &&
  573.         (SHIST_GetIndex(&mContext.hist, theHist) != inURL->history_num)        &&    // We are not reloading one page
  574.          (inURL->force_reload == 0)                                            &&
  575.         ((inOutputFormat == FO_PRESENT) || (inOutputFormat == FO_CACHE_AND_PRESENT)) &&    // And only if we want to display the result
  576.         (XP_FindNamedAnchor(&mContext, inURL, &theXPos, &theYPos)))
  577.         {
  578.         // Ñ no double redraw
  579.         SetDocPosition(0, theXPos, theYPos);
  580.         if (inURL->history_num == 0)
  581.             {
  582.             /* Create URL from prev history entry to preserve security, etc. */
  583.             URL_Struct *theURLCopy = SHIST_CreateURLStructFromHistoryEntry(&mContext, theHist);
  584.  
  585.             /*  Swap addresses. */
  586.             char *temp = inURL->address;
  587.             inURL->address = theURLCopy->address;
  588.             theURLCopy->address = temp;
  589.  
  590.             /*  Free old URL, and reassign. */
  591.             NET_FreeURLStruct(inURL);
  592.             inURL = theURLCopy;
  593.             
  594.             SHIST_AddDocument(&mContext, SHIST_CreateHistoryEntry(inURL, theHist->title));
  595.             }
  596.         else
  597.             SHIST_SetCurrent(&mContext.hist, inURL->history_num);
  598.             
  599.         GH_UpdateGlobalHistory(inURL);
  600.         NET_FreeURLStruct(inURL);
  601.         // Ñ╩update global history for the named anchor & refresh them
  602.         XP_RefreshAnchors();
  603.  
  604.         // Since this was not a net load, we need to signal all clients that the
  605.         // load in complete.
  606.         AllConnectionsComplete();
  607.         }
  608.     else
  609.         {
  610.         // otherwise, go off the net
  611.         EarlManager::StartLoadURL(inURL, &mContext, inOutputFormat);
  612.         }
  613. }
  614.  
  615. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  616. //    Ñ    
  617. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  618.  
  619. void CNSContext::ImmediateLoadURL(
  620.     URL_Struct*                inURL,
  621.     FO_Present_Types        inOutputFormat)
  622. {
  623.     EnsureContextProgress();
  624.     BroadcastMessage(msg_NSCStartLoadURL, inURL);
  625.     EarlManager::StartLoadURL(inURL, &mContext, inOutputFormat);
  626. }
  627.  
  628.  
  629. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  630. //
  631. #pragma mark --- CALLBACK IMPLEMENTATION ---
  632. //
  633. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  634.  
  635. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  636. //    Ñ    
  637. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  638.  
  639. char* CNSContext::TranslateISOText(                                            
  640.     int                     /* inCharset */,
  641.     char*                    inISOText)
  642. {
  643.     return inISOText;
  644. }
  645.  
  646. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  647. //    Ñ    
  648. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  649.  
  650. void CNSContext::GraphProgressInit(
  651.     URL_Struct*                /*inURL*/,
  652.     Int32                     inContentLength)
  653. {
  654.     EnsureContextProgress();
  655.     mProgress->mInitCount++;
  656.     
  657.     if (inContentLength <= 0)
  658.         mProgress->mUnknownCount++;
  659.     else
  660.         mProgress->mTotal += inContentLength;
  661.  
  662.     if (mProgress->mInitCount == 1)
  663.         {
  664.         mProgress->mStartTime = ::TickCount() / 60;
  665.         BroadcastMessage(msg_NSCProgressBegin, mProgress);
  666.         }
  667. }
  668.  
  669. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  670. //    Ñ    
  671. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  672.  
  673. void CNSContext::GraphProgress(
  674.     URL_Struct*                /*inURL*/,
  675.     Int32                     inBytesReceived,
  676.     Int32                     inBytesSinceLast,
  677.     Int32                     inContentLength)
  678. {
  679.     EnsureContextProgress();
  680.         
  681.     Uint32 theTotalBytes;
  682.     if ((mProgress->mUnknownCount > 0) || (inBytesReceived > inContentLength))
  683.         theTotalBytes = 0;
  684.     else
  685.         theTotalBytes = mProgress->mTotal;
  686.         
  687.     mProgress->mRead += inBytesSinceLast;
  688.  
  689.     Uint32 theTime = ::TickCount() / 60;
  690.     const char* theMessage = XP_ProgressText(theTotalBytes, mProgress->mRead, mProgress->mStartTime, theTime);
  691.  
  692.     if (inContentLength > 0)
  693.         mProgress->mPercent = inBytesReceived / (double)inContentLength * 100;
  694.     else
  695.         mProgress->mPercent = -1; // this signifies and indefinite ammount
  696.  
  697.     if (theMessage != NULL)
  698.         {
  699.         mProgress->mMessage = theMessage;
  700.         BroadcastMessage(msg_NSCProgressUpdate, mProgress);
  701.         }
  702. }
  703.  
  704. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  705. //    Ñ    
  706. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  707.  
  708. void CNSContext::GraphProgressDestroy(
  709.     URL_Struct*                /*inURL*/,
  710.     Int32                     inContentLength,
  711.     Int32                     inTotalRead)
  712. {
  713.     Assert_(mProgress != NULL);
  714.     if (mProgress)
  715.     {
  716.     if (inContentLength <= 0 )
  717.         mProgress->mUnknownCount--;
  718.     else
  719.         mProgress->mTotal -= inContentLength;    
  720.  
  721.     mProgress->mRead -= inTotalRead;
  722.  
  723.     mProgress->mInitCount--;
  724.     if (mProgress->mInitCount == 0)
  725.         BroadcastMessage(msg_NSCProgressEnd, mProgress);
  726.     }
  727. }
  728.  
  729. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  730. //    Ñ    
  731. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  732.  
  733. void CNSContext::SetProgressBarPercent(
  734.     Int32                     inPercent)
  735. {
  736.     BroadcastMessage(msg_NSCProgressPercentChanged, &inPercent);
  737. }
  738.  
  739. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  740. //    Ñ    
  741. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  742.  
  743. void CNSContext::Progress(
  744.     const char*                inMessageText)
  745. {
  746.     // We MUST make a copy of this string, because of CStr255's finitely many buffers,
  747.     // one of which is used by the caller (NET_Progress).
  748.     char messageCopy[255];
  749.     if ( inMessageText )
  750.         XP_STRNCPY_SAFE(messageCopy, inMessageText, sizeof(messageCopy));
  751.     else
  752.         messageCopy[0] = 0;
  753.     BroadcastMessage(msg_NSCProgressMessageChanged, messageCopy);
  754. }
  755.  
  756. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  757. //    Ñ    
  758. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  759.  
  760. void CNSContext::Alert(
  761.     const char*                inAlertText)
  762. {
  763.     CStr255     pmessage( inAlertText );
  764.  
  765.     ConvertCRtoLF( pmessage );    // In fact, this function converts LF to CRs and 
  766.                                 // that's what everybody is using it for. Well...
  767.  
  768.     StripDoubleCRs( pmessage );
  769.     pmessage=NET_UnEscape(pmessage);
  770.     UStdDialogs::Alert(pmessage, eAlertTypeCaution);
  771. }
  772.  
  773. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  774. //    Ñ    
  775. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  776.  
  777. void CNSContext::SetCallNetlibAllTheTime(void)
  778. {
  779. #ifndef NSPR20
  780.     extern CNetworkDriver* gNetDriver;
  781.     Assert_(gNetDriver != NULL);
  782.      gNetDriver->SetCallAllTheTime();
  783. #endif
  784. }
  785.  
  786.  
  787. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  788. //    Ñ    
  789. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  790.  
  791. void CNSContext::ClearCallNetlibAllTheTime(void)
  792. {
  793. #ifndef NSPR20
  794.     extern CNetworkDriver* gNetDriver;
  795.     Assert_(gNetDriver != NULL);
  796.      gNetDriver->ClearCallAllTheTime();
  797. #endif
  798. }
  799.  
  800. // A temporary abortion, we need this routine outside of MWContext function table
  801. void XP_ClearCallNetlibAllTheTime(MWContext *)
  802. {
  803. #ifndef NSPR20
  804.     extern CNetworkDriver* gNetDriver;
  805.     Assert_(gNetDriver != NULL);
  806.      gNetDriver->SetCallAllTheTime();
  807. #endif
  808. }
  809.  
  810. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  811. //    Ñ    
  812. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  813.  
  814. XP_Bool CNSContext::UseFancyFTP(void)
  815. {
  816.     return mContext.fancyFTP;
  817. }
  818.  
  819. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  820. //    Ñ    
  821. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  822.  
  823. XP_Bool CNSContext::UseFancyNewsgroupListing(void)
  824. {
  825.     return CPrefs::GetBoolean(CPrefs::UseFancyNews);
  826. }
  827.  
  828. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  829. //    Ñ    
  830. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  831.  
  832. int CNSContext::FileSortMethod(void)
  833. {
  834.     return CPrefs::GetLong( CPrefs::FileSortMethod );
  835. }
  836.  
  837. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  838. //    Ñ    
  839. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  840.  
  841. XP_Bool CNSContext::ShowAllNewsArticles(void)
  842. {
  843.     return CPrefs::GetBoolean( CPrefs::ShowAllNews );
  844. }
  845.  
  846. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  847. //    Ñ    
  848. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  849.  
  850. XP_Bool    CNSContext::Confirm(
  851.     const char*             inMessage)
  852. {
  853.     CStr255 mesg(inMessage);
  854.     mesg = NET_UnEscape(mesg);
  855.     return UStdDialogs::AskOkCancel(mesg);
  856. }
  857.  
  858. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  859. //    Ñ    
  860. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  861.  
  862. char* CNSContext::Prompt(
  863.     const char*             inMessage,
  864.     const char*                inDefaultText)
  865. {
  866.     return PromptWithCaption("", inMessage, inDefaultText);
  867. }
  868.  
  869. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  870. //    Ñ    
  871. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  872. char* CNSContext::PromptWithCaption(
  873.     const char*                inTitleBarText,
  874.     const char*             inMessage,
  875.     const char*                inDefaultText)
  876. {
  877.     char* result = NULL;
  878.     CStr255 mesg(inMessage), ioString(inDefaultText);
  879.     mesg = NET_UnEscape(mesg);
  880.  
  881.     if (UStdDialogs::AskStandardTextPrompt(inTitleBarText, mesg, ioString))
  882.     {
  883.         if (ioString.Length() > 0)
  884.         {
  885.             result = (char*)XP_STRDUP((const char*)ioString);
  886.         }
  887.     }
  888.  
  889.     return result;    
  890. }
  891.  
  892. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  893. //    Ñ    
  894. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  895.  
  896. XP_Bool CNSContext::PromptUsernameAndPassword(
  897.     const char*                inMessage,
  898.     char**                    outUserName,
  899.     char**                    outPassword)
  900. {
  901.     CStr255 mesg(inMessage), username, password;
  902.     if (UStdDialogs::AskForNameAndPassword(mesg, username, password))
  903.     {
  904.         *outUserName = XP_STRDUP((const char*)username);
  905.         *outPassword = XP_STRDUP((const char*)password);
  906.         return true;
  907.     }
  908.     return false;
  909. }
  910.  
  911. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  912. //    Ñ    
  913. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  914.  
  915. char* CNSContext::PromptPassword(
  916.     const char*             inMessage)
  917. {
  918.     CStr255 message(inMessage), password;
  919.     if (UStdDialogs::AskForPassword(message, password))
  920.         return XP_STRDUP((const char*)password);
  921.     return nil;
  922. }
  923.  
  924. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  925. //    Ñ    
  926. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  927.  
  928. void CNSContext::AllConnectionsComplete(void)
  929. {
  930. //    mIsRepaginating = false;
  931.     // For certain contexts (i.e. biff context), we don't get
  932.     // a start loading URL call, so mProgress is NULL
  933.     if (mProgress)
  934.     {
  935.         mProgress->RemoveUser(this);
  936.         mProgress = NULL;
  937.     }
  938.     
  939.     XP_RefreshAnchors();
  940.     BroadcastMessage(msg_NSCAllConnectionsComplete);
  941.  
  942. //    if (mContext.type == MWContextMail)
  943.     {
  944.         // There are listeners that listen to several contexts (eg, in mail windows).
  945.         // This works by reference counting, and such listeners assume calls to
  946.         // SwitchLoadURL and AllConnectionsComplete are balanced.  Each context must
  947.         // therefore ensure that they are, even if it is done artificially.
  948.         for (mLoadRefCount--; mLoadRefCount > 0; mLoadRefCount--)
  949.             BroadcastMessage(msg_NSCAllConnectionsComplete);
  950.                 // decrement the ref count on the spinning-N the same number of times
  951.                 // as we incremented it.
  952.     }
  953.     mLoadRefCount = 0;
  954. }
  955.  
  956. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  957. //
  958. #pragma mark --- PROGRESS STATISTICS ---
  959. //
  960. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  961.  
  962.  
  963. CContextProgress::CContextProgress()
  964. {
  965.     mTotal = 0;
  966.     mRead = 0;            // How many have been read
  967.     mUnknownCount = 0;    // How many connections of the unknown length do we have
  968.     mPercent = 0;
  969.     mStartTime = 0;
  970.     mInitCount = 0;
  971. }        
  972.  
  973. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  974. //
  975. #pragma mark --- STUFF ---
  976. //
  977. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  978.  
  979. // SIGH!!!!!
  980. extern int MK_OUT_OF_MEMORY;
  981.  
  982. void CNSContext::CompleteLoad(URL_Struct* inURL, int inStatus)
  983. {
  984.     if ( inStatus < 0 )
  985.     {
  986.         if ( inURL->error_msg )
  987.         {
  988. // FIX ME!!! If anyone ever redoes progress process apple events this code needs
  989. // to be re-enabled
  990. //            if (HasProgressProcess())
  991. //            {
  992. //                fDidSetProgressPercent = FALSE;
  993. //                SendMakingProgressEvent(nurl->error_msg, 0);
  994. //            }
  995. //            else
  996.                 ErrorManager::PlainAlert( inURL->error_msg, NULL, NULL, NULL );
  997.         }
  998.         Progress("");
  999.     }
  1000.     if ( inStatus == MK_OUT_OF_MEMORY )
  1001.     {
  1002.         XP_InterruptContext( *this );
  1003.           ErrorManager::PlainAlert( NO_MEM_LOAD_ERR_RESID );
  1004.     }
  1005.     
  1006.     if (inStatus == MK_CHANGING_CONTEXT)
  1007.         Progress((const char*)GetCString(DOWNLD_CONT_IN_NEW_WIND));
  1008. }
  1009.  
  1010. // Clear fe.newView inside MWContext
  1011. // This is so that we can catch XP code trying to layout in a
  1012. // window that's been destroyed.
  1013. void CNSContext::ClearMWContextViewPtr(void)
  1014. {
  1015.     mContext.fe.newView = NULL;
  1016. }
  1017.  
  1018. void CNSContext::WaitWhileBusy()
  1019. {
  1020.     EventRecord stupidNullEvent = {0};
  1021.     while (XP_IsContextBusy(*this))
  1022.     {
  1023.         ThrowIf_(CmdPeriod());
  1024.         TheEarlManager.SpendTime(stupidNullEvent);
  1025.     }
  1026. } // CNSContext::WaitWhileBusy
  1027.  
  1028.  
  1029. void CNSContext::CopyListenersToContext(CNSContext* aSubContext)        // used when spawning grid contexts
  1030. {
  1031.         // give this grid context all the same listeners as the parent context
  1032.         // deeje 97-02-12
  1033.     CHTMLView*        theRootView = ExtractHyperView(*this);
  1034.     
  1035.     LArrayIterator iterator(mListeners);
  1036.     LListener    *theListener;
  1037.     while (iterator.Next(&theListener))
  1038.     {
  1039.         CURLEditField* urlField  = dynamic_cast<CURLEditField*>(theListener);
  1040.         if (urlField == NULL && theListener != theRootView)
  1041.         {
  1042.             aSubContext->AddListener(theListener);
  1043.         }
  1044.     }
  1045. }
  1046.  
  1047. MWContext* CNSContext::CreateNewDocWindow(URL_Struct*  inURL )
  1048. {
  1049.     CURLDispatcher::DispatchURL(inURL, nil);
  1050.     return NULL;
  1051. }
  1052.  
  1053. History_entry* CNSContext::GetCurrentHistoryEntry()
  1054. {
  1055.     return SHIST_GetCurrent(&mContext.hist);
  1056. }
  1057.  
  1058. Int32 CNSContext::GetHistoryListCount(void)
  1059. {
  1060.     Int32 count = 0;
  1061.     XP_List* historyList = SHIST_GetList(&mContext);
  1062.     if (historyList)
  1063.         count = XP_ListCount(historyList);
  1064.     return count;
  1065. }
  1066.  
  1067. Int32 CNSContext::GetIndexOfCurrentHistoryEntry(void)
  1068. {
  1069.     Int32 index = 0;
  1070.     History_entry* theCurrentHist = GetCurrentHistoryEntry();
  1071.     if (theCurrentHist != NULL)
  1072.         index = SHIST_GetIndex(&mContext.hist, theCurrentHist);
  1073.     return index;
  1074. }
  1075.  
  1076. // inIndex is one-based
  1077. cstring* CNSContext::GetHistoryEntryTitleByIndex(Int32 inIndex)
  1078. {
  1079.     cstring* title = NULL;
  1080.     History_entry* theCurrentHist = SHIST_GetObjectNum(&mContext.hist, inIndex);
  1081.     if (theCurrentHist != NULL)
  1082.     {
  1083.         try {
  1084.             title = new cstring;
  1085.             *title = theCurrentHist->title;
  1086.         } catch (...) {
  1087.         }
  1088.     }
  1089.     return title;
  1090. }
  1091.  
  1092. void CNSContext::GetHistoryURLByIndex(cstring& outURL, Int32 inIndex)
  1093. {
  1094.     History_entry* theEntry = SHIST_GetObjectNum(&mContext.hist, inIndex);
  1095.     if (theEntry)
  1096.     {
  1097.         outURL = theEntry->address;
  1098.     }
  1099.     else
  1100.     {
  1101.         throw IndexOutOfRangeException();
  1102.     }
  1103. }
  1104.  
  1105.  
  1106. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1107. //
  1108. #pragma mark --- STUBS ---
  1109. //
  1110. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  1111.  
  1112. void CNSContext::LayoutNewDocument(
  1113.     URL_Struct*            /* inURL */,
  1114.     Int32*                /* inWidth */,
  1115.     Int32*                /* inHeight */,
  1116.     Int32*                /* inMarginWidth */,
  1117.     Int32*                /* inMarginHeight */) {}
  1118. void CNSContext::SetDocTitle(char* /* inTitle */) {}
  1119. void CNSContext::FinishedLayout(void) {}
  1120. int CNSContext::GetTextInfo(
  1121.     LO_TextStruct*            /* inText */,
  1122.     LO_TextInfo*            /* inTextInfo */) {    return 1; }
  1123. int CNSContext::MeasureText(
  1124.     LO_TextStruct*            /* inText */,
  1125.     short*                    /* outCharLocs */) { return 0; }
  1126. void CNSContext::GetEmbedSize(
  1127.     LO_EmbedStruct* /* inEmbedStruct */,
  1128.     NET_ReloadMethod /* inReloadMethod */) {}
  1129. void CNSContext::GetJavaAppSize(
  1130.     LO_JavaAppStruct* /* inJavaAppStruct */,
  1131.     NET_ReloadMethod /* inReloadMethod */) {}
  1132. void CNSContext::GetFormElementInfo(LO_FormElementStruct* /* inElement */) {}
  1133. void CNSContext::GetFormElementValue(
  1134.     LO_FormElementStruct* /* inElement */,
  1135.     XP_Bool /*inHide */) {}
  1136. void CNSContext::ResetFormElement(LO_FormElementStruct* /* inElement */) {}
  1137. void CNSContext::SetFormElementToggle(
  1138.     LO_FormElementStruct* /* inElement */,
  1139.     XP_Bool /* inToggle */) {}
  1140. void CNSContext::FreeEmbedElement(LO_EmbedStruct* /* inEmbedStruct */) {}
  1141. void CNSContext::CreateEmbedWindow(NPEmbeddedApp* /* inEmbeddedApp */) {}
  1142. void CNSContext::SaveEmbedWindow(NPEmbeddedApp* /* inEmbeddedApp */) {}
  1143. void CNSContext::RestoreEmbedWindow(NPEmbeddedApp* /* inEmbeddedApp */) {}
  1144. void CNSContext::DestroyEmbedWindow(NPEmbeddedApp* /* inEmbeddedApp */) {}
  1145. void CNSContext::FreeJavaAppElement(LJAppletData* /* inAppletData */) {}
  1146. void CNSContext::HideJavaAppElement(LJAppletData* /* inAppletData */) {}
  1147. void CNSContext::FreeEdgeElement(LO_EdgeStruct* /* inEdgeStruct */) {}
  1148. void CNSContext::FormTextIsSubmit(LO_FormElementStruct* /* inElement */) {}
  1149. void CNSContext::DisplaySubtext(
  1150.     int                     /* inLocation */,
  1151.     LO_TextStruct*            /* inText */,
  1152.     Int32                     /* inStartPos */,
  1153.     Int32                    /* inEndPos */,
  1154.     XP_Bool                 /* inNeedBG */) {}
  1155. void CNSContext::DisplayText(
  1156.     int                     /* inLocation */,
  1157.     LO_TextStruct*            /* inText */,
  1158.     XP_Bool                 /* inNeedBG */) {}
  1159. void CNSContext::DisplayEmbed(
  1160.     int /* inLocation */,
  1161.     LO_EmbedStruct* /* inEmbedStruct */) {}
  1162. void CNSContext::DisplayJavaApp(
  1163.     int /* inLocation */,
  1164.     LO_JavaAppStruct* /* inJavaAppStruct */) {}
  1165. void CNSContext::DisplayEdge (
  1166.     int /* inLocation */,
  1167.     LO_EdgeStruct* /* inEdgeStruct */) {}
  1168. void CNSContext::DisplayTable(
  1169.     int                     /* inLocation */,
  1170.     LO_TableStruct*            /* inTableStruct */) {}
  1171. void CNSContext::DisplayCell(
  1172.     int /* inLocation */,
  1173.     LO_CellStruct* /* inCellStruct */) {}
  1174. void CNSContext::InvalidateEntireTableOrCell(
  1175.     LO_Element*                /* inElement */) {}
  1176. void CNSContext::DisplayAddRowOrColBorder(
  1177.     XP_Rect*                /* inRect */,
  1178.     XP_Bool                    /* inDoErase */) {}
  1179. void CNSContext::DisplaySubDoc(
  1180.     int                     /* inLocation */,
  1181.     LO_SubDocStruct*        /* inSubdocStruct */) {}
  1182. void CNSContext::DisplayLineFeed(
  1183.     int                     /* inLocation */,
  1184.     LO_LinefeedStruct*        /* inLinefeedStruct */,
  1185.     XP_Bool                 /* inNeedBG */) {}
  1186. void CNSContext::DisplayHR(
  1187.     int                     /* inLocation */,
  1188.     LO_HorizRuleStruct*        /* inRuleStruct */) {}
  1189. void CNSContext::DisplayBullet(
  1190.     int                     /* inLocation */,
  1191.     LO_BullettStruct*        /* inBullettStruct */) {}
  1192. void CNSContext::DisplayFormElement(
  1193.     int /* inLocation */,
  1194.     LO_FormElementStruct* /* inFormElement */) {}
  1195. void CNSContext::DisplayBorder(
  1196.     int             /* inLocation */,
  1197.     int                /* inX */,
  1198.     int                /* inY */,
  1199.     int                /* inWidth */,
  1200.     int                /* inHeight */,
  1201.     int                /* inBW */,
  1202.     LO_Color*         /* inColor */,
  1203.     LO_LineStyle)    /* inStyle */ {}
  1204. void CNSContext::DisplayFeedback(
  1205.     int             /* inLocation */,
  1206.     LO_Element_struct*    /* inElement */)    /* inStyle */ {}
  1207. void CNSContext::UpdateEnableStates() {}
  1208. void CNSContext::ClearView(int /* inWhich */) {}
  1209. void CNSContext::SetDocDimension(
  1210.     int /* inLocation */,
  1211.     Int32 /* inWidth */,
  1212.     Int32 /* inLength */) {}
  1213. void CNSContext::SetDocPosition(
  1214.     int /* inLocation */,
  1215.     Int32 /* inX */,
  1216.     Int32 /* inY */) {}
  1217. void CNSContext::GetDocPosition(
  1218.     int /* inLocation */,
  1219.     Int32* /* outX */,
  1220.     Int32* /* outY */) {}
  1221. void CNSContext::BeginPreSection(void) {}
  1222. void CNSContext::EndPreSection(void) {}
  1223. void CNSContext::SetBackgroundColor(
  1224.     Uint8 /* inRed */,
  1225.     Uint8 /* inGreen */,
  1226.     Uint8 /* inBlue */) {}
  1227. void CNSContext::EnableClicking(void) {}
  1228. void CNSContext::EraseBackground(
  1229.     int /* inLocation */,
  1230.     Int32 /* inX */,
  1231.     Int32 /* inY */,
  1232.     Uint32 /* inWidth */,
  1233.     Uint32 /* inHieght */,
  1234.     LO_Color* /* inColor */) {}
  1235. void CNSContext::SetDrawable(CL_Drawable* /* inDrawable */) {}
  1236. void CNSContext::GetTextFrame(
  1237.     LO_TextStruct* /* inTextStruct */,
  1238.     Int32 /* inStartPos */,
  1239.     Int32 /* inEndPos */,
  1240.     XP_Rect* /* outFrame */) {}
  1241. void CNSContext::GetDefaultBackgroundColor(
  1242.     LO_Color* /* outColor */) const {}
  1243. void CNSContext::DrawJavaApp(
  1244.     int /*inLocation*/,
  1245.     LO_JavaAppStruct* /*inJavaAppStruct*/) {}
  1246. void CNSContext::HandleClippingView(
  1247.     struct LJAppletData* /*appletD*/, 
  1248.     int /*x*/, 
  1249.     int /*y*/, 
  1250.     int /*width*/, 
  1251.     int /*height*/) {}
  1252.     
  1253.