Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <dbaccess/dataview.hxx>
21 : #include <toolkit/helper/vclunohelper.hxx>
22 : #include <comphelper/types.hxx>
23 : #include <comphelper/namedvaluecollection.hxx>
24 : #include <sfx2/app.hxx>
25 : #include <sfx2/imgmgr.hxx>
26 : #include <dbaccess/IController.hxx>
27 : #include "UITools.hxx"
28 : #include <sfx2/sfx.hrc>
29 : #include <svtools/imgdef.hxx>
30 : #include <tools/diagnose_ex.h>
31 : #include <vcl/settings.hxx>
32 :
33 : namespace dbaui
34 : {
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::beans;
37 : using namespace ::com::sun::star::util;
38 : using namespace ::com::sun::star::lang;
39 : using namespace ::com::sun::star::frame;
40 :
41 8 : ODataView::ODataView( vcl::Window* pParent,
42 : IController& _rController,
43 : const Reference< XComponentContext >& _rxContext,
44 : WinBits nStyle)
45 : :Window(pParent,nStyle)
46 : ,m_xContext(_rxContext)
47 : ,m_xController( &_rController )
48 8 : ,m_aSeparator( VclPtr<FixedLine>::Create(this) )
49 : {
50 8 : m_pAccel.reset(::svt::AcceleratorExecute::createAcceleratorHelper());
51 8 : m_aSeparator->Show();
52 8 : }
53 :
54 16 : void ODataView::Construct()
55 : {
56 16 : }
57 :
58 12 : ODataView::~ODataView()
59 : {
60 6 : disposeOnce();
61 6 : }
62 :
63 6 : void ODataView::dispose()
64 : {
65 6 : m_xController.clear();
66 6 : m_aSeparator.disposeAndClear();
67 6 : m_pAccel.reset();
68 6 : vcl::Window::dispose();
69 6 : }
70 :
71 0 : void ODataView::resizeDocumentView( Rectangle& /*_rPlayground*/ )
72 : {
73 0 : }
74 :
75 12 : void ODataView::Paint(vcl::RenderContext& rRenderContext, const Rectangle& _rRect)
76 : {
77 : // draw the background
78 : {
79 12 : rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR);
80 12 : rRenderContext.SetLineColor(COL_TRANSPARENT);
81 12 : rRenderContext.SetFillColor(GetSettings().GetStyleSettings().GetFaceColor());
82 12 : rRenderContext.DrawRect(_rRect);
83 12 : rRenderContext.Pop();
84 : }
85 :
86 : // let the base class do anything it needs
87 12 : Window::Paint(rRenderContext, _rRect);
88 12 : }
89 :
90 31 : void ODataView::resizeAll( const Rectangle& _rPlayground )
91 : {
92 31 : Rectangle aPlayground( _rPlayground );
93 :
94 : // position the separator
95 31 : const Size aSeparatorSize = Size( aPlayground.GetWidth(), 2 );
96 31 : m_aSeparator->SetPosSizePixel( aPlayground.TopLeft(), aSeparatorSize );
97 31 : aPlayground.Top() += aSeparatorSize.Height() + 1;
98 :
99 : // position the controls of the document's view
100 31 : resizeDocumentView( aPlayground );
101 31 : }
102 :
103 31 : void ODataView::Resize()
104 : {
105 31 : Window::Resize();
106 31 : resizeAll( Rectangle( Point( 0, 0), GetSizePixel() ) );
107 31 : }
108 98 : bool ODataView::PreNotify( NotifyEvent& _rNEvt )
109 : {
110 98 : bool bHandled = false;
111 98 : switch ( _rNEvt.GetType() )
112 : {
113 : case MouseNotifyEvent::KEYINPUT:
114 : {
115 0 : const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
116 0 : const vcl::KeyCode& aKeyCode = pKeyEvent->GetKeyCode();
117 0 : if ( m_pAccel.get() && m_pAccel->execute( aKeyCode ) )
118 : // the accelerator consumed the event
119 0 : return true;
120 : }
121 : // NO break
122 : case MouseNotifyEvent::KEYUP:
123 : case MouseNotifyEvent::MOUSEBUTTONDOWN:
124 : case MouseNotifyEvent::MOUSEBUTTONUP:
125 0 : bHandled = m_xController->interceptUserInput( _rNEvt );
126 0 : break;
127 : default:
128 98 : break;
129 : }
130 98 : return bHandled || Window::PreNotify( _rNEvt );
131 : }
132 15 : void ODataView::StateChanged( StateChangedType nType )
133 : {
134 15 : Window::StateChanged( nType );
135 :
136 15 : if ( nType == StateChangedType::ControlBackground )
137 : {
138 : // Check if we need to get new images for normal/high contrast mode
139 0 : m_xController->notifyHiContrastChanged();
140 : }
141 :
142 15 : if ( nType == StateChangedType::InitShow )
143 : {
144 : // now that there's a view which is finally visible, remove the "Hidden" value from the
145 : // model's arguments.
146 : try
147 : {
148 7 : Reference< XController > xController( m_xController->getXController(), UNO_SET_THROW );
149 14 : Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
150 7 : if ( xModel.is() )
151 : {
152 0 : ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
153 0 : aArgs.remove( "Hidden" );
154 0 : xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() );
155 7 : }
156 : }
157 0 : catch( const Exception& )
158 : {
159 : DBG_UNHANDLED_EXCEPTION();
160 : }
161 : }
162 15 : }
163 0 : void ODataView::DataChanged( const DataChangedEvent& rDCEvt )
164 : {
165 0 : Window::DataChanged( rDCEvt );
166 :
167 0 : if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
168 0 : (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
169 0 : (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
170 0 : ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
171 0 : (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
172 : {
173 : // Check if we need to get new images for normal/high contrast mode
174 0 : m_xController->notifyHiContrastChanged();
175 : }
176 0 : }
177 13 : void ODataView::attachFrame(const Reference< XFrame >& _xFrame)
178 : {
179 13 : m_pAccel->init(m_xContext, _xFrame);
180 13 : }
181 36 : }
182 :
183 : // namespace dbaui
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|