1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <vcl/svapp.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/dispatch.hxx>
#include <avmedia/mediaplayer.hxx>
#include "helpid.hrc"
#include "galbrws2.hxx"
#include "svx/galtheme.hxx"
#include "svx/galmisc.hxx"
#include "svx/galctrl.hxx"
#include "editeng/AccessibleStringWrap.hxx"
#include <editeng/svxfont.hxx>
#include "galobj.hxx"
#include <avmedia/mediawindow.hxx>
#include "gallery.hrc"
#include <vcl/graphicfilter.hxx>
#include <vcl/settings.hxx>
#include <vcl/builderfactory.hxx>
#define GALLERY_BRWBOX_TITLE 1
GalleryPreview::GalleryPreview(vcl::Window* pParent, WinBits nStyle, GalleryTheme* pTheme)
: Window(pParent, nStyle)
, DropTargetHelper(this)
, DragSourceHelper(this)
, mpTheme(pTheme)
{
SetHelpId( HID_GALLERY_WINDOW );
InitSettings();
}
VCL_BUILDER_FACTORY_CONSTRUCTOR(GalleryPreview, WB_TABSTOP)
Size GalleryPreview::GetOptimalSize() const
{
return LogicToPixel(Size(70, 88), MapUnit::MapAppFont);
}
bool GalleryPreview::SetGraphic( const INetURLObject& _aURL )
{
bool bRet = true;
Graphic aGraphic;
if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ), "" ) )
{
aGraphic = BitmapEx( GAL_RES( RID_SVXBMP_GALLERY_MEDIA ) );
}
else
{
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
GalleryProgress aProgress( &rFilter );
if( rFilter.ImportGraphic( aGraphic, _aURL ) )
bRet = false;
}
SetGraphic( aGraphic );
Invalidate();
return bRet;
}
void GalleryPreview::InitSettings()
{
SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
SetControlBackground( GALLERY_BG_COLOR );
SetControlForeground( GALLERY_FG_COLOR );
}
void GalleryPreview::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
InitSettings();
else
Window::DataChanged( rDCEvt );
}
bool GalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
{
const Size aWinSize( GetOutputSizePixel() );
Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
bool bRet = false;
if( aNewSize.Width() && aNewSize.Height() )
{
// scale to fit window
const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
if ( fGrfWH < fWinWH )
{
aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
aNewSize.Height()= aWinSize.Height();
}
else
{
aNewSize.Width() = aWinSize.Width();
aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
}
const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
( aWinSize.Height() - aNewSize.Height() ) >> 1 );
rResultRect = Rectangle( aNewPos, aNewSize );
bRet = true;
}
return bRet;
}
void GalleryPreview::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
{
Window::Paint(rRenderContext, rRect);
if (ImplGetGraphicCenterRect(aGraphicObj.GetGraphic(), aPreviewRect))
{
const Point aPos( aPreviewRect.TopLeft() );
const Size aSize( aPreviewRect.GetSize() );
if( aGraphicObj.IsAnimated() )
aGraphicObj.StartAnimation(&rRenderContext, aPos, aSize);
else
aGraphicObj.Draw(&rRenderContext, aPos, aSize);
}
}
void GalleryPreview::MouseButtonDown(const MouseEvent& rMEvt)
{
if (mpTheme && (rMEvt.GetClicks() == 2))
static_cast<GalleryBrowser2*>(GetParent())->TogglePreview(this);
}
void GalleryPreview::Command(const CommandEvent& rCEvt)
{
Window::Command(rCEvt);
if (mpTheme && (rCEvt.GetCommand() == CommandEventId::ContextMenu))
{
GalleryBrowser2* pGalleryBrowser = static_cast<GalleryBrowser2*>(GetParent());
pGalleryBrowser->ShowContextMenu(this, (rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : nullptr));
}
}
void GalleryPreview::KeyInput(const KeyEvent& rKEvt)
{
if(mpTheme)
{
GalleryBrowser2* pBrowser = static_cast< GalleryBrowser2* >( GetParent() );
switch( rKEvt.GetKeyCode().GetCode() )
{
case KEY_BACKSPACE:
pBrowser->TogglePreview( this );
break;
case KEY_HOME:
pBrowser->Travel( GALLERYBROWSERTRAVEL_FIRST );
break;
case KEY_END:
pBrowser->Travel( GALLERYBROWSERTRAVEL_LAST );
break;
case KEY_LEFT:
case KEY_UP:
pBrowser->Travel( GALLERYBROWSERTRAVEL_PREVIOUS );
break;
case KEY_RIGHT:
case KEY_DOWN:
pBrowser->Travel( GALLERYBROWSERTRAVEL_NEXT );
break;
default:
{
if (!pBrowser->KeyInput(rKEvt, this))
Window::KeyInput(rKEvt);
}
break;
}
}
else
{
Window::KeyInput(rKEvt);
}
}
sal_Int8 GalleryPreview::AcceptDrop( const AcceptDropEvent& rEvt )
{
sal_Int8 nRet;
if (mpTheme)
nRet = static_cast<GalleryBrowser2*>(GetParent())->AcceptDrop(*this, rEvt);
else
nRet = DND_ACTION_NONE;
return nRet;
}
sal_Int8 GalleryPreview::ExecuteDrop( const ExecuteDropEvent& rEvt )
{
sal_Int8 nRet;
if (mpTheme)
nRet = static_cast<GalleryBrowser2*>(GetParent())->ExecuteDrop(*this, rEvt);
else
nRet = DND_ACTION_NONE;
return nRet;
}
void GalleryPreview::StartDrag( sal_Int8, const Point& )
{
if(mpTheme)
static_cast<GalleryBrowser2*>(GetParent())->StartDrag(this);
}
void GalleryPreview::PreviewMedia( const INetURLObject& rURL )
{
if (rURL.GetProtocol() != INetProtocol::NotValid)
{
::avmedia::MediaFloater* pFloater = avmedia::getMediaFloater();
if (!pFloater)
{
SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_AVMEDIA_PLAYER, SfxCallMode::SYNCHRON );
pFloater = avmedia::getMediaFloater();
}
if (pFloater)
pFloater->setURL( rURL.GetMainURL( INetURLObject::DecodeMechanism::Unambiguous ), "", true );
}
}
void drawTransparenceBackground(vcl::RenderContext& rOut, const Point& rPos, const Size& rSize)
{
// draw checkered background
static const sal_uInt32 nLen(8);
static const Color aW(COL_WHITE);
static const Color aG(0xef, 0xef, 0xef);
rOut.DrawCheckered(rPos, rSize, nLen, aW, aG);
}
GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
ValueSet( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET ),
DropTargetHelper( this ),
DragSourceHelper( this ),
mpTheme ( pTheme )
{
EnableFullItemMode( false );
SetHelpId( HID_GALLERY_WINDOW );
InitSettings();
SetExtraSpacing( 2 );
SetItemWidth( S_THUMB + 6 );
SetItemHeight( S_THUMB + 6 );
}
void GalleryIconView::InitSettings()
{
SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
SetControlBackground( GALLERY_BG_COLOR );
SetControlForeground( GALLERY_FG_COLOR );
SetColor( GALLERY_BG_COLOR );
}
void GalleryIconView::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
InitSettings();
else
ValueSet::DataChanged( rDCEvt );
}
void GalleryIconView::UserDraw(const UserDrawEvent& rUDEvt)
{
const sal_uInt16 nId = rUDEvt.GetItemId();
if (nId && mpTheme)
{
const Rectangle& rRect = rUDEvt.GetRect();
const Size aSize(rRect.GetWidth(), rRect.GetHeight());
BitmapEx aBitmapEx;
Size aPreparedSize;
OUString aItemTextTitle;
OUString aItemTextPath;
mpTheme->GetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);
bool bNeedToCreate(aBitmapEx.IsEmpty());
if (!bNeedToCreate && aItemTextTitle.isEmpty())
{
bNeedToCreate = true;
}
if (!bNeedToCreate && aPreparedSize != aSize)
{
bNeedToCreate = true;
}
if (bNeedToCreate)
{
SgaObject* pObj = mpTheme->AcquireObject(nId - 1);
if(pObj)
{
aBitmapEx = pObj->createPreviewBitmapEx(aSize);
aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GalleryItemFlags::Title);
mpTheme->SetPreviewBitmapExAndStrings(nId - 1, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
GalleryTheme::ReleaseObject(pObj);
}
}
if (!aBitmapEx.IsEmpty())
{
const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
const Point aPos(
((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
OutputDevice* pDev = rUDEvt.GetRenderContext();
if(aBitmapEx.IsTransparent())
{
// draw checkered background for full rectangle.
drawTransparenceBackground(*pDev, rRect.TopLeft(), rRect.GetSize());
}
pDev->DrawBitmapEx(aPos, aBitmapEx);
}
SetItemText(nId, aItemTextTitle);
}
}
void GalleryIconView::MouseButtonDown(const MouseEvent& rMEvt)
{
ValueSet::MouseButtonDown(rMEvt);
if (rMEvt.GetClicks() == 2)
static_cast<GalleryBrowser2*>(GetParent())->TogglePreview(this, &rMEvt.GetPosPixel());
}
void GalleryIconView::Command(const CommandEvent& rCEvt)
{
ValueSet::Command(rCEvt);
if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
{
GalleryBrowser2* pGalleryBrowser = static_cast<GalleryBrowser2*>(GetParent());
pGalleryBrowser->ShowContextMenu(this, (rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : nullptr));
}
}
void GalleryIconView::KeyInput(const KeyEvent& rKEvt)
{
if (!mpTheme || !static_cast<GalleryBrowser2*>(GetParent())->KeyInput(rKEvt, this))
ValueSet::KeyInput(rKEvt);
}
sal_Int8 GalleryIconView::AcceptDrop(const AcceptDropEvent& rEvt)
{
return(static_cast<GalleryBrowser2*>(GetParent())->AcceptDrop(*this, rEvt));
}
sal_Int8 GalleryIconView::ExecuteDrop(const ExecuteDropEvent& rEvt)
{
return(static_cast<GalleryBrowser2*>(GetParent())->ExecuteDrop(*this, rEvt));
}
void GalleryIconView::StartDrag(sal_Int8, const Point&)
{
const CommandEvent aEvt(GetPointerPosPixel(), CommandEventId::StartDrag, true);
vcl::Region aRegion;
// call this to initiate dragging for ValueSet
ValueSet::StartDrag(aEvt, aRegion);
static_cast<GalleryBrowser2*>(GetParent())->StartDrag(this);
}
GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ),
mpTheme( pTheme ),
mnCurRow( 0 )
{
SetHelpId( HID_GALLERY_WINDOW );
InitSettings();
SetMode( BrowserMode::AUTO_VSCROLL | BrowserMode::AUTOSIZE_LASTCOL | BrowserMode::AUTO_HSCROLL );
SetDataRowHeight( 28 );
InsertDataColumn( GALLERY_BRWBOX_TITLE, GAL_RESSTR(RID_SVXSTR_GALLERY_TITLE), 256 );
}
void GalleryListView::InitSettings()
{
SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
SetControlBackground( GALLERY_BG_COLOR );
SetControlForeground( GALLERY_FG_COLOR );
}
void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
InitSettings();
else
BrowseBox::DataChanged( rDCEvt );
}
bool GalleryListView::SeekRow( long nRow )
{
mnCurRow = nRow;
return true;
}
OUString GalleryListView::GetCellText(long _nRow, sal_uInt16 /*nColumnId*/) const
{
OUString sRet;
if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) )
{
SgaObject* pObj = mpTheme->AcquireObject( _nRow );
if( pObj )
{
sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj, GalleryItemFlags::Title );
GalleryTheme::ReleaseObject( pObj );
}
}
return sRet;
}
Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex)
{
DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow");
Rectangle aRect;
if ( SeekRow(_nRow) )
{
SvxFont aFont( GetFont() );
AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) );
// get the bounds inside the string
aStringWrap.GetCharacterBounds(nIndex, aRect);
// offset to
}
return aRect;
}
sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
{
DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow");
sal_Int32 nRet = -1;
if ( SeekRow(_nRow) )
{
SvxFont aFont( GetFont() );
AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) );
nRet = aStringWrap.GetIndexAtPoint(_rPoint);
}
return nRet;
}
void GalleryListView::PaintField(vcl::RenderContext& rDev, const Rectangle& rRect, sal_uInt16 /*nColumnId*/) const
{
rDev.Push( PushFlags::CLIPREGION );
rDev.IntersectClipRegion( rRect );
if( mpTheme && ( static_cast<size_t>(mnCurRow) < mpTheme->GetObjectCount() ) )
{
const Size aSize(rRect.GetHeight(), rRect.GetHeight());
BitmapEx aBitmapEx;
Size aPreparedSize;
OUString aItemTextTitle;
OUString aItemTextPath;
mpTheme->GetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aPreparedSize, aItemTextTitle, aItemTextPath);
bool bNeedToCreate(aBitmapEx.IsEmpty());
if(!bNeedToCreate && (aItemTextTitle.isEmpty() || aPreparedSize != aSize))
bNeedToCreate = true;
if(bNeedToCreate)
{
SgaObject* pObj = mpTheme->AcquireObject(mnCurRow);
if(pObj)
{
aBitmapEx = pObj->createPreviewBitmapEx(aSize);
aItemTextTitle = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GalleryItemFlags::Title);
aItemTextPath = GalleryBrowser2::GetItemText(*mpTheme, *pObj, GalleryItemFlags::Path);
mpTheme->SetPreviewBitmapExAndStrings(mnCurRow, aBitmapEx, aSize, aItemTextTitle, aItemTextPath);
GalleryTheme::ReleaseObject(pObj);
}
}
const long nTextPosY(rRect.Top() + ((rRect.GetHeight() - rDev.GetTextHeight()) >> 1));
if(!aBitmapEx.IsEmpty())
{
const Size aBitmapExSizePixel(aBitmapEx.GetSizePixel());
const Point aPos(
((aSize.Width() - aBitmapExSizePixel.Width()) >> 1) + rRect.Left(),
((aSize.Height() - aBitmapExSizePixel.Height()) >> 1) + rRect.Top());
if(aBitmapEx.IsTransparent())
{
// draw checkered background
drawTransparenceBackground(rDev, aPos, aBitmapExSizePixel);
}
rDev.DrawBitmapEx(aPos, aBitmapEx);
}
rDev.DrawText(Point(rRect.Left() + rRect.GetHeight() + 6, nTextPosY), aItemTextTitle);
}
rDev.Pop();
}
void GalleryListView::Command( const CommandEvent& rCEvt )
{
BrowseBox::Command( rCEvt );
if( rCEvt.GetCommand() == CommandEventId::ContextMenu )
{
const Point* pPos = nullptr;
if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) )
pPos = &rCEvt.GetMousePosPixel();
static_cast<GalleryBrowser2*>( GetParent() )->ShowContextMenu( this, pPos );
}
}
void GalleryListView::KeyInput( const KeyEvent& rKEvt )
{
if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
BrowseBox::KeyInput( rKEvt );
}
void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt )
{
BrowseBox::DoubleClick( rEvt );
if( rEvt.GetRow() != BROWSER_ENDOFSELECTION )
static_cast<GalleryBrowser2*>( GetParent() )->TogglePreview( this, &rEvt.GetPosPixel() );
}
void GalleryListView::Select()
{
maSelectHdl.Call( this );
}
sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& )
{
sal_Int8 nRet = DND_ACTION_NONE;
if( mpTheme && !mpTheme->IsReadOnly() )
nRet = DND_ACTION_COPY;
return nRet;
}
sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
{
ExecuteDropEvent aEvt( rEvt );
aEvt.maPosPixel.Y() += GetTitleHeight();
return( static_cast<GalleryBrowser2*>( GetParent() )->ExecuteDrop( *this, aEvt ) );
}
void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel )
{
static_cast<GalleryBrowser2*>( GetParent() )->StartDrag( this, &rPosPixel );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|