diff options
Diffstat (limited to 'wizards/com/sun/star/wizards/document')
-rw-r--r-- | wizards/com/sun/star/wizards/document/Control.java | 346 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/DatabaseControl.java | 208 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/FormHandler.java | 447 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/GridControl.java | 90 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/OfficeDocument.java | 229 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/OfficeDocument.py | 208 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/Shape.java | 131 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/TimeStampControl.java | 111 | ||||
-rw-r--r-- | wizards/com/sun/star/wizards/document/__init__.py | 0 |
9 files changed, 1770 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 000000000..5731aa7cf --- /dev/null +++ b/wizards/com/sun/star/wizards/document/Control.java @@ -0,0 +1,346 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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.beans.XPropertySetInfo; +import com.sun.star.container.XNameAccess; +import com.sun.star.container.XNameContainer; +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.XShapes; +import com.sun.star.lang.IllegalArgumentException; +import com.sun.star.util.Date; +import com.sun.star.util.Time; + +public class Control extends Shape +{ + + XControlModel xControlModel; + private XControl xControl; + public XPropertySet xPropertySet; + XWindowPeer xWindowPeer; + private static final int SOMAXTEXTSIZE = 50; + private int icontroltype; + private XNameContainer xFormName; + private static 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, null, _FieldName); + } + + public Control(FormHandler _oFormHandler, int _icontroltype, Point _aPoint, Size _aSize) + { + super(_oFormHandler, _aPoint, _aSize); + createControl(_icontroltype, null, null); + } + + private void createControl(int _icontroltype, XShapes _xGroupShapes, String _FieldName) + { + try + { + icontroltype = _icontroltype; + String sServiceName = oFormHandler.sModelServices[icontroltype]; + Object oControlModel = oFormHandler.xMSFDoc.createInstance(sServiceName); + xControlModel = UnoRuntime.queryInterface( XControlModel.class, oControlModel ); + xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, oControlModel ); + + XPropertySetInfo xPSI = xPropertySet.getPropertySetInfo(); + if ( xPSI.hasPropertyByName( "MouseWheelBehavior" ) ) + xPropertySet.setPropertyValue( "MouseWheelBehavior", Short.valueOf( com.sun.star.awt.MouseWheelBehavior.SCROLL_DISABLED ) ); + + insertControlInContainer(_FieldName); + xControlShape.setControl(xControlModel); + if (_xGroupShapes == null) + { + oFormHandler.xDrawPage.add(xShape); + } + else + { + _xGroupShapes.add(xShape); + } + xControl = oFormHandler.xControlAccess.getControl(xControlModel); + UnoRuntime.queryInterface( XPropertySet.class, xControl ); + xWindowPeer = xControl.getPeer(); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private void insertControlInContainer(String _fieldname) + { + try + { + if (xFormName != null) + { + XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, xFormName); + String sControlName = Desktop.getUniqueName(xNameAccess, getControlName(_fieldname)); + xPropertySet.setPropertyValue(PropertyNames.PROPERTY_NAME, sControlName); + xFormName.insertByName(sControlName, xControlModel); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + private String getControlName(String _fieldname) + { + String controlname = PropertyNames.EMPTY_STRING; + 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; + } + + 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(); + int nWidth; + if (aPeerSize == null) + nWidth = 0; + else + nWidth = aPeerSize.Width; + + // 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 nWidth * oFormHandler.getXPixelFactor(); + } + else + { + return (nWidth * oFormHandler.getXPixelFactor()) + 200; + } + } + } + + public int getPreferredHeight() + { + if (getControlType() == FormHandler.SOIMAGECONTROL) + { + return 2000; + } + else + { + Size aPeerSize = getPeerSize(); + int nHeight; + if (aPeerSize == null) + nHeight = 0; + else + 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()); + } + } + + private Size getPreferredSize(String sText) + { + try + { + if (xPropertySet.getPropertySetInfo().hasPropertyByName("Text")) + { + xPropertySet.setPropertyValue("Text", sText); + } + else if (xPropertySet.getPropertySetInfo().hasPropertyByName(PropertyNames.PROPERTY_LABEL)) + { + xPropertySet.setPropertyValue(PropertyNames.PROPERTY_LABEL, sText); + } + else + { + throw new IllegalArgumentException(); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + return getPeer().getPreferredSize(); + } + + 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 + */ + private XLayoutConstrains getPeer() + { + return UnoRuntime.queryInterface(XLayoutConstrains.class, xControl.getPeer()); + } + + private Size getPeerSize() + { + try + { + Size aPreferredSize = null; + double dblEffMax = 0; + if (xPropertySet.getPropertySetInfo().hasPropertyByName("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) + { + Date d = new Date(); + d.Day = 30; + d.Month = 12; + d.Year = 9999; + xPropertySet.setPropertyValue("Date", d); + aPreferredSize = getPeer().getPreferredSize(); + xPropertySet.setPropertyValue("Date", com.sun.star.uno.Any.VOID); + } + else if (getControlType() == FormHandler.SOTIMECONTROL) + { + Time t = new Time(); + t.NanoSeconds = 999999999; + t.Seconds = 59; + t.Minutes = 59; + t.Hours = 22; + xPropertySet.setPropertyValue("Time", t); + aPreferredSize = getPeer().getPreferredSize(); + xPropertySet.setPropertyValue("Time", com.sun.star.uno.Any.VOID); + } + else + { + String stext; + short iTextLength = AnyConverter.toShort(xPropertySet.getPropertyValue("MaxTextLen")); + if (iTextLength < SOMAXTEXTSIZE) + { + stext = FormHandler.SOSIZETEXT.substring(0, SOMAXTEXTSIZE); + } + else + { + stext = FormHandler.SOSIZETEXT.substring(0, iTextLength); + } + xPropertySet.setPropertyValue("Text", stext); + aPreferredSize = getPeer().getPreferredSize(); + xPropertySet.setPropertyValue("Text", PropertyNames.EMPTY_STRING); + } + return aPreferredSize; + } + catch (Exception e) + { + e.printStackTrace(System.err); + return null; + } + } + + 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 000000000..a90cc849f --- /dev/null +++ b/wizards/com/sun/star/wizards/document/DatabaseControl.java @@ -0,0 +1,208 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +package com.sun.star.wizards.document; + +import com.sun.star.awt.Point; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; +import com.sun.star.container.XNameContainer; +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.common.PropertyNames; +import com.sun.star.wizards.db.FieldColumn; + +/** + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class DatabaseControl extends Control +{ + + private int m_nFieldType; + + public DatabaseControl(GridControl _oGridControl, FieldColumn _curfieldcolumn) + { + super(); + if (_curfieldcolumn.getFieldType() != DataType.TIMESTAMP) + { + createGridColumn(_oGridControl, _curfieldcolumn, _curfieldcolumn.getFieldType(), _curfieldcolumn.getFieldTitle()); + } + } + + public DatabaseControl(GridControl _oGridControl, FieldColumn _curfieldcolumn, int _fieldtype, String _columntitle) + { + super(); + createGridColumn(_oGridControl, _curfieldcolumn, _fieldtype, _columntitle); + } + + private 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(PropertyNames.PROPERTY_NAME, sUniqueName); + boolean bHidden = false; + if (_fieldtype == DataType.LONGVARBINARY) //TODO CONTROLType abfragen!!!!!! + { + bHidden = true; + } + xPropColumn.setPropertyValue("Hidden", Boolean.valueOf(bHidden)); + xPropColumn.setPropertyValue("DataField", sFieldName); + xPropColumn.setPropertyValue(PropertyNames.PROPERTY_LABEL, _columntitle); + xPropColumn.setPropertyValue(PropertyNames.PROPERTY_WIDTH, 0); // Width of column is adjusted to Columname + + XPropertySetInfo xPSI = xPropColumn.getPropertySetInfo(); + if ( xPSI.hasPropertyByName( "MouseWheelBehavior" ) ) + xPropColumn.setPropertyValue( "MouseWheelBehavior", Short.valueOf( com.sun.star.awt.MouseWheelBehavior.SCROLL_DISABLED ) ); + + setNumericLimits(); + _oGridControl.xNameContainer.insertByName(sFieldName, xPropColumn); + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + 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.err); + } + } + + private String getGridColumnName() + { + for (int i = 0; i < FormHandler.oControlData.length; i++) + { + if (FormHandler.oControlData[i].DataType == getFieldType()) + { + return FormHandler.oControlData[i].GridColumnName; + } + } + return PropertyNames.EMPTY_STRING; + } + + public int getControlHeight() + { + if (getControlType() == FormHandler.SOIMAGECONTROL) + { + return oFormHandler.getControlReferenceHeight() * 4; + } + else + { + if (getFieldType() == DataType.LONGVARCHAR) + { + return oFormHandler.getControlReferenceHeight() * 4; + } + 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 void setNumericLimits() + { + try + { + if (getControlType() == FormHandler.SONUMERICCONTROL) + { + xPropertySet.setPropertyValue("TreatAsNumber", Boolean.TRUE); + 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(Byte.MAX_VALUE)); + xPropertySet.setPropertyValue("EffectiveMin", new Double(Byte.MIN_VALUE)); + break; + case DataType.FLOAT: + case DataType.REAL: + case DataType.DOUBLE: + case DataType.DECIMAL: + case DataType.NUMERIC: + break; + } + } + else if (getControlType() == FormHandler.SOIMAGECONTROL) + { + xPropertySet.setPropertyValue("ScaleMode", com.sun.star.awt.ImageScaleMode.ISOTROPIC); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + /** + * @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 000000000..6ff44ceb3 --- /dev/null +++ b/wizards/com/sun/star/wizards/document/FormHandler.java @@ -0,0 +1,447 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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.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; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class FormHandler +{ + private static final String CHECKBOX = "CheckBox"; + private static final String DATEFIELD = "DateField"; + private static final String FORMATTEDFIELD = "FormattedField"; + private static final String TEXTFIELD = "TextField"; + private static final String TIMEFIELD = "TimeField"; + + private XFormsSupplier xFormsSupplier; + public XMultiServiceFactory xMSFDoc; + public XMultiServiceFactory xMSF; + public XDrawPage xDrawPage; + public String[] sModelServices = new String[8]; + public static ControlData[] oControlData; + + public static final int SOLABEL = 0; + public static final int SOTEXTBOX = 1; + public static final int SOCHECKBOX = 2; + public static final int SODATECONTROL = 3; + public static final int SOTIMECONTROL = 4; + public static final int SONUMERICCONTROL = 5; + public static final int SOGRIDCONTROL = 6; + public static final int SOIMAGECONTROL = 7; + public static final int SODATETIMECONTROL = 8; + public static String SOSIZETEXT = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog."; + private int iXPixelFactor = -1; + private int iYPixelFactor = -1; + private int iXNirwanaPos = 50000; + private int iYNirwanaPos = 50000; + private int nLabelHeight = -1; + private int nDBRefHeight = -1; + private int BasicLabelDiffHeight = -1; + private XNameAccess xNamedForms; + XControlAccess xControlAccess; + XShapeGrouper xShapeGrouper; + + public static class ControlData + { + int DataType; + private int ControlType; + String GridColumnName; + } + + /** 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 = UnoRuntime.queryInterface(XFormsSupplier.class, xDrawPage); + xShapeGrouper = UnoRuntime.queryInterface(XShapeGrouper.class, xDrawPage); + xControlAccess = UnoRuntime.queryInterface(XControlAccess.class, xTextDocument.getCurrentController()); + xMSFDoc = 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[23]; + oControlData[0] = createControlData(DataType.BIT, SOCHECKBOX, CHECKBOX); + oControlData[1] = createControlData(DataType.BOOLEAN, SOCHECKBOX, CHECKBOX); + oControlData[2] = createControlData(DataType.TINYINT, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[3] = createControlData(DataType.SMALLINT, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[4] = createControlData(DataType.INTEGER, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[5] = createControlData(DataType.BIGINT, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[6] = createControlData(DataType.FLOAT, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[7] = createControlData(DataType.REAL, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[8] = createControlData(DataType.DOUBLE, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[9] = createControlData(DataType.NUMERIC, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[10] = createControlData(DataType.DECIMAL, SONUMERICCONTROL, FORMATTEDFIELD); + oControlData[11] = createControlData(DataType.CHAR, SOTEXTBOX, TEXTFIELD); + oControlData[12] = createControlData(DataType.VARCHAR, SOTEXTBOX, TEXTFIELD); + oControlData[13] = createControlData(DataType.LONGVARCHAR, SOTEXTBOX, TEXTFIELD); + oControlData[14] = createControlData(DataType.DATE, SODATECONTROL, DATEFIELD); + oControlData[15] = createControlData(DataType.TIME, SOTIMECONTROL, TIMEFIELD); + oControlData[16] = createControlData(DataType.TIMESTAMP, SODATECONTROL, TEXTFIELD); + oControlData[17] = createControlData(DataType.BINARY, SOIMAGECONTROL, TEXTFIELD); + oControlData[18] = createControlData(DataType.VARBINARY, SOIMAGECONTROL, TEXTFIELD); + oControlData[19] = createControlData(DataType.LONGVARBINARY, SOIMAGECONTROL, TEXTFIELD); + oControlData[20] = createControlData(DataType.BLOB, SOIMAGECONTROL, TEXTFIELD); + oControlData[21] = createControlData(DataType.CLOB, SOIMAGECONTROL, TEXTFIELD); + + oControlData[22] = createControlData(DataType.OTHER, SOIMAGECONTROL, TEXTFIELD); + } + + public int getControlType(int _fieldtype) + { + for (int i = 0; i < oControlData.length; i++) + { + if (oControlData[i].DataType == _fieldtype) + { + return oControlData[i].ControlType; + } + } + return -1; + } + + private void initializeBasicControlValues() + { + Control oLabelControl = new Control(this, SOLABEL, new Point(), new Size()); + 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); + } + + private ControlData createControlData(int _datatype, int _controltype, String _gridcolumnname) + { + ControlData curControlData = new ControlData(); + curControlData.DataType = _datatype; + curControlData.ControlType = _controltype; + curControlData.GridColumnName = _gridcolumnname; + return curControlData; + } + + public XNameContainer getDocumentForms() + { + return xFormsSupplier.getForms(); + } + + public String getValueofHiddenControl(XNameAccess xNamedForm, String ControlName) + { + String value = ""; + try + { + if (xNamedForm.hasByName(ControlName)) + { + value = AnyConverter.toString(com.sun.star.wizards.common.Helper.getUnoPropertyValue(xNamedForm.getByName(ControlName), "HiddenValue")); + } + } + catch (Exception ex) + { + Logger.getLogger( FormHandler.class.getName() ).log( Level.SEVERE, null, ex ); + } + return value; + } + + public void insertHiddenControl(XNameAccess xNameAccess, XNameContainer xNamedForm, String ControlName, String ControlValue) + { + try + { + XInterface xHiddenControl; + if (xNameAccess.hasByName(ControlName)) + { + 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 ex) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, ex); + } + } + + private boolean hasFormByName(String _FormName) + { + XNameContainer xNamedFormContainer = getDocumentForms(); + xNamedForms = UnoRuntime.queryInterface(XNameAccess.class, xNamedFormContainer); + return xNamedForms.hasByName(_FormName); + } + + public void removeControlsofForm(String _FormName) + { + try + { + for (int i = xDrawPage.getCount() - 1; i >= 0; i--) + { + if (belongsToForm(xDrawPage.getByIndex(i), _FormName)) + { + XShape xShape = UnoRuntime.queryInterface(XShape.class, xDrawPage.getByIndex(i)); + xDrawPage.remove(xShape); + } + } + } + catch (Exception e) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + } + } + + public void removeElement( XNameContainer _parentContainer, String _formName ) + { + try + { + _parentContainer.removeByName( _formName ); + } + catch ( WrappedTargetException e ) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + } + catch( final NoSuchElementException e ) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + } + } + + private boolean belongsToForm(Object _oDrawPageElement, String _FormName) + { + XServiceInfo xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, _oDrawPageElement); + while (xServiceInfo.supportsService("com.sun.star.drawing.GroupShape")) + { + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, _oDrawPageElement); + try + { + _oDrawPageElement = xShapes.getByIndex(0); + xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, _oDrawPageElement); + } + catch(final com.sun.star.uno.Exception e) + { + return false; + } + } + if (xServiceInfo.supportsService("com.sun.star.drawing.ControlShape")) + { + XControlShape xControlShape = UnoRuntime.queryInterface(XControlShape.class, _oDrawPageElement); + XControlModel xControlModel = xControlShape.getControl(); + xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, xControlShape.getControl()); + if (xServiceInfo.supportsService("com.sun.star.form.FormComponent")) + { + XChild xChild = UnoRuntime.queryInterface(XChild.class, xControlModel); + 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 = UnoRuntime.queryInterface(XNameContainer.class, oDBForm); + return xNamedForm; + } + else + { + return getFormByName(_FormName); + } + } + catch (com.sun.star.uno.Exception e) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + return null; + } + } + + public XNameContainer insertFormbyName(String _FormName) + { + return insertFormbyName(_FormName, getDocumentForms()); + } + + private 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 = UnoRuntime.queryInterface(XNameContainer.class, oDBForm); + } + } + catch (IllegalArgumentException e) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + } + return xNamedForm; + } + + public int getXPixelFactor() + { + if (iXPixelFactor == -1) + { + initializeBasicControlValues(); + } + return iXPixelFactor; + } + + public int getYPixelFactor() + { + if (iYPixelFactor == -1) + { + initializeBasicControlValues(); + } + return iYPixelFactor; + } + + // 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) + { + ControlList[i].setPosition(new Point(this.iXNirwanaPos, this.iYNirwanaPos)); + } + } + } + } + + /** + * By removing the shape the whole control is disposed too + * + */ + public void removeShape(XShape _xShape) + { + xDrawPage.remove(_xShape); + XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, _xShape); + xComponent.dispose(); + } + + public XShape groupShapesTogether(XMultiServiceFactory _xMSF, XShape _xLabelShape, XShape _xControlShape) + { + try + { + Object oGroupShape = _xMSF.createInstance("com.sun.star.drawing.ShapeCollection"); + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, oGroupShape); + xShapes.add(_xLabelShape); + xShapes.add(_xControlShape); + return this.xShapeGrouper.group(xShapes); + } + catch (Exception e) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + return null; + } + } + + public int getBasicLabelDiffHeight() + { + if (this.BasicLabelDiffHeight == -1) + { + initializeBasicControlValues(); + } + return BasicLabelDiffHeight; + } + + public int getControlReferenceHeight() + { + if (this.nDBRefHeight == -1) + { + initializeBasicControlValues(); + } + return nDBRefHeight; + } + + public int getLabelHeight() + { + if (this.nLabelHeight == -1) + { + initializeBasicControlValues(); + } + return nLabelHeight; + } + + public void setDrawObjectsCaptureMode(boolean _bCaptureObjects) + { + try + { + XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, this.xMSFDoc.createInstance("com.sun.star.text.DocumentSettings")); + xPropertySet.setPropertyValue("DoNotCaptureDrawObjsOnPage", Boolean.valueOf(!_bCaptureObjects)); + } + catch (Exception e) + { + Logger.getLogger(FormHandler.class.getName()).log(Level.SEVERE, null, e); + } + } +} 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 000000000..79f35de33 --- /dev/null +++ b/wizards/com/sun/star/wizards/document/GridControl.java @@ -0,0 +1,90 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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 +{ + + public XNameContainer xNameContainer; + public XGridColumnFactory xGridColumnFactory; + public XPropertySet xPropertySet; + XNameAccess xNameAccess; + public XComponent xComponent; + + public GridControl(XMultiServiceFactory _xMSF, String _sname, FormHandler _oFormHandler, XNameContainer _xFormName, FieldColumn[] _fieldcolumns, Point _aPoint, Size _aSize) + { + super(_oFormHandler, _aPoint, _aSize); + try + { + Object oGridModel = oFormHandler.xMSFDoc.createInstance(oFormHandler.sModelServices[FormHandler.SOGRIDCONTROL]); + xNameContainer = UnoRuntime.queryInterface( XNameContainer.class, oGridModel ); + xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, oGridModel ); + _xFormName.insertByName(_sname, oGridModel); + XControlModel xControlModel = UnoRuntime.queryInterface( XControlModel.class, oGridModel ); + // test if the interface was available + if (xControlModel == null) { + throw new Exception( + "Error: GridModel does not export XControlModel interface"); + } + + if (xControlShape == null) { + throw new Exception( + "Error: GridModel does not have a XControlShape"); + } + + xControlShape.setControl(xControlModel); + xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, oGridModel ); + oFormHandler.xDrawPage.add(xShape); + xGridColumnFactory = UnoRuntime.queryInterface( XGridColumnFactory.class, oGridModel ); + xComponent = UnoRuntime.queryInterface( XComponent.class, oGridModel ); + + for (int i = 0; i < _fieldcolumns.length; i++) + { + FieldColumn curfieldcolumn = _fieldcolumns[i]; + if (curfieldcolumn.getFieldType() == DataType.TIMESTAMP) + { + new TimeStampControl(new Resource(_xMSF), this, curfieldcolumn); + } + else + { + new DatabaseControl(this, curfieldcolumn); + } + } + + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } +} 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 000000000..1868c1989 --- /dev/null +++ b/wizards/com/sun/star/wizards/document/OfficeDocument.java @@ -0,0 +1,229 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.document; + +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; +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.sheet.XCellRangeData; +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.XTerminateListener; +import com.sun.star.util.XCloseable; +import com.sun.star.util.XModifiable; + +public class OfficeDocument +{ + + public static void dispose(XMultiServiceFactory xMSF, XComponent xComponent) + { + try + { + if (xComponent != null) + { + XModifiable xModified = UnoRuntime.queryInterface(XModifiable.class, xComponent); + 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 (Exception exception) + { + exception.printStackTrace(System.err); + } + } + + public static XFrame createNewFrame(XMultiServiceFactory xMSF, XTerminateListener listener) + { + return createNewFrame(xMSF, listener, "_blank"); + } + + private 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 = UnoRuntime.queryInterface(XFrame.class, Desktop.getDesktop(xMSF)); + xFrame = xF.findFrame(FrameName, 0); + if (listener != null) + { + XFramesSupplier xFS = UnoRuntime.queryInterface(XFramesSupplier.class, xF); + XFrames xFF = xFS.getFrames(); + xFF.remove(xFrame); + XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, xF); + xDesktop.addTerminateListener(listener); + } + } + return xFrame; + } + + private static XFrame createNewPreviewFrame(XMultiServiceFactory xMSF, XTerminateListener listener) + { + XFrame xFrame = null; + try + { + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, xMSF.createInstance("com.sun.star.awt.Toolkit")); + + //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 = UnoRuntime.queryInterface(XWindowPeer.class, xToolkit.createWindow(aDescriptor)); + 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 = UnoRuntime.queryInterface(XFrame.class, xMSF.createInstance("com.sun.star.frame.Frame")); + xFrame.initialize(xWindow); + + //from now this frame is usable ... + //and not part of the desktop tree. + //You are alone with him .-) + + if (listener != null) + { + Desktop.getDesktop(xMSF).addTerminateListener(listener); + } + } + catch (Exception e) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return xFrame; + + } + + public static Object load(XInterface xInterface, String sURL, String sFrame, PropertyValue[] xValues) + { + Object oDocument = null; + com.sun.star.frame.XComponentLoader xComponentLoader = null; + try + { + xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, xInterface); + com.sun.star.lang.XComponent xComponent = xComponentLoader.loadComponentFromURL(sURL, sFrame, 0, xValues); + + XServiceInfo xComponentService = UnoRuntime.queryInterface(XServiceInfo.class, xComponent); + if (xComponentService.supportsService("com.sun.star.text.TextDocument")) + { + oDocument = UnoRuntime.queryInterface(XTextDocument.class, xComponent); //TODO: write if clauses for Calc, Impress and Draw + } + } + catch (Exception exception) + { + exception.printStackTrace(System.err); + } + return oDocument; + } + + public static boolean close(XComponent xComponent) + { + boolean bState = false; + XModel xModel = UnoRuntime.queryInterface(XModel.class, xComponent); + + if (xModel != null) + { + 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 = 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 = UnoRuntime.queryInterface(XCellRange.class, oTable); + XCellRange xNewRange = xCellRange.getCellRangeByPosition(xpos, ypos, (colcount + xpos) - 1, (rowcount + ypos) - 1); + XCellRangeData xDataArray = UnoRuntime.queryInterface(XCellRangeData.class, xNewRange); + xDataArray.setDataArray(datalist); + } + } + } + catch (Exception e) + { + e.printStackTrace(); + } + } + +} diff --git a/wizards/com/sun/star/wizards/document/OfficeDocument.py b/wizards/com/sun/star/wizards/document/OfficeDocument.py new file mode 100644 index 000000000..1483f902d --- /dev/null +++ b/wizards/com/sun/star/wizards/document/OfficeDocument.py @@ -0,0 +1,208 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# +import uno +import traceback +from unohelper import systemPathToFileUrl, absolutize +from ..common.Desktop import Desktop +from ..common.SystemDialog import SystemDialog + +from com.sun.star.awt import WindowDescriptor +from com.sun.star.awt import Rectangle +from com.sun.star.awt.WindowClass import TOP +from com.sun.star.task import ErrorCodeIOException + +#Window Constants +com_sun_star_awt_WindowAttribute_BORDER \ + = uno.getConstantByName( "com.sun.star.awt.WindowAttribute.BORDER" ) +com_sun_star_awt_WindowAttribute_SIZEABLE \ + = uno.getConstantByName( "com.sun.star.awt.WindowAttribute.SIZEABLE" ) +com_sun_star_awt_WindowAttribute_MOVEABLE \ + = uno.getConstantByName( "com.sun.star.awt.WindowAttribute.MOVEABLE" ) +com_sun_star_awt_VclWindowPeerAttribute_CLIPCHILDREN \ + = uno.getConstantByName( + "com.sun.star.awt.VclWindowPeerAttribute.CLIPCHILDREN" ) + +class OfficeDocument(object): + '''Creates a new instance of OfficeDocument ''' + + def __init__(self, _xMSF): + self.xMSF = _xMSF + + @classmethod + def attachEventCall(self, xComponent, EventName, EventType, EventURL): + try: + oEventProperties = list(range(2)) + oEventProperties[0] = uno.createUnoStruct( + 'com.sun.star.beans.PropertyValue') + oEventProperties[0].Name = "EventType" + oEventProperties[0].Value = EventType + # "Service", "StarBasic" + oEventProperties[1] = uno.createUnoStruct( + 'com.sun.star.beans.PropertyValue') + oEventProperties[1].Name = "Script" #"URL"; + oEventProperties[1].Value = EventURL + uno.invoke(xComponent.Events, "replaceByName", + (EventName, uno.Any("[]com.sun.star.beans.PropertyValue", + tuple(oEventProperties)))) + except Exception: + traceback.print_exc() + + def dispose(self, xMSF, xComponent): + try: + if xComponent is not None: + xFrame = xComponent.CurrentController.Frame + if xComponent.isModified(): + xComponent.setModified(False) + + Desktop.dispatchURL(xMSF, ".uno:CloseDoc", xFrame) + + except Exception: + traceback.print_exc() + + @classmethod + def createNewFrame(self, xMSF, listener, FrameName="_blank"): + xFrame = None + if FrameName.lower() == "WIZARD_LIVE_PREVIEW".lower(): + xFrame = self.createNewPreviewFrame(xMSF, listener) + else: + xF = Desktop.getDesktop(xMSF) + xFrame = xF.findFrame(FrameName, 0) + if listener is not None: + xFF = xF.getFrames() + xFF.remove(xFrame) + xF.addTerminateListener(listener) + + return xFrame + + @classmethod + def createNewPreviewFrame(self, xMSF, listener): + xToolkit = None + try: + xToolkit = xMSF.createInstance("com.sun.star.awt.Toolkit") + except Exception: + # TODO Auto-generated catch block + traceback.print_exc() + + #describe the window and its properties + aDescriptor = WindowDescriptor() + aDescriptor.Type = TOP + aDescriptor.WindowServiceName = "window" + aDescriptor.ParentIndex = -1 + aDescriptor.Parent = None + aDescriptor.Bounds = Rectangle(10, 10, 640, 480) + + #Set Window Attributes + gnDefaultWindowAttributes = \ + com_sun_star_awt_WindowAttribute_BORDER + \ + com_sun_star_awt_WindowAttribute_MOVEABLE + \ + com_sun_star_awt_WindowAttribute_SIZEABLE + \ + com_sun_star_awt_VclWindowPeerAttribute_CLIPCHILDREN + + aDescriptor.WindowAttributes = gnDefaultWindowAttributes + #create a new blank container window + xPeer = None + try: + xPeer = xToolkit.createWindow(aDescriptor) + except Exception: + traceback.print_exc() + + #define some further properties of the frame window + #if it's needed .-) + #xPeer->setBackground(...); + #create new empty frame and set window on it + xFrame = None + try: + xFrame = xMSF.createInstance("com.sun.star.frame.Frame") + except Exception: + traceback.print_exc() + + xFrame.initialize(xPeer) + #from now this frame is usable ... + #and not part of the desktop tree. + #You are alone with him .-) + if listener is not None: + Desktop.getDesktop(xMSF).addTerminateListener(listener) + + return xFrame + + @classmethod + def load(self, xInterface, sURL, sFrame, xValues): + xComponent = None + try: + if not sURL.startswith("file://"): + sURL = systemPathToFileUrl(sURL) + xComponent = xInterface.loadComponentFromURL( + sURL, sFrame, 0, tuple(xValues)) + except Exception: + traceback.print_exc() + + return xComponent + + @classmethod + def store(self, xMSF, xComponent, StorePath, FilterName): + try: + if len(FilterName): + oStoreProperties = list(range(2)) + oStoreProperties[0] = uno.createUnoStruct( + 'com.sun.star.beans.PropertyValue') + oStoreProperties[0].Name = "FilterName" + oStoreProperties[0].Value = FilterName + oStoreProperties[1] = uno.createUnoStruct( + 'com.sun.star.beans.PropertyValue') + oStoreProperties[1].Name = "InteractionHandler" + oStoreProperties[1].Value = xMSF.createInstance( + "com.sun.star.comp.uui.UUIInteractionHandler") + else: + oStoreProperties = list(range(0)) + + StorePath = systemPathToFileUrl(StorePath) + sPath = StorePath[:(StorePath.rfind("/") + 1)] + sFile = StorePath[(StorePath.rfind("/") + 1):] + xComponent.storeToURL( + absolutize(sPath, sFile), tuple(oStoreProperties)) + return True + except ErrorCodeIOException: + #Throw this exception when trying to save a file + #which is already opened in Libreoffice + #TODO: handle it properly + return True + pass + except Exception: + traceback.print_exc() + return False + + def close(self, xComponent): + bState = False + if xComponent is not None: + try: + xComponent.close(True) + bState = True + except Exception: + print ("could not close doc") + bState = False + + else: + bState = True + + return bState + + def showMessageBox( + self, xMSF, windowServiceName, windowAttribute, MessageText): + + return SystemDialog.showMessageBox( + xMSF, windowServiceName, windowAttribute, MessageText) 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 000000000..72c17d7f8 --- /dev/null +++ b/wizards/com/sun/star/wizards/document/Shape.java @@ -0,0 +1,131 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +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; + +/** + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class Shape +{ + + public XShape xShape; + protected FormHandler oFormHandler; + public XServiceInfo xServiceInfo; + protected Point aPoint; + private Size aSize; + protected XControlShape xControlShape; + private XMultiServiceFactory xMSF; + 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 = UnoRuntime.queryInterface(XShapes.class, oShape); + 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 = 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 = UnoRuntime.queryInterface(XServiceInfo.class, xShape); + xControlShape = UnoRuntime.queryInterface(XControlShape.class, xShape); + + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + } + + public Size getSize() + { + return xShape.getSize(); + } + + public void setSize(Size _aSize) + { + try + { + xShape.setSize(_aSize); + } + catch (PropertyVetoException e) + { + e.printStackTrace(System.err); + } + } + + 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 000000000..0ce10a33c --- /dev/null +++ b/wizards/com/sun/star/wizards/document/TimeStampControl.java @@ -0,0 +1,111 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +package com.sun.star.wizards.document; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +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.XShapes; + +public class TimeStampControl extends DatabaseControl +{ + + private DatabaseControl oDateControl; + private DatabaseControl oTimeControl; + private Resource oResource; + private int nDBWidth; + + public TimeStampControl(Resource _oResource, FormHandler _oFormHandler, XNameContainer _xFormName, String _curFieldName, Point _aPoint) + { + super(_oFormHandler, "com.sun.star.drawing.ShapeCollection", _aPoint); + oResource = _oResource; + oDateControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.DATE, aPoint); + int nDBHeight = oDateControl.getControlHeight(); + int 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); + int nTimeWidth = oTimeControl.getPreferredWidth(); + oTimeControl.setSize(new Size(nTimeWidth, nDBHeight)); + nDBWidth = nDateWidth + nTimeWidth + 10; + xShapes.add(oDateControl.xShape); + xShapes.add(oTimeControl.xShape); + xShape = _oFormHandler.xShapeGrouper.group(xShapes); + xShapes = UnoRuntime.queryInterface(XShapes.class, xShape); + } + + public XPropertySet getControlofGroupShapeByIndex(int _i) + { + try + { + if (_i < xShapes.getCount()) + { + Object oControl = xShapes.getByIndex(_i); + XControlShape xControlShape = UnoRuntime.queryInterface(XControlShape.class, oControl); + return UnoRuntime.queryInterface(XPropertySet.class, xControlShape.getControl()); + } + } + catch (Exception e) + { + e.printStackTrace(System.err); + } + return null; + } + + public TimeStampControl(Resource _oResource, GridControl _oGridControl, FieldColumn _curfieldcolumn) + { + super(_oGridControl, _curfieldcolumn); + oResource = _oResource; + String sDateAppendix = oResource.getResText("RID_FORM_88"); + String sTimeAppendix = oResource.getResText("RID_FORM_89"); + oDateControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.DATE, _curfieldcolumn.getFieldTitle() + PropertyNames.SPACE + sDateAppendix); + oTimeControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.TIME, _curfieldcolumn.getFieldTitle() + PropertyNames.SPACE + sTimeAppendix); + } + + @Override + public void setPropertyValue(String _sPropertyName, Object _aPropertyValue) throws Exception + { + oDateControl.setPropertyValue(_sPropertyName, _aPropertyValue); + oTimeControl.setPropertyValue(_sPropertyName, _aPropertyValue); + } + + @Override + public int getPreferredWidth() + { + return nDBWidth; + } + + @Override + public int getControlType() + { + return FormHandler.SODATETIMECONTROL; + } +} + + + + + diff --git a/wizards/com/sun/star/wizards/document/__init__.py b/wizards/com/sun/star/wizards/document/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/wizards/com/sun/star/wizards/document/__init__.py |