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 "dbu_qry.hrc"
25 #include "browserids.hxx"
26 #include "adtabdlg.hxx"
27 #include "querycontroller.hxx"
28 #include "sqledit.hxx"
29 #include <boost/scoped_ptr.hpp>
31 using namespace dbaui
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::lang
;
35 OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow
* _pParent
, OQueryController
& _rController
,const Reference
< XComponentContext
>& _rxContext
)
36 : m_bAddTableDialogWasVisible(false)
39 m_pTextView
= VclPtr
<OQueryTextView
>::Create(_pParent
);
40 m_pDesignView
= VclPtr
<OQueryDesignView
>::Create( _pParent
, _rController
, _rxContext
);
43 OQueryViewSwitch::~OQueryViewSwitch()
46 m_pDesignView
.disposeAndClear();
47 m_pTextView
.disposeAndClear();
50 void OQueryViewSwitch::Construct()
52 m_pDesignView
->Construct( );
55 void OQueryViewSwitch::initialize()
57 // initially be in SQL mode
59 m_pDesignView
->initialize();
62 bool OQueryViewSwitch::checkStatement()
64 if(m_pTextView
->IsVisible())
66 return m_pDesignView
->checkStatement();
69 OUString
OQueryViewSwitch::getStatement()
71 if(m_pTextView
->IsVisible())
72 return m_pTextView
->getStatement();
73 return m_pDesignView
->getStatement();
76 void OQueryViewSwitch::clear()
78 if(m_pTextView
->IsVisible())
81 m_pDesignView
->clear();
84 void OQueryViewSwitch::GrabFocus()
86 if ( m_pTextView
&& m_pTextView
->IsVisible() )
87 m_pTextView
->GrabFocus();
88 else if ( m_pDesignView
&& m_pDesignView
->IsVisible() )
89 m_pDesignView
->GrabFocus();
92 void OQueryViewSwitch::setStatement(const OUString
& _rsStatement
)
94 if(m_pTextView
->IsVisible())
95 m_pTextView
->setStatement(_rsStatement
);
97 m_pDesignView
->setStatement(_rsStatement
);
100 void OQueryViewSwitch::copy()
102 if(m_pTextView
->IsVisible())
105 m_pDesignView
->copy();
108 bool OQueryViewSwitch::isCutAllowed()
110 if(m_pTextView
->IsVisible())
111 return m_pTextView
->isCutAllowed();
112 return m_pDesignView
->isCutAllowed();
115 bool OQueryViewSwitch::isCopyAllowed()
117 if(m_pTextView
->IsVisible())
119 return m_pDesignView
->isCopyAllowed();
122 bool OQueryViewSwitch::isPasteAllowed()
124 if(m_pTextView
->IsVisible())
126 return m_pDesignView
->isPasteAllowed();
129 void OQueryViewSwitch::cut()
131 if(m_pTextView
->IsVisible())
134 m_pDesignView
->cut();
137 void OQueryViewSwitch::paste()
139 if(m_pTextView
->IsVisible())
140 m_pTextView
->paste();
142 m_pDesignView
->paste();
145 OQueryContainerWindow
* OQueryViewSwitch::getContainer() const
147 vcl::Window
* pDesignParent
= getDesignView() ? getDesignView()->GetParent() : NULL
;
148 return static_cast< OQueryContainerWindow
* >( pDesignParent
);
151 void OQueryViewSwitch::impl_forceSQLView()
153 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
155 // hide the "Add Table" dialog
156 m_bAddTableDialogWasVisible
= pAddTabDialog
&& pAddTabDialog
->IsVisible();
157 if ( m_bAddTableDialogWasVisible
)
158 pAddTabDialog
->Hide();
160 // tell the views they're in/active
161 m_pDesignView
->stopTimer();
162 m_pTextView
->getSqlEdit()->startTimer();
164 // set the most recent statement at the text view
165 m_pTextView
->clear();
166 m_pTextView
->setStatement(static_cast<OQueryController
&>(m_pDesignView
->getController()).getStatement());
169 void OQueryViewSwitch::forceInitialView()
171 OQueryController
& rQueryController( static_cast< OQueryController
& >( m_pDesignView
->getController() ) );
172 const bool bGraphicalDesign
= rQueryController
.isGraphicalDesign();
173 if ( !bGraphicalDesign
)
177 // tell the text view it's inactive now
178 m_pTextView
->getSqlEdit()->stopTimer();
180 // update the "Add Table" dialog
181 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
183 pAddTabDialog
->Update();
185 // initialize the design view
186 m_pDesignView
->initByFieldDescriptions( rQueryController
.getFieldInformation() );
188 // tell the design view it's active now
189 m_pDesignView
->startTimer();
192 impl_postViewSwitch( bGraphicalDesign
, true );
195 bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
198 bool bGraphicalDesign
= static_cast<OQueryController
&>(m_pDesignView
->getController()).isGraphicalDesign();
200 if ( !bGraphicalDesign
)
206 // tell the text view it's inactive now
207 m_pTextView
->getSqlEdit()->stopTimer();
209 // update the "Add Table" dialog
210 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
212 pAddTabDialog
->Update();
214 // initialize the design view
215 bRet
= m_pDesignView
->initByParseIterator( _pErrorInfo
);
217 // tell the design view it's active now
218 m_pDesignView
->startTimer();
221 return impl_postViewSwitch( bGraphicalDesign
, bRet
);
224 bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign
, const bool i_bSuccess
)
228 m_pTextView
->Show ( !i_bGraphicalDesign
);
229 m_pDesignView
->Show ( i_bGraphicalDesign
);
230 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
232 if ( i_bGraphicalDesign
&& m_bAddTableDialogWasVisible
)
233 pAddTabDialog
->Show();
238 OQueryContainerWindow
* pContainer
= getContainer();
240 pContainer
->Resize();
242 m_pDesignView
->getController().ClearUndoManager();
243 m_pDesignView
->getController().InvalidateAll();
248 OAddTableDlg
* OQueryViewSwitch::getAddTableDialog()
250 if ( !m_pDesignView
)
252 return m_pDesignView
->getController().getAddTableDialog();
255 bool OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId
)
257 return m_pDesignView
->isSlotEnabled(_nSlotId
);
260 void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId
, bool _bEnable
)
262 m_pDesignView
->setSlotEnabled(_nSlotId
,_bEnable
);
265 void OQueryViewSwitch::SaveUIConfig()
267 if(m_pDesignView
->IsVisible())
268 m_pDesignView
->SaveUIConfig();
271 void OQueryViewSwitch::SetPosSizePixel( Point _rPt
,Size _rSize
)
273 m_pDesignView
->SetPosSizePixel( _rPt
,_rSize
);
274 m_pDesignView
->Resize();
275 m_pTextView
->SetPosSizePixel( _rPt
,_rSize
);
278 Reference
< XComponentContext
> OQueryViewSwitch::getORB() const
280 return m_pDesignView
->getORB();
283 bool OQueryViewSwitch::reset( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
285 m_pDesignView
->reset();
286 if ( !m_pDesignView
->initByParseIterator( _pErrorInfo
) )
289 if ( switchView( _pErrorInfo
) )
295 void OQueryViewSwitch::setNoneVisbleRow(sal_Int32 _nRows
)
298 m_pDesignView
->setNoneVisbleRow(_nRows
);
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */