LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/control - filectrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 87 0.0 %
Date: 2012-12-27 Functions: 0 12 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             : #include <svtools/svtresid.hxx>
      21             : #include <svtools/filectrl.hxx>
      22             : #include <filectrl.hrc>
      23             : 
      24             : // =======================================================================
      25             : 
      26           0 : FileControl::FileControl( Window* pParent, WinBits nStyle, FileControlMode nFlags ) :
      27             :     Window( pParent, nStyle|WB_DIALOGCONTROL ),
      28             :     maEdit( this, (nStyle&(~WB_BORDER))|WB_NOTABSTOP ),
      29             :     maButton( this, (nStyle&(~WB_BORDER))|WB_NOLIGHTBORDER|WB_NOPOINTERFOCUS|WB_NOTABSTOP ),
      30             :     maButtonText( SVT_RESSTR(STR_FILECTRL_BUTTONTEXT) ),
      31             :     mnFlags( nFlags ),
      32           0 :     mnInternalFlags( FILECTRL_ORIGINALBUTTONTEXT )
      33             : {
      34           0 :     maButton.SetClickHdl( LINK( this, FileControl, ButtonHdl ) );
      35           0 :     mbOpenDlg = sal_True;
      36             : 
      37           0 :     maButton.Show();
      38           0 :     maEdit.Show();
      39             : 
      40           0 :     SetCompoundControl( sal_True );
      41             : 
      42           0 :     SetStyle( ImplInitStyle( GetStyle() ) );
      43           0 : }
      44             : 
      45             : // -----------------------------------------------------------------------
      46             : 
      47           0 : WinBits FileControl::ImplInitStyle( WinBits nStyle )
      48             : {
      49           0 :     if ( !( nStyle & WB_NOTABSTOP ) )
      50             :     {
      51           0 :         maEdit.SetStyle( (maEdit.GetStyle()|WB_TABSTOP)&(~WB_NOTABSTOP) );
      52           0 :         maButton.SetStyle( (maButton.GetStyle()|WB_TABSTOP)&(~WB_NOTABSTOP) );
      53             :     }
      54             :     else
      55             :     {
      56           0 :         maEdit.SetStyle( (maEdit.GetStyle()|WB_NOTABSTOP)&(~WB_TABSTOP) );
      57           0 :         maButton.SetStyle( (maButton.GetStyle()|WB_NOTABSTOP)&(~WB_TABSTOP) );
      58             :     }
      59             : 
      60           0 :     const WinBits nAlignmentStyle = ( WB_TOP | WB_VCENTER | WB_BOTTOM );
      61           0 :     maEdit.SetStyle( ( maEdit.GetStyle() & ~nAlignmentStyle ) | ( nStyle & nAlignmentStyle ) );
      62             : 
      63           0 :     if ( !(nStyle & WB_NOGROUP) )
      64           0 :         nStyle |= WB_GROUP;
      65             : 
      66           0 :     if ( !(nStyle & WB_NOBORDER ) )
      67           0 :         nStyle |= WB_BORDER;
      68             : 
      69           0 :     nStyle &= ~WB_TABSTOP;
      70             : 
      71           0 :     return nStyle;
      72             : }
      73             : 
      74             : // -----------------------------------------------------------------------
      75             : 
      76           0 : FileControl::~FileControl()
      77             : {
      78           0 : }
      79             : 
      80             : // -----------------------------------------------------------------------
      81             : 
      82           0 : void FileControl::SetText( const XubString& rStr )
      83             : {
      84           0 :     maEdit.SetText( rStr );
      85           0 :     if ( mnFlags & FILECTRL_RESIZEBUTTONBYPATHLEN )
      86           0 :         Resize();
      87           0 : }
      88             : 
      89             : // -----------------------------------------------------------------------
      90             : 
      91           0 : XubString FileControl::GetText() const
      92             : {
      93           0 :     return maEdit.GetText();
      94             : }
      95             : 
      96             : // -----------------------------------------------------------------------
      97             : 
      98           0 : void FileControl::StateChanged( StateChangedType nType )
      99             : {
     100           0 :     if ( nType == STATE_CHANGE_ENABLE )
     101             :     {
     102           0 :         maEdit.Enable( IsEnabled() );
     103           0 :         maButton.Enable( IsEnabled() );
     104             :     }
     105           0 :     else if ( nType == STATE_CHANGE_ZOOM )
     106             :     {
     107           0 :         GetEdit().SetZoom( GetZoom() );
     108           0 :         GetButton().SetZoom( GetZoom() );
     109             :     }
     110           0 :     else if ( nType == STATE_CHANGE_STYLE )
     111             :     {
     112           0 :         SetStyle( ImplInitStyle( GetStyle() ) );
     113             :     }
     114           0 :     else if ( nType == STATE_CHANGE_CONTROLFONT )
     115             :     {
     116           0 :         GetEdit().SetControlFont( GetControlFont() );
     117             :         // Fuer den Button nur die Hoehe uebernehmen, weil in
     118             :         // HTML immer Courier eingestellt wird.
     119           0 :         Font aFont = GetButton().GetControlFont();
     120           0 :         aFont.SetSize( GetControlFont().GetSize() );
     121           0 :         GetButton().SetControlFont( aFont );
     122             :     }
     123           0 :     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
     124             :     {
     125           0 :         GetEdit().SetControlForeground( GetControlForeground() );
     126           0 :         GetButton().SetControlForeground( GetControlForeground() );
     127             :     }
     128           0 :     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
     129             :     {
     130           0 :         GetEdit().SetControlBackground( GetControlBackground() );
     131           0 :         GetButton().SetControlBackground( GetControlBackground() );
     132             :     }
     133           0 :     Window::StateChanged( nType );
     134           0 : }
     135             : 
     136             : // -----------------------------------------------------------------------
     137             : 
     138           0 : void FileControl::Resize()
     139             : {
     140             :     static long ButtonBorder = 10;
     141             : 
     142           0 :     if( mnInternalFlags & FILECTRL_INRESIZE )
     143           0 :         return;
     144           0 :     mnInternalFlags |= FILECTRL_INRESIZE;//InResize = sal_True
     145             : 
     146           0 :     Size aOutSz = GetOutputSizePixel();
     147           0 :     long nButtonTextWidth = maButton.GetTextWidth( maButtonText );
     148           0 :     if ( ((mnInternalFlags & FILECTRL_ORIGINALBUTTONTEXT) == 0) ||
     149           0 :         ( nButtonTextWidth < aOutSz.Width()/3 &&
     150             :         ( mnFlags & FILECTRL_RESIZEBUTTONBYPATHLEN
     151           0 :         ? ( maEdit.GetTextWidth( maEdit.GetText() )
     152           0 :             <= aOutSz.Width() - nButtonTextWidth - ButtonBorder )
     153           0 :         : sal_True ) )
     154             :        )
     155             :     {
     156           0 :         maButton.SetText( maButtonText );
     157             :     }
     158             :     else
     159             :     {
     160           0 :         rtl::OUString aSmallText( "..." );
     161           0 :         maButton.SetText( aSmallText );
     162           0 :         nButtonTextWidth = maButton.GetTextWidth( aSmallText );
     163             :     }
     164             : 
     165           0 :     long nButtonWidth = nButtonTextWidth+ButtonBorder;
     166           0 :     maEdit.setPosSizePixel( 0, 0, aOutSz.Width()-nButtonWidth, aOutSz.Height() );
     167           0 :     maButton.setPosSizePixel( aOutSz.Width()-nButtonWidth, 0, nButtonWidth, aOutSz.Height() );
     168             : 
     169           0 :     mnInternalFlags &= ~FILECTRL_INRESIZE; //InResize = sal_False
     170             : }
     171             : 
     172             : // -----------------------------------------------------------------------
     173             : 
     174           0 : IMPL_LINK_NOARG(FileControl, ButtonHdl)
     175             : {
     176           0 :     ImplBrowseFile( );
     177             : 
     178           0 :     return 0;
     179             : }
     180             : 
     181             : // -----------------------------------------------------------------------
     182             : 
     183           0 : void FileControl::GetFocus()
     184             : {
     185           0 :     maEdit.GrabFocus();
     186           0 : }
     187             : 
     188             : // -----------------------------------------------------------------------
     189             : 
     190           0 : void FileControl::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags )
     191             : {
     192           0 :     WinBits nOldEditStyle = GetEdit().GetStyle();
     193           0 :     if ( GetStyle() & WB_BORDER )
     194           0 :         GetEdit().SetStyle( nOldEditStyle|WB_BORDER );
     195           0 :     GetEdit().Draw( pDev, rPos, rSize, nFlags );
     196           0 :     if ( GetStyle() & WB_BORDER )
     197           0 :         GetEdit().SetStyle( nOldEditStyle );
     198           0 : }
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10