Files
libreoffice/svtools/source/contnr/ivctrl.cxx

514 lines
14 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: Jurgen Schmidt remove onlineregistration with dependencies http://svn.apache.org/viewvc?view=revision&revision=1240245 imported patch package_eventlistener.patch http://svn.apache.org/viewvc?view=revision&revision=1172103 Patch contributed by Pedro Giffuni Accept Google Chrome OS fonts as equivalent to MS fonts. http://svn.apache.org/viewvc?view=revision&revision=1233155 http://svn.apache.org/viewvc?view=revision&revision=1233408 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 Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i114600#: remove forbidden characters from list of unencoded characters http://svn.apache.org/viewvc?view=revision&revision=1172370 Patches contributed by Oliver Rainer-Wittman some clean up in JPEGReader due to memory constraints http://svn.apache.org/viewvc?view=revision&revision=1299729 119114 - method <UpdateDialog::addSpecificError(..)> - create entry with correct type http://svn.apache.org/viewvc?view=revision&revision=1305265 Patches contributed by Ariel Constenla-Haile i118707 - make toolbar control's popup window grab focus http://svn.apache.org/viewvc?view=revision&revision=1225846 Patches contributed by Herbert Duerr #i118662# remove usage of BerkeleyDB in desktop module http://svn.apache.org/viewvc?view=revision&revision=1213171 minor cleanups in dp_persmap.* http://svn.apache.org/viewvc?view=revision&revision=1215064 flush early to prevent problem with extension manager not cleaning up its objects http://svn.apache.org/viewvc?view=revision&revision=1228147 i118726 do not flush *pmap file while reading it http://svn.apache.org/viewvc?view=revision&revision=1230614 #i119048# migrate BDB extension entries using a simple heuristic http://svn.apache.org/viewvc?view=revision&revision=1300972 #i119048# handle edge cases when importing BDB hash files http://svn.apache.org/viewvc?view=revision&revision=1301428 #i119113# fix of-by-one when importing BDB files http://svn.apache.org/viewvc?view=revision&revision=1305420 restore our encryption settings, icon themes, and dictionaries. removed wrapper hacks, kill obsolete bundled extension blob / pre-registration handling, remove duplicated quickstart code. remove OS/2 conditionals.
2012-11-15 17:28:16 +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 .
*/
2001-05-07 09:33:55 +00:00
#include <svtools/ivctrl.hxx>
2001-05-07 09:33:55 +00:00
#include "imivctl.hxx"
#include <vcl/bitmapex.hxx>
#include <vcl/controllayout.hxx>
#include <vcl/mnemonic.hxx>
using namespace ::com::sun::star::accessibility;
2002-08-13 06:25:04 +00:00
2001-05-07 09:33:55 +00:00
/*****************************************************************************
|
| class : SvxIconChoiceCtrlEntry
|
\*****************************************************************************/
SvxIconChoiceCtrlEntry::SvxIconChoiceCtrlEntry( const OUString& rText,
const Image& rImage,
sal_uInt16 _nFlags )
: aImage(rImage)
, aText(rText)
, pUserData(NULL)
, nPos(0)
, pblink(0)
, pflink(0)
, eTextMode(IcnShowTextShort)
, nX(0)
, nY(0)
, nFlags(_nFlags)
2001-05-07 09:33:55 +00:00
{
}
OUString SvxIconChoiceCtrlEntry::GetDisplayText() const
2002-08-13 06:25:04 +00:00
{
return MnemonicGenerator::EraseAllMnemonicChars( aText );
2002-08-13 06:25:04 +00:00
}
2001-05-07 09:33:55 +00:00
// ----------------------------------------------------------------------------
SvxIconChoiceCtrlColumnInfo::SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& rInfo )
: aColText( rInfo.aColText ), aColImage( rInfo.aColImage )
{
nWidth = rInfo.nWidth;
eAlignment = rInfo.eAlignment;
nSubItem = rInfo.nSubItem;
}
/*****************************************************************************
|
| class : SvtIconChoiceCtrl
|
\*****************************************************************************/
SvtIconChoiceCtrl::SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle ) :
// WB_CLIPCHILDREN on, as ScrollBars lie on the window!
Control( pParent, nWinStyle | WB_CLIPCHILDREN ),
_pCurKeyEvent ( NULL ),
_pImp ( new SvxIconChoiceCtrl_Impl( this, nWinStyle ) ),
_bAutoFontColor ( sal_False )
2001-05-07 09:33:55 +00:00
{
SetLineColor();
_pImp->SetGrid( Size( 100, 70 ) );
2001-05-07 09:33:55 +00:00
_pImp->InitSettings();
_pImp->SetPositionMode( IcnViewPositionModeAutoArrange );
2001-05-07 09:33:55 +00:00
}
SvtIconChoiceCtrl::~SvtIconChoiceCtrl()
{
2002-08-13 06:25:04 +00:00
_pImp->CallEventListeners( VCLEVENT_OBJECT_DYING );
2001-05-07 09:33:55 +00:00
delete _pImp;
}
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::InsertEntry( const OUString& rText, const Image& rImage, sal_uLong nPos, const Point* pPos, sal_uInt16 nFlags )
2001-05-07 09:33:55 +00:00
{
SvxIconChoiceCtrlEntry* pEntry = new SvxIconChoiceCtrlEntry( rText, rImage, nFlags);
_pImp->InsertEntry( pEntry, nPos, pPos );
return pEntry;
}
sal_Bool SvtIconChoiceCtrl::EditedEntry( SvxIconChoiceCtrlEntry*, const OUString&, sal_Bool )
2001-05-07 09:33:55 +00:00
{
2011-03-11 18:04:44 +00:00
return sal_True;
2001-05-07 09:33:55 +00:00
}
2010-11-16 19:03:56 -08:00
sal_Bool SvtIconChoiceCtrl::EditingEntry( SvxIconChoiceCtrlEntry* )
2001-05-07 09:33:55 +00:00
{
return sal_True;
2001-05-07 09:33:55 +00:00
}
2010-11-16 19:03:56 -08:00
2001-05-07 09:33:55 +00:00
void SvtIconChoiceCtrl::DrawEntryImage( SvxIconChoiceCtrlEntry* pEntry, const Point& rPos, OutputDevice& rDev )
{
2010-11-16 19:03:56 -08:00
rDev.DrawImage( rPos, pEntry->GetImage() );
2001-05-07 09:33:55 +00:00
}
2010-11-16 19:03:56 -08:00
OUString SvtIconChoiceCtrl::GetEntryText( SvxIconChoiceCtrlEntry* pEntry, sal_Bool )
2001-05-07 09:33:55 +00:00
{
return pEntry->GetText();
}
2010-11-16 19:03:56 -08:00
sal_Bool SvtIconChoiceCtrl::HasBackground() const
2001-05-07 09:33:55 +00:00
{
return sal_False;
2001-05-07 09:33:55 +00:00
}
2010-11-16 19:03:56 -08:00
sal_Bool SvtIconChoiceCtrl::HasFont() const
2001-05-07 09:33:55 +00:00
{
return sal_False;
2001-05-07 09:33:55 +00:00
}
2010-11-16 19:03:56 -08:00
sal_Bool SvtIconChoiceCtrl::HasFontTextColor() const
2001-05-07 09:33:55 +00:00
{
return sal_True;
2001-05-07 09:33:55 +00:00
}
2010-11-16 19:03:56 -08:00
sal_Bool SvtIconChoiceCtrl::HasFontFillColor() const
2001-05-07 09:33:55 +00:00
{
return sal_True;
2001-05-07 09:33:55 +00:00
}
void SvtIconChoiceCtrl::Paint( const Rectangle& rRect )
{
_pImp->Paint( rRect );
}
void SvtIconChoiceCtrl::MouseButtonDown( const MouseEvent& rMEvt )
{
if( !_pImp->MouseButtonDown( rMEvt ) )
Control::MouseButtonDown( rMEvt );
}
void SvtIconChoiceCtrl::MouseButtonUp( const MouseEvent& rMEvt )
{
if( !_pImp->MouseButtonUp( rMEvt ) )
Control::MouseButtonUp( rMEvt );
}
void SvtIconChoiceCtrl::MouseMove( const MouseEvent& rMEvt )
{
if( !_pImp->MouseMove( rMEvt ) )
Control::MouseMove( rMEvt );
}
void SvtIconChoiceCtrl::ArrangeIcons()
{
if ( GetStyle() & WB_ALIGN_TOP )
{
Size aFullSize;
Rectangle aEntryRect;
for ( sal_uLong i = 0; i < GetEntryCount(); i++ )
2001-05-07 09:33:55 +00:00
{
SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
aFullSize.setWidth ( aFullSize.getWidth()+aEntryRect.GetWidth() );
}
_pImp->Arrange ( sal_False, aFullSize.getWidth() );
2001-05-07 09:33:55 +00:00
}
else if ( GetStyle() & WB_ALIGN_LEFT )
{
Size aFullSize;
Rectangle aEntryRect;
for ( sal_uLong i = 0; i < GetEntryCount(); i++ )
2001-05-07 09:33:55 +00:00
{
SvxIconChoiceCtrlEntry* pEntry = GetEntry ( i );
aEntryRect = _pImp->GetEntryBoundRect ( pEntry );
aFullSize.setHeight ( aFullSize.getHeight()+aEntryRect.GetHeight() );
}
_pImp->Arrange ( sal_False, 0, aFullSize.getHeight() );
2001-05-07 09:33:55 +00:00
}
else
{
_pImp->Arrange();
}
_pImp->Arrange( sal_False, 0, 1000 );
2001-05-07 09:33:55 +00:00
}
void SvtIconChoiceCtrl::Resize()
{
_pImp->Resize();
Control::Resize();
}
Point SvtIconChoiceCtrl::GetPixelPos( const Point& rPosLogic ) const
{
Point aPos( rPosLogic );
aPos += GetMapMode().GetOrigin();
return aPos;
}
void SvtIconChoiceCtrl::DocumentRectChanged()
{
_aDocRectChangedHdl.Call( this );
}
void SvtIconChoiceCtrl::VisibleRectChanged()
{
_aVisRectChangedHdl.Call( this );
}
void SvtIconChoiceCtrl::GetFocus()
{
_pImp->GetFocus();
Control::GetFocus();
sal_uLong nPos;
2002-08-13 06:25:04 +00:00
SvxIconChoiceCtrlEntry* pSelectedEntry = GetSelectedEntry ( nPos );
if ( pSelectedEntry )
_pImp->CallEventListeners( VCLEVENT_LISTBOX_SELECT, pSelectedEntry );
2001-05-07 09:33:55 +00:00
}
void SvtIconChoiceCtrl::LoseFocus()
{
_pImp->LoseFocus();
Control::LoseFocus();
}
void SvtIconChoiceCtrl::SetFont( const Font& rFont )
{
if( rFont != GetFont() )
{
Control::SetFont( rFont );
_pImp->FontModified();
}
}
void SvtIconChoiceCtrl::SetPointFont( const Font& rFont )
{
if( rFont != GetPointFont() )
{
Control::SetPointFont( rFont );
_pImp->FontModified();
}
}
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( const Point& rPixPos, sal_Bool bHit ) const
2001-05-07 09:33:55 +00:00
{
Point aPos( rPixPos );
aPos -= GetMapMode().GetOrigin();
return ((SvtIconChoiceCtrl*)this)->_pImp->GetEntry( aPos, bHit );
}
void SvtIconChoiceCtrl::SetStyle( WinBits nWinStyle )
{
_pImp->SetStyle( nWinStyle );
}
WinBits SvtIconChoiceCtrl::GetStyle() const
{
return _pImp->GetStyle();
}
void SvtIconChoiceCtrl::Command( const CommandEvent& rCEvt )
{
_pImp->Command( rCEvt );
}
void SvtIconChoiceCtrl::SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry )
{
_pImp->SetEntryTextMode( eMode, pEntry );
}
sal_uLong SvtIconChoiceCtrl::GetEntryCount() const
2001-05-07 09:33:55 +00:00
{
return _pImp->GetEntryCount();
}
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetEntry( sal_uLong nPos ) const
2001-05-07 09:33:55 +00:00
{
return _pImp->GetEntry( nPos );
}
void SvtIconChoiceCtrl::CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics )
{
_pImp->CreateAutoMnemonics( &_rUsedMnemonics );
}
void SvtIconChoiceCtrl::CreateAutoMnemonics( void )
{
_pImp->CreateAutoMnemonics();
}
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetSelectedEntry( sal_uLong& rPos ) const
2001-05-07 09:33:55 +00:00
{
return _pImp->GetFirstSelectedEntry( rPos );
}
2001-08-10 08:23:12 +00:00
2001-05-07 09:33:55 +00:00
void SvtIconChoiceCtrl::ClickIcon()
{
sal_uLong nPos;
GetSelectedEntry ( nPos );
2001-05-07 09:33:55 +00:00
_aClickIconHdl.Call( this );
}
sal_Bool SvtIconChoiceCtrl::IsEntryEditing() const
2001-05-07 09:33:55 +00:00
{
return _pImp->IsEntryEditing();
}
sal_Bool SvtIconChoiceCtrl::SetChoiceWithCursor ( sal_Bool bDo )
2001-05-07 09:33:55 +00:00
{
return _pImp->SetChoiceWithCursor (bDo);
}
2001-05-07 09:33:55 +00:00
void SvtIconChoiceCtrl::KeyInput( const KeyEvent& rKEvt )
{
sal_Bool bKeyUsed = DoKeyInput( rKEvt );
2001-05-07 09:33:55 +00:00
if ( !bKeyUsed )
{
_pCurKeyEvent = (KeyEvent*)&rKEvt;
Control::KeyInput( rKEvt );
_pCurKeyEvent = NULL;
2001-05-07 09:33:55 +00:00
}
}
sal_Bool SvtIconChoiceCtrl::DoKeyInput( const KeyEvent& rKEvt )
2001-05-07 09:33:55 +00:00
{
// under OS/2, we get key up/down even while editing
2001-05-07 09:33:55 +00:00
if( IsEntryEditing() )
return sal_True;
2001-05-07 09:33:55 +00:00
_pCurKeyEvent = (KeyEvent*)&rKEvt;
sal_Bool bHandled = _pImp->KeyInput( rKEvt );
_pCurKeyEvent = NULL;
2001-05-07 09:33:55 +00:00
return bHandled;
}
sal_uLong SvtIconChoiceCtrl::GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const
2001-05-07 09:33:55 +00:00
{
return _pImp->GetEntryListPos( pEntry );
}
2001-08-10 08:23:12 +00:00
SvxIconChoiceCtrlEntry* SvtIconChoiceCtrl::GetCursor( ) const
{
return _pImp->GetCurEntry( );
}
2001-07-04 07:37:00 +00:00
void SvtIconChoiceCtrl::SetCursor( SvxIconChoiceCtrlEntry* pEntry )
{
_pImp->SetCursor( pEntry );
}
2001-05-07 09:33:55 +00:00
void SvtIconChoiceCtrl::InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry )
{
_pImp->InvalidateEntry( pEntry );
}
2011-11-12 12:53:02 +00:00
2001-05-07 09:33:55 +00:00
void SvtIconChoiceCtrl::StateChanged( StateChangedType nType )
{
Control::StateChanged( nType );
}
void SvtIconChoiceCtrl::DataChanged( const DataChangedEvent& rDCEvt )
{
if ( ((rDCEvt.GetType() == DATACHANGED_SETTINGS) ||
(rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
(rDCEvt.GetType() == DATACHANGED_FONTS) ) &&
(rDCEvt.GetFlags() & SETTINGS_STYLE) )
{
_pImp->InitSettings();
Invalidate(INVALIDATE_NOCHILDREN);
}
else
Control::DataChanged( rDCEvt );
}
void SvtIconChoiceCtrl::SetBackground( const Wallpaper& rPaper )
{
if( rPaper != GetBackground() )
{
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
Wallpaper aEmpty;
if( rPaper == aEmpty )
Control::SetBackground( rStyleSettings.GetFieldColor() );
2001-05-07 09:33:55 +00:00
else
{
Wallpaper aBackground( rPaper );
// HACK, as background might be transparent!
2001-05-07 09:33:55 +00:00
if( !aBackground.IsBitmap() )
aBackground.SetStyle( WALLPAPER_TILE );
WallpaperStyle eStyle = aBackground.GetStyle();
Color aBack( aBackground.GetColor());
Color aTrans( COL_TRANSPARENT );
if( aBack == aTrans && (
(!aBackground.IsBitmap() ||
aBackground.GetBitmap().IsTransparent() ||
(eStyle != WALLPAPER_TILE && eStyle != WALLPAPER_SCALE))))
{
aBackground.SetColor( rStyleSettings.GetFieldColor() );
2001-05-07 09:33:55 +00:00
}
if( aBackground.IsScrollable() )
{
Rectangle aRect;
aRect.SetSize( Size(32765, 32765) );
aBackground.SetRect( aRect );
}
else
{
Rectangle aRect( _pImp->GetOutputRect() );
aBackground.SetRect( aRect );
}
Control::SetBackground( aBackground );
}
// If text colors are attributed "hard," don't use automatism to select
// a readable text color.
2001-05-07 09:33:55 +00:00
Font aFont( GetFont() );
aFont.SetColor( rStyleSettings.GetFieldTextColor() );
2001-05-07 09:33:55 +00:00
SetFont( aFont );
Invalidate(INVALIDATE_NOCHILDREN);
}
}
2001-05-07 09:33:55 +00:00
void SvtIconChoiceCtrl::RequestHelp( const HelpEvent& rHEvt )
{
if ( !_pImp->RequestHelp( rHEvt ) )
2001-05-07 09:33:55 +00:00
Control::RequestHelp( rHEvt );
}
void SvtIconChoiceCtrl::SetSelectionMode( SelectionMode eMode )
{
_pImp->SetSelectionMode( eMode );
}
2002-08-13 06:25:04 +00:00
Rectangle SvtIconChoiceCtrl::GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const
{
return _pImp->GetEntryBoundRect( pEntry );
2002-08-13 06:25:04 +00:00
}
void SvtIconChoiceCtrl::FillLayoutData() const
{
CreateLayoutData();
SvtIconChoiceCtrl* pNonConstMe = const_cast< SvtIconChoiceCtrl* >( this );
// loop through all entries
2002-09-16 08:52:34 +00:00
sal_uInt16 nCount = (sal_uInt16)GetEntryCount();
sal_uInt16 nPos = 0;
while ( nPos < nCount )
{
SvxIconChoiceCtrlEntry* pEntry = GetEntry( nPos );
Point aPos = _pImp->GetEntryBoundRect( pEntry ).TopLeft();
OUString sEntryText = pEntry->GetDisplayText( );
Rectangle aTextRect = _pImp->CalcTextRect( pEntry, &aPos, sal_False, &sEntryText );
sal_Bool bLargeIconMode = WB_ICON == ( _pImp->GetStyle() & ( VIEWMODE_MASK ) );
sal_uInt16 nTextPaintFlags = bLargeIconMode ? PAINTFLAG_HOR_CENTERED : PAINTFLAG_VER_CENTERED;
_pImp->PaintItem( aTextRect, IcnViewFieldTypeText, pEntry, nTextPaintFlags, pNonConstMe, &sEntryText, GetLayoutData() );
++nPos;
}
}
Rectangle SvtIconChoiceCtrl::GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const
{
Rectangle aRect;
Pair aEntryCharacterRange = GetLineStartEnd( _nEntryPos );
if ( aEntryCharacterRange.A() + _nCharacterIndex < aEntryCharacterRange.B() )
{
aRect = GetCharacterBounds( aEntryCharacterRange.A() + _nCharacterIndex );
}
return aRect;
}
2002-09-16 06:50:53 +00:00
void SvtIconChoiceCtrl::SetNoSelection()
{
_pImp->SetNoSelection();
}
void SvtIconChoiceCtrl::CallImplEventListeners(sal_uLong nEvent, void* pData)
2002-08-13 06:25:04 +00:00
{
CallEventListeners(nEvent, pData);
2002-08-13 06:25:04 +00:00
}
::com::sun::star::uno::Reference< XAccessible > SvtIconChoiceCtrl::CreateAccessible()
{
Window* pParent = GetAccessibleParentWindow();
DBG_ASSERT( pParent, "SvTreeListBox::CreateAccessible - accessible parent not found" );
::com::sun::star::uno::Reference< XAccessible > xAccessible;
if ( pParent )
{
::com::sun::star::uno::Reference< XAccessible > xAccParent = pParent->GetAccessible();
if ( xAccParent.is() )
{
::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > xTemp(GetComponentInterface());
xAccessible = _pImp->GetAccessibleFactory().createAccessibleIconChoiceCtrl( *this, xAccParent );
}
2002-08-13 06:25:04 +00:00
}
return xAccessible;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */