bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / app / sdmod.cxx
blobd1c4e6f2a49de7635fef08e6666be7f456c49d96
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <vcl/status.hxx>
26 #include <svl/intitem.hxx>
27 #include <sfx2/msg.hxx>
28 #include <sfx2/objface.hxx>
29 #include <sfx2/printer.hxx>
30 #include <sfx2/request.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"
45 #include "sdmod.hxx"
46 #include "sdresid.hxx"
47 #include "optsitem.hxx"
48 #include "DrawDocShell.hxx"
49 #include "drawdoc.hxx"
50 #include "app.hrc"
51 #include "glob.hrc"
52 #include "strings.hrc"
53 #include "res_bmp.hrc"
54 #include "cfgids.hxx"
55 #include "tools/SdGlobalResourceContainer.hxx"
57 TYPEINIT1( SdModule, SfxModule );
59 #define SdModule
60 #include "sdslots.hxx"
62 SFX_IMPL_INTERFACE(SdModule, SfxModule)
64 void SdModule::InitInterface_Impl()
66 GetStaticInterface()->RegisterStatusBar(SdResId(RID_DRAW_STATUSBAR));
69 // Ctor
70 SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
71 : SfxModule( ResMgr::CreateResMgr("sd"), false,
72 pFact1, pFact2, NULL ),
73 pTransferClip(NULL),
74 pTransferDrag(NULL),
75 pTransferSelection(NULL),
76 pImpressOptions(NULL),
77 pDrawOptions(NULL),
78 pSearchItem(NULL),
79 pNumberFormatter( NULL ),
80 bWaterCan(false),
81 mpResourceContainer(new ::sd::SdGlobalResourceContainer()),
82 mbEventListenerAdded(false)
84 SetName( OUString( "StarDraw" ) ); // Do not translate!
85 pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
86 pSearchItem->SetAppFlag(SvxSearchApp::DRAW);
87 StartListening( *SfxGetpApp() );
88 SvxErrorHandler::ensure();
89 mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
90 ERRCODE_AREA_SD,
91 ERRCODE_AREA_SD_END,
92 GetResMgr() );
94 // Create a new ref device and (by calling SetReferenceDevice())
95 // set its resolution to 600 DPI. This leads to a visually better
96 // formatting of text in small sizes (6 point and below.)
97 mpVirtualRefDevice.reset(VclPtr<VirtualDevice>::Create());
98 mpVirtualRefDevice->SetMapMode( MAP_100TH_MM );
99 mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
102 // Dtor
103 SdModule::~SdModule()
105 delete pSearchItem;
106 delete pNumberFormatter;
108 if (mbEventListenerAdded)
110 Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
113 mpResourceContainer.reset();
115 // Mark the module in the global AppData structure as deleted.
116 SdModule** ppShellPointer = reinterpret_cast<SdModule**>(GetAppData(SHL_DRAW));
117 if (ppShellPointer != NULL)
118 (*ppShellPointer) = NULL;
120 delete mpErrorHdl;
121 mpVirtualRefDevice.disposeAndClear();
124 /// get notifications
125 void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
127 const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
128 if( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
130 delete pImpressOptions, pImpressOptions = NULL;
131 delete pDrawOptions, pDrawOptions = NULL;
135 /// Return options
136 SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
138 SdOptions* pOptions = NULL;
140 if (eDocType == DOCUMENT_TYPE_DRAW)
142 if (!pDrawOptions)
143 pDrawOptions = new SdOptions( SDCFG_DRAW );
145 pOptions = pDrawOptions;
147 else if (eDocType == DOCUMENT_TYPE_IMPRESS)
149 if (!pImpressOptions)
150 pImpressOptions = new SdOptions( SDCFG_IMPRESS );
152 pOptions = pImpressOptions;
154 if( pOptions )
156 sal_uInt16 nMetric = pOptions->GetMetric();
158 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
159 SdDrawDocument* pDoc = NULL;
160 if (pDocSh)
161 pDoc = pDocSh->GetDoc();
163 if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
164 PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
167 return pOptions;
171 * Open and return option stream for internal options;
172 * if the stream is opened for reading but does not exist, an 'empty'
173 * RefObject is returned
175 tools::SvRef<SotStorageStream> SdModule::GetOptionStream( const OUString& rOptionName,
176 SdOptionStreamMode eMode )
178 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
179 tools::SvRef<SotStorageStream> xStm;
181 if( pDocSh )
183 DocumentType eType = pDocSh->GetDoc()->GetDocumentType();
185 if( !xOptionStorage.Is() )
187 INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
189 aURL.Append( OUString( "drawing.cfg" ) );
191 SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
193 if( pStm )
194 xOptionStorage = new SotStorage( pStm, true );
197 OUString aStmName;
199 if( DOCUMENT_TYPE_DRAW == eType )
200 aStmName = "Draw_";
201 else
202 aStmName = "Impress_";
204 aStmName += rOptionName;
206 if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
207 xStm = xOptionStorage->OpenSotStream( aStmName );
210 return xStm;
213 SvNumberFormatter* SdModule::GetNumberFormatter()
215 if( !pNumberFormatter )
216 pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM );
218 return pNumberFormatter;
221 /** This method is deprecated and only an alias to
222 * <member>GetVirtualRefDevice()</member>. The given argument is ignored.
224 OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
226 return GetVirtualRefDevice();
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */