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
);
87 void SfxPrinter::Store( SvStream
& rStream
) const
91 Saves the used JobSetup of <SfxPrinter>s.
95 WriteJobSetup( rStream
, GetJobSetup() );
99 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
) :
103 This constructor creates a default printer.
105 pOptions( pTheOptions
),
106 pImpl( new SfxPrinter_Impl
),
113 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
,
114 const JobSetup
& rTheOrigJobSetup
) :
115 Printer( rTheOrigJobSetup
.GetPrinterName() ),
116 pOptions( pTheOptions
),
117 pImpl( new SfxPrinter_Impl
)
120 bKnown
= GetName() == rTheOrigJobSetup
.GetPrinterName();
123 SetJobSetup( rTheOrigJobSetup
);
127 SfxPrinter::SfxPrinter( SfxItemSet
* pTheOptions
,
128 const OUString
& rPrinterName
) :
129 Printer( rPrinterName
),
130 pOptions( pTheOptions
),
131 pImpl( new SfxPrinter_Impl
),
132 bKnown( GetName() == rPrinterName
)
138 SfxPrinter::SfxPrinter( const SfxPrinter
& rPrinter
) :
140 Printer( rPrinter
.GetName() ),
141 pOptions( rPrinter
.GetOptions().Clone() ),
142 pImpl( new SfxPrinter_Impl
),
143 bKnown( rPrinter
.IsKnown() )
146 SetJobSetup( rPrinter
.GetJobSetup() );
147 SetPrinterProps( &rPrinter
);
148 SetMapMode( rPrinter
.GetMapMode() );
150 pImpl
->mbAll
= rPrinter
.pImpl
->mbAll
;
151 pImpl
->mbSelection
= rPrinter
.pImpl
->mbSelection
;
152 pImpl
->mbFromTo
= rPrinter
.pImpl
->mbFromTo
;
153 pImpl
->mbRange
= rPrinter
.pImpl
->mbRange
;
157 VclPtr
<SfxPrinter
> SfxPrinter::Clone() const
159 if ( IsDefPrinter() )
161 VclPtr
<SfxPrinter
> pNewPrinter
= VclPtr
<SfxPrinter
>::Create( GetOptions().Clone() );
162 pNewPrinter
->SetJobSetup( GetJobSetup() );
163 pNewPrinter
->SetPrinterProps( this );
164 pNewPrinter
->SetMapMode( GetMapMode() );
165 pNewPrinter
->pImpl
->mbAll
= pImpl
->mbAll
;
166 pNewPrinter
->pImpl
->mbSelection
=pImpl
->mbSelection
;
167 pNewPrinter
->pImpl
->mbFromTo
= pImpl
->mbFromTo
;
168 pNewPrinter
->pImpl
->mbRange
=pImpl
->mbRange
;
172 return VclPtr
<SfxPrinter
>::Create( *this );
176 SfxPrinter::~SfxPrinter()
181 void SfxPrinter::dispose()
189 void SfxPrinter::SetOptions( const SfxItemSet
&rNewOptions
)
191 pOptions
->Set(rNewOptions
);
195 SfxPrintOptionsDialog::SfxPrintOptionsDialog(vcl::Window
*pParent
,
196 SfxViewShell
*pViewShell
,
197 const SfxItemSet
*pSet
)
199 : ModalDialog(pParent
, "PrinterOptionsDialog",
200 "sfx/ui/printeroptionsdialog.ui")
201 , pDlgImpl(new SfxPrintOptDlg_Impl
)
202 , pViewSh(pViewShell
)
203 , pOptions(pSet
->Clone())
205 VclContainer
*pVBox
= get_content_area();
208 pPage
.reset(pViewSh
->CreatePrintOptionsPage(pVBox
, *pOptions
));
209 DBG_ASSERT( pPage
, "CreatePrintOptions != SFX_VIEW_HAS_PRINTOPTIONS" );
212 pPage
->Reset( pOptions
);
213 SetHelpId( pPage
->GetHelpId() );
219 SfxPrintOptionsDialog::~SfxPrintOptionsDialog()
224 void SfxPrintOptionsDialog::dispose()
227 pPage
.disposeAndClear();
229 ModalDialog::dispose();
233 short SfxPrintOptionsDialog::Execute()
238 short nRet
= ModalDialog::Execute();
239 if ( nRet
== RET_OK
)
240 pPage
->FillItemSet( pOptions
);
242 pPage
->Reset( pOptions
);
247 bool SfxPrintOptionsDialog::Notify( NotifyEvent
& rNEvt
)
249 if ( rNEvt
.GetType() == MouseNotifyEvent::KEYINPUT
)
251 if ( rNEvt
.GetKeyEvent()->GetKeyCode().GetCode() == KEY_F1
&& pDlgImpl
->mbHelpDisabled
)
252 return true; // help disabled -> <F1> does nothing
255 return ModalDialog::Notify( rNEvt
);
259 void SfxPrintOptionsDialog::DisableHelp()
261 pDlgImpl
->mbHelpDisabled
= true;
263 get
<HelpButton
>("help")->Disable();
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */