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