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