summaryrefslogtreecommitdiff
path: root/wizards/com/sun/star/wizards/letter
diff options
context:
space:
mode:
authorKurt Zenker <kz@openoffice.org>2004-05-19 11:43:14 +0000
committerKurt Zenker <kz@openoffice.org>2004-05-19 11:43:14 +0000
commit323cb37e2b3e85a5083e0619080432fccaf9b68d (patch)
tree55e69a028c6455b00b4bce5c4da1de663458d7f8 /wizards/com/sun/star/wizards/letter
parent1593f5684edaa1fcc0e2cbbf10d100cad5bcac20 (diff)
INTEGRATION: CWS qwizards1 (1.1.2); FILE ADDED
2004/04/14 14:54:11 tv 1.1.2.17: correct relation for frames 2004/04/02 13:17:29 tv 1.1.2.16: increased startup performance 2004/03/19 14:07:21 tv 1.1.2.15: put pre-printed elements in the background 2004/03/12 15:37:49 tv 1.1.2.14: some property debugging code inserted 2004/03/09 17:16:41 tv 1.1.2.13: added resource support for Greeting and Salutation 2004/03/08 13:15:12 tv 1.1.2.12: correct setting of the document after reading the configuration 2004/03/02 09:13:13 tv 1.1.2.11: added some configuration modifications 2004/02/13 10:35:02 tv 1.1.2.10: correct TabIndex & added Configuration (Part1) 2004/02/06 10:11:16 tv 1.1.2.9: all basic functionality complete 2004/02/02 11:28:08 tv 1.1.2.8: formatted with autoformatter (indents now use TAB) 2004/01/28 16:05:08 tv 1.1.2.7: added configuration, added background objects.. 2003/11/26 16:04:17 tv 1.1.2.6: integrated roadmap control 2003/10/16 14:25:55 tv 1.1.2.5: several small fixes 2003/10/10 08:16:33 tv 1.1.2.4: several changes for LetterWizard 2003/09/22 12:02:46 tv 1.1.2.3: added loading of templates to letter wizard 2003/09/08 15:07:08 tv 1.1.2.2: optimized Speed 2003/09/05 13:43:25 tv 1.1.2.1: first draft of letter wizard (mainly UI)
Diffstat (limited to 'wizards/com/sun/star/wizards/letter')
-rw-r--r--wizards/com/sun/star/wizards/letter/LetterDocument.java259
1 files changed, 259 insertions, 0 deletions
diff --git a/wizards/com/sun/star/wizards/letter/LetterDocument.java b/wizards/com/sun/star/wizards/letter/LetterDocument.java
new file mode 100644
index 000000000000..2bf1f09fe730
--- /dev/null
+++ b/wizards/com/sun/star/wizards/letter/LetterDocument.java
@@ -0,0 +1,259 @@
+package com.sun.star.wizards.letter;
+
+import com.sun.star.wizards.common.*;
+import com.sun.star.wizards.document.*;
+import com.sun.star.wizards.text.*;
+import com.sun.star.frame.XDesktop;
+import com.sun.star.table.BorderLine;
+import com.sun.star.text.*;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.awt.XWindowPeer;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.drawing.XShape;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.awt.Size;
+import com.sun.star.style.NumberingType;
+import com.sun.star.style.ParagraphAdjust;
+import com.sun.star.style.XStyleFamiliesSupplier;
+import com.sun.star.style.XStyle;
+
+public class LetterDocument extends TextDocument {
+
+ XDesktop xDesktop;
+ XMultiServiceFactory xDocMSF;
+ XTextDocument xTextDocument;
+ Size DocSize = null;
+
+ public LetterDocument(XMultiServiceFactory xMSF) {
+ super(xMSF);
+ }
+
+ public XTextDocument loadTemplate(String sDefaultTemplate) {
+ 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 = Boolean.FALSE;
+ loadValues[2] = new PropertyValue();
+ loadValues[2].Name = "Preview";
+ loadValues[2].Value = Boolean.TRUE;
+
+
+ Object oDoc = OfficeDocument.load(xFrame, sDefaultTemplate, "_self", loadValues);
+ xTextDocument = (com.sun.star.text.XTextDocument) oDoc;
+ DocSize = getPageSize();
+ xDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDocument);
+
+ ViewHandler myViewHandler = new ViewHandler(xDocMSF, xTextDocument);
+ try {
+ myViewHandler.setViewSetting("ZoomType", new Short(com.sun.star.view.DocumentZoomType.ENTIRE_PAGE));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return xTextDocument;
+ }
+
+ public XWindowPeer getWindowPeer() {
+ XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xTextDocument);
+ return xWindowPeer;
+ }
+
+ public void switchElement(String sElement, boolean bState) {
+ try {
+ TextSectionHandler mySectionHandler = new TextSectionHandler(xMSF, xTextDocument);
+ Object oSection = mySectionHandler.xTextSectionsSupplier.getTextSections().getByName(sElement);
+ Helper.setUnoPropertyValue(oSection, "IsVisible", new Boolean(bState));
+
+ } catch (Exception exception) {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void switchFooter(String sPageStyle, boolean bState, boolean bPageNumber, String sText) {
+ if (xTextDocument != null) {
+ 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"));
+
+ XText xFooterText;
+ XStyle xPageStyle = (XStyle) UnoRuntime.queryInterface(XStyle.class, xPageStyleCollection.getByName(sPageStyle));
+
+ if (bState) {
+ Helper.setUnoPropertyValue(xPageStyle, "FooterIsOn", new Boolean(true));
+ xFooterText = (XText) UnoRuntime.queryInterface(XText.class, Helper.getUnoPropertyValue(xPageStyle, "FooterText"));
+ xFooterText.setString(sText);
+ if (bPageNumber) {
+ //Adding the Page Number
+ XTextCursor myCursor = xFooterText.createTextCursor();
+ myCursor.gotoEnd(false);
+ xFooterText.insertControlCharacter(myCursor, ControlCharacter.PARAGRAPH_BREAK, false);
+ XPropertySet xCursorPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, myCursor);
+ //XTextField xPageNumberField = (XTextField) UnoRuntime.queryInterface(XTextField.class, xDocMSF.createInstance("com.sun.star.style.ParagraphProperties"));
+ xCursorPSet.setPropertyValue("ParaAdjust", ParagraphAdjust.CENTER);
+ XTextField xPageNumberField = (XTextField) UnoRuntime.queryInterface(XTextField.class, xDocMSF.createInstance("com.sun.star.text.TextField.PageNumber"));
+ XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPageNumberField);
+ xPSet.setPropertyValue("SubType", PageNumberType.CURRENT);
+ xPSet.setPropertyValue("NumberingType", new Short (NumberingType.ARABIC));
+ xFooterText.insertTextContent(xFooterText.getEnd(), xPageNumberField, false);
+ }
+ } else {
+ Helper.setUnoPropertyValue(xPageStyle, "FooterIsOn", new Boolean(false));
+ }
+ } catch (Exception exception) {
+ exception.printStackTrace(System.out);
+ }
+ }
+ }
+
+ public boolean hasElement(String sElement) {
+ if (xTextDocument != null) {
+ TextSectionHandler mySectionHandler = new TextSectionHandler(xMSF, xTextDocument);
+ return mySectionHandler.hasTextSectionByName(sElement);
+ } else {
+ return false;
+ }
+ }
+
+ public void switchUserField(String sFieldName, String sNewContent, boolean bState) {
+ TextFieldHandler myFieldHandler = new TextFieldHandler(xMSF, xTextDocument);
+ if (bState) {
+ myFieldHandler.changeUserFieldContent(sFieldName, sNewContent);
+ } else {
+ myFieldHandler.changeUserFieldContent(sFieldName, "");
+ }
+ }
+
+ public void fillSenderWithUserData() {
+ try {
+ TextFieldHandler myFieldHandler = new TextFieldHandler(xDocMSF, xTextDocument);
+ Object oUserDataAccess = Configuration.getConfigurationRoot(xMSF, "org.openoffice.UserProfile/Data", false);
+ myFieldHandler.changeUserFieldContent("Company", (String) Helper.getUnoObjectbyName(oUserDataAccess, "o"));
+ myFieldHandler.changeUserFieldContent("Street", (String) Helper.getUnoObjectbyName(oUserDataAccess, "street"));
+ myFieldHandler.changeUserFieldContent("PostCode", (String) Helper.getUnoObjectbyName(oUserDataAccess, "postalcode"));
+ myFieldHandler.changeUserFieldContent("City", (String) Helper.getUnoObjectbyName(oUserDataAccess, "l"));
+ } catch (Exception exception) {
+ exception.printStackTrace(System.out);
+ }
+ }
+
+ public void killEmptyUserFields() {
+ TextFieldHandler myFieldHandler = new TextFieldHandler(xMSF, xTextDocument);
+ myFieldHandler.removeUserFieldByContent("Salutation");
+ myFieldHandler.removeUserFieldByContent("Greeting");
+ }
+
+ public void loadResult(String sLoadURL, boolean bAsTemplate) {
+ PropertyValue loadValues[] = new PropertyValue[1];
+ loadValues[0] = new PropertyValue();
+ loadValues[0].Name = "AsTemplate";
+ loadValues[0].Value = new Boolean(bAsTemplate);
+ String sFrame = "_self";
+ OfficeDocument.load(xDesktop, sLoadURL, sFrame, loadValues);
+ }
+
+ 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;
+ }
+ }
+
+ public class BusinessPaperObject {
+
+ public int iWidth;
+ public int iHeight;
+ public int iXPos;
+ public int iYPos;
+
+ XTextFrame xFrame;
+ XShape xShape;
+
+ public BusinessPaperObject(String FrameText, int Width, int Height, int XPos, int YPos) {
+
+ iWidth = Width;
+ iHeight = Height;
+ iXPos = XPos;
+ iYPos = YPos;
+
+ try {
+ xFrame = (XTextFrame) UnoRuntime.queryInterface(XTextFrame.class, xDocMSF.createInstance("com.sun.star.text.TextFrame"));
+ xShape = (XShape) UnoRuntime.queryInterface(XShape.class, xFrame);
+
+ setFramePosition();
+ Helper.setUnoPropertyValue(xShape, "AnchorType", TextContentAnchorType.AT_PAGE);
+ Helper.setUnoPropertyValue(xShape, "SizeType", new Short(SizeType.FIX));
+
+ Helper.setUnoPropertyValue(xFrame, "TextWrap", WrapTextMode.THROUGHT);
+ Helper.setUnoPropertyValue(xFrame, "Opaque", Boolean.FALSE);
+ Helper.setUnoPropertyValue(xFrame, "BackColor", new Integer(15790320));
+
+ BorderLine myBorder = new BorderLine();
+ myBorder.OuterLineWidth = 0;
+ Helper.setUnoPropertyValue(xFrame, "LeftBorder", myBorder);
+ Helper.setUnoPropertyValue(xFrame, "RightBorder", myBorder);
+ Helper.setUnoPropertyValue(xFrame, "TopBorder", myBorder);
+ Helper.setUnoPropertyValue(xFrame, "BottomBorder", myBorder);
+
+ XTextCursor xTextCursor = xTextDocument.getText().createTextCursor();
+ xTextCursor.gotoEnd(true);
+ XText xText = xTextDocument.getText();
+ xText.insertTextContent(xTextCursor, xFrame, false);
+
+ XText xFrameText = xFrame.getText();
+ XTextCursor xFrameCursor = xFrameText.createTextCursor();
+ XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFrameCursor);
+ xCursorProps.setPropertyValue("CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD));
+ xCursorProps.setPropertyValue("CharColor", new Integer(16777215));
+ xCursorProps.setPropertyValue("CharFontName", new String("Albany"));
+ xCursorProps.setPropertyValue("CharHeight", new Float(18));
+
+ xFrameText.insertString(xFrameCursor, FrameText, false);
+
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ }
+
+ public void setFramePosition() {
+ Helper.setUnoPropertyValue(xFrame, "HoriOrient", new Short(HoriOrientation.NONE));
+ Helper.setUnoPropertyValue(xFrame, "VertOrient", new Short(VertOrientation.NONE));
+ Helper.setUnoPropertyValue(xFrame, "Height", new Integer(iHeight));
+ Helper.setUnoPropertyValue(xFrame, "Width", new Integer(iWidth));
+ Helper.setUnoPropertyValue(xFrame, "HoriOrientPosition", new Integer(iXPos));
+ Helper.setUnoPropertyValue(xFrame, "VertOrientPosition", new Integer(iYPos));
+ Helper.setUnoPropertyValue(xFrame, "HoriOrientRelation", new Short(RelOrientation.PAGE_FRAME));
+ Helper.setUnoPropertyValue(xFrame, "VertOrientRelation", new Short(RelOrientation.PAGE_FRAME));
+ }
+
+ public void removeFrame() {
+ if (xFrame != null) {
+ try {
+ xTextDocument.getText().removeTextContent(xFrame);
+ } catch (Exception e) {
+ e.printStackTrace(System.out);
+ }
+ }
+ }
+
+ }
+
+}