LCOV - code coverage report
Current view: top level - vcl/source/window - tabdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 137 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 10 20.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             : #include <vcl/fixed.hxx>
      21             : #include <vcl/layout.hxx>
      22             : #include <vcl/tabctrl.hxx>
      23             : #include <vcl/tabdlg.hxx>
      24             : #include <tools/rc.h>
      25             : 
      26           0 : void TabDialog::ImplInitTabDialogData()
      27             : {
      28           0 :     mpFixedLine     = NULL;
      29           0 :     mpViewWindow    = NULL;
      30           0 :     meViewAlign     = WINDOWALIGN_LEFT;
      31           0 :     mbPosControls   = true;
      32           0 : }
      33             : 
      34           0 : void TabDialog::ImplPosControls()
      35             : {
      36           0 :     if (isLayoutEnabled())
      37           0 :         return;
      38             : 
      39           0 :     Size        aCtrlSize( IMPL_MINSIZE_BUTTON_WIDTH, IMPL_MINSIZE_BUTTON_HEIGHT );
      40           0 :     long        nDownCtrl = 0;
      41           0 :     long        nOffY = 0;
      42           0 :     vcl::Window*     pTabControl = NULL;
      43             : 
      44           0 :     vcl::Window* pChild = GetWindow( GetWindowType::FirstChild );
      45           0 :     while ( pChild )
      46             :     {
      47           0 :         if ( pChild->IsVisible() && (pChild != mpViewWindow) )
      48             :         {
      49           0 :             if (pChild->GetType() == WINDOW_TABCONTROL || isContainerWindow(*pChild))
      50           0 :                 pTabControl = pChild;
      51           0 :             else if ( pTabControl )
      52             :             {
      53           0 :                 Size aOptimalSize(pChild->get_preferred_size());
      54           0 :                 long nTxtWidth = aOptimalSize.Width();
      55           0 :                 if ( nTxtWidth > aCtrlSize.Width() )
      56           0 :                     aCtrlSize.Width() = nTxtWidth;
      57           0 :                 long nTxtHeight = aOptimalSize.Height();
      58           0 :                 if ( nTxtHeight > aCtrlSize.Height() )
      59           0 :                     aCtrlSize.Height() = nTxtHeight;
      60           0 :                 nDownCtrl++;
      61             :             }
      62             :             else
      63             :             {
      64           0 :                 long nHeight = pChild->GetSizePixel().Height();
      65           0 :                 if ( nHeight > nOffY )
      66           0 :                     nOffY = nHeight;
      67             :             }
      68             :         }
      69             : 
      70           0 :         pChild = pChild->GetWindow( GetWindowType::Next );
      71             :     }
      72             : 
      73             :     // do we have a TabControl ?
      74           0 :     if ( pTabControl )
      75             :     {
      76             :         // adapt offset for other controls by an extra distance
      77           0 :         if ( nOffY )
      78           0 :             nOffY += IMPL_DIALOG_BAR_OFFSET*2 + 2;
      79             : 
      80           0 :         Point   aTabOffset( IMPL_DIALOG_OFFSET, IMPL_DIALOG_OFFSET+nOffY );
      81             : 
      82           0 :         if (isContainerWindow(*pTabControl))
      83           0 :             pTabControl->SetSizePixel(pTabControl->get_preferred_size());
      84             : 
      85           0 :         Size    aTabSize = pTabControl->GetSizePixel();
      86             : 
      87           0 :         Size    aDlgSize( aTabSize.Width() + IMPL_DIALOG_OFFSET*2,
      88           0 :                           aTabSize.Height() + IMPL_DIALOG_OFFSET*2 + nOffY );
      89           0 :         long    nBtnEx = 0;
      90             : 
      91             :         // consider Preview-Fenster and adapt the sizes/offsets
      92           0 :         if ( mpViewWindow && mpViewWindow->IsVisible() )
      93             :         {
      94           0 :             long    nViewOffX = 0;
      95           0 :             long    nViewOffY = 0;
      96           0 :             long    nViewWidth = 0;
      97           0 :             long    nViewHeight = 0;
      98           0 :             PosSizeFlags nViewPosFlags = PosSizeFlags::Pos;
      99           0 :             Size    aViewSize = mpViewWindow->GetSizePixel();
     100           0 :             if (  meViewAlign == WINDOWALIGN_TOP )
     101             :             {
     102           0 :                 nViewOffX       = aTabOffset.X();
     103           0 :                 nViewOffY       = nOffY+IMPL_DIALOG_OFFSET;
     104           0 :                 nViewWidth      = aTabSize.Width();
     105           0 :                 nViewPosFlags  |= PosSizeFlags::Width;
     106           0 :                 aTabOffset.Y() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
     107           0 :                 aDlgSize.Height() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
     108             :             }
     109           0 :             else if (  meViewAlign == WINDOWALIGN_BOTTOM )
     110             :             {
     111           0 :                 nViewOffX       = aTabOffset.X();
     112           0 :                 nViewOffY       = aTabOffset.Y()+aTabSize.Height()+IMPL_DIALOG_OFFSET;
     113           0 :                 nViewWidth      = aTabSize.Width();
     114           0 :                 nViewPosFlags  |= PosSizeFlags::Width;
     115           0 :                 aDlgSize.Height() += aViewSize.Height()+IMPL_DIALOG_OFFSET;
     116             :             }
     117           0 :             else if (  meViewAlign == WINDOWALIGN_RIGHT )
     118             :             {
     119           0 :                 nViewOffX       = aTabOffset.X()+aTabSize.Width()+IMPL_DIALOG_OFFSET;
     120           0 :                 nViewOffY       = aTabOffset.Y();
     121           0 :                 nViewHeight     = aTabSize.Height();
     122           0 :                 nViewPosFlags  |= PosSizeFlags::Height;
     123           0 :                 aDlgSize.Width() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
     124           0 :                 nBtnEx          = aViewSize.Width()+IMPL_DIALOG_OFFSET;
     125             :             }
     126             :             else // meViewAlign == WINDOWALIGN_LEFT
     127             :             {
     128           0 :                 nViewOffX       = IMPL_DIALOG_OFFSET;
     129           0 :                 nViewOffY       = aTabOffset.Y();
     130           0 :                 nViewHeight     = aTabSize.Height();
     131           0 :                 nViewPosFlags  |= PosSizeFlags::Height;
     132           0 :                 aTabOffset.X() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
     133           0 :                 aDlgSize.Width() += aViewSize.Width()+IMPL_DIALOG_OFFSET;
     134           0 :                 nBtnEx          = aViewSize.Width()+IMPL_DIALOG_OFFSET;
     135             :             }
     136             : 
     137           0 :             mpViewWindow->setPosSizePixel( nViewOffX, nViewOffY,
     138             :                                            nViewWidth, nViewHeight,
     139           0 :                                            nViewPosFlags );
     140             :         }
     141             : 
     142             :         // adapt positioning
     143           0 :         pTabControl->SetPosPixel( aTabOffset );
     144             : 
     145             :         // position all other Children
     146           0 :         bool bTabCtrl   = false;
     147           0 :         int  nLines     = 0;
     148             :         long nX;
     149           0 :         long nY         = aDlgSize.Height();
     150           0 :         long nTopX      = IMPL_DIALOG_OFFSET;
     151             : 
     152             :         // all buttons are right aligned under Windows 95
     153           0 :         nX = IMPL_DIALOG_OFFSET;
     154           0 :         long nCtrlBarWidth = ((aCtrlSize.Width()+IMPL_DIALOG_OFFSET)*nDownCtrl)-IMPL_DIALOG_OFFSET;
     155           0 :         if ( nCtrlBarWidth <= (aTabSize.Width()+nBtnEx) )
     156           0 :             nX = (aTabSize.Width()+nBtnEx) - nCtrlBarWidth + IMPL_DIALOG_OFFSET;
     157             : 
     158           0 :         vcl::Window* pChild2 = GetWindow( GetWindowType::FirstChild );
     159           0 :         while ( pChild2 )
     160             :         {
     161           0 :             if ( pChild2->IsVisible() && (pChild2 != mpViewWindow) )
     162             :             {
     163           0 :                 if ( pChild2 == pTabControl )
     164           0 :                     bTabCtrl = true;
     165           0 :                 else if ( bTabCtrl )
     166             :                 {
     167           0 :                     if ( !nLines )
     168           0 :                         nLines = 1;
     169             : 
     170           0 :                     if ( nX+aCtrlSize.Width()-IMPL_DIALOG_OFFSET > (aTabSize.Width()+nBtnEx) )
     171             :                     {
     172           0 :                         nY += aCtrlSize.Height()+IMPL_DIALOG_OFFSET;
     173           0 :                         nX  = IMPL_DIALOG_OFFSET;
     174           0 :                         nLines++;
     175             :                     }
     176             : 
     177           0 :                     pChild2->SetPosSizePixel( Point( nX, nY ), aCtrlSize );
     178           0 :                     nX += aCtrlSize.Width()+IMPL_DIALOG_OFFSET;
     179             :                 }
     180             :                 else
     181             :                 {
     182           0 :                     Size aChildSize = pChild2->GetSizePixel();
     183           0 :                     pChild2->SetPosPixel( Point( nTopX, (nOffY-aChildSize.Height())/2 ) );
     184           0 :                     nTopX += aChildSize.Width()+2;
     185             :                 }
     186             :             }
     187             : 
     188           0 :             pChild2 = pChild2->GetWindow( GetWindowType::Next );
     189             :         }
     190             : 
     191           0 :         aDlgSize.Height() += nLines * (aCtrlSize.Height()+IMPL_DIALOG_OFFSET);
     192           0 :         SetOutputSizePixel( aDlgSize );
     193             :     }
     194             : 
     195             :     // store offset
     196           0 :     if ( nOffY )
     197             :     {
     198           0 :         Size aDlgSize = GetOutputSizePixel();
     199           0 :         if ( !mpFixedLine )
     200           0 :             mpFixedLine = VclPtr<FixedLine>::Create( this );
     201           0 :         mpFixedLine->SetPosSizePixel( Point( 0, nOffY ),
     202           0 :                                       Size( aDlgSize.Width(), 2 ) );
     203           0 :         mpFixedLine->Show();
     204             :     }
     205             : 
     206           0 :     mbPosControls = false;
     207             : }
     208             : 
     209           0 : TabDialog::TabDialog( vcl::Window* pParent, WinBits nStyle ) :
     210           0 :     Dialog( WINDOW_TABDIALOG )
     211             : {
     212           0 :     ImplInitTabDialogData();
     213           0 :     ImplInit( pParent, nStyle );
     214           0 : }
     215             : 
     216           0 : TabDialog::TabDialog( vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription ) :
     217           0 :     Dialog(pParent, rID, rUIXMLDescription, WINDOW_TABDIALOG)
     218             : {
     219           0 :     ImplInitTabDialogData();
     220           0 : }
     221             : 
     222           0 : TabDialog::~TabDialog()
     223             : {
     224           0 :     disposeOnce();
     225           0 : }
     226             : 
     227           0 : void TabDialog::dispose()
     228             : {
     229           0 :     mpFixedLine.disposeAndClear();
     230           0 :     mpViewWindow.clear();
     231           0 :     Dialog::dispose();
     232           0 : }
     233             : 
     234           0 : void TabDialog::StateChanged( StateChangedType nType )
     235             : {
     236           0 :     if ( nType == StateChangedType::InitShow )
     237             :     {
     238             :         // Calculate the Layout only for the initialized state
     239           0 :         if ( mbPosControls )
     240           0 :             ImplPosControls();
     241             :     }
     242           0 :     Dialog::StateChanged( nType );
     243         801 : }
     244             : 
     245             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11