home *** CD-ROM | disk | FTP | other *** search
- package icontrols;
-
- import com.ms.wd.app.DataObject;
- import com.ms.wd.core.Component;
- import com.ms.wd.core.IComponent;
- import com.ms.wd.core.IContainer;
- import com.ms.wd.core.ISite;
- import com.ms.wd.html.DhComponentWrapper;
- import com.ms.wd.html.DhDocument;
- import com.ms.wd.html.DhElement;
- import com.ms.wd.html.DhEnumeration;
- import com.ms.wd.html.DhModule;
- import com.ms.wd.html.event.DhEvent;
- import com.ms.wd.html.om.IHTMLBodyElement;
- import com.ms.wd.html.om.IHTMLDocument2;
- import com.ms.wd.html.om.IHTMLElement;
- import com.ms.wd.html.om.IHTMLWindow2;
- import com.ms.wd.html.om.IHostWindow;
- import com.ms.wd.ole32.FORMATETC;
- import com.ms.wd.ole32.IOleDropTarget;
- import com.ms.wd.ui.AxControl;
- import com.ms.wd.ui.Color;
- import com.ms.wd.ui.Control;
- import com.ms.wd.ui.Point;
- import com.ms.wd.ui.Rectangle;
- import java.io.ByteArrayInputStream;
-
- public class HTMLControl extends AxControl {
- private DhDocument m_document;
- private IHTMLDocument2 m_hdoc;
- private DocUIHandler m_docUI;
- String m_importHTMLFile;
- String m_html;
- IOleDropTarget pTridentDropTarget;
-
- public void internalOnClick(DhEvent e) {
- this.m_document.dumpHTML();
- }
-
- private boolean initDocument() {
- if (this.m_document == null) {
- Object ctrl = ((AxControl)this).getControl();
- if (ctrl != null) {
- this.m_hdoc = (IHTMLDocument2)ctrl;
- IHTMLElement body = this.m_hdoc.getBody();
- if (body != null) {
- body.setInnerHTML("");
- body.getStyle().setBorderWidth("0px");
- body.getStyle().setPadding("0 0 0 0");
- body.getStyle().setMargin("0 0 0 0");
- ((IHTMLBodyElement)body).setScroll("no");
- }
-
- this.m_document = new DhDocument((DhModule)null, this.m_hdoc, (IHTMLWindow2)this.m_hdoc.getScript());
- }
- }
-
- return this.m_document != null;
- }
-
- public HTMLControl() {
- super("htmlfile");
- this.m_document = null;
- this.m_hdoc = null;
- this.m_docUI = null;
- this.m_importHTMLFile = null;
- this.m_html = null;
- ((Control)this).setStyle(2, false);
- ((Control)this).setStyle(8, true);
- ((Control)this).setTabStop(false);
- this.initDocument();
- this.m_docUI = new DocUIHandler(this);
- ((IHostWindow)AxControl.AtlAxGetHost(((Control)this).getHandle())).SetExternalUIHandler(this.m_docUI);
- }
-
- public HTMLControl(IContainer cont) {
- this();
- if (cont != null) {
- cont.add(this);
- }
-
- }
-
- public void add(DhElement e) {
- if (this.initDocument()) {
- this.m_document.add(e);
- }
-
- }
-
- public void add(Control c) {
- super.add(c);
- ISite site = ((Component)this).getSite();
- if (site != null) {
- IContainer cont = site.getContainer();
- if (cont != null) {
- }
- }
-
- DhComponentWrapper cw = new DhComponentWrapper(c, true);
- this.add((DhElement)cw);
- Point sz = ((Control)this).getSize();
- Rectangle cRect = c.getBounds();
- ((Control)this).setSize(Math.max(sz.x, cRect.x + cRect.width + 1), Math.max(sz.y, cRect.y + cRect.height + 1));
- }
-
- public DhDocument getDocument() {
- return this.m_document;
- }
-
- public void setImportHTMLFileName(String filename) {
- this.m_importHTMLFile = filename;
- this.m_html = null;
- this.m_document.importHTMLFromFile(filename);
- }
-
- public String getImportHTMLFileName() {
- return this.m_importHTMLFile;
- }
-
- byte[] getIStreamData(DataObject pDO, FORMATETC fm) {
- ByteArrayInputStream bais;
- try {
- bais = (ByteArrayInputStream)pDO.getData("Java Component");
- } catch (Exception var6) {
- return null;
- }
-
- int size = bais.available();
- byte[] bArray = new byte[size];
- bais.read(bArray, 0, size);
- return bArray;
- }
-
- public void setBackColor(Color c) {
- if (this.initDocument()) {
- this.m_document.setBackColor(c);
- }
-
- }
-
- public Color getBackColor() {
- return this.initDocument() ? this.m_document.getBackColor() : null;
- }
-
- public void setImportHTML(String html) {
- this.m_html = html;
- this.m_importHTMLFile = null;
- this.m_document.importHTML(html);
- DhEnumeration enum = new DhEnumeration(this.m_document, 1);
- ISite site = ((Component)this).getSite();
- IContainer cont = null;
- if (site != null) {
- cont = site.getContainer();
- }
-
- while(enum.hasMoreItems() && cont != null) {
- cont.add((IComponent)enum.nextItem());
- }
-
- }
-
- public String getImportHTML() {
- return this.m_html;
- }
-
- String extractNameFromData(byte[] pData) {
- int pCur = 15;
- if (pData != null && pData.length >= pCur + 4) {
- int nLen = pData.length;
- long lSize = (long)(pData[pCur + 3] << 32 | pData[pCur + 2] << 16 | pData[pCur + 1] << 8 | pData[pCur]);
- StringBuffer sb = new StringBuffer(32);
- pCur += 4;
- lSize = Math.min(lSize, (long)(nLen - pCur));
-
- for(int i = 0; (long)i < lSize; i += 2) {
- sb.append((char)(pData[i + pCur + 1] << 8 | pData[i + pCur]));
- }
-
- return sb.toString();
- } else {
- return "";
- }
- }
- }
-