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::util
;
34 using namespace ::com::sun::star::frame
;
36 ODataView::ODataView( vcl::Window
* pParent
,
37 IController
& _rController
,
38 const Reference
< XComponentContext
>& _rxContext
,
40 :Window(pParent
,nStyle
)
41 ,m_xContext(_rxContext
)
42 ,m_xController( &_rController
)
44 m_pAccel
= ::svt::AcceleratorExecute::createAcceleratorHelper();
47 void ODataView::Construct()
51 ODataView::~ODataView()
56 void ODataView::dispose()
58 m_xController
.clear();
60 vcl::Window::dispose();
63 void ODataView::resizeDocumentView(tools::Rectangle
& /*_rPlayground*/)
67 void ODataView::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& _rRect
)
69 // draw the background
71 rRenderContext
.Push(vcl::PushFlags::LINECOLOR
| vcl::PushFlags::FILLCOLOR
);
72 rRenderContext
.SetLineColor(COL_TRANSPARENT
);
73 rRenderContext
.SetFillColor(GetSettings().GetStyleSettings().GetFaceColor());
74 rRenderContext
.DrawRect(_rRect
);
78 // let the base class do anything it needs
79 Window::Paint(rRenderContext
, _rRect
);
82 void ODataView::resizeAll(const tools::Rectangle
& rPlayground
)
84 // position the controls of the document's view
85 tools::Rectangle
aPlayground(rPlayground
);
86 resizeDocumentView(aPlayground
);
89 void ODataView::Resize()
92 resizeAll( tools::Rectangle( Point( 0, 0), GetSizePixel() ) );
94 bool ODataView::PreNotify( NotifyEvent
& _rNEvt
)
96 bool bHandled
= false;
97 switch ( _rNEvt
.GetType() )
99 case NotifyEventType::KEYINPUT
:
101 const KeyEvent
* pKeyEvent
= _rNEvt
.GetKeyEvent();
102 const vcl::KeyCode
& aKeyCode
= pKeyEvent
->GetKeyCode();
103 if ( m_pAccel
&& m_pAccel
->execute( aKeyCode
) )
104 // the accelerator consumed the event
108 case NotifyEventType::KEYUP
:
109 case NotifyEventType::MOUSEBUTTONDOWN
:
110 case NotifyEventType::MOUSEBUTTONUP
:
111 bHandled
= m_xController
->interceptUserInput( _rNEvt
);
116 return bHandled
|| Window::PreNotify( _rNEvt
);
118 void ODataView::StateChanged( StateChangedType nType
)
120 Window::StateChanged( nType
);
122 if ( nType
!= StateChangedType::InitShow
)
125 // now that there's a view which is finally visible, remove the "Hidden" value from the
126 // model's arguments.
129 Reference
< XController
> xController( m_xController
->getXController(), UNO_SET_THROW
);
130 Reference
< XModel
> xModel
= xController
->getModel();
133 ::comphelper::NamedValueCollection
aArgs( xModel
->getArgs() );
134 aArgs
.remove( u
"Hidden"_ustr
);
135 xModel
->attachResource( xModel
->getURL(), aArgs
.getPropertyValues() );
138 catch( const Exception
& )
140 DBG_UNHANDLED_EXCEPTION("dbaccess");
144 void ODataView::attachFrame(const Reference
< XFrame
>& _xFrame
)
146 m_pAccel
->init(m_xContext
, _xFrame
);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */