Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <vcl/svapp.hxx>
31 : : #include <sfx2/viewfrm.hxx>
32 : : #include <sfx2/dispatch.hxx>
33 : : #include <avmedia/mediaplayer.hxx>
34 : : #include "helpid.hrc"
35 : : #include "galbrws2.hxx"
36 : : #include "svx/galtheme.hxx"
37 : : #include "svx/galmisc.hxx"
38 : : #include "svx/galctrl.hxx"
39 : : #include "editeng/AccessibleStringWrap.hxx"
40 : : #include <editeng/svxfont.hxx>
41 : : #include "galobj.hxx"
42 : : #include <avmedia/mediawindow.hxx>
43 : : #include "gallery.hrc"
44 : : #include <svtools/filter.hxx>
45 : :
46 : : // -----------
47 : : // - Defines -
48 : : // -----------
49 : :
50 : : #define GALLERY_BRWBOX_TITLE 1
51 : : #define GALLERY_BRWBOX_PATH 2
52 : :
53 : : // ------------------
54 : : // - GalleryPreview -
55 : : // ------------------
56 : :
57 : 0 : GalleryPreview::GalleryPreview( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
58 : : Window( pParent, WB_TABSTOP | WB_BORDER ),
59 : : DropTargetHelper( this ),
60 : : DragSourceHelper( this ),
61 [ # # ][ # # ]: 0 : mpTheme( pTheme )
[ # # ][ # # ]
62 : : {
63 [ # # ]: 0 : SetHelpId( HID_GALLERY_WINDOW );
64 [ # # ]: 0 : InitSettings();
65 : 0 : }
66 : :
67 : : // ------------------------------------------------------------------------
68 : :
69 : 0 : GalleryPreview::GalleryPreview( Window* pParent, const ResId & rResId ) :
70 : : Window( pParent, rResId ),
71 : : DropTargetHelper( this ),
72 : : DragSourceHelper( this ),
73 [ # # ][ # # ]: 0 : mpTheme( NULL )
[ # # ][ # # ]
74 : : {
75 [ # # ]: 0 : SetHelpId( HID_GALLERY_PREVIEW );
76 [ # # ]: 0 : InitSettings();
77 : 0 : }
78 : :
79 : : // ------------------------------------------------------------------------
80 : :
81 [ # # ][ # # ]: 0 : GalleryPreview::~GalleryPreview()
[ # # ]
82 : : {
83 [ # # ]: 0 : }
84 : :
85 : :
86 : 0 : bool GalleryPreview::SetGraphic( const INetURLObject& _aURL )
87 : : {
88 : 0 : bool bRet = true;
89 [ # # ]: 0 : Graphic aGraphic;
90 [ # # ][ # # ]: 0 : if( ::avmedia::MediaWindow::isMediaURL( _aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
[ # # ]
91 : : {
92 [ # # ][ # # ]: 0 : aGraphic = BitmapEx( GAL_RES( RID_SVXBMP_GALLERY_MEDIA ) );
[ # # ][ # # ]
[ # # ][ # # ]
93 : : }
94 : : else
95 : : {
96 [ # # ]: 0 : GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
97 [ # # ]: 0 : GalleryProgress aProgress( &rFilter );
98 [ # # ][ # # ]: 0 : if( rFilter.ImportGraphic( aGraphic, _aURL, GRFILTER_FORMAT_DONTKNOW ) )
99 [ # # ]: 0 : bRet = false;
100 : : }
101 : :
102 [ # # ]: 0 : SetGraphic( aGraphic );
103 [ # # ]: 0 : Invalidate();
104 [ # # ]: 0 : return bRet;
105 : : }
106 : :
107 : : // ------------------------------------------------------------------------
108 : :
109 : 0 : void GalleryPreview::InitSettings()
110 : : {
111 [ # # ]: 0 : SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
112 : 0 : SetControlBackground( GALLERY_BG_COLOR );
113 : 0 : SetControlForeground( GALLERY_FG_COLOR );
114 : 0 : }
115 : :
116 : : // -----------------------------------------------------------------------
117 : :
118 : 0 : void GalleryPreview::DataChanged( const DataChangedEvent& rDCEvt )
119 : : {
120 [ # # ][ # # ]: 0 : if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
[ # # ]
121 : 0 : InitSettings();
122 : : else
123 : 0 : Window::DataChanged( rDCEvt );
124 : 0 : }
125 : :
126 : : // ------------------------------------------------------------------------
127 : :
128 : 0 : sal_Bool GalleryPreview::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
129 : : {
130 : 0 : const Size aWinSize( GetOutputSizePixel() );
131 [ # # ][ # # ]: 0 : Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
[ # # ][ # # ]
132 : 0 : sal_Bool bRet = sal_False;
133 : :
134 [ # # ][ # # ]: 0 : if( aNewSize.Width() && aNewSize.Height() )
[ # # ]
135 : : {
136 : : // scale to fit window
137 : 0 : const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
138 : 0 : const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
139 : :
140 [ # # ]: 0 : if ( fGrfWH < fWinWH )
141 : : {
142 : 0 : aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
143 : 0 : aNewSize.Height()= aWinSize.Height();
144 : : }
145 : : else
146 : : {
147 : 0 : aNewSize.Width() = aWinSize.Width();
148 : 0 : aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
149 : : }
150 : :
151 : 0 : const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
152 : 0 : ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
153 : :
154 [ # # ]: 0 : rResultRect = Rectangle( aNewPos, aNewSize );
155 : 0 : bRet = sal_True;
156 : : }
157 : :
158 : 0 : return bRet;
159 : : }
160 : :
161 : : // ------------------------------------------------------------------------
162 : :
163 : 0 : void GalleryPreview::Paint( const Rectangle& rRect )
164 : : {
165 : 0 : Window::Paint( rRect );
166 : :
167 [ # # ]: 0 : if( ImplGetGraphicCenterRect( aGraphicObj.GetGraphic(), aPreviewRect ) )
168 : : {
169 : 0 : const Point aPos( aPreviewRect.TopLeft() );
170 [ # # ]: 0 : const Size aSize( aPreviewRect.GetSize() );
171 : :
172 [ # # ]: 0 : if( aGraphicObj.IsAnimated() )
173 [ # # ]: 0 : aGraphicObj.StartAnimation( this, aPos, aSize );
174 : : else
175 [ # # ]: 0 : aGraphicObj.Draw( this, aPos, aSize );
176 : : }
177 : 0 : }
178 : :
179 : : // ------------------------------------------------------------------------
180 : :
181 : 0 : void GalleryPreview::MouseButtonDown( const MouseEvent& rMEvt )
182 : : {
183 [ # # ][ # # ]: 0 : if( mpTheme && ( rMEvt.GetClicks() == 2 ) )
[ # # ]
184 : 0 : ( (GalleryBrowser2*) GetParent() )->TogglePreview( this );
185 : 0 : }
186 : :
187 : : // ------------------------------------------------------------------------
188 : :
189 : 0 : void GalleryPreview::Command(const CommandEvent& rCEvt )
190 : : {
191 : 0 : Window::Command( rCEvt );
192 : :
193 [ # # ][ # # ]: 0 : if( mpTheme && ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) )
[ # # ]
194 : 0 : ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this,
195 [ # # ]: 0 : ( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) );
196 : 0 : }
197 : :
198 : : // ------------------------------------------------------------------------
199 : :
200 : 0 : void GalleryPreview::KeyInput( const KeyEvent& rKEvt )
201 : : {
202 [ # # ]: 0 : if( mpTheme )
203 : : {
204 : 0 : GalleryBrowser2* pBrowser = static_cast< GalleryBrowser2* >( GetParent() );
205 : :
206 [ # # # # : 0 : switch( rKEvt.GetKeyCode().GetCode() )
# # ]
207 : : {
208 : : case( KEY_BACKSPACE ):
209 : 0 : pBrowser->TogglePreview( this );
210 : 0 : break;
211 : :
212 : : case( KEY_HOME ):
213 : 0 : pBrowser->Travel( GALLERYBROWSERTRAVEL_FIRST );
214 : 0 : break;
215 : :
216 : : case( KEY_END ):
217 : 0 : pBrowser->Travel( GALLERYBROWSERTRAVEL_LAST );
218 : 0 : break;
219 : :
220 : : case( KEY_LEFT ):
221 : : case( KEY_UP ):
222 : 0 : pBrowser->Travel( GALLERYBROWSERTRAVEL_PREVIOUS );
223 : 0 : break;
224 : :
225 : : case( KEY_RIGHT ):
226 : : case( KEY_DOWN ):
227 : 0 : pBrowser->Travel( GALLERYBROWSERTRAVEL_NEXT );
228 : 0 : break;
229 : :
230 : : default:
231 : : {
232 [ # # ]: 0 : if( !pBrowser->KeyInput( rKEvt, this ) )
233 : 0 : Window::KeyInput( rKEvt );
234 : : }
235 : 0 : break;
236 : : }
237 : : }
238 : : else
239 : 0 : Window::KeyInput( rKEvt );
240 : 0 : }
241 : :
242 : : // ------------------------------------------------------------------------
243 : :
244 : 0 : sal_Int8 GalleryPreview::AcceptDrop( const AcceptDropEvent& rEvt )
245 : : {
246 : : sal_Int8 nRet;
247 : :
248 [ # # ]: 0 : if( mpTheme )
249 : 0 : nRet = ( (GalleryBrowser2*) GetParent() )->AcceptDrop( *this, rEvt );
250 : : else
251 : 0 : nRet = DND_ACTION_NONE;
252 : :
253 : 0 : return nRet;
254 : : }
255 : :
256 : : // ------------------------------------------------------------------------
257 : :
258 : 0 : sal_Int8 GalleryPreview::ExecuteDrop( const ExecuteDropEvent& rEvt )
259 : : {
260 : : sal_Int8 nRet;
261 : :
262 [ # # ]: 0 : if( mpTheme )
263 : 0 : nRet = ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, rEvt );
264 : : else
265 : 0 : nRet = DND_ACTION_NONE;
266 : :
267 : 0 : return nRet;
268 : : }
269 : :
270 : : // ------------------------------------------------------------------------
271 : :
272 : 0 : void GalleryPreview::StartDrag( sal_Int8, const Point& )
273 : : {
274 [ # # ]: 0 : if( mpTheme )
275 : 0 : ( (GalleryBrowser2*) GetParent() )->StartDrag( this );
276 : 0 : }
277 : :
278 : : // ------------------------------------------------------------------------
279 : :
280 : 0 : void GalleryPreview::PreviewMedia( const INetURLObject& rURL )
281 : : {
282 [ # # ]: 0 : if( rURL.GetProtocol() != INET_PROT_NOT_VALID )
283 : : {
284 [ # # ][ # # ]: 0 : ::avmedia::MediaFloater* pFloater = AVMEDIA_MEDIAWINDOW();
285 : :
286 [ # # ]: 0 : if( !pFloater )
287 : : {
288 : 0 : SfxViewFrame::Current()->GetBindings().GetDispatcher()->Execute( SID_AVMEDIA_PLAYER, SFX_CALLMODE_SYNCHRON );
289 [ # # ][ # # ]: 0 : pFloater = AVMEDIA_MEDIAWINDOW();
290 : : }
291 : :
292 [ # # ]: 0 : if( pFloater )
293 [ # # ]: 0 : pFloater->setURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ), true );
294 : : }
295 : 0 : }
296 : :
297 : : // ------------------------------------------------------------------------
298 : :
299 : : // -------------------
300 : : // - GalleryIconView -
301 : : // -------------------
302 : :
303 : 0 : GalleryIconView::GalleryIconView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
304 : : ValueSet( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER | WB_ITEMBORDER | WB_DOUBLEBORDER | WB_VSCROLL | WB_FLATVALUESET ),
305 : : DropTargetHelper( this ),
306 : : DragSourceHelper( this ),
307 [ # # ][ # # ]: 0 : mpTheme ( pTheme )
308 : : {
309 [ # # ]: 0 : EnableFullItemMode( sal_False );
310 : :
311 [ # # ]: 0 : SetHelpId( HID_GALLERY_WINDOW );
312 [ # # ]: 0 : InitSettings();
313 [ # # ]: 0 : SetExtraSpacing( 2 );
314 [ # # ]: 0 : SetItemWidth( S_THUMB + 6 );
315 [ # # ]: 0 : SetItemHeight( S_THUMB + 6 );
316 : 0 : }
317 : :
318 : : // ------------------------------------------------------------------------
319 : :
320 [ # # ][ # # ]: 0 : GalleryIconView::~GalleryIconView()
321 : : {
322 [ # # ]: 0 : }
323 : :
324 : : // ------------------------------------------------------------------------
325 : :
326 : 0 : void GalleryIconView::InitSettings()
327 : : {
328 [ # # ]: 0 : SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
329 : 0 : SetControlBackground( GALLERY_BG_COLOR );
330 : 0 : SetControlForeground( GALLERY_FG_COLOR );
331 : 0 : SetColor( GALLERY_BG_COLOR );
332 : 0 : }
333 : :
334 : : // -----------------------------------------------------------------------
335 : :
336 : 0 : void GalleryIconView::DataChanged( const DataChangedEvent& rDCEvt )
337 : : {
338 [ # # ][ # # ]: 0 : if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
[ # # ]
339 : 0 : InitSettings();
340 : : else
341 : 0 : ValueSet::DataChanged( rDCEvt );
342 : 0 : }
343 : :
344 : : // ------------------------------------------------------------------------
345 : :
346 : 0 : void GalleryIconView::UserDraw( const UserDrawEvent& rUDEvt )
347 : : {
348 : 0 : const sal_uInt16 nId = rUDEvt.GetItemId();
349 : :
350 [ # # ][ # # ]: 0 : if( nId && mpTheme )
351 : : {
352 : 0 : SgaObject* pObj = mpTheme->AcquireObject( nId - 1 );
353 : :
354 [ # # ]: 0 : if( pObj )
355 : : {
356 : 0 : const Rectangle& rRect = rUDEvt.GetRect();
357 : 0 : OutputDevice* pDev = rUDEvt.GetDevice();
358 [ # # ]: 0 : Graphic aGraphic;
359 : :
360 [ # # ]: 0 : if( pObj->IsThumbBitmap() )
361 : : {
362 [ # # ]: 0 : Bitmap aBmp( pObj->GetThumbBmp() );
363 : :
364 [ # # ][ # # ]: 0 : if( pObj->GetObjKind() == SGA_OBJ_SOUND )
365 [ # # ]: 0 : aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
366 : :
367 [ # # ][ # # ]: 0 : if( ( pDev->GetBitCount() <= 8 ) && ( aBmp.GetBitCount() >= 8 ) )
[ # # ][ # # ]
[ # # ]
368 [ # # ]: 0 : aBmp.Dither( BMP_DITHER_FLOYD );
369 : :
370 [ # # ][ # # ]: 0 : aGraphic = aBmp;
[ # # ][ # # ]
371 : : }
372 : : else
373 [ # # ][ # # ]: 0 : aGraphic = pObj->GetThumbMtf();
[ # # ]
374 : :
375 [ # # ]: 0 : Size aSize( aGraphic.GetSizePixel( pDev ) );
376 : :
377 [ # # ][ # # ]: 0 : if ( aSize.Width() && aSize.Height() )
[ # # ]
378 : : {
379 [ # # ][ # # ]: 0 : if( ( aSize.Width() > rRect.GetWidth() ) || ( aSize.Height() > rRect.GetHeight() ) )
[ # # ][ # # ]
[ # # ]
380 : : {
381 : 0 : Point aNewPos;
382 : 0 : const double fBmpWH = (double) aSize.Width() / aSize.Height();
383 [ # # ][ # # ]: 0 : const double fThmpWH = (double) rRect.GetWidth() / rRect.GetHeight();
384 : :
385 : : // Bitmap an Thumbgroesse anpassen
386 [ # # ]: 0 : if ( fBmpWH < fThmpWH )
387 : : {
388 [ # # ]: 0 : aSize.Width() = (long) ( rRect.GetHeight() * fBmpWH );
389 [ # # ]: 0 : aSize.Height()= rRect.GetHeight();
390 : : }
391 : : else
392 : : {
393 [ # # ]: 0 : aSize.Width() = rRect.GetWidth();
394 [ # # ]: 0 : aSize.Height()= (long) ( rRect.GetWidth() / fBmpWH );
395 : : }
396 : : }
397 : :
398 [ # # ]: 0 : const Point aPos( ( ( rRect.GetWidth() - aSize.Width() ) >> 1 ) + rRect.Left(),
399 [ # # ]: 0 : ( ( rRect.GetHeight() - aSize.Height() ) >> 1 ) + rRect.Top() );
400 : :
401 [ # # ]: 0 : aGraphic.Draw( pDev, aPos, aSize );
402 : : }
403 : :
404 [ # # ][ # # ]: 0 : SetItemText( nId, GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE) );
[ # # ]
405 [ # # ][ # # ]: 0 : mpTheme->ReleaseObject( pObj );
406 : : }
407 : : }
408 : 0 : }
409 : :
410 : : // ------------------------------------------------------------------------
411 : :
412 : 0 : void GalleryIconView::MouseButtonDown( const MouseEvent& rMEvt )
413 : : {
414 : 0 : ValueSet::MouseButtonDown( rMEvt );
415 : :
416 [ # # ]: 0 : if( rMEvt.GetClicks() == 2 )
417 : 0 : ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rMEvt.GetPosPixel() );
418 : 0 : }
419 : :
420 : : // ------------------------------------------------------------------------
421 : :
422 : 0 : void GalleryIconView::Command( const CommandEvent& rCEvt )
423 : : {
424 : 0 : ValueSet::Command( rCEvt );
425 : :
426 [ # # ]: 0 : if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
427 : : {
428 : 0 : ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this,
429 [ # # ]: 0 : ( rCEvt.IsMouseEvent() ? &rCEvt.GetMousePosPixel() : NULL ) );
430 : : }
431 : 0 : }
432 : :
433 : : // ------------------------------------------------------------------------
434 : :
435 : 0 : void GalleryIconView::KeyInput( const KeyEvent& rKEvt )
436 : : {
437 [ # # ][ # # ]: 0 : if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
[ # # ]
438 : 0 : ValueSet::KeyInput( rKEvt );
439 : 0 : }
440 : :
441 : : // ------------------------------------------------------------------------
442 : :
443 : 0 : sal_Int8 GalleryIconView::AcceptDrop( const AcceptDropEvent& rEvt )
444 : : {
445 : 0 : return( static_cast< GalleryBrowser2* >( GetParent() )->AcceptDrop( *this, rEvt ) );
446 : : }
447 : :
448 : : // ------------------------------------------------------------------------
449 : :
450 : 0 : sal_Int8 GalleryIconView::ExecuteDrop( const ExecuteDropEvent& rEvt )
451 : : {
452 : 0 : return( static_cast< GalleryBrowser2* >( GetParent() )->ExecuteDrop( *this, rEvt ) );
453 : : }
454 : :
455 : : // ------------------------------------------------------------------------
456 : :
457 : 0 : void GalleryIconView::StartDrag( sal_Int8, const Point& )
458 : : {
459 [ # # ][ # # ]: 0 : const CommandEvent aEvt( GetPointerPosPixel(), COMMAND_STARTDRAG, sal_True );
460 [ # # ]: 0 : Region aRegion;
461 : :
462 : : // call this to initiate dragging for ValueSet
463 [ # # ]: 0 : ValueSet::StartDrag( aEvt, aRegion );
464 [ # # ][ # # ]: 0 : static_cast< GalleryBrowser2* >( GetParent() )->StartDrag( this );
[ # # ]
465 : 0 : }
466 : :
467 : : // -------------------
468 : : // - GalleryListView -
469 : : // -------------------
470 : :
471 : 0 : GalleryListView::GalleryListView( GalleryBrowser2* pParent, GalleryTheme* pTheme ) :
472 : : BrowseBox( pParent, WB_TABSTOP | WB_3DLOOK | WB_BORDER ),
473 : : mpTheme( pTheme ),
474 [ # # ]: 0 : mnCurRow( 0 )
475 : : {
476 [ # # ]: 0 : SetHelpId( HID_GALLERY_WINDOW );
477 : :
478 [ # # ]: 0 : InitSettings();
479 : :
480 [ # # ]: 0 : SetMode( BROWSER_AUTO_VSCROLL | BROWSER_AUTOSIZE_LASTCOL );
481 [ # # ]: 0 : SetDataRowHeight( 28 );
482 [ # # ][ # # ]: 0 : InsertDataColumn( GALLERY_BRWBOX_TITLE, GAL_RESSTR(RID_SVXSTR_GALLERY_TITLE), 256 );
[ # # ][ # # ]
[ # # ]
483 [ # # ][ # # ]: 0 : InsertDataColumn( GALLERY_BRWBOX_PATH, GAL_RESSTR(RID_SVXSTR_GALLERY_PATH), 256 );
[ # # ][ # # ]
[ # # ]
484 : 0 : }
485 : :
486 : : // ------------------------------------------------------------------------
487 : :
488 : 0 : GalleryListView::~GalleryListView()
489 : : {
490 [ # # ]: 0 : }
491 : :
492 : : // ------------------------------------------------------------------------
493 : :
494 : 0 : void GalleryListView::InitSettings()
495 : : {
496 [ # # ]: 0 : SetBackground( Wallpaper( GALLERY_BG_COLOR ) );
497 : 0 : SetControlBackground( GALLERY_BG_COLOR );
498 : 0 : SetControlForeground( GALLERY_FG_COLOR );
499 : 0 : }
500 : :
501 : : // -----------------------------------------------------------------------
502 : :
503 : 0 : void GalleryListView::DataChanged( const DataChangedEvent& rDCEvt )
504 : : {
505 [ # # ][ # # ]: 0 : if ( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
[ # # ]
506 : 0 : InitSettings();
507 : : else
508 : 0 : BrowseBox::DataChanged( rDCEvt );
509 : 0 : }
510 : :
511 : : // ------------------------------------------------------------------------
512 : :
513 : 0 : sal_Bool GalleryListView::SeekRow( long nRow )
514 : : {
515 : 0 : mnCurRow = nRow;
516 : 0 : return sal_True;
517 : : }
518 : :
519 : : // -----------------------------------------------------------------------------
520 : :
521 : 0 : String GalleryListView::GetCellText(long _nRow, sal_uInt16 nColumnId) const
522 : : {
523 : 0 : String sRet;
524 [ # # ][ # # ]: 0 : if( mpTheme && ( _nRow < static_cast< long >( mpTheme->GetObjectCount() ) ) )
[ # # ]
525 : : {
526 [ # # ]: 0 : SgaObject* pObj = mpTheme->AcquireObject( _nRow );
527 : :
528 [ # # ]: 0 : if( pObj )
529 : : {
530 : : sRet = GalleryBrowser2::GetItemText( *mpTheme, *pObj,
531 [ # # ][ # # ]: 0 : ( GALLERY_BRWBOX_TITLE == nColumnId ) ? GALLERY_ITEM_TITLE : GALLERY_ITEM_PATH );
[ # # ][ # # ]
532 : :
533 [ # # ]: 0 : mpTheme->ReleaseObject( pObj );
534 : : }
535 : : }
536 : :
537 : 0 : return sRet;
538 : : }
539 : :
540 : : // -----------------------------------------------------------------------------
541 : :
542 : 0 : Rectangle GalleryListView::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex)
543 : : {
544 : : DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldCharacterBounds: _nColumnId overflow");
545 : 0 : Rectangle aRect;
546 [ # # ]: 0 : if ( SeekRow(_nRow) )
547 : : {
548 [ # # ]: 0 : SvxFont aFont( GetFont() );
549 [ # # ][ # # ]: 0 : AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>( GetColumnId( sal::static_int_cast<sal_uInt16>(_nColumnPos) ) ) ) );
[ # # ][ # # ]
550 : :
551 : : // get the bounds inside the string
552 [ # # ][ # # ]: 0 : aStringWrap.GetCharacterBounds(nIndex, aRect);
[ # # ]
553 : :
554 : : // offset to
555 : : }
556 : 0 : return aRect;
557 : : }
558 : :
559 : : // -----------------------------------------------------------------------------
560 : :
561 : 0 : sal_Int32 GalleryListView::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
562 : : {
563 : : DBG_ASSERT(_nColumnPos >= 0 && _nColumnPos <= USHRT_MAX, "GalleryListView::GetFieldIndexAtPoint: _nColumnId overflow");
564 : 0 : sal_Int32 nRet = -1;
565 [ # # ]: 0 : if ( SeekRow(_nRow) )
566 : : {
567 [ # # ]: 0 : SvxFont aFont( GetFont() );
568 [ # # ][ # # ]: 0 : AccessibleStringWrap aStringWrap( *this, aFont, GetCellText(_nRow, sal::static_int_cast<sal_uInt16>(GetColumnId(sal::static_int_cast<sal_uInt16>(_nColumnPos)))) );
[ # # ][ # # ]
569 [ # # ][ # # ]: 0 : nRet = aStringWrap.GetIndexAtPoint(_rPoint);
[ # # ]
570 : : }
571 : 0 : return nRet;
572 : : }
573 : :
574 : : // ------------------------------------------------------------------------
575 : :
576 : 0 : void GalleryListView::PaintField( OutputDevice& rDev, const Rectangle& rRect, sal_uInt16 nColumnId ) const
577 : : {
578 : 0 : rDev.Push( PUSH_CLIPREGION );
579 : 0 : rDev.IntersectClipRegion( rRect );
580 : :
581 [ # # ][ # # ]: 0 : if( mpTheme && ( mnCurRow < mpTheme->GetObjectCount() ) )
[ # # ]
582 : : {
583 : 0 : SgaObject* pObj = mpTheme->AcquireObject( mnCurRow );
584 : :
585 [ # # ]: 0 : if( pObj )
586 : : {
587 : 0 : const long nTextPosY = rRect.Top() + ( ( rRect.GetHeight() - rDev.GetTextHeight() ) >> 1 );
588 : :
589 [ # # ]: 0 : if( GALLERY_BRWBOX_TITLE == nColumnId )
590 : : {
591 [ # # ][ # # ]: 0 : Rectangle aOutputRect( rRect.TopLeft(), Size( rRect.GetHeight(), rRect.GetHeight() ) );
[ # # ]
592 [ # # ]: 0 : GraphicObject aGrfObj;
593 : :
594 [ # # ][ # # ]: 0 : if( pObj->GetObjKind() == SGA_OBJ_SOUND )
595 [ # # ][ # # ]: 0 : aGrfObj = Graphic( BitmapEx( GAL_RES( RID_SVXBMP_GALLERY_MEDIA ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
596 [ # # ]: 0 : else if( pObj->IsThumbBitmap() )
597 [ # # ][ # # ]: 0 : aGrfObj = Graphic( pObj->GetThumbBmp() );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
598 : : else
599 [ # # ][ # # ]: 0 : aGrfObj = Graphic( pObj->GetThumbMtf() );
[ # # ][ # # ]
[ # # ]
600 : :
601 [ # # ]: 0 : Size aSize( rDev.LogicToPixel( aGrfObj.GetPrefSize(), aGrfObj.GetPrefMapMode() ) );
602 : :
603 [ # # ][ # # ]: 0 : if( aSize.Width() && aSize.Height() )
[ # # ]
604 : : {
605 [ # # ][ # # ]: 0 : if( ( aSize.Width() > aOutputRect.GetWidth() ) || ( aSize.Height() > aOutputRect.GetHeight() ) )
[ # # ][ # # ]
[ # # ]
606 : : {
607 : 0 : Point aNewPos;
608 : 0 : const double fBmpWH = (double) aSize.Width() / aSize.Height();
609 [ # # ][ # # ]: 0 : const double fThmpWH = (double) aOutputRect.GetWidth() / aOutputRect.GetHeight();
610 : :
611 : : // Bitmap an Thumbgroesse anpassen
612 [ # # ]: 0 : if ( fBmpWH < fThmpWH )
613 : : {
614 [ # # ]: 0 : aSize.Width() = (long) ( aOutputRect.GetHeight() * fBmpWH );
615 [ # # ]: 0 : aSize.Height()= aOutputRect.GetHeight();
616 : : }
617 : : else
618 : : {
619 [ # # ]: 0 : aSize.Width() = aOutputRect.GetWidth();
620 [ # # ]: 0 : aSize.Height()= (long) ( aOutputRect.GetWidth() / fBmpWH );
621 : : }
622 : : }
623 : :
624 : 0 : aSize.Width() = Max( aSize.Width(), 4L );
625 : 0 : aSize.Height() = Max( aSize.Height(), 4L );
626 : :
627 [ # # ]: 0 : const Point aPos( ( ( aOutputRect.GetWidth() - aSize.Width() ) >> 1 ) + aOutputRect.Left(),
628 [ # # ]: 0 : ( ( aOutputRect.GetHeight() - aSize.Height() ) >> 1 ) + aOutputRect.Top() );
629 : :
630 [ # # ]: 0 : aGrfObj.Draw( &rDev, aPos, aSize );
631 : : }
632 : :
633 [ # # ][ # # ]: 0 : rDev.DrawText( Point( aOutputRect.Right() + 6, nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_TITLE ) );
[ # # ][ # # ]
634 : : }
635 [ # # ]: 0 : else if( GALLERY_BRWBOX_PATH == nColumnId )
636 [ # # ]: 0 : rDev.DrawText( Point( rRect.Left(), nTextPosY ), GalleryBrowser2::GetItemText( *mpTheme, *pObj, GALLERY_ITEM_PATH ) );
637 : :
638 : 0 : mpTheme->ReleaseObject( pObj );
639 : : }
640 : : }
641 : :
642 : 0 : rDev.Pop();
643 : 0 : }
644 : :
645 : : // ------------------------------------------------------------------------
646 : :
647 : 0 : void GalleryListView::Command( const CommandEvent& rCEvt )
648 : : {
649 : 0 : BrowseBox::Command( rCEvt );
650 : :
651 [ # # ]: 0 : if( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
652 : : {
653 : 0 : const Point* pPos = NULL;
654 : :
655 [ # # ][ # # ]: 0 : if( rCEvt.IsMouseEvent() && ( GetRowAtYPosPixel( rCEvt.GetMousePosPixel().Y() ) != BROWSER_ENDOFSELECTION ) )
[ # # ]
656 : 0 : pPos = &rCEvt.GetMousePosPixel();
657 : :
658 : 0 : ( (GalleryBrowser2*) GetParent() )->ShowContextMenu( this, pPos );
659 : : }
660 : 0 : }
661 : :
662 : : // ------------------------------------------------------------------------
663 : :
664 : 0 : void GalleryListView::KeyInput( const KeyEvent& rKEvt )
665 : : {
666 [ # # ][ # # ]: 0 : if( !mpTheme || !static_cast< GalleryBrowser2* >( GetParent() )->KeyInput( rKEvt, this ) )
[ # # ]
667 : 0 : BrowseBox::KeyInput( rKEvt );
668 : 0 : }
669 : :
670 : : // ------------------------------------------------------------------------
671 : :
672 : 0 : void GalleryListView::DoubleClick( const BrowserMouseEvent& rEvt )
673 : : {
674 : 0 : BrowseBox::DoubleClick( rEvt );
675 : :
676 [ # # ]: 0 : if( rEvt.GetRow() != BROWSER_ENDOFSELECTION )
677 : 0 : ( (GalleryBrowser2*) GetParent() )->TogglePreview( this, &rEvt.GetPosPixel() );
678 : 0 : }
679 : :
680 : : // ------------------------------------------------------------------------
681 : :
682 : 0 : void GalleryListView::Select()
683 : : {
684 [ # # ]: 0 : if( maSelectHdl.IsSet() )
685 : 0 : maSelectHdl.Call( this );
686 : 0 : }
687 : :
688 : : // ------------------------------------------------------------------------
689 : :
690 : 0 : sal_Int8 GalleryListView::AcceptDrop( const BrowserAcceptDropEvent& )
691 : : {
692 : 0 : sal_Int8 nRet = DND_ACTION_NONE;
693 : :
694 [ # # ][ # # ]: 0 : if( mpTheme && !mpTheme->IsReadOnly() )
[ # # ]
695 : 0 : nRet = DND_ACTION_COPY;
696 : :
697 : 0 : return nRet;
698 : : }
699 : :
700 : : // ------------------------------------------------------------------------
701 : :
702 : 0 : sal_Int8 GalleryListView::ExecuteDrop( const BrowserExecuteDropEvent& rEvt )
703 : : {
704 [ # # ]: 0 : ExecuteDropEvent aEvt( rEvt );
705 : :
706 [ # # ]: 0 : aEvt.maPosPixel.Y() += GetTitleHeight();
707 : :
708 [ # # ][ # # ]: 0 : return( ( (GalleryBrowser2*) GetParent() )->ExecuteDrop( *this, aEvt ) );
[ # # ]
709 : : }
710 : :
711 : : // ------------------------------------------------------------------------
712 : :
713 : 0 : void GalleryListView::StartDrag( sal_Int8, const Point& rPosPixel )
714 : : {
715 : 0 : ( (GalleryBrowser2*) GetParent() )->StartDrag( this, &rPosPixel );
716 : 0 : }
717 : :
718 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|