1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "docsignature.hxx"
22 #include <basic/sbx.hxx>
23 #include "basicrenderable.hxx"
25 #include <com/sun/star/frame/XTitle.hpp>
27 #include <basidesh.hxx>
28 #include <basidesh.hrc>
29 #include <baside2.hxx>
32 #include <vcl/texteng.hxx>
33 #include <vcl/textview.hxx>
34 #include <vcl/xtextedt.hxx>
35 #include <tools/diagnose_ex.h>
36 #include <sfx2/childwin.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/sfxdefs.hxx>
39 #include <sfx2/signaturestate.hxx>
40 #include <com/sun/star/container/XNameContainer.hpp>
41 #include <com/sun/star/container/XNamed.hpp>
42 #include <com/sun/star/lang/XServiceInfo.hpp>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
50 Reference
< view::XRenderable
> Shell::GetRenderable()
52 return Reference
<view::XRenderable
>( new Renderable(pCurWin
) );
55 sal_Bool
Shell::HasSelection( sal_Bool
/* bText */ ) const
57 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
))
59 TextView
* pEditView
= pMCurWin
->GetEditView();
60 if ( pEditView
&& pEditView
->HasSelection() )
66 String
Shell::GetSelectionText( sal_Bool bWholeWord
)
69 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
))
71 if (TextView
* pEditView
= pMCurWin
->GetEditView())
73 if ( bWholeWord
&& !pEditView
->HasSelection() )
75 aText
= pEditView
->GetTextEngine()->GetWord( pEditView
->GetSelection().GetEnd() );
79 TextSelection aSel
= pEditView
->GetSelection();
80 if ( !bWholeWord
|| ( aSel
.GetStart().GetPara() == aSel
.GetEnd().GetPara() ) )
81 aText
= pEditView
->GetSelected();
88 SfxPrinter
* Shell::GetPrinter( sal_Bool bCreate
)
92 DocShell
* pDocShell
= (DocShell
*)GetViewFrame()->GetObjectShell();
93 DBG_ASSERT( pDocShell
, "DocShell ?!" );
94 return pDocShell
->GetPrinter( bCreate
);
99 sal_uInt16
Shell::SetPrinter( SfxPrinter
*pNewPrinter
, sal_uInt16 nDiffFlags
, bool )
102 DocShell
* pDocShell
= (DocShell
*)GetViewFrame()->GetObjectShell();
103 DBG_ASSERT( pDocShell
, "DocShell ?!" );
104 pDocShell
->SetPrinter( pNewPrinter
);
108 void Shell::SetMDITitle()
110 OUStringBuffer aTitleBuf
;
111 if ( !m_aCurLibName
.isEmpty() )
113 LibraryLocation eLocation
= m_aCurDocument
.getLibraryLocation( m_aCurLibName
);
114 aTitleBuf
= m_aCurDocument
.getTitle(eLocation
) + "." + m_aCurLibName
;
117 aTitleBuf
= IDE_RESSTR(RID_STR_ALL
) ;
119 DocumentSignature
aCurSignature( m_aCurDocument
);
120 if ( aCurSignature
.getScriptingSignatureState() == SIGNATURESTATE_SIGNATURES_OK
)
122 aTitleBuf
= aTitleBuf
+ " " + IDE_RESSTR(RID_STR_SIGNED
) + " ";
124 OUString
aTitle(aTitleBuf
.makeStringAndClear());
126 SfxViewFrame
* pViewFrame
= GetViewFrame();
129 SfxObjectShell
* pShell
= pViewFrame
->GetObjectShell();
130 if ( pShell
&& !pShell
->GetTitle( SFX_TITLE_CAPTION
).Equals(aTitle
) )
132 pShell
->SetTitle( aTitle
);
133 pShell
->SetModified(false);
136 css::uno::Reference
< css::frame::XController
> xController
= GetController ();
137 css::uno::Reference
< css::frame::XTitle
> xTitle (xController
, css::uno::UNO_QUERY
);
139 xTitle
->setTitle (aTitle
);
143 ModulWindow
* Shell::CreateBasWin( const ScriptDocument
& rDocument
, const OUString
& rLibName
, const OUString
& rModName
)
145 bCreatingWindow
= true;
148 ModulWindow
* pWin
= 0;
150 OUString
aLibName( rLibName
);
151 OUString
aModName( rModName
);
153 if ( aLibName
.isEmpty() )
154 aLibName
= "Standard" ;
156 uno::Reference
< container::XNameContainer
> xLib
= rDocument
.getOrCreateLibrary( E_SCRIPTS
, aLibName
);
158 if ( aModName
.isEmpty() )
159 aModName
= rDocument
.createObjectName( E_SCRIPTS
, aLibName
);
161 // maybe there's an suspended one?
162 pWin
= FindBasWin( rDocument
, aLibName
, aModName
, false, true );
167 bool bSuccess
= false;
168 if ( rDocument
.hasModule( aLibName
, aModName
) )
169 bSuccess
= rDocument
.getModule( aLibName
, aModName
, aModule
);
171 bSuccess
= rDocument
.createModule( aLibName
, aModName
, true, aModule
);
175 pWin
= FindBasWin( rDocument
, aLibName
, aModName
, false, true );
180 pModulLayout
.reset(new ModulWindowLayout(&GetViewFrame()->GetWindow(), aObjectCatalog
));
181 pWin
= new ModulWindow(pModulLayout
.get(), rDocument
, aLibName
, aModName
, aModule
);
182 nKey
= InsertWindowInTable( pWin
);
184 else // we've gotten called recursively ( via listener from createModule above ), get outta here
190 pWin
->SetStatus( pWin
->GetStatus() & ~BASWIN_SUSPENDED
);
191 nKey
= GetWindowId( pWin
);
192 DBG_ASSERT( nKey
, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
194 if( nKey
&& xLib
.is() && rDocument
.isInVBAMode() )
196 // display a nice friendly name in the ObjectModule tab,
197 // combining the objectname and module name, e.g. Sheet1 ( Financials )
199 ModuleInfoHelper::getObjectName( xLib
, rModName
, sObjName
);
200 if( !sObjName
.isEmpty() )
202 OUStringBuffer
aModNameBuf(aModName
);
203 aModNameBuf
.append(' ');
204 aModNameBuf
.append('(');
205 aModNameBuf
.append(sObjName
);
206 aModNameBuf
.append(')');
207 aModName
= aModNameBuf
.makeStringAndClear();
210 pTabBar
->InsertPage( (sal_uInt16
)nKey
, aModName
);
214 pWin
->GrabScrollBars( &aHScrollBar
, &aVScrollBar
);
216 SetCurWindow( pWin
, false, false );
218 bCreatingWindow
= false;
222 ModulWindow
* Shell::FindBasWin (
223 ScriptDocument
const& rDocument
,
224 OUString
const& rLibName
, OUString
const& rName
,
225 bool bCreateIfNotExist
, bool bFindSuspended
228 if (BaseWindow
* pWin
= FindWindow(rDocument
, rLibName
, rName
, TYPE_MODULE
, bFindSuspended
))
229 return static_cast<ModulWindow
*>(pWin
);
230 return bCreateIfNotExist
? CreateBasWin(rDocument
, rLibName
, rName
) : 0;
235 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
))
236 pMCurWin
->FrameWindowMoved();
239 void Shell::ShowCursor( bool bOn
)
241 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
))
242 pMCurWin
->ShowCursor(bOn
);
245 // only if basic window above:
246 void Shell::ExecuteBasic( SfxRequest
& rReq
)
248 if (dynamic_cast<ModulWindow
*>(pCurWin
))
250 pCurWin
->ExecuteCommand( rReq
);
256 } // namespace basctl
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */