1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
28cdf0e10cSrcweir #include "querycontainerwindow.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef DBAUI_QUERYDESIGNVIEW_HXX
31cdf0e10cSrcweir #include "QueryDesignView.hxx"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX
37cdf0e10cSrcweir #include <vcl/svapp.hxx>
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef DBAUI_JOINCONTROLLER_HXX
40cdf0e10cSrcweir #include "JoinController.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
43cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
46cdf0e10cSrcweir #include "dbustrings.hrc"
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _SFXSIDS_HRC
49cdf0e10cSrcweir #include <sfx2/sfxsids.hrc>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef _SV_FIXED_HXX
52cdf0e10cSrcweir #include <vcl/fixed.hxx>
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
55cdf0e10cSrcweir #include "UITools.hxx"
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
58cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
61cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //.........................................................................
65cdf0e10cSrcweir namespace dbaui
66cdf0e10cSrcweir {
67cdf0e10cSrcweir //.........................................................................
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
70cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
71cdf0e10cSrcweir 	using namespace ::com::sun::star::frame;
72cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	//=====================================================================
75cdf0e10cSrcweir 	//= OQueryContainerWindow
76cdf0e10cSrcweir 	//=====================================================================
DBG_NAME(OQueryContainerWindow)77cdf0e10cSrcweir 	DBG_NAME(OQueryContainerWindow)
78cdf0e10cSrcweir 	OQueryContainerWindow::OQueryContainerWindow(Window* pParent, OQueryController& _rController,const Reference< XMultiServiceFactory >& _rFactory)
79cdf0e10cSrcweir 		:ODataView( pParent, _rController, _rFactory )
80cdf0e10cSrcweir 		,m_pViewSwitch(NULL)
81cdf0e10cSrcweir 		,m_pBeamer(NULL)
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		DBG_CTOR(OQueryContainerWindow,NULL);
84cdf0e10cSrcweir 		m_pViewSwitch = new OQueryViewSwitch( this, _rController, _rFactory );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 		m_pSplitter = new Splitter(this,WB_VSCROLL);
87cdf0e10cSrcweir 		m_pSplitter->Hide();
88cdf0e10cSrcweir 		m_pSplitter->SetSplitHdl( LINK( this, OQueryContainerWindow, SplitHdl ) );
89cdf0e10cSrcweir 		m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
90cdf0e10cSrcweir 	}
91cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
~OQueryContainerWindow()92cdf0e10cSrcweir 	OQueryContainerWindow::~OQueryContainerWindow()
93cdf0e10cSrcweir 	{
94cdf0e10cSrcweir 		DBG_DTOR(OQueryContainerWindow,NULL);
95cdf0e10cSrcweir 		{
96cdf0e10cSrcweir 			::std::auto_ptr<OQueryViewSwitch> aTemp(m_pViewSwitch);
97cdf0e10cSrcweir 			m_pViewSwitch = NULL;
98cdf0e10cSrcweir 		}
99cdf0e10cSrcweir 		if ( m_pBeamer )
100cdf0e10cSrcweir 			::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
101cdf0e10cSrcweir 		m_pBeamer = NULL;
102cdf0e10cSrcweir 		if ( m_xBeamer.is() )
103cdf0e10cSrcweir 		{
104cdf0e10cSrcweir 			Reference< ::com::sun::star::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
105cdf0e10cSrcweir 			m_xBeamer = NULL;
106cdf0e10cSrcweir             if(xCloseable.is())
107cdf0e10cSrcweir                 xCloseable->close(sal_False); // false - holds the owner ship of this frame
108cdf0e10cSrcweir 			//	m_xBeamer->setComponent(NULL,NULL);
109cdf0e10cSrcweir 		}
110cdf0e10cSrcweir 		{
111cdf0e10cSrcweir 			::std::auto_ptr<Window> aTemp(m_pSplitter);
112cdf0e10cSrcweir 			m_pSplitter = NULL;
113cdf0e10cSrcweir 		}
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
switchView(::dbtools::SQLExceptionInfo * _pErrorInfo)116cdf0e10cSrcweir 	bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		return m_pViewSwitch->switchView( _pErrorInfo );
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
forceInitialView()122cdf0e10cSrcweir     void OQueryContainerWindow::forceInitialView()
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir 		return m_pViewSwitch->forceInitialView();
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
resizeAll(const Rectangle & _rPlayground)128cdf0e10cSrcweir 	void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground )
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		Rectangle aPlayground( _rPlayground );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 		if ( m_pBeamer && m_pBeamer->IsVisible() )
133cdf0e10cSrcweir 		{
134cdf0e10cSrcweir 			// calc pos and size of the splitter
135cdf0e10cSrcweir 			Point aSplitPos		= m_pSplitter->GetPosPixel();
136cdf0e10cSrcweir 			Size aSplitSize		= m_pSplitter->GetOutputSizePixel();
137cdf0e10cSrcweir 			aSplitSize.Width() = aPlayground.GetWidth();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 			if ( aSplitPos.Y() <= aPlayground.Top() )
140cdf0e10cSrcweir 				aSplitPos.Y() = aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 			if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
143cdf0e10cSrcweir 				aSplitPos.Y() = aPlayground.GetHeight() - aSplitSize.Height();
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 			// set pos and size of the splitter
146cdf0e10cSrcweir 			m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
147cdf0e10cSrcweir 			m_pSplitter->SetDragRectPixel(	aPlayground );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 			// set pos and size of the beamer
150cdf0e10cSrcweir 			Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
151cdf0e10cSrcweir 			m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			// shrink the playground by the size which is occupied by the beamer
154cdf0e10cSrcweir 			aPlayground.Top() = aSplitPos.Y() + aSplitSize.Height();
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 		ODataView::resizeAll( aPlayground );
158cdf0e10cSrcweir 	}
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
resizeDocumentView(Rectangle & _rPlayground)161cdf0e10cSrcweir 	void OQueryContainerWindow::resizeDocumentView( Rectangle& _rPlayground )
162cdf0e10cSrcweir 	{
163cdf0e10cSrcweir 		m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		ODataView::resizeDocumentView( _rPlayground );
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
GetFocus()169cdf0e10cSrcweir 	void OQueryContainerWindow::GetFocus()
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		ODataView::GetFocus();
172cdf0e10cSrcweir 		if(m_pViewSwitch)
173cdf0e10cSrcweir 			m_pViewSwitch->GrabFocus();
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
176cdf0e10cSrcweir 	IMPL_LINK( OQueryContainerWindow, SplitHdl, void*, /*p*/ )
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 		m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
179cdf0e10cSrcweir 		Resize();
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 		return 0L;
182cdf0e10cSrcweir 	}
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
Construct()185cdf0e10cSrcweir 	void OQueryContainerWindow::Construct()
186cdf0e10cSrcweir 	{
187cdf0e10cSrcweir 		m_pViewSwitch->Construct();
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
disposingPreview()191cdf0e10cSrcweir 	void OQueryContainerWindow::disposingPreview()
192cdf0e10cSrcweir 	{
193cdf0e10cSrcweir 		if ( m_pBeamer )
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			// here I know that we will be destroyed from the frame
196cdf0e10cSrcweir 			::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
197cdf0e10cSrcweir 			m_pBeamer = NULL;
198cdf0e10cSrcweir 			m_xBeamer = NULL;
199cdf0e10cSrcweir 			m_pSplitter->Hide();
200cdf0e10cSrcweir 			Resize();
201cdf0e10cSrcweir 		}
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
PreNotify(NotifyEvent & rNEvt)204cdf0e10cSrcweir 	long OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
205cdf0e10cSrcweir 	{
206cdf0e10cSrcweir 		sal_Bool bHandled = sal_False;
207cdf0e10cSrcweir 		switch (rNEvt.GetType())
208cdf0e10cSrcweir 		{
209cdf0e10cSrcweir 			case  EVENT_GETFOCUS:
210cdf0e10cSrcweir 				if ( m_pViewSwitch )
211cdf0e10cSrcweir 				{
212cdf0e10cSrcweir 					OJoinController& rController = m_pViewSwitch->getDesignView()->getController();
213cdf0e10cSrcweir 					rController.InvalidateFeature(SID_CUT);
214cdf0e10cSrcweir 					rController.InvalidateFeature(SID_COPY);
215cdf0e10cSrcweir 					rController.InvalidateFeature(SID_PASTE);
216cdf0e10cSrcweir 				}
217cdf0e10cSrcweir 		}
218cdf0e10cSrcweir 		return bHandled ? 1L : ODataView::PreNotify(rNEvt);
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
showPreview(const Reference<XFrame> & _xFrame)221cdf0e10cSrcweir 	void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
222cdf0e10cSrcweir 	{
223cdf0e10cSrcweir 		if(!m_pBeamer)
224cdf0e10cSrcweir 		{
225cdf0e10cSrcweir 			m_pBeamer = new OBeamer(this);
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 			::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 			Reference < XFrame > xBeamerFrame( m_pViewSwitch->getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Frame")),UNO_QUERY );
230cdf0e10cSrcweir             m_xBeamer.set( xBeamerFrame );
231cdf0e10cSrcweir 			OSL_ENSURE(m_xBeamer.is(),"No frame created!");
232cdf0e10cSrcweir 			m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir             // notify layout manager to not create internal toolbars
235cdf0e10cSrcweir             Reference < XPropertySet > xPropSet( xBeamerFrame, UNO_QUERY );
236cdf0e10cSrcweir             try
237cdf0e10cSrcweir             {
238cdf0e10cSrcweir                 const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
239cdf0e10cSrcweir                 Reference < XPropertySet > xLMPropSet(xPropSet->getPropertyValue( aLayoutManager ),UNO_QUERY);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir                 if ( xLMPropSet.is() )
242cdf0e10cSrcweir                 {
243cdf0e10cSrcweir                     const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
244cdf0e10cSrcweir                     xLMPropSet->setPropertyValue( aAutomaticToolbars, Any( sal_False ));
245cdf0e10cSrcweir                 }
246cdf0e10cSrcweir             }
247cdf0e10cSrcweir             catch( Exception& )
248cdf0e10cSrcweir             {
249cdf0e10cSrcweir             }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 			m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 			// append our frame
254cdf0e10cSrcweir 			Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
255cdf0e10cSrcweir 			Reference < XFrames > xFrames = xSup->getFrames();
256cdf0e10cSrcweir 			xFrames->append( m_xBeamer );
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 			Size aSize = GetOutputSizePixel();
259cdf0e10cSrcweir 			Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 			const long	nFrameHeight = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
262cdf0e10cSrcweir 			Point aPos(0,aBeamer.Height()+nFrameHeight);
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 			m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
265cdf0e10cSrcweir 			m_pBeamer->Show();
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 			m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
268cdf0e10cSrcweir 			// a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
269cdf0e10cSrcweir 			m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
270cdf0e10cSrcweir 			m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 			m_pSplitter->Show();
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 			Resize();
275cdf0e10cSrcweir 		}
276cdf0e10cSrcweir 	}
277cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 
280cdf0e10cSrcweir //.........................................................................
281cdf0e10cSrcweir }	// namespace dbaui
282cdf0e10cSrcweir //.........................................................................
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 
285