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 <tools/debug.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
25 #include "JoinController.hxx"
26 #include <toolkit/helper/vclunohelper.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>
39 using namespace ::com::sun::star::uno
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::frame
;
42 using namespace ::com::sun::star::beans
;
44 // OQueryContainerWindow
45 OQueryContainerWindow::OQueryContainerWindow(vcl::Window
* pParent
, OQueryController
& _rController
,const Reference
< XComponentContext
>& _rxContext
)
46 :ODataView( pParent
, _rController
, _rxContext
)
47 ,m_pViewSwitch(nullptr)
50 m_pViewSwitch
= new OQueryViewSwitch( this, _rController
, _rxContext
);
52 m_pSplitter
= VclPtr
<Splitter
>::Create(this,WB_VSCROLL
);
54 m_pSplitter
->SetSplitHdl( LINK( this, OQueryContainerWindow
, SplitHdl
) );
55 m_pSplitter
->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
57 OQueryContainerWindow::~OQueryContainerWindow()
61 void OQueryContainerWindow::dispose()
64 std::unique_ptr
<OQueryViewSwitch
> aTemp(m_pViewSwitch
);
65 m_pViewSwitch
= nullptr;
68 ::dbaui::notifySystemWindow(this,m_pBeamer
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
72 Reference
< css::util::XCloseable
> xCloseable(m_xBeamer
,UNO_QUERY
);
75 xCloseable
->close(false); // false - holds the ownership of this frame
78 m_pSplitter
.disposeAndClear();
81 bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
83 return m_pViewSwitch
->switchView( _pErrorInfo
);
86 void OQueryContainerWindow::forceInitialView()
88 return m_pViewSwitch
->forceInitialView();
91 void OQueryContainerWindow::resizeAll( const Rectangle
& _rPlayground
)
93 Rectangle
aPlayground( _rPlayground
);
95 if ( m_pBeamer
&& m_pBeamer
->IsVisible() )
97 // calc pos and size of the splitter
98 Point aSplitPos
= m_pSplitter
->GetPosPixel();
99 Size aSplitSize
= m_pSplitter
->GetOutputSizePixel();
100 aSplitSize
.Width() = aPlayground
.GetWidth();
102 if ( aSplitPos
.Y() <= aPlayground
.Top() )
103 aSplitPos
.Y() = aPlayground
.Top() + sal_Int32( aPlayground
.GetHeight() * 0.2 );
105 if ( aSplitPos
.Y() + aSplitSize
.Height() > aPlayground
.GetHeight() )
106 aSplitPos
.Y() = aPlayground
.GetHeight() - aSplitSize
.Height();
108 // set pos and size of the splitter
109 m_pSplitter
->SetPosSizePixel( aSplitPos
, aSplitSize
);
110 m_pSplitter
->SetDragRectPixel( aPlayground
);
112 // set pos and size of the beamer
113 Size
aBeamerSize( aPlayground
.GetWidth(), aSplitPos
.Y() );
114 m_pBeamer
->SetPosSizePixel( aPlayground
.TopLeft(), aBeamerSize
);
116 // shrink the playground by the size which is occupied by the beamer
117 aPlayground
.Top() = aSplitPos
.Y() + aSplitSize
.Height();
120 ODataView::resizeAll( aPlayground
);
123 void OQueryContainerWindow::resizeDocumentView( Rectangle
& _rPlayground
)
125 m_pViewSwitch
->SetPosSizePixel( _rPlayground
.TopLeft(), Size( _rPlayground
.GetWidth(), _rPlayground
.GetHeight() ) );
127 ODataView::resizeDocumentView( _rPlayground
);
130 void OQueryContainerWindow::GetFocus()
132 ODataView::GetFocus();
134 m_pViewSwitch
->GrabFocus();
136 IMPL_LINK_NOARG_TYPED( OQueryContainerWindow
, SplitHdl
, Splitter
*, void )
138 m_pSplitter
->SetPosPixel( Point( m_pSplitter
->GetPosPixel().X(),m_pSplitter
->GetSplitPosPixel() ) );
142 void OQueryContainerWindow::Construct()
144 m_pViewSwitch
->Construct();
147 void OQueryContainerWindow::disposingPreview()
151 // here I know that we will be destroyed from the frame
152 ::dbaui::notifySystemWindow(this,m_pBeamer
,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
159 bool OQueryContainerWindow::PreNotify( NotifyEvent
& rNEvt
)
161 bool bHandled
= false;
162 if (rNEvt
.GetType() == MouseNotifyEvent::GETFOCUS
&& m_pViewSwitch
)
164 OJoinController
& rController
= m_pViewSwitch
->getDesignView()->getController();
165 rController
.InvalidateFeature(SID_CUT
);
166 rController
.InvalidateFeature(SID_COPY
);
167 rController
.InvalidateFeature(SID_PASTE
);
169 return bHandled
|| ODataView::PreNotify(rNEvt
);
171 void OQueryContainerWindow::showPreview(const Reference
<XFrame
>& _xFrame
)
175 m_pBeamer
= VclPtr
<OBeamer
>::Create(this);
177 ::dbaui::notifySystemWindow(this,m_pBeamer
,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
179 m_xBeamer
= Frame::create( m_pViewSwitch
->getORB() );
180 m_xBeamer
->initialize( VCLUnoHelper::GetInterface ( m_pBeamer
) );
182 // notify layout manager to not create internal toolbars
185 Reference
< XPropertySet
> xLMPropSet(m_xBeamer
->getLayoutManager(), UNO_QUERY
);
186 if ( xLMPropSet
.is() )
188 const OUString
aAutomaticToolbars( "AutomaticToolbars" );
189 xLMPropSet
->setPropertyValue( aAutomaticToolbars
, Any( false ));
196 m_xBeamer
->setName(FRAME_NAME_QUERY_PREVIEW
);
199 Reference
< XFramesSupplier
> xSup(_xFrame
,UNO_QUERY
);
200 Reference
< XFrames
> xFrames
= xSup
->getFrames();
201 xFrames
->append( Reference
<XFrame
>(m_xBeamer
,UNO_QUERY_THROW
) );
203 Size aSize
= GetOutputSizePixel();
204 Size
aBeamer(aSize
.Width(),sal_Int32(aSize
.Height()*0.33));
206 const long nFrameHeight
= LogicToPixel( Size( 0, 3 ), MAP_APPFONT
).Height();
207 Point
aPos(0,aBeamer
.Height()+nFrameHeight
);
209 m_pBeamer
->SetPosSizePixel(Point(0,0),aBeamer
);
212 m_pSplitter
->SetPosSizePixel( Point(0,aBeamer
.Height()), Size(aSize
.Width(),nFrameHeight
) );
213 // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
214 m_pSplitter
->SetSplitPosPixel( aBeamer
.Height() );
215 m_pViewSwitch
->SetPosSizePixel(aPos
,Size(aBeamer
.Width(),aSize
.Height() - aBeamer
.Height()-nFrameHeight
));
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */