Files
libreoffice/svx/source/dialog/checklbx.cxx

250 lines
6.5 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patch contributed by Christian Lippka impress212: #i113063# patch: dubios self assign in svx/source/dialog/framelink.cxx http://svn.apache.org/viewvc?view=revision&revision=1167619 Patches contributed by Mathias Bauer gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117712#: fix several resource errors introduced by IAccessible2 implementation http://svn.apache.org/viewvc?view=revision&revision=1172343 cws mba34issues01: #i117719#: use correct resource ID http://svn.apache.org/viewvc?view=revision&revision=1172351 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Armin Le-Grand #118804# corrected GraphicExporter behaviour on shortcut when pixel graphic is requested http://svn.apache.org/viewvc?view=revision&revision=1240195 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118524: apply patch, followup fixes to 118485 http://svn.apache.org/viewvc?view=revision&revision=1186077 13f79535-47bb-0310-9956-ffa450edef68 Patch contributed by Regina Henschel linecap: Reintegrating finished LineCap feature http://svn.apache.org/viewvc?view=revision&revision=1232507 Patch contributed by Wang Lei (leiw) #i118760# split the first table cell vertically, then undo&redo, the Presentation app will crash http://svn.apache.org/viewvc?view=revision&revision=1301361 cleanup globlmn hacks, undo dependent fixmes.
2012-11-21 22:06:52 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 16:07:07 +00:00
#include <svtools/treelistentry.hxx>
#include <svx/checklbx.hxx>
#include <svx/dialmgr.hxx>
2000-09-18 16:07:07 +00:00
#include <svx/dialogs.hrc>
#include <vcl/builder.hxx>
SvxCheckListBox::SvxCheckListBox( vcl::Window* pParent, WinBits nWinStyle ) :
SvTreeListBox( pParent, nWinStyle )
2000-09-18 16:07:07 +00:00
{
Init_Impl();
}
extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSvxCheckListBox(vcl::Window *pParent, VclBuilder::stringmap &rMap)
{
WinBits nWinStyle = WB_TABSTOP;
OString sBorder = VclBuilder::extractCustomProperty(rMap);
if (!sBorder.isEmpty())
nWinStyle |= WB_BORDER;
return new SvxCheckListBox(pParent, nWinStyle);
}
void SvxCheckListBox::SetNormalStaticImage(const Image& rNormalStaticImage)
{
pCheckButton->SetImage(SvBmp::STATICIMAGE, rNormalStaticImage);
}
SvxCheckListBox::~SvxCheckListBox()
2000-09-18 16:07:07 +00:00
{
delete pCheckButton;
}
void SvxCheckListBox::Init_Impl()
{
pCheckButton = new SvLBoxButtonData( this );
2000-09-18 16:07:07 +00:00
EnableCheckButton( pCheckButton );
}
void SvxCheckListBox::InsertEntry( const OUString& rStr, sal_uLong nPos,
void* pUserData,
SvLBoxButtonKind eButtonKind )
2000-09-18 16:07:07 +00:00
{
SvTreeListBox::InsertEntry( rStr, NULL, false, nPos, pUserData,
eButtonKind );
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
void SvxCheckListBox::RemoveEntry( sal_uLong nPos )
2000-09-18 16:07:07 +00:00
{
if ( nPos < GetEntryCount() )
SvTreeListBox::GetModel()->Remove( GetEntry( nPos ) );
}
2000-09-18 16:07:07 +00:00
void SvxCheckListBox::SelectEntryPos( sal_uLong nPos, bool bSelect )
2000-09-18 16:07:07 +00:00
{
if ( nPos < GetEntryCount() )
Select( GetEntry( nPos ), bSelect );
}
2000-09-18 16:07:07 +00:00
sal_uLong SvxCheckListBox::GetSelectEntryPos() const
2000-09-18 16:07:07 +00:00
{
SvTreeListEntry* pEntry = GetCurEntry();
2000-09-18 16:07:07 +00:00
if ( pEntry )
return GetModel()->GetAbsPos( pEntry );
return TREELIST_ENTRY_NOTFOUND;
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
OUString SvxCheckListBox::GetText( sal_uLong nPos ) const
2000-09-18 16:07:07 +00:00
{
SvTreeListEntry* pEntry = GetEntry( nPos );
2000-09-18 16:07:07 +00:00
if ( pEntry )
return GetEntryText( pEntry );
return OUString();
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
sal_uLong SvxCheckListBox::GetCheckedEntryCount() const
2000-09-18 16:07:07 +00:00
{
sal_uLong nCheckCount = 0;
sal_uLong nCount = GetEntryCount();
2000-09-18 16:07:07 +00:00
for ( sal_uLong i = 0; i < nCount; ++i )
{
2000-09-18 16:07:07 +00:00
if ( IsChecked( i ) )
nCheckCount++;
}
2000-09-18 16:07:07 +00:00
return nCheckCount;
}
2000-09-18 16:07:07 +00:00
void SvxCheckListBox::CheckEntryPos( sal_uLong nPos, bool bCheck )
2000-09-18 16:07:07 +00:00
{
if ( nPos < GetEntryCount() )
SetCheckButtonState(
GetEntry( nPos ), bCheck ? SvButtonState( SV_BUTTON_CHECKED ) :
SvButtonState( SV_BUTTON_UNCHECKED ) );
}
2000-09-18 16:07:07 +00:00
bool SvxCheckListBox::IsChecked( sal_uLong nPos ) const
2000-09-18 16:07:07 +00:00
{
if ( nPos < GetEntryCount() )
return (GetCheckButtonState( GetEntry( nPos ) ) == SV_BUTTON_CHECKED);
else
return false;
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
void* SvxCheckListBox::SetEntryData ( sal_uLong nPos, void* pNewData )
2000-09-18 16:07:07 +00:00
{
void* pOld = NULL;
if ( nPos < GetEntryCount() )
{
pOld = GetEntry( nPos )->GetUserData();
GetEntry( nPos )->SetUserData( pNewData );
}
return pOld;
}
2000-09-18 16:07:07 +00:00
void* SvxCheckListBox::GetEntryData( sal_uLong nPos ) const
2000-09-18 16:07:07 +00:00
{
if ( nPos < GetEntryCount() )
return GetEntry( nPos )->GetUserData();
else
return NULL;
}
2000-09-18 16:07:07 +00:00
void SvxCheckListBox::ToggleCheckButton( SvTreeListEntry* pEntry )
2000-09-18 16:07:07 +00:00
{
if ( pEntry )
{
if ( !IsSelected( pEntry ) )
Select( pEntry );
else
CheckEntryPos( GetSelectEntryPos(), !IsChecked( GetSelectEntryPos() ) );
}
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
void SvxCheckListBox::MouseButtonDown( const MouseEvent& rMEvt )
{
if ( rMEvt.IsLeft() )
{
const Point aPnt = rMEvt.GetPosPixel();
SvTreeListEntry* pEntry = GetEntry( aPnt );
2000-09-18 16:07:07 +00:00
if ( pEntry )
{
bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
2000-09-18 16:07:07 +00:00
SvLBoxItem* pItem = GetItem( pEntry, aPnt.X() );
if (pItem && pItem->GetType() == SV_ITEM_ID_LBOXBUTTON)
2000-09-18 16:07:07 +00:00
{
SvTreeListBox::MouseButtonDown( rMEvt );
Select( pEntry, true );
2000-09-18 16:07:07 +00:00
return;
}
else
{
ToggleCheckButton( pEntry );
SvTreeListBox::MouseButtonDown( rMEvt );
// check if the entry below the mouse changed during the base method call. This is possible if,
// for instance, a handler invoked by the base class tampers with the list entries.
const SvTreeListEntry* pNewEntry = GetEntry( aPnt );
if ( pNewEntry != pEntry )
return;
if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
2000-09-18 16:07:07 +00:00
CheckButtonHdl();
return;
}
}
}
SvTreeListBox::MouseButtonDown( rMEvt );
}
2000-09-18 16:07:07 +00:00
void SvxCheckListBox::KeyInput( const KeyEvent& rKEvt )
{
const vcl::KeyCode& rKey = rKEvt.GetKeyCode();
2000-09-18 16:07:07 +00:00
if ( rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_SPACE )
{
SvTreeListEntry* pEntry = GetCurEntry();
2000-09-18 16:07:07 +00:00
if ( pEntry )
{
bool bCheck = ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED );
2000-09-18 16:07:07 +00:00
ToggleCheckButton( pEntry );
if ( bCheck != ( GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED ) )
2000-09-18 16:07:07 +00:00
CheckButtonHdl();
}
}
else if ( GetEntryCount() )
SvTreeListBox::KeyInput( rKEvt );
}
SvTreeListEntry* SvxCheckListBox::InsertEntry( const OUString& rText, SvTreeListEntry* pParent, bool bChildrenOnDemand, sal_uIntPtr nPos, void* pUserData, SvLBoxButtonKind eButtonKind )
{
2011-12-07 02:33:51 -08:00
return SvTreeListBox::InsertEntry( rText, pParent, bChildrenOnDemand, nPos, pUserData, eButtonKind );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */