bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / basides2.cxx
blobcfe05b3b56dc734aaaa38b974dc5c73d73eca34f
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 "docsignature.hxx"
22 #include "basicrenderable.hxx"
24 #include <com/sun/star/frame/XTitle.hpp>
26 #include <basidesh.hrc>
27 #include <baside2.hxx>
28 #include <basdoc.hxx>
29 #include <vcl/xtextedt.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <sfx2/signaturestate.hxx>
32 #include <com/sun/star/container/XNamed.hpp>
34 namespace basctl
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
40 Reference< view::XRenderable > Shell::GetRenderable()
42 return Reference<view::XRenderable>( new Renderable(pCurWin) );
45 bool Shell::HasSelection( bool /* bText */ ) const
47 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
49 TextView* pEditView = pMCurWin->GetEditView();
50 if ( pEditView && pEditView->HasSelection() )
51 return true;
53 return false;
56 OUString Shell::GetSelectionText( bool bWholeWord )
58 OUString aText;
59 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
61 if (TextView* pEditView = pMCurWin->GetEditView())
63 if ( bWholeWord && !pEditView->HasSelection() )
65 aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() );
67 else
69 TextSelection aSel = pEditView->GetSelection();
70 if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) )
71 aText = pEditView->GetSelected();
75 return aText;
78 SfxPrinter* Shell::GetPrinter( bool bCreate )
80 if ( pCurWin )
82 DocShell* pDocShell = static_cast<DocShell*>(GetViewFrame()->GetObjectShell());
83 DBG_ASSERT( pDocShell, "DocShell ?!" );
84 return pDocShell->GetPrinter( bCreate );
86 return 0;
89 sal_uInt16 Shell::SetPrinter( SfxPrinter *pNewPrinter, SfxPrinterChangeFlags , bool )
91 DocShell* pDocShell = static_cast<DocShell*>(GetViewFrame()->GetObjectShell());
92 DBG_ASSERT( pDocShell, "DocShell ?!" );
93 pDocShell->SetPrinter( pNewPrinter );
94 return 0;
97 void Shell::SetMDITitle()
99 OUStringBuffer aTitleBuf;
100 if ( !m_aCurLibName.isEmpty() )
102 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
103 aTitleBuf = m_aCurDocument.getTitle(eLocation) + "." + m_aCurLibName ;
105 else
106 aTitleBuf = IDE_RESSTR(RID_STR_ALL) ;
108 DocumentSignature aCurSignature( m_aCurDocument );
109 if ( aCurSignature.getScriptingSignatureState() == SignatureState::OK )
111 aTitleBuf = aTitleBuf + " " + IDE_RESSTR(RID_STR_SIGNED) + " ";
113 OUString aTitle(aTitleBuf.makeStringAndClear());
115 SfxViewFrame* pViewFrame = GetViewFrame();
116 if ( pViewFrame )
118 SfxObjectShell* pShell = pViewFrame->GetObjectShell();
119 if ( pShell && pShell->GetTitle( SFX_TITLE_CAPTION ) != aTitle )
121 pShell->SetTitle( aTitle );
122 pShell->SetModified(false);
125 css::uno::Reference< css::frame::XController > xController = GetController ();
126 css::uno::Reference< css::frame::XTitle > xTitle (xController, css::uno::UNO_QUERY);
127 if (xTitle.is ())
128 xTitle->setTitle (aTitle);
132 VclPtr<ModulWindow> Shell::CreateBasWin( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rModName )
134 bCreatingWindow = true;
136 sal_uLong nKey = 0;
137 VclPtr<ModulWindow> pWin;
139 OUString aLibName( rLibName );
140 OUString aModName( rModName );
142 if ( aLibName.isEmpty() )
143 aLibName = "Standard" ;
145 uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
147 if ( aModName.isEmpty() )
148 aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
150 // maybe there's an suspended one?
151 pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
153 if ( !pWin )
155 OUString aModule;
156 bool bSuccess = false;
157 if ( rDocument.hasModule( aLibName, aModName ) )
158 bSuccess = rDocument.getModule( aLibName, aModName, aModule );
159 else
160 bSuccess = rDocument.createModule( aLibName, aModName, true, aModule );
162 if ( bSuccess )
164 pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
165 if( !pWin )
167 // new module window
168 if (!pModulLayout)
169 pModulLayout.reset(VclPtr<ModulWindowLayout>::Create(&GetViewFrame()->GetWindow(), *aObjectCatalog.get()));
170 pWin = VclPtr<ModulWindow>::Create(pModulLayout.get(), rDocument, aLibName, aModName, aModule);
171 nKey = InsertWindowInTable( pWin );
173 else // we've gotten called recursively ( via listener from createModule above ), get outta here
174 return pWin;
177 else
179 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
180 nKey = GetWindowId( pWin );
181 DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
183 if( nKey && xLib.is() && rDocument.isInVBAMode() )
185 // display a nice friendly name in the ObjectModule tab,
186 // combining the objectname and module name, e.g. Sheet1 ( Financials )
187 OUString sObjName;
188 ModuleInfoHelper::getObjectName( xLib, rModName, sObjName );
189 if( !sObjName.isEmpty() )
191 aModName += " (" + sObjName + ")";
194 pTabBar->InsertPage( (sal_uInt16)nKey, aModName );
195 pTabBar->Sort();
196 if(pWin)
198 pWin->GrabScrollBars( aHScrollBar.get(), aVScrollBar.get() );
199 if ( !pCurWin )
200 SetCurWindow( pWin, false, false );
202 bCreatingWindow = false;
203 return pWin;
206 VclPtr<ModulWindow> Shell::FindBasWin (
207 ScriptDocument const& rDocument,
208 OUString const& rLibName, OUString const& rName,
209 bool bCreateIfNotExist, bool bFindSuspended
212 if (BaseWindow* pWin = FindWindow(rDocument, rLibName, rName, TYPE_MODULE, bFindSuspended))
213 return VclPtr<ModulWindow>(static_cast<ModulWindow*>(pWin));
214 return bCreateIfNotExist ? CreateBasWin(rDocument, rLibName, rName) : 0;
217 void Shell::Move()
221 void Shell::ShowCursor( bool bOn )
223 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
224 pMCurWin->ShowCursor(bOn);
227 // only if basic window above:
228 void Shell::ExecuteBasic( SfxRequest& rReq )
230 if (dynamic_cast<ModulWindow*>(pCurWin.get()))
232 pCurWin->ExecuteCommand( rReq );
233 if (nShellCount)
234 CheckWindows();
238 } // namespace basctl
240 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */