1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: QueryViewSwitch.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBAUI_QUERYVIEWSWITCH_HXX
34 #include "QueryViewSwitch.hxx"
36 #ifndef DBAUI_QUERYDESIGNVIEW_HXX
37 #include "QueryDesignView.hxx"
39 #ifndef DBAUI_QUERYVIEW_TEXT_HXX
40 #include "QueryTextView.hxx"
42 #ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
43 #include "querycontainerwindow.hxx"
46 #include "dbu_qry.hrc"
48 #ifndef DBACCESS_UI_BROWSER_ID_HXX
49 #include "browserids.hxx"
51 #ifndef DBAUI_QYDLGTAB_HXX
52 #include "adtabdlg.hxx"
54 #ifndef DBAUI_QUERYCONTROLLER_HXX
55 #include "querycontroller.hxx"
57 #ifndef DBAUI_SQLEDIT_HXX
58 #include "sqledit.hxx"
60 #ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
61 #include "querycontainerwindow.hxx"
64 using namespace dbaui
;
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::lang
;
68 DBG_NAME(OQueryViewSwitch
)
69 OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow
* _pParent
, OQueryController
& _rController
,const Reference
< XMultiServiceFactory
>& _rFactory
)
70 : m_bAddTableDialogWasVisible(sal_False
)
72 DBG_CTOR(OQueryViewSwitch
,NULL
);
74 m_pTextView
= new OQueryTextView(_pParent
);
75 m_pDesignView
= new OQueryDesignView( _pParent
, _rController
, _rFactory
);
77 // -----------------------------------------------------------------------------
78 OQueryViewSwitch::~OQueryViewSwitch()
80 DBG_DTOR(OQueryViewSwitch
,NULL
);
82 ::std::auto_ptr
<Window
> aTemp(m_pTextView
);
86 ::std::auto_ptr
<Window
> aTemp(m_pDesignView
);
90 // -------------------------------------------------------------------------
91 void OQueryViewSwitch::Construct()
93 m_pDesignView
->Construct( );
95 // -----------------------------------------------------------------------------
96 void OQueryViewSwitch::initialize()
98 // initially be in SQL mode
100 m_pDesignView
->initialize();
102 // -------------------------------------------------------------------------
103 void OQueryViewSwitch::resizeDocumentView(Rectangle
& _rPlayground
)
105 m_pTextView
->SetPosSizePixel( _rPlayground
.TopLeft(), _rPlayground
.GetSize() );
106 m_pDesignView
->SetPosSizePixel( _rPlayground
.TopLeft(), _rPlayground
.GetSize() );
108 // just for completeness: there is no space left, we occupied it all ...
109 _rPlayground
.SetPos( _rPlayground
.BottomRight() );
110 _rPlayground
.SetSize( Size( 0, 0 ) );
112 // -----------------------------------------------------------------------------
113 sal_Bool
OQueryViewSwitch::checkStatement()
115 if(m_pTextView
->IsVisible())
116 return m_pTextView
->checkStatement();
117 return m_pDesignView
->checkStatement();
119 // -----------------------------------------------------------------------------
120 ::rtl::OUString
OQueryViewSwitch::getStatement()
122 if(m_pTextView
->IsVisible())
123 return m_pTextView
->getStatement();
124 return m_pDesignView
->getStatement();
126 // -----------------------------------------------------------------------------
127 void OQueryViewSwitch::setReadOnly(sal_Bool _bReadOnly
)
129 if(m_pTextView
->IsVisible())
130 m_pTextView
->setReadOnly(_bReadOnly
);
132 m_pDesignView
->setReadOnly(_bReadOnly
);
134 // -----------------------------------------------------------------------------
135 void OQueryViewSwitch::clear()
137 if(m_pTextView
->IsVisible())
138 m_pTextView
->clear();
140 m_pDesignView
->clear();
142 // -----------------------------------------------------------------------------
143 void OQueryViewSwitch::GrabFocus()
145 if ( m_pTextView
&& m_pTextView
->IsVisible() )
146 m_pTextView
->GrabFocus();
147 else if ( m_pDesignView
&& m_pDesignView
->IsVisible() )
148 m_pDesignView
->GrabFocus();
150 // -----------------------------------------------------------------------------
151 void OQueryViewSwitch::setStatement(const ::rtl::OUString
& _rsStatement
)
153 if(m_pTextView
->IsVisible())
154 m_pTextView
->setStatement(_rsStatement
);
156 m_pDesignView
->setStatement(_rsStatement
);
158 // -----------------------------------------------------------------------------
159 void OQueryViewSwitch::copy()
161 if(m_pTextView
->IsVisible())
164 m_pDesignView
->copy();
166 // -----------------------------------------------------------------------------
167 sal_Bool
OQueryViewSwitch::isCutAllowed()
169 if(m_pTextView
->IsVisible())
170 return m_pTextView
->isCutAllowed();
171 return m_pDesignView
->isCutAllowed();
173 // -----------------------------------------------------------------------------
174 sal_Bool
OQueryViewSwitch::isCopyAllowed()
176 if(m_pTextView
->IsVisible())
177 return m_pTextView
->isCopyAllowed();
178 return m_pDesignView
->isCopyAllowed();
180 // -----------------------------------------------------------------------------
181 sal_Bool
OQueryViewSwitch::isPasteAllowed()
183 if(m_pTextView
->IsVisible())
184 return m_pTextView
->isPasteAllowed();
185 return m_pDesignView
->isPasteAllowed();
187 // -----------------------------------------------------------------------------
188 void OQueryViewSwitch::cut()
190 if(m_pTextView
->IsVisible())
193 m_pDesignView
->cut();
195 // -----------------------------------------------------------------------------
196 void OQueryViewSwitch::paste()
198 if(m_pTextView
->IsVisible())
199 m_pTextView
->paste();
201 m_pDesignView
->paste();
203 // -----------------------------------------------------------------------------
204 OQueryContainerWindow
* OQueryViewSwitch::getContainer() const
206 Window
* pDesignParent
= getDesignView() ? getDesignView()->GetParent() : NULL
;
207 return static_cast< OQueryContainerWindow
* >( pDesignParent
);
210 // -----------------------------------------------------------------------------
211 bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
213 sal_Bool bRet
= sal_True
;
214 sal_Bool bGraphicalDesign
= static_cast<OQueryController
&>(m_pDesignView
->getController()).isGraphicalDesign();
216 OAddTableDlg
* pAddTabDialog( getAddTableDialog() );
218 OQueryContainerWindow
* pContainer
= getContainer();
219 if ( !bGraphicalDesign
)
221 // hide the "Add Table" dialog
222 m_bAddTableDialogWasVisible
= pAddTabDialog
? pAddTabDialog
->IsVisible() : false;
223 if ( m_bAddTableDialogWasVisible
)
224 pAddTabDialog
->Hide();
226 // tell the views they're in/active
227 m_pDesignView
->stopTimer();
228 m_pTextView
->getSqlEdit()->startTimer();
230 // set the most recent statement at the text view
231 m_pTextView
->clear();
232 m_pTextView
->setStatement(static_cast<OQueryController
&>(m_pDesignView
->getController()).getStatement());
236 // tell the text view it's inactive now
237 m_pTextView
->getSqlEdit()->stopTimer();
239 ::rtl::OUString sOldStatement
= static_cast<OQueryController
&>(m_pDesignView
->getController()).getStatement();
241 // update the "Add Table" dialog
243 pAddTabDialog
->Update();
245 // initialize the design view
246 bRet
= m_pDesignView
->initByParseIterator( _pErrorInfo
);
248 // tell the design view it's active now
249 m_pDesignView
->startTimer();
254 m_pTextView
->Show ( !bGraphicalDesign
);
255 m_pDesignView
->Show ( bGraphicalDesign
);
256 if ( bGraphicalDesign
&& m_bAddTableDialogWasVisible
&& pAddTabDialog
)
257 pAddTabDialog
->Show();
263 pContainer
->Resize();
265 m_pDesignView
->getController().getUndoMgr()->Clear();
266 m_pDesignView
->getController().InvalidateAll();
270 // -----------------------------------------------------------------------------
271 OAddTableDlg
* OQueryViewSwitch::getAddTableDialog()
273 if ( !m_pDesignView
)
275 return m_pDesignView
->getController().getAddTableDialog();
277 // -----------------------------------------------------------------------------
278 sal_Bool
OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId
)
280 return m_pDesignView
->isSlotEnabled(_nSlotId
);
282 // -----------------------------------------------------------------------------
283 void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId
,sal_Bool _bEnable
)
285 m_pDesignView
->setSlotEnabled(_nSlotId
,_bEnable
);
287 // -----------------------------------------------------------------------------
288 void OQueryViewSwitch::SaveUIConfig()
290 if(m_pDesignView
->IsVisible())
291 m_pDesignView
->SaveUIConfig();
293 // -----------------------------------------------------------------------------
294 void OQueryViewSwitch::SetPosSizePixel( Point _rPt
,Size _rSize
)
296 m_pDesignView
->SetPosSizePixel( _rPt
,_rSize
);
297 m_pDesignView
->Resize();
298 m_pTextView
->SetPosSizePixel( _rPt
,_rSize
);
300 // -----------------------------------------------------------------------------
301 Reference
< XMultiServiceFactory
> OQueryViewSwitch::getORB() const
303 return m_pDesignView
->getORB();
305 // -----------------------------------------------------------------------------
306 bool OQueryViewSwitch::reset( ::dbtools::SQLExceptionInfo
* _pErrorInfo
)
308 m_pDesignView
->reset();
309 if ( !m_pDesignView
->initByParseIterator( _pErrorInfo
) )
312 if ( switchView( _pErrorInfo
) )
317 // -----------------------------------------------------------------------------
318 void OQueryViewSwitch::setNoneVisbleRow(sal_Int32 _nRows
)
321 m_pDesignView
->setNoneVisbleRow(_nRows
);
323 // -----------------------------------------------------------------------------