summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/text
diff options
context:
space:
mode:
Diffstat (limited to 'wizards/com/sun/star/wizards/text')
-rw-r--r--wizards/com/sun/star/wizards/text/TextDocument.java483
-rw-r--r--wizards/com/sun/star/wizards/text/TextFieldHandler.java348
-rw-r--r--wizards/com/sun/star/wizards/text/TextFrameHandler.java51
-rw-r--r--wizards/com/sun/star/wizards/text/TextSectionHandler.java271
-rw-r--r--wizards/com/sun/star/wizards/text/TextStyleHandler.java114
-rw-r--r--wizards/com/sun/star/wizards/text/TextTableHandler.java253
-rw-r--r--wizards/com/sun/star/wizards/text/ViewHandler.java115
7 files changed, 1635 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/text/TextDocument.java b/wizards/com/sun/star/wizards/text/TextDocument.java
new file mode 100644
index 000000000000..4fe2e9f0d710
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextDocument.java
@@ -0,0 +1,483 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.document.XDocumentProperties;
+import com.sun.star.document.XDocumentPropertiesSupplier;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XFramesSupplier;
+import com.sun.star.frame.XLoadable;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XModule;
+import com.sun.star.frame.XTerminateListener;
+import com.sun.star.frame.XStorable;
+import com.sun.star.i18n.NumberFormatIndex;
+import com.sun.star.awt.Size;
+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.lang.Locale;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+
+import com.sun.star.style.XStyle;
+import com.sun.star.style.XStyleFamiliesSupplier;
+import com.sun.star.task.XStatusIndicatorFactory;
+import com.sun.star.text.XPageCursor;
+import com.sun.star.text.XSimpleText;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextViewCursor;
+import com.sun.star.text.XTextViewCursorSupplier;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.DateTime;
+import com.sun.star.util.XModifiable;
+import com.sun.star.util.XNumberFormatsSupplier;
+import com.sun.star.util.XRefreshable;
+import com.sun.star.wizards.common.Configuration;
+import com.sun.star.wizards.common.Desktop;
+import com.sun.star.wizards.common.Helper;
+import com.sun.star.wizards.common.JavaTools;
+import com.sun.star.wizards.common.Helper.DateUtils;
+import com.sun.star.wizards.document.OfficeDocument;
+
+public class TextDocument
+{
+
+ public XComponent xComponent;
+ public com.sun.star.text.XTextDocument xTextDocument;
+ public com.sun.star.util.XNumberFormats NumberFormats;
+ public com.sun.star.document.XDocumentProperties m_xDocProps;
+ public com.sun.star.task.XStatusIndicator xProgressBar;
+ public com.sun.star.frame.XFrame xFrame;
+ public XText xText;
+ public XMultiServiceFactory xMSFDoc;
+ public XMultiServiceFactory xMSF;
+ public com.sun.star.util.XNumberFormatsSupplier xNumberFormatsSupplier;
+ public com.sun.star.awt.XWindowPeer xWindowPeer;
+ public int PageWidth;
+ public int ScaleWidth;
+ public Size DocSize;
+ public com.sun.star.awt.Rectangle PosSize;
+ public com.sun.star.lang.Locale CharLocale;
+ public XStorable xStorable;
+
+ // creates an instance of TextDocument and creates a named frame. No document is actually loaded into this frame.
+ public TextDocument(XMultiServiceFactory xMSF, XTerminateListener listener, String FrameName)
+ {
+ this.xMSF = xMSF;
+ xFrame = OfficeDocument.createNewFrame(xMSF, listener, FrameName);
+ }
+
+ // creates an instance of TextDocument by loading a given URL as preview
+ public TextDocument(XMultiServiceFactory xMSF, String _sPreviewURL, boolean bShowStatusIndicator, XTerminateListener listener)
+ {
+ this.xMSF = xMSF;
+
+ xFrame = OfficeDocument.createNewFrame(xMSF, listener);
+ xTextDocument = loadAsPreview(_sPreviewURL, true);
+ xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xTextDocument);
+
+ if (bShowStatusIndicator)
+ {
+ showStatusIndicator();
+ }
+ init();
+ }
+
+ // creates an instance of TextDocument from the desktop's current frame
+ public TextDocument(XMultiServiceFactory xMSF, boolean bShowStatusIndicator, XTerminateListener listener)
+ {
+ this.xMSF = xMSF;
+
+ XDesktop xDesktop = Desktop.getDesktop(xMSF);
+ XFramesSupplier xFrameSupplier = (XFramesSupplier) UnoRuntime.queryInterface(XFramesSupplier.class, xDesktop);
+ xFrame = xFrameSupplier.getActiveFrame();
+ xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xFrame.getController().getModel());
+ xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent);
+
+ if (bShowStatusIndicator)
+ {
+ showStatusIndicator();
+ }
+ init();
+ }
+
+ public static class ModuleIdentifier
+ {
+
+ private String m_identifier;
+
+ protected final String getIdentifier()
+ {
+ return m_identifier;
+ }
+
+ public ModuleIdentifier(String _identifier)
+ {
+ m_identifier = _identifier;
+ }
+ };
+
+ // creates an instance of TextDocument containing a blank text document
+ public TextDocument(XMultiServiceFactory xMSF, ModuleIdentifier _moduleIdentifier, boolean bShowStatusIndicator)
+ {
+ this.xMSF = xMSF;
+
+ try
+ {
+ // create the empty document, and set its module identifier
+ xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,
+ xMSF.createInstance("com.sun.star.text.TextDocument"));
+
+ XLoadable xLoadable = (XLoadable) UnoRuntime.queryInterface(XLoadable.class, xTextDocument);
+ xLoadable.initNew();
+
+ XModule xModule = (XModule) UnoRuntime.queryInterface(XModule.class,
+ xTextDocument);
+ xModule.setIdentifier(_moduleIdentifier.getIdentifier());
+
+ // load the document into a blank frame
+ XDesktop xDesktop = Desktop.getDesktop(xMSF);
+ XComponentLoader xLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
+ PropertyValue[] loadArgs = new PropertyValue[]
+ {
+ new PropertyValue("Model", -1, xTextDocument, com.sun.star.beans.PropertyState.DIRECT_VALUE)
+ };
+ xLoader.loadComponentFromURL("private:object", "_blank", 0, loadArgs);
+
+ // remember some things for later usage
+ xFrame = xTextDocument.getCurrentController().getFrame();
+ xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xTextDocument);
+ }
+ catch (Exception e)
+ {
+ // TODO: it seems the whole project does not really have an error handling. Other menthods
+ // seem to generally silence errors, so we can't do anything else here ...
+ }
+
+ if (bShowStatusIndicator)
+ {
+ showStatusIndicator();
+ }
+ init();
+ }
+
+ //creates an instance of TextDocument from a given XTextDocument
+ public TextDocument(XMultiServiceFactory xMSF, XTextDocument _textDocument, boolean bshowStatusIndicator)
+ {
+ this.xMSF = xMSF;
+ xFrame = _textDocument.getCurrentController().getFrame();
+ xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, _textDocument);
+ xTextDocument = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xComponent);
+ //PosSize = xFrame.getComponentWindow().getPosSize();
+ if (bshowStatusIndicator)
+ {
+ XStatusIndicatorFactory xStatusIndicatorFactory = (XStatusIndicatorFactory) UnoRuntime.queryInterface(XStatusIndicatorFactory.class, xFrame);
+ xProgressBar = xStatusIndicatorFactory.createStatusIndicator();
+ xProgressBar.start("", 100);
+ xProgressBar.setValue(5);
+ }
+ xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xFrame.getComponentWindow());
+ xMSFDoc = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ xNumberFormatsSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+
+ XDocumentPropertiesSupplier xDocPropsSuppl = (XDocumentPropertiesSupplier) UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument);
+ m_xDocProps = xDocPropsSuppl.getDocumentProperties();
+ CharLocale = (Locale) Helper.getUnoStructValue((Object) xComponent, "CharLocale");
+ xText = xTextDocument.getText();
+ }
+
+ private void init()
+ {
+ xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xFrame.getComponentWindow());
+ xMSFDoc = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ xNumberFormatsSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+ XDocumentPropertiesSupplier xDocPropsSuppl = (XDocumentPropertiesSupplier) UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument);
+ m_xDocProps = xDocPropsSuppl.getDocumentProperties();
+ CharLocale = (Locale) Helper.getUnoStructValue((Object) xComponent, "CharLocale");
+ xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xTextDocument);
+ xText = xTextDocument.getText();
+ }
+
+ private void showStatusIndicator()
+ {
+ XStatusIndicatorFactory xStatusIndicatorFactory = (XStatusIndicatorFactory) UnoRuntime.queryInterface(XStatusIndicatorFactory.class, xFrame);
+ xProgressBar = xStatusIndicatorFactory.createStatusIndicator();
+ xProgressBar.start("", 100);
+ xProgressBar.setValue(5);
+ }
+
+ public XTextDocument loadAsPreview(String sDefaultTemplate, boolean asTemplate)
+ {
+ PropertyValue loadValues[] = new PropertyValue[3];
+ // open document in the Preview mode
+ loadValues[0] = new PropertyValue();
+ loadValues[0].Name = "ReadOnly";
+ loadValues[0].Value = Boolean.TRUE;
+ loadValues[1] = new PropertyValue();
+ loadValues[1].Name = "AsTemplate";
+ loadValues[1].Value = asTemplate ? Boolean.TRUE : Boolean.FALSE;
+ loadValues[2] = new PropertyValue();
+ loadValues[2].Name = "Preview";
+ loadValues[2].Value = Boolean.TRUE;
+
+ //set the preview document to non-modified mode in order to avoid the 'do u want to save' box
+ if (xTextDocument != null)
+ {
+ try
+ {
+ XModifiable xModi = (XModifiable) UnoRuntime.queryInterface(XModifiable.class, xTextDocument);
+ xModi.setModified(false);
+ }
+ catch (PropertyVetoException e1)
+ {
+ e1.printStackTrace(System.out);
+ }
+ }
+ Object oDoc = OfficeDocument.load(xFrame, sDefaultTemplate, "_self", loadValues);
+ xTextDocument = (com.sun.star.text.XTextDocument) oDoc;
+ DocSize = getPageSize();
+ xMSFDoc = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+
+ ViewHandler myViewHandler = new ViewHandler(xMSFDoc, xTextDocument);
+ try
+ {
+ myViewHandler.setViewSetting("ZoomType", new Short(com.sun.star.view.DocumentZoomType.ENTIRE_PAGE));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ TextFieldHandler myFieldHandler = new TextFieldHandler(xMSF, xTextDocument);
+ myFieldHandler.updateDocInfoFields();
+
+ return xTextDocument;
+
+ }
+
+ public Size getPageSize()
+ {
+ try
+ {
+ XStyleFamiliesSupplier xStyleFamiliesSupplier = (XStyleFamiliesSupplier) com.sun.star.uno.UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDocument);
+ com.sun.star.container.XNameAccess xNameAccess = null;
+ xNameAccess = xStyleFamiliesSupplier.getStyleFamilies();
+ com.sun.star.container.XNameContainer xPageStyleCollection = null;
+ xPageStyleCollection = (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(com.sun.star.container.XNameContainer.class, xNameAccess.getByName("PageStyles"));
+ XStyle xPageStyle = (XStyle) UnoRuntime.queryInterface(XStyle.class, xPageStyleCollection.getByName("First Page"));
+ return (Size) Helper.getUnoPropertyValue(xPageStyle, "Size");
+
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ return null;
+ }
+ }
+
+ //creates an instance of TextDocument and creates a frame and loads a document
+ public TextDocument(XMultiServiceFactory xMSF, String URL, PropertyValue[] xArgs, XTerminateListener listener)
+ {
+ this.xMSF = xMSF;
+ XDesktop xDesktop = Desktop.getDesktop(xMSF);
+
+ xFrame = OfficeDocument.createNewFrame(xMSF, listener);
+ Object oDoc = OfficeDocument.load(xFrame, URL, "_self", xArgs);
+ xTextDocument = (XTextDocument) oDoc;
+ xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xTextDocument);
+ XWindow xWindow = xFrame.getComponentWindow();
+
+ xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xFrame.getComponentWindow());
+ xMSFDoc = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ xNumberFormatsSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+
+ XDocumentPropertiesSupplier xDocPropsSuppl = (XDocumentPropertiesSupplier) UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument);
+ m_xDocProps = xDocPropsSuppl.getDocumentProperties();
+ CharLocale = (Locale) Helper.getUnoStructValue((Object) xComponent, "CharLocale");
+ }
+
+ public static XTextCursor createTextCursor(Object oCursorContainer)
+ {
+ XSimpleText xText = (XSimpleText) UnoRuntime.queryInterface(XSimpleText.class, oCursorContainer);
+ XTextCursor xTextCursor = xText.createTextCursor();
+ return xTextCursor;
+ }
+
+ // Todo: This method is unsecure because the last index is not necessarily the last section
+
+ // Todo: This Routine should be modified, because I cannot rely on the last Table in the document to be the last in the TextTables sequence
+ // to make it really safe you must acquire the Tablenames before the insertion and after the insertion of the new Table. By comparing the
+ // two sequences of tablenames you can find out the tablename of the last inserted Table
+
+ // Todo: This method is unsecure because the last index is not necessarily the last section
+ public int getCharWidth(String ScaleString)
+ {
+ int iScale = 200;
+ xTextDocument.lockControllers();
+ int iScaleLen = ScaleString.length();
+ com.sun.star.text.XTextCursor xTextCursor = createTextCursor(xTextDocument.getText());
+ xTextCursor.gotoStart(false);
+ com.sun.star.wizards.common.Helper.setUnoPropertyValue(xTextCursor, "PageDescName", "First Page");
+ xTextCursor.setString(ScaleString);
+ XTextViewCursorSupplier xViewCursor = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xTextDocument.getCurrentController());
+ XTextViewCursor xTextViewCursor = xViewCursor.getViewCursor();
+ xTextViewCursor.gotoStart(false);
+ int iFirstPos = xTextViewCursor.getPosition().X;
+ xTextViewCursor.gotoEnd(false);
+ int iLastPos = xTextViewCursor.getPosition().X;
+ iScale = (iLastPos - iFirstPos) / iScaleLen;
+ xTextCursor.gotoStart(false);
+ xTextCursor.gotoEnd(true);
+ xTextCursor.setString("");
+ unlockallControllers();
+ return iScale;
+ }
+
+ public void unlockallControllers()
+ {
+ while (xTextDocument.hasControllersLocked() == true)
+ {
+ xTextDocument.unlockControllers();
+ }
+ }
+
+ public void refresh()
+ {
+ XRefreshable xRefreshable = (XRefreshable) UnoRuntime.queryInterface(XRefreshable.class, xTextDocument);
+ xRefreshable.refresh();
+ }
+
+ /**
+ * This method sets the Author of a Wizard-generated template correctly
+ * and adds a explanatory sentence to the template description.
+ * @param WizardName The name of the Wizard.
+ * @param TemplateDescription The old Description which is being appended with another sentence.
+ * @return void.
+ */
+ public void setWizardTemplateDocInfo(String WizardName, String TemplateDescription)
+ {
+ try
+ {
+ Object uD = Configuration.getConfigurationRoot(xMSF, "/org.openoffice.UserProfile/Data", false);
+ XNameAccess xNA = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, uD);
+ Object gn = xNA.getByName("givenname");
+ Object sn = xNA.getByName("sn");
+ String fullname = (String) gn + " " + (String) sn;
+
+ Calendar cal = new GregorianCalendar();
+ int year = cal.get(Calendar.YEAR);
+ int month = cal.get(Calendar.MONTH);
+ int day = cal.get(Calendar.DAY_OF_MONTH);
+ DateTime currentDate = new DateTime();
+ currentDate.Day = (short) day;
+ currentDate.Month = (short) month;
+ currentDate.Year = (short) year;
+ DateUtils du = new DateUtils(xMSF, this.xTextDocument);
+ int ff = du.getFormat(NumberFormatIndex.DATE_SYS_DDMMYY);
+ String myDate = du.format(ff, currentDate);
+
+ XDocumentPropertiesSupplier xDocPropsSuppl = (XDocumentPropertiesSupplier) UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument);
+ XDocumentProperties xDocProps2 = xDocPropsSuppl.getDocumentProperties();
+ xDocProps2.setAuthor(fullname);
+ xDocProps2.setModifiedBy(fullname);
+ String description = xDocProps2.getDescription();
+ description = description + " " + TemplateDescription;
+ description = JavaTools.replaceSubString(description, WizardName, "<wizard_name>");
+ description = JavaTools.replaceSubString(description, myDate, "<current_date>");
+ xDocProps2.setDescription(description);
+ }
+ catch (NoSuchElementException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (WrappedTargetException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * removes an arbitrary Object which supports the 'XTextContent' interface
+ * @param oTextContent
+ * @return
+ */
+ public boolean removeTextContent(Object oTextContent)
+ {
+ try
+ {
+ XTextContent xTextContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, oTextContent);
+ xText.removeTextContent(xTextContent);
+ return true;
+ }
+ catch (NoSuchElementException e)
+ {
+ e.printStackTrace(System.out);
+ return false;
+ }
+ }
+
+ /**
+ * Apparently there is no other way to get the
+ * page count of a text document other than using a cursor and
+ * making it jump to the last page...
+ * @param model the document model.
+ * @return the page count of the document.
+ */
+ public static int getPageCount(Object model)
+ {
+ XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, model);
+ XController xController = xModel.getCurrentController();
+ XTextViewCursorSupplier xTextVCS = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xController);
+ XTextViewCursor xTextVC = xTextVCS.getViewCursor();
+ XPageCursor xPC = (XPageCursor) UnoRuntime.queryInterface(XPageCursor.class, xTextVC);
+ xPC.jumpToLastPage();
+ return xPC.getPage();
+ }
+
+ /* Possible Values for "OptionString" are: "LoadCellStyles", "LoadTextStyles", "LoadFrameStyles",
+ "LoadPageStyles", "LoadNumberingStyles", "OverwriteStyles" */
+}
diff --git a/wizards/com/sun/star/wizards/text/TextFieldHandler.java b/wizards/com/sun/star/wizards/text/TextFieldHandler.java
new file mode 100644
index 000000000000..5d8c677c621e
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextFieldHandler.java
@@ -0,0 +1,348 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+import java.util.Vector;
+
+import com.sun.star.text.XDependentTextField;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextFieldsSupplier;
+import com.sun.star.text.XTextRange;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.util.DateTime;
+import com.sun.star.util.XRefreshable;
+import com.sun.star.util.XUpdatable;
+import com.sun.star.wizards.common.Helper;
+
+public class TextFieldHandler
+{
+
+ public XTextFieldsSupplier xTextFieldsSupplier;
+ private XMultiServiceFactory xMSFDoc;
+
+ /**
+ * Creates a new instance of TextFieldHandler
+ * @param xMSF
+ * @param xTextDocument
+ */
+ public TextFieldHandler(XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSFDoc = xMSF;
+ xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime.queryInterface(XTextFieldsSupplier.class, xTextDocument);
+ }
+
+ public void refreshTextFields()
+ {
+ XRefreshable xUp = (XRefreshable) UnoRuntime.queryInterface(XRefreshable.class, xTextFieldsSupplier.getTextFields());
+ xUp.refresh();
+ }
+
+ public String getUserFieldContent(XTextCursor xTextCursor)
+ {
+ try
+ {
+ XTextRange xTextRange = xTextCursor.getEnd();
+ Object oTextField = Helper.getUnoPropertyValue(xTextRange, "TextField");
+ if (com.sun.star.uno.AnyConverter.isVoid(oTextField))
+ {
+ return "";
+ }
+ else
+ {
+ XDependentTextField xDependent = (XDependentTextField) UnoRuntime.queryInterface(XDependentTextField.class, oTextField);
+ XPropertySet xMaster = xDependent.getTextFieldMaster();
+ String UserFieldContent = (String) xMaster.getPropertyValue("Content");
+ return UserFieldContent;
+ }
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ return "";
+ }
+
+ public void insertUserField(XTextCursor xTextCursor, String FieldName, String FieldTitle)
+ {
+ try
+ {
+ XInterface xField = (XInterface) xMSFDoc.createInstance("com.sun.star.text.TextField.User");
+ XDependentTextField xDepField = (XDependentTextField) UnoRuntime.queryInterface(XDependentTextField.class, xField);
+ XTextContent xFieldContent = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xField);
+ if (xTextFieldsSupplier.getTextFieldMasters().hasByName("com.sun.star.text.FieldMaster.User." + FieldName))
+ {
+ Object oMaster = xTextFieldsSupplier.getTextFieldMasters().getByName("com.sun.star.text.FieldMaster.User." + FieldName);
+ XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, oMaster);
+ xComponent.dispose();
+ }
+ XPropertySet xPSet = createUserField(FieldName, FieldTitle);
+ xDepField.attachTextFieldMaster(xPSet);
+ xTextCursor.getText().insertTextContent(xTextCursor, xFieldContent, false);
+
+// try
+// {
+// XPropertySet xTestProp = xDepField.getTextFieldMaster();
+// String UserFieldName = (String) xTestProp.getPropertyValue("Name");
+// // UserFieldName == FieldName?
+// int dummy = 0;
+// }
+// catch (com.sun.star.uno.Exception e)
+// {
+// int dummy2 = 0;
+// }
+
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public XPropertySet createUserField(String FieldName, String FieldTitle) throws com.sun.star.uno.Exception
+ {
+ Object oMaster = xMSFDoc.createInstance("com.sun.star.text.FieldMaster.User");
+ XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oMaster);
+ xPSet.setPropertyValue("Name", FieldName);
+ xPSet.setPropertyValue("Content", FieldTitle);
+
+ // DEBUG
+ // String sFieldName = (String)xPSet.getPropertyValue("Name");
+
+ return xPSet;
+ }
+
+ private XDependentTextField[] getTextFieldsByProperty(String _PropertyName, Object _aPropertyValue, String _TypeName) throws Exception
+ {
+ try
+ {
+ XDependentTextField[] xDependentFields;
+ Vector xDependentVector = new Vector();
+ if (xTextFieldsSupplier.getTextFields().hasElements())
+ {
+ XEnumeration xEnum = xTextFieldsSupplier.getTextFields().createEnumeration();
+ while (xEnum.hasMoreElements())
+ {
+ Object oTextField = xEnum.nextElement();
+ XDependentTextField xDependent = (XDependentTextField) UnoRuntime.queryInterface(XDependentTextField.class, oTextField);
+ XPropertySet xPropertySet = xDependent.getTextFieldMaster();
+ if (xPropertySet.getPropertySetInfo().hasPropertyByName(_PropertyName))
+ {
+ Object oValue = xPropertySet.getPropertyValue(_PropertyName);
+ // TODO replace the following comparison via com.sun.star.uno.Any.Type
+ if (AnyConverter.isString(oValue))
+ {
+ if (_TypeName.equals("String"))
+ {
+ String sValue = AnyConverter.toString(oValue);
+ if (sValue.equals(_aPropertyValue))
+ {
+ xDependentVector.addElement(xDependent);
+ }
+ }
+ }
+ else if (AnyConverter.isShort(oValue))
+ {
+ if (_TypeName.equals("Short"))
+ {
+ short iShortParam = ((Short) _aPropertyValue).shortValue();
+ short ishortValue = AnyConverter.toShort(oValue);
+ if (ishortValue == iShortParam)
+ {
+ xDependentVector.addElement(xDependent);
+ }
+ }
+ }
+ }
+ }
+ }
+ if (xDependentVector.size() > 0)
+ {
+ xDependentFields = new XDependentTextField[xDependentVector.size()];
+ xDependentVector.toArray(xDependentFields);
+ return xDependentFields;
+ }
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace(System.out);
+ }
+ return null;
+ }
+
+ public void changeUserFieldContent(String _FieldName, String _FieldContent)
+ {
+ try
+ {
+ XDependentTextField[] xDependentTextFields = getTextFieldsByProperty("Name", _FieldName, "String");
+ if (xDependentTextFields != null)
+ {
+ for (int i = 0; i < xDependentTextFields.length; i++)
+ {
+ xDependentTextFields[i].getTextFieldMaster().setPropertyValue("Content", _FieldContent);
+ }
+ refreshTextFields();
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void updateDocInfoFields()
+ {
+ try
+ {
+ XEnumeration xEnum = xTextFieldsSupplier.getTextFields().createEnumeration();
+ while (xEnum.hasMoreElements())
+ {
+ Object oTextField = xEnum.nextElement();
+ XServiceInfo xSI = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, oTextField);
+
+ if (xSI.supportsService("com.sun.star.text.TextField.ExtendedUser"))
+ {
+ XUpdatable xUp = (XUpdatable) UnoRuntime.queryInterface(XUpdatable.class, oTextField);
+ xUp.update();
+ }
+ if (xSI.supportsService("com.sun.star.text.TextField.User"))
+ {
+ XUpdatable xUp = (XUpdatable) UnoRuntime.queryInterface(XUpdatable.class, oTextField);
+ xUp.update();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void updateDateFields()
+ {
+ try
+ {
+ XEnumeration xEnum = xTextFieldsSupplier.getTextFields().createEnumeration();
+ Calendar cal = new GregorianCalendar();
+ DateTime dt = new DateTime();
+ dt.Day = (short) cal.get(Calendar.DAY_OF_MONTH);
+ dt.Year = (short) cal.get(Calendar.YEAR);
+ dt.Month = (short) cal.get(Calendar.MONTH);
+ dt.Month++;
+
+ while (xEnum.hasMoreElements())
+ {
+ Object oTextField = xEnum.nextElement();
+ XServiceInfo xSI = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, oTextField);
+
+ if (xSI.supportsService("com.sun.star.text.TextField.DateTime"))
+ {
+ XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTextField);
+ xPSet.setPropertyValue("IsFixed", Boolean.FALSE);
+ xPSet.setPropertyValue("DateTimeValue", dt);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void fixDateFields(boolean _bSetFixed)
+ {
+ try
+ {
+ XEnumeration xEnum = xTextFieldsSupplier.getTextFields().createEnumeration();
+ while (xEnum.hasMoreElements())
+ {
+ Object oTextField = xEnum.nextElement();
+ XServiceInfo xSI = (XServiceInfo) UnoRuntime.queryInterface(XServiceInfo.class, oTextField);
+ if (xSI.supportsService("com.sun.star.text.TextField.DateTime"))
+ {
+ XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTextField);
+ xPSet.setPropertyValue("IsFixed", new Boolean(_bSetFixed));
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void removeUserFieldByContent(String _FieldContent)
+ {
+ try
+ {
+ XDependentTextField[] xDependentTextFields = getTextFieldsByProperty("Content", _FieldContent, "String");
+ if (xDependentTextFields != null)
+ {
+ for (int i = 0; i < xDependentTextFields.length; i++)
+ {
+ xDependentTextFields[i].dispose();
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void changeExtendedUserFieldContent(short UserDataPart, String _FieldContent)
+ {
+ try
+ {
+ XDependentTextField[] xDependentTextFields = getTextFieldsByProperty("UserDataType", new Short(UserDataPart), "Short");
+ if (xDependentTextFields != null)
+ {
+ for (int i = 0; i < xDependentTextFields.length; i++)
+ {
+ xDependentTextFields[i].getTextFieldMaster().setPropertyValue("Content", _FieldContent);
+ }
+ }
+ refreshTextFields();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/TextFrameHandler.java b/wizards/com/sun/star/wizards/text/TextFrameHandler.java
new file mode 100644
index 000000000000..562444a1ad84
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextFrameHandler.java
@@ -0,0 +1,51 @@
+/*
+ ************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import com.sun.star.container.NoSuchElementException;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextFrame;
+import com.sun.star.text.XTextFramesSupplier;
+import com.sun.star.uno.UnoRuntime;
+
+public class TextFrameHandler
+{
+
+ public static XTextFrame getFrameByName(String sFrameName, XTextDocument xTD) throws NoSuchElementException, WrappedTargetException
+ {
+ XTextFramesSupplier xFrameSupplier = (XTextFramesSupplier) UnoRuntime.queryInterface(XTextFramesSupplier.class, xTD);
+ if (xFrameSupplier.getTextFrames().hasByName(sFrameName))
+ {
+ Object oTextFrame = xFrameSupplier.getTextFrames().getByName(sFrameName);
+ XTextFrame xTextFrame = (XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, oTextFrame);
+ return xTextFrame;
+ }
+ return null;
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/TextSectionHandler.java b/wizards/com/sun/star/wizards/text/TextSectionHandler.java
new file mode 100644
index 000000000000..42fd75879c3c
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextSectionHandler.java
@@ -0,0 +1,271 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNamed;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.text.ControlCharacter;
+import com.sun.star.text.SectionFileLink;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextSectionsSupplier;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.wizards.common.Helper;
+
+public class TextSectionHandler
+{
+
+ public XTextSectionsSupplier xTextSectionsSupplier;
+ private XMultiServiceFactory xMSFDoc;
+ private XTextDocument xTextDocument;
+ private XText xText;
+
+ /** Creates a new instance of TextSectionHandler */
+ public TextSectionHandler(XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSFDoc = xMSF;
+ this.xTextDocument = xTextDocument;
+ xText = xTextDocument.getText();
+ xTextSectionsSupplier = (XTextSectionsSupplier) UnoRuntime.queryInterface(XTextSectionsSupplier.class, xTextDocument);
+ }
+
+ public void removeTextSectionbyName(String SectionName)
+ {
+ try
+ {
+ XNameAccess xAllTextSections = xTextSectionsSupplier.getTextSections();
+ if (xAllTextSections.hasByName(SectionName) == true)
+ {
+ Object oTextSection = xTextSectionsSupplier.getTextSections().getByName(SectionName);
+ removeTextSection(oTextSection);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public boolean hasTextSectionByName(String SectionName)
+ {
+ com.sun.star.container.XNameAccess xAllTextSections = xTextSectionsSupplier.getTextSections();
+ return xAllTextSections.hasByName(SectionName);
+ }
+
+ public void removeLastTextSection()
+ {
+ try
+ {
+ XIndexAccess xAllTextSections = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ Object oTextSection = xAllTextSections.getByIndex(xAllTextSections.getCount() - 1);
+ removeTextSection(oTextSection);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeTextSection(Object _oTextSection)
+ {
+ try
+ {
+ XTextContent xTextContentTextSection = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, _oTextSection);
+ xText.removeTextContent(xTextContentTextSection);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeInvisibleTextSections()
+ {
+ try
+ {
+ XIndexAccess xAllTextSections = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ int TextSectionCount = xAllTextSections.getCount();
+ for (int i = TextSectionCount - 1; i >= 0; i--)
+ {
+ XTextContent xTextContentTextSection = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xAllTextSections.getByIndex(i));
+ XPropertySet xTextSectionPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextContentTextSection);
+ boolean bRemoveTextSection = (!AnyConverter.toBoolean(xTextSectionPropertySet.getPropertyValue("IsVisible")));
+ if (bRemoveTextSection)
+ {
+ xText.removeTextContent(xTextContentTextSection);
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeAllTextSections()
+ {
+ try
+ {
+ XIndexAccess xAllTextSections = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ int TextSectionCount = xAllTextSections.getCount();
+ for (int i = TextSectionCount - 1; i >= 0; i--)
+ {
+ XTextContent xTextContentTextSection = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xAllTextSections.getByIndex(i));
+ XPropertySet xTextSectionPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xTextContentTextSection);
+ xText.removeTextContent(xTextContentTextSection);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void breakLinkofTextSections()
+ {
+ try
+ {
+ Object oTextSection;
+ XIndexAccess xAllTextSections = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ int iSectionCount = xAllTextSections.getCount();
+ SectionFileLink oSectionLink = new SectionFileLink();
+ oSectionLink.FileURL = "";
+ for (int i = 0; i < iSectionCount; i++)
+ {
+ oTextSection = xAllTextSections.getByIndex(i);
+ Helper.setUnoPropertyValues(oTextSection, new String[]
+ {
+ "FileLink", "LinkRegion"
+ }, new Object[]
+ {
+ oSectionLink, ""
+ });
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void breakLinkOfTextSection(Object oTextSection)
+ {
+ SectionFileLink oSectionLink = new SectionFileLink();
+ oSectionLink.FileURL = "";
+ Helper.setUnoPropertyValues(oTextSection, new String[]
+ {
+ "FileLink", "LinkRegion"
+ }, new Object[]
+ {
+ oSectionLink, ""
+ });
+ }
+
+ public void linkSectiontoTemplate(String TemplateName, String SectionName)
+ {
+ try
+ {
+ Object oTextSection = xTextSectionsSupplier.getTextSections().getByName(SectionName);
+ linkSectiontoTemplate(oTextSection, TemplateName, SectionName);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void linkSectiontoTemplate(Object oTextSection, String TemplateName, String SectionName)
+ {
+ SectionFileLink oSectionLink = new SectionFileLink();
+ oSectionLink.FileURL = TemplateName;
+ Helper.setUnoPropertyValues(oTextSection, new String[]
+ {
+ "FileLink", "LinkRegion"
+ }, new Object[]
+ {
+ oSectionLink, SectionName
+ });
+ XNamed xSectionName = (XNamed) UnoRuntime.queryInterface(XNamed.class, oTextSection);
+ String NewSectionName = xSectionName.getName();
+ if (NewSectionName.compareTo(SectionName) != 0)
+ {
+ xSectionName.setName(SectionName);
+ }
+ }
+
+ public void insertTextSection(String GroupName, String TemplateName, boolean _bAddParagraph)
+ {
+ try
+ {
+ if (_bAddParagraph)
+ {
+ XTextCursor xTextCursor = xText.createTextCursor();
+ xText.insertControlCharacter(xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false);
+ // Helper.setUnoPropertyValue(xTextCursor, "PageDescName", "First Page");
+ xTextCursor.collapseToEnd();
+ }
+ XTextCursor xSecondTextCursor = xText.createTextCursor();
+ xSecondTextCursor.gotoEnd(false);
+ insertTextSection(GroupName, TemplateName, xSecondTextCursor);
+ }
+ catch (IllegalArgumentException e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void insertTextSection(String sectionName, String templateName, XTextCursor position)
+ {
+ try
+ {
+ Object xTextSection;
+ if (xTextSectionsSupplier.getTextSections().hasByName(sectionName) == true)
+ {
+ xTextSection = xTextSectionsSupplier.getTextSections().getByName(sectionName);
+ }
+ else
+ {
+ xTextSection = xMSFDoc.createInstance("com.sun.star.text.TextSection");
+ XTextContent xTextContentSection = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xTextSection);
+ position.getText().insertTextContent(position, xTextContentSection, false);
+ }
+ linkSectiontoTemplate(xTextSection, templateName, sectionName);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/TextStyleHandler.java b/wizards/com/sun/star/wizards/text/TextStyleHandler.java
new file mode 100644
index 000000000000..e6c952e65785
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextStyleHandler.java
@@ -0,0 +1,114 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import com.sun.star.awt.Size;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.style.XStyleFamiliesSupplier;
+import com.sun.star.style.XStyleLoader;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+
+public class TextStyleHandler
+{
+
+ public XStyleFamiliesSupplier xStyleFamiliesSupplier;
+ private XMultiServiceFactory xMSFDoc;
+ private XTextDocument xTextDocument;
+
+ /** Creates a new instance of TextStyleHandler */
+ public TextStyleHandler(com.sun.star.lang.XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSFDoc = xMSF;
+ this.xTextDocument = xTextDocument;
+ xStyleFamiliesSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDocument);
+ }
+
+ public void loadStyleTemplates(String sTemplateUrl, String OptionString)
+ {
+ try
+ {
+ XStyleLoader xStyleLoader = (XStyleLoader) UnoRuntime.queryInterface(XStyleLoader.class, xStyleFamiliesSupplier.getStyleFamilies());
+ com.sun.star.beans.PropertyValue[] StyleOptions = xStyleLoader.getStyleLoaderOptions();
+ String CurOptionName = "";
+ int PropCount = StyleOptions.length;
+ for (int i = 0; i < PropCount; i++)
+ {
+ CurOptionName = StyleOptions[i].Name;
+ StyleOptions[i].Value = new Boolean((CurOptionName.compareTo(OptionString) == 0) || (CurOptionName.compareTo("OverwriteStyles") == 0));
+ }
+ xStyleLoader.loadStylesFromURL(sTemplateUrl, StyleOptions);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public XPropertySet getStyleByName(String sStyleFamily, String sStyleName)
+ {
+ try
+ {
+ XPropertySet xPropertySet = null;
+ Object oStyleFamily = xStyleFamiliesSupplier.getStyleFamilies().getByName(sStyleFamily);
+ XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oStyleFamily);
+ if (xNameAccess.hasByName(sStyleName))
+ {
+ xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xNameAccess.getByName(sStyleName));
+ }
+ return xPropertySet;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ return null;
+ }
+
+ public Size changePageAlignment(XPropertySet _xPropPageStyle, boolean _bIsLandscape)
+ {
+ try
+ {
+ _xPropPageStyle.setPropertyValue("IsLandscape", new Boolean(_bIsLandscape));
+ Size aPageSize = (Size) AnyConverter.toObject(Size.class, _xPropPageStyle.getPropertyValue("Size"));
+ int nPageWidth = aPageSize.Width;
+ int nPageHeight = aPageSize.Height;
+ Size aSize = new Size(nPageHeight, nPageWidth);
+ _xPropPageStyle.setPropertyValue("Size", aSize);
+ return (Size) AnyConverter.toObject(Size.class, _xPropPageStyle.getPropertyValue("Size"));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.out);
+ return null;
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/TextTableHandler.java b/wizards/com/sun/star/wizards/text/TextTableHandler.java
new file mode 100644
index 000000000000..d3646a7cfa37
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextTableHandler.java
@@ -0,0 +1,253 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.container.XNamed;
+import com.sun.star.frame.XFrame;
+import com.sun.star.lang.Locale;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.style.BreakType;
+import com.sun.star.table.XCellRange;
+import com.sun.star.text.XSimpleText;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextTable;
+import com.sun.star.text.XTextTablesSupplier;
+import com.sun.star.uno.AnyConverter;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.uno.XInterface;
+import com.sun.star.util.XNumberFormatsSupplier;
+import com.sun.star.view.XSelectionSupplier;
+import com.sun.star.wizards.common.Desktop;
+import com.sun.star.wizards.common.Helper;
+import com.sun.star.wizards.common.NumberFormatter;
+
+public class TextTableHandler
+{
+
+ public XTextTablesSupplier xTextTablesSupplier;
+ public XMultiServiceFactory xMSFDoc;
+ public XTextDocument xTextDocument;
+ public XSimpleText xSimpleText;
+ private XText xText;
+ private NumberFormatter oNumberFormatter;
+ private Locale aCharLocale;
+
+ /** Creates a new instance of TextTableHandler */
+ public TextTableHandler(XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ try
+ {
+ this.xMSFDoc = xMSF;
+ this.xTextDocument = xTextDocument;
+ xText = xTextDocument.getText();
+ xTextTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(XTextTablesSupplier.class, xTextDocument);
+ xSimpleText = (XSimpleText) UnoRuntime.queryInterface(XSimpleText.class, xTextDocument.getText());
+ XNumberFormatsSupplier xNumberFormatsSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+ aCharLocale = (Locale) Helper.getUnoStructValue((Object) xTextDocument, "CharLocale");
+ oNumberFormatter = new NumberFormatter(xNumberFormatsSupplier, aCharLocale);
+ }
+ catch (java.lang.Exception e)
+ {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public NumberFormatter getNumberFormatter()
+ {
+ return oNumberFormatter;
+ }
+
+ public XTextTable getByName(String _sTableName)
+ {
+ XTextTable xTextTable = null;
+ try
+ {
+ XNameAccess xAllTextTables = xTextTablesSupplier.getTextTables();
+ if (xAllTextTables.hasByName(_sTableName))
+ {
+ Object oTable = xAllTextTables.getByName(_sTableName);
+ xTextTable = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, oTable);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ return xTextTable;
+ }
+
+ public com.sun.star.text.XTextTable getlastTextTable()
+ {
+ try
+ {
+ XIndexAccess xAllTextTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextTablesSupplier.getTextTables());
+ int MaxIndex = xAllTextTables.getCount() - 1;
+ Object oTable = xAllTextTables.getByIndex(MaxIndex);
+ XTextTable xTextTable = (XTextTable) UnoRuntime.queryInterface(XTextTable.class, oTable);
+ return xTextTable;
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ return null;
+ }
+ }
+
+ public void insertTextTable(com.sun.star.text.XTextCursor xTextCursor)
+ {
+ try
+ {
+ com.sun.star.uno.XInterface xTextTable = (XInterface) xMSFDoc.createInstance("com.sun.star.text.TextTable");
+ XTextContent xTextContentTable = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xTextTable);
+ if (xTextCursor == null)
+ {
+ xTextCursor = xTextDocument.getText().createTextCursor();
+ xTextCursor.gotoEnd(false);
+ }
+ xTextCursor.getText().insertTextContent(xTextCursor, xTextContentTable, false);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeAllTextTables()
+ {
+ try
+ {
+ XIndexAccess xAllTextTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextTablesSupplier.getTextTables());
+ int TextTableCount = xAllTextTables.getCount();
+ for (int i = TextTableCount - 1; i >= 0; i--)
+ {
+ removeTextTable(xAllTextTables.getByIndex(i));
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeLastTextTable()
+ {
+ try
+ {
+ XIndexAccess xAllTextTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xTextTablesSupplier.getTextTables());
+ Object oTextTable = xAllTextTables.getByIndex(xAllTextTables.getCount() - 1);
+ removeTextTable(oTextTable);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeTextTable(Object oTextTable)
+ {
+ try
+ {
+ XTextContent xTextContentTable = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, oTextTable);
+ xTextDocument.getText().removeTextContent(xTextContentTable);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void removeTextTablebyName(String TableName)
+ {
+ try
+ {
+ XNameAccess xAllTextTables = xTextTablesSupplier.getTextTables();
+ if (xAllTextTables.hasByName(TableName) == true)
+ {
+ removeTextTable(xAllTextTables.getByName(TableName));
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void renameTextTable(String OldTableName, String NewTableName)
+ {
+ try
+ {
+ XNameAccess xTextTableNames = xTextTablesSupplier.getTextTables();
+ if (xTextTableNames.hasByName(OldTableName))
+ {
+ Object oTextTable = xTextTableNames.getByName(OldTableName);
+ XNamed xTextTableName = (XNamed) UnoRuntime.queryInterface(XNamed.class, oTextTable);
+ xTextTableName.setName(NewTableName);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public static BreakType resetBreakTypeofTextTable(Object oTextTable)
+ {
+ BreakType CorrBreakValue = null;
+ BreakType BreakValue = (BreakType) com.sun.star.wizards.common.Helper.getUnoStructValue(oTextTable, "BreakType");
+ // if (BreakValue.equals(BreakType.NONE) == false){
+ // CorrBreakValue = BreakValue;
+ Helper.setUnoPropertyValue(oTextTable, "BreakType", BreakType.NONE);
+ // }
+ return BreakType.NONE;
+ }
+
+ public void adjustOptimalTableWidths(XMultiServiceFactory _xMSF, XTextTable xTextTable)
+ { // setTableColumnSeparators(){
+ try
+ {
+ XFrame xFrame = this.xTextDocument.getCurrentController().getFrame();
+ int ColCount = xTextTable.getColumns().getCount();
+ XCellRange xCellRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, xTextTable);
+ XCellRange xLocCellRange = xCellRange.getCellRangeByPosition(0, 0, ColCount - 1, 1);
+ short iHoriOrient = AnyConverter.toShort(Helper.getUnoPropertyValue(xTextTable, "HoriOrient"));
+ XSelectionSupplier xSelection = (XSelectionSupplier) UnoRuntime.queryInterface(XSelectionSupplier.class, xTextDocument.getCurrentController());
+ xSelection.select(xLocCellRange);
+ Desktop.dispatchURL(_xMSF, ".Uno:DistributeColumns", xFrame);
+ Desktop.dispatchURL(_xMSF, ".Uno:SetOptimalColumnWidth", xFrame);
+ Helper.setUnoPropertyValue(xTextTable, "HoriOrient", new Short(iHoriOrient));
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/ViewHandler.java b/wizards/com/sun/star/wizards/text/ViewHandler.java
new file mode 100644
index 000000000000..e29ad10cfbb1
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/ViewHandler.java
@@ -0,0 +1,115 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * 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.text;
+
+import com.sun.star.beans.PropertyVetoException;
+import com.sun.star.beans.UnknownPropertyException;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.container.XNameAccess;
+import com.sun.star.lang.IllegalArgumentException;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.style.XStyleFamiliesSupplier;
+import com.sun.star.text.XPageCursor;
+import com.sun.star.text.XTextContent;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XTextRange;
+import com.sun.star.text.XTextViewCursor;
+import com.sun.star.text.XTextViewCursorSupplier;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.view.XViewSettingsSupplier;
+import com.sun.star.wizards.common.Helper;
+
+public class ViewHandler
+{
+
+ private XTextViewCursorSupplier xTextViewCursorSupplier;
+ private XMultiServiceFactory xMSFDoc;
+ private XTextDocument xTextDocument;
+ private XStyleFamiliesSupplier xStyleFamiliesSupplier;
+ private XViewSettingsSupplier xViewSettingsSupplier;
+
+ /** Creates a new instance of View */
+ public ViewHandler(XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSFDoc = xMSF;
+ this.xTextDocument = xTextDocument;
+ xTextViewCursorSupplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xTextDocument.getCurrentController());
+ xViewSettingsSupplier = (XViewSettingsSupplier) UnoRuntime.queryInterface(XViewSettingsSupplier.class, xTextDocument.getCurrentController());
+ xStyleFamiliesSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDocument);
+ }
+
+ public void selectFirstPage(TextTableHandler oTextTableHandler)
+ {
+ try
+ {
+ XPageCursor xPageCursor = (XPageCursor) UnoRuntime.queryInterface(XPageCursor.class, xTextViewCursorSupplier.getViewCursor());
+ XTextCursor xViewTextCursor = (XTextCursor) UnoRuntime.queryInterface(XTextCursor.class, xPageCursor);
+ xPageCursor.jumpToFirstPage();
+ xPageCursor.jumpToStartOfPage();
+ Helper.setUnoPropertyValue(xPageCursor, "PageDescName", "First Page");
+ Object oPageStyles = xStyleFamiliesSupplier.getStyleFamilies().getByName("PageStyles");
+ XNameAccess xName = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oPageStyles);
+ Object oPageStyle = xName.getByName("First Page");
+ XIndexAccess xAllTextTables = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, oTextTableHandler.xTextTablesSupplier.getTextTables());
+ XTextContent xTextTable = (XTextContent) UnoRuntime.queryInterface(XTextContent.class, xAllTextTables.getByIndex(0));
+ XTextRange xRange = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, xTextTable.getAnchor().getText());
+ xViewTextCursor.gotoRange(xRange, false);
+// if (xPageCursor.getPage() == (short) 1) {
+// Helper.setUnoPropertyValue(xTextTable, "PageDescName", "First Page");
+// TextTableHandler.resetBreakTypeofTextTable(xTextTable);
+// }
+ // }
+ XTextRange xHeaderRange = (XTextRange) Helper.getUnoPropertyValue(oPageStyle, "HeaderText", XTextRange.class);
+ if (!com.sun.star.uno.AnyConverter.isVoid(xHeaderRange))
+ {
+ xViewTextCursor.gotoRange(xHeaderRange, false);
+ xViewTextCursor.collapseToStart();
+ }
+ else
+ {
+ System.out.println("No Headertext available");
+ }
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void setViewSetting(String Setting, Object Value) throws UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException
+ {
+ xViewSettingsSupplier.getViewSettings().setPropertyValue(Setting, Value);
+ }
+
+ public void collapseViewCursorToStart()
+ {
+ XTextViewCursor xTextViewCursor = xTextViewCursorSupplier.getViewCursor();
+ xTextViewCursor.collapseToStart();
+ }
+}