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 .
22 #include <sal/config.h>
26 #include "doceventnotifier.hxx"
28 #include <vcl/weld.hxx>
29 #include <basctl/sbxitem.hxx>
30 #include <o3tl/typed_flags_set.hxx>
40 All
= Modules
| Subs
| Dialogs
,
43 template<> struct typed_flags
<BrowseMode
> : is_typed_flags
<BrowseMode
, 0x7> {};
57 OBJ_TYPE_DOCUMENT_OBJECTS
,
59 OBJ_TYPE_NORMAL_MODULES
,
60 OBJ_TYPE_CLASS_MODULES
69 explicit Entry(EntryType eType
)
76 Entry(Entry
const &) = default;
77 Entry(Entry
&&) = default;
78 Entry
& operator =(Entry
const &) = default;
79 Entry
& operator =(Entry
&&) = default;
81 EntryType
GetType () const { return m_eType
; }
84 class DocumentEntry
: public Entry
87 ScriptDocument m_aDocument
;
88 LibraryLocation m_eLocation
;
92 ScriptDocument aDocument
,
93 LibraryLocation eLocation
,
94 EntryType eType
= OBJ_TYPE_DOCUMENT
96 virtual ~DocumentEntry () override
;
98 ScriptDocument
const& GetDocument() const { return m_aDocument
; }
99 LibraryLocation
GetLocation() const { return m_eLocation
; }
102 class LibEntry
: public DocumentEntry
109 ScriptDocument
const& rDocument
,
110 LibraryLocation eLocation
,
113 virtual ~LibEntry () override
;
115 OUString
const& GetLibName () const { return m_aLibName
; }
118 class EntryDescriptor
120 ScriptDocument m_aDocument
;
121 LibraryLocation m_eLocation
;
123 OUString m_aLibSubName
; // for vba entry: Document Objects, Class Modules, Forms and Normal Modules
125 OUString m_aMethodName
;
131 ScriptDocument aDocument
,
132 LibraryLocation eLocation
,
134 OUString aLibSubName
,
139 ScriptDocument aDocument
,
140 LibraryLocation eLocation
,
142 OUString aLibSubName
,
144 OUString aMethodName
,
148 ScriptDocument
const& GetDocument() const { return m_aDocument
; }
149 LibraryLocation
GetLocation() const { return m_eLocation
; }
151 const OUString
& GetLibName() const { return m_aLibName
; }
152 const OUString
& GetLibSubName() const { return m_aLibSubName
; }
153 const OUString
& GetName() const { return m_aName
; }
154 const OUString
& GetMethodName() const { return m_aMethodName
; }
155 void SetMethodName( const OUString
& aMethodName
) { m_aMethodName
= aMethodName
; }
157 EntryType
GetType() const { return m_eType
; }
158 void SetType( EntryType eType
) { m_eType
= eType
; }
163 Classification of types and pointers in the Entries:
165 OBJ_TYPE_DOCUMENT DocumentEntry
166 OBJ_TYPE_LIBRARY Entry
167 OBJ_TYPE_MODULE Entry
168 OBJ_TYPE_DIALOG Entry
169 OBJ_TYPE_METHOD Entry
173 class SbTreeListBox
: public DocumentEventListener
176 std::unique_ptr
<weld::TreeView
> m_xControl
;
177 std::unique_ptr
<weld::TreeIter
> m_xScratchIter
;
178 weld::Window
* m_pTopLevel
;
179 bool m_bFreezeOnFirstAddRemove
;
181 DocumentEventNotifier m_aNotifier
;
182 void SetEntryBitmaps(const weld::TreeIter
& rIter
, const OUString
& rImage
);
185 DECL_LINK(RequestingChildrenHdl
, const weld::TreeIter
&, bool);
186 DECL_LINK(OpenCurrentHdl
, weld::TreeView
&, bool);
187 void ImpCreateLibEntries(const weld::TreeIter
& rShellRootEntry
, const ScriptDocument
& rDocument
, LibraryLocation eLocation
);
188 void ImpCreateLibSubEntries(const weld::TreeIter
& rLibRootEntry
, const ScriptDocument
& rDocument
, const OUString
& rLibName
);
189 void ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter
& rLibRootEntry
, const ScriptDocument
& rDocument
, const OUString
& rLibName
);
190 void ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter
& rLibRootEntry
, const ScriptDocument
& rDocument
, const OUString
& rLibName
);
191 bool ImpFindEntry(weld::TreeIter
& rIter
, std::u16string_view rText
);
193 // DocumentEventListener
194 virtual void onDocumentCreated( const ScriptDocument
& _rDocument
) override
;
195 virtual void onDocumentOpened( const ScriptDocument
& _rDocument
) override
;
196 virtual void onDocumentSave( const ScriptDocument
& _rDocument
) override
;
197 virtual void onDocumentSaveDone( const ScriptDocument
& _rDocument
) override
;
198 virtual void onDocumentSaveAs( const ScriptDocument
& _rDocument
) override
;
199 virtual void onDocumentSaveAsDone( const ScriptDocument
& _rDocument
) override
;
200 virtual void onDocumentClosed( const ScriptDocument
& _rDocument
) override
;
201 virtual void onDocumentTitleChanged( const ScriptDocument
& _rDocument
) override
;
202 virtual void onDocumentModeChanged( const ScriptDocument
& _rDocument
) override
;
205 SbTreeListBox(std::unique_ptr
<weld::TreeView
> xControl
, weld::Window
* pTopLevel
);
206 virtual ~SbTreeListBox() override
;
208 void ScanEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
);
209 void ScanAllEntries();
210 void UpdateEntries();
212 bool IsEntryProtected(const weld::TreeIter
* pEntry
);
214 void SetMode( BrowseMode nM
) { nMode
= nM
; }
215 BrowseMode
GetMode() const { return nMode
; }
217 SbModule
* FindModule(const weld::TreeIter
* pEntry
);
218 SbxVariable
* FindVariable(const weld::TreeIter
* pEntry
);
219 bool FindRootEntry(const ScriptDocument
& rDocument
, LibraryLocation eLocation
, weld::TreeIter
& rIter
);
220 bool FindEntry(std::u16string_view rText
, EntryType eType
, weld::TreeIter
& rIter
);
221 EntryDescriptor
GetEntryDescriptor(const weld::TreeIter
* pEntry
);
223 static SbxItemType
ConvertType (EntryType eType
);
224 bool IsValidEntry(const weld::TreeIter
& rEntry
);
225 void AddEntry(const OUString
& rText
, const OUString
& rImage
,
226 const weld::TreeIter
* pParent
, bool bChildrenOnDemand
,
227 std::unique_ptr
<Entry
>&& rUserData
,
228 weld::TreeIter
* pRet
= nullptr);
230 void connect_changed(const Link
<weld::TreeView
&, void>& rLink
)
232 m_xControl
->connect_selection_changed(rLink
);
234 std::unique_ptr
<weld::TreeIter
> make_iterator(const weld::TreeIter
* pIter
= nullptr) const { return m_xControl
->make_iterator(pIter
); }
235 void copy_iterator(const weld::TreeIter
& rSource
, weld::TreeIter
& rDest
) const { m_xControl
->copy_iterator(rSource
, rDest
); }
236 bool get_selected(weld::TreeIter
* pIter
) const { return m_xControl
->get_selected(pIter
); }
237 void select(const weld::TreeIter
& rIter
) { m_xControl
->select(rIter
); }
238 void unselect(const weld::TreeIter
& rIter
) { m_xControl
->unselect(rIter
); }
239 void remove(const weld::TreeIter
& rIter
) { m_xControl
->remove(rIter
); }
240 bool get_cursor(weld::TreeIter
* pIter
) const { return m_xControl
->get_cursor(pIter
); }
241 void set_cursor(const weld::TreeIter
& rIter
) { m_xControl
->set_cursor(rIter
); }
242 OUString
get_text(const weld::TreeIter
& rIter
) const { return m_xControl
->get_text(rIter
); }
243 void set_text(const weld::TreeIter
& rIter
, const OUString
& rText
) { m_xControl
->set_text(rIter
, rText
); }
244 OUString
get_id(const weld::TreeIter
& rIter
) const { return m_xControl
->get_id(rIter
); }
245 bool get_iter_first(weld::TreeIter
& rIter
) const { return m_xControl
->get_iter_first(rIter
); }
246 bool iter_next_sibling(weld::TreeIter
& rIter
) const { return m_xControl
->iter_next_sibling(rIter
); }
247 bool iter_children(weld::TreeIter
& rIter
) const { return m_xControl
->iter_children(rIter
); }
248 bool iter_parent(weld::TreeIter
& rIter
) const { return m_xControl
->iter_parent(rIter
); }
249 int get_iter_depth(const weld::TreeIter
& rIter
) const { return m_xControl
->get_iter_depth(rIter
); }
250 bool get_row_expanded(const weld::TreeIter
& rIter
) const { return m_xControl
->get_row_expanded(rIter
); }
251 void expand_row(const weld::TreeIter
& rIter
) { m_xControl
->expand_row(rIter
); }
252 void set_size_request(int nWidth
, int nHeight
) { m_xControl
->set_size_request(nWidth
, nHeight
); }
253 float get_approximate_digit_width() const { return m_xControl
->get_approximate_digit_width(); }
254 int get_height_rows(int nRows
) const { return m_xControl
->get_height_rows(nRows
); }
255 int get_iter_index_in_parent(const weld::TreeIter
& rIter
) const { return m_xControl
->get_iter_index_in_parent(rIter
); }
256 void connect_editing(const Link
<const weld::TreeIter
&, bool>& rStartLink
,
257 const Link
<const std::pair
<const weld::TreeIter
&, OUString
>&, bool>& rEndLink
)
259 m_xControl
->connect_editing(rStartLink
, rEndLink
);
262 void make_sorted() { m_xControl
->make_sorted(); };
264 void RemoveEntry(const weld::TreeIter
& rIter
);
265 void RemoveEntry(const ScriptDocument
&);
267 OUString
GetRootEntryName(const ScriptDocument
& rDocument
, LibraryLocation eLocation
) const;
268 static OUString
GetRootEntryBitmaps(const ScriptDocument
& rDocument
);
270 void SetCurrentEntry (EntryDescriptor
const &);
272 weld::TreeView
& get_widget() { return *m_xControl
; }
275 LibraryType
GetLibraryType() const;
278 } // namespace basctl
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */