bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / ui / querydesign / querycontainerwindow.cxx
blob2c04309c68be15d19acabaea081759803374ae5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "querycontainerwindow.hxx"
22 #include "QueryDesignView.hxx"
23 #include <tools/debug.hxx>
24 #include <vcl/svapp.hxx>
25 #include "JoinController.hxx"
26 #include <toolkit/unohlp.hxx>
27 #include "dbustrings.hrc"
28 #include <sfx2/sfxsids.hrc>
29 #include <vcl/fixed.hxx>
30 #include "UITools.hxx"
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/frame/Frame.hpp>
33 #include <com/sun/star/util/XCloseable.hpp>
35 //.........................................................................
36 namespace dbaui
38 //.........................................................................
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::frame;
43 using namespace ::com::sun::star::beans;
45 //=====================================================================
46 //= OQueryContainerWindow
47 //=====================================================================
48 DBG_NAME(OQueryContainerWindow)
49 OQueryContainerWindow::OQueryContainerWindow(Window* pParent, OQueryController& _rController,const Reference< XComponentContext >& _rxContext)
50 :ODataView( pParent, _rController, _rxContext )
51 ,m_pViewSwitch(NULL)
52 ,m_pBeamer(NULL)
54 DBG_CTOR(OQueryContainerWindow,NULL);
55 m_pViewSwitch = new OQueryViewSwitch( this, _rController, _rxContext );
57 m_pSplitter = new Splitter(this,WB_VSCROLL);
58 m_pSplitter->Hide();
59 m_pSplitter->SetSplitHdl( LINK( this, OQueryContainerWindow, SplitHdl ) );
60 m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
62 // -----------------------------------------------------------------------------
63 OQueryContainerWindow::~OQueryContainerWindow()
65 DBG_DTOR(OQueryContainerWindow,NULL);
67 ::std::auto_ptr<OQueryViewSwitch> aTemp(m_pViewSwitch);
68 m_pViewSwitch = NULL;
70 if ( m_pBeamer )
71 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
72 m_pBeamer = NULL;
73 if ( m_xBeamer.is() )
75 Reference< ::com::sun::star::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
76 m_xBeamer = NULL;
77 if(xCloseable.is())
78 xCloseable->close(sal_False); // false - holds the owner ship of this frame
81 ::std::auto_ptr<Window> aTemp(m_pSplitter);
82 m_pSplitter = NULL;
85 // -----------------------------------------------------------------------------
86 bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
88 return m_pViewSwitch->switchView( _pErrorInfo );
91 // -----------------------------------------------------------------------------
92 void OQueryContainerWindow::forceInitialView()
94 return m_pViewSwitch->forceInitialView();
97 // -----------------------------------------------------------------------------
98 void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground )
100 Rectangle aPlayground( _rPlayground );
102 if ( m_pBeamer && m_pBeamer->IsVisible() )
104 // calc pos and size of the splitter
105 Point aSplitPos = m_pSplitter->GetPosPixel();
106 Size aSplitSize = m_pSplitter->GetOutputSizePixel();
107 aSplitSize.Width() = aPlayground.GetWidth();
109 if ( aSplitPos.Y() <= aPlayground.Top() )
110 aSplitPos.Y() = aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 );
112 if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
113 aSplitPos.Y() = aPlayground.GetHeight() - aSplitSize.Height();
115 // set pos and size of the splitter
116 m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
117 m_pSplitter->SetDragRectPixel( aPlayground );
119 // set pos and size of the beamer
120 Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
121 m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
123 // shrink the playground by the size which is occupied by the beamer
124 aPlayground.Top() = aSplitPos.Y() + aSplitSize.Height();
127 ODataView::resizeAll( aPlayground );
130 // -----------------------------------------------------------------------------
131 void OQueryContainerWindow::resizeDocumentView( Rectangle& _rPlayground )
133 m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
135 ODataView::resizeDocumentView( _rPlayground );
138 // -----------------------------------------------------------------------------
139 void OQueryContainerWindow::GetFocus()
141 ODataView::GetFocus();
142 if(m_pViewSwitch)
143 m_pViewSwitch->GrabFocus();
145 // -----------------------------------------------------------------------------
146 IMPL_LINK( OQueryContainerWindow, SplitHdl, void*, /*p*/ )
148 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
149 Resize();
151 return 0L;
154 // -----------------------------------------------------------------------------
155 void OQueryContainerWindow::Construct()
157 m_pViewSwitch->Construct();
160 // -----------------------------------------------------------------------------
161 void OQueryContainerWindow::disposingPreview()
163 if ( m_pBeamer )
165 // here I know that we will be destroyed from the frame
166 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
167 m_pBeamer = NULL;
168 m_xBeamer = NULL;
169 m_pSplitter->Hide();
170 Resize();
173 // -----------------------------------------------------------------------------
174 long OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
176 sal_Bool bHandled = sal_False;
177 switch (rNEvt.GetType())
179 case EVENT_GETFOCUS:
180 if ( m_pViewSwitch )
182 OJoinController& rController = m_pViewSwitch->getDesignView()->getController();
183 rController.InvalidateFeature(SID_CUT);
184 rController.InvalidateFeature(SID_COPY);
185 rController.InvalidateFeature(SID_PASTE);
188 return bHandled ? 1L : ODataView::PreNotify(rNEvt);
190 // -----------------------------------------------------------------------------
191 void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
193 if(!m_pBeamer)
195 m_pBeamer = new OBeamer(this);
197 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
199 m_xBeamer = Frame::create( m_pViewSwitch->getORB() );
200 m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
202 // notify layout manager to not create internal toolbars
205 Reference < XPropertySet > xLMPropSet(m_xBeamer->getLayoutManager(), UNO_QUERY);
206 if ( xLMPropSet.is() )
208 const OUString aAutomaticToolbars( "AutomaticToolbars" );
209 xLMPropSet->setPropertyValue( aAutomaticToolbars, Any( sal_False ));
212 catch( Exception& )
216 m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
218 // append our frame
219 Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
220 Reference < XFrames > xFrames = xSup->getFrames();
221 xFrames->append( Reference<XFrame>(m_xBeamer,UNO_QUERY_THROW) );
223 Size aSize = GetOutputSizePixel();
224 Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
226 const long nFrameHeight = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
227 Point aPos(0,aBeamer.Height()+nFrameHeight);
229 m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
230 m_pBeamer->Show();
232 m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
233 // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
234 m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
235 m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
237 m_pSplitter->Show();
239 Resize();
242 // -----------------------------------------------------------------------------
245 //.........................................................................
246 } // namespace dbaui
247 //.........................................................................
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */