001package org.vishia.gral.swt;
002
003import org.eclipse.swt.browser.Browser;
004import org.eclipse.swt.widgets.Composite;
005import org.eclipse.swt.widgets.Control;
006import org.eclipse.swt.widgets.Text;
007import org.vishia.byteData.VariableContainer_ifc;
008import org.vishia.gral.base.GralHtmlBox;
009import org.vishia.gral.base.GralMng;
010import org.vishia.gral.base.GralPanelContent;
011import org.vishia.gral.ifc.GralColor;
012import org.vishia.gral.ifc.GralRectangle;
013
014public class SwtHtmlBox extends GralHtmlBox.ImplAccess
015{
016  
017  
018  /**Version, history and license.
019   * <ul>
020   * <li>2012-07-13 Hartmut chg: It is registered in the mng yet, therefore resize works.
021   * </ul>
022   * 
023   * <b>Copyright/Copyleft</b>:<br>
024   * For this source the LGPL Lesser General Public License,
025   * published by the Free Software Foundation is valid.
026   * It means:
027   * <ol>
028   * <li> You can use this source without any restriction for any desired purpose.
029   * <li> You can redistribute copies of this source to everybody.
030   * <li> Every user of this source, also the user of redistribute copies
031   *    with or without payment, must accept this license for further using.
032   * <li> But the LPGL is not appropriate for a whole software product,
033   *    if this source is only a part of them. It means, the user
034   *    must publish this part of source,
035   *    but doesn't need to publish the whole source of the own product.
036   * <li> You can study and modify (improve) this source
037   *    for own using or for redistribution, but you have to license the
038   *    modified sources likewise under this LGPL Lesser General Public License.
039   *    You mustn't delete this Copyright/Copyleft inscription in this source file.
040   * </ol>
041   * If you intent to use this source without publishing its usage, you can get
042   * a second license subscribing a special contract with the author. 
043   * 
044   * @author Hartmut Schorrig = hartmut.schorrig@vishia.de
045   */
046  public static final int version = 20120713;
047
048  Browser boxSwt;
049  
050  String lastUrl="no-help", lastUrlOk ="no-help";
051  
052  public boolean bActiv;
053  
054  public SwtHtmlBox(GralHtmlBox box, SwtMng mngSwt)
055  { super(box);
056    //SwtMng mngSwt = (SwtMng)(GralMng.get()).impl;
057    GralPanelContent panel = widgg.pos().panel;
058    Composite parent;
059    if(panel == null){
060      parent = mngSwt.displaySwt.getActiveShell();
061    } else {
062      parent = (Composite)(panel.getWidgetImplementation());
063      //parent = ((SwtPanel)panel.getWidgetImplementation()).panelComposite; //(Composite)(panel.getPanelImpl());
064    }
065    try {
066      boxSwt = new Browser(parent,0);
067      //mng.registerWidget(this);
068      mngSwt.setPosAndSizeSwt(box.pos(), boxSwt, 0, 0);
069    } catch(Throwable exc){
070      System.err.println("can't create SWT-Browser");
071      exc.printStackTrace(System.err);
072    }
073    bActiv = false;
074  }
075
076  
077  static SwtHtmlBox createHtmlBox(GralHtmlBox widgg, SwtMng mng){
078    return new SwtHtmlBox(widgg, mng);
079    //
080  }
081
082  
083  
084  
085  @Override public void setUrl(String url){
086    //this.w
087    lastUrl = url;
088    if(bActiv){
089      boolean bOk = boxSwt.setUrl(url);
090      if(bOk){
091        lastUrlOk = url;
092      } else {
093        boxSwt.setUrl(lastUrlOk);
094      }
095    }
096  }
097
098  
099  
100  @Override public void activate(){
101    if(boxSwt !=null){
102      bActiv = true;
103      setUrl(lastUrl);
104    }
105  }
106  
107
108  
109  
110  @Override
111  public void removeWidgetImplementation()
112  {
113    // TODO Auto-generated method stub
114    
115  }
116
117  @Override
118  public boolean setFocusGThread()
119  {
120    // TODO Auto-generated method stub
121    return false;
122  }
123  
124  @Override public void setVisibleGThread(boolean bVisible) { super.setVisibleState(bVisible); boxSwt.setVisible(bVisible); }
125
126
127  @Override public void repaintGthread(){
128    if(boxSwt !=null){ boxSwt.redraw(); }
129  }
130
131
132  
133  @Override public Object getWidgetImplementation(){ return boxSwt; }
134  
135  
136  
137
138
139  @Override
140  public void setBoundsPixel(int x, int y, int dx, int dy)
141  {
142    // TODO Auto-generated method stub
143    
144  }
145
146  @Override public GralRectangle getPixelPositionSize()
147  {
148    // TODO Auto-generated method stub
149    return null;
150  }
151
152
153  
154  
155
156}