home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / COMMON / TOOLS / VB / CABINETS / MSDAO350.CAB / icontrols / HTMLControl.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-01-08  |  6.5 KB  |  186 lines

  1. package icontrols;
  2.  
  3. import com.ms.wd.app.DataObject;
  4. import com.ms.wd.core.Component;
  5. import com.ms.wd.core.IComponent;
  6. import com.ms.wd.core.IContainer;
  7. import com.ms.wd.core.ISite;
  8. import com.ms.wd.html.DhComponentWrapper;
  9. import com.ms.wd.html.DhDocument;
  10. import com.ms.wd.html.DhElement;
  11. import com.ms.wd.html.DhEnumeration;
  12. import com.ms.wd.html.DhModule;
  13. import com.ms.wd.html.event.DhEvent;
  14. import com.ms.wd.html.om.IHTMLBodyElement;
  15. import com.ms.wd.html.om.IHTMLDocument2;
  16. import com.ms.wd.html.om.IHTMLElement;
  17. import com.ms.wd.html.om.IHTMLWindow2;
  18. import com.ms.wd.html.om.IHostWindow;
  19. import com.ms.wd.ole32.FORMATETC;
  20. import com.ms.wd.ole32.IOleDropTarget;
  21. import com.ms.wd.ui.AxControl;
  22. import com.ms.wd.ui.Color;
  23. import com.ms.wd.ui.Control;
  24. import com.ms.wd.ui.Point;
  25. import com.ms.wd.ui.Rectangle;
  26. import java.io.ByteArrayInputStream;
  27.  
  28. public class HTMLControl extends AxControl {
  29.    private DhDocument m_document;
  30.    private IHTMLDocument2 m_hdoc;
  31.    private DocUIHandler m_docUI;
  32.    String m_importHTMLFile;
  33.    String m_html;
  34.    IOleDropTarget pTridentDropTarget;
  35.  
  36.    public void internalOnClick(DhEvent e) {
  37.       this.m_document.dumpHTML();
  38.    }
  39.  
  40.    private boolean initDocument() {
  41.       if (this.m_document == null) {
  42.          Object ctrl = ((AxControl)this).getControl();
  43.          if (ctrl != null) {
  44.             this.m_hdoc = (IHTMLDocument2)ctrl;
  45.             IHTMLElement body = this.m_hdoc.getBody();
  46.             if (body != null) {
  47.                body.setInnerHTML("");
  48.                body.getStyle().setBorderWidth("0px");
  49.                body.getStyle().setPadding("0 0 0 0");
  50.                body.getStyle().setMargin("0 0 0 0");
  51.                ((IHTMLBodyElement)body).setScroll("no");
  52.             }
  53.  
  54.             this.m_document = new DhDocument((DhModule)null, this.m_hdoc, (IHTMLWindow2)this.m_hdoc.getScript());
  55.          }
  56.       }
  57.  
  58.       return this.m_document != null;
  59.    }
  60.  
  61.    public HTMLControl() {
  62.       super("htmlfile");
  63.       this.m_document = null;
  64.       this.m_hdoc = null;
  65.       this.m_docUI = null;
  66.       this.m_importHTMLFile = null;
  67.       this.m_html = null;
  68.       ((Control)this).setStyle(2, false);
  69.       ((Control)this).setStyle(8, true);
  70.       ((Control)this).setTabStop(false);
  71.       this.initDocument();
  72.       this.m_docUI = new DocUIHandler(this);
  73.       ((IHostWindow)AxControl.AtlAxGetHost(((Control)this).getHandle())).SetExternalUIHandler(this.m_docUI);
  74.    }
  75.  
  76.    public HTMLControl(IContainer cont) {
  77.       this();
  78.       if (cont != null) {
  79.          cont.add(this);
  80.       }
  81.  
  82.    }
  83.  
  84.    public void add(DhElement e) {
  85.       if (this.initDocument()) {
  86.          this.m_document.add(e);
  87.       }
  88.  
  89.    }
  90.  
  91.    public void add(Control c) {
  92.       super.add(c);
  93.       ISite site = ((Component)this).getSite();
  94.       if (site != null) {
  95.          IContainer cont = site.getContainer();
  96.          if (cont != null) {
  97.          }
  98.       }
  99.  
  100.       DhComponentWrapper cw = new DhComponentWrapper(c, true);
  101.       this.add((DhElement)cw);
  102.       Point sz = ((Control)this).getSize();
  103.       Rectangle cRect = c.getBounds();
  104.       ((Control)this).setSize(Math.max(sz.x, cRect.x + cRect.width + 1), Math.max(sz.y, cRect.y + cRect.height + 1));
  105.    }
  106.  
  107.    public DhDocument getDocument() {
  108.       return this.m_document;
  109.    }
  110.  
  111.    public void setImportHTMLFileName(String filename) {
  112.       this.m_importHTMLFile = filename;
  113.       this.m_html = null;
  114.       this.m_document.importHTMLFromFile(filename);
  115.    }
  116.  
  117.    public String getImportHTMLFileName() {
  118.       return this.m_importHTMLFile;
  119.    }
  120.  
  121.    byte[] getIStreamData(DataObject pDO, FORMATETC fm) {
  122.       ByteArrayInputStream bais;
  123.       try {
  124.          bais = (ByteArrayInputStream)pDO.getData("Java Component");
  125.       } catch (Exception var6) {
  126.          return null;
  127.       }
  128.  
  129.       int size = bais.available();
  130.       byte[] bArray = new byte[size];
  131.       bais.read(bArray, 0, size);
  132.       return bArray;
  133.    }
  134.  
  135.    public void setBackColor(Color c) {
  136.       if (this.initDocument()) {
  137.          this.m_document.setBackColor(c);
  138.       }
  139.  
  140.    }
  141.  
  142.    public Color getBackColor() {
  143.       return this.initDocument() ? this.m_document.getBackColor() : null;
  144.    }
  145.  
  146.    public void setImportHTML(String html) {
  147.       this.m_html = html;
  148.       this.m_importHTMLFile = null;
  149.       this.m_document.importHTML(html);
  150.       DhEnumeration enum = new DhEnumeration(this.m_document, 1);
  151.       ISite site = ((Component)this).getSite();
  152.       IContainer cont = null;
  153.       if (site != null) {
  154.          cont = site.getContainer();
  155.       }
  156.  
  157.       while(enum.hasMoreItems() && cont != null) {
  158.          cont.add((IComponent)enum.nextItem());
  159.       }
  160.  
  161.    }
  162.  
  163.    public String getImportHTML() {
  164.       return this.m_html;
  165.    }
  166.  
  167.    String extractNameFromData(byte[] pData) {
  168.       int pCur = 15;
  169.       if (pData != null && pData.length >= pCur + 4) {
  170.          int nLen = pData.length;
  171.          long lSize = (long)(pData[pCur + 3] << 32 | pData[pCur + 2] << 16 | pData[pCur + 1] << 8 | pData[pCur]);
  172.          StringBuffer sb = new StringBuffer(32);
  173.          pCur += 4;
  174.          lSize = Math.min(lSize, (long)(nLen - pCur));
  175.  
  176.          for(int i = 0; (long)i < lSize; i += 2) {
  177.             sb.append((char)(pData[i + pCur + 1] << 8 | pData[i + pCur]));
  178.          }
  179.  
  180.          return sb.toString();
  181.       } else {
  182.          return "";
  183.       }
  184.    }
  185. }
  186.