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