Branch data Line data Source code
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 <basic/sbx.hxx>
23 : : #include "basicrenderable.hxx"
24 : :
25 : : #include <com/sun/star/frame/XTitle.hpp>
26 : :
27 : : #include <basidesh.hxx>
28 : : #include <basidesh.hrc>
29 : : #include <baside2.hxx>
30 : : #include <basdoc.hxx>
31 : : #include <basobj.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>
43 : :
44 : : using namespace ::com::sun::star;
45 : : using namespace ::com::sun::star::uno;
46 : : namespace css = ::com::sun::star;
47 : :
48 : : using basctl::ModulWindow;
49 : : using basctl::ModulWindowLayout;
50 : :
51 : 0 : Reference< view::XRenderable > BasicIDEShell::GetRenderable()
52 : : {
53 : 0 : return Reference< view::XRenderable >( new basicide::BasicRenderable( pCurWin ) );
54 : : }
55 : :
56 : 0 : sal_Bool BasicIDEShell::HasSelection( sal_Bool /* bText */ ) const
57 : : {
58 : 0 : if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
59 : : {
60 : 0 : TextView* pEditView = pMCurWin->GetEditView();
61 : 0 : if ( pEditView && pEditView->HasSelection() )
62 : 0 : return true;
63 : : }
64 : 0 : return false;
65 : : }
66 : :
67 : 0 : String BasicIDEShell::GetSelectionText( sal_Bool bWholeWord )
68 : : {
69 : 0 : String aText;
70 : 0 : if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
71 : : {
72 : 0 : if (TextView* pEditView = pMCurWin->GetEditView())
73 : : {
74 : 0 : if ( bWholeWord && !pEditView->HasSelection() )
75 : : {
76 : 0 : aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() );
77 : : }
78 : : else
79 : : {
80 : 0 : TextSelection aSel = pEditView->GetSelection();
81 : 0 : if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) )
82 : 0 : aText = pEditView->GetSelected();
83 : : }
84 : : }
85 : : }
86 : 0 : return aText;
87 : : }
88 : :
89 : 0 : SfxPrinter* BasicIDEShell::GetPrinter( sal_Bool bCreate )
90 : : {
91 : 0 : if ( pCurWin )
92 : : {
93 : 0 : BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell();
94 : : DBG_ASSERT( pDocShell, "DocShell ?!" );
95 : 0 : return pDocShell->GetPrinter( bCreate );
96 : : }
97 : 0 : return 0;
98 : : }
99 : :
100 : 0 : sal_uInt16 BasicIDEShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
101 : : {
102 : : (void)nDiffFlags;
103 : 0 : BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell();
104 : : DBG_ASSERT( pDocShell, "DocShell ?!" );
105 : 0 : pDocShell->SetPrinter( pNewPrinter );
106 : 0 : return 0;
107 : : }
108 : :
109 : 0 : void BasicIDEShell::SetMDITitle()
110 : : {
111 : 0 : ::rtl::OUStringBuffer aTitleBuf;
112 : 0 : if ( !m_aCurLibName.isEmpty() )
113 : : {
114 : 0 : LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
115 : 0 : aTitleBuf.append(m_aCurDocument.getTitle(eLocation));
116 : 0 : aTitleBuf.append('.');
117 : 0 : aTitleBuf.append(m_aCurLibName);
118 : : }
119 : : else
120 : 0 : aTitleBuf.append(IDE_RESSTR(RID_STR_ALL));
121 : :
122 : 0 : ::basctl::DocumentSignature aCurSignature( m_aCurDocument );
123 : 0 : if ( aCurSignature.getScriptingSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
124 : : {
125 : 0 : aTitleBuf.append(' ');
126 : 0 : aTitleBuf.append(IDE_RESSTR(RID_STR_SIGNED));
127 : 0 : aTitleBuf.append(' ');
128 : : }
129 : 0 : ::rtl::OUString aTitle(aTitleBuf.makeStringAndClear());
130 : :
131 : 0 : SfxViewFrame* pViewFrame = GetViewFrame();
132 : 0 : if ( pViewFrame )
133 : : {
134 : 0 : SfxObjectShell* pShell = pViewFrame->GetObjectShell();
135 : 0 : if ( pShell && !pShell->GetTitle( SFX_TITLE_CAPTION ).Equals(aTitle) )
136 : : {
137 : 0 : pShell->SetTitle( aTitle );
138 : 0 : pShell->SetModified(false);
139 : : }
140 : :
141 : 0 : css::uno::Reference< css::frame::XController > xController = GetController ();
142 : 0 : css::uno::Reference< css::frame::XTitle > xTitle (xController, css::uno::UNO_QUERY);
143 : 0 : if (xTitle.is ())
144 : 0 : xTitle->setTitle (aTitle);
145 : 0 : }
146 : 0 : }
147 : :
148 : 0 : ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const ::rtl::OUString& rLibName, const ::rtl::OUString& rModName )
149 : : {
150 : 0 : bCreatingWindow = true;
151 : :
152 : 0 : sal_uLong nKey = 0;
153 : 0 : ModulWindow* pWin = 0;
154 : :
155 : 0 : ::rtl::OUString aLibName( rLibName );
156 : 0 : ::rtl::OUString aModName( rModName );
157 : :
158 : 0 : if ( aLibName.isEmpty() )
159 : 0 : aLibName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard"));
160 : :
161 : 0 : uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
162 : :
163 : 0 : if ( aModName.isEmpty() )
164 : 0 : aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
165 : :
166 : : // maybe there's an suspended one?
167 : 0 : pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
168 : :
169 : 0 : if ( !pWin )
170 : : {
171 : 0 : ::rtl::OUString aModule;
172 : 0 : bool bSuccess = false;
173 : 0 : if ( rDocument.hasModule( aLibName, aModName ) )
174 : 0 : bSuccess = rDocument.getModule( aLibName, aModName, aModule );
175 : : else
176 : 0 : bSuccess = rDocument.createModule( aLibName, aModName, true, aModule );
177 : :
178 : 0 : if ( bSuccess )
179 : : {
180 : 0 : pWin = FindBasWin( rDocument, aLibName, aModName, false, true );
181 : 0 : if( !pWin )
182 : : {
183 : : // new module window
184 : 0 : if (!pModulLayout)
185 : 0 : pModulLayout.reset(new ModulWindowLayout(&GetViewFrame()->GetWindow(), aObjectCatalog));
186 : 0 : pWin = new ModulWindow(pModulLayout.get(), rDocument, aLibName, aModName, aModule);
187 : 0 : nKey = InsertWindowInTable( pWin );
188 : : }
189 : : else // we've gotten called recursively ( via listener from createModule above ), get outta here
190 : 0 : return pWin;
191 : 0 : }
192 : : }
193 : : else
194 : : {
195 : 0 : pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
196 : 0 : nKey = GetIDEWindowId( pWin );
197 : : DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
198 : : }
199 : 0 : if( nKey && xLib.is() && rDocument.isInVBAMode() )
200 : : {
201 : : // display a nice friendly name in the ObjectModule tab,
202 : : // combining the objectname and module name, e.g. Sheet1 ( Financials )
203 : 0 : ::rtl::OUString sObjName;
204 : 0 : ModuleInfoHelper::getObjectName( xLib, rModName, sObjName );
205 : 0 : if( !sObjName.isEmpty() )
206 : : {
207 : 0 : ::rtl::OUStringBuffer aModNameBuf(aModName);
208 : 0 : aModNameBuf.append(' ');
209 : 0 : aModNameBuf.append('(');
210 : 0 : aModNameBuf.append(sObjName);
211 : 0 : aModNameBuf.append(')');
212 : 0 : aModName = aModNameBuf.makeStringAndClear();
213 : 0 : }
214 : : }
215 : 0 : pTabBar->InsertPage( (sal_uInt16)nKey, aModName );
216 : 0 : pTabBar->Sort();
217 : 0 : pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
218 : 0 : if ( !pCurWin )
219 : 0 : SetCurWindow( pWin, false, false );
220 : :
221 : 0 : bCreatingWindow = false;
222 : 0 : return pWin;
223 : : }
224 : :
225 : 0 : ModulWindow* BasicIDEShell::FindBasWin (
226 : : ScriptDocument const& rDocument,
227 : : rtl::OUString const& rLibName, rtl::OUString const& rName,
228 : : bool bCreateIfNotExist, bool bFindSuspended
229 : : )
230 : : {
231 : 0 : if (IDEBaseWindow* pWin = FindWindow(rDocument, rLibName, rName, BASICIDE_TYPE_MODULE, bFindSuspended))
232 : 0 : return static_cast<ModulWindow*>(pWin);
233 : 0 : return bCreateIfNotExist ? CreateBasWin(rDocument, rLibName, rName) : 0;
234 : : }
235 : :
236 : 0 : void BasicIDEShell::Move()
237 : : {
238 : 0 : if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
239 : 0 : pMCurWin->FrameWindowMoved();
240 : 0 : }
241 : :
242 : 0 : void BasicIDEShell::ShowCursor( bool bOn )
243 : : {
244 : 0 : if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
245 : 0 : pMCurWin->ShowCursor(bOn);
246 : 0 : }
247 : :
248 : : // Hack for #101048
249 : : sal_Int32 getBasicIDEShellCount( void );
250 : :
251 : : // only if basic window above:
252 : 0 : void BasicIDEShell::ExecuteBasic( SfxRequest& rReq )
253 : : {
254 : 0 : if (dynamic_cast<ModulWindow*>(pCurWin))
255 : : {
256 : 0 : pCurWin->ExecuteCommand( rReq );
257 : 0 : if (getBasicIDEShellCount())
258 : 0 : CheckWindows();
259 : : }
260 : 0 : }
261 : :
262 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|