Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / browser / dataview.cxx
blob908b9b57703fecfed08d47cd450d3cf370db1242
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "dataview.hxx"
31 #include <toolkit/unohlp.hxx>
32 #include <comphelper/types.hxx>
33 #include <comphelper/namedvaluecollection.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/imgmgr.hxx>
36 #include "IController.hxx"
37 #include "UITools.hxx"
38 #include <sfx2/sfx.hrc>
39 #include <svtools/imgdef.hxx>
40 #include <tools/diagnose_ex.h>
42 //.........................................................................
43 namespace dbaui
45 //.........................................................................
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::util;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::frame;
52 //=====================================================================
53 //= ColorChanger
54 //=====================================================================
55 class ColorChanger
57 protected:
58 OutputDevice* m_pDev;
60 public:
61 ColorChanger( OutputDevice* _pDev, const Color& _rNewLineColor, const Color& _rNewFillColor )
62 :m_pDev( _pDev )
64 m_pDev->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
65 m_pDev->SetLineColor( _rNewLineColor );
66 m_pDev->SetFillColor( _rNewFillColor );
69 ~ColorChanger()
71 m_pDev->Pop();
75 DBG_NAME(ODataView)
76 // -------------------------------------------------------------------------
77 ODataView::ODataView( Window* pParent,
78 IController& _rController,
79 const Reference< XMultiServiceFactory >& _rFactory,
80 WinBits nStyle)
81 :Window(pParent,nStyle)
82 ,m_xServiceFactory(_rFactory)
83 ,m_rController( _rController )
84 ,m_aSeparator( this )
86 DBG_CTOR(ODataView,NULL);
87 m_rController.acquire();
88 m_pAccel.reset(::svt::AcceleratorExecute::createAcceleratorHelper());
89 m_aSeparator.Show();
92 // -------------------------------------------------------------------------
93 void ODataView::Construct()
97 // -------------------------------------------------------------------------
98 ODataView::~ODataView()
100 DBG_DTOR(ODataView,NULL);
102 m_rController.release();
105 // -------------------------------------------------------------------------
106 void ODataView::resizeDocumentView( Rectangle& /*_rPlayground*/ )
110 // -------------------------------------------------------------------------
111 void ODataView::Paint( const Rectangle& _rRect )
113 //.................................................................
114 // draw the background
116 ColorChanger aColors( this, COL_TRANSPARENT, GetSettings().GetStyleSettings().GetFaceColor() );
117 DrawRect( _rRect );
120 // let the base class do anything it needs
121 Window::Paint( _rRect );
124 // -------------------------------------------------------------------------
125 void ODataView::resizeAll( const Rectangle& _rPlayground )
127 Rectangle aPlayground( _rPlayground );
129 // position the separator
130 const Size aSeparatorSize = Size( aPlayground.GetWidth(), 2 );
131 m_aSeparator.SetPosSizePixel( aPlayground.TopLeft(), aSeparatorSize );
132 aPlayground.Top() += aSeparatorSize.Height() + 1;
134 // position the controls of the document's view
135 resizeDocumentView( aPlayground );
138 // -------------------------------------------------------------------------
139 void ODataView::Resize()
141 Window::Resize();
142 resizeAll( Rectangle( Point( 0, 0), GetSizePixel() ) );
144 // -----------------------------------------------------------------------------
145 long ODataView::PreNotify( NotifyEvent& _rNEvt )
147 bool bHandled = false;
148 switch ( _rNEvt.GetType() )
150 case EVENT_KEYINPUT:
152 const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
153 const KeyCode& aKeyCode = pKeyEvent->GetKeyCode();
154 if ( m_pAccel.get() && m_pAccel->execute( aKeyCode ) )
155 // the accelerator consumed the event
156 return 1L;
158 // NO break
159 case EVENT_KEYUP:
160 case EVENT_MOUSEBUTTONDOWN:
161 case EVENT_MOUSEBUTTONUP:
162 bHandled = m_rController.interceptUserInput( _rNEvt );
163 break;
165 return bHandled ? 1L : Window::PreNotify( _rNEvt );
167 // -----------------------------------------------------------------------------
168 void ODataView::StateChanged( StateChangedType nType )
170 Window::StateChanged( nType );
172 if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
174 // Check if we need to get new images for normal/high contrast mode
175 m_rController.notifyHiContrastChanged();
178 if ( nType == STATE_CHANGE_INITSHOW )
180 // now that there's a view which is finally visible, remove the "Hidden" value from the
181 // model's arguments.
184 Reference< XController > xController( m_rController.getXController(), UNO_SET_THROW );
185 Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
186 if ( xModel.is() )
188 ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
189 aArgs.remove( "Hidden" );
190 xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() );
193 catch( const Exception& )
195 DBG_UNHANDLED_EXCEPTION();
199 // -----------------------------------------------------------------------------
200 void ODataView::DataChanged( const DataChangedEvent& rDCEvt )
202 Window::DataChanged( rDCEvt );
204 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
205 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
206 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
207 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
208 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
210 // Check if we need to get new images for normal/high contrast mode
211 m_rController.notifyHiContrastChanged();
214 // -----------------------------------------------------------------------------
215 void ODataView::attachFrame(const Reference< XFrame >& _xFrame)
217 m_pAccel->init(m_xServiceFactory,_xFrame);
219 //.........................................................................
221 // namespace dbaui
222 //.........................................................................
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */