1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="view_XPrintable" script:language="StarBasic">
4
5
6'*************************************************************************
7'
8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9'
10' Copyright 2000, 2010 Oracle and/or its affiliates.
11'
12' OpenOffice.org - a multi-platform office productivity suite
13'
14' This file is part of OpenOffice.org.
15'
16' OpenOffice.org is free software: you can redistribute it and/or modify
17' it under the terms of the GNU Lesser General Public License version 3
18' only, as published by the Free Software Foundation.
19'
20' OpenOffice.org is distributed in the hope that it will be useful,
21' but WITHOUT ANY WARRANTY; without even the implied warranty of
22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23' GNU Lesser General Public License version 3 for more details
24' (a copy is included in the LICENSE file that accompanied this code).
25'
26' You should have received a copy of the GNU Lesser General Public License
27' version 3 along with OpenOffice.org.  If not, see
28' <http://www.openoffice.org/license.html>
29' for a copy of the LGPLv3 License.
30'
31'*************************************************************************
32'*************************************************************************
33
34
35
36' Be sure that all variables are dimensioned:
37option explicit
38
39
40
41Sub RunTest()
42
43'*************************************************************************
44' INTERFACE:
45' com.sun.star.view.XPrintable
46'*************************************************************************
47On Error Goto ErrHndl
48    Dim bOK As Boolean
49    Dim sFileName, sFileUrl As String
50    Dim aPrintingOptions(1) As New com.sun.star.beans.PropertyValue
51    Dim aPrinterProps As Variant
52    Dim i As Integer
53
54    Test.StartMethod("getPrinter()")
55    bOK = true
56    aPrinterProps = oObj.getPrinter()
57    bOK = bOK AND (ubound(aPrinterProps) &gt; 0)
58    Test.MethodTested("getPrinter()", bOK)
59
60
61    Test.StartMethod("print()")
62    bOK = true
63
64    sFileUrl = utils.getTempFileURL("/XPrintable.prt", true)
65    sFileName = utils.URL2Path(sFileUrl)
66
67    aPrintingOptions(0).Name = "FileName"
68    aPrintingOptions(0).Value = sFileName
69    aPrintingOptions(0).State = com.sun.star.beans.PropertyState.DEFAULT_VALUE
70
71    aPrintingOptions(1).Name = "Wait"
72    aPrintingOptions(1).Value = true
73    oObj.Print(aPrintingOptions())
74
75    ' without waiting Office can hang on setPrinter() call.
76    wait(500)
77
78    bOK = bOK AND FileExists(sFileName)
79    Test.MethodTested("print()", bOK)
80
81    Test.StartMethod("setPrinter()")
82    bOK = true
83    Dim iPaperFormat As Integer
84    Dim iNewPaperFormat As Integer
85
86    for i = 0 to ubound(aPrinterProps())
87        if (aPrinterProps(i).Name = "PaperFormat") then
88            iPaperFormat = aPrinterProps(i).Value
89            exit for
90        endif
91    next i
92
93    if (iPaperFormat = com.sun.star.view.PaperFormat.A4) then
94        iNewPaperFormat = com.sun.star.view.PaperFormat.LETTER
95    else
96        iNewPaperFormat = com.sun.star.view.PaperFormat.A4
97    endif
98
99    aPrinterProps(i).Value = iNewPaperFormat
100
101    oObj.setPrinter(aPrinterProps())
102
103    aPrinterProps() = oObj.getPrinter()
104
105    for i = 0 to ubound(aPrinterProps())
106        if (aPrinterProps(i).Name = "PaperFormat") then
107            bOK = bOK AND (aPrinterProps(i).Value = iNewPaperFormat)
108            exit for
109        endif
110    next i
111    Test.MethodTested("setPrinter()", bOK)
112
113Exit Sub
114ErrHndl:
115    Test.Exception()
116    bOK = false
117    resume next
118End Sub
119</script:module>
120