Files
libreoffice/svx/source/form/tabwin.cxx

422 lines
12 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 "tabwin.hxx"
2009-11-04 12:06:36 +01:00
#include "svx/fmtools.hxx"
2000-09-18 16:07:07 +00:00
#include "fmservs.hxx"
#include "stringlistresource.hxx"
#include <svx/svxids.hrc>
#include <svx/dbaexchange.hxx>
2000-09-18 16:07:07 +00:00
#include <com/sun/star/sdb/CommandType.hpp>
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#include <com/sun/star/sdbc/XPreparedStatement.hpp>
#include <com/sun/star/awt/XControlContainer.hpp>
#include <com/sun/star/util/XLocalizedAliases.hpp>
2000-10-20 13:18:57 +00:00
#include <comphelper/processfactory.hxx>
2000-09-18 16:07:07 +00:00
#include "fmhelp.hrc"
#include <svx/fmshell.hxx>
#include "fmshimp.hxx"
#include <svx/fmpage.hxx>
2000-09-18 16:07:07 +00:00
#include "fmpgeimp.hxx"
#include "fmprop.hrc"
#include "svx/fmresids.hrc"
#include <svx/dialmgr.hxx>
#include <svx/svdpagv.hxx>
2000-09-18 16:07:07 +00:00
#include <sfx2/objitem.hxx>
#include <sfx2/dispatch.hxx>
2000-10-20 13:18:57 +00:00
#include <comphelper/property.hxx>
#include <sfx2/frame.hxx>
#include <svx/dataaccessdescriptor.hxx>
#include "svtools/treelistentry.hxx"
#include <vcl/settings.hxx>
2000-09-18 16:07:07 +00:00
const long STD_WIN_SIZE_X = 120;
const long STD_WIN_SIZE_Y = 150;
const long LISTBOX_BORDER = 2;
2000-11-06 06:19:53 +00:00
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::datatransfer;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::form;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star;
using namespace ::svxform;
using namespace ::svx;
using namespace ::dbtools;
2000-11-06 06:19:53 +00:00
namespace {
struct ColumnInfo
{
OUString sColumnName;
OUString sLabel;
ColumnInfo(const OUString& i_sColumnName,const OUString& i_sLabel)
: sColumnName(i_sColumnName)
, sLabel(i_sLabel)
{
}
};
}
static void lcl_addToList( SvTreeListBox& _rListBox, const uno::Reference< container::XNameAccess>& i_xColumns )
{
uno::Sequence< OUString > aEntries = i_xColumns->getElementNames();
const OUString* pEntries = aEntries.getConstArray();
sal_Int32 nEntries = aEntries.getLength();
for ( sal_Int32 i = 0; i < nEntries; ++i, ++pEntries )
{
uno::Reference< beans::XPropertySet> xColumn(i_xColumns->getByName(*pEntries),UNO_QUERY_THROW);
OUString sLabel;
if ( xColumn->getPropertySetInfo()->hasPropertyByName(FM_PROP_LABEL) )
xColumn->getPropertyValue(FM_PROP_LABEL) >>= sLabel;
if ( !sLabel.isEmpty() )
_rListBox.InsertEntry( sLabel, NULL, false, TREELIST_APPEND, new ColumnInfo(*pEntries,sLabel) );
else
_rListBox.InsertEntry( *pEntries, NULL, false, TREELIST_APPEND, new ColumnInfo(*pEntries,sLabel) );
}
}
2000-09-18 16:07:07 +00:00
FmFieldWinListBox::FmFieldWinListBox( FmFieldWin* pParent )
:SvTreeListBox( pParent, WB_HASBUTTONS|WB_BORDER )
,pTabWin( pParent )
{
SetHelpId( HID_FIELD_SEL );
SetHighlightRange( );
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
FmFieldWinListBox::~FmFieldWinListBox()
{
}
sal_Int8 FmFieldWinListBox::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
{
return DND_ACTION_NONE;
}
sal_Int8 FmFieldWinListBox::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
{
return DND_ACTION_NONE;
}
bool FmFieldWinListBox::DoubleClickHdl()
{
if ( pTabWin->createSelectionControls() )
return true;
return SvTreeListBox::DoubleClickHdl();
}
void FmFieldWinListBox::StartDrag( sal_Int8 /*_nAction*/, const Point& /*_rPosPixel*/ )
2000-09-18 16:07:07 +00:00
{
SvTreeListEntry* pSelected = FirstSelected();
if (!pSelected)
// no drag without a field
return;
::svx::ODataAccessDescriptor aDescriptor;
aDescriptor[ daDataSource ] <<= pTabWin->GetDatabaseName();
aDescriptor[ daConnection ] <<= pTabWin->GetConnection().getTyped();
aDescriptor[ daCommand ] <<= pTabWin->GetObjectName();
aDescriptor[ daCommandType ]<<= pTabWin->GetObjectType();
ColumnInfo* pInfo = static_cast<ColumnInfo*>(pSelected->GetUserData());
aDescriptor[ daColumnName ] <<= pInfo->sColumnName;
TransferableHelper* pTransferColumn = new OColumnTransferable(
aDescriptor, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR
);
Reference< XTransferable> xEnsureDelete = pTransferColumn;
EndSelection();
pTransferColumn->StartDrag( this, DND_ACTION_COPY );
2000-09-18 16:07:07 +00:00
}
FmFieldWinData::FmFieldWinData()
{
}
2000-09-18 16:07:07 +00:00
FmFieldWinData::~FmFieldWinData()
{
}
FmFieldWin::FmFieldWin(SfxBindings* _pBindings, SfxChildWindow* _pMgr, vcl::Window* _pParent)
:SfxFloatingWindow(_pBindings, _pMgr, _pParent, WinBits(WB_STDMODELESS|WB_SIZEABLE))
,SfxControllerItem(SID_FM_FIELDS_CONTROL, *_pBindings)
2000-10-20 13:18:57 +00:00
,::comphelper::OPropertyChangeListener(m_aMutex)
2000-09-18 16:07:07 +00:00
,pData(new FmFieldWinData)
,m_nObjectType(0)
,m_pChangeListener(NULL)
{
SetHelpId( HID_FIELD_SEL_WIN );
SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor()) );
pListBox = new FmFieldWinListBox( this );
pListBox->Show();
UpdateContent(NULL);
2000-09-18 16:07:07 +00:00
SetSizePixel(Size(STD_WIN_SIZE_X,STD_WIN_SIZE_Y));
}
2000-09-18 16:07:07 +00:00
FmFieldWin::~FmFieldWin()
{
if (m_pChangeListener)
{
m_pChangeListener->dispose();
m_pChangeListener->release();
// delete m_pChangeListener;
}
delete pListBox;
delete pData;
}
void FmFieldWin::GetFocus()
{
if ( pListBox )
pListBox->GrabFocus();
else
SfxFloatingWindow::GetFocus();
}
bool FmFieldWin::createSelectionControls( )
{
SvTreeListEntry* pSelected = pListBox->FirstSelected();
if ( pSelected )
{
// build a descriptor for the currently selected field
ODataAccessDescriptor aDescr;
aDescr.setDataSource(GetDatabaseName());
aDescr[ daConnection ] <<= GetConnection().getTyped();
aDescr[ daCommand ] <<= GetObjectName();
aDescr[ daCommandType ] <<= GetObjectType();
ColumnInfo* pInfo = static_cast<ColumnInfo*>(pSelected->GetUserData());
aDescr[ daColumnName ] <<= pInfo->sColumnName;//OUString( pListBox->GetEntryText( pSelected) );
// transfer this to the SFX world
SfxUnoAnyItem aDescriptorItem( SID_FM_DATACCESS_DESCRIPTOR, makeAny( aDescr.createPropertyValueSequence() ) );
const SfxPoolItem* pArgs[] =
{
&aDescriptorItem, NULL
};
// execute the create slot
GetBindings().Execute( SID_FM_CREATE_FIELDCONTROL, pArgs );
}
return NULL != pSelected;
}
bool FmFieldWin::PreNotify( NotifyEvent& _rNEvt )
{
if ( MouseNotifyEvent::KEYINPUT == _rNEvt.GetType() )
{
const vcl::KeyCode& rKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode();
if ( ( 0 == rKeyCode.GetModifier() ) && ( KEY_RETURN == rKeyCode.GetCode() ) )
{
if ( createSelectionControls() )
return true;
}
}
return SfxFloatingWindow::PreNotify( _rNEvt );
}
bool FmFieldWin::Close()
2000-09-18 16:07:07 +00:00
{
return SfxFloatingWindow::Close();
}
2000-09-18 16:07:07 +00:00
void FmFieldWin::_propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw( ::com::sun::star::uno::RuntimeException )
{
::com::sun::star::uno::Reference< ::com::sun::star::form::XForm > xForm(evt.Source, ::com::sun::star::uno::UNO_QUERY);
UpdateContent(xForm);
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
void FmFieldWin::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
{
if (!pState || SID_FM_FIELDS_CONTROL != nSID)
return;
if (eState >= SfxItemState::DEFAULT)
2000-09-18 16:07:07 +00:00
{
FmFormShell* pShell = PTR_CAST(FmFormShell, static_cast<const SfxObjectItem*>(pState)->GetShell());
UpdateContent(pShell);
2000-09-18 16:07:07 +00:00
}
else
UpdateContent(NULL);
2000-09-18 16:07:07 +00:00
}
void FmFieldWin::UpdateContent(FmFormShell* pShell)
2000-09-18 16:07:07 +00:00
{
pListBox->Clear();
OUString aTitle(SVX_RESSTR(RID_STR_FIELDSELECTION));
SetText( aTitle );
2000-09-18 16:07:07 +00:00
if (!pShell || !pShell->GetImpl())
return;
2000-09-18 16:07:07 +00:00
Reference< XForm > xForm = pShell->GetImpl()->getCurrentForm();
if ( xForm.is() )
UpdateContent( xForm );
2000-09-18 16:07:07 +00:00
}
void FmFieldWin::UpdateContent(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XForm > & xForm)
2000-09-18 16:07:07 +00:00
{
try
2000-09-18 16:07:07 +00:00
{
// delete ListBox
pListBox->Clear();
OUString aTitle(SVX_RES(RID_STR_FIELDSELECTION));
SetText(aTitle);
if (!xForm.is())
return;
Reference< XPreparedStatement > xStatement;
Reference< XPropertySet > xSet(xForm, UNO_QUERY);
m_aObjectName = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_COMMAND));
m_aDatabaseName = ::comphelper::getString(xSet->getPropertyValue(FM_PROP_DATASOURCE));
m_nObjectType = ::comphelper::getINT32(xSet->getPropertyValue(FM_PROP_COMMANDTYPE));
// get the connection of the form
m_aConnection.reset(
connectRowset( Reference< XRowSet >( xForm, UNO_QUERY ), ::comphelper::getProcessComponentContext(), true ),
SharedConnection::NoTakeOwnership
);
// TODO: When incompatible changes (such as extending the "virtualdbtools" interface by ensureRowSetConnection)
// are allowed, again, we should change this: dbtools should consistently use SharedConnection all over
// the place, and connectRowset should be replaced with ensureRowSetConnection
// get the fields of the object
if ( m_aConnection.is() && !m_aObjectName.isEmpty() )
{
Reference< XComponent > xKeepFieldsAlive;
Reference< XNameAccess > xColumns = getFieldsByCommandDescriptor( m_aConnection, m_nObjectType, m_aObjectName,xKeepFieldsAlive );
if ( xColumns.is() )
lcl_addToList(*pListBox,xColumns);
}
// set prefix
OUString aPrefix;
StringListResource aPrefixes( SVX_RES( RID_RSC_TABWIN_PREFIX ) );
switch (m_nObjectType)
{
case CommandType::TABLE:
aPrefix = aPrefixes[0];
break;
case CommandType::QUERY:
aPrefix = aPrefixes[1];
break;
default:
aPrefix = aPrefixes[2];
break;
}
2000-09-18 16:07:07 +00:00
// listen for changes at ControlSource in PropertySet
if (m_pChangeListener)
{
m_pChangeListener->dispose();
m_pChangeListener->release();
}
m_pChangeListener = new ::comphelper::OPropertyChangeMultiplexer(this, xSet);
m_pChangeListener->acquire();
m_pChangeListener->addProperty(FM_PROP_DATASOURCE);
m_pChangeListener->addProperty(FM_PROP_COMMAND);
m_pChangeListener->addProperty(FM_PROP_COMMANDTYPE);
// Titel setzen
aTitle = aTitle + " " + aPrefix + " " + OUString(m_aObjectName.getStr());
SetText( aTitle );
}
catch( const Exception& )
2000-09-18 16:07:07 +00:00
{
2011-03-01 19:07:44 +01:00
OSL_FAIL( "FmTabWin::UpdateContent: caught an exception!" );
2000-09-18 16:07:07 +00:00
}
}
2000-09-18 16:07:07 +00:00
void FmFieldWin::Resize()
{
SfxFloatingWindow::Resize();
Size aOutputSize( GetOutputSizePixel() );
2000-09-18 16:07:07 +00:00
2000-09-18 16:07:07 +00:00
// adapt size of ::com::sun::star::form::ListBox
2000-09-18 16:07:07 +00:00
Point aLBPos( LISTBOX_BORDER, LISTBOX_BORDER );
Size aLBSize( aOutputSize );
2000-09-18 16:07:07 +00:00
aLBSize.Width() -= (2*LISTBOX_BORDER);
aLBSize.Height() -= (2*LISTBOX_BORDER);
pListBox->SetPosSizePixel( aLBPos, aLBSize );
}
2000-09-18 16:07:07 +00:00
void FmFieldWin::FillInfo( SfxChildWinInfo& rInfo ) const
{
rInfo.bVisible = false;
2000-09-18 16:07:07 +00:00
}
2000-09-18 16:07:07 +00:00
SFX_IMPL_FLOATINGWINDOW(FmFieldWinMgr, SID_FM_ADD_FIELD)
FmFieldWinMgr::FmFieldWinMgr(vcl::Window* _pParent, sal_uInt16 _nId,
SfxBindings* _pBindings, SfxChildWinInfo* _pInfo)
:SfxChildWindow(_pParent, _nId)
2000-09-18 16:07:07 +00:00
{
pWindow = new FmFieldWin(_pBindings, this, _pParent);
SetHideNotDelete(true);
eChildAlignment = SfxChildAlignment::NOALIGNMENT;
static_cast<SfxFloatingWindow*>(pWindow)->Initialize( _pInfo );
2000-09-18 16:07:07 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */