1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "scriptdocument.hxx"
23 #include "sbxitem.hxx"
24 #include <svtools/scrolladaptor.hxx>
25 #include <svtools/tabbar.hxx>
26 #include <basic/sbdef.hxx>
27 #include <vcl/dockwin.hxx>
28 #include <vcl/weld.hxx>
30 #include <string_view>
31 #include <unordered_map>
38 enum class SearchOptionFlags
;
53 constexpr auto LINE_SEP_CR
= 0x0D;
54 constexpr auto LINE_SEP
= 0x0A;
56 // Implementation: baside2b.cxx
57 sal_Int32
searchEOL( std::u16string_view rStr
, sal_Int32 fromIndex
);
59 // Meaning of bToBeKilled:
60 // While being in a reschedule-loop, I may not destroy the window.
61 // It must first break from the reschedule-loop to self-destroy then.
62 // Does unfortunately not work that way: Destroying Window with living Child!
68 bool bIsInReschedule
: 1;
69 BasicDebugFlags nBasicFlags
;
74 bIsInReschedule(false),
75 nBasicFlags(BasicDebugFlags::NONE
) { }
79 // basctl::DockingWindow -- special docking window for the Basic IDE
80 // Not to be confused with ::DockingWindow from vcl.
82 class DockingWindow
: public ResizableDockingWindow
85 DockingWindow(vcl::Window
* pParent
, const OUString
& rUIXMLDescription
, const OUString
& rID
);
86 DockingWindow(Layout
* pParent
);
87 virtual ~DockingWindow() override
;
88 virtual void dispose() override
;
89 void ResizeIfDocking (Point
const&, Size
const&);
90 void ResizeIfDocking (Size
const&);
91 Size
GetDockingSize () const { return aDockingRect
.GetSize(); }
92 void SetLayoutWindow (Layout
*);
94 void Show (bool = true);
98 virtual bool Docking( const Point
& rPos
, tools::Rectangle
& rRect
) override
;
99 virtual void EndDocking( const tools::Rectangle
& rRect
, bool bFloatMode
) override
;
100 virtual void ToggleFloatingMode() override
;
101 virtual bool PrepareToggleFloatingMode() override
;
102 virtual void StartDocking() override
;
105 std::unique_ptr
<weld::Builder
> m_xBuilder
;
106 std::unique_ptr
<weld::Container
> m_xContainer
;
109 // the position and the size of the floating window
110 tools::Rectangle aFloatingRect
;
111 // the position and the size of the docking window
112 tools::Rectangle aDockingRect
;
113 // the parent layout window (only when docking)
114 VclPtr
<Layout
> pLayout
;
115 // > 0: shown, <= 0: hidden, ++ by Show() and -- by Hide()
118 static WinBits
const StyleBits
;
126 // Not to be confused with ::TabBar from svtools.
128 class TabBar
: public ::TabBar
131 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
132 virtual void Command( const CommandEvent
& rCEvt
) override
;
134 virtual TabBarAllowRenamingReturnCode
AllowRenaming() override
;
135 virtual void EndRenaming() override
;
138 TabBar (vcl::Window
* pParent
);
143 enum BasicWindowStatus
145 BASWIN_RUNNINGBASIC
= 0x01,
146 BASWIN_TOBEKILLED
= 0x02,
147 BASWIN_SUSPENDED
= 0x04,
148 BASWIN_INRESCHEDULE
= 0x08
151 class EntryDescriptor
;
154 // BaseWindow -- the base of both ModulWindow and DialogWindow.
156 class BaseWindow
: public vcl::Window
159 VclPtr
<ScrollAdaptor
> pShellHScrollBar
;
160 VclPtr
<ScrollAdaptor
> pShellVScrollBar
;
162 DECL_LINK( VertScrollHdl
, weld::Scrollbar
&, void );
163 DECL_LINK( HorzScrollHdl
, weld::Scrollbar
&, void );
166 ScriptDocument m_aDocument
;
170 friend class ModulWindow
;
171 friend class DialogWindow
;
174 virtual void DoScroll(Scrollable
* pCurScrollBar
);
177 BaseWindow( vcl::Window
* pParent
, ScriptDocument aDocument
, OUString aLibName
, OUString aName
);
178 virtual ~BaseWindow() override
;
179 virtual void dispose() override
;
182 virtual void DoInit();
183 virtual void Activating () = 0;
184 virtual void Deactivating () = 0;
185 void GrabScrollBars(ScrollAdaptor
* pHScroll
, ScrollAdaptor
* pVScroll
);
187 ScrollAdaptor
* GetHScrollBar() const { return pShellHScrollBar
.get(); }
188 ScrollAdaptor
* GetVScrollBar() const { return pShellVScrollBar
.get(); }
189 void ShowShellScrollBars(bool bVisible
= true);
191 virtual void ExecuteCommand (SfxRequest
&);
192 virtual void ExecuteGlobal (SfxRequest
&);
193 virtual void GetState (SfxItemSet
&) = 0;
194 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
196 virtual void StoreData();
197 virtual void UpdateData();
199 // return number of pages to be printed
200 virtual sal_Int32
countPages( Printer
* pPrinter
) = 0;
202 virtual void printPage( sal_Int32 nPage
, Printer
* pPrinter
) = 0;
204 virtual OUString
GetTitle();
205 OUString
CreateQualifiedName();
206 virtual EntryDescriptor
CreateEntryDescriptor() = 0;
208 virtual bool IsModified();
210 virtual bool AllowUndo();
212 virtual void SetReadOnly (bool bReadOnly
);
213 virtual bool IsReadOnly();
214 void ShowReadOnlyInfoBar();
216 int GetStatus() const { return nStatus
; }
217 void SetStatus(int n
) { nStatus
= n
; }
218 void AddStatus(int n
) { nStatus
|= n
; }
219 void ClearStatus(int n
) { nStatus
&= ~n
; }
221 virtual SfxUndoManager
* GetUndoManager ();
223 virtual SearchOptionFlags
GetSearchOptions();
224 virtual sal_uInt16
StartSearchAndReplace (SvxSearchItem
const&, bool bFromStart
= false);
226 virtual void BasicStarted();
227 virtual void BasicStopped();
229 bool IsSuspended() const { return nStatus
& BASWIN_SUSPENDED
; }
231 const ScriptDocument
&
232 GetDocument() const { return m_aDocument
; }
233 bool IsDocument( const ScriptDocument
& rDocument
) const { return rDocument
== m_aDocument
; }
234 const OUString
& GetLibName() const { return m_aLibName
; }
236 const OUString
& GetName() const { return m_aName
; }
237 void SetName( const OUString
& aName
) { m_aName
= aName
; }
239 virtual void OnNewDocument ();
240 virtual OUString
GetHid () const = 0;
241 virtual ItemType
GetType () const = 0;
242 void InsertLibInfo () const;
243 bool Is (ScriptDocument
const&, std::u16string_view
, std::u16string_view
, ItemType
, bool bFindSuspended
);
244 virtual bool HasActiveEditor () const;
255 void InsertInfo (ScriptDocument
const&, OUString
const& rLibName
, OUString
const& rCurrentName
, ItemType eCurrentType
);
256 void RemoveInfoFor (ScriptDocument
const&);
257 Item
const* GetInfo (ScriptDocument
const&, OUString
const& rLibName
);
263 ScriptDocument m_aDocument
;
267 Key (ScriptDocument
, OUString aLibName
);
269 bool operator == (Key
const&) const;
272 size_t operator () (Key
const&) const;
275 const ScriptDocument
& GetDocument() const { return m_aDocument
; }
281 OUString m_aCurrentName
;
282 ItemType m_eCurrentType
;
285 Item (OUString aCurrentName
, ItemType eCurrentType
);
286 const OUString
& GetCurrentName() const { return m_aCurrentName
; }
287 ItemType
GetCurrentType() const { return m_eCurrentType
; }
290 typedef std::unordered_map
<Key
, Item
, Key::Hash
> Map
;
294 void CutLines( OUString
& rStr
, sal_Int32 nStartLine
, sal_Int32 nLines
);
295 OUString
CreateMgrAndLibStr( std::u16string_view rMgrName
, std::u16string_view rLibName
);
296 sal_uInt32
CalcLineCount( SvStream
& rStream
);
298 bool QueryReplaceMacro( std::u16string_view rName
, weld::Widget
* pParent
);
299 bool QueryDelMacro( std::u16string_view rName
, weld::Widget
* pParent
);
300 bool QueryDelDialog( std::u16string_view rName
, weld::Widget
* pParent
);
301 bool QueryDelModule( std::u16string_view rName
, weld::Widget
* pParent
);
302 bool QueryDelLib( std::u16string_view rName
, bool bRef
, weld::Widget
* pParent
);
303 bool QueryPassword(weld::Widget
* pDialogParent
, const css::uno::Reference
< css::script::XLibraryContainer
>& xLibContainer
, const OUString
& rLibName
, OUString
& rPassword
, bool bRepeat
= false, bool bNewTitle
= false);
305 class ModuleInfoHelper
307 ModuleInfoHelper (const ModuleInfoHelper
&) = delete;
308 ModuleInfoHelper
& operator = (const ModuleInfoHelper
&) = delete;
310 static void getObjectName( const css::uno::Reference
< css::container::XNameContainer
>& rLib
, const OUString
& rModName
, OUString
& rObjName
);
311 static sal_Int32
getModuleType( const css::uno::Reference
< css::container::XNameContainer
>& rLib
, const OUString
& rModName
);
314 } // namespace basctl
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */