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