home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / oleview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.9 KB  |  99 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. /********************************XXXM12N**************************************/
  20. #include "net.h"
  21. #include "merrors.h"
  22. #include "xp_mem.h"
  23. #include "xp_mcom.h"
  24. #include "xpassert.h"
  25.  
  26. static unsigned int
  27. ole_view_write_ready(NET_StreamClass *stream)
  28. {    
  29.     return 1;
  30. }
  31.  
  32. /* Abort the stream if we get this far */
  33. static int ole_view_write(NET_StreamClass *stream, const  char *str, int32 len)
  34. {    
  35.     return MK_INTERRUPTED;
  36. }
  37.  
  38. static void
  39. ole_view_complete(NET_StreamClass *stream)
  40. {    
  41. }
  42.  
  43. static void 
  44. ole_view_abort(NET_StreamClass *stream, int status)
  45. {    
  46. }
  47.  
  48.  
  49. static char fakehtml[] = "<EMBED SRC=\"internal-ole-viewer:%s\"\n>";
  50.  
  51. NET_StreamClass *
  52. OLE_ViewStream(int format_out, void *pDataObj, URL_Struct *urls,
  53.               MWContext *pContext)
  54. {
  55.     NET_StreamClass *stream = nil, *viewstream;
  56.     char *org_content_type;
  57.     
  58.     if (!(stream = XP_NEW_ZAP(NET_StreamClass))) {
  59.         XP_TRACE(("OLE_ViewStream memory lossage"));
  60.         return 0;
  61.     }
  62.     
  63.     stream->name           = "ole viewer";
  64.     stream->complete       = ole_view_complete;
  65.     stream->abort          = ole_view_abort;
  66.     stream->is_write_ready = ole_view_write_ready;
  67.     stream->data_object    = NULL;
  68.     stream->window_id      = pContext;
  69.     stream->put_block      = (MKStreamWriteFunc)ole_view_write;
  70.  
  71.     org_content_type = urls->content_type; 
  72.     urls->content_type = 0;
  73.     StrAllocCopy(urls->content_type, TEXT_HTML);
  74.     urls->is_binary = 1;    /* secret flag for mail-to save as */
  75.  
  76.     if((viewstream=NET_StreamBuilder(format_out, urls, pContext)) != 0)
  77.     {
  78.         char *buffer = (char*)
  79.             XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1);
  80.  
  81.         if (buffer)
  82.         {
  83.             XP_SPRINTF(buffer, fakehtml, urls->address);
  84.             (*viewstream->put_block)(viewstream,
  85.                                      buffer, XP_STRLEN(buffer));
  86.             (*viewstream->complete)(viewstream);
  87.             XP_FREE(buffer);
  88.         }
  89.     }
  90.  
  91.     /* XXX hack alert - this has to be set back for abort to work
  92.        correctly */
  93.     XP_FREE(urls->content_type);
  94.     urls->content_type = org_content_type;
  95.  
  96.     return stream;
  97. }
  98.  
  99.