tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / basctl / source / basicide / basides2.cxx
blob249b3e6f43c76bd28e0f9c05511c2dc42eefd89a
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 <iderid.hxx>
27 #include <strings.hrc>
28 #include "baside2.hxx"
29 #include "basdoc.hxx"
30 #include <basidesh.hxx>
31 #include <tools/debug.hxx>
32 #include <vcl/texteng.hxx>
33 #include <vcl/textview.hxx>
34 #include <sfx2/signaturestate.hxx>
35 #include <sfx2/viewfrm.hxx>
37 namespace basctl
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
43 Reference< view::XRenderable > Shell::GetRenderable()
45 return Reference<view::XRenderable>( new Renderable(pCurWin) );
48 bool Shell::HasSelection( bool /* bText */ ) const
50 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
52 TextView* pEditView = pMCurWin->GetEditView();
53 if ( pEditView && pEditView->HasSelection() )
54 return true;
56 return false;
59 OUString Shell::GetSelectionText( bool bWholeWord, bool /*bOnlyASample*/ )
61 OUString aText;
62 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
64 if (TextView* pEditView = pMCurWin->GetEditView())
66 if ( bWholeWord && !pEditView->HasSelection() )
68 aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() );
70 else
72 TextSelection aSel = pEditView->GetSelection();
73 if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) )
74 aText = pEditView->GetSelected();
78 return aText;
81 SfxPrinter* Shell::GetPrinter( bool bCreate )
83 if ( pCurWin )
85 DocShell* pDocShell = static_cast<DocShell*>(GetViewFrame().GetObjectShell());
86 assert(pDocShell && "DocShell ?!");
87 return pDocShell->GetPrinter( bCreate );
89 return nullptr;
92 sal_uInt16 Shell::SetPrinter( SfxPrinter *pNewPrinter, SfxPrinterChangeFlags )
94 DocShell* pDocShell = static_cast<DocShell*>(GetViewFrame().GetObjectShell());
95 assert(pDocShell && "DocShell ?!");
96 pDocShell->SetPrinter( pNewPrinter );
97 return 0;
100 void Shell::SetMDITitle()
102 OUString aTitle;
103 if ( !m_aCurLibName.isEmpty() )
105 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
106 aTitle = m_aCurDocument.getTitle(eLocation) + "." + m_aCurLibName ;
108 else
109 aTitle = IDEResId(RID_STR_ALL) ;
111 DocumentSignature aCurSignature( m_aCurDocument );
112 if ( aCurSignature.getScriptingSignatureState() == SignatureState::OK )
114 aTitle += " " + IDEResId(RID_STR_SIGNED) + " ";
117 SfxViewFrame& rViewFrame = GetViewFrame();
118 SfxObjectShell* pShell = rViewFrame.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);
131 VclPtr<ModulWindow> Shell::CreateBasWin( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rModName )
133 bCreatingWindow = true;
135 sal_uInt16 nKey = 0;
136 VclPtr<ModulWindow> pWin;
138 OUString aLibName( rLibName );
139 OUString aModName( rModName );
141 if ( aLibName.isEmpty() )
142 aLibName = "Standard" ;
144 uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
146 if ( aModName.isEmpty() )
147 aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
149 // maybe there's an suspended one?
150 pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
152 if ( !pWin )
154 OUString aModule;
155 bool bSuccess = false;
156 if ( rDocument.hasModule( aLibName, aModName ) )
157 bSuccess = rDocument.getModule( aLibName, aModName, aModule );
158 else
159 bSuccess = rDocument.createModule( aLibName, aModName, true, aModule );
161 if ( bSuccess )
163 pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
164 if( !pWin )
166 // new module window
167 if (!pModulLayout)
168 pModulLayout.reset(VclPtr<ModulWindowLayout>::Create(&GetViewFrame().GetWindow(), *aObjectCatalog));
169 pWin = VclPtr<ModulWindow>::Create(pModulLayout.get(), rDocument, aLibName, aModName, aModule);
170 nKey = InsertWindowInTable( pWin );
172 else // we've gotten called recursively ( via listener from createModule above ), get outta here
173 return pWin;
176 else
178 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
179 nKey = GetWindowId( pWin );
180 DBG_ASSERT( nKey, "CreateBasWin: No Key - Window not found!" );
182 if( nKey && xLib.is() && rDocument.isInVBAMode() )
184 // display a nice friendly name in the ObjectModule tab,
185 // combining the objectname and module name, e.g. Sheet1 ( Financials )
186 OUString sObjName;
187 ModuleInfoHelper::getObjectName( xLib, rModName, sObjName );
188 if( !sObjName.isEmpty() )
190 aModName += " (" + sObjName + ")";
193 pTabBar->InsertPage( nKey, aModName );
194 pTabBar->Sort();
195 if(pWin)
197 pWin->GrabScrollBars( aHScrollBar.get(), aVScrollBar.get() );
198 if ( !pCurWin )
199 SetCurWindow( pWin, false, false );
201 bCreatingWindow = false;
202 return pWin;
205 VclPtr<ModulWindow> Shell::FindBasWin (
206 ScriptDocument const& rDocument,
207 OUString const& rLibName, OUString const& rName,
208 bool bCreateIfNotExist, bool bFindSuspended
211 if (VclPtr<BaseWindow> pWin = FindWindow(rDocument, rLibName, rName, SBX_TYPE_MODULE, bFindSuspended))
212 return VclPtr<ModulWindow>(static_cast<ModulWindow*>(pWin.get()));
213 return bCreateIfNotExist ? CreateBasWin(rDocument, rLibName, rName) : nullptr;
216 void Shell::Move()
220 void Shell::ShowCursor( bool bOn )
222 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
223 pMCurWin->ShowCursor(bOn);
226 // only if basic window above:
227 void Shell::ExecuteBasic( SfxRequest& rReq )
229 if (dynamic_cast<ModulWindow*>(pCurWin.get()))
231 pCurWin->ExecuteCommand( rReq );
232 if (nShellCount)
233 CheckWindows();
237 } // namespace basctl
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */