1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basctl.hxx"
26 
27 
28 #include <vector>
29 #include <algorithm>
30 
31 #include <ide_pch.hxx>
32 
33 
34 #include <basic/sbx.hxx>
35 #include <helpid.hrc>
36 #include <basidesh.hrc>
37 #include <bastypes.hxx>
38 #include <bastype2.hxx>
39 #include <baside2.hxx>	// Leider brauche ich teilweise pModulWindow...
40 #include <baside3.hxx>
41 #include <baside2.hrc>
42 #include <svtools/textview.hxx>
43 #include <svtools/texteng.hxx>
44 #include <basobj.hxx>
45 #include <sbxitem.hxx>
46 #include <iderdll.hxx>
47 
48 #ifndef _PASSWD_HXX //autogen
49 #include <sfx2/passwd.hxx>
50 #endif
51 
52 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
53 #include <com/sun/star/script/XLibraryContainer2.hpp>
54 #endif
55 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
56 #include <com/sun/star/script/ModuleType.hpp>
57 
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star;
60 
61 
62 DBG_NAME( IDEBaseWindow )
63 
64 const char* pRegName = "BasicIDETabBar";
65 
66 TYPEINIT0( IDEBaseWindow )
67 TYPEINIT1( SbxItem, SfxPoolItem );
68 
IDEBaseWindow(Window * pParent,const ScriptDocument & rDocument,String aLibName,String aName)69 IDEBaseWindow::IDEBaseWindow( Window* pParent, const ScriptDocument& rDocument, String aLibName, String aName )
70     :Window( pParent, WinBits( WB_3DLOOK ) )
71 	,m_aDocument( rDocument )
72 	,m_aLibName( aLibName )
73 	,m_aName( aName )
74 {
75 	DBG_CTOR( IDEBaseWindow, 0 );
76 	pShellHScrollBar = 0;
77 	pShellVScrollBar = 0;
78 	nStatus	= 0;
79 }
80 
81 
82 
~IDEBaseWindow()83 __EXPORT IDEBaseWindow::~IDEBaseWindow()
84 {
85 	DBG_DTOR( IDEBaseWindow, 0 );
86 	if ( pShellVScrollBar )
87 		pShellVScrollBar->SetScrollHdl( Link() );
88 	if ( pShellHScrollBar )
89 		pShellHScrollBar->SetScrollHdl( Link() );
90 }
91 
92 
93 
Init()94 void IDEBaseWindow::Init()
95 {
96 	DBG_CHKTHIS( IDEBaseWindow, 0 );
97 	if ( pShellVScrollBar )
98 		pShellVScrollBar->SetScrollHdl( LINK( this, IDEBaseWindow, ScrollHdl ) );
99 	if ( pShellHScrollBar )
100 		pShellHScrollBar->SetScrollHdl( LINK( this, IDEBaseWindow, ScrollHdl ) );
101 	DoInit();	// virtuell...
102 }
103 
104 
105 
DoInit()106 void __EXPORT IDEBaseWindow::DoInit()
107 {
108 }
109 
110 
111 
GrabScrollBars(ScrollBar * pHScroll,ScrollBar * pVScroll)112 void IDEBaseWindow::GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll )
113 {
114 	DBG_CHKTHIS( IDEBaseWindow, 0 );
115 	pShellHScrollBar = pHScroll;
116 	pShellVScrollBar = pVScroll;
117 //	Init();	// macht kein Sinn, fuehrt zu flackern, fuehr zu Fehlern...
118 }
119 
120 
121 
IMPL_LINK_INLINE_START(IDEBaseWindow,ScrollHdl,ScrollBar *,pCurScrollBar)122 IMPL_LINK_INLINE_START( IDEBaseWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
123 {
124 	DBG_CHKTHIS( IDEBaseWindow, 0 );
125 	DoScroll( pCurScrollBar );
126 	return 0;
127 }
IMPL_LINK_INLINE_END(IDEBaseWindow,ScrollHdl,ScrollBar *,pCurScrollBar)128 IMPL_LINK_INLINE_END( IDEBaseWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
129 
130 
131 
132 void __EXPORT IDEBaseWindow::ExecuteCommand( SfxRequest& )
133 {
134 	DBG_CHKTHIS( IDEBaseWindow, 0 );
135 }
136 
137 
138 
GetState(SfxItemSet &)139 void __EXPORT IDEBaseWindow::GetState( SfxItemSet& )
140 {
141 	DBG_CHKTHIS( IDEBaseWindow, 0 );
142 }
143 
144 
Notify(NotifyEvent & rNEvt)145 long IDEBaseWindow::Notify( NotifyEvent& rNEvt )
146 {
147 	long nDone = 0;
148 
149 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
150 	{
151 		KeyEvent aKEvt = *rNEvt.GetKeyEvent();
152 		KeyCode aCode = aKEvt.GetKeyCode();
153 		sal_uInt16 nCode = aCode.GetCode();
154 
155 		switch ( nCode )
156 		{
157 			case KEY_PAGEUP:
158 			case KEY_PAGEDOWN:
159 			{
160 				if ( aCode.IsMod1() )
161 				{
162 					BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
163 					if ( pIDEShell )
164 						pIDEShell->NextPage( nCode == KEY_PAGEUP );
165 
166 					nDone = 1;
167 				}
168 			}
169 			break;
170 		}
171 	}
172 
173 	return nDone ? nDone : Window::Notify( rNEvt );
174 }
175 
176 
DoScroll(ScrollBar *)177 void __EXPORT IDEBaseWindow::DoScroll( ScrollBar* )
178 {
179 	DBG_CHKTHIS( IDEBaseWindow, 0 );
180 }
181 
182 
StoreData()183 void __EXPORT IDEBaseWindow::StoreData()
184 {
185 }
186 
CanClose()187 sal_Bool __EXPORT IDEBaseWindow::CanClose()
188 {
189 	return sal_True;
190 }
191 
AllowUndo()192 sal_Bool __EXPORT IDEBaseWindow::AllowUndo()
193 {
194 	return sal_True;
195 }
196 
197 
198 
UpdateData()199 void __EXPORT IDEBaseWindow::UpdateData()
200 {
201 }
202 
203 
GetTitle()204 String __EXPORT IDEBaseWindow::GetTitle()
205 {
206 	return String();
207 }
208 
209 
210 
CreateQualifiedName()211 String IDEBaseWindow::CreateQualifiedName()
212 {
213     String aName;
214     if ( m_aLibName.Len() )
215     {
216         LibraryLocation eLocation = m_aDocument.getLibraryLocation( m_aLibName );
217         aName = m_aDocument.getTitle( eLocation );
218         aName += '.';
219         aName += m_aLibName;
220         aName += '.';
221         aName += GetTitle();
222     }
223 
224 	return aName;
225 }
226 
SetReadOnly(sal_Bool)227 void IDEBaseWindow::SetReadOnly( sal_Bool )
228 {
229 }
230 
IsReadOnly()231 sal_Bool IDEBaseWindow::IsReadOnly()
232 {
233     return sal_False;
234 }
235 
BasicStarted()236 void __EXPORT IDEBaseWindow::BasicStarted()
237 {
238 }
239 
BasicStopped()240 void __EXPORT IDEBaseWindow::BasicStopped()
241 {
242 }
243 
IsModified()244 sal_Bool __EXPORT IDEBaseWindow::IsModified()
245 {
246 	return sal_True;
247 }
248 
IsPasteAllowed()249 sal_Bool __EXPORT IDEBaseWindow::IsPasteAllowed()
250 {
251     return sal_False;
252 }
253 
GetLayoutWindow()254 Window* __EXPORT IDEBaseWindow::GetLayoutWindow()
255 {
256 	return this;
257 }
258 
GetUndoManager()259 ::svl::IUndoManager* __EXPORT IDEBaseWindow::GetUndoManager()
260 {
261 	return NULL;
262 }
263 
BreakPointList()264 BreakPointList::BreakPointList()
265 {}
266 
BreakPointList(BreakPointList const & rList)267 BreakPointList::BreakPointList(BreakPointList const & rList):
268     BreakPL( sal::static_int_cast<sal_uInt16>( rList.Count() ))
269 {
270     for (sal_uLong i = 0; i < rList.Count(); ++i)
271         Insert(new BreakPoint(*rList.GetObject(i)), i);
272 }
273 
~BreakPointList()274 BreakPointList::~BreakPointList()
275 {
276     reset();
277 }
278 
reset()279 void BreakPointList::reset()
280 {
281     while (Count() > 0)
282         delete Remove(Count() - 1);
283 }
284 
transfer(BreakPointList & rList)285 void BreakPointList::transfer(BreakPointList & rList)
286 {
287     reset();
288     for (sal_uLong i = 0; i < rList.Count(); ++i)
289         Insert(rList.GetObject(i), i);
290     rList.Clear();
291 }
292 
InsertSorted(BreakPoint * pNewBrk)293 void BreakPointList::InsertSorted( BreakPoint* pNewBrk )
294 {
295 	BreakPoint* pBrk = First();
296 	while ( pBrk )
297 	{
298 		if ( pNewBrk->nLine <= pBrk->nLine )
299 		{
300 			DBG_ASSERT( ( pBrk->nLine != pNewBrk->nLine ) || pNewBrk->bTemp, "BreakPoint existiert schon!" );
301 			Insert( pNewBrk );
302 			return;
303 		}
304 		pBrk = Next();
305 	}
306 	// Keine Einfuegeposition gefunden => LIST_APPEND
307 	Insert( pNewBrk, LIST_APPEND );
308 }
309 
SetBreakPointsInBasic(SbModule * pModule)310 void BreakPointList::SetBreakPointsInBasic( SbModule* pModule )
311 {
312 	pModule->ClearAllBP();
313 
314 	BreakPoint* pBrk = First();
315 	while ( pBrk )
316 	{
317 		if ( pBrk->bEnabled )
318 			pModule->SetBP( (sal_uInt16)pBrk->nLine );
319 		pBrk = Next();
320 	}
321 }
322 
FindBreakPoint(sal_uLong nLine)323 BreakPoint*	BreakPointList::FindBreakPoint( sal_uLong nLine )
324 {
325 	BreakPoint* pBrk = First();
326 	while ( pBrk )
327 	{
328 		if ( pBrk->nLine == nLine )
329 			return pBrk;
330 
331 		pBrk = Next();
332 	}
333 
334 	return (BreakPoint*)0;
335 }
336 
337 
338 
AdjustBreakPoints(sal_uLong nLine,sal_Bool bInserted)339 void BreakPointList::AdjustBreakPoints( sal_uLong nLine, sal_Bool bInserted )
340 {
341 	BreakPoint* pBrk = First();
342 	while ( pBrk )
343 	{
344 		sal_Bool bDelBrk = sal_False;
345 		if ( pBrk->nLine == nLine )
346 		{
347 			if ( bInserted )
348 				pBrk->nLine++;
349 			else
350 				bDelBrk = sal_True;
351 		}
352 		else if ( pBrk->nLine > nLine )
353 		{
354 			if ( bInserted )
355 				pBrk->nLine++;
356 			else
357 				pBrk->nLine--;
358 		}
359 
360 		if ( bDelBrk )
361 		{
362 			sal_uLong n = GetCurPos();
363 			delete Remove( pBrk );
364 			pBrk = Seek( n );
365 		}
366 		else
367 		{
368 			pBrk = Next();
369 		}
370 	}
371 }
372 
ResetHitCount()373 void BreakPointList::ResetHitCount()
374 {
375 	BreakPoint* pBrk = First();
376 	while ( pBrk )
377 	{
378         pBrk->nHitCount = 0;
379 		pBrk = Next();
380 	}
381 }
382 
Deactivating()383 void IDEBaseWindow::Deactivating()
384 {
385 }
386 
GetSearchOptions()387 sal_uInt16 __EXPORT IDEBaseWindow::GetSearchOptions()
388 {
389 	return 0;
390 }
391 
392 
BasicDockingWindow(Window * pParent)393 BasicDockingWindow::BasicDockingWindow( Window* pParent ) :
394 	DockingWindow( pParent,	WB_BORDER | WB_3DLOOK | WB_DOCKABLE | WB_MOVEABLE |
395 							WB_SIZEABLE | WB_ROLLABLE |
396 							WB_DOCKABLE | WB_CLIPCHILDREN )
397 {
398 }
399 
400 
401 
Docking(const Point & rPos,Rectangle & rRect)402 sal_Bool __EXPORT BasicDockingWindow::Docking( const Point& rPos, Rectangle& rRect )
403 {
404 	ModulWindowLayout* pLayout = (ModulWindowLayout*)GetParent();
405 	Rectangle aTmpRec( rRect );
406 	sal_Bool bDock = IsDockingPrevented() ? sal_False : pLayout->IsToBeDocked( this, rPos, aTmpRec );
407 	if ( bDock )
408 	{
409 		rRect.SetSize( aTmpRec.GetSize() );
410 	}
411 	else	// Alte Groesse einstellen
412 	{
413 		if ( !aFloatingPosAndSize.IsEmpty() )
414 			rRect.SetSize( aFloatingPosAndSize.GetSize() );
415 	}
416 	return !bDock;	// bFloat
417 }
418 
419 
420 
EndDocking(const Rectangle & rRect,sal_Bool bFloatMode)421 void __EXPORT BasicDockingWindow::EndDocking( const Rectangle& rRect, sal_Bool bFloatMode )
422 {
423 	if ( bFloatMode )
424 		DockingWindow::EndDocking( rRect, bFloatMode );
425 	else
426 	{
427 		SetFloatingMode( sal_False );
428 		ModulWindowLayout* pLayout = (ModulWindowLayout*)GetParent();
429 		pLayout->DockaWindow( this );
430 	}
431 }
432 
433 
434 
ToggleFloatingMode()435 void __EXPORT BasicDockingWindow::ToggleFloatingMode()
436 {
437 	ModulWindowLayout* pLayout = (ModulWindowLayout*)GetParent();
438 	if ( IsFloatingMode() )
439 	{
440 		if ( !aFloatingPosAndSize.IsEmpty() )
441 			SetPosSizePixel( GetParent()->ScreenToOutputPixel( aFloatingPosAndSize.TopLeft() ),
442 				aFloatingPosAndSize.GetSize() );
443 	}
444 	pLayout->DockaWindow( this );
445 }
446 
447 
448 
PrepareToggleFloatingMode()449 sal_Bool __EXPORT BasicDockingWindow::PrepareToggleFloatingMode()
450 {
451 	if ( IsFloatingMode() )
452 	{
453 		// Position und Groesse auf dem Desktop merken...
454 		aFloatingPosAndSize.SetPos( GetParent()->OutputToScreenPixel( GetPosPixel() ) );
455 		aFloatingPosAndSize.SetSize( GetSizePixel() );
456 	}
457 	return sal_True;
458 }
459 
460 
461 
StartDocking()462 void __EXPORT BasicDockingWindow::StartDocking()
463 {
464 	// Position und Groesse auf dem Desktop merken...
465 	if ( IsFloatingMode() )
466 	{
467 		aFloatingPosAndSize.SetPos( GetParent()->OutputToScreenPixel( GetPosPixel() ) );
468 		aFloatingPosAndSize.SetSize( GetSizePixel() );
469 	}
470 }
471 
472 
473 
ExtendedEdit(Window * pParent,IDEResId nRes)474 ExtendedEdit::ExtendedEdit( Window* pParent, IDEResId nRes ) :
475 	Edit( pParent, nRes )
476 {
477 	aAcc.SetSelectHdl( LINK( this, ExtendedEdit, EditAccHdl ) );
478 	Control::SetGetFocusHdl( LINK( this, ExtendedEdit, ImplGetFocusHdl ) );
479 	Control::SetLoseFocusHdl( LINK( this, ExtendedEdit, ImplLoseFocusHdl ) );
480 }
481 
IMPL_LINK(ExtendedEdit,ImplGetFocusHdl,Control *,EMPTYARG)482 IMPL_LINK( ExtendedEdit, ImplGetFocusHdl, Control*, EMPTYARG )
483 {
484 	Application::InsertAccel( &aAcc );
485 	aLoseFocusHdl.Call( this );
486 	return 0;
487 }
488 
489 
IMPL_LINK(ExtendedEdit,ImplLoseFocusHdl,Control *,EMPTYARG)490 IMPL_LINK( ExtendedEdit, ImplLoseFocusHdl, Control*, EMPTYARG )
491 {
492 	Application::RemoveAccel( &aAcc );
493 	return 0;
494 }
495 
496 
IMPL_LINK_INLINE_START(ExtendedEdit,EditAccHdl,Accelerator *,pAcc)497 IMPL_LINK_INLINE_START( ExtendedEdit, EditAccHdl, Accelerator *, pAcc )
498 {
499 	aAccHdl.Call( pAcc );
500 	return 0;
501 }
502 IMPL_LINK_INLINE_END( ExtendedEdit, EditAccHdl, Accelerator *, pAcc )
503 
504 
505 
506 struct TabBarDDInfo
507 {
508 	sal_uLong 	npTabBar;
509 	sal_uInt16 	nPage;
510 
TabBarDDInfoTabBarDDInfo511 	TabBarDDInfo() { npTabBar = 0; nPage = 0; }
TabBarDDInfoTabBarDDInfo512 	TabBarDDInfo( sal_uLong _npTabBar, sal_uInt16 _nPage ) { npTabBar = _npTabBar; nPage = _nPage; }
513 };
514 
515 
BasicIDETabBar(Window * pParent)516 BasicIDETabBar::BasicIDETabBar( Window* pParent ) :
517 	TabBar( pParent, WinBits( WB_3DLOOK | WB_SCROLL | WB_BORDER | WB_SIZEABLE | WB_DRAG ) )
518 {
519 	EnableEditMode( sal_True );
520 
521 	SetHelpId( HID_BASICIDE_TABBAR );
522 }
523 
MouseButtonDown(const MouseEvent & rMEvt)524 void __EXPORT BasicIDETabBar::MouseButtonDown( const MouseEvent& rMEvt )
525 {
526 	if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) && !IsInEditMode() )
527 	{
528         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
529         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
530 	    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
531         if( pDispatcher )
532 		{
533 			pDispatcher->Execute( SID_BASICIDE_MODULEDLG );
534 		}
535 	}
536 	else
537 	{
538 		TabBar::MouseButtonDown( rMEvt );
539 	}
540 }
541 
Command(const CommandEvent & rCEvt)542 void __EXPORT BasicIDETabBar::Command( const CommandEvent& rCEvt )
543 {
544 	if ( ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) && !IsInEditMode() )
545 	{
546 		Point aPos( rCEvt.IsMouseEvent() ? rCEvt.GetMousePosPixel() : Point(1,1) );
547 		if ( rCEvt.IsMouseEvent() ) 	// Richtige Tab selektieren
548 		{
549 			Point aP = PixelToLogic( aPos );
550 			MouseEvent aMouseEvent( aP, 1, MOUSE_SIMPLECLICK, MOUSE_LEFT );
551 			TabBar::MouseButtonDown( aMouseEvent );
552 		}
553 
554         PopupMenu aPopup( IDEResId( RID_POPUP_TABBAR ) );
555 		if ( GetPageCount() == 0 )
556 		{
557 			aPopup.EnableItem( SID_BASICIDE_DELETECURRENT, sal_False );
558 			aPopup.EnableItem( SID_BASICIDE_RENAMECURRENT, sal_False );
559 			aPopup.EnableItem( SID_BASICIDE_HIDECURPAGE, sal_False );
560 		}
561 
562         if ( StarBASIC::IsRunning() )
563         {
564             aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
565             aPopup.EnableItem( SID_BASICIDE_RENAMECURRENT, false);
566             aPopup.EnableItem(SID_BASICIDE_MODULEDLG, false);
567         }
568 
569         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
570         if ( pIDEShell )
571         {
572             ScriptDocument aDocument( pIDEShell->GetCurDocument() );
573             ::rtl::OUString aOULibName( pIDEShell->GetCurLibName() );
574             Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
575             Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
576             if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
577                  ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
578             {
579                 aPopup.EnableItem( aPopup.GetItemId( 0 ), sal_False );
580                 aPopup.EnableItem( SID_BASICIDE_DELETECURRENT, sal_False );
581                 aPopup.EnableItem( SID_BASICIDE_RENAMECURRENT, sal_False );
582                 aPopup.RemoveDisabledEntries();
583             }
584 		 	if ( aDocument.isInVBAMode() )
585 			{
586 				// disable to delete or remove object modules in IDE
587 				BasicManager* pBasMgr = aDocument.getBasicManager();
588 				if ( pBasMgr )
589 				{
590 					StarBASIC* pBasic = pBasMgr->GetLib( aOULibName );
591 					if( pBasic )
592 					{
593 						IDEWindowTable& aIDEWindowTable = pIDEShell->GetIDEWindowTable();
594 						IDEBaseWindow* pWin = aIDEWindowTable.Get( GetCurPageId() );
595 						if( pWin && pWin->ISA( ModulWindow ) )
596 						{
597 							SbModule* pActiveModule = (SbModule*)pBasic->FindModule( pWin->GetName() );
598 							if( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
599 							{
600 								aPopup.EnableItem( SID_BASICIDE_DELETECURRENT, sal_False );
601 								aPopup.EnableItem( SID_BASICIDE_RENAMECURRENT, sal_False );
602 	        				}
603 						}
604 					}
605 				}
606 			}
607         }
608 
609 
610         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
611 	    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
612         if ( pDispatcher )
613 			pDispatcher->Execute( aPopup.Execute( this, aPos ) );
614     }
615 }
616 
AllowRenaming()617 long BasicIDETabBar::AllowRenaming()
618 {
619 	sal_Bool bValid = BasicIDE::IsValidSbxName( GetEditText() );
620 
621 	if ( !bValid )
622 		ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute();
623 
624     return bValid ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
625 }
626 
627 
EndRenaming()628 void __EXPORT BasicIDETabBar::EndRenaming()
629 {
630 	if ( !IsEditModeCanceled() )
631 	{
632 		SfxUInt16Item aID( SID_BASICIDE_ARG_TABID, GetEditPageId() );
633 		SfxStringItem aNewName( SID_BASICIDE_ARG_MODULENAME, GetEditText() );
634         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
635         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
636 	    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
637         if( pDispatcher )
638 		{
639 			pDispatcher->Execute( SID_BASICIDE_NAMECHANGEDONTAB,
640 								  SFX_CALLMODE_SYNCHRON, &aID, &aNewName, 0L );
641 		}
642 	}
643 }
644 
645 
Sort()646 void BasicIDETabBar::Sort()
647 {
648 	BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
649 	if ( pIDEShell )
650 	{
651 		IDEWindowTable& aIDEWindowTable = pIDEShell->GetIDEWindowTable();
652 		TabBarSortHelper aTabBarSortHelper;
653 		::std::vector<TabBarSortHelper> aModuleList;
654 		::std::vector<TabBarSortHelper> aDialogList;
655 		sal_uInt16 nPageCount = GetPageCount();
656 		sal_uInt16 i;
657 
658 		// create module and dialog lists for sorting
659 		for ( i = 0; i < nPageCount; i++)
660 		{
661 			sal_uInt16 nId = GetPageId( i );
662 			aTabBarSortHelper.nPageId = nId;
663 			aTabBarSortHelper.aPageText = GetPageText( nId );
664 			IDEBaseWindow* pWin = aIDEWindowTable.Get( nId );
665 
666 			if ( pWin->IsA( TYPE( ModulWindow ) ) )
667 			{
668 				aModuleList.push_back( aTabBarSortHelper );
669 			}
670 			else if ( pWin->IsA( TYPE( DialogWindow ) ) )
671 			{
672 				aDialogList.push_back( aTabBarSortHelper );
673 			}
674 		}
675 
676 		// sort module and dialog lists by page text
677 		::std::sort( aModuleList.begin() , aModuleList.end() );
678 		::std::sort( aDialogList.begin() , aDialogList.end() );
679 
680 
681 		sal_uInt16 nModules = sal::static_int_cast<sal_uInt16>( aModuleList.size() );
682 		sal_uInt16 nDialogs = sal::static_int_cast<sal_uInt16>( aDialogList.size() );
683 
684 		// move module pages to new positions
685 		for (i = 0; i < nModules; i++)
686 		{
687 			MovePage( aModuleList[i].nPageId , i );
688 		}
689 
690 		// move dialog pages to new positions
691 		for (i = 0; i < nDialogs; i++)
692 		{
693 			MovePage( aDialogList[i].nPageId , nModules + i );
694 		}
695 	}
696 }
697 
CutLines(::rtl::OUString & rStr,sal_Int32 nStartLine,sal_Int32 nLines,sal_Bool bEraseTrailingEmptyLines)698 void CutLines( ::rtl::OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, sal_Bool bEraseTrailingEmptyLines )
699 {
700 	sal_Int32 nStartPos = 0;
701 	sal_Int32 nEndPos = 0;
702 	sal_Int32 nLine = 0;
703 	while ( nLine < nStartLine )
704 	{
705 		nStartPos = searchEOL( rStr, nStartPos );
706         if( nStartPos == -1 )
707             break;
708 		nStartPos++;	// nicht das \n.
709 		nLine++;
710 	}
711 
712 	DBG_ASSERTWARNING( nStartPos != -1, "CutLines: Startzeile nicht gefunden!" );
713 
714 	if ( nStartPos != -1 )
715 	{
716 		nEndPos = nStartPos;
717 		for ( sal_Int32 i = 0; i < nLines; i++ )
718 			nEndPos = searchEOL( rStr, nEndPos+1 );
719 
720 		if ( nEndPos == -1 ) // kann bei letzter Zeile passieren
721 			nEndPos = rStr.getLength();
722         else
723 			nEndPos++;
724 
725         ::rtl::OUString aEndStr = rStr.copy( nEndPos );
726         rStr = rStr.copy( 0, nStartPos );
727         rStr += aEndStr;
728 	}
729 	if ( bEraseTrailingEmptyLines )
730 	{
731 		sal_Int32 n = nStartPos;
732 		sal_Int32 nLen = rStr.getLength();
733 		while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ||
734 								  rStr.getStr()[ n ] == LINE_SEP_CR ) )
735 		{
736 			n++;
737 		}
738 
739 		if ( n > nStartPos )
740         {
741             ::rtl::OUString aEndStr = rStr.copy( n );
742             rStr = rStr.copy( 0, nStartPos );
743             rStr += aEndStr;
744         }
745 	}
746 }
747 
CalcLineCount(SvStream & rStream)748 sal_uLong CalcLineCount( SvStream& rStream )
749 {
750 	sal_uLong nLFs = 0;
751 	sal_uLong nCRs = 0;
752 	char c;
753 
754 	rStream.Seek( 0 );
755 	rStream >> c;
756 	while ( !rStream.IsEof() )
757 	{
758 		if ( c == '\n' )
759 			nLFs++;
760 		else if ( c == '\r' )
761 			nCRs++;
762 		rStream >> c;
763 	}
764 
765 	rStream.Seek( 0 );
766 	if ( nLFs > nCRs )
767 		return nLFs;
768 	return nCRs;
769 }
770 
LibInfoKey(const ScriptDocument & rDocument,const String & rLibName)771 LibInfoKey::LibInfoKey( const ScriptDocument& rDocument, const String& rLibName )
772     :m_aDocument( rDocument )
773     ,m_aLibName( rLibName )
774 {
775 }
776 
~LibInfoKey()777 LibInfoKey::~LibInfoKey()
778 {
779 }
780 
LibInfoKey(const LibInfoKey & rKey)781 LibInfoKey::LibInfoKey( const LibInfoKey& rKey )
782     :m_aDocument( rKey.m_aDocument )
783     ,m_aLibName( rKey.m_aLibName )
784 {
785 }
786 
operator =(const LibInfoKey & rKey)787 LibInfoKey& LibInfoKey::operator=( const LibInfoKey& rKey )
788 {
789     m_aDocument = rKey.m_aDocument;
790     m_aLibName = rKey.m_aLibName;
791     return *this;
792 }
793 
operator ==(const LibInfoKey & rKey) const794 bool LibInfoKey::operator==( const LibInfoKey& rKey ) const
795 {
796 	bool bRet = false;
797     if ( m_aDocument == rKey.m_aDocument && m_aLibName == rKey.m_aLibName )
798 		bRet = true;
799 	return bRet;
800 }
801 
LibInfoItem(const ScriptDocument & rDocument,const String & rLibName,const String & rCurrentName,sal_uInt16 nCurrentType)802 LibInfoItem::LibInfoItem( const ScriptDocument& rDocument, const String& rLibName, const String& rCurrentName, sal_uInt16 nCurrentType )
803     :m_aDocument( rDocument )
804     ,m_aLibName( rLibName )
805     ,m_aCurrentName( rCurrentName )
806     ,m_nCurrentType( nCurrentType )
807 {
808 }
809 
~LibInfoItem()810 LibInfoItem::~LibInfoItem()
811 {
812 }
813 
LibInfoItem(const LibInfoItem & rItem)814 LibInfoItem::LibInfoItem( const LibInfoItem& rItem )
815     :m_aDocument( rItem.m_aDocument )
816     ,m_aLibName( rItem.m_aLibName )
817     ,m_aCurrentName( rItem.m_aCurrentName )
818     ,m_nCurrentType( rItem.m_nCurrentType )
819 {
820 }
821 
operator =(const LibInfoItem & rItem)822 LibInfoItem& LibInfoItem::operator=( const LibInfoItem& rItem )
823 {
824     m_aDocument = rItem.m_aDocument;
825     m_aLibName = rItem.m_aLibName;
826     m_aCurrentName = rItem.m_aCurrentName;
827     m_nCurrentType = rItem.m_nCurrentType;
828 
829     return *this;
830 }
831 
LibInfos()832 LibInfos::LibInfos()
833 {
834 }
835 
~LibInfos()836 LibInfos::~LibInfos()
837 {
838     LibInfoMap::iterator end = m_aLibInfoMap.end();
839     for ( LibInfoMap::iterator it = m_aLibInfoMap.begin(); it != end; ++it )
840         delete it->second;
841     m_aLibInfoMap.clear();
842 }
843 
InsertInfo(LibInfoItem * pItem)844 void LibInfos::InsertInfo( LibInfoItem* pItem )
845 {
846     LibInfoKey aKey( pItem->GetDocument(), pItem->GetLibName() );
847     LibInfoMap::iterator it = m_aLibInfoMap.find( aKey );
848     if ( it != m_aLibInfoMap.end() )
849     {
850         LibInfoItem* pI = it->second;
851         m_aLibInfoMap.erase( it );
852         delete pI;
853     }
854     m_aLibInfoMap.insert( LibInfoMap::value_type( aKey, pItem ) );
855 }
856 
RemoveInfoFor(const ScriptDocument & _rDocument)857 void LibInfos::RemoveInfoFor( const ScriptDocument& _rDocument )
858 {
859     for (   LibInfoMap::iterator it = m_aLibInfoMap.begin();
860             it != m_aLibInfoMap.end();
861         )
862     {
863         if ( it->first.GetDocument() != _rDocument )
864         {
865             ++it;
866             continue;
867         }
868 
869         LibInfoItem* pItem = it->second;
870 
871         LibInfoMap::iterator next_it = it; ++next_it;
872         m_aLibInfoMap.erase( it );
873         it = next_it;
874 
875         delete pItem;
876     }
877 }
878 
GetInfo(const LibInfoKey & rKey)879 LibInfoItem* LibInfos::GetInfo( const LibInfoKey& rKey )
880 {
881     LibInfoItem* pItem = 0;
882     LibInfoMap::iterator it = m_aLibInfoMap.find( rKey );
883     if ( it != m_aLibInfoMap.end() )
884         pItem = it->second;
885     return pItem;
886 }
887 
SbxItem(sal_uInt16 nWhich_,const ScriptDocument & rDocument,const String & aLibName,const String & aName,sal_uInt16 nType)888 SbxItem::SbxItem(sal_uInt16 nWhich_, const ScriptDocument& rDocument, const String& aLibName, const String& aName, sal_uInt16 nType )
889 	:SfxPoolItem( nWhich_ )
890 	,m_aDocument(rDocument)
891 	,m_aLibName(aLibName)
892 	,m_aName(aName)
893 	,m_nType(nType)
894 {
895 }
896 
SbxItem(sal_uInt16 nWhich_,const ScriptDocument & rDocument,const String & aLibName,const String & aName,const String & aMethodName,sal_uInt16 nType)897 SbxItem::SbxItem(sal_uInt16 nWhich_, const ScriptDocument& rDocument, const String& aLibName, const String& aName, const String& aMethodName, sal_uInt16 nType )
898 	:SfxPoolItem( nWhich_ )
899 	,m_aDocument(rDocument)
900 	,m_aLibName(aLibName)
901 	,m_aName(aName)
902 	,m_aMethodName(aMethodName)
903 	,m_nType(nType)
904 {
905 }
906 
SbxItem(const SbxItem & rCopy)907 SbxItem::SbxItem(const SbxItem& rCopy)
908     :SfxPoolItem( rCopy )
909     ,m_aDocument( rCopy.m_aDocument )
910 {
911 	m_aLibName = rCopy.m_aLibName;
912 	m_aName = rCopy.m_aName;
913 	m_aMethodName = rCopy.m_aMethodName;
914 	m_nType = rCopy.m_nType;
915 }
916 
operator ==(const SfxPoolItem & rCmp) const917 int SbxItem::operator==( const SfxPoolItem& rCmp) const
918 {
919 	DBG_ASSERT( rCmp.ISA( SbxItem ), "==: Kein SbxItem!" );
920 	return ( SfxPoolItem::operator==( rCmp ) && ( m_aDocument == ((const SbxItem&)rCmp).m_aDocument )
921 											 && ( m_aLibName == ((const SbxItem&)rCmp).m_aLibName )
922 											 && ( m_aName == ((const SbxItem&)rCmp).m_aName )
923 											 && ( m_aMethodName == ((const SbxItem&)rCmp).m_aMethodName )
924 											 && ( m_nType == ((const SbxItem&)rCmp).m_nType ) );
925 }
926 
Clone(SfxItemPool *) const927 SfxPoolItem *SbxItem::Clone( SfxItemPool* ) const
928 {
929 	return new SbxItem(*this);
930 }
931 
QueryDel(const String & rName,const ResId & rId,Window * pParent)932 sal_Bool QueryDel( const String& rName, const ResId& rId, Window* pParent )
933 {
934 	String aQuery( rId );
935 	String aName( rName );
936 	aName += '\'';
937 	aName.Insert( '\'', 0 );
938 	aQuery.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aName );
939 	QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_YES, aQuery );
940 	if ( aQueryBox.Execute() == RET_YES )
941 		return sal_True;
942 	return sal_False;
943 }
944 
QueryDelMacro(const String & rName,Window * pParent)945 sal_Bool QueryDelMacro( const String& rName, Window* pParent )
946 {
947 	return QueryDel( rName, IDEResId( RID_STR_QUERYDELMACRO ), pParent );
948 }
949 
QueryReplaceMacro(const String & rName,Window * pParent)950 sal_Bool QueryReplaceMacro( const String& rName, Window* pParent )
951 {
952     return QueryDel( rName, IDEResId( RID_STR_QUERYREPLACEMACRO ), pParent );
953 }
954 
QueryDelDialog(const String & rName,Window * pParent)955 sal_Bool QueryDelDialog( const String& rName, Window* pParent )
956 {
957 	return QueryDel( rName, IDEResId( RID_STR_QUERYDELDIALOG ), pParent );
958 }
959 
QueryDelLib(const String & rName,sal_Bool bRef,Window * pParent)960 sal_Bool QueryDelLib( const String& rName, sal_Bool bRef, Window* pParent )
961 {
962 	return QueryDel( rName, IDEResId( bRef ? RID_STR_QUERYDELLIBREF : RID_STR_QUERYDELLIB ), pParent );
963 }
964 
QueryDelModule(const String & rName,Window * pParent)965 sal_Bool QueryDelModule( const String& rName, Window* pParent )
966 {
967 	return QueryDel( rName, IDEResId( RID_STR_QUERYDELMODULE ), pParent );
968 }
969 
QueryPassword(const Reference<script::XLibraryContainer> & xLibContainer,const String & rLibName,String & rPassword,sal_Bool bRepeat,sal_Bool bNewTitle)970 sal_Bool QueryPassword( const Reference< script::XLibraryContainer >& xLibContainer, const String& rLibName, String& rPassword, sal_Bool bRepeat, sal_Bool bNewTitle )
971 {
972 	sal_Bool bOK = sal_False;
973     sal_uInt16 nRet = 0;
974 
975     do
976     {
977         // password dialog
978 	    SfxPasswordDialog* pDlg = new SfxPasswordDialog( Application::GetDefDialogParent() );
979 	    pDlg->SetMinLen( 1 );
980 
981         // set new title
982         if ( bNewTitle )
983         {
984             String aTitle( IDEResId( RID_STR_ENTERPASSWORD ) );
985 			aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), rLibName );
986             pDlg->SetText( aTitle );
987         }
988 
989         // execute dialog
990         nRet = pDlg->Execute();
991 
992         // verify password
993         if ( nRet == RET_OK )
994 	    {
995             ::rtl::OUString aOULibName( rLibName );
996             if ( xLibContainer.is() && xLibContainer->hasByName( aOULibName ) )
997             {
998                 Reference< script::XLibraryContainerPassword > xPasswd( xLibContainer, UNO_QUERY );
999                 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aOULibName ) && !xPasswd->isLibraryPasswordVerified( aOULibName ) )
1000                 {
1001                     rPassword = pDlg->GetPassword();
1002                     ::rtl::OUString aOUPassword( rPassword );
1003                     bOK = xPasswd->verifyLibraryPassword( aOULibName, aOUPassword );
1004 
1005                     if ( !bOK )
1006                     {
1007 			            ErrorBox aErrorBox( Application::GetDefDialogParent(), WB_OK, String( IDEResId( RID_STR_WRONGPASSWORD ) ) );
1008 			            aErrorBox.Execute();
1009                     }
1010                 }
1011             }
1012         }
1013 
1014     	delete pDlg;
1015     }
1016     while ( bRepeat && !bOK && nRet == RET_OK );
1017 
1018     return bOK;
1019 }
1020 
1021