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 "basidesh.hrc"
21 : #include "helpid.hrc"
22 :
23 : #include "baside2.hxx"
24 : #include "baside3.hxx"
25 : #include "iderdll.hxx"
26 : #include "iderdll2.hxx"
27 :
28 : #include <basic/basmgr.hxx>
29 : #include <com/sun/star/script/ModuleType.hpp>
30 : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
31 : #include <sfx2/dispatch.hxx>
32 : #include <sfx2/passwd.hxx>
33 : #include <svl/intitem.hxx>
34 : #include <svl/stritem.hxx>
35 : #include <svl/srchdefs.hxx>
36 :
37 : namespace basctl
38 : {
39 :
40 : using namespace ::com::sun::star::uno;
41 : using namespace ::com::sun::star;
42 :
43 0 : TYPEINIT0( BaseWindow )
44 0 : TYPEINIT1( SbxItem, SfxPoolItem );
45 :
46 0 : BaseWindow::BaseWindow( vcl::Window* pParent, const ScriptDocument& rDocument, const OUString& aLibName, const OUString& aName )
47 : :Window( pParent, WinBits( WB_3DLOOK ) )
48 : ,m_aDocument( rDocument )
49 : ,m_aLibName( aLibName )
50 0 : ,m_aName( aName )
51 : {
52 0 : pShellHScrollBar = 0;
53 0 : pShellVScrollBar = 0;
54 0 : nStatus = 0;
55 0 : }
56 :
57 0 : BaseWindow::~BaseWindow()
58 : {
59 0 : disposeOnce();
60 0 : }
61 :
62 0 : void BaseWindow::dispose()
63 : {
64 0 : if ( pShellVScrollBar )
65 0 : pShellVScrollBar->SetScrollHdl( Link<>() );
66 0 : if ( pShellHScrollBar )
67 0 : pShellHScrollBar->SetScrollHdl( Link<>() );
68 0 : pShellVScrollBar.clear();
69 0 : pShellHScrollBar.clear();
70 0 : vcl::Window::dispose();
71 0 : }
72 :
73 :
74 :
75 0 : void BaseWindow::Init()
76 : {
77 0 : if ( pShellVScrollBar )
78 0 : pShellVScrollBar->SetScrollHdl( LINK( this, BaseWindow, ScrollHdl ) );
79 0 : if ( pShellHScrollBar )
80 0 : pShellHScrollBar->SetScrollHdl( LINK( this, BaseWindow, ScrollHdl ) );
81 0 : DoInit(); // virtual...
82 0 : }
83 :
84 :
85 :
86 0 : void BaseWindow::DoInit()
87 0 : { }
88 :
89 :
90 :
91 0 : void BaseWindow::GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll )
92 : {
93 0 : pShellHScrollBar = pHScroll;
94 0 : pShellVScrollBar = pVScroll;
95 : // Init(); // does not make sense, leads to flickering and errors...
96 0 : }
97 :
98 :
99 :
100 0 : IMPL_LINK( BaseWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
101 : {
102 0 : DoScroll( pCurScrollBar );
103 0 : return 0;
104 : }
105 :
106 0 : void BaseWindow::ExecuteCommand (SfxRequest&)
107 0 : { }
108 :
109 0 : void BaseWindow::ExecuteGlobal (SfxRequest&)
110 0 : { }
111 :
112 :
113 0 : bool BaseWindow::Notify( NotifyEvent& rNEvt )
114 : {
115 0 : bool nDone = false;
116 :
117 0 : if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
118 : {
119 0 : KeyEvent aKEvt = *rNEvt.GetKeyEvent();
120 0 : vcl::KeyCode aCode = aKEvt.GetKeyCode();
121 0 : sal_uInt16 nCode = aCode.GetCode();
122 :
123 0 : switch ( nCode )
124 : {
125 : case KEY_PAGEUP:
126 : case KEY_PAGEDOWN:
127 : {
128 0 : if ( aCode.IsMod1() )
129 : {
130 0 : if (Shell* pShell = GetShell())
131 0 : pShell->NextPage( nCode == KEY_PAGEUP );
132 0 : nDone = true;
133 : }
134 : }
135 0 : break;
136 : }
137 : }
138 :
139 0 : return nDone || Window::Notify( rNEvt );
140 : }
141 :
142 :
143 0 : void BaseWindow::DoScroll( ScrollBar* )
144 : {
145 0 : }
146 :
147 :
148 0 : void BaseWindow::StoreData()
149 : {
150 0 : }
151 :
152 0 : bool BaseWindow::CanClose()
153 : {
154 0 : return true;
155 : }
156 :
157 0 : bool BaseWindow::AllowUndo()
158 : {
159 0 : return true;
160 : }
161 :
162 :
163 :
164 0 : void BaseWindow::UpdateData()
165 : {
166 0 : }
167 :
168 0 : OUString BaseWindow::GetTitle()
169 : {
170 0 : return OUString();
171 : }
172 :
173 0 : OUString BaseWindow::CreateQualifiedName()
174 : {
175 0 : OUString aName;
176 0 : if ( !m_aLibName.isEmpty() )
177 : {
178 0 : LibraryLocation eLocation = m_aDocument.getLibraryLocation( m_aLibName );
179 0 : aName = m_aDocument.getTitle(eLocation) + "." + m_aLibName + "." +
180 0 : GetTitle();
181 : }
182 0 : return aName;
183 : }
184 :
185 0 : void BaseWindow::SetReadOnly (bool)
186 : {
187 0 : }
188 :
189 0 : bool BaseWindow::IsReadOnly ()
190 : {
191 0 : return false;
192 : }
193 :
194 0 : void BaseWindow::BasicStarted()
195 : {
196 0 : }
197 :
198 0 : void BaseWindow::BasicStopped()
199 : {
200 0 : }
201 :
202 0 : bool BaseWindow::IsModified ()
203 : {
204 0 : return true;
205 : }
206 :
207 0 : bool BaseWindow::IsPasteAllowed ()
208 : {
209 0 : return false;
210 : }
211 :
212 0 : ::svl::IUndoManager* BaseWindow::GetUndoManager()
213 : {
214 0 : return NULL;
215 : }
216 :
217 0 : SearchOptionFlags BaseWindow::GetSearchOptions()
218 : {
219 0 : return SearchOptionFlags::NONE;
220 : }
221 :
222 0 : sal_uInt16 BaseWindow::StartSearchAndReplace (SvxSearchItem const&, bool bFromStart)
223 : {
224 : static_cast<void>(bFromStart);
225 0 : return 0;
226 : }
227 :
228 0 : void BaseWindow::OnNewDocument ()
229 0 : { }
230 :
231 0 : void BaseWindow::InsertLibInfo () const
232 : {
233 0 : if (ExtraData* pData = GetExtraData())
234 0 : pData->GetLibInfos().InsertInfo(m_aDocument, m_aLibName, m_aName, GetType());
235 0 : }
236 :
237 0 : bool BaseWindow::Is (
238 : ScriptDocument const& rDocument,
239 : OUString const& rLibName, OUString const& rName,
240 : ItemType eType, bool bFindSuspended
241 : )
242 : {
243 0 : if (bFindSuspended || !IsSuspended())
244 : {
245 : // any non-suspended window is ok
246 0 : if (rLibName.isEmpty() || rName.isEmpty() || eType == TYPE_UNKNOWN)
247 0 : return true;
248 : // ok if the parameters match
249 0 : if (m_aDocument == rDocument && m_aLibName == rLibName && m_aName == rName && GetType() == eType)
250 0 : return true;
251 : }
252 0 : return false;
253 : }
254 :
255 0 : bool BaseWindow::HasActiveEditor () const
256 : {
257 0 : return false;
258 : }
259 :
260 :
261 :
262 : // DockingWindow
263 :
264 :
265 :
266 : // style bits for DockingWindow
267 : WinBits const DockingWindow::StyleBits =
268 : WB_BORDER | WB_3DLOOK | WB_CLIPCHILDREN |
269 : WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_DOCKABLE;
270 :
271 0 : DockingWindow::DockingWindow (vcl::Window* pParent) :
272 : ::DockingWindow(pParent, StyleBits),
273 : pLayout(0),
274 0 : nShowCount(0)
275 0 : { }
276 :
277 0 : DockingWindow::DockingWindow (Layout* pParent) :
278 : ::DockingWindow(pParent, StyleBits),
279 : pLayout(pParent),
280 0 : nShowCount(0)
281 0 : { }
282 :
283 0 : DockingWindow::~DockingWindow()
284 : {
285 0 : disposeOnce();
286 0 : }
287 :
288 0 : void DockingWindow::dispose()
289 : {
290 0 : pLayout.clear();
291 0 : ::DockingWindow::dispose();
292 0 : }
293 :
294 : // Sets the position and the size of the docking window. This property is saved
295 : // when the window is floating. Called by Layout.
296 0 : void DockingWindow::ResizeIfDocking (Point const& rPos, Size const& rSize)
297 : {
298 0 : Rectangle const rRect(rPos, rSize);
299 0 : if (rRect != aDockingRect)
300 : {
301 : // saving the position and the size
302 0 : aDockingRect = rRect;
303 : // resizing if actually docking
304 0 : if (!IsFloatingMode())
305 0 : SetPosSizePixel(rPos, rSize);
306 : }
307 0 : }
308 0 : void DockingWindow::ResizeIfDocking (Size const& rSize)
309 : {
310 0 : ResizeIfDocking(aDockingRect.TopLeft(), rSize);
311 0 : }
312 :
313 : // Sets the parent Layout window.
314 : // The physical parent is set only when the window is docking.
315 0 : void DockingWindow::SetLayoutWindow (Layout* pLayout_)
316 : {
317 0 : pLayout = pLayout_;
318 0 : if (!IsFloatingMode())
319 0 : SetParent(pLayout);
320 :
321 0 : }
322 :
323 : // Increases the "show" reference count.
324 : // The window is shown when the reference count is positive.
325 0 : void DockingWindow::Show (bool bShow) // = true
326 : {
327 0 : if (bShow)
328 : {
329 0 : if (++nShowCount == 1)
330 0 : ::DockingWindow::Show();
331 : }
332 : else
333 : {
334 0 : if (--nShowCount == 0)
335 0 : ::DockingWindow::Hide();
336 : }
337 0 : }
338 :
339 : // Decreases the "show" reference count.
340 : // The window is hidden when the reference count reaches zero.
341 0 : void DockingWindow::Hide ()
342 : {
343 0 : Show(false);
344 0 : }
345 :
346 0 : bool DockingWindow::Docking( const Point& rPos, Rectangle& rRect )
347 : {
348 0 : if (!IsDockingPrevented() && aDockingRect.IsInside(rPos))
349 : {
350 0 : rRect.SetSize(aDockingRect.GetSize());
351 0 : return false; // dock
352 : }
353 : else // adjust old size
354 : {
355 0 : if (!aFloatingRect.IsEmpty())
356 0 : rRect.SetSize(aFloatingRect.GetSize());
357 0 : return true; // float
358 : }
359 : }
360 :
361 0 : void DockingWindow::EndDocking( const Rectangle& rRect, bool bFloatMode )
362 : {
363 0 : if ( bFloatMode )
364 0 : ::DockingWindow::EndDocking( rRect, bFloatMode );
365 : else
366 : {
367 0 : SetFloatingMode(false);
368 0 : DockThis();
369 : }
370 0 : }
371 :
372 0 : void DockingWindow::ToggleFloatingMode()
373 : {
374 0 : if (IsFloatingMode())
375 : {
376 0 : if (!aFloatingRect.IsEmpty())
377 : SetPosSizePixel(
378 0 : GetParent()->ScreenToOutputPixel(aFloatingRect.TopLeft()),
379 0 : aFloatingRect.GetSize()
380 0 : );
381 : }
382 0 : DockThis();
383 0 : }
384 :
385 0 : bool DockingWindow::PrepareToggleFloatingMode()
386 : {
387 0 : if (IsFloatingMode())
388 : {
389 : // memorize position and size on the desktop...
390 : aFloatingRect = Rectangle(
391 0 : GetParent()->OutputToScreenPixel(GetPosPixel()),
392 0 : GetSizePixel()
393 0 : );
394 : }
395 0 : return true;
396 : }
397 :
398 0 : void DockingWindow::StartDocking()
399 : {
400 0 : if (IsFloatingMode())
401 : {
402 : aFloatingRect = Rectangle(
403 0 : GetParent()->OutputToScreenPixel(GetPosPixel()),
404 0 : GetSizePixel()
405 0 : );
406 : }
407 0 : }
408 :
409 0 : void DockingWindow::DockThis ()
410 : {
411 : // resizing when floating -> docking
412 0 : if (!IsFloatingMode())
413 : {
414 0 : Point const aPos = aDockingRect.TopLeft();
415 0 : Size const aSize = aDockingRect.GetSize();
416 0 : if (aSize != GetSizePixel() || aPos != GetPosPixel())
417 0 : SetPosSizePixel(aPos, aSize);
418 : }
419 :
420 0 : if (pLayout)
421 : {
422 0 : if (!IsFloatingMode() && GetParent() != pLayout)
423 0 : SetParent(pLayout);
424 0 : pLayout->DockaWindow(this);
425 : }
426 0 : }
427 :
428 :
429 :
430 : // ExtendedEdit
431 :
432 :
433 :
434 0 : ExtendedEdit::ExtendedEdit( vcl::Window* pParent, IDEResId nRes ) :
435 0 : Edit( pParent, nRes )
436 : {
437 0 : aAcc.SetSelectHdl( LINK( this, ExtendedEdit, EditAccHdl ) );
438 0 : Control::SetGetFocusHdl( LINK( this, ExtendedEdit, ImplGetFocusHdl ) );
439 0 : Control::SetLoseFocusHdl( LINK( this, ExtendedEdit, ImplLoseFocusHdl ) );
440 0 : }
441 :
442 0 : IMPL_LINK_NOARG(ExtendedEdit, ImplGetFocusHdl)
443 : {
444 0 : Application::InsertAccel( &aAcc );
445 0 : aLoseFocusHdl.Call( this );
446 0 : return 0;
447 : }
448 :
449 :
450 0 : IMPL_LINK_NOARG(ExtendedEdit, ImplLoseFocusHdl)
451 : {
452 0 : Application::RemoveAccel( &aAcc );
453 0 : return 0;
454 : }
455 :
456 :
457 0 : IMPL_LINK( ExtendedEdit, EditAccHdl, Accelerator *, pAcc )
458 : {
459 0 : aAccHdl.Call( pAcc );
460 0 : return 0;
461 : }
462 :
463 : // TabBar
464 :
465 :
466 :
467 0 : TabBar::TabBar( vcl::Window* pParent ) :
468 0 : ::TabBar( pParent, WinBits( WB_3DLOOK | WB_SCROLL | WB_BORDER | WB_SIZEABLE | WB_DRAG ) )
469 : {
470 0 : EnableEditMode(true);
471 :
472 0 : SetHelpId( HID_BASICIDE_TABBAR );
473 0 : }
474 :
475 0 : void TabBar::MouseButtonDown( const MouseEvent& rMEvt )
476 : {
477 0 : if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) && !IsInEditMode() )
478 : {
479 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
480 0 : pDispatcher->Execute( SID_BASICIDE_MODULEDLG );
481 : }
482 : else
483 : {
484 0 : ::TabBar::MouseButtonDown( rMEvt ); // base class version
485 : }
486 0 : }
487 :
488 0 : void TabBar::Command( const CommandEvent& rCEvt )
489 : {
490 0 : if ( ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) && !IsInEditMode() )
491 : {
492 0 : Point aPos( rCEvt.IsMouseEvent() ? rCEvt.GetMousePosPixel() : Point(1,1) );
493 0 : if ( rCEvt.IsMouseEvent() ) // select right tab
494 : {
495 0 : Point aP = PixelToLogic( aPos );
496 0 : MouseEvent aMouseEvent( aP, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT );
497 0 : ::TabBar::MouseButtonDown( aMouseEvent ); // base class
498 : }
499 :
500 0 : PopupMenu aPopup( IDEResId( RID_POPUP_TABBAR ) );
501 0 : if ( GetPageCount() == 0 )
502 : {
503 0 : aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
504 0 : aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
505 0 : aPopup.EnableItem(SID_BASICIDE_HIDECURPAGE, false);
506 : }
507 :
508 0 : if ( StarBASIC::IsRunning() )
509 : {
510 0 : aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
511 0 : aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
512 0 : aPopup.EnableItem(SID_BASICIDE_MODULEDLG, false);
513 : }
514 :
515 0 : if (Shell* pShell = GetShell())
516 : {
517 0 : ScriptDocument aDocument( pShell->GetCurDocument() );
518 0 : OUString aOULibName( pShell->GetCurLibName() );
519 0 : Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
520 0 : Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
521 0 : if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
522 0 : ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
523 : {
524 0 : aPopup.EnableItem(aPopup.GetItemId( 0 ), false);
525 0 : aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
526 0 : aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
527 0 : aPopup.RemoveDisabledEntries();
528 : }
529 0 : if ( aDocument.isInVBAMode() )
530 : {
531 : // disable to delete or remove object modules in IDE
532 0 : if (BasicManager* pBasMgr = aDocument.getBasicManager())
533 : {
534 0 : if (StarBASIC* pBasic = pBasMgr->GetLib(aOULibName))
535 : {
536 0 : Shell::WindowTable& aWindowTable = pShell->GetWindowTable();
537 0 : Shell::WindowTableIt it = aWindowTable.find( GetCurPageId() );
538 0 : if (it != aWindowTable.end() && dynamic_cast<ModulWindow*>(it->second.get()))
539 : {
540 0 : SbModule* pActiveModule = pBasic->FindModule( it->second->GetName() );
541 0 : if( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
542 : {
543 0 : aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
544 0 : aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
545 : }
546 : }
547 : }
548 : }
549 0 : }
550 : }
551 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
552 0 : pDispatcher->Execute(aPopup.Execute(this, aPos));
553 : }
554 0 : }
555 :
556 0 : TabBarAllowRenamingReturnCode TabBar::AllowRenaming()
557 : {
558 0 : bool const bValid = IsValidSbxName(GetEditText());
559 :
560 0 : if ( !bValid )
561 0 : ScopedVclPtrInstance<MessageDialog>::Create(this, IDEResId(RID_STR_BADSBXNAME))->Execute();
562 :
563 0 : return bValid ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
564 : }
565 :
566 :
567 0 : void TabBar::EndRenaming()
568 : {
569 0 : if ( !IsEditModeCanceled() )
570 : {
571 0 : SfxUInt16Item aID( SID_BASICIDE_ARG_TABID, GetEditPageId() );
572 0 : SfxStringItem aNewName( SID_BASICIDE_ARG_MODULENAME, GetEditText() );
573 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
574 : pDispatcher->Execute( SID_BASICIDE_NAMECHANGEDONTAB,
575 0 : SfxCallMode::SYNCHRON, &aID, &aNewName, 0L );
576 : }
577 0 : }
578 :
579 :
580 : namespace
581 : {
582 :
583 : // helper class for sorting TabBar
584 0 : struct TabBarSortHelper
585 : {
586 : sal_uInt16 nPageId;
587 : OUString aPageText;
588 :
589 0 : bool operator < (TabBarSortHelper const& rComp) const
590 : {
591 0 : return aPageText.compareToIgnoreAsciiCase(rComp.aPageText) < 0;
592 : }
593 : };
594 :
595 : } // namespace
596 :
597 0 : void TabBar::Sort()
598 : {
599 0 : if (Shell* pShell = GetShell())
600 : {
601 0 : Shell::WindowTable& aWindowTable = pShell->GetWindowTable();
602 0 : TabBarSortHelper aTabBarSortHelper;
603 0 : std::vector<TabBarSortHelper> aModuleList;
604 0 : std::vector<TabBarSortHelper> aDialogList;
605 0 : sal_uInt16 nPageCount = GetPageCount();
606 : sal_uInt16 i;
607 :
608 : // create module and dialog lists for sorting
609 0 : for ( i = 0; i < nPageCount; i++)
610 : {
611 0 : sal_uInt16 nId = GetPageId( i );
612 0 : aTabBarSortHelper.nPageId = nId;
613 0 : aTabBarSortHelper.aPageText = GetPageText( nId );
614 0 : BaseWindow* pWin = aWindowTable[ nId ];
615 :
616 0 : if (dynamic_cast<ModulWindow*>(pWin))
617 : {
618 0 : aModuleList.push_back( aTabBarSortHelper );
619 : }
620 0 : else if (dynamic_cast<DialogWindow*>(pWin))
621 : {
622 0 : aDialogList.push_back( aTabBarSortHelper );
623 : }
624 : }
625 :
626 : // sort module and dialog lists by page text
627 0 : ::std::sort( aModuleList.begin() , aModuleList.end() );
628 0 : ::std::sort( aDialogList.begin() , aDialogList.end() );
629 :
630 :
631 0 : sal_uInt16 nModules = sal::static_int_cast<sal_uInt16>( aModuleList.size() );
632 0 : sal_uInt16 nDialogs = sal::static_int_cast<sal_uInt16>( aDialogList.size() );
633 :
634 : // move module pages to new positions
635 0 : for (i = 0; i < nModules; i++)
636 : {
637 0 : MovePage( aModuleList[i].nPageId , i );
638 : }
639 :
640 : // move dialog pages to new positions
641 0 : for (i = 0; i < nDialogs; i++)
642 : {
643 0 : MovePage( aDialogList[i].nPageId , nModules + i );
644 0 : }
645 : }
646 0 : }
647 :
648 0 : void CutLines( OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, bool bEraseTrailingEmptyLines )
649 : {
650 0 : sal_Int32 nStartPos = 0;
651 0 : sal_Int32 nLine = 0;
652 0 : while ( nLine < nStartLine )
653 : {
654 0 : nStartPos = searchEOL( rStr, nStartPos );
655 0 : if( nStartPos == -1 )
656 0 : break;
657 0 : nStartPos++; // not the \n.
658 0 : nLine++;
659 : }
660 :
661 : DBG_ASSERTWARNING( nStartPos != -1, "CutLines: Startzeile nicht gefunden!" );
662 :
663 0 : if ( nStartPos == -1 )
664 0 : return;
665 :
666 0 : sal_Int32 nEndPos = nStartPos;
667 :
668 0 : for ( sal_Int32 i = 0; i < nLines; i++ )
669 0 : nEndPos = searchEOL( rStr, nEndPos+1 );
670 :
671 0 : if ( nEndPos == -1 ) // might happen at the last line
672 0 : nEndPos = rStr.getLength();
673 : else
674 0 : nEndPos++;
675 :
676 0 : OUString aEndStr = rStr.copy( nEndPos );
677 0 : rStr = rStr.copy( 0, nStartPos );
678 0 : rStr += aEndStr;
679 :
680 0 : if ( bEraseTrailingEmptyLines )
681 : {
682 0 : sal_Int32 n = nStartPos;
683 0 : sal_Int32 nLen = rStr.getLength();
684 0 : while ( ( n < nLen ) && ( rStr[ n ] == LINE_SEP ||
685 0 : rStr[ n ] == LINE_SEP_CR ) )
686 : {
687 0 : n++;
688 : }
689 :
690 0 : if ( n > nStartPos )
691 : {
692 0 : aEndStr = rStr.copy( n );
693 0 : rStr = rStr.copy( 0, nStartPos );
694 0 : rStr += aEndStr;
695 : }
696 0 : }
697 : }
698 :
699 0 : sal_uLong CalcLineCount( SvStream& rStream )
700 : {
701 0 : sal_uLong nLFs = 0;
702 0 : sal_uLong nCRs = 0;
703 : char c;
704 :
705 0 : rStream.Seek( 0 );
706 0 : rStream.ReadChar( c );
707 0 : while ( !rStream.IsEof() )
708 : {
709 0 : if ( c == '\n' )
710 0 : nLFs++;
711 0 : else if ( c == '\r' )
712 0 : nCRs++;
713 0 : rStream.ReadChar( c );
714 : }
715 :
716 0 : rStream.Seek( 0 );
717 0 : if ( nLFs > nCRs )
718 0 : return nLFs;
719 0 : return nCRs;
720 : }
721 :
722 :
723 : // LibInfos
724 :
725 :
726 :
727 0 : LibInfos::LibInfos ()
728 0 : { }
729 :
730 0 : LibInfos::~LibInfos ()
731 0 : { }
732 :
733 0 : void LibInfos::InsertInfo (
734 : ScriptDocument const& rDocument,
735 : OUString const& rLibName,
736 : OUString const& rCurrentName,
737 : ItemType eCurrentType
738 : )
739 : {
740 0 : Key aKey(rDocument, rLibName);
741 0 : m_aMap.erase(aKey);
742 0 : m_aMap.insert(Map::value_type(aKey, Item(rDocument, rLibName, rCurrentName, eCurrentType)));
743 0 : }
744 :
745 0 : void LibInfos::RemoveInfoFor (ScriptDocument const& rDocument)
746 : {
747 0 : Map::iterator it;
748 0 : for (it = m_aMap.begin(); it != m_aMap.end(); ++it)
749 0 : if (it->first.GetDocument() == rDocument)
750 0 : break;
751 0 : if (it != m_aMap.end())
752 0 : m_aMap.erase(it);
753 0 : }
754 :
755 0 : LibInfos::Item const* LibInfos::GetInfo (
756 : ScriptDocument const& rDocument, OUString const& rLibName
757 : )
758 : {
759 0 : Map::iterator it = m_aMap.find(Key(rDocument, rLibName));
760 0 : return it != m_aMap.end() ? &it->second : 0;
761 : }
762 :
763 0 : LibInfos::Key::Key (ScriptDocument const& rDocument, OUString const& rLibName) :
764 0 : m_aDocument(rDocument), m_aLibName(rLibName)
765 0 : { }
766 :
767 0 : LibInfos::Key::~Key ()
768 0 : { }
769 :
770 0 : bool LibInfos::Key::operator == (Key const& rKey) const
771 : {
772 0 : return m_aDocument == rKey.m_aDocument && m_aLibName == rKey.m_aLibName;
773 : }
774 :
775 0 : size_t LibInfos::Key::Hash::operator () (Key const& rKey) const
776 : {
777 0 : return rKey.m_aDocument.hashCode() + rKey.m_aLibName.hashCode();
778 : }
779 :
780 0 : LibInfos::Item::Item (
781 : ScriptDocument const& rDocument,
782 : OUString const& rLibName,
783 : OUString const& rCurrentName,
784 : ItemType eCurrentType
785 : ) :
786 : m_aDocument(rDocument),
787 : m_aLibName(rLibName),
788 : m_aCurrentName(rCurrentName),
789 0 : m_eCurrentType(eCurrentType)
790 0 : { }
791 :
792 0 : LibInfos::Item::~Item ()
793 0 : { }
794 :
795 0 : bool QueryDel( const OUString& rName, const ResId& rId, vcl::Window* pParent )
796 : {
797 0 : OUString aQuery(rId.toString());
798 0 : OUStringBuffer aNameBuf( rName );
799 0 : aNameBuf.append('\'');
800 0 : aNameBuf.insert(0, '\'');
801 0 : aQuery = aQuery.replaceAll("XX", aNameBuf.makeStringAndClear());
802 0 : ScopedVclPtrInstance< MessageDialog > aQueryBox(pParent, aQuery, VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
803 0 : return ( aQueryBox->Execute() == RET_YES );
804 : }
805 :
806 0 : bool QueryDelMacro( const OUString& rName, vcl::Window* pParent )
807 : {
808 0 : return QueryDel( rName, IDEResId( RID_STR_QUERYDELMACRO ), pParent );
809 : }
810 :
811 0 : bool QueryReplaceMacro( const OUString& rName, vcl::Window* pParent )
812 : {
813 0 : return QueryDel( rName, IDEResId( RID_STR_QUERYREPLACEMACRO ), pParent );
814 : }
815 :
816 0 : bool QueryDelDialog( const OUString& rName, vcl::Window* pParent )
817 : {
818 0 : return QueryDel( rName, IDEResId( RID_STR_QUERYDELDIALOG ), pParent );
819 : }
820 :
821 0 : bool QueryDelLib( const OUString& rName, bool bRef, vcl::Window* pParent )
822 : {
823 0 : return QueryDel( rName, IDEResId( bRef ? RID_STR_QUERYDELLIBREF : RID_STR_QUERYDELLIB ), pParent );
824 : }
825 :
826 0 : bool QueryDelModule( const OUString& rName, vcl::Window* pParent )
827 : {
828 0 : return QueryDel( rName, IDEResId( RID_STR_QUERYDELMODULE ), pParent );
829 : }
830 :
831 0 : bool QueryPassword( const Reference< script::XLibraryContainer >& xLibContainer, const OUString& rLibName, OUString& rPassword, bool bRepeat, bool bNewTitle )
832 : {
833 0 : bool bOK = false;
834 0 : sal_uInt16 nRet = 0;
835 :
836 0 : do
837 : {
838 : // password dialog
839 0 : ScopedVclPtrInstance< SfxPasswordDialog > aDlg(Application::GetDefDialogParent());
840 0 : aDlg->SetMinLen( 1 );
841 :
842 : // set new title
843 0 : if ( bNewTitle )
844 : {
845 0 : OUString aTitle(IDE_RESSTR(RID_STR_ENTERPASSWORD));
846 0 : aTitle = aTitle.replaceAll("XX", rLibName);
847 0 : aDlg->SetText( aTitle );
848 : }
849 :
850 : // execute dialog
851 0 : nRet = aDlg->Execute();
852 :
853 : // verify password
854 0 : if ( nRet == RET_OK )
855 : {
856 0 : if ( xLibContainer.is() && xLibContainer->hasByName( rLibName ) )
857 : {
858 0 : Reference< script::XLibraryContainerPassword > xPasswd( xLibContainer, UNO_QUERY );
859 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( rLibName ) && !xPasswd->isLibraryPasswordVerified( rLibName ) )
860 : {
861 0 : rPassword = aDlg->GetPassword();
862 : // OUString aOUPassword( rPassword );
863 0 : bOK = xPasswd->verifyLibraryPassword( rLibName, rPassword );
864 :
865 0 : if ( !bOK )
866 : {
867 0 : ScopedVclPtrInstance< MessageDialog > aErrorBox(Application::GetDefDialogParent(), IDE_RESSTR(RID_STR_WRONGPASSWORD));
868 0 : aErrorBox->Execute();
869 : }
870 0 : }
871 : }
872 0 : }
873 : }
874 0 : while ( bRepeat && !bOK && nRet == RET_OK );
875 :
876 0 : return bOK;
877 : }
878 :
879 :
880 0 : } // namespace basctl
881 :
882 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|