1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #define _SV_FIELCTRL_CXX 32*cdf0e10cSrcweir #include <tools/urlobj.hxx> 33*cdf0e10cSrcweir #include <svtools/svtdata.hxx> 34*cdf0e10cSrcweir #include <svtools/filectrl.hxx> 35*cdf0e10cSrcweir #include <filectrl.hrc> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // ======================================================================= 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir FileControl::FileControl( Window* pParent, WinBits nStyle, FileControlMode nFlags ) : 40*cdf0e10cSrcweir Window( pParent, nStyle|WB_DIALOGCONTROL ), 41*cdf0e10cSrcweir maEdit( this, (nStyle&(~WB_BORDER))|WB_NOTABSTOP ), 42*cdf0e10cSrcweir maButton( this, (nStyle&(~WB_BORDER))|WB_NOLIGHTBORDER|WB_NOPOINTERFOCUS|WB_NOTABSTOP ), 43*cdf0e10cSrcweir maButtonText( SvtResId( STR_FILECTRL_BUTTONTEXT ) ), 44*cdf0e10cSrcweir mnFlags( nFlags ), 45*cdf0e10cSrcweir mnInternalFlags( FILECTRL_ORIGINALBUTTONTEXT ) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir maButton.SetClickHdl( LINK( this, FileControl, ButtonHdl ) ); 48*cdf0e10cSrcweir mbOpenDlg = sal_True; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir maButton.Show(); 51*cdf0e10cSrcweir maEdit.Show(); 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir SetCompoundControl( sal_True ); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir SetStyle( ImplInitStyle( GetStyle() ) ); 56*cdf0e10cSrcweir } 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // ----------------------------------------------------------------------- 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir WinBits FileControl::ImplInitStyle( WinBits nStyle ) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir if ( !( nStyle & WB_NOTABSTOP ) ) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir maEdit.SetStyle( (maEdit.GetStyle()|WB_TABSTOP)&(~WB_NOTABSTOP) ); 65*cdf0e10cSrcweir maButton.SetStyle( (maButton.GetStyle()|WB_TABSTOP)&(~WB_NOTABSTOP) ); 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir else 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir maEdit.SetStyle( (maEdit.GetStyle()|WB_NOTABSTOP)&(~WB_TABSTOP) ); 70*cdf0e10cSrcweir maButton.SetStyle( (maButton.GetStyle()|WB_NOTABSTOP)&(~WB_TABSTOP) ); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir const WinBits nAlignmentStyle = ( WB_TOP | WB_VCENTER | WB_BOTTOM ); 74*cdf0e10cSrcweir maEdit.SetStyle( ( maEdit.GetStyle() & ~nAlignmentStyle ) | ( nStyle & nAlignmentStyle ) ); 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir if ( !(nStyle & WB_NOGROUP) ) 77*cdf0e10cSrcweir nStyle |= WB_GROUP; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir if ( !(nStyle & WB_NOBORDER ) ) 80*cdf0e10cSrcweir nStyle |= WB_BORDER; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir nStyle &= ~WB_TABSTOP; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir return nStyle; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir // ----------------------------------------------------------------------- 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir FileControl::~FileControl() 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // ----------------------------------------------------------------------- 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir void FileControl::SetText( const XubString& rStr ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir maEdit.SetText( rStr ); 98*cdf0e10cSrcweir if ( mnFlags & FILECTRL_RESIZEBUTTONBYPATHLEN ) 99*cdf0e10cSrcweir Resize(); 100*cdf0e10cSrcweir } 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // ----------------------------------------------------------------------- 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir XubString FileControl::GetText() const 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir return maEdit.GetText(); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // ----------------------------------------------------------------------- 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir void FileControl::StateChanged( StateChangedType nType ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir if ( nType == STATE_CHANGE_ENABLE ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir maEdit.Enable( IsEnabled() ); 116*cdf0e10cSrcweir maButton.Enable( IsEnabled() ); 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_ZOOM ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir GetEdit().SetZoom( GetZoom() ); 121*cdf0e10cSrcweir GetButton().SetZoom( GetZoom() ); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_STYLE ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir SetStyle( ImplInitStyle( GetStyle() ) ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFONT ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir GetEdit().SetControlFont( GetControlFont() ); 130*cdf0e10cSrcweir // Fuer den Button nur die Hoehe uebernehmen, weil in 131*cdf0e10cSrcweir // HTML immer Courier eingestellt wird. 132*cdf0e10cSrcweir Font aFont = GetButton().GetControlFont(); 133*cdf0e10cSrcweir aFont.SetSize( GetControlFont().GetSize() ); 134*cdf0e10cSrcweir GetButton().SetControlFont( aFont ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir GetEdit().SetControlForeground( GetControlForeground() ); 139*cdf0e10cSrcweir GetButton().SetControlForeground( GetControlForeground() ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir GetEdit().SetControlBackground( GetControlBackground() ); 144*cdf0e10cSrcweir GetButton().SetControlBackground( GetControlBackground() ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir Window::StateChanged( nType ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir // ----------------------------------------------------------------------- 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir void FileControl::Resize() 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir static long ButtonBorder = 10; 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if( mnInternalFlags & FILECTRL_INRESIZE ) 156*cdf0e10cSrcweir return; 157*cdf0e10cSrcweir mnInternalFlags |= FILECTRL_INRESIZE;//InResize = sal_True 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir Size aOutSz = GetOutputSizePixel(); 160*cdf0e10cSrcweir long nButtonTextWidth = maButton.GetTextWidth( maButtonText ); 161*cdf0e10cSrcweir if ( ((mnInternalFlags & FILECTRL_ORIGINALBUTTONTEXT) == 0) || 162*cdf0e10cSrcweir ( nButtonTextWidth < aOutSz.Width()/3 && 163*cdf0e10cSrcweir ( mnFlags & FILECTRL_RESIZEBUTTONBYPATHLEN 164*cdf0e10cSrcweir ? ( maEdit.GetTextWidth( maEdit.GetText() ) 165*cdf0e10cSrcweir <= aOutSz.Width() - nButtonTextWidth - ButtonBorder ) 166*cdf0e10cSrcweir : sal_True ) ) 167*cdf0e10cSrcweir ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir maButton.SetText( maButtonText ); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir else 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir XubString aSmallText( RTL_CONSTASCII_USTRINGPARAM( "..." ) ); 174*cdf0e10cSrcweir maButton.SetText( aSmallText ); 175*cdf0e10cSrcweir nButtonTextWidth = maButton.GetTextWidth( aSmallText ); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir long nButtonWidth = nButtonTextWidth+ButtonBorder; 179*cdf0e10cSrcweir maEdit.SetPosSizePixel( 0, 0, aOutSz.Width()-nButtonWidth, aOutSz.Height() ); 180*cdf0e10cSrcweir maButton.SetPosSizePixel( aOutSz.Width()-nButtonWidth, 0, nButtonWidth, aOutSz.Height() ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir mnInternalFlags &= ~FILECTRL_INRESIZE; //InResize = sal_False 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // ----------------------------------------------------------------------- 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir IMPL_LINK( FileControl, ButtonHdl, PushButton*, EMPTYARG ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir ImplBrowseFile( ); 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir return 0; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // ----------------------------------------------------------------------- 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir void FileControl::GetFocus() 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir maEdit.GrabFocus(); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // ----------------------------------------------------------------------- 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir void FileControl::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir WinBits nOldEditStyle = GetEdit().GetStyle(); 206*cdf0e10cSrcweir if ( GetStyle() & WB_BORDER ) 207*cdf0e10cSrcweir GetEdit().SetStyle( nOldEditStyle|WB_BORDER ); 208*cdf0e10cSrcweir GetEdit().Draw( pDev, rPos, rSize, nFlags ); 209*cdf0e10cSrcweir if ( GetStyle() & WB_BORDER ) 210*cdf0e10cSrcweir GetEdit().SetStyle( nOldEditStyle ); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir // ----------------------------------------------------------------------- 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir void FileControl::SetButtonText( const XubString& rStr ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir mnInternalFlags &= ~FILECTRL_ORIGINALBUTTONTEXT; 218*cdf0e10cSrcweir maButtonText = rStr; 219*cdf0e10cSrcweir Resize(); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir // ----------------------------------------------------------------------- 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir void FileControl::ResetButtonText() 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir mnInternalFlags |= FILECTRL_ORIGINALBUTTONTEXT; 227*cdf0e10cSrcweir maButtonText = XubString( SvtResId( STR_FILECTRL_BUTTONTEXT ) ); 228*cdf0e10cSrcweir Resize(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir 232