1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: checklbx.cxx,v $
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
)
54 // -----------------------------------------------------------------------
56 SvxCheckListBox::SvxCheckListBox( Window
* pParent
, const ResId
& rResId
) :
58 SvTreeListBox( pParent
, rResId
)
64 // -----------------------------------------------------------------------
66 SvxCheckListBox::SvxCheckListBox( Window
* pParent
, const ResId
& rResId
,
67 const Image
& rNormalStaticImage
,
68 const Image
& /*TODO#i72485# rHighContrastStaticImage*/ ) :
70 SvTreeListBox( pParent
, rResId
)
74 pCheckButton
->aBmps
[SV_BMP_STATICIMAGE
] = rNormalStaticImage
;
77 // -----------------------------------------------------------------------
79 SvxCheckListBox::~SvxCheckListBox()
84 // -----------------------------------------------------------------------
86 void SvxCheckListBox::Init_Impl()
88 pCheckButton
= new SvLBoxButtonData( this );
89 EnableCheckButton( pCheckButton
);
92 // -----------------------------------------------------------------------
94 void SvxCheckListBox::InsertEntry( const String
& rStr
, USHORT nPos
,
96 SvLBoxButtonKind eButtonKind
)
98 SvTreeListBox::InsertEntry( rStr
, NULL
, FALSE
, nPos
, pUserData
,
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();
125 return (USHORT
)GetModel()->GetAbsPos( pEntry
);
126 return LISTBOX_ENTRY_NOTFOUND
;
129 // -----------------------------------------------------------------------
131 String
SvxCheckListBox::GetText( USHORT nPos
) const
133 SvLBoxEntry
* pEntry
= GetEntry( nPos
);
136 return GetEntryText( pEntry
);
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
) )
155 // -----------------------------------------------------------------------
157 void SvxCheckListBox::CheckEntryPos( USHORT nPos
, BOOL bCheck
)
159 if ( nPos
< GetEntryCount() )
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
);
175 // -----------------------------------------------------------------------
177 void* SvxCheckListBox::SetEntryData ( USHORT nPos
, void* pNewData
)
181 if ( nPos
< GetEntryCount() )
183 pOld
= GetEntry( nPos
)->GetUserData();
184 GetEntry( nPos
)->SetUserData( pNewData
);
189 // -----------------------------------------------------------------------
191 void* SvxCheckListBox::GetEntryData( USHORT nPos
) const
193 if ( nPos
< GetEntryCount() )
194 return GetEntry( nPos
)->GetUserData();
199 // -----------------------------------------------------------------------
201 void SvxCheckListBox::ToggleCheckButton( SvLBoxEntry
* pEntry
)
205 if ( !IsSelected( pEntry
) )
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
);
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
);
234 ToggleCheckButton( pEntry
);
235 SvTreeListBox::MouseButtonDown( rMEvt
);
236 if ( bCheck
!= ( GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
) )
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();
257 BOOL bCheck
= ( GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
);
258 ToggleCheckButton( pEntry
);
259 if ( bCheck
!= ( GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
) )
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
);