home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / cxsave.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.1 KB  |  210 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. // cxsave.h : header file
  19. //
  20.  
  21. #include "cxstubs.h"
  22. #include "widgetry.h"
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CSaveCX dialog
  26.  
  27. class CSaveCX : public CDialog, public CStubsCX
  28. {
  29. // Construction
  30. private:
  31.     char* GetMailNewsTempFileName(char* pTempPath, char *pFileName = NULL);
  32.     BOOL CanCreate(URL_Struct * pUrl = NULL); //    Can we proceed with creation?  Used by SaveObject.
  33.     BOOL Creator();
  34. public:
  35.     CSaveCX(const char *pAnchor, const char *pViewer = NULL, CWnd *pParent = NULL); //  For external viewing or saving
  36.     ~CSaveCX();
  37.  
  38. //    Indirect Construction
  39. private:
  40.     void DoCreate()    {
  41.         //    Set dimensions of progress
  42.         m_crBounds = CRect(5, 50, 5 + 175, 50 + 15);
  43.         MapDialogRect(m_crBounds);
  44.         m_crBounds.InflateRect(-1, -1);    //    Shrink for border.
  45.     }
  46. public:
  47.     static BOOL SaveAnchorObject(const char *pAnchor, History_entry *pHist, int16 iCSID = 0, CWnd *pParent = NULL, char * pFileName = NULL);
  48.     static BOOL SaveAnchorAsText(const char *pAnchor, History_entry *pHist,  CWnd *pParent, char *pFileName);
  49.     static NET_StreamClass *SaveUrlObject(URL_Struct *pUrl, CWnd *pParent = NULL, char * pFileName = NULL);
  50.     static NET_StreamClass *ViewUrlObject(URL_Struct *pUrl, const char *pViewer, CWnd *pParent = NULL);
  51.     static NET_StreamClass *OleStreamObject(NET_StreamClass *pOleStream, URL_Struct *pUrl, const char *pViewer, CWnd *pParent = NULL);
  52.     static BOOL SaveToGlobal(HGLOBAL *phGlobal, LPCSTR lpszUrl, LPCSTR lpszTitle); // Returns context id
  53.  
  54. //  What we're saving
  55. private:
  56.     CProgressMeter m_ProgressMeter;
  57.     History_entry * m_pHist;
  58.  
  59.     CString m_csAnchor; //  The anchor to load
  60.     CString m_csViewer; //  The viewer to spawn, if specified, file will be removed on exit and
  61.                         //      the user is not prompted for a file name in which to save.
  62.  
  63.     int m_iFileType;    //  The format of the file (needed for text front end when saving basically....)
  64.     CString m_csFileName;   //  The file to save it in
  65.  
  66.     CWnd *m_pParent;    //  Our parent (need for possible file dialogs).
  67.     NET_StreamClass *m_pSecondaryStream;    //    A secondary stream, sometimes we chain together streams.
  68.     long tFirstTime;
  69.     long tLastTime;
  70.     long tLastBarTime;
  71.     int iLastPercent;
  72.  
  73. //  Wether or not we were interrupted (cleanup even more).
  74. public:
  75.     URL_Struct *m_pUrl;   //  The URL_Struct as known by the netlib
  76.     BOOL m_bInterrupted;
  77.     BOOL m_bAborted;
  78.     BOOL m_bSavingToGlobal;
  79.     int16  m_iCSID;        //WinCX pass default character set information here    
  80.  
  81. //    A way to manually set the URL we're handling without having
  82. //        the dialog create one.
  83. //    Also a way to manually set the secondary stream for the URL that
  84. //        we're handling.
  85. public:
  86.     void SetUrl(URL_Struct *pUrl)    {
  87.         ASSERT(m_pUrl == NULL);
  88.         m_pUrl = pUrl;
  89.     }
  90.     void SetSecondaryStream(NET_StreamClass *pSecondaryStream)    {
  91.         ASSERT(m_pSecondaryStream == NULL);
  92.         ASSERT(m_pSink == NULL);    //    Secondary streams require no sink.
  93.         ASSERT(!m_csViewer.IsEmpty() || m_bSavingToGlobal);
  94.         pSecondaryStream->window_id = GetContext();
  95.         m_pSecondaryStream = pSecondaryStream;
  96.     }
  97.     NET_StreamClass *GetSecondaryStream() const    {
  98.         return(m_pSecondaryStream);
  99.     }
  100.     void ClearSecondary() {
  101.         m_pSecondaryStream = NULL;
  102.     }
  103.  
  104. //  Informational
  105. public:
  106.     BOOL IsSaving() const    {
  107.         return(m_csViewer.IsEmpty());
  108.     }
  109.     BOOL IsViewing() const    {
  110.         return(IsSaving() == FALSE ? TRUE : FALSE);
  111.     }
  112.     BOOL IsShellExecute() const {
  113.         return(m_csViewer == "ShellExecute");
  114.     }
  115.     BOOL IsSavingToGlobal() const {
  116.         return m_bSavingToGlobal;
  117.     }
  118.     CString GetFileName() const    {
  119.         return(m_csFileName);
  120.     }
  121.     CString GetAnchor() const    {
  122.         return(m_csAnchor);
  123.     }
  124.     CString GetViewer()    const;
  125.  
  126. //    For dialogs
  127. public:
  128.     virtual CWnd *GetDialogOwner() const;
  129.  
  130. //  Serialization information
  131. private:
  132.     CStdioFile *m_pSink;
  133. public:
  134.     void SetSink(CStdioFile *pSink) {
  135.         ASSERT(m_pSecondaryStream == NULL);    //    Sinks require no secondary stream.
  136.         m_pSink = pSink;
  137.     }
  138.     CStdioFile *GetSink() const    {
  139.         return(m_pSink);
  140.     }
  141.     void ClearSink()    {
  142.         m_pSink = NULL;
  143.     }
  144.  
  145. //    Progress Information, manipulated by GraphProgress
  146. private:
  147.     void Progress(int32 lPercent);    //    Draw progress bar
  148.     int32 m_lOldPercent;        //    Old percentage to optimize drawing in OnPaint.
  149.     CRect m_crBounds;    //    Bounds of dialog progress bar.
  150.  
  151. //    Context Overrides
  152. public:
  153.     //  The URL exit routine.
  154.     virtual void GetUrlExitRoutine(URL_Struct *pUrl, int iStatus, MWContext *pContext);
  155.     //  The text translation exit routine.
  156.     virtual void TextTranslationExitRoutine(PrintSetup *pTextFE);
  157.     //    All Connections are done.
  158.     virtual void AllConnectionsComplete(MWContext *pContext);
  159.     //    Textual progress information.
  160.     virtual void Progress(MWContext *pContext, const char *pMessage);
  161.     //    Progress bar function.
  162.     virtual void SetProgressBarPercent(MWContext *pContext, int32 lPercent);
  163.     //    Graph progression.
  164.     virtual void GraphProgress(MWContext *pContext, URL_Struct *pURL, int32 lBytesReceived, int32 lBytesSinceLastTime, int32 lContentLength);
  165.  
  166. // Dialog Data
  167.     //{{AFX_DATA(CSaveCX)
  168.     enum { IDD = IDD_CONTEXT_SAVE };
  169.     CString    m_csAction;
  170.     CString    m_csDestination;
  171.     CString    m_csLocation;
  172.     CString m_csProgress;
  173.     CString    m_csTimeLeft;
  174.     CString    m_csPercentComplete;
  175.     //}}AFX_DATA
  176.  
  177.  
  178. // Overrides
  179.     // ClassWizard generated virtual function overrides
  180.     //{{AFX_VIRTUAL(CSaveCX)
  181.     protected:
  182.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  183.     //}}AFX_VIRTUAL
  184.  
  185. // Implementation
  186. protected:
  187.  
  188.     // Generated message map functions
  189.     //{{AFX_MSG(CSaveCX)
  190.     virtual void OnCancel();
  191.     afx_msg void OnPaint();
  192.     afx_msg HCURSOR OnQueryDragIcon();
  193.     afx_msg void OnSize(UINT nType, int cx, int cy);
  194.     afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
  195.     afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  196.     virtual BOOL OnInitDialog();
  197.     //}}AFX_MSG
  198.     DECLARE_MESSAGE_MAP()
  199. };
  200.  
  201. extern "C"  {
  202. //  Netlib API to the stream that will save the file to disk.
  203. NET_StreamClass *ContextSaveStream(int iFormatOut, void *pDataObj, URL_Struct *pUrl, MWContext *pContext);
  204.  
  205. unsigned int ContextSaveReady(NET_StreamClass *stream);
  206. int ContextSaveWrite(NET_StreamClass *stream, const char *pWriteData, int32 iDataLength);
  207. void ContextSaveComplete(NET_StreamClass *stream);
  208. void ContextSaveAbort(NET_StreamClass *stream, int iStatus);
  209. };
  210.