1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 #include "DialogListBox.hxx"
35 DialogListBox::DialogListBox( Window
* pParent
, WinBits nWinStyle
) :
36 Control( pParent
, nWinStyle
),
39 mpVScrollBar
= new ScrollBar( this, WB_VSCROLL
| WB_DRAG
);
40 mpHScrollBar
= new ScrollBar( this, WB_HSCROLL
| WB_DRAG
);
41 mpScrollBarBox
= new ScrollBarBox( this );
43 Link
aLink( LINK( this, DialogListBox
, ScrollBarHdl
) );
44 mpVScrollBar
->SetScrollHdl( aLink
);
45 mpHScrollBar
->SetScrollHdl( aLink
);
49 mbAutoHScroll
= ( nWinStyle
& WB_AUTOHSCROLL
) ? true : false;
52 // -----------------------------------------------------------------------
54 DialogListBox::~DialogListBox()
58 delete mpScrollBarBox
;
62 // -----------------------------------------------------------------------
64 void DialogListBox::SetChildWindow( Window
* pChild
, const Size
& rMinSize
)
72 ImplCheckScrollBars();
75 // -----------------------------------------------------------------------
77 void DialogListBox::GetFocus()
83 // -----------------------------------------------------------------------
85 ::Window
* DialogListBox::GetPreferredKeyInputWindow()
93 // -----------------------------------------------------------------------
95 void DialogListBox::Resize()
99 ImplCheckScrollBars();
102 // -----------------------------------------------------------------------
104 IMPL_LINK( DialogListBox
, ScrollBarHdl
, ScrollBar
*, EMPTYARG
)
110 // -----------------------------------------------------------------------
112 void DialogListBox::ImplCheckScrollBars()
114 bool bArrange
= false;
116 Size aOutSz
= GetOutputSizePixel();
119 if( aOutSz
.Height() < maMinSize
.Height() )
135 long nWidth
= aOutSz
.Width();
137 nWidth
-= mpVScrollBar
->GetSizePixel().Width();
138 if( nWidth
< maMinSize
.Width() )
146 int nHeight
= aOutSz
.Height() - mpHScrollBar
->GetSizePixel().Height();
147 if( nHeight
< maMinSize
.Height() )
164 ImplResizeControls();
166 ImplInitScrollBars();
169 // -----------------------------------------------------------------------
171 void DialogListBox::ImplInitScrollBars()
175 Size
aOutSize( GetOutputSizePixel() );
176 if( mbHScroll
) aOutSize
.Height() -= mpHScrollBar
->GetSizePixel().Height();
177 if( mbVScroll
) aOutSize
.Width() -= mpVScrollBar
->GetSizePixel().Width();
181 mpVScrollBar
->SetRangeMax( maMinSize
.Height() );
182 mpVScrollBar
->SetVisibleSize( aOutSize
.Height() );
183 mpVScrollBar
->SetPageSize( 16 );
188 mpHScrollBar
->SetRangeMax( maMinSize
.Width() );
189 mpHScrollBar
->SetVisibleSize( aOutSize
.Width() );
190 mpHScrollBar
->SetPageSize( 16 );
195 // -----------------------------------------------------------------------
197 void DialogListBox::ImplResizeControls()
199 Size
aOutSz( GetOutputSizePixel() );
200 long nSBWidth
= GetSettings().GetStyleSettings().GetScrollBarSize();
201 nSBWidth
= CalcZoom( nSBWidth
);
203 maInnerSize
= aOutSz
;
205 maInnerSize
.Width() -= nSBWidth
;
207 maInnerSize
.Height() -= nSBWidth
;
210 if( mbVScroll
&& mbHScroll
)
212 Point
aBoxPos( maInnerSize
.Width(), maInnerSize
.Height() );
213 mpScrollBarBox
->SetPosSizePixel( aBoxPos
, Size( nSBWidth
, nSBWidth
) );
214 mpScrollBarBox
->Show();
218 mpScrollBarBox
->Hide();
224 // Scrollbar on left or right side?
225 Point
aVPos( aOutSz
.Width() - nSBWidth
, 0 );
226 mpVScrollBar
->SetPosSizePixel( aVPos
, Size( nSBWidth
, maInnerSize
.Height() ) );
227 mpVScrollBar
->Show();
231 mpVScrollBar
->Hide();
237 Point
aHPos( 0, aOutSz
.Height() - nSBWidth
);
238 mpHScrollBar
->SetPosSizePixel( aHPos
, Size( maInnerSize
.Width(), nSBWidth
) );
239 mpHScrollBar
->Show();
243 mpHScrollBar
->Hide();
249 void DialogListBox::ImplResizeChild()
252 Size
aSize( maInnerSize
);
257 nOffset
= mpHScrollBar
->GetThumbPos();
258 aWinPos
.X() = -nOffset
;
259 aSize
.Width() += nOffset
;
264 nOffset
= mpVScrollBar
->GetThumbPos();
265 aWinPos
.Y() = -nOffset
;
266 aSize
.Height() += nOffset
;
269 mpChild
->SetPosSizePixel( aWinPos
, aSize
);
272 // -----------------------------------------------------------------------
274 void DialogListBox::StateChanged( StateChangedType nType
)
276 if ( nType
== STATE_CHANGE_INITSHOW
)
278 ImplCheckScrollBars();
280 else if ( ( nType
== STATE_CHANGE_UPDATEMODE
) || ( nType
== STATE_CHANGE_DATA
) )
282 sal_Bool bUpdate
= IsUpdateMode();
283 mpChild
->SetUpdateMode( bUpdate
);
284 if ( bUpdate
&& IsReallyVisible() )
285 ImplCheckScrollBars();
287 else if( nType
== STATE_CHANGE_ENABLE
)
289 mpHScrollBar
->Enable( IsEnabled() );
290 mpVScrollBar
->Enable( IsEnabled() );
291 mpScrollBarBox
->Enable( IsEnabled() );
294 else if ( nType
== STATE_CHANGE_ZOOM
)
296 mpChild
->SetZoom( GetZoom() );
299 else if ( nType
== STATE_CHANGE_CONTROLFONT
)
301 mpChild
->SetControlFont( GetControlFont() );
303 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
305 mpChild
->SetControlForeground( GetControlForeground() );
307 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
309 mpChild
->SetControlBackground( GetControlBackground() );
311 else if( nType
== STATE_CHANGE_VISIBLE
)
313 mpChild
->Show( IsVisible() );
316 Control::StateChanged( nType
);
319 // -----------------------------------------------------------------------
321 long DialogListBox::Notify( NotifyEvent
& rNEvt
)
324 if ( rNEvt
.GetType() == EVENT_COMMAND
)
326 const CommandEvent
& rCEvt
= *rNEvt
.GetCommandEvent();
327 if ( rCEvt
.GetCommand() == COMMAND_WHEEL
)
329 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
330 if( !pData
->GetModifier() && ( pData
->GetMode() == COMMAND_WHEEL_SCROLL
) )
332 nDone
= HandleScrollCommand( rCEvt
, mpHScrollBar
, mpVScrollBar
);
337 return nDone
? nDone
: Window::Notify( rNEvt
);