Update ooo320-m1
[ooovba.git] / dbaccess / source / ui / browser / dataview.cxx
blobef16f0afbc76206b2e695ab8459883c5bf667912
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dataview.cxx,v $
10 * $Revision: 1.23 $
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 DBAUI_DATAVIEW_HXX
35 #include "dataview.hxx"
36 #endif
37 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
38 #include <toolkit/unohlp.hxx>
39 #endif
40 #ifndef _COMPHELPER_TYPES_HXX_
41 #include <comphelper/types.hxx>
42 #endif
43 #ifndef _SFXAPP_HXX //autogen wg. SFX_APP
44 #include <sfx2/app.hxx>
45 #endif
46 #ifndef _SFXIMGMGR_HXX
47 #include <sfx2/imgmgr.hxx>
48 #endif
49 #ifndef _SV_FIXED_HXX
50 #include <vcl/fixed.hxx>
51 #endif
52 #ifndef DBAUI_ICONTROLLER_HXX
53 #include "IController.hxx"
54 #endif
55 #ifndef DBAUI_TOOLS_HXX
56 #include "UITools.hxx"
57 #endif
58 #ifndef _SFX_HRC
59 #include <sfx2/sfx.hrc>
60 #endif
61 #ifndef _SVTOOLS_IMGDEF_HXX
62 #include <svtools/imgdef.hxx>
63 #endif
65 //.........................................................................
66 namespace dbaui
68 //.........................................................................
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::util;
72 using namespace ::com::sun::star::lang;
73 using namespace ::com::sun::star::frame;
75 //=====================================================================
76 //= ColorChanger
77 //=====================================================================
78 class ColorChanger
80 protected:
81 OutputDevice* m_pDev;
83 public:
84 ColorChanger( OutputDevice* _pDev, const Color& _rNewLineColor, const Color& _rNewFillColor )
85 :m_pDev( _pDev )
87 m_pDev->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
88 m_pDev->SetLineColor( _rNewLineColor );
89 m_pDev->SetFillColor( _rNewFillColor );
92 ~ColorChanger()
94 m_pDev->Pop();
98 DBG_NAME(ODataView)
99 // -------------------------------------------------------------------------
100 ODataView::ODataView( Window* pParent,
101 IController& _rController,
102 const Reference< XMultiServiceFactory >& _rFactory,
103 WinBits nStyle)
104 :Window(pParent,nStyle)
105 ,m_xServiceFactory(_rFactory)
106 ,m_rController( _rController )
107 ,m_pSeparator( NULL )
109 DBG_CTOR(ODataView,NULL);
110 m_rController.acquire();
111 m_pAccel.reset(::svt::AcceleratorExecute::createAcceleratorHelper());
114 // -------------------------------------------------------------------------
115 void ODataView::Construct()
119 // -------------------------------------------------------------------------
120 ODataView::~ODataView()
122 DBG_DTOR(ODataView,NULL);
124 enableSeparator( sal_False );
125 m_rController.release();
128 // -------------------------------------------------------------------------
129 void ODataView::enableSeparator( const sal_Bool _bEnable )
131 if ( _bEnable == isSeparatorEnabled() )
132 // nothing to do
133 return;
135 if ( _bEnable )
137 m_pSeparator = new FixedLine( this );
138 m_pSeparator->Show( );
140 else
142 ::std::auto_ptr<FixedLine> aTemp(m_pSeparator);
143 m_pSeparator = NULL;
145 Resize();
147 // -------------------------------------------------------------------------
148 void ODataView::resizeDocumentView( Rectangle& /*_rPlayground*/ )
152 // -------------------------------------------------------------------------
153 void ODataView::Paint( const Rectangle& _rRect )
155 //.................................................................
156 // draw the background
158 ColorChanger aColors( this, COL_TRANSPARENT, GetSettings().GetStyleSettings().GetFaceColor() );
159 DrawRect( _rRect );
162 // let the base class do anything it needs
163 Window::Paint( _rRect );
166 // -------------------------------------------------------------------------
167 void ODataView::resizeAll( const Rectangle& _rPlayground )
169 Rectangle aPlayground( _rPlayground );
171 // position thew separator
172 if ( m_pSeparator )
174 Size aSeparatorSize = Size( aPlayground.GetWidth(), 2 );
176 m_pSeparator->SetPosSizePixel( aPlayground.TopLeft(), aSeparatorSize );
178 aPlayground.Top() += aSeparatorSize.Height() + 1;
181 // position the controls of the document's view
182 resizeDocumentView( aPlayground );
185 // -------------------------------------------------------------------------
186 void ODataView::Resize()
188 Window::Resize();
189 resizeAll( Rectangle( Point( 0, 0), GetSizePixel() ) );
191 // -----------------------------------------------------------------------------
192 long ODataView::PreNotify( NotifyEvent& _rNEvt )
194 bool bHandled = false;
195 switch ( _rNEvt.GetType() )
197 case EVENT_KEYINPUT:
199 const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
200 const KeyCode& aKeyCode = pKeyEvent->GetKeyCode();
201 if ( m_pAccel.get() && m_pAccel->execute( aKeyCode ) )
202 // the accelerator consumed the event
203 return 1L;
205 // NO break
206 case EVENT_KEYUP:
207 case EVENT_MOUSEBUTTONDOWN:
208 case EVENT_MOUSEBUTTONUP:
209 bHandled = m_rController.interceptUserInput( _rNEvt );
210 break;
212 return bHandled ? 1L : Window::PreNotify( _rNEvt );
214 // -----------------------------------------------------------------------------
215 void ODataView::StateChanged( StateChangedType nType )
217 Window::StateChanged( nType );
219 if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
221 // Check if we need to get new images for normal/high contrast mode
222 m_rController.notifyHiContrastChanged();
225 // -----------------------------------------------------------------------------
226 void ODataView::DataChanged( const DataChangedEvent& rDCEvt )
228 Window::DataChanged( rDCEvt );
230 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
231 (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
232 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
233 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
234 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
236 // Check if we need to get new images for normal/high contrast mode
237 m_rController.notifyHiContrastChanged();
240 // -----------------------------------------------------------------------------
241 void ODataView::attachFrame(const Reference< XFrame >& _xFrame)
243 m_pAccel->init(m_xServiceFactory,_xFrame);
245 //.........................................................................
247 // namespace dbaui
248 //.........................................................................