cid#1607171 Data race condition
[LibreOffice.git] / sd / source / ui / inc / navigatr.hxx
blob1e3657616167b73f1e30a9023d7d16679294033e
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 <sfx2/ctrlitem.hxx>
23 #include <sfx2/sidebar/PanelLayout.hxx>
24 #include <sfx2/navigat.hxx>
25 #include "sdtreelb.hxx"
26 #include <pres.hxx>
28 #include <sfx2/sidebar/IContextChangeReceiver.hxx>
29 #include <vcl/EnumContext.hxx>
31 // forward
32 namespace vcl { class Window; }
34 namespace sd {
35 class DrawDocShell;
36 class SdNavigatorFloat;
38 class Menu;
39 class SdNavigatorControllerItem;
40 class SdPageNameControllerItem;
42 enum class NavState {
43 NONE = 0x000000,
44 TableUpdate = 0x000100,
45 BtnFirstEnabled = 0x001000,
46 BtnFirstDisabled = 0x002000,
47 BtnPrevEnabled = 0x004000,
48 BtnPrevDisabled = 0x008000,
49 BtnLastEnabled = 0x010000,
50 BtnLastDisabled = 0x020000,
51 BtnNextEnabled = 0x040000,
52 BtnNextDisabled = 0x080000,
54 namespace o3tl {
55 template<> struct typed_flags<NavState> : is_typed_flags<NavState, 0x0ff100> {};
58 class NavDocInfo
60 public:
61 NavDocInfo()
62 : bName(false)
63 , bActive(false)
64 , mpDocShell(nullptr)
68 bool HasName() const { return bName; }
69 bool IsActive() const { return bActive; }
71 void SetName( bool bOn ) { bName = bOn; }
72 void SetActive( bool bOn ) { bActive = bOn; }
74 ::sd::DrawDocShell* GetDrawDocShell() {return mpDocShell;}
76 private:
77 friend class SdNavigatorWin;
78 bool bName : 1;
79 bool bActive : 1;
80 ::sd::DrawDocShell* mpDocShell;
83 namespace sd {
85 class SdNavigatorFloat final : public SfxNavigator
87 private:
88 std::unique_ptr<SdNavigatorWin> m_xNavWin;
89 bool m_bSetInitialFocusOnActivate;
91 public:
92 SdNavigatorFloat(SfxBindings* _pBindings, SfxChildWindow* pMgr,
93 vcl::Window* pParent, SfxChildWinInfo* pInfo);
94 void InitTreeLB(const SdDrawDocument* pDoc);
95 virtual void Activate() override;
96 virtual void dispose() override;
97 virtual ~SdNavigatorFloat() override;
102 class SAL_DLLPUBLIC_RTTI SdNavigatorWin : public PanelLayout, public sfx2::sidebar::IContextChangeReceiver
104 public:
105 typedef ::std::function<void ()> UpdateRequestFunctor;
107 /** Create a new instance of the navigator.
108 @param bUseActiveUpdate
109 When <TRUE/>, the default, then the SdNavigatorWin object
110 will make a SID_NAVIGATOR_INIT call whenever it thinks an
111 update is necessary. When <FALSE/> the navigator will
112 rely on others to trigger updates.
114 SD_DLLPUBLIC SdNavigatorWin(weld::Widget* pParent, SfxBindings* pBindings, SfxNavigator* pNavigatorDlg);
115 void SetUpdateRequestFunctor(const UpdateRequestFunctor& rUpdateRequest);
116 virtual ~SdNavigatorWin() override;
118 SD_DLLPUBLIC void InitTreeLB( const SdDrawDocument* pDoc );
119 void RefreshDocumentLB( const OUString* pDocName = nullptr );
120 void FirstFocus();
122 bool InsertFile(const OUString& rFileName);
124 NavigatorDragType GetNavigatorDragType();
125 SD_DLLPUBLIC SdPageObjsTLV& GetObjects();
127 virtual void HandleContextChange(const vcl::EnumContext& eContext) override;
129 private:
130 friend class SdNavigatorFloat;
131 friend class SdNavigatorControllerItem;
132 friend class SdPageNameControllerItem;
134 std::unique_ptr<weld::Toolbar> mxToolbox;
135 std::unique_ptr<SdPageObjsTLV> mxTlbObjects;
136 std::unique_ptr<weld::ComboBox> mxLbDocs;
137 std::unique_ptr<weld::Menu> mxDragModeMenu;
138 std::unique_ptr<weld::Menu> mxShapeMenu;
140 VclPtr<SfxNavigator> mxNavigatorDlg;
142 bool mbDocImported;
143 OUString maDropFileName;
144 NavigatorDragType meDragType;
145 std::vector<NavDocInfo> maDocList;
146 SfxBindings* mpBindings;
147 std::unique_ptr<SdNavigatorControllerItem> mpNavigatorCtrlItem;
148 std::unique_ptr<SdPageNameControllerItem> mpPageNameCtrlItem;
150 /** This flag controls whether all shapes or only the named shapes are
151 shown.
153 // bool mbShowAllShapes;
155 static const OUString & GetDragTypeSdBmpId(NavigatorDragType eDT);
156 NavDocInfo* GetDocInfo();
158 DECL_DLLPRIVATE_LINK( SelectToolboxHdl, const OUString&, void );
159 DECL_DLLPRIVATE_LINK( DropdownClickToolBoxHdl, const OUString&, void );
160 DECL_DLLPRIVATE_LINK( ClickObjectHdl, weld::TreeView&, bool );
161 DECL_DLLPRIVATE_LINK( SelectDocumentHdl, weld::ComboBox&, void );
162 DECL_DLLPRIVATE_LINK( MenuSelectHdl, const OUString&, void );
163 DECL_DLLPRIVATE_LINK( ShapeFilterCallback, const OUString&, void );
164 DECL_DLLPRIVATE_LINK( KeyInputHdl, const KeyEvent&, bool );
165 DECL_DLLPRIVATE_STATIC_LINK(SdNavigatorWin, MouseReleaseHdl, const MouseEvent&, bool);
166 DECL_LINK(CommandHdl, const CommandEvent&, bool);
168 void SetDragImage();
170 void ExecuteContextMenuAction(std::u16string_view rSelectedPopupEntry);
172 public:
173 virtual weld::Window* GetFrameWeld() const override;
177 * ControllerItem for Navigator
179 class SdNavigatorControllerItem final : public SfxControllerItem
181 public:
182 SdNavigatorControllerItem( sal_uInt16, SdNavigatorWin*, SfxBindings*,
183 SdNavigatorWin::UpdateRequestFunctor aUpdateRequest);
185 protected:
186 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSId, SfxItemState eState,
187 const SfxPoolItem* pState ) override;
189 private:
190 SdNavigatorWin* pNavigatorWin;
191 const SdNavigatorWin::UpdateRequestFunctor maUpdateRequest;
195 * ControllerItem for Navigator to show the page in the TreeLB
197 class SdPageNameControllerItem final : public SfxControllerItem
199 public:
200 SdPageNameControllerItem( sal_uInt16, SdNavigatorWin*, SfxBindings*);
202 protected:
203 virtual void StateChangedAtToolBoxControl( sal_uInt16 nSId, SfxItemState eState,
204 const SfxPoolItem* pState ) override;
206 private:
207 SdNavigatorWin* pNavigatorWin;
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */