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

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "fehist.h"
  21. #include "mhst_ent.h"
  22. CHistory::CHistory(HISTORY *pUseThis, BOOL bClone)
  23. {
  24.     m_pHistory = NULL;
  25.  
  26.     if(pUseThis)    {
  27.         if(!bClone) {
  28.             m_pHistory = pUseThis;
  29.         }
  30.         else    {
  31.             m_pHistory = Clone(pUseThis);
  32.         }
  33.     }
  34.     else    {
  35.         JMCException *pEX = NULL;
  36.         m_pHistory = HISTORYFactory_Create(&pEX);
  37.         if(pEX) {
  38.             CJMCException e(pEX);
  39.             e.ReportError();
  40.  
  41.             m_pHistory = NULL;
  42.         }
  43.     }
  44. }
  45.  
  46. CHistory::~CHistory()
  47. {
  48.     JMCException *pEX = NULL;
  49.     if(m_pHistory)  {
  50.         HISTORY_release(m_pHistory, &pEX);
  51.         if(pEX) {
  52.             CJMCException e(pEX);
  53.             e.ReportError();
  54.         }
  55.         m_pHistory = NULL;
  56.     }
  57. }
  58.  
  59. void CHistory::SetHISTORY(HISTORY *pUsurp, BOOL bClone)
  60. {
  61.     JMCException *pEX = NULL;
  62.     if(m_pHistory)  {
  63.         HISTORY_release(m_pHistory, &pEX);
  64.         if(pEX) {
  65.             CJMCException e(pEX);
  66.             e.ReportError();
  67.         }
  68.         m_pHistory = NULL;
  69.     }
  70.  
  71.     if(!bClone) {
  72.         m_pHistory = pUsurp;
  73.     }
  74.     else    {
  75.         m_pHistory = Clone(pUsurp);
  76.     }
  77. }
  78.  
  79. HISTORY *CHistory::GetHISTORY()
  80. {
  81.     return(m_pHistory);
  82. }
  83.  
  84. HISTORY *CHistory::Clone(HISTORY *pTwin)
  85. {
  86.     JMCException *j = NULL;
  87.     HISTORY *pRetval = NULL;
  88.  
  89.     if(pTwin)  {
  90.         pRetval = (HISTORY *)HISTORY_clone(pTwin, &j);
  91.         if(j)   {
  92.             CJMCException e(j);
  93.             e.ReportError();
  94.             pRetval = NULL;
  95.         }
  96.     }
  97.  
  98.     return(pRetval);
  99. }
  100.  
  101. HST_ENT *CHistory::Clone(HST_ENT *pTwin)
  102. {
  103.     JMCException *j = NULL;
  104.     HST_ENT *pRetval = NULL;
  105.  
  106.     if(pTwin)  {
  107.         pRetval = (HST_ENT *)HST_ENT_clone(pTwin, &j);
  108.         if(j)   {
  109.             CJMCException e(j);
  110.             e.ReportError();
  111.             pRetval = NULL;
  112.         }
  113.     }
  114.  
  115.     return(pRetval);
  116. }
  117.  
  118. BOOL CHistory::Compare(HISTORY *p1, HISTORY *p2)
  119. {
  120.     BOOL bRetval = FALSE;
  121.     JMCException *j = NULL;
  122.  
  123.     if(p1 && p2)    {
  124.         bRetval = HISTORY_equals(p1, (void *)p2, &j);
  125.         if(j)   {
  126.             CJMCException e(j);
  127.             e.ReportError();
  128.  
  129.             bRetval = FALSE;
  130.         }
  131.     }
  132.     else if(!p1 && !p2) {
  133.         //  NULLs are true.
  134.         bRetval = TRUE;
  135.     }
  136.  
  137.     return(bRetval);
  138. }
  139.  
  140. BOOL CHistory::Compare(HST_ENT *p1, HST_ENT *p2)
  141. {
  142.     BOOL bRetval = FALSE;
  143.     JMCException *j = NULL;
  144.  
  145.     if(p1 && p2)    {
  146.         bRetval = HST_ENT_equals(p1, (void *)p2, &j);
  147.         if(j)   {
  148.             CJMCException e(j);
  149.             e.ReportError();
  150.  
  151.             bRetval = FALSE;
  152.         }
  153.     }
  154.     else if(!p1 && !p2) {
  155.         //  NULLs are true.
  156.         bRetval = TRUE;
  157.     }
  158.  
  159.     return(bRetval);
  160. }
  161.  
  162.  
  163. void CHistory::Add(HST_ENT *pAdd)
  164. {
  165.     if(m_pHistory && pAdd)  {
  166.         HISTORY_addHistoryEntry(m_pHistory, pAdd, TRUE);
  167.     }
  168. }
  169.  
  170. HST_ENT *CHistory::Add(URL *pUrl)
  171. {
  172.     HST_ENT *pRetval = NULL;
  173.     JMCException *j;
  174.  
  175.     if(pUrl)    {
  176.         pRetval = HST_ENTFactory_Create(&j, pUrl, NULL);
  177.         if(j)   {
  178.             CJMCException e(j);
  179.             e.ReportError();
  180.  
  181.             pRetval = NULL;
  182.         }
  183.     }
  184.  
  185.     return(pRetval);
  186. }
  187.  
  188. void CHistory::SetCurrent(HST_ENT *pCurrent)
  189. {
  190.     if(m_pHistory && pCurrent)  {
  191.         HISTORY_setCurrentHistoryEntry(m_pHistory, pCurrent);
  192.     }
  193. }
  194.  
  195. void CHistory::SetCurrentIndex(int iIndex)
  196. {
  197.     SetCurrent(GetIndex(iIndex));
  198. }
  199.  
  200. HST_ENT *CHistory::GetCurrent()
  201. {
  202.     HST_ENT *pRetval = NULL;
  203.  
  204.     if(m_pHistory)    {
  205.         pRetval = HISTORY_getCurrentHistoryEntry(m_pHistory);
  206.     }
  207.  
  208.     return(pRetval);
  209. }
  210.  
  211. BOOL CHistory::Remove(HST_ENT *pRemove)
  212. {
  213.     BOOL bRetval = FALSE;
  214.  
  215.     if(m_pHistory)  {
  216.         bRetval = HISTORY_removeHistoryEntry(m_pHistory, pRemove);
  217.     }
  218.  
  219.     return(bRetval);
  220. }
  221.  
  222. HST_ENT *CHistory::GetNext()
  223. {
  224.     HST_ENT *pRetval = NULL;
  225.  
  226.     if(m_pHistory)    {
  227.         pRetval = HISTORY_getNextHistoryEntry(m_pHistory, GetCurrent());
  228.     }
  229.  
  230.     return(pRetval);
  231. }
  232.  
  233. HST_ENT *CHistory::GetPrev()
  234. {
  235.     HST_ENT *pRetval = NULL;
  236.  
  237.     if(m_pHistory)    {
  238.         pRetval = HISTORY_getPreviousHistoryEntry(m_pHistory, GetCurrent());
  239.     }
  240.  
  241.     return(pRetval);
  242. }
  243.  
  244. HST_ENT *CHistory::GetIndex(int iIndex)
  245. {
  246.     HST_ENT *pRetval = NULL;
  247.  
  248.     if(m_pHistory)    {
  249.         pRetval = HISTORY_getIndexedHistoryEntry(m_pHistory, iIndex);
  250.     }
  251.  
  252.     return(pRetval);
  253. }
  254.  
  255. int CHistory::GetIndex(HST_ENT *pEntry)
  256. {
  257.     int iRetval = 0;
  258.  
  259.     if(m_pHistory && pEntry)    {
  260.         iRetval = HISTORY_getHistoryEntryIndex(m_pHistory, pEntry);
  261.     }
  262.  
  263.     return(iRetval);
  264. }
  265.  
  266. void CHistory::SetUrl(HST_ENT *pHist, URL *pUrl)
  267. {
  268.     if(pHist && pUrl)   {
  269.         HST_ENT_setURL(pHist, pUrl);
  270.     }
  271. }
  272.  
  273. URL *CHistory::GetUrl(HST_ENT *pHist)
  274. {
  275.     URL *pRetval = NULL;
  276.  
  277.     if(pHist)   {
  278.         pRetval = HST_ENT_getURL(pHist);
  279.     }
  280.  
  281.     return(pRetval);
  282. }
  283.  
  284. int CHistory::SetTitle(HST_ENT *pHist, const char *pTitle)
  285. {
  286.     int iRetval = 0;    //  What's the default?
  287.  
  288.     //  Allow NULL title....
  289.     if(pHist) {
  290.         iRetval = HST_ENT_setTitle(pHist, pTitle);
  291.     }
  292.  
  293.     return(iRetval);
  294. }
  295.  
  296. const char *CHistory::GetTitle(HST_ENT *pHist)
  297. {
  298.     const char *pRetval = NULL;
  299.  
  300.     if(pHist)   {
  301.         pRetval = HST_ENT_getTitle(pHist);
  302.     }
  303.  
  304.     return(pRetval);
  305. }
  306.  
  307. int CHistory::SetFormData(HST_ENT *pHist, void *pData)
  308. {
  309.     int iRetval = 0;    //  What's the default?
  310.  
  311.     //  Allow NULL data....
  312.     if(pHist)  {
  313.         iRetval = HST_ENT_setFormData(pHist, pData);
  314.     }
  315.  
  316.     return(iRetval);
  317. }
  318.  
  319. void *CHistory::GetFormData(HST_ENT *pHist)
  320. {
  321.     void *pRetval = NULL;
  322.  
  323.     if(pHist)   {
  324.         pRetval = HST_ENT_getFormData(pHist);
  325.     }
  326.  
  327.     return(pRetval);
  328. }
  329.  
  330. int CHistory::SetEmbedData(HST_ENT *pHist, void *pData)
  331. {
  332.     int iRetval = 0;    //  What's the default?
  333.  
  334.     //  Allow NULL data....
  335.     if(pHist)  {
  336.         iRetval = HST_ENT_setEmbedData(pHist, pData);
  337.     }
  338.  
  339.     return(iRetval);
  340. }
  341.  
  342. void *CHistory::GetEmbedData(HST_ENT *pHist)
  343. {
  344.     void *pRetval = NULL;
  345.  
  346.     if(pHist)   {
  347.         pRetval = HST_ENT_getEmbedData(pHist);
  348.     }
  349.  
  350.     return(pRetval);
  351. }
  352.  
  353. int CHistory::SetGridData(HST_ENT *pHist, void *pData)
  354. {
  355.     int iRetval = 0;    //  What's the default?
  356.  
  357.     //  Allow NULL data....
  358.     if(pHist)  {
  359.         iRetval = HST_ENT_setGridData(pHist, pData);
  360.     }
  361.  
  362.     return(iRetval);
  363. }
  364.  
  365. void *CHistory::GetGridData(HST_ENT *pHist)
  366. {
  367.     void *pRetval = NULL;
  368.  
  369.     if(pHist)   {
  370.         pRetval = HST_ENT_getGridData(pHist);
  371.     }
  372.  
  373.     return(pRetval);
  374. }
  375.  
  376. int CHistory::SetWindowData(HST_ENT *pHist, void *pData)
  377. {
  378.     int iRetval = 0;    //  What's the default?
  379.  
  380.     //  Allow NULL data....
  381.     if(pHist)  {
  382.         iRetval = HST_ENT_setWindowData(pHist, pData);
  383.     }
  384.  
  385.     return(iRetval);
  386. }
  387.  
  388. void *CHistory::GetWindowData(HST_ENT *pHist)
  389. {
  390.     void *pRetval = NULL;
  391.  
  392.     if(pHist)   {
  393.         pRetval = HST_ENT_getWindowData(pHist);
  394.     }
  395.  
  396.     return(pRetval);
  397. }
  398.  
  399. int CHistory::SetAppletData(HST_ENT *pHist, void *pData)
  400. {
  401.     int iRetval = 0;    //  What's the default?
  402.  
  403.     //  Allow NULL data....
  404.     if(pHist)  {
  405.         iRetval = HST_ENT_setAppletData(pHist, pData);
  406.     }
  407.  
  408.     return(iRetval);
  409. }
  410.  
  411. void *CHistory::GetAppletData(HST_ENT *pHist)
  412. {
  413.     void *pRetval = NULL;
  414.  
  415.     if(pHist)   {
  416.         pRetval = HST_ENT_getAppletData(pHist);
  417.     }
  418.  
  419.     return(pRetval);
  420. }
  421.  
  422. void CHistory::SetPosition(HST_ENT *pHist, long lEleID)
  423. {
  424.     if(pHist)   {
  425.         HST_ENT_setDocumentPosition(pHist, lEleID);
  426.     }
  427. }
  428.  
  429. long CHistory::GetPosition(HST_ENT *pHist)
  430. {
  431.     long lRetval = 0;   //  What's a good default?
  432.  
  433.     if(pHist)   {
  434.         lRetval = HST_ENT_getDocumentPosition(pHist);
  435.     }
  436.  
  437.     return(lRetval);
  438. }
  439.  
  440. HST_ENT *CHistory::GetNext(HST_ENT *pEntry)
  441. {
  442.     HST_ENT *pRetval = NULL;
  443.     if(pEntry)  {
  444.         pRetval = HST_ENT_getNext(pEntry);
  445.     }
  446.  
  447.     return(pRetval);
  448. }
  449.  
  450. void CHistory::SetNext(HST_ENT *pThis, HST_ENT *pNext)
  451. {
  452.     //  Allow NULL next....
  453.     if(pThis)   {
  454.         HST_ENT_setNext(pThis, pNext);
  455.     }
  456. }
  457.