1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: brwview.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _SBA_BWRCTRLR_HXX
35 #include "brwctrlr.hxx"
37 #ifndef _SBX_BRWVIEW_HXX
38 #include "brwview.hxx"
41 #include "sbagrid.hxx"
43 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
44 #include <toolkit/helper/vclunohelper.hxx>
46 #ifndef _COMPHELPER_TYPES_HXX_
47 #include <comphelper/types.hxx>
50 #include <vcl/split.hxx>
52 #ifndef DBACCESS_UI_DBTREEVIEW_HXX
53 #include "dbtreeview.hxx"
55 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
56 #include "dbustrings.hrc"
59 #include "dbu_brw.hrc"
61 #ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
62 #include <com/sun/star/form/XLoadable.hpp>
64 #ifndef _COM_SUN_STAR_AWT_XCONTROLCONTAINER_HPP_
65 #include <com/sun/star/awt/XControlContainer.hpp>
67 #ifndef DBAUI_TOOLS_HXX
68 #include "UITools.hxx"
72 using namespace dbaui
;
73 using namespace ::com::sun::star::uno
;
74 using namespace ::com::sun::star::sdb
;
75 using namespace ::com::sun::star::form
;
76 // using namespace ::com::sun::star::sdbcx;
77 using namespace ::com::sun::star::beans
;
78 using namespace ::com::sun::star::container
;
79 using namespace ::com::sun::star::lang
;
84 sal_Bool
isGrabVclControlFocusAllowed(const UnoDataBrowserView
* _pView
)
86 sal_Bool bGrabFocus
= sal_False
;
87 SbaGridControl
* pVclControl
= _pView
->getVclControl();
88 Reference
< ::com::sun::star::awt::XControl
> xGrid
= _pView
->getGridControl();
89 if (pVclControl
&& xGrid
.is())
91 bGrabFocus
= sal_True
;
92 if(!pVclControl
->HasChildPathFocus())
94 Reference
<XChild
> xChild(xGrid
->getModel(),UNO_QUERY
);
95 Reference
<XLoadable
> xLoad
;
97 xLoad
.set(xChild
->getParent(),UNO_QUERY
);
98 bGrabFocus
= xLoad
.is() && xLoad
->isLoaded();
104 //==================================================================
105 //= UnoDataBrowserView
106 //==================================================================
108 DBG_NAME(UnoDataBrowserView
)
109 // -------------------------------------------------------------------------
110 UnoDataBrowserView::UnoDataBrowserView( Window
* pParent
,
111 IController
& _rController
,
112 const Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rFactory
)
113 :ODataView(pParent
,_rController
,_rFactory
)
119 DBG_CTOR(UnoDataBrowserView
,NULL
);
122 // -------------------------------------------------------------------------
123 void UnoDataBrowserView::Construct(const Reference
< ::com::sun::star::awt::XControlModel
>& xModel
)
127 ODataView::Construct();
129 // our UNO representation
130 m_xMe
= VCLUnoHelper::CreateControlContainer(this);
132 // create the (UNO-) control
133 m_xGrid
= new SbaXGridControl(getORB());
134 DBG_ASSERT(m_xGrid
.is(), "UnoDataBrowserView::Construct : could not create a grid control !");
135 // in design mode (for the moment)
136 m_xGrid
->setDesignMode(sal_True
);
138 Reference
< ::com::sun::star::awt::XWindow
> xGridWindow(m_xGrid
, UNO_QUERY
);
139 xGridWindow
->setVisible(sal_True
);
140 xGridWindow
->setEnable(sal_True
);
142 // introduce the model to the grid
143 m_xGrid
->setModel(xModel
);
144 // introduce the container (me) to the grid
145 Reference
< ::com::sun::star::beans::XPropertySet
> xModelSet(xModel
, UNO_QUERY
);
146 getContainer()->addControl(::comphelper::getString(xModelSet
->getPropertyValue(PROPERTY_NAME
)), m_xGrid
);
148 // get the VCL-control
149 m_pVclControl
= NULL
;
152 DBG_ASSERT(m_pVclControl
!= NULL
, "UnoDataBrowserView::Construct : no real grid control !");
156 ::comphelper::disposeComponent(m_xGrid
);
160 // -------------------------------------------------------------------------
161 UnoDataBrowserView::~UnoDataBrowserView()
164 ::std::auto_ptr
<Splitter
> aTemp(m_pSplitter
);
177 ::comphelper::disposeComponent(m_xGrid
);
178 ::comphelper::disposeComponent(m_xMe
);
183 DBG_DTOR(UnoDataBrowserView
,NULL
);
185 // -----------------------------------------------------------------------------
186 IMPL_LINK( UnoDataBrowserView
, SplitHdl
, void*, /*NOINTERESTEDIN*/ )
188 long nYPos
= m_pSplitter
->GetPosPixel().Y();
189 m_pSplitter
->SetPosPixel( Point( m_pSplitter
->GetSplitPosPixel(), nYPos
) );
194 // -------------------------------------------------------------------------
195 void UnoDataBrowserView::setSplitter(Splitter
* _pSplitter
)
197 m_pSplitter
= _pSplitter
;
198 m_pSplitter
->SetSplitHdl( LINK( this, UnoDataBrowserView
, SplitHdl
) );
199 LINK( this, UnoDataBrowserView
, SplitHdl
).Call(m_pSplitter
);
201 // -------------------------------------------------------------------------
202 void UnoDataBrowserView::setTreeView(DBTreeView
* _pTreeView
)
204 if (m_pTreeView
!= _pTreeView
)
208 ::std::auto_ptr
<Window
> aTemp(m_pTreeView
);
211 m_pTreeView
= _pTreeView
;
214 // -------------------------------------------------------------------------
215 void UnoDataBrowserView::showStatus( const String
& _rStatus
)
217 if (0 == _rStatus
.Len())
222 m_pStatus
= new FixedText(this);
223 m_pStatus
->SetText(_rStatus
);
230 // -------------------------------------------------------------------------
231 void UnoDataBrowserView::hideStatus()
233 if (!m_pStatus
|| !m_pStatus
->IsVisible())
241 // -------------------------------------------------------------------------
242 void UnoDataBrowserView::resizeDocumentView(Rectangle
& _rPlayground
)
246 Point
aPlaygroundPos( _rPlayground
.TopLeft() );
247 Size
aPlaygroundSize( _rPlayground
.GetSize() );
249 if (m_pTreeView
&& m_pTreeView
->IsVisible() && m_pSplitter
)
251 // calculate the splitter pos and size
252 aSplitPos
= m_pSplitter
->GetPosPixel();
253 aSplitPos
.Y() = aPlaygroundPos
.Y();
254 aSplitSize
= m_pSplitter
->GetOutputSizePixel();
255 aSplitSize
.Height() = aPlaygroundSize
.Height();
257 if( ( aSplitPos
.X() + aSplitSize
.Width() ) > ( aPlaygroundSize
.Width() ))
258 aSplitPos
.X() = aPlaygroundSize
.Width() - aSplitSize
.Width();
260 if( aSplitPos
.X() <= aPlaygroundPos
.X() )
261 aSplitPos
.X() = aPlaygroundPos
.X() + sal_Int32(aPlaygroundSize
.Width() * 0.2);
263 // the tree pos and size
264 Point
aTreeViewPos( aPlaygroundPos
);
265 Size
aTreeViewSize( aSplitPos
.X(), aPlaygroundSize
.Height() );
267 // the status pos and size
268 if (m_pStatus
&& m_pStatus
->IsVisible())
270 Size
aStatusSize(aPlaygroundPos
.X(), GetTextHeight() + 2);
271 aStatusSize
= LogicToPixel(aStatusSize
, MAP_APPFONT
);
272 aStatusSize
.Width() = aTreeViewSize
.Width() - 2 - 2;
274 Point
aStatusPos( aPlaygroundPos
.X() + 2, aTreeViewPos
.Y() + aTreeViewSize
.Height() - aStatusSize
.Height() );
275 m_pStatus
->SetPosSizePixel( aStatusPos
, aStatusSize
);
276 aTreeViewSize
.Height() -= aStatusSize
.Height();
279 // set the size of treelistbox
280 m_pTreeView
->SetPosSizePixel( aTreeViewPos
, aTreeViewSize
);
282 //set the size of the splitter
283 m_pSplitter
->SetPosSizePixel( aSplitPos
, Size( aSplitSize
.Width(), aPlaygroundSize
.Height() ) );
284 m_pSplitter
->SetDragRectPixel( _rPlayground
);
287 // set the size of grid control
288 Reference
< ::com::sun::star::awt::XWindow
> xGridAsWindow(m_xGrid
, UNO_QUERY
);
289 if (xGridAsWindow
.is())
290 xGridAsWindow
->setPosSize( aSplitPos
.X() + aSplitSize
.Width(), aPlaygroundPos
.Y(),
291 aPlaygroundSize
.Width() - aSplitSize
.Width() - aSplitPos
.X(), aPlaygroundSize
.Height(), ::com::sun::star::awt::PosSize::POSSIZE
);
293 // just for completeness: there is no space left, we occupied it all ...
294 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
295 _rPlayground
.SetSize( Size( 0, 0 ) );
298 //------------------------------------------------------------------
299 sal_uInt16
UnoDataBrowserView::View2ModelPos(sal_uInt16 nPos
) const
301 return m_pVclControl
? m_pVclControl
->GetModelColumnPos(m_pVclControl
->GetColumnIdFromViewPos(nPos
)) : -1;
304 // -----------------------------------------------------------------------------
305 SbaGridControl
* UnoDataBrowserView::getVclControl() const
307 if ( !m_pVclControl
)
309 OSL_ENSURE(m_xGrid
.is(),"Grid not set!");
312 Reference
< ::com::sun::star::awt::XWindowPeer
> xPeer
= m_xGrid
->getPeer();
315 SbaXGridPeer
* pPeer
= SbaXGridPeer::getImplementation(xPeer
);
316 UnoDataBrowserView
* pTHIS
= const_cast<UnoDataBrowserView
*>(this);
319 m_pVclControl
= static_cast<SbaGridControl
*>(pPeer
->GetWindow());
320 pTHIS
->startComponentListening(Reference
<XComponent
>(VCLUnoHelper::GetInterface(m_pVclControl
),UNO_QUERY
));
325 return m_pVclControl
;
327 // -----------------------------------------------------------------------------
328 void UnoDataBrowserView::GetFocus()
330 ODataView::GetFocus();
331 if( m_pTreeView
&& m_pTreeView
->IsVisible() && !m_pTreeView
->HasChildPathFocus())
332 m_pTreeView
->GrabFocus();
333 else if (m_pVclControl
&& m_xGrid
.is())
335 sal_Bool bGrabFocus
= sal_False
;
336 if(!m_pVclControl
->HasChildPathFocus())
338 bGrabFocus
= isGrabVclControlFocusAllowed(this);
340 m_pVclControl
->GrabFocus();
342 if(!bGrabFocus
&& m_pTreeView
&& m_pTreeView
->IsVisible() )
343 m_pTreeView
->GrabFocus();
346 // -----------------------------------------------------------------------------
347 void UnoDataBrowserView::_disposing( const ::com::sun::star::lang::EventObject
& /*_rSource*/ )
349 stopComponentListening(Reference
<XComponent
>(VCLUnoHelper::GetInterface(m_pVclControl
),UNO_QUERY
));
350 m_pVclControl
= NULL
;
352 // -------------------------------------------------------------------------
353 long UnoDataBrowserView::PreNotify( NotifyEvent
& rNEvt
)
356 if(rNEvt
.GetType() == EVENT_KEYINPUT
)
358 sal_Bool bGrabAllowed
= isGrabVclControlFocusAllowed(this);
361 const KeyEvent
* pKeyEvt
= rNEvt
.GetKeyEvent();
362 const KeyCode
& rKeyCode
= pKeyEvt
->GetKeyCode();
363 if ( ( rKeyCode
== KeyCode( KEY_E
, TRUE
, TRUE
, FALSE
, FALSE
) )
364 || ( rKeyCode
== KeyCode( KEY_TAB
, TRUE
, FALSE
, FALSE
, FALSE
) )
367 if ( m_pTreeView
&& m_pVclControl
&& m_pTreeView
->HasChildPathFocus() )
368 m_pVclControl
->GrabFocus();
369 else if ( m_pTreeView
&& m_pVclControl
&& m_pVclControl
->HasChildPathFocus() )
370 m_pTreeView
->GrabFocus();
376 return nDone
? nDone
: ODataView::PreNotify(rNEvt
);
379 DBG_NAME(BrowserViewStatusDisplay
)
380 // -----------------------------------------------------------------------------
381 BrowserViewStatusDisplay::BrowserViewStatusDisplay( UnoDataBrowserView
* _pView
, const String
& _rStatus
)
384 DBG_CTOR(BrowserViewStatusDisplay
,NULL
);
387 m_pView
->showStatus(_rStatus
);
390 // -----------------------------------------------------------------------------
391 BrowserViewStatusDisplay::~BrowserViewStatusDisplay( )
394 m_pView
->showStatus(String());
396 DBG_DTOR(BrowserViewStatusDisplay
,NULL
);
398 // -----------------------------------------------------------------------------