Update ooo320-m1
[ooovba.git] / svx / source / dialog / checklbx.cxx
blobe48736bf37854c23f3c83ca99b2b959444460569
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: checklbx.cxx,v $
10 * $Revision: 1.13 $
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_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/shl.hxx>
37 #define _SVX_CHECKLBX_CXX
39 #include <svx/checklbx.hxx>
40 #include <svx/dialmgr.hxx>
42 #include <svx/dialogs.hrc>
44 // class SvxCheckListBox -------------------------------------------------
46 SvxCheckListBox::SvxCheckListBox( Window* pParent, WinBits nWinStyle ) :
48 SvTreeListBox( pParent, nWinStyle )
51 Init_Impl();
54 // -----------------------------------------------------------------------
56 SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId ) :
58 SvTreeListBox( pParent, rResId )
61 Init_Impl();
64 // -----------------------------------------------------------------------
66 SvxCheckListBox::SvxCheckListBox( Window* pParent, const ResId& rResId,
67 const Image& rNormalStaticImage,
68 const Image& /*TODO#i72485# rHighContrastStaticImage*/ ) :
70 SvTreeListBox( pParent, rResId )
73 Init_Impl();
74 pCheckButton->aBmps[SV_BMP_STATICIMAGE] = rNormalStaticImage;
77 // -----------------------------------------------------------------------
79 SvxCheckListBox::~SvxCheckListBox()
81 delete pCheckButton;
84 // -----------------------------------------------------------------------
86 void SvxCheckListBox::Init_Impl()
88 pCheckButton = new SvLBoxButtonData( this );
89 EnableCheckButton( pCheckButton );
92 // -----------------------------------------------------------------------
94 void SvxCheckListBox::InsertEntry( const String& rStr, USHORT nPos,
95 void* pUserData,
96 SvLBoxButtonKind eButtonKind )
98 SvTreeListBox::InsertEntry( rStr, NULL, FALSE, nPos, pUserData,
99 eButtonKind );
102 // -----------------------------------------------------------------------
104 void SvxCheckListBox::RemoveEntry( USHORT nPos )
106 if ( nPos < GetEntryCount() )
107 SvTreeListBox::GetModel()->Remove( GetEntry( nPos ) );
110 // -----------------------------------------------------------------------
112 void SvxCheckListBox::SelectEntryPos( USHORT nPos, BOOL bSelect )
114 if ( nPos < GetEntryCount() )
115 Select( GetEntry( nPos ), bSelect );
118 // -----------------------------------------------------------------------
120 USHORT SvxCheckListBox::GetSelectEntryPos() const
122 SvLBoxEntry* pEntry = GetCurEntry();
124 if ( pEntry )
125 return (USHORT)GetModel()->GetAbsPos( pEntry );
126 return LISTBOX_ENTRY_NOTFOUND;
129 // -----------------------------------------------------------------------
131 String SvxCheckListBox::GetText( USHORT nPos ) const
133 SvLBoxEntry* pEntry = GetEntry( nPos );
135 if ( pEntry )
136 return GetEntryText( pEntry );
137 return String();
140 // -----------------------------------------------------------------------
142 USHORT SvxCheckListBox::GetCheckedEntryCount() const
144 USHORT nCheckCount = 0;
145 USHORT nCount = (USHORT)GetEntryCount();
147 for ( USHORT i = 0; i < nCount; ++i )
149 if ( IsChecked( i ) )
150 nCheckCount++;
152 return nCheckCount;
155 // -----------------------------------------------------------------------
157 void SvxCheckListBox::CheckEntryPos( USHORT nPos, BOOL bCheck )
159 if ( nPos < GetEntryCount() )
160 SetCheckButtonState(
161 GetEntry( nPos ), bCheck ? SvButtonState( SV_BUTTON_CHECKED ) :
162 SvButtonState( SV_BUTTON_UNCHECKED ) );
165 // -----------------------------------------------------------------------
167 BOOL SvxCheckListBox::IsChecked( USHORT nPos ) const
169 if ( nPos < GetEntryCount() )
170 return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED);
171 else
172 return FALSE;
175 // -----------------------------------------------------------------------
177 void* SvxCheckListBox::SetEntryData ( USHORT nPos, void* pNewData )
179 void* pOld = NULL;
181 if ( nPos < GetEntryCount() )
183 pOld = GetEntry( nPos )->GetUserData();
184 GetEntry( nPos )->SetUserData( pNewData );
186 return pOld;
189 // -----------------------------------------------------------------------
191 void* SvxCheckListBox::GetEntryData( USHORT nPos ) const
193 if ( nPos < GetEntryCount() )
194 return GetEntry( nPos )->GetUserData();
195 else
196 return NULL;
199 // -----------------------------------------------------------------------
201 void SvxCheckListBox::ToggleCheckButton( SvLBoxEntry* pEntry )
203 if ( pEntry )
205 if ( !IsSelected( pEntry ) )
206 Select( pEntry );
207 else
208 CheckEntryPos( GetSelectEntryPos(), !IsChecked( GetSelectEntryPos() ) );
212 // -----------------------------------------------------------------------
214 void SvxCheckListBox::MouseButtonDown( const MouseEvent& rMEvt )
216 if ( rMEvt.IsLeft() )
218 Point aPnt = rMEvt.GetPosPixel();
219 SvLBoxEntry* pEntry = GetEntry( aPnt );
221 if ( pEntry )
223 BOOL bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
224 SvLBoxItem* pItem = GetItem( pEntry, aPnt.X() );
226 if ( pItem && pItem->IsA() == SV_ITEM_ID_LBOXBUTTON )
228 SvTreeListBox::MouseButtonDown( rMEvt );
229 Select( pEntry, TRUE );
230 return;
232 else
234 ToggleCheckButton( pEntry );
235 SvTreeListBox::MouseButtonDown( rMEvt );
236 if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
237 CheckButtonHdl();
238 return;
242 SvTreeListBox::MouseButtonDown( rMEvt );
245 // -----------------------------------------------------------------------
247 void SvxCheckListBox::KeyInput( const KeyEvent& rKEvt )
249 const KeyCode& rKey = rKEvt.GetKeyCode();
251 if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
253 SvLBoxEntry* pEntry = GetCurEntry();
255 if ( pEntry )
257 BOOL bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
258 ToggleCheckButton( pEntry );
259 if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
260 CheckButtonHdl();
263 else if ( GetEntryCount() )
264 SvTreeListBox::KeyInput( rKEvt );
267 // -----------------------------------------------------------------------
269 SvLBoxEntry* SvxCheckListBox::InsertEntry( const XubString& rText, SvLBoxEntry* pParent, BOOL bChildsOnDemand, ULONG nPos, void* pUserData, SvLBoxButtonKind eButtonKind )
271 return SvTreeListBox::InsertEntry( rText, pParent, bChildsOnDemand, nPos, pUserData, eButtonKind );