1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <svl/lstner.hxx>
23 #include <vcl/customweld.hxx>
24 #include <vcl/transfer.hxx>
25 #include <vcl/weld.hxx>
26 #include <svx/galmisc.hxx>
27 #include <svx/galctrl.hxx>
28 #include <unotools/charclass.hxx>
30 #include <com/sun/star/util/XURLTransformer.hpp>
31 #include <com/sun/star/frame/XDispatch.hpp>
32 #include <com/sun/star/frame/XFrame.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
35 class GalleryBrowser1
;
38 class GalleryThemeEntry
;
40 class VclAbstractDialog
;
43 class GalleryDragDrop
;
44 class GalleryIconView
;
45 class GalleryListView
;
49 enum GalleryBrowserMode
51 GALLERYBROWSERMODE_NONE
= 0,
52 GALLERYBROWSERMODE_ICON
= 1,
53 GALLERYBROWSERMODE_LIST
= 2,
54 GALLERYBROWSERMODE_PREVIEW
= 3
57 enum class GalleryBrowserTravel
65 enum class GalleryItemFlags
72 template <> struct typed_flags
<GalleryItemFlags
> : is_typed_flags
<GalleryItemFlags
, 0x0006>
77 namespace svx::sidebar
85 OUString maEntryTitle
;
88 ThemeEntry(const OUString
& rThemeName
, const OUString
& rEntryTitle
, size_t nId
)
89 : maThemeName(rThemeName
)
90 , maEntryTitle(rEntryTitle
)
95 typedef ::std::vector
<ThemeEntry
> GalleryThemeEntries
;
97 class GalleryBrowser1 final
: public SfxListener
99 friend class GalleryBrowser
;
100 friend class svx::sidebar::GalleryControl
;
103 std::unique_ptr
<weld::Button
> mxNewTheme
;
104 std::unique_ptr
<weld::TreeView
> mxThemes
;
105 std::unique_ptr
<weld::Button
> mxMoreGalleries
;
107 std::unique_ptr
<ExchangeData
> mpExchangeData
;
108 std::unique_ptr
<SfxItemSet
> mpThemePropsDlgItemSet
;
111 OUString aImgDefault
;
112 OUString aImgReadOnly
;
114 GalleryTheme
* mpCurTheme
;
115 std::unique_ptr
<GalleryIconView
> mxIconView
;
116 std::unique_ptr
<weld::CustomWeld
> mxIconViewWin
;
117 std::unique_ptr
<weld::TreeView
> mxListView
;
118 std::unique_ptr
<GalleryDragDrop
> mxDragDropTargetHelper
;
119 std::unique_ptr
<GalleryPreview
> mxPreview
;
120 std::unique_ptr
<weld::CustomWeld
> mxPreviewWin
;
121 std::unique_ptr
<weld::ToggleButton
> mxIconButton
;
122 std::unique_ptr
<weld::ToggleButton
> mxListButton
;
123 std::unique_ptr
<weld::Entry
> mxSearchField
;
124 std::unique_ptr
<weld::Label
> mxInfoBar
;
126 rtl::Reference
<GalleryTransferable
> m_xHelper
;
127 sal_uInt32 mnCurActionPos
;
128 GalleryBrowserMode meMode
;
129 GalleryBrowserMode meLastMode
;
131 GalleryThemeEntries maAllThemeEntries
;
132 GalleryThemeEntries maFoundThemeEntries
;
134 css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
135 css::uno::Reference
<css::util::XURLTransformer
> m_xTransformer
;
137 CharClass m_aCharacterClassficator
;
138 SfxListener maLocalListener
;
140 void ImplInsertThemeEntry(const GalleryThemeEntry
* pEntry
);
141 static void ImplFillExchangeData(const GalleryTheme
& rThm
, ExchangeData
& rData
);
142 void ImplGetExecuteVector(std::vector
<OUString
>& o_aExec
);
143 void ImplExecute(std::u16string_view rIdent
);
144 void ImplGalleryThemeProperties(std::u16string_view rThemeName
, bool bCreateNew
);
145 void EndNewThemePropertiesDlgHdl(sal_Int32 nResult
);
146 void EndThemePropertiesDlgHdl(sal_Int32 nResult
);
147 void ImplEndGalleryThemeProperties(bool bCreateNew
, sal_Int32 nResult
);
149 void ImplUpdateViews(sal_uInt16 nSelectionId
);
150 void ImplUpdateInfoBar();
151 sal_uInt32
ImplGetSelectedItemId(const Point
* pSelPosPixel
, Point
& rSelPos
);
152 void ImplSelectItemId(sal_uInt32 nItemId
);
153 void ImplUpdateSelection();
154 void UpdateRows(bool bVisibleOnly
);
155 void FillThemeEntries();
158 virtual void Notify(SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
160 DECL_LINK(ClickNewThemeHdl
, weld::Button
&, void);
161 DECL_LINK(SelectThemeHdl
, weld::TreeView
&, void);
162 DECL_LINK(PopupMenuHdl1
, const CommandEvent
&, bool);
163 DECL_LINK(KeyInputHdl1
, const KeyEvent
&, bool);
164 DECL_STATIC_LINK(GalleryBrowser1
, OnMoreGalleriesClick
, weld::Button
&, void);
166 DECL_LINK(SelectObjectHdl
, weld::TreeView
&, void);
167 DECL_LINK(SelectObjectValueSetHdl
, ValueSet
*, void);
168 DECL_LINK(SelectTbxHdl
, weld::Toggleable
&, void);
169 DECL_LINK(PopupMenuHdl2
, const CommandEvent
&, bool);
170 DECL_LINK(KeyInputHdl2
, const KeyEvent
&, bool);
171 DECL_LINK(RowActivatedHdl
, weld::TreeView
&, bool);
172 DECL_LINK(DragBeginHdl
, bool&, bool);
173 DECL_LINK(VisRowsScrolledHdl
, weld::TreeView
&, void);
174 DECL_LINK(SizeAllocHdl
, const Size
&, void);
175 DECL_LINK(SearchHdl
, weld::Entry
&, void);
177 static GalleryBrowserMode meInitMode
;
180 GalleryBrowser1(weld::Builder
& rBuilder
, Gallery
* pGallery
);
184 void SelectTheme(sal_uInt16 nThemePos
)
186 mxThemes
->select(nThemePos
);
187 SelectThemeHdl(*mxThemes
);
189 OUString
GetSelectedTheme() const { return mxThemes
->get_selected_text(); }
191 static OUString
GetItemText(const SgaObject
& rObj
, GalleryItemFlags nItemTextFlags
);
194 void SelectTheme(std::u16string_view rThemeName
);
196 GalleryBrowserMode
GetMode() const { return meMode
; }
197 void SetMode(GalleryBrowserMode eMode
);
199 weld::Widget
* GetViewWindow() const;
201 void Travel(GalleryBrowserTravel eTravel
);
203 INetURLObject
GetURL() const;
204 OUString
GetFilterName() const;
206 sal_Int8
AcceptDrop(const DropTargetHelper
& rTarget
);
207 sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
);
209 void TogglePreview();
210 bool ShowContextMenu(const CommandEvent
& rCEvt
);
211 bool KeyInput(const KeyEvent
& rEvt
);
212 bool ViewBoxHasFocus() const;
214 static css::uno::Reference
<css::frame::XFrame
> GetFrame();
215 const css::uno::Reference
<css::util::XURLTransformer
>& GetURLTransformer() const
217 return m_xTransformer
;
220 void Execute(std::u16string_view rIdent
);
221 void DispatchAdd(const css::uno::Reference
<css::frame::XDispatch
>& rxDispatch
,
222 const css::util::URL
& rURL
);
224 DECL_STATIC_LINK(GalleryBrowser1
, AsyncDispatch_Impl
, void*, void);
227 class GalleryDragDrop final
: public DropTargetHelper
230 GalleryBrowser1
* m_pParent
;
232 virtual sal_Int8
AcceptDrop(const AcceptDropEvent
& /*rEvt*/) override
234 return m_pParent
->AcceptDrop(*this);
237 virtual sal_Int8
ExecuteDrop(const ExecuteDropEvent
& rEvt
) override
239 return m_pParent
->ExecuteDrop(rEvt
);
243 GalleryDragDrop(GalleryBrowser1
* pParent
,
244 const css::uno::Reference
<css::datatransfer::dnd::XDropTarget
>& rDropTarget
)
245 : DropTargetHelper(rDropTarget
)
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */