xref: /trunk/main/dbaccess/source/ui/browser/dataview.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef DBAUI_DATAVIEW_HXX
32 #include "dataview.hxx"
33 #endif
34 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
35 #include <toolkit/unohlp.hxx>
36 #endif
37 #ifndef _COMPHELPER_TYPES_HXX_
38 #include <comphelper/types.hxx>
39 #endif
40 #include <comphelper/namedvaluecollection.hxx>
41 #ifndef _SFXAPP_HXX //autogen wg. SFX_APP
42 #include <sfx2/app.hxx>
43 #endif
44 #ifndef _SFXIMGMGR_HXX
45 #include <sfx2/imgmgr.hxx>
46 #endif
47 #ifndef DBAUI_ICONTROLLER_HXX
48 #include "IController.hxx"
49 #endif
50 #ifndef DBAUI_TOOLS_HXX
51 #include "UITools.hxx"
52 #endif
53 #ifndef _SFX_HRC
54 #include <sfx2/sfx.hrc>
55 #endif
56 #ifndef _SVTOOLS_IMGDEF_HXX
57 #include <svtools/imgdef.hxx>
58 #endif
59 #include <tools/diagnose_ex.h>
60 
61 //.........................................................................
62 namespace dbaui
63 {
64 //.........................................................................
65     using namespace ::com::sun::star::uno;
66     using namespace ::com::sun::star::beans;
67     using namespace ::com::sun::star::util;
68     using namespace ::com::sun::star::lang;
69     using namespace ::com::sun::star::frame;
70 
71     //=====================================================================
72     //= ColorChanger
73     //=====================================================================
74     class ColorChanger
75     {
76     protected:
77         OutputDevice*   m_pDev;
78 
79     public:
80         ColorChanger( OutputDevice* _pDev, const Color& _rNewLineColor, const Color& _rNewFillColor )
81             :m_pDev( _pDev )
82         {
83             m_pDev->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
84             m_pDev->SetLineColor( _rNewLineColor );
85             m_pDev->SetFillColor( _rNewFillColor );
86         }
87 
88         ~ColorChanger()
89         {
90             m_pDev->Pop();
91         }
92     };
93 
94     DBG_NAME(ODataView)
95     // -------------------------------------------------------------------------
96     ODataView::ODataView(   Window* pParent,
97                             IController& _rController,
98                             const Reference< XMultiServiceFactory >& _rFactory,
99                             WinBits nStyle)
100         :Window(pParent,nStyle)
101         ,m_xServiceFactory(_rFactory)
102         ,m_rController( _rController )
103         ,m_aSeparator( this )
104     {
105         DBG_CTOR(ODataView,NULL);
106         m_rController.acquire();
107         m_pAccel.reset(::svt::AcceleratorExecute::createAcceleratorHelper());
108         m_aSeparator.Show();
109     }
110 
111     // -------------------------------------------------------------------------
112     void ODataView::Construct()
113     {
114     }
115 
116     // -------------------------------------------------------------------------
117     ODataView::~ODataView()
118     {
119         DBG_DTOR(ODataView,NULL);
120 
121         m_rController.release();
122     }
123 
124     // -------------------------------------------------------------------------
125     void ODataView::resizeDocumentView( Rectangle& /*_rPlayground*/ )
126     {
127     }
128 
129     // -------------------------------------------------------------------------
130     void ODataView::Paint( const Rectangle& _rRect )
131     {
132         //.................................................................
133         // draw the background
134         {
135             ColorChanger aColors( this, COL_TRANSPARENT, GetSettings().GetStyleSettings().GetFaceColor() );
136             DrawRect( _rRect );
137         }
138 
139         // let the base class do anything it needs
140         Window::Paint( _rRect );
141     }
142 
143     // -------------------------------------------------------------------------
144     void ODataView::resizeAll( const Rectangle& _rPlayground )
145     {
146         Rectangle aPlayground( _rPlayground );
147 
148         // position the separator
149         const Size aSeparatorSize = Size( aPlayground.GetWidth(), 2 );
150         m_aSeparator.SetPosSizePixel( aPlayground.TopLeft(), aSeparatorSize );
151         aPlayground.Top() += aSeparatorSize.Height() + 1;
152 
153         // position the controls of the document's view
154         resizeDocumentView( aPlayground );
155     }
156 
157     // -------------------------------------------------------------------------
158     void ODataView::Resize()
159     {
160         Window::Resize();
161         resizeAll( Rectangle( Point( 0, 0), GetSizePixel() ) );
162     }
163     // -----------------------------------------------------------------------------
164     long ODataView::PreNotify( NotifyEvent& _rNEvt )
165     {
166         bool bHandled = false;
167         switch ( _rNEvt.GetType() )
168         {
169             case EVENT_KEYINPUT:
170             {
171                 const KeyEvent* pKeyEvent = _rNEvt.GetKeyEvent();
172                 const KeyCode& aKeyCode = pKeyEvent->GetKeyCode();
173                 if ( m_pAccel.get() && m_pAccel->execute( aKeyCode ) )
174                     // the accelerator consumed the event
175                     return 1L;
176             }
177             // NO break
178             case EVENT_KEYUP:
179             case EVENT_MOUSEBUTTONDOWN:
180             case EVENT_MOUSEBUTTONUP:
181                 bHandled = m_rController.interceptUserInput( _rNEvt );
182                 break;
183         }
184         return bHandled ? 1L : Window::PreNotify( _rNEvt );
185     }
186     // -----------------------------------------------------------------------------
187     void ODataView::StateChanged( StateChangedType nType )
188     {
189         Window::StateChanged( nType );
190 
191         if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
192         {
193             // Check if we need to get new images for normal/high contrast mode
194             m_rController.notifyHiContrastChanged();
195         }
196 
197         if ( nType == STATE_CHANGE_INITSHOW )
198         {
199             // now that there's a view which is finally visible, remove the "Hidden" value from the
200             // model's arguments.
201             try
202             {
203                 Reference< XController > xController( m_rController.getXController(), UNO_SET_THROW );
204                 Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
205                 if ( xModel.is() )
206                 {
207                     ::comphelper::NamedValueCollection aArgs( xModel->getArgs() );
208                     aArgs.remove( "Hidden" );
209                     xModel->attachResource( xModel->getURL(), aArgs.getPropertyValues() );
210                 }
211             }
212             catch( const Exception& )
213             {
214                 DBG_UNHANDLED_EXCEPTION();
215             }
216         }
217     }
218     // -----------------------------------------------------------------------------
219     void ODataView::DataChanged( const DataChangedEvent& rDCEvt )
220     {
221         Window::DataChanged( rDCEvt );
222 
223         if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
224             (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
225             (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
226             ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
227             (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
228         {
229             // Check if we need to get new images for normal/high contrast mode
230             m_rController.notifyHiContrastChanged();
231         }
232     }
233     // -----------------------------------------------------------------------------
234     void ODataView::attachFrame(const Reference< XFrame >& _xFrame)
235     {
236         m_pAccel->init(m_xServiceFactory,_xFrame);
237     }
238 //.........................................................................
239 }
240 // namespace dbaui
241 //.........................................................................
242