LibreOffice Module sfx2 (master) 1
StyleList.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
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>
32
33class SfxObjectShell;
35class SfxTemplateItem;
38
39enum class StyleFlags
40{
41 NONE = 0,
43 UpdateFamily = 2
44};
45
46namespace o3tl
47{
48template <> struct typed_flags<StyleFlags> : is_typed_flags<StyleFlags, 3>
49{
50};
51}
52
54
55constexpr int MAX_FAMILIES = 6;
56constexpr int COUNT_BOUND_FUNC = 14;
57
58class StyleList final : public SfxListener
59{
60 friend class TreeViewDropTarget;
62
63public:
64 // Constructor
66 weld::Container* pC, OUString treeviewname, OUString flatviewname);
67
68 // Destructor
69 ~StyleList();
70
71 // This function connects m_xTreeBox, m_xFmtLb and m_pParentDialog with certain LINKs
72 void Initialize();
73
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]; }
80
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);
84
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);
90
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
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(); }
99
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; }
110
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; }
116
117 // Used in Dialog's Execute_Impl
118 // It is a necessary condition to execute a style
119 bool EnableExecute();
120
127
128 void FamilySelect(sal_uInt16 nEntry, bool bRefresh = false);
129 void FilterSelect(sal_uInt16 nActFilter, bool bsetFilter);
130
131 DECL_LINK(NewMenuExecuteAction, void*, void);
132
138
139private:
140 void FillTreeBox(SfxStyleFamily eFam);
141
142 void UpdateFamily();
143 void UpdateStyles(StyleFlags nFlags);
144
145 OUString getDefaultStyleName(const SfxStyleFamily eFam);
147 void GetSelectedStyle() const;
148
149 sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt, const DropTargetHelper& rHelper);
150 void DropHdl(const OUString& rStyle, const OUString& rParent);
151
152 void MenuSelect(const OUString& rIdent);
153 void PrepareMenu(const Point& rPos);
154 void ShowMenu(const CommandEvent& rCEvt);
155 void CreateContextMenu();
156
157 void Notify(SfxBroadcaster& rBC, const SfxHint& rHint);
158
159 // In which FamilyState do I have to look, in order to get the
160 // information of the ith Family in the pStyleFamilies.
161 sal_uInt16 StyleNrToInfoOffset(sal_uInt16 i);
162
163 DECL_LINK(ReadResource, void*, size_t);
164 DECL_LINK(Clear, void*, void);
165 DECL_LINK(Cleanup, void*, void);
166 DECL_LINK(ExecuteDrop, const ExecuteDropEvent&, sal_Int8);
167 DECL_LINK(IsSafeForWaterCan, void*, bool);
168 DECL_LINK(HasSelectedStyle, void*, bool);
169 DECL_LINK(UpdateStyleDependents, void*, void);
170 DECL_LINK(TimeOut, Timer*, void);
171 DECL_LINK(EnableTreeDrag, bool, void);
172 DECL_LINK(EnableDelete, void*, void);
173 DECL_LINK(SetWaterCanState, const SfxBoolItem*, void);
174 DECL_LINK(SetFamily, sal_uInt16, void);
175
176 void InvalidateBindings();
177
178 void Update();
185
186 void NewHdl();
187 void EditHdl();
188 void DeleteHdl();
189 void HideHdl();
190 void ShowHdl();
191
192 DECL_LINK(DragBeginHdl, bool&, bool);
193 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
194 DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
195 DECL_LINK(CustomRenderHdl, weld::TreeView::render_args, void);
196 DECL_LINK(FmtSelectHdl, weld::TreeView&, void);
197 DECL_LINK(TreeListApplyHdl, weld::TreeView&, bool);
198 DECL_LINK(MousePressHdl, const MouseEvent&, bool);
200 DECL_LINK(PopupFlatMenuHdl, const CommandEvent&, bool);
201 DECL_LINK(PopupTreeMenuHdl, const CommandEvent&, bool);
202 DECL_LINK(MenuSelectAsyncHdl, void*, void);
203
205
209 bool m_bTreeDrag : 1;
210 bool m_bCanEdit : 1;
211 bool m_bCanHide : 1;
212 bool m_bCanShow : 1;
213 bool m_bCanNew : 1;
215 bool m_bCanDel : 1;
218 sal_uInt16 m_nActFilter;
219 std::unique_ptr<weld::TreeView> m_xFmtLb;
220 std::unique_ptr<weld::TreeView> m_xTreeBox;
221
222 std::unique_ptr<weld::Builder> mxMenuBuilder;
223 std::unique_ptr<weld::Menu> mxMenu;
224
225 std::optional<SfxStyleFamilies> m_xStyleFamilies;
226 std::array<std::unique_ptr<SfxTemplateItem>, MAX_FAMILIES> m_pFamilyState;
228 sal_uInt16 m_nActFamily;
229 SfxStyleSearchBits m_nAppFilter; // Filter, which has set the application (for automatic)
230
231 std::unique_ptr<TreeViewDropTarget> m_xTreeView1DropTargetHelper;
232 std::unique_ptr<TreeViewDropTarget> m_xTreeView2DropTargetHelper;
233
236 std::array<std::unique_ptr<SfxTemplateControllerItem>, COUNT_BOUND_FUNC> pBoundItems;
237
238 std::unique_ptr<Idle> pIdle;
239
242 sal_uInt16 m_nModifier;
244
248};
constexpr int COUNT_BOUND_FUNC
Definition: StyleList.hxx:56
StyleFlags
Definition: StyleList.hxx:40
constexpr int MAX_FAMILIES
Definition: StyleList.hxx:55
SfxBindings * pBindings
Definition: ctrlitem.hxx:34
DECL_LINK(MousePressHdl, const MouseEvent &, bool)
const SfxStyleFamilyItem & GetFamilyItemByIndex(size_t i) const
Definition: StyleList.cxx:1870
DECL_LINK(EnableTreeDrag, bool, void)
sal_Int8 AcceptDrop(const AcceptDropEvent &rEvt, const DropTargetHelper &rHelper)
Drop is enabled as long as it is allowed to create a new style by example, i.e.
Definition: StyleList.cxx:455
DECL_LINK(SetFamily, sal_uInt16, void)
bool IsHierarchical() const
Definition: StyleList.hxx:109
void FamilySelect(sal_uInt16 nEntry, bool bRefresh=false)
Definition: StyleList.cxx:872
bool m_bNewByExampleDisabled
Definition: StyleList.hxx:207
Link< StyleFlags, void > m_aUpdateStyles
Definition: StyleList.hxx:179
std::unique_ptr< weld::TreeView > m_xTreeBox
Definition: StyleList.hxx:220
void Initialize()
Definition: StyleList.cxx:347
DECL_LINK(IsSafeForWaterCan, void *, bool)
void UpdateStyles(StyleFlags nFlags)
Definition: StyleList.cxx:1161
SfxStyleFamily GetActualFamily() const
Definition: StyleList.cxx:1132
bool m_bHighlightCharStyles
Definition: StyleList.hxx:247
void UpdateFamily()
Definition: StyleList.cxx:401
void Enabledel(bool candel)
Definition: StyleList.hxx:111
OUString getDefaultStyleName(const SfxStyleFamily eFam)
Definition: StyleList.cxx:1104
void CreateContextMenu()
Definition: StyleList.cxx:175
std::optional< SfxStyleFamilies > m_xStyleFamilies
Definition: StyleList.hxx:225
std::array< std::unique_ptr< SfxTemplateItem >, MAX_FAMILIES > m_pFamilyState
Definition: StyleList.hxx:226
void SetHighlightParaStyles(bool bSet)
Definition: StyleList.hxx:134
bool m_bBindingUpdate
Definition: StyleList.hxx:216
std::unique_ptr< Idle > pIdle
Definition: StyleList.hxx:238
bool m_bTreeDrag
Definition: StyleList.hxx:209
bool m_bCanShow
Definition: StyleList.hxx:212
SfxModule * m_Module
Definition: StyleList.hxx:241
void EditHdl()
Definition: StyleList.cxx:1320
void HideHdl()
Definition: StyleList.cxx:1397
bool HasStylesHighlighterFeature()
Definition: StyleList.hxx:133
Link< StyleList &, SfxObjectShell * > m_aSaveSelection
Definition: StyleList.hxx:183
sal_uInt16 m_nModifier
Definition: StyleList.hxx:242
SfxCommonTemplateDialog_Impl * m_pParentDialog
Definition: StyleList.hxx:234
Link< void *, void > m_aClearResource
Definition: StyleList.hxx:181
void connect_LoadFactoryStyleFilter(const Link< SfxObjectShell const *, sal_Int32 > &rLink)
Definition: StyleList.cxx:442
void Enableshow(bool canshow)
Definition: StyleList.hxx:113
Link< StyleList &, void > m_aUpdateFamily
Definition: StyleList.hxx:184
bool IsTreeView() const
Definition: StyleList.hxx:98
void SelectStyle(const OUString &rStr, bool bIsCallback)
Definition: StyleList.cxx:896
bool m_bHierarchical
Definition: StyleList.hxx:204
DECL_LINK(HasSelectedStyle, void *, bool)
DECL_LINK(CustomRenderHdl, weld::TreeView::render_args, void)
void connect_ClearResource(const Link< void *, void > &rLink)
Definition: StyleList.hxx:123
Link< StyleList &, void > m_aReadResource
Definition: StyleList.hxx:180
const SfxStyleFamilyItem * GetFamilyItem() const
Definition: StyleList.cxx:808
void SetFamilyState(sal_uInt16 nSlotId, const SfxTemplateItem *pItem)
Definition: StyleList.cxx:1274
void Enablenew(bool cannew)
Definition: StyleList.hxx:114
DECL_LINK(ExecuteDrop, const ExecuteDropEvent &, sal_Int8)
bool m_bCanEdit
Definition: StyleList.hxx:210
DECL_LINK(PopupFlatMenuHdl, const CommandEvent &, bool)
void connect_ReadResource(const Link< StyleList &, void > &rLink)
Definition: StyleList.hxx:122
DECL_LINK(Clear, void *, void)
void DeleteHdl()
Definition: StyleList.cxx:1334
DECL_LINK(EnableDelete, void *, void)
void PrepareMenu(const Point &rPos)
Definition: StyleList.cxx:588
void EnableNewByExample(bool newByExampleDisabled)
Definition: StyleList.cxx:298
void connect_SaveSelection(const Link< StyleList &, SfxObjectShell * > rLink)
Definition: StyleList.cxx:447
void Enableedit(bool canedit)
Definition: StyleList.hxx:115
std::unique_ptr< weld::Menu > mxMenu
Definition: StyleList.hxx:223
sal_uInt16 m_nActFamily
Definition: StyleList.hxx:228
void MenuSelect(const OUString &rIdent)
Definition: StyleList.cxx:1486
bool m_bDontUpdate
Definition: StyleList.hxx:208
void Update()
Definition: StyleList.cxx:1764
DECL_STATIC_LINK(StyleList, CustomGetSizeHdl, weld::TreeView::get_size_args, Size)
DECL_LINK(TimeOut, Timer *, void)
bool m_bHighlightParaStyles
Definition: StyleList.hxx:246
DECL_LINK(FmtSelectHdl, weld::TreeView &, void)
DECL_LINK(QueryTooltipHdl, const weld::TreeIter &, OUString)
void connect_UpdateFamily(const Link< StyleList &, void > rLink)
Definition: StyleList.hxx:126
DECL_LINK(Cleanup, void *, void)
std::array< std::unique_ptr< SfxTemplateControllerItem >, COUNT_BOUND_FUNC > pBoundItems
Definition: StyleList.hxx:236
std::unique_ptr< TreeViewDropTarget > m_xTreeView2DropTargetHelper
Definition: StyleList.hxx:232
SfxObjectShell * m_pCurObjShell
Definition: StyleList.hxx:227
DECL_LINK(MenuSelectAsyncHdl, void *, void)
StyleList(weld::Builder *pBuilder, SfxBindings *pBindings, SfxCommonTemplateDialog_Impl *Parent, weld::Container *pC, OUString treeviewname, OUString flatviewname)
Definition: StyleList.cxx:121
void SetFilterControlsHandle()
Definition: StyleList.cxx:1293
void ShowMenu(const CommandEvent &rCEvt)
Definition: StyleList.cxx:1477
void FillTreeBox(SfxStyleFamily eFam)
Definition: StyleList.cxx:1007
void connect_UpdateStyles(const Link< StyleFlags, void > &rLink)
Definition: StyleList.hxx:121
DECL_LINK(PopupTreeMenuHdl, const CommandEvent &, bool)
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
sal_uInt16 StyleNrToInfoOffset(sal_uInt16 i)
Definition: StyleList.cxx:801
SfxStyleSearchBits m_nAppFilter
Definition: StyleList.hxx:229
void NewHdl()
Definition: StyleList.cxx:1301
DECL_LINK(UpdateStyleDependents, void *, void)
std::unique_ptr< TreeViewDropTarget > m_xTreeView1DropTargetHelper
Definition: StyleList.hxx:231
void FilterSelect(sal_uInt16 nActFilter, bool bsetFilter)
Definition: StyleList.cxx:303
SfxBindings * m_pBindings
Definition: StyleList.hxx:235
DECL_LINK(TreeListApplyHdl, weld::TreeView &, bool)
bool m_bModuleHasStylesHighlighterFeature
Definition: StyleList.hxx:245
void Enablehide(bool canhide)
Definition: StyleList.hxx:112
std::unique_ptr< weld::TreeView > m_xFmtLb
Definition: StyleList.hxx:219
bool CurrentFamilyHasState()
Definition: StyleList.hxx:79
Link< SfxObjectShell const *, sal_Int32 > m_aLoadFactoryStyleFilter
Definition: StyleList.hxx:182
bool m_bCanNew
Definition: StyleList.hxx:213
void ShowHdl()
Definition: StyleList.cxx:1413
bool m_bAllowReParentDrop
Definition: StyleList.hxx:206
void InvalidateBindings()
Definition: StyleList.cxx:333
void SetHierarchical()
Definition: StyleList.cxx:1283
SfxStyleSheetBasePool * m_pStyleSheetPool
Definition: StyleList.hxx:217
sal_uInt16 m_nActFilter
Definition: StyleList.hxx:218
bool m_bUpdateFamily
Definition: StyleList.hxx:214
weld::Container * m_pContainer
Definition: StyleList.hxx:243
DECL_LINK(DragBeginHdl, bool &, bool)
bool m_bCanHide
Definition: StyleList.hxx:211
void Notify(SfxBroadcaster &rBC, const SfxHint &rHint)
Definition: StyleList.cxx:1494
OUString sLastItemIdent
Definition: StyleList.hxx:240
void DropHdl(const OUString &rStyle, const OUString &rParent)
Definition: StyleList.cxx:578
std::unique_ptr< weld::Builder > mxMenuBuilder
Definition: StyleList.hxx:222
DECL_LINK(SetWaterCanState, const SfxBoolItem *, void)
DECL_LINK(ReadResource, void *, size_t)
void GetSelectedStyle() const
Definition: StyleList.cxx:821
bool IsHighlightParaStyles()
Definition: StyleList.hxx:135
bool EnableExecute()
Definition: StyleList.cxx:437
OUString GetSelectedEntry() const
Definition: StyleList.cxx:829
bool IsHighlightCharStyles()
Definition: StyleList.hxx:137
void SetHighlightCharStyles(bool bSet)
Definition: StyleList.hxx:136
DECL_LINK(NewMenuExecuteAction, void *, void)
bool m_bCanDel
Definition: StyleList.hxx:215
std::tuple< vcl::RenderContext &, const tools::Rectangle &, bool, const OUString & > render_args
std::pair< vcl::RenderContext &, const OUString & > get_size_args
NONE
SfxStyleFamily
SfxStyleSearchBits
signed char sal_Int8