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