LibreOffice Module svx (master) 1
galctrl.cxx
Go to the documentation of this file.
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#include <config_features.h>
21
22#include <sfx2/viewfrm.hxx>
23#include <sfx2/dispatch.hxx>
24#include <sfx2/sfxsids.hrc>
26#include <helpids.h>
27#include <galbrws2.hxx>
28#include <svx/galtheme.hxx>
29#include <svx/galmisc.hxx>
30#include <svx/galctrl.hxx>
31#include <galobj.hxx>
33#include <vcl/event.hxx>
34#include <vcl/commandevent.hxx>
35#include <vcl/graphicfilter.hxx>
36#include <bitmaps.hlst>
37
38GalleryPreview::GalleryPreview(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow)
39 : mxScrolledWindow(std::move(xScrolledWindow))
40 , mpParent(pParent)
41 , mpTheme(nullptr)
42{
43}
44
46{
47 mxScrolledWindow->show();
49}
50
52{
54 mxScrolledWindow->hide();
55}
56
58{
59}
60
62{
63 CustomWidgetController::SetDrawingArea(pDrawingArea);
64 Size aSize = pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont));
65 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
66 SetOutputSizePixel(aSize);
67
68 pDrawingArea->set_help_id(HID_GALLERY_WINDOW);
69
71}
72
73namespace
74{
75 bool ImplGetGraphicCenterRect(const weld::CustomWidgetController& rWidget, const Graphic& rGraphic, tools::Rectangle& rResultRect)
76 {
77 const Size aWinSize(rWidget.GetOutputSizePixel());
78 Size aNewSize(rWidget.GetDrawingArea()->get_ref_device().LogicToPixel(rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode()));
79 bool bRet = false;
80
81 if( aNewSize.Width() && aNewSize.Height() )
82 {
83 // scale to fit window
84 const double fGrfWH = static_cast<double>(aNewSize.Width()) / aNewSize.Height();
85 const double fWinWH = static_cast<double>(aWinSize.Width()) / aWinSize.Height();
86
87 if ( fGrfWH < fWinWH )
88 {
89 aNewSize.setWidth( static_cast<tools::Long>( aWinSize.Height() * fGrfWH ) );
90 aNewSize.setHeight( aWinSize.Height() );
91 }
92 else
93 {
94 aNewSize.setWidth( aWinSize.Width() );
95 aNewSize.setHeight( static_cast<tools::Long>( aWinSize.Width() / fGrfWH) );
96 }
97
98 const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
99 ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
100
101 rResultRect = tools::Rectangle( aNewPos, aNewSize );
102 bRet = true;
103 }
104
105 return bRet;
106 }
107}
108
109bool GalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, tools::Rectangle& rResultRect ) const
110{
111 return ::ImplGetGraphicCenterRect(*this, rGraphic, rResultRect);
112}
113
114void GalleryPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
115{
117 rRenderContext.Erase();
118
120 {
121 const Point aPos( aPreviewRect.TopLeft() );
122 const Size aSize( aPreviewRect.GetSize() );
123
124 if( aGraphicObj.IsAnimated() )
125 aGraphicObj.StartAnimation(rRenderContext, aPos, aSize);
126 else
127 aGraphicObj.Draw(rRenderContext, aPos, aSize);
128 }
129}
130
132{
133 if (mpTheme && (rMEvt.GetClicks() == 2))
135 return true;
136}
137
139{
140 if (mpTheme && (rCEvt.GetCommand() == CommandEventId::ContextMenu))
141 {
143 return true;
144 }
145 return false;
146}
147
149{
150 if(mpTheme)
151 {
152 GalleryBrowser2* pBrowser = mpParent;
153
154 switch( rKEvt.GetKeyCode().GetCode() )
155 {
156 case KEY_BACKSPACE:
157 pBrowser->TogglePreview();
158 break;
159
160 case KEY_HOME:
162 break;
163
164 case KEY_END:
166 break;
167
168 case KEY_LEFT:
169 case KEY_UP:
171 break;
172
173 case KEY_RIGHT:
174 case KEY_DOWN:
176 break;
177
178 default:
179 {
180 if (!pBrowser->KeyInput(rKEvt))
181 return false;
182 }
183 break;
184 }
185
186 return true;
187 }
188 return false;
189}
190
192{
193 if (mpTheme)
194 return mpParent->StartDrag();
195 return true;
196}
197
199{
200#if HAVE_FEATURE_AVMEDIA
201 if (rURL.GetProtocol() == INetProtocol::NotValid)
202 return;
203
205
206 if (!pFloater)
207 {
208 if (SfxViewFrame* pViewFrm = SfxViewFrame::Current())
209 pViewFrm->GetBindings().GetDispatcher()->Execute( SID_AVMEDIA_PLAYER, SfxCallMode::SYNCHRON );
210 pFloater = avmedia::getMediaFloater();
211 }
212
213 if (pFloater)
215#else
216 (void) rURL;
217#endif
218}
219
221{
222}
223
225{
226 CustomWidgetController::SetDrawingArea(pDrawingArea);
227 Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont)));
228 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
229 pDrawingArea->set_help_id(HID_GALLERY_WINDOW);
230}
231
233{
234 bool bRet = true;
235 Graphic aGraphic;
236#if HAVE_FEATURE_AVMEDIA
238 {
239 aGraphic = BitmapEx(RID_SVXBMP_GALLERY_MEDIA);
240 }
241 else
242#endif
243 {
245 GalleryProgress aProgress( &rFilter );
246 if( rFilter.ImportGraphic( aGraphic, _aURL ) )
247 bRet = false;
248 }
249
250 SetGraphic( aGraphic );
251 Invalidate();
252 return bRet;
253}
254
256{
257 return ::ImplGetGraphicCenterRect(*this, rGraphic, rResultRect);
258}
259
261{
263
265 {
266 const Point aPos( aPreviewRect.TopLeft() );
267 const Size aSize( aPreviewRect.GetSize() );
268
269 if( aGraphicObj.IsAnimated() )
270 aGraphicObj.StartAnimation(rRenderContext, aPos, aSize);
271 else
272 aGraphicObj.Draw(rRenderContext, aPos, aSize);
273 }
274}
275
277{
278 // draw checkered background
279 static const sal_uInt32 nLen(8);
280 static const Color aW(COL_WHITE);
281 static const Color aG(0xef, 0xef, 0xef);
282
283 rOut.DrawCheckered(rPos, rSize, nLen, aW, aG);
284}
285
286GalleryIconView::GalleryIconView(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow)
287 : ValueSet(std::move(xScrolledWindow))
288 , mpParent(pParent)
289 , mpTheme(nullptr)
290{
291}
292
294{
295}
296
298{
299 ValueSet::SetDrawingArea(pDrawingArea);
300
302 EnableFullItemMode( false );
303
305 SetExtraSpacing( 2 );
306 SetItemWidth( S_THUMB + 6 );
307 SetItemHeight( S_THUMB + 6 );
308
310}
311
313{
314 const sal_uInt16 nId = rUDEvt.GetItemId();
315
316 if (!nId || !mpTheme)
317 return;
318
319 const tools::Rectangle& rRect = rUDEvt.GetRect();
320 const Size aSize(rRect.GetWidth(), rRect.GetHeight());
321 BitmapEx aBitmapEx;
322 Size aPreparedSize;
323 OUString aItemTextTitle;
324 OUString aItemTextPath;
325
326 mpTheme->GetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);
327
328 bool bNeedToCreate(aBitmapEx.IsEmpty());
329
330 if (!bNeedToCreate && aItemTextTitle.isEmpty())
331 {
332 bNeedToCreate = true;
333 }
334
335 if (!bNeedToCreate && aPreparedSize != aSize)
336 {
337 bNeedToCreate = true;
338 }
339
340 if (bNeedToCreate)
341 {
342 std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject(nId - 1);
343
344 if(pObj)
345 {
346 aBitmapEx = pObj->createPreviewBitmapEx(aSize);
348
349 mpTheme->SetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
350 }
351 }
352
353 if (!aBitmapEx.IsEmpty())
354 {
355 const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
356 const Point aPos(
357 ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
358 ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
359 OutputDevice* pDev = rUDEvt.GetRenderContext();
360
361 if(aBitmapEx.IsAlpha())
362 {
363 // draw checkered background for full rectangle.
365 }
366
367 pDev->DrawBitmapEx(aPos, aBitmapEx);
368 }
369
370 SetItemText(nId, aItemTextTitle);
371}
372
374{
375 bool bRet = ValueSet::MouseButtonDown(rMEvt);
376
377 if (rMEvt.GetClicks() == 2)
379
380 return bRet;
381}
382
384{
385 bool bRet = ValueSet::Command(rCEvt);
386
387 if (!bRet && rCEvt.GetCommand() == CommandEventId::ContextMenu)
388 {
389 bRet = mpParent->ShowContextMenu(rCEvt);
390 }
391
392 return bRet;
393}
394
396{
397 if (!mpTheme || !mpParent->KeyInput(rKEvt))
398 return ValueSet::KeyInput(rKEvt);
399 return true;
400}
401
403{
404 Select();
405 return mpParent->StartDrag();
406}
407
408/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsAlpha() const
bool IsEmpty() const
const Size & GetSizePixel() const
CommandEventId GetCommand() const
void SetGraphic(const Graphic &rGraphic)
Definition: galctrl.hxx:84
GraphicObject aGraphicObj
Definition: galctrl.hxx:72
tools::Rectangle aPreviewRect
Definition: galctrl.hxx:73
virtual SVX_DLLPRIVATE void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: galctrl.cxx:260
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: galctrl.cxx:224
SVX_DLLPRIVATE bool ImplGetGraphicCenterRect(const Graphic &rGraphic, tools::Rectangle &rResultRect) const
Definition: galctrl.cxx:255
void Travel(GalleryBrowserTravel eTravel)
Definition: galbrws2.cxx:727
void TogglePreview()
Definition: galbrws2.cxx:483
bool StartDrag()
Definition: galbrws2.cxx:470
bool KeyInput(const KeyEvent &rEvt)
Definition: galbrws2.cxx:522
bool ShowContextMenu(const CommandEvent &rCEvt)
Definition: galbrws2.cxx:489
static OUString GetItemText(const SgaObject &rObj, GalleryItemFlags nItemTextFlags)
Definition: galbrws2.cxx:1154
virtual void UserDraw(const UserDrawEvent &rUDEvt) override
Definition: galctrl.cxx:312
virtual bool Command(const CommandEvent &rCEvt) override
Definition: galctrl.cxx:383
GalleryIconView(GalleryBrowser2 *pParent, std::unique_ptr< weld::ScrolledWindow > xScrolledWindow)
Definition: galctrl.cxx:286
GalleryTheme * mpTheme
Definition: galctrl.hxx:94
GalleryBrowser2 * mpParent
Definition: galctrl.hxx:93
virtual bool StartDrag() override
Definition: galctrl.cxx:402
static void drawTransparenceBackground(vcl::RenderContext &rOut, const Point &rPos, const Size &rSize)
Definition: galctrl.cxx:276
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: galctrl.cxx:297
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: galctrl.cxx:395
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: galctrl.cxx:373
virtual ~GalleryIconView() override
Definition: galctrl.cxx:293
std::unique_ptr< GalleryDragDrop > mxDragDropTargetHelper
Definition: galctrl.hxx:91
virtual bool Command(const CommandEvent &rCEvt) override
Definition: galctrl.cxx:138
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: galctrl.cxx:148
virtual void Show() override
Definition: galctrl.cxx:45
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: galctrl.cxx:131
virtual bool StartDrag() override
Definition: galctrl.cxx:191
virtual void Hide() override
Definition: galctrl.cxx:51
tools::Rectangle aPreviewRect
Definition: galctrl.hxx:41
virtual ~GalleryPreview() override
Definition: galctrl.cxx:57
std::unique_ptr< weld::ScrolledWindow > mxScrolledWindow
Definition: galctrl.hxx:39
static void PreviewMedia(const INetURLObject &rURL)
Definition: galctrl.cxx:198
GalleryBrowser2 * mpParent
Definition: galctrl.hxx:42
GraphicObject aGraphicObj
Definition: galctrl.hxx:40
GalleryTheme * mpTheme
Definition: galctrl.hxx:43
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: galctrl.cxx:114
std::unique_ptr< GalleryDragDrop > mxDragDropTargetHelper
Definition: galctrl.hxx:38
bool ImplGetGraphicCenterRect(const Graphic &rGraphic, tools::Rectangle &rResultRect) const
Definition: galctrl.cxx:109
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: galctrl.cxx:61
GalleryPreview(GalleryBrowser2 *pParent, std::unique_ptr< weld::ScrolledWindow > xScrolledWindow)
Definition: galctrl.cxx:38
std::unique_ptr< SgaObject > AcquireObject(sal_uInt32 nPos)
Definition: galtheme.cxx:142
SAL_DLLPRIVATE void SetPreviewBitmapExAndStrings(sal_uInt32 nPos, const BitmapEx &rBitmapEx, const Size &rSize, const OUString &rTitle, const OUString &rPath)
Definition: galtheme.cxx:157
SAL_DLLPRIVATE void GetPreviewBitmapExAndStrings(sal_uInt32 nPos, BitmapEx &rBitmapEx, Size &rSize, OUString &rTitle, OUString &rPath)
Definition: galtheme.cxx:147
static GraphicFilter & GetGraphicFilter()
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
const Graphic & GetGraphic() const
bool IsAnimated() const
bool StartAnimation(OutputDevice &rOut, const Point &rPt, const Size &rSz, tools::Long nExtraData=0, OutputDevice *pFirstFrameOutDev=nullptr)
bool Draw(OutputDevice &rOut, const Point &rPt, const Size &rSz, const GraphicAttr *pAttr=nullptr) const
Size GetPrefSize() const
MapMode GetPrefMapMode() const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
INetProtocol GetProtocol() const
const vcl::KeyCode & GetKeyCode() const
sal_uInt16 GetClicks() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
void DrawCheckered(const Point &rPos, const Size &rSize, sal_uInt32 nLen=8, Color aStart=COL_WHITE, Color aEnd=COL_BLACK)
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
void SetBackground()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
sal_uInt16 GetItemId() const
void SetItemText(sal_uInt16 nItemId, const OUString &rStr)
void SetStyle(WinBits nStyle)
void EnableFullItemMode(bool bFullMode)
virtual void Select()
WinBits GetStyle() const
void SetItemHeight(tools::Long nLineHeight)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
virtual bool KeyInput(const KeyEvent &rKEvt) override
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void SetExtraSpacing(sal_uInt16 nNewSpacing)
void SetItemWidth(tools::Long nItemWidth)
void setURL(const OUString &rURL, const OUString &rReferer, bool bPlayImmediately)
static bool isMediaURL(std::u16string_view rURL, const OUString &rReferer, bool bDeep=false, rtl::Reference< PlayerListener > xPreferredPixelSizeListener=nullptr)
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
constexpr Point TopLeft() const
constexpr Size GetSize() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
sal_uInt16 GetCode() const
weld::DrawingArea * GetDrawingArea() const
void SetOutputSizePixel(const Size &rSize)
Size const & GetOutputSizePixel() const
virtual OutputDevice & get_ref_device()=0
virtual void set_help_id(const OUString &rName)=0
virtual css::uno::Reference< css::datatransfer::dnd::XDropTarget > get_drop_target()=0
virtual void set_size_request(int nWidth, int nHeight)=0
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
virtual void SetHelpId(const OUString &) override
RegionData_Impl * mpParent
#define GALLERY_BG_COLOR
Definition: galmisc.hxx:78
#define S_THUMB
Definition: galobj.hxx:29
constexpr OUStringLiteral HID_GALLERY_WINDOW
Definition: helpids.h:34
constexpr sal_uInt16 KEY_HOME
constexpr sal_uInt16 KEY_LEFT
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_RIGHT
constexpr sal_uInt16 KEY_DOWN
constexpr sal_uInt16 KEY_BACKSPACE
constexpr sal_uInt16 KEY_END
MediaFloater * getMediaFloater()
long Long
sal_Int16 nId
#define WB_FLATVALUESET
#define WB_ITEMBORDER
#define WB_DOUBLEBORDER
WinBits const WB_3DLOOK
WinBits const WB_BORDER
WinBits const WB_VSCROLL
WinBits const WB_TABSTOP