xref: /trunk/main/dbaccess/source/ui/querydesign/QueryViewSwitch.cxx (revision b63233d868a9af170b0457a7aa0c5809011cc2c1)
196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir #ifndef DBAUI_QUERYVIEWSWITCH_HXX
27cdf0e10cSrcweir #include "QueryViewSwitch.hxx"
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #ifndef DBAUI_QUERYDESIGNVIEW_HXX
30cdf0e10cSrcweir #include "QueryDesignView.hxx"
31cdf0e10cSrcweir #endif
32cdf0e10cSrcweir #ifndef DBAUI_QUERYVIEW_TEXT_HXX
33cdf0e10cSrcweir #include "QueryTextView.hxx"
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir #ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
36cdf0e10cSrcweir #include "querycontainerwindow.hxx"
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #ifndef _DBU_QRY_HRC_
39cdf0e10cSrcweir #include "dbu_qry.hrc"
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
42cdf0e10cSrcweir #include "browserids.hxx"
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir #ifndef DBAUI_QYDLGTAB_HXX
45cdf0e10cSrcweir #include "adtabdlg.hxx"
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifndef DBAUI_QUERYCONTROLLER_HXX
48cdf0e10cSrcweir #include "querycontroller.hxx"
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifndef DBAUI_SQLEDIT_HXX
51cdf0e10cSrcweir #include "sqledit.hxx"
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir #ifndef DBAUI_QUERYCONTAINERWINDOW_HXX
54cdf0e10cSrcweir #include "querycontainerwindow.hxx"
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir 
57cdf0e10cSrcweir using namespace dbaui;
58cdf0e10cSrcweir using namespace ::com::sun::star::uno;
59cdf0e10cSrcweir using namespace ::com::sun::star::lang;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir DBG_NAME(OQueryViewSwitch)
62cdf0e10cSrcweir OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow* _pParent, OQueryController& _rController,const Reference< XMultiServiceFactory >& _rFactory)
63cdf0e10cSrcweir : m_bAddTableDialogWasVisible(sal_False)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     DBG_CTOR(OQueryViewSwitch,NULL);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     m_pTextView     = new OQueryTextView(_pParent);
68cdf0e10cSrcweir     m_pDesignView   = new OQueryDesignView( _pParent, _rController, _rFactory );
69cdf0e10cSrcweir }
70cdf0e10cSrcweir // -----------------------------------------------------------------------------
71cdf0e10cSrcweir OQueryViewSwitch::~OQueryViewSwitch()
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     DBG_DTOR(OQueryViewSwitch,NULL);
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         ::std::auto_ptr<Window> aTemp(m_pTextView);
76cdf0e10cSrcweir         m_pTextView = NULL;
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         ::std::auto_ptr<Window> aTemp(m_pDesignView);
80cdf0e10cSrcweir         m_pDesignView = NULL;
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir // -------------------------------------------------------------------------
84cdf0e10cSrcweir void OQueryViewSwitch::Construct()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     m_pDesignView->Construct( );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir // -----------------------------------------------------------------------------
89cdf0e10cSrcweir void OQueryViewSwitch::initialize()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     // initially be in SQL mode
92cdf0e10cSrcweir     m_pTextView->Show();
93cdf0e10cSrcweir     m_pDesignView->initialize();
94cdf0e10cSrcweir }
95cdf0e10cSrcweir // -------------------------------------------------------------------------
96cdf0e10cSrcweir void OQueryViewSwitch::resizeDocumentView(Rectangle& _rPlayground)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     m_pTextView->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
99cdf0e10cSrcweir     m_pDesignView->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     // just for completeness: there is no space left, we occupied it all ...
102cdf0e10cSrcweir     _rPlayground.SetPos( _rPlayground.BottomRight() );
103cdf0e10cSrcweir     _rPlayground.SetSize( Size( 0, 0 ) );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir // -----------------------------------------------------------------------------
106cdf0e10cSrcweir sal_Bool OQueryViewSwitch::checkStatement()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir     if(m_pTextView->IsVisible())
109cdf0e10cSrcweir         return m_pTextView->checkStatement();
110cdf0e10cSrcweir     return m_pDesignView->checkStatement();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir // -----------------------------------------------------------------------------
113cdf0e10cSrcweir ::rtl::OUString OQueryViewSwitch::getStatement()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     if(m_pTextView->IsVisible())
116cdf0e10cSrcweir         return m_pTextView->getStatement();
117cdf0e10cSrcweir     return m_pDesignView->getStatement();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir // -----------------------------------------------------------------------------
120cdf0e10cSrcweir void OQueryViewSwitch::setReadOnly(sal_Bool _bReadOnly)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     if(m_pTextView->IsVisible())
123cdf0e10cSrcweir         m_pTextView->setReadOnly(_bReadOnly);
124cdf0e10cSrcweir     else
125cdf0e10cSrcweir         m_pDesignView->setReadOnly(_bReadOnly);
126cdf0e10cSrcweir }
127cdf0e10cSrcweir // -----------------------------------------------------------------------------
128cdf0e10cSrcweir void OQueryViewSwitch::clear()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     if(m_pTextView->IsVisible())
131cdf0e10cSrcweir         m_pTextView->clear();
132cdf0e10cSrcweir     else
133cdf0e10cSrcweir         m_pDesignView->clear();
134cdf0e10cSrcweir }
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
136cdf0e10cSrcweir void OQueryViewSwitch::GrabFocus()
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     if ( m_pTextView && m_pTextView->IsVisible() )
139cdf0e10cSrcweir         m_pTextView->GrabFocus();
140cdf0e10cSrcweir     else if ( m_pDesignView && m_pDesignView->IsVisible() )
141cdf0e10cSrcweir         m_pDesignView->GrabFocus();
142cdf0e10cSrcweir }
143cdf0e10cSrcweir // -----------------------------------------------------------------------------
144cdf0e10cSrcweir void OQueryViewSwitch::setStatement(const ::rtl::OUString& _rsStatement)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     if(m_pTextView->IsVisible())
147cdf0e10cSrcweir         m_pTextView->setStatement(_rsStatement);
148cdf0e10cSrcweir     else
149cdf0e10cSrcweir         m_pDesignView->setStatement(_rsStatement);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir // -----------------------------------------------------------------------------
152cdf0e10cSrcweir void OQueryViewSwitch::copy()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     if(m_pTextView->IsVisible())
155cdf0e10cSrcweir         m_pTextView->copy();
156cdf0e10cSrcweir     else
157cdf0e10cSrcweir         m_pDesignView->copy();
158cdf0e10cSrcweir }
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
160cdf0e10cSrcweir sal_Bool OQueryViewSwitch::isCutAllowed()
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     if(m_pTextView->IsVisible())
163cdf0e10cSrcweir         return m_pTextView->isCutAllowed();
164cdf0e10cSrcweir     return m_pDesignView->isCutAllowed();
165cdf0e10cSrcweir }
166cdf0e10cSrcweir // -----------------------------------------------------------------------------
167cdf0e10cSrcweir sal_Bool OQueryViewSwitch::isCopyAllowed()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     if(m_pTextView->IsVisible())
170cdf0e10cSrcweir         return m_pTextView->isCopyAllowed();
171cdf0e10cSrcweir     return m_pDesignView->isCopyAllowed();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir // -----------------------------------------------------------------------------
174cdf0e10cSrcweir sal_Bool OQueryViewSwitch::isPasteAllowed()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     if(m_pTextView->IsVisible())
177cdf0e10cSrcweir         return m_pTextView->isPasteAllowed();
178cdf0e10cSrcweir     return m_pDesignView->isPasteAllowed();
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // -----------------------------------------------------------------------------
181cdf0e10cSrcweir void OQueryViewSwitch::cut()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     if(m_pTextView->IsVisible())
184cdf0e10cSrcweir         m_pTextView->cut();
185cdf0e10cSrcweir     else
186cdf0e10cSrcweir         m_pDesignView->cut();
187cdf0e10cSrcweir }
188cdf0e10cSrcweir // -----------------------------------------------------------------------------
189cdf0e10cSrcweir void OQueryViewSwitch::paste()
190cdf0e10cSrcweir {
191cdf0e10cSrcweir     if(m_pTextView->IsVisible())
192cdf0e10cSrcweir         m_pTextView->paste();
193cdf0e10cSrcweir     else
194cdf0e10cSrcweir         m_pDesignView->paste();
195cdf0e10cSrcweir }
196cdf0e10cSrcweir // -----------------------------------------------------------------------------
197cdf0e10cSrcweir OQueryContainerWindow* OQueryViewSwitch::getContainer() const
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     Window* pDesignParent = getDesignView() ? getDesignView()->GetParent() : NULL;
200cdf0e10cSrcweir     return static_cast< OQueryContainerWindow* >( pDesignParent );
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir // -----------------------------------------------------------------------------
204cdf0e10cSrcweir void OQueryViewSwitch::impl_forceSQLView()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     OAddTableDlg* pAddTabDialog( getAddTableDialog() );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     // hide the "Add Table" dialog
209cdf0e10cSrcweir     m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false;
210cdf0e10cSrcweir     if ( m_bAddTableDialogWasVisible )
211cdf0e10cSrcweir         pAddTabDialog->Hide();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     // tell the views they're in/active
214cdf0e10cSrcweir     m_pDesignView->stopTimer();
215cdf0e10cSrcweir     m_pTextView->getSqlEdit()->startTimer();
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     // set the most recent statement at the text view
218cdf0e10cSrcweir     m_pTextView->clear();
219cdf0e10cSrcweir     m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement());
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir // -----------------------------------------------------------------------------
223cdf0e10cSrcweir void OQueryViewSwitch::forceInitialView()
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     OQueryController& rQueryController( static_cast< OQueryController& >( m_pDesignView->getController() ) );
226cdf0e10cSrcweir     const sal_Bool bGraphicalDesign = rQueryController.isGraphicalDesign();
227cdf0e10cSrcweir     if ( !bGraphicalDesign )
228cdf0e10cSrcweir         impl_forceSQLView();
229cdf0e10cSrcweir     else
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir         // tell the text view it's inactive now
232cdf0e10cSrcweir         m_pTextView->getSqlEdit()->stopTimer();
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         // update the "Add Table" dialog
235cdf0e10cSrcweir         OAddTableDlg* pAddTabDialog( getAddTableDialog() );
236cdf0e10cSrcweir         if ( pAddTabDialog )
237cdf0e10cSrcweir             pAddTabDialog->Update();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         // initialize the design view
240cdf0e10cSrcweir         m_pDesignView->initByFieldDescriptions( rQueryController.getFieldInformation() );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         // tell the design view it's active now
243cdf0e10cSrcweir         m_pDesignView->startTimer();
244cdf0e10cSrcweir     }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     impl_postViewSwitch( bGraphicalDesign, true );
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249cdf0e10cSrcweir // -----------------------------------------------------------------------------
250cdf0e10cSrcweir bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     sal_Bool bRet = sal_True;
253cdf0e10cSrcweir     sal_Bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign();
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     if ( !bGraphicalDesign )
256cdf0e10cSrcweir     {
257cdf0e10cSrcweir         impl_forceSQLView();
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir     else
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         // tell the text view it's inactive now
262cdf0e10cSrcweir         m_pTextView->getSqlEdit()->stopTimer();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         // update the "Add Table" dialog
265cdf0e10cSrcweir         OAddTableDlg* pAddTabDialog( getAddTableDialog() );
266cdf0e10cSrcweir         if ( pAddTabDialog )
267cdf0e10cSrcweir             pAddTabDialog->Update();
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         // initialize the design view
270cdf0e10cSrcweir         bRet = m_pDesignView->initByParseIterator( _pErrorInfo );
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         // tell the design view it's active now
273cdf0e10cSrcweir         m_pDesignView->startTimer();
274cdf0e10cSrcweir     }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     return impl_postViewSwitch( bGraphicalDesign, bRet );
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir // -----------------------------------------------------------------------------
280cdf0e10cSrcweir bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir     if ( i_bSuccess )
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir         m_pTextView->Show   ( !i_bGraphicalDesign );
285cdf0e10cSrcweir         m_pDesignView->Show ( i_bGraphicalDesign );
286cdf0e10cSrcweir         OAddTableDlg* pAddTabDialog( getAddTableDialog() );
287cdf0e10cSrcweir         if ( pAddTabDialog )
288cdf0e10cSrcweir             if ( i_bGraphicalDesign && m_bAddTableDialogWasVisible )
289cdf0e10cSrcweir                 pAddTabDialog->Show();
290cdf0e10cSrcweir 
291cdf0e10cSrcweir         GrabFocus();
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     OQueryContainerWindow* pContainer = getContainer();
295cdf0e10cSrcweir     if ( pContainer )
296cdf0e10cSrcweir         pContainer->Resize();
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     m_pDesignView->getController().ClearUndoManager();
299cdf0e10cSrcweir     m_pDesignView->getController().InvalidateAll();
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     return i_bSuccess;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir // -----------------------------------------------------------------------------
305cdf0e10cSrcweir OAddTableDlg* OQueryViewSwitch::getAddTableDialog()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir     if ( !m_pDesignView )
308cdf0e10cSrcweir         return NULL;
309cdf0e10cSrcweir     return m_pDesignView->getController().getAddTableDialog();
310cdf0e10cSrcweir }
311cdf0e10cSrcweir // -----------------------------------------------------------------------------
312cdf0e10cSrcweir sal_Bool OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     return m_pDesignView->isSlotEnabled(_nSlotId);
315cdf0e10cSrcweir }
316cdf0e10cSrcweir // -----------------------------------------------------------------------------
317cdf0e10cSrcweir void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     m_pDesignView->setSlotEnabled(_nSlotId,_bEnable);
320cdf0e10cSrcweir }
321cdf0e10cSrcweir // -----------------------------------------------------------------------------
322cdf0e10cSrcweir void OQueryViewSwitch::SaveUIConfig()
323cdf0e10cSrcweir {
324cdf0e10cSrcweir     if(m_pDesignView->IsVisible())
325cdf0e10cSrcweir         m_pDesignView->SaveUIConfig();
326cdf0e10cSrcweir }
327cdf0e10cSrcweir // -----------------------------------------------------------------------------
328cdf0e10cSrcweir void OQueryViewSwitch::SetPosSizePixel( Point _rPt,Size _rSize)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     m_pDesignView->SetPosSizePixel( _rPt,_rSize);
331cdf0e10cSrcweir     m_pDesignView->Resize();
332cdf0e10cSrcweir     m_pTextView->SetPosSizePixel( _rPt,_rSize);
333cdf0e10cSrcweir }
334cdf0e10cSrcweir // -----------------------------------------------------------------------------
335cdf0e10cSrcweir Reference< XMultiServiceFactory > OQueryViewSwitch::getORB() const
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     return m_pDesignView->getORB();
338cdf0e10cSrcweir }
339cdf0e10cSrcweir // -----------------------------------------------------------------------------
340cdf0e10cSrcweir bool OQueryViewSwitch::reset( ::dbtools::SQLExceptionInfo* _pErrorInfo )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir     m_pDesignView->reset();
343cdf0e10cSrcweir     if ( !m_pDesignView->initByParseIterator( _pErrorInfo ) )
344cdf0e10cSrcweir         return false;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     if ( switchView( _pErrorInfo ) )
347cdf0e10cSrcweir         return false;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     return true;
350cdf0e10cSrcweir }
351cdf0e10cSrcweir // -----------------------------------------------------------------------------
352cdf0e10cSrcweir void OQueryViewSwitch::setNoneVisbleRow(sal_Int32 _nRows)
353cdf0e10cSrcweir {
354cdf0e10cSrcweir     if(m_pDesignView)
355cdf0e10cSrcweir         m_pDesignView->setNoneVisbleRow(_nRows);
356cdf0e10cSrcweir }
357cdf0e10cSrcweir // -----------------------------------------------------------------------------
358