1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svtools/svtresid.hxx>
21 #include <svtools/filectrl.hxx>
22 #include <filectrl.hrc>
24 // =======================================================================
26 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
) ),
32 mnInternalFlags( FILECTRL_ORIGINALBUTTONTEXT
)
34 maButton
.SetClickHdl( LINK( this, FileControl
, ButtonHdl
) );
40 SetCompoundControl( sal_True
);
42 SetStyle( ImplInitStyle( GetStyle() ) );
45 // -----------------------------------------------------------------------
47 WinBits
FileControl::ImplInitStyle( WinBits nStyle
)
49 if ( !( nStyle
& WB_NOTABSTOP
) )
51 maEdit
.SetStyle( (maEdit
.GetStyle()|WB_TABSTOP
)&(~WB_NOTABSTOP
) );
52 maButton
.SetStyle( (maButton
.GetStyle()|WB_TABSTOP
)&(~WB_NOTABSTOP
) );
56 maEdit
.SetStyle( (maEdit
.GetStyle()|WB_NOTABSTOP
)&(~WB_TABSTOP
) );
57 maButton
.SetStyle( (maButton
.GetStyle()|WB_NOTABSTOP
)&(~WB_TABSTOP
) );
60 const WinBits nAlignmentStyle
= ( WB_TOP
| WB_VCENTER
| WB_BOTTOM
);
61 maEdit
.SetStyle( ( maEdit
.GetStyle() & ~nAlignmentStyle
) | ( nStyle
& nAlignmentStyle
) );
63 if ( !(nStyle
& WB_NOGROUP
) )
66 if ( !(nStyle
& WB_NOBORDER
) )
69 nStyle
&= ~WB_TABSTOP
;
74 // -----------------------------------------------------------------------
76 FileControl::~FileControl()
80 // -----------------------------------------------------------------------
82 void FileControl::SetText( const OUString
& rStr
)
84 maEdit
.SetText( rStr
);
85 if ( mnFlags
& FILECTRL_RESIZEBUTTONBYPATHLEN
)
89 // -----------------------------------------------------------------------
91 OUString
FileControl::GetText() const
93 return maEdit
.GetText();
96 // -----------------------------------------------------------------------
98 void FileControl::StateChanged( StateChangedType nType
)
100 if ( nType
== STATE_CHANGE_ENABLE
)
102 maEdit
.Enable( IsEnabled() );
103 maButton
.Enable( IsEnabled() );
105 else if ( nType
== STATE_CHANGE_ZOOM
)
107 GetEdit().SetZoom( GetZoom() );
108 GetButton().SetZoom( GetZoom() );
110 else if ( nType
== STATE_CHANGE_STYLE
)
112 SetStyle( ImplInitStyle( GetStyle() ) );
114 else if ( nType
== STATE_CHANGE_CONTROLFONT
)
116 GetEdit().SetControlFont( GetControlFont() );
117 // Fuer den Button nur die Hoehe uebernehmen, weil in
118 // HTML immer Courier eingestellt wird.
119 Font aFont
= GetButton().GetControlFont();
120 aFont
.SetSize( GetControlFont().GetSize() );
121 GetButton().SetControlFont( aFont
);
123 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
125 GetEdit().SetControlForeground( GetControlForeground() );
126 GetButton().SetControlForeground( GetControlForeground() );
128 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
130 GetEdit().SetControlBackground( GetControlBackground() );
131 GetButton().SetControlBackground( GetControlBackground() );
133 Window::StateChanged( nType
);
136 // -----------------------------------------------------------------------
138 void FileControl::Resize()
140 static long ButtonBorder
= 10;
142 if( mnInternalFlags
& FILECTRL_INRESIZE
)
144 mnInternalFlags
|= FILECTRL_INRESIZE
;//InResize = sal_True
146 Size aOutSz
= GetOutputSizePixel();
147 long nButtonTextWidth
= maButton
.GetTextWidth( maButtonText
);
148 if ( ((mnInternalFlags
& FILECTRL_ORIGINALBUTTONTEXT
) == 0) ||
149 ( nButtonTextWidth
< aOutSz
.Width()/3 &&
150 ( mnFlags
& FILECTRL_RESIZEBUTTONBYPATHLEN
151 ? ( maEdit
.GetTextWidth( maEdit
.GetText() )
152 <= aOutSz
.Width() - nButtonTextWidth
- ButtonBorder
)
156 maButton
.SetText( maButtonText
);
160 OUString
aSmallText( "..." );
161 maButton
.SetText( aSmallText
);
162 nButtonTextWidth
= maButton
.GetTextWidth( aSmallText
);
165 long nButtonWidth
= nButtonTextWidth
+ButtonBorder
;
166 maEdit
.setPosSizePixel( 0, 0, aOutSz
.Width()-nButtonWidth
, aOutSz
.Height() );
167 maButton
.setPosSizePixel( aOutSz
.Width()-nButtonWidth
, 0, nButtonWidth
, aOutSz
.Height() );
169 mnInternalFlags
&= ~FILECTRL_INRESIZE
; //InResize = sal_False
172 // -----------------------------------------------------------------------
174 IMPL_LINK_NOARG(FileControl
, ButtonHdl
)
181 // -----------------------------------------------------------------------
183 void FileControl::GetFocus()
188 // -----------------------------------------------------------------------
190 void FileControl::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, sal_uLong nFlags
)
192 WinBits nOldEditStyle
= GetEdit().GetStyle();
193 if ( GetStyle() & WB_BORDER
)
194 GetEdit().SetStyle( nOldEditStyle
|WB_BORDER
);
195 GetEdit().Draw( pDev
, rPos
, rSize
, nFlags
);
196 if ( GetStyle() & WB_BORDER
)
197 GetEdit().SetStyle( nOldEditStyle
);
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */