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

Generated by: LCOV version 1.10