Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
37 :
38 : #include <svx/svxids.hrc>
39 : #include <svl/srchitem.hxx>
40 : #include <svx/svxerr.hxx>
41 :
42 : #include <svx/xmlsecctrl.hxx>
43 :
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"
56 :
57 939 : TYPEINIT1( SdModule, SfxModule );
58 :
59 : #define SdModule
60 : #include "sdslots.hxx"
61 :
62 3149 : SFX_IMPL_INTERFACE(SdModule, SfxModule)
63 :
64 21 : void SdModule::InitInterface_Impl()
65 : {
66 21 : GetStaticInterface()->RegisterStatusBar(SdResId(RID_DRAW_STATUSBAR));
67 21 : }
68 :
69 : // Ctor
70 21 : 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 0 : mpResourceContainer(new ::sd::SdGlobalResourceContainer()),
82 21 : mbEventListenerAdded(false)
83 : {
84 21 : SetName( OUString( "StarDraw" ) ); // Do not translate!
85 21 : pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
86 21 : pSearchItem->SetAppFlag(SvxSearchApp::DRAW);
87 21 : StartListening( *SfxGetpApp() );
88 21 : SvxErrorHandler::ensure();
89 : mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
90 : ERRCODE_AREA_SD,
91 : ERRCODE_AREA_SD_END,
92 21 : GetResMgr() );
93 :
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 21 : mpVirtualRefDevice.reset(VclPtr<VirtualDevice>::Create());
98 21 : mpVirtualRefDevice->SetMapMode( MAP_100TH_MM );
99 21 : mpVirtualRefDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
100 21 : }
101 :
102 : // Dtor
103 33 : SdModule::~SdModule()
104 : {
105 11 : delete pSearchItem;
106 11 : delete pNumberFormatter;
107 :
108 11 : if (mbEventListenerAdded)
109 : {
110 4 : Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
111 : }
112 :
113 11 : mpResourceContainer.reset();
114 :
115 : // Mark the module in the global AppData structure as deleted.
116 11 : SdModule** ppShellPointer = reinterpret_cast<SdModule**>(GetAppData(SHL_DRAW));
117 11 : if (ppShellPointer != NULL)
118 11 : (*ppShellPointer) = NULL;
119 :
120 11 : delete mpErrorHdl;
121 11 : mpVirtualRefDevice.disposeAndClear();
122 22 : }
123 :
124 : /// get notifications
125 2701 : void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
126 : {
127 2701 : const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
128 2701 : if( pSimpleHint && pSimpleHint->GetId() == SFX_HINT_DEINITIALIZING )
129 : {
130 11 : delete pImpressOptions, pImpressOptions = NULL;
131 11 : delete pDrawOptions, pDrawOptions = NULL;
132 : }
133 2701 : }
134 :
135 : /// Return options
136 2891 : SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
137 : {
138 2891 : SdOptions* pOptions = NULL;
139 :
140 2891 : if (eDocType == DOCUMENT_TYPE_DRAW)
141 : {
142 930 : if (!pDrawOptions)
143 12 : pDrawOptions = new SdOptions( SDCFG_DRAW );
144 :
145 930 : pOptions = pDrawOptions;
146 : }
147 1961 : else if (eDocType == DOCUMENT_TYPE_IMPRESS)
148 : {
149 1961 : if (!pImpressOptions)
150 14 : pImpressOptions = new SdOptions( SDCFG_IMPRESS );
151 :
152 1961 : pOptions = pImpressOptions;
153 : }
154 2891 : if( pOptions )
155 : {
156 2891 : sal_uInt16 nMetric = pOptions->GetMetric();
157 :
158 2891 : ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
159 2891 : SdDrawDocument* pDoc = NULL;
160 2891 : if (pDocSh)
161 569 : pDoc = pDocSh->GetDoc();
162 :
163 2891 : if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
164 569 : PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
165 : }
166 :
167 2891 : return pOptions;
168 : }
169 :
170 : /**
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
174 : */
175 0 : tools::SvRef<SotStorageStream> SdModule::GetOptionStream( const OUString& rOptionName,
176 : SdOptionStreamMode eMode )
177 : {
178 0 : ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
179 0 : tools::SvRef<SotStorageStream> xStm;
180 :
181 0 : if( pDocSh )
182 : {
183 0 : DocumentType eType = pDocSh->GetDoc()->GetDocumentType();
184 :
185 0 : if( !xOptionStorage.Is() )
186 : {
187 0 : INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
188 :
189 0 : aURL.Append( OUString( "drawing.cfg" ) );
190 :
191 0 : SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
192 :
193 0 : if( pStm )
194 0 : xOptionStorage = new SotStorage( pStm, true );
195 : }
196 :
197 0 : OUString aStmName;
198 :
199 0 : if( DOCUMENT_TYPE_DRAW == eType )
200 0 : aStmName = "Draw_";
201 : else
202 0 : aStmName = "Impress_";
203 :
204 0 : aStmName += rOptionName;
205 :
206 0 : if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
207 0 : xStm = xOptionStorage->OpenSotStream( aStmName );
208 : }
209 :
210 0 : return xStm;
211 : }
212 :
213 53 : SvNumberFormatter* SdModule::GetNumberFormatter()
214 : {
215 53 : if( !pNumberFormatter )
216 4 : pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessComponentContext(), LANGUAGE_SYSTEM );
217 :
218 53 : return pNumberFormatter;
219 : }
220 :
221 : /** This method is deprecated and only an alias to
222 : * <member>GetVirtualRefDevice()</member>. The given argument is ignored.
223 : */
224 284 : OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
225 : {
226 284 : return GetVirtualRefDevice();
227 66 : }
228 :
229 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|