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

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20.  
  21. #include "cxmeta.h"
  22.  
  23. //    The purpose of this file is to output a load to a DC.
  24. //    The name MetaFile is just a term, the DC need not be a MetaFileDC.
  25. //    If however, the DC passed in is a MetaFile DC, then all setup of DC
  26. //        must occur outside of this code.
  27. //    Further, the DC must remain valid throughout the course of the load.
  28. //    It may be more easier for you to derive from this class and handle creation
  29. //        and destruction of your DC therein.
  30.  
  31. //    Indirect construction of the Class which loads a URL and
  32. //        returns the context ID, 0 on failure.
  33. //    Calling code can track when the MetaFile is finished, by realizing
  34. //        when the context ID is no longer found in the context list.
  35. DWORD CMetaFileCX::MetaFileAnchorObject(CDC * pMetaFileDC, SIZE& pSize, URL_Struct *pUrl)
  36. {
  37.     //    Create a new object.
  38.     CMetaFileCX *pDontCare = new CMetaFileCX(pMetaFileDC, pSize, pUrl);
  39.     if(pDontCare != NULL)    {
  40.         //    The return value is!
  41.         DWORD dwID = pDontCare->GetContextID();
  42.  
  43.         //    Load the URL.
  44.         pDontCare->GetUrl(pUrl, FO_CACHE_AND_PRESENT);
  45.  
  46.         //    Success as far as we are concerned.
  47.         return(dwID);
  48.     }
  49.     
  50.     //    Failure.
  51.     return(0);
  52. }
  53.  
  54. //    Construct the class.
  55. CMetaFileCX::CMetaFileCX(CDC* pMetaFileDC, SIZE& pSize, URL_Struct *pUrl)
  56. {
  57.     TRACE("Creating CMetaFileCX %p\n", this);
  58.  
  59.     //    Set the context type.
  60.     m_cxType = MetaFile;
  61.     GetContext()->type = MWContextMetaFile;
  62.     // this is a hack to save the layout data for embedlist.  For embed layout will
  63.     // make a copy of the pSavedData.  We need to free the memory here.
  64.     m_embedList = (lo_SavedEmbedListData*)pUrl->savedData.EmbedList;
  65.  
  66.     //    Initialize the class members.
  67.     m_pMetaFileDC = NULL;
  68.     m_csViewport.cx = m_csViewport.cy = 0;
  69.  
  70.     //    Set them.
  71.     m_pMetaFileDC = pMetaFileDC;
  72.     ASSERT(m_pMetaFileDC);
  73.  
  74.     m_csViewport = pSize;
  75.     ASSERT(m_csViewport.cx != 0 && m_csViewport.cy != 0);
  76.  
  77.     //    Should be able to initialize ourselves safely now.
  78.     Initialize(TRUE);
  79. }
  80.  
  81. //    We are now destroyed.
  82. //    Callers can tell when we've gone away by checking for our context ID
  83. //        in the list of all contexts -- Returned by MetaFileAnchorObject.
  84. CMetaFileCX::~CMetaFileCX()
  85. {
  86.     TRACE("Destroying CMetaFileCX %p\n", this);
  87.     // MWH - this is a hack to free the embed list that layout make copy from the original
  88.     // SavedData.  I removed the freeing from lib\layout\layfree.c lo_FreeDocumentEmbedListData.
  89.     // and free the data here.  This will fix an OLE printing problem.  The problem is when a .doc file
  90.     // is on the net, i.e. http://....//xxx.doc.  When layout free the EmbedList in 
  91.     // lo_FreeDocumentEmbedListData will cause the page not printed.  Since for printing we need
  92.     // to use the cached data.
  93.  
  94.     if (m_embedList && (m_embedList->embed_data_list != NULL)) {
  95.         int32 i;
  96.         lo_EmbedDataElement* embed_data_list;
  97.  
  98.         PA_LOCK(embed_data_list, lo_EmbedDataElement*, m_embedList->embed_data_list);
  99.         for (i=0; i < m_embedList->embed_count; i++)
  100.         {
  101.             if (embed_data_list[i].freeProc && embed_data_list[i].data)
  102.                 (*(embed_data_list[i].freeProc))(GetContext(), embed_data_list[i].data);
  103.         }
  104.         PA_UNLOCK(m_embedList->embed_data_list);
  105.         PA_FREE(m_embedList->embed_data_list);
  106.  
  107.         m_embedList->embed_count = 0;
  108.         m_embedList->embed_data_list = NULL;
  109.  
  110.     }
  111. }
  112.  
  113. //    Returns the DC for this context.
  114. HDC CMetaFileCX::GetContextDC()
  115. {
  116.     return(m_pMetaFileDC->GetSafeHdc());
  117. }
  118.  
  119. //    Releases the DC for this context.
  120. //    Since the DC is static, there is no need to really do anything fancy here.
  121. void CMetaFileCX::ReleaseContextDC(HDC pDC)
  122. {
  123. }
  124.  
  125. //    Initializes the context for work after all the members are set.
  126. //    We leave the DC as persistant, as it doesn't really change while we're doing
  127. //        this (it better!).
  128. void CMetaFileCX::Initialize(BOOL bOwnDC, RECT *pRect, BOOL bInitialPalette, BOOL bNewMemDC)
  129. {
  130.     //    We're going to use MM_TEXT for simplicity sake.
  131.     //    Another reason, is simply, that on 16 bit windows, all the GDI functions
  132.     //        take 16 bit ints, which wrap if the page gets too long.
  133.     //    The page will be increadibly long, since this is a metafile, and this
  134.     //        will prolong the wrapping.
  135.     m_MM = MM_TEXT;
  136.  
  137.     //    Set our width and height to that specified in the constructor.
  138.     m_lWidth = Twips2PixX(Metric2TwipsX(m_csViewport.cx));
  139.     m_lHeight = Twips2PixY(Metric2TwipsY(m_csViewport.cy));
  140.     TRACE("Metafile width is %ld\n", m_lWidth);
  141.     TRACE("Metafile height is %ld\n", m_lHeight);
  142.  
  143.     //    Call the base.
  144.     CDCCX::Initialize(bOwnDC, pRect, bInitialPalette, bNewMemDC);
  145. }
  146.  
  147. //    A new document is starting to be laid out.
  148. //    Inform layout of our dimensions, etc.
  149. void CMetaFileCX::LayoutNewDocument(MWContext *pContext, URL_Struct *pURL, int32 *pWidth, int32 *pHeight, int32 *pmWidth, int32 *pmHeight)
  150. {
  151.     //    Turn off all display blocking, since we allow the metafile to
  152.     //        be the full representation of a document.
  153.     DisableDisplayBlocking();
  154.  
  155.     //    Call the base
  156.     CDCCX::LayoutNewDocument(pContext, pURL, pWidth, pHeight, pmWidth, pmHeight);
  157. }
  158.  
  159. //    The load is finished for all intents and purposes.
  160. //    Get rid of ourselves.
  161. void CMetaFileCX::AllConnectionsComplete(MWContext *pContext)
  162. {
  163.     //    Call the base.
  164.     CDCCX::AllConnectionsComplete(pContext);
  165.  
  166.     //    We're done.
  167.     DestroyContext();
  168. }
  169.  
  170. //    Do not allow incremental image display.
  171. PRBool CMetaFileCX::ResolveIncrementalImages()
  172. {
  173.     return(PR_FALSE);
  174. }
  175.