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 #ifndef INCLUDED_SFX2_SOURCE_INC_TEMPLDGI_HXX
20 #define INCLUDED_SFX2_SOURCE_INC_TEMPLDGI_HXX
21 
22 class SfxTemplateControllerItem;
23 
24 #include <sal/config.h>
25 
26 #include <array>
27 #include <memory>
28 #include <optional>
29 
30 #include <vcl/transfer.hxx>
31 #include <vcl/weld.hxx>
32 #include <svl/lstner.hxx>
33 #include <svl/eitem.hxx>
34 
35 #include <svl/style.hxx>
36 
37 #include <sfx2/childwin.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <sfx2/styfitem.hxx>
40 #include <sfx2/templdlg.hxx>
41 
42 #include <vcl/idle.hxx>
43 
44 class SfxStyleFamilyItem;
45 class SfxTemplateItem;
46 class SfxBindings;
47 class SfxStyleSheetBase;
48 class SfxStyleSheetBasePool;
49 class StyleTreeListBox_Impl;
50 class SfxTemplateDialog_Impl;
51 class SfxCommonTemplateDialog_Impl;
52 
53 namespace com::sun::star::frame {
54     class XModuleManager2;
55 }
56 
57 enum class StyleFlags {
58     NONE=0, UpdateFamilyList=1, UpdateFamily=2
59 };
60 namespace o3tl {
61     template<> struct typed_flags<StyleFlags> : is_typed_flags<StyleFlags, 3> {};
62 }
63 
64 class TreeViewDropTarget;
65 
66 class SfxCommonTemplateDialog_Impl : public SfxListener
67 {
68 private:
69     class DeletionWatcher;
70     friend class DeletionWatcher;
71 
72     void ReadResource();
73     void ClearResource();
74     void impl_clear();
75     DeletionWatcher* impl_setDeletionWatcher(DeletionWatcher* pNewWatcher);
76     OUString getDefaultStyleName( const SfxStyleFamily eFam );
77 
78 protected:
79 #define MAX_FAMILIES            6
80 #define COUNT_BOUND_FUNC        14
81 
82     friend class SfxTemplateControllerItem;
83 
84     SfxBindings* pBindings;
85     std::array<std::unique_ptr<SfxTemplateControllerItem>, COUNT_BOUND_FUNC> pBoundItems;
86 
87     weld::Container* mpContainer;
88     std::unique_ptr<weld::Builder> mxMenuBuilder;
89     std::unique_ptr<weld::Menu> mxMenu;
90     OString sLastItemIdent;
91     SfxModule* pModule;
92     std::unique_ptr<Idle> pIdle;
93 
94     std::optional<SfxStyleFamilies> mxStyleFamilies;
95     std::array<std::unique_ptr<SfxTemplateItem>, MAX_FAMILIES> pFamilyState;
96     SfxStyleSheetBasePool* pStyleSheetPool;
97     SfxObjectShell* pCurObjShell;
98     css::uno::Reference<css::frame::XModuleManager2> xModuleManager;
99     DeletionWatcher* m_pDeletionWatcher;
100 
101     std::unique_ptr<weld::TreeView> mxFmtLb;
102     std::unique_ptr<weld::TreeView> mxTreeBox;
103     std::unique_ptr<weld::CheckButton> mxPreviewCheckbox;
104     std::unique_ptr<weld::ComboBox> mxFilterLb;
105     std::unique_ptr<TreeViewDropTarget> m_xTreeView1DropTargetHelper;
106     std::unique_ptr<TreeViewDropTarget> m_xTreeView2DropTargetHelper;
107 
108     sal_uInt16 nActFamily; // Id in the ToolBox = Position - 1
109     sal_uInt16 nActFilter; // FilterIdx
110     SfxStyleSearchBits nAppFilter; // Filter, which has set the application (for automatic)
111 
112     sal_uInt16 m_nModifier;
113     bool bDontUpdate :1;
114     bool bIsWater :1;
115     bool bUpdate :1;
116     bool bUpdateFamily :1;
117     bool bCanEdit :1;
118     bool bCanDel :1;
119     bool bCanNew :1;
120     bool bCanHide :1;
121     bool bCanShow :1;
122     bool bWaterDisabled :1;
123     bool bNewByExampleDisabled :1;
124     bool bUpdateByExampleDisabled :1;
125     bool bTreeDrag :1;
126     bool bAllowReParentDrop:1;
127     bool bHierarchical :1;
128     bool m_bWantHierarchical :1;
129     bool bBindingUpdate :1;
130 
131     DECL_LINK(FilterSelectHdl, weld::ComboBox&, void );
132     DECL_LINK(FmtSelectHdl, weld::TreeView&, void);
133     DECL_LINK(TreeListApplyHdl, weld::TreeView&, bool);
134     DECL_LINK(MousePressHdl, const MouseEvent&, bool);
135     DECL_LINK(TimeOut, Timer*, void );
136     DECL_LINK(PreviewHdl, weld::Toggleable&, void);
137     DECL_LINK(PopupFlatMenuHdl, const CommandEvent&, bool);
138     DECL_LINK(PopupTreeMenuHdl, const CommandEvent&, bool);
139     DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
140     DECL_LINK(QueryTooltipHdl, const weld::TreeIter&, OUString);
141     DECL_LINK(OnAsyncExecuteDrop, void *, void);
142     DECL_LINK(DragBeginHdl, bool&, bool);
143     DECL_LINK(CustomRenderHdl, weld::TreeView::render_args, void);
144     DECL_STATIC_LINK(SfxCommonTemplateDialog_Impl, CustomGetSizeHdl, weld::TreeView::get_size_args, Size);
145 
146     void DropHdl(const OUString& rStyle, const OUString& rParent);
147 
EnableItem(const OString &,bool=true)148     virtual void EnableItem(const OString& /*rMesId*/, bool /*bCheck*/ = true)
149     {}
CheckItem(const OString &,bool=true)150     virtual void CheckItem(const OString& /*rMesId*/, bool /*bCheck*/ = true)
151     {}
IsCheckedItem(const OString &)152     virtual bool IsCheckedItem(const OString& /*rMesId*/ )
153     {
154         return true;
155     }
156 
157     void InvalidateBindings();
158     virtual void InsertFamilyItem(sal_uInt16 nId, const SfxStyleFamilyItem& rItem) = 0;
159     virtual void EnableFamilyItem(sal_uInt16 nId, bool bEnabled) = 0;
160     virtual void ClearFamilyList() = 0;
161     virtual void ReplaceUpdateButtonByMenu();
162 
163     void NewHdl();
164     void EditHdl();
165     void DeleteHdl();
166     void HideHdl();
167     void ShowHdl();
168 
169     bool Execute_Impl(sal_uInt16 nId, const OUString& rStr, const OUString& rRefStr,
170                       sal_uInt16 nFamily, SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto,
171                       sal_uInt16* pIdx = nullptr, const sal_uInt16* pModifier = nullptr );
172 
173     void UpdateStyles_Impl(StyleFlags nFlags);
174     const SfxStyleFamilyItem* GetFamilyItem_Impl() const;
IsInitialized() const175     bool IsInitialized() const
176     {
177         return nActFamily != 0xffff;
178     }
179     void EnableDelete();
180     void Initialize();
181     void EnableHierarchical(bool);
182 
183     void FilterSelect( sal_uInt16 nFilterIdx, bool bForce );
184     void SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* );
185     void SetWaterCanState( const SfxBoolItem* pItem );
186     bool IsSafeForWaterCan() const;
187 
188     void SelectStyle(const OUString& rStyle, bool bIsCallback);
189     void UpdateStyleDependents();
190     bool HasSelectedStyle() const;
191     void GetSelectedStyle() const;
192     void FillTreeBox();
193     void Update_Impl();
194     void UpdateFamily_Impl();
195 
196     // In which FamilyState do I have to look, in order to get the
197     // information of the ith Family in the pStyleFamilies.
198     sal_uInt16 StyleNrToInfoOffset( sal_uInt16 i );
199 
200     void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
201 
202     void FamilySelect( sal_uInt16 nId, bool bPreviewRefresh = false );
203     void SetFamily(SfxStyleFamily nFamily);
204     void ActionSelect(const OString& rId);
205 
206     sal_Int32 LoadFactoryStyleFilter( SfxObjectShell const * i_pObjSh );
207     void SaveFactoryStyleFilter( SfxObjectShell const * i_pObjSh, sal_Int32 i_nFilter );
208     SfxObjectShell* SaveSelection();
209 
210     void PrepareMenu(const Point& rPos);
211     void ShowMenu(const CommandEvent& rCEvt);
212 
213 public:
214 
215     SfxCommonTemplateDialog_Impl(SfxBindings* pB, weld::Container*, weld::Builder* pBuilder);
216     virtual ~SfxCommonTemplateDialog_Impl() override;
217 
218     void MenuSelect(const OString& rIdent);
219     DECL_LINK( MenuSelectAsyncHdl, void*, void );
220 
EnableEdit(bool b)221     virtual void EnableEdit( bool b )
222     {
223         bCanEdit = b;
224     }
EnableDel(bool b)225     void EnableDel( bool b )
226     {
227         bCanDel = b;
228     }
EnableNew(bool b)229     void EnableNew( bool b )
230     {
231         bCanNew = b;
232     }
EnableHide(bool b)233     void EnableHide( bool b )
234     {
235         bCanHide = b;
236     }
EnableShow(bool b)237     void EnableShow( bool b )
238     {
239         bCanShow = b;
240     }
241 
242     void EnableTreeDrag(bool b);
243     void EnableExample_Impl(sal_uInt16 nId, bool bEnable);
244     SfxStyleFamily GetActualFamily() const;
245     OUString GetSelectedEntry() const;
246 
GetObjectShell() const247     SfxObjectShell* GetObjectShell() const
248     {
249         return pCurObjShell;
250     }
251 
252     sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt, const DropTargetHelper& rHelper);
253     sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt);
254 
255     void CreateContextMenu();
256 };
257 
258 class ToolbarDropTarget;
259 class DropTargetHelper;
260 
261 class SfxTemplateDialog_Impl :  public SfxCommonTemplateDialog_Impl
262 {
263 private:
264     friend class SfxTemplateControllerItem;
265     friend class SfxTemplatePanelControl;
266 
267     std::unique_ptr<ToolbarDropTarget> m_xToolbarDropTargetHelper;
268     std::unique_ptr<weld::Toolbar> m_xActionTbL;
269     std::unique_ptr<weld::Toolbar> m_xActionTbR;
270     std::unique_ptr<weld::Menu> m_xToolMenu;
271     int m_nActionTbLVisible;
272 
273     void FillToolMenu();
274 
275     DECL_LINK(ToolBoxLSelect, const OString&, void);
276     DECL_LINK(ToolBoxRSelect, const OString&, void);
277     DECL_LINK(ToolMenuSelectHdl, const OString&, void);
278 
279 protected:
280     virtual void EnableEdit( bool ) override;
281     virtual void EnableItem(const OString& rMesId, bool bCheck = true) override;
282     virtual void CheckItem(const OString& rMesId, bool bCheck = true) override;
283     virtual bool IsCheckedItem(const OString& rMesId) override;
284     virtual void InsertFamilyItem(sal_uInt16 nId, const SfxStyleFamilyItem& rItem) override;
285     virtual void EnableFamilyItem(sal_uInt16 nId, bool bEnabled) override;
286     virtual void ClearFamilyList() override;
287     virtual void ReplaceUpdateButtonByMenu() override;
288 
289 public:
290     friend class SfxTemplateDialog;
291 
292     SfxTemplateDialog_Impl( SfxBindings*, SfxTemplatePanelControl* pDlgWindow );
293     virtual ~SfxTemplateDialog_Impl() override;
294 
295     sal_Int8 AcceptToolbarDrop(const AcceptDropEvent& rEvt, const DropTargetHelper& rHelper);
296 
297     void Initialize();
298 };
299 
300 #endif // INCLUDED_SFX2_SOURCE_INC_TEMPLDGI_HXX
301 
302 
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
304