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 #ifndef INCLUDED_SVX_INC_GALBRWS2_HXX
21 #define INCLUDED_SVX_INC_GALBRWS2_HXX
22 
23 #include <vcl/transfer.hxx>
24 #include <svl/lstner.hxx>
25 #include <svx/galctrl.hxx>
26 
27 #include <com/sun/star/frame/XDispatch.hpp>
28 #include <com/sun/star/frame/XFrame.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/util/XURLTransformer.hpp>
31 
32 
33 enum GalleryBrowserMode
34 {
35     GALLERYBROWSERMODE_NONE = 0,
36     GALLERYBROWSERMODE_ICON = 1,
37     GALLERYBROWSERMODE_LIST = 2,
38     GALLERYBROWSERMODE_PREVIEW = 3
39 };
40 
41 
42 enum class GalleryBrowserTravel
43 {
44     First, Last, Previous, Next
45 };
46 
47 enum class GalleryItemFlags {
48     Title      = 0x0002,
49     Path       = 0x0004
50 };
51 namespace o3tl
52 {
53     template<> struct typed_flags<GalleryItemFlags> : is_typed_flags<GalleryItemFlags, 0x0006> {};
54 }
55 
56 
57 class Gallery;
58 class GalleryDragDrop;
59 class GalleryTheme;
60 class GalleryIconView;
61 class GalleryListView;
62 class GalleryPreview;
63 class GalleryTransferable;
64 class Menu;
65 class SgaObject;
66 struct DispatchInfo;
67 
68 namespace svx::sidebar { class GalleryControl; }
69 
70 class GalleryBrowser2 : public SfxListener
71 {
72     friend class GalleryBrowser;
73     friend class svx::sidebar::GalleryControl;
74 
75 private:
76 
77     Gallery*            mpGallery;
78     GalleryTheme*       mpCurTheme;
79     std::unique_ptr<GalleryIconView> mxIconView;
80     std::unique_ptr<weld::CustomWeld> mxIconViewWin;
81     std::unique_ptr<weld::TreeView> mxListView;
82     std::unique_ptr<GalleryDragDrop> mxDragDropTargetHelper;
83     std::unique_ptr<GalleryPreview> mxPreview;
84     std::unique_ptr<weld::CustomWeld> mxPreviewWin;
85     std::unique_ptr<weld::ToggleButton> mxIconButton;
86     std::unique_ptr<weld::ToggleButton> mxListButton;
87     std::unique_ptr<weld::Label> mxInfoBar;
88     Size maPreviewSize;
89     rtl::Reference<GalleryTransferable> m_xHelper;
90     sal_uInt32 mnCurActionPos;
91     GalleryBrowserMode  meMode;
92     GalleryBrowserMode  meLastMode;
93 
94     css::uno::Reference< css::uno::XComponentContext > m_xContext;
95     css::uno::Reference< css::util::XURLTransformer > m_xTransformer;
96 
97     void                ImplUpdateViews( sal_uInt16 nSelectionId );
98     void                ImplUpdateInfoBar();
99     sal_uInt32          ImplGetSelectedItemId( const Point* pSelPosPixel, Point& rSelPos );
100     void                ImplSelectItemId(sal_uInt32 nItemId);
101     void                ImplUpdateSelection();
102     void                UpdateRows(bool bVisibleOnly);
103 
104     // SfxListener
105     virtual void        Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
106 
107                         DECL_LINK( SelectObjectHdl, weld::TreeView&, void );
108                         DECL_LINK( SelectObjectValueSetHdl, ValueSet*, void );
109                         DECL_LINK( SelectTbxHdl, weld::Toggleable&, void );
110                         DECL_LINK( PopupMenuHdl, const CommandEvent&, bool );
111                         DECL_LINK( KeyInputHdl, const KeyEvent&, bool );
112                         DECL_LINK( RowActivatedHdl, weld::TreeView&, bool );
113                         DECL_LINK( DragBeginHdl, bool&, bool );
114                         DECL_LINK( VisRowsScrolledHdl, weld::TreeView&, void );
115                         DECL_LINK( SizeAllocHdl, const Size&, void );
116 
117 private:
118 
119     static GalleryBrowserMode meInitMode;
120 
121 public:
122 
123     static OUString     GetItemText( const SgaObject& rObj, GalleryItemFlags nItemTextFlags );
124 
125 public:
126 
127     GalleryBrowser2(weld::Builder& rBuilder, Gallery* pGallery);
128     ~GalleryBrowser2();
129 
130     void                SelectTheme( std::u16string_view rThemeName );
131 
GetMode() const132     GalleryBrowserMode  GetMode() const { return meMode; }
133     void                SetMode( GalleryBrowserMode eMode );
134 
135     weld::Widget*       GetViewWindow() const;
136 
137     void                Travel( GalleryBrowserTravel eTravel );
138 
139     INetURLObject       GetURL() const;
140     OUString            GetFilterName() const;
141 
142     sal_Int8            AcceptDrop( const DropTargetHelper& rTarget );
143     sal_Int8            ExecuteDrop( const ExecuteDropEvent& rEvt );
144     bool                StartDrag();
145     void                TogglePreview();
146     void                ShowContextMenu(const CommandEvent& rCEvt);
147     bool                KeyInput(const KeyEvent& rEvt);
148     bool                ViewBoxHasFocus() const;
149 
150     static css::uno::Reference< css::frame::XFrame > GetFrame();
GetURLTransformer() const151     const css::uno::Reference< css::util::XURLTransformer >& GetURLTransformer() const { return m_xTransformer; }
152 
153     void Execute(std::string_view rIdent);
154     void DispatchAdd(const css::uno::Reference<css::frame::XDispatch> &rxDispatch,
155                      const css::util::URL &rURL);
156 
157     DECL_STATIC_LINK( GalleryBrowser2, AsyncDispatch_Impl, void*, void );
158 };
159 
160 class GalleryDragDrop : public DropTargetHelper
161 {
162 private:
163     GalleryBrowser2* m_pParent;
164 
AcceptDrop(const AcceptDropEvent &)165     virtual sal_Int8 AcceptDrop(const AcceptDropEvent& /*rEvt*/) override
166     {
167         return m_pParent->AcceptDrop(*this);
168     }
169 
ExecuteDrop(const ExecuteDropEvent & rEvt)170     virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override
171     {
172         return m_pParent->ExecuteDrop(rEvt);
173     }
174 
175 public:
GalleryDragDrop(GalleryBrowser2 * pParent,const css::uno::Reference<css::datatransfer::dnd::XDropTarget> & rDropTarget)176     GalleryDragDrop(GalleryBrowser2* pParent, const css::uno::Reference<css::datatransfer::dnd::XDropTarget>& rDropTarget)
177         : DropTargetHelper(rDropTarget)
178         , m_pParent(pParent)
179     {
180     }
181 };
182 
183 #endif
184 
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
186