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 "AppDetailPageHelper.hxx"
21 : #include "moduledbu.hxx"
22 : #include <tools/debug.hxx>
23 : #include <tools/diagnose_ex.h>
24 : #include <connectivity/dbtools.hxx>
25 : #include "tabletree.hxx"
26 : #include "UITools.hxx"
27 : #include "dbtreelistbox.hxx"
28 : #include <com/sun/star/frame/XLayoutManager.hpp>
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/awt/XTabController.hpp>
31 : #include <com/sun/star/sdbc/XConnection.hpp>
32 : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
33 : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
34 : #include <com/sun/star/frame/XFrame.hpp>
35 : #include <com/sun/star/frame/FrameSearchFlag.hpp>
36 : #include <com/sun/star/frame/XComponentLoader.hpp>
37 : #include <com/sun/star/frame/XFrames.hpp>
38 : #include <com/sun/star/frame/XFramesSupplier.hpp>
39 : #include <com/sun/star/awt/XWindow.hpp>
40 : #include <toolkit/helper/vclunohelper.hxx>
41 : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
42 : #include <com/sun/star/ucb/XCommandProcessor.hpp>
43 : #include <com/sun/star/ucb/Command.hpp>
44 : #include <com/sun/star/form/XLoadable.hpp>
45 : #include <com/sun/star/container/XChild.hpp>
46 : #include <com/sun/star/container/XContainer.hpp>
47 : #include <com/sun/star/sdb/CommandType.hpp>
48 : #include <com/sun/star/util/XCloseable.hpp>
49 : #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
50 : #include <com/sun/star/sdb/application/DatabaseObject.hpp>
51 : #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
52 : #include "AppView.hxx"
53 : #include "dbaccess_helpid.hrc"
54 : #include "dbu_app.hrc"
55 : #include "callbacks.hxx"
56 : #include "IController.hxx"
57 : #include "dbustrings.hrc"
58 : #include "dbaccess_slotid.hrc"
59 : #include "databaseobjectview.hxx"
60 : #include "imageprovider.hxx"
61 : #include <vcl/waitobj.hxx>
62 : #include <tools/stream.hxx>
63 : #include <rtl/ustrbuf.hxx>
64 : #include "IApplicationController.hxx"
65 : #include "svtools/treelistentry.hxx"
66 :
67 : #include <com/sun/star/document/XDocumentProperties.hpp>
68 :
69 :
70 : using namespace ::dbaui;
71 : using namespace ::com::sun::star::container;
72 : using namespace ::com::sun::star::uno;
73 : using namespace ::com::sun::star::ucb;
74 : using namespace ::com::sun::star::frame;
75 : using namespace ::com::sun::star::form;
76 : using namespace ::com::sun::star::sdb;
77 : using namespace ::com::sun::star::sdb::application;
78 : using namespace ::com::sun::star::sdbc;
79 : using namespace ::com::sun::star::sdbcx;
80 : using namespace ::com::sun::star::beans;
81 : using namespace ::com::sun::star;
82 : using ::com::sun::star::awt::XTabController;
83 :
84 : namespace dbaui
85 : {
86 : namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
87 : namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
88 : }
89 :
90 : namespace
91 : {
92 0 : SvTreeListEntry* lcl_findEntry_impl(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvTreeListEntry* _pFirst)
93 : {
94 0 : SvTreeListEntry* pReturn = NULL;
95 0 : sal_Int32 nIndex = 0;
96 0 : String sName( _rName.getToken(0,'/',nIndex) );
97 :
98 0 : SvTreeListEntry* pEntry = _pFirst;
99 0 : while( pEntry )
100 : {
101 0 : if ( rTree.GetEntryText(pEntry) == sName )
102 : {
103 0 : if ( nIndex != -1 )
104 : {
105 0 : sName = _rName.getToken(0,'/',nIndex);
106 0 : pEntry = rTree.FirstChild(pEntry);
107 : }
108 : else
109 : {
110 0 : pReturn = pEntry;
111 0 : break;
112 : }
113 : }
114 : else
115 0 : pEntry = rTree.NextSibling(pEntry);
116 : }
117 0 : return pReturn;
118 : }
119 0 : SvTreeListEntry* lcl_findEntry(DBTreeListBox& rTree,const ::rtl::OUString& _rName,SvTreeListEntry* _pFirst)
120 : {
121 0 : sal_Int32 nIndex = 0;
122 0 : ::rtl::OUString sErase = _rName.getToken(0,'/',nIndex); // we don't want to have the "private:forms" part
123 0 : return (nIndex != -1 ? lcl_findEntry_impl(rTree,_rName.copy(sErase.getLength() + 1),_pFirst) : NULL);
124 : }
125 : //==================================================================
126 : // class OPreviewWindow
127 : //==================================================================
128 0 : class OTablePreviewWindow : public Window
129 : {
130 : DECL_LINK(OnDisableInput, void*);
131 : void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
132 : protected:
133 : virtual void DataChanged(const DataChangedEvent& rDCEvt);
134 : public:
135 : OTablePreviewWindow( Window* pParent, WinBits nStyle = 0 );
136 : virtual long Notify( NotifyEvent& rNEvt );
137 : };
138 : // -----------------------------------------------------------------------------
139 0 : OTablePreviewWindow::OTablePreviewWindow(Window* pParent, WinBits nStyle) : Window( pParent, nStyle)
140 : {
141 0 : ImplInitSettings( sal_True, sal_True, sal_True );
142 0 : }
143 : // -----------------------------------------------------------------------------
144 0 : long OTablePreviewWindow::Notify( NotifyEvent& rNEvt )
145 : {
146 0 : long nRet = Window::Notify( rNEvt );
147 0 : if ( rNEvt.GetType() == EVENT_INPUTENABLE && IsInputEnabled() )
148 0 : PostUserEvent( LINK( this, OTablePreviewWindow, OnDisableInput) );
149 0 : return nRet;
150 : }
151 : // -----------------------------------------------------------------------------
152 0 : IMPL_LINK_NOARG(OTablePreviewWindow, OnDisableInput)
153 : {
154 0 : EnableInput(sal_False);
155 0 : return 0L;
156 : }
157 : // -----------------------------------------------------------------------------
158 0 : void OTablePreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
159 : {
160 0 : Window::DataChanged( rDCEvt );
161 :
162 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
163 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
164 : {
165 0 : ImplInitSettings( sal_True, sal_True, sal_True );
166 0 : Invalidate();
167 : }
168 0 : }
169 : // -----------------------------------------------------------------------------
170 0 : void OTablePreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
171 : {
172 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
173 0 : if( bFont )
174 : {
175 0 : Font aFont;
176 0 : aFont = rStyleSettings.GetFieldFont();
177 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
178 0 : SetPointFont( aFont );
179 : }
180 :
181 0 : if( bForeground || bFont )
182 : {
183 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
184 0 : SetTextFillColor();
185 : }
186 :
187 0 : if( bBackground )
188 0 : SetBackground( rStyleSettings.GetFieldColor() );
189 0 : }
190 :
191 : }
192 : //==================================================================
193 : // class OAppDetailPageHelper
194 : DBG_NAME(OAppDetailPageHelper)
195 : //==================================================================
196 0 : OAppDetailPageHelper::OAppDetailPageHelper(Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode) : Window(_pParent,WB_DIALOGCONTROL)
197 : ,m_rBorderWin(_rBorderWin)
198 : ,m_aFL(this,WB_VERT)
199 : ,m_aTBPreview(this,WB_TABSTOP )
200 : ,m_aBorder(this,WB_BORDER | WB_READONLY)
201 : ,m_aPreview(&m_aBorder)
202 : ,m_aDocumentInfo(&m_aBorder,WB_LEFT | WB_VSCROLL | WB_READONLY )
203 : ,m_pTablePreview(NULL)
204 0 : ,m_ePreviewMode(_ePreviewMode)
205 : {
206 : DBG_CTOR(OAppDetailPageHelper,NULL);
207 :
208 0 : m_aBorder.SetBorderStyle(WINDOW_BORDER_MONO);
209 :
210 0 : m_aMenu.reset(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
211 :
212 0 : m_aTBPreview.SetOutStyle(TOOLBOX_STYLE_FLAT);
213 0 : m_aTBPreview.InsertItem(SID_DB_APP_DISABLE_PREVIEW,m_aMenu->GetItemText(SID_DB_APP_DISABLE_PREVIEW),TIB_LEFT|TIB_DROPDOWN|TIB_AUTOSIZE|TIB_RADIOCHECK);
214 0 : m_aTBPreview.SetHelpId(HID_APP_VIEW_PREVIEW_CB);
215 0 : m_aTBPreview.SetDropdownClickHdl( LINK( this, OAppDetailPageHelper, OnDropdownClickHdl ) );
216 0 : m_aTBPreview.EnableMenuStrings();
217 0 : m_aTBPreview.Enable(sal_True);
218 :
219 0 : m_aBorder.SetUniqueId(UID_APP_VIEW_PREVIEW_1);
220 :
221 0 : m_aPreview.SetHelpId(HID_APP_VIEW_PREVIEW_1);
222 :
223 0 : m_pTablePreview = new OTablePreviewWindow(&m_aBorder,WB_READONLY | WB_DIALOGCONTROL );
224 0 : m_pTablePreview->SetHelpId(HID_APP_VIEW_PREVIEW_2);
225 :
226 0 : m_aDocumentInfo.SetHelpId(HID_APP_VIEW_PREVIEW_3);
227 :
228 0 : m_xWindow = VCLUnoHelper::GetInterface( m_pTablePreview );
229 :
230 0 : SetUniqueId(UID_APP_DETAILPAGE_HELPER);
231 0 : for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
232 0 : m_pLists[i] = NULL;
233 0 : ImplInitSettings();
234 0 : }
235 : // -----------------------------------------------------------------------------
236 0 : OAppDetailPageHelper::~OAppDetailPageHelper()
237 : {
238 : try
239 : {
240 0 : Reference< ::util::XCloseable> xCloseable(m_xFrame,UNO_QUERY);
241 0 : if ( xCloseable.is() )
242 0 : xCloseable->close(sal_True);
243 : }
244 0 : catch(const Exception&)
245 : {
246 : OSL_FAIL("Exception thrown while disposing preview frame!");
247 : }
248 :
249 0 : for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
250 : {
251 0 : if ( m_pLists[i] )
252 : {
253 0 : m_pLists[i]->clearCurrentSelection();
254 0 : m_pLists[i]->Hide();
255 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
256 0 : ::std::auto_ptr<DBTreeListBox> aTemp(m_pLists[i]);
257 : SAL_WNODEPRECATED_DECLARATIONS_POP
258 0 : m_pLists[i]->clearCurrentSelection(); // why a second time?
259 0 : m_pLists[i] = NULL;
260 : }
261 :
262 : }
263 :
264 : DBG_DTOR(OAppDetailPageHelper,NULL);
265 0 : }
266 : // -----------------------------------------------------------------------------
267 0 : int OAppDetailPageHelper::getVisibleControlIndex() const
268 : {
269 0 : int i = 0;
270 0 : for (; i < E_ELEMENT_TYPE_COUNT ; ++i)
271 : {
272 0 : if ( m_pLists[i] && m_pLists[i]->IsVisible() )
273 0 : break;
274 : }
275 0 : return i;
276 : }
277 : // -----------------------------------------------------------------------------
278 0 : void OAppDetailPageHelper::selectAll()
279 : {
280 0 : int nPos = getVisibleControlIndex();
281 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
282 : {
283 0 : m_pLists[nPos]->SelectAll(sal_True);
284 : }
285 0 : }
286 : // -----------------------------------------------------------------------------
287 0 : void OAppDetailPageHelper::sort(int _nPos,SvSortMode _eSortMode )
288 : {
289 : OSL_ENSURE(m_pLists[_nPos],"List can not be NULL! ->GPF");
290 0 : SvTreeList* pModel = m_pLists[_nPos]->GetModel();
291 0 : SvSortMode eOldSortMode = pModel->GetSortMode();
292 0 : pModel->SetSortMode(_eSortMode);
293 0 : if ( eOldSortMode != _eSortMode )
294 0 : pModel->Resort();
295 0 : }
296 : // -----------------------------------------------------------------------------
297 0 : sal_Bool OAppDetailPageHelper::isSortUp() const
298 : {
299 0 : SvSortMode eSortMode = SortNone;
300 0 : int nPos = getVisibleControlIndex();
301 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
302 : {
303 0 : SvTreeList* pModel = m_pLists[nPos]->GetModel();
304 0 : eSortMode = pModel->GetSortMode();
305 : }
306 0 : return eSortMode == SortAscending;
307 : }
308 : // -----------------------------------------------------------------------------
309 0 : void OAppDetailPageHelper::sortDown()
310 : {
311 0 : int nPos = getVisibleControlIndex();
312 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
313 0 : sort(nPos,SortDescending);
314 0 : }
315 : // -----------------------------------------------------------------------------
316 0 : void OAppDetailPageHelper::sortUp()
317 : {
318 0 : int nPos = getVisibleControlIndex();
319 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
320 0 : sort(nPos,SortAscending);
321 0 : }
322 : // -----------------------------------------------------------------------------
323 0 : void OAppDetailPageHelper::getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const
324 : {
325 0 : int nPos = getVisibleControlIndex();
326 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
327 : {
328 0 : DBTreeListBox& rTree = *m_pLists[nPos];
329 0 : sal_Int32 nCount = rTree.GetEntryCount();
330 0 : _rNames.reserve(nCount);
331 0 : SvTreeListEntry* pEntry = rTree.FirstSelected();
332 0 : ElementType eType = getElementType();
333 0 : while( pEntry )
334 : {
335 0 : if ( eType == E_TABLE )
336 : {
337 0 : if( rTree.GetChildCount(pEntry) == 0 )
338 0 : _rNames.push_back( getQualifiedName( pEntry ) );
339 : }
340 : else
341 : {
342 0 : ::rtl::OUString sName = rTree.GetEntryText(pEntry);
343 0 : SvTreeListEntry* pParent = rTree.GetParent(pEntry);
344 0 : while(pParent)
345 : {
346 0 : sName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sName;
347 0 : pParent = rTree.GetParent(pParent);
348 : }
349 0 : _rNames.push_back(sName);
350 : }
351 0 : pEntry = rTree.NextSelected(pEntry);
352 : }
353 : }
354 0 : }
355 :
356 : // -----------------------------------------------------------------------------
357 0 : void OAppDetailPageHelper::describeCurrentSelectionForControl( const Control& _rControl, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
358 : {
359 0 : enum ElementType eType = E_TABLE;
360 0 : for ( size_t i=0; i < E_ELEMENT_TYPE_COUNT; eType = static_cast< ElementType >( ++i ) )
361 : {
362 0 : if ( m_pLists[eType] == &_rControl )
363 : {
364 0 : describeCurrentSelectionForType( eType, _out_rSelectedObjects );
365 0 : return;
366 : }
367 : }
368 : OSL_FAIL( "OAppDetailPageHelper::describeCurrentSelectionForControl: invalid control!" );
369 : }
370 :
371 : // -----------------------------------------------------------------------------
372 0 : void OAppDetailPageHelper::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
373 : {
374 : OSL_ENSURE( _eType < E_ELEMENT_TYPE_COUNT, "OAppDetailPageHelper::describeCurrentSelectionForType: invalid type!" );
375 0 : DBTreeListBox* pList = ( _eType < E_ELEMENT_TYPE_COUNT ) ? m_pLists[ _eType ] : NULL;
376 : OSL_ENSURE( pList, "OAppDetailPageHelper::describeCurrentSelectionForType: "
377 : "You really should ensure this type has already been viewed before!" );
378 0 : if ( !pList )
379 0 : return;
380 :
381 0 : ::std::vector< NamedDatabaseObject > aSelected;
382 :
383 0 : SvTreeListEntry* pEntry = pList->FirstSelected();
384 0 : while( pEntry )
385 : {
386 0 : NamedDatabaseObject aObject;
387 0 : switch ( _eType )
388 : {
389 : case E_TABLE:
390 : {
391 0 : OTableTreeListBox& rTableTree = dynamic_cast< OTableTreeListBox& >( *pList );
392 0 : aObject = rTableTree.describeObject( pEntry );
393 : }
394 0 : break;
395 : case E_QUERY:
396 0 : aObject.Type = DatabaseObject::QUERY;
397 0 : aObject.Name = pList->GetEntryText( pEntry );
398 0 : break;
399 :
400 : case E_FORM:
401 : case E_REPORT:
402 : {
403 0 : ::rtl::OUString sName = pList->GetEntryText(pEntry);
404 0 : SvTreeListEntry* pParent = pList->GetParent(pEntry);
405 0 : while ( pParent )
406 : {
407 0 : ::rtl::OUStringBuffer buffer;
408 0 : buffer.append( pList->GetEntryText( pParent ) );
409 0 : buffer.append( sal_Unicode( '/' ) );
410 0 : buffer.append( sName );
411 0 : sName = buffer.makeStringAndClear();
412 :
413 0 : pParent = pList->GetParent( pParent );
414 0 : }
415 :
416 0 : if ( isLeaf( pEntry ) )
417 0 : aObject.Type = ( _eType == E_FORM ) ? DatabaseObject::FORM : DatabaseObject::REPORT;
418 : else
419 0 : aObject.Type = ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER : DatabaseObjectContainer::REPORTS_FOLDER;
420 0 : aObject.Name = sName;
421 : }
422 0 : break;
423 : default:
424 : OSL_FAIL( "OAppDetailPageHelper::describeCurrentSelectionForType: unexpected type!" );
425 0 : break;
426 : }
427 :
428 0 : if ( !aObject.Name.isEmpty() )
429 : {
430 0 : aSelected.push_back( aObject );
431 : }
432 :
433 0 : pEntry = pList->NextSelected(pEntry);
434 0 : }
435 :
436 0 : _out_rSelectedObjects.realloc( aSelected.size() );
437 0 : ::std::copy( aSelected.begin(), aSelected.end(), _out_rSelectedObjects.getArray() );
438 : }
439 :
440 : // -----------------------------------------------------------------------------
441 0 : void OAppDetailPageHelper::selectElements(const Sequence< ::rtl::OUString>& _aNames)
442 : {
443 0 : int nPos = getVisibleControlIndex();
444 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
445 : {
446 0 : DBTreeListBox& rTree = *m_pLists[nPos];
447 0 : rTree.SelectAll(sal_False);
448 0 : const ::rtl::OUString* pIter = _aNames.getConstArray();
449 0 : const ::rtl::OUString* pEnd = pIter + _aNames.getLength();
450 0 : for(;pIter != pEnd;++pIter)
451 : {
452 0 : SvTreeListEntry* pEntry = rTree.GetEntryPosByName(*pIter);
453 0 : if ( pEntry )
454 0 : rTree.Select(pEntry);
455 : }
456 : }
457 0 : }
458 : // -----------------------------------------------------------------------------
459 0 : ::rtl::OUString OAppDetailPageHelper::getQualifiedName( SvTreeListEntry* _pEntry ) const
460 : {
461 0 : int nPos = getVisibleControlIndex();
462 0 : ::rtl::OUString sComposedName;
463 :
464 0 : if ( nPos >= E_ELEMENT_TYPE_COUNT )
465 0 : return sComposedName;
466 :
467 : OSL_ENSURE(m_pLists[nPos],"Tables tree view is NULL! -> GPF");
468 0 : DBTreeListBox& rTree = *m_pLists[nPos];
469 :
470 0 : SvTreeListEntry* pEntry = _pEntry;
471 0 : if ( !pEntry )
472 0 : pEntry = rTree.FirstSelected();
473 :
474 0 : if ( !pEntry )
475 0 : return sComposedName;
476 :
477 0 : if ( getElementType() == E_TABLE )
478 : {
479 0 : const OTableTreeListBox& rTreeView = dynamic_cast< const OTableTreeListBox& >( *m_pLists[nPos] );
480 0 : sComposedName = rTreeView.getQualifiedTableName( pEntry );
481 : }
482 : else
483 : {
484 0 : sComposedName = rTree.GetEntryText(pEntry);
485 0 : SvTreeListEntry* pParent = rTree.GetParent(pEntry);
486 0 : while(pParent)
487 : {
488 0 : sComposedName = rTree.GetEntryText(pParent) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")) + sComposedName;
489 0 : pParent = rTree.GetParent(pParent);
490 : }
491 : }
492 :
493 0 : return sComposedName;
494 : }
495 : // -----------------------------------------------------------------------------
496 0 : ElementType OAppDetailPageHelper::getElementType() const
497 : {
498 0 : int nPos = getVisibleControlIndex();
499 0 : return static_cast<ElementType>(nPos);
500 : }
501 : // -----------------------------------------------------------------------------
502 0 : sal_Int32 OAppDetailPageHelper::getSelectionCount()
503 : {
504 0 : sal_Int32 nCount = 0;
505 0 : int nPos = getVisibleControlIndex();
506 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
507 : {
508 0 : DBTreeListBox& rTree = *m_pLists[nPos];
509 0 : SvTreeListEntry* pEntry = rTree.FirstSelected();
510 0 : while( pEntry )
511 : {
512 0 : ++nCount;
513 0 : pEntry = rTree.NextSelected(pEntry);
514 : }
515 : }
516 0 : return nCount;
517 : }
518 : // -----------------------------------------------------------------------------
519 0 : sal_Int32 OAppDetailPageHelper::getElementCount()
520 : {
521 0 : sal_Int32 nCount = 0;
522 0 : int nPos = getVisibleControlIndex();
523 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
524 : {
525 0 : nCount = m_pLists[nPos]->GetEntryCount();
526 : }
527 0 : return nCount;
528 : }
529 : // -----------------------------------------------------------------------------
530 0 : sal_Bool OAppDetailPageHelper::isCutAllowed()
531 : {
532 0 : return sal_False;
533 : }
534 : // -----------------------------------------------------------------------------
535 0 : sal_Bool OAppDetailPageHelper::isCopyAllowed()
536 : {
537 0 : return sal_True;
538 : }
539 : // -----------------------------------------------------------------------------
540 0 : sal_Bool OAppDetailPageHelper::isPasteAllowed()
541 : {
542 0 : return sal_True;
543 : }
544 : // -----------------------------------------------------------------------------
545 0 : void OAppDetailPageHelper::copy()
546 : {
547 0 : }
548 : // -----------------------------------------------------------------------------
549 0 : void OAppDetailPageHelper::cut()
550 : {
551 0 : }
552 : // -----------------------------------------------------------------------------
553 0 : void OAppDetailPageHelper::paste()
554 : {
555 0 : }
556 : // -----------------------------------------------------------------------------
557 0 : bool OAppDetailPageHelper::isLeaf(SvTreeListEntry* _pEntry) const
558 : {
559 0 : if ( !_pEntry )
560 0 : return false;
561 0 : sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
562 0 : if ( ( nEntryType == DatabaseObjectContainer::TABLES )
563 : || ( nEntryType == DatabaseObjectContainer::CATALOG )
564 : || ( nEntryType == DatabaseObjectContainer::SCHEMA )
565 : || ( nEntryType == DatabaseObjectContainer::FORMS_FOLDER )
566 : || ( nEntryType == DatabaseObjectContainer::REPORTS_FOLDER )
567 : )
568 0 : return false;
569 :
570 0 : return true;
571 : }
572 :
573 : // -----------------------------------------------------------------------------
574 0 : sal_Bool OAppDetailPageHelper::isALeafSelected() const
575 : {
576 0 : int nPos = getVisibleControlIndex();
577 0 : sal_Bool bLeafSelected = sal_False;
578 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
579 : {
580 0 : DBTreeListBox& rTree = *m_pLists[nPos];
581 0 : SvTreeListEntry* pEntry = rTree.FirstSelected( );
582 0 : while( !bLeafSelected && pEntry )
583 : {
584 0 : bLeafSelected = isLeaf( pEntry );
585 0 : pEntry = rTree.NextSelected(pEntry);
586 : }
587 : }
588 0 : return bLeafSelected;
589 : }
590 : // -----------------------------------------------------------------------------
591 0 : SvTreeListEntry* OAppDetailPageHelper::getEntry( const Point& _aPosPixel) const
592 : {
593 0 : SvTreeListEntry* pReturn = NULL;
594 0 : int nPos = getVisibleControlIndex();
595 0 : if ( nPos < E_ELEMENT_TYPE_COUNT )
596 0 : pReturn = m_pLists[nPos]->GetEntry( _aPosPixel,sal_True );
597 0 : return pReturn;
598 : }
599 : // -----------------------------------------------------------------------------
600 0 : void OAppDetailPageHelper::createTablesPage(const Reference< XConnection>& _xConnection)
601 : {
602 : OSL_ENSURE(_xConnection.is(),"Connection is NULL! -> GPF");
603 :
604 0 : if ( !m_pLists[E_TABLE] )
605 : {
606 : OTableTreeListBox* pTreeView = new OTableTreeListBox(this
607 0 : ,getBorderWin().getView()->getORB()
608 : ,WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP
609 0 : ,sal_False);
610 0 : pTreeView->SetHelpId(HID_APP_TABLE_TREE);
611 0 : m_pLists[E_TABLE] = pTreeView;
612 :
613 0 : ImageProvider aImageProvider( _xConnection );
614 : createTree( pTreeView,
615 : aImageProvider.getDefaultImage( DatabaseObject::TABLE )
616 0 : );
617 :
618 0 : pTreeView->notifyHiContrastChanged();
619 0 : m_aBorder.SetZOrder(pTreeView, WINDOW_ZORDER_BEHIND);
620 : }
621 0 : if ( !m_pLists[E_TABLE]->GetEntryCount() )
622 : {
623 0 : static_cast<OTableTreeListBox*>(m_pLists[E_TABLE])->UpdateTableList(_xConnection);
624 :
625 0 : SvTreeListEntry* pEntry = m_pLists[E_TABLE]->First();
626 0 : if ( pEntry )
627 0 : m_pLists[E_TABLE]->Expand(pEntry);
628 0 : m_pLists[E_TABLE]->SelectAll(sal_False);
629 : }
630 :
631 0 : setDetailPage(m_pLists[E_TABLE]);
632 0 : }
633 :
634 : // -----------------------------------------------------------------------------
635 0 : void OAppDetailPageHelper::getElementIcons( ElementType _eType, sal_uInt16& _rImageId)
636 : {
637 0 : ImageProvider aImageProvider;
638 0 : _rImageId = 0;
639 :
640 0 : sal_Int32 nDatabaseObjectType( 0 );
641 0 : switch(_eType )
642 : {
643 0 : case E_FORM: nDatabaseObjectType = DatabaseObject::FORM; break;
644 0 : case E_REPORT: nDatabaseObjectType = DatabaseObject::REPORT; break;
645 0 : case E_QUERY: nDatabaseObjectType = DatabaseObject::QUERY; break;
646 : default:
647 : OSL_FAIL( "OAppDetailPageHelper::GetElementIcons: invalid element type!" );
648 0 : return;
649 : }
650 0 : _rImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType );
651 : }
652 :
653 : // -----------------------------------------------------------------------------
654 0 : void OAppDetailPageHelper::createPage(ElementType _eType,const Reference< XNameAccess >& _xContainer)
655 : {
656 : OSL_ENSURE(E_TABLE != _eType,"E_TABLE isn't allowed.");
657 :
658 0 : sal_uInt16 nImageId = 0;
659 0 : rtl::OString sHelpId;
660 0 : ImageProvider aImageProvider;
661 0 : Image aFolderImage;
662 0 : switch( _eType )
663 : {
664 : case E_FORM:
665 0 : sHelpId = HID_APP_FORM_TREE;
666 0 : aFolderImage = aImageProvider.getFolderImage( DatabaseObject::FORM );
667 0 : break;
668 : case E_REPORT:
669 0 : sHelpId = HID_APP_REPORT_TREE;
670 0 : aFolderImage = aImageProvider.getFolderImage( DatabaseObject::REPORT );
671 0 : break;
672 : case E_QUERY:
673 0 : sHelpId = HID_APP_QUERY_TREE;
674 0 : aFolderImage = aImageProvider.getFolderImage( DatabaseObject::QUERY );
675 0 : break;
676 : default:
677 : OSL_FAIL("Illegal call!");
678 : }
679 0 : getElementIcons( _eType, nImageId );
680 :
681 0 : if ( !m_pLists[_eType] )
682 : {
683 0 : m_pLists[_eType] = createSimpleTree( sHelpId, aFolderImage );
684 : }
685 :
686 0 : if ( m_pLists[_eType] )
687 : {
688 0 : if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() )
689 : {
690 0 : fillNames( _xContainer, _eType, nImageId, NULL );
691 :
692 0 : m_pLists[_eType]->SelectAll(sal_False);
693 : }
694 0 : setDetailPage(m_pLists[_eType]);
695 0 : }
696 0 : }
697 : // -----------------------------------------------------------------------------
698 0 : void OAppDetailPageHelper::setDetailPage(Window* _pWindow)
699 : {
700 : OSL_ENSURE(_pWindow,"OAppDetailPageHelper::setDetailPage: Window is NULL!");
701 0 : Window* pCurrent = getCurrentView();
702 0 : if ( pCurrent )
703 0 : pCurrent->Hide();
704 :
705 0 : showPreview(NULL);
706 0 : sal_Bool bHasFocus = sal_False;
707 0 : m_aFL.Show();
708 : {
709 0 : bHasFocus = pCurrent->HasChildPathFocus();
710 0 : _pWindow->Show();
711 : }
712 0 : m_aTBPreview.Show();
713 0 : m_aBorder.Show();
714 0 : switchPreview(m_ePreviewMode,sal_True);
715 :
716 0 : if ( bHasFocus )
717 0 : _pWindow->GrabFocus();
718 0 : Resize();
719 0 : }
720 :
721 : // -----------------------------------------------------------------------------
722 : namespace
723 : {
724 : namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
725 : namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
726 :
727 0 : static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType )
728 : {
729 : const sal_Int32 nFolderIndicator =
730 : ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER
731 0 : : ( _eType == E_REPORT ) ? DatabaseObjectContainer::REPORTS_FOLDER : -1;
732 0 : return nFolderIndicator;
733 : }
734 : }
735 :
736 : // -----------------------------------------------------------------------------
737 0 : void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType,
738 : const sal_uInt16 _nImageId, SvTreeListEntry* _pParent )
739 : {
740 : OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF");
741 : OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" );
742 :
743 0 : DBTreeListBox* pList = m_pLists[ _eType ];
744 : OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" );
745 0 : if ( !pList )
746 0 : return;
747 :
748 0 : if ( _xContainer.is() && _xContainer->hasElements() )
749 : {
750 0 : const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
751 :
752 0 : Sequence< ::rtl::OUString> aSeq = _xContainer->getElementNames();
753 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
754 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
755 0 : for(;pIter != pEnd;++pIter)
756 : {
757 0 : SvTreeListEntry* pEntry = NULL;
758 0 : Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY);
759 0 : if ( xSubElements.is() )
760 : {
761 0 : pEntry = pList->InsertEntry( *pIter, _pParent, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
762 0 : getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) );
763 0 : fillNames( xSubElements, _eType, _nImageId, pEntry );
764 : }
765 : else
766 : {
767 0 : pEntry = pList->InsertEntry( *pIter, _pParent );
768 :
769 0 : Image aImage = Image( ModuleRes( _nImageId ) );
770 0 : pList->SetExpandedEntryBmp( pEntry, aImage );
771 0 : pList->SetCollapsedEntryBmp( pEntry, aImage );
772 : }
773 0 : }
774 : }
775 : }
776 : // -----------------------------------------------------------------------------
777 0 : DBTreeListBox* OAppDetailPageHelper::createSimpleTree( const rtl::OString& _sHelpId, const Image& _rImage)
778 : {
779 0 : DBTreeListBox* pTreeView = new DBTreeListBox(this,getBorderWin().getView()->getORB(),WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
780 0 : pTreeView->SetHelpId( _sHelpId );
781 0 : return createTree( pTreeView, _rImage );
782 : }
783 :
784 : // -----------------------------------------------------------------------------
785 0 : DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage )
786 : {
787 0 : WaitObject aWaitCursor(this);
788 :
789 0 : _pTreeView->SetStyle(_pTreeView->GetStyle() | WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
790 0 : _pTreeView->GetModel()->SetSortMode(SortAscending);
791 0 : _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
792 0 : _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
793 :
794 0 : _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
795 0 : _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
796 :
797 0 : _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
798 0 : _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
799 0 : _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
800 :
801 0 : _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
802 0 : _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
803 0 : _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
804 0 : _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
805 :
806 0 : _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
807 0 : _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
808 :
809 0 : return _pTreeView;
810 : }
811 : // -----------------------------------------------------------------------------
812 0 : void OAppDetailPageHelper::clearPages()
813 : {
814 0 : showPreview(NULL);
815 0 : for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
816 : {
817 0 : if ( m_pLists[i] )
818 0 : m_pLists[i]->Clear();
819 : }
820 0 : }
821 : // -----------------------------------------------------------------------------
822 0 : sal_Bool OAppDetailPageHelper::isFilled() const
823 : {
824 0 : size_t i = 0;
825 0 : for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
826 : ;
827 0 : return i != E_ELEMENT_TYPE_COUNT;
828 : }
829 : // -----------------------------------------------------------------------------
830 0 : void OAppDetailPageHelper::elementReplaced(ElementType _eType
831 : ,const ::rtl::OUString& _rOldName
832 : ,const ::rtl::OUString& _rNewName )
833 : {
834 0 : DBTreeListBox* pTreeView = getCurrentView();
835 0 : if ( pTreeView )
836 : {
837 0 : ::rtl::OUString sNewName = _rNewName;
838 0 : SvTreeListEntry* pEntry = NULL;
839 0 : switch( _eType )
840 : {
841 : case E_TABLE:
842 0 : static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
843 0 : static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
844 0 : return;
845 :
846 : case E_QUERY:
847 0 : pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
848 0 : break;
849 : case E_FORM:
850 : case E_REPORT:
851 0 : pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
852 0 : break;
853 : default:
854 : OSL_FAIL("Invalid element type");
855 : }
856 : OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
857 0 : if ( pEntry )
858 : {
859 0 : pTreeView->SetEntryText(pEntry,sNewName);
860 0 : }
861 : }
862 : }
863 : // -----------------------------------------------------------------------------
864 0 : SvTreeListEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const ::rtl::OUString& _rName, const Any& _rObject )
865 : {
866 0 : SvTreeListEntry* pRet = NULL;
867 0 : DBTreeListBox* pTreeView = m_pLists[_eType];
868 0 : if( _eType == E_TABLE && pTreeView )
869 : {
870 0 : pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
871 : }
872 0 : else if ( pTreeView )
873 : {
874 :
875 0 : SvTreeListEntry* pEntry = NULL;
876 0 : Reference<XChild> xChild(_rObject,UNO_QUERY);
877 0 : if ( xChild.is() && E_QUERY != _eType )
878 : {
879 0 : Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
880 0 : if ( xContent.is() )
881 : {
882 0 : ::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
883 0 : pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
884 0 : }
885 : }
886 :
887 0 : sal_uInt16 nImageId = 0;
888 0 : getElementIcons( _eType, nImageId );
889 0 : Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
890 0 : if ( xContainer.is() )
891 : {
892 0 : const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
893 0 : pRet = pTreeView->InsertEntry( _rName, pEntry, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
894 0 : fillNames( xContainer, _eType, nImageId, pRet );
895 : }
896 : else
897 : {
898 0 : pRet = pTreeView->InsertEntry( _rName, pEntry );
899 :
900 0 : Image aImage = Image( ModuleRes( nImageId ) );
901 0 : pTreeView->SetExpandedEntryBmp( pRet, aImage );
902 0 : pTreeView->SetCollapsedEntryBmp( pRet, aImage );
903 0 : }
904 : }
905 0 : return pRet;
906 : }
907 : // -----------------------------------------------------------------------------
908 0 : void OAppDetailPageHelper::elementRemoved( ElementType _eType,const ::rtl::OUString& _rName )
909 : {
910 0 : DBTreeListBox* pTreeView = getCurrentView();
911 0 : if ( pTreeView )
912 : {
913 0 : switch( _eType )
914 : {
915 : case E_TABLE:
916 : // we don't need to clear the table here, it is already done by the dispose listener
917 0 : static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
918 0 : break;
919 : case E_QUERY:
920 0 : if ( pTreeView )
921 : {
922 0 : SvTreeListEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
923 0 : if ( pEntry )
924 0 : pTreeView->GetModel()->Remove(pEntry);
925 : }
926 0 : break;
927 : case E_FORM:
928 : case E_REPORT:
929 : {
930 0 : if ( pTreeView )
931 : {
932 0 : SvTreeListEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
933 0 : if ( pEntry )
934 0 : pTreeView->GetModel()->Remove(pEntry);
935 : }
936 : }
937 0 : break;
938 : default:
939 : OSL_FAIL("Invalid element type");
940 : }
941 0 : if ( !pTreeView->GetEntryCount() )
942 0 : showPreview(NULL);
943 : }
944 0 : }
945 : // -----------------------------------------------------------------------------
946 0 : IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
947 : {
948 : OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
949 0 : bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
950 0 : return bHandled ? 1L : 0L;
951 : }
952 : // -----------------------------------------------------------------------------
953 0 : IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
954 : {
955 0 : getBorderWin().getView()->getAppController().onSelectionChanged();
956 0 : return 1L;
957 : }
958 : // -----------------------------------------------------------------------------
959 0 : IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
960 : {
961 0 : getBorderWin().getView()->getAppController().onCutEntry();
962 0 : return 1L;
963 : }
964 : // -----------------------------------------------------------------------------
965 0 : IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
966 : {
967 0 : getBorderWin().getView()->getAppController().onCopyEntry();
968 0 : return 1L;
969 : }
970 : // -----------------------------------------------------------------------------
971 0 : IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
972 : {
973 0 : getBorderWin().getView()->getAppController().onPasteEntry();
974 0 : return 1L;
975 : }
976 : // -----------------------------------------------------------------------------
977 0 : IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
978 : {
979 0 : getBorderWin().getView()->getAppController().onDeleteEntry();
980 0 : return 1L;
981 : }
982 : // -----------------------------------------------------------------------------
983 0 : void OAppDetailPageHelper::Resize()
984 : {
985 : // parent window dimension
986 0 : Size aOutputSize( GetOutputSize() );
987 0 : long nOutputWidth = aOutputSize.Width();
988 0 : long nOutputHeight = aOutputSize.Height();
989 :
990 0 : Window* pWindow = getCurrentView();
991 0 : if ( pWindow )
992 : {
993 0 : Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
994 0 : sal_Int32 n6PPT = aFLSize.Height();
995 0 : long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
996 :
997 0 : pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
998 :
999 0 : m_aFL.SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
1000 :
1001 0 : String sText = m_aTBPreview.GetItemText(SID_DB_APP_DISABLE_PREVIEW);
1002 0 : Size aTBSize = m_aTBPreview.CalcWindowSizePixel();
1003 0 : m_aTBPreview.SetPosSizePixel(Point(nOutputWidth - aTBSize.getWidth(), 0 ),
1004 0 : aTBSize );
1005 :
1006 0 : m_aBorder.SetPosSizePixel(Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
1007 0 : Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
1008 0 : m_aPreview.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1009 0 : m_aDocumentInfo.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1010 0 : m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1011 : }
1012 0 : }
1013 : // -----------------------------------------------------------------------------
1014 0 : PreviewMode OAppDetailPageHelper::getPreviewMode()
1015 : {
1016 0 : return m_ePreviewMode;
1017 : }
1018 : // -----------------------------------------------------------------------------
1019 0 : sal_Bool OAppDetailPageHelper::isPreviewEnabled()
1020 : {
1021 0 : return m_ePreviewMode != E_PREVIEWNONE;
1022 : }
1023 : // -----------------------------------------------------------------------------
1024 0 : void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,sal_Bool _bForce)
1025 : {
1026 0 : if ( m_ePreviewMode != _eMode || _bForce )
1027 : {
1028 0 : m_ePreviewMode = _eMode;
1029 :
1030 0 : getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
1031 :
1032 0 : sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1033 0 : switch ( m_ePreviewMode )
1034 : {
1035 : case E_PREVIEWNONE:
1036 0 : nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1037 0 : break;
1038 : case E_DOCUMENT:
1039 0 : nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
1040 0 : break;
1041 : case E_DOCUMENTINFO:
1042 0 : if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1043 0 : nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1044 : else
1045 0 : m_ePreviewMode = E_PREVIEWNONE;
1046 0 : break;
1047 : }
1048 :
1049 0 : m_aMenu->CheckItem(nSelectedAction);
1050 0 : m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1051 0 : Resize();
1052 :
1053 : // simulate a selectionChanged event at the controller, to force the preview to be updated
1054 0 : if ( isPreviewEnabled() )
1055 : {
1056 0 : if ( getCurrentView() && getCurrentView()->FirstSelected() )
1057 : {
1058 0 : getBorderWin().getView()->getAppController().onSelectionChanged();
1059 : }
1060 : }
1061 : else
1062 : {
1063 0 : m_pTablePreview->Hide();
1064 0 : m_aPreview.Hide();
1065 0 : m_aDocumentInfo.Hide();
1066 : }
1067 : }
1068 0 : }
1069 : // -----------------------------------------------------------------------------
1070 0 : void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1071 : {
1072 0 : if ( isPreviewEnabled() )
1073 : {
1074 0 : m_pTablePreview->Hide();
1075 :
1076 0 : WaitObject aWaitCursor( this );
1077 : try
1078 : {
1079 0 : Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1080 0 : if ( xContent.is() )
1081 : {
1082 0 : com::sun::star::ucb::Command aCommand;
1083 0 : if ( m_ePreviewMode == E_DOCUMENT )
1084 0 : aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("preview"));
1085 : else
1086 0 : aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getDocumentInfo"));
1087 :
1088 0 : Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1089 0 : if ( m_ePreviewMode == E_DOCUMENT )
1090 : {
1091 0 : m_aDocumentInfo.Hide();
1092 0 : m_aPreview.Show();
1093 :
1094 0 : Graphic aGraphic;
1095 0 : Sequence < sal_Int8 > aBmpSequence;
1096 0 : if ( aPreview >>= aBmpSequence )
1097 : {
1098 0 : SvMemoryStream aData( aBmpSequence.getArray(),
1099 0 : aBmpSequence.getLength(),
1100 0 : STREAM_READ );
1101 :
1102 0 : GraphicConverter::Import(aData,aGraphic);
1103 : }
1104 0 : m_aPreview.setGraphic( aGraphic );
1105 0 : m_aPreview.Invalidate();
1106 : }
1107 : else
1108 : {
1109 0 : m_aPreview.Hide();
1110 0 : m_aDocumentInfo.clear();
1111 0 : m_aDocumentInfo.Show();
1112 : Reference<document::XDocumentProperties> xProp(
1113 0 : aPreview, UNO_QUERY);
1114 0 : if ( xProp.is() )
1115 0 : m_aDocumentInfo.fill(xProp,String());
1116 0 : }
1117 : }
1118 : else
1119 : {
1120 0 : m_aPreview.Hide();
1121 0 : m_aDocumentInfo.Hide();
1122 0 : }
1123 : }
1124 0 : catch( const Exception& )
1125 : {
1126 : DBG_UNHANDLED_EXCEPTION();
1127 0 : }
1128 : }
1129 0 : }
1130 : // -----------------------------------------------------------------------------
1131 0 : void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName,
1132 : const ::rtl::OUString& _sName,
1133 : sal_Bool _bTable)
1134 : {
1135 0 : if ( isPreviewEnabled() )
1136 : {
1137 0 : WaitObject aWaitCursor( this );
1138 0 : m_aPreview.Hide();
1139 0 : m_aDocumentInfo.Hide();
1140 0 : m_pTablePreview->Show();
1141 0 : if ( !m_xFrame.is() )
1142 : {
1143 : try
1144 : {
1145 0 : m_xFrame = Reference < XFrame > ( getBorderWin().getView()->getORB()->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")) ), UNO_QUERY );
1146 0 : m_xFrame->initialize( m_xWindow );
1147 :
1148 : // no layout manager (and thus no toolbars) in the preview
1149 : // Must be called after initialize ... but before any other call to this frame.
1150 : // Otherwise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1151 0 : Reference< XPropertySet > xFrameProps( m_xFrame, UNO_QUERY_THROW );
1152 0 : xFrameProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ), makeAny(Reference< XLayoutManager >()) );
1153 :
1154 0 : Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1155 0 : if ( xSup.is() )
1156 : {
1157 0 : Reference<XFrames> xFrames = xSup->getFrames();
1158 0 : xFrames->append(m_xFrame);
1159 0 : }
1160 : }
1161 0 : catch(const Exception&)
1162 : {
1163 : }
1164 : }
1165 :
1166 0 : Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1167 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1168 : ::std::auto_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1169 0 : getBorderWin().getView()->getORB(), xApplication, NULL, _bTable
1170 0 : ) );
1171 : SAL_WNODEPRECATED_DECLARATIONS_POP
1172 0 : pDispatcher->setTargetFrame( m_xFrame );
1173 :
1174 0 : ::comphelper::NamedValueCollection aArgs;
1175 0 : aArgs.put( "Preview", sal_True );
1176 0 : aArgs.put( "ReadOnly", sal_True );
1177 0 : aArgs.put( "AsTemplate", sal_False );
1178 0 : aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False );
1179 :
1180 0 : Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1181 0 : sal_Bool bClearPreview = !xPreview.is();
1182 :
1183 : // clear the preview when the query or table could not be loaded
1184 0 : if ( !bClearPreview )
1185 : {
1186 0 : Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1187 0 : bClearPreview = !xTabController.is();
1188 0 : if ( !bClearPreview )
1189 : {
1190 0 : Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1191 0 : bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1192 0 : }
1193 : }
1194 0 : if ( bClearPreview )
1195 0 : showPreview(NULL);
1196 : }
1197 0 : }
1198 : // -----------------------------------------------------------------------------
1199 0 : IMPL_LINK(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, /*pToolBox*/)
1200 : {
1201 0 : m_aTBPreview.EndSelection();
1202 :
1203 : // tell the toolbox that the item is pressed down
1204 0 : m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_True );
1205 :
1206 : // simulate a mouse move (so the "down" state is really painted)
1207 0 : Point aPoint = m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1208 0 : MouseEvent aMove( aPoint, 0, MOUSE_SIMPLEMOVE | MOUSE_SYNTHETIC );
1209 0 : m_aTBPreview.MouseMove( aMove );
1210 :
1211 0 : m_aTBPreview.Update();
1212 :
1213 : // execute the menu
1214 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1215 0 : ::std::auto_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1216 : SAL_WNODEPRECATED_DECLARATIONS_POP
1217 :
1218 : sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1219 : , SID_DB_APP_VIEW_DOC_PREVIEW
1220 : , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1221 0 : };
1222 :
1223 0 : for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1224 : {
1225 0 : aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1226 : }
1227 0 : aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1228 :
1229 : // no disabled entries
1230 0 : aMenu->RemoveDisabledEntries();
1231 :
1232 0 : sal_uInt16 nSelectedAction = aMenu->Execute(&m_aTBPreview, m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1233 : // "cleanup" the toolbox state
1234 0 : MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
1235 0 : m_aTBPreview.MouseMove( aLeave );
1236 0 : m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_False);
1237 0 : if ( nSelectedAction )
1238 : {
1239 0 : m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1240 0 : Resize();
1241 0 : getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1242 : }
1243 0 : return 0L;
1244 : }
1245 :
1246 : // -----------------------------------------------------------------------------
1247 0 : void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1248 : {
1249 0 : SvTreeListBox* pCurrentView = getCurrentView();
1250 : OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1251 :
1252 0 : KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1253 0 : sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1254 :
1255 0 : if ( ( KEY_RETURN == nCode ) && pCurrentView )
1256 : {
1257 0 : getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1258 : }
1259 : else
1260 0 : Window::KeyInput(rKEvt);
1261 0 : }
1262 :
1263 : // -----------------------------------------------------------------------------
1264 0 : void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1265 : {
1266 0 : Window::DataChanged( rDCEvt );
1267 :
1268 0 : if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1269 0 : (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1270 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1271 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1272 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1273 :
1274 : {
1275 0 : ImplInitSettings();
1276 0 : if ( m_pLists[ E_TABLE ] )
1277 : {
1278 0 : OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ] );
1279 : OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1280 0 : if ( pTableTree )
1281 0 : pTableTree->notifyHiContrastChanged();
1282 : }
1283 : }
1284 0 : }
1285 : // -----------------------------------------------------------------------------
1286 0 : void OAppDetailPageHelper::ImplInitSettings()
1287 : {
1288 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1289 0 : Font aFont;
1290 0 : aFont = rStyleSettings.GetFieldFont();
1291 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1292 0 : SetPointFont( aFont );
1293 0 : m_aTBPreview.SetPointFont( aFont );
1294 :
1295 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
1296 0 : SetTextFillColor();
1297 0 : m_aBorder.SetTextColor( rStyleSettings.GetFieldTextColor() );
1298 0 : m_aBorder.SetTextFillColor();
1299 0 : m_aTBPreview.SetTextColor( rStyleSettings.GetFieldTextColor() );
1300 0 : m_aTBPreview.SetTextFillColor();
1301 :
1302 0 : SetBackground( rStyleSettings.GetFieldColor() );
1303 0 : m_aBorder.SetBackground( rStyleSettings.GetFieldColor() );
1304 0 : m_aFL.SetBackground( rStyleSettings.GetFieldColor() );
1305 0 : m_aDocumentInfo.SetBackground( rStyleSettings.GetFieldColor() );
1306 0 : m_aTBPreview.SetBackground( rStyleSettings.GetFieldColor() );
1307 0 : m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1308 0 : }
1309 : // -----------------------------------------------------------------------------
1310 0 : OPreviewWindow::OPreviewWindow(Window* _pParent)
1311 0 : : Window(_pParent)
1312 : {
1313 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1314 0 : }
1315 : // -----------------------------------------------------------------------------
1316 0 : sal_Bool OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1317 : {
1318 0 : const Size aWinSize( GetOutputSizePixel() );
1319 0 : Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1320 0 : sal_Bool bRet = sal_False;
1321 :
1322 0 : if( aNewSize.Width() && aNewSize.Height() )
1323 : {
1324 : // scale to fit window
1325 0 : const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1326 0 : const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1327 :
1328 0 : if ( fGrfWH < fWinWH )
1329 : {
1330 0 : aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1331 0 : aNewSize.Height()= aWinSize.Height();
1332 : }
1333 : else
1334 : {
1335 0 : aNewSize.Width() = aWinSize.Width();
1336 0 : aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1337 : }
1338 :
1339 0 : const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
1340 0 : ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1341 :
1342 0 : rResultRect = Rectangle( aNewPos, aNewSize );
1343 0 : bRet = sal_True;
1344 : }
1345 :
1346 0 : return bRet;
1347 : }
1348 :
1349 : // ------------------------------------------------------------------------
1350 :
1351 0 : void OPreviewWindow::Paint( const Rectangle& rRect )
1352 : {
1353 0 : Window::Paint( rRect );
1354 :
1355 0 : if( ImplGetGraphicCenterRect( m_aGraphicObj.GetGraphic(), m_aPreviewRect ) )
1356 : {
1357 0 : const Point aPos( m_aPreviewRect.TopLeft() );
1358 0 : const Size aSize( m_aPreviewRect.GetSize() );
1359 :
1360 0 : if( m_aGraphicObj.IsAnimated() )
1361 0 : m_aGraphicObj.StartAnimation( this, aPos, aSize );
1362 : else
1363 0 : m_aGraphicObj.Draw( this, aPos, aSize );
1364 : }
1365 0 : }
1366 : // -----------------------------------------------------------------------------
1367 0 : void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1368 : {
1369 0 : Window::DataChanged( rDCEvt );
1370 :
1371 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1372 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1373 : {
1374 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1375 0 : Invalidate();
1376 : }
1377 0 : }
1378 : // -----------------------------------------------------------------------------
1379 0 : void OPreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
1380 : {
1381 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1382 0 : if( bFont )
1383 : {
1384 0 : Font aFont;
1385 0 : aFont = rStyleSettings.GetFieldFont();
1386 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1387 0 : SetPointFont( aFont );
1388 : }
1389 :
1390 0 : if( bForeground || bFont )
1391 : {
1392 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
1393 0 : SetTextFillColor();
1394 : }
1395 :
1396 0 : if( bBackground )
1397 0 : SetBackground( rStyleSettings.GetFieldColor() );
1398 0 : }
1399 : // -----------------------------------------------------------------------------
1400 : // -----------------------------------------------------------------------------
1401 :
1402 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|