Branch data Line data Source code
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"
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 : :
30 : : using namespace dbaui;
31 : : using namespace ::com::sun::star::uno;
32 : : using namespace ::com::sun::star::lang;
33 : :
34 : : DBG_NAME(OQueryViewSwitch)
35 : 0 : OQueryViewSwitch::OQueryViewSwitch(OQueryContainerWindow* _pParent, OQueryController& _rController,const Reference< XMultiServiceFactory >& _rFactory)
36 : 0 : : m_bAddTableDialogWasVisible(sal_False)
37 : : {
38 : : DBG_CTOR(OQueryViewSwitch,NULL);
39 : :
40 [ # # ]: 0 : m_pTextView = new OQueryTextView(_pParent);
41 [ # # ]: 0 : m_pDesignView = new OQueryDesignView( _pParent, _rController, _rFactory );
42 : 0 : }
43 : : // -----------------------------------------------------------------------------
44 : 0 : OQueryViewSwitch::~OQueryViewSwitch()
45 : : {
46 : : DBG_DTOR(OQueryViewSwitch,NULL);
47 : : {
48 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
49 : 0 : ::std::auto_ptr<Window> aTemp(m_pTextView);
50 : : SAL_WNODEPRECATED_DECLARATIONS_POP
51 [ # # ]: 0 : m_pTextView = NULL;
52 : : }
53 : : {
54 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
55 : 0 : ::std::auto_ptr<Window> aTemp(m_pDesignView);
56 : : SAL_WNODEPRECATED_DECLARATIONS_POP
57 [ # # ]: 0 : m_pDesignView = NULL;
58 : : }
59 [ # # ]: 0 : }
60 : : // -------------------------------------------------------------------------
61 : 0 : void OQueryViewSwitch::Construct()
62 : : {
63 : 0 : m_pDesignView->Construct( );
64 : 0 : }
65 : : // -----------------------------------------------------------------------------
66 : 0 : void OQueryViewSwitch::initialize()
67 : : {
68 : : // initially be in SQL mode
69 : 0 : m_pTextView->Show();
70 : 0 : m_pDesignView->initialize();
71 : 0 : }
72 : : // -------------------------------------------------------------------------
73 : 0 : void OQueryViewSwitch::resizeDocumentView(Rectangle& _rPlayground)
74 : : {
75 [ # # ]: 0 : m_pTextView->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
76 [ # # ]: 0 : m_pDesignView->SetPosSizePixel( _rPlayground.TopLeft(), _rPlayground.GetSize() );
77 : :
78 : : // just for completeness: there is no space left, we occupied it all ...
79 : 0 : _rPlayground.SetPos( _rPlayground.BottomRight() );
80 [ # # ]: 0 : _rPlayground.SetSize( Size( 0, 0 ) );
81 : 0 : }
82 : : // -----------------------------------------------------------------------------
83 : 0 : sal_Bool OQueryViewSwitch::checkStatement()
84 : : {
85 [ # # ]: 0 : if(m_pTextView->IsVisible())
86 : 0 : return m_pTextView->checkStatement();
87 : 0 : return m_pDesignView->checkStatement();
88 : : }
89 : : // -----------------------------------------------------------------------------
90 : 0 : ::rtl::OUString OQueryViewSwitch::getStatement()
91 : : {
92 [ # # ]: 0 : if(m_pTextView->IsVisible())
93 : 0 : return m_pTextView->getStatement();
94 : 0 : return m_pDesignView->getStatement();
95 : : }
96 : : // -----------------------------------------------------------------------------
97 : 0 : void OQueryViewSwitch::setReadOnly(sal_Bool _bReadOnly)
98 : : {
99 [ # # ]: 0 : if(m_pTextView->IsVisible())
100 : 0 : m_pTextView->setReadOnly(_bReadOnly);
101 : : else
102 : 0 : m_pDesignView->setReadOnly(_bReadOnly);
103 : 0 : }
104 : : // -----------------------------------------------------------------------------
105 : 0 : void OQueryViewSwitch::clear()
106 : : {
107 [ # # ]: 0 : if(m_pTextView->IsVisible())
108 : 0 : m_pTextView->clear();
109 : : else
110 : 0 : m_pDesignView->clear();
111 : 0 : }
112 : : // -----------------------------------------------------------------------------
113 : 0 : void OQueryViewSwitch::GrabFocus()
114 : : {
115 [ # # ][ # # ]: 0 : if ( m_pTextView && m_pTextView->IsVisible() )
[ # # ]
116 : 0 : m_pTextView->GrabFocus();
117 [ # # ][ # # ]: 0 : else if ( m_pDesignView && m_pDesignView->IsVisible() )
[ # # ]
118 : 0 : m_pDesignView->GrabFocus();
119 : 0 : }
120 : : // -----------------------------------------------------------------------------
121 : 0 : void OQueryViewSwitch::setStatement(const ::rtl::OUString& _rsStatement)
122 : : {
123 [ # # ]: 0 : if(m_pTextView->IsVisible())
124 : 0 : m_pTextView->setStatement(_rsStatement);
125 : : else
126 : 0 : m_pDesignView->setStatement(_rsStatement);
127 : 0 : }
128 : : // -----------------------------------------------------------------------------
129 : 0 : void OQueryViewSwitch::copy()
130 : : {
131 [ # # ]: 0 : if(m_pTextView->IsVisible())
132 : 0 : m_pTextView->copy();
133 : : else
134 : 0 : m_pDesignView->copy();
135 : 0 : }
136 : : // -----------------------------------------------------------------------------
137 : 0 : sal_Bool OQueryViewSwitch::isCutAllowed()
138 : : {
139 [ # # ]: 0 : if(m_pTextView->IsVisible())
140 : 0 : return m_pTextView->isCutAllowed();
141 : 0 : return m_pDesignView->isCutAllowed();
142 : : }
143 : : // -----------------------------------------------------------------------------
144 : 0 : sal_Bool OQueryViewSwitch::isCopyAllowed()
145 : : {
146 [ # # ]: 0 : if(m_pTextView->IsVisible())
147 : 0 : return m_pTextView->isCopyAllowed();
148 : 0 : return m_pDesignView->isCopyAllowed();
149 : : }
150 : : // -----------------------------------------------------------------------------
151 : 0 : sal_Bool OQueryViewSwitch::isPasteAllowed()
152 : : {
153 [ # # ]: 0 : if(m_pTextView->IsVisible())
154 : 0 : return m_pTextView->isPasteAllowed();
155 : 0 : return m_pDesignView->isPasteAllowed();
156 : : }
157 : : // -----------------------------------------------------------------------------
158 : 0 : void OQueryViewSwitch::cut()
159 : : {
160 [ # # ]: 0 : if(m_pTextView->IsVisible())
161 : 0 : m_pTextView->cut();
162 : : else
163 : 0 : m_pDesignView->cut();
164 : 0 : }
165 : : // -----------------------------------------------------------------------------
166 : 0 : void OQueryViewSwitch::paste()
167 : : {
168 [ # # ]: 0 : if(m_pTextView->IsVisible())
169 : 0 : m_pTextView->paste();
170 : : else
171 : 0 : m_pDesignView->paste();
172 : 0 : }
173 : : // -----------------------------------------------------------------------------
174 : 0 : OQueryContainerWindow* OQueryViewSwitch::getContainer() const
175 : : {
176 [ # # ]: 0 : Window* pDesignParent = getDesignView() ? getDesignView()->GetParent() : NULL;
177 : 0 : return static_cast< OQueryContainerWindow* >( pDesignParent );
178 : : }
179 : :
180 : : // -----------------------------------------------------------------------------
181 : 0 : void OQueryViewSwitch::impl_forceSQLView()
182 : : {
183 : 0 : OAddTableDlg* pAddTabDialog( getAddTableDialog() );
184 : :
185 : : // hide the "Add Table" dialog
186 [ # # ]: 0 : m_bAddTableDialogWasVisible = pAddTabDialog ? pAddTabDialog->IsVisible() : false;
187 [ # # ]: 0 : if ( m_bAddTableDialogWasVisible )
188 : 0 : pAddTabDialog->Hide();
189 : :
190 : : // tell the views they're in/active
191 : 0 : m_pDesignView->stopTimer();
192 : 0 : m_pTextView->getSqlEdit()->startTimer();
193 : :
194 : : // set the most recent statement at the text view
195 : 0 : m_pTextView->clear();
196 [ # # ]: 0 : m_pTextView->setStatement(static_cast<OQueryController&>(m_pDesignView->getController()).getStatement());
197 : 0 : }
198 : :
199 : : // -----------------------------------------------------------------------------
200 : 0 : void OQueryViewSwitch::forceInitialView()
201 : : {
202 : 0 : OQueryController& rQueryController( static_cast< OQueryController& >( m_pDesignView->getController() ) );
203 : 0 : const sal_Bool bGraphicalDesign = rQueryController.isGraphicalDesign();
204 [ # # ]: 0 : if ( !bGraphicalDesign )
205 : 0 : impl_forceSQLView();
206 : : else
207 : : {
208 : : // tell the text view it's inactive now
209 : 0 : m_pTextView->getSqlEdit()->stopTimer();
210 : :
211 : : // update the "Add Table" dialog
212 : 0 : OAddTableDlg* pAddTabDialog( getAddTableDialog() );
213 [ # # ]: 0 : if ( pAddTabDialog )
214 : 0 : pAddTabDialog->Update();
215 : :
216 : : // initialize the design view
217 : 0 : m_pDesignView->initByFieldDescriptions( rQueryController.getFieldInformation() );
218 : :
219 : : // tell the design view it's active now
220 : 0 : m_pDesignView->startTimer();
221 : : }
222 : :
223 : 0 : impl_postViewSwitch( bGraphicalDesign, true );
224 : 0 : }
225 : :
226 : : // -----------------------------------------------------------------------------
227 : 0 : bool OQueryViewSwitch::switchView( ::dbtools::SQLExceptionInfo* _pErrorInfo )
228 : : {
229 : 0 : sal_Bool bRet = sal_True;
230 : 0 : sal_Bool bGraphicalDesign = static_cast<OQueryController&>(m_pDesignView->getController()).isGraphicalDesign();
231 : :
232 [ # # ]: 0 : if ( !bGraphicalDesign )
233 : : {
234 : 0 : impl_forceSQLView();
235 : : }
236 : : else
237 : : {
238 : : // tell the text view it's inactive now
239 : 0 : m_pTextView->getSqlEdit()->stopTimer();
240 : :
241 : : // update the "Add Table" dialog
242 : 0 : OAddTableDlg* pAddTabDialog( getAddTableDialog() );
243 [ # # ]: 0 : if ( pAddTabDialog )
244 : 0 : pAddTabDialog->Update();
245 : :
246 : : // initialize the design view
247 : 0 : bRet = m_pDesignView->initByParseIterator( _pErrorInfo );
248 : :
249 : : // tell the design view it's active now
250 : 0 : m_pDesignView->startTimer();
251 : : }
252 : :
253 : 0 : return impl_postViewSwitch( bGraphicalDesign, bRet );
254 : : }
255 : :
256 : : // -----------------------------------------------------------------------------
257 : 0 : bool OQueryViewSwitch::impl_postViewSwitch( const bool i_bGraphicalDesign, const bool i_bSuccess )
258 : : {
259 [ # # ]: 0 : if ( i_bSuccess )
260 : : {
261 : 0 : m_pTextView->Show ( !i_bGraphicalDesign );
262 : 0 : m_pDesignView->Show ( i_bGraphicalDesign );
263 : 0 : OAddTableDlg* pAddTabDialog( getAddTableDialog() );
264 [ # # ]: 0 : if ( pAddTabDialog )
265 [ # # ][ # # ]: 0 : if ( i_bGraphicalDesign && m_bAddTableDialogWasVisible )
266 : 0 : pAddTabDialog->Show();
267 : :
268 : 0 : GrabFocus();
269 : : }
270 : :
271 : 0 : OQueryContainerWindow* pContainer = getContainer();
272 [ # # ]: 0 : if ( pContainer )
273 : 0 : pContainer->Resize();
274 : :
275 : 0 : m_pDesignView->getController().ClearUndoManager();
276 : 0 : m_pDesignView->getController().InvalidateAll();
277 : :
278 : 0 : return i_bSuccess;
279 : : }
280 : :
281 : : // -----------------------------------------------------------------------------
282 : 0 : OAddTableDlg* OQueryViewSwitch::getAddTableDialog()
283 : : {
284 [ # # ]: 0 : if ( !m_pDesignView )
285 : 0 : return NULL;
286 : 0 : return m_pDesignView->getController().getAddTableDialog();
287 : : }
288 : : // -----------------------------------------------------------------------------
289 : 0 : sal_Bool OQueryViewSwitch::isSlotEnabled(sal_Int32 _nSlotId)
290 : : {
291 : 0 : return m_pDesignView->isSlotEnabled(_nSlotId);
292 : : }
293 : : // -----------------------------------------------------------------------------
294 : 0 : void OQueryViewSwitch::setSlotEnabled(sal_Int32 _nSlotId,sal_Bool _bEnable)
295 : : {
296 : 0 : m_pDesignView->setSlotEnabled(_nSlotId,_bEnable);
297 : 0 : }
298 : : // -----------------------------------------------------------------------------
299 : 0 : void OQueryViewSwitch::SaveUIConfig()
300 : : {
301 [ # # ]: 0 : if(m_pDesignView->IsVisible())
302 : 0 : m_pDesignView->SaveUIConfig();
303 : 0 : }
304 : : // -----------------------------------------------------------------------------
305 : 0 : void OQueryViewSwitch::SetPosSizePixel( Point _rPt,Size _rSize)
306 : : {
307 : 0 : m_pDesignView->SetPosSizePixel( _rPt,_rSize);
308 : 0 : m_pDesignView->Resize();
309 : 0 : m_pTextView->SetPosSizePixel( _rPt,_rSize);
310 : 0 : }
311 : : // -----------------------------------------------------------------------------
312 : 0 : Reference< XMultiServiceFactory > OQueryViewSwitch::getORB() const
313 : : {
314 : 0 : return m_pDesignView->getORB();
315 : : }
316 : : // -----------------------------------------------------------------------------
317 : 0 : bool OQueryViewSwitch::reset( ::dbtools::SQLExceptionInfo* _pErrorInfo )
318 : : {
319 : 0 : m_pDesignView->reset();
320 [ # # ]: 0 : if ( !m_pDesignView->initByParseIterator( _pErrorInfo ) )
321 : 0 : return false;
322 : :
323 [ # # ]: 0 : if ( switchView( _pErrorInfo ) )
324 : 0 : return false;
325 : :
326 : 0 : return true;
327 : : }
328 : : // -----------------------------------------------------------------------------
329 : 0 : void OQueryViewSwitch::setNoneVisbleRow(sal_Int32 _nRows)
330 : : {
331 [ # # ]: 0 : if(m_pDesignView)
332 : 0 : m_pDesignView->setNoneVisbleRow(_nRows);
333 : 0 : }
334 : : // -----------------------------------------------------------------------------
335 : :
336 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|