1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdmod.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <svtools/pathoptions.hxx>
34 #include <svtools/languageoptions.hxx>
35 #ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX
36 #include <unotools/ucbstreamhelper.hxx>
38 #include <tools/urlobj.hxx>
39 #include <vcl/virdev.hxx>
40 #include <sfx2/app.hxx>
41 #include <vcl/status.hxx>
42 #include <svtools/intitem.hxx>
43 #include <sfx2/msg.hxx>
44 #include <sfx2/objface.hxx>
45 #include <sfx2/printer.hxx>
46 #include <svx/pszctrl.hxx>
47 #include <svx/zoomctrl.hxx>
48 #include <svx/modctrl.hxx>
49 #include <svtools/zforlist.hxx>
50 #include <comphelper/processfactory.hxx>
51 #include <svtools/ehdl.hxx>
53 #include <svx/svxids.hrc>
54 #include <sfx2/srchitem.hxx>
55 #include <svx/svxerr.hxx>
57 #include <svx/xmlsecctrl.hxx>
60 #define _SD_DLL // fuer SD_MOD()
61 #include "sderror.hxx"
64 #include "sdresid.hxx"
65 #include "optsitem.hxx"
66 #include "DrawDocShell.hxx"
67 #include "drawdoc.hxx"
70 #include "strings.hrc"
71 #include "res_bmp.hrc"
73 #include "tools/SdGlobalResourceContainer.hxx"
75 TYPEINIT1( SdModule
, SfxModule
);
78 #include "sdslots.hxx"
81 SFX_IMPL_INTERFACE(SdModule
, SfxModule
, SdResId(STR_APPLICATIONOBJECTBAR
))
83 SFX_STATUSBAR_REGISTRATION(SdResId(RID_DRAW_STATUSBAR
));
86 /*************************************************************************
90 \************************************************************************/
92 SdModule::SdModule(SfxObjectFactory
* pFact1
, SfxObjectFactory
* pFact2
)
93 : SfxModule( SfxApplication::CreateResManager("sd"), FALSE
,
94 pFact1
, pFact2
, NULL
),
97 pTransferSelection(NULL
),
98 pImpressOptions(NULL
),
101 pNumberFormatter( NULL
),
103 mpResourceContainer(new ::sd::SdGlobalResourceContainer())
105 SetName( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarDraw" ) ) ); // Nicht uebersetzen!
106 pSearchItem
= new SvxSearchItem(SID_SEARCH_ITEM
);
107 pSearchItem
->SetAppFlag(SVX_SEARCHAPP_DRAW
);
108 StartListening( *SFX_APP() );
109 SvxErrorHandler::Get();
110 mpErrorHdl
= new SfxErrorHandler( RID_SD_ERRHDL
,
115 // Create a new ref device and (by calling SetReferenceDevice())
116 // set its resolution to 600 DPI. This leads to a visually better
117 // formatting of text in small sizes (6 point and below.)
118 VirtualDevice
* pDevice
= new VirtualDevice
;
119 mpVirtualRefDevice
= pDevice
;
120 pDevice
->SetMapMode( MAP_100TH_MM
);
121 pDevice
->SetReferenceDevice ( VirtualDevice::REFDEV_MODE06
);
126 /*************************************************************************
130 \************************************************************************/
132 SdModule::~SdModule()
134 // Mark the module in the global AppData structure as deleted.
135 SdModule
** ppShellPointer
= (SdModule
**)GetAppData(SHL_DRAW
);
136 if (ppShellPointer
!= NULL
)
137 (*ppShellPointer
) = NULL
;
141 if( pNumberFormatter
)
142 delete pNumberFormatter
;
144 ::sd::DrawDocShell
* pDocShell
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current());
147 ::sd::ViewShell
* pViewShell
= pDocShell
->GetViewShell();
150 // Removing our event listener
151 Application::RemoveEventListener( LINK( this, SdModule
, EventListenerHdl
) );
156 delete static_cast< VirtualDevice
* >( mpVirtualRefDevice
);
160 /*************************************************************************
162 |* Statusbar erzeugen
164 \************************************************************************/
166 #define AUTOSIZE_WIDTH 180
167 #define TEXT_WIDTH(s) rStatusBar.GetTextWidth((s))
169 void SdModule::FillStatusBar(StatusBar
& rStatusBar
)
172 rStatusBar
.InsertItem( SID_CONTEXT
, TEXT_WIDTH( String().Fill( 30, 'x' ) ), // vorher 52
173 SIB_IN
| SIB_LEFT
| SIB_AUTOSIZE
);
175 // Groesse und Position
176 rStatusBar
.InsertItem( SID_ATTR_SIZE
, SvxPosSizeStatusBarControl::GetDefItemWidth(rStatusBar
), // vorher 42
177 SIB_IN
| SIB_USERDRAW
);
178 // SIB_AUTOSIZE | SIB_LEFT | SIB_OWNERDRAW );
181 rStatusBar
.InsertItem( SID_ATTR_ZOOM
, SvxZoomStatusBarControl::GetDefItemWidth(rStatusBar
), SIB_IN
| SIB_CENTER
);
183 // Einfuege- / Uberschreibmodus
184 rStatusBar.InsertItem( SID_ATTR_INSERT, TEXT_WIDTH( "EINFG" ),
185 SIB_IN | SIB_CENTER );
188 rStatusBar.InsertItem( SID_STATUS_SELMODE, TEXT_WIDTH( "ERG" ),
189 SIB_IN | SIB_CENTER );
191 // Dokument geaendert
192 rStatusBar
.InsertItem( SID_DOC_MODIFIED
, SvxModifyControl::GetDefItemWidth(rStatusBar
) );
195 rStatusBar
.InsertItem( SID_SIGNATURE
, XmlSecStatusBarControl::GetDefItemWidth( rStatusBar
), SIB_USERDRAW
);
196 rStatusBar
.SetHelpId(SID_SIGNATURE
, SID_SIGNATURE
);
201 rStatusBar
.InsertItem( SID_STATUS_PAGE
, TEXT_WIDTH( String().Fill( 24, 'X' ) ),
204 // Praesentationslayout
205 rStatusBar
.InsertItem( SID_STATUS_LAYOUT
, TEXT_WIDTH( String().Fill( 10, 'X' ) ),
206 SIB_IN
| SIB_LEFT
| SIB_AUTOSIZE
);
211 /*************************************************************************
215 \************************************************************************/
217 void SdModule::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
219 if( rHint
.ISA( SfxSimpleHint
) &&
220 ( (SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_DEINITIALIZING
)
222 delete pImpressOptions
, pImpressOptions
= NULL
;
223 delete pDrawOptions
, pDrawOptions
= NULL
;
227 /*************************************************************************
229 |* Optionen zurueckgeben
231 \************************************************************************/
233 SdOptions
* SdModule::GetSdOptions(DocumentType eDocType
)
235 SdOptions
* pOptions
= NULL
;
237 if (eDocType
== DOCUMENT_TYPE_DRAW
)
240 pDrawOptions
= new SdOptions( SDCFG_DRAW
);
242 pOptions
= pDrawOptions
;
244 else if (eDocType
== DOCUMENT_TYPE_IMPRESS
)
246 if (!pImpressOptions
)
247 pImpressOptions
= new SdOptions( SDCFG_IMPRESS
);
249 pOptions
= pImpressOptions
;
253 UINT16 nMetric
= pOptions
->GetMetric();
255 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
256 SdDrawDocument
* pDoc
= NULL
;
258 pDoc
= pDocSh
->GetDoc();
260 if( nMetric
!= 0xffff && pDoc
&& eDocType
== pDoc
->GetDocumentType() )
261 PutItem( SfxUInt16Item( SID_ATTR_METRIC
, nMetric
) );
267 /*************************************************************************
269 |* Optionen-Stream fuer interne Options oeffnen und zurueckgeben;
270 |* falls der Stream zum Lesen geoeffnet wird, aber noch nicht
271 |* angelegt wurde, wird ein 'leeres' RefObject zurueckgegeben
273 \************************************************************************/
275 SvStorageStreamRef
SdModule::GetOptionStream( const String
& rOptionName
,
276 SdOptionStreamMode eMode
)
278 ::sd::DrawDocShell
* pDocSh
= PTR_CAST(::sd::DrawDocShell
, SfxObjectShell::Current() );
279 SvStorageStreamRef xStm
;
283 DocumentType eType
= pDocSh
->GetDoc()->GetDocumentType();
286 if( !xOptionStorage
.Is() )
288 INetURLObject
aURL( SvtPathOptions().GetUserConfigPath() );
290 aURL
.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "drawing.cfg" ) ) );
292 SvStream
* pStm
= ::utl::UcbStreamHelper::CreateStream( aURL
.GetMainURL( INetURLObject::NO_DECODE
), STREAM_READWRITE
);
295 xOptionStorage
= new SvStorage( pStm
, TRUE
);
298 if( DOCUMENT_TYPE_DRAW
== eType
)
299 aStmName
.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Draw_" ) );
301 aStmName
.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Impress_" ) );
303 aStmName
+= rOptionName
;
305 if( SD_OPTION_STORE
== eMode
|| xOptionStorage
->IsContained( aStmName
) )
306 xStm
= xOptionStorage
->OpenSotStream( aStmName
);
312 /*************************************************************************
314 \************************************************************************/
316 SvNumberFormatter
* SdModule::GetNumberFormatter()
318 if( !pNumberFormatter
)
319 pNumberFormatter
= new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), LANGUAGE_SYSTEM
);
321 return pNumberFormatter
;
324 /*************************************************************************
326 \************************************************************************/
328 OutputDevice
* SdModule::GetVirtualRefDevice (void)
330 return mpVirtualRefDevice
;
333 /** This method is deprecated and only an alias to
334 <member>GetVirtualRefDevice()</member>. The given argument is ignored.
336 OutputDevice
* SdModule::GetRefDevice (::sd::DrawDocShell
& )
338 return GetVirtualRefDevice();
342 /*************************************************************************
344 \************************************************************************/
346 ::com::sun::star::text::WritingMode
SdModule::GetDefaultWritingMode() const
349 const SvtLanguageOptions aLanguageOptions;
351 return( aLanguageOptions.IsCTLFontEnabled() ?
352 ::com::sun::star::text::WritingMode_RL_TB :
353 ::com::sun::star::text::WritingMode_LR_TB );
355 return ::com::sun::star::text::WritingMode_LR_TB
;