LCOV - code coverage report
Current view: top level - sfx2/source/dialog - titledockwin.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 97 158 61.4 %
Date: 2014-04-11 Functions: 11 20 55.0 %
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             : 
      21             : #include <sfx2/titledockwin.hxx>
      22             : #include <sfx2/bindings.hxx>
      23             : #include <sfx2/dispatch.hxx>
      24             : #include "sfxlocal.hrc"
      25             : #include <sfx2/sfxresid.hxx>
      26             : 
      27             : #include <svl/eitem.hxx>
      28             : #include <vcl/settings.hxx>
      29             : 
      30             : 
      31             : namespace sfx2
      32             : {
      33             : 
      34             : 
      35             : 
      36             :     //= TitledDockingWindow
      37             : 
      38             : 
      39           0 :     TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
      40             :             WinBits i_nStyle )
      41             :         :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_nStyle )
      42             :         ,m_sTitle()
      43             :         ,m_aToolbox( this )
      44             :         ,m_aContentWindow( this, WB_DIALOGCONTROL )
      45             :         ,m_aBorder( 3, 1, 3, 3 )
      46             :         ,m_bLayoutPending( false )
      47           0 :         ,m_nTitleBarHeight(0)
      48             :     {
      49           0 :         impl_construct();
      50           0 :     }
      51             : 
      52             : 
      53          63 :     TitledDockingWindow::TitledDockingWindow( SfxBindings* i_pBindings, SfxChildWindow* i_pChildWindow, Window* i_pParent,
      54             :             const ResId& i_rResId )
      55             :         :SfxDockingWindow( i_pBindings, i_pChildWindow, i_pParent, i_rResId )
      56             :         ,m_sTitle()
      57             :         ,m_aToolbox( this )
      58             :         ,m_aContentWindow( this )
      59             :         ,m_aBorder( 3, 1, 3, 3 )
      60          63 :         ,m_bLayoutPending( false )
      61             :     {
      62          63 :         impl_construct();
      63          63 :     }
      64             : 
      65             : 
      66          63 :     void TitledDockingWindow::impl_construct()
      67             :     {
      68          63 :         SetBackground( Wallpaper() );
      69             : 
      70          63 :         m_aToolbox.SetSelectHdl( LINK( this, TitledDockingWindow, OnToolboxItemSelected ) );
      71          63 :         m_aToolbox.SetOutStyle( TOOLBOX_STYLE_FLAT );
      72          63 :         m_aToolbox.SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetDialogColor() ) );
      73          63 :         m_aToolbox.Show();
      74          63 :         impl_resetToolBox();
      75             : 
      76          63 :         m_aContentWindow.Show();
      77          63 :     }
      78             : 
      79             : 
      80          63 :     TitledDockingWindow::~TitledDockingWindow()
      81             :     {
      82          63 :     }
      83             : 
      84             : 
      85          63 :     void TitledDockingWindow::SetTitle( const OUString& i_rTitle )
      86             :     {
      87          63 :         m_sTitle = i_rTitle;
      88          63 :         Invalidate();
      89          63 :     }
      90             : 
      91             : 
      92           0 :     void TitledDockingWindow::SetText( const OUString& i_rText )
      93             :     {
      94           0 :         SfxDockingWindow::SetText( i_rText );
      95           0 :         if ( m_sTitle.isEmpty() )
      96             :             // our text is used as title, too => repaint
      97           0 :             Invalidate();
      98           0 :     }
      99             : 
     100             : 
     101         158 :     void TitledDockingWindow::Resize()
     102             :     {
     103         158 :         SfxDockingWindow::Resize();
     104         158 :         impl_scheduleLayout();
     105         158 :     }
     106             : 
     107             : 
     108          72 :     void TitledDockingWindow::onLayoutDone()
     109             :     {
     110             :         // not interested in
     111          72 :     }
     112             : 
     113             : 
     114         158 :     void TitledDockingWindow::impl_scheduleLayout()
     115             :     {
     116         158 :         m_bLayoutPending = true;
     117         158 :     }
     118             : 
     119             : 
     120          72 :     void TitledDockingWindow::impl_layout()
     121             :     {
     122          72 :         m_bLayoutPending = false;
     123             : 
     124          72 :         m_aToolbox.ShowItem( 1, !IsFloatingMode() );
     125             : 
     126          72 :         const Size aToolBoxSize( m_aToolbox.CalcWindowSizePixel() );
     127          72 :         Size aWindowSize( GetOutputSizePixel() );
     128             : 
     129             :         // position the tool box
     130          72 :         m_nTitleBarHeight = GetSettings().GetStyleSettings().GetTitleHeight();
     131          72 :         if ( aToolBoxSize.Height() > m_nTitleBarHeight )
     132           0 :             m_nTitleBarHeight = aToolBoxSize.Height();
     133             :         m_aToolbox.SetPosSizePixel(
     134             :             Point(
     135         144 :                 aWindowSize.Width() - aToolBoxSize.Width(),
     136          72 :                 ( m_nTitleBarHeight - aToolBoxSize.Height() ) / 2
     137             :             ),
     138             :             aToolBoxSize
     139         216 :         );
     140             : 
     141             :         // Place the content window.
     142          72 :         if ( m_nTitleBarHeight < aToolBoxSize.Height() )
     143           0 :             m_nTitleBarHeight = aToolBoxSize.Height();
     144          72 :         aWindowSize.Height() -= m_nTitleBarHeight;
     145             :         m_aContentWindow.SetPosSizePixel(
     146         144 :             Point( m_aBorder.Left(), m_nTitleBarHeight + m_aBorder.Top() ),
     147             :             Size(
     148          72 :                 aWindowSize.Width() - m_aBorder.Left() - m_aBorder.Right(),
     149          72 :                 aWindowSize.Height() - m_aBorder.Top() - m_aBorder.Bottom()
     150             :             )
     151         288 :         );
     152             : 
     153          72 :         onLayoutDone();
     154          72 :     }
     155             : 
     156             : 
     157         121 :     void TitledDockingWindow::Paint( const Rectangle& i_rArea )
     158             :     {
     159         121 :         if ( m_bLayoutPending )
     160          72 :             impl_layout();
     161             : 
     162         121 :         SfxDockingWindow::Paint( i_rArea );
     163             : 
     164         121 :         Push( PUSH_FONT | PUSH_FILLCOLOR | PUSH_LINECOLOR );
     165             : 
     166         121 :         SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
     167         121 :         SetLineColor();
     168             : 
     169             :         // bold font
     170         121 :         Font aFont( GetFont() );
     171         121 :         aFont.SetWeight( WEIGHT_BOLD );
     172         121 :         SetFont( aFont );
     173             : 
     174             :         // Set border values.
     175         121 :         Size aWindowSize( GetOutputSizePixel() );
     176         121 :         int nOuterLeft = 0;
     177         121 :         int nInnerLeft = nOuterLeft + m_aBorder.Left() - 1;
     178         121 :         int nOuterRight = aWindowSize.Width() - 1;
     179         121 :         int nInnerRight = nOuterRight - m_aBorder.Right() + 1;
     180         121 :         int nInnerTop = m_nTitleBarHeight + m_aBorder.Top() - 1;
     181         121 :         int nOuterBottom = aWindowSize.Height() - 1;
     182         121 :         int nInnerBottom = nOuterBottom - m_aBorder.Bottom() + 1;
     183             : 
     184             :         // Paint title bar background.
     185             :         Rectangle aTitleBarBox( Rectangle(
     186             :             nOuterLeft,
     187             :             0,
     188             :             nOuterRight,
     189         121 :             nInnerTop-1
     190         121 :         ) );
     191         121 :         DrawRect( aTitleBarBox );
     192             : 
     193         121 :         if ( nInnerLeft > nOuterLeft )
     194         121 :             DrawRect( Rectangle( nOuterLeft, nInnerTop, nInnerLeft, nInnerBottom ) );
     195         121 :         if ( nOuterRight > nInnerRight )
     196         121 :             DrawRect( Rectangle( nInnerRight, nInnerTop, nOuterRight, nInnerBottom ) );
     197         121 :         if ( nInnerBottom < nOuterBottom )
     198         121 :             DrawRect( Rectangle( nOuterLeft, nInnerBottom, nOuterRight, nOuterBottom ) );
     199             : 
     200             :         // Paint bevel border.
     201         121 :         SetFillColor();
     202         121 :         SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
     203         121 :         if ( m_aBorder.Top() > 0 )
     204         121 :             DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerLeft, nInnerBottom ) );
     205         121 :         if ( m_aBorder.Left() > 0 )
     206         121 :             DrawLine( Point( nInnerLeft, nInnerTop ), Point( nInnerRight, nInnerTop ) );
     207             : 
     208         121 :         SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
     209         121 :         if ( m_aBorder.Bottom() > 0 )
     210         121 :             DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerLeft, nInnerBottom ) );
     211         121 :         if ( m_aBorder.Right() > 0 )
     212         121 :             DrawLine( Point( nInnerRight, nInnerBottom ), Point( nInnerRight, nInnerTop ) );
     213             : 
     214             :         // Paint title bar text.
     215         121 :         SetLineColor( GetSettings().GetStyleSettings().GetActiveTextColor() );
     216         121 :         aTitleBarBox.Left() += 3;
     217         121 :         DrawText( aTitleBarBox, impl_getTitle(), TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
     218             : 
     219             :         // Restore original values of the output device.
     220         121 :         Pop();
     221         121 :     }
     222             : 
     223             : 
     224         121 :     OUString TitledDockingWindow::impl_getTitle() const
     225             :     {
     226         121 :         return !m_sTitle.isEmpty() ? m_sTitle : GetText();
     227             :     }
     228             : 
     229             : 
     230          63 :     void TitledDockingWindow::impl_resetToolBox()
     231             :     {
     232          63 :         m_aToolbox.Clear();
     233             : 
     234             :         // Get the closer bitmap and set it as right most button.
     235          63 :         Image aImage( SfxResId( SFX_IMG_CLOSE_DOC ) );
     236          63 :         m_aToolbox.InsertItem( 1, aImage );
     237          63 :         m_aToolbox.ShowItem( 1 );
     238          63 :     }
     239             : 
     240             : 
     241           0 :     sal_uInt16 TitledDockingWindow::impl_addDropDownToolBoxItem( const OUString& i_rItemText, const OString& i_nHelpId, const Link& i_rCallback )
     242             :     {
     243             :         // Add the menu before the closer button.
     244           0 :         const sal_uInt16 nItemCount( m_aToolbox.GetItemCount() );
     245           0 :         const sal_uInt16 nItemId( nItemCount + 1 );
     246           0 :         m_aToolbox.InsertItem( nItemId, i_rItemText, TIB_DROPDOWNONLY, nItemCount > 0 ? nItemCount - 1 : TOOLBOX_APPEND );
     247           0 :         m_aToolbox.SetHelpId( nItemId, i_nHelpId );
     248           0 :         m_aToolbox.SetClickHdl( i_rCallback );
     249           0 :         m_aToolbox.SetDropdownClickHdl( i_rCallback );
     250             : 
     251             :         // The tool box has likely changed its size. The title bar has to be
     252             :         // resized.
     253           0 :         impl_scheduleLayout();
     254           0 :         Invalidate();
     255             : 
     256           0 :         return nItemId;
     257             :     }
     258             : 
     259             : 
     260           0 :     IMPL_LINK( TitledDockingWindow, OnToolboxItemSelected, ToolBox*, pToolBox )
     261             :     {
     262           0 :         const sal_uInt16 nId = pToolBox->GetCurItemId();
     263             : 
     264           0 :         if ( nId == 1 )
     265             :         {
     266             :             // the closer
     267           0 :             EndTracking();
     268           0 :             const sal_uInt16 nChildWindowId( GetChildWindow_Impl()->GetType() );
     269           0 :             const SfxBoolItem aVisibility( nChildWindowId, false );
     270           0 :             GetBindings().GetDispatcher()->Execute(
     271             :                 nChildWindowId,
     272             :                 SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
     273             :                 &aVisibility,
     274             :                 NULL
     275           0 :             );
     276             :         }
     277             : 
     278           0 :         return 0;
     279             :     }
     280             : 
     281             : 
     282           0 :     void TitledDockingWindow::StateChanged( StateChangedType i_nType )
     283             :     {
     284           0 :         switch ( i_nType )
     285             :         {
     286             :             case STATE_CHANGE_INITSHOW:
     287           0 :                 impl_scheduleLayout();
     288           0 :                 break;
     289             :         }
     290           0 :         SfxDockingWindow::StateChanged( i_nType );
     291           0 :     }
     292             : 
     293             :     //------------------------------------------------------------------------------------------------------------------
     294           0 :     void TitledDockingWindow::EndDocking( const Rectangle& i_rRect, bool i_bFloatMode )
     295             :     {
     296           0 :         SfxDockingWindow::EndDocking( i_rRect, i_bFloatMode );
     297             : 
     298           0 :         if ( m_aEndDockingHdl.IsSet() )
     299           0 :             m_aEndDockingHdl.Call( this );
     300           0 :     }
     301             : 
     302             : 
     303           0 :     void TitledDockingWindow::DataChanged( const DataChangedEvent& i_rDataChangedEvent )
     304             :     {
     305           0 :         SfxDockingWindow::DataChanged( i_rDataChangedEvent );
     306             : 
     307           0 :         switch ( i_rDataChangedEvent.GetType() )
     308             :         {
     309             :             case DATACHANGED_SETTINGS:
     310           0 :                 if ( ( i_rDataChangedEvent.GetFlags() & SETTINGS_STYLE ) == 0)
     311           0 :                     break;
     312             :                 // else fall through.
     313             :             case DATACHANGED_FONTS:
     314             :             case DATACHANGED_FONTSUBSTITUTION:
     315             :             {
     316           0 :                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     317             : 
     318             :                 // Font.
     319           0 :                 Font aFont = rStyleSettings.GetAppFont();
     320           0 :                 if ( IsControlFont() )
     321           0 :                     aFont.Merge( GetControlFont() );
     322           0 :                 SetZoomedPointFont( aFont );
     323             : 
     324             :                 // Color.
     325           0 :                 Color aColor;
     326           0 :                 if ( IsControlForeground() )
     327           0 :                     aColor = GetControlForeground();
     328             :                 else
     329           0 :                     aColor = rStyleSettings.GetButtonTextColor();
     330           0 :                 SetTextColor( aColor );
     331           0 :                 SetTextFillColor();
     332             : 
     333           0 :                 impl_scheduleLayout();
     334           0 :                 Invalidate();
     335             :             }
     336           0 :             break;
     337             :         }
     338           0 :     }
     339             : 
     340             : 
     341             : } // namespace sfx2
     342             : 
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10