1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/frame/XController.hpp>
21 #include <com/sun/star/frame/XModel.hpp>
22 #include <dbaccess/dataview.hxx>
23 #include <comphelper/namedvaluecollection.hxx>
24 #include <dbaccess/IController.hxx>
25 #include <svtools/acceleratorexecute.hxx>
26 #include <comphelper/diagnose_ex.hxx>
27 #include <vcl/event.hxx>
28 #include <vcl/settings.hxx>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::util
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::frame
;
38 ODataView::ODataView( vcl::Window
* pParent
,
39 IController
& _rController
,
40 const Reference
< XComponentContext
>& _rxContext
,
42 :Window(pParent
,nStyle
)
43 ,m_xContext(_rxContext
)
44 ,m_xController( &_rController
)
46 m_pAccel
= ::svt::AcceleratorExecute::createAcceleratorHelper();
49 void ODataView::Construct()
53 ODataView::~ODataView()
58 void ODataView::dispose()
60 m_xController
.clear();
62 vcl::Window::dispose();
65 void ODataView::resizeDocumentView(tools::Rectangle
& /*_rPlayground*/)
69 void ODataView::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& _rRect
)
71 // draw the background
73 rRenderContext
.Push(vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
);
74 rRenderContext
.SetLineColor(COL_TRANSPARENT
);
75 rRenderContext
.SetFillColor(GetSettings().GetStyleSettings().GetFaceColor());
76 rRenderContext
.DrawRect(_rRect
);
80 // let the base class do anything it needs
81 Window::Paint(rRenderContext
, _rRect
);
84 void ODataView::resizeAll(const tools::Rectangle
& rPlayground
)
86 // position the controls of the document's view
87 tools::Rectangle
aPlayground(rPlayground
);
88 resizeDocumentView(aPlayground
);
91 void ODataView::Resize()
94 resizeAll( tools::Rectangle( Point( 0, 0), GetSizePixel() ) );
96 bool ODataView::PreNotify( NotifyEvent
& _rNEvt
)
98 bool bHandled
= false;
99 switch ( _rNEvt
.GetType() )
101 case NotifyEventType::KEYINPUT
:
103 const KeyEvent
* pKeyEvent
= _rNEvt
.GetKeyEvent();
104 const vcl::KeyCode
& aKeyCode
= pKeyEvent
->GetKeyCode();
105 if ( m_pAccel
&& m_pAccel
->execute( aKeyCode
) )
106 // the accelerator consumed the event
110 case NotifyEventType::KEYUP
:
111 case NotifyEventType::MOUSEBUTTONDOWN
:
112 case NotifyEventType::MOUSEBUTTONUP
:
113 bHandled
= m_xController
->interceptUserInput( _rNEvt
);
118 return bHandled
|| Window::PreNotify( _rNEvt
);
120 void ODataView::StateChanged( StateChangedType nType
)
122 Window::StateChanged( nType
);
124 if ( nType
!= StateChangedType::InitShow
)
127 // now that there's a view which is finally visible, remove the "Hidden" value from the
128 // model's arguments.
131 Reference
< XController
> xController( m_xController
->getXController(), UNO_SET_THROW
);
132 Reference
< XModel
> xModel
= xController
->getModel();
135 ::comphelper::NamedValueCollection
aArgs( xModel
->getArgs() );
136 aArgs
.remove( "Hidden" );
137 xModel
->attachResource( xModel
->getURL(), aArgs
.getPropertyValues() );
140 catch( const Exception
& )
142 DBG_UNHANDLED_EXCEPTION("dbaccess");
146 void ODataView::attachFrame(const Reference
< XFrame
>& _xFrame
)
148 m_pAccel
->init(m_xContext
, _xFrame
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */