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