Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
34 : #include <boost/scoped_ptr.hpp>
35 :
36 : namespace dbaui
37 : {
38 :
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;
43 :
44 : // OQueryContainerWindow
45 0 : OQueryContainerWindow::OQueryContainerWindow(vcl::Window* pParent, OQueryController& _rController,const Reference< XComponentContext >& _rxContext)
46 : :ODataView( pParent, _rController, _rxContext )
47 : ,m_pViewSwitch(NULL)
48 0 : ,m_pBeamer(NULL)
49 : {
50 0 : m_pViewSwitch = new OQueryViewSwitch( this, _rController, _rxContext );
51 :
52 0 : m_pSplitter = VclPtr<Splitter>::Create(this,WB_VSCROLL);
53 0 : m_pSplitter->Hide();
54 0 : m_pSplitter->SetSplitHdl( LINK( this, OQueryContainerWindow, SplitHdl ) );
55 0 : m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
56 0 : }
57 0 : OQueryContainerWindow::~OQueryContainerWindow()
58 : {
59 0 : disposeOnce();
60 0 : }
61 0 : void OQueryContainerWindow::dispose()
62 : {
63 : {
64 0 : boost::scoped_ptr<OQueryViewSwitch> aTemp(m_pViewSwitch);
65 0 : m_pViewSwitch = NULL;
66 : }
67 0 : if ( m_pBeamer )
68 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
69 0 : m_pBeamer.clear();
70 0 : if ( m_xBeamer.is() )
71 : {
72 0 : Reference< ::com::sun::star::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
73 0 : m_xBeamer = NULL;
74 0 : if(xCloseable.is())
75 0 : xCloseable->close(sal_False); // false - holds the ownership of this frame
76 : }
77 :
78 0 : m_pSplitter.disposeAndClear();
79 0 : ODataView::dispose();
80 0 : }
81 0 : bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
82 : {
83 0 : return m_pViewSwitch->switchView( _pErrorInfo );
84 : }
85 :
86 0 : void OQueryContainerWindow::forceInitialView()
87 : {
88 0 : return m_pViewSwitch->forceInitialView();
89 : }
90 :
91 0 : void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground )
92 : {
93 0 : Rectangle aPlayground( _rPlayground );
94 :
95 0 : if ( m_pBeamer && m_pBeamer->IsVisible() )
96 : {
97 : // calc pos and size of the splitter
98 0 : Point aSplitPos = m_pSplitter->GetPosPixel();
99 0 : Size aSplitSize = m_pSplitter->GetOutputSizePixel();
100 0 : aSplitSize.Width() = aPlayground.GetWidth();
101 :
102 0 : if ( aSplitPos.Y() <= aPlayground.Top() )
103 0 : aSplitPos.Y() = aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 );
104 :
105 0 : if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
106 0 : aSplitPos.Y() = aPlayground.GetHeight() - aSplitSize.Height();
107 :
108 : // set pos and size of the splitter
109 0 : m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
110 0 : m_pSplitter->SetDragRectPixel( aPlayground );
111 :
112 : // set pos and size of the beamer
113 0 : Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
114 0 : m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
115 :
116 : // shrink the playground by the size which is occupied by the beamer
117 0 : aPlayground.Top() = aSplitPos.Y() + aSplitSize.Height();
118 : }
119 :
120 0 : ODataView::resizeAll( aPlayground );
121 0 : }
122 :
123 0 : void OQueryContainerWindow::resizeDocumentView( Rectangle& _rPlayground )
124 : {
125 0 : m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
126 :
127 0 : ODataView::resizeDocumentView( _rPlayground );
128 0 : }
129 :
130 0 : void OQueryContainerWindow::GetFocus()
131 : {
132 0 : ODataView::GetFocus();
133 0 : if(m_pViewSwitch)
134 0 : m_pViewSwitch->GrabFocus();
135 0 : }
136 0 : IMPL_LINK_NOARG( OQueryContainerWindow, SplitHdl )
137 : {
138 0 : m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
139 0 : Resize();
140 :
141 0 : return 0L;
142 : }
143 :
144 0 : void OQueryContainerWindow::Construct()
145 : {
146 0 : m_pViewSwitch->Construct();
147 0 : }
148 :
149 0 : void OQueryContainerWindow::disposingPreview()
150 : {
151 0 : if ( m_pBeamer )
152 : {
153 : // here I know that we will be destroyed from the frame
154 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
155 0 : m_pBeamer = NULL;
156 0 : m_xBeamer = NULL;
157 0 : m_pSplitter->Hide();
158 0 : Resize();
159 : }
160 0 : }
161 0 : bool OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
162 : {
163 0 : bool bHandled = false;
164 0 : if (rNEvt.GetType() == MouseNotifyEvent::GETFOCUS && m_pViewSwitch)
165 : {
166 0 : OJoinController& rController = m_pViewSwitch->getDesignView()->getController();
167 0 : rController.InvalidateFeature(SID_CUT);
168 0 : rController.InvalidateFeature(SID_COPY);
169 0 : rController.InvalidateFeature(SID_PASTE);
170 : }
171 0 : return bHandled || ODataView::PreNotify(rNEvt);
172 : }
173 0 : void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
174 : {
175 0 : if(!m_pBeamer)
176 : {
177 0 : m_pBeamer = VclPtr<OBeamer>::Create(this);
178 :
179 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
180 :
181 0 : m_xBeamer = Frame::create( m_pViewSwitch->getORB() );
182 0 : m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
183 :
184 : // notify layout manager to not create internal toolbars
185 : try
186 : {
187 0 : Reference < XPropertySet > xLMPropSet(m_xBeamer->getLayoutManager(), UNO_QUERY);
188 0 : if ( xLMPropSet.is() )
189 : {
190 0 : const OUString aAutomaticToolbars( "AutomaticToolbars" );
191 0 : xLMPropSet->setPropertyValue( aAutomaticToolbars, Any( sal_False ));
192 0 : }
193 : }
194 0 : catch( Exception& )
195 : {
196 : }
197 :
198 0 : m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
199 :
200 : // append our frame
201 0 : Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
202 0 : Reference < XFrames > xFrames = xSup->getFrames();
203 0 : xFrames->append( Reference<XFrame>(m_xBeamer,UNO_QUERY_THROW) );
204 :
205 0 : Size aSize = GetOutputSizePixel();
206 0 : Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
207 :
208 0 : const long nFrameHeight = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
209 0 : Point aPos(0,aBeamer.Height()+nFrameHeight);
210 :
211 0 : m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
212 0 : m_pBeamer->Show();
213 :
214 0 : m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
215 : // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
216 0 : m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
217 0 : m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
218 :
219 0 : m_pSplitter->Show();
220 :
221 0 : Resize();
222 : }
223 0 : }
224 :
225 36 : } // namespace dbaui
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|