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(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 = new Splitter(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 : {
60 0 : boost::scoped_ptr<OQueryViewSwitch> aTemp(m_pViewSwitch);
61 0 : m_pViewSwitch = NULL;
62 : }
63 0 : if ( m_pBeamer )
64 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
65 0 : m_pBeamer = NULL;
66 0 : if ( m_xBeamer.is() )
67 : {
68 0 : Reference< ::com::sun::star::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
69 0 : m_xBeamer = NULL;
70 0 : if(xCloseable.is())
71 0 : xCloseable->close(sal_False); // false - holds the owner ship of this frame
72 : }
73 :
74 0 : boost::scoped_ptr<Window> aTemp(m_pSplitter);
75 0 : m_pSplitter = NULL;
76 :
77 0 : }
78 0 : bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
79 : {
80 0 : return m_pViewSwitch->switchView( _pErrorInfo );
81 : }
82 :
83 0 : void OQueryContainerWindow::forceInitialView()
84 : {
85 0 : return m_pViewSwitch->forceInitialView();
86 : }
87 :
88 0 : void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground )
89 : {
90 0 : Rectangle aPlayground( _rPlayground );
91 :
92 0 : if ( m_pBeamer && m_pBeamer->IsVisible() )
93 : {
94 : // calc pos and size of the splitter
95 0 : Point aSplitPos = m_pSplitter->GetPosPixel();
96 0 : Size aSplitSize = m_pSplitter->GetOutputSizePixel();
97 0 : aSplitSize.Width() = aPlayground.GetWidth();
98 :
99 0 : if ( aSplitPos.Y() <= aPlayground.Top() )
100 0 : aSplitPos.Y() = aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 );
101 :
102 0 : if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
103 0 : aSplitPos.Y() = aPlayground.GetHeight() - aSplitSize.Height();
104 :
105 : // set pos and size of the splitter
106 0 : m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
107 0 : m_pSplitter->SetDragRectPixel( aPlayground );
108 :
109 : // set pos and size of the beamer
110 0 : Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
111 0 : m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
112 :
113 : // shrink the playground by the size which is occupied by the beamer
114 0 : aPlayground.Top() = aSplitPos.Y() + aSplitSize.Height();
115 : }
116 :
117 0 : ODataView::resizeAll( aPlayground );
118 0 : }
119 :
120 0 : void OQueryContainerWindow::resizeDocumentView( Rectangle& _rPlayground )
121 : {
122 0 : m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
123 :
124 0 : ODataView::resizeDocumentView( _rPlayground );
125 0 : }
126 :
127 0 : void OQueryContainerWindow::GetFocus()
128 : {
129 0 : ODataView::GetFocus();
130 0 : if(m_pViewSwitch)
131 0 : m_pViewSwitch->GrabFocus();
132 0 : }
133 0 : IMPL_LINK( OQueryContainerWindow, SplitHdl, void*, /*p*/ )
134 : {
135 0 : m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
136 0 : Resize();
137 :
138 0 : return 0L;
139 : }
140 :
141 0 : void OQueryContainerWindow::Construct()
142 : {
143 0 : m_pViewSwitch->Construct();
144 0 : }
145 :
146 0 : void OQueryContainerWindow::disposingPreview()
147 : {
148 0 : if ( m_pBeamer )
149 : {
150 : // here I know that we will be destroyed from the frame
151 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
152 0 : m_pBeamer = NULL;
153 0 : m_xBeamer = NULL;
154 0 : m_pSplitter->Hide();
155 0 : Resize();
156 : }
157 0 : }
158 0 : bool OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
159 : {
160 0 : sal_Bool bHandled = sal_False;
161 0 : switch (rNEvt.GetType())
162 : {
163 : case EVENT_GETFOCUS:
164 0 : if ( 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 : }
172 0 : return bHandled || ODataView::PreNotify(rNEvt);
173 : }
174 0 : void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
175 : {
176 0 : if(!m_pBeamer)
177 : {
178 0 : m_pBeamer = new OBeamer(this);
179 :
180 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
181 :
182 0 : m_xBeamer = Frame::create( m_pViewSwitch->getORB() );
183 0 : m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
184 :
185 : // notify layout manager to not create internal toolbars
186 : try
187 : {
188 0 : Reference < XPropertySet > xLMPropSet(m_xBeamer->getLayoutManager(), UNO_QUERY);
189 0 : if ( xLMPropSet.is() )
190 : {
191 0 : const OUString aAutomaticToolbars( "AutomaticToolbars" );
192 0 : xLMPropSet->setPropertyValue( aAutomaticToolbars, Any( sal_False ));
193 0 : }
194 : }
195 0 : catch( Exception& )
196 : {
197 : }
198 :
199 0 : m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
200 :
201 : // append our frame
202 0 : Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
203 0 : Reference < XFrames > xFrames = xSup->getFrames();
204 0 : xFrames->append( Reference<XFrame>(m_xBeamer,UNO_QUERY_THROW) );
205 :
206 0 : Size aSize = GetOutputSizePixel();
207 0 : Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
208 :
209 0 : const long nFrameHeight = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
210 0 : Point aPos(0,aBeamer.Height()+nFrameHeight);
211 :
212 0 : m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
213 0 : m_pBeamer->Show();
214 :
215 0 : m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
216 : // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
217 0 : m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
218 0 : m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
219 :
220 0 : m_pSplitter->Show();
221 :
222 0 : Resize();
223 : }
224 0 : }
225 :
226 : } // namespace dbaui
227 :
228 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|