home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cxabstra.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.4 KB  |  354 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. #ifndef __CX_ABSTRACT_H
  19. //    Avoid include redundancy
  20. //
  21. #define __CX_ABSTRACT_H
  22.  
  23. #ifndef _APICX_H
  24. #include "apicx.h"
  25. #endif
  26. #include "ni_pixmp.h"
  27.  
  28. //    Purpose:    Provide the abstract context implementation.
  29. //    Comments:   Pure virtual; must be derived from.
  30. //              Through wrapping functions, the C XP libs will call into the context, and
  31. //                  virtual resolution will resolve the correct context.
  32. //    Revision History:
  33. //      04-26-95    created GAB
  34. //
  35.  
  36. //    Required Includes
  37. //
  38.  
  39. //    Constants
  40. //
  41.  
  42. //    Structures
  43. //
  44. //  Mechanism for run time information.
  45. //  Must be updated with the addition of every new context type.
  46. //  For optimizations for specific output devices in common code.
  47. //  All classes meant to be abstract will have values of 0x0.
  48. //      This allows us to ASSERT if the context is of a valid type.
  49.  
  50. typedef enum ContextType    {
  51.     Abstract = 0x0000,
  52.     DeviceContext = 0x0000,
  53.     Stubs = 0x0000,
  54.     Network,
  55.     Save,
  56.     Print,
  57.     Pane,
  58.     Window,
  59.     Bookmarks,
  60.     MetaFile,
  61.     MailCX,
  62.     NewsCX,
  63.     MailThreadCX,
  64.     NewsThreadCX,
  65.     SearchCX,
  66.     AddressCX,
  67.     HtmlHelp,
  68.     HistoryCX,    
  69.     IconCX,
  70.     RDFSlave,
  71.     MaxContextTypes   //  Leave as last entry please
  72. } ContextType;
  73.  
  74. //  The abstract windows context
  75. class CAbstractCX: public IMWContext {
  76. private:
  77.     //  The actual XP context.
  78.     MWContext *m_pXPCX;
  79.  
  80. protected:
  81.     //  Set this in the constructor of each derived class for run time type information.
  82.     ContextType m_cxType;
  83.     IL_GroupContext* m_pImageGroupContext;
  84.  
  85. public:
  86.     CAbstractCX();
  87.     virtual ~CAbstractCX();
  88.     //    Function to load a URL with this context, with the custom exit routing handler.
  89.     //    Use this to NET_GetURL instead or XL_TranslateText instead.
  90.     virtual int GetUrl(URL_Struct *pUrl, FO_Present_Types iFormatOut, BOOL bReallyLoad = TRUE, BOOL bForceNew = FALSE);
  91.     virtual XL_TextTranslation TranslateText(URL_Struct *pUrl, const char *pFileName, const char *pPrefix = NULL, int iWidth = 75);
  92.  
  93.     virtual void UpdateStopState(MWContext *pContext) = 0;
  94.  
  95.     //    Generic brain dead interface to load a URL.
  96.     //    This used to be known as OnNormalLoad.
  97.     int NormalGetUrl(const char *pUrl, const char *pReferrer = NULL, const char *pTarget = NULL, BOOL bForceNew = FALSE);
  98.  
  99.     //    Atomic load operations regarding history.
  100.     virtual void Reload(NET_ReloadMethod iReloadType = NET_NORMAL_RELOAD);
  101.     virtual void NiceReload(int usePassInType = 0, NET_ReloadMethod iReloadType = NET_NORMAL_RELOAD);
  102.     virtual void Back();
  103.     virtual void Forward();
  104.     virtual void ImageComplete(NI_Pixmap* image) {;}
  105.     virtual BITMAPINFO*    NewPixmap(NI_Pixmap* pImage, BOOL mask = FALSE) { return NULL;}
  106.  
  107.  
  108.     //    Function for easy creation of a URL from the current history entry.
  109.     virtual URL_Struct *CreateUrlFromHist(BOOL bClearStateData = FALSE, SHIST_SavedData *pSavedData = NULL, BOOL bWysiwyg = FALSE);
  110.     virtual BOOL CanCreateUrlFromHist();
  111. //  Construction/destruction (creates/destroys XP context)
  112.     virtual void DestroyContext();
  113.     void NiceDestroyContext();
  114. private:
  115.     BOOL m_bDestroyed;
  116. public:
  117.     char * m_pLastStatus;
  118.     BOOL IsDestroyed() const    {
  119.         //    This function is very important.
  120.         //    It allows you to write code which can detect when a context
  121.         //        is actually in the process of being destroyed.
  122.         //    In many cases, you will receive callbacks from the XP libraries
  123.         //        while the context is being destroyed.  If you GPF, then use
  124.         //        this function to better detect your course of action.
  125.         return(m_bDestroyed);
  126.     }
  127.  
  128. public:
  129.     //  Access to type information, for optimizations in common code.
  130.     ContextType GetContextType() const  {
  131.         ASSERT(m_cxType);
  132.         return(m_cxType);
  133.     }
  134.  
  135.     int16 GetWinCsid();
  136.  
  137.     BOOL IsDCContext() const    {
  138.         ASSERT(m_cxType);
  139.         switch(m_cxType)    {
  140.         case Print:
  141.         case Window:
  142.         case MetaFile:
  143.         case Pane:
  144.             return(TRUE);
  145.  
  146.         default:
  147.             return(FALSE);
  148.         }
  149.     }
  150.     BOOL IsPureDCContext() const    {
  151.         //    Return TRUE if all we depend upon is
  152.         //        a DC for display (non windowed).
  153.         return(!IsWindowContext() && IsDCContext() == TRUE);
  154.     }
  155.     BOOL IsPrintContext() const {
  156.         ASSERT(m_cxType);
  157.         switch(m_cxType)    {
  158.         case Print:
  159.             return(TRUE);
  160.  
  161.         default:
  162.             return(FALSE);
  163.         }
  164.     }
  165.     BOOL IsWindowContext() const    {
  166.         ASSERT(m_cxType);
  167.         switch(m_cxType)    {
  168.         case Window:
  169.         case Pane:
  170.             return(TRUE);
  171.  
  172.         default:
  173.             return(FALSE);
  174.         }
  175.     }
  176.  
  177.     BOOL IsFrameContext() const {
  178.         ASSERT(m_cxType);
  179.         switch (m_cxType) {
  180.         case Window:
  181.             return TRUE;
  182.  
  183.         default:
  184.             return FALSE;
  185.         }
  186.     }
  187.  
  188. public:
  189.     //    Owner of any dialogs that we'll bring up.
  190.     virtual CWnd *GetDialogOwner() const;
  191.  
  192. public:
  193.     //  For the foolhardy, who desire access to the XP context in our hour of need.
  194.     MWContext *GetContext() const   {
  195.         return(m_pXPCX);
  196.     }
  197.     MWContext *GetParentContext() const   {
  198.         //    Only valid if IsGridCell is true.
  199.         return(m_pXPCX->grid_parent);
  200.     }
  201.     // Override to allow XP Context->Frame matching
  202.     virtual CFrameGlue *GetFrame() const { return NULL; }
  203.  
  204.     //    Named contexts and grid stuff.
  205.     void SetContextName(const char *pName);
  206.     void SetParentContext(MWContext *pParentContext);
  207.     BOOL IsGridCell() const;
  208.     BOOL IsGridParent() const;
  209.  
  210.  
  211.     //  layout modularization effort.
  212. public:
  213.     MWContext *GetDocumentContext() const   {
  214.         return(m_pXPCX);
  215.     }
  216.  
  217. public:
  218.     //    A function to interrupt any loads in this context.
  219.     //    This happens immediatly or idly.
  220.     //    Also, if the call is not nested, it may destroy this object
  221.     //        if DestroyContext has been called previously.
  222.     virtual void Interrupt();
  223. public:
  224.     BOOL m_bIdleInterrupt;
  225.     BOOL m_bIdleDestroy;
  226. private:
  227.     int m_iInterruptNest;
  228.  
  229. private:
  230.     BOOL m_bImagesLoading; // True if any images in this context are loading.
  231.     BOOL m_bImagesLooping; // True if any images in this context are looping.
  232.     BOOL m_bImagesDelayed; // True if any images in this context are delayed. 
  233.     BOOL m_bMochaImagesLoading;
  234.     BOOL m_bMochaImagesLooping;
  235.     BOOL m_bMochaImagesDelayed;
  236.     BOOL IsContextStoppableRecurse();
  237.  
  238. public:
  239.     BOOL m_bNetHelpWnd;
  240.  
  241.     BOOL IsNetHelpWnd() { return m_bNetHelpWnd; }
  242.     
  243. public:
  244.     // A wrapper around XP_IsContextStoppable.  This is necessary
  245.     // because a context is stoppable if its image context is
  246.     // stoppable, and the image context is owned by the Front End.
  247.     BOOL IsContextStoppable();
  248.  
  249.     // Returns TRUE if this context or its children have any looping images.
  250.     BOOL IsContextLooping();
  251.  
  252.     void SetImagesLoading(BOOL val) {m_bImagesLoading = val;}
  253.     void SetImagesLooping(BOOL val) {m_bImagesLooping = val;}
  254.     void SetImagesDelayed(BOOL val) {m_bImagesDelayed = val;}
  255.     void SetMochaImagesLoading(BOOL val) {m_bMochaImagesLoading = val;}
  256.     void SetMochaImagesLooping(BOOL val) {m_bMochaImagesLooping = val;}
  257.     void SetMochaImagesDelayed(BOOL val) {m_bMochaImagesDelayed = val;}
  258.  
  259.     //  Client pull timer information.
  260. public:
  261.     void *m_pClientPullData;
  262.     void *m_pClientPullTimeout;
  263.  
  264. private:
  265.     //    Information to time a load.
  266.     time_t m_ttStopwatch;
  267.     time_t m_ttOldwatch;
  268. public:
  269.     BOOL ProgressReady(time_t ttCurTime)    {
  270.         BOOL bRetval = ttCurTime != m_ttOldwatch;
  271.         m_ttOldwatch = ttCurTime;
  272.         return(bRetval);
  273.     }
  274.     time_t GetElapsedSeconds(time_t ttCurTime)    {
  275.         return(ttCurTime - m_ttStopwatch);
  276.     }
  277.  
  278.     //moved to .cpp due to dependency problems
  279.     void ResetStopwatch();
  280.  
  281. public:
  282.     //    Context Identification.
  283.     DWORD GetContextID()    {
  284.         return((DWORD)(m_pXPCX->context_id));
  285.     }
  286.     static CAbstractCX *FindContextByID(DWORD dwID);
  287.  
  288. public:
  289.     //    NCAPI context pointer.
  290.     CNcapiUrlData *m_pNcapiUrlData;
  291.  
  292. //    Progress Helpers
  293.     virtual int32 QueryProgressPercent() { return 0; }
  294.     virtual void StartAnimation() {}
  295.     virtual void StopAnimation() {}
  296.  
  297. //    MFC Helpers;  abstraction away
  298. public:
  299.     virtual void MailDocument();
  300.     virtual BOOL CanMailDocument();
  301.     virtual void NewWindow();
  302.     virtual BOOL CanNewWindow();
  303.     virtual void OpenUrl();
  304.     virtual BOOL CanOpenUrl();
  305.     virtual void AllBack();
  306.     virtual BOOL CanAllBack();
  307.     virtual void AllForward();
  308.     virtual BOOL CanAllForward();
  309.     virtual void AllInterrupt();
  310.     virtual BOOL CanAllInterrupt();
  311.     virtual void AllReload(NET_ReloadMethod iReloadType = NET_NORMAL_RELOAD);
  312.     virtual BOOL CanAllReload();
  313.     virtual void CopySelection();
  314.     virtual BOOL CanCopySelection();
  315.     virtual void AddToBookmarks();
  316.     virtual BOOL CanAddToBookmarks();
  317.  
  318. #ifdef LAYERS
  319.        virtual BOOL HandleLayerEvent(CL_Layer * pLayer, CL_Event * pEvent) 
  320.           { return FALSE; }
  321.        virtual BOOL HandleEmbedEvent(LO_EmbedStruct *embed, CL_Event * pEvent) 
  322.           { return FALSE; }
  323. #endif
  324.     virtual void GoHome(){}
  325.     virtual void AllFind(MWContext *pSearchContext = NULL){}
  326.     virtual BOOL DoFind(CWnd * pWnd, const char * pFindString, 
  327.                 BOOL bMatchCase, BOOL bSearchDown, BOOL bAlertOnNotFound)
  328.         { return FALSE; }
  329.     virtual void PrintContext(){}
  330.     virtual void GetWindowOffset(int32 *x, int32 *y){}
  331.     
  332.        void    MochaDestructionComplete();
  333. };
  334. //    Global variables
  335. //
  336.  
  337. //    Macros
  338. //
  339.  
  340. //    Function declarations
  341. //
  342. //  The common front end, called in every context, that in turn uses a virtual call into
  343. //      the correct context, except in specific optimized situations.
  344. #define MAKE_FE_FUNCS_PREFIX(funkage)   CFE_##funkage
  345. #define MAKE_FE_FUNCS_EXTERN
  346. #include "mk_cx_fn.h"
  347.  
  348. //  The exit routines.
  349. void CFE_GetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext);
  350. void CFE_SimpleGetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext);
  351. void CFE_TextTranslationExitRoutine(PrintSetup *pTextFE);
  352.  
  353. #endif // __CX_ABSTRACT_H
  354.