1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/virdev.hxx>
21 #include <vcl/metric.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <unotools/printwarningoptions.hxx>
24 #include <svtools/printoptions.hxx>
27 #include <sfx2/printer.hxx>
28 #include <sfx2/printopt.hxx>
29 #include "sfxtypes.hxx"
30 #include <sfx2/prnmon.hxx>
31 #include <sfx2/viewsh.hxx>
32 #include <sfx2/tabdlg.hxx>
33 #include "sfx2/sfxresid.hxx"
36 // struct SfxPrinter_Impl ------------------------------------------------
38 struct SfxPrinter_Impl
47 mbSelection ( sal_True
),
48 mbFromTo ( sal_True
),
49 mbRange ( sal_True
) {}
53 struct SfxPrintOptDlg_Impl
55 sal_Bool mbHelpDisabled
;
57 SfxPrintOptDlg_Impl() :
58 mbHelpDisabled ( sal_False
) {}
61 // class SfxPrinter ------------------------------------------------------
63 SfxPrinter
* SfxPrinter::Create( SvStream
& rStream
, SfxItemSet
* pOptions
)
67 Creates a <SfxPrinter> from the stream. Loading is really only a jobsetup.
68 If such a printer is not available on the system, then the original is
69 marked as the original Job-setup and a comparable printer is selected from
72 The 'pOptions' are taken over in the generated SfxPrinter, the return
73 value belongs to the caller.
78 JobSetup aFileJobSetup
;
79 rStream
>> aFileJobSetup
;
82 SfxPrinter
*pPrinter
= new SfxPrinter( pOptions
, aFileJobSetup
);
86 //--------------------------------------------------------------------
88 SvStream
& SfxPrinter::Store( SvStream
& rStream
) const
92 Saves the used JobSetup of <SfxPrinter>s.
96 return ( rStream
<< GetJobSetup() );
99 //--------------------------------------------------------------------
101 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
) :
105 This constructor creates a default printer.
108 pOptions( pTheOptions
),
112 pImpl
= new SfxPrinter_Impl
;
115 //--------------------------------------------------------------------
117 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
,
118 const JobSetup
& rTheOrigJobSetup
) :
120 Printer ( rTheOrigJobSetup
.GetPrinterName() ),
121 pOptions ( pTheOptions
)
124 pImpl
= new SfxPrinter_Impl
;
125 bKnown
= GetName() == rTheOrigJobSetup
.GetPrinterName();
128 SetJobSetup( rTheOrigJobSetup
);
131 //--------------------------------------------------------------------
133 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
,
134 const String
& rPrinterName
) :
136 Printer ( rPrinterName
),
137 pOptions ( pTheOptions
),
138 bKnown ( String( GetName() ) == rPrinterName
)
141 pImpl
= new SfxPrinter_Impl
;
144 //--------------------------------------------------------------------
146 SfxPrinter::SfxPrinter( const SfxPrinter
& rPrinter
) :
148 Printer ( rPrinter
.GetName() ),
149 pOptions( rPrinter
.GetOptions().Clone() ),
150 bKnown ( rPrinter
.IsKnown() )
152 SetJobSetup( rPrinter
.GetJobSetup() );
153 SetPrinterProps( &rPrinter
);
154 SetMapMode( rPrinter
.GetMapMode() );
156 pImpl
= new SfxPrinter_Impl
;
157 pImpl
->mbAll
= rPrinter
.pImpl
->mbAll
;
158 pImpl
->mbSelection
= rPrinter
.pImpl
->mbSelection
;
159 pImpl
->mbFromTo
= rPrinter
.pImpl
->mbFromTo
;
160 pImpl
->mbRange
= rPrinter
.pImpl
->mbRange
;
163 //--------------------------------------------------------------------
165 SfxPrinter
* SfxPrinter::Clone() const
167 if ( IsDefPrinter() )
169 SfxPrinter
*pNewPrinter
;
170 pNewPrinter
= new SfxPrinter( GetOptions().Clone() );
171 pNewPrinter
->SetJobSetup( GetJobSetup() );
172 pNewPrinter
->SetPrinterProps( this );
173 pNewPrinter
->SetMapMode( GetMapMode() );
174 pNewPrinter
->pImpl
->mbAll
= pImpl
->mbAll
;
175 pNewPrinter
->pImpl
->mbSelection
=pImpl
->mbSelection
;
176 pNewPrinter
->pImpl
->mbFromTo
= pImpl
->mbFromTo
;
177 pNewPrinter
->pImpl
->mbRange
=pImpl
->mbRange
;
181 return new SfxPrinter( *this );
184 //--------------------------------------------------------------------
186 SfxPrinter::~SfxPrinter()
192 //--------------------------------------------------------------------
194 void SfxPrinter::SetOptions( const SfxItemSet
&rNewOptions
)
196 pOptions
->Set(rNewOptions
);
199 //--------------------------------------------------------------------
201 SfxPrintOptionsDialog::SfxPrintOptionsDialog(Window
*pParent
,
202 SfxViewShell
*pViewShell
,
203 const SfxItemSet
*pSet
)
205 : ModalDialog(pParent
, "PrinterOptionsDialog",
206 "sfx/ui/printeroptionsdialog.ui")
207 , pDlgImpl(new SfxPrintOptDlg_Impl
)
208 , pViewSh(pViewShell
)
209 , pOptions(pSet
->Clone())
211 VclContainer
*pVBox
= get_content_area();
214 pPage
= pViewSh
->CreatePrintOptionsPage(pVBox
, *pOptions
);
215 DBG_ASSERT( pPage
, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
218 pPage
->Reset( *pOptions
);
219 SetHelpId( pPage
->GetHelpId() );
224 //--------------------------------------------------------------------
226 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
233 //--------------------------------------------------------------------
235 short SfxPrintOptionsDialog::Execute()
240 short nRet
= ModalDialog::Execute();
241 if ( nRet
== RET_OK
)
242 pPage
->FillItemSet( *pOptions
);
244 pPage
->Reset( *pOptions
);
248 //--------------------------------------------------------------------
250 long SfxPrintOptionsDialog::Notify( NotifyEvent
& rNEvt
)
252 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
254 if ( rNEvt
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1
&& pDlgImpl
->mbHelpDisabled
)
255 return 1; // help disabled -> <F1> does nothing
258 return ModalDialog::Notify( rNEvt
);
261 //--------------------------------------------------------------------
263 void SfxPrintOptionsDialog::DisableHelp()
265 pDlgImpl
->mbHelpDisabled
= sal_True
;
267 get
<HelpButton
>("help")->Disable();
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */