CWS-TOOLING: integrate CWS os150
[LibreOffice.git] / sd / source / ui / animations / DialogListBox.cxx
blob83e4cbdd4d6548118fb4466677b6751891132c71
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"
32 namespace sd
35 DialogListBox::DialogListBox( Window* pParent, WinBits nWinStyle ) :
36 Control( pParent, nWinStyle ),
37 mpChild( 0 )
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 );
47 mbVScroll = false;
48 mbHScroll = false;
49 mbAutoHScroll = ( nWinStyle & WB_AUTOHSCROLL ) ? true : false;
52 // -----------------------------------------------------------------------
54 DialogListBox::~DialogListBox()
56 delete mpHScrollBar;
57 delete mpVScrollBar;
58 delete mpScrollBarBox;
59 delete mpChild;
62 // -----------------------------------------------------------------------
64 void DialogListBox::SetChildWindow( Window* pChild, const Size& rMinSize )
66 if( mpChild )
67 delete mpChild;
69 mpChild = pChild;
70 maMinSize = rMinSize;
71 ImplResizeControls();
72 ImplCheckScrollBars();
75 // -----------------------------------------------------------------------
77 void DialogListBox::GetFocus()
79 if( mpChild )
80 mpChild->GrabFocus();
83 // -----------------------------------------------------------------------
85 ::Window* DialogListBox::GetPreferredKeyInputWindow()
87 if( mpChild )
88 return mpChild;
89 else
90 return this;
93 // -----------------------------------------------------------------------
95 void DialogListBox::Resize()
97 Control::Resize();
98 ImplResizeControls();
99 ImplCheckScrollBars();
102 // -----------------------------------------------------------------------
104 IMPL_LINK( DialogListBox, ScrollBarHdl, ScrollBar*, EMPTYARG )
106 ImplResizeChild();
107 return 1;
110 // -----------------------------------------------------------------------
112 void DialogListBox::ImplCheckScrollBars()
114 bool bArrange = false;
116 Size aOutSz = GetOutputSizePixel();
118 // vert. ScrollBar
119 if( aOutSz.Height() < maMinSize.Height() )
121 if( !mbVScroll )
122 bArrange = true;
123 mbVScroll = true;
125 else
127 if( mbVScroll )
128 bArrange = true;
129 mbVScroll = false;
132 // horz. ScrollBar
133 if( mbAutoHScroll )
135 long nWidth = aOutSz.Width();
136 if ( mbVScroll )
137 nWidth -= mpVScrollBar->GetSizePixel().Width();
138 if( nWidth < maMinSize.Width() )
140 if( !mbHScroll )
141 bArrange = true;
142 mbHScroll = true;
144 if ( !mbVScroll )
146 int nHeight = aOutSz.Height() - mpHScrollBar->GetSizePixel().Height();
147 if( nHeight < maMinSize.Height() )
149 if( !mbVScroll )
150 bArrange = true;
151 mbVScroll = true;
155 else
157 if( mbHScroll )
158 bArrange = true;
159 mbHScroll = false;
163 if( bArrange )
164 ImplResizeControls();
166 ImplInitScrollBars();
169 // -----------------------------------------------------------------------
171 void DialogListBox::ImplInitScrollBars()
173 if( mpChild )
175 Size aOutSize( GetOutputSizePixel() );
176 if( mbHScroll ) aOutSize.Height() -= mpHScrollBar->GetSizePixel().Height();
177 if( mbVScroll ) aOutSize.Width() -= mpVScrollBar->GetSizePixel().Width();
179 if ( mbVScroll )
181 mpVScrollBar->SetRangeMax( maMinSize.Height() );
182 mpVScrollBar->SetVisibleSize( aOutSize.Height() );
183 mpVScrollBar->SetPageSize( 16 );
186 if ( mbHScroll )
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;
204 if ( mbVScroll )
205 maInnerSize.Width() -= nSBWidth;
206 if ( mbHScroll )
207 maInnerSize.Height() -= nSBWidth;
209 // ScrollBarBox
210 if( mbVScroll && mbHScroll )
212 Point aBoxPos( maInnerSize.Width(), maInnerSize.Height() );
213 mpScrollBarBox->SetPosSizePixel( aBoxPos, Size( nSBWidth, nSBWidth ) );
214 mpScrollBarBox->Show();
216 else
218 mpScrollBarBox->Hide();
221 // vert. ScrollBar
222 if( mbVScroll )
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();
229 else
231 mpVScrollBar->Hide();
234 // horz. ScrollBar
235 if( mbHScroll )
237 Point aHPos( 0, aOutSz.Height() - nSBWidth );
238 mpHScrollBar->SetPosSizePixel( aHPos, Size( maInnerSize.Width(), nSBWidth ) );
239 mpHScrollBar->Show();
241 else
243 mpHScrollBar->Hide();
246 ImplResizeChild();
249 void DialogListBox::ImplResizeChild()
251 Point aWinPos;
252 Size aSize( maInnerSize );
254 int nOffset;
255 if( mbHScroll )
257 nOffset = mpHScrollBar->GetThumbPos();
258 aWinPos.X() = -nOffset;
259 aSize.Width() += nOffset;
262 if( mbVScroll )
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() );
292 Invalidate();
294 else if ( nType == STATE_CHANGE_ZOOM )
296 mpChild->SetZoom( GetZoom() );
297 Resize();
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 )
323 long nDone = 0;
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 );
340 } // namespace sd