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
37' Be sure that all variables are dimensioned:
38option explicit
39
40
41
42Sub RunTest()
43
44'*************************************************************************
45' INTERFACE:
46' com.sun.star.view.XPrintable
47'*************************************************************************
48On Error Goto ErrHndl
49    Dim bOK As Boolean
50    Dim sFileName, sFileUrl As String
51    Dim aPrintingOptions(1) As New com.sun.star.beans.PropertyValue
52    Dim aPrinterProps As Variant
53    Dim i As Integer
54
55    Test.StartMethod("getPrinter()")
56    bOK = true
57    aPrinterProps = oObj.getPrinter()
58    bOK = bOK AND (ubound(aPrinterProps) &gt; 0)
59    Test.MethodTested("getPrinter()", bOK)
60
61
62    Test.StartMethod("print()")
63    bOK = true
64
65    sFileUrl = utils.getTempFileURL("/XPrintable.prt", true)
66    sFileName = utils.URL2Path(sFileUrl)
67
68    aPrintingOptions(0).Name = "FileName"
69    aPrintingOptions(0).Value = sFileName
70    aPrintingOptions(0).State = com.sun.star.beans.PropertyState.DEFAULT_VALUE
71
72    aPrintingOptions(1).Name = "Wait"
73    aPrintingOptions(1).Value = true
74    oObj.Print(aPrintingOptions())
75
76    ' without waiting Office can hang on setPrinter() call.
77    wait(500)
78
79    bOK = bOK AND FileExists(sFileName)
80    Test.MethodTested("print()", bOK)
81
82    Test.StartMethod("setPrinter()")
83    bOK = true
84    Dim iPaperFormat As Integer
85    Dim iNewPaperFormat As Integer
86
87    for i = 0 to ubound(aPrinterProps())
88        if (aPrinterProps(i).Name = "PaperFormat") then
89            iPaperFormat = aPrinterProps(i).Value
90            exit for
91        endif
92    next i
93
94    if (iPaperFormat = com.sun.star.view.PaperFormat.A4) then
95        iNewPaperFormat = com.sun.star.view.PaperFormat.LETTER
96    else
97        iNewPaperFormat = com.sun.star.view.PaperFormat.A4
98    endif
99
100    aPrinterProps(i).Value = iNewPaperFormat
101
102    oObj.setPrinter(aPrinterProps())
103
104    aPrinterProps() = oObj.getPrinter()
105
106    for i = 0 to ubound(aPrinterProps())
107        if (aPrinterProps(i).Name = "PaperFormat") then
108            bOK = bOK AND (aPrinterProps(i).Value = iNewPaperFormat)
109            exit for
110        endif
111    next i
112    Test.MethodTested("setPrinter()", bOK)
113
114Exit Sub
115ErrHndl:
116    Test.Exception()
117    bOK = false
118    resume next
119End Sub
120</script:module>
121