1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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)
47 m_pViewSwitch
= new OQueryViewSwitch( this, _rController
, _rxContext
);
49 m_pSplitter
= VclPtr
<Splitter
>::Create(this,WB_VSCROLL
);
51 m_pSplitter
->SetSplitHdl( LINK( this, OQueryContainerWindow
, SplitHdl
) );
52 m_pSplitter
->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
54 OQueryContainerWindow::~OQueryContainerWindow()
58 void OQueryContainerWindow::dispose()
61 OQueryViewSwitch
* pTemp
= m_pViewSwitch
;
62 m_pViewSwitch
= nullptr;
66 ::dbaui::notifySystemWindow(this,m_pBeamer
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
70 Reference
< css::util::XCloseable
> xCloseable(m_xBeamer
,UNO_QUERY
);
73 xCloseable
->close(false); // false - holds the ownership of this frame
76 m_pSplitter
.disposeAndClear();
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();
132 m_pViewSwitch
->GrabFocus();
134 IMPL_LINK_NOARG( OQueryContainerWindow
, SplitHdl
, Splitter
*, void )
136 m_pSplitter
->SetPosPixel( Point( m_pSplitter
->GetPosPixel().X(),m_pSplitter
->GetSplitPosPixel() ) );
140 void OQueryContainerWindow::Construct()
142 m_pViewSwitch
->Construct();
145 void OQueryContainerWindow::disposingPreview()
149 // here I know that we will be destroyed from the frame
150 ::dbaui::notifySystemWindow(this,m_pBeamer
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
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
)
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 ));
193 m_xBeamer
->setName(FRAME_NAME_QUERY_PREVIEW
);
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
);
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
));
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */