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