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
53 struct SfxPrintOptDlg_Impl
57 SfxPrintOptDlg_Impl() :
58 mbHelpDisabled ( false ) {}
61 // class SfxPrinter ------------------------------------------------------
63 VclPtr
<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 ReadJobSetup( rStream
, aFileJobSetup
);
82 VclPtr
<SfxPrinter
> pPrinter
= VclPtr
<SfxPrinter
>::Create( pOptions
, aFileJobSetup
);
88 SvStream
& SfxPrinter::Store( SvStream
& rStream
) const
92 Saves the used JobSetup of <SfxPrinter>s.
96 return WriteJobSetup( rStream
, GetJobSetup() );
101 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
) :
105 This constructor creates a default printer.
108 pOptions( pTheOptions
),
113 pImpl
= new SfxPrinter_Impl
;
118 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
,
119 const JobSetup
& rTheOrigJobSetup
) :
121 Printer ( rTheOrigJobSetup
.GetPrinterName() ),
122 pOptions ( pTheOptions
)
126 pImpl
= new SfxPrinter_Impl
;
127 bKnown
= GetName() == rTheOrigJobSetup
.GetPrinterName();
130 SetJobSetup( rTheOrigJobSetup
);
135 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
,
136 const OUString
& rPrinterName
) :
138 Printer ( rPrinterName
),
139 pOptions ( pTheOptions
),
140 bKnown ( GetName() == rPrinterName
)
144 pImpl
= new SfxPrinter_Impl
;
149 SfxPrinter::SfxPrinter( const SfxPrinter
& rPrinter
) :
151 Printer ( rPrinter
.GetName() ),
152 pOptions( rPrinter
.GetOptions().Clone() ),
153 bKnown ( rPrinter
.IsKnown() )
156 SetJobSetup( rPrinter
.GetJobSetup() );
157 SetPrinterProps( &rPrinter
);
158 SetMapMode( rPrinter
.GetMapMode() );
160 pImpl
= new SfxPrinter_Impl
;
161 pImpl
->mbAll
= rPrinter
.pImpl
->mbAll
;
162 pImpl
->mbSelection
= rPrinter
.pImpl
->mbSelection
;
163 pImpl
->mbFromTo
= rPrinter
.pImpl
->mbFromTo
;
164 pImpl
->mbRange
= rPrinter
.pImpl
->mbRange
;
169 VclPtr
<SfxPrinter
> SfxPrinter::Clone() const
171 if ( IsDefPrinter() )
173 VclPtr
<SfxPrinter
> pNewPrinter
= VclPtr
<SfxPrinter
>::Create( GetOptions().Clone() );
174 pNewPrinter
->SetJobSetup( GetJobSetup() );
175 pNewPrinter
->SetPrinterProps( this );
176 pNewPrinter
->SetMapMode( GetMapMode() );
177 pNewPrinter
->pImpl
->mbAll
= pImpl
->mbAll
;
178 pNewPrinter
->pImpl
->mbSelection
=pImpl
->mbSelection
;
179 pNewPrinter
->pImpl
->mbFromTo
= pImpl
->mbFromTo
;
180 pNewPrinter
->pImpl
->mbRange
=pImpl
->mbRange
;
184 return VclPtr
<SfxPrinter
>::Create( *this );
189 SfxPrinter::~SfxPrinter()
194 void SfxPrinter::dispose()
203 void SfxPrinter::SetOptions( const SfxItemSet
&rNewOptions
)
205 pOptions
->Set(rNewOptions
);
210 SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window
*pParent
,
211 SfxViewShell
*pViewShell
,
212 const SfxItemSet
*pSet
)
214 : ModalDialog(pParent
, "PrinterOptionsDialog",
215 "sfx/ui/printeroptionsdialog.ui")
216 , pDlgImpl(new SfxPrintOptDlg_Impl
)
217 , pViewSh(pViewShell
)
218 , pOptions(pSet
->Clone())
220 VclContainer
*pVBox
= get_content_area();
223 pPage
.reset(pViewSh
->CreatePrintOptionsPage(pVBox
, *pOptions
));
224 DBG_ASSERT( pPage
, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
227 pPage
->Reset( pOptions
);
228 SetHelpId( pPage
->GetHelpId() );
235 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
240 void SfxPrintOptionsDialog::dispose()
243 pPage
.disposeAndClear();
245 ModalDialog::dispose();
250 short SfxPrintOptionsDialog::Execute()
255 short nRet
= ModalDialog::Execute();
256 if ( nRet
== RET_OK
)
257 pPage
->FillItemSet( pOptions
);
259 pPage
->Reset( pOptions
);
265 bool SfxPrintOptionsDialog::Notify( NotifyEvent
& rNEvt
)
267 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
269 if ( rNEvt
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1
&& pDlgImpl
->mbHelpDisabled
)
270 return true; // help disabled -> <F1> does nothing
273 return ModalDialog::Notify( rNEvt
);
278 void SfxPrintOptionsDialog::DisableHelp()
280 pDlgImpl
->mbHelpDisabled
= true;
282 get
<HelpButton
>("help")->Disable();
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */