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 <QueryViewSwitch.hxx>
21 #include <QueryDesignView.hxx>
22 #include <QueryTextView.hxx>
23 #include <querycontainerwindow.hxx>
24 #include <adtabdlg.hxx>
25 #include <querycontroller.hxx>
27 using namespace dbaui
;
28 using namespace ::com::sun::star::uno
;
29 using namespace ::com::sun::star::lang
;
31 OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow
* _pParent
, OQueryController
& _rController
,const Reference
< XComponentContext
>& _rxContext
)
32 : m_bAddTableDialogWasVisible(false)
35 m_pTextView
= VclPtr
<OQueryTextView
>::Create(_pParent
, _rController
);
36 m_pDesignView
= VclPtr
<OQueryDesignView
>::Create( _pParent
, _rController
, _rxContext
);
39 OQueryViewSwitch::~OQueryViewSwitch()
42 m_pDesignView
.disposeAndClear();
43 m_pTextView
.disposeAndClear();
46 void OQueryViewSwitch::Construct()
48 m_pDesignView
->Construct( );
51 void OQueryViewSwitch::initialize()
53 // initially be in SQL mode
55 m_pDesignView
->initialize();
58 bool OQueryViewSwitch::checkStatement()
60 if(m_pTextView
->IsVisible())
62 return m_pDesignView
->checkStatement();
65 OUString
OQueryViewSwitch::getStatement()
67 if(m_pTextView
->IsVisible())
68 return m_pTextView
->getStatement();
69 return m_pDesignView
->getStatement();
72 void OQueryViewSwitch::clear()
74 if(m_pTextView
->IsVisible())
77 m_pDesignView
->clear();
80 void OQueryViewSwitch::GrabFocus()
82 if ( m_pTextView
&& m_pTextView
->IsVisible() )
83 m_pTextView
->GrabFocus();
84 else if ( m_pDesignView
&& m_pDesignView
->IsVisible() )
85 m_pDesignView
->GrabFocus();
88 void OQueryViewSwitch::setStatement(const OUString
& _rsStatement
)
90 if(m_pTextView
->IsVisible())
91 m_pTextView
->setStatement(_rsStatement
);
94 void OQueryViewSwitch::copy()
96 if(m_pTextView
->IsVisible())
99 m_pDesignView
->copy();
102 bool OQueryViewSwitch::isCutAllowed() const
104 if(m_pTextView
->IsVisible())
105 return m_pTextView
->isCutAllowed();
106 return m_pDesignView
->isCutAllowed();
109 bool OQueryViewSwitch::isCopyAllowed() const
111 if(m_pTextView
->IsVisible())
113 return m_pDesignView
->isCopyAllowed();
116 bool OQueryViewSwitch::isPasteAllowed() const
118 if(m_pTextView
->IsVisible())
120 return m_pDesignView
->isPasteAllowed();
123 void OQueryViewSwitch::cut()
125 if(m_pTextView
->IsVisible())
128 m_pDesignView
->cut();
131 void OQueryViewSwitch::paste()
133 if(m_pTextView
->IsVisible())
134 m_pTextView
->paste();
136 m_pDesignView
->paste();
139 OQueryContainerWindow
* OQueryViewSwitch::getContainer() const
141 vcl::Window
* pDesignParent
= getDesignView() ? getDesignView()->GetParent() : nullptr;
142 return static_cast< OQueryContainerWindow
* >( pDesignParent
);
145 void OQueryViewSwitch::impl_forceSQLView()
147 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
149 // hide the "Add Table" dialog
150 m_bAddTableDialogWasVisible
= pAddTabDialog
!= nullptr;
151 if (m_bAddTableDialogWasVisible
)
152 pAddTabDialog
->response(RET_CLOSE
);
154 // tell the views they're in/active
155 m_pDesignView
->stopTimer();
156 m_pTextView
->startTimer();
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());
163 void OQueryViewSwitch::forceInitialView()
165 OQueryController
& rQueryController( static_cast< OQueryController
& >( m_pDesignView
->getController() ) );
166 const bool bGraphicalDesign
= rQueryController
.isGraphicalDesign();
167 if ( !bGraphicalDesign
)
171 // tell the text view it's inactive now
172 m_pTextView
->stopTimer();
174 // update the "Add Table" dialog
175 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
177 pAddTabDialog
->Update();
179 // initialize the design view
180 m_pDesignView
->initByFieldDescriptions( rQueryController
.getFieldInformation() );
182 // tell the design view it's active now
183 m_pDesignView
->startTimer();
186 impl_postViewSwitch( bGraphicalDesign
, true );
189 bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
192 bool bGraphicalDesign
= static_cast<OQueryController
&>(m_pDesignView
->getController()).isGraphicalDesign();
194 if ( !bGraphicalDesign
)
200 // tell the text view it's inactive now
201 m_pTextView
->stopTimer();
203 // update the "Add Table" dialog
204 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
206 pAddTabDialog
->Update();
208 // initialize the design view
209 bRet
= m_pDesignView
->initByParseIterator( _pErrorInfo
);
211 // tell the design view it's active now
212 m_pDesignView
->startTimer();
215 return impl_postViewSwitch( bGraphicalDesign
, bRet
);
218 bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign
, const bool i_bSuccess
)
222 m_pTextView
->Show ( !i_bGraphicalDesign
);
223 m_pDesignView
->Show ( i_bGraphicalDesign
);
224 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
226 if ( i_bGraphicalDesign
&& m_bAddTableDialogWasVisible
)
227 m_pDesignView
->getController().runDialogAsync();
232 OQueryContainerWindow
* pContainer
= getContainer();
234 pContainer
->Resize();
236 m_pDesignView
->getController().ClearUndoManager();
237 m_pDesignView
->getController().InvalidateAll();
242 OAddTableDlg
* OQueryViewSwitch::getAddTableDialog()
244 if ( !m_pDesignView
)
246 return m_pDesignView
->getController().getAddTableDialog();
249 bool OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId
)
251 return m_pDesignView
->isSlotEnabled(_nSlotId
);
254 void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId
, bool _bEnable
)
256 m_pDesignView
->setSlotEnabled(_nSlotId
,_bEnable
);
259 void OQueryViewSwitch::SaveUIConfig()
261 if(m_pDesignView
->IsVisible())
262 m_pDesignView
->SaveUIConfig();
265 void OQueryViewSwitch::SetPosSizePixel( Point _rPt
,Size _rSize
)
267 m_pDesignView
->SetPosSizePixel( _rPt
,_rSize
);
268 m_pDesignView
->Resize();
269 m_pTextView
->SetPosSizePixel( _rPt
,_rSize
);
272 Reference
< XComponentContext
> const & OQueryViewSwitch::getORB() const
274 return m_pDesignView
->getORB();
277 void OQueryViewSwitch::reset()
279 m_pDesignView
->reset();
280 if ( !m_pDesignView
->initByParseIterator( nullptr ) )
283 switchView( nullptr );
286 void OQueryViewSwitch::setNoneVisibleRow(sal_Int32 _nRows
)
289 m_pDesignView
->setNoneVisibleRow(_nRows
);
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */