bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / app / sdmod.cxx
blob8b8f78a0b08eb505389e662aa1f57c00db4e7a59
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 <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"
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"
63 SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
65 SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR));
68 // Ctor
69 SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
70 : SfxModule( SfxApplication::CreateResManager("sd"), sal_False,
71 pFact1, pFact2, NULL ),
72 pTransferClip(NULL),
73 pTransferDrag(NULL),
74 pTransferSelection(NULL),
75 pImpressOptions(NULL),
76 pDrawOptions(NULL),
77 pSearchItem(NULL),
78 pNumberFormatter( NULL ),
79 bWaterCan(sal_False),
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,
88 ERRCODE_AREA_SD,
89 ERRCODE_AREA_SD_END,
90 GetResMgr() );
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 );
101 // Dtor
102 SdModule::~SdModule()
104 delete pSearchItem;
106 if( pNumberFormatter )
107 delete pNumberFormatter;
109 ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
110 if( pDocShell )
112 ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
113 if (pViewShell)
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;
127 delete mpErrorHdl;
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;
142 /// Return options
143 SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
145 SdOptions* pOptions = NULL;
147 if (eDocType == DOCUMENT_TYPE_DRAW)
149 if (!pDrawOptions)
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;
161 if( pOptions )
163 sal_uInt16 nMetric = pOptions->GetMetric();
165 ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
166 SdDrawDocument* pDoc = NULL;
167 if (pDocSh)
168 pDoc = pDocSh->GetDoc();
170 if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
171 PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
174 return(pOptions);
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;
188 if( pDocSh )
190 DocumentType eType = pDocSh->GetDoc()->GetDocumentType();
191 String aStmName;
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 );
201 if( pStm )
202 xOptionStorage = new SvStorage( pStm, sal_True );
205 if( DOCUMENT_TYPE_DRAW == eType )
206 aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
207 else
208 aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
210 aStmName += rOptionName;
212 if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
213 xStm = xOptionStorage->OpenSotStream( aStmName );
216 return xStm;
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: */