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 :
21 : #include "querycontainerwindow.hxx"
22 : #include "QueryDesignView.hxx"
23 : #include <tools/debug.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include "JoinController.hxx"
26 : #include <toolkit/unohlp.hxx>
27 : #include "dbustrings.hrc"
28 : #include <sfx2/sfxsids.hrc>
29 : #include <vcl/fixed.hxx>
30 : #include "UITools.hxx"
31 : #include <com/sun/star/util/XCloseable.hpp>
32 : #include <com/sun/star/beans/XPropertySet.hpp>
33 :
34 : //.........................................................................
35 : namespace dbaui
36 : {
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 : //=====================================================================
45 : //= OQueryContainerWindow
46 : //=====================================================================
47 : DBG_NAME(OQueryContainerWindow)
48 0 : OQueryContainerWindow::OQueryContainerWindow(Window* pParent, OQueryController& _rController,const Reference< XComponentContext >& _rxContext)
49 : :ODataView( pParent, _rController, _rxContext )
50 : ,m_pViewSwitch(NULL)
51 0 : ,m_pBeamer(NULL)
52 : {
53 : DBG_CTOR(OQueryContainerWindow,NULL);
54 0 : m_pViewSwitch = new OQueryViewSwitch( this, _rController, _rxContext );
55 :
56 0 : m_pSplitter = new Splitter(this,WB_VSCROLL);
57 0 : m_pSplitter->Hide();
58 0 : m_pSplitter->SetSplitHdl( LINK( this, OQueryContainerWindow, SplitHdl ) );
59 0 : m_pSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetDialogColor() ) );
60 0 : }
61 : // -----------------------------------------------------------------------------
62 0 : OQueryContainerWindow::~OQueryContainerWindow()
63 : {
64 : DBG_DTOR(OQueryContainerWindow,NULL);
65 : {
66 0 : ::std::auto_ptr<OQueryViewSwitch> aTemp(m_pViewSwitch);
67 0 : m_pViewSwitch = NULL;
68 : }
69 0 : if ( m_pBeamer )
70 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
71 0 : m_pBeamer = NULL;
72 0 : if ( m_xBeamer.is() )
73 : {
74 0 : Reference< ::com::sun::star::util::XCloseable > xCloseable(m_xBeamer,UNO_QUERY);
75 0 : m_xBeamer = NULL;
76 0 : if(xCloseable.is())
77 0 : xCloseable->close(sal_False); // false - holds the owner ship of this frame
78 : }
79 :
80 0 : ::std::auto_ptr<Window> aTemp(m_pSplitter);
81 0 : m_pSplitter = NULL;
82 :
83 0 : }
84 : // -----------------------------------------------------------------------------
85 0 : bool OQueryContainerWindow::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
86 : {
87 0 : return m_pViewSwitch->switchView( _pErrorInfo );
88 : }
89 :
90 : // -----------------------------------------------------------------------------
91 0 : void OQueryContainerWindow::forceInitialView()
92 : {
93 0 : return m_pViewSwitch->forceInitialView();
94 : }
95 :
96 : // -----------------------------------------------------------------------------
97 0 : void OQueryContainerWindow::resizeAll( const Rectangle& _rPlayground )
98 : {
99 0 : Rectangle aPlayground( _rPlayground );
100 :
101 0 : if ( m_pBeamer && m_pBeamer->IsVisible() )
102 : {
103 : // calc pos and size of the splitter
104 0 : Point aSplitPos = m_pSplitter->GetPosPixel();
105 0 : Size aSplitSize = m_pSplitter->GetOutputSizePixel();
106 0 : aSplitSize.Width() = aPlayground.GetWidth();
107 :
108 0 : if ( aSplitPos.Y() <= aPlayground.Top() )
109 0 : aSplitPos.Y() = aPlayground.Top() + sal_Int32( aPlayground.GetHeight() * 0.2 );
110 :
111 0 : if ( aSplitPos.Y() + aSplitSize.Height() > aPlayground.GetHeight() )
112 0 : aSplitPos.Y() = aPlayground.GetHeight() - aSplitSize.Height();
113 :
114 : // set pos and size of the splitter
115 0 : m_pSplitter->SetPosSizePixel( aSplitPos, aSplitSize );
116 0 : m_pSplitter->SetDragRectPixel( aPlayground );
117 :
118 : // set pos and size of the beamer
119 0 : Size aBeamerSize( aPlayground.GetWidth(), aSplitPos.Y() );
120 0 : m_pBeamer->SetPosSizePixel( aPlayground.TopLeft(), aBeamerSize );
121 :
122 : // shrink the playground by the size which is occupied by the beamer
123 0 : aPlayground.Top() = aSplitPos.Y() + aSplitSize.Height();
124 : }
125 :
126 0 : ODataView::resizeAll( aPlayground );
127 0 : }
128 :
129 : // -----------------------------------------------------------------------------
130 0 : void OQueryContainerWindow::resizeDocumentView( Rectangle& _rPlayground )
131 : {
132 0 : m_pViewSwitch->SetPosSizePixel( _rPlayground.TopLeft(), Size( _rPlayground.GetWidth(), _rPlayground.GetHeight() ) );
133 :
134 0 : ODataView::resizeDocumentView( _rPlayground );
135 0 : }
136 :
137 : // -----------------------------------------------------------------------------
138 0 : void OQueryContainerWindow::GetFocus()
139 : {
140 0 : ODataView::GetFocus();
141 0 : if(m_pViewSwitch)
142 0 : m_pViewSwitch->GrabFocus();
143 0 : }
144 : // -----------------------------------------------------------------------------
145 0 : IMPL_LINK( OQueryContainerWindow, SplitHdl, void*, /*p*/ )
146 : {
147 0 : m_pSplitter->SetPosPixel( Point( m_pSplitter->GetPosPixel().X(),m_pSplitter->GetSplitPosPixel() ) );
148 0 : Resize();
149 :
150 0 : return 0L;
151 : }
152 :
153 : // -----------------------------------------------------------------------------
154 0 : void OQueryContainerWindow::Construct()
155 : {
156 0 : m_pViewSwitch->Construct();
157 0 : }
158 :
159 : // -----------------------------------------------------------------------------
160 0 : void OQueryContainerWindow::disposingPreview()
161 : {
162 0 : if ( m_pBeamer )
163 : {
164 : // here I know that we will be destroyed from the frame
165 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
166 0 : m_pBeamer = NULL;
167 0 : m_xBeamer = NULL;
168 0 : m_pSplitter->Hide();
169 0 : Resize();
170 : }
171 0 : }
172 : // -----------------------------------------------------------------------------
173 0 : long OQueryContainerWindow::PreNotify( NotifyEvent& rNEvt )
174 : {
175 0 : sal_Bool bHandled = sal_False;
176 0 : switch (rNEvt.GetType())
177 : {
178 : case EVENT_GETFOCUS:
179 0 : if ( m_pViewSwitch )
180 : {
181 0 : OJoinController& rController = m_pViewSwitch->getDesignView()->getController();
182 0 : rController.InvalidateFeature(SID_CUT);
183 0 : rController.InvalidateFeature(SID_COPY);
184 0 : rController.InvalidateFeature(SID_PASTE);
185 : }
186 : }
187 0 : return bHandled ? 1L : ODataView::PreNotify(rNEvt);
188 : }
189 : // -----------------------------------------------------------------------------
190 0 : void OQueryContainerWindow::showPreview(const Reference<XFrame>& _xFrame)
191 : {
192 0 : if(!m_pBeamer)
193 : {
194 0 : m_pBeamer = new OBeamer(this);
195 :
196 0 : ::dbaui::notifySystemWindow(this,m_pBeamer,::comphelper::mem_fun(&TaskPaneList::AddWindow));
197 :
198 0 : Reference < XFrame > xBeamerFrame( m_pViewSwitch->getORB()->getServiceManager()->createInstanceWithContext(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")), m_pViewSwitch->getORB()),UNO_QUERY );
199 0 : m_xBeamer.set( xBeamerFrame );
200 : OSL_ENSURE(m_xBeamer.is(),"No frame created!");
201 0 : m_xBeamer->initialize( VCLUnoHelper::GetInterface ( m_pBeamer ) );
202 :
203 : // notify layout manager to not create internal toolbars
204 0 : Reference < XPropertySet > xPropSet( xBeamerFrame, UNO_QUERY );
205 : try
206 : {
207 0 : const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
208 0 : Reference < XPropertySet > xLMPropSet(xPropSet->getPropertyValue( aLayoutManager ),UNO_QUERY);
209 :
210 0 : if ( xLMPropSet.is() )
211 : {
212 0 : const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
213 0 : xLMPropSet->setPropertyValue( aAutomaticToolbars, Any( sal_False ));
214 0 : }
215 : }
216 0 : catch( Exception& )
217 : {
218 : }
219 :
220 0 : m_xBeamer->setName(FRAME_NAME_QUERY_PREVIEW);
221 :
222 : // append our frame
223 0 : Reference < XFramesSupplier > xSup(_xFrame,UNO_QUERY);
224 0 : Reference < XFrames > xFrames = xSup->getFrames();
225 0 : xFrames->append( m_xBeamer );
226 :
227 0 : Size aSize = GetOutputSizePixel();
228 0 : Size aBeamer(aSize.Width(),sal_Int32(aSize.Height()*0.33));
229 :
230 0 : const long nFrameHeight = LogicToPixel( Size( 0, 3 ), MAP_APPFONT ).Height();
231 0 : Point aPos(0,aBeamer.Height()+nFrameHeight);
232 :
233 0 : m_pBeamer->SetPosSizePixel(Point(0,0),aBeamer);
234 0 : m_pBeamer->Show();
235 :
236 0 : m_pSplitter->SetPosSizePixel( Point(0,aBeamer.Height()), Size(aSize.Width(),nFrameHeight) );
237 : // a default pos for the splitter, so that the listbox is about 80 (logical) pixels wide
238 0 : m_pSplitter->SetSplitPosPixel( aBeamer.Height() );
239 0 : m_pViewSwitch->SetPosSizePixel(aPos,Size(aBeamer.Width(),aSize.Height() - aBeamer.Height()-nFrameHeight));
240 :
241 0 : m_pSplitter->Show();
242 :
243 0 : Resize();
244 : }
245 0 : }
246 : // -----------------------------------------------------------------------------
247 :
248 :
249 : //.........................................................................
250 : } // namespace dbaui
251 : //.........................................................................
252 :
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|