LCOV - code coverage report
Current view: top level - svx/source/gallery2 - GalleryControl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 110 0.9 %
Date: 2014-04-11 Functions: 2 12 16.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  *
       8             :  * This file incorporates work covered by the following license notice:
       9             :  *
      10             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      11             :  *   contributor license agreements. See the NOTICE file distributed
      12             :  *   with this work for additional information regarding copyright
      13             :  *   ownership. The ASF licenses this file to you under the Apache
      14             :  *   License, Version 2.0 (the "License"); you may not use this file
      15             :  *   except in compliance with the License. You may obtain a copy of
      16             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      17             :  */
      18             : 
      19             : #include "GalleryControl.hxx"
      20             : 
      21             : #include "gallery.hrc"
      22             : #include "svx/galmisc.hxx"
      23             : #include "svx/gallery1.hxx"
      24             : #include "galbrws1.hxx"
      25             : #include "galbrws2.hxx"
      26             : #include "GallerySplitter.hxx"
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/settings.hxx>
      29             : #include <sfx2/sidebar/Theme.hxx>
      30             : 
      31             : #include <boost/bind.hpp>
      32             : 
      33             : namespace svx { namespace sidebar {
      34             : 
      35             : static const sal_Int32 gnInitialVerticalSplitPosition (150);
      36             : 
      37           0 : GalleryControl::GalleryControl (
      38             :     SfxBindings* /*pBindings*/,
      39             :     Window* pParentWindow)
      40           0 :     : Window(pParentWindow, GAL_RES(RID_SVXDLG_GALLERYBROWSER)),
      41           0 :       mpGallery (Gallery::GetGalleryInstance()),
      42             :       mpSplitter(new GallerySplitter(
      43             :               this,
      44           0 :               GAL_RES(GALLERY_SPLITTER),
      45           0 :               ::boost::bind(&GalleryControl::InitSettings, this))),
      46             :       mpBrowser1(new GalleryBrowser1(
      47             :               this,
      48           0 :               GAL_RES(GALLERY_BROWSER1),
      49             :               mpGallery,
      50             :               ::boost::bind(&GalleryControl::GalleryKeyInput,this,_1,_2),
      51           0 :               ::boost::bind(&GalleryControl::ThemeSelectionHasChanged, this))),
      52           0 :       mpBrowser2(new GalleryBrowser2(this, GAL_RES(GALLERY_BROWSER2), mpGallery)),
      53           0 :       maLastSize(GetOutputSizePixel()),
      54           0 :       mbIsInitialResize(true)
      55             : {
      56           0 :     FreeResource();
      57             : 
      58           0 :     mpBrowser1->SelectTheme(0);
      59           0 :     mpBrowser1->Show(true);
      60             : 
      61           0 :     mpBrowser2->Show(true);
      62             : 
      63           0 :     mpSplitter->SetHorizontal(false);
      64           0 :     mpSplitter->SetSplitHdl( LINK( this, GalleryControl, SplitHdl ) );
      65           0 :     mpSplitter->Show( true );
      66             : 
      67           0 :     InitSettings();
      68           0 : }
      69             : 
      70           0 : GalleryControl::~GalleryControl (void)
      71             : {
      72           0 : }
      73             : 
      74           0 : void GalleryControl::InitSettings (void)
      75             : {
      76           0 :     SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
      77           0 :     SetControlBackground( GALLERY_DLG_COLOR );
      78           0 :     SetControlForeground( GALLERY_DLG_COLOR );
      79             : 
      80           0 :     mpSplitter->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
      81           0 :     mpSplitter->SetControlBackground( GALLERY_DLG_COLOR );
      82           0 :     mpSplitter->SetControlForeground( GALLERY_DLG_COLOR );
      83             : 
      84           0 :     mpBrowser1->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
      85           0 :     mpBrowser1->SetControlBackground( GALLERY_DLG_COLOR );
      86           0 :     mpBrowser1->SetControlForeground( GALLERY_DLG_COLOR );
      87             : 
      88           0 :     mpBrowser2->SetBackground( Wallpaper( GALLERY_DLG_COLOR ) );
      89           0 :     mpBrowser2->SetControlBackground( GALLERY_DLG_COLOR );
      90           0 :     mpBrowser2->SetControlForeground( GALLERY_DLG_COLOR );
      91             : 
      92           0 :     const Wallpaper aBackground (sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
      93           0 :     mpSplitter->SetBackground(aBackground);
      94           0 :     SetBackground(aBackground);
      95           0 :     mpBrowser2->SetBackground(aBackground);
      96           0 : }
      97             : 
      98           0 : void GalleryControl::Resize (void)
      99             : {
     100             :     // call parent
     101           0 :     Window::Resize();
     102             : 
     103             :     // update hor/ver
     104           0 :     const Size aNewSize( GetOutputSizePixel() );
     105           0 :     if (aNewSize.Width()<=0 || aNewSize.Height()<=0)
     106           0 :         return;
     107             : 
     108           0 :     const bool bNewLayoutHorizontal(aNewSize.Width() > aNewSize.Height());
     109           0 :     const bool bOldLayoutHorizontal(mpSplitter->IsHorizontal());
     110           0 :     long nSplitPos( bOldLayoutHorizontal ? mpSplitter->GetPosPixel().X() : mpSplitter->GetPosPixel().Y());
     111           0 :     const long nSplitSize( bOldLayoutHorizontal ? mpSplitter->GetOutputSizePixel().Width() : mpSplitter->GetOutputSizePixel().Height());
     112             : 
     113           0 :     if(bNewLayoutHorizontal != bOldLayoutHorizontal)
     114             :     {
     115           0 :         mpSplitter->SetHorizontal(bNewLayoutHorizontal);
     116             :     }
     117             :     else
     118             :     {
     119           0 :         if (mbIsInitialResize)
     120             :         {
     121           0 :             nSplitPos = gnInitialVerticalSplitPosition;
     122           0 :             if (nSplitPos > aNewSize.Height()/2)
     123           0 :                 nSplitPos = aNewSize.Height()/2;
     124             :         }
     125             :     }
     126           0 :     mbIsInitialResize = false;
     127             : 
     128           0 :     const long nFrameLen = LogicToPixel( Size( 3, 0 ), MAP_APPFONT ).Width();
     129           0 :     const long nFrameLen2 = nFrameLen << 1;
     130             : 
     131           0 :     if(bNewLayoutHorizontal)
     132             :     {
     133           0 :         mpBrowser1->SetPosSizePixel(
     134             :             Point( nFrameLen, nFrameLen ),
     135           0 :             Size(nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2) );
     136             : 
     137           0 :         mpSplitter->SetPosSizePixel(
     138             :             Point( nSplitPos, 0),
     139           0 :             Size( nSplitSize, aNewSize.Height() ) );
     140             : 
     141           0 :         mpSplitter->SetDragRectPixel(
     142             :             Rectangle(
     143             :                 Point( nFrameLen2, 0 ),
     144           0 :                 Size( aNewSize.Width() - ( nFrameLen2 << 1 ) - nSplitSize, aNewSize.Height() ) ) );
     145             : 
     146           0 :         mpBrowser2->SetPosSizePixel(
     147             :             Point( nSplitPos + nSplitSize, nFrameLen ),
     148           0 :             Size( aNewSize.Width() - nSplitSize - nSplitPos - nFrameLen, aNewSize.Height() - nFrameLen2 ) );
     149             :     }
     150             :     else
     151             :     {
     152           0 :         mpBrowser1->SetPosSizePixel(
     153             :             Point( nFrameLen, nFrameLen ),
     154           0 :             Size(aNewSize.Width() - nFrameLen2, nSplitPos - nFrameLen));
     155             : 
     156           0 :         mpSplitter->SetPosSizePixel(
     157             :             Point( 0, nSplitPos),
     158           0 :             Size( aNewSize.Width(), nSplitSize ) );
     159             : 
     160           0 :         mpSplitter->SetDragRectPixel(
     161             :             Rectangle(
     162             :                 Point( 0, nFrameLen2 ),
     163           0 :                 Size( aNewSize.Width(), aNewSize.Height() - ( nFrameLen2 << 1 ) - nSplitSize ) ));
     164             : 
     165           0 :         mpBrowser2->SetPosSizePixel(
     166             :             Point( nFrameLen, nSplitPos + nSplitSize ),
     167           0 :             Size( aNewSize.Width() - nFrameLen2, aNewSize.Height() - nSplitSize - nSplitPos - nFrameLen ));
     168             :     }
     169             : 
     170           0 :     maLastSize = aNewSize;
     171             : }
     172             : 
     173           0 : sal_Bool GalleryControl::GalleryKeyInput( const KeyEvent& rKEvt, Window* )
     174             : {
     175           0 :     const sal_uInt16    nCode = rKEvt.GetKeyCode().GetCode();
     176           0 :     sal_Bool            bRet = ( !rKEvt.GetKeyCode().IsMod1() &&
     177           0 :                            ( ( KEY_TAB == nCode ) || ( KEY_F6 == nCode && rKEvt.GetKeyCode().IsMod2() ) ) );
     178             : 
     179           0 :     if( bRet )
     180             :     {
     181           0 :         if( !rKEvt.GetKeyCode().IsShift() )
     182             :         {
     183           0 :             if( mpBrowser1->mpThemes->HasChildPathFocus( true ) )
     184           0 :                 mpBrowser2->GetViewWindow()->GrabFocus();
     185           0 :             else if( mpBrowser2->GetViewWindow()->HasFocus() )
     186           0 :                 mpBrowser2->maViewBox.GrabFocus();
     187           0 :             else if( mpBrowser2->maViewBox.HasFocus() )
     188           0 :                 mpBrowser1->maNewTheme.GrabFocus();
     189             :             else
     190           0 :                 mpBrowser1->mpThemes->GrabFocus();
     191             :         }
     192             :         else
     193             :         {
     194           0 :             if( mpBrowser1->mpThemes->HasChildPathFocus( true ) )
     195           0 :                 mpBrowser1->maNewTheme.GrabFocus();
     196           0 :             else if( mpBrowser1->maNewTheme.HasFocus() )
     197           0 :                 mpBrowser2->maViewBox.GrabFocus();
     198           0 :             else if( mpBrowser2->maViewBox.HasFocus() )
     199           0 :                 mpBrowser2->GetViewWindow()->GrabFocus();
     200             :             else
     201           0 :                 mpBrowser1->mpThemes->GrabFocus();
     202             :         }
     203             :     }
     204             : 
     205           0 :     return bRet;
     206             : }
     207             : 
     208           0 : void GalleryControl::GetFocus (void)
     209             : {
     210           0 :     Window::GetFocus();
     211           0 :     mpBrowser1->GrabFocus();
     212           0 : }
     213             : 
     214           0 : void GalleryControl::ThemeSelectionHasChanged (void)
     215             : {
     216           0 :     mpBrowser2->SelectTheme(mpBrowser1->GetSelectedTheme());
     217           0 : }
     218             : 
     219           0 : IMPL_LINK( GalleryControl, SplitHdl, void*, EMPTYARG )
     220             : {
     221           0 :     if(mpSplitter->IsHorizontal())
     222             :     {
     223           0 :         mpSplitter->SetPosPixel( Point( mpSplitter->GetSplitPosPixel(), mpSplitter->GetPosPixel().Y() ) );
     224             :     }
     225             :     else
     226             :     {
     227           0 :         mpSplitter->SetPosPixel( Point( mpSplitter->GetPosPixel().X(), mpSplitter->GetSplitPosPixel() ) );
     228             :     }
     229             : 
     230           0 :     Resize();
     231             : 
     232           0 :     return 0L;
     233             : }
     234             : 
     235             : 
     236         297 : } } // end of namespace svx::sidebar

Generated by: LCOV version 1.10