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