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_SW_SOURCE_UIBASE_INC_CONTTREE_HXX 20 #define INCLUDED_SW_SOURCE_UIBASE_INC_CONTTREE_HXX 21 22 #include <svl/lstner.hxx> 23 #include <vcl/treelistbox.hxx> 24 #include <vcl/svlbitm.hxx> 25 #include "swcont.hxx" 26 27 #include <map> 28 #include <memory> 29 30 #include <o3tl/enumarray.hxx> 31 #include <o3tl/typed_flags_set.hxx> 32 33 class SwWrtShell; 34 class SwContentType; 35 class SwNavigationPI; 36 class SwNavigationConfig; 37 class Menu; 38 class ToolBox; 39 class SwGlblDocContents; 40 class SwGlblDocContent; 41 class SfxObjectShell; 42 class SdrObject; 43 44 enum class EditEntryMode 45 { 46 EDIT = 0, 47 UPD_IDX = 1, 48 RMV_IDX = 2, 49 UNPROTECT_TABLE = 3, 50 DELETE = 4, 51 RENAME = 5, 52 }; 53 54 // Flags for PopupMenu-enable/disable 55 enum class MenuEnableFlags { 56 NONE = 0x0000, 57 InsertIdx = 0x0001, 58 InsertFile = 0x0002, 59 InsertText = 0x0004, 60 Edit = 0x0008, 61 Delete = 0x0010, 62 Update = 0x0020, 63 UpdateSel = 0x0040, 64 EditLink = 0x0080 65 }; 66 namespace o3tl { 67 template<> struct typed_flags<MenuEnableFlags> : is_typed_flags<MenuEnableFlags, 0x00ff> {}; 68 } 69 70 /** TreeListBox for content indicator */ 71 class SwContentTree final 72 : public SvTreeListBox 73 , public SfxListener 74 { 75 VclPtr<SwNavigationPI> m_xDialog; 76 OUString const m_sSpace; 77 AutoTimer m_aUpdTimer; 78 79 o3tl::enumarray<ContentTypeId,std::unique_ptr<SwContentType>> m_aActiveContentArr; 80 o3tl::enumarray<ContentTypeId,std::unique_ptr<SwContentType>> m_aHiddenContentArr; 81 OUString m_aContextStrings[CONTEXT_COUNT + 1]; 82 OUString const m_sRemoveIdx; 83 OUString const m_sUpdateIdx; 84 OUString const m_sUnprotTable; 85 OUString const m_sRename; 86 OUString const m_sReadonlyIdx; 87 OUString const m_sInvisible; 88 OUString const m_sPostItShow; 89 OUString const m_sPostItHide; 90 OUString const m_sPostItDelete; 91 92 SwWrtShell* m_pHiddenShell; // dropped Doc 93 SwWrtShell* m_pActiveShell; // the active or a const. open view 94 SwNavigationConfig* m_pConfig; 95 96 std::map< void*, bool > mOutLineNodeMap; 97 98 sal_Int32 m_nActiveBlock; 99 sal_Int32 m_nHiddenBlock; 100 ContentTypeId m_nRootType; 101 ContentTypeId m_nLastSelType; 102 sal_uInt8 m_nOutlineLevel; 103 104 enum class State { ACTIVE, CONSTANT, HIDDEN } m_eState; 105 106 bool m_bDocChgdInDragging :1; 107 bool m_bIsInternalDrag :1; 108 bool m_bIsRoot :1; 109 bool m_bIsIdleClear :1; 110 bool m_bIsLastReadOnly :1; 111 bool m_bIsOutlineMoveable :1; 112 bool m_bViewHasChanged :1; 113 114 static bool bIsInDrag; 115 116 bool m_bIsKeySpace; 117 tools::Rectangle m_aOldRectangle; 118 119 // outline root mode drag & drop 120 std::vector< SvTreeListEntry* > m_aDndOutlinesSelected; 121 122 /** 123 * Before any data will be deleted, the last active entry has to be found. 124 * After this the UserData will be deleted 125 */ 126 void FindActiveTypeAndRemoveUserData(); 127 128 using SvTreeListBox::ExecuteDrop; 129 using SvTreeListBox::EditEntry; 130 131 virtual void RequestHelp( const HelpEvent& rHEvt ) override; 132 virtual void InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&) override; 133 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; 134 135 SwNavigationPI* GetParentWindow(); 136 137 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override; 138 virtual void DragFinished( sal_Int8 ) override; 139 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; 140 141 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; 142 143 bool FillTransferData( TransferDataContainer& rTransfer, 144 sal_Int8& rDragMode ); 145 146 /** Check if the displayed content is valid. */ 147 bool HasContentChanged(); 148 149 virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData, 150 SvTreeListEntry* ) override; 151 virtual bool NotifyAcceptDrop( SvTreeListEntry* ) override; 152 153 virtual TriState NotifyMoving( SvTreeListEntry* pTarget, 154 SvTreeListEntry* pEntry, 155 SvTreeListEntry*& rpNewParent, 156 sal_uLong& rNewChildPos 157 ) override; 158 virtual TriState NotifyCopying( SvTreeListEntry* pTarget, 159 SvTreeListEntry* pEntry, 160 SvTreeListEntry*& rpNewParent, 161 sal_uLong& rNewChildPos 162 ) override; 163 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; 164 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; 165 166 void EditEntry( SvTreeListEntry const * pEntry, EditEntryMode nMode ); 167 168 void GotoContent(const SwContent* pCnt); SetInDrag(bool bSet)169 static void SetInDrag(bool bSet) {bIsInDrag = bSet;} 170 171 virtual VclPtr<PopupMenu> CreateContextMenu() override; 172 virtual void ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override; 173 174 public: 175 SwContentTree(vcl::Window* pParent, SwNavigationPI* pDialog); 176 virtual ~SwContentTree() override; 177 virtual void dispose() override; 178 OUString GetEntryAltText( SvTreeListEntry* pEntry ) const override; 179 OUString GetEntryLongDescription( SvTreeListEntry* pEntry ) const override; 180 SdrObject* GetDrawingObjectsByContent(const SwContent *pCnt); 181 182 /** Switch the display to Root */ 183 void ToggleToRoot(); 184 void SetRootType(ContentTypeId nType); 185 186 /** Show the file */ 187 void Display( bool bActiveView ); 188 /** In the Clear the content types have to be deleted, also. */ 189 void Clear(); 190 191 /** After a file is dropped on the Navigator, the new shell will be set */ 192 void SetHiddenShell(SwWrtShell* pSh); 193 void ShowHiddenShell(); 194 void ShowActualView(); 195 196 /** Document change - set new Shell */ 197 void SetActiveShell(SwWrtShell* pSh); 198 199 /** Set an open view as active. */ 200 void SetConstantShell(SwWrtShell* pSh); 201 GetWrtShell()202 SwWrtShell* GetWrtShell() 203 { return State::HIDDEN == m_eState ? m_pHiddenShell : m_pActiveShell; } 204 IsInDrag()205 static bool IsInDrag() {return bIsInDrag;} 206 GetOutlineLevel() const207 sal_uInt8 GetOutlineLevel()const {return m_nOutlineLevel;} 208 void SetOutlineLevel(sal_uInt8 nSet); 209 210 /** Expand - Remember the state for content types */ 211 virtual bool Expand( SvTreeListEntry* pParent ) override; 212 /** Collapse - Remember the state for content types. */ 213 virtual bool Collapse( SvTreeListEntry* pParent ) override; 214 215 /** Execute commands of the Navigator */ 216 void ExecCommand(const OUString& rCmd, bool bModifier); 217 218 void ShowTree(); 219 /** folded together will not be glidled */ 220 void HideTree(); 221 IsConstantView() const222 bool IsConstantView() const { return State::CONSTANT == m_eState; } IsActiveView() const223 bool IsActiveView() const { return State::ACTIVE == m_eState; } IsHiddenView() const224 bool IsHiddenView() const { return State::HIDDEN == m_eState; } 225 GetActiveWrtShell() const226 const SwWrtShell* GetActiveWrtShell() const {return m_pActiveShell;} GetHiddenWrtShell()227 SwWrtShell* GetHiddenWrtShell() {return m_pHiddenShell;} 228 229 DECL_LINK( ContentDoubleClickHdl, SvTreeListBox*, bool ); 230 DECL_LINK( TimerUpdate, Timer *, void ); 231 232 virtual sal_IntPtr GetTabPos( SvTreeListEntry*, SvLBoxTab* ) override; 233 virtual void RequestingChildren( SvTreeListEntry* pParent ) override; 234 virtual void GetFocus() override; 235 virtual void KeyInput(const KeyEvent& rKEvt) override; 236 237 virtual bool Select( SvTreeListEntry* pEntry, bool bSelect=true ) override; 238 virtual Size GetOptimalSize() const override; 239 240 virtual void Notify(SfxBroadcaster& rBC, SfxHint const& rHint) override; 241 242 }; 243 244 // TreeListBox for global documents 245 246 class SwLBoxString : public SvLBoxString 247 { 248 public: 249 SwLBoxString(const OUString & rStr)250 SwLBoxString( const OUString& rStr ) : SvLBoxString(rStr) 251 { 252 } 253 254 virtual void Paint(const Point& rPos, SvTreeListBox& rDev, vcl::RenderContext& rRenderContext, 255 const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) override; 256 }; 257 258 namespace sfx2 { class DocumentInserter; } 259 namespace sfx2 { class FileDialogHelper; } 260 261 class SwGlobalTree final : public SvTreeListBox 262 { 263 private: 264 VclPtr<SwNavigationPI> m_xDialog; 265 AutoTimer m_aUpdateTimer; 266 OUString m_aContextStrings[GLOBAL_CONTEXT_COUNT]; 267 268 SwWrtShell* m_pActiveShell; 269 SvTreeListEntry* m_pEmphasisEntry; // Drag'n Drop emphasis 270 SvTreeListEntry* m_pDDSource; // source for Drag'n Drop 271 std::unique_ptr<SwGlblDocContents> m_pSwGlblDocContents; // array with sorted content 272 273 std::unique_ptr<SwGlblDocContent> m_pDocContent; 274 std::unique_ptr<sfx2::DocumentInserter> m_pDocInserter; 275 276 bool m_bIsInternalDrag :1; 277 bool m_bLastEntryEmphasis :1; // Drag'n Drop 278 279 static const SfxObjectShell* pShowShell; 280 281 void InsertRegion( const SwGlblDocContent* _pContent, 282 const css::uno::Sequence< OUString >& _rFiles ); 283 284 DECL_LINK( DialogClosedHdl, sfx2::FileDialogHelper*, void ); 285 286 using SvTreeListBox::DoubleClickHdl; 287 using SvTreeListBox::ExecuteDrop; 288 using Window::Update; 289 290 virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; 291 292 virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; 293 294 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; 295 296 virtual void RequestHelp( const HelpEvent& rHEvt ) override; 297 298 virtual sal_IntPtr GetTabPos( SvTreeListEntry*, SvLBoxTab* ) override; 299 virtual TriState NotifyMoving( SvTreeListEntry* pTarget, 300 SvTreeListEntry* pEntry, 301 SvTreeListEntry*& rpNewParent, 302 sal_uLong& rNewChildPos 303 ) override; 304 virtual TriState NotifyCopying( SvTreeListEntry* pTarget, 305 SvTreeListEntry* pEntry, 306 SvTreeListEntry*& rpNewParent, 307 sal_uLong& rNewChildPos 308 ) override; 309 310 virtual void StartDrag( sal_Int8 nAction, const Point& rPosPixel ) override; 311 virtual void DragFinished( sal_Int8 ) override; 312 virtual DragDropMode NotifyStartDrag( TransferDataContainer& rData, 313 SvTreeListEntry* ) override; 314 virtual bool NotifyAcceptDrop( SvTreeListEntry* ) override; 315 316 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; 317 virtual void KeyInput(const KeyEvent& rKEvt) override; 318 virtual void GetFocus() override; 319 virtual void SelectHdl() override; 320 virtual void DeselectHdl() override; 321 virtual void InitEntry(SvTreeListEntry*, const OUString&, const Image&, const Image&) override; 322 323 void Clear(); 324 325 DECL_LINK( PopupHdl, Menu*, bool ); 326 DECL_LINK( Timeout, Timer*, void ); 327 DECL_LINK( DoubleClickHdl, SvTreeListBox*, bool ); 328 329 SwNavigationPI* GetParentWindow(); 330 331 void OpenDoc(const SwGlblDocContent*); 332 void GotoContent(const SwGlblDocContent*); 333 MenuEnableFlags GetEnableFlags() const; 334 SetShowShell(const SfxObjectShell * pSet)335 static void SetShowShell(const SfxObjectShell*pSet) {pShowShell = pSet;} 336 DECL_STATIC_LINK(SwGlobalTree, ShowFrameHdl, void*, void); 337 338 virtual VclPtr<PopupMenu> CreateContextMenu() override; 339 virtual void ExecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry ) override; 340 341 public: 342 SwGlobalTree(vcl::Window* pParent, SwNavigationPI* pDialog); 343 virtual ~SwGlobalTree() override; 344 virtual void dispose() override; 345 virtual Size GetOptimalSize() const override; 346 347 void TbxMenuHdl(sal_uInt16 nTbxId, ToolBox* pBox); 348 void InsertRegion( const SwGlblDocContent* pCont, 349 const OUString* pFileName = nullptr ); 350 void EditContent(const SwGlblDocContent* pCont ); 351 352 void ShowTree(); 353 void HideTree(); 354 355 void ExecCommand(const OUString& rCmd); 356 357 void Display(bool bOnlyUpdateUserData = false); 358 359 bool Update(bool bHard); 360 }; 361 362 #endif 363 364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 365