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 : : #define _SOLAR__PRIVATE 1
21 : :
22 : : #include "basidesh.hrc"
23 : : #include "helpid.hrc"
24 : :
25 : : #include "baside2.hxx"
26 : : #include "baside3.hxx"
27 : : #include "basobj.hxx"
28 : : #include "docsignature.hxx"
29 : : #include "iderdll.hxx"
30 : : #include "iderdll2.hxx"
31 : : #include "localizationmgr.hxx"
32 : : #include "managelang.hxx"
33 : :
34 : : #include <basic/basmgr.hxx>
35 : : #include <basic/sbmeth.hxx>
36 : : #include <com/sun/star/frame/XLayoutManager.hpp>
37 : : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
38 : : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
39 : : #include <sfx2/childwin.hxx>
40 : : #include <sfx2/docfac.hxx>
41 : : #include <sfx2/dinfdlg.hxx>
42 : : #include <sfx2/dispatch.hxx>
43 : : #include <sfx2/minfitem.hxx>
44 : : #include <sfx2/objface.hxx>
45 : : #include <sfx2/printer.hxx>
46 : : #include <sfx2/request.hxx>
47 : : #include <svl/aeitem.hxx>
48 : : #include <svl/intitem.hxx>
49 : : #include <svl/srchitem.hxx>
50 : : #include <svl/visitem.hxx>
51 : : #include <svl/whiter.hxx>
52 : : #include <vcl/xtextedt.hxx>
53 : : #include <vcl/msgbox.hxx>
54 : :
55 : : using namespace ::com::sun::star;
56 : : using namespace ::com::sun::star::uno;
57 : : using namespace ::com::sun::star::frame;
58 : :
59 : : using basctl::ModulWindow;
60 : : using basctl::ModulWindowLayout;
61 : : using basctl::DialogWindow;
62 : : using basctl::DialogWindowLayout;
63 : :
64 : 0 : void BasicIDEShell::ExecuteCurrent( SfxRequest& rReq )
65 : : {
66 : 0 : if ( !pCurWin )
67 : 0 : return;
68 : :
69 : 0 : switch ( rReq.GetSlot() )
70 : : {
71 : : case SID_BASICIDE_HIDECURPAGE:
72 : : {
73 : 0 : pCurWin->StoreData();
74 : 0 : RemoveWindow( pCurWin, false );
75 : : }
76 : 0 : break;
77 : : case SID_BASICIDE_RENAMECURRENT:
78 : : {
79 : 0 : pTabBar->StartEditMode( pTabBar->GetCurPageId() );
80 : : }
81 : 0 : break;
82 : : case FID_SEARCH_NOW:
83 : : {
84 : 0 : if (!pCurWin->HasActiveEditor())
85 : 0 : break;
86 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
87 : 0 : SfxItemSet const& rArgs = *rReq.GetArgs();
88 : : // unfortunately I don't know the ID:
89 : 0 : sal_uInt16 nWhich = rArgs.GetWhichByPos( 0 );
90 : : DBG_ASSERT( nWhich, "Wich fuer SearchItem ?" );
91 : 0 : SfxPoolItem const& rItem = rArgs.Get(nWhich);
92 : : DBG_ASSERT(dynamic_cast<SvxSearchItem const*>(&rItem), "no searchitem!");
93 : 0 : SvxSearchItem const& rSearchItem = static_cast<SvxSearchItem const&>(rItem);
94 : : // memorize item because of the adjustments...
95 : 0 : BasicIDEGlobals::GetExtraData()->SetSearchItem(rSearchItem);
96 : 0 : sal_Int32 nFound = 0;
97 : 0 : bool bCanceled = false;
98 : 0 : if (rSearchItem.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL)
99 : : {
100 : 0 : sal_uInt16 nActModWindows = 0;
101 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
102 : : {
103 : 0 : IDEBaseWindow* pWin = it->second;
104 : 0 : if (pWin->HasActiveEditor())
105 : 0 : nActModWindows++;
106 : : }
107 : :
108 : 0 : if ( nActModWindows <= 1 || ( !rSearchItem.GetSelection() && QueryBox( pCurWin, WB_YES_NO|WB_DEF_YES, String(IDEResId(RID_STR_SEARCHALLMODULES)) ).Execute() == RET_YES ) )
109 : : {
110 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
111 : : {
112 : 0 : IDEBaseWindow* pWin = it->second;
113 : 0 : nFound += pWin->StartSearchAndReplace(rSearchItem);
114 : : }
115 : : }
116 : : else
117 : 0 : nFound = pCurWin->StartSearchAndReplace(rSearchItem);
118 : :
119 : 0 : rtl::OUString aReplStr(IDE_RESSTR(RID_STR_SEARCHREPLACES));
120 : 0 : aReplStr = aReplStr.replaceAll("XX", rtl::OUString::valueOf(nFound));
121 : 0 : InfoBox( pCurWin, aReplStr ).Execute();
122 : : }
123 : : else
124 : : {
125 : 0 : nFound = pCurWin->StartSearchAndReplace(rSearchItem);
126 : 0 : if ( !nFound && !rSearchItem.GetSelection() )
127 : : {
128 : : // search other modules...
129 : 0 : bool bChangeCurWindow = false;
130 : 0 : WindowTableIt it;
131 : 0 : for (it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
132 : 0 : if (it->second == pCurWin)
133 : 0 : break;
134 : 0 : if (it != aIDEWindowTable.end())
135 : 0 : ++it;
136 : 0 : IDEBaseWindow* pWin = it != aIDEWindowTable.end() ? it->second : 0;
137 : :
138 : 0 : bool bSearchedFromStart = false;
139 : 0 : while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
140 : : {
141 : 0 : if ( !pWin )
142 : : {
143 : 0 : SfxViewFrame* pViewFrame = GetViewFrame();
144 : 0 : SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow( SID_SEARCH_DLG ) : NULL;
145 : 0 : Window* pParent = pChildWin ? pChildWin->GetWindow() : NULL;
146 : 0 : QueryBox aQuery(pParent, WB_YES_NO|WB_DEF_YES, IDE_RESSTR(RID_STR_SEARCHFROMSTART));
147 : 0 : if ( aQuery.Execute() == RET_YES )
148 : : {
149 : 0 : it = aIDEWindowTable.begin();
150 : 0 : if ( it != aIDEWindowTable.end() )
151 : 0 : pWin = it->second;
152 : 0 : bSearchedFromStart = true;
153 : : }
154 : : else
155 : 0 : bCanceled = true;
156 : : }
157 : :
158 : 0 : if (pWin && pWin->HasActiveEditor())
159 : : {
160 : 0 : if ( pWin != pCurWin )
161 : : {
162 : 0 : if ( pCurWin )
163 : 0 : pWin->SetSizePixel( pCurWin->GetSizePixel() );
164 : 0 : nFound = pWin->StartSearchAndReplace(rSearchItem, true);
165 : : }
166 : 0 : if ( nFound )
167 : : {
168 : 0 : bChangeCurWindow = true;
169 : 0 : break;
170 : : }
171 : : }
172 : 0 : if ( pWin && ( pWin != pCurWin ) )
173 : : {
174 : 0 : if ( it != aIDEWindowTable.end() )
175 : 0 : ++it;
176 : 0 : pWin = it != aIDEWindowTable.end() ? it->second : 0;
177 : : }
178 : : else
179 : 0 : pWin = 0;
180 : : }
181 : 0 : if ( !nFound && bSearchedFromStart )
182 : 0 : nFound = pCurWin->StartSearchAndReplace(rSearchItem, true);
183 : 0 : if ( bChangeCurWindow )
184 : 0 : SetCurWindow( pWin, true );
185 : : }
186 : 0 : if ( !nFound && !bCanceled )
187 : 0 : InfoBox( pCurWin, String(IDEResId(RID_STR_SEARCHNOTFOUND)) ).Execute();
188 : : }
189 : :
190 : 0 : rReq.Done();
191 : : }
192 : 0 : break;
193 : : case SID_UNDO:
194 : : case SID_REDO:
195 : 0 : if ( GetUndoManager() && pCurWin->AllowUndo() )
196 : 0 : GetViewFrame()->ExecuteSlot( rReq );
197 : 0 : break;
198 : : default:
199 : 0 : pCurWin->ExecuteCommand( rReq );
200 : : }
201 : : }
202 : :
203 : : // no matter who's at the top, influence on the shell:
204 : 0 : void BasicIDEShell::ExecuteGlobal( SfxRequest& rReq )
205 : : {
206 : 0 : sal_uInt16 nSlot = rReq.GetSlot();
207 : 0 : switch ( nSlot )
208 : : {
209 : : case SID_BASICSTOP:
210 : : {
211 : : // maybe do not simply stop if on breakpoint!
212 : 0 : if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
213 : 0 : pMCurWin->BasicStop();
214 : 0 : BasicIDE::StopBasic();
215 : : }
216 : 0 : break;
217 : :
218 : : case SID_SAVEDOC:
219 : : {
220 : 0 : if ( pCurWin )
221 : : {
222 : : // rewrite date into the BASIC
223 : 0 : StoreAllWindowData();
224 : :
225 : : // document basic
226 : 0 : ScriptDocument aDocument( pCurWin->GetDocument() );
227 : 0 : if ( aDocument.isDocument() )
228 : : {
229 : 0 : uno::Reference< task::XStatusIndicator > xStatusIndicator;
230 : :
231 : 0 : SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem,
232 : : SID_PROGRESS_STATUSBAR_CONTROL, false );
233 : 0 : if ( pStatusIndicatorItem )
234 : 0 : OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
235 : : else
236 : : {
237 : : // get statusindicator
238 : 0 : SfxViewFrame *pFrame_ = GetFrame();
239 : 0 : if ( pFrame_ )
240 : : {
241 : : uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
242 : 0 : pFrame_->GetFrame().GetFrameInterface(),
243 : 0 : uno::UNO_QUERY );
244 : 0 : if( xStatFactory.is() )
245 : 0 : xStatusIndicator = xStatFactory->createStatusIndicator();
246 : : }
247 : :
248 : 0 : if ( xStatusIndicator.is() )
249 : 0 : rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) ) );
250 : : }
251 : :
252 : 0 : aDocument.saveDocument( xStatusIndicator );
253 : : }
254 : :
255 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
256 : 0 : if ( pBindings )
257 : : {
258 : 0 : pBindings->Invalidate( SID_DOC_MODIFIED );
259 : 0 : pBindings->Invalidate( SID_SAVEDOC );
260 : 0 : pBindings->Invalidate( SID_SIGNATURE );
261 : 0 : }
262 : : }
263 : : }
264 : 0 : break;
265 : : case SID_BASICIDE_MODULEDLG:
266 : : {
267 : 0 : if ( rReq.GetArgs() )
268 : : {
269 : 0 : const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
270 : 0 : BasicIDE::Organize( rTabId.GetValue() );
271 : : }
272 : : else
273 : 0 : BasicIDE::Organize( 0 );
274 : : }
275 : 0 : break;
276 : : case SID_BASICIDE_CHOOSEMACRO:
277 : : {
278 : 0 : BasicIDE::ChooseMacro( NULL, false, ::rtl::OUString() );
279 : : }
280 : 0 : break;
281 : : case SID_BASICIDE_CREATEMACRO:
282 : : case SID_BASICIDE_EDITMACRO:
283 : : {
284 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
285 : 0 : const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
286 : 0 : BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
287 : : DBG_ASSERT( pBasMgr, "Nichts selektiert im Basic-Baum ?" );
288 : :
289 : 0 : ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
290 : :
291 : 0 : StartListening( *pBasMgr, true /* log on only once */ );
292 : 0 : ::rtl::OUString aLibName( rInfo.GetLib() );
293 : 0 : if ( aLibName.isEmpty() )
294 : 0 : aLibName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard"));
295 : 0 : StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
296 : 0 : if ( !pBasic )
297 : : {
298 : : // load module and dialog library (if not loaded)
299 : 0 : aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
300 : 0 : aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
301 : :
302 : : // get Basic
303 : 0 : pBasic = pBasMgr->GetLib( aLibName );
304 : : }
305 : : DBG_ASSERT( pBasic, "Kein Basic!" );
306 : :
307 : 0 : SetCurLib( aDocument, aLibName );
308 : :
309 : 0 : if ( rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
310 : : {
311 : 0 : SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
312 : 0 : if ( !pModule )
313 : : {
314 : 0 : if ( rInfo.GetModule().Len() || !pBasic->GetModules()->Count() )
315 : : {
316 : 0 : ::rtl::OUString aModName = rInfo.GetModule();
317 : :
318 : 0 : ::rtl::OUString sModuleCode;
319 : 0 : if ( aDocument.createModule( aLibName, aModName, false, sModuleCode ) )
320 : 0 : pModule = pBasic->FindModule( aModName );
321 : : }
322 : : else
323 : 0 : pModule = (SbModule*) pBasic->GetModules()->Get(0);
324 : : }
325 : : DBG_ASSERT( pModule, "Kein Modul!" );
326 : 0 : if ( !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxCLASS_METHOD ) )
327 : 0 : BasicIDE::CreateMacro( pModule, rInfo.GetMethod() );
328 : : }
329 : 0 : SfxViewFrame* pViewFrame = GetViewFrame();
330 : 0 : if ( pViewFrame )
331 : 0 : pViewFrame->ToTop();
332 : 0 : ModulWindow* pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), true );
333 : : DBG_ASSERT( pWin, "Edit/Create Macro: Fenster wurde nicht erzeugt/gefunden!" );
334 : 0 : SetCurWindow( pWin, true );
335 : 0 : pWin->EditMacro( rInfo.GetMethod() );
336 : : }
337 : 0 : break;
338 : :
339 : : case SID_BASICIDE_OBJCAT:
340 : : // toggling object catalog
341 : 0 : aObjectCatalog.Show(!aObjectCatalog.IsVisible());
342 : 0 : if (pLayout)
343 : 0 : pLayout->ArrangeWindows();
344 : : // refresh the button state
345 : 0 : if (SfxBindings* pBindings = BasicIDE::GetBindingsPtr())
346 : 0 : pBindings->Invalidate(SID_BASICIDE_OBJCAT);
347 : 0 : break;
348 : :
349 : : case SID_BASICIDE_NAMECHANGEDONTAB:
350 : : {
351 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
352 : 0 : const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
353 : 0 : const SfxStringItem &rModName = (const SfxStringItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
354 : 0 : if ( aIDEWindowTable.find( rTabId.GetValue() ) != aIDEWindowTable.end() )
355 : : {
356 : 0 : IDEBaseWindow* pWin = aIDEWindowTable[ rTabId.GetValue() ];
357 : 0 : ::rtl::OUString aNewName( rModName.GetValue() );
358 : 0 : ::rtl::OUString aOldName( pWin->GetName() );
359 : 0 : if ( aNewName != aOldName )
360 : : {
361 : 0 : bool bRenameOk = false;
362 : 0 : if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
363 : : {
364 : 0 : rtl::OUString aLibName = pModWin->GetLibName();
365 : 0 : ScriptDocument aDocument( pWin->GetDocument() );
366 : :
367 : 0 : if ( BasicIDE::RenameModule( pModWin, aDocument, aLibName, aOldName, aNewName ) )
368 : : {
369 : 0 : bRenameOk = true;
370 : : // Because we listen for container events for script
371 : : // modules, rename will delete the 'old' window
372 : : // pWin has been invalidated, restore now
373 : 0 : pWin = FindBasWin( aDocument, aLibName, aNewName, true );
374 : 0 : }
375 : :
376 : : }
377 : 0 : else if (DialogWindow* pDlgWin = dynamic_cast<DialogWindow*>(pWin))
378 : : {
379 : 0 : bRenameOk = pDlgWin->RenameDialog( aNewName );
380 : : }
381 : 0 : if ( bRenameOk )
382 : : {
383 : 0 : BasicIDE::MarkDocumentModified( pWin->GetDocument() );
384 : : }
385 : : else
386 : : {
387 : : // set old name in TabWriter
388 : 0 : sal_uInt16 nId = GetIDEWindowId( pWin );
389 : : DBG_ASSERT( nId, "No entry in Tabbar!" );
390 : 0 : if ( nId )
391 : 0 : pTabBar->SetPageText( nId, aOldName );
392 : : }
393 : : }
394 : :
395 : : // set focus to current window
396 : 0 : pWin->GrabFocus();
397 : : }
398 : : }
399 : 0 : break;
400 : : case SID_BASICIDE_STOREMODULESOURCE:
401 : : case SID_BASICIDE_UPDATEMODULESOURCE:
402 : : {
403 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
404 : 0 : const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
405 : 0 : BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
406 : : DBG_ASSERT( pBasMgr, "Store source: Kein BasMgr?" );
407 : 0 : ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
408 : 0 : ModulWindow* pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), false, true );
409 : 0 : if ( pWin )
410 : : {
411 : 0 : if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
412 : 0 : pWin->StoreData();
413 : : else
414 : 0 : pWin->UpdateData();
415 : 0 : }
416 : : }
417 : 0 : break;
418 : : case SID_BASICIDE_STOREALLMODULESOURCES:
419 : : case SID_BASICIDE_UPDATEALLMODULESOURCES:
420 : : {
421 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
422 : : {
423 : 0 : IDEBaseWindow* pWin = it->second;
424 : 0 : if (!pWin->IsSuspended() && dynamic_cast<ModulWindow*>(pWin))
425 : : {
426 : 0 : if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
427 : 0 : pWin->StoreData();
428 : : else
429 : 0 : pWin->UpdateData();
430 : : }
431 : : }
432 : : }
433 : 0 : break;
434 : : case SID_BASICIDE_LIBSELECTED:
435 : : case SID_BASICIDE_LIBREMOVED:
436 : : case SID_BASICIDE_LIBLOADED:
437 : : {
438 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
439 : 0 : const SfxUsrAnyItem& rShellItem = (const SfxUsrAnyItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
440 : 0 : uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
441 : 0 : ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
442 : 0 : const SfxStringItem& rLibNameItem = (const SfxStringItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
443 : 0 : ::rtl::OUString aLibName( rLibNameItem.GetValue() );
444 : :
445 : 0 : if ( nSlot == SID_BASICIDE_LIBSELECTED )
446 : : {
447 : : // load module and dialog library (if not loaded)
448 : 0 : aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
449 : 0 : aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
450 : :
451 : : // check password, if library is password protected and not verified
452 : 0 : bool bOK = true;
453 : 0 : Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
454 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
455 : : {
456 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
457 : 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
458 : : {
459 : 0 : ::rtl::OUString aPassword;
460 : 0 : bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
461 : 0 : }
462 : : }
463 : :
464 : 0 : if ( bOK )
465 : : {
466 : 0 : SetCurLib( aDocument, aLibName, true, false );
467 : : }
468 : : else
469 : : {
470 : : // adjust old value...
471 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
472 : 0 : if ( pBindings )
473 : 0 : pBindings->Invalidate(SID_BASICIDE_LIBSELECTOR, true, false);
474 : 0 : }
475 : : }
476 : 0 : else if ( nSlot == SID_BASICIDE_LIBREMOVED )
477 : : {
478 : 0 : if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
479 : : {
480 : 0 : RemoveWindows( aDocument, aLibName, true );
481 : 0 : if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
482 : : {
483 : 0 : m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
484 : 0 : m_aCurLibName = String();
485 : : // no UpdateWindows!
486 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
487 : 0 : if ( pBindings )
488 : 0 : pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
489 : : }
490 : : }
491 : : }
492 : : else // Loaded...
493 : 0 : UpdateWindows();
494 : : }
495 : 0 : break;
496 : : case SID_BASICIDE_NEWMODULE:
497 : : {
498 : 0 : ModulWindow* pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, String() );
499 : : DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
500 : 0 : SetCurWindow( pWin, true );
501 : : }
502 : 0 : break;
503 : : case SID_BASICIDE_NEWDIALOG:
504 : : {
505 : 0 : DialogWindow* pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, String() );
506 : : DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
507 : 0 : SetCurWindow( pWin, true );
508 : : }
509 : 0 : break;
510 : : case SID_BASICIDE_SBXRENAMED:
511 : : {
512 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
513 : : }
514 : 0 : break;
515 : : case SID_BASICIDE_SBXINSERTED:
516 : : {
517 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
518 : 0 : const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
519 : 0 : ScriptDocument aDocument( rSbxItem.GetDocument() );
520 : 0 : ::rtl::OUString aLibName( rSbxItem.GetLibName() );
521 : 0 : ::rtl::OUString aName( rSbxItem.GetName() );
522 : 0 : if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
523 : : {
524 : 0 : if ( rSbxItem.GetType() == BASICIDE_TYPE_MODULE )
525 : 0 : FindBasWin( aDocument, aLibName, aName, true );
526 : 0 : else if ( rSbxItem.GetType() == BASICIDE_TYPE_DIALOG )
527 : 0 : FindDlgWin( aDocument, aLibName, aName, true );
528 : 0 : }
529 : : }
530 : 0 : break;
531 : : case SID_BASICIDE_SBXDELETED:
532 : : {
533 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
534 : 0 : const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
535 : 0 : ScriptDocument aDocument( rSbxItem.GetDocument() );
536 : 0 : IDEBaseWindow* pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), true );
537 : 0 : if ( pWin )
538 : 0 : RemoveWindow( pWin, true );
539 : : }
540 : 0 : break;
541 : : case SID_BASICIDE_SHOWSBX:
542 : : {
543 : : DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
544 : 0 : const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
545 : 0 : ScriptDocument aDocument( rSbxItem.GetDocument() );
546 : 0 : ::rtl::OUString aLibName( rSbxItem.GetLibName() );
547 : 0 : ::rtl::OUString aName( rSbxItem.GetName() );
548 : 0 : SetCurLib( aDocument, aLibName );
549 : 0 : IDEBaseWindow* pWin = 0;
550 : 0 : if ( rSbxItem.GetType() == BASICIDE_TYPE_DIALOG )
551 : : {
552 : 0 : pWin = FindDlgWin( aDocument, aLibName, aName, true );
553 : : }
554 : 0 : else if ( rSbxItem.GetType() == BASICIDE_TYPE_MODULE )
555 : : {
556 : 0 : pWin = FindBasWin( aDocument, aLibName, aName, true );
557 : : }
558 : 0 : else if ( rSbxItem.GetType() == BASICIDE_TYPE_METHOD )
559 : : {
560 : 0 : pWin = FindBasWin( aDocument, aLibName, aName, true );
561 : 0 : ((ModulWindow*)pWin)->EditMacro( rSbxItem.GetMethodName() );
562 : : }
563 : : DBG_ASSERT( pWin, "Fenster wurde nicht erzeugt!" );
564 : 0 : SetCurWindow( pWin, true );
565 : 0 : pTabBar->MakeVisible( pTabBar->GetCurPageId() );
566 : : }
567 : 0 : break;
568 : : case SID_SHOW_PROPERTYBROWSER:
569 : : {
570 : 0 : GetViewFrame()->ChildWindowExecute( rReq );
571 : 0 : rReq.Done();
572 : : }
573 : 0 : break;
574 : : case SID_BASICIDE_SHOWWINDOW:
575 : : {
576 : 0 : ::std::auto_ptr< ScriptDocument > pDocument;
577 : :
578 : 0 : SFX_REQUEST_ARG( rReq, pDocumentItem, SfxStringItem, SID_BASICIDE_ARG_DOCUMENT, false );
579 : 0 : if ( pDocumentItem )
580 : : {
581 : 0 : ::rtl::OUString sDocumentCaption = pDocumentItem->GetValue();
582 : 0 : if ( !sDocumentCaption.isEmpty() )
583 : 0 : pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
584 : : }
585 : :
586 : 0 : SFX_REQUEST_ARG( rReq, pDocModelItem, SfxUsrAnyItem, SID_BASICIDE_ARG_DOCUMENT_MODEL, false );
587 : 0 : if ( !pDocument.get() && pDocModelItem )
588 : : {
589 : 0 : uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
590 : 0 : if ( xModel.is() )
591 : 0 : pDocument.reset( new ScriptDocument( xModel ) );
592 : : }
593 : :
594 : 0 : if ( !pDocument.get() )
595 : : break;
596 : :
597 : 0 : SFX_REQUEST_ARG( rReq, pLibNameItem, SfxStringItem, SID_BASICIDE_ARG_LIBNAME, false );
598 : 0 : if ( !pLibNameItem )
599 : : break;
600 : :
601 : 0 : ::rtl::OUString aLibName( pLibNameItem->GetValue() );
602 : 0 : pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
603 : 0 : SetCurLib( *pDocument, aLibName );
604 : 0 : SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_BASICIDE_ARG_NAME, false );
605 : 0 : if ( pNameItem )
606 : : {
607 : 0 : ::rtl::OUString aName( pNameItem->GetValue() );
608 : 0 : ::rtl::OUString aModType(RTL_CONSTASCII_USTRINGPARAM("Module"));
609 : 0 : ::rtl::OUString aDlgType(RTL_CONSTASCII_USTRINGPARAM("Dialog"));
610 : 0 : ::rtl::OUString aType( aModType );
611 : 0 : SFX_REQUEST_ARG( rReq, pTypeItem, SfxStringItem, SID_BASICIDE_ARG_TYPE, false );
612 : 0 : if ( pTypeItem )
613 : 0 : aType = pTypeItem->GetValue();
614 : :
615 : 0 : IDEBaseWindow* pWin = 0;
616 : 0 : if ( aType == aModType )
617 : 0 : pWin = FindBasWin( *pDocument, aLibName, aName, false );
618 : 0 : else if ( aType == aDlgType )
619 : 0 : pWin = FindDlgWin( *pDocument, aLibName, aName, false );
620 : :
621 : 0 : if ( pWin )
622 : : {
623 : 0 : SetCurWindow( pWin, true );
624 : 0 : if ( pTabBar )
625 : 0 : pTabBar->MakeVisible( pTabBar->GetCurPageId() );
626 : :
627 : 0 : if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
628 : : {
629 : 0 : SFX_REQUEST_ARG( rReq, pLineItem, SfxUInt32Item, SID_BASICIDE_ARG_LINE, false );
630 : 0 : if ( pLineItem )
631 : : {
632 : 0 : pModWin->AssertValidEditEngine();
633 : 0 : TextView* pTextView = pModWin->GetEditView();
634 : 0 : if ( pTextView )
635 : : {
636 : 0 : TextEngine* pTextEngine = pTextView->GetTextEngine();
637 : 0 : if ( pTextEngine )
638 : : {
639 : 0 : sal_uInt32 nLine = pLineItem->GetValue();
640 : 0 : sal_uInt32 nLineCount = 0;
641 : 0 : for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
642 : 0 : nLineCount += pTextEngine->GetLineCount( i );
643 : 0 : if ( nLine > nLineCount )
644 : 0 : nLine = nLineCount;
645 : 0 : if ( nLine > 0 )
646 : 0 : --nLine;
647 : :
648 : : // scroll window and set selection
649 : 0 : long nVisHeight = pModWin->GetOutputSizePixel().Height();
650 : 0 : long nTextHeight = pTextEngine->GetTextHeight();
651 : 0 : if ( nTextHeight > nVisHeight )
652 : : {
653 : 0 : long nMaxY = nTextHeight - nVisHeight;
654 : 0 : long nOldY = pTextView->GetStartDocPos().Y();
655 : 0 : long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
656 : 0 : nNewY = ::std::min( nNewY, nMaxY );
657 : 0 : pTextView->Scroll( 0, -( nNewY - nOldY ) );
658 : 0 : pTextView->ShowCursor( false, true );
659 : 0 : pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
660 : : }
661 : 0 : sal_uInt16 nCol1 = 0, nCol2 = 0;
662 : 0 : SFX_REQUEST_ARG( rReq, pCol1Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN1, false );
663 : 0 : if ( pCol1Item )
664 : : {
665 : 0 : nCol1 = pCol1Item->GetValue();
666 : 0 : if ( nCol1 > 0 )
667 : 0 : --nCol1;
668 : 0 : nCol2 = nCol1;
669 : : }
670 : 0 : SFX_REQUEST_ARG( rReq, pCol2Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN2, false );
671 : 0 : if ( pCol2Item )
672 : : {
673 : 0 : nCol2 = pCol2Item->GetValue();
674 : 0 : if ( nCol2 > 0 )
675 : 0 : --nCol2;
676 : : }
677 : 0 : TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
678 : 0 : pTextView->SetSelection( aSel );
679 : 0 : pTextView->ShowCursor();
680 : 0 : Window* pWindow_ = pTextView->GetWindow();
681 : 0 : if ( pWindow_ )
682 : 0 : pWindow_->GrabFocus();
683 : : }
684 : : }
685 : : }
686 : : }
687 : 0 : }
688 : : }
689 : 0 : rReq.Done();
690 : : }
691 : 0 : break;
692 : :
693 : : case SID_BASICIDE_MANAGE_LANG:
694 : : {
695 : 0 : ManageLanguageDialog aDlg(pCurWin, m_pCurLocalizationMgr);
696 : 0 : aDlg.Execute();
697 : 0 : rReq.Done();
698 : : }
699 : 0 : break;
700 : :
701 : : default:
702 : 0 : if (pCurWin)
703 : 0 : pCurWin->ExecuteGlobal(rReq);
704 : 0 : break;
705 : : }
706 : 0 : }
707 : :
708 : 0 : void BasicIDEShell::GetState(SfxItemSet &rSet)
709 : : {
710 : 0 : SfxWhichIter aIter(rSet);
711 : 0 : for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
712 : : {
713 : 0 : switch ( nWh )
714 : : {
715 : : case SID_DOCINFO:
716 : : {
717 : 0 : rSet.DisableItem( nWh );
718 : : }
719 : 0 : break;
720 : : case SID_SAVEDOC:
721 : : {
722 : 0 : bool bDisable = false;
723 : :
724 : 0 : if ( pCurWin )
725 : : {
726 : 0 : if ( !pCurWin->IsModified() )
727 : : {
728 : 0 : ScriptDocument aDocument( pCurWin->GetDocument() );
729 : 0 : bDisable = ( !aDocument.isAlive() )
730 : 0 : || ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
731 : : }
732 : : }
733 : : else
734 : : {
735 : 0 : bDisable = true;
736 : : }
737 : :
738 : 0 : if ( bDisable )
739 : 0 : rSet.DisableItem( nWh );
740 : : }
741 : 0 : break;
742 : : case SID_NEWWINDOW:
743 : : case SID_SAVEASDOC:
744 : : {
745 : 0 : rSet.DisableItem( nWh );
746 : : }
747 : 0 : break;
748 : : case SID_SIGNATURE:
749 : : {
750 : 0 : sal_uInt16 nState = 0;
751 : 0 : if ( pCurWin )
752 : : {
753 : 0 : ::basctl::DocumentSignature aSignature( pCurWin->GetDocument() );
754 : 0 : nState = aSignature.getScriptingSignatureState();
755 : : }
756 : 0 : rSet.Put( SfxUInt16Item( SID_SIGNATURE, nState ) );
757 : : }
758 : 0 : break;
759 : : case SID_BASICIDE_MODULEDLG:
760 : : {
761 : 0 : if ( StarBASIC::IsRunning() )
762 : 0 : rSet.DisableItem( nWh );
763 : : }
764 : 0 : break;
765 : : case SID_BASICIDE_OBJCAT:
766 : 0 : if (pLayout)
767 : 0 : rSet.Put(SfxBoolItem(nWh, aObjectCatalog.IsVisible()));
768 : : else
769 : 0 : rSet.Put(SfxVisibilityItem(nWh, false));
770 : 0 : break;
771 : : case SID_BASICIDE_SHOWSBX:
772 : : case SID_BASICIDE_CREATEMACRO:
773 : : case SID_BASICIDE_EDITMACRO:
774 : : case SID_BASICIDE_NAMECHANGEDONTAB:
775 : : {
776 : : ;
777 : : }
778 : 0 : break;
779 : :
780 : : case SID_BASICIDE_ADDWATCH:
781 : : case SID_BASICIDE_REMOVEWATCH:
782 : : case SID_BASICLOAD:
783 : : case SID_BASICSAVEAS:
784 : : case SID_BASICIDE_MATCHGROUP:
785 : : {
786 : 0 : if (!dynamic_cast<ModulWindow*>(pCurWin))
787 : 0 : rSet.DisableItem( nWh );
788 : 0 : else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
789 : 0 : rSet.DisableItem( nWh );
790 : : }
791 : 0 : break;
792 : : case SID_BASICRUN:
793 : : case SID_BASICSTEPINTO:
794 : : case SID_BASICSTEPOVER:
795 : : case SID_BASICSTEPOUT:
796 : : case SID_BASICIDE_TOGGLEBRKPNT:
797 : : case SID_BASICIDE_MANAGEBRKPNTS:
798 : : {
799 : 0 : if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin))
800 : : {
801 : 0 : if (StarBASIC::IsRunning() && !pMCurWin->GetBasicStatus().bIsInReschedule)
802 : 0 : rSet.DisableItem(nWh);
803 : : }
804 : : else
805 : 0 : rSet.DisableItem( nWh );
806 : : }
807 : 0 : break;
808 : : case SID_BASICCOMPILE:
809 : : {
810 : 0 : if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow*>(pCurWin))
811 : 0 : rSet.DisableItem( nWh );
812 : : }
813 : 0 : break;
814 : : case SID_BASICSTOP:
815 : : {
816 : : // stop is always possible when some Basic is running...
817 : 0 : if (!StarBASIC::IsRunning())
818 : 0 : rSet.DisableItem( nWh );
819 : : }
820 : 0 : break;
821 : : case SID_CHOOSE_CONTROLS:
822 : : case SID_DIALOG_TESTMODE:
823 : : case SID_INSERT_FORM_RADIO:
824 : : case SID_INSERT_FORM_CHECK:
825 : : case SID_INSERT_FORM_LIST:
826 : : case SID_INSERT_FORM_COMBO:
827 : : case SID_INSERT_FORM_VSCROLL:
828 : : case SID_INSERT_FORM_HSCROLL:
829 : : case SID_INSERT_FORM_SPIN:
830 : : {
831 : 0 : if (!dynamic_cast<DialogWindow*>(pCurWin))
832 : 0 : rSet.DisableItem( nWh );
833 : : }
834 : 0 : break;
835 : : case SID_SHOW_FORMS:
836 : : case SID_SHOW_HIDDEN:
837 : : {
838 : 0 : rSet.DisableItem( nWh );
839 : : }
840 : 0 : break;
841 : : case SID_SEARCH_OPTIONS:
842 : : {
843 : 0 : sal_uInt16 nOptions = 0;
844 : 0 : if( pCurWin )
845 : 0 : nOptions = pCurWin->GetSearchOptions();
846 : 0 : rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOptions ) );
847 : : }
848 : 0 : break;
849 : : case SID_BASICIDE_LIBSELECTOR:
850 : : {
851 : 0 : ::rtl::OUString aName;
852 : 0 : if ( !m_aCurLibName.isEmpty() )
853 : : {
854 : 0 : LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
855 : 0 : aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
856 : : }
857 : 0 : SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
858 : 0 : rSet.Put( aItem );
859 : : }
860 : 0 : break;
861 : : case SID_SEARCH_ITEM:
862 : : {
863 : 0 : ::rtl::OUString aSelected = GetSelectionText(true);
864 : 0 : SvxSearchItem& rItem = BasicIDEGlobals::GetExtraData()->GetSearchItem();
865 : 0 : rItem.SetSearchString( aSelected );
866 : 0 : rSet.Put( rItem );
867 : : }
868 : 0 : break;
869 : : case SID_BASICIDE_STAT_DATE:
870 : : {
871 : 0 : ::rtl::OUString aDate(RTL_CONSTASCII_USTRINGPARAM("Datum?!"));
872 : 0 : SfxStringItem aItem( SID_BASICIDE_STAT_DATE, aDate );
873 : 0 : rSet.Put( aItem );
874 : : }
875 : 0 : break;
876 : : case SID_DOC_MODIFIED:
877 : : {
878 : 0 : bool bModified = false;
879 : :
880 : 0 : if ( pCurWin )
881 : : {
882 : 0 : if ( pCurWin->IsModified() )
883 : 0 : bModified = true;
884 : : else
885 : : {
886 : 0 : ScriptDocument aDocument( pCurWin->GetDocument() );
887 : 0 : bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
888 : : }
889 : : }
890 : :
891 : 0 : SfxBoolItem aItem(SID_DOC_MODIFIED, bModified);
892 : 0 : rSet.Put( aItem );
893 : : }
894 : 0 : break;
895 : : case SID_BASICIDE_STAT_TITLE:
896 : : {
897 : 0 : if ( pCurWin )
898 : : {
899 : 0 : ::rtl::OUString aTitle = pCurWin->CreateQualifiedName();
900 : 0 : SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
901 : 0 : rSet.Put( aItem );
902 : : }
903 : : }
904 : 0 : break;
905 : : // are interpreted by the controller:
906 : : case SID_ATTR_SIZE:
907 : : case SID_ATTR_INSERT:
908 : 0 : break;
909 : : case SID_UNDO:
910 : : case SID_REDO:
911 : : {
912 : 0 : if( GetUndoManager() ) // recursive GetState else
913 : 0 : GetViewFrame()->GetSlotState( nWh, NULL, &rSet );
914 : : }
915 : 0 : break;
916 : : case SID_SHOW_PROPERTYBROWSER:
917 : : {
918 : 0 : if ( GetViewFrame()->KnowsChildWindow( nWh ) )
919 : 0 : rSet.Put( SfxBoolItem( nWh, GetViewFrame()->HasChildWindow( nWh ) ) );
920 : : else
921 : 0 : rSet.DisableItem( nWh );
922 : : }
923 : 0 : break;
924 : :
925 : : case SID_BASICIDE_CURRENT_LANG:
926 : : {
927 : 0 : if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
928 : 0 : rSet.DisableItem( nWh );
929 : : else
930 : : {
931 : 0 : ::rtl::OUString aItemStr;
932 : 0 : boost::shared_ptr<LocalizationMgr> pCurMgr(GetCurLocalizationMgr());
933 : 0 : if ( pCurMgr->isLibraryLocalized() )
934 : : {
935 : 0 : Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
936 : 0 : const lang::Locale* pLocale = aLocaleSeq.getConstArray();
937 : 0 : sal_Int32 i, nCount = aLocaleSeq.getLength();
938 : :
939 : : // Force different results for any combination of locales and default locale
940 : 0 : ::rtl::OUString aLangStr;
941 : 0 : for ( i = 0; i <= nCount; ++i )
942 : : {
943 : 0 : lang::Locale aLocale;
944 : 0 : if( i < nCount )
945 : 0 : aLocale = pLocale[i];
946 : : else
947 : 0 : aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
948 : :
949 : 0 : aLangStr += aLocale.Language;
950 : 0 : aLangStr += aLocale.Country;
951 : 0 : aLangStr += aLocale.Variant;
952 : 0 : }
953 : 0 : aItemStr = aLangStr;
954 : : }
955 : 0 : rSet.Put( SfxStringItem( nWh, aItemStr ) );
956 : : }
957 : : }
958 : 0 : break;
959 : :
960 : : case SID_BASICIDE_MANAGE_LANG:
961 : : {
962 : 0 : if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
963 : 0 : rSet.DisableItem( nWh );
964 : : }
965 : 0 : break;
966 : : case SID_GOTOLINE:
967 : : {
968 : : // if this is not a module window hide the
969 : : // setting, doesn't make sense for example if the
970 : : // dialog editor is open
971 : 0 : if (pCurWin && !dynamic_cast<ModulWindow*>(pCurWin))
972 : : {
973 : 0 : rSet.DisableItem( nWh );
974 : 0 : rSet.Put(SfxVisibilityItem(nWh, false));
975 : : }
976 : 0 : break;
977 : : }
978 : : default:
979 : 0 : if (pLayout)
980 : 0 : pLayout->GetState(rSet, nWh);
981 : : }
982 : : }
983 : 0 : if ( pCurWin )
984 : 0 : pCurWin->GetState( rSet );
985 : 0 : }
986 : :
987 : 0 : sal_Bool BasicIDEShell::HasUIFeature( sal_uInt32 nFeature )
988 : : {
989 : 0 : bool bResult = false;
990 : :
991 : 0 : if ( (nFeature & BASICIDE_UI_FEATURE_SHOW_BROWSER) == BASICIDE_UI_FEATURE_SHOW_BROWSER )
992 : : {
993 : : // fade out (in) property browser in module (dialog) windows
994 : 0 : if (dynamic_cast<DialogWindow*>(pCurWin) && !pCurWin->IsReadOnly())
995 : 0 : bResult = true;
996 : : }
997 : :
998 : 0 : return bResult;
999 : : }
1000 : :
1001 : 0 : void BasicIDEShell::SetCurWindow( IDEBaseWindow* pNewWin, bool bUpdateTabBar, bool bRememberAsCurrent )
1002 : : {
1003 : 0 : if ( pNewWin != pCurWin )
1004 : : {
1005 : 0 : pCurWin = pNewWin;
1006 : 0 : if (pLayout)
1007 : 0 : pLayout->Deactivating();
1008 : 0 : if (pCurWin)
1009 : : {
1010 : 0 : if (pCurWin->GetType() == BASICIDE_TYPE_MODULE)
1011 : 0 : pLayout = pModulLayout.get();
1012 : : else
1013 : 0 : pLayout = pDialogLayout.get();
1014 : 0 : AdjustPosSizePixel(Point(0, 0), GetViewFrame()->GetWindow().GetOutputSizePixel());
1015 : 0 : pLayout->Activating(*pCurWin);
1016 : 0 : GetViewFrame()->GetWindow().SetHelpId(pCurWin->GetHid());
1017 : 0 : if (bRememberAsCurrent)
1018 : 0 : pCurWin->InsertLibInfo();
1019 : 0 : if (GetViewFrame()->GetWindow().IsVisible()) // SFX will do it later otherwise
1020 : 0 : pCurWin->Show();
1021 : 0 : pCurWin->Init();
1022 : 0 : if ( !BasicIDEGlobals::GetExtraData()->ShellInCriticalSection() )
1023 : : {
1024 : 0 : Window* pFrameWindow = &GetViewFrame()->GetWindow();
1025 : 0 : Window* pFocusWindow = Application::GetFocusWindow();
1026 : 0 : while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
1027 : 0 : pFocusWindow = pFocusWindow->GetParent();
1028 : 0 : if ( pFocusWindow ) // Focus in BasicIDE
1029 : 0 : pNewWin->GrabFocus();
1030 : : }
1031 : : }
1032 : : else
1033 : 0 : pLayout = 0;
1034 : 0 : if ( bUpdateTabBar )
1035 : : {
1036 : 0 : sal_uLong nKey = GetIDEWindowId( pCurWin );
1037 : 0 : if ( pCurWin && ( pTabBar->GetPagePos( (sal_uInt16)nKey ) == TAB_PAGE_NOTFOUND ) )
1038 : 0 : pTabBar->InsertPage( (sal_uInt16)nKey, pCurWin->GetTitle() ); // has just been faded in
1039 : 0 : pTabBar->SetCurPageId( (sal_uInt16)nKey );
1040 : : }
1041 : 0 : if ( pCurWin && pCurWin->IsSuspended() ) // if the window is shown in the case of an error...
1042 : 0 : pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
1043 : 0 : if ( pCurWin )
1044 : : {
1045 : 0 : SetWindow( pCurWin );
1046 : 0 : if ( pCurWin->GetDocument().isDocument() )
1047 : 0 : SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
1048 : : }
1049 : 0 : else if (pLayout)
1050 : : {
1051 : 0 : SetWindow(pLayout);
1052 : 0 : GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1053 : 0 : SfxObjectShell::SetCurrentComponent(0);
1054 : : }
1055 : 0 : aObjectCatalog.SetCurrentEntry(pCurWin);
1056 : 0 : SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : 0 );
1057 : 0 : InvalidateBasicIDESlots();
1058 : 0 : EnableScrollbars(pCurWin != 0);
1059 : :
1060 : 0 : if ( m_pCurLocalizationMgr )
1061 : 0 : m_pCurLocalizationMgr->handleTranslationbar();
1062 : :
1063 : 0 : ManageToolbars();
1064 : :
1065 : : // fade out (in) property browser in module (dialog) windows
1066 : 0 : UIFeatureChanged();
1067 : : }
1068 : 0 : }
1069 : :
1070 : 0 : void BasicIDEShell::ManageToolbars()
1071 : : {
1072 : 0 : static ::rtl::OUString aLayoutManagerName( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
1073 : 0 : static ::rtl::OUString aMacroBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/macrobar" ));
1074 : 0 : static ::rtl::OUString aDialogBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/dialogbar" ));
1075 : 0 : static ::rtl::OUString aInsertControlsBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcontrolsbar" ));
1076 : 0 : static ::rtl::OUString aFormControlsBarResName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/formcontrolsbar" ));
1077 : : (void)aInsertControlsBarResName;
1078 : :
1079 : 0 : if( !pCurWin )
1080 : 0 : return;
1081 : :
1082 : : Reference< beans::XPropertySet > xFrameProps
1083 : 0 : ( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
1084 : 0 : if ( xFrameProps.is() )
1085 : : {
1086 : 0 : Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
1087 : 0 : uno::Any a = xFrameProps->getPropertyValue( aLayoutManagerName );
1088 : 0 : a >>= xLayoutManager;
1089 : 0 : if ( xLayoutManager.is() )
1090 : : {
1091 : 0 : xLayoutManager->lock();
1092 : 0 : if (dynamic_cast<DialogWindow*>(pCurWin))
1093 : : {
1094 : 0 : xLayoutManager->destroyElement( aMacroBarResName );
1095 : :
1096 : 0 : xLayoutManager->requestElement( aDialogBarResName );
1097 : 0 : xLayoutManager->requestElement( aInsertControlsBarResName );
1098 : 0 : xLayoutManager->requestElement( aFormControlsBarResName );
1099 : : }
1100 : : else
1101 : : {
1102 : 0 : xLayoutManager->destroyElement( aDialogBarResName );
1103 : 0 : xLayoutManager->destroyElement( aInsertControlsBarResName );
1104 : 0 : xLayoutManager->destroyElement( aFormControlsBarResName );
1105 : :
1106 : 0 : xLayoutManager->requestElement( aMacroBarResName );
1107 : : }
1108 : 0 : xLayoutManager->unlock();
1109 : 0 : }
1110 : 0 : }
1111 : : }
1112 : :
1113 : 0 : IDEBaseWindow* BasicIDEShell::FindApplicationWindow()
1114 : : {
1115 : 0 : return FindWindow( ScriptDocument::getApplicationScriptDocument() );
1116 : : }
1117 : :
1118 : 0 : IDEBaseWindow* BasicIDEShell::FindWindow(
1119 : : ScriptDocument const& rDocument,
1120 : : rtl::OUString const& rLibName, rtl::OUString const& rName,
1121 : : BasicIDEType eType, bool bFindSuspended
1122 : : )
1123 : : {
1124 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
1125 : : {
1126 : 0 : IDEBaseWindow* const pWin = it->second;
1127 : 0 : if (pWin->Is(rDocument, rLibName, rName, eType, bFindSuspended))
1128 : 0 : return pWin;
1129 : : }
1130 : 0 : return 0;
1131 : : }
1132 : :
1133 : 0 : long BasicIDEShell::CallBasicErrorHdl( StarBASIC* pBasic )
1134 : : {
1135 : 0 : long nRet = 0;
1136 : 0 : ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
1137 : 0 : if ( pModWin )
1138 : 0 : nRet = pModWin->BasicErrorHdl( pBasic );
1139 : 0 : return nRet;
1140 : : }
1141 : :
1142 : 0 : long BasicIDEShell::CallBasicBreakHdl( StarBASIC* pBasic )
1143 : : {
1144 : 0 : long nRet = 0;
1145 : 0 : ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
1146 : 0 : if ( pModWin )
1147 : : {
1148 : : bool bAppWindowDisabled, bDispatcherLocked;
1149 : : sal_uInt16 nWaitCount;
1150 : : SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
1151 : : BasicIDE::BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
1152 : 0 : &nWaitCount, &pSWActionCount, &pSWLockViewCount );
1153 : :
1154 : 0 : nRet = pModWin->BasicBreakHdl( pBasic );
1155 : :
1156 : 0 : if ( StarBASIC::IsRunning() ) // if cancelled...
1157 : : {
1158 : 0 : if ( bAppWindowDisabled )
1159 : 0 : Application::GetDefDialogParent()->Enable(false);
1160 : :
1161 : 0 : if ( nWaitCount )
1162 : : {
1163 : 0 : BasicIDEShell* pIDEShell = BasicIDEGlobals::GetShell();
1164 : 0 : for ( sal_uInt16 n = 0; n < nWaitCount; n++ )
1165 : 0 : pIDEShell->GetViewFrame()->GetWindow().EnterWait();
1166 : : }
1167 : : }
1168 : : }
1169 : 0 : return nRet;
1170 : : }
1171 : :
1172 : 0 : ModulWindow* BasicIDEShell::ShowActiveModuleWindow( StarBASIC* pBasic )
1173 : : {
1174 : 0 : SetCurLib( ScriptDocument::getApplicationScriptDocument(), ::rtl::OUString(), false );
1175 : :
1176 : 0 : SbModule* pActiveModule = StarBASIC::GetActiveModule();
1177 : 0 : if (SbClassModuleObject* pCMO = dynamic_cast<SbClassModuleObject*>(pActiveModule))
1178 : 0 : pActiveModule = pCMO->getClassModule();
1179 : :
1180 : : DBG_ASSERT( pActiveModule, "Kein aktives Modul im ErrorHdl?!" );
1181 : 0 : if ( pActiveModule )
1182 : : {
1183 : 0 : ModulWindow* pWin = 0;
1184 : 0 : SbxObject* pParent = pActiveModule->GetParent();
1185 : 0 : if (StarBASIC* pLib = dynamic_cast<StarBASIC*>(pParent))
1186 : : {
1187 : 0 : BasicManager* pBasMgr = BasicIDE::FindBasicManager( pLib );
1188 : 0 : if ( pBasMgr )
1189 : : {
1190 : 0 : ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
1191 : 0 : ::rtl::OUString aLibName = pLib->GetName();
1192 : 0 : pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), true );
1193 : : DBG_ASSERT( pWin, "Error/Step-Hdl: Fenster wurde nicht erzeugt/gefunden!" );
1194 : 0 : SetCurLib( aDocument, aLibName );
1195 : 0 : SetCurWindow( pWin, true );
1196 : : }
1197 : : }
1198 : : else
1199 : : DBG_ASSERT(false, "Kein BASIC!");
1200 : 0 : BasicManager* pBasicMgr = BasicIDE::FindBasicManager( pBasic );
1201 : 0 : if ( pBasicMgr )
1202 : 0 : StartListening( *pBasicMgr, true /* log on only once */ );
1203 : 0 : return pWin;
1204 : : }
1205 : 0 : return 0;
1206 : : }
1207 : :
1208 : 0 : void BasicIDEShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
1209 : : {
1210 : : // not if iconified because the whole text would be displaced then at restore
1211 : 0 : if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
1212 : 0 : return;
1213 : :
1214 : 0 : Size aSz( rSize );
1215 : 0 : Size aScrollBarBoxSz( aScrollBarBox.GetSizePixel() );
1216 : 0 : aSz.Height() -= aScrollBarBoxSz.Height();
1217 : :
1218 : 0 : Size aOutSz( aSz );
1219 : 0 : aSz.Width() -= aScrollBarBoxSz.Width();
1220 : 0 : aScrollBarBox.SetPosPixel( Point( rSize.Width() - aScrollBarBoxSz.Width(), rSize.Height() - aScrollBarBoxSz.Height() ) );
1221 : 0 : aVScrollBar.SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( aScrollBarBoxSz.Width(), aSz.Height() ) );
1222 : 0 : if ( bTabBarSplitted )
1223 : : {
1224 : : // SplitSize is 0 at a resize!
1225 : 0 : long nSplitPos = pTabBar->GetSizePixel().Width();
1226 : 0 : if ( nSplitPos > aSz.Width() )
1227 : 0 : nSplitPos = aSz.Width();
1228 : 0 : pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( nSplitPos, aScrollBarBoxSz.Height() ) );
1229 : 0 : long nScrlStart = rPos.X() + nSplitPos;
1230 : 0 : aHScrollBar.SetPosSizePixel( Point( nScrlStart, rPos.Y()+aSz.Height() ), Size( aSz.Width() - nScrlStart + 1, aScrollBarBoxSz.Height() ) );
1231 : 0 : aHScrollBar.Update();
1232 : : }
1233 : : else
1234 : : {
1235 : 0 : aHScrollBar.SetPosSizePixel( Point( rPos.X()+ aSz.Width()/2 - 1, rPos.Y()+aSz.Height() ), Size( aSz.Width()/2 + 2, aScrollBarBoxSz.Height() ) );
1236 : 0 : pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aSz.Width()/2, aScrollBarBoxSz.Height() ) );
1237 : : }
1238 : :
1239 : 0 : if (pLayout)
1240 : 0 : pLayout->SetPosSizePixel(rPos, dynamic_cast<DialogWindow*>(pCurWin) ? aSz : aOutSz);
1241 : : }
1242 : :
1243 : 0 : Reference< XModel > BasicIDEShell::GetCurrentDocument() const
1244 : : {
1245 : 0 : Reference< XModel > xDocument;
1246 : 0 : if ( pCurWin && pCurWin->GetDocument().isDocument() )
1247 : 0 : xDocument = pCurWin->GetDocument().getDocument();
1248 : 0 : return xDocument;
1249 : : }
1250 : :
1251 : 0 : void BasicIDEShell::Activate( sal_Bool bMDI )
1252 : : {
1253 : 0 : SfxViewShell::Activate( bMDI );
1254 : :
1255 : 0 : if ( bMDI )
1256 : : {
1257 : 0 : if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin))
1258 : 0 : pDCurWin->UpdateBrowser();
1259 : : }
1260 : 0 : }
1261 : :
1262 : 0 : void BasicIDEShell::Deactivate( sal_Bool bMDI )
1263 : : {
1264 : : // bMDI == true means that another MDI has been activated; in case of a
1265 : : // deactivate due to a MessageBox bMDI is false
1266 : 0 : if ( bMDI )
1267 : : {
1268 : 0 : if (DialogWindow* pXDlgWin = dynamic_cast<DialogWindow*>(pCurWin))
1269 : : {
1270 : 0 : pXDlgWin->DisableBrowser();
1271 : 0 : if( pXDlgWin->IsModified() )
1272 : 0 : BasicIDE::MarkDocumentModified( pXDlgWin->GetDocument() );
1273 : : }
1274 : :
1275 : : // test CanClose to also test during deactivating the BasicIDE whether
1276 : : // the sourcecode is too large in one of the modules...
1277 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
1278 : : {
1279 : 0 : IDEBaseWindow* pWin = it->second;
1280 : 0 : if ( /* !pWin->IsSuspended() && */ !pWin->CanClose() )
1281 : : {
1282 : 0 : if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
1283 : 0 : SetCurLib( ScriptDocument::getApplicationScriptDocument(), ::rtl::OUString(), false );
1284 : 0 : SetCurWindow( pWin, true );
1285 : 0 : break;
1286 : : }
1287 : : }
1288 : : }
1289 : 0 : }
1290 : :
1291 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|