Files
libreoffice/dbaccess/source/ui/browser/brwview.cxx

405 lines
14 KiB
C++
Raw Normal View History

2000-10-26 13:46:14 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-10-26 13:46:14 +00:00
*
* $RCSfile: brwview.cxx,v $
2000-10-26 13:46:14 +00:00
*
* $Revision: 1.22 $
2000-10-26 13:46:14 +00:00
*
* last change: $Author: rt $ $Date: 2005-09-08 14:25:57 $
2000-10-26 13:46:14 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-10-26 13:46:14 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-10-26 13:46:14 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-10-26 13:46:14 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-10-26 13:46:14 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-10-26 13:46:14 +00:00
*
************************************************************************/
#ifndef _SBA_BWRCTRLR_HXX
#include "brwctrlr.hxx"
#endif
2000-10-26 13:46:14 +00:00
#ifndef _SBX_BRWVIEW_HXX
#include "brwview.hxx"
#endif
#ifndef _SBA_GRID_HXX
#include "sbagrid.hxx"
#endif
#ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
#include <toolkit/helper/vclunohelper.hxx>
#endif
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
#ifndef _SV_SPLIT_HXX
#include <vcl/split.hxx>
#endif
#ifndef DBACCESS_UI_DBTREEVIEW_HXX
#include "dbtreeview.hxx"
#endif
#ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
#include "dbustrings.hrc"
#endif
#ifndef _DBAUI_MODULE_DBU_HXX_
#include "moduledbu.hxx"
#endif
2002-08-19 06:32:53 +00:00
#ifndef _DBU_BRW_HRC_
#include "dbu_brw.hrc"
2000-10-26 13:46:14 +00:00
#endif
#ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
#include <com/sun/star/form/XLoadable.hpp>
#endif
2002-02-11 11:32:29 +00:00
#ifndef _COM_SUN_STAR_AWT_XCONTROLCONTAINER_HPP_
#include <com/sun/star/awt/XControlContainer.hpp>
#endif
2002-04-29 07:25:58 +00:00
#ifndef DBAUI_TOOLS_HXX
#include "UITools.hxx"
#endif
2000-10-26 13:46:14 +00:00
using namespace dbaui;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::form;
2000-10-26 13:46:14 +00:00
// using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
2000-10-26 13:46:14 +00:00
2002-02-11 11:32:29 +00:00
namespace
{
sal_Bool isGrabVclControlFocusAllowed(const UnoDataBrowserView* _pView)
{
sal_Bool bGrabFocus = sal_False;
SbaGridControl* pVclControl = _pView->getVclControl();
Reference< ::com::sun::star::awt::XControl > xGrid = _pView->getGridControl();
if (pVclControl && xGrid.is())
{
bGrabFocus = sal_True;
if(!pVclControl->HasChildPathFocus())
{
Reference<XChild> xChild(xGrid->getModel(),UNO_QUERY);
Reference<XLoadable> xLoad;
if(xChild.is())
xLoad.set(xChild->getParent(),UNO_QUERY);
2002-02-11 11:32:29 +00:00
bGrabFocus = xLoad.is() && xLoad->isLoaded();
}
}
return bGrabFocus;
}
}
2000-10-26 13:46:14 +00:00
//==================================================================
//= UnoDataBrowserView
//==================================================================
// -------------------------------------------------------------------------
2002-02-11 11:32:29 +00:00
UnoDataBrowserView::UnoDataBrowserView( Window* pParent,
IController* _pController,
const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rFactory)
:ODataView(pParent,_pController,_rFactory)
2000-10-26 13:46:14 +00:00
,m_pVclControl(NULL)
,m_pSplitter(NULL)
,m_pTreeView(NULL)
2001-04-03 07:15:53 +00:00
,m_pStatus(NULL)
2000-10-26 13:46:14 +00:00
{
}
// -------------------------------------------------------------------------
void UnoDataBrowserView::Construct(const Reference< ::com::sun::star::awt::XControlModel >& xModel)
{
try
{
ODataView::Construct();
// our UNO representation
m_xMe = VCLUnoHelper::CreateControlContainer(this);
2000-10-26 13:46:14 +00:00
// create the (UNO-) control
2001-01-09 14:52:33 +00:00
m_xGrid = new SbaXGridControl(getORB());
2000-10-26 13:46:14 +00:00
DBG_ASSERT(m_xGrid.is(), "UnoDataBrowserView::Construct : could not create a grid control !");
// in design mode (for the moment)
m_xGrid->setDesignMode(sal_True);
Reference< ::com::sun::star::awt::XWindow > xGridWindow(m_xGrid, UNO_QUERY);
xGridWindow->setVisible(sal_True);
xGridWindow->setEnable(sal_True);
// introduce the model to the grid
m_xGrid->setModel(xModel);
// introduce the container (me) to the grid
Reference< ::com::sun::star::beans::XPropertySet > xModelSet(xModel, UNO_QUERY);
2001-01-09 14:52:33 +00:00
getContainer()->addControl(::comphelper::getString(xModelSet->getPropertyValue(PROPERTY_NAME)), m_xGrid);
2000-10-26 13:46:14 +00:00
// get the VCL-control
m_pVclControl = NULL;
getVclControl();
2000-10-26 13:46:14 +00:00
DBG_ASSERT(m_pVclControl != NULL, "UnoDataBrowserView::Construct : no real grid control !");
}
2001-01-09 14:52:33 +00:00
catch(Exception&)
2000-10-26 13:46:14 +00:00
{
::comphelper::disposeComponent(m_xGrid);
throw;
}
}
// -------------------------------------------------------------------------
UnoDataBrowserView::~UnoDataBrowserView()
{
{
::std::auto_ptr<Splitter> aTemp(m_pSplitter);
m_pSplitter = NULL;
}
2002-04-29 07:25:58 +00:00
setTreeView(NULL);
if ( m_pStatus )
{
delete m_pStatus;
m_pStatus = NULL;
}
try
{
::comphelper::disposeComponent(m_xGrid);
::comphelper::disposeComponent(m_xMe);
}
catch(Exception)
{}
2000-10-26 13:46:14 +00:00
}
// -----------------------------------------------------------------------------
IMPL_LINK( UnoDataBrowserView, SplitHdl, void*, p )
{
long nTest = m_pSplitter->GetPosPixel().Y();
2000-10-26 13:46:14 +00:00
m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), m_pSplitter->GetPosPixel().Y() ) );
Resize();
return 0L;
}
// -------------------------------------------------------------------------
void UnoDataBrowserView::setSplitter(Splitter* _pSplitter)
{
m_pSplitter = _pSplitter;
m_pSplitter->SetSplitHdl( LINK( this, UnoDataBrowserView, SplitHdl ) );
2000-11-06 16:41:04 +00:00
LINK( this, UnoDataBrowserView, SplitHdl ).Call(m_pSplitter);
2000-10-26 13:46:14 +00:00
}
// -------------------------------------------------------------------------
void UnoDataBrowserView::setTreeView(DBTreeView* _pTreeView)
{
2001-01-09 14:52:33 +00:00
if (m_pTreeView != _pTreeView)
{
if (m_pTreeView)
{
::std::auto_ptr<Window> aTemp(m_pTreeView);
m_pTreeView = NULL;
}
2001-01-09 14:52:33 +00:00
m_pTreeView = _pTreeView;
}
2000-10-26 13:46:14 +00:00
}
2001-04-03 07:15:53 +00:00
// -------------------------------------------------------------------------
2001-04-12 14:31:09 +00:00
void UnoDataBrowserView::showStatus( const String& _rStatus )
2001-04-03 07:15:53 +00:00
{
if (0 == _rStatus.Len())
hideStatus();
else
{
if (!m_pStatus)
m_pStatus = new FixedText(this);
m_pStatus->SetText(_rStatus);
m_pStatus->Show();
Resize();
Update();
}
}
// -------------------------------------------------------------------------
void UnoDataBrowserView::hideStatus()
{
if (!m_pStatus || !m_pStatus->IsVisible())
// nothing to do
return;
m_pStatus->Hide();
Resize();
Update();
}
2000-10-26 13:46:14 +00:00
// -------------------------------------------------------------------------
void UnoDataBrowserView::resizeDocumentView(Rectangle& _rPlayground)
2000-10-26 13:46:14 +00:00
{
2001-08-15 12:43:46 +00:00
Point aSplitPos;
Size aSplitSize;
Point aPlaygroundPos( _rPlayground.TopLeft() );
Size aPlaygroundSize( _rPlayground.GetSize() );
2000-12-08 20:18:38 +00:00
if (m_pTreeView && m_pTreeView->IsVisible() && m_pSplitter)
2000-10-26 13:46:14 +00:00
{
2001-08-15 12:43:46 +00:00
// calculate the splitter pos and size
2000-10-26 13:46:14 +00:00
aSplitPos = m_pSplitter->GetPosPixel();
2001-08-15 12:43:46 +00:00
aSplitPos.Y() = aPlaygroundPos.Y();
2000-10-26 13:46:14 +00:00
aSplitSize = m_pSplitter->GetOutputSizePixel();
2001-08-15 12:43:46 +00:00
aSplitSize.Height() = aPlaygroundSize.Height();
2000-10-26 13:46:14 +00:00
2001-08-15 12:43:46 +00:00
if( ( aSplitPos.X() + aSplitSize.Width() ) > ( aPlaygroundSize.Width() ))
aSplitPos.X() = aPlaygroundSize.Width() - aSplitSize.Width();
2000-10-26 13:46:14 +00:00
2001-08-15 12:43:46 +00:00
if( aSplitPos.X() <= aPlaygroundPos.X() )
aSplitPos.X() = aPlaygroundPos.X() + sal_Int32(aPlaygroundSize.Width() * 0.2);
2000-12-08 20:18:38 +00:00
2001-08-15 12:43:46 +00:00
// the tree pos and size
Point aTreeViewPos( aPlaygroundPos );
Size aTreeViewSize( aSplitPos.X(), aPlaygroundSize.Height() );
2001-04-03 07:15:53 +00:00
2001-08-15 12:43:46 +00:00
// the status pos and size
2001-04-03 07:15:53 +00:00
if (m_pStatus && m_pStatus->IsVisible())
{
2001-08-15 12:43:46 +00:00
Size aStatusSize(aPlaygroundPos.X(), GetTextHeight() + 2);
2001-04-03 07:15:53 +00:00
aStatusSize = LogicToPixel(aStatusSize, MAP_APPFONT);
aStatusSize.Width() = aTreeViewSize.Width() - 2 - 2;
2001-08-15 12:43:46 +00:00
Point aStatusPos( aPlaygroundPos.X() + 2, aTreeViewPos.Y() + aTreeViewSize.Height() - aStatusSize.Height() );
2001-04-03 07:15:53 +00:00
m_pStatus->SetPosSizePixel( aStatusPos, aStatusSize );
aTreeViewSize.Height() -= aStatusSize.Height();
}
2000-10-26 13:46:14 +00:00
// set the size of treelistbox
2001-04-03 07:15:53 +00:00
m_pTreeView->SetPosSizePixel( aTreeViewPos, aTreeViewSize );
2000-10-26 13:46:14 +00:00
//set the size of the splitter
2001-08-15 12:43:46 +00:00
m_pSplitter->SetPosSizePixel( aSplitPos, Size( aSplitSize.Width(), aPlaygroundSize.Height() ) );
m_pSplitter->SetDragRectPixel( _rPlayground );
2000-10-26 13:46:14 +00:00
}
// set the size of grid control
Reference< ::com::sun::star::awt::XWindow > xGridAsWindow(m_xGrid, UNO_QUERY);
if (xGridAsWindow.is())
2001-08-15 12:43:46 +00:00
xGridAsWindow->setPosSize( aSplitPos.X() + aSplitSize.Width(), aPlaygroundPos.Y(),
aPlaygroundSize.Width() - aSplitSize.Width() - aSplitPos.X(), aPlaygroundSize.Height(), ::com::sun::star::awt::PosSize::POSSIZE);
2000-10-26 13:46:14 +00:00
2001-08-15 12:43:46 +00:00
// just for completeness: there is no space left, we occupied it all ...
_rPlayground.SetPos( _rPlayground.BottomRight() );
_rPlayground.SetSize( Size( 0, 0 ) );
2000-10-26 13:46:14 +00:00
}
//------------------------------------------------------------------
sal_uInt16 UnoDataBrowserView::Model2ViewPos(sal_uInt16 nPos) const
{
return m_pVclControl ? m_pVclControl->GetViewColumnPos(m_pVclControl->GetColumnIdFromModelPos(nPos)) : -1;
}
//------------------------------------------------------------------
sal_uInt16 UnoDataBrowserView::View2ModelPos(sal_uInt16 nPos) const
{
return m_pVclControl ? m_pVclControl->GetModelColumnPos(m_pVclControl->GetColumnIdFromViewPos(nPos)) : -1;
}
//------------------------------------------------------------------
sal_uInt16 UnoDataBrowserView::ViewColumnCount() const
{
return m_pVclControl ? m_pVclControl->GetViewColCount() : 0;
}
// -----------------------------------------------------------------------------
SbaGridControl* UnoDataBrowserView::getVclControl() const
{
if ( !m_pVclControl )
{
OSL_ENSURE(m_xGrid.is(),"Grid not set!");
if ( m_xGrid.is() )
{
Reference< ::com::sun::star::awt::XWindowPeer > xPeer = m_xGrid->getPeer();
if ( xPeer.is() )
{
SbaXGridPeer* pPeer = SbaXGridPeer::getImplementation(xPeer);
UnoDataBrowserView* pTHIS = const_cast<UnoDataBrowserView*>(this);
if ( pPeer )
{
m_pVclControl = static_cast<SbaGridControl*>(pPeer->GetWindow());
pTHIS->startComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
}
}
}
}
return m_pVclControl;
}
// -----------------------------------------------------------------------------
2000-10-26 13:46:14 +00:00
void UnoDataBrowserView::GetFocus()
{
2002-05-02 06:10:09 +00:00
ODataView::GetFocus();
if( m_pTreeView && m_pTreeView->IsVisible() && !m_pTreeView->HasChildPathFocus())
2002-02-11 11:32:29 +00:00
m_pTreeView->GrabFocus();
else if (m_pVclControl && m_xGrid.is())
{
2002-02-11 11:32:29 +00:00
sal_Bool bGrabFocus = sal_False;
if(!m_pVclControl->HasChildPathFocus())
{
2002-02-11 11:32:29 +00:00
bGrabFocus = isGrabVclControlFocusAllowed(this);
if( bGrabFocus )
m_pVclControl->GrabFocus();
}
2002-05-02 06:10:09 +00:00
if(!bGrabFocus && m_pTreeView && m_pTreeView->IsVisible() )
m_pTreeView->GrabFocus();
}
2000-10-26 13:46:14 +00:00
}
// -----------------------------------------------------------------------------
void UnoDataBrowserView::_disposing( const ::com::sun::star::lang::EventObject& _rSource )
{
stopComponentListening(Reference<XComponent>(VCLUnoHelper::GetInterface(m_pVclControl),UNO_QUERY));
m_pVclControl = NULL;
}
2000-10-26 13:46:14 +00:00
// -------------------------------------------------------------------------
long UnoDataBrowserView::PreNotify( NotifyEvent& rNEvt )
{
long nDone = 0L;
if(rNEvt.GetType() == EVENT_KEYINPUT)
{
2002-02-11 11:32:29 +00:00
sal_Bool bGrabAllowed = isGrabVclControlFocusAllowed(this);
2002-05-02 06:10:09 +00:00
if ( bGrabAllowed )
2002-02-11 11:32:29 +00:00
{
2002-05-02 06:10:09 +00:00
const KeyEvent* pKeyEvt = rNEvt.GetKeyEvent();
const KeyCode& rKeyCode = pKeyEvt->GetKeyCode();
if ( ( rKeyCode == KeyCode( KEY_E, TRUE, TRUE, FALSE ) )
|| ( rKeyCode == KeyCode( KEY_TAB, TRUE, FALSE, FALSE ) )
)
2002-02-11 11:32:29 +00:00
{
2002-05-02 06:10:09 +00:00
if ( m_pTreeView && m_pVclControl && m_pTreeView->HasChildPathFocus() )
m_pVclControl->GrabFocus();
else if ( m_pTreeView && m_pVclControl && m_pVclControl->HasChildPathFocus() )
m_pTreeView->GrabFocus();
2002-05-02 06:10:09 +00:00
nDone = 1L;
2002-02-11 11:32:29 +00:00
}
}
}
2002-05-02 06:10:09 +00:00
return nDone ? nDone : ODataView::PreNotify(rNEvt);
}
2001-04-12 14:31:09 +00:00
// -----------------------------------------------------------------------------
2001-04-12 14:31:09 +00:00
BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView* _pView, const String& _rStatus )
:m_pView(_pView)
{
if (m_pView)
m_pView->showStatus(_rStatus);
}
2001-04-12 14:31:09 +00:00
// -----------------------------------------------------------------------------
BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
{
if (m_pView)
m_pView->showStatus(String());
}
2002-05-02 06:10:09 +00:00
// -----------------------------------------------------------------------------