summaryrefslogtreecommitdiffstats
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.java273
-rw-r--r--wizards/com/sun/star/wizards/text/TextDocument.py258
-rw-r--r--wizards/com/sun/star/wizards/text/TextElement.py27
-rw-r--r--wizards/com/sun/star/wizards/text/TextFieldHandler.java287
-rw-r--r--wizards/com/sun/star/wizards/text/TextFieldHandler.py115
-rw-r--r--wizards/com/sun/star/wizards/text/TextSectionHandler.java245
-rw-r--r--wizards/com/sun/star/wizards/text/TextSectionHandler.py116
-rw-r--r--wizards/com/sun/star/wizards/text/TextStyleHandler.java101
-rw-r--r--wizards/com/sun/star/wizards/text/TextTableHandler.java206
-rw-r--r--wizards/com/sun/star/wizards/text/ViewHandler.java96
-rw-r--r--wizards/com/sun/star/wizards/text/__init__.py0
11 files changed, 1724 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 000000000..74a24eb7f
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextDocument.java
@@ -0,0 +1,273 @@
+/*
+ * 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.text;
+
+import com.sun.star.document.XDocumentPropertiesSupplier;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.frame.XLoadable;
+import com.sun.star.frame.XModule;
+import com.sun.star.frame.XTerminateListener;
+import com.sun.star.frame.XStorable;
+import com.sun.star.awt.Size;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.PropertyVetoException;
+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.XSimpleText;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.XModifiable;
+import com.sun.star.util.XNumberFormatsSupplier;
+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.document.OfficeDocument;
+
+public class TextDocument
+{
+
+ public XComponent xComponent;
+ public com.sun.star.text.XTextDocument xTextDocument;
+ 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.awt.XWindowPeer xWindowPeer;
+
+ // 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 = UnoRuntime.queryInterface(XComponent.class, xTextDocument);
+
+ if (bShowStatusIndicator)
+ {
+ showStatusIndicator();
+ }
+ init();
+ }
+
+ public static class ModuleIdentifier
+ {
+
+ private final String m_identifier;
+
+ private 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 = UnoRuntime.queryInterface(XTextDocument.class,
+ xMSF.createInstance("com.sun.star.text.TextDocument"));
+
+ XLoadable xLoadable = UnoRuntime.queryInterface(XLoadable.class, xTextDocument);
+ xLoadable.initNew();
+
+ 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 = 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 = UnoRuntime.queryInterface(XComponent.class, xTextDocument);
+ }
+ catch (Exception e)
+ {
+ // TODO: it seems the whole project does not really have an error handling. Other methods
+ // seem to generally silence errors, so we can't do anything else here...
+ e.printStackTrace();
+ }
+
+ 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 = UnoRuntime.queryInterface(XComponent.class, _textDocument);
+ xTextDocument = UnoRuntime.queryInterface(XTextDocument.class, xComponent);
+ //PosSize = xFrame.getComponentWindow().getPosSize();
+ if (bshowStatusIndicator)
+ {
+ XStatusIndicatorFactory xStatusIndicatorFactory = UnoRuntime.queryInterface(XStatusIndicatorFactory.class, xFrame);
+ xProgressBar = xStatusIndicatorFactory.createStatusIndicator();
+ xProgressBar.start(PropertyNames.EMPTY_STRING, 100);
+ xProgressBar.setValue(5);
+ }
+ xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, xFrame.getComponentWindow());
+ xMSFDoc = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+
+ XDocumentPropertiesSupplier xDocPropsSuppl = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument);
+ xDocPropsSuppl.getDocumentProperties();
+ Helper.getUnoStructValue(xComponent, "CharLocale");
+ xText = xTextDocument.getText();
+ }
+
+ private void init()
+ {
+ xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, xFrame.getComponentWindow());
+ xMSFDoc = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+ UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+ XDocumentPropertiesSupplier xDocPropsSuppl = UnoRuntime.queryInterface(XDocumentPropertiesSupplier.class, xTextDocument);
+ xDocPropsSuppl.getDocumentProperties();
+ Helper.getUnoStructValue(xComponent, "CharLocale");
+ UnoRuntime.queryInterface(XStorable.class, xTextDocument);
+ xText = xTextDocument.getText();
+ }
+
+ private void showStatusIndicator()
+ {
+ XStatusIndicatorFactory xStatusIndicatorFactory = UnoRuntime.queryInterface(XStatusIndicatorFactory.class, xFrame);
+ xProgressBar = xStatusIndicatorFactory.createStatusIndicator();
+ xProgressBar.start(PropertyNames.EMPTY_STRING, 100);
+ xProgressBar.setValue(5);
+ }
+
+ private XTextDocument loadAsPreview(String sDefaultTemplate, boolean asTemplate)
+ {
+ PropertyValue loadValues[] = new PropertyValue[3];
+ // open document in the Preview mode
+ loadValues[0] = new PropertyValue();
+ loadValues[0].Name = PropertyNames.READ_ONLY;
+ 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 = UnoRuntime.queryInterface(XModifiable.class, xTextDocument);
+ xModi.setModified(false);
+ }
+ catch (PropertyVetoException e1)
+ {
+ e1.printStackTrace(System.err);
+ }
+ }
+ Object oDoc = OfficeDocument.load(xFrame, sDefaultTemplate, "_self", loadValues);
+ xTextDocument = (com.sun.star.text.XTextDocument) oDoc;
+ getPageSize();
+ xMSFDoc = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+
+ ViewHandler myViewHandler = new ViewHandler(xTextDocument);
+ try
+ {
+ myViewHandler.setViewSetting("ZoomType", Short.valueOf(com.sun.star.view.DocumentZoomType.ENTIRE_PAGE));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ TextFieldHandler myFieldHandler = new TextFieldHandler(xMSF, xTextDocument);
+ myFieldHandler.updateDocInfoFields();
+
+ return xTextDocument;
+
+ }
+
+ private Size getPageSize()
+ {
+ try
+ {
+ XStyleFamiliesSupplier xStyleFamiliesSupplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDocument);
+ com.sun.star.container.XNameAccess xNameAccess = null;
+ xNameAccess = xStyleFamiliesSupplier.getStyleFamilies();
+ com.sun.star.container.XNameContainer xPageStyleCollection = null;
+ xPageStyleCollection = UnoRuntime.queryInterface(com.sun.star.container.XNameContainer.class, xNameAccess.getByName("PageStyles"));
+ XStyle xPageStyle = UnoRuntime.queryInterface(XStyle.class, xPageStyleCollection.getByName("First Page"));
+ return (Size) Helper.getUnoPropertyValue(xPageStyle, "Size");
+
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ return null;
+ }
+ }
+
+ public static XTextCursor createTextCursor(Object oCursorContainer)
+ {
+ XSimpleText xText = UnoRuntime.queryInterface(XSimpleText.class, oCursorContainer);
+ return xText.createTextCursor();
+ }
+
+ // 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
+
+
+
+ public void unlockallControllers()
+ {
+ while (xTextDocument.hasControllersLocked())
+ {
+ xTextDocument.unlockControllers();
+ }
+ }
+
+}
diff --git a/wizards/com/sun/star/wizards/text/TextDocument.py b/wizards/com/sun/star/wizards/text/TextDocument.py
new file mode 100644
index 000000000..f975dad57
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextDocument.py
@@ -0,0 +1,258 @@
+#
+# 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
+import time
+from datetime import date as dateTimeObject
+from .TextFieldHandler import TextFieldHandler
+from ..document.OfficeDocument import OfficeDocument
+from ..common.Desktop import Desktop
+from ..common.Configuration import Configuration
+from ..common.NumberFormatter import NumberFormatter
+
+from com.sun.star.i18n.NumberFormatIndex import DATE_SYS_DDMMYY
+from com.sun.star.view.DocumentZoomType import ENTIRE_PAGE
+from com.sun.star.beans.PropertyState import DIRECT_VALUE
+
+class TextDocument(object):
+
+ def __init__(self, xMSF,listener=None,bShowStatusIndicator=None,
+ FrameName=None,_sPreviewURL=None,_moduleIdentifier=None,
+ _textDocument=None, xArgs=None):
+
+ self.xMSF = xMSF
+ self.xTextDocument = None
+
+ if listener is not None:
+ if FrameName is not None:
+ '''creates an instance of TextDocument
+ and creates a named frame.
+ No document is actually loaded into this frame.'''
+ self.xFrame = OfficeDocument.createNewFrame(
+ xMSF, listener, FrameName)
+ return
+
+ elif _sPreviewURL is not None:
+ '''creates an instance of TextDocument by
+ loading a given URL as preview'''
+ self.xFrame = OfficeDocument.createNewFrame(xMSF, listener)
+ self.xTextDocument = self.loadAsPreview(_sPreviewURL, True)
+
+ elif xArgs is not None:
+ '''creates an instance of TextDocument
+ and creates a frame and loads a document'''
+ self.xDesktop = Desktop.getDesktop(xMSF);
+ self.xFrame = OfficeDocument.createNewFrame(xMSF, listener)
+ self.xTextDocument = OfficeDocument.load(
+ self.xFrame, URL, "_self", xArgs);
+ self.xWindowPeer = self.xFrame.getComponentWindow()
+ self.m_xDocProps = self.xTextDocument.DocumentProperties
+ CharLocale = self.xTextDocument.CharLocale
+ return
+
+ else:
+ '''creates an instance of TextDocument from
+ the desktop's current frame'''
+ self.xDesktop = Desktop.getDesktop(xMSF);
+ self.xFrame = self.xDesktop.getActiveFrame()
+ self.xTextDocument = self.xFrame.getController().Model
+
+ elif _moduleIdentifier is not None:
+ try:
+ '''create the empty document, and set its module identifier'''
+ self.xTextDocument = xMSF.createInstance(
+ "com.sun.star.text.TextDocument")
+ self.xTextDocument.initNew()
+ self.xTextDocument.setIdentifier(
+ _moduleIdentifier.Identifier)
+ # load the document into a blank frame
+ xDesktop = Desktop.getDesktop(xMSF)
+ loadArgs = list(range(1))
+ loadArgs[0] = "Model"
+ loadArgs[0] = -1
+ loadArgs[0] = self.xTextDocument
+ loadArgs[0] = DIRECT_VALUE
+ xDesktop.loadComponentFromURL(
+ "private:object", "_blank", 0, loadArgs)
+ # remember some things for later usage
+ self.xFrame = self.xTextDocument.CurrentController.Frame
+ except Exception:
+ traceback.print_exc()
+
+ elif _textDocument is not None:
+ '''creates an instance of TextDocument
+ from a given XTextDocument'''
+ self.xFrame = _textDocument.CurrentController.Frame
+ self.xTextDocument = _textDocument
+ if bShowStatusIndicator:
+ self.showStatusIndicator()
+ self.init()
+
+ def init(self):
+ self.xWindowPeer = self.xFrame.getComponentWindow()
+ self.m_xDocProps = self.xTextDocument.DocumentProperties
+ self.CharLocale = self.xTextDocument.CharLocale
+ self.xText = self.xTextDocument.Text
+
+ def showStatusIndicator(self):
+ self.xProgressBar = self.xFrame.createStatusIndicator()
+ self.xProgressBar.start("", 100)
+ self.xProgressBar.setValue(5)
+
+ def loadAsPreview(self, sDefaultTemplate, asTemplate):
+ loadValues = list(range(3))
+ # open document in the Preview mode
+ loadValues[0] = uno.createUnoStruct(
+ 'com.sun.star.beans.PropertyValue')
+ loadValues[0].Name = "ReadOnly"
+ loadValues[0].Value = True
+ loadValues[1] = uno.createUnoStruct(
+ 'com.sun.star.beans.PropertyValue')
+ loadValues[1].Name = "AsTemplate"
+ if asTemplate:
+ loadValues[1].Value = True
+ else:
+ loadValues[1].Value = False
+
+ loadValues[2] = uno.createUnoStruct(
+ 'com.sun.star.beans.PropertyValue')
+ loadValues[2].Name = "Preview"
+ loadValues[2].Value = True
+
+ self.xTextDocument = OfficeDocument.load(
+ self.xFrame, sDefaultTemplate, "_self", loadValues)
+
+ self.DocSize = self.getPageSize()
+
+ try:
+ self.xTextDocument.CurrentController.ViewSettings.ZoomType = ENTIRE_PAGE
+ except Exception:
+ traceback.print_exc()
+ myFieldHandler = TextFieldHandler(self.xMSF, self.xTextDocument)
+ myFieldHandler.updateDocInfoFields()
+ return self.xTextDocument
+
+ def getPageSize(self):
+ try:
+ xNameAccess = self.xTextDocument.StyleFamilies
+ xPageStyleCollection = xNameAccess.getByName("PageStyles")
+ xPageStyle = xPageStyleCollection.getByName("First Page")
+ return xPageStyle.Size
+ except Exception:
+ traceback.print_exc()
+ return None
+
+ '''creates an instance of TextDocument and creates a
+ frame and loads a document'''
+
+ def createTextCursor(self, oCursorContainer):
+ xTextCursor = oCursorContainer.createTextCursor()
+ return xTextCursor
+
+ def refresh(self):
+ self.xTextDocument.refresh()
+
+ '''
+ This method sets the Author of a Wizard-generated template correctly
+ and adds an 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.
+ '''
+
+ def setWizardTemplateDocInfo(self, WizardName, TemplateDescription):
+ try:
+ xNA = Configuration.getConfigurationRoot(
+ self.xMSF, "/org.openoffice.UserProfile/Data", False)
+ gn = xNA.getByName("givenname")
+ sn = xNA.getByName("sn")
+ fullname = str(gn) + " " + str(sn)
+ now = time.localtime(time.time())
+ year = time.strftime("%Y", now)
+ month = time.strftime("%m", now)
+ day = time.strftime("%d", now)
+
+ dateObject = dateTimeObject(int(year), int(month), int(day))
+ du = self.DateUtils(self.xMSF, self.xTextDocument)
+ ff = du.getFormat(DATE_SYS_DDMMYY)
+ myDate = du.format(ff, dateObject)
+ xDocProps2 = self.xTextDocument.DocumentProperties
+ xDocProps2.Author = fullname
+ xDocProps2.ModifiedBy = fullname
+ description = xDocProps2.Description
+ description = description + " " + TemplateDescription
+ description = description.replace("<wizard_name>", WizardName)
+ description = description.replace("<current_date>", myDate)
+ xDocProps2.Description = description
+ except Exception:
+ traceback.print_exc()
+
+ @classmethod
+ def getFrameByName(self, sFrameName, xTD):
+ if xTD.TextFrames.hasByName(sFrameName):
+ return xTD.TextFrames.getByName(sFrameName)
+
+ return None
+
+ def searchFillInItems(self, typeSearch):
+ sd = self.xTextDocument.createSearchDescriptor()
+
+ if typeSearch == 0:
+ sd.setSearchString("<[^>]+>")
+ elif typeSearch == 1:
+ sd.setSearchString("#[^#]+#")
+
+ sd.setPropertyValue("SearchRegularExpression", True)
+ sd.setPropertyValue("SearchWords", True)
+
+ auxList = []
+ allItems = self.xTextDocument.findAll(sd)
+ for i in list(range(allItems.Count)):
+ auxList.append(allItems.getByIndex(i))
+
+ return auxList
+
+ class DateUtils(object):
+
+ def __init__(self, xmsf, document):
+ self.formatSupplier = document
+ formatSettings = self.formatSupplier.getNumberFormatSettings()
+ date = formatSettings.NullDate
+ self.calendar = dateTimeObject(date.Year, date.Month, date.Day)
+ self.formatter = NumberFormatter.createNumberFormatter(xmsf,
+ self.formatSupplier)
+
+ '''
+ @param format a constant of the enumeration NumberFormatIndex
+ @return
+ '''
+
+ def getFormat(self, format):
+ return NumberFormatter.getNumberFormatterKey(
+ self.formatSupplier, format)
+
+ '''
+ @param date a VCL date in form of 20041231
+ @return a document relative date
+ '''
+
+ def format(self, formatIndex, date):
+ difference = date - self.calendar
+ return self.formatter.convertNumberToString(formatIndex,
+ difference.days)
diff --git a/wizards/com/sun/star/wizards/text/TextElement.py b/wizards/com/sun/star/wizards/text/TextElement.py
new file mode 100644
index 000000000..57aa4ea26
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextElement.py
@@ -0,0 +1,27 @@
+#
+# 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 .
+#
+
+class TextElement(object):
+
+ def __init__(self, item, placeHolderText):
+ self.item = item
+ self.placeHolderText = placeHolderText
+
+ def write(self):
+ if self.item is not None:
+ self.item.String = self.placeHolderText
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 000000000..da43b3d88
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextFieldHandler.java
@@ -0,0 +1,287 @@
+/*
+ * 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.text;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+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.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.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;
+import com.sun.star.wizards.common.PropertyNames;
+
+public class TextFieldHandler
+{
+
+ private XTextFieldsSupplier xTextFieldsSupplier;
+ private final XMultiServiceFactory xMSFDoc;
+
+ /**
+ * Creates a new instance of TextFieldHandler
+ */
+ public TextFieldHandler(XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSFDoc = xMSF;
+ xTextFieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, xTextDocument);
+ }
+
+ private void refreshTextFields()
+ {
+ XRefreshable xUp = 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 PropertyNames.EMPTY_STRING;
+ }
+ else
+ {
+ XDependentTextField xDependent = UnoRuntime.queryInterface(XDependentTextField.class, oTextField);
+ XPropertySet xMaster = xDependent.getTextFieldMaster();
+ return (String) xMaster.getPropertyValue("Content");
+ }
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ return PropertyNames.EMPTY_STRING;
+ }
+
+ public void insertUserField(XTextCursor xTextCursor, String FieldName, String FieldTitle)
+ {
+ try
+ {
+ XInterface xField = (XInterface) xMSFDoc.createInstance("com.sun.star.text.TextField.User");
+ XDependentTextField xDepField = UnoRuntime.queryInterface(XDependentTextField.class, xField);
+ XTextContent xFieldContent = 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 = UnoRuntime.queryInterface(XComponent.class, oMaster);
+ xComponent.dispose();
+ }
+ XPropertySet xPSet = createUserField(FieldName, FieldTitle);
+ xDepField.attachTextFieldMaster(xPSet);
+ xTextCursor.getText().insertTextContent(xTextCursor, xFieldContent, false);
+
+ }
+ catch (com.sun.star.uno.Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ private XPropertySet createUserField(String FieldName, String FieldTitle) throws com.sun.star.uno.Exception
+ {
+ Object oMaster = xMSFDoc.createInstance("com.sun.star.text.FieldMaster.User");
+ XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oMaster);
+ xPSet.setPropertyValue(PropertyNames.PROPERTY_NAME, FieldName);
+ xPSet.setPropertyValue("Content", FieldTitle);
+
+ return xPSet;
+ }
+
+ private XDependentTextField[] getTextFieldsByProperty(String _PropertyName, Object _aPropertyValue, String _TypeName)
+ {
+ try
+ {
+ XDependentTextField[] xDependentFields;
+ ArrayList<XDependentTextField> xDependentVector = new ArrayList<XDependentTextField>();
+ if (xTextFieldsSupplier.getTextFields().hasElements())
+ {
+ XEnumeration xEnum = xTextFieldsSupplier.getTextFields().createEnumeration();
+ while (xEnum.hasMoreElements())
+ {
+ Object oTextField = xEnum.nextElement();
+ XDependentTextField xDependent = 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.add(xDependent);
+ }
+ }
+ }
+ else if (AnyConverter.isShort(oValue))
+ {
+ if (_TypeName.equals("Short"))
+ {
+ short iShortParam = ((Short) _aPropertyValue).shortValue();
+ short ishortValue = AnyConverter.toShort(oValue);
+ if (ishortValue == iShortParam)
+ {
+ xDependentVector.add(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.err);
+ }
+ return null;
+ }
+
+ public void changeUserFieldContent(String _FieldName, String _FieldContent)
+ {
+ try
+ {
+ XDependentTextField[] xDependentTextFields = getTextFieldsByProperty(PropertyNames.PROPERTY_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.err);
+ }
+ }
+
+ public void updateDocInfoFields()
+ {
+ try
+ {
+ XEnumeration xEnum = xTextFieldsSupplier.getTextFields().createEnumeration();
+ while (xEnum.hasMoreElements())
+ {
+ Object oTextField = xEnum.nextElement();
+ XServiceInfo xSI = UnoRuntime.queryInterface(XServiceInfo.class, oTextField);
+
+ if (xSI.supportsService("com.sun.star.text.TextField.ExtendedUser"))
+ {
+ XUpdatable xUp = UnoRuntime.queryInterface(XUpdatable.class, oTextField);
+ xUp.update();
+ }
+ if (xSI.supportsService("com.sun.star.text.TextField.User"))
+ {
+ XUpdatable xUp = 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 = UnoRuntime.queryInterface(XServiceInfo.class, oTextField);
+
+ if (xSI.supportsService("com.sun.star.text.TextField.DateTime"))
+ {
+ XPropertySet xPSet = 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 = UnoRuntime.queryInterface(XServiceInfo.class, oTextField);
+ if (xSI.supportsService("com.sun.star.text.TextField.DateTime"))
+ {
+ XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, oTextField);
+ xPSet.setPropertyValue("IsFixed", Boolean.valueOf(_bSetFixed));
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+
+
+
+}
diff --git a/wizards/com/sun/star/wizards/text/TextFieldHandler.py b/wizards/com/sun/star/wizards/text/TextFieldHandler.py
new file mode 100644
index 000000000..c250e091e
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextFieldHandler.py
@@ -0,0 +1,115 @@
+#
+# 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 traceback
+import time
+
+from com.sun.star.util import DateTime
+from com.sun.star.uno import RuntimeException
+from com.sun.star.beans import UnknownPropertyException
+
+class TextFieldHandler(object):
+
+ xTextFieldsSupplierAux = None
+ arrayTextFields = []
+ dictTextFields = {}
+
+ def __init__(self, xMSF, xTextDocument):
+ self.xMSFDoc = xMSF
+ self.xTextFieldsSupplier = xTextDocument
+ if TextFieldHandler.xTextFieldsSupplierAux is not \
+ self.xTextFieldsSupplier:
+ self.__getTextFields()
+ TextFieldHandler.xTextFieldsSupplierAux = self.xTextFieldsSupplier
+
+ def refreshTextFields(self):
+ xUp = self.xTextFieldsSupplier.TextFields
+ xUp.refresh()
+
+ def __getTextFields(self):
+ try:
+ if self.xTextFieldsSupplier.TextFields.hasElements():
+ xEnum = \
+ self.xTextFieldsSupplier.TextFields.createEnumeration()
+ while xEnum.hasMoreElements():
+ oTextField = xEnum.nextElement()
+ TextFieldHandler.arrayTextFields.append(oTextField)
+ xPropertySet = oTextField.TextFieldMaster
+ if xPropertySet.Name:
+ TextFieldHandler.dictTextFields[xPropertySet.Name] = \
+ oTextField
+ except Exception:
+ traceback.print_exc()
+
+ def changeUserFieldContent(self, _FieldName, _FieldContent):
+ try:
+ DependentTextFields = \
+ TextFieldHandler.dictTextFields[_FieldName]
+ except KeyError:
+ return None
+ try:
+ if hasattr(DependentTextFields, "TextFieldMaster"):
+ DependentTextFields.TextFieldMaster.Content = _FieldContent
+ self.refreshTextFields()
+ except UnknownPropertyException:
+ pass
+
+ def updateDocInfoFields(self):
+ try:
+ for i in TextFieldHandler.arrayTextFields:
+ if i.supportsService(
+ "com.sun.star.text.TextField.ExtendedUser"):
+ i.update()
+
+ if i.supportsService(
+ "com.sun.star.text.TextField.User"):
+ i.update()
+
+ except Exception:
+ traceback.print_exc()
+
+ def updateDateFields(self):
+ try:
+ now = time.localtime(time.time())
+ dt = DateTime()
+ dt.Day = time.strftime("%d", now)
+ dt.Year = time.strftime("%Y", now)
+ dt.Month = time.strftime("%m", now)
+ dt.Month += 1
+ for i in TextFieldHandler.arrayTextFields:
+ if i.supportsService(
+ "com.sun.star.text.TextField.DateTime"):
+ try:
+ i.IsFixed = False
+ i.DateTimeValue = dt
+ except RuntimeException:
+ pass
+
+ except Exception:
+ traceback.print_exc()
+
+ def removeUserFieldByContent(self):
+ #Remove userfield when its text is empty
+ xDependentTextFields = TextFieldHandler.arrayTextFields
+ for i in xDependentTextFields:
+ try:
+ if not i.TextFieldMaster.Content:
+ i.dispose()
+ except Exception:
+ #TextField doesn't even have the attribute Content,
+ #so it's empty
+ i.dispose()
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 000000000..14348b455
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextSectionHandler.java
@@ -0,0 +1,245 @@
+/*
+ * 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.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;
+import com.sun.star.wizards.common.PropertyNames;
+
+public class TextSectionHandler
+{
+
+ public XTextSectionsSupplier xTextSectionsSupplier;
+ private final XMultiServiceFactory xMSFDoc;
+ private final XText xText;
+
+ /** Creates a new instance of TextSectionHandler */
+ public TextSectionHandler(XMultiServiceFactory xMSF, XTextDocument xTextDocument)
+ {
+ this.xMSFDoc = xMSF;
+ xText = xTextDocument.getText();
+ xTextSectionsSupplier = UnoRuntime.queryInterface(XTextSectionsSupplier.class, xTextDocument);
+ }
+
+ public void removeTextSectionbyName(String SectionName)
+ {
+ try
+ {
+ XNameAccess xAllTextSections = xTextSectionsSupplier.getTextSections();
+ if (xAllTextSections.hasByName(SectionName))
+ {
+ Object oTextSection = xTextSectionsSupplier.getTextSections().getByName(SectionName);
+ removeTextSection(oTextSection);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+
+
+ public void removeLastTextSection()
+ {
+ try
+ {
+ XIndexAccess xAllTextSections = UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ Object oTextSection = xAllTextSections.getByIndex(xAllTextSections.getCount() - 1);
+ removeTextSection(oTextSection);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ private void removeTextSection(Object _oTextSection)
+ {
+ try
+ {
+ XTextContent xTextContentTextSection = UnoRuntime.queryInterface(XTextContent.class, _oTextSection);
+ xText.removeTextContent(xTextContentTextSection);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public void removeInvisibleTextSections()
+ {
+ try
+ {
+ XIndexAccess xAllTextSections = UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ int TextSectionCount = xAllTextSections.getCount();
+ for (int i = TextSectionCount - 1; i >= 0; i--)
+ {
+ XTextContent xTextContentTextSection = UnoRuntime.queryInterface(XTextContent.class, xAllTextSections.getByIndex(i));
+ XPropertySet xTextSectionPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xTextContentTextSection);
+ boolean bRemoveTextSection = (!AnyConverter.toBoolean(xTextSectionPropertySet.getPropertyValue("IsVisible")));
+ if (bRemoveTextSection)
+ {
+ xText.removeTextContent(xTextContentTextSection);
+ }
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public void removeAllTextSections()
+ {
+ try
+ {
+ XIndexAccess xAllTextSections = UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ int TextSectionCount = xAllTextSections.getCount();
+ for (int i = TextSectionCount - 1; i >= 0; i--)
+ {
+ XTextContent xTextContentTextSection = UnoRuntime.queryInterface(XTextContent.class, xAllTextSections.getByIndex(i));
+ xText.removeTextContent(xTextContentTextSection);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public void breakLinkofTextSections()
+ {
+ try
+ {
+ Object oTextSection;
+ XIndexAccess xAllTextSections = UnoRuntime.queryInterface(XIndexAccess.class, xTextSectionsSupplier.getTextSections());
+ int iSectionCount = xAllTextSections.getCount();
+ SectionFileLink oSectionLink = new SectionFileLink();
+ oSectionLink.FileURL = PropertyNames.EMPTY_STRING;
+ for (int i = 0; i < iSectionCount; i++)
+ {
+ oTextSection = xAllTextSections.getByIndex(i);
+ Helper.setUnoPropertyValues(oTextSection, new String[]
+ {
+ "FileLink", "LinkRegion"
+ }, new Object[]
+ {
+ oSectionLink, PropertyNames.EMPTY_STRING
+ });
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+
+
+ public void linkSectiontoTemplate(String TemplateName, String SectionName)
+ {
+ try
+ {
+ Object oTextSection = xTextSectionsSupplier.getTextSections().getByName(SectionName);
+ linkSectiontoTemplate(oTextSection, TemplateName, SectionName);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ private 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 = 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.err);
+ }
+ }
+
+ private void insertTextSection(String sectionName, String templateName, XTextCursor position)
+ {
+ try
+ {
+ Object xTextSection;
+ if (xTextSectionsSupplier.getTextSections().hasByName(sectionName))
+ {
+ xTextSection = xTextSectionsSupplier.getTextSections().getByName(sectionName);
+ }
+ else
+ {
+ xTextSection = xMSFDoc.createInstance("com.sun.star.text.TextSection");
+ XTextContent xTextContentSection = UnoRuntime.queryInterface(XTextContent.class, xTextSection);
+ position.getText().insertTextContent(position, xTextContentSection, false);
+ }
+ linkSectiontoTemplate(xTextSection, templateName, sectionName);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/TextSectionHandler.py b/wizards/com/sun/star/wizards/text/TextSectionHandler.py
new file mode 100644
index 000000000..e8d649a31
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextSectionHandler.py
@@ -0,0 +1,116 @@
+#
+# 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
+
+class TextSectionHandler(object):
+ '''Creates a new instance of TextSectionHandler'''
+ def __init__(self, xMSF, xTextDocument):
+ self.xMSFDoc = xMSF
+ self.xTextDocument = xTextDocument
+ self.xText = xTextDocument.Text
+
+ def removeTextSectionbyName(self, SectionName):
+ try:
+ xAllTextSections = self.xTextDocument.TextSections
+ if xAllTextSections.hasByName(SectionName):
+ oTextSection = self.xTextDocument.TextSections.getByName(
+ SectionName)
+ self.removeTextSection(oTextSection)
+
+
+ except Exception:
+ traceback.print_exc()
+
+ def hasTextSectionByName(self, SectionName):
+ xAllTextSections = self.xTextDocument.TextSections
+ return xAllTextSections.hasByName(SectionName)
+
+ def removeTextSection(self, _oTextSection):
+ try:
+ self.xText.removeTextContent(_oTextSection)
+ except Exception:
+ traceback.print_exc()
+
+ def removeAllTextSections(self):
+ try:
+ TextSectionCount = self.xTextDocument.TextSections.Count
+ xAllTextSections = self.xTextDocument.TextSections
+ for i in range(TextSectionCount - 1, -1, -1):
+ xTextContentTextSection = xAllTextSections.getByIndex(i)
+ self.xText.removeTextContent(xTextContentTextSection)
+ except Exception:
+ traceback.print_exc()
+
+ def breakLinkOfTextSection(self, oTextSection):
+ try:
+ oSectionLink = \
+ uno.createUnoStruct('com.sun.star.text.SectionFileLink')
+ oSectionLink.FileURL = ""
+ uno.invoke(oTextSection, "setPropertyValues",
+ (("FileLink", "LinkRegion"), (oSectionLink, "")))
+ except Exception:
+ traceback.print_exc()
+
+ def linkSectiontoTemplate(
+ self, TemplateName, SectionName, oTextSection=None):
+ try:
+ if not oTextSection:
+ oTextSection = self.xTextDocument.TextSections.getByName(
+ SectionName)
+ oSectionLink = \
+ uno.createUnoStruct('com.sun.star.text.SectionFileLink')
+ oSectionLink.FileURL = TemplateName
+ uno.invoke(oTextSection, "setPropertyValues",
+ (("FileLink", "LinkRegion"), (oSectionLink, SectionName)))
+
+ NewSectionName = oTextSection.Name
+ if NewSectionName is not SectionName:
+ oTextSection.Name = SectionName
+ except Exception:
+ traceback.print_exc()
+
+ def insertTextSection(self, GroupName, TemplateName, _bAddParagraph):
+ try:
+ if _bAddParagraph:
+ xTextCursor = self.xText.createTextCursor()
+ self.xText.insertControlCharacter(
+ xTextCursor, ControlCharacter.PARAGRAPH_BREAK, False)
+ xTextCursor.collapseToEnd()
+
+ xSecondTextCursor = self.xText.createTextCursor()
+ xSecondTextCursor.gotoEnd(False)
+ insertTextSection(GroupName, TemplateName, xSecondTextCursor)
+ except Exception:
+ traceback.print_exc()
+
+ def insertTextSection(self, sectionName, templateName, position):
+ try:
+ if self.xTextDocument.TextSections.hasByName(sectionName):
+ xTextSection = \
+ self.xTextDocument.TextSections.getByName(sectionName)
+ else:
+ xTextSection = self.xMSFDoc.createInstance(
+ "com.sun.star.text.TextSection")
+ position.getText().insertTextContent(
+ position, xTextSection, False)
+
+ linkSectiontoTemplate(xTextSection, templateName, sectionName)
+ except Exception:
+ traceback.print_exc()
+
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 000000000..c36bdc670
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextStyleHandler.java
@@ -0,0 +1,101 @@
+/*
+ * 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.text;
+
+import com.sun.star.awt.Size;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.container.XNameAccess;
+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;
+import com.sun.star.wizards.common.PropertyNames;
+
+public class TextStyleHandler
+{
+
+ public XStyleFamiliesSupplier xStyleFamiliesSupplier;
+
+ /** Creates a new instance of TextStyleHandler */
+ public TextStyleHandler(XTextDocument xTextDocument)
+ {
+ xStyleFamiliesSupplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDocument);
+ }
+
+ public void loadStyleTemplates(String sTemplateUrl, String OptionString)
+ {
+ try
+ {
+ XStyleLoader xStyleLoader = UnoRuntime.queryInterface(XStyleLoader.class, xStyleFamiliesSupplier.getStyleFamilies());
+ com.sun.star.beans.PropertyValue[] StyleOptions = xStyleLoader.getStyleLoaderOptions();
+ String CurOptionName = PropertyNames.EMPTY_STRING;
+ int PropCount = StyleOptions.length;
+ for (int i = 0; i < PropCount; i++)
+ {
+ CurOptionName = StyleOptions[i].Name;
+ StyleOptions[i].Value = Boolean.valueOf(CurOptionName.equals(OptionString) || CurOptionName.equals("OverwriteStyles"));
+ }
+ xStyleLoader.loadStylesFromURL(sTemplateUrl, StyleOptions);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public XPropertySet getStyleByName(String sStyleFamily, String sStyleName)
+ {
+ try
+ {
+ XPropertySet xPropertySet = null;
+ Object oStyleFamily = xStyleFamiliesSupplier.getStyleFamilies().getByName(sStyleFamily);
+ XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oStyleFamily);
+ if (xNameAccess.hasByName(sStyleName))
+ {
+ xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xNameAccess.getByName(sStyleName));
+ }
+ return xPropertySet;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(System.err);
+ }
+ return null;
+ }
+
+ public Size changePageAlignment(XPropertySet _xPropPageStyle, boolean _bIsLandscape)
+ {
+ try
+ {
+ _xPropPageStyle.setPropertyValue("IsLandscape", Boolean.valueOf(_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.err);
+ 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 000000000..74e896639
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/TextTableHandler.java
@@ -0,0 +1,206 @@
+/*
+ * 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.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.table.XCellRange;
+import com.sun.star.text.XSimpleText;
+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.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;
+ private XTextDocument xTextDocument;
+ private NumberFormatter oNumberFormatter;
+
+ /** Creates a new instance of TextTableHandler */
+ public TextTableHandler(XTextDocument xTextDocument)
+ {
+ try
+ {
+ this.xTextDocument = xTextDocument;
+ xTextTablesSupplier = UnoRuntime.queryInterface(XTextTablesSupplier.class, xTextDocument);
+ UnoRuntime.queryInterface(XSimpleText.class, xTextDocument.getText());
+ XNumberFormatsSupplier xNumberFormatsSupplier = UnoRuntime.queryInterface(XNumberFormatsSupplier.class, xTextDocument);
+ Locale aCharLocale = (Locale) Helper.getUnoStructValue(xTextDocument, "CharLocale");
+ oNumberFormatter = new NumberFormatter(xNumberFormatsSupplier, aCharLocale);
+ }
+ catch (java.lang.Exception e)
+ {
+ e.printStackTrace(System.err);
+ }
+ }
+
+ 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 = UnoRuntime.queryInterface(XTextTable.class, oTable);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ return xTextTable;
+ }
+
+ public com.sun.star.text.XTextTable getlastTextTable()
+ {
+ try
+ {
+ XIndexAccess xAllTextTables = UnoRuntime.queryInterface(XIndexAccess.class, xTextTablesSupplier.getTextTables());
+ int MaxIndex = xAllTextTables.getCount() - 1;
+ Object oTable = xAllTextTables.getByIndex(MaxIndex);
+ return UnoRuntime.queryInterface(XTextTable.class, oTable);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ return null;
+ }
+ }
+
+
+
+ public void removeAllTextTables()
+ {
+ try
+ {
+ XIndexAccess xAllTextTables = 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.err);
+ }
+ }
+
+ public void removeLastTextTable()
+ {
+ try
+ {
+ XIndexAccess xAllTextTables = UnoRuntime.queryInterface(XIndexAccess.class, xTextTablesSupplier.getTextTables());
+ Object oTextTable = xAllTextTables.getByIndex(xAllTextTables.getCount() - 1);
+ removeTextTable(oTextTable);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ private void removeTextTable(Object oTextTable)
+ {
+ try
+ {
+ XTextContent xTextContentTable = UnoRuntime.queryInterface(XTextContent.class, oTextTable);
+ xTextDocument.getText().removeTextContent(xTextContentTable);
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public void removeTextTablebyName(String TableName)
+ {
+ try
+ {
+ XNameAccess xAllTextTables = xTextTablesSupplier.getTextTables();
+ if (xAllTextTables.hasByName(TableName))
+ {
+ removeTextTable(xAllTextTables.getByName(TableName));
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public void renameTextTable(String OldTableName, String NewTableName)
+ {
+ try
+ {
+ XNameAccess xTextTableNames = xTextTablesSupplier.getTextTables();
+ if (xTextTableNames.hasByName(OldTableName))
+ {
+ Object oTextTable = xTextTableNames.getByName(OldTableName);
+ XNamed xTextTableName = UnoRuntime.queryInterface(XNamed.class, oTextTable);
+ xTextTableName.setName(NewTableName);
+ }
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+
+ public void adjustOptimalTableWidths(XMultiServiceFactory _xMSF, XTextTable xTextTable)
+ {
+ try
+ {
+ XFrame xFrame = this.xTextDocument.getCurrentController().getFrame();
+ int ColCount = xTextTable.getColumns().getCount();
+ 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 = 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", Short.valueOf(iHoriOrient));
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace(System.err);
+ }
+ }
+}
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 000000000..fc7842996
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/ViewHandler.java
@@ -0,0 +1,96 @@
+/*
+ * 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.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.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 final XTextViewCursorSupplier xTextViewCursorSupplier;
+ private final XStyleFamiliesSupplier xStyleFamiliesSupplier;
+ private final XViewSettingsSupplier xViewSettingsSupplier;
+
+ /** Creates a new instance of View */
+ public ViewHandler(XTextDocument xTextDocument)
+ {
+ xTextViewCursorSupplier = UnoRuntime.queryInterface(XTextViewCursorSupplier.class, xTextDocument.getCurrentController());
+ xViewSettingsSupplier = UnoRuntime.queryInterface(XViewSettingsSupplier.class, xTextDocument.getCurrentController());
+ xStyleFamiliesSupplier = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, xTextDocument);
+ }
+
+ public void selectFirstPage(TextTableHandler oTextTableHandler)
+ {
+ try
+ {
+ XPageCursor xPageCursor = UnoRuntime.queryInterface(XPageCursor.class, xTextViewCursorSupplier.getViewCursor());
+ XTextCursor xViewTextCursor = UnoRuntime.queryInterface(XTextCursor.class, xPageCursor);
+ xPageCursor.jumpToFirstPage();
+ xPageCursor.jumpToStartOfPage();
+ Helper.setUnoPropertyValue(xPageCursor, "PageDescName", "First Page");
+ Object oPageStyles = xStyleFamiliesSupplier.getStyleFamilies().getByName("PageStyles");
+ XNameAccess xName = UnoRuntime.queryInterface(XNameAccess.class, oPageStyles);
+ Object oPageStyle = xName.getByName("First Page");
+ XIndexAccess xAllTextTables = UnoRuntime.queryInterface(XIndexAccess.class, oTextTableHandler.xTextTablesSupplier.getTextTables());
+ XTextContent xTextTable = UnoRuntime.queryInterface(XTextContent.class, xAllTextTables.getByIndex(0));
+ XTextRange xRange = UnoRuntime.queryInterface(XTextRange.class, xTextTable.getAnchor().getText());
+ xViewTextCursor.gotoRange(xRange, false);
+ 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.err);
+ }
+ }
+
+ 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();
+ }
+}
diff --git a/wizards/com/sun/star/wizards/text/__init__.py b/wizards/com/sun/star/wizards/text/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/wizards/com/sun/star/wizards/text/__init__.py