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 SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_AVMEDIA_PLAYER, SfxCallMode::SYNCHRON );
209 pFloater = avmedia::getMediaFloater();
210 }
211
212 if (pFloater)
214#else
215 (void) rURL;
216#endif
217}
218
220{
221}
222
224{
225 CustomWidgetController::SetDrawingArea(pDrawingArea);
226 Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(70, 88), MapMode(MapUnit::MapAppFont)));
227 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
228 pDrawingArea->set_help_id(HID_GALLERY_WINDOW);
229}
230
232{
233 bool bRet = true;
234 Graphic aGraphic;
235#if HAVE_FEATURE_AVMEDIA
237 {
238 aGraphic = BitmapEx(RID_SVXBMP_GALLERY_MEDIA);
239 }
240 else
241#endif
242 {
244 GalleryProgress aProgress( &rFilter );
245 if( rFilter.ImportGraphic( aGraphic, _aURL ) )
246 bRet = false;
247 }
248
249 SetGraphic( aGraphic );
250 Invalidate();
251 return bRet;
252}
253
255{
256 return ::ImplGetGraphicCenterRect(*this, rGraphic, rResultRect);
257}
258
260{
262
264 {
265 const Point aPos( aPreviewRect.TopLeft() );
266 const Size aSize( aPreviewRect.GetSize() );
267
268 if( aGraphicObj.IsAnimated() )
269 aGraphicObj.StartAnimation(rRenderContext, aPos, aSize);
270 else
271 aGraphicObj.Draw(rRenderContext, aPos, aSize);
272 }
273}
274
275void GalleryIconView::drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize)
276{
277 // draw checkered background
278 static const sal_uInt32 nLen(8);
279 static const Color aW(COL_WHITE);
280 static const Color aG(0xef, 0xef, 0xef);
281
282 rOut.DrawCheckered(rPos, rSize, nLen, aW, aG);
283}
284
285GalleryIconView::GalleryIconView(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow)
286 : ValueSet(std::move(xScrolledWindow))
287 , mpParent(pParent)
288 , mpTheme(nullptr)
289{
290}
291
293{
294}
295
297{
298 ValueSet::SetDrawingArea(pDrawingArea);
299
301 EnableFullItemMode( false );
302
304 SetExtraSpacing( 2 );
305 SetItemWidth( S_THUMB + 6 );
306 SetItemHeight( S_THUMB + 6 );
307
309}
310
312{
313 const sal_uInt16 nId = rUDEvt.GetItemId();
314
315 if (!nId || !mpTheme)
316 return;
317
318 const tools::Rectangle& rRect = rUDEvt.GetRect();
319 const Size aSize(rRect.GetWidth(), rRect.GetHeight());
320 BitmapEx aBitmapEx;
321 Size aPreparedSize;
322 OUString aItemTextTitle;
323 OUString aItemTextPath;
324
325 mpTheme->GetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);
326
327 bool bNeedToCreate(aBitmapEx.IsEmpty());
328
329 if (!bNeedToCreate && aItemTextTitle.isEmpty())
330 {
331 bNeedToCreate = true;
332 }
333
334 if (!bNeedToCreate && aPreparedSize != aSize)
335 {
336 bNeedToCreate = true;
337 }
338
339 if (bNeedToCreate)
340 {
341 std::unique_ptr<SgaObject> pObj = mpTheme->AcquireObject(nId - 1);
342
343 if(pObj)
344 {
345 aBitmapEx = pObj->createPreviewBitmapEx(aSize);
347
348 mpTheme->SetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
349 }
350 }
351
352 if (!aBitmapEx.IsEmpty())
353 {
354 const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
355 const Point aPos(
356 ((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
357 ((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
358 OutputDevice* pDev = rUDEvt.GetRenderContext();
359
360 if(aBitmapEx.IsAlpha())
361 {
362 // draw checkered background for full rectangle.
364 }
365
366 pDev->DrawBitmapEx(aPos, aBitmapEx);
367 }
368
369 SetItemText(nId, aItemTextTitle);
370}
371
373{
374 bool bRet = ValueSet::MouseButtonDown(rMEvt);
375
376 if (rMEvt.GetClicks() == 2)
378
379 return bRet;
380}
381
383{
384 bool bRet = ValueSet::Command(rCEvt);
385
386 if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
387 {
389 }
390
391 return bRet;
392}
393
395{
396 if (!mpTheme || !mpParent->KeyInput(rKEvt))
397 return ValueSet::KeyInput(rKEvt);
398 return true;
399}
400
402{
403 Select();
404 return mpParent->StartDrag();
405}
406
407/* 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:259
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: galctrl.cxx:223
SVX_DLLPRIVATE bool ImplGetGraphicCenterRect(const Graphic &rGraphic, tools::Rectangle &rResultRect) const
Definition: galctrl.cxx:254
void Travel(GalleryBrowserTravel eTravel)
Definition: galbrws2.cxx:726
void ShowContextMenu(const CommandEvent &rCEvt)
Definition: galbrws2.cxx:489
void TogglePreview()
Definition: galbrws2.cxx:483
bool StartDrag()
Definition: galbrws2.cxx:470
bool KeyInput(const KeyEvent &rEvt)
Definition: galbrws2.cxx:521
static OUString GetItemText(const SgaObject &rObj, GalleryItemFlags nItemTextFlags)
Definition: galbrws2.cxx:1153
virtual void UserDraw(const UserDrawEvent &rUDEvt) override
Definition: galctrl.cxx:311
virtual bool Command(const CommandEvent &rCEvt) override
Definition: galctrl.cxx:382
GalleryIconView(GalleryBrowser2 *pParent, std::unique_ptr< weld::ScrolledWindow > xScrolledWindow)
Definition: galctrl.cxx:285
GalleryTheme * mpTheme
Definition: galctrl.hxx:94
GalleryBrowser2 * mpParent
Definition: galctrl.hxx:93
virtual bool StartDrag() override
Definition: galctrl.cxx:401
static void drawTransparenceBackground(vcl::RenderContext &rOut, const Point &rPos, const Size &rSize)
Definition: galctrl.cxx:275
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
Definition: galctrl.cxx:296
virtual bool KeyInput(const KeyEvent &rKEvt) override
Definition: galctrl.cxx:394
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
Definition: galctrl.cxx:372
virtual ~GalleryIconView() override
Definition: galctrl.cxx:292
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()
SfxDispatcher * GetDispatcher() const
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
static SfxViewFrame * Current()
SfxBindings & GetBindings()
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 OString &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 OString &) override
RegionData_Impl * mpParent
#define GALLERY_BG_COLOR
Definition: galmisc.hxx:78
#define S_THUMB
Definition: galobj.hxx:29
constexpr OStringLiteral 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