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

Generated by: LCOV version 1.11