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

347 lines
11 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2012-06-14 17:39:53 +01: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-10-26 13:46:14 +00:00
#include "brwctrlr.hxx"
2000-10-26 13:46:14 +00:00
#include "brwview.hxx"
#include "sbagrid.hxx"
#include <toolkit/helper/vclunohelper.hxx>
#include <comphelper/types.hxx>
#include <vcl/split.hxx>
#include "dbtreeview.hxx"
#include "dbustrings.hrc"
2002-08-19 06:32:53 +00:00
#include "dbu_brw.hrc"
#include <com/sun/star/form/XLoadable.hpp>
2002-02-11 11:32:29 +00:00
#include <com/sun/star/awt/XControlContainer.hpp>
2002-04-29 07:25:58 +00:00
#include "UITools.hxx"
2011-02-03 00:33:36 +01:00
#include <osl/diagnose.h>
#include <boost/scoped_ptr.hpp>
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::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
{
bool isGrabVclControlFocusAllowed(const UnoDataBrowserView* _pView)
2002-02-11 11:32:29 +00:00
{
bool bGrabFocus = false;
2002-02-11 11:32:29 +00:00
SbaGridControl* pVclControl = _pView->getVclControl();
Reference< ::com::sun::star::awt::XControl > xGrid = _pView->getGridControl();
if (pVclControl && xGrid.is())
{
bGrabFocus = true;
2002-02-11 11:32:29 +00:00
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;
}
}
// UnoDataBrowserView
2000-10-26 13:46:14 +00:00
UnoDataBrowserView::UnoDataBrowserView( vcl::Window* pParent,
IController& _rController,
const Reference< ::com::sun::star::uno::XComponentContext >& _rxContext)
:ODataView(pParent,_rController,_rxContext)
2000-10-26 13:46:14 +00:00
,m_pTreeView(NULL)
,m_pSplitter(NULL)
,m_pVclControl(NULL)
2001-04-03 07:15:53 +00:00
,m_pStatus(NULL)
2000-10-26 13:46:14 +00:00
{
2000-10-26 13:46:14 +00:00
}
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
m_xGrid = new SbaXGridControl( getORB() );
2011-02-03 00:33:36 +01:00
OSL_ENSURE(m_xGrid.is(), "UnoDataBrowserView::Construct : could not create a grid control !");
2000-10-26 13:46:14 +00:00
// 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
2011-02-03 00:33:36 +01:00
OSL_ENSURE(m_pVclControl != NULL, "UnoDataBrowserView::Construct : no real grid control !");
2000-10-26 13:46:14 +00:00
}
2011-04-13 09:40:26 +01:00
catch(const Exception&)
2000-10-26 13:46:14 +00:00
{
::comphelper::disposeComponent(m_xGrid);
throw;
}
}
2000-10-26 13:46:14 +00:00
UnoDataBrowserView::~UnoDataBrowserView()
{
{
boost::scoped_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);
}
2011-04-13 09:40:26 +01:00
catch(const Exception&)
{}
2000-10-26 13:46:14 +00:00
}
IMPL_LINK( UnoDataBrowserView, SplitHdl, void*, /*NOINTERESTEDIN*/ )
2000-10-26 13:46:14 +00:00
{
long nYPos = m_pSplitter->GetPosPixel().Y();
m_pSplitter->SetPosPixel( Point( m_pSplitter->GetSplitPosPixel(), nYPos ) );
2000-10-26 13:46:14 +00:00
Resize();
return 0L;
}
2000-10-26 13:46:14 +00:00
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
}
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)
{
boost::scoped_ptr<vcl::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
}
void UnoDataBrowserView::showStatus( const OUString& _rStatus )
2001-04-03 07:15:53 +00:00
{
if (_rStatus.isEmpty())
2001-04-03 07:15:53 +00:00
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();
}
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::View2ModelPos(sal_uInt16 nPos) const
{
return m_pVclControl ? m_pVclControl->GetModelColumnPos(m_pVclControl->GetColumnIdFromViewPos(nPos)) : -1;
}
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())
{
bool bGrabFocus = 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;
}
bool UnoDataBrowserView::PreNotify( NotifyEvent& rNEvt )
{
bool nDone = false;
if(rNEvt.GetType() == MouseNotifyEvent::KEYINPUT)
{
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 vcl::KeyCode& rKeyCode = pKeyEvt->GetKeyCode();
if ( ( rKeyCode == vcl::KeyCode( KEY_E, true, true, false, false ) )
|| ( rKeyCode == vcl::KeyCode( KEY_TAB, true, false, 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();
nDone = true;
2002-02-11 11:32:29 +00:00
}
}
}
return nDone || ODataView::PreNotify(rNEvt);
}
2001-04-12 14:31:09 +00:00
BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView* _pView, const OUString& _rStatus )
2001-04-12 14:31:09 +00:00
:m_pView(_pView)
{
2001-04-12 14:31:09 +00:00
if (m_pView)
m_pView->showStatus(_rStatus);
}
2001-04-12 14:31:09 +00:00
BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
{
if (m_pView)
m_pView->showStatus(OUString());
2001-04-12 14:31:09 +00:00
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */