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

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

Generated by: LCOV version 1.10