30#include <svx/svxids.hrc>
43#include <com/sun/star/frame/FrameSearchFlag.hpp>
44#include <com/sun/star/frame/XDispatchProvider.hpp>
45#include <com/sun/star/frame/XFrame.hpp>
46#include <com/sun/star/gallery/GalleryItemType.hpp>
47#include <com/sun/star/graphic/XGraphic.hpp>
48#include <com/sun/star/lang/XComponent.hpp>
49#include <com/sun/star/style/GraphicLocation.hpp>
55#include <osl/diagnose.h>
63 css::uno::Sequence< css::beans::PropertyValue >
Arguments;
64 css::uno::Reference< css::frame::XDispatch >
Dispatch;
70 if ( pDispatchInfo && pDispatchInfo->
Dispatch.is() )
77 catch (
const css::uno::Exception& )
91 css::uno::Reference< css::frame::XDispatch > Dispatch;
93 explicit CommandInfo(
const OUString &rURL )
99class GalleryThemePopup :
public ::cppu::WeakImplHelper< css::frame::XStatusListener >
103 sal_uInt32 mnObjectPos;
105 std::unique_ptr<weld::Builder> mxBuilder;
106 std::unique_ptr<weld::Menu> mxPopupMenu;
107 std::unique_ptr<weld::Menu> mxBackgroundPopup;
110 typedef std::map< int, CommandInfo > CommandInfoMap;
111 CommandInfoMap m_aCommandInfo;
113 static void Execute(
const CommandInfo &rCmdInfo,
114 const css::uno::Sequence< css::beans::PropertyValue > &rArguments );
116 void MenuSelectHdl(std::u16string_view rIdent);
117 void BackgroundMenuSelectHdl(sal_uInt16 nId);
121 sal_uInt32 nObjectPos,
125 void ExecutePopup(
weld::Widget* pParent, const ::Point &rPos);
127 virtual void SAL_CALL statusChanged(
const css::frame::FeatureStateEvent &rEvent)
override;
128 virtual void SAL_CALL disposing(
const css::lang::EventObject &rSource)
override;
132GalleryThemePopup::GalleryThemePopup(
135 sal_uInt32 nObjectPos,
139 , mnObjectPos( nObjectPos )
140 , mbPreview( bPreview )
141 , mxBuilder(
Application::CreateBuilder(pParent,
"svx/ui/gallerymenu2.ui"))
142 , mxPopupMenu(mxBuilder->weld_menu(
"menu"))
143 , mxBackgroundPopup(mxBuilder->weld_menu(
"backgroundmenu"))
144 , mpBrowser( pBrowser )
147 m_aCommandInfo.emplace(
148 SID_GALLERY_ENABLE_ADDCOPY,
149 CommandInfo(
".uno:GalleryEnableAddCopy" ));
151 m_aCommandInfo.emplace(
152 SID_GALLERY_BG_BRUSH,
153 CommandInfo(
".uno:BackgroundImage" ));
155 m_aCommandInfo.emplace(
157 CommandInfo(
".uno:InsertGalleryPic" ));
161void SAL_CALL GalleryThemePopup::statusChanged(
162 const css::frame::FeatureStateEvent &rEvent )
164 const OUString &rURL = rEvent.FeatureURL.Complete;
165 if ( rURL ==
".uno:GalleryEnableAddCopy" )
167 if ( !rEvent.IsEnabled )
169 mxPopupMenu->set_visible(
"add",
false);
172 else if ( rURL ==
".uno:BackgroundImage" )
174 mxBackgroundPopup->clear();
175 if ( rEvent.IsEnabled )
178 css::uno::Sequence< OUString > sItems;
179 if ( ( rEvent.State >>= sItem ) && sItem.getLength() )
181 mxBackgroundPopup->append(OUString::number(1), sItem);
183 else if ( ( rEvent.State >>= sItems ) && sItems.hasElements() )
186 for (
const OUString& rStr : std::as_const(sItems) )
188 mxBackgroundPopup->append(OUString::number(nId), rStr);
196void SAL_CALL GalleryThemePopup::disposing(
197 const css::lang::EventObject &)
201void GalleryThemePopup::Execute(
202 const CommandInfo &rCmdInfo,
203 const css::uno::Sequence< css::beans::PropertyValue > &rArguments )
205 if ( rCmdInfo.Dispatch.is() )
208 pInfo->TargetURL = rCmdInfo.URL;
209 pInfo->Arguments = rArguments;
210 pInfo->Dispatch = rCmdInfo.Dispatch;
218void GalleryThemePopup::ExecutePopup(
weld::Widget* pParent, const ::Point &rPos)
220 css::uno::Reference< css::frame::XStatusListener > xThis(
this );
222 const SgaObjKind eObjKind = mpTheme->GetObjectKind( mnObjectPos );
226 const bool bValidURL = (
aURL.GetProtocol() != INetProtocol::NotValid );
230 mxPopupMenu->set_visible(
"preview", bValidURL);
231 mxPopupMenu->set_active(
"preview", mbPreview);
233 if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() )
235 mxPopupMenu->set_visible(
"delete",
false);
236 mxPopupMenu->set_visible(
"title",
false);
237 if (mpTheme->IsReadOnly())
238 mxPopupMenu->set_visible(
"paste",
false);
240 if (!mpTheme->GetObjectCount())
241 mxPopupMenu->set_visible(
"copy",
false);
245 mxPopupMenu->set_visible(
"delete", !mbPreview);
246 mxPopupMenu->set_visible(
"title",
true);
247 mxPopupMenu->set_visible(
"copy",
true);
248 mxPopupMenu->set_visible(
"paste",
true);
252 css::uno::Reference< css::frame::XDispatchProvider> xDispatchProvider(
254 css::uno::Reference< css::util::XURLTransformer > xTransformer(
255 mpBrowser->GetURLTransformer() );
256 for (
auto& rInfo : m_aCommandInfo )
260 CommandInfo &rCmdInfo = rInfo.second;
261 if ( xTransformer.is() )
262 xTransformer->parseStrict( rCmdInfo.URL );
264 if ( xDispatchProvider.is() )
266 rCmdInfo.Dispatch = xDispatchProvider->queryDispatch(
269 css::frame::FrameSearchFlag::SELF );
272 if ( rCmdInfo.Dispatch.is() )
274 rCmdInfo.Dispatch->addStatusListener(
this, rCmdInfo.URL );
275 rCmdInfo.Dispatch->removeStatusListener(
this, rCmdInfo.URL );
283 mxPopupMenu->set_visible(
"background",
false);
285 mxPopupMenu->set_visible(
"background",
true);
290void GalleryThemePopup::MenuSelectHdl(std::u16string_view rIdent)
298 BackgroundMenuSelectHdl(nSubMenuId-1);
302 if (rIdent == u
"add")
304 const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_FORMATS );
305 if (it != m_aCommandInfo.end())
306 mpBrowser->DispatchAdd(it->second.Dispatch, it->second.URL);
309 mpBrowser->Execute(rIdent);
312void GalleryThemePopup::BackgroundMenuSelectHdl(sal_uInt16 nPos)
315 OUString aFilterName( mpBrowser->GetFilterName() );
317 css::uno::Sequence< css::beans::PropertyValue > aArgs{
326 const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_BG_BRUSH );
327 if ( it != m_aCommandInfo.end() )
334 : mpGallery(pGallery)
335 , mpCurTheme(nullptr)
336 , mxIconView(new
GalleryIconView(this, rBuilder.weld_scrolled_window(
"galleryscroll", true)))
337 , mxIconViewWin(new
weld::CustomWeld(rBuilder,
"gallery", *mxIconView))
338 , mxListView(rBuilder.weld_tree_view(
"gallerylist"))
339 , mxPreview(new
GalleryPreview(this, rBuilder.weld_scrolled_window(
"previewscroll")))
340 , mxPreviewWin(new
weld::CustomWeld(rBuilder,
"preview", *mxPreview))
341 , mxIconButton(rBuilder.weld_toggle_button(
"icon"))
342 , mxListButton(rBuilder.weld_toggle_button(
"list"))
343 , mxInfoBar(rBuilder.weld_label(
"label"))
344 , maPreviewSize(28, 28)
345 , mnCurActionPos ( 0xffffffff )
349 m_xContext.set( ::comphelper::getProcessComponentContext() );
351 int nHeight =
mxListView->get_height_rows(10);
356 m_xContext->getServiceManager()->createInstanceWithContext(
357 "com.sun.star.util.URLTransformer",
m_xContext ),
358 css::uno::UNO_QUERY );
383 if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
385 ShowContextMenu(rCEvt);
410 switch( rGalleryHint.
GetType() )
434 if(
rTarget.IsDropFormatSupported( SotClipboardFormatId::DRAWING ) ||
435 rTarget.IsDropFormatSupported( SotClipboardFormatId::FILE_LIST ) ||
436 rTarget.IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE ) ||
437 rTarget.IsDropFormatSupported( SotClipboardFormatId::SVXB ) ||
438 rTarget.IsDropFormatSupported( SotClipboardFormatId::GDIMETAFILE ) ||
439 rTarget.IsDropFormatSupported( SotClipboardFormatId::BITMAP ) )
479 rUnsetDragIcon =
false;
495 if( !(
mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() )) )
507 new GalleryThemePopup(
513 xPopup->ExecutePopup(pParent, aSelPos);
530 OUString sExecuteIdent;
535 const bool bValidURL = (
aURL.GetProtocol() != INetProtocol::NotValid );
536 bool bPreview = bValidURL;
537 bool bDelete =
false;
566 DispatchAdd(css::uno::Reference<css::frame::XDispatch>(), css::util::URL());
576 sExecuteIdent =
"delete";
583 sExecuteIdent =
"title";
591 if (!sExecuteIdent.isEmpty())
683 const sal_uInt32
nPos = nItemId - 1;
738 sal_uInt32 nNewItemId = nItemId;
755 if( nNewItemId == nItemId )
765 const sal_uInt32
nPos = nNewItemId - 1;
787 const int nAlwaysUpToDate = 15;
797 if (
i == nAlwaysUpToDate)
801 if (
nCount < nAlwaysUpToDate)
837 OUString sItemTextTitle;
838 OUString sItemTextPath;
840 sal_Int32
i =
sId.toUInt32();
843 bool bNeedToCreate(aBitmapEx.
IsEmpty());
844 if (!bNeedToCreate && (sItemTextTitle.isEmpty() || aPreparedSize !=
maPreviewSize))
845 bNeedToCreate =
true;
876 xDev->DrawBitmapEx(aPos, aBitmapEx);
920 m_xHelper->SelectObject(nSelectedObject);
936 rSelPos =
Point( aOutputSizePixel.
Width() >> 1, aOutputSizePixel.
Height() >> 1 );
949 rSelPos =
mxIconView->GetItemRect(nRet).Center();
954 std::unique_ptr<weld::TreeIter> xIter =
mxListView->make_iterator();
957 if (
mxListView->get_dest_row_at_pos(*pSelPos, xIter.get(),
false))
958 nRet =
mxListView->get_iter_index_in_parent(*xIter) + 1;
965 nRet =
mxListView->get_iter_index_in_parent(*xIter) + 1;
966 rSelPos =
mxListView->get_row_area(*xIter).Center();
989css::uno::Reference< css::frame::XFrame >
992 css::uno::Reference< css::frame::XFrame >
xFrame;
994 if ( pCurrentViewFrame )
1004 const css::uno::Reference< css::frame::XDispatch > &rxDispatch,
1005 const css::util::URL &rURL)
1015 css::uno::Reference< css::frame::XDispatch >
xDispatch( rxDispatch );
1016 css::util::URL
aURL = rURL;
1020 css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider(
1025 aURL.Complete =
".uno:InsertGalleryPic";
1027 xDispatch = xDispatchProvider->queryDispatch(
1030 css::frame::FrameSearchFlag::SELF );
1037 OUString aFilterName;
1038 css::uno::Reference< css::lang::XComponent > xDrawing;
1039 css::uno::Reference< css::graphic::XGraphic > xGraphic;
1050 nType = css::gallery::GalleryItemType::GRAPHIC;
1054 nType = css::gallery::GalleryItemType::MEDIA;
1064 if ( bGraphic && !aGraphic.
IsNone() )
1066 OSL_ENSURE( xGraphic.is(),
"gallery item is graphic, but the reference is invalid!" );
1068 css::uno::Sequence< css::beans::PropertyValue >
aSeq{
1081 pInfo->TargetURL =
aURL;
1082 pInfo->Arguments = aArgs;
1100 if (rIdent ==
u"preview")
1102 else if (rIdent ==
u"delete")
1107 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog(
"QueryDeleteObjectDialog"));
1114 else if (rIdent ==
u"title")
1124 if( aDlg->Execute() ==
RET_OK )
1126 OUString aNewTitle( aDlg->GetTitle() );
1128 if( ( aNewTitle.isEmpty() && !pObj->GetTitle().isEmpty() ) || ( aNewTitle != aOldTitle ) )
1130 if( aNewTitle.isEmpty() )
1131 aNewTitle =
"__<empty>__";
1133 pObj->SetTitle( aNewTitle );
1139 else if (rIdent ==
u"copy")
1143 else if (rIdent ==
u"paste")
1162 OUString aTitle( rObj.GetTitle() );
1164 if( aTitle.isEmpty() )
1167 if( aTitle.isEmpty() )
1170 aTitle = aTitle.copy( aTitle.lastIndexOf(
'/')+1 );
1178 const OUString aPath(
aURL.getFSysPath( FSysStyle::Detect ) );
1183 aRet +=
aURL.getFSysPath( FSysStyle::Detect );
1204 OUString aFilterName;
1227 ImplUpdateSelection();
1232 ImplUpdateSelection();
1237 if (&rBox == mxIconButton.get())
1239 else if (&rBox == mxListButton.get())
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
const Size & GetSizePixel() const
const Point & GetMousePosPixel() const
bool IsMouseEvent() const
OUString GetFilterName() const
sal_Int8 AcceptDrop(const DropTargetHelper &rTarget)
css::uno::Reference< css::uno::XComponentContext > m_xContext
void Travel(GalleryBrowserTravel eTravel)
static css::uno::Reference< css::frame::XFrame > GetFrame()
static GalleryBrowserMode meInitMode
sal_uInt32 mnCurActionPos
std::unique_ptr< weld::Label > mxInfoBar
GalleryTheme * mpCurTheme
void UpdateRows(bool bVisibleOnly)
void ImplUpdateSelection()
void SelectTheme(std::u16string_view rThemeName)
sal_Int8 ExecuteDrop(const ExecuteDropEvent &rEvt)
GalleryBrowser2(weld::Builder &rBuilder, Gallery *pGallery)
bool ViewBoxHasFocus() const
rtl::Reference< GalleryTransferable > m_xHelper
void ImplSelectItemId(sal_uInt32 nItemId)
void ImplUpdateViews(sal_uInt16 nSelectionId)
std::unique_ptr< weld::TreeView > mxListView
weld::Widget * GetViewWindow() const
std::unique_ptr< weld::ToggleButton > mxListButton
void DispatchAdd(const css::uno::Reference< css::frame::XDispatch > &rxDispatch, const css::util::URL &rURL)
void Execute(std::u16string_view rIdent)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
void SetMode(GalleryBrowserMode eMode)
bool KeyInput(const KeyEvent &rEvt)
bool ShowContextMenu(const CommandEvent &rCEvt)
css::uno::Reference< css::util::XURLTransformer > m_xTransformer
static OUString GetItemText(const SgaObject &rObj, GalleryItemFlags nItemTextFlags)
sal_uInt32 ImplGetSelectedItemId(const Point *pSelPosPixel, Point &rSelPos)
INetURLObject GetURL() const
std::unique_ptr< GalleryPreview > mxPreview
std::unique_ptr< weld::ToggleButton > mxIconButton
std::unique_ptr< GalleryDragDrop > mxDragDropTargetHelper
GalleryBrowserMode GetMode() const
GalleryBrowserMode meMode
GalleryBrowserMode meLastMode
std::unique_ptr< GalleryIconView > mxIconView
GalleryHintType GetType() const
static void drawTransparenceBackground(vcl::RenderContext &rOut, const Point &rPos, const Size &rSize)
static void PreviewMedia(const INetURLObject &rURL)
const OUString & GetName() const
SAL_DLLPRIVATE void CopyToClipboard(const weld::Widget &rWidget, sal_uInt32 nPos)
bool GetGraphic(sal_uInt32 nPos, Graphic &rGraphic)
bool InsertObject(const SgaObject &rObj, sal_uInt32 nPos=SAL_MAX_UINT32)
bool ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos)
SAL_DLLPRIVATE bool InsertTransferable(const css::uno::Reference< css::datatransfer::XTransferable > &rxTransferable, sal_uInt32 nInsertPos)
SAL_DLLPRIVATE sal_uInt32 GetDragPos() const
SAL_DLLPRIVATE const INetURLObject & GetObjectURL(sal_uInt32 nPos) const
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
SAL_DLLPRIVATE bool IsDragging() const
std::unique_ptr< SgaObject > AcquireObject(sal_uInt32 nPos)
void RemoveObject(sal_uInt32 nPos)
SAL_DLLPRIVATE SgaObjKind GetObjectKind(sal_uInt32 nPos) const
SAL_DLLPRIVATE void SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx &rBitmapEx, const Size &rSize, const OUString &rTitle, const OUString &rPath)
SAL_DLLPRIVATE bool GetURL(sal_uInt32 nPos, INetURLObject &rURL)
SAL_DLLPRIVATE void GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx &rBitmapEx, Size &rSize, OUString &rTitle, OUString &rPath)
void ReleaseTheme(GalleryTheme *pTheme, SfxListener &rListener)
GalleryTheme * AcquireTheme(std::u16string_view rThemeName, SfxListener &rListener)
static GraphicFilter & GetGraphicFilter()
OUString GetImportFormatName(sal_uInt16 nFormat)
sal_uInt16 GetImportFormatNumberForShortName(std::u16string_view rShortName)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
const vcl::KeyCode & GetKeyCode() const
css::uno::Reference< css::frame::XFrame > GetActiveFrame() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxBindings & GetBindings()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static SvxAbstractDialogFactory * Create()
virtual VclPtr< AbstractTitleDialog > CreateTitleDialog(weld::Widget *pParent, const OUString &rOldText)=0
static TransferableDataHelper CreateFromClipboard(const css::uno::Reference< css::datatransfer::clipboard::XClipboard > &rClipboard)
const css::uno::Reference< css::datatransfer::XTransferable > & GetTransferable() const
sal_uInt16 GetCode() const
Reference< XDispatch > xDispatch
virtual OUString GetURL() const override
IMPL_LINK_NOARG(GalleryBrowser2, RowActivatedHdl, weld::TreeView &, bool)
IMPL_LINK(GalleryBrowser2, PopupMenuHdl, const CommandEvent &, rCEvt, bool)
IMPL_STATIC_LINK(GalleryBrowser2, AsyncDispatch_Impl, void *, p, void)
@ GALLERYBROWSERMODE_PREVIEW
@ GALLERYBROWSERMODE_NONE
@ GALLERYBROWSERMODE_ICON
@ GALLERYBROWSERMODE_LIST
constexpr OUStringLiteral SVXGALLERYITEM_DRAWING
constexpr OUStringLiteral SVXGALLERYITEM_GRAPHIC
constexpr OUStringLiteral SVXGALLERYITEM_TYPE
constexpr OUStringLiteral SVXGALLERYITEM_FILTER
constexpr OUStringLiteral SVXGALLERYITEM_URL
#define SVXGALLERYITEM_PARAMS
constexpr OUStringLiteral SVXGALLERYITEM_ARGNAME
#define GRFILTER_FORMAT_DONTKNOW
constexpr OUStringLiteral HID_GALLERY_LISTVIEW
constexpr OUStringLiteral HID_GALLERY_ICONVIEW
constexpr OUStringLiteral HID_GALLERY_WINDOW
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_I
constexpr sal_uInt16 KEY_T
constexpr sal_uInt16 KEY_D
constexpr sal_uInt16 KEY_DELETE
constexpr sal_uInt16 KEY_SPACE
constexpr sal_uInt16 KEY_P
constexpr sal_uInt16 KEY_INSERT
#define LINK(Instance, Class, Member)
Sequence< sal_Int8 > aSeq
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
sal_uInt32 toUInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr OUStringLiteral EMPTY
css::uno::Reference< css::frame::XDispatch > Dispatch
css::uno::Sequence< css::beans::PropertyValue > Arguments
const css::datatransfer::dnd::DropTargetDropEvent maDropEvent
Reference< XFrame > xFrame