xref: /AOO41X/main/sd/source/ui/animations/DialogListBox.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sd.hxx"
30*cdf0e10cSrcweir #include "DialogListBox.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir namespace sd
33*cdf0e10cSrcweir {
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir DialogListBox::DialogListBox( Window* pParent, WinBits nWinStyle ) :
36*cdf0e10cSrcweir 	Control( pParent, nWinStyle ),
37*cdf0e10cSrcweir 	mpChild( 0 )
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir 	mpVScrollBar	= new ScrollBar( this, WB_VSCROLL | WB_DRAG );
40*cdf0e10cSrcweir 	mpHScrollBar	= new ScrollBar( this, WB_HSCROLL | WB_DRAG );
41*cdf0e10cSrcweir 	mpScrollBarBox	= new ScrollBarBox( this );
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 	Link aLink( LINK( this, DialogListBox, ScrollBarHdl ) );
44*cdf0e10cSrcweir 	mpVScrollBar->SetScrollHdl( aLink );
45*cdf0e10cSrcweir 	mpHScrollBar->SetScrollHdl( aLink );
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 	mbVScroll		= false;
48*cdf0e10cSrcweir 	mbHScroll		= false;
49*cdf0e10cSrcweir 	mbAutoHScroll	= ( nWinStyle & WB_AUTOHSCROLL ) ? true : false;
50*cdf0e10cSrcweir }
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // -----------------------------------------------------------------------
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir DialogListBox::~DialogListBox()
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 	delete mpHScrollBar;
57*cdf0e10cSrcweir 	delete mpVScrollBar;
58*cdf0e10cSrcweir 	delete mpScrollBarBox;
59*cdf0e10cSrcweir 	delete mpChild;
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir // -----------------------------------------------------------------------
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir void DialogListBox::SetChildWindow( Window* pChild, const Size& rMinSize )
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	if( mpChild )
67*cdf0e10cSrcweir 		delete mpChild;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	mpChild = pChild;
70*cdf0e10cSrcweir 	maMinSize = rMinSize;
71*cdf0e10cSrcweir 	ImplResizeControls();
72*cdf0e10cSrcweir 	ImplCheckScrollBars();
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir // -----------------------------------------------------------------------
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir void DialogListBox::GetFocus()
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir 	if( mpChild )
80*cdf0e10cSrcweir 		mpChild->GrabFocus();
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir // -----------------------------------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir ::Window* DialogListBox::GetPreferredKeyInputWindow()
86*cdf0e10cSrcweir {
87*cdf0e10cSrcweir 	if( mpChild )
88*cdf0e10cSrcweir 		return mpChild;
89*cdf0e10cSrcweir 	else
90*cdf0e10cSrcweir 		return this;
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir // -----------------------------------------------------------------------
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void DialogListBox::Resize()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     Control::Resize();
98*cdf0e10cSrcweir 	ImplResizeControls();
99*cdf0e10cSrcweir 	ImplCheckScrollBars();
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir // -----------------------------------------------------------------------
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir IMPL_LINK( DialogListBox, ScrollBarHdl, ScrollBar*, EMPTYARG )
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	ImplResizeChild();
107*cdf0e10cSrcweir 	return 1;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir // -----------------------------------------------------------------------
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir void DialogListBox::ImplCheckScrollBars()
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir 	bool bArrange = false;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	Size aOutSz = GetOutputSizePixel();
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	// vert. ScrollBar
119*cdf0e10cSrcweir 	if( aOutSz.Height() < maMinSize.Height() )
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		if( !mbVScroll )
122*cdf0e10cSrcweir 			bArrange = true;
123*cdf0e10cSrcweir 		mbVScroll = true;
124*cdf0e10cSrcweir 	}
125*cdf0e10cSrcweir 	else
126*cdf0e10cSrcweir 	{
127*cdf0e10cSrcweir 		if( mbVScroll )
128*cdf0e10cSrcweir 			bArrange = true;
129*cdf0e10cSrcweir 		mbVScroll = false;
130*cdf0e10cSrcweir 	}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	// horz. ScrollBar
133*cdf0e10cSrcweir 	if( mbAutoHScroll )
134*cdf0e10cSrcweir 	{
135*cdf0e10cSrcweir 		long nWidth = aOutSz.Width();
136*cdf0e10cSrcweir 		if ( mbVScroll )
137*cdf0e10cSrcweir 			nWidth -= mpVScrollBar->GetSizePixel().Width();
138*cdf0e10cSrcweir 		if( nWidth < maMinSize.Width() )
139*cdf0e10cSrcweir 		{
140*cdf0e10cSrcweir 			if( !mbHScroll )
141*cdf0e10cSrcweir 				bArrange = true;
142*cdf0e10cSrcweir 			mbHScroll = true;
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 			if ( !mbVScroll )
145*cdf0e10cSrcweir 			{
146*cdf0e10cSrcweir 				int nHeight = aOutSz.Height() - mpHScrollBar->GetSizePixel().Height();
147*cdf0e10cSrcweir 				if( nHeight < maMinSize.Height() )
148*cdf0e10cSrcweir 				{
149*cdf0e10cSrcweir 					if( !mbVScroll )
150*cdf0e10cSrcweir 						bArrange = true;
151*cdf0e10cSrcweir 					mbVScroll = true;
152*cdf0e10cSrcweir 				}
153*cdf0e10cSrcweir 			}
154*cdf0e10cSrcweir 		}
155*cdf0e10cSrcweir 		else
156*cdf0e10cSrcweir 		{
157*cdf0e10cSrcweir 			if( mbHScroll )
158*cdf0e10cSrcweir 				bArrange = true;
159*cdf0e10cSrcweir 			mbHScroll = false;
160*cdf0e10cSrcweir 		}
161*cdf0e10cSrcweir 	}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	if( bArrange )
164*cdf0e10cSrcweir 		ImplResizeControls();
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	ImplInitScrollBars();
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir // -----------------------------------------------------------------------
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir void DialogListBox::ImplInitScrollBars()
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir 	if( mpChild )
174*cdf0e10cSrcweir 	{
175*cdf0e10cSrcweir 		Size aOutSize( GetOutputSizePixel() );
176*cdf0e10cSrcweir 		if( mbHScroll ) aOutSize.Height() -= mpHScrollBar->GetSizePixel().Height();
177*cdf0e10cSrcweir 		if( mbVScroll ) aOutSize.Width() -= mpVScrollBar->GetSizePixel().Width();
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 		if ( mbVScroll )
180*cdf0e10cSrcweir 		{
181*cdf0e10cSrcweir 			mpVScrollBar->SetRangeMax( maMinSize.Height() );
182*cdf0e10cSrcweir 			mpVScrollBar->SetVisibleSize( aOutSize.Height() );
183*cdf0e10cSrcweir 			mpVScrollBar->SetPageSize( 16 );
184*cdf0e10cSrcweir 		}
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 		if ( mbHScroll )
187*cdf0e10cSrcweir 		{
188*cdf0e10cSrcweir 			mpHScrollBar->SetRangeMax( maMinSize.Width() );
189*cdf0e10cSrcweir 			mpHScrollBar->SetVisibleSize( aOutSize.Width() );
190*cdf0e10cSrcweir 			mpHScrollBar->SetPageSize( 16 );
191*cdf0e10cSrcweir 		}
192*cdf0e10cSrcweir 	}
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // -----------------------------------------------------------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir void DialogListBox::ImplResizeControls()
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	Size aOutSz( GetOutputSizePixel() );
200*cdf0e10cSrcweir 	long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
201*cdf0e10cSrcweir 	nSBWidth = CalcZoom( nSBWidth );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	maInnerSize = aOutSz;
204*cdf0e10cSrcweir 	if ( mbVScroll )
205*cdf0e10cSrcweir 		maInnerSize.Width() -= nSBWidth;
206*cdf0e10cSrcweir 	if ( mbHScroll )
207*cdf0e10cSrcweir 		maInnerSize.Height() -= nSBWidth;
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	// ScrollBarBox
210*cdf0e10cSrcweir 	if( mbVScroll && mbHScroll )
211*cdf0e10cSrcweir 	{
212*cdf0e10cSrcweir 		Point aBoxPos( maInnerSize.Width(), maInnerSize.Height() );
213*cdf0e10cSrcweir 		mpScrollBarBox->SetPosSizePixel( aBoxPos, Size( nSBWidth, nSBWidth ) );
214*cdf0e10cSrcweir 		mpScrollBarBox->Show();
215*cdf0e10cSrcweir 	}
216*cdf0e10cSrcweir 	else
217*cdf0e10cSrcweir 	{
218*cdf0e10cSrcweir 		mpScrollBarBox->Hide();
219*cdf0e10cSrcweir 	}
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	// vert. ScrollBar
222*cdf0e10cSrcweir 	if( mbVScroll )
223*cdf0e10cSrcweir 	{
224*cdf0e10cSrcweir 		// Scrollbar on left or right side?
225*cdf0e10cSrcweir 		Point aVPos( aOutSz.Width() - nSBWidth, 0 );
226*cdf0e10cSrcweir 		mpVScrollBar->SetPosSizePixel( aVPos, Size( nSBWidth, maInnerSize.Height() ) );
227*cdf0e10cSrcweir 		mpVScrollBar->Show();
228*cdf0e10cSrcweir 	}
229*cdf0e10cSrcweir 	else
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		mpVScrollBar->Hide();
232*cdf0e10cSrcweir 	}
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 	// horz. ScrollBar
235*cdf0e10cSrcweir 	if( mbHScroll )
236*cdf0e10cSrcweir 	{
237*cdf0e10cSrcweir 		Point aHPos( 0, aOutSz.Height() - nSBWidth );
238*cdf0e10cSrcweir 		mpHScrollBar->SetPosSizePixel( aHPos, Size( maInnerSize.Width(), nSBWidth ) );
239*cdf0e10cSrcweir 		mpHScrollBar->Show();
240*cdf0e10cSrcweir 	}
241*cdf0e10cSrcweir 	else
242*cdf0e10cSrcweir 	{
243*cdf0e10cSrcweir 		mpHScrollBar->Hide();
244*cdf0e10cSrcweir 	}
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	ImplResizeChild();
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir void DialogListBox::ImplResizeChild()
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	Point aWinPos;
252*cdf0e10cSrcweir 	Size aSize( maInnerSize );
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 	int nOffset;
255*cdf0e10cSrcweir 	if( mbHScroll )
256*cdf0e10cSrcweir 	{
257*cdf0e10cSrcweir 		nOffset = mpHScrollBar->GetThumbPos();
258*cdf0e10cSrcweir 		aWinPos.X() = -nOffset;
259*cdf0e10cSrcweir 		aSize.Width() += nOffset;
260*cdf0e10cSrcweir 	}
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	if( mbVScroll )
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 		nOffset = mpVScrollBar->GetThumbPos();
265*cdf0e10cSrcweir 		aWinPos.Y() = -nOffset;
266*cdf0e10cSrcweir 		aSize.Height() += nOffset;
267*cdf0e10cSrcweir 	}
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 	mpChild->SetPosSizePixel( aWinPos, aSize );
270*cdf0e10cSrcweir }
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir // -----------------------------------------------------------------------
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void DialogListBox::StateChanged( StateChangedType nType )
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir 	if ( nType == STATE_CHANGE_INITSHOW )
277*cdf0e10cSrcweir 	{
278*cdf0e10cSrcweir 		ImplCheckScrollBars();
279*cdf0e10cSrcweir 	}
280*cdf0e10cSrcweir 	else if ( ( nType == STATE_CHANGE_UPDATEMODE ) || ( nType == STATE_CHANGE_DATA ) )
281*cdf0e10cSrcweir 	{
282*cdf0e10cSrcweir 		sal_Bool bUpdate = IsUpdateMode();
283*cdf0e10cSrcweir 		mpChild->SetUpdateMode( bUpdate );
284*cdf0e10cSrcweir 		if ( bUpdate && IsReallyVisible() )
285*cdf0e10cSrcweir 			ImplCheckScrollBars();
286*cdf0e10cSrcweir 	}
287*cdf0e10cSrcweir 	else if( nType == STATE_CHANGE_ENABLE )
288*cdf0e10cSrcweir 	{
289*cdf0e10cSrcweir 		mpHScrollBar->Enable( IsEnabled() );
290*cdf0e10cSrcweir 		mpVScrollBar->Enable( IsEnabled() );
291*cdf0e10cSrcweir 		mpScrollBarBox->Enable( IsEnabled() );
292*cdf0e10cSrcweir 		Invalidate();
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_ZOOM )
295*cdf0e10cSrcweir 	{
296*cdf0e10cSrcweir 		mpChild->SetZoom( GetZoom() );
297*cdf0e10cSrcweir 		Resize();
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLFONT )
300*cdf0e10cSrcweir 	{
301*cdf0e10cSrcweir 		mpChild->SetControlFont( GetControlFont() );
302*cdf0e10cSrcweir 	}
303*cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
304*cdf0e10cSrcweir 	{
305*cdf0e10cSrcweir 		mpChild->SetControlForeground( GetControlForeground() );
306*cdf0e10cSrcweir 	}
307*cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
308*cdf0e10cSrcweir 	{
309*cdf0e10cSrcweir 		mpChild->SetControlBackground( GetControlBackground() );
310*cdf0e10cSrcweir 	}
311*cdf0e10cSrcweir 	else if( nType == STATE_CHANGE_VISIBLE )
312*cdf0e10cSrcweir 	{
313*cdf0e10cSrcweir 		mpChild->Show( IsVisible() );
314*cdf0e10cSrcweir 	}
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	Control::StateChanged( nType );
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir // -----------------------------------------------------------------------
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir long DialogListBox::Notify( NotifyEvent& rNEvt )
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir 	long nDone = 0;
324*cdf0e10cSrcweir 	if ( rNEvt.GetType() == EVENT_COMMAND )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir 		const CommandEvent& rCEvt = *rNEvt.GetCommandEvent();
327*cdf0e10cSrcweir 		if ( rCEvt.GetCommand() == COMMAND_WHEEL )
328*cdf0e10cSrcweir 		{
329*cdf0e10cSrcweir 			const CommandWheelData* pData = rCEvt.GetWheelData();
330*cdf0e10cSrcweir 			if( !pData->GetModifier() && ( pData->GetMode() == COMMAND_WHEEL_SCROLL ) )
331*cdf0e10cSrcweir 			{
332*cdf0e10cSrcweir 				nDone = HandleScrollCommand( rCEvt, mpHScrollBar, mpVScrollBar );
333*cdf0e10cSrcweir 			}
334*cdf0e10cSrcweir 		}
335*cdf0e10cSrcweir 	}
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 	return nDone ? nDone : Window::Notify( rNEvt );
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir } //  namespace sd
341