merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / animations / DialogListBox.cxx
blob8dc54b6313348e119176aeaa00a8aa8bc084c96b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DialogListBox.cxx,v $
10 * $Revision: 1.7 $
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"
35 namespace sd
38 DialogListBox::DialogListBox( Window* pParent, WinBits nWinStyle ) :
39 Control( pParent, nWinStyle ),
40 mpChild( 0 )
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 );
50 mbVScroll = false;
51 mbHScroll = false;
52 mbAutoHScroll = ( nWinStyle & WB_AUTOHSCROLL ) ? true : false;
55 // -----------------------------------------------------------------------
57 DialogListBox::~DialogListBox()
59 delete mpHScrollBar;
60 delete mpVScrollBar;
61 delete mpScrollBarBox;
62 delete mpChild;
65 // -----------------------------------------------------------------------
67 void DialogListBox::SetChildWindow( Window* pChild, const Size& rMinSize )
69 if( mpChild )
70 delete mpChild;
72 mpChild = pChild;
73 maMinSize = rMinSize;
74 ImplResizeControls();
75 ImplCheckScrollBars();
78 // -----------------------------------------------------------------------
80 void DialogListBox::GetFocus()
82 if( mpChild )
83 mpChild->GrabFocus();
86 // -----------------------------------------------------------------------
88 ::Window* DialogListBox::GetPreferredKeyInputWindow()
90 if( mpChild )
91 return mpChild;
92 else
93 return this;
96 // -----------------------------------------------------------------------
98 void DialogListBox::Resize()
100 Control::Resize();
101 ImplResizeControls();
102 ImplCheckScrollBars();
105 // -----------------------------------------------------------------------
107 IMPL_LINK( DialogListBox, ScrollBarHdl, ScrollBar*, EMPTYARG )
109 ImplResizeChild();
110 return 1;
113 // -----------------------------------------------------------------------
115 void DialogListBox::ImplCheckScrollBars()
117 bool bArrange = false;
119 Size aOutSz = GetOutputSizePixel();
121 // vert. ScrollBar
122 if( aOutSz.Height() < maMinSize.Height() )
124 if( !mbVScroll )
125 bArrange = true;
126 mbVScroll = true;
128 else
130 if( mbVScroll )
131 bArrange = true;
132 mbVScroll = false;
135 // horz. ScrollBar
136 if( mbAutoHScroll )
138 long nWidth = aOutSz.Width();
139 if ( mbVScroll )
140 nWidth -= mpVScrollBar->GetSizePixel().Width();
141 if( nWidth < maMinSize.Width() )
143 if( !mbHScroll )
144 bArrange = true;
145 mbHScroll = true;
147 if ( !mbVScroll )
149 int nHeight = aOutSz.Height() - mpHScrollBar->GetSizePixel().Height();
150 if( nHeight < maMinSize.Height() )
152 if( !mbVScroll )
153 bArrange = true;
154 mbVScroll = true;
158 else
160 if( mbHScroll )
161 bArrange = true;
162 mbHScroll = false;
166 if( bArrange )
167 ImplResizeControls();
169 ImplInitScrollBars();
172 // -----------------------------------------------------------------------
174 void DialogListBox::ImplInitScrollBars()
176 if( mpChild )
178 Size aOutSize( GetOutputSizePixel() );
179 if( mbHScroll ) aOutSize.Height() -= mpHScrollBar->GetSizePixel().Height();
180 if( mbVScroll ) aOutSize.Width() -= mpVScrollBar->GetSizePixel().Width();
182 if ( mbVScroll )
184 mpVScrollBar->SetRangeMax( maMinSize.Height() );
185 mpVScrollBar->SetVisibleSize( aOutSize.Height() );
186 mpVScrollBar->SetPageSize( 16 );
189 if ( mbHScroll )
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;
207 if ( mbVScroll )
208 maInnerSize.Width() -= nSBWidth;
209 if ( mbHScroll )
210 maInnerSize.Height() -= nSBWidth;
212 // ScrollBarBox
213 if( mbVScroll && mbHScroll )
215 Point aBoxPos( maInnerSize.Width(), maInnerSize.Height() );
216 mpScrollBarBox->SetPosSizePixel( aBoxPos, Size( nSBWidth, nSBWidth ) );
217 mpScrollBarBox->Show();
219 else
221 mpScrollBarBox->Hide();
224 // vert. ScrollBar
225 if( mbVScroll )
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();
232 else
234 mpVScrollBar->Hide();
237 // horz. ScrollBar
238 if( mbHScroll )
240 Point aHPos( 0, aOutSz.Height() - nSBWidth );
241 mpHScrollBar->SetPosSizePixel( aHPos, Size( maInnerSize.Width(), nSBWidth ) );
242 mpHScrollBar->Show();
244 else
246 mpHScrollBar->Hide();
249 ImplResizeChild();
252 void DialogListBox::ImplResizeChild()
254 Point aWinPos;
255 Size aSize( maInnerSize );
257 int nOffset;
258 if( mbHScroll )
260 nOffset = mpHScrollBar->GetThumbPos();
261 aWinPos.X() = -nOffset;
262 aSize.Width() += nOffset;
265 if( mbVScroll )
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() );
295 Invalidate();
297 else if ( nType == STATE_CHANGE_ZOOM )
299 mpChild->SetZoom( GetZoom() );
300 Resize();
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 )
326 long nDone = 0;
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 );
343 } // namespace sd