xref: /trunk/main/sd/source/ui/app/sdmod.cxx (revision 5829e3e65d041dae4777b7e48d9eac1549ff4f1a)
15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
225b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
27cdf0e10cSrcweir #include <svl/languageoptions.hxx>
28cdf0e10cSrcweir #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
29cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #include <tools/urlobj.hxx>
32cdf0e10cSrcweir #include <vcl/virdev.hxx>
33cdf0e10cSrcweir #include <sfx2/app.hxx>
34cdf0e10cSrcweir #include <vcl/status.hxx>
35cdf0e10cSrcweir #include <svl/intitem.hxx>
36cdf0e10cSrcweir #include <sfx2/msg.hxx>
37cdf0e10cSrcweir #include <sfx2/objface.hxx>
38cdf0e10cSrcweir #include <sfx2/printer.hxx>
39cdf0e10cSrcweir #include <svx/pszctrl.hxx>
40cdf0e10cSrcweir #include <svx/zoomctrl.hxx>
41cdf0e10cSrcweir #include <svx/modctrl.hxx>
42cdf0e10cSrcweir #include <svl/zforlist.hxx>
43cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
44cdf0e10cSrcweir #include <svtools/ehdl.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <svx/svxids.hrc>
47cdf0e10cSrcweir #include <svl/srchitem.hxx>
48cdf0e10cSrcweir #include <svx/svxerr.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <svx/xmlsecctrl.hxx>
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #define _SD_DLL // fuer SD_MOD()
54cdf0e10cSrcweir #include "sderror.hxx"
55cdf0e10cSrcweir #include "sdmod.hxx"
56cdf0e10cSrcweir #include "sddll.hxx"
57cdf0e10cSrcweir #include "sdresid.hxx"
58cdf0e10cSrcweir #include "optsitem.hxx"
59cdf0e10cSrcweir #include "DrawDocShell.hxx"
60cdf0e10cSrcweir #include "drawdoc.hxx"
61cdf0e10cSrcweir #include "app.hrc"
62cdf0e10cSrcweir #include "glob.hrc"
63cdf0e10cSrcweir #include "strings.hrc"
64cdf0e10cSrcweir #include "res_bmp.hrc"
65cdf0e10cSrcweir #include "cfgids.hxx"
66cdf0e10cSrcweir #include "tools/SdGlobalResourceContainer.hxx"
67cdf0e10cSrcweir 
68cdf0e10cSrcweir TYPEINIT1( SdModule, SfxModule );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir #define SdModule
71cdf0e10cSrcweir #include "sdslots.hxx"
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
SFX_IMPL_INTERFACE(SdModule,SfxModule,SdResId (STR_APPLICATIONOBJECTBAR))74cdf0e10cSrcweir SFX_IMPL_INTERFACE(SdModule, SfxModule, SdResId(STR_APPLICATIONOBJECTBAR))
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR));
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir /*************************************************************************
80cdf0e10cSrcweir |* Ctor
81cdf0e10cSrcweir \************************************************************************/
82cdf0e10cSrcweir 
SdModule(SfxObjectFactory * pFact1,SfxObjectFactory * pFact2)83cdf0e10cSrcweir SdModule::SdModule(SfxObjectFactory* pFact1, SfxObjectFactory* pFact2 )
84cdf0e10cSrcweir :   SfxModule( SfxApplication::CreateResManager("sd"), sal_False,
85cdf0e10cSrcweir                   pFact1, pFact2, NULL ),
86cdf0e10cSrcweir     pTransferClip(NULL),
87cdf0e10cSrcweir     pTransferDrag(NULL),
88cdf0e10cSrcweir     pTransferSelection(NULL),
89cdf0e10cSrcweir     pImpressOptions(NULL),
90cdf0e10cSrcweir     pDrawOptions(NULL),
91cdf0e10cSrcweir     pSearchItem(NULL),
92cdf0e10cSrcweir     pNumberFormatter( NULL ),
93cdf0e10cSrcweir     bWaterCan(sal_False),
94cdf0e10cSrcweir     mpResourceContainer(new ::sd::SdGlobalResourceContainer())
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     SetName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarDraw" ) ) );  // Nicht uebersetzen!
97cdf0e10cSrcweir     pSearchItem = new SvxSearchItem(SID_SEARCH_ITEM);
98cdf0e10cSrcweir     pSearchItem->SetAppFlag(SVX_SEARCHAPP_DRAW);
99cdf0e10cSrcweir     StartListening( *SFX_APP() );
100cdf0e10cSrcweir     SvxErrorHandler::Get();
101cdf0e10cSrcweir     mpErrorHdl = new SfxErrorHandler( RID_SD_ERRHDL,
102cdf0e10cSrcweir                                          ERRCODE_AREA_SD,
103cdf0e10cSrcweir                                          ERRCODE_AREA_SD_END,
104cdf0e10cSrcweir                                          GetResMgr() );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir     // Create a new ref device and (by calling SetReferenceDevice())
107cdf0e10cSrcweir     // set its resolution to 600 DPI. This leads to a visually better
108cdf0e10cSrcweir     // formatting of text in small sizes (6 point and below.)
109cdf0e10cSrcweir     VirtualDevice* pDevice = new VirtualDevice;
110cdf0e10cSrcweir     mpVirtualRefDevice = pDevice;
111cdf0e10cSrcweir     pDevice->SetMapMode( MAP_100TH_MM );
112cdf0e10cSrcweir     pDevice->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06 );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir /*************************************************************************
118cdf0e10cSrcweir |* Dtor
119cdf0e10cSrcweir \************************************************************************/
120cdf0e10cSrcweir 
~SdModule()121cdf0e10cSrcweir SdModule::~SdModule()
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     delete pSearchItem;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     if( pNumberFormatter )
126cdf0e10cSrcweir     delete pNumberFormatter;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     ::sd::DrawDocShell* pDocShell = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current());
129cdf0e10cSrcweir     if( pDocShell )
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
132cdf0e10cSrcweir         if (pViewShell)
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             // Removing our event listener
135cdf0e10cSrcweir             Application::RemoveEventListener( LINK( this, SdModule, EventListenerHdl ) );
136cdf0e10cSrcweir         }
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     mpResourceContainer.reset();
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     // Mark the module in the global AppData structure as deleted.
142cdf0e10cSrcweir     SdModule** ppShellPointer = (SdModule**)GetAppData(SHL_DRAW);
143cdf0e10cSrcweir     if (ppShellPointer != NULL)
144cdf0e10cSrcweir         (*ppShellPointer) = NULL;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     delete mpErrorHdl;
147cdf0e10cSrcweir     delete static_cast< VirtualDevice* >( mpVirtualRefDevice );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 
151cdf0e10cSrcweir /*************************************************************************
152cdf0e10cSrcweir |* get notifications
153cdf0e10cSrcweir \************************************************************************/
154cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)155cdf0e10cSrcweir void SdModule::Notify( SfxBroadcaster&, const SfxHint& rHint )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir     if( rHint.ISA( SfxSimpleHint ) &&
158cdf0e10cSrcweir         ( (SfxSimpleHint&) rHint ).GetId() == SFX_HINT_DEINITIALIZING )
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         delete pImpressOptions, pImpressOptions = NULL;
161cdf0e10cSrcweir         delete pDrawOptions, pDrawOptions = NULL;
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir /*************************************************************************
166*5829e3e6Smseidel |* return options
167cdf0e10cSrcweir \************************************************************************/
168cdf0e10cSrcweir 
GetSdOptions(DocumentType eDocType)169cdf0e10cSrcweir SdOptions* SdModule::GetSdOptions(DocumentType eDocType)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     SdOptions* pOptions = NULL;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     if (eDocType == DOCUMENT_TYPE_DRAW)
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         if (!pDrawOptions)
176cdf0e10cSrcweir             pDrawOptions = new SdOptions( SDCFG_DRAW );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         pOptions = pDrawOptions;
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir     else if (eDocType == DOCUMENT_TYPE_IMPRESS)
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         if (!pImpressOptions)
183cdf0e10cSrcweir             pImpressOptions = new SdOptions( SDCFG_IMPRESS );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         pOptions = pImpressOptions;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir     if( pOptions )
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         sal_uInt16 nMetric = pOptions->GetMetric();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         ::sd::DrawDocShell* pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
192cdf0e10cSrcweir         SdDrawDocument* pDoc = NULL;
193cdf0e10cSrcweir         if (pDocSh)
194cdf0e10cSrcweir             pDoc = pDocSh->GetDoc();
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         if( nMetric != 0xffff && pDoc && eDocType == pDoc->GetDocumentType() )
197cdf0e10cSrcweir             PutItem( SfxUInt16Item( SID_ATTR_METRIC, nMetric ) );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     return(pOptions);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir /*************************************************************************
204cdf0e10cSrcweir |* Optionen-Stream fuer interne Options oeffnen und zurueckgeben;
205cdf0e10cSrcweir |* falls der Stream zum Lesen geoeffnet wird, aber noch nicht
206cdf0e10cSrcweir |* angelegt wurde, wird ein 'leeres' RefObject zurueckgegeben
207cdf0e10cSrcweir \************************************************************************/
208cdf0e10cSrcweir 
GetOptionStream(const String & rOptionName,SdOptionStreamMode eMode)209cdf0e10cSrcweir SvStorageStreamRef SdModule::GetOptionStream( const String& rOptionName,
210cdf0e10cSrcweir                                               SdOptionStreamMode eMode )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     ::sd::DrawDocShell*     pDocSh = PTR_CAST(::sd::DrawDocShell, SfxObjectShell::Current() );
213cdf0e10cSrcweir     SvStorageStreamRef  xStm;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     if( pDocSh )
216cdf0e10cSrcweir     {
217cdf0e10cSrcweir         DocumentType    eType = pDocSh->GetDoc()->GetDocumentType();
218cdf0e10cSrcweir         String          aStmName;
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         if( !xOptionStorage.Is() )
221cdf0e10cSrcweir         {
222cdf0e10cSrcweir             INetURLObject aURL( SvtPathOptions().GetUserConfigPath() );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             aURL.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "drawing.cfg" ) ) );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir             SvStream* pStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READWRITE );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir             if( pStm )
229cdf0e10cSrcweir                 xOptionStorage = new SvStorage( pStm, sal_True );
230cdf0e10cSrcweir         }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         if( DOCUMENT_TYPE_DRAW == eType )
233cdf0e10cSrcweir             aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
234cdf0e10cSrcweir         else
235cdf0e10cSrcweir             aStmName.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir         aStmName += rOptionName;
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         if( SD_OPTION_STORE == eMode || xOptionStorage->IsContained( aStmName ) )
240cdf0e10cSrcweir             xStm = xOptionStorage->OpenSotStream( aStmName );
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     return xStm;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir /*************************************************************************
247cdf0e10cSrcweir |*
248cdf0e10cSrcweir \************************************************************************/
249cdf0e10cSrcweir 
GetNumberFormatter()250cdf0e10cSrcweir SvNumberFormatter* SdModule::GetNumberFormatter()
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     if( !pNumberFormatter )
253cdf0e10cSrcweir         pNumberFormatter = new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), LANGUAGE_SYSTEM );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     return pNumberFormatter;
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir /*************************************************************************
259cdf0e10cSrcweir |*
260cdf0e10cSrcweir \************************************************************************/
261cdf0e10cSrcweir 
GetVirtualRefDevice(void)262cdf0e10cSrcweir OutputDevice* SdModule::GetVirtualRefDevice (void)
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     return mpVirtualRefDevice;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir /** This method is deprecated and only an alias to
268cdf0e10cSrcweir     <member>GetVirtualRefDevice()</member>. The given argument is ignored.
269cdf0e10cSrcweir */
GetRefDevice(::sd::DrawDocShell &)270cdf0e10cSrcweir OutputDevice* SdModule::GetRefDevice (::sd::DrawDocShell& )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     return GetVirtualRefDevice();
273cdf0e10cSrcweir }
274