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