1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_BASCTL_SOURCE_INC_BASTYPE2_HXX
#define INCLUDED_BASCTL_SOURCE_INC_BASTYPE2_HXX
#include <sal/config.h>
#include <memory>
#include "doceventnotifier.hxx"
#include <vcl/weld.hxx>
#include "sbxitem.hxx"
#include <o3tl/typed_flags_set.hxx>
class SbModule;
class SbxVariable;
enum class BrowseMode
{
Modules = 0x01,
Subs = 0x02,
Dialogs = 0x04,
All = Modules | Subs | Dialogs,
};
namespace o3tl {
template<> struct typed_flags<BrowseMode> : is_typed_flags<BrowseMode, 0x7> {};
}
namespace basctl
{
using namespace ::com::sun::star::uno;
enum EntryType
{
OBJ_TYPE_UNKNOWN,
OBJ_TYPE_DOCUMENT,
OBJ_TYPE_LIBRARY,
OBJ_TYPE_MODULE,
OBJ_TYPE_DIALOG,
OBJ_TYPE_METHOD,
OBJ_TYPE_DOCUMENT_OBJECTS,
OBJ_TYPE_USERFORMS,
OBJ_TYPE_NORMAL_MODULES,
OBJ_TYPE_CLASS_MODULES
};
class Entry
{
private:
EntryType m_eType;
public:
explicit Entry(EntryType eType)
: m_eType(eType)
{
}
virtual ~Entry();
Entry(Entry const &) = default;
Entry(Entry &&) = default;
Entry & operator =(Entry const &) = default;
Entry & operator =(Entry &&) = default;
EntryType GetType () const { return m_eType; }
};
class DocumentEntry : public Entry
{
private:
ScriptDocument m_aDocument;
LibraryLocation m_eLocation;
public:
DocumentEntry (
ScriptDocument const& rDocument,
LibraryLocation eLocation,
EntryType eType = OBJ_TYPE_DOCUMENT
);
virtual ~DocumentEntry () override;
ScriptDocument const& GetDocument() const { return m_aDocument; }
LibraryLocation GetLocation() const { return m_eLocation; }
};
class LibEntry : public DocumentEntry
{
private:
OUString m_aLibName;
public:
LibEntry (
ScriptDocument const& rDocument,
LibraryLocation eLocation,
OUString const& rLibName
);
virtual ~LibEntry () override;
OUString const& GetLibName () const { return m_aLibName; }
};
class EntryDescriptor
{
ScriptDocument m_aDocument;
LibraryLocation m_eLocation;
OUString m_aLibName;
OUString m_aLibSubName; // for vba entry: Document Objects, Class Modules, Forms and Normal Modules
OUString m_aName;
OUString m_aMethodName;
EntryType m_eType;
public:
EntryDescriptor ();
EntryDescriptor (
ScriptDocument const& rDocument,
LibraryLocation eLocation,
OUString const& rLibName,
OUString const& rLibSubName,
OUString const& rName,
EntryType eType
);
EntryDescriptor (
ScriptDocument const& rDocument,
LibraryLocation eLocation,
OUString const& rLibName,
OUString const& rLibSubName,
OUString const& rName,
OUString const& rMethodName,
EntryType eType
);
ScriptDocument const& GetDocument() const { return m_aDocument; }
LibraryLocation GetLocation() const { return m_eLocation; }
const OUString& GetLibName() const { return m_aLibName; }
const OUString& GetLibSubName() const { return m_aLibSubName; }
const OUString& GetName() const { return m_aName; }
const OUString& GetMethodName() const { return m_aMethodName; }
void SetMethodName( const OUString& aMethodName ) { m_aMethodName = aMethodName; }
EntryType GetType() const { return m_eType; }
void SetType( EntryType eType ) { m_eType = eType; }
};
/*
Classification of types and pointers in the Entries:
OBJ_TYPE_DOCUMENT DocumentEntry
OBJ_TYPE_LIBRARY Entry
OBJ_TYPE_MODULE Entry
OBJ_TYPE_DIALOG Entry
OBJ_TYPE_METHOD Entry
*/
class SbTreeListBox : public DocumentEventListener
{
private:
std::unique_ptr<weld::TreeView> m_xControl;
std::unique_ptr<weld::TreeIter> m_xIter;
weld::Window* m_pTopLevel;
bool m_bFreezeOnFirstAddRemove;
BrowseMode nMode;
DocumentEventNotifier m_aNotifier;
void SetEntryBitmaps(const weld::TreeIter& rIter, const OUString& rImage);
protected:
DECL_LINK(RequestingChildrenHdl, const weld::TreeIter&, bool);
DECL_LINK(OpenCurrentHdl, weld::TreeView&, bool);
void ImpCreateLibEntries(const weld::TreeIter& rShellRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation);
void ImpCreateLibSubEntries(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName);
void ImpCreateLibSubEntriesInVBAMode(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName );
void ImpCreateLibSubSubEntriesInVBAMode(const weld::TreeIter& rLibRootEntry, const ScriptDocument& rDocument, const OUString& rLibName);
bool ImpFindEntry(weld::TreeIter& rIter, const OUString& rText);
// DocumentEventListener
virtual void onDocumentCreated( const ScriptDocument& _rDocument ) override;
virtual void onDocumentOpened( const ScriptDocument& _rDocument ) override;
virtual void onDocumentSave( const ScriptDocument& _rDocument ) override;
virtual void onDocumentSaveDone( const ScriptDocument& _rDocument ) override;
virtual void onDocumentSaveAs( const ScriptDocument& _rDocument ) override;
virtual void onDocumentSaveAsDone( const ScriptDocument& _rDocument ) override;
virtual void onDocumentClosed( const ScriptDocument& _rDocument ) override;
virtual void onDocumentTitleChanged( const ScriptDocument& _rDocument ) override;
virtual void onDocumentModeChanged( const ScriptDocument& _rDocument ) override;
public:
SbTreeListBox(std::unique_ptr<weld::TreeView> xControl, weld::Window* pTopLevel);
virtual ~SbTreeListBox() override;
void ScanEntry( const ScriptDocument& rDocument, LibraryLocation eLocation );
void ScanAllEntries();
void UpdateEntries();
bool IsEntryProtected(const weld::TreeIter* pEntry);
void SetMode( BrowseMode nM ) { nMode = nM; }
BrowseMode GetMode() const { return nMode; }
SbModule* FindModule(const weld::TreeIter* pEntry);
SbxVariable* FindVariable(const weld::TreeIter* pEntry);
bool FindRootEntry(const ScriptDocument& rDocument, LibraryLocation eLocation, weld::TreeIter& rIter);
bool FindEntry(const OUString& rText, EntryType eType, weld::TreeIter& rIter);
EntryDescriptor GetEntryDescriptor(const weld::TreeIter* pEntry);
static ItemType ConvertType (EntryType eType);
bool IsValidEntry(weld::TreeIter& rEntry);
void AddEntry(const OUString& rText, const OUString& rImage,
const weld::TreeIter* pParent, bool bChildrenOnDemand,
std::unique_ptr<Entry>&& rUserData,
weld::TreeIter* pRet = nullptr);
void connect_changed(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_changed(rLink); }
std::unique_ptr<weld::TreeIter> make_iterator(const weld::TreeIter* pIter = nullptr) const { return m_xControl->make_iterator(pIter); }
void copy_iterator(const weld::TreeIter& rSource, weld::TreeIter& rDest) const { m_xControl->copy_iterator(rSource, rDest); }
bool get_selected(weld::TreeIter* pIter) const { return m_xControl->get_selected(pIter); }
void select(const weld::TreeIter& rIter) { m_xControl->select(rIter); }
void unselect(const weld::TreeIter& rIter) { m_xControl->unselect(rIter); }
void remove(const weld::TreeIter& rIter) { m_xControl->remove(rIter); }
bool get_cursor(weld::TreeIter* pIter) const { return m_xControl->get_cursor(pIter); }
void set_cursor(const weld::TreeIter& rIter) { m_xControl->set_cursor(rIter); }
OUString get_text(const weld::TreeIter& rIter) const { return m_xControl->get_text(rIter); }
void set_text(const weld::TreeIter& rIter, const OUString& rText) { m_xControl->set_text(rIter, rText); }
OUString get_id(const weld::TreeIter& rIter) const { return m_xControl->get_id(rIter); }
bool get_iter_first(weld::TreeIter& rIter) const { return m_xControl->get_iter_first(rIter); }
bool iter_next_sibling(weld::TreeIter& rIter) const { return m_xControl->iter_next_sibling(rIter); }
bool iter_children(weld::TreeIter& rIter) const { return m_xControl->iter_children(rIter); }
bool iter_parent(weld::TreeIter& rIter) const { return m_xControl->iter_parent(rIter); }
int get_iter_depth(const weld::TreeIter& rIter) const { return m_xControl->get_iter_depth(rIter); }
bool get_row_expanded(const weld::TreeIter& rIter) const { return m_xControl->get_row_expanded(rIter); }
void expand_row(const weld::TreeIter& rIter) { m_xControl->expand_row(rIter); }
void set_size_request(int nWidth, int nHeight) { m_xControl->set_size_request(nWidth, nHeight); }
float get_approximate_digit_width() const { return m_xControl->get_approximate_digit_width(); }
int get_height_rows(int nRows) const { return m_xControl->get_height_rows(nRows); }
int get_iter_index_in_parent(const weld::TreeIter& rIter) const { return m_xControl->get_iter_index_in_parent(rIter); }
void connect_editing(const Link<const weld::TreeIter&, bool>& rStartLink,
const Link<const std::pair<const weld::TreeIter&, OUString>&, bool>& rEndLink)
{
m_xControl->connect_editing(rStartLink, rEndLink);
}
void make_sorted() { m_xControl->make_sorted(); };
void make_unsorted() { m_xControl->make_unsorted(); }
bool get_sort_order() const { return m_xControl->get_sort_order(); }
void set_sort_order(bool bAscending) { m_xControl->set_sort_order(bAscending); }
void set_sort_indicator(TriState eState, int nColumn = -1)
{
m_xControl->set_sort_indicator(eState, nColumn);
}
TriState get_sort_indicator(int nColumn = -1)
{
return m_xControl->get_sort_indicator(nColumn);
}
int get_sort_column() const { return m_xControl->get_sort_column(); }
void set_sort_column(int nColumn) { m_xControl->set_sort_column(nColumn); }
void set_sort_func(const std::function<int(const weld::TreeIter&, const weld::TreeIter&)>& func)
{
m_xControl->set_sort_func(func);
}
void RemoveEntry(const weld::TreeIter& rIter);
void RemoveEntry(const ScriptDocument&);
OUString GetRootEntryName(const ScriptDocument& rDocument, LibraryLocation eLocation) const;
static OUString GetRootEntryBitmaps(const ScriptDocument& rDocument);
void SetCurrentEntry (EntryDescriptor const &);
weld::TreeView& get_widget() { return *m_xControl; }
private:
LibraryType GetLibraryType() const;
};
} // namespace basctl
#endif // INCLUDED_BASCTL_SOURCE_INC_BASTYPE2_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|