Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / querydesign / querycontainerwindow.cxx
blob2c1788620a24fbc6bead4b11cd2562e3dc184fbe
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 .
20 #include <querycontainerwindow.hxx>
21 #include <QueryDesignView.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/settings.hxx>
24 #include <JoinController.hxx>
25 #include <toolkit/helper/vclunohelper.hxx>
26 #include <strings.hxx>
27 #include <sfx2/sfxsids.hrc>
28 #include <vcl/event.hxx>
29 #include <UITools.hxx>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/frame/Frame.hpp>
32 #include <com/sun/star/util/XCloseable.hpp>
34 namespace dbaui
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::frame;
39 using namespace ::com::sun::star::beans;
41 // OQueryContainerWindow
42 OQueryContainerWindow::OQueryContainerWindow(vcl::Window* pParent, OQueryController& _rController,const Reference< XComponentContext >& _rxContext)
43 :ODataView( pParent, _rController, _rxContext )
44 ,m_pViewSwitch(nullptr)
45 ,m_pBeamer(nullptr)
47 m_pViewSwitch = new OQueryViewSwitch( this, _rController, _rxContext );
49 m_pSplitter = VclPtr<Splitter>::Create(this,WB_VSCROLL);
50 m_pSplitter->Hide();
51 m_pSplitter->SetSplitHdl( LINK( this, OQueryContainerWindow, SplitHdl ) );
52 m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
54 OQueryContainerWindow::~OQueryContainerWindow()
56 disposeOnce();
58 void OQueryContainerWindow::dispose()
61 OQueryViewSwitch* pTemp = m_pViewSwitch;
62 m_pViewSwitch = nullptr;
63 delete pTemp;
65 if ( m_pBeamer )
66 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
67 m_pBeamer.clear();
68 if ( m_xBeamer.is() )
70 Reference< css::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
71 m_xBeamer = nullptr;
72 if(xCloseable.is())
73 xCloseable->close(false); // false - holds the ownership of this frame
76 m_pSplitter.disposeAndClear();
77 ODataView::dispose();
79 bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
81 return m_pViewSwitch->switchView( _pErrorInfo );
84 void OQueryContainerWindow::forceInitialView()
86 return m_pViewSwitch->forceInitialView();
89 void OQueryContainerWindow::resizeAll( const tools::Rectangle& _rPlayground )
91 tools::Rectangle aPlayground( _rPlayground );
93 if ( m_pBeamer && m_pBeamer->IsVisible() )
95 // calc pos and size of the splitter
96 Point aSplitPos = m_pSplitter->GetPosPixel();
97 Size aSplitSize = m_pSplitter->GetOutputSizePixel();
98 aSplitSize.setWidth( aPlayground.GetWidth() );
100 if ( aSplitPos.Y() <= aPlayground.Top() )
101 aSplitPos.setY( aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 ) );
103 if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
104 aSplitPos.setY( aPlayground.GetHeight() - aSplitSize.Height() );
106 // set pos and size of the splitter
107 m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
108 m_pSplitter->SetDragRectPixel( aPlayground );
110 // set pos and size of the beamer
111 Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
112 m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
114 // shrink the playground by the size which is occupied by the beamer
115 aPlayground.SetTop( aSplitPos.Y() + aSplitSize.Height() );
118 ODataView::resizeAll( aPlayground );
121 void OQueryContainerWindow::resizeDocumentView( tools::Rectangle& _rPlayground )
123 m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
125 ODataView::resizeDocumentView( _rPlayground );
128 void OQueryContainerWindow::GetFocus()
130 ODataView::GetFocus();
131 if(m_pViewSwitch)
132 m_pViewSwitch->GrabFocus();
134 IMPL_LINK_NOARG( OQueryContainerWindow, SplitHdl, Splitter*, void )
136 m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
137 Resize();
140 void OQueryContainerWindow::Construct()
142 m_pViewSwitch->Construct();
145 void OQueryContainerWindow::disposingPreview()
147 if ( m_pBeamer )
149 // here I know that we will be destroyed from the frame
150 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
151 m_pBeamer = nullptr;
152 m_xBeamer = nullptr;
153 m_pSplitter->Hide();
154 Resize();
157 bool OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
159 if (rNEvt.GetType() == NotifyEventType::GETFOCUS && m_pViewSwitch)
161 OJoinController& rController = m_pViewSwitch->getDesignView()->getController();
162 rController.InvalidateFeature(SID_CUT);
163 rController.InvalidateFeature(SID_COPY);
164 rController.InvalidateFeature(SID_PASTE);
166 return ODataView::PreNotify(rNEvt);
168 void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
170 if(m_pBeamer)
171 return;
173 m_pBeamer = VclPtr<OBeamer>::Create(this);
175 ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
177 m_xBeamer = Frame::create( m_pViewSwitch->getORB() );
178 m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
180 // notify layout manager to not create internal toolbars
183 Reference < XPropertySet > xLMPropSet(m_xBeamer->getLayoutManager(), UNO_QUERY);
184 if ( xLMPropSet.is() )
186 xLMPropSet->setPropertyValue( u"AutomaticToolbars"_ustr, Any( false ));
189 catch( Exception& )
193 m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
195 // append our frame
196 Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
197 Reference < XFrames > xFrames = xSup->getFrames();
198 xFrames->append( Reference<XFrame>(m_xBeamer,UNO_QUERY_THROW) );
200 Size aSize = GetOutputSizePixel();
201 Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
203 const tools::Long nFrameHeight = LogicToPixel(Size(0, 3), MapMode(MapUnit::MapAppFont)).Height();
204 Point aPos(0,aBeamer.Height()+nFrameHeight);
206 m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
207 m_pBeamer->Show();
209 m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
210 // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
211 m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
212 m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
214 m_pSplitter->Show();
216 Resize();
219 } // namespace dbaui
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */