summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/document
diff options
context:
space:
mode:
Diffstat (limited to 'wizards/com/sun/star/wizards/document')
-rw-r--r--wizards/com/sun/star/wizards/document/Control.java356
-rw-r--r--wizards/com/sun/star/wizards/document/DatabaseControl.java266
-rw-r--r--wizards/com/sun/star/wizards/document/FormHandler.java597
-rw-r--r--wizards/com/sun/star/wizards/document/GridControl.java96
-rw-r--r--wizards/com/sun/star/wizards/document/OfficeDocument.java460
-rw-r--r--wizards/com/sun/star/wizards/document/Shape.java145
-rw-r--r--wizards/com/sun/star/wizards/document/TimeStampControl.java175
7 files changed, 2095 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/document/Control.java b/wizards/com/sun/star/wizards/document/Control.java
new file mode 100644
index 000000000000..602aab2fd423
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/Control.java
@@ -0,0 +1,356 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: Control.java,v $
+ * $Revision: 1.7 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.document;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.awt.XControl;
+import com.sun.star.awt.XControlModel;
+import com.sun.star.awt.XLayoutConstrains;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.container.XNamed;
+import com.sun.star.wizards.common.*;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.drawing.XShape;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.lang.IllegalArgumentException;
+
+public class Control extends Shape
+{
+
+ XControlModel xControlModel;
+ XControl xControl;
+ public XPropertySet xPropertySet;
+ XPropertySet xControlPropertySet;
+ XWindowPeer xWindowPeer;
+ Object oDefaultValue;
+ GridControl oGridControl;
+ String sServiceName;
+ XNamed xNamed;
+ final int SOMAXTEXTSIZE = 50;
+ private int icontroltype;
+ protected XNameContainer xFormName;
+ protected final int IIMGFIELDWIDTH = 3000;
+
+ public Control()
+ {
+ }
+
+ public Control(FormHandler _oFormHandler, String _sServiceName, Point _aPoint)
+ {
+ super(_oFormHandler, _sServiceName, _aPoint, null);
+ }
+
+ public Control(FormHandler _oFormHandler, XNameContainer _xFormName, int _icontroltype, String _FieldName, Point _aPoint, Size _aSize)
+ {
+ super(_oFormHandler, _aPoint, _aSize);
+ xFormName = _xFormName;
+ createControl(_icontroltype, _aPoint, _aSize, null, _FieldName);
+ }
+
+ public Control(FormHandler _oFormHandler, XShapes _xGroupShapes, XNameContainer _xFormName, int _icontroltype, Point _aPoint, Size _aSize)
+ {
+ super(_oFormHandler, _aPoint, _aSize);
+ xFormName = _xFormName;
+ createControl(_icontroltype, _aPoint, _aSize, _xGroupShapes, null);
+ }
+
+ public Control(FormHandler _oFormHandler, int _icontroltype, Point _aPoint, Size _aSize)
+ {
+ super(_oFormHandler, _aPoint, _aSize);
+ createControl(_icontroltype, _aPoint, _aSize, null, null);
+ }
+
+ public void createControl(int _icontroltype, Point _aPoint, Size _aSize, XShapes _xGroupShapes, String _FieldName)
+ {
+ try
+ {
+ icontroltype = _icontroltype;
+ sServiceName = oFormHandler.sModelServices[getControlType()];
+ Object oControlModel = oFormHandler.xMSFDoc.createInstance(sServiceName);
+ xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oControlModel);
+ xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oControlModel);
+ insertControlInContainer(_FieldName);
+ xControlShape.setControl(xControlModel);
+ if (_xGroupShapes == null)
+ {
+ oFormHandler.xDrawPage.add(xShape);
+ }
+ else
+ {
+ _xGroupShapes.add(xShape);
+ }
+ xControl = oFormHandler.xControlAccess.getControl(xControlModel);
+ xControlPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControl);
+ xWindowPeer = xControl.getPeer();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void insertControlInContainer(String _fieldname)
+ {
+ try
+ {
+ if (xFormName != null)
+ {
+ XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xFormName);
+ String sControlName = Desktop.getUniqueName(xNameAccess, getControlName(_fieldname));
+ xPropertySet.setPropertyValue("Name", sControlName);
+ xFormName.insertByName(sControlName, xControlModel);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public String getControlName(String _fieldname)
+ {
+ String controlname = "";
+ switch (getControlType())
+ {
+ case FormHandler.SOLABEL:
+ controlname = "lbl" + _fieldname;
+ break;
+ case FormHandler.SOTEXTBOX:
+ controlname = "txt" + _fieldname;
+ break;
+ case FormHandler.SOCHECKBOX:
+ controlname = "chk" + _fieldname;
+ break;
+ case FormHandler.SODATECONTROL:
+ controlname = "dat" + _fieldname;
+ break;
+ case FormHandler.SOTIMECONTROL:
+ controlname = "tim" + _fieldname;
+ break;
+ case FormHandler.SONUMERICCONTROL:
+ controlname = "fmt" + _fieldname;
+ break;
+ case FormHandler.SOGRIDCONTROL:
+ controlname = "grd" + _fieldname;
+ break;
+ case FormHandler.SOIMAGECONTROL:
+ controlname = "img" + _fieldname;
+ break;
+ default:
+ controlname = "ctrl" + _fieldname;
+ }
+ return controlname;
+ }
+
+ private void setDefaultValue(Object DatabaseField)
+ {
+ oDefaultValue = Helper.getUnoPropertyValue(DatabaseField, "DefaultValue");
+ }
+
+ public int getPreferredWidth(String sText)
+ {
+ Size aPeerSize = getPreferredSize(sText);
+ return ((aPeerSize.Width + 10) * oFormHandler.getXPixelFactor());
+ }
+
+ public int getPreferredHeight(String sText)
+ {
+ Size aPeerSize = getPreferredSize(sText);
+ if (getControlType() == FormHandler.SOCHECKBOX)
+ {
+ return (aPeerSize.Height * oFormHandler.getXPixelFactor());
+ }
+ else
+ {
+ return ((aPeerSize.Height + 2) * oFormHandler.getXPixelFactor());
+ }
+ }
+
+ public int getPreferredWidth()
+ {
+ if (getControlType() == FormHandler.SOIMAGECONTROL)
+ {
+ return IIMGFIELDWIDTH;
+ }
+ else
+ {
+ Size aPeerSize = getPeerSize();
+ // We increase the preferred Width a bit so that the control does not become too small
+ // when we change the border from "3D" to "Flat"
+ if (getControlType() == FormHandler.SOCHECKBOX)
+ {
+ return ((aPeerSize.Width * oFormHandler.getXPixelFactor()));
+ }
+ else
+ {
+ return ((aPeerSize.Width * oFormHandler.getXPixelFactor()) + 200);
+ }
+ }
+ }
+
+ public int getPreferredHeight()
+ {
+ if (getControlType() == FormHandler.SOIMAGECONTROL)
+ {
+ return 2000;
+ }
+ else
+ {
+ Size aPeerSize = getPeerSize();
+ int nHeight = aPeerSize.Height;
+ // We increase the preferred Height a bit so that the control does not become too small
+ // when we change the border from "3D" to "Flat"
+ return ((nHeight + 1) * oFormHandler.getYPixelFactor());
+ }
+ }
+
+ public Size getPreferredSize(String sText)
+ {
+ try
+ {
+ if (xPropertySet.getPropertySetInfo().hasPropertyByName("Text"))
+ {
+ xPropertySet.setPropertyValue("Text", sText);
+ }
+ else if (xPropertySet.getPropertySetInfo().hasPropertyByName("Label"))
+ {
+ xPropertySet.setPropertyValue("Label", sText);
+ }
+ else
+ {
+ throw new IllegalArgumentException();
+ }
+ return getPeer().getPreferredSize();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ return null;
+ }
+ }
+
+ public void setPropertyValue(String _sPropertyName, Object _aPropertyValue) throws Exception
+ {
+ if (xPropertySet.getPropertySetInfo().hasPropertyByName(_sPropertyName))
+ {
+ xPropertySet.setPropertyValue(_sPropertyName, _aPropertyValue);
+ }
+ }
+
+ /** the peer should be retrieved every time before it is used because it
+ * might be disposed otherwise
+ *
+ * @return
+ */
+ public XLayoutConstrains getPeer()
+ {
+ return (XLayoutConstrains) UnoRuntime.queryInterface(XLayoutConstrains.class, xControl.getPeer());
+ }
+
+ public Size getPeerSize()
+ {
+ try
+ {
+ Size aPreferredSize = null;
+ double dblEffMax = 0;
+ if (xPropertySet.getPropertySetInfo().hasPropertyByName("EffectiveMax"))
+ {
+ Object oValue = xPropertySet.getPropertyValue("EffectiveMax");
+ if (xPropertySet.getPropertyValue("EffectiveMax") != com.sun.star.uno.Any.VOID)
+ {
+ dblEffMax = AnyConverter.toDouble(xPropertySet.getPropertyValue("EffectiveMax"));
+ }
+ if (dblEffMax == 0)
+ {
+ // This is relevant for decimal fields
+ xPropertySet.setPropertyValue("EffectiveValue", new Double(99999));
+ }
+ else
+ {
+ xPropertySet.setPropertyValue("EffectiveValue", new Double(dblEffMax)); //new Double(100000.2)); //
+ }
+ aPreferredSize = getPeer().getPreferredSize();
+ xPropertySet.setPropertyValue("EffectiveValue", com.sun.star.uno.Any.VOID);
+ }
+ else if (getControlType() == FormHandler.SOCHECKBOX)
+ {
+ aPreferredSize = getPeer().getPreferredSize();
+ }
+ else if (getControlType() == FormHandler.SODATECONTROL)
+ {
+ xPropertySet.setPropertyValue("Date", new Integer(4711)); //TODO find a better date
+ aPreferredSize = getPeer().getPreferredSize();
+ xPropertySet.setPropertyValue("Date", com.sun.star.uno.Any.VOID);
+ }
+ else if (getControlType() == FormHandler.SOTIMECONTROL)
+ {
+ xPropertySet.setPropertyValue("Time", new Integer(47114)); //TODO find a better time
+ aPreferredSize = getPeer().getPreferredSize();
+ xPropertySet.setPropertyValue("Time", com.sun.star.uno.Any.VOID);
+ }
+ else
+ {
+ String stext;
+ short iTextLength = AnyConverter.toShort(xPropertySet.getPropertyValue("MaxTextLen"));
+ if (iTextLength < this.SOMAXTEXTSIZE)
+ {
+ stext = FormHandler.SOSIZETEXT.substring(0, this.SOMAXTEXTSIZE);
+ }
+ else
+ {
+ stext = FormHandler.SOSIZETEXT.substring(0, iTextLength);
+ }
+ xPropertySet.setPropertyValue("Text", stext);
+ aPreferredSize = getPeer().getPreferredSize();
+ xPropertySet.setPropertyValue("Text", "");
+ }
+ return aPreferredSize;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ return null;
+ }
+ }
+
+ /**
+ * @return
+ */
+ public int getControlType()
+ {
+ return icontroltype;
+ }
+}
diff --git a/wizards/com/sun/star/wizards/document/DatabaseControl.java b/wizards/com/sun/star/wizards/document/DatabaseControl.java
new file mode 100644
index 000000000000..ed48ddbc04ea
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/DatabaseControl.java
@@ -0,0 +1,266 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: DatabaseControl.java,v $
+ * $Revision: 1.9 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+package com.sun.star.wizards.document;
+
+import com.sun.star.awt.Point;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.sdbc.DataType;
+import com.sun.star.wizards.common.Desktop;
+import com.sun.star.wizards.common.Helper;
+import com.sun.star.wizards.db.FieldColumn;
+
+/**
+ * @author Administrator
+ *
+ * To change the template for this generated type comment go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+public class DatabaseControl extends Control
+{
+
+ private int m_nFieldType;
+ // private int iMemofieldwidth = IIMGFIELDWIDTH;
+ // private int iMemofieldheight = -1;
+ // private FieldColumn m_FieldColumn;
+
+ public DatabaseControl(GridControl _oGridControl, FieldColumn _curfieldcolumn)
+ {
+ super();
+ // m_FieldColumn = _curfieldcolumn;
+ if (_curfieldcolumn.getFieldType() != DataType.TIMESTAMP)
+ {
+ createGridColumn(_oGridControl, _curfieldcolumn, _curfieldcolumn.getFieldType(), _curfieldcolumn.getFieldTitle());
+ }
+ }
+
+ public DatabaseControl(GridControl _oGridControl, FieldColumn _curfieldcolumn, int _fieldtype, String _columntitle)
+ {
+ super();
+ // m_FieldColumn = _curfieldcolumn;
+ createGridColumn(_oGridControl, _curfieldcolumn, _fieldtype, _columntitle);
+ }
+
+ protected int getFieldType()
+ {
+ return m_nFieldType;
+ }
+
+ private void createGridColumn(GridControl _oGridControl, FieldColumn _curfieldcolumn, int _fieldtype, String _columntitle)
+ {
+ try
+ {
+ m_nFieldType = _fieldtype;
+ String sFieldName = _curfieldcolumn.getFieldName();
+ String sUniqueName = Desktop.getUniqueName(_oGridControl.xNameAccess, sFieldName);
+
+ String sGridColumnName = getGridColumnName();
+ XPropertySet xPropColumn = _oGridControl.xGridColumnFactory.createColumn(sGridColumnName);
+ xPropColumn.setPropertyValue("Name", sUniqueName);
+ boolean bHidden = false;
+ if (_fieldtype == DataType.LONGVARBINARY) //TODO CONTROLType abfragen!!!!!!
+ {
+ bHidden = true;
+ }
+ xPropColumn.setPropertyValue("Hidden", new Boolean(bHidden));
+ xPropColumn.setPropertyValue("DataField", sFieldName);
+ xPropColumn.setPropertyValue("Label", _columntitle);
+ xPropColumn.setPropertyValue("Width", new Integer(0)); // Width of column is adjusted to Columname
+ setNumericLimits();
+ _oGridControl.xNameContainer.insertByName(sFieldName, xPropColumn);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public DatabaseControl(FormHandler _oFormHandler, String _sServiceName, Point _aPoint)
+ {
+ super(_oFormHandler, _sServiceName, _aPoint);
+ }
+
+ public DatabaseControl(FormHandler _oFormHandler, XNameContainer _xFormName, String _curFieldName, int _fieldtype, Point _aPoint)
+ {
+ super(_oFormHandler, _xFormName, _oFormHandler.getControlType(_fieldtype), _curFieldName, _aPoint, null);
+ try
+ {
+ m_nFieldType = _fieldtype;
+ Helper.setUnoPropertyValue(xControlModel, "DataField", _curFieldName);
+ setNumericLimits();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public DatabaseControl(FormHandler _oFormHandler, XShapes _xGroupShapes, XNameContainer _xFormName, String _curFieldName, int _fieldtype, Point _aPoint)
+ {
+ super(_oFormHandler, _xGroupShapes, _xFormName, _oFormHandler.getControlType(_fieldtype), _aPoint, null);
+ try
+ {
+ m_nFieldType = _fieldtype;
+ Helper.setUnoPropertyValue(xControlModel, "DataField", _curFieldName);
+ setNumericLimits();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ private String getGridColumnName()
+ {
+ for (int i = 0; i < FormHandler.oControlData.length; i++)
+ {
+ if (FormHandler.oControlData[i].DataType == getFieldType())
+ {
+ return FormHandler.oControlData[i].GridColumnName;
+ }
+ }
+ return "";
+ }
+
+ public int getControlHeight()
+ {
+ if (getControlType() == FormHandler.SOIMAGECONTROL)
+ {
+ // return oFormHandler.getImageControlHeight();
+ final int nMemofieldheight = oFormHandler.getControlReferenceHeight() * 4;
+ return nMemofieldheight;
+ }
+ else
+ {
+ if (getFieldType() == DataType.LONGVARCHAR)
+ {
+ // Helper.setUnoPropertyValue(xControlModel, "MultiLine", Boolean.TRUE);
+ final int nMemofieldheight = oFormHandler.getControlReferenceHeight() * 4;
+ return nMemofieldheight;
+ }
+ else if (getControlType() == FormHandler.SOCHECKBOX)
+ {
+ return super.getPreferredHeight();
+ }
+ }
+ return oFormHandler.getControlReferenceHeight();
+ }
+
+ public int getControlWidth()
+ {
+ if (getControlType() == FormHandler.SOIMAGECONTROL)
+ {
+ return 2 * getControlHeight();
+ }
+ if (getFieldType() == DataType.LONGVARCHAR)
+ {
+ return 2 * getControlHeight();
+ }
+ else
+ {
+ return getPreferredWidth();
+ }
+ }
+
+ private static long m_nLongMax = 0;
+ public static long getLongMax()
+ {
+ if (m_nLongMax == 0)
+ {
+ }
+ return m_nLongMax;
+ }
+ public void setNumericLimits()
+ {
+ try
+ {
+ if (getControlType() == FormHandler.SONUMERICCONTROL)
+ {
+ xPropertySet.setPropertyValue("TreatAsNumber", Boolean.TRUE);
+ // Math.
+ // 2^63 - 1 = 9223372036854775807
+ // int nIntMax = 0x7fffffff;
+ // int nIntMin = -0x80000000;
+ // long nLongMax = nIntMax;
+ // nLongMax <<= (4*4);
+ // nLongMax |= 0xffff;
+ // nLongMax <<= (4*4);
+ // nLongMax |= 0xffff;
+
+ // long nLongMin = nIntMin;
+ // nLongMin <<= (8*4);
+
+ // long nLong2 = (long)9223372036854775807;
+
+ switch (getFieldType())
+ {
+ case DataType.BIGINT:
+ xPropertySet.setPropertyValue("EffectiveMax", new Double(Long.MAX_VALUE));
+ xPropertySet.setPropertyValue("EffectiveMin", new Double(Long.MIN_VALUE));
+ break;
+ case DataType.INTEGER:
+ xPropertySet.setPropertyValue("EffectiveMax", new Double(Integer.MAX_VALUE));
+ xPropertySet.setPropertyValue("EffectiveMin", new Double(Integer.MIN_VALUE));
+ break;
+ case DataType.SMALLINT:
+ xPropertySet.setPropertyValue("EffectiveMax", new Double(Short.MAX_VALUE));
+ xPropertySet.setPropertyValue("EffectiveMin", new Double(Short.MIN_VALUE));
+ break;
+ case DataType.TINYINT:
+ xPropertySet.setPropertyValue("EffectiveMax", new Double(127));
+ xPropertySet.setPropertyValue("EffectiveMin", new Double(-128));
+ break;
+ case DataType.FLOAT:
+ case DataType.REAL:
+ case DataType.DOUBLE:
+ case DataType.DECIMAL:
+ case DataType.NUMERIC:
+ break;
+ }
+ }
+ // else if (getControlType() == FormHandler.SOTEXTBOX)
+ // { // com.sun.star.sdbc.DataType.CHAR, com.sun.star.sdbc.DataType.VARCHAR, com.sun.star.sdbc.DataType.LONGVARCHAR
+ // }
+ else if (getControlType() == FormHandler.SOIMAGECONTROL)
+ {
+ xPropertySet.setPropertyValue("ScaleMode", com.sun.star.awt.ImageScaleMode.Isotropic);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+ /**
+ * @return
+ */
+}
diff --git a/wizards/com/sun/star/wizards/document/FormHandler.java b/wizards/com/sun/star/wizards/document/FormHandler.java
new file mode 100644
index 000000000000..20555455e2fe
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/FormHandler.java
@@ -0,0 +1,597 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: FormHandler.java,v $
+ * $Revision: 1.12 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.document;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.awt.VclWindowPeerAttribute;
+import com.sun.star.awt.XControlModel;
+import com.sun.star.awt.XDevice;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.container.XChild;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.view.XControlAccess;
+import com.sun.star.wizards.common.*;
+
+import com.sun.star.sdbc.DataType;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.Type;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.XInterface;
+import com.sun.star.drawing.XControlShape;
+import com.sun.star.drawing.XDrawPage;
+import com.sun.star.drawing.XDrawPageSupplier;
+import com.sun.star.drawing.XShape;
+import com.sun.star.drawing.XShapeGrouper;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.form.XFormsSupplier;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.container.XNamed;
+
+public class FormHandler
+{
+
+ public XFormsSupplier xFormsSupplier;
+ public XMultiServiceFactory xMSFDoc;
+ public XMultiServiceFactory xMSF;
+ public XDrawPage xDrawPage;
+ private XDrawPageSupplier xDrawPageSupplier;
+ public String[] sModelServices = new String[8];
+ public static ControlData[] oControlData;
+
+ public final static int SOLABEL = 0;
+ public final static int SOTEXTBOX = 1;
+ public final static int SOCHECKBOX = 2;
+ public final static int SODATECONTROL = 3;
+ public final static int SOTIMECONTROL = 4;
+ public final static int SONUMERICCONTROL = 5;
+ public final static int SOGRIDCONTROL = 6;
+ public final static int SOIMAGECONTROL = 7;
+ public final static int SODATETIMECONTROL = 8;
+ int iImageControlHeight = 2000;
+ public static String SOSIZETEXT = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.";
+ int iXPixelFactor = -1;
+ int iYPixelFactor = -1;
+ int iXNirwanaPos = 50000;
+ int iYNirwanaPos = 50000;
+ public int nLabelHeight = -1;
+ public int nDBRefHeight = -1;
+ public int BasicLabelDiffHeight = -1;
+ XNameAccess xNamedForms;
+ XControlAccess xControlAccess;
+ XShapeGrouper xShapeGrouper;
+ XNameContainer xNamedFormContainer;
+
+ public class ControlData
+ {
+
+ int DataType;
+ int ControlType;
+ String ControlService;
+ String GridColumnName;
+ boolean bIsText;
+ }
+
+ /** Creates a new instance of FormHandler */
+ public FormHandler(XMultiServiceFactory _xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSF = _xMSF;
+ xDrawPageSupplier = (XDrawPageSupplier) UnoRuntime.queryInterface(XDrawPageSupplier.class, xTextDocument);
+ xDrawPage = xDrawPageSupplier.getDrawPage();
+ xFormsSupplier = (XFormsSupplier) UnoRuntime.queryInterface(XFormsSupplier.class, xDrawPage);
+ xShapeGrouper = (XShapeGrouper) UnoRuntime.queryInterface(XShapeGrouper.class, xDrawPage);
+ xControlAccess = (XControlAccess) UnoRuntime.queryInterface(XControlAccess.class, xTextDocument.getCurrentController());
+ xMSFDoc = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ sModelServices[SOLABEL] = "com.sun.star.form.component.FixedText";
+ sModelServices[SOTEXTBOX] = "com.sun.star.form.component.TextField";
+ sModelServices[SOCHECKBOX] = "com.sun.star.form.component.CheckBox";
+ sModelServices[SODATECONTROL] = "com.sun.star.form.component.DateField";
+ sModelServices[SOTIMECONTROL] = "com.sun.star.form.component.TimeField";
+ sModelServices[SONUMERICCONTROL] = "com.sun.star.form.component.FormattedField";
+ sModelServices[SOGRIDCONTROL] = "com.sun.star.form.component.GridControl";
+ sModelServices[SOIMAGECONTROL] = "com.sun.star.form.component.DatabaseImageControl";
+
+ oControlData = new ControlData[22];
+ oControlData[0] = createControlData(DataType.BIT, SOCHECKBOX, "CheckBox", "CheckBox", false);
+ oControlData[1] = createControlData(DataType.BOOLEAN, SOCHECKBOX, "CheckBox", "CheckBox", false);
+ oControlData[2] = createControlData(DataType.TINYINT, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[3] = createControlData(DataType.SMALLINT, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[4] = createControlData(DataType.INTEGER, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[5] = createControlData(DataType.BIGINT, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[6] = createControlData(DataType.FLOAT, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[7] = createControlData(DataType.REAL, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[8] = createControlData(DataType.DOUBLE, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[9] = createControlData(DataType.NUMERIC, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[10] = createControlData(DataType.DECIMAL, SONUMERICCONTROL, "FormattedField", "FormattedField", false);
+ oControlData[11] = createControlData(DataType.CHAR, SOTEXTBOX, "TextField", "TextField", false);
+ oControlData[12] = createControlData(DataType.VARCHAR, SOTEXTBOX, "TextField", "TextField", true);
+ oControlData[13] = createControlData(DataType.LONGVARCHAR, SOTEXTBOX, "TextField", "TextField", true);
+ oControlData[14] = createControlData(DataType.DATE, SODATECONTROL, "DateField", "DateField", false);
+ oControlData[15] = createControlData(DataType.TIME, SOTIMECONTROL, "TimeField", "TimeField", false);
+ oControlData[16] = createControlData(DataType.TIMESTAMP, SODATECONTROL, "DateField", "TextField", false);
+ // oImageControlData = new ControlData[4];
+ oControlData[17] = createControlData(DataType.BINARY, SOIMAGECONTROL, "ImageControl", "TextField", false);
+ oControlData[18] = createControlData(DataType.VARBINARY, SOIMAGECONTROL, "ImageControl", "TextField", false);
+ oControlData[19] = createControlData(DataType.LONGVARBINARY, SOIMAGECONTROL, "ImageControl", "TextField", false);
+ oControlData[20] = createControlData(DataType.BLOB, SOIMAGECONTROL, "ImageControl", "TextField", false);
+
+ oControlData[21] = createControlData(DataType.OTHER, SOIMAGECONTROL, "ImageControl", "TextField", false);
+ }
+
+ public int getControlType(int _fieldtype)
+ {
+ for (int i = 0; i < oControlData.length; i++)
+ {
+ if (oControlData[i].DataType == _fieldtype)
+ {
+ final int nType = oControlData[i].ControlType;
+ return nType;
+ }
+ }
+ return -1;
+ }
+
+ public void setglobalMultiServiceFactory(XMultiServiceFactory _xMSF)
+ {
+ xMSF = _xMSF;
+ }
+
+ public String getModelServiceName(int _fieldtype)
+ {
+ int icontroltype = getControlType(_fieldtype);
+ if (icontroltype > -1)
+ {
+ return sModelServices[icontroltype];
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void initializeBasicControlValues()
+ {
+ Control oLabelControl = new Control(this, SOLABEL, new Point(), new Size());
+ XDevice xDevice = (XDevice) UnoRuntime.queryInterface(XDevice.class, oLabelControl.xWindowPeer);
+ iXPixelFactor = (int) (100000 / xDevice.getInfo().PixelPerMeterX);
+ iYPixelFactor = (int) (100000 / xDevice.getInfo().PixelPerMeterY);
+
+ nLabelHeight = (oLabelControl.getPreferredHeight("The quick brown fox...") + 1);
+ Control oTextControl = new Control(this, SOTEXTBOX, new Point(), new Size());
+ nDBRefHeight = (oTextControl.getPreferredHeight("The quick brown fox...") + 1);
+ BasicLabelDiffHeight = (nDBRefHeight - nLabelHeight) / 2;
+ xDrawPage.remove(oLabelControl.xShape);
+ xDrawPage.remove(oTextControl.xShape);
+ }
+
+ public ControlData createControlData(int _datatype, int _controltype, String _scontrolservicename, String _gridcolumnname, boolean _bIsTextControl)
+ {
+ ControlData curControlData = new ControlData();
+ curControlData.DataType = _datatype;
+ curControlData.ControlType = _controltype;
+ curControlData.ControlService = _scontrolservicename;
+ curControlData.GridColumnName = _gridcolumnname;
+ curControlData.bIsText = _bIsTextControl;
+ return curControlData;
+ }
+
+ public XNameContainer getDocumentForms()
+ {
+ XNameContainer xNamedForms = xFormsSupplier.getForms();
+ return xNamedForms;
+ }
+
+ public String getValueofHiddenControl(XNameAccess xNamedForm, String ControlName, String sMsg) throws com.sun.star.wizards.document.FormHandler.UnknownHiddenControlException
+ {
+ try
+ {
+ if (xNamedForm.hasByName(ControlName))
+ {
+ String ControlValue = AnyConverter.toString(com.sun.star.wizards.common.Helper.getUnoPropertyValue(xNamedForm.getByName(ControlName), "HiddenValue"));
+ return ControlValue;
+ }
+ else
+ {
+ throw new UnknownHiddenControlException(xNamedForm, ControlName, sMsg);
+ }
+ }
+ catch (Exception exception)
+ {
+ throw new UnknownHiddenControlException(xNamedForm, ControlName, sMsg);
+ }
+ }
+
+ public void insertHiddenControl(XNameAccess xNameAccess, XNameContainer xNamedForm, String ControlName, String ControlValue)
+ {
+ try
+ {
+ XInterface xHiddenControl;
+ if (xNameAccess.hasByName(ControlName) == true)
+ {
+ xHiddenControl = (XInterface) AnyConverter.toObject(new Type(XInterface.class), xNameAccess.getByName(ControlName));
+ }
+ else
+ {
+ xHiddenControl = (XInterface) xMSFDoc.createInstance("com.sun.star.form.component.HiddenControl");
+ xNamedForm.insertByName(ControlName, xHiddenControl);
+ }
+ Helper.setUnoPropertyValue(xHiddenControl, "HiddenValue", ControlValue);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public class UnknownHiddenControlException extends java.lang.Throwable
+ {
+
+ public UnknownHiddenControlException(XNameAccess xNamedForm, String ControlName, String sMsgHiddenControlisMissing)
+ {
+ XNamed xNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, xNamedForm);
+ String FormName = xNamed.getName();
+ sMsgHiddenControlisMissing = JavaTools.replaceSubString(sMsgHiddenControlisMissing, FormName, "<REPORTFORM>");
+ sMsgHiddenControlisMissing = JavaTools.replaceSubString(sMsgHiddenControlisMissing, ControlName, "<CONTROLNAME>");
+ SystemDialog.showMessageBox(xMSFDoc, "ErrorBox", VclWindowPeerAttribute.OK, sMsgHiddenControlisMissing);
+ }
+ }
+
+ public boolean hasFormByName(String _FormName)
+ {
+ xNamedFormContainer = getDocumentForms();
+ xNamedForms = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xNamedFormContainer);
+ return xNamedForms.hasByName(_FormName);
+ }
+
+ public void removeFormByName(String _FormName)
+ {
+ try
+ {
+ if (hasFormByName(_FormName))
+ {
+ removeControlsofForm(_FormName);
+ xNamedFormContainer.removeByName(_FormName);
+ }
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeControlsofForm(String _FormName)
+ {
+ try
+ {
+ for (int i = xDrawPage.getCount() - 1; i >= 0; i--)
+ {
+ if (belongsToForm(xDrawPage.getByIndex(i), _FormName))
+ {
+ XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xDrawPage.getByIndex(i));
+ xDrawPage.remove(xShape);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void removeElement( XNameContainer _parentContainer, String _formName )
+ {
+ try
+ {
+ _parentContainer.removeByName( _formName );
+ }
+ catch ( WrappedTargetException e )
+ {
+ e.printStackTrace( System.err );
+ }
+ catch( final NoSuchElementException e )
+ {
+ e.printStackTrace( System.err );
+ }
+ }
+
+ public boolean belongsToForm(Object _oDrawPageElement, String _FormName)
+ {
+ XServiceInfo xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, _oDrawPageElement);
+ if (xServiceInfo.supportsService("com.sun.star.drawing.ControlShape"))
+ {
+ XControlShape xControlShape = (XControlShape) UnoRuntime.queryInterface(XControlShape.class, _oDrawPageElement);
+ XControlModel xControlModel = xControlShape.getControl();
+ xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xControlShape.getControl());
+ if (xServiceInfo.supportsService("com.sun.star.form.FormComponent"))
+ {
+ XChild xChild = (XChild) UnoRuntime.queryInterface(XChild.class, xControlModel);
+ XNamed xNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, xChild.getParent());
+ String sName = xNamed.getName();
+ return _FormName.equals(sName);
+ }
+ }
+ return false;
+ }
+
+ public XNameContainer insertFormbyName(String _FormName, XNameContainer _xNamedFormContainer)
+ {
+ try
+ {
+ Object oDBForm;
+ if (!hasFormByName(_FormName))
+ {
+ oDBForm = xMSFDoc.createInstance("com.sun.star.form.component.Form");
+ _xNamedFormContainer.insertByName(_FormName, oDBForm);
+ XNameContainer xNamedForm;
+ xNamedForm = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDBForm);
+ return xNamedForm;
+ }
+ else
+ {
+ return getFormByName(_FormName);
+ }
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ return null;
+ }
+ }
+
+ public XNameContainer insertSubFormbyName(String _FormName, XNameContainer _xNamedFormContainer)
+ {
+ return insertFormbyName(_FormName, _xNamedFormContainer);
+ }
+
+ public XNameContainer insertFormbyName(String _FormName)
+ {
+ return insertFormbyName(_FormName, getDocumentForms());
+ }
+
+ public XNameContainer getFormByName(String _sname)
+ {
+ XNameContainer xNamedForm = null;
+ try
+ {
+ if (xNamedForms.hasByName(_sname))
+ {
+ Object oDBForm = AnyConverter.toObject(new Type(XInterface.class), Helper.getUnoObjectbyName(xNamedForms, _sname));
+ xNamedForm = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDBForm);
+ }
+ }
+ catch (IllegalArgumentException e)
+ {
+ e.printStackTrace(System.out);
+ }
+ return xNamedForm;
+ }
+
+ /**
+ * @return
+ */
+ public int getXPixelFactor()
+ {
+ if (iXPixelFactor == -1)
+ {
+ initializeBasicControlValues();
+ }
+ return iXPixelFactor;
+ }
+
+ /**
+ * @return
+ */
+ public int getYPixelFactor()
+ {
+ if (iYPixelFactor == -1)
+ {
+ initializeBasicControlValues();
+ }
+ return iYPixelFactor;
+ }
+
+ /**
+ * @param i
+ */
+ public void setXPixelFactor(int i)
+ {
+ iXPixelFactor = i;
+ }
+
+ /**
+ * @param i
+ */
+ public void setYPixelFactor(int i)
+ {
+ iYPixelFactor = i;
+ }
+
+ /**
+ * @return
+ */
+ public int getImageControlHeight()
+ {
+ return iImageControlHeight;
+ }
+
+ /**
+ * @param i
+ */
+ public void setImageControlHeight(int i)
+ {
+ iImageControlHeight = i;
+ }
+ // Note: as Shapes cannot be removed from the DrawPage without destroying
+ // the object we have to park them somewhere beyond the visible area of the page
+ public void moveShapesToNirwana(Control[] ControlList)
+ {
+ if (ControlList != null)
+ {
+ for (int i = 0; i < ControlList.length; i++)
+ {
+ if (ControlList[i] != null)
+// try {
+// this.xDrawPage.remove(ControlList[i].xShape);
+ {
+ ControlList[i].setPosition(new Point(this.iXNirwanaPos, this.iYNirwanaPos));
+// String sControlName = (String) ControlList[i].xPropertySet.getPropertyValue("Name");
+//
+// if (_xNamedForm.hasByName(sControlName))
+// _xNamedForm.removeByName(sControlName);
+// } catch (Exception e) {
+// e.printStackTrace(System.out);
+// }
+ }
+ }
+ }
+ }
+
+ public void moveShapesToNirwana()
+ {
+ try
+ {
+ for (int i = 0; i < this.xDrawPage.getCount(); i++)
+ {
+ XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xDrawPage.getByIndex(i));
+ xShape.setPosition(new Point(this.iXNirwanaPos, this.iYNirwanaPos));
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void removeAllShapes() throws Exception
+ {
+ for (int i = this.xDrawPage.getCount(); i > -1; i--)
+ {
+ XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xDrawPage.getByIndex(i));
+ removeShape(xShape);
+ }
+ }
+
+ /**
+ * By removing the shape the whole control is disposed too
+ *
+ */
+ public void removeShape(XShape _xShape)
+ {
+ xDrawPage.remove(_xShape);
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, _xShape);
+ xComponent.dispose();
+ }
+ // Destroy all Shapes in Nirwana
+ public void removeNirwanaShapes() throws Exception
+ {
+ for (int i = this.xDrawPage.getCount(); i > -1; i--)
+ {
+ XShape xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xDrawPage.getByIndex(i));
+ if (xShape.getPosition().Y < this.iYNirwanaPos)
+ {
+ xDrawPage.remove(xShape);
+ }
+ }
+ }
+
+ public XShape groupShapesTogether(XMultiServiceFactory _xMSF, XShape _xLabelShape, XShape _xControlShape)
+ {
+ try
+ {
+ Object oGroupShape = _xMSF.createInstance("com.sun.star.drawing.ShapeCollection");
+ XShapes xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, oGroupShape);
+ xShapes.add(_xLabelShape);
+ xShapes.add(_xControlShape);
+ return this.xShapeGrouper.group(xShapes);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ return null;
+ }
+ }
+
+ /**
+ * @return
+ */
+ public int getBasicLabelDiffHeight()
+ {
+ if (this.BasicLabelDiffHeight == -1)
+ {
+ initializeBasicControlValues();
+ }
+ return BasicLabelDiffHeight;
+ }
+
+ /**
+ * @return
+ */
+ public int getControlReferenceHeight()
+ {
+ if (this.nDBRefHeight == -1)
+ {
+ initializeBasicControlValues();
+ }
+ return nDBRefHeight;
+ }
+
+ /**
+ * @return
+ */
+ public int getLabelHeight()
+ {
+ if (this.nLabelHeight == -1)
+ {
+ initializeBasicControlValues();
+ }
+ return nLabelHeight;
+ }
+
+ public void setDrawObjectsCaptureMode(boolean _bCaptureObjects)
+ {
+ try
+ {
+ XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, this.xMSFDoc.createInstance("com.sun.star.text.DocumentSettings"));
+ xPropertySet.setPropertyValue("DoNotCaptureDrawObjsOnPage", new Boolean(!_bCaptureObjects));
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace(System.out);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/document/GridControl.java b/wizards/com/sun/star/wizards/document/GridControl.java
new file mode 100644
index 000000000000..426aa026213b
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/GridControl.java
@@ -0,0 +1,96 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: GridControl.java,v $
+ * $Revision: 1.7 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.document;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.awt.XControlModel;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.wizards.common.*;
+import com.sun.star.wizards.db.FieldColumn;
+import com.sun.star.sdbc.*;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.form.XGridColumnFactory;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+
+public class GridControl extends Shape
+{
+
+ FieldColumn[] fieldcolumns;
+ public XNameContainer xNameContainer;
+ public XGridColumnFactory xGridColumnFactory;
+ public XPropertySet xPropertySet;
+ XNameAccess xNameAccess;
+ final String SODEFAULTNAME = "Grid1";
+ XControlModel xControlModel;
+ public XComponent xComponent;
+
+ public GridControl(XMultiServiceFactory _xMSF, String _sname, FormHandler _oFormHandler, XNameContainer _xFormName, FieldColumn[] _fieldcolumns, Point _aPoint, Size _aSize)
+ {
+ super(_oFormHandler, _aPoint, _aSize);
+ try
+ {
+ fieldcolumns = _fieldcolumns;
+ Object oGridModel = oFormHandler.xMSFDoc.createInstance(oFormHandler.sModelServices[FormHandler.SOGRIDCONTROL]);
+ xNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oGridModel);
+ xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oGridModel);
+ _xFormName.insertByName(_sname, oGridModel);
+ xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oGridModel);
+ xControlShape.setControl(xControlModel);
+ xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oGridModel);
+ oFormHandler.xDrawPage.add(xShape);
+ xGridColumnFactory = (XGridColumnFactory) UnoRuntime.queryInterface(XGridColumnFactory.class, oGridModel);
+ xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, oGridModel);
+
+// Helper.setUnoPropertyValue(oGridModel, "Name", _sname);
+ for (int i = 0; i < fieldcolumns.length; i++)
+ {
+ FieldColumn curfieldcolumn = fieldcolumns[i];
+ if (curfieldcolumn.getFieldType() == DataType.TIMESTAMP)
+ {
+ TimeStampControl oControl = new TimeStampControl(new Resource(_xMSF, "", "dbw"), this, curfieldcolumn);
+ }
+ else
+ {
+ Control oControl = new DatabaseControl(this, curfieldcolumn);
+ }
+ }
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/document/OfficeDocument.java b/wizards/com/sun/star/wizards/document/OfficeDocument.java
new file mode 100644
index 000000000000..8dc513de0e9d
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/OfficeDocument.java
@@ -0,0 +1,460 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: OfficeDocument.java,v $
+ * $Revision: 1.9 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.document;
+
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.document.XDocumentProperties;
+import com.sun.star.document.XDocumentPropertiesSupplier;
+import com.sun.star.document.XEventsSupplier;
+import com.sun.star.document.XTypeDetection;
+import com.sun.star.drawing.XDrawPagesSupplier;
+import com.sun.star.wizards.common.*;
+import com.sun.star.awt.Rectangle;
+import com.sun.star.awt.VclWindowPeerAttribute;
+import com.sun.star.awt.WindowAttribute;
+import com.sun.star.awt.WindowDescriptor;
+import com.sun.star.awt.XToolkit;
+import com.sun.star.awt.XWindow;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.sheet.XCellRangeData;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.XCellRange;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XFrames;
+import com.sun.star.frame.XFramesSupplier;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XStorable;
+import com.sun.star.frame.XTerminateListener;
+import com.sun.star.util.XCloseable;
+import com.sun.star.util.XModifiable;
+
+public class OfficeDocument
+{
+
+ private XWindowPeer xWindowPeer;
+ private XMultiServiceFactory xMSF;
+
+ /** Creates a new instance of OfficeDocument */
+ public OfficeDocument(XMultiServiceFactory _xMSF)
+ {
+ xMSF = _xMSF;
+ }
+
+ public static void attachEventCall(XComponent xComponent, String EventName, String EventType, String EventURL)
+ {
+ try
+ {
+ XEventsSupplier xEventsSuppl = (XEventsSupplier) UnoRuntime.queryInterface(XEventsSupplier.class, xComponent);
+ PropertyValue[] oEventProperties = new PropertyValue[2];
+ oEventProperties[0] = new PropertyValue();
+ oEventProperties[0].Name = "EventType";
+ oEventProperties[0].Value = EventType; // "Service", "StarBasic"
+ oEventProperties[1] = new PropertyValue();
+ oEventProperties[1].Name = "Script"; //"URL";
+ oEventProperties[1].Value = EventURL;
+ xEventsSuppl.getEvents().replaceByName(EventName, oEventProperties);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public static void dispose(XMultiServiceFactory xMSF, XComponent xComponent)
+ {
+ try
+ {
+ if (xComponent != null)
+ {
+ XModifiable xModified = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, xComponent);
+ XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent);
+ XFrame xFrame = xModel.getCurrentController().getFrame();
+ if (xModified.isModified())
+ {
+ xModified.setModified(false);
+ }
+ Desktop.dispatchURL(xMSF, ".uno:CloseDoc", xFrame);
+ }
+ }
+ catch (PropertyVetoException exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ /**
+ * Create a new office document, attached to the given frame.
+ * @param desktop
+ * @param frame
+ * @param sDocumentType e.g. swriter, scalc, ( simpress, scalc : not tested)
+ * @return the document Component (implements XComponent) object ( XTextDocument, or XSpreadsheedDocument )
+ */
+ public static Object createNewDocument(XFrame frame, String sDocumentType, boolean preview, boolean readonly)
+ {
+
+ PropertyValue[] loadValues = new PropertyValue[2];
+ loadValues[0] = new PropertyValue();
+ loadValues[0].Name = "ReadOnly";
+ loadValues[0].Value = readonly ? Boolean.TRUE : Boolean.FALSE;
+ loadValues[1] = new PropertyValue();
+ loadValues[1].Name = "Preview";
+ loadValues[1].Value = preview ? Boolean.TRUE : Boolean.FALSE;
+
+ Object oDocument = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ XInterface xInterface = null;
+ String sURL = "private:factory/" + sDocumentType;
+
+ try
+ {
+ xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, frame);
+ /*if (frame.getName() == null || frame.getName().equals(""));
+ frame.setName("T" + System.currentTimeMillis());*/
+ XComponent xComponent = xComponentLoader.loadComponentFromURL(sURL, "_self", 0, loadValues);
+
+ if (sDocumentType == "swriter")
+ {
+ oDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent);
+ }
+ else if (sDocumentType == "scalc")
+ {
+ oDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, xComponent);
+ //TODO:
+ // else if (sDocumentType == "simpress")
+ // else if (sDocumentType == "sdraw")
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ return oDocument;
+ }
+
+ public static XFrame createNewFrame(XMultiServiceFactory xMSF, XTerminateListener listener)
+ {
+ return createNewFrame(xMSF, listener, "_blank");
+ }
+
+ public static XFrame createNewFrame(XMultiServiceFactory xMSF, XTerminateListener listener, String FrameName)
+ {
+ XFrame xFrame = null;
+ if (FrameName.equalsIgnoreCase("WIZARD_LIVE_PREVIEW"))
+ {
+ xFrame = createNewPreviewFrame(xMSF, listener);
+ }
+ else
+ {
+ XFrame xF = (XFrame) UnoRuntime.queryInterface(XFrame.class, Desktop.getDesktop(xMSF));
+ xFrame = xF.findFrame(FrameName, 0);
+ if (listener != null)
+ {
+ XFramesSupplier xFS = (XFramesSupplier) UnoRuntime.queryInterface(XFramesSupplier.class, xF);
+ XFrames xFF = xFS.getFrames();
+ xFF.remove(xFrame);
+ XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, xF);
+ xDesktop.addTerminateListener(listener);
+ }
+ }
+ return xFrame;
+ }
+
+ public static XFrame createNewPreviewFrame(XMultiServiceFactory xMSF, XTerminateListener listener)
+ {
+ XToolkit xToolkit = null;
+ try
+ {
+ xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, xMSF.createInstance("com.sun.star.awt.Toolkit"));
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ //describe the window and its properties
+ WindowDescriptor aDescriptor = new WindowDescriptor();
+ aDescriptor.Type = com.sun.star.awt.WindowClass.TOP;
+ aDescriptor.WindowServiceName = "window";
+ aDescriptor.ParentIndex = -1;
+ aDescriptor.Parent = null;
+ aDescriptor.Bounds = new Rectangle(10, 10, 640, 480);
+ aDescriptor.WindowAttributes = WindowAttribute.BORDER |
+ WindowAttribute.MOVEABLE |
+ WindowAttribute.SIZEABLE |
+ //WindowAttribute.CLOSEABLE |
+ VclWindowPeerAttribute.CLIPCHILDREN;
+
+ //create a new blank container window
+ XWindowPeer xPeer = null;
+ try
+ {
+ xPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xToolkit.createWindow(aDescriptor));
+ }
+ catch (IllegalArgumentException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xPeer);
+
+ //define some further properties of the frame window
+ //if it's needed .-)
+ //xPeer->setBackground(...);
+
+ //create new empty frame and set window on it
+ XFrame xFrame = null;
+ try
+ {
+ xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Frame"));
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ xFrame.initialize(xWindow);
+
+ //from now this frame is useable ...
+ //and not part of the desktop tree.
+ //You are alone with him .-)
+
+ if (listener != null)
+ {
+ Desktop.getDesktop(xMSF).addTerminateListener(listener);
+ }
+
+ return xFrame;
+
+ }
+
+ public static Object load(XInterface xInterface, String sURL, String sFrame, PropertyValue[] xValues)
+ {
+ // XComponent xComponent = null;
+ Object oDocument = null;
+ com.sun.star.frame.XComponentLoader xComponentLoader = null;
+ //XInterface xInterface = null;
+ try
+ {
+ xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, xInterface);
+ com.sun.star.lang.XComponent xComponent = xComponentLoader.loadComponentFromURL(sURL, sFrame, 0, xValues);
+
+ XServiceInfo xComponentService = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xComponent);
+ if (xComponentService.supportsService("com.sun.star.text.TextDocument"))
+ {
+ oDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent); //TODO: write if clauses for Calc, Impress and Draw
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ return oDocument;
+ }
+
+ public static boolean store(XMultiServiceFactory xMSF, XComponent xComponent, String StorePath, String FilterName, boolean bStoreToUrl, String sMsgSavingImpossible)
+ {
+ try
+ {
+ XStorable xStoreable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xComponent);
+ PropertyValue[] oStoreProperties;
+ if (FilterName.length() > 0)
+ {
+ oStoreProperties = new PropertyValue[1];
+ oStoreProperties[0] = new PropertyValue();
+ oStoreProperties[0].Name = "FilterName";
+ oStoreProperties[0].Value = FilterName;
+ }
+ else
+ {
+ oStoreProperties = new PropertyValue[0];
+ }
+ if (bStoreToUrl == true)
+ {
+ xStoreable.storeToURL(StorePath, oStoreProperties);
+ }
+ else
+ {
+ xStoreable.storeAsURL(StorePath, oStoreProperties);
+ }
+ return true;
+ }
+ catch (Exception exception)
+ {
+
+ exception.printStackTrace(System.out);
+ //TODO make sure that the peer of the dialog is used when available
+ showMessageBox(xMSF, "ErrorBox", VclWindowPeerAttribute.OK, sMsgSavingImpossible);
+ return false;
+ }
+ }
+
+ public static boolean close(XComponent xComponent)
+ {
+ boolean bState = false;
+ XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xComponent);
+
+ if (xModel != null)
+ {
+ XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xModel);
+
+ if (xCloseable != null)
+ {
+ try
+ {
+ xCloseable.close(true);
+ bState = true;
+ }
+ catch (com.sun.star.util.CloseVetoException exCloseVeto)
+ {
+ System.out.println("could not close doc");
+ bState = false;
+ }
+ }
+ else
+ {
+ XComponent xDisposeable = (XComponent) UnoRuntime.queryInterface(XComponent.class, xModel);
+ xDisposeable.dispose();
+ bState = true;
+ }
+ }
+ return bState;
+ }
+
+ public static void ArraytoCellRange(Object[][] datalist, Object oTable, int xpos, int ypos)
+ {
+ try
+ {
+ int rowcount = datalist.length;
+ if (rowcount > 0)
+ {
+ int colcount = datalist[0].length;
+ if (colcount > 0)
+ {
+ XCellRange xCellRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, oTable);
+ XCellRange xNewRange = xCellRange.getCellRangeByPosition(xpos, ypos, (colcount + xpos) - 1, (rowcount + ypos) - 1);
+ XCellRangeData xDataArray = (XCellRangeData) UnoRuntime.queryInterface(XCellRangeData.class, xNewRange);
+ xDataArray.setDataArray(datalist);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public static PropertyValue[] getFileMediaDecriptor(XMultiServiceFactory xmsf, String url)
+ throws Exception
+ {
+ Object typeDetect = xmsf.createInstance("com.sun.star.document.TypeDetection");
+
+ PropertyValue[][] mediaDescr = new PropertyValue[1][1];
+ mediaDescr[0][0] = new PropertyValue();
+ mediaDescr[0][0].Name = "URL";
+ mediaDescr[0][0].Value = url;
+
+ String type = ((XTypeDetection) UnoRuntime.queryInterface(XTypeDetection.class, typeDetect)).queryTypeByDescriptor(mediaDescr, true);
+
+ XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, typeDetect);
+ if (type.equals(""))
+ {
+ return null;
+ }
+ else
+ {
+ return (PropertyValue[]) xNameAccess.getByName(type);
+ }
+ }
+
+ public static PropertyValue[] getTypeMediaDescriptor(XMultiServiceFactory xmsf, String type)
+ throws Exception
+ {
+ Object typeDetect = xmsf.createInstance("com.sun.star.document.TypeDetection");
+ XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, typeDetect);
+ return (PropertyValue[]) xNameAccess.getByName(type);
+ }
+
+ /**
+ * returns the count of slides in a presentation,
+ * or the count of pages in a draw document.
+ * @param model a presentation or a draw document
+ * @return the number of slides/pages in the given document.
+ */
+ public static int getSlideCount(Object model)
+ {
+ XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, model);
+ return xDrawPagesSupplier.getDrawPages().getCount();
+ }
+
+ public static XDocumentProperties getDocumentProperties(Object document)
+ {
+ XDocumentPropertiesSupplier xDocumentPropertiesSupplier = (XDocumentPropertiesSupplier) UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, document);
+ return xDocumentPropertiesSupplier.getDocumentProperties();
+ }
+
+ public static int showMessageBox(XMultiServiceFactory xMSF, String windowServiceName, int windowAttribute, String MessageText)
+ {
+// if (getWindowPeer() != null)
+ // return SystemDialog.showMessageBox(xMSF, xWindowPeer, windowServiceName, windowAttribute, MessageText);
+// else
+ return SystemDialog.showMessageBox(xMSF, windowServiceName, windowAttribute, MessageText);
+ }
+
+ /**
+ * @return Returns the xWindowPeer.
+ */
+ public XWindowPeer getWindowPeer()
+ {
+ return xWindowPeer;
+ }
+
+ /**
+ * @param windowPeer The xWindowPeer to set.
+ * Should be called as soon as a Windowpeer of a wizard dialog is available
+ * The windowpeer is needed to call a Messagebox
+ */
+ public void setWindowPeer(XWindowPeer windowPeer)
+ {
+ xWindowPeer = windowPeer;
+ }
+}
diff --git a/wizards/com/sun/star/wizards/document/Shape.java b/wizards/com/sun/star/wizards/document/Shape.java
new file mode 100644
index 000000000000..a038ad629d6a
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/Shape.java
@@ -0,0 +1,145 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: Shape.java,v $
+ * $Revision: 1.6 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.document;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.drawing.XControlShape;
+import com.sun.star.drawing.XShape;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.text.TextContentAnchorType;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.wizards.common.Helper;
+
+/**
+ * @author Administrator
+ *
+ * To change the template for this generated type comment go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+public class Shape
+{
+
+ public XShape xShape;
+ protected FormHandler oFormHandler;
+ public XServiceInfo xServiceInfo;
+ protected Point aPoint;
+ protected Size aSize;
+ protected XControlShape xControlShape;
+ public XMultiServiceFactory xMSF;
+ public XShapes xShapes;
+
+ public Shape(FormHandler _oFormHandler, Point _aPoint, Size _aSize)
+ {
+ this.aPoint = _aPoint;
+ this.aSize = _aSize;
+ this.oFormHandler = _oFormHandler;
+ createShape("com.sun.star.drawing.ControlShape");
+ }
+
+ public Shape(FormHandler _oFormHandler, String _sServiceName, Point _aPoint, Size _aSize)
+ {
+ try
+ {
+ this.aPoint = _aPoint;
+ this.aSize = _aSize;
+ this.oFormHandler = _oFormHandler;
+ Object oShape = oFormHandler.xMSF.createInstance(_sServiceName);
+ xShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, oShape);
+ xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, oShape);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public Shape()
+ {
+ }
+
+ private void createShape(String sServiceName)
+ {
+ try
+ {
+ xMSF = oFormHandler.xMSFDoc;
+ Object oShape = xMSF.createInstance(sServiceName);
+ xShape = (XShape) UnoRuntime.queryInterface(XShape.class, oShape);
+ xShape.setPosition(aPoint);
+ if (aSize != null)
+ {
+ xShape.setSize(aSize);
+ }
+ else
+ {
+ xShape.setSize(new Size(1000, 100));
+ }
+ Helper.setUnoPropertyValue(xShape, "AnchorType", TextContentAnchorType.AT_PARAGRAPH);
+ xServiceInfo = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, xShape);
+ xControlShape = (XControlShape) UnoRuntime.queryInterface(XControlShape.class, xShape);
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public Size getSize()
+ {
+ return xShape.getSize();
+ }
+
+ public void setSize(Size _aSize)
+ {
+ try
+ {
+ xShape.setSize(_aSize);
+ }
+ catch (PropertyVetoException e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public Point getPosition()
+ {
+ return xShape.getPosition();
+ }
+
+ public void setPosition(Point _aPoint)
+ {
+ xShape.setPosition(_aPoint);
+ }
+}
diff --git a/wizards/com/sun/star/wizards/document/TimeStampControl.java b/wizards/com/sun/star/wizards/document/TimeStampControl.java
new file mode 100644
index 000000000000..52209308edc1
--- /dev/null
+++ b/wizards/com/sun/star/wizards/document/TimeStampControl.java
@@ -0,0 +1,175 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: TimeStampControl.java,v $
+ * $Revision: 1.7 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+package com.sun.star.wizards.document;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.wizards.common.*;
+import com.sun.star.wizards.db.FieldColumn;
+import com.sun.star.wizards.ui.*;
+import com.sun.star.sdbc.*;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.container.XNameContainer;
+import com.sun.star.drawing.XControlShape;
+import com.sun.star.drawing.XShape;
+import com.sun.star.drawing.XShapes;
+
+public class TimeStampControl extends DatabaseControl
+{
+
+ DatabaseControl oDateControl;
+ DatabaseControl oTimeControl;
+// XShape xGroupShape;
+ Resource oResource;
+ private String sDateAppendix; // = GetResText(RID_FORM + 4)
+ private String sTimeAppendix; // = GetResText(RID_FORM + 5)
+ XShapes xGroupShapes = null;
+ double nreldatewidth;
+ double nreltimewidth;
+ int nTimeWidth;
+ int nDBWidth;
+ int nDateWidth;
+ XShape xShapeGroup;
+
+ public TimeStampControl(Resource _oResource, FormHandler _oFormHandler, XNameContainer _xFormName, String _curFieldName, Point _aPoint)
+ {
+ super(_oFormHandler, "com.sun.star.drawing.ShapeCollection", _aPoint);
+ oResource = _oResource;
+// xGroupShape = xShape;
+ oDateControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.DATE, aPoint);
+ int nDBHeight = oDateControl.getControlHeight();
+ nDateWidth = oDateControl.getPreferredWidth();
+ oDateControl.setSize(new Size(nDateWidth, nDBHeight));
+ Point aTimePoint = new Point(aPoint.X + 10 + nDateWidth, aPoint.Y);
+ oTimeControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.TIME, aTimePoint);
+ nTimeWidth = oTimeControl.getPreferredWidth();
+ oTimeControl.setSize(new Size(nTimeWidth, nDBHeight));
+ nDBWidth = nDateWidth + nTimeWidth + 10;
+ xShapes.add(oDateControl.xShape);
+ xShapes.add(oTimeControl.xShape);
+ xShapeGroup = _oFormHandler.xShapeGrouper.group(xShapes);
+ xShapeGroup = (XShape) UnoRuntime.queryInterface(XShape.class, xShapeGroup);
+ nreldatewidth = 1.0 / ((double) getSize().Width / (double) nDateWidth);
+ nreltimewidth = 1.0 - nreldatewidth;
+ }
+
+ public XPropertySet getControlofGroupShapeByIndex(int _i)
+ {
+ try
+ {
+ if (_i < xShapes.getCount())
+ {
+ Object oControl = xShapes.getByIndex(_i);
+ XControlShape xControlShape = (XControlShape) UnoRuntime.queryInterface(XControlShape.class, oControl);
+ XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlShape.getControl());
+ return xPropertySet;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ return null;
+ }
+
+ public TimeStampControl(Resource _oResource, GridControl _oGridControl, FieldColumn _curfieldcolumn)
+ {
+ super(_oGridControl, _curfieldcolumn);
+ oResource = _oResource;
+ sDateAppendix = oResource.getResText(UIConsts.RID_FORM + 88);
+ sTimeAppendix = oResource.getResText(UIConsts.RID_FORM + 89);
+ oDateControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.DATE, _curfieldcolumn.getFieldTitle() + " " + sDateAppendix);
+ oTimeControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.TIME, _curfieldcolumn.getFieldTitle() + " " + sTimeAppendix);
+ }
+
+ public void setPropertyValue(String _sPropertyName, Object _aPropertyValue) throws Exception
+ {
+ oDateControl.setPropertyValue(_sPropertyName, _aPropertyValue);
+ oTimeControl.setPropertyValue(_sPropertyName, _aPropertyValue);
+ }
+
+ public int getPreferredWidth()
+ {
+ return nDBWidth;
+ }
+
+ public void setSize(Size _aSize)
+ {
+ try
+ {
+ int ndatewidth = (int) (nreldatewidth * (double) _aSize.Width);
+ int ntimewidth = (int) (nreltimewidth * (double) _aSize.Width);
+ oDateControl.xShape.setSize(new Size(ndatewidth, _aSize.Height));
+ oTimeControl.xShape.setSize(new Size(ntimewidth, _aSize.Height));
+ }
+ catch (PropertyVetoException e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public Size getSize()
+ {
+ int ncontrolwidth = oDateControl.xShape.getSize().Width + oTimeControl.xShape.getSize().Width;
+ return new Size(ncontrolwidth, oDateControl.xShape.getSize().Height);
+ }
+
+ public Point getPosition()
+ {
+ return xShapeGroup.getPosition();
+ }
+
+ public void setPosition(Point _aPoint)
+ {
+ // --> TESTING
+ Point aBeforePt = xShapeGroup.getPosition();
+ // <--
+ xShapeGroup.setPosition(_aPoint);
+// oDateControl.xShape.setPosition(_aPoint);
+// Point atimepoint = new Point(oDateControl.xShape.getPosition().X + oDateControl.xShape.getSize().Width, oDateControl.xShape.getPosition().Y );
+// oTimeControl.xShape.setPosition(atimepoint);
+ // --> TESTING
+ Point aAfterPt = xShapeGroup.getPosition();
+ // <--
+ }
+
+ public int getControlType()
+ {
+ return FormHandler.SODATETIMECONTROL;
+ }
+}
+
+
+
+
+