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 <unotools/pathoptions.hxx>
21 #include <svl/languageoptions.hxx>
22 #include <unotools/ucbstreamhelper.hxx>
23 #include <tools/urlobj.hxx>
24 #include <vcl/virdev.hxx>
25 #include <sfx2/app.hxx>
26 #include <vcl/status.hxx>
27 #include <svl/intitem.hxx>
28 #include <sfx2/msg.hxx>
29 #include <sfx2/objface.hxx>
30 #include <sfx2/printer.hxx>
31 #include <svx/pszctrl.hxx>
32 #include <svx/zoomctrl.hxx>
33 #include <svx/modctrl.hxx>
34 #include <svl/zforlist.hxx>
35 #include <comphelper/processfactory.hxx>
36 #include <svtools/ehdl.hxx>
38 #include <svx/svxids.hrc>
39 #include <svl/srchitem.hxx>
40 #include <svx/svxerr.hxx>
42 #include <svx/xmlsecctrl.hxx>
44 #include "sderror.hxx"
46 #include "sdresid.hxx"
47 #include "optsitem.hxx"
48 #include "DrawDocShell.hxx"
49 #include "drawdoc.hxx"
52 #include "strings.hrc"
53 #include "res_bmp.hrc"
55 #include "tools/SdGlobalResourceContainer.hxx"
57 TYPEINIT1( SdModule
, SfxModule
);
60 #include "sdslots.hxx"
63 SFX_IMPL_INTERFACE(SdModule
, SfxModule
, SdResId(STR_APPLICATIONOBJECTBAR
))
65 SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR
));
69 SdModule::SdModule(SfxObjectFactory
* pFact1
, SfxObjectFactory
* pFact2
)
70 : SfxModule( SfxApplication::CreateResManager("sd"), sal_False
,
71 pFact1
, pFact2
, NULL
),
74 pTransferSelection(NULL
),
75 pImpressOptions(NULL
),
78 pNumberFormatter( NULL
),
80 mpResourceContainer(new ::sd::SdGlobalResourceContainer())
82 SetName( OUString( "StarDraw" ) ); // Do not translate!
83 pSearchItem
= new SvxSearchItem(SID_SEARCH_ITEM
);
84 pSearchItem
->SetAppFlag(SVX_SEARCHAPP_DRAW
);
85 StartListening( *SFX_APP() );
86 SvxErrorHandler::ensure();
87 mpErrorHdl
= new SfxErrorHandler( RID_SD_ERRHDL
,
92 // Create a new ref device and (by calling SetReferenceDevice())
93 // set its resolution to 600 DPI. This leads to a visually better
94 // formatting of text in small sizes (6 point and below.)
95 VirtualDevice
* pDevice
= new VirtualDevice
;
96 mpVirtualRefDevice
= pDevice
;
97 pDevice
->SetMapMode( MAP_100TH_MM
);
98 pDevice
->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06
);
102 SdModule::~SdModule()
106 if( pNumberFormatter
)
107 delete pNumberFormatter
;
109 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
112 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
115 // Removing our event listener
116 Application::RemoveEventListener( LINK( this, SdModule
, EventListenerHdl
) );
120 mpResourceContainer
.reset();
122 // Mark the module in the global AppData structure as deleted.
123 SdModule
** ppShellPointer
= (SdModule
**)GetAppData(SHL_DRAW
);
124 if (ppShellPointer
!= NULL
)
125 (*ppShellPointer
) = NULL
;
128 delete static_cast< VirtualDevice
* >( mpVirtualRefDevice
);
131 /// get notifications
132 void SdModule::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
134 if( rHint
.ISA( SfxSimpleHint
) &&
135 ( (SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_DEINITIALIZING
)
137 delete pImpressOptions
, pImpressOptions
= NULL
;
138 delete pDrawOptions
, pDrawOptions
= NULL
;
143 SdOptions
* SdModule::GetSdOptions(DocumentType eDocType
)
145 SdOptions
* pOptions
= NULL
;
147 if (eDocType
== DOCUMENT_TYPE_DRAW
)
150 pDrawOptions
= new SdOptions( SDCFG_DRAW
);
152 pOptions
= pDrawOptions
;
154 else if (eDocType
== DOCUMENT_TYPE_IMPRESS
)
156 if (!pImpressOptions
)
157 pImpressOptions
= new SdOptions( SDCFG_IMPRESS
);
159 pOptions
= pImpressOptions
;
163 sal_uInt16 nMetric
= pOptions
->GetMetric();
165 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
166 SdDrawDocument
* pDoc
= NULL
;
168 pDoc
= pDocSh
->GetDoc();
170 if( nMetric
!= 0xffff && pDoc
&& eDocType
== pDoc
->GetDocumentType() )
171 PutItem( SfxUInt16Item( SID_ATTR_METRIC
, nMetric
) );
178 * Open and return option stream for internal options;
179 * if the stream is opened for reading but does not exist, an 'empty'
180 * RefObject is returned
182 SvStorageStreamRef
SdModule::GetOptionStream( const String
& rOptionName
,
183 SdOptionStreamMode eMode
)
185 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
186 SvStorageStreamRef xStm
;
190 DocumentType eType
= pDocSh
->GetDoc()->GetDocumentType();
193 if( !xOptionStorage
.Is() )
195 INetURLObject
aURL( SvtPathOptions().GetUserConfigPath() );
197 aURL
.Append( OUString( "drawing.cfg" ) );
199 SvStream
* pStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READWRITE
);
202 xOptionStorage
= new SvStorage( pStm
, sal_True
);
205 if( DOCUMENT_TYPE_DRAW
== eType
)
206 aStmName
.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
208 aStmName
.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
210 aStmName
+= rOptionName
;
212 if( SD_OPTION_STORE
== eMode
|| xOptionStorage
->IsContained( aStmName
) )
213 xStm
= xOptionStorage
->OpenSotStream( aStmName
);
219 SvNumberFormatter
* SdModule::GetNumberFormatter()
221 if( !pNumberFormatter
)
222 pNumberFormatter
= new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM
);
224 return pNumberFormatter
;
227 OutputDevice
* SdModule::GetVirtualRefDevice (void)
229 return mpVirtualRefDevice
;
232 /** This method is deprecated and only an alias to
233 * <member>GetVirtualRefDevice()</member>. The given argument is ignored.
235 OutputDevice
* SdModule::GetRefDevice (::sd::DrawDocShell
& )
237 return GetVirtualRefDevice();
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */