1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6e50924SAndrew Rist * distributed with this work for additional information
6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10*f6e50924SAndrew Rist *
11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist *
13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17*f6e50924SAndrew Rist * specific language governing permissions and limitations
18*f6e50924SAndrew Rist * under the License.
19*f6e50924SAndrew Rist *
20*f6e50924SAndrew Rist *************************************************************/
21*f6e50924SAndrew Rist
22*f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir #include <tools/shl.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #define _SVX_CHECKLBX_CXX
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <svx/checklbx.hxx>
33cdf0e10cSrcweir #include <svx/dialmgr.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <svx/dialogs.hrc>
36cdf0e10cSrcweir
37cdf0e10cSrcweir // class SvxCheckListBox -------------------------------------------------
38cdf0e10cSrcweir
SvxCheckListBox(Window * pParent,WinBits nWinStyle)39cdf0e10cSrcweir SvxCheckListBox::SvxCheckListBox( Window* pParent, WinBits nWinStyle ) :
40cdf0e10cSrcweir
41cdf0e10cSrcweir SvTreeListBox( pParent, nWinStyle )
42cdf0e10cSrcweir
43cdf0e10cSrcweir {
44cdf0e10cSrcweir Init_Impl();
45cdf0e10cSrcweir }
46cdf0e10cSrcweir
47cdf0e10cSrcweir // -----------------------------------------------------------------------
48cdf0e10cSrcweir
SvxCheckListBox(Window * pParent,const ResId & rResId)49cdf0e10cSrcweir SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId ) :
50cdf0e10cSrcweir
51cdf0e10cSrcweir SvTreeListBox( pParent, rResId )
52cdf0e10cSrcweir
53cdf0e10cSrcweir {
54cdf0e10cSrcweir Init_Impl();
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
57cdf0e10cSrcweir // -----------------------------------------------------------------------
58cdf0e10cSrcweir
SvxCheckListBox(Window * pParent,const ResId & rResId,const Image & rNormalStaticImage,const Image &)59cdf0e10cSrcweir SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId,
60cdf0e10cSrcweir const Image& rNormalStaticImage,
61cdf0e10cSrcweir const Image& /*TODO#i72485# rHighContrastStaticImage*/ ) :
62cdf0e10cSrcweir
63cdf0e10cSrcweir SvTreeListBox( pParent, rResId )
64cdf0e10cSrcweir
65cdf0e10cSrcweir {
66cdf0e10cSrcweir Init_Impl();
67cdf0e10cSrcweir pCheckButton->aBmps[SV_BMP_STATICIMAGE] = rNormalStaticImage;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
70cdf0e10cSrcweir // -----------------------------------------------------------------------
71cdf0e10cSrcweir
~SvxCheckListBox()72cdf0e10cSrcweir SvxCheckListBox::~SvxCheckListBox()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir delete pCheckButton;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir // -----------------------------------------------------------------------
78cdf0e10cSrcweir
Init_Impl()79cdf0e10cSrcweir void SvxCheckListBox::Init_Impl()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir pCheckButton = new SvLBoxButtonData( this );
82cdf0e10cSrcweir EnableCheckButton( pCheckButton );
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
85cdf0e10cSrcweir // -----------------------------------------------------------------------
86cdf0e10cSrcweir
InsertEntry(const String & rStr,sal_uInt16 nPos,void * pUserData,SvLBoxButtonKind eButtonKind)87cdf0e10cSrcweir void SvxCheckListBox::InsertEntry( const String& rStr, sal_uInt16 nPos,
88cdf0e10cSrcweir void* pUserData,
89cdf0e10cSrcweir SvLBoxButtonKind eButtonKind )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir SvTreeListBox::InsertEntry( rStr, NULL, sal_False, nPos, pUserData,
92cdf0e10cSrcweir eButtonKind );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
95cdf0e10cSrcweir // -----------------------------------------------------------------------
96cdf0e10cSrcweir
RemoveEntry(sal_uInt16 nPos)97cdf0e10cSrcweir void SvxCheckListBox::RemoveEntry( sal_uInt16 nPos )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir if ( nPos < GetEntryCount() )
100cdf0e10cSrcweir SvTreeListBox::GetModel()->Remove( GetEntry( nPos ) );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir
103cdf0e10cSrcweir // -----------------------------------------------------------------------
104cdf0e10cSrcweir
SelectEntryPos(sal_uInt16 nPos,sal_Bool bSelect)105cdf0e10cSrcweir void SvxCheckListBox::SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect )
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if ( nPos < GetEntryCount() )
108cdf0e10cSrcweir Select( GetEntry( nPos ), bSelect );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir // -----------------------------------------------------------------------
112cdf0e10cSrcweir
GetSelectEntryPos() const113cdf0e10cSrcweir sal_uInt16 SvxCheckListBox::GetSelectEntryPos() const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir SvLBoxEntry* pEntry = GetCurEntry();
116cdf0e10cSrcweir
117cdf0e10cSrcweir if ( pEntry )
118cdf0e10cSrcweir return (sal_uInt16)GetModel()->GetAbsPos( pEntry );
119cdf0e10cSrcweir return LISTBOX_ENTRY_NOTFOUND;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
122cdf0e10cSrcweir // -----------------------------------------------------------------------
123cdf0e10cSrcweir
GetText(sal_uInt16 nPos) const124cdf0e10cSrcweir String SvxCheckListBox::GetText( sal_uInt16 nPos ) const
125cdf0e10cSrcweir {
126cdf0e10cSrcweir SvLBoxEntry* pEntry = GetEntry( nPos );
127cdf0e10cSrcweir
128cdf0e10cSrcweir if ( pEntry )
129cdf0e10cSrcweir return GetEntryText( pEntry );
130cdf0e10cSrcweir return String();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir // -----------------------------------------------------------------------
134cdf0e10cSrcweir
GetCheckedEntryCount() const135cdf0e10cSrcweir sal_uInt16 SvxCheckListBox::GetCheckedEntryCount() const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir sal_uInt16 nCheckCount = 0;
138cdf0e10cSrcweir sal_uInt16 nCount = (sal_uInt16)GetEntryCount();
139cdf0e10cSrcweir
140cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < nCount; ++i )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir if ( IsChecked( i ) )
143cdf0e10cSrcweir nCheckCount++;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir return nCheckCount;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir // -----------------------------------------------------------------------
149cdf0e10cSrcweir
CheckEntryPos(sal_uInt16 nPos,sal_Bool bCheck)150cdf0e10cSrcweir void SvxCheckListBox::CheckEntryPos( sal_uInt16 nPos, sal_Bool bCheck )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir if ( nPos < GetEntryCount() )
153cdf0e10cSrcweir SetCheckButtonState(
154cdf0e10cSrcweir GetEntry( nPos ), bCheck ? SvButtonState( SV_BUTTON_CHECKED ) :
155cdf0e10cSrcweir SvButtonState( SV_BUTTON_UNCHECKED ) );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir // -----------------------------------------------------------------------
159cdf0e10cSrcweir
IsChecked(sal_uInt16 nPos) const160cdf0e10cSrcweir sal_Bool SvxCheckListBox::IsChecked( sal_uInt16 nPos ) const
161cdf0e10cSrcweir {
162cdf0e10cSrcweir if ( nPos < GetEntryCount() )
163cdf0e10cSrcweir return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED);
164cdf0e10cSrcweir else
165cdf0e10cSrcweir return sal_False;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir // -----------------------------------------------------------------------
169cdf0e10cSrcweir
SetEntryData(sal_uInt16 nPos,void * pNewData)170cdf0e10cSrcweir void* SvxCheckListBox::SetEntryData ( sal_uInt16 nPos, void* pNewData )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir void* pOld = NULL;
173cdf0e10cSrcweir
174cdf0e10cSrcweir if ( nPos < GetEntryCount() )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir pOld = GetEntry( nPos )->GetUserData();
177cdf0e10cSrcweir GetEntry( nPos )->SetUserData( pNewData );
178cdf0e10cSrcweir }
179cdf0e10cSrcweir return pOld;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir // -----------------------------------------------------------------------
183cdf0e10cSrcweir
GetEntryData(sal_uInt16 nPos) const184cdf0e10cSrcweir void* SvxCheckListBox::GetEntryData( sal_uInt16 nPos ) const
185cdf0e10cSrcweir {
186cdf0e10cSrcweir if ( nPos < GetEntryCount() )
187cdf0e10cSrcweir return GetEntry( nPos )->GetUserData();
188cdf0e10cSrcweir else
189cdf0e10cSrcweir return NULL;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir
192cdf0e10cSrcweir // -----------------------------------------------------------------------
193cdf0e10cSrcweir
ToggleCheckButton(SvLBoxEntry * pEntry)194cdf0e10cSrcweir void SvxCheckListBox::ToggleCheckButton( SvLBoxEntry* pEntry )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir if ( pEntry )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir if ( !IsSelected( pEntry ) )
199cdf0e10cSrcweir Select( pEntry );
200cdf0e10cSrcweir else
201cdf0e10cSrcweir CheckEntryPos( GetSelectEntryPos(), !IsChecked( GetSelectEntryPos() ) );
202cdf0e10cSrcweir }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir
205cdf0e10cSrcweir // -----------------------------------------------------------------------
206cdf0e10cSrcweir
MouseButtonDown(const MouseEvent & rMEvt)207cdf0e10cSrcweir void SvxCheckListBox::MouseButtonDown( const MouseEvent& rMEvt )
208cdf0e10cSrcweir {
209cdf0e10cSrcweir if ( rMEvt.IsLeft() )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir const Point aPnt = rMEvt.GetPosPixel();
212cdf0e10cSrcweir SvLBoxEntry* pEntry = GetEntry( aPnt );
213cdf0e10cSrcweir
214cdf0e10cSrcweir if ( pEntry )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir sal_Bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
217cdf0e10cSrcweir SvLBoxItem* pItem = GetItem( pEntry, aPnt.X() );
218cdf0e10cSrcweir
219cdf0e10cSrcweir if ( pItem && pItem->IsA() == SV_ITEM_ID_LBOXBUTTON )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir SvTreeListBox::MouseButtonDown( rMEvt );
222cdf0e10cSrcweir Select( pEntry, sal_True );
223cdf0e10cSrcweir return;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir else
226cdf0e10cSrcweir {
227cdf0e10cSrcweir ToggleCheckButton( pEntry );
228cdf0e10cSrcweir SvTreeListBox::MouseButtonDown( rMEvt );
229cdf0e10cSrcweir
230cdf0e10cSrcweir // check if the entry below the mouse changed during the base method call. This is possible if,
231cdf0e10cSrcweir // for instance, a handler invoked by the base class tampers with the list entries.
232cdf0e10cSrcweir const SvLBoxEntry* pNewEntry = GetEntry( aPnt );
233cdf0e10cSrcweir if ( pNewEntry != pEntry )
234cdf0e10cSrcweir return;
235cdf0e10cSrcweir
236cdf0e10cSrcweir if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
237cdf0e10cSrcweir CheckButtonHdl();
238cdf0e10cSrcweir return;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir }
241cdf0e10cSrcweir }
242cdf0e10cSrcweir SvTreeListBox::MouseButtonDown( rMEvt );
243cdf0e10cSrcweir }
244cdf0e10cSrcweir
245cdf0e10cSrcweir // -----------------------------------------------------------------------
246cdf0e10cSrcweir
KeyInput(const KeyEvent & rKEvt)247cdf0e10cSrcweir void SvxCheckListBox::KeyInput( const KeyEvent& rKEvt )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir const KeyCode& rKey = rKEvt.GetKeyCode();
250cdf0e10cSrcweir
251cdf0e10cSrcweir if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir SvLBoxEntry* pEntry = GetCurEntry();
254cdf0e10cSrcweir
255cdf0e10cSrcweir if ( pEntry )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir sal_Bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
258cdf0e10cSrcweir ToggleCheckButton( pEntry );
259cdf0e10cSrcweir if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
260cdf0e10cSrcweir CheckButtonHdl();
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir else if ( GetEntryCount() )
264cdf0e10cSrcweir SvTreeListBox::KeyInput( rKEvt );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
267cdf0e10cSrcweir // -----------------------------------------------------------------------
268cdf0e10cSrcweir
InsertEntry(const XubString & rText,SvLBoxEntry * pParent,sal_Bool bChildsOnDemand,sal_uIntPtr nPos,void * pUserData,SvLBoxButtonKind eButtonKind)269cdf0e10cSrcweir SvLBoxEntry* SvxCheckListBox::InsertEntry( const XubString& rText, SvLBoxEntry* pParent, sal_Bool bChildsOnDemand, sal_uIntPtr nPos, void* pUserData, SvLBoxButtonKind eButtonKind )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir return SvTreeListBox::InsertEntry( rText, pParent, bChildsOnDemand, nPos, pUserData, eButtonKind );
272cdf0e10cSrcweir }
273cdf0e10cSrcweir
274