LibreOffice Module dbaccess (master) 1
QueryViewSwitch.cxx
Go to the documentation of this file.
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 <QueryViewSwitch.hxx>
21#include <QueryDesignView.hxx>
22#include <QueryTextView.hxx>
24#include <adtabdlg.hxx>
25#include <querycontroller.hxx>
26
27using namespace dbaui;
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star::lang;
30
31OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow* _pParent, OQueryController& _rController,const Reference< XComponentContext >& _rxContext)
32: m_bAddTableDialogWasVisible(false)
33{
34
35 m_pTextView = VclPtr<OQueryTextView>::Create(_pParent, _rController);
36 m_pDesignView = VclPtr<OQueryDesignView>::Create( _pParent, _rController, _rxContext );
37}
38
40{
41 // destroy children
42 m_pDesignView.disposeAndClear();
43 m_pTextView.disposeAndClear();
44}
45
47{
48 m_pDesignView->Construct( );
49}
50
52{
53 // initially be in SQL mode
54 m_pTextView->Show();
55 m_pDesignView->initialize();
56}
57
59{
60 if(m_pTextView->IsVisible())
61 return true;
62 return m_pDesignView->checkStatement();
63}
64
66{
67 if(m_pTextView->IsVisible())
68 return m_pTextView->getStatement();
69 return m_pDesignView->getStatement();
70}
71
73{
74 if(m_pTextView->IsVisible())
75 m_pTextView->clear();
76 else
77 m_pDesignView->clear();
78}
79
81{
82 if ( m_pTextView && m_pTextView->IsVisible() )
83 m_pTextView->GrabFocus();
84 else if ( m_pDesignView && m_pDesignView->IsVisible() )
85 m_pDesignView->GrabFocus();
86}
87
88void OQueryViewSwitch::setStatement(const OUString& _rsStatement)
89{
90 if(m_pTextView->IsVisible())
91 m_pTextView->setStatement(_rsStatement);
92}
93
95{
96 if(m_pTextView->IsVisible())
97 m_pTextView->copy();
98 else
99 m_pDesignView->copy();
100}
101
103{
104 if(m_pTextView->IsVisible())
105 return m_pTextView->isCutAllowed();
106 return m_pDesignView->isCutAllowed();
107}
108
110{
111 if(m_pTextView->IsVisible())
112 return true;
113 return m_pDesignView->isCopyAllowed();
114}
115
117{
118 if(m_pTextView->IsVisible())
119 return true;
120 return m_pDesignView->isPasteAllowed();
121}
122
124{
125 if(m_pTextView->IsVisible())
126 m_pTextView->cut();
127 else
128 m_pDesignView->cut();
129}
130
132{
133 if(m_pTextView->IsVisible())
134 m_pTextView->paste();
135 else
136 m_pDesignView->paste();
137}
138
140{
141 vcl::Window* pDesignParent = getDesignView() ? getDesignView()->GetParent() : nullptr;
142 return static_cast< OQueryContainerWindow* >( pDesignParent );
143}
144
146{
147 OAddTableDlg* pAddTabDialog( getAddTableDialog() );
148
149 // hide the "Add Table" dialog
150 m_bAddTableDialogWasVisible = pAddTabDialog != nullptr;
152 pAddTabDialog->response(RET_CLOSE);
153
154 // tell the views they're in/active
155 m_pDesignView->stopTimer();
156 m_pTextView->startTimer();
157
158 // set the most recent statement at the text view
159 m_pTextView->clear();
160 m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement());
161}
162
164{
165 OQueryController& rQueryController( static_cast< OQueryController& >( m_pDesignView->getController() ) );
166 const bool bGraphicalDesign = rQueryController.isGraphicalDesign();
167 if ( !bGraphicalDesign )
169 else
170 {
171 // tell the text view it's inactive now
172 m_pTextView->stopTimer();
173
174 // update the "Add Table" dialog
175 OAddTableDlg* pAddTabDialog( getAddTableDialog() );
176 if ( pAddTabDialog )
177 pAddTabDialog->Update();
178
179 // initialize the design view
180 m_pDesignView->initByFieldDescriptions( rQueryController.getFieldInformation() );
181
182 // tell the design view it's active now
183 m_pDesignView->startTimer();
184 }
185
186 impl_postViewSwitch( bGraphicalDesign, true );
187}
188
190{
191 bool bRet = true;
192 bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign();
193
194 if ( !bGraphicalDesign )
195 {
197 }
198 else
199 {
200 // tell the text view it's inactive now
201 m_pTextView->stopTimer();
202
203 // update the "Add Table" dialog
204 OAddTableDlg* pAddTabDialog( getAddTableDialog() );
205 if ( pAddTabDialog )
206 pAddTabDialog->Update();
207
208 // initialize the design view
209 bRet = m_pDesignView->initByParseIterator( _pErrorInfo );
210
211 // tell the design view it's active now
212 m_pDesignView->startTimer();
213 }
214
215 return impl_postViewSwitch( bGraphicalDesign, bRet );
216}
217
218bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess )
219{
220 if ( i_bSuccess )
221 {
222 m_pTextView->Show ( !i_bGraphicalDesign );
223 m_pDesignView->Show ( i_bGraphicalDesign );
224 OAddTableDlg* pAddTabDialog( getAddTableDialog() );
225 if ( pAddTabDialog )
226 if ( i_bGraphicalDesign && m_bAddTableDialogWasVisible )
227 m_pDesignView->getController().runDialogAsync();
228
229 GrabFocus();
230 }
231
232 OQueryContainerWindow* pContainer = getContainer();
233 if ( pContainer )
234 pContainer->Resize();
235
236 m_pDesignView->getController().ClearUndoManager();
237 m_pDesignView->getController().InvalidateAll();
238
239 return i_bSuccess;
240}
241
243{
244 if ( !m_pDesignView )
245 return nullptr;
246 return m_pDesignView->getController().getAddTableDialog();
247}
248
249bool OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId)
250{
251 return m_pDesignView->isSlotEnabled(_nSlotId);
252}
253
254void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId, bool _bEnable)
255{
256 m_pDesignView->setSlotEnabled(_nSlotId,_bEnable);
257}
258
260{
261 if(m_pDesignView->IsVisible())
262 m_pDesignView->SaveUIConfig();
263}
264
266{
267 m_pDesignView->SetPosSizePixel( _rPt,_rSize);
268 m_pDesignView->Resize();
269 m_pTextView->SetPosSizePixel( _rPt,_rSize);
270}
271
273{
274 return m_pDesignView->getORB();
275}
276
278{
279 m_pDesignView->reset();
280 if ( !m_pDesignView->initByParseIterator( nullptr ) )
281 return;
282
283 switchView( nullptr );
284}
285
287{
288 if(m_pDesignView)
289 m_pDesignView->setNoneVisibleRow(_nRows);
290}
291
292/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void Resize() override
Definition: dataview.cxx:91
const css::uno::Sequence< css::beans::PropertyValue > & getFieldInformation() const
const OUString & getStatement() const
bool isSlotEnabled(sal_Int32 _nSlotId)
void setSlotEnabled(sal_Int32 _nSlotId, bool _bEnable)
css::uno::Reference< css::uno::XComponentContext > const & getORB() const
void Construct()
late construction
void setNoneVisibleRow(sal_Int32 _nRows)
bool switchView(::dbtools::SQLExceptionInfo *_pErrorInfo)
show the text or the design view
void setStatement(const OUString &_rsStatement)
VclPtr< OQueryDesignView > m_pDesignView
OQueryContainerWindow * getContainer() const
void SetPosSizePixel(Point _rPt, Size _rSize)
OAddTableDlg * getAddTableDialog()
OQueryDesignView * getDesignView() const
VclPtr< OQueryTextView > m_pTextView
bool impl_postViewSwitch(const bool i_bGraphicalDesign, const bool i_bSuccess)
vcl::Window * GetParent() const
void response(int nResponse)
RET_CLOSE