LibreOffice Module basctl (master) 1
basides2.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <docsignature.hxx>
21
22#include "basicrenderable.hxx"
23
24#include <com/sun/star/frame/XTitle.hpp>
25
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>
35#include <sfx2/viewfrm.hxx>
36
37namespace basctl
38{
39
40using namespace ::com::sun::star;
41using namespace ::com::sun::star::uno;
42
44{
46}
47
48bool Shell::HasSelection( bool /* bText */ ) const
49{
50 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
51 {
52 TextView* pEditView = pMCurWin->GetEditView();
53 if ( pEditView && pEditView->HasSelection() )
54 return true;
55 }
56 return false;
57}
58
59OUString Shell::GetSelectionText( bool bWholeWord, bool /*bOnlyASample*/ )
60{
61 OUString aText;
62 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
63 {
64 if (TextView* pEditView = pMCurWin->GetEditView())
65 {
66 if ( bWholeWord && !pEditView->HasSelection() )
67 {
68 aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() );
69 }
70 else
71 {
72 TextSelection aSel = pEditView->GetSelection();
73 if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) )
74 aText = pEditView->GetSelected();
75 }
76 }
77 }
78 return aText;
79}
80
82{
83 if ( pCurWin )
84 {
85 DocShell* pDocShell = static_cast<DocShell*>(GetViewFrame().GetObjectShell());
86 assert(pDocShell && "DocShell ?!");
87 return pDocShell->GetPrinter( bCreate );
88 }
89 return nullptr;
90}
91
93{
94 DocShell* pDocShell = static_cast<DocShell*>(GetViewFrame().GetObjectShell());
95 assert(pDocShell && "DocShell ?!");
96 pDocShell->SetPrinter( pNewPrinter );
97 return 0;
98}
99
101{
102 OUString aTitle;
103 if ( !m_aCurLibName.isEmpty() )
104 {
106 aTitle = m_aCurDocument.getTitle(eLocation) + "." + m_aCurLibName ;
107 }
108 else
109 aTitle = IDEResId(RID_STR_ALL) ;
110
111 DocumentSignature aCurSignature( m_aCurDocument );
112 if ( aCurSignature.getScriptingSignatureState() == SignatureState::OK )
113 {
114 aTitle += " " + IDEResId(RID_STR_SIGNED) + " ";
115 }
116
117 SfxViewFrame& rViewFrame = GetViewFrame();
118 SfxObjectShell* pShell = rViewFrame.GetObjectShell();
119 if ( pShell && pShell->GetTitle( SFX_TITLE_CAPTION ) != aTitle )
120 {
121 pShell->SetTitle( aTitle );
122 pShell->SetModified(false);
123 }
124
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);
129}
130
131VclPtr<ModulWindow> Shell::CreateBasWin( const ScriptDocument& rDocument, const OUString& rLibName, const OUString& rModName )
132{
133 bCreatingWindow = true;
134
135 sal_uInt16 nKey = 0;
137
138 OUString aLibName( rLibName );
139 OUString aModName( rModName );
140
141 if ( aLibName.isEmpty() )
142 aLibName = "Standard" ;
143
144 uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
145
146 if ( aModName.isEmpty() )
147 aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
148
149 // maybe there's an suspended one?
150 pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
151
152 if ( !pWin )
153 {
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 );
160
161 if ( bSuccess )
162 {
163 pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
164 if( !pWin )
165 {
166 // new module window
167 if (!pModulLayout)
169 pWin = VclPtr<ModulWindow>::Create(pModulLayout.get(), rDocument, aLibName, aModName, aModule);
170 nKey = InsertWindowInTable( pWin );
171 }
172 else // we've gotten called recursively ( via listener from createModule above ), get outta here
173 return pWin;
174 }
175 }
176 else
177 {
178 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
179 nKey = GetWindowId( pWin );
180 DBG_ASSERT( nKey, "CreateBasWin: No Key - Window not found!" );
181 }
182 if( nKey && xLib.is() && rDocument.isInVBAMode() )
183 {
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() )
189 {
190 aModName += " (" + sObjName + ")";
191 }
192 }
193 pTabBar->InsertPage( nKey, aModName );
194 pTabBar->Sort();
195 if(pWin)
196 {
197 pWin->GrabScrollBars( aHScrollBar.get(), aVScrollBar.get() );
198 if ( !pCurWin )
199 SetCurWindow( pWin, false, false );
200 }
201 bCreatingWindow = false;
202 return pWin;
203}
204
206 ScriptDocument const& rDocument,
207 OUString const& rLibName, OUString const& rName,
208 bool bCreateIfNotExist, bool bFindSuspended
209)
210{
211 if (VclPtr<BaseWindow> pWin = FindWindow(rDocument, rLibName, rName, TYPE_MODULE, bFindSuspended))
212 return VclPtr<ModulWindow>(static_cast<ModulWindow*>(pWin.get()));
213 return bCreateIfNotExist ? CreateBasWin(rDocument, rLibName, rName) : nullptr;
214}
215
217{
218}
219
220void Shell::ShowCursor( bool bOn )
221{
222 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
223 pMCurWin->ShowCursor(bOn);
224}
225
226// only if basic window above:
228{
229 if (dynamic_cast<ModulWindow*>(pCurWin.get()))
230 {
231 pCurWin->ExecuteCommand( rReq );
232 if (nShellCount)
233 CheckWindows();
234 }
235}
236
237} // namespace basctl
238
239/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetTitle(const OUString &rTitle)
OUString GetTitle(sal_uInt16 nMaxLen=0) const
virtual void SetModified(bool bModified=true)
virtual SfxObjectShell * GetObjectShell() override
css::uno::Reference< css::frame::XController > GetController() const
SfxViewFrame & GetViewFrame() const
vcl::Window * GetWindow() const
sal_uInt32 GetPara() const
const TextPaM & GetStart() const
const TextPaM & GetEnd() const
bool HasSelection() const
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
SfxPrinter * GetPrinter(bool bCreate)
Definition: basdoc.cxx:62
void SetPrinter(SfxPrinter *pPrinter)
Definition: basdoc.cxx:72
encapsulates (actions on) the signature/state of a document
SignatureState getScriptingSignatureState() const
retrieves the state of the signature of the scripting content inside the document
static void getObjectName(const css::uno::Reference< css::container::XNameContainer > &rLib, const OUString &rModName, OUString &rObjName)
Definition: bastype2.cxx:52
encapsulates a document which contains Basic scripts and dialogs
css::uno::Reference< css::container::XNameContainer > getOrCreateLibrary(LibraryContainerType _eType, const OUString &_rLibName) const
creates a script or dialog library in the document, or returns an existing one
OUString getTitle(LibraryLocation _eLocation, LibraryType _eType=LibraryType::All) const
returns the title for the document
bool getModule(const OUString &_rLibName, const OUString &_rModName, OUString &_rModuleSource) const
retrieves a module's source
bool createModule(const OUString &_rLibName, const OUString &_rModName, bool _bCreateMain, OUString &_out_rNewModuleCode) const
creates a module with the given name in the given library
bool hasModule(const OUString &_rLibName, const OUString &_rModName) const
determines whether a module with the given name exists in the given library
LibraryLocation getLibraryLocation(const OUString &_rLibName) const
returns the location of a library given by name
OUString createObjectName(LibraryContainerType _eType, const OUString &_rLibName) const
retrieves a name for a newly to be created module or dialog
virtual void ShowCursor(bool bOn=true) override
Definition: basides2.cxx:220
VclPtr< ModulWindow > FindBasWin(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rModName, bool bCreateIfNotExist=false, bool bFindSuspended=false)
Definition: basides2.cxx:205
virtual bool HasSelection(bool bText=true) const override
Definition: basides2.cxx:48
VclPtr< BaseWindow > FindWindow(const ScriptDocument &rDocument, std::u16string_view rLibName, std::u16string_view rName, ItemType nType, bool bFindSuspended=false)
Definition: basides1.cxx:1391
sal_uInt16 GetWindowId(BaseWindow const *pWin) const
Definition: basides3.cxx:125
static unsigned nShellCount
Definition: basidesh.hxx:115
VclPtr< TabBar > pTabBar
Definition: basidesh.hxx:81
VclPtr< ScrollAdaptor > aVScrollBar
Definition: basidesh.hxx:80
VclPtr< ModulWindowLayout > pModulLayout
Definition: basidesh.hxx:85
OUString m_aCurLibName
Definition: basidesh.hxx:74
void CheckWindows()
Definition: basidesh.cxx:582
ScriptDocument m_aCurDocument
Definition: basidesh.hxx:73
void SetMDITitle()
Definition: basides2.cxx:100
bool bCreatingWindow
Definition: basidesh.hxx:82
VclPtr< ModulWindow > CreateBasWin(const ScriptDocument &rDocument, const OUString &rLibName, const OUString &rModName)
Definition: basides2.cxx:131
virtual SfxPrinter * GetPrinter(bool bCreate=false) override
Definition: basides2.cxx:81
virtual sal_uInt16 SetPrinter(SfxPrinter *pNewPrinter, SfxPrinterChangeFlags nDiffFlags=SFX_PRINTER_ALL) override
Definition: basides2.cxx:92
VclPtr< ObjectCatalog > aObjectCatalog
Definition: basidesh.hxx:89
VclPtr< ScrollAdaptor > aHScrollBar
Definition: basidesh.hxx:79
void ExecuteBasic(SfxRequest &rReq)
Definition: basides2.cxx:227
virtual OUString GetSelectionText(bool bCompleteWords=false, bool bOnlyASample=false) override
Definition: basides2.cxx:59
virtual css::uno::Reference< css::view::XRenderable > GetRenderable() override
Definition: basides2.cxx:43
sal_uInt16 InsertWindowInTable(BaseWindow *pNewWin)
Definition: basidesh.cxx:841
VclPtr< BaseWindow > pCurWin
Definition: basidesh.hxx:72
void SetCurWindow(BaseWindow *pNewWin, bool bUpdateTabBar=false, bool bRememberAsCurrent=true)
Definition: basides1.cxx:1271
virtual void Move() override
Definition: basides2.cxx:216
#define DBG_ASSERT(sCon, aError)
@ BASWIN_SUSPENDED
Definition: bastypes.hxx:147
@ TYPE_MODULE
Definition: sbxitem.hxx:32
OUString IDEResId(TranslateId aId)
Definition: iderdll.cxx:108
#define SFX_TITLE_CAPTION
Reference< XController > xController
SfxPrinterChangeFlags