1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filectrl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _SV_FIELCTRL_CXX
35 #include <tools/urlobj.hxx>
36 #include <svtools/svtdata.hxx>
37 #include <filectrl.hxx>
38 #ifndef _SV_FILECTRL_HRC
39 #include <filectrl.hrc>
45 // =======================================================================
47 FileControl::FileControl( Window
* pParent
, WinBits nStyle
, FileControlMode nFlags
) :
48 Window( pParent
, nStyle
|WB_DIALOGCONTROL
),
49 maEdit( this, (nStyle
&(~WB_BORDER
))|WB_NOTABSTOP
),
50 maButton( this, (nStyle
&(~WB_BORDER
))|WB_NOLIGHTBORDER
|WB_NOPOINTERFOCUS
|WB_NOTABSTOP
),
51 maButtonText( SvtResId( STR_FILECTRL_BUTTONTEXT
) ),
53 mnInternalFlags( FILECTRL_ORIGINALBUTTONTEXT
)
55 maButton
.SetClickHdl( LINK( this, FileControl
, ButtonHdl
) );
61 SetCompoundControl( TRUE
);
63 SetStyle( ImplInitStyle( GetStyle() ) );
66 // -----------------------------------------------------------------------
68 WinBits
FileControl::ImplInitStyle( WinBits nStyle
)
70 if ( !( nStyle
& WB_NOTABSTOP
) )
72 maEdit
.SetStyle( (maEdit
.GetStyle()|WB_TABSTOP
)&(~WB_NOTABSTOP
) );
73 maButton
.SetStyle( (maButton
.GetStyle()|WB_TABSTOP
)&(~WB_NOTABSTOP
) );
77 maEdit
.SetStyle( (maEdit
.GetStyle()|WB_NOTABSTOP
)&(~WB_TABSTOP
) );
78 maButton
.SetStyle( (maButton
.GetStyle()|WB_NOTABSTOP
)&(~WB_TABSTOP
) );
81 if ( !(nStyle
& WB_NOGROUP
) )
84 if ( !(nStyle
& WB_NOBORDER
) )
87 nStyle
&= ~WB_TABSTOP
;
92 // -----------------------------------------------------------------------
94 FileControl::~FileControl()
98 // -----------------------------------------------------------------------
100 void FileControl::SetText( const XubString
& rStr
)
102 maEdit
.SetText( rStr
);
103 if ( mnFlags
& FILECTRL_RESIZEBUTTONBYPATHLEN
)
107 // -----------------------------------------------------------------------
109 XubString
FileControl::GetText() const
111 return maEdit
.GetText();
114 // -----------------------------------------------------------------------
116 void FileControl::StateChanged( StateChangedType nType
)
118 if ( nType
== STATE_CHANGE_ENABLE
)
120 maEdit
.Enable( IsEnabled() );
121 maButton
.Enable( IsEnabled() );
123 else if ( nType
== STATE_CHANGE_ZOOM
)
125 GetEdit().SetZoom( GetZoom() );
126 GetButton().SetZoom( GetZoom() );
128 else if ( nType
== STATE_CHANGE_STYLE
)
130 SetStyle( ImplInitStyle( GetStyle() ) );
132 else if ( nType
== STATE_CHANGE_CONTROLFONT
)
134 GetEdit().SetControlFont( GetControlFont() );
135 // Fuer den Button nur die Hoehe uebernehmen, weil in
136 // HTML immer Courier eingestellt wird.
137 Font aFont
= GetButton().GetControlFont();
138 aFont
.SetSize( GetControlFont().GetSize() );
139 GetButton().SetControlFont( aFont
);
141 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
143 GetEdit().SetControlForeground( GetControlForeground() );
144 GetButton().SetControlForeground( GetControlForeground() );
146 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
148 GetEdit().SetControlBackground( GetControlBackground() );
149 GetButton().SetControlBackground( GetControlBackground() );
151 Window::StateChanged( nType
);
154 // -----------------------------------------------------------------------
156 void FileControl::Resize()
158 static long ButtonBorder
= 10;
160 if( mnInternalFlags
& FILECTRL_INRESIZE
)
162 mnInternalFlags
|= FILECTRL_INRESIZE
;//InResize = TRUE
164 Size aOutSz
= GetOutputSizePixel();
165 long nButtonTextWidth
= maButton
.GetTextWidth( maButtonText
);
166 if ( ((mnInternalFlags
& FILECTRL_ORIGINALBUTTONTEXT
) == 0) ||
167 ( nButtonTextWidth
< aOutSz
.Width()/3 &&
168 ( mnFlags
& FILECTRL_RESIZEBUTTONBYPATHLEN
169 ? ( maEdit
.GetTextWidth( maEdit
.GetText() )
170 <= aOutSz
.Width() - nButtonTextWidth
- ButtonBorder
)
174 maButton
.SetText( maButtonText
);
178 XubString
aSmallText( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
179 maButton
.SetText( aSmallText
);
180 nButtonTextWidth
= maButton
.GetTextWidth( aSmallText
);
183 long nButtonWidth
= nButtonTextWidth
+ButtonBorder
;
184 maEdit
.SetPosSizePixel( 0, 0, aOutSz
.Width()-nButtonWidth
, aOutSz
.Height() );
185 maButton
.SetPosSizePixel( aOutSz
.Width()-nButtonWidth
, 0, nButtonWidth
, aOutSz
.Height() );
187 mnInternalFlags
&= ~FILECTRL_INRESIZE
; //InResize = FALSE
190 // -----------------------------------------------------------------------
192 IMPL_LINK( FileControl
, ButtonHdl
, PushButton
*, EMPTYARG
)
199 // -----------------------------------------------------------------------
201 void FileControl::GetFocus()
206 // -----------------------------------------------------------------------
208 void FileControl::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, ULONG nFlags
)
210 WinBits nOldEditStyle
= GetEdit().GetStyle();
211 if ( GetStyle() & WB_BORDER
)
212 GetEdit().SetStyle( nOldEditStyle
|WB_BORDER
);
213 GetEdit().Draw( pDev
, rPos
, rSize
, nFlags
);
214 if ( GetStyle() & WB_BORDER
)
215 GetEdit().SetStyle( nOldEditStyle
);
218 // -----------------------------------------------------------------------
220 void FileControl::SetButtonText( const XubString
& rStr
)
222 mnInternalFlags
&= ~FILECTRL_ORIGINALBUTTONTEXT
;
227 // -----------------------------------------------------------------------
229 void FileControl::ResetButtonText()
231 mnInternalFlags
|= FILECTRL_ORIGINALBUTTONTEXT
;
232 maButtonText
= XubString( SvtResId( STR_FILECTRL_BUTTONTEXT
) );