home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CNSContext.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  16.1 KB  |  521 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.h
  20.  
  21.  
  22. #pragma once
  23.  
  24.  
  25. #include <LBroadcaster.h>
  26. #include <LSharable.h>
  27.  
  28. #include "structs.h"
  29. #include "cstring.h"
  30.  
  31. class CHTMLView;
  32. class CNSContext;
  33.  
  34.  
  35. inline CNSContext* ExtractNSContext(MWContext* inContext)
  36.     {    return inContext->fe.newContext;        }
  37.  
  38. inline const CNSContext* ExtractConstNSContext(const MWContext* inContext)
  39.     {    return inContext->fe.newContext;        }
  40.  
  41. inline CHTMLView* ExtractHyperView(const MWContext* inContext)
  42.     {    return inContext->fe.newView;                }
  43.  
  44.  
  45. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  46. //    This enumeration contains all of the possible broadcast messages that
  47. //    a CNSContext can give.
  48. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  49.  
  50. enum {
  51.         // These messages notify thge clients about the layout state.        
  52.     msg_NSCDocTitleChanged                =    'DTCG',                    // cstring* theNewTitle
  53.     msg_NSCLayoutNewDocument            =    'LOND',                    // URL_Struct* theURL
  54.     msg_NSCFinishedLayout                =    'FNLO',                    // < none >
  55.  
  56.         // These messages notify thge clients about the repagination state.        
  57.     msg_NSCPEmptyRepagination            =    'NLPG',                    // < none >
  58.     msg_NSCPAboutToRepaginate            =    'ABPG',                    // < none >
  59.     msg_NSCPEditorRepaginate            =    'EDPG',                    // < none >
  60.  
  61.         // These messages are key to the whole process of loading a URL.
  62.         // The start loading and all connections complete notifications are
  63.         // guaranteed to be symmetrical.
  64.     msg_NSCStartLoadURL                    =    'SLUB',                    // URL_Struct* theURL
  65.     msg_NSCConfirmLoadNewURL            =    'CLNU',                    // Boolean*
  66.     msg_NSCAllConnectionsComplete        =    'ACCP',                    // < none >
  67.  
  68.         // A message to all context clients that this grid context is about to die.
  69.         // Clients should clean up and remove their shared references to the context
  70.         // upon receiving this message.
  71.     msg_NSCGridContextPreDispose        =    'GCPD',                    // Boolean* isSavingHistory
  72.     
  73.         // A message to all context clients that a child grid context has been
  74.         // created or disposed.  Clients will want to know if a grid is created
  75.         // so that they can add themselves as a listener or add a shared reference
  76.         // to the new context.
  77.     msg_NSCGridContextCreated            =    'GCCR',                    // CNSContext* new grid
  78.     msg_NSCGridContextDisposed            =    'GCDP',                    // < none >
  79.     
  80.         // Progress notifications, like the url loading notifications are
  81.         // guaranteed to be symmetric.  There will always be one begin,
  82.         // n updates, and one end notification.    
  83.     msg_NSCProgressBegin                =    'PGST',                    // CContextProgress*
  84.     msg_NSCProgressUpdate                =    'PGUP',                    // CContextProgress*
  85.     msg_NSCProgressEnd                    =    'PGED',                    // CContextProgress*
  86.  
  87.         // These are progress messages that are not guaranteed to be sent
  88.         // between bind and end progress notifications.
  89. //    msg_NSCProgressMessageChanged        =    'PGMC',                    // cstring* theNewMessage
  90.     msg_NSCProgressMessageChanged        =    'PGMC',                    // const char* theNewMessage
  91.     msg_NSCProgressPercentChanged        =    'PGPC'                    // Int32* theNewPercent
  92. };
  93.  
  94. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  95. //  The progress of a particular url loading operation is encapsulated in the
  96. //    following object.  Accessors are provided in the context to support this.
  97. //    This object is only instantiated during the actual load itself, begining
  98. //    with msg_NSCStartLoadURL notification and ending with the
  99. //    msg_NSCAllConnectionsComplete notification.  At all other (inactive) times
  100. //    the accessors for this object will return NULL.  See the accessor comments
  101. //    for further information.
  102. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  103.  
  104. class CContextProgress : public LSharable
  105. {
  106.     public:
  107.                         CContextProgress();
  108.         
  109.         Int32            mTotal;            // Total bytes tracked
  110.         Int32            mRead;            // How many have been read
  111.         Int32            mUnknownCount;    // How many connections of the unknown length do we have
  112.         Int32            mPercent;        // Percent complete
  113.         Int32            mInitCount;
  114.         Uint32            mStartTime;
  115.         
  116.         cstring            mAction;
  117.         cstring            mMessage;
  118.         cstring            mComment;
  119. };
  120.  
  121. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  122. //
  123. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  124.  
  125. class CNSContext : public LBroadcaster, public LSharable
  126. {
  127.     friend class CNSContextCallbacks;
  128.     friend class CPlainTextConversionContext;
  129.     
  130.     public:
  131.                                 CNSContext(MWContextType inType);
  132.                                 CNSContext(const CNSContext& inOriginal);
  133.                                 
  134.         virtual                 ~CNSContext();
  135.  
  136.         virtual    void            NoMoreUsers();
  137.         
  138.         operator MWContext*();
  139.         operator const MWContext*() const;
  140.         operator MWContext&();
  141.         operator const MWContext&() const;
  142.  
  143.         virtual    CContextProgress*     GetContextProgress();
  144.  
  145.     protected:
  146.         virtual    void                 SetContextProgress(CContextProgress* inProgress);
  147.     public:
  148.         void                        EnsureContextProgress();
  149.  
  150.         virtual cstring                GetDescriptor() const;
  151.         virtual void                SetDescriptor(const char* inDescriptor);
  152.     
  153.         virtual    Boolean                IsCloneRequired() const;
  154.         virtual    void                SetRequiresClone(Boolean inClone);
  155.     
  156.         virtual    CContextProgress*    GetCurrentProgressStats();
  157.         virtual    void                UpdateCurrentProgressStats();
  158.  
  159.         virtual void                WaitWhileBusy();
  160.  
  161. // FIX ME!!! ACCESSOR for unique ID
  162.  
  163.             // CHARACTER SET ACCESSORS
  164.             
  165.         void                        InitDefaultCSID();
  166.         virtual    void                SetDefaultCSID(Int16 inDefaultCSID);
  167.         virtual    Int16                GetDefaultCSID() const;
  168.         virtual    void                SetDocCSID(Int16 inDocCSID);
  169.         virtual    Int16                GetDocCSID() const;
  170.         virtual    void                SetWinCSID(Int16 inWinCSID);
  171.         virtual    Int16                GetWinCSID() const;
  172.         virtual    Int16                GetWCSIDFromDocCSID(
  173.                                             Int16                    inDocCSID);
  174.  
  175.  
  176.         class IndexOutOfRangeException { };
  177.         virtual History_entry*        GetCurrentHistoryEntry();
  178.         virtual Int32                GetHistoryListCount();
  179.         virtual cstring*            GetHistoryEntryTitleByIndex(Int32 inIndex); // one-based index
  180.         virtual Int32                GetIndexOfCurrentHistoryEntry();
  181.         virtual void                GetHistoryURLByIndex(cstring& outURL, Int32 inIndex);    // one-based index
  182.  
  183.             // URL MANIPULATION
  184.         virtual    cstring                GetCurrentURL();
  185.         
  186.         virtual    void                SwitchLoadURL(
  187.                                             URL_Struct*                inURL,
  188.                                             FO_Present_Types        inOutputFormat);
  189.                                             
  190.         virtual    void                ImmediateLoadURL(
  191.                                             URL_Struct*                inURL,
  192.                                             FO_Present_Types        inOutputFormat);
  193.  
  194.         // Need to make Alert public because we need to be able to call it from FE_Alert
  195.         virtual    void                 Alert(
  196.                                             const char*                inAlertText);
  197.         
  198.             // STATUS        
  199.  
  200.         virtual const char*            GetDefaultStatus() const;
  201.         virtual void                ClearDefaultStatus();
  202.         virtual void                SetStatus(const char* inStatus);
  203.  
  204.             // STUFF
  205.         virtual void                 CompleteLoad(URL_Struct* inURL, int inStatus);
  206.         virtual void                ClearMWContextViewPtr();
  207.  
  208.         virtual void                CopyListenersToContext(CNSContext* aSubContext);        // used when spawning grid contexts
  209.  
  210.     protected:
  211.  
  212.  
  213.             // CALLBACK IMPLEMENTATION
  214.  
  215.         virtual    MWContext*             CreateNewDocWindow(
  216.                                             URL_Struct*                inURL);
  217.  
  218.         virtual    void                 LayoutNewDocument(
  219.                                             URL_Struct*                inURL,
  220.                                             Int32*                    inWidth,
  221.                                             Int32*                    inHeight,
  222.                                             Int32*                    inMarginWidth,
  223.                                             Int32*                    inMarginHeight);
  224.  
  225.         virtual    void                 SetDocTitle(
  226.                                             char*                     inTitle);
  227.                                             
  228.         virtual    void                 FinishedLayout();
  229.                                             
  230.         virtual    char*                 TranslateISOText(
  231.                                             int                     inCharset,
  232.                                             char*                    inISOText);
  233.                                             
  234.         virtual    int                 GetTextInfo(
  235.                                             LO_TextStruct*            inText,
  236.                                             LO_TextInfo*            inTextInfo);
  237.                                             
  238.         virtual    int                 MeasureText(
  239.                                             LO_TextStruct*            inText,
  240.                                             short*                    outCharLocs);
  241.                                             
  242.         virtual    void                 GetEmbedSize(
  243.                                             LO_EmbedStruct*            inEmbedStruct,
  244.                                             NET_ReloadMethod        inReloadMethod);
  245.                                             
  246.         virtual    void                 GetJavaAppSize(
  247.                                             LO_JavaAppStruct*        inJavaAppStruct,
  248.                                             NET_ReloadMethod        inReloadMethod);
  249.                                             
  250.         virtual    void                 GetFormElementInfo(
  251.                                             LO_FormElementStruct*     inElement);
  252.  
  253.         virtual    void                 GetFormElementValue(
  254.                                             LO_FormElementStruct*     inElement,
  255.                                             XP_Bool                 inHide);
  256.  
  257.         virtual    void                 ResetFormElement(
  258.                                             LO_FormElementStruct*     inElement);
  259.  
  260.         virtual    void                 SetFormElementToggle(
  261.                                             LO_FormElementStruct*     inElement,
  262.                                             XP_Bool                 inToggle);
  263.  
  264.         virtual    void                 FreeEmbedElement(
  265.                                             LO_EmbedStruct*            inEmbedStruct);
  266.                                             
  267.         virtual void                CreateEmbedWindow(
  268.                                             NPEmbeddedApp*            inEmbeddedApp);
  269.                                             
  270.         virtual void                SaveEmbedWindow(
  271.                                             NPEmbeddedApp*            inEmbeddedApp);
  272.  
  273.         virtual void                RestoreEmbedWindow(
  274.                                             NPEmbeddedApp*            inEmbeddedApp);
  275.  
  276.         virtual void                DestroyEmbedWindow(
  277.                                             NPEmbeddedApp*            inEmbeddedApp);
  278.  
  279.         virtual    void                 FreeJavaAppElement(
  280.                                             LJAppletData*            inAppletData);
  281.  
  282.         virtual    void                 HideJavaAppElement(
  283.                                             LJAppletData*                inAppletData);
  284.  
  285.         virtual    void                 FreeEdgeElement(
  286.                                             LO_EdgeStruct*            inEdgeStruct);
  287.  
  288.         virtual    void                 FormTextIsSubmit(
  289.                                             LO_FormElementStruct*     inElement);
  290.  
  291.         virtual    void                 DisplaySubtext(
  292.                                             int                     inLocation,
  293.                                             LO_TextStruct*            inText,
  294.                                             Int32                     inStartPos,
  295.                                             Int32                    inEndPos,
  296.                                             XP_Bool                 inNeedBG);
  297.  
  298.         virtual    void                 DisplayText(
  299.                                             int                     inLocation,
  300.                                             LO_TextStruct*            inText,
  301.                                             XP_Bool                 inNeedBG);
  302.  
  303.         virtual    void                 DisplayEmbed(
  304.                                             int                     inLocation,
  305.                                             LO_EmbedStruct*            inEmbedStruct);
  306.  
  307.         virtual    void                 DisplayJavaApp(
  308.                                             int                     inLocation,
  309.                                             LO_JavaAppStruct*        inJavaAppStruct);
  310.  
  311.         virtual    void                 DisplayEdge (
  312.                                             int                     inLocation,
  313.                                             LO_EdgeStruct*            inEdgeStruct);
  314.  
  315.         virtual    void                 DisplayTable(
  316.                                             int                     inLocation,
  317.                                             LO_TableStruct*            inTableStruct);
  318.  
  319.         virtual    void                 DisplayCell(
  320.                                             int                     inLocation,
  321.                                             LO_CellStruct*            inCellStruct);
  322.  
  323.         virtual    void                 InvalidateEntireTableOrCell(
  324.                                             LO_Element*                inElement);
  325.  
  326.         virtual    void                 DisplayAddRowOrColBorder(
  327.                                             XP_Rect*                inRect,
  328.                                             XP_Bool                    inDoErase);
  329.  
  330.         virtual    void                 DisplaySubDoc(
  331.                                             int                     inLocation,
  332.                                             LO_SubDocStruct*        inSubdocStruct);
  333.  
  334.         virtual    void                 DisplayLineFeed(
  335.                                             int                     inLocation,
  336.                                             LO_LinefeedStruct*        inLinefeedStruct,
  337.                                             XP_Bool                 inNeedBG);
  338.  
  339.         virtual    void                 DisplayHR(
  340.                                             int                     inLocation,
  341.                                             LO_HorizRuleStruct*        inRuleStruct);
  342.  
  343.         virtual    void                 DisplayBullet(
  344.                                             int                     inLocation,
  345.                                             LO_BullettStruct*        inBullettStruct);
  346.  
  347.         virtual    void                 DisplayFormElement(
  348.                                             int                     inLocation,
  349.                                             LO_FormElementStruct*     inFormElement);
  350.  
  351.         virtual    void                 DisplayBorder(
  352.                                             int                     inLocation,
  353.                                             int                        inX,
  354.                                             int                        inY,
  355.                                             int                        inWidth,
  356.                                             int                        inHeight,
  357.                                             int                        inBW,
  358.                                             LO_Color*                 inColor,
  359.                                             LO_LineStyle            inStyle);
  360.  
  361.         virtual void                 UpdateEnableStates();
  362.         
  363.         virtual void                 DisplayFeedback(
  364.                                             int                     inLocation,
  365.                                             LO_Element*             inElement);
  366.  
  367.         virtual    void                 ClearView(
  368.                                             int                     inWhich);
  369.  
  370.         virtual    void                 SetDocDimension(
  371.                                             int                     inLocation,
  372.                                             Int32                     inWidth,
  373.                                             Int32                     inLength);
  374.  
  375.         virtual    void                 SetDocPosition(
  376.                                             int                     inLocation,
  377.                                             Int32                     inX,
  378.                                             Int32                     inY);
  379.  
  380.         virtual    void                 GetDocPosition(
  381.                                             int                     inLocation,
  382.                                             Int32*                    outX,
  383.                                             Int32*                    outY);
  384.  
  385.         virtual    void                 BeginPreSection();
  386.  
  387.         virtual    void                 EndPreSection();
  388.  
  389.         virtual    void                 SetProgressBarPercent(
  390.                                             Int32                     inPercent);
  391.  
  392.         virtual    void                 SetBackgroundColor(
  393.                                             Uint8                     inRed,
  394.                                             Uint8                    inGreen,
  395.                                             Uint8                     inBlue);
  396.  
  397. public:
  398.         virtual    void                 Progress(
  399.                                             const char*                inMessageText);
  400. protected:
  401.         virtual    void                 SetCallNetlibAllTheTime();
  402.  
  403.         virtual    void                 ClearCallNetlibAllTheTime();
  404.  
  405.         virtual    void                 GraphProgressInit(
  406.                                             URL_Struct*                inURL,
  407.                                             Int32                     inContentLength);
  408.  
  409.         virtual    void                 GraphProgressDestroy(
  410.                                             URL_Struct*                inURL,
  411.                                             Int32                     inContentLength,
  412.                                             Int32                     inTotalRead);
  413.  
  414.         virtual    void                 GraphProgress(
  415.                                             URL_Struct*                inURL,
  416.                                             Int32                     inBytesReceived,
  417.                                             Int32                     inBytesSinceLast,
  418.                                             Int32                     inContentLength);
  419.  
  420.         virtual    XP_Bool             UseFancyFTP();
  421.  
  422.         virtual    XP_Bool             UseFancyNewsgroupListing();
  423.  
  424.         virtual    int                 FileSortMethod();
  425.  
  426.         virtual    XP_Bool             ShowAllNewsArticles();
  427.  
  428.         virtual    XP_Bool                Confirm(
  429.                                             const char*             inMessage);
  430.  
  431.         virtual    char*                 Prompt(
  432.                                             const char*             inMessage,
  433.                                             const char*                inDefaultText);
  434.  
  435.         virtual    char*                 PromptWithCaption(
  436.                                             const char*                inCaption,
  437.                                             const char*             inMessage,
  438.                                             const char*                inDefaultText);
  439.  
  440.         virtual    XP_Bool             PromptUsernameAndPassword(
  441.                                             const char*                inMessage,
  442.                                             char**                    outUserName,
  443.                                             char**                    outPassword);
  444.  
  445.         virtual    char*                 PromptPassword(
  446.                                             const char*             inMessage);
  447.  
  448.         virtual    void                 EnableClicking();
  449.  
  450.         virtual    void                 AllConnectionsComplete();
  451.  
  452.         virtual    void                 EraseBackground(
  453.                                             int                        inLocation,
  454.                                             Int32                    inX,
  455.                                             Int32                    inY,
  456.                                             Uint32                    inWidth,
  457.                                             Uint32                    inHieght,
  458.                                             LO_Color*                inColor);
  459.  
  460.         virtual    void                 SetDrawable(
  461.                                             CL_Drawable*            inDrawable);
  462.  
  463.         virtual    void                 GetTextFrame(
  464.                                             LO_TextStruct*            inTextStruct,
  465.                                             Int32                    inStartPos,
  466.                                             Int32                    inEndPos,
  467.                                             XP_Rect*                outFrame);
  468.  
  469.         virtual    void                 GetDefaultBackgroundColor(
  470.                                             LO_Color*                outColor) const;
  471.  
  472.         virtual    void                 DrawJavaApp(
  473.                                             int                     inLocation,
  474.                                             LO_JavaAppStruct*        inJavaAppStruct);
  475.                                             
  476.         virtual    void                 HandleClippingView(
  477.                                             struct LJAppletData     *appletD, 
  478.                                             int                     x, 
  479.                                             int                     y, 
  480.                                             int                     width, 
  481.                                             int                     height);
  482.  
  483. public:
  484.  
  485.         static    UInt32    sNSCWindowID;        // Unique ID, incremented for each context
  486.         UInt32            fNSCWindowID;        // ID of this window
  487.         Int32            fNSCProgressID;    // 
  488.  
  489.         Int32            GetTransactionID() { return fNSCProgressID; }
  490.         Int32            GetContextUniqueID() { return fNSCWindowID; }
  491.         // Window ID. Used to identify the context
  492.  
  493.  
  494.         // There are listeners that listen to several contexts (eg, in mail windows).
  495.         // This works by reference counting, and such listeners assume calls to
  496.         // SwitchLoadURL and AllConnectionsComplete are balanced.  Each context must
  497.         // therefore ensure that they are, even if it is done artificially.
  498.         Int32                        mLoadRefCount;
  499.  
  500.  
  501. protected:
  502.  
  503.  
  504.         MWContext                mContext;
  505.  
  506.         Int16                     mDefaultCSID;
  507.         Boolean                    mRequiresClone;        
  508.         CContextProgress*        mProgress;
  509. };
  510.  
  511.  
  512. inline CNSContext::operator MWContext*()
  513.     {    return &mContext;        };
  514. inline CNSContext::operator const MWContext*() const
  515.     {    return &mContext;        };
  516. inline CNSContext::operator MWContext&()
  517.     {    return mContext;        };
  518. inline CNSContext::operator const MWContext&() const
  519.     {    return mContext;        };
  520.     
  521.