update dev300-m58
[ooovba.git] / dbaccess / source / ui / querydesign / querycontainerwindow.cxx
blob7905aa56f68e48e66707cfb4f8b5da76ffcd12b2
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: querycontainerwindow.cxx,v $
10 * $Revision: 1.19 $
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_QUERYCONTAINERWINDOW_HXX
35 #include "querycontainerwindow.hxx"
36 #endif
37 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
38 #include "QueryDesignView.hxx"
39 #endif
40 #ifndef _TOOLS_DEBUG_HXX
41 #include <tools/debug.hxx>
42 #endif
43 #ifndef _SV_SVAPP_HXX
44 #include <vcl/svapp.hxx>
45 #endif
46 #ifndef DBAUI_JOINCONTROLLER_HXX
47 #include "JoinController.hxx"
48 #endif
49 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
50 #include <toolkit/unohlp.hxx>
51 #endif
52 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
53 #include "dbustrings.hrc"
54 #endif
55 #ifndef _SFXSIDS_HRC
56 #include <sfx2/sfxsids.hrc>
57 #endif
58 #ifndef _SV_FIXED_HXX
59 #include <vcl/fixed.hxx>
60 #endif
61 #ifndef DBAUI_TOOLS_HXX
62 #include "UITools.hxx"
63 #endif
64 #ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
65 #include <com/sun/star/util/XCloseable.hpp>
66 #endif
67 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
68 #include <com/sun/star/beans/XPropertySet.hpp>
69 #endif
71 //.........................................................................
72 namespace dbaui
74 //.........................................................................
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::frame;
79 using namespace ::com::sun::star::beans;
81 //=====================================================================
82 //= OQueryContainerWindow
83 //=====================================================================
84 DBG_NAME(OQueryContainerWindow)
85 OQueryContainerWindow::OQueryContainerWindow(Window* pParent, OQueryController& _rController,const Reference< XMultiServiceFactory >& _rFactory)
86 :ODataView( pParent, _rController, _rFactory )
87 ,m_pViewSwitch(NULL)
88 ,m_pBeamer(NULL)
90 DBG_CTOR(OQueryContainerWindow,NULL);
91 m_pViewSwitch = new OQueryViewSwitch( this, _rController, _rFactory );
93 m_pSplitter = new Splitter(this,WB_VSCROLL);
94 m_pSplitter->Hide();
95 m_pSplitter->SetSplitHdl( LINK( this, OQueryContainerWindow, SplitHdl ) );
96 m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
98 // -----------------------------------------------------------------------------
99 OQueryContainerWindow::~OQueryContainerWindow()
101 DBG_DTOR(OQueryContainerWindow,NULL);
103 ::std::auto_ptr<OQueryViewSwitch> aTemp(m_pViewSwitch);
104 m_pViewSwitch = NULL;
106 if ( m_pBeamer )
107 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
108 m_pBeamer = NULL;
109 if ( m_xBeamer.is() )
111 Reference< ::com::sun::star::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
112 m_xBeamer = NULL;
113 if(xCloseable.is())
114 xCloseable->close(sal_False); // false - holds the owner ship of this frame
115 // m_xBeamer->setComponent(NULL,NULL);
118 ::std::auto_ptr<Window> aTemp(m_pSplitter);
119 m_pSplitter = NULL;
122 // -----------------------------------------------------------------------------
123 bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
125 return m_pViewSwitch->switchView( _pErrorInfo );
128 // -----------------------------------------------------------------------------
129 void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground )
131 Rectangle aPlayground( _rPlayground );
133 if ( m_pBeamer && m_pBeamer->IsVisible() )
135 // calc pos and size of the splitter
136 Point aSplitPos = m_pSplitter->GetPosPixel();
137 Size aSplitSize = m_pSplitter->GetOutputSizePixel();
138 aSplitSize.Width() = aPlayground.GetWidth();
140 if ( aSplitPos.Y() <= aPlayground.Top() )
141 aSplitPos.Y() = aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 );
143 if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
144 aSplitPos.Y() = aPlayground.GetHeight() - aSplitSize.Height();
146 // set pos and size of the splitter
147 m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
148 m_pSplitter->SetDragRectPixel( aPlayground );
150 // set pos and size of the beamer
151 Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
152 m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
154 // shrink the playground by the size which is occupied by the beamer
155 aPlayground.Top() = aSplitPos.Y() + aSplitSize.Height();
158 ODataView::resizeAll( aPlayground );
161 // -----------------------------------------------------------------------------
162 void OQueryContainerWindow::resizeDocumentView( Rectangle& _rPlayground )
164 m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
166 ODataView::resizeDocumentView( _rPlayground );
169 // -----------------------------------------------------------------------------
170 void OQueryContainerWindow::GetFocus()
172 ODataView::GetFocus();
173 if(m_pViewSwitch)
174 m_pViewSwitch->GrabFocus();
176 // -----------------------------------------------------------------------------
177 IMPL_LINK( OQueryContainerWindow, SplitHdl, void*, /*p*/ )
179 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
180 Resize();
182 return 0L;
185 // -----------------------------------------------------------------------------
186 void OQueryContainerWindow::Construct()
188 m_pViewSwitch->Construct();
191 // -----------------------------------------------------------------------------
192 void OQueryContainerWindow::disposingPreview()
194 if ( m_pBeamer )
196 // here I know that we will be destroyed from the frame
197 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
198 m_pBeamer = NULL;
199 m_xBeamer = NULL;
200 m_pSplitter->Hide();
201 Resize();
204 // -----------------------------------------------------------------------------
205 long OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
207 BOOL bHandled = FALSE;
208 switch (rNEvt.GetType())
210 case EVENT_GETFOCUS:
211 if ( m_pViewSwitch )
213 OJoinController& rController = m_pViewSwitch->getDesignView()->getController();
214 rController.InvalidateFeature(SID_CUT);
215 rController.InvalidateFeature(SID_COPY);
216 rController.InvalidateFeature(SID_PASTE);
219 return bHandled ? 1L : ODataView::PreNotify(rNEvt);
221 // -----------------------------------------------------------------------------
222 void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
224 if(!m_pBeamer)
226 m_pBeamer = new OBeamer(this);
228 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
230 Reference < XFrame > xBeamerFrame( m_pViewSwitch->getORB()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.Frame")),UNO_QUERY );
231 m_xBeamer.set( xBeamerFrame );
233 // notify layout manager to not create internal toolbars
234 Reference < XPropertySet > xPropSet( xBeamerFrame, UNO_QUERY );
237 const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
238 Reference < XPropertySet > xLMPropSet;
240 Any a = xPropSet->getPropertyValue( aLayoutManager );
241 if ( a >>= xLMPropSet )
243 const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
244 xLMPropSet->setPropertyValue( aAutomaticToolbars, Any( sal_False ));
247 catch( Exception& )
251 OSL_ENSURE(m_xBeamer.is(),"No frame created!");
252 m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
253 m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
255 // append our frame
256 Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
257 Reference < XFrames > xFrames = xSup->getFrames();
258 xFrames->append( m_xBeamer );
260 Size aSize = GetOutputSizePixel();
261 Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
263 const long nFrameHeight = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
264 Point aPos(0,aBeamer.Height()+nFrameHeight);
266 m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
267 m_pBeamer->Show();
269 m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
270 // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
271 m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
272 m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
274 m_pSplitter->Show();
276 Resize();
279 // -----------------------------------------------------------------------------
282 //.........................................................................
283 } // namespace dbaui
284 //.........................................................................