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: DialogListBox.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_sd.hxx"
33 #include "DialogListBox.hxx"
38 DialogListBox::DialogListBox( Window
* pParent
, WinBits nWinStyle
) :
39 Control( pParent
, nWinStyle
),
42 mpVScrollBar
= new ScrollBar( this, WB_VSCROLL
| WB_DRAG
);
43 mpHScrollBar
= new ScrollBar( this, WB_HSCROLL
| WB_DRAG
);
44 mpScrollBarBox
= new ScrollBarBox( this );
46 Link
aLink( LINK( this, DialogListBox
, ScrollBarHdl
) );
47 mpVScrollBar
->SetScrollHdl( aLink
);
48 mpHScrollBar
->SetScrollHdl( aLink
);
52 mbAutoHScroll
= ( nWinStyle
& WB_AUTOHSCROLL
) ? true : false;
55 // -----------------------------------------------------------------------
57 DialogListBox::~DialogListBox()
61 delete mpScrollBarBox
;
65 // -----------------------------------------------------------------------
67 void DialogListBox::SetChildWindow( Window
* pChild
, const Size
& rMinSize
)
75 ImplCheckScrollBars();
78 // -----------------------------------------------------------------------
80 void DialogListBox::GetFocus()
86 // -----------------------------------------------------------------------
88 ::Window
* DialogListBox::GetPreferredKeyInputWindow()
96 // -----------------------------------------------------------------------
98 void DialogListBox::Resize()
101 ImplResizeControls();
102 ImplCheckScrollBars();
105 // -----------------------------------------------------------------------
107 IMPL_LINK( DialogListBox
, ScrollBarHdl
, ScrollBar
*, EMPTYARG
)
113 // -----------------------------------------------------------------------
115 void DialogListBox::ImplCheckScrollBars()
117 bool bArrange
= false;
119 Size aOutSz
= GetOutputSizePixel();
122 if( aOutSz
.Height() < maMinSize
.Height() )
138 long nWidth
= aOutSz
.Width();
140 nWidth
-= mpVScrollBar
->GetSizePixel().Width();
141 if( nWidth
< maMinSize
.Width() )
149 int nHeight
= aOutSz
.Height() - mpHScrollBar
->GetSizePixel().Height();
150 if( nHeight
< maMinSize
.Height() )
167 ImplResizeControls();
169 ImplInitScrollBars();
172 // -----------------------------------------------------------------------
174 void DialogListBox::ImplInitScrollBars()
178 Size
aOutSize( GetOutputSizePixel() );
179 if( mbHScroll
) aOutSize
.Height() -= mpHScrollBar
->GetSizePixel().Height();
180 if( mbVScroll
) aOutSize
.Width() -= mpVScrollBar
->GetSizePixel().Width();
184 mpVScrollBar
->SetRangeMax( maMinSize
.Height() );
185 mpVScrollBar
->SetVisibleSize( aOutSize
.Height() );
186 mpVScrollBar
->SetPageSize( 16 );
191 mpHScrollBar
->SetRangeMax( maMinSize
.Width() );
192 mpHScrollBar
->SetVisibleSize( aOutSize
.Width() );
193 mpHScrollBar
->SetPageSize( 16 );
198 // -----------------------------------------------------------------------
200 void DialogListBox::ImplResizeControls()
202 Size
aOutSz( GetOutputSizePixel() );
203 long nSBWidth
= GetSettings().GetStyleSettings().GetScrollBarSize();
204 nSBWidth
= CalcZoom( nSBWidth
);
206 maInnerSize
= aOutSz
;
208 maInnerSize
.Width() -= nSBWidth
;
210 maInnerSize
.Height() -= nSBWidth
;
213 if( mbVScroll
&& mbHScroll
)
215 Point
aBoxPos( maInnerSize
.Width(), maInnerSize
.Height() );
216 mpScrollBarBox
->SetPosSizePixel( aBoxPos
, Size( nSBWidth
, nSBWidth
) );
217 mpScrollBarBox
->Show();
221 mpScrollBarBox
->Hide();
227 // Scrollbar on left or right side?
228 Point
aVPos( aOutSz
.Width() - nSBWidth
, 0 );
229 mpVScrollBar
->SetPosSizePixel( aVPos
, Size( nSBWidth
, maInnerSize
.Height() ) );
230 mpVScrollBar
->Show();
234 mpVScrollBar
->Hide();
240 Point
aHPos( 0, aOutSz
.Height() - nSBWidth
);
241 mpHScrollBar
->SetPosSizePixel( aHPos
, Size( maInnerSize
.Width(), nSBWidth
) );
242 mpHScrollBar
->Show();
246 mpHScrollBar
->Hide();
252 void DialogListBox::ImplResizeChild()
255 Size
aSize( maInnerSize
);
260 nOffset
= mpHScrollBar
->GetThumbPos();
261 aWinPos
.X() = -nOffset
;
262 aSize
.Width() += nOffset
;
267 nOffset
= mpVScrollBar
->GetThumbPos();
268 aWinPos
.Y() = -nOffset
;
269 aSize
.Height() += nOffset
;
272 mpChild
->SetPosSizePixel( aWinPos
, aSize
);
275 // -----------------------------------------------------------------------
277 void DialogListBox::StateChanged( StateChangedType nType
)
279 if ( nType
== STATE_CHANGE_INITSHOW
)
281 ImplCheckScrollBars();
283 else if ( ( nType
== STATE_CHANGE_UPDATEMODE
) || ( nType
== STATE_CHANGE_DATA
) )
285 BOOL bUpdate
= IsUpdateMode();
286 mpChild
->SetUpdateMode( bUpdate
);
287 if ( bUpdate
&& IsReallyVisible() )
288 ImplCheckScrollBars();
290 else if( nType
== STATE_CHANGE_ENABLE
)
292 mpHScrollBar
->Enable( IsEnabled() );
293 mpVScrollBar
->Enable( IsEnabled() );
294 mpScrollBarBox
->Enable( IsEnabled() );
297 else if ( nType
== STATE_CHANGE_ZOOM
)
299 mpChild
->SetZoom( GetZoom() );
302 else if ( nType
== STATE_CHANGE_CONTROLFONT
)
304 mpChild
->SetControlFont( GetControlFont() );
306 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
308 mpChild
->SetControlForeground( GetControlForeground() );
310 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
312 mpChild
->SetControlBackground( GetControlBackground() );
314 else if( nType
== STATE_CHANGE_VISIBLE
)
316 mpChild
->Show( IsVisible() );
319 Control::StateChanged( nType
);
322 // -----------------------------------------------------------------------
324 long DialogListBox::Notify( NotifyEvent
& rNEvt
)
327 if ( rNEvt
.GetType() == EVENT_COMMAND
)
329 const CommandEvent
& rCEvt
= *rNEvt
.GetCommandEvent();
330 if ( rCEvt
.GetCommand() == COMMAND_WHEEL
)
332 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
333 if( !pData
->GetModifier() && ( pData
->GetMode() == COMMAND_WHEEL_SCROLL
) )
335 nDone
= HandleScrollCommand( rCEvt
, mpHScrollBar
, mpVScrollBar
);
340 return nDone
? nDone
: Window::Notify( rNEvt
);