File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | |||||||||||||||||
21 | #include <sot/formats.hxx> | ||||||||||||||||
22 | #include <vcl/commandevent.hxx> | ||||||||||||||||
23 | #include <vcl/event.hxx> | ||||||||||||||||
24 | #include <vcl/transfer.hxx> | ||||||||||||||||
25 | #include <vcl/virdev.hxx> | ||||||||||||||||
26 | #include <sfx2/bindings.hxx> | ||||||||||||||||
27 | #include <sfx2/viewfrm.hxx> | ||||||||||||||||
28 | #include <vcl/graphicfilter.hxx> | ||||||||||||||||
29 | #include <helpids.h> | ||||||||||||||||
30 | #include <svx/svxids.hrc> | ||||||||||||||||
31 | #include <galobj.hxx> | ||||||||||||||||
32 | #include <svx/gallery1.hxx> | ||||||||||||||||
33 | #include <svx/galtheme.hxx> | ||||||||||||||||
34 | #include <svx/galctrl.hxx> | ||||||||||||||||
35 | #include <svx/galmisc.hxx> | ||||||||||||||||
36 | #include <galbrws2.hxx> | ||||||||||||||||
37 | #include <vcl/svapp.hxx> | ||||||||||||||||
38 | #include <vcl/weld.hxx> | ||||||||||||||||
39 | #include <svx/svxdlg.hxx> | ||||||||||||||||
40 | #include <svx/galleryitem.hxx> | ||||||||||||||||
41 | #include <comphelper/processfactory.hxx> | ||||||||||||||||
42 | #include <com/sun/star/frame/FrameSearchFlag.hpp> | ||||||||||||||||
43 | #include <com/sun/star/frame/XDispatchProvider.hpp> | ||||||||||||||||
44 | #include <com/sun/star/frame/XFrame.hpp> | ||||||||||||||||
45 | #include <com/sun/star/gallery/GalleryItemType.hpp> | ||||||||||||||||
46 | #include <com/sun/star/graphic/XGraphic.hpp> | ||||||||||||||||
47 | #include <com/sun/star/lang/XComponent.hpp> | ||||||||||||||||
48 | #include <com/sun/star/style/GraphicLocation.hpp> | ||||||||||||||||
49 | #include <map> | ||||||||||||||||
50 | #include <memory> | ||||||||||||||||
51 | #include <cppuhelper/implbase.hxx> | ||||||||||||||||
52 | |||||||||||||||||
53 | GalleryBrowserMode GalleryBrowser2::meInitMode = GALLERYBROWSERMODE_ICON; | ||||||||||||||||
54 | |||||||||||||||||
55 | struct DispatchInfo | ||||||||||||||||
56 | { | ||||||||||||||||
57 | css::util::URL TargetURL; | ||||||||||||||||
58 | css::uno::Sequence< css::beans::PropertyValue > Arguments; | ||||||||||||||||
59 | css::uno::Reference< css::frame::XDispatch > Dispatch; | ||||||||||||||||
60 | }; | ||||||||||||||||
61 | |||||||||||||||||
62 | IMPL_STATIC_LINK( GalleryBrowser2, AsyncDispatch_Impl, void*, p, void )void GalleryBrowser2::LinkStubAsyncDispatch_Impl(void * instance , void* data) { return AsyncDispatch_Impl(static_cast<GalleryBrowser2 *>(instance), data); } void GalleryBrowser2::AsyncDispatch_Impl (__attribute__ ((unused)) GalleryBrowser2 *, void* p) | ||||||||||||||||
63 | { | ||||||||||||||||
64 | DispatchInfo* pDispatchInfo = static_cast<DispatchInfo*>(p); | ||||||||||||||||
65 | if ( pDispatchInfo && pDispatchInfo->Dispatch.is() ) | ||||||||||||||||
66 | { | ||||||||||||||||
67 | try | ||||||||||||||||
68 | { | ||||||||||||||||
69 | pDispatchInfo->Dispatch->dispatch( pDispatchInfo->TargetURL, | ||||||||||||||||
70 | pDispatchInfo->Arguments ); | ||||||||||||||||
71 | } | ||||||||||||||||
72 | catch ( const css::uno::Exception& ) | ||||||||||||||||
73 | { | ||||||||||||||||
74 | } | ||||||||||||||||
75 | } | ||||||||||||||||
76 | |||||||||||||||||
77 | delete pDispatchInfo; | ||||||||||||||||
78 | } | ||||||||||||||||
79 | |||||||||||||||||
80 | namespace | ||||||||||||||||
81 | { | ||||||||||||||||
82 | |||||||||||||||||
83 | struct CommandInfo | ||||||||||||||||
84 | { | ||||||||||||||||
85 | css::util::URL URL; | ||||||||||||||||
86 | css::uno::Reference< css::frame::XDispatch > Dispatch; | ||||||||||||||||
87 | |||||||||||||||||
88 | explicit CommandInfo( const OUString &rURL ) | ||||||||||||||||
89 | { | ||||||||||||||||
90 | URL.Complete = rURL; | ||||||||||||||||
91 | } | ||||||||||||||||
92 | }; | ||||||||||||||||
93 | |||||||||||||||||
94 | class GalleryThemePopup : public ::cppu::WeakImplHelper< css::frame::XStatusListener > | ||||||||||||||||
95 | { | ||||||||||||||||
96 | private: | ||||||||||||||||
97 | const GalleryTheme* mpTheme; | ||||||||||||||||
98 | sal_uInt32 mnObjectPos; | ||||||||||||||||
99 | bool mbPreview; | ||||||||||||||||
100 | std::unique_ptr<weld::Builder> mxBuilder; | ||||||||||||||||
101 | std::unique_ptr<weld::Menu> mxPopupMenu; | ||||||||||||||||
102 | std::unique_ptr<weld::Menu> mxBackgroundPopup; | ||||||||||||||||
103 | GalleryBrowser2* mpBrowser; | ||||||||||||||||
104 | |||||||||||||||||
105 | typedef std::map< int, CommandInfo > CommandInfoMap; | ||||||||||||||||
106 | CommandInfoMap m_aCommandInfo; | ||||||||||||||||
107 | |||||||||||||||||
108 | static void Execute( const CommandInfo &rCmdInfo, | ||||||||||||||||
109 | const css::uno::Sequence< css::beans::PropertyValue > &rArguments ); | ||||||||||||||||
110 | |||||||||||||||||
111 | void MenuSelectHdl(const OString& rIdent); | ||||||||||||||||
112 | void BackgroundMenuSelectHdl(sal_uInt16 nId); | ||||||||||||||||
113 | public: | ||||||||||||||||
114 | GalleryThemePopup(weld::Widget* pParent, | ||||||||||||||||
115 | const GalleryTheme* pTheme, | ||||||||||||||||
116 | sal_uInt32 nObjectPos, | ||||||||||||||||
117 | bool bPreview, | ||||||||||||||||
118 | GalleryBrowser2* pBrowser); | ||||||||||||||||
119 | |||||||||||||||||
120 | void ExecutePopup(weld::Widget* pParent, const ::Point &rPos); | ||||||||||||||||
121 | |||||||||||||||||
122 | virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent &rEvent) override; | ||||||||||||||||
123 | virtual void SAL_CALL disposing( const css::lang::EventObject &rSource) override; | ||||||||||||||||
124 | }; | ||||||||||||||||
125 | |||||||||||||||||
126 | |||||||||||||||||
127 | GalleryThemePopup::GalleryThemePopup( | ||||||||||||||||
128 | weld::Widget* pParent, | ||||||||||||||||
129 | const GalleryTheme* pTheme, | ||||||||||||||||
130 | sal_uInt32 nObjectPos, | ||||||||||||||||
131 | bool bPreview, | ||||||||||||||||
132 | GalleryBrowser2* pBrowser ) | ||||||||||||||||
133 | : mpTheme( pTheme ) | ||||||||||||||||
134 | , mnObjectPos( nObjectPos ) | ||||||||||||||||
135 | , mbPreview( bPreview ) | ||||||||||||||||
136 | , mxBuilder(Application::CreateBuilder(pParent, "svx/ui/gallerymenu2.ui")) | ||||||||||||||||
137 | , mxPopupMenu(mxBuilder->weld_menu("menu")) | ||||||||||||||||
138 | , mxBackgroundPopup(mxBuilder->weld_menu("backgroundmenu")) | ||||||||||||||||
139 | , mpBrowser( pBrowser ) | ||||||||||||||||
140 | { | ||||||||||||||||
141 | // SID_GALLERY_ENABLE_ADDCOPY | ||||||||||||||||
142 | m_aCommandInfo.emplace( | ||||||||||||||||
143 | SID_GALLERY_ENABLE_ADDCOPY( 10000 + 276 ), | ||||||||||||||||
144 | CommandInfo( ".uno:GalleryEnableAddCopy" )); | ||||||||||||||||
145 | // SID_GALLERY_BG_BRUSH | ||||||||||||||||
146 | m_aCommandInfo.emplace( | ||||||||||||||||
147 | SID_GALLERY_BG_BRUSH(10000 + 279), | ||||||||||||||||
148 | CommandInfo( ".uno:BackgroundImage" )); | ||||||||||||||||
149 | // SID_GALLERY_FORMATS | ||||||||||||||||
150 | m_aCommandInfo.emplace( | ||||||||||||||||
151 | SID_GALLERY_FORMATS( 10000 + 280 ), | ||||||||||||||||
152 | CommandInfo( ".uno:InsertGalleryPic" )); | ||||||||||||||||
153 | |||||||||||||||||
154 | } | ||||||||||||||||
155 | |||||||||||||||||
156 | void SAL_CALL GalleryThemePopup::statusChanged( | ||||||||||||||||
157 | const css::frame::FeatureStateEvent &rEvent ) | ||||||||||||||||
158 | { | ||||||||||||||||
159 | const OUString &rURL = rEvent.FeatureURL.Complete; | ||||||||||||||||
160 | if ( rURL == ".uno:GalleryEnableAddCopy" ) | ||||||||||||||||
161 | { | ||||||||||||||||
162 | if ( !rEvent.IsEnabled ) | ||||||||||||||||
163 | { | ||||||||||||||||
164 | mxPopupMenu->set_visible("add", false); | ||||||||||||||||
165 | } | ||||||||||||||||
166 | } | ||||||||||||||||
167 | else if ( rURL == ".uno:BackgroundImage" ) | ||||||||||||||||
168 | { | ||||||||||||||||
169 | mxBackgroundPopup->clear(); | ||||||||||||||||
170 | if ( rEvent.IsEnabled ) | ||||||||||||||||
171 | { | ||||||||||||||||
172 | OUString sItem; | ||||||||||||||||
173 | css::uno::Sequence< OUString > sItems; | ||||||||||||||||
174 | if ( ( rEvent.State >>= sItem ) && sItem.getLength() ) | ||||||||||||||||
175 | { | ||||||||||||||||
176 | mxBackgroundPopup->append(OUString::number(1), sItem); | ||||||||||||||||
177 | } | ||||||||||||||||
178 | else if ( ( rEvent.State >>= sItems ) && sItems.hasElements() ) | ||||||||||||||||
179 | { | ||||||||||||||||
180 | sal_uInt16 nId = 1; | ||||||||||||||||
181 | for ( const OUString& rStr : std::as_const(sItems) ) | ||||||||||||||||
182 | { | ||||||||||||||||
183 | mxBackgroundPopup->append(OUString::number(nId), rStr); | ||||||||||||||||
184 | nId++; | ||||||||||||||||
185 | } | ||||||||||||||||
186 | } | ||||||||||||||||
187 | } | ||||||||||||||||
188 | } | ||||||||||||||||
189 | } | ||||||||||||||||
190 | |||||||||||||||||
191 | void SAL_CALL GalleryThemePopup::disposing( | ||||||||||||||||
192 | const css::lang::EventObject &/*rSource*/) | ||||||||||||||||
193 | { | ||||||||||||||||
194 | } | ||||||||||||||||
195 | |||||||||||||||||
196 | void GalleryThemePopup::Execute( | ||||||||||||||||
197 | const CommandInfo &rCmdInfo, | ||||||||||||||||
198 | const css::uno::Sequence< css::beans::PropertyValue > &rArguments ) | ||||||||||||||||
199 | { | ||||||||||||||||
200 | if ( rCmdInfo.Dispatch.is() ) | ||||||||||||||||
201 | { | ||||||||||||||||
202 | std::unique_ptr<DispatchInfo> pInfo(new DispatchInfo); | ||||||||||||||||
203 | pInfo->TargetURL = rCmdInfo.URL; | ||||||||||||||||
204 | pInfo->Arguments = rArguments; | ||||||||||||||||
205 | pInfo->Dispatch = rCmdInfo.Dispatch; | ||||||||||||||||
206 | |||||||||||||||||
207 | if ( Application::PostUserEvent( | ||||||||||||||||
208 | LINK( nullptr, GalleryBrowser2, AsyncDispatch_Impl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(nullptr), &GalleryBrowser2::LinkStubAsyncDispatch_Impl ), pInfo.get() ) ) | ||||||||||||||||
209 | pInfo.release(); | ||||||||||||||||
210 | } | ||||||||||||||||
211 | } | ||||||||||||||||
212 | |||||||||||||||||
213 | void GalleryThemePopup::ExecutePopup(weld::Widget* pParent, const ::Point &rPos) | ||||||||||||||||
214 | { | ||||||||||||||||
215 | css::uno::Reference< css::frame::XStatusListener > xThis( this ); | ||||||||||||||||
216 | |||||||||||||||||
217 | const SgaObjKind eObjKind = mpTheme->GetObjectKind( mnObjectPos ); | ||||||||||||||||
218 | INetURLObject aURL; | ||||||||||||||||
219 | |||||||||||||||||
220 | const_cast< GalleryTheme* >( mpTheme )->GetURL( mnObjectPos, aURL ); | ||||||||||||||||
221 | const bool bValidURL = ( aURL.GetProtocol() != INetProtocol::NotValid ); | ||||||||||||||||
222 | |||||||||||||||||
223 | mxPopupMenu->set_visible("add", bValidURL && SgaObjKind::Sound != eObjKind); | ||||||||||||||||
224 | |||||||||||||||||
225 | mxPopupMenu->set_visible("preview", bValidURL); | ||||||||||||||||
226 | mxPopupMenu->set_active("preview", mbPreview); | ||||||||||||||||
227 | |||||||||||||||||
228 | if( mpTheme->IsReadOnly() || !mpTheme->GetObjectCount() ) | ||||||||||||||||
229 | { | ||||||||||||||||
230 | mxPopupMenu->set_visible("delete", false); | ||||||||||||||||
231 | mxPopupMenu->set_visible("title", false); | ||||||||||||||||
232 | if (mpTheme->IsReadOnly()) | ||||||||||||||||
233 | mxPopupMenu->set_visible("paste", false); | ||||||||||||||||
234 | |||||||||||||||||
235 | if (!mpTheme->GetObjectCount()) | ||||||||||||||||
236 | mxPopupMenu->set_visible("copy", false); | ||||||||||||||||
237 | } | ||||||||||||||||
238 | else | ||||||||||||||||
239 | { | ||||||||||||||||
240 | mxPopupMenu->set_visible("delete", !mbPreview); | ||||||||||||||||
241 | mxPopupMenu->set_visible("title", true); | ||||||||||||||||
242 | mxPopupMenu->set_visible("copy", true); | ||||||||||||||||
243 | mxPopupMenu->set_visible("paste", true); | ||||||||||||||||
244 | } | ||||||||||||||||
245 | |||||||||||||||||
246 | // update status | ||||||||||||||||
247 | css::uno::Reference< css::frame::XDispatchProvider> xDispatchProvider( | ||||||||||||||||
248 | GalleryBrowser2::GetFrame(), css::uno::UNO_QUERY ); | ||||||||||||||||
249 | css::uno::Reference< css::util::XURLTransformer > xTransformer( | ||||||||||||||||
250 | mpBrowser->GetURLTransformer() ); | ||||||||||||||||
251 | for ( auto& rInfo : m_aCommandInfo ) | ||||||||||||||||
252 | { | ||||||||||||||||
253 | try | ||||||||||||||||
254 | { | ||||||||||||||||
255 | CommandInfo &rCmdInfo = rInfo.second; | ||||||||||||||||
256 | if ( xTransformer.is() ) | ||||||||||||||||
257 | xTransformer->parseStrict( rCmdInfo.URL ); | ||||||||||||||||
258 | |||||||||||||||||
259 | if ( xDispatchProvider.is() ) | ||||||||||||||||
260 | { | ||||||||||||||||
261 | rCmdInfo.Dispatch = xDispatchProvider->queryDispatch( | ||||||||||||||||
262 | rCmdInfo.URL, | ||||||||||||||||
263 | "_self", | ||||||||||||||||
264 | css::frame::FrameSearchFlag::SELF ); | ||||||||||||||||
265 | } | ||||||||||||||||
266 | |||||||||||||||||
267 | if ( rCmdInfo.Dispatch.is() ) | ||||||||||||||||
268 | { | ||||||||||||||||
269 | rCmdInfo.Dispatch->addStatusListener( this, rCmdInfo.URL ); | ||||||||||||||||
270 | rCmdInfo.Dispatch->removeStatusListener( this, rCmdInfo.URL ); | ||||||||||||||||
271 | } | ||||||||||||||||
272 | } | ||||||||||||||||
273 | catch ( ... ) | ||||||||||||||||
274 | {} | ||||||||||||||||
275 | } | ||||||||||||||||
276 | |||||||||||||||||
277 | if( !mxBackgroundPopup->n_children() || ( eObjKind == SgaObjKind::SvDraw ) || ( eObjKind == SgaObjKind::Sound ) ) | ||||||||||||||||
278 | mxPopupMenu->set_visible("background", false); | ||||||||||||||||
279 | else | ||||||||||||||||
280 | mxPopupMenu->set_visible("background", true); | ||||||||||||||||
281 | |||||||||||||||||
282 | MenuSelectHdl(mxPopupMenu->popup_at_rect(pParent, tools::Rectangle(rPos, Size(1,1)))); | ||||||||||||||||
283 | } | ||||||||||||||||
284 | |||||||||||||||||
285 | void GalleryThemePopup::MenuSelectHdl(const OString& rIdent) | ||||||||||||||||
286 | { | ||||||||||||||||
287 | if (rIdent.isEmpty()) | ||||||||||||||||
288 | return; | ||||||||||||||||
289 | |||||||||||||||||
290 | sal_uInt16 nSubMenuId = rIdent.toUInt32(); | ||||||||||||||||
291 | if (nSubMenuId) | ||||||||||||||||
292 | { | ||||||||||||||||
293 | BackgroundMenuSelectHdl(nSubMenuId-1); | ||||||||||||||||
294 | return; | ||||||||||||||||
295 | } | ||||||||||||||||
296 | |||||||||||||||||
297 | if (rIdent == "add") | ||||||||||||||||
298 | { | ||||||||||||||||
299 | const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_FORMATS( 10000 + 280 ) ); | ||||||||||||||||
300 | if (it != m_aCommandInfo.end()) | ||||||||||||||||
301 | mpBrowser->DispatchAdd(it->second.Dispatch, it->second.URL); | ||||||||||||||||
302 | } | ||||||||||||||||
303 | else | ||||||||||||||||
304 | mpBrowser->Execute(rIdent); | ||||||||||||||||
305 | } | ||||||||||||||||
306 | |||||||||||||||||
307 | void GalleryThemePopup::BackgroundMenuSelectHdl(sal_uInt16 nPos) | ||||||||||||||||
308 | { | ||||||||||||||||
309 | OUString aURL( mpBrowser->GetURL().GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); | ||||||||||||||||
310 | OUString aFilterName( mpBrowser->GetFilterName() ); | ||||||||||||||||
311 | |||||||||||||||||
312 | css::uno::Sequence< css::beans::PropertyValue > aArgs( 6 ); | ||||||||||||||||
313 | aArgs[0].Name = "Background.Transparent"; | ||||||||||||||||
314 | aArgs[0].Value <<= sal_Int32( 0 ); // 0 - 100 | ||||||||||||||||
315 | aArgs[1].Name = "Background.BackColor"; | ||||||||||||||||
316 | aArgs[1].Value <<= sal_Int32( - 1 ); | ||||||||||||||||
317 | aArgs[2].Name = "Background.URL"; | ||||||||||||||||
318 | aArgs[2].Value <<= aURL; | ||||||||||||||||
319 | aArgs[3].Name = "Background.Filtername"; // FIXME should be FilterName | ||||||||||||||||
320 | aArgs[3].Value <<= aFilterName; | ||||||||||||||||
321 | aArgs[4].Name = "Background.Position"; | ||||||||||||||||
322 | aArgs[4].Value <<= css::style::GraphicLocation_TILED; | ||||||||||||||||
323 | aArgs[5].Name = "Position"; | ||||||||||||||||
324 | aArgs[5].Value <<= nPos; | ||||||||||||||||
325 | |||||||||||||||||
326 | const CommandInfoMap::const_iterator it = m_aCommandInfo.find( SID_GALLERY_BG_BRUSH(10000 + 279) ); | ||||||||||||||||
327 | if ( it != m_aCommandInfo.end() ) | ||||||||||||||||
328 | Execute( it->second, aArgs ); | ||||||||||||||||
329 | } | ||||||||||||||||
330 | |||||||||||||||||
331 | } // end anonymous namespace | ||||||||||||||||
332 | |||||||||||||||||
333 | GalleryBrowser2::GalleryBrowser2(weld::Builder& rBuilder, Gallery* pGallery) | ||||||||||||||||
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 | , mxDev(mxListView->create_virtual_device()) | ||||||||||||||||
345 | , maPreviewSize(28, 28) | ||||||||||||||||
346 | , mnCurActionPos ( 0xffffffff ) | ||||||||||||||||
347 | , meMode ( GALLERYBROWSERMODE_NONE ) | ||||||||||||||||
348 | , meLastMode ( GALLERYBROWSERMODE_NONE ) | ||||||||||||||||
349 | { | ||||||||||||||||
350 | mxDev->SetOutputSizePixel(maPreviewSize); | ||||||||||||||||
351 | |||||||||||||||||
352 | m_xContext.set( ::comphelper::getProcessComponentContext() ); | ||||||||||||||||
353 | |||||||||||||||||
354 | int nHeight = mxListView->get_height_rows(10); | ||||||||||||||||
355 | mxListView->set_size_request(-1, nHeight); | ||||||||||||||||
356 | mxIconView->set_size_request(-1, nHeight); | ||||||||||||||||
357 | |||||||||||||||||
358 | m_xTransformer.set( | ||||||||||||||||
359 | m_xContext->getServiceManager()->createInstanceWithContext( | ||||||||||||||||
360 | "com.sun.star.util.URLTransformer", m_xContext ), | ||||||||||||||||
361 | css::uno::UNO_QUERY ); | ||||||||||||||||
362 | |||||||||||||||||
363 | mxIconButton->set_help_id(HID_GALLERY_ICONVIEW"SVX_HID_GALLERY_ICONVIEW"); | ||||||||||||||||
364 | mxListButton->set_help_id(HID_GALLERY_LISTVIEW"SVX_HID_GALLERY_LISTVIEW"); | ||||||||||||||||
365 | |||||||||||||||||
366 | mxIconButton->connect_toggled( LINK( this, GalleryBrowser2, SelectTbxHdl )::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubSelectTbxHdl) ); | ||||||||||||||||
367 | mxListButton->connect_toggled( LINK( this, GalleryBrowser2, SelectTbxHdl )::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubSelectTbxHdl) ); | ||||||||||||||||
368 | |||||||||||||||||
369 | mxIconView->SetSelectHdl( LINK( this, GalleryBrowser2, SelectObjectValueSetHdl )::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubSelectObjectValueSetHdl ) ); | ||||||||||||||||
370 | mxListView->connect_visible_range_changed(LINK(this, GalleryBrowser2, VisRowsScrolledHdl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubVisRowsScrolledHdl )); | ||||||||||||||||
371 | mxListView->connect_size_allocate(LINK(this, GalleryBrowser2, SizeAllocHdl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubSizeAllocHdl)); | ||||||||||||||||
372 | mxListView->connect_changed( LINK( this, GalleryBrowser2, SelectObjectHdl )::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubSelectObjectHdl) ); | ||||||||||||||||
373 | mxListView->connect_popup_menu(LINK(this, GalleryBrowser2, PopupMenuHdl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubPopupMenuHdl)); | ||||||||||||||||
374 | mxListView->connect_key_press(LINK(this, GalleryBrowser2, KeyInputHdl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubKeyInputHdl)); | ||||||||||||||||
375 | mxListView->connect_row_activated(LINK(this, GalleryBrowser2, RowActivatedHdl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubRowActivatedHdl)); | ||||||||||||||||
376 | mxDragDropTargetHelper.reset(new GalleryDragDrop(this, mxListView->get_drop_target())); | ||||||||||||||||
377 | mxListView->connect_drag_begin(LINK(this, GalleryBrowser2, DragBeginHdl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(this), &GalleryBrowser2::LinkStubDragBeginHdl)); | ||||||||||||||||
378 | |||||||||||||||||
379 | mxListView->set_help_id(HID_GALLERY_WINDOW"SVX_HID_GALLERY_WINDOW"); | ||||||||||||||||
380 | |||||||||||||||||
381 | SetMode( ( GALLERYBROWSERMODE_PREVIEW != GalleryBrowser2::meInitMode ) ? GalleryBrowser2::meInitMode : GALLERYBROWSERMODE_ICON ); | ||||||||||||||||
382 | } | ||||||||||||||||
383 | |||||||||||||||||
384 | IMPL_LINK(GalleryBrowser2, PopupMenuHdl, const CommandEvent&, rCEvt, bool)bool GalleryBrowser2::LinkStubPopupMenuHdl(void * instance, const CommandEvent& data) { return static_cast<GalleryBrowser2 *>(instance)->PopupMenuHdl(data); } bool GalleryBrowser2 ::PopupMenuHdl(const CommandEvent& rCEvt) | ||||||||||||||||
385 | { | ||||||||||||||||
386 | if (rCEvt.GetCommand() != CommandEventId::ContextMenu) | ||||||||||||||||
387 | return false; | ||||||||||||||||
388 | ShowContextMenu(rCEvt); | ||||||||||||||||
389 | return true; | ||||||||||||||||
390 | } | ||||||||||||||||
391 | |||||||||||||||||
392 | IMPL_LINK(GalleryBrowser2, KeyInputHdl, const KeyEvent&, rKEvt, bool)bool GalleryBrowser2::LinkStubKeyInputHdl(void * instance, const KeyEvent& data) { return static_cast<GalleryBrowser2 * >(instance)->KeyInputHdl(data); } bool GalleryBrowser2:: KeyInputHdl(const KeyEvent& rKEvt) | ||||||||||||||||
| |||||||||||||||||
393 | { | ||||||||||||||||
394 | return KeyInput(rKEvt); | ||||||||||||||||
395 | } | ||||||||||||||||
396 | |||||||||||||||||
397 | IMPL_LINK_NOARG(GalleryBrowser2, RowActivatedHdl, weld::TreeView&, bool)bool GalleryBrowser2::LinkStubRowActivatedHdl(void * instance , weld::TreeView& data) { return static_cast<GalleryBrowser2 *>(instance)->RowActivatedHdl(data); } bool GalleryBrowser2 ::RowActivatedHdl(__attribute__ ((unused)) weld::TreeView& ) | ||||||||||||||||
398 | { | ||||||||||||||||
399 | TogglePreview(); | ||||||||||||||||
400 | return true; | ||||||||||||||||
401 | } | ||||||||||||||||
402 | |||||||||||||||||
403 | GalleryBrowser2::~GalleryBrowser2() | ||||||||||||||||
404 | { | ||||||||||||||||
405 | if (mpCurTheme) | ||||||||||||||||
406 | mpGallery->ReleaseTheme( mpCurTheme, *this ); | ||||||||||||||||
407 | } | ||||||||||||||||
408 | |||||||||||||||||
409 | void GalleryBrowser2::Notify( SfxBroadcaster&, const SfxHint& rHint ) | ||||||||||||||||
410 | { | ||||||||||||||||
411 | const GalleryHint& rGalleryHint = static_cast<const GalleryHint&>(rHint); | ||||||||||||||||
412 | |||||||||||||||||
413 | switch( rGalleryHint.GetType() ) | ||||||||||||||||
414 | { | ||||||||||||||||
415 | case GalleryHintType::THEME_UPDATEVIEW: | ||||||||||||||||
416 | { | ||||||||||||||||
417 | if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) | ||||||||||||||||
418 | SetMode( meLastMode ); | ||||||||||||||||
419 | |||||||||||||||||
420 | ImplUpdateViews( reinterpret_cast<size_t>(rGalleryHint.GetData1()) + 1 ); | ||||||||||||||||
421 | } | ||||||||||||||||
422 | break; | ||||||||||||||||
423 | |||||||||||||||||
424 | default: | ||||||||||||||||
425 | break; | ||||||||||||||||
426 | } | ||||||||||||||||
427 | } | ||||||||||||||||
428 | |||||||||||||||||
429 | sal_Int8 GalleryBrowser2::AcceptDrop( const DropTargetHelper& rTarget ) | ||||||||||||||||
430 | { | ||||||||||||||||
431 | sal_Int8 nRet = DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | ||||||||||||||||
432 | |||||||||||||||||
433 | if( mpCurTheme && !mpCurTheme->IsReadOnly() ) | ||||||||||||||||
434 | { | ||||||||||||||||
435 | if( !mpCurTheme->IsDragging() ) | ||||||||||||||||
436 | { | ||||||||||||||||
437 | if( rTarget.IsDropFormatSupported( SotClipboardFormatId::DRAWING ) || | ||||||||||||||||
438 | rTarget.IsDropFormatSupported( SotClipboardFormatId::FILE_LIST ) || | ||||||||||||||||
439 | rTarget.IsDropFormatSupported( SotClipboardFormatId::SIMPLE_FILE ) || | ||||||||||||||||
440 | rTarget.IsDropFormatSupported( SotClipboardFormatId::SVXB ) || | ||||||||||||||||
441 | rTarget.IsDropFormatSupported( SotClipboardFormatId::GDIMETAFILE ) || | ||||||||||||||||
442 | rTarget.IsDropFormatSupported( SotClipboardFormatId::BITMAP ) ) | ||||||||||||||||
443 | { | ||||||||||||||||
444 | nRet = DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY; | ||||||||||||||||
445 | } | ||||||||||||||||
446 | } | ||||||||||||||||
447 | else | ||||||||||||||||
448 | nRet = DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY; | ||||||||||||||||
449 | } | ||||||||||||||||
450 | |||||||||||||||||
451 | return nRet; | ||||||||||||||||
452 | } | ||||||||||||||||
453 | |||||||||||||||||
454 | sal_Int8 GalleryBrowser2::ExecuteDrop( const ExecuteDropEvent& rEvt ) | ||||||||||||||||
455 | { | ||||||||||||||||
456 | sal_Int8 nRet = DND_ACTION_NONEcss::datatransfer::dnd::DNDConstants::ACTION_NONE; | ||||||||||||||||
457 | |||||||||||||||||
458 | if( mpCurTheme ) | ||||||||||||||||
459 | { | ||||||||||||||||
460 | Point aSelPos; | ||||||||||||||||
461 | const sal_uInt32 nItemId = ImplGetSelectedItemId( &rEvt.maPosPixel, aSelPos ); | ||||||||||||||||
462 | const sal_uInt32 nInsertPos = (nItemId ? (nItemId - 1) : mpCurTheme->GetObjectCount()); | ||||||||||||||||
463 | |||||||||||||||||
464 | if( mpCurTheme->IsDragging() ) | ||||||||||||||||
465 | mpCurTheme->ChangeObjectPos( mpCurTheme->GetDragPos(), nInsertPos ); | ||||||||||||||||
466 | else | ||||||||||||||||
467 | nRet = mpCurTheme->InsertTransferable( rEvt.maDropEvent.Transferable, nInsertPos ) ? 1 : 0; | ||||||||||||||||
468 | } | ||||||||||||||||
469 | |||||||||||||||||
470 | return nRet; | ||||||||||||||||
471 | } | ||||||||||||||||
472 | |||||||||||||||||
473 | bool GalleryBrowser2::StartDrag() | ||||||||||||||||
474 | { | ||||||||||||||||
475 | if (!mpCurTheme) | ||||||||||||||||
476 | return true; | ||||||||||||||||
477 | return m_xHelper->StartDrag(); | ||||||||||||||||
478 | } | ||||||||||||||||
479 | |||||||||||||||||
480 | IMPL_LINK(GalleryBrowser2, DragBeginHdl, bool&, rUnsetDragIcon, bool)bool GalleryBrowser2::LinkStubDragBeginHdl(void * instance, bool & data) { return static_cast<GalleryBrowser2 *>(instance )->DragBeginHdl(data); } bool GalleryBrowser2::DragBeginHdl (bool& rUnsetDragIcon) | ||||||||||||||||
481 | { | ||||||||||||||||
482 | rUnsetDragIcon = false; | ||||||||||||||||
483 | return StartDrag(); | ||||||||||||||||
484 | } | ||||||||||||||||
485 | |||||||||||||||||
486 | void GalleryBrowser2::TogglePreview() | ||||||||||||||||
487 | { | ||||||||||||||||
488 | SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode ); | ||||||||||||||||
489 | GetViewWindow()->grab_focus(); | ||||||||||||||||
490 | } | ||||||||||||||||
491 | |||||||||||||||||
492 | void GalleryBrowser2::ShowContextMenu(const CommandEvent& rCEvt) | ||||||||||||||||
493 | { | ||||||||||||||||
494 | Point aMousePos = rCEvt.GetMousePosPixel(); | ||||||||||||||||
495 | Point aSelPos; | ||||||||||||||||
496 | const sal_uInt32 nItemId = ImplGetSelectedItemId( rCEvt.IsMouseEvent() ? &aMousePos : nullptr, aSelPos ); | ||||||||||||||||
497 | |||||||||||||||||
498 | if( !(mpCurTheme && nItemId && ( nItemId <= mpCurTheme->GetObjectCount() )) ) | ||||||||||||||||
499 | return; | ||||||||||||||||
500 | |||||||||||||||||
501 | ImplSelectItemId( nItemId ); | ||||||||||||||||
502 | |||||||||||||||||
503 | css::uno::Reference< css::frame::XFrame > xFrame( GetFrame() ); | ||||||||||||||||
504 | if ( !xFrame.is() ) | ||||||||||||||||
505 | return; | ||||||||||||||||
506 | |||||||||||||||||
507 | weld::Widget* pParent = GetViewWindow(); | ||||||||||||||||
508 | mnCurActionPos = nItemId - 1; | ||||||||||||||||
509 | rtl::Reference< GalleryThemePopup > xPopup( | ||||||||||||||||
510 | new GalleryThemePopup( | ||||||||||||||||
511 | pParent, | ||||||||||||||||
512 | mpCurTheme, | ||||||||||||||||
513 | mnCurActionPos, | ||||||||||||||||
514 | GALLERYBROWSERMODE_PREVIEW == GetMode(), | ||||||||||||||||
515 | this ) ); | ||||||||||||||||
516 | xPopup->ExecutePopup(pParent, aSelPos); | ||||||||||||||||
517 | } | ||||||||||||||||
518 | |||||||||||||||||
519 | bool GalleryBrowser2::ViewBoxHasFocus() const | ||||||||||||||||
520 | { | ||||||||||||||||
521 | return mxIconButton->has_focus() || mxListButton->has_focus(); | ||||||||||||||||
522 | } | ||||||||||||||||
523 | |||||||||||||||||
524 | bool GalleryBrowser2::KeyInput(const KeyEvent& rKEvt) | ||||||||||||||||
525 | { | ||||||||||||||||
526 | Point aSelPos; | ||||||||||||||||
527 | const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); | ||||||||||||||||
528 | bool bRet = false; | ||||||||||||||||
529 | |||||||||||||||||
530 | if (!ViewBoxHasFocus() && nItemId
| ||||||||||||||||
531 | { | ||||||||||||||||
532 | OString sExecuteIdent; | ||||||||||||||||
533 | INetURLObject aURL; | ||||||||||||||||
534 | |||||||||||||||||
535 | mpCurTheme->GetURL( nItemId - 1, aURL ); | ||||||||||||||||
536 | |||||||||||||||||
537 | const bool bValidURL = ( aURL.GetProtocol() != INetProtocol::NotValid ); | ||||||||||||||||
538 | bool bPreview = bValidURL; | ||||||||||||||||
539 | bool bDelete = false; | ||||||||||||||||
540 | bool bTitle = false; | ||||||||||||||||
541 | |||||||||||||||||
542 | if( !mpCurTheme->IsReadOnly() && mpCurTheme->GetObjectCount() ) | ||||||||||||||||
543 | { | ||||||||||||||||
544 | bDelete = ( GALLERYBROWSERMODE_PREVIEW != GetMode() ); | ||||||||||||||||
545 | bTitle = true; | ||||||||||||||||
546 | } | ||||||||||||||||
547 | |||||||||||||||||
548 | switch( rKEvt.GetKeyCode().GetCode() ) | ||||||||||||||||
549 | { | ||||||||||||||||
550 | case KEY_SPACE: | ||||||||||||||||
551 | case KEY_RETURN: | ||||||||||||||||
552 | case KEY_P: | ||||||||||||||||
553 | { | ||||||||||||||||
554 | if( bPreview ) | ||||||||||||||||
555 | { | ||||||||||||||||
556 | TogglePreview(); | ||||||||||||||||
557 | bRet = true; | ||||||||||||||||
558 | } | ||||||||||||||||
559 | } | ||||||||||||||||
560 | break; | ||||||||||||||||
561 | |||||||||||||||||
562 | case KEY_INSERT: | ||||||||||||||||
563 | case KEY_I: | ||||||||||||||||
564 | { | ||||||||||||||||
565 | // Inserting a gallery item in the document must be dispatched | ||||||||||||||||
566 | if( bValidURL ) | ||||||||||||||||
567 | { | ||||||||||||||||
568 | DispatchAdd(css::uno::Reference<css::frame::XDispatch>(), css::util::URL()); | ||||||||||||||||
569 | return true; | ||||||||||||||||
570 | } | ||||||||||||||||
571 | } | ||||||||||||||||
572 | break; | ||||||||||||||||
573 | |||||||||||||||||
574 | case KEY_DELETE: | ||||||||||||||||
575 | case KEY_D: | ||||||||||||||||
576 | { | ||||||||||||||||
577 | if( bDelete ) | ||||||||||||||||
578 | sExecuteIdent = "delete"; | ||||||||||||||||
579 | } | ||||||||||||||||
580 | break; | ||||||||||||||||
581 | |||||||||||||||||
582 | case KEY_T: | ||||||||||||||||
583 | { | ||||||||||||||||
584 | if( bTitle ) | ||||||||||||||||
585 | sExecuteIdent = "title"; | ||||||||||||||||
586 | } | ||||||||||||||||
587 | break; | ||||||||||||||||
588 | |||||||||||||||||
589 | default: | ||||||||||||||||
590 | break; | ||||||||||||||||
591 | } | ||||||||||||||||
592 | |||||||||||||||||
593 | if (!sExecuteIdent.isEmpty()) | ||||||||||||||||
594 | { | ||||||||||||||||
595 | Execute(sExecuteIdent); | ||||||||||||||||
596 | bRet = true; | ||||||||||||||||
597 | } | ||||||||||||||||
598 | } | ||||||||||||||||
599 | |||||||||||||||||
600 | return bRet; | ||||||||||||||||
601 | } | ||||||||||||||||
602 | |||||||||||||||||
603 | void GalleryBrowser2::SelectTheme( const OUString& rThemeName ) | ||||||||||||||||
604 | { | ||||||||||||||||
605 | if( mpCurTheme ) | ||||||||||||||||
606 | mpGallery->ReleaseTheme( mpCurTheme, *this ); | ||||||||||||||||
607 | |||||||||||||||||
608 | mpCurTheme = mpGallery->AcquireTheme( rThemeName, *this ); | ||||||||||||||||
609 | |||||||||||||||||
610 | m_xHelper.set(new GalleryTransferable(mpCurTheme, 0, true)); | ||||||||||||||||
611 | rtl::Reference<TransferDataContainer> xHelper(m_xHelper.get()); | ||||||||||||||||
612 | mxListView->enable_drag_source(xHelper, DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY | DND_ACTION_LINKcss::datatransfer::dnd::DNDConstants::ACTION_LINK); | ||||||||||||||||
613 | mxIconView->SetDragDataTransferrable(xHelper, DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY | DND_ACTION_LINKcss::datatransfer::dnd::DNDConstants::ACTION_LINK); | ||||||||||||||||
614 | mxPreview->SetDragDataTransferrable(xHelper, DND_ACTION_COPYcss::datatransfer::dnd::DNDConstants::ACTION_COPY | DND_ACTION_LINKcss::datatransfer::dnd::DNDConstants::ACTION_LINK); | ||||||||||||||||
615 | |||||||||||||||||
616 | mxIconView->SetTheme(mpCurTheme); | ||||||||||||||||
617 | mxPreview->SetTheme(mpCurTheme); | ||||||||||||||||
618 | |||||||||||||||||
619 | if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) | ||||||||||||||||
620 | meMode = meLastMode; | ||||||||||||||||
621 | |||||||||||||||||
622 | ImplUpdateViews( 1 ); | ||||||||||||||||
623 | |||||||||||||||||
624 | bool bIconMode = (GALLERYBROWSERMODE_ICON == GetMode()); | ||||||||||||||||
625 | mxIconButton->set_sensitive(true); | ||||||||||||||||
626 | mxListButton->set_sensitive(true); | ||||||||||||||||
627 | mxIconButton->set_active(bIconMode); | ||||||||||||||||
628 | mxListButton->set_active(!bIconMode); | ||||||||||||||||
629 | } | ||||||||||||||||
630 | |||||||||||||||||
631 | void GalleryBrowser2::SetMode( GalleryBrowserMode eMode ) | ||||||||||||||||
632 | { | ||||||||||||||||
633 | if( GetMode() == eMode ) | ||||||||||||||||
634 | return; | ||||||||||||||||
635 | |||||||||||||||||
636 | meLastMode = GetMode(); | ||||||||||||||||
637 | |||||||||||||||||
638 | switch( eMode ) | ||||||||||||||||
639 | { | ||||||||||||||||
640 | case GALLERYBROWSERMODE_ICON: | ||||||||||||||||
641 | { | ||||||||||||||||
642 | mxListView->hide(); | ||||||||||||||||
643 | |||||||||||||||||
644 | mxPreview->Hide(); | ||||||||||||||||
645 | mxPreview->SetGraphic( Graphic() ); | ||||||||||||||||
646 | GalleryPreview::PreviewMedia( INetURLObject() ); | ||||||||||||||||
647 | |||||||||||||||||
648 | mxIconView->Show(); | ||||||||||||||||
649 | |||||||||||||||||
650 | mxIconButton->set_sensitive(true); | ||||||||||||||||
651 | mxListButton->set_sensitive(true); | ||||||||||||||||
652 | |||||||||||||||||
653 | mxIconButton->set_active(true); | ||||||||||||||||
654 | mxListButton->set_active(false); | ||||||||||||||||
655 | } | ||||||||||||||||
656 | break; | ||||||||||||||||
657 | |||||||||||||||||
658 | case GALLERYBROWSERMODE_LIST: | ||||||||||||||||
659 | { | ||||||||||||||||
660 | mxIconView->Hide(); | ||||||||||||||||
661 | |||||||||||||||||
662 | mxPreview->Hide(); | ||||||||||||||||
663 | mxPreview->SetGraphic( Graphic() ); | ||||||||||||||||
664 | GalleryPreview::PreviewMedia( INetURLObject() ); | ||||||||||||||||
665 | |||||||||||||||||
666 | mxListView->show(); | ||||||||||||||||
667 | UpdateRows(true); | ||||||||||||||||
668 | |||||||||||||||||
669 | mxIconButton->set_sensitive(true); | ||||||||||||||||
670 | mxListButton->set_sensitive(true); | ||||||||||||||||
671 | |||||||||||||||||
672 | mxIconButton->set_active(false); | ||||||||||||||||
673 | mxListButton->set_active(true); | ||||||||||||||||
674 | } | ||||||||||||||||
675 | break; | ||||||||||||||||
676 | |||||||||||||||||
677 | case GALLERYBROWSERMODE_PREVIEW: | ||||||||||||||||
678 | { | ||||||||||||||||
679 | Graphic aGraphic; | ||||||||||||||||
680 | Point aSelPos; | ||||||||||||||||
681 | const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); | ||||||||||||||||
682 | |||||||||||||||||
683 | if( nItemId ) | ||||||||||||||||
684 | { | ||||||||||||||||
685 | const sal_uInt32 nPos = nItemId - 1; | ||||||||||||||||
686 | |||||||||||||||||
687 | mxIconView->Hide(); | ||||||||||||||||
688 | mxListView->hide(); | ||||||||||||||||
689 | |||||||||||||||||
690 | if( mpCurTheme ) | ||||||||||||||||
691 | mpCurTheme->GetGraphic( nPos, aGraphic ); | ||||||||||||||||
692 | |||||||||||||||||
693 | mxPreview->SetGraphic( aGraphic ); | ||||||||||||||||
694 | mxPreview->Show(); | ||||||||||||||||
695 | |||||||||||||||||
696 | if( mpCurTheme && mpCurTheme->GetObjectKind( nPos ) == SgaObjKind::Sound ) | ||||||||||||||||
697 | GalleryPreview::PreviewMedia( mpCurTheme->GetObjectURL( nPos ) ); | ||||||||||||||||
698 | |||||||||||||||||
699 | mxIconButton->set_sensitive(false); | ||||||||||||||||
700 | mxListButton->set_sensitive(false); | ||||||||||||||||
701 | } | ||||||||||||||||
702 | } | ||||||||||||||||
703 | break; | ||||||||||||||||
704 | |||||||||||||||||
705 | default: | ||||||||||||||||
706 | break; | ||||||||||||||||
707 | } | ||||||||||||||||
708 | |||||||||||||||||
709 | GalleryBrowser2::meInitMode = meMode = eMode; | ||||||||||||||||
710 | } | ||||||||||||||||
711 | |||||||||||||||||
712 | weld::Widget* GalleryBrowser2::GetViewWindow() const | ||||||||||||||||
713 | { | ||||||||||||||||
714 | weld::Widget* pRet; | ||||||||||||||||
715 | |||||||||||||||||
716 | switch( GetMode() ) | ||||||||||||||||
717 | { | ||||||||||||||||
718 | case GALLERYBROWSERMODE_LIST: pRet = mxListView.get(); break; | ||||||||||||||||
719 | case GALLERYBROWSERMODE_PREVIEW: pRet = mxPreview->GetDrawingArea(); break; | ||||||||||||||||
720 | |||||||||||||||||
721 | default: | ||||||||||||||||
722 | pRet = mxIconView->GetDrawingArea(); | ||||||||||||||||
723 | break; | ||||||||||||||||
724 | } | ||||||||||||||||
725 | |||||||||||||||||
726 | return pRet; | ||||||||||||||||
727 | } | ||||||||||||||||
728 | |||||||||||||||||
729 | void GalleryBrowser2::Travel( GalleryBrowserTravel eTravel ) | ||||||||||||||||
730 | { | ||||||||||||||||
731 | if( !mpCurTheme ) | ||||||||||||||||
732 | return; | ||||||||||||||||
733 | |||||||||||||||||
734 | Point aSelPos; | ||||||||||||||||
735 | const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); | ||||||||||||||||
736 | |||||||||||||||||
737 | if( !nItemId ) | ||||||||||||||||
738 | return; | ||||||||||||||||
739 | |||||||||||||||||
740 | sal_uInt32 nNewItemId = nItemId; | ||||||||||||||||
741 | |||||||||||||||||
742 | switch( eTravel ) | ||||||||||||||||
743 | { | ||||||||||||||||
744 | case GalleryBrowserTravel::First: nNewItemId = 1; break; | ||||||||||||||||
745 | case GalleryBrowserTravel::Last: nNewItemId = mpCurTheme->GetObjectCount(); break; | ||||||||||||||||
746 | case GalleryBrowserTravel::Previous: nNewItemId--; break; | ||||||||||||||||
747 | case GalleryBrowserTravel::Next: nNewItemId++; break; | ||||||||||||||||
748 | default: | ||||||||||||||||
749 | break; | ||||||||||||||||
750 | } | ||||||||||||||||
751 | |||||||||||||||||
752 | if( nNewItemId < 1 ) | ||||||||||||||||
753 | nNewItemId = 1; | ||||||||||||||||
754 | else if( nNewItemId > mpCurTheme->GetObjectCount() ) | ||||||||||||||||
755 | nNewItemId = mpCurTheme->GetObjectCount(); | ||||||||||||||||
756 | |||||||||||||||||
757 | if( nNewItemId == nItemId ) | ||||||||||||||||
758 | return; | ||||||||||||||||
759 | |||||||||||||||||
760 | ImplSelectItemId( nNewItemId ); | ||||||||||||||||
761 | ImplUpdateInfoBar(); | ||||||||||||||||
762 | |||||||||||||||||
763 | if( GALLERYBROWSERMODE_PREVIEW != GetMode() ) | ||||||||||||||||
764 | return; | ||||||||||||||||
765 | |||||||||||||||||
766 | Graphic aGraphic; | ||||||||||||||||
767 | const sal_uInt32 nPos = nNewItemId - 1; | ||||||||||||||||
768 | |||||||||||||||||
769 | mpCurTheme->GetGraphic( nPos, aGraphic ); | ||||||||||||||||
770 | mxPreview->SetGraphic( aGraphic ); | ||||||||||||||||
771 | |||||||||||||||||
772 | if( SgaObjKind::Sound == mpCurTheme->GetObjectKind( nPos ) ) | ||||||||||||||||
773 | GalleryPreview::PreviewMedia( mpCurTheme->GetObjectURL( nPos ) ); | ||||||||||||||||
774 | |||||||||||||||||
775 | mxPreview->Invalidate(); | ||||||||||||||||
776 | } | ||||||||||||||||
777 | |||||||||||||||||
778 | void GalleryBrowser2::ImplUpdateViews( sal_uInt16 nSelectionId ) | ||||||||||||||||
779 | { | ||||||||||||||||
780 | mxIconView->Hide(); | ||||||||||||||||
781 | mxListView->hide(); | ||||||||||||||||
782 | mxPreview->Hide(); | ||||||||||||||||
783 | |||||||||||||||||
784 | mxIconView->Clear(); | ||||||||||||||||
785 | mxListView->clear(); | ||||||||||||||||
786 | |||||||||||||||||
787 | if( mpCurTheme ) | ||||||||||||||||
788 | { | ||||||||||||||||
789 | const int nAlwaysUpToDate = 15; | ||||||||||||||||
790 | |||||||||||||||||
791 | mxListView->freeze(); | ||||||||||||||||
792 | |||||||||||||||||
793 | sal_uInt32 nCount = mpCurTheme->GetObjectCount(); | ||||||||||||||||
794 | for (sal_uInt32 i = 0; i < nCount; ++i) | ||||||||||||||||
795 | { | ||||||||||||||||
796 | mxIconView->InsertItem(i + 1); // skip reserved id 0 | ||||||||||||||||
797 | mxListView->append(OUString::number(i), ""); // create on-demand in VisRowsScrolledHdl | ||||||||||||||||
798 | |||||||||||||||||
799 | if (i == nAlwaysUpToDate) // fill in the first block | ||||||||||||||||
800 | UpdateRows(false); | ||||||||||||||||
801 | } | ||||||||||||||||
802 | |||||||||||||||||
803 | if (nCount < nAlwaysUpToDate) // if less than block size, fill in all of them | ||||||||||||||||
804 | UpdateRows(false); | ||||||||||||||||
805 | |||||||||||||||||
806 | mxListView->thaw(); | ||||||||||||||||
807 | |||||||||||||||||
808 | ImplSelectItemId( std::min<sal_uInt16>( nSelectionId, mpCurTheme->GetObjectCount() ) ); | ||||||||||||||||
809 | } | ||||||||||||||||
810 | |||||||||||||||||
811 | switch( GetMode() ) | ||||||||||||||||
812 | { | ||||||||||||||||
813 | case GALLERYBROWSERMODE_ICON: mxIconView->Show(); break; | ||||||||||||||||
814 | case GALLERYBROWSERMODE_LIST: | ||||||||||||||||
815 | mxListView->show(); | ||||||||||||||||
816 | UpdateRows(true); | ||||||||||||||||
817 | break; | ||||||||||||||||
818 | case GALLERYBROWSERMODE_PREVIEW: mxPreview->Show(); break; | ||||||||||||||||
819 | |||||||||||||||||
820 | default: | ||||||||||||||||
821 | break; | ||||||||||||||||
822 | } | ||||||||||||||||
823 | |||||||||||||||||
824 | ImplUpdateInfoBar(); | ||||||||||||||||
825 | } | ||||||||||||||||
826 | |||||||||||||||||
827 | void GalleryBrowser2::UpdateRows(bool bVisibleOnly) | ||||||||||||||||
828 | { | ||||||||||||||||
829 | auto lambda = [this](weld::TreeIter& rEntry){ | ||||||||||||||||
830 | // id is non-null if the preview is pending creation | ||||||||||||||||
831 | OUString sId(mxListView->get_id(rEntry)); | ||||||||||||||||
832 | if (sId.isEmpty()) | ||||||||||||||||
833 | return false; | ||||||||||||||||
834 | |||||||||||||||||
835 | // get the icon for the listview | ||||||||||||||||
836 | BitmapEx aBitmapEx; | ||||||||||||||||
837 | Size aPreparedSize; | ||||||||||||||||
838 | |||||||||||||||||
839 | OUString sItemTextTitle; | ||||||||||||||||
840 | OUString sItemTextPath; | ||||||||||||||||
841 | |||||||||||||||||
842 | sal_Int32 i = sId.toUInt32(); | ||||||||||||||||
843 | mpCurTheme->GetPreviewBitmapExAndStrings(i, aBitmapEx, aPreparedSize, sItemTextTitle, sItemTextPath); | ||||||||||||||||
844 | |||||||||||||||||
845 | bool bNeedToCreate(aBitmapEx.IsEmpty()); | ||||||||||||||||
846 | if (!bNeedToCreate && (sItemTextTitle.isEmpty() || aPreparedSize != maPreviewSize)) | ||||||||||||||||
847 | bNeedToCreate = true; | ||||||||||||||||
848 | |||||||||||||||||
849 | if (bNeedToCreate) | ||||||||||||||||
850 | { | ||||||||||||||||
851 | std::unique_ptr<SgaObject> xObj = mpCurTheme->AcquireObject(i); | ||||||||||||||||
852 | if (xObj) | ||||||||||||||||
853 | { | ||||||||||||||||
854 | aBitmapEx = xObj->createPreviewBitmapEx(maPreviewSize); | ||||||||||||||||
855 | sItemTextTitle = GalleryBrowser2::GetItemText(*xObj, GalleryItemFlags::Title); | ||||||||||||||||
856 | sItemTextPath = GalleryBrowser2::GetItemText(*xObj, GalleryItemFlags::Path); | ||||||||||||||||
857 | |||||||||||||||||
858 | mpCurTheme->SetPreviewBitmapExAndStrings(i, aBitmapEx, maPreviewSize, sItemTextTitle, sItemTextPath); | ||||||||||||||||
859 | } | ||||||||||||||||
860 | } | ||||||||||||||||
861 | |||||||||||||||||
862 | if (!aBitmapEx.IsEmpty()) | ||||||||||||||||
863 | { | ||||||||||||||||
864 | const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel()); | ||||||||||||||||
865 | const Point aPos( | ||||||||||||||||
866 | ((maPreviewSize.Width() - aBitmapExSizePixel.Width()) >> 1), | ||||||||||||||||
867 | ((maPreviewSize.Height() - aBitmapExSizePixel.Height()) >> 1)); | ||||||||||||||||
868 | |||||||||||||||||
869 | mxDev->Erase(); | ||||||||||||||||
870 | |||||||||||||||||
871 | if (aBitmapEx.IsTransparent()) | ||||||||||||||||
872 | { | ||||||||||||||||
873 | // draw checkered background | ||||||||||||||||
874 | GalleryIconView::drawTransparenceBackground(*mxDev, aPos, aBitmapExSizePixel); | ||||||||||||||||
875 | } | ||||||||||||||||
876 | |||||||||||||||||
877 | mxDev->DrawBitmapEx(aPos, aBitmapEx); | ||||||||||||||||
878 | } | ||||||||||||||||
879 | |||||||||||||||||
880 | mxListView->set_text(rEntry, sItemTextTitle); | ||||||||||||||||
881 | mxListView->set_image(rEntry, *mxDev); | ||||||||||||||||
882 | mxListView->set_id(rEntry, OUString()); | ||||||||||||||||
883 | |||||||||||||||||
884 | return false; | ||||||||||||||||
885 | }; | ||||||||||||||||
886 | |||||||||||||||||
887 | if (bVisibleOnly) | ||||||||||||||||
888 | { | ||||||||||||||||
889 | // ensure all visible entries are up to date | ||||||||||||||||
890 | mxListView->visible_foreach(lambda); | ||||||||||||||||
891 | // and ensure all selected entries are up to date | ||||||||||||||||
892 | mxListView->selected_foreach(lambda); | ||||||||||||||||
893 | return; | ||||||||||||||||
894 | } | ||||||||||||||||
895 | |||||||||||||||||
896 | mxListView->all_foreach(lambda); | ||||||||||||||||
897 | } | ||||||||||||||||
898 | |||||||||||||||||
899 | IMPL_LINK_NOARG(GalleryBrowser2, VisRowsScrolledHdl, weld::TreeView&, void)void GalleryBrowser2::LinkStubVisRowsScrolledHdl(void * instance , weld::TreeView& data) { return static_cast<GalleryBrowser2 *>(instance)->VisRowsScrolledHdl(data); } void GalleryBrowser2 ::VisRowsScrolledHdl(__attribute__ ((unused)) weld::TreeView& ) | ||||||||||||||||
900 | { | ||||||||||||||||
901 | UpdateRows(true); | ||||||||||||||||
902 | } | ||||||||||||||||
903 | |||||||||||||||||
904 | IMPL_LINK_NOARG(GalleryBrowser2, SizeAllocHdl, const Size&, void)void GalleryBrowser2::LinkStubSizeAllocHdl(void * instance, const Size& data) { return static_cast<GalleryBrowser2 *> (instance)->SizeAllocHdl(data); } void GalleryBrowser2::SizeAllocHdl (__attribute__ ((unused)) const Size&) | ||||||||||||||||
905 | { | ||||||||||||||||
906 | UpdateRows(true); | ||||||||||||||||
907 | } | ||||||||||||||||
908 | |||||||||||||||||
909 | void GalleryBrowser2::ImplUpdateInfoBar() | ||||||||||||||||
910 | { | ||||||||||||||||
911 | if (!mpCurTheme) | ||||||||||||||||
912 | return; | ||||||||||||||||
913 | mxInfoBar->set_label( mpCurTheme->GetName() ); | ||||||||||||||||
914 | } | ||||||||||||||||
915 | |||||||||||||||||
916 | void GalleryBrowser2::ImplUpdateSelection() | ||||||||||||||||
917 | { | ||||||||||||||||
918 | if (!mpCurTheme) | ||||||||||||||||
919 | return; | ||||||||||||||||
920 | auto nSelectedObject = (GALLERYBROWSERMODE_ICON == GetMode()) ? (mxIconView->GetSelectedItemId() - 1) : mxListView->get_selected_index(); | ||||||||||||||||
921 | m_xHelper->SelectObject(nSelectedObject); | ||||||||||||||||
922 | } | ||||||||||||||||
923 | |||||||||||||||||
924 | sal_uInt32 GalleryBrowser2::ImplGetSelectedItemId( const Point* pSelPos, Point& rSelPos ) | ||||||||||||||||
925 | { | ||||||||||||||||
926 | sal_uInt32 nRet = 0; | ||||||||||||||||
927 | |||||||||||||||||
928 | if( GALLERYBROWSERMODE_PREVIEW == GetMode() ) | ||||||||||||||||
929 | { | ||||||||||||||||
930 | nRet = ( ( GALLERYBROWSERMODE_ICON == meLastMode ) ? mxIconView->GetSelectedItemId() : ( mxListView->get_selected_index() + 1 ) ); | ||||||||||||||||
931 | |||||||||||||||||
932 | if( pSelPos ) | ||||||||||||||||
933 | rSelPos = *pSelPos; | ||||||||||||||||
934 | else | ||||||||||||||||
935 | { | ||||||||||||||||
936 | Size aOutputSizePixel(mxPreview->GetOutputSizePixel()); | ||||||||||||||||
937 | rSelPos = Point( aOutputSizePixel.Width() >> 1, aOutputSizePixel.Height() >> 1 ); | ||||||||||||||||
938 | } | ||||||||||||||||
939 | } | ||||||||||||||||
940 | else if (GALLERYBROWSERMODE_ICON == GetMode()) | ||||||||||||||||
941 | { | ||||||||||||||||
942 | if (pSelPos) | ||||||||||||||||
943 | { | ||||||||||||||||
944 | nRet = mxIconView->GetItemId( *pSelPos ); | ||||||||||||||||
945 | rSelPos = *pSelPos; | ||||||||||||||||
946 | } | ||||||||||||||||
947 | else | ||||||||||||||||
948 | { | ||||||||||||||||
949 | nRet = mxIconView->GetSelectedItemId(); | ||||||||||||||||
950 | rSelPos = mxIconView->GetItemRect(nRet).Center(); | ||||||||||||||||
951 | } | ||||||||||||||||
952 | } | ||||||||||||||||
953 | else | ||||||||||||||||
954 | { | ||||||||||||||||
955 | std::unique_ptr<weld::TreeIter> xIter = mxListView->make_iterator(); | ||||||||||||||||
956 | if( pSelPos ) | ||||||||||||||||
957 | { | ||||||||||||||||
958 | if (mxListView->get_dest_row_at_pos(*pSelPos, xIter.get(), false)) | ||||||||||||||||
959 | nRet = mxListView->get_iter_index_in_parent(*xIter) + 1; | ||||||||||||||||
960 | rSelPos = *pSelPos; | ||||||||||||||||
961 | } | ||||||||||||||||
962 | else | ||||||||||||||||
963 | { | ||||||||||||||||
964 | if (mxListView->get_selected(xIter.get())) | ||||||||||||||||
965 | { | ||||||||||||||||
966 | nRet = mxListView->get_iter_index_in_parent(*xIter) + 1; | ||||||||||||||||
967 | rSelPos = mxListView->get_row_area(*xIter).Center(); | ||||||||||||||||
968 | } | ||||||||||||||||
969 | } | ||||||||||||||||
970 | } | ||||||||||||||||
971 | |||||||||||||||||
972 | if( nRet && ( !mpCurTheme || ( nRet > mpCurTheme->GetObjectCount() ) ) ) | ||||||||||||||||
973 | { | ||||||||||||||||
974 | nRet = 0; | ||||||||||||||||
975 | } | ||||||||||||||||
976 | |||||||||||||||||
977 | return nRet; | ||||||||||||||||
978 | } | ||||||||||||||||
979 | |||||||||||||||||
980 | void GalleryBrowser2::ImplSelectItemId(sal_uInt32 nItemId) | ||||||||||||||||
981 | { | ||||||||||||||||
982 | if( nItemId ) | ||||||||||||||||
983 | { | ||||||||||||||||
984 | mxIconView->SelectItem(nItemId); | ||||||||||||||||
985 | mxListView->select( nItemId - 1 ); | ||||||||||||||||
986 | ImplUpdateSelection(); | ||||||||||||||||
987 | } | ||||||||||||||||
988 | } | ||||||||||||||||
989 | |||||||||||||||||
990 | css::uno::Reference< css::frame::XFrame > | ||||||||||||||||
991 | GalleryBrowser2::GetFrame() | ||||||||||||||||
992 | { | ||||||||||||||||
993 | css::uno::Reference< css::frame::XFrame > xFrame; | ||||||||||||||||
994 | SfxViewFrame* pCurrentViewFrame = SfxViewFrame::Current(); | ||||||||||||||||
995 | if ( pCurrentViewFrame ) | ||||||||||||||||
996 | { | ||||||||||||||||
997 | SfxBindings& rBindings = pCurrentViewFrame->GetBindings(); | ||||||||||||||||
998 | xFrame.set( rBindings.GetActiveFrame() ); | ||||||||||||||||
999 | } | ||||||||||||||||
1000 | |||||||||||||||||
1001 | return xFrame; | ||||||||||||||||
1002 | } | ||||||||||||||||
1003 | |||||||||||||||||
1004 | void GalleryBrowser2::DispatchAdd( | ||||||||||||||||
1005 | const css::uno::Reference< css::frame::XDispatch > &rxDispatch, | ||||||||||||||||
1006 | const css::util::URL &rURL) | ||||||||||||||||
1007 | { | ||||||||||||||||
1008 | Point aSelPos; | ||||||||||||||||
1009 | const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); | ||||||||||||||||
1010 | |||||||||||||||||
1011 | if( !mpCurTheme || !nItemId ) | ||||||||||||||||
1012 | return; | ||||||||||||||||
1013 | |||||||||||||||||
1014 | mnCurActionPos = nItemId - 1; | ||||||||||||||||
1015 | |||||||||||||||||
1016 | css::uno::Reference< css::frame::XDispatch > xDispatch( rxDispatch ); | ||||||||||||||||
1017 | css::util::URL aURL = rURL; | ||||||||||||||||
1018 | |||||||||||||||||
1019 | if ( !xDispatch.is() ) | ||||||||||||||||
1020 | { | ||||||||||||||||
1021 | css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider( | ||||||||||||||||
1022 | GetFrame(), css::uno::UNO_QUERY ); | ||||||||||||||||
1023 | if ( !xDispatchProvider.is() || !m_xTransformer.is() ) | ||||||||||||||||
1024 | return; | ||||||||||||||||
1025 | |||||||||||||||||
1026 | aURL.Complete = ".uno:InsertGalleryPic"; | ||||||||||||||||
1027 | m_xTransformer->parseStrict( aURL ); | ||||||||||||||||
1028 | xDispatch = xDispatchProvider->queryDispatch( | ||||||||||||||||
1029 | aURL, | ||||||||||||||||
1030 | "_self", | ||||||||||||||||
1031 | css::frame::FrameSearchFlag::SELF ); | ||||||||||||||||
1032 | } | ||||||||||||||||
1033 | |||||||||||||||||
1034 | if ( !xDispatch.is() ) | ||||||||||||||||
1035 | return; | ||||||||||||||||
1036 | |||||||||||||||||
1037 | sal_Int8 nType = 0; | ||||||||||||||||
1038 | OUString aFilterName; | ||||||||||||||||
1039 | css::uno::Reference< css::lang::XComponent > xDrawing; | ||||||||||||||||
1040 | css::uno::Reference< css::graphic::XGraphic > xGraphic; | ||||||||||||||||
1041 | |||||||||||||||||
1042 | aFilterName = GetFilterName(); | ||||||||||||||||
1043 | |||||||||||||||||
1044 | switch( mpCurTheme->GetObjectKind( mnCurActionPos ) ) | ||||||||||||||||
1045 | { | ||||||||||||||||
1046 | case SgaObjKind::Bitmap: | ||||||||||||||||
1047 | case SgaObjKind::Animation: | ||||||||||||||||
1048 | case SgaObjKind::Inet: | ||||||||||||||||
1049 | // TODO drawing objects are inserted as drawings only via drag&drop | ||||||||||||||||
1050 | case SgaObjKind::SvDraw: | ||||||||||||||||
1051 | nType = css::gallery::GalleryItemType::GRAPHIC; | ||||||||||||||||
1052 | break; | ||||||||||||||||
1053 | |||||||||||||||||
1054 | case SgaObjKind::Sound : | ||||||||||||||||
1055 | nType = css::gallery::GalleryItemType::MEDIA; | ||||||||||||||||
1056 | break; | ||||||||||||||||
1057 | |||||||||||||||||
1058 | default: | ||||||||||||||||
1059 | nType = css::gallery::GalleryItemType::EMPTY; | ||||||||||||||||
1060 | break; | ||||||||||||||||
1061 | } | ||||||||||||||||
1062 | |||||||||||||||||
1063 | Graphic aGraphic; | ||||||||||||||||
1064 | bool bGraphic = mpCurTheme->GetGraphic( mnCurActionPos, aGraphic ); | ||||||||||||||||
1065 | if ( bGraphic && !aGraphic.IsNone() ) | ||||||||||||||||
1066 | xGraphic.set( aGraphic.GetXGraphic() ); | ||||||||||||||||
1067 | OSL_ENSURE( xGraphic.is(), "gallery item is graphic, but the reference is invalid!" )do { if (true && (!(xGraphic.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svx/source/gallery2/galbrws2.cxx" ":" "1067" ": "), "%s", "gallery item is graphic, but the reference is invalid!" ); } } while (false); | ||||||||||||||||
1068 | |||||||||||||||||
1069 | css::uno::Sequence< css::beans::PropertyValue > aSeq( SVXGALLERYITEM_PARAMS5 ); | ||||||||||||||||
1070 | |||||||||||||||||
1071 | aSeq[0].Name = SVXGALLERYITEM_TYPE"GalleryItemType"; | ||||||||||||||||
1072 | aSeq[0].Value <<= nType; | ||||||||||||||||
1073 | aSeq[1].Name = SVXGALLERYITEM_URL"URL"; | ||||||||||||||||
1074 | aSeq[1].Value <<= OUString(); | ||||||||||||||||
1075 | aSeq[2].Name = SVXGALLERYITEM_FILTER"FilterName"; | ||||||||||||||||
1076 | aSeq[2].Value <<= aFilterName; | ||||||||||||||||
1077 | aSeq[3].Name = SVXGALLERYITEM_DRAWING"Drawing"; | ||||||||||||||||
1078 | aSeq[3].Value <<= xDrawing; | ||||||||||||||||
1079 | aSeq[4].Name = SVXGALLERYITEM_GRAPHIC"Graphic"; | ||||||||||||||||
1080 | aSeq[4].Value <<= xGraphic; | ||||||||||||||||
1081 | |||||||||||||||||
1082 | css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 ); | ||||||||||||||||
1083 | aArgs[0].Name = SVXGALLERYITEM_ARGNAME"GalleryItem"; | ||||||||||||||||
1084 | aArgs[0].Value <<= aSeq; | ||||||||||||||||
1085 | |||||||||||||||||
1086 | std::unique_ptr<DispatchInfo> pInfo(new DispatchInfo); | ||||||||||||||||
1087 | pInfo->TargetURL = aURL; | ||||||||||||||||
1088 | pInfo->Arguments = aArgs; | ||||||||||||||||
1089 | pInfo->Dispatch = xDispatch; | ||||||||||||||||
1090 | |||||||||||||||||
1091 | if ( Application::PostUserEvent( | ||||||||||||||||
1092 | LINK( nullptr, GalleryBrowser2, AsyncDispatch_Impl)::tools::detail::makeLink( ::tools::detail::castTo<GalleryBrowser2 *>(nullptr), &GalleryBrowser2::LinkStubAsyncDispatch_Impl ), pInfo.get() ) ) | ||||||||||||||||
1093 | pInfo.release(); | ||||||||||||||||
1094 | } | ||||||||||||||||
1095 | |||||||||||||||||
1096 | void GalleryBrowser2::Execute(const OString &rIdent) | ||||||||||||||||
1097 | { | ||||||||||||||||
1098 | Point aSelPos; | ||||||||||||||||
1099 | const sal_uInt32 nItemId = ImplGetSelectedItemId( nullptr, aSelPos ); | ||||||||||||||||
1100 | |||||||||||||||||
1101 | if( !(mpCurTheme && nItemId) ) | ||||||||||||||||
1102 | return; | ||||||||||||||||
1103 | |||||||||||||||||
1104 | mnCurActionPos = nItemId - 1; | ||||||||||||||||
1105 | |||||||||||||||||
1106 | if (rIdent == "preview") | ||||||||||||||||
1107 | SetMode( ( GALLERYBROWSERMODE_PREVIEW != GetMode() ) ? GALLERYBROWSERMODE_PREVIEW : meLastMode ); | ||||||||||||||||
1108 | else if (rIdent == "delete") | ||||||||||||||||
1109 | { | ||||||||||||||||
1110 | if (!mpCurTheme->IsReadOnly()) | ||||||||||||||||
1111 | { | ||||||||||||||||
1112 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetViewWindow(), "svx/ui/querydeleteobjectdialog.ui")); | ||||||||||||||||
1113 | std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("QueryDeleteObjectDialog")); | ||||||||||||||||
1114 | if (xQuery->run() == RET_YES) | ||||||||||||||||
1115 | { | ||||||||||||||||
1116 | mpCurTheme->RemoveObject( mnCurActionPos ); | ||||||||||||||||
1117 | } | ||||||||||||||||
1118 | } | ||||||||||||||||
1119 | } | ||||||||||||||||
1120 | else if (rIdent == "title") | ||||||||||||||||
1121 | { | ||||||||||||||||
1122 | std::unique_ptr<SgaObject> pObj = mpCurTheme->AcquireObject( mnCurActionPos ); | ||||||||||||||||
1123 | |||||||||||||||||
1124 | if( pObj ) | ||||||||||||||||
1125 | { | ||||||||||||||||
1126 | const OUString aOldTitle( GetItemText( *pObj, GalleryItemFlags::Title ) ); | ||||||||||||||||
1127 | |||||||||||||||||
1128 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); | ||||||||||||||||
1129 | ScopedVclPtr<AbstractTitleDialog> aDlg(pFact->CreateTitleDialog(GetViewWindow(), aOldTitle)); | ||||||||||||||||
1130 | if( aDlg->Execute() == RET_OK ) | ||||||||||||||||
1131 | { | ||||||||||||||||
1132 | OUString aNewTitle( aDlg->GetTitle() ); | ||||||||||||||||
1133 | |||||||||||||||||
1134 | if( ( aNewTitle.isEmpty() && !pObj->GetTitle().isEmpty() ) || ( aNewTitle != aOldTitle ) ) | ||||||||||||||||
1135 | { | ||||||||||||||||
1136 | if( aNewTitle.isEmpty() ) | ||||||||||||||||
1137 | aNewTitle = "__<empty>__"; | ||||||||||||||||
1138 | |||||||||||||||||
1139 | pObj->SetTitle( aNewTitle ); | ||||||||||||||||
1140 | mpCurTheme->InsertObject( *pObj ); | ||||||||||||||||
1141 | } | ||||||||||||||||
1142 | } | ||||||||||||||||
1143 | } | ||||||||||||||||
1144 | } | ||||||||||||||||
1145 | else if (rIdent == "copy") | ||||||||||||||||
1146 | { | ||||||||||||||||
1147 | mpCurTheme->CopyToClipboard(mnCurActionPos); | ||||||||||||||||
1148 | } | ||||||||||||||||
1149 | else if (rIdent == "paste") | ||||||||||||||||
1150 | { | ||||||||||||||||
1151 | if( !mpCurTheme->IsReadOnly() ) | ||||||||||||||||
1152 | { | ||||||||||||||||
1153 | TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromClipboard(GetSystemClipboard())); | ||||||||||||||||
1154 | mpCurTheme->InsertTransferable( aDataHelper.GetTransferable(), mnCurActionPos ); | ||||||||||||||||
1155 | } | ||||||||||||||||
1156 | } | ||||||||||||||||
1157 | } | ||||||||||||||||
1158 | |||||||||||||||||
1159 | OUString GalleryBrowser2::GetItemText( const SgaObject& rObj, GalleryItemFlags nItemTextFlags ) | ||||||||||||||||
1160 | { | ||||||||||||||||
1161 | OUString aRet; | ||||||||||||||||
1162 | |||||||||||||||||
1163 | const INetURLObject& aURL(rObj.GetURL()); | ||||||||||||||||
1164 | |||||||||||||||||
1165 | if( nItemTextFlags & GalleryItemFlags::Title ) | ||||||||||||||||
1166 | { | ||||||||||||||||
1167 | OUString aTitle( rObj.GetTitle() ); | ||||||||||||||||
1168 | |||||||||||||||||
1169 | if( aTitle.isEmpty() ) | ||||||||||||||||
1170 | aTitle = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DecodeMechanism::Unambiguous ); | ||||||||||||||||
1171 | |||||||||||||||||
1172 | if( aTitle.isEmpty() ) | ||||||||||||||||
1173 | { | ||||||||||||||||
1174 | aTitle = aURL.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ); | ||||||||||||||||
1175 | aTitle = aTitle.copy( aTitle.lastIndexOf('/')+1 ); | ||||||||||||||||
1176 | } | ||||||||||||||||
1177 | |||||||||||||||||
1178 | aRet += aTitle; | ||||||||||||||||
1179 | } | ||||||||||||||||
1180 | |||||||||||||||||
1181 | if( nItemTextFlags & GalleryItemFlags::Path ) | ||||||||||||||||
1182 | { | ||||||||||||||||
1183 | const OUString aPath( aURL.getFSysPath( FSysStyle::Detect ) ); | ||||||||||||||||
1184 | |||||||||||||||||
1185 | if( !aPath.isEmpty() && ( nItemTextFlags & GalleryItemFlags::Title ) ) | ||||||||||||||||
1186 | aRet += " ("; | ||||||||||||||||
1187 | |||||||||||||||||
1188 | aRet += aURL.getFSysPath( FSysStyle::Detect ); | ||||||||||||||||
1189 | |||||||||||||||||
1190 | if( !aPath.isEmpty() && ( nItemTextFlags & GalleryItemFlags::Title ) ) | ||||||||||||||||
1191 | aRet += ")"; | ||||||||||||||||
1192 | } | ||||||||||||||||
1193 | |||||||||||||||||
1194 | return aRet; | ||||||||||||||||
1195 | } | ||||||||||||||||
1196 | |||||||||||||||||
1197 | INetURLObject GalleryBrowser2::GetURL() const | ||||||||||||||||
1198 | { | ||||||||||||||||
1199 | INetURLObject aURL; | ||||||||||||||||
1200 | |||||||||||||||||
1201 | if( mpCurTheme && mnCurActionPos != 0xffffffff ) | ||||||||||||||||
1202 | aURL = mpCurTheme->GetObjectURL( mnCurActionPos ); | ||||||||||||||||
1203 | |||||||||||||||||
1204 | return aURL; | ||||||||||||||||
1205 | } | ||||||||||||||||
1206 | |||||||||||||||||
1207 | OUString GalleryBrowser2::GetFilterName() const | ||||||||||||||||
1208 | { | ||||||||||||||||
1209 | OUString aFilterName; | ||||||||||||||||
1210 | |||||||||||||||||
1211 | if( mpCurTheme && mnCurActionPos != 0xffffffff ) | ||||||||||||||||
1212 | { | ||||||||||||||||
1213 | const SgaObjKind eObjKind = mpCurTheme->GetObjectKind( mnCurActionPos ); | ||||||||||||||||
1214 | |||||||||||||||||
1215 | if( ( SgaObjKind::Bitmap == eObjKind ) || ( SgaObjKind::Animation == eObjKind ) ) | ||||||||||||||||
1216 | { | ||||||||||||||||
1217 | GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); | ||||||||||||||||
1218 | INetURLObject aURL; | ||||||||||||||||
1219 | mpCurTheme->GetURL( mnCurActionPos, aURL ); | ||||||||||||||||
1220 | sal_uInt16 nFilter = rFilter.GetImportFormatNumberForShortName(aURL.GetFileExtension()); | ||||||||||||||||
1221 | |||||||||||||||||
1222 | if( GRFILTER_FORMAT_DONTKNOW(sal_uInt16(0xFFFF)) != nFilter ) | ||||||||||||||||
1223 | aFilterName = rFilter.GetImportFormatName( nFilter ); | ||||||||||||||||
1224 | } | ||||||||||||||||
1225 | } | ||||||||||||||||
1226 | |||||||||||||||||
1227 | return aFilterName; | ||||||||||||||||
1228 | } | ||||||||||||||||
1229 | |||||||||||||||||
1230 | IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectValueSetHdl, ValueSet*, void)void GalleryBrowser2::LinkStubSelectObjectValueSetHdl(void * instance , ValueSet* data) { return static_cast<GalleryBrowser2 *> (instance)->SelectObjectValueSetHdl(data); } void GalleryBrowser2 ::SelectObjectValueSetHdl(__attribute__ ((unused)) ValueSet*) | ||||||||||||||||
1231 | { | ||||||||||||||||
1232 | ImplUpdateSelection(); | ||||||||||||||||
1233 | } | ||||||||||||||||
1234 | |||||||||||||||||
1235 | IMPL_LINK_NOARG(GalleryBrowser2, SelectObjectHdl, weld::TreeView&, void)void GalleryBrowser2::LinkStubSelectObjectHdl(void * instance , weld::TreeView& data) { return static_cast<GalleryBrowser2 *>(instance)->SelectObjectHdl(data); } void GalleryBrowser2 ::SelectObjectHdl(__attribute__ ((unused)) weld::TreeView& ) | ||||||||||||||||
1236 | { | ||||||||||||||||
1237 | ImplUpdateSelection(); | ||||||||||||||||
1238 | } | ||||||||||||||||
1239 | |||||||||||||||||
1240 | IMPL_LINK(GalleryBrowser2, SelectTbxHdl, weld::ToggleButton&, rBox, void)void GalleryBrowser2::LinkStubSelectTbxHdl(void * instance, weld ::ToggleButton& data) { return static_cast<GalleryBrowser2 *>(instance)->SelectTbxHdl(data); } void GalleryBrowser2 ::SelectTbxHdl(weld::ToggleButton& rBox) | ||||||||||||||||
1241 | { | ||||||||||||||||
1242 | if (&rBox == mxIconButton.get()) | ||||||||||||||||
1243 | SetMode(rBox.get_active() ? GALLERYBROWSERMODE_ICON : GALLERYBROWSERMODE_LIST); | ||||||||||||||||
1244 | else if (&rBox == mxListButton.get()) | ||||||||||||||||
1245 | SetMode(rBox.get_active() ? GALLERYBROWSERMODE_LIST : GALLERYBROWSERMODE_ICON); | ||||||||||||||||
1246 | } | ||||||||||||||||
1247 | |||||||||||||||||
1248 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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_VCL_PTR_HXX |
21 | #define INCLUDED_VCL_PTR_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <rtl/ref.hxx> |
26 | |
27 | #include <utility> |
28 | #include <type_traits> |
29 | |
30 | #ifdef DBG_UTIL |
31 | #ifndef _WIN32 |
32 | #include <vcl/vclmain.hxx> |
33 | #endif |
34 | #endif |
35 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase( |
44 | int (*)[sizeof(T)]) |
45 | { return std::is_base_of<VclReferenceBase, T>::value; } |
46 | |
47 | } // namespace vcl::detail |
48 | |
49 | /** |
50 | * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses. |
51 | * |
52 | * For more details on the design please see vcl/README.lifecycle |
53 | * |
54 | * @param reference_type must be a subclass of vcl::Window |
55 | */ |
56 | template <class reference_type> |
57 | class VclPtr |
58 | { |
59 | static_assert( |
60 | vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>( |
61 | nullptr), |
62 | "template argument type must be derived from VclReferenceBase"); |
63 | |
64 | ::rtl::Reference<reference_type> m_rInnerRef; |
65 | |
66 | public: |
67 | /** Constructor... |
68 | */ |
69 | VclPtr() |
70 | : m_rInnerRef() |
71 | {} |
72 | |
73 | /** Constructor... |
74 | */ |
75 | VclPtr (reference_type * pBody) |
76 | : m_rInnerRef(pBody) |
77 | {} |
78 | |
79 | /** Constructor... that doesn't take a ref. |
80 | */ |
81 | VclPtr (reference_type * pBody, __sal_NoAcquire) |
82 | : m_rInnerRef(pBody, SAL_NO_ACQUIRE) |
83 | {} |
84 | |
85 | /** Up-casting conversion constructor: Copies interface reference. |
86 | |
87 | Does not work for up-casts to ambiguous bases. For the special case of |
88 | up-casting to Reference< XInterface >, see the corresponding conversion |
89 | operator. |
90 | |
91 | @param rRef another reference |
92 | */ |
93 | template< class derived_type > |
94 | VclPtr( |
95 | const VclPtr< derived_type > & rRef, |
96 | typename std::enable_if< |
97 | std::is_base_of<reference_type, derived_type>::value, int>::type |
98 | = 0 ) |
99 | : m_rInnerRef( static_cast<reference_type*>(rRef) ) |
100 | { |
101 | } |
102 | |
103 | #if defined(DBG_UTIL) && !defined(_WIN32) |
104 | virtual ~VclPtr() |
105 | { |
106 | assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain ::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 106, __extension__ __PRETTY_FUNCTION__)); |
107 | // We can be one of the intermediate counts, but if we are the last |
108 | // VclPtr keeping this object alive, then something forgot to call dispose(). |
109 | assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)) |
110 | && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef ->isDisposed() || m_rInnerRef->getRefCount() > 1) && "someone forgot to call dispose()") ? void (0) : __assert_fail ("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\"" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 110, __extension__ __PRETTY_FUNCTION__)); |
111 | } |
112 | VclPtr(VclPtr const &) = default; |
113 | VclPtr(VclPtr &&) = default; |
114 | VclPtr & operator =(VclPtr const &) = default; |
115 | VclPtr & operator =(VclPtr &&) = default; |
116 | #endif |
117 | |
118 | /** |
119 | * A construction helper for VclPtr. Since VclPtr types are created |
120 | * with a reference-count of one - to help fit into the existing |
121 | * code-flow; this helps us to construct them easily. |
122 | * |
123 | * For more details on the design please see vcl/README.lifecycle |
124 | * |
125 | * @tparam reference_type must be a subclass of vcl::Window |
126 | */ |
127 | template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg) |
128 | { |
129 | return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ); |
130 | } |
131 | |
132 | /** Probably most common used: handle->someBodyOp(). |
133 | */ |
134 | reference_type * operator->() const |
135 | { |
136 | return m_rInnerRef.get(); |
137 | } |
138 | |
139 | /** Get the body. Can be used instead of operator->(). |
140 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() |
141 | are the same. |
142 | */ |
143 | reference_type * get() const |
144 | { |
145 | return m_rInnerRef.get(); |
146 | } |
147 | |
148 | void set(reference_type *pBody) |
149 | { |
150 | m_rInnerRef.set(pBody); |
151 | } |
152 | |
153 | void reset(reference_type *pBody) |
154 | { |
155 | m_rInnerRef.set(pBody); |
156 | } |
157 | |
158 | /** Up-casting copy assignment operator. |
159 | |
160 | Does not work for up-casts to ambiguous bases. |
161 | |
162 | @param rRef another reference |
163 | */ |
164 | template<typename derived_type> |
165 | typename std::enable_if< |
166 | std::is_base_of<reference_type, derived_type>::value, |
167 | VclPtr &>::type |
168 | operator =(VclPtr<derived_type> const & rRef) |
169 | { |
170 | m_rInnerRef.set(rRef.get()); |
171 | return *this; |
172 | } |
173 | |
174 | VclPtr & operator =(reference_type * pBody) |
175 | { |
176 | m_rInnerRef.set(pBody); |
177 | return *this; |
178 | } |
179 | |
180 | operator reference_type * () const |
181 | { |
182 | return m_rInnerRef.get(); |
183 | } |
184 | |
185 | explicit operator bool () const |
186 | { |
187 | return m_rInnerRef.get() != nullptr; |
188 | } |
189 | |
190 | void clear() |
191 | { |
192 | m_rInnerRef.clear(); |
193 | } |
194 | |
195 | void reset() |
196 | { |
197 | m_rInnerRef.clear(); |
198 | } |
199 | |
200 | void disposeAndClear() |
201 | { |
202 | // hold it alive for the lifetime of this method |
203 | ::rtl::Reference<reference_type> aTmp(m_rInnerRef); |
204 | m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-) |
205 | if (aTmp.get()) { |
206 | aTmp->disposeOnce(); |
207 | } |
208 | } |
209 | |
210 | /** Needed to place VclPtr's into STL collection. |
211 | */ |
212 | bool operator< (const VclPtr<reference_type> & handle) const |
213 | { |
214 | return (m_rInnerRef < handle.m_rInnerRef); |
215 | } |
216 | }; // class VclPtr |
217 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) { |
261 | return !(p1 == p2); |
262 | } |
263 | |
264 | /** |
265 | * A construction helper for a temporary VclPtr. Since VclPtr types |
266 | * are created with a reference-count of one - to help fit into |
267 | * the existing code-flow; this helps us to construct them easily. |
268 | * see also VclPtr::Create and ScopedVclPtr |
269 | * |
270 | * For more details on the design please see vcl/README.lifecycle |
271 | * |
272 | * @param reference_type must be a subclass of vcl::Window |
273 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
278 | template<typename... Arg> VclPtrInstance(Arg &&... arg) |
279 | : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
280 | { |
281 | } |
282 | |
283 | /** |
284 | * Override and disallow this, to prevent people accidentally calling it and actually |
285 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
286 | */ |
287 | template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete; |
288 | }; |
289 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
294 | /** Constructor... |
295 | */ |
296 | ScopedVclPtr() |
297 | : VclPtr<reference_type>() |
298 | {} |
299 | |
300 | /** Constructor |
301 | */ |
302 | ScopedVclPtr (reference_type * pBody) |
303 | : VclPtr<reference_type>(pBody) |
304 | {} |
305 | |
306 | /** Copy constructor... |
307 | */ |
308 | ScopedVclPtr (const VclPtr<reference_type> & handle) |
309 | : VclPtr<reference_type>(handle) |
310 | {} |
311 | |
312 | /** |
313 | Assignment that releases the last reference. |
314 | */ |
315 | void disposeAndReset(reference_type *pBody) |
316 | { |
317 | if (pBody != this->get()) { |
318 | VclPtr<reference_type>::disposeAndClear(); |
319 | VclPtr<reference_type>::set(pBody); |
320 | } |
321 | } |
322 | |
323 | /** |
324 | Assignment that releases the last reference. |
325 | */ |
326 | ScopedVclPtr<reference_type>& operator = (reference_type * pBody) |
327 | { |
328 | disposeAndReset(pBody); |
329 | return *this; |
330 | } |
331 | |
332 | /** Up-casting conversion constructor: Copies interface reference. |
333 | |
334 | Does not work for up-casts to ambiguous bases. For the special case of |
335 | up-casting to Reference< XInterface >, see the corresponding conversion |
336 | operator. |
337 | |
338 | @param rRef another reference |
339 | */ |
340 | template< class derived_type > |
341 | ScopedVclPtr( |
342 | const VclPtr< derived_type > & rRef, |
343 | typename std::enable_if< |
344 | std::is_base_of<reference_type, derived_type>::value, int>::type |
345 | = 0 ) |
346 | : VclPtr<reference_type>( rRef ) |
347 | { |
348 | } |
349 | |
350 | /** Up-casting assignment operator. |
351 | |
352 | Does not work for up-casts to ambiguous bases. |
353 | |
354 | @param rRef another VclPtr |
355 | */ |
356 | template<typename derived_type> |
357 | typename std::enable_if< |
358 | std::is_base_of<reference_type, derived_type>::value, |
359 | ScopedVclPtr &>::type |
360 | operator =(VclPtr<derived_type> const & rRef) |
361 | { |
362 | disposeAndReset(rRef.get()); |
363 | return *this; |
364 | } |
365 | |
366 | /** |
367 | * Override and disallow this, to prevent people accidentally calling it and actually |
368 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
369 | */ |
370 | template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete; |
371 | |
372 | ~ScopedVclPtr() |
373 | { |
374 | VclPtr<reference_type>::disposeAndClear(); |
375 | assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get( ) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr" , "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx" , 375, __extension__ __PRETTY_FUNCTION__)); // make sure there are no lingering references |
376 | } |
377 | |
378 | private: |
379 | // Most likely we don't want this default copy-constructor. |
380 | ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete; |
381 | // And certainly we don't want a default assignment operator. |
382 | ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete; |
383 | // And disallow reset as that doesn't call disposeAndClear on the original reference |
384 | void reset() = delete; |
385 | void reset(reference_type *pBody) = delete; |
386 | |
387 | protected: |
388 | ScopedVclPtr (reference_type * pBody, __sal_NoAcquire) |
389 | : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE) |
390 | {} |
391 | }; |
392 | |
393 | /** |
394 | * A construction helper for ScopedVclPtr. Since VclPtr types are created |
395 | * with a reference-count of one - to help fit into the existing |
396 | * code-flow; this helps us to construct them easily. |
397 | * |
398 | * For more details on the design please see vcl/README.lifecycle |
399 | * |
400 | * @param reference_type must be a subclass of vcl::Window |
401 | */ |
402 | #if defined _MSC_VER |
403 | #pragma warning(push) |
404 | #pragma warning(disable: 4521) // " multiple copy constructors specified" |
405 | #endif |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
410 | template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg) |
411 | : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE ) |
412 | { |
413 | } |
414 | |
415 | /** |
416 | * Override and disallow this, to prevent people accidentally calling it and actually |
417 | * getting VclPtr::Create and getting a naked VclPtr<> instance |
418 | */ |
419 | template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete; |
420 | |
421 | private: |
422 | // Prevent the above perfect forwarding ctor from hijacking (accidental) |
423 | // attempts at ScopedVclPtrInstance copy construction (where the hijacking |
424 | // would typically lead to somewhat obscure error messages); both non-const |
425 | // and const variants are needed here, as the ScopedVclPtr base class has a |
426 | // const--variant copy ctor, so the implicitly declared copy ctor for |
427 | // ScopedVclPtrInstance would also be the const variant, so non-const copy |
428 | // construction attempts would be hijacked by the perfect forwarding ctor; |
429 | // but if we only declared a non-const variant here, the const variant would |
430 | // no longer be implicitly declared (as there would already be an explicitly |
431 | // declared copy ctor), so const copy construction attempts would then be |
432 | // hijacked by the perfect forwarding ctor: |
433 | ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete; |
434 | ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete; |
435 | }; |
436 | #if defined _MSC_VER |
437 | #pragma warning(pop) |
438 | #endif |
439 | |
440 | #endif // INCLUDED_VCL_PTR_HXX |
441 | |
442 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody) | ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody
| ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody) | ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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_VCL_Reference_HXX |
20 | #define INCLUDED_VCL_Reference_HXX |
21 | |
22 | #include <vcl/dllapi.h> |
23 | #include <osl/interlck.h> |
24 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
32 | void acquire() const |
33 | { |
34 | osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1); |
35 | } |
36 | |
37 | void release() const |
38 | { |
39 | if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |