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 "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> {};
48 using namespace ::com::sun::star::uno
;
58 OBJ_TYPE_DOCUMENT_OBJECTS
,
60 OBJ_TYPE_NORMAL_MODULES
,
61 OBJ_TYPE_CLASS_MODULES
70 explicit Entry(EntryType eType
)
77 Entry(Entry
const &) = default;
78 Entry(Entry
&&) = default;
79 Entry
& operator =(Entry
const &) = default;
80 Entry
& operator =(Entry
&&) = default;
82 EntryType
GetType () const { return m_eType
; }
85 class DocumentEntry
: public Entry
88 ScriptDocument m_aDocument
;
89 LibraryLocation m_eLocation
;
93 ScriptDocument
const& rDocument
,
94 LibraryLocation eLocation
,
95 EntryType eType
= OBJ_TYPE_DOCUMENT
97 virtual ~DocumentEntry () override
;
99 ScriptDocument
const& GetDocument() const { return m_aDocument
; }
100 LibraryLocation
GetLocation() const { return m_eLocation
; }
103 class LibEntry
: public DocumentEntry
110 ScriptDocument
const& rDocument
,
111 LibraryLocation eLocation
,
112 OUString
const& rLibName
114 virtual ~LibEntry () override
;
116 OUString
const& GetLibName () const { return m_aLibName
; }
119 class EntryDescriptor
121 ScriptDocument m_aDocument
;
122 LibraryLocation m_eLocation
;
124 OUString m_aLibSubName
; // for vba entry: Document Objects, Class Modules, Forms and Normal Modules
126 OUString m_aMethodName
;
132 ScriptDocument
const& rDocument
,
133 LibraryLocation eLocation
,
134 OUString
const& rLibName
,
135 OUString
const& rLibSubName
,
136 OUString
const& rName
,
140 ScriptDocument
const& rDocument
,
141 LibraryLocation eLocation
,
142 OUString
const& rLibName
,
143 OUString
const& rLibSubName
,
144 OUString
const& rName
,
145 OUString
const& rMethodName
,
149 ScriptDocument
const& GetDocument() const { return m_aDocument
; }
150 LibraryLocation
GetLocation() const { return m_eLocation
; }
152 const OUString
& GetLibName() const { return m_aLibName
; }
153 const OUString
& GetLibSubName() const { return m_aLibSubName
; }
154 const OUString
& GetName() const { return m_aName
; }
155 const OUString
& GetMethodName() const { return m_aMethodName
; }
156 void SetMethodName( const OUString
& aMethodName
) { m_aMethodName
= aMethodName
; }
158 EntryType
GetType() const { return m_eType
; }
159 void SetType( EntryType eType
) { m_eType
= eType
; }
164 Classification of types and pointers in the Entries:
166 OBJ_TYPE_DOCUMENT DocumentEntry
167 OBJ_TYPE_LIBRARY Entry
168 OBJ_TYPE_MODULE Entry
169 OBJ_TYPE_DIALOG Entry
170 OBJ_TYPE_METHOD Entry
174 class SbTreeListBox
: public DocumentEventListener
177 std::unique_ptr
<weld::TreeView
> m_xControl
;
178 std::unique_ptr
<weld::TreeIter
> m_xScratchIter
;
179 weld::Window
* m_pTopLevel
;
180 bool m_bFreezeOnFirstAddRemove
;
182 DocumentEventNotifier m_aNotifier
;
183 void SetEntryBitmaps(const weld::TreeIter
& rIter
, const OUString
& rImage
);
186 DECL_LINK(RequestingChildrenHdl
, const weld::TreeIter
&, bool);
187 DECL_LINK(OpenCurrentHdl
, weld::TreeView
&, bool);
188 void ImpCreateLibEntries(const weld::TreeIter
& rShellRootEntry
, const ScriptDocument
& rDocument
, LibraryLocation eLocation
);
189 void ImpCreateLibSubEntries(const weld::TreeIter
& rLibRootEntry
, const ScriptDocument
& rDocument
, const OUString
& rLibName
);
190 void ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter
& rLibRootEntry
, const ScriptDocument
& rDocument
, const OUString
& rLibName
);
191 void ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter
& rLibRootEntry
, const ScriptDocument
& rDocument
, const OUString
& rLibName
);
192 bool ImpFindEntry(weld::TreeIter
& rIter
, const OUString
& rText
);
194 // DocumentEventListener
195 virtual void onDocumentCreated( const ScriptDocument
& _rDocument
) override
;
196 virtual void onDocumentOpened( const ScriptDocument
& _rDocument
) override
;
197 virtual void onDocumentSave( const ScriptDocument
& _rDocument
) override
;
198 virtual void onDocumentSaveDone( const ScriptDocument
& _rDocument
) override
;
199 virtual void onDocumentSaveAs( const ScriptDocument
& _rDocument
) override
;
200 virtual void onDocumentSaveAsDone( const ScriptDocument
& _rDocument
) override
;
201 virtual void onDocumentClosed( const ScriptDocument
& _rDocument
) override
;
202 virtual void onDocumentTitleChanged( const ScriptDocument
& _rDocument
) override
;
203 virtual void onDocumentModeChanged( const ScriptDocument
& _rDocument
) override
;
206 SbTreeListBox(std::unique_ptr
<weld::TreeView
> xControl
, weld::Window
* pTopLevel
);
207 virtual ~SbTreeListBox() override
;
209 void ScanEntry( const ScriptDocument
& rDocument
, LibraryLocation eLocation
);
210 void ScanAllEntries();
211 void UpdateEntries();
213 bool IsEntryProtected(const weld::TreeIter
* pEntry
);
215 void SetMode( BrowseMode nM
) { nMode
= nM
; }
216 BrowseMode
GetMode() const { return nMode
; }
218 SbModule
* FindModule(const weld::TreeIter
* pEntry
);
219 SbxVariable
* FindVariable(const weld::TreeIter
* pEntry
);
220 bool FindRootEntry(const ScriptDocument
& rDocument
, LibraryLocation eLocation
, weld::TreeIter
& rIter
);
221 bool FindEntry(const OUString
& rText
, EntryType eType
, weld::TreeIter
& rIter
);
222 EntryDescriptor
GetEntryDescriptor(const weld::TreeIter
* pEntry
);
224 static ItemType
ConvertType (EntryType eType
);
225 bool IsValidEntry(weld::TreeIter
& rEntry
);
226 void AddEntry(const OUString
& rText
, const OUString
& rImage
,
227 const weld::TreeIter
* pParent
, bool bChildrenOnDemand
,
228 std::unique_ptr
<Entry
>&& rUserData
,
229 weld::TreeIter
* pRet
= nullptr);
231 void connect_changed(const Link
<weld::TreeView
&, void>& rLink
) { m_xControl
->connect_changed(rLink
); }
232 std::unique_ptr
<weld::TreeIter
> make_iterator(const weld::TreeIter
* pIter
= nullptr) const { return m_xControl
->make_iterator(pIter
); }
233 void copy_iterator(const weld::TreeIter
& rSource
, weld::TreeIter
& rDest
) const { m_xControl
->copy_iterator(rSource
, rDest
); }
234 bool get_selected(weld::TreeIter
* pIter
) const { return m_xControl
->get_selected(pIter
); }
235 void select(const weld::TreeIter
& rIter
) { m_xControl
->select(rIter
); }
236 void unselect(const weld::TreeIter
& rIter
) { m_xControl
->unselect(rIter
); }
237 void remove(const weld::TreeIter
& rIter
) { m_xControl
->remove(rIter
); }
238 bool get_cursor(weld::TreeIter
* pIter
) const { return m_xControl
->get_cursor(pIter
); }
239 void set_cursor(const weld::TreeIter
& rIter
) { m_xControl
->set_cursor(rIter
); }
240 OUString
get_text(const weld::TreeIter
& rIter
) const { return m_xControl
->get_text(rIter
); }
241 void set_text(const weld::TreeIter
& rIter
, const OUString
& rText
) { m_xControl
->set_text(rIter
, rText
); }
242 OUString
get_id(const weld::TreeIter
& rIter
) const { return m_xControl
->get_id(rIter
); }
243 bool get_iter_first(weld::TreeIter
& rIter
) const { return m_xControl
->get_iter_first(rIter
); }
244 bool iter_next_sibling(weld::TreeIter
& rIter
) const { return m_xControl
->iter_next_sibling(rIter
); }
245 bool iter_children(weld::TreeIter
& rIter
) const { return m_xControl
->iter_children(rIter
); }
246 bool iter_parent(weld::TreeIter
& rIter
) const { return m_xControl
->iter_parent(rIter
); }
247 int get_iter_depth(const weld::TreeIter
& rIter
) const { return m_xControl
->get_iter_depth(rIter
); }
248 bool get_row_expanded(const weld::TreeIter
& rIter
) const { return m_xControl
->get_row_expanded(rIter
); }
249 void expand_row(const weld::TreeIter
& rIter
) { m_xControl
->expand_row(rIter
); }
250 void set_size_request(int nWidth
, int nHeight
) { m_xControl
->set_size_request(nWidth
, nHeight
); }
251 float get_approximate_digit_width() const { return m_xControl
->get_approximate_digit_width(); }
252 int get_height_rows(int nRows
) const { return m_xControl
->get_height_rows(nRows
); }
253 int get_iter_index_in_parent(const weld::TreeIter
& rIter
) const { return m_xControl
->get_iter_index_in_parent(rIter
); }
254 void connect_editing(const Link
<const weld::TreeIter
&, bool>& rStartLink
,
255 const Link
<const std::pair
<const weld::TreeIter
&, OUString
>&, bool>& rEndLink
)
257 m_xControl
->connect_editing(rStartLink
, rEndLink
);
260 void make_sorted() { m_xControl
->make_sorted(); };
262 void RemoveEntry(const weld::TreeIter
& rIter
);
263 void RemoveEntry(const ScriptDocument
&);
265 OUString
GetRootEntryName(const ScriptDocument
& rDocument
, LibraryLocation eLocation
) const;
266 static OUString
GetRootEntryBitmaps(const ScriptDocument
& rDocument
);
268 void SetCurrentEntry (EntryDescriptor
const &);
270 weld::TreeView
& get_widget() { return *m_xControl
; }
273 LibraryType
GetLibraryType() const;
276 } // namespace basctl
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */