sd: keep a non-owning pointer to the OverridingShell
[LibreOffice.git] / sfx2 / source / inc / StyleList.hxx
blobbc8a90ada2482e935a70cb4cb81d4cb0603d7fd5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
22 #include <sal/config.h>
24 #include <o3tl/typed_flags_set.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/styfitem.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/style.hxx>
29 #include <vcl/idle.hxx>
30 #include <vcl/transfer.hxx>
31 #include <vcl/weld.hxx>
33 class SfxObjectShell;
34 class SfxStyleFamilyItem;
35 class SfxTemplateItem;
36 class SfxCommonTemplateDialog_Impl;
37 class SfxTemplateControllerItem;
39 enum class StyleFlags
41 NONE = 0,
42 UpdateFamilyList = 1,
43 UpdateFamily = 2
46 namespace o3tl
48 template <> struct typed_flags<StyleFlags> : is_typed_flags<StyleFlags, 3>
53 class TreeViewDropTarget;
55 constexpr int MAX_FAMILIES = 6;
56 constexpr int COUNT_BOUND_FUNC = 14;
58 class StyleList final : public SfxListener
60 friend class TreeViewDropTarget;
61 friend class SfxTemplateControllerItem;
63 public:
64 // Constructor
65 StyleList(weld::Builder* pBuilder, SfxBindings* pBindings, SfxCommonTemplateDialog_Impl* Parent,
66 weld::Container* pC, const OUString& treeviewname, const OUString& flatviewname);
68 // Destructor
69 ~StyleList();
71 // This function connects m_xTreeBox, m_xFmtLb and m_pParentDialog with certain LINKs
72 void Initialize();
74 // It selects the style in treeview
75 // bIsCallBack is true for the selected style. For eg. if "Addressee" is selected in
76 // styles, bIsCallBack will be true for it.
77 void SelectStyle(const OUString& rStr, bool bIsCallback);
78 // Checks whether a family has a saved state
79 bool CurrentFamilyHasState() { return nullptr != m_pFamilyState[m_nActFamily - 1]; }
81 // This function is a subpart of Dialog's SetFamilyState
82 // When a new style is selected for use, it resets it.
83 void SetFamilyState(sal_uInt16 nSlotId, const SfxTemplateItem* pItem);
85 // It is used in Dialog's EnableExample_Impl
86 // When the value of m_bNewbyExampleDisabled is updated there
87 // while creating a new style by example,
88 // the corresponding value gets updated here too.
89 void EnableNewByExample(bool newByExampleDisabled);
91 // This function is used to set a hierarchical view.
92 void SetHierarchical();
93 // This function handles the controls while setting a filter except hierarchical
94 void SetFilterControlsHandle();
95 // Return whether treeview is visible
96 // It is used in StyleList's UpdateStyles_Hdl
97 // It is used to defaultly set the hierarchical view
98 bool IsTreeView() const { return m_xTreeBox->get_visible(); }
100 // Helper function: Access to the current family item
101 // Used in Dialog's updateStyleHandler, Execute_Impl etc...
102 const SfxStyleFamilyItem* GetFamilyItem() const;
103 // Used to get the current selected entry in treeview
104 // Used in Dialog's Execute_Impl, Action_Select etc...
105 OUString GetSelectedEntry() const;
106 // Returns the Family Item at ith index
107 // Used in Dialog's ReadResource_Hdl
108 const SfxStyleFamilyItem& GetFamilyItemByIndex(size_t i) const;
109 bool IsHierarchical() const { return m_bHierarchical; }
111 void Enabledel(bool candel) { m_bCanDel = candel; }
112 void Enablehide(bool canhide) { m_bCanHide = canhide; }
113 void Enableshow(bool canshow) { m_bCanShow = canshow; }
114 void Enablenew(bool cannew) { m_bCanNew = cannew; }
115 void Enableedit(bool canedit) { m_bCanEdit = canedit; }
117 // Used in Dialog's Execute_Impl
118 // It is a necessary condition to execute a style
119 bool EnableExecute();
121 void connect_UpdateStyles(const Link<StyleFlags, void>& rLink) { m_aUpdateStyles = rLink; }
122 void connect_ReadResource(const Link<StyleList&, void>& rLink) { m_aReadResource = rLink; }
123 void connect_ClearResource(const Link<void*, void>& rLink) { m_aClearResource = rLink; }
124 void connect_LoadFactoryStyleFilter(const Link<SfxObjectShell const*, sal_Int32>& rLink);
125 void connect_SaveSelection(const Link<StyleList&, SfxObjectShell*> rLink);
126 void connect_UpdateFamily(const Link<StyleList&, void> rLink) { m_aUpdateFamily = rLink; }
128 void FamilySelect(sal_uInt16 nEntry, bool bRefresh = false);
129 void FilterSelect(sal_uInt16 nActFilter, bool bsetFilter);
131 DECL_LINK(NewMenuExecuteAction, void*, void);
132 DECL_LINK(OnPopupEnd, const OUString&, void);
134 bool HasStylesHighlighterFeature() { return m_bModuleHasStylesHighlighterFeature; }
135 void SetHighlightParaStyles(bool bSet) { m_bHighlightParaStyles = bSet; }
136 bool IsHighlightParaStyles() { return m_bHighlightParaStyles; }
137 void SetHighlightCharStyles(bool bSet) { m_bHighlightCharStyles = bSet; }
138 bool IsHighlightCharStyles() { return m_bHighlightCharStyles; }
140 private:
141 void FillTreeBox(SfxStyleFamily eFam);
143 void UpdateFamily();
144 void UpdateStyles(StyleFlags nFlags);
146 OUString getDefaultStyleName(const SfxStyleFamily eFam);
147 SfxStyleFamily GetActualFamily() const;
148 void GetSelectedStyle() const;
150 sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt, const DropTargetHelper& rHelper);
151 void DropHdl(const OUString& rStyle, const OUString& rParent);
153 void MenuSelect(const OUString& rIdent);
154 void PrepareMenu(const Point& rPos);
155 void ShowMenu(const CommandEvent& rCEvt);
156 void CreateContextMenu();
158 void Notify(SfxBroadcaster& rBC, const SfxHint& rHint);
160 // In which FamilyState do I have to look, in order to get the
161 // information of the ith Family in the pStyleFamilies.
162 sal_uInt16 StyleNrToInfoOffset(sal_uInt16 i);
164 DECL_LINK(ReadResource, void*, size_t);
165 DECL_LINK(Clear, void*, void);
166 DECL_LINK(Cleanup, void*, void);
167 DECL_LINK(ExecuteDrop, const ExecuteDropEvent&, sal_Int8);
168 DECL_LINK(IsSafeForWaterCan, void*, bool);
169 DECL_LINK(HasSelectedStyle, void*, bool);
170 DECL_LINK(UpdateStyleDependents, void*, void);
171 DECL_LINK(TimeOut, Timer*, void);
172 DECL_LINK(EnableTreeDrag, bool, void);
173 DECL_LINK(EnableDelete, void*, void);
174 DECL_LINK(SetWaterCanState, const SfxBoolItem*, void);
175 DECL_LINK(SetFamily, sal_uInt16, void);
177 void InvalidateBindings();
179 void Update();
180 Link<StyleFlags, void> m_aUpdateStyles;
181 Link<StyleList&, void> m_aReadResource;
182 Link<void*, void> m_aClearResource;
183 Link<SfxObjectShell const*, sal_Int32> m_aLoadFactoryStyleFilter;
184 Link<StyleList&, SfxObjectShell*> m_aSaveSelection;
185 Link<StyleList&, void> m_aUpdateFamily;
187 void NewHdl();
188 void EditHdl();
189 void DeleteHdl();
190 void HideHdl();
191 void ShowHdl();
193 DECL_LINK(DragBeginHdl, bool&, bool);
194 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
195 DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
196 DECL_LINK(CustomRenderHdl, weld::TreeView::render_args, void);
197 DECL_LINK(FmtSelectHdl, weld::TreeView&, void);
198 DECL_LINK(TreeListApplyHdl, weld::TreeView&, bool);
199 DECL_LINK(MousePressHdl, const MouseEvent&, bool);
200 DECL_STATIC_LINK(StyleList, CustomGetSizeHdl, weld::TreeView::get_size_args, Size);
201 DECL_LINK(PopupFlatMenuHdl, const CommandEvent&, bool);
202 DECL_LINK(PopupTreeMenuHdl, const CommandEvent&, bool);
203 DECL_LINK(MenuSelectAsyncHdl, void*, void);
205 bool m_bHierarchical : 1;
207 bool m_bAllowReParentDrop : 1;
208 bool m_bNewByExampleDisabled : 1;
209 bool m_bDontUpdate : 1;
210 bool m_bTreeDrag : 1;
211 bool m_bCanEdit : 1;
212 bool m_bCanHide : 1;
213 bool m_bCanShow : 1;
214 bool m_bCanNew : 1;
215 bool m_bUpdateFamily : 1;
216 bool m_bCanDel : 1;
217 bool m_bBindingUpdate : 1;
218 SfxStyleSheetBasePool* m_pStyleSheetPool;
219 sal_uInt16 m_nActFilter;
220 std::unique_ptr<weld::TreeView> m_xFmtLb;
221 std::unique_ptr<weld::TreeView> m_xTreeBox;
223 std::unique_ptr<weld::Builder> mxMenuBuilder;
224 std::unique_ptr<weld::Menu> mxMenu;
226 std::optional<SfxStyleFamilies> m_xStyleFamilies;
227 std::array<std::unique_ptr<SfxTemplateItem>, MAX_FAMILIES> m_pFamilyState;
228 SfxObjectShell* m_pCurObjShell;
229 sal_uInt16 m_nActFamily;
230 SfxStyleSearchBits m_nAppFilter; // Filter, which has set the application (for automatic)
232 std::unique_ptr<TreeViewDropTarget> m_xTreeView1DropTargetHelper;
233 std::unique_ptr<TreeViewDropTarget> m_xTreeView2DropTargetHelper;
235 SfxCommonTemplateDialog_Impl* m_pParentDialog;
236 SfxBindings* m_pBindings;
237 std::array<std::unique_ptr<SfxTemplateControllerItem>, COUNT_BOUND_FUNC> pBoundItems;
239 std::unique_ptr<Idle> pIdle;
241 OUString sLastItemIdent;
242 SfxModule* m_Module;
243 sal_uInt16 m_nModifier;
244 weld::Container* m_pContainer;
246 bool m_bModuleHasStylesHighlighterFeature = false;
247 bool m_bHighlightParaStyles = false;
248 bool m_bHighlightCharStyles = false;