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 : ,uno::Reference<lang::XMultiServiceFactory>(getBorderWin().getView()->getORB()->getServiceManager(), uno::UNO_QUERY_THROW)
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 : DBTreeListBox* pTreeView = new DBTreeListBox(this,
780 0 : uno::Reference<lang::XMultiServiceFactory>(getBorderWin().getView()->getORB()->getServiceManager(), uno::UNO_QUERY_THROW),
781 0 : WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
782 0 : pTreeView->SetHelpId( _sHelpId );
783 0 : return createTree( pTreeView, _rImage );
784 : }
785 :
786 : // -----------------------------------------------------------------------------
787 0 : DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage )
788 : {
789 0 : WaitObject aWaitCursor(this);
790 :
791 0 : _pTreeView->SetStyle(_pTreeView->GetStyle() | WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
792 0 : _pTreeView->GetModel()->SetSortMode(SortAscending);
793 0 : _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
794 0 : _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
795 :
796 0 : _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
797 0 : _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
798 :
799 0 : _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
800 0 : _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
801 0 : _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
802 :
803 0 : _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
804 0 : _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
805 0 : _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
806 0 : _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
807 :
808 0 : _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
809 0 : _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
810 :
811 0 : return _pTreeView;
812 : }
813 : // -----------------------------------------------------------------------------
814 0 : void OAppDetailPageHelper::clearPages()
815 : {
816 0 : showPreview(NULL);
817 0 : for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
818 : {
819 0 : if ( m_pLists[i] )
820 0 : m_pLists[i]->Clear();
821 : }
822 0 : }
823 : // -----------------------------------------------------------------------------
824 0 : sal_Bool OAppDetailPageHelper::isFilled() const
825 : {
826 0 : size_t i = 0;
827 0 : for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
828 : ;
829 0 : return i != E_ELEMENT_TYPE_COUNT;
830 : }
831 : // -----------------------------------------------------------------------------
832 0 : void OAppDetailPageHelper::elementReplaced(ElementType _eType
833 : ,const ::rtl::OUString& _rOldName
834 : ,const ::rtl::OUString& _rNewName )
835 : {
836 0 : DBTreeListBox* pTreeView = getCurrentView();
837 0 : if ( pTreeView )
838 : {
839 0 : ::rtl::OUString sNewName = _rNewName;
840 0 : SvTreeListEntry* pEntry = NULL;
841 0 : switch( _eType )
842 : {
843 : case E_TABLE:
844 0 : static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
845 0 : static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
846 0 : return;
847 :
848 : case E_QUERY:
849 0 : pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
850 0 : break;
851 : case E_FORM:
852 : case E_REPORT:
853 0 : pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
854 0 : break;
855 : default:
856 : OSL_FAIL("Invalid element type");
857 : }
858 : OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
859 0 : if ( pEntry )
860 : {
861 0 : pTreeView->SetEntryText(pEntry,sNewName);
862 0 : }
863 : }
864 : }
865 : // -----------------------------------------------------------------------------
866 0 : SvTreeListEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const ::rtl::OUString& _rName, const Any& _rObject )
867 : {
868 0 : SvTreeListEntry* pRet = NULL;
869 0 : DBTreeListBox* pTreeView = m_pLists[_eType];
870 0 : if( _eType == E_TABLE && pTreeView )
871 : {
872 0 : pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
873 : }
874 0 : else if ( pTreeView )
875 : {
876 :
877 0 : SvTreeListEntry* pEntry = NULL;
878 0 : Reference<XChild> xChild(_rObject,UNO_QUERY);
879 0 : if ( xChild.is() && E_QUERY != _eType )
880 : {
881 0 : Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
882 0 : if ( xContent.is() )
883 : {
884 0 : ::rtl::OUString sName = xContent->getIdentifier()->getContentIdentifier();
885 0 : pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
886 0 : }
887 : }
888 :
889 0 : sal_uInt16 nImageId = 0;
890 0 : getElementIcons( _eType, nImageId );
891 0 : Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
892 0 : if ( xContainer.is() )
893 : {
894 0 : const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
895 0 : pRet = pTreeView->InsertEntry( _rName, pEntry, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
896 0 : fillNames( xContainer, _eType, nImageId, pRet );
897 : }
898 : else
899 : {
900 0 : pRet = pTreeView->InsertEntry( _rName, pEntry );
901 :
902 0 : Image aImage = Image( ModuleRes( nImageId ) );
903 0 : pTreeView->SetExpandedEntryBmp( pRet, aImage );
904 0 : pTreeView->SetCollapsedEntryBmp( pRet, aImage );
905 0 : }
906 : }
907 0 : return pRet;
908 : }
909 : // -----------------------------------------------------------------------------
910 0 : void OAppDetailPageHelper::elementRemoved( ElementType _eType,const ::rtl::OUString& _rName )
911 : {
912 0 : DBTreeListBox* pTreeView = getCurrentView();
913 0 : if ( pTreeView )
914 : {
915 0 : switch( _eType )
916 : {
917 : case E_TABLE:
918 : // we don't need to clear the table here, it is already done by the dispose listener
919 0 : static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
920 0 : break;
921 : case E_QUERY:
922 0 : if ( pTreeView )
923 : {
924 0 : SvTreeListEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
925 0 : if ( pEntry )
926 0 : pTreeView->GetModel()->Remove(pEntry);
927 : }
928 0 : break;
929 : case E_FORM:
930 : case E_REPORT:
931 : {
932 0 : if ( pTreeView )
933 : {
934 0 : SvTreeListEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
935 0 : if ( pEntry )
936 0 : pTreeView->GetModel()->Remove(pEntry);
937 : }
938 : }
939 0 : break;
940 : default:
941 : OSL_FAIL("Invalid element type");
942 : }
943 0 : if ( !pTreeView->GetEntryCount() )
944 0 : showPreview(NULL);
945 : }
946 0 : }
947 : // -----------------------------------------------------------------------------
948 0 : IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
949 : {
950 : OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
951 0 : bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
952 0 : return bHandled ? 1L : 0L;
953 : }
954 : // -----------------------------------------------------------------------------
955 0 : IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
956 : {
957 0 : getBorderWin().getView()->getAppController().onSelectionChanged();
958 0 : return 1L;
959 : }
960 : // -----------------------------------------------------------------------------
961 0 : IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
962 : {
963 0 : getBorderWin().getView()->getAppController().onCutEntry();
964 0 : return 1L;
965 : }
966 : // -----------------------------------------------------------------------------
967 0 : IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
968 : {
969 0 : getBorderWin().getView()->getAppController().onCopyEntry();
970 0 : return 1L;
971 : }
972 : // -----------------------------------------------------------------------------
973 0 : IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
974 : {
975 0 : getBorderWin().getView()->getAppController().onPasteEntry();
976 0 : return 1L;
977 : }
978 : // -----------------------------------------------------------------------------
979 0 : IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
980 : {
981 0 : getBorderWin().getView()->getAppController().onDeleteEntry();
982 0 : return 1L;
983 : }
984 : // -----------------------------------------------------------------------------
985 0 : void OAppDetailPageHelper::Resize()
986 : {
987 : // parent window dimension
988 0 : Size aOutputSize( GetOutputSize() );
989 0 : long nOutputWidth = aOutputSize.Width();
990 0 : long nOutputHeight = aOutputSize.Height();
991 :
992 0 : Window* pWindow = getCurrentView();
993 0 : if ( pWindow )
994 : {
995 0 : Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
996 0 : sal_Int32 n6PPT = aFLSize.Height();
997 0 : long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
998 :
999 0 : pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
1000 :
1001 0 : m_aFL.SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
1002 :
1003 0 : String sText = m_aTBPreview.GetItemText(SID_DB_APP_DISABLE_PREVIEW);
1004 0 : Size aTBSize = m_aTBPreview.CalcWindowSizePixel();
1005 0 : m_aTBPreview.SetPosSizePixel(Point(nOutputWidth - aTBSize.getWidth(), 0 ),
1006 0 : aTBSize );
1007 :
1008 0 : m_aBorder.SetPosSizePixel(Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
1009 0 : Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
1010 0 : m_aPreview.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1011 0 : m_aDocumentInfo.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1012 0 : m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1013 : }
1014 0 : }
1015 : // -----------------------------------------------------------------------------
1016 0 : PreviewMode OAppDetailPageHelper::getPreviewMode()
1017 : {
1018 0 : return m_ePreviewMode;
1019 : }
1020 : // -----------------------------------------------------------------------------
1021 0 : sal_Bool OAppDetailPageHelper::isPreviewEnabled()
1022 : {
1023 0 : return m_ePreviewMode != E_PREVIEWNONE;
1024 : }
1025 : // -----------------------------------------------------------------------------
1026 0 : void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,sal_Bool _bForce)
1027 : {
1028 0 : if ( m_ePreviewMode != _eMode || _bForce )
1029 : {
1030 0 : m_ePreviewMode = _eMode;
1031 :
1032 0 : getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
1033 :
1034 0 : sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1035 0 : switch ( m_ePreviewMode )
1036 : {
1037 : case E_PREVIEWNONE:
1038 0 : nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1039 0 : break;
1040 : case E_DOCUMENT:
1041 0 : nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
1042 0 : break;
1043 : case E_DOCUMENTINFO:
1044 0 : if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1045 0 : nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1046 : else
1047 0 : m_ePreviewMode = E_PREVIEWNONE;
1048 0 : break;
1049 : }
1050 :
1051 0 : m_aMenu->CheckItem(nSelectedAction);
1052 0 : m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1053 0 : Resize();
1054 :
1055 : // simulate a selectionChanged event at the controller, to force the preview to be updated
1056 0 : if ( isPreviewEnabled() )
1057 : {
1058 0 : if ( getCurrentView() && getCurrentView()->FirstSelected() )
1059 : {
1060 0 : getBorderWin().getView()->getAppController().onSelectionChanged();
1061 : }
1062 : }
1063 : else
1064 : {
1065 0 : m_pTablePreview->Hide();
1066 0 : m_aPreview.Hide();
1067 0 : m_aDocumentInfo.Hide();
1068 : }
1069 : }
1070 0 : }
1071 : // -----------------------------------------------------------------------------
1072 0 : void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1073 : {
1074 0 : if ( isPreviewEnabled() )
1075 : {
1076 0 : m_pTablePreview->Hide();
1077 :
1078 0 : WaitObject aWaitCursor( this );
1079 : try
1080 : {
1081 0 : Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1082 0 : if ( xContent.is() )
1083 : {
1084 0 : com::sun::star::ucb::Command aCommand;
1085 0 : if ( m_ePreviewMode == E_DOCUMENT )
1086 0 : aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("preview"));
1087 : else
1088 0 : aCommand.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getDocumentInfo"));
1089 :
1090 0 : Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1091 0 : if ( m_ePreviewMode == E_DOCUMENT )
1092 : {
1093 0 : m_aDocumentInfo.Hide();
1094 0 : m_aPreview.Show();
1095 :
1096 0 : Graphic aGraphic;
1097 0 : Sequence < sal_Int8 > aBmpSequence;
1098 0 : if ( aPreview >>= aBmpSequence )
1099 : {
1100 0 : SvMemoryStream aData( aBmpSequence.getArray(),
1101 0 : aBmpSequence.getLength(),
1102 0 : STREAM_READ );
1103 :
1104 0 : GraphicConverter::Import(aData,aGraphic);
1105 : }
1106 0 : m_aPreview.setGraphic( aGraphic );
1107 0 : m_aPreview.Invalidate();
1108 : }
1109 : else
1110 : {
1111 0 : m_aPreview.Hide();
1112 0 : m_aDocumentInfo.clear();
1113 0 : m_aDocumentInfo.Show();
1114 : Reference<document::XDocumentProperties> xProp(
1115 0 : aPreview, UNO_QUERY);
1116 0 : if ( xProp.is() )
1117 0 : m_aDocumentInfo.fill(xProp,String());
1118 0 : }
1119 : }
1120 : else
1121 : {
1122 0 : m_aPreview.Hide();
1123 0 : m_aDocumentInfo.Hide();
1124 0 : }
1125 : }
1126 0 : catch( const Exception& )
1127 : {
1128 : DBG_UNHANDLED_EXCEPTION();
1129 0 : }
1130 : }
1131 0 : }
1132 : // -----------------------------------------------------------------------------
1133 0 : void OAppDetailPageHelper::showPreview( const ::rtl::OUString& _sDataSourceName,
1134 : const ::rtl::OUString& _sName,
1135 : sal_Bool _bTable)
1136 : {
1137 0 : if ( isPreviewEnabled() )
1138 : {
1139 0 : WaitObject aWaitCursor( this );
1140 0 : m_aPreview.Hide();
1141 0 : m_aDocumentInfo.Hide();
1142 0 : m_pTablePreview->Show();
1143 0 : if ( !m_xFrame.is() )
1144 : {
1145 : try
1146 : {
1147 0 : m_xFrame = Reference < XFrame > ( getBorderWin().getView()->getORB()->getServiceManager()->createInstanceWithContext( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Frame")), getBorderWin().getView()->getORB() ), UNO_QUERY );
1148 0 : m_xFrame->initialize( m_xWindow );
1149 :
1150 : // no layout manager (and thus no toolbars) in the preview
1151 : // Must be called after initialize ... but before any other call to this frame.
1152 : // Otherwise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1153 0 : Reference< XPropertySet > xFrameProps( m_xFrame, UNO_QUERY_THROW );
1154 0 : xFrameProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ), makeAny(Reference< XLayoutManager >()) );
1155 :
1156 0 : Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1157 0 : if ( xSup.is() )
1158 : {
1159 0 : Reference<XFrames> xFrames = xSup->getFrames();
1160 0 : xFrames->append(m_xFrame);
1161 0 : }
1162 : }
1163 0 : catch(const Exception&)
1164 : {
1165 : }
1166 : }
1167 :
1168 0 : Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1169 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1170 : ::std::auto_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1171 0 : uno::Reference<lang::XMultiServiceFactory>(getBorderWin().getView()->getORB()->getServiceManager(), uno::UNO_QUERY_THROW),
1172 : xApplication, NULL, _bTable
1173 0 : ) );
1174 : SAL_WNODEPRECATED_DECLARATIONS_POP
1175 0 : pDispatcher->setTargetFrame( m_xFrame );
1176 :
1177 0 : ::comphelper::NamedValueCollection aArgs;
1178 0 : aArgs.put( "Preview", sal_True );
1179 0 : aArgs.put( "ReadOnly", sal_True );
1180 0 : aArgs.put( "AsTemplate", sal_False );
1181 0 : aArgs.put( (::rtl::OUString)PROPERTY_SHOWMENU, sal_False );
1182 :
1183 0 : Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1184 0 : sal_Bool bClearPreview = !xPreview.is();
1185 :
1186 : // clear the preview when the query or table could not be loaded
1187 0 : if ( !bClearPreview )
1188 : {
1189 0 : Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1190 0 : bClearPreview = !xTabController.is();
1191 0 : if ( !bClearPreview )
1192 : {
1193 0 : Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1194 0 : bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1195 0 : }
1196 : }
1197 0 : if ( bClearPreview )
1198 0 : showPreview(NULL);
1199 : }
1200 0 : }
1201 : // -----------------------------------------------------------------------------
1202 0 : IMPL_LINK(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, /*pToolBox*/)
1203 : {
1204 0 : m_aTBPreview.EndSelection();
1205 :
1206 : // tell the toolbox that the item is pressed down
1207 0 : m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_True );
1208 :
1209 : // simulate a mouse move (so the "down" state is really painted)
1210 0 : Point aPoint = m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1211 0 : MouseEvent aMove( aPoint, 0, MOUSE_SIMPLEMOVE | MOUSE_SYNTHETIC );
1212 0 : m_aTBPreview.MouseMove( aMove );
1213 :
1214 0 : m_aTBPreview.Update();
1215 :
1216 : // execute the menu
1217 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1218 0 : ::std::auto_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1219 : SAL_WNODEPRECATED_DECLARATIONS_POP
1220 :
1221 : sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1222 : , SID_DB_APP_VIEW_DOC_PREVIEW
1223 : , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1224 0 : };
1225 :
1226 0 : for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1227 : {
1228 0 : aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1229 : }
1230 0 : aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1231 :
1232 : // no disabled entries
1233 0 : aMenu->RemoveDisabledEntries();
1234 :
1235 0 : sal_uInt16 nSelectedAction = aMenu->Execute(&m_aTBPreview, m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1236 : // "cleanup" the toolbox state
1237 0 : MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
1238 0 : m_aTBPreview.MouseMove( aLeave );
1239 0 : m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_False);
1240 0 : if ( nSelectedAction )
1241 : {
1242 0 : m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1243 0 : Resize();
1244 0 : getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1245 : }
1246 0 : return 0L;
1247 : }
1248 :
1249 : // -----------------------------------------------------------------------------
1250 0 : void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1251 : {
1252 0 : SvTreeListBox* pCurrentView = getCurrentView();
1253 : OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1254 :
1255 0 : KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1256 0 : sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1257 :
1258 0 : if ( ( KEY_RETURN == nCode ) && pCurrentView )
1259 : {
1260 0 : getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1261 : }
1262 : else
1263 0 : Window::KeyInput(rKEvt);
1264 0 : }
1265 :
1266 : // -----------------------------------------------------------------------------
1267 0 : void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1268 : {
1269 0 : Window::DataChanged( rDCEvt );
1270 :
1271 0 : if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1272 0 : (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1273 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1274 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1275 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1276 :
1277 : {
1278 0 : ImplInitSettings();
1279 0 : if ( m_pLists[ E_TABLE ] )
1280 : {
1281 0 : OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ] );
1282 : OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1283 0 : if ( pTableTree )
1284 0 : pTableTree->notifyHiContrastChanged();
1285 : }
1286 : }
1287 0 : }
1288 : // -----------------------------------------------------------------------------
1289 0 : void OAppDetailPageHelper::ImplInitSettings()
1290 : {
1291 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1292 0 : Font aFont;
1293 0 : aFont = rStyleSettings.GetFieldFont();
1294 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1295 0 : SetPointFont( aFont );
1296 0 : m_aTBPreview.SetPointFont( aFont );
1297 :
1298 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
1299 0 : SetTextFillColor();
1300 0 : m_aBorder.SetTextColor( rStyleSettings.GetFieldTextColor() );
1301 0 : m_aBorder.SetTextFillColor();
1302 0 : m_aTBPreview.SetTextColor( rStyleSettings.GetFieldTextColor() );
1303 0 : m_aTBPreview.SetTextFillColor();
1304 :
1305 0 : SetBackground( rStyleSettings.GetFieldColor() );
1306 0 : m_aBorder.SetBackground( rStyleSettings.GetFieldColor() );
1307 0 : m_aFL.SetBackground( rStyleSettings.GetFieldColor() );
1308 0 : m_aDocumentInfo.SetBackground( rStyleSettings.GetFieldColor() );
1309 0 : m_aTBPreview.SetBackground( rStyleSettings.GetFieldColor() );
1310 0 : m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1311 0 : }
1312 : // -----------------------------------------------------------------------------
1313 0 : OPreviewWindow::OPreviewWindow(Window* _pParent)
1314 0 : : Window(_pParent)
1315 : {
1316 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1317 0 : }
1318 : // -----------------------------------------------------------------------------
1319 0 : sal_Bool OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1320 : {
1321 0 : const Size aWinSize( GetOutputSizePixel() );
1322 0 : Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1323 0 : sal_Bool bRet = sal_False;
1324 :
1325 0 : if( aNewSize.Width() && aNewSize.Height() )
1326 : {
1327 : // scale to fit window
1328 0 : const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1329 0 : const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1330 :
1331 0 : if ( fGrfWH < fWinWH )
1332 : {
1333 0 : aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1334 0 : aNewSize.Height()= aWinSize.Height();
1335 : }
1336 : else
1337 : {
1338 0 : aNewSize.Width() = aWinSize.Width();
1339 0 : aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1340 : }
1341 :
1342 0 : const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
1343 0 : ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1344 :
1345 0 : rResultRect = Rectangle( aNewPos, aNewSize );
1346 0 : bRet = sal_True;
1347 : }
1348 :
1349 0 : return bRet;
1350 : }
1351 :
1352 : // ------------------------------------------------------------------------
1353 :
1354 0 : void OPreviewWindow::Paint( const Rectangle& rRect )
1355 : {
1356 0 : Window::Paint( rRect );
1357 :
1358 0 : if( ImplGetGraphicCenterRect( m_aGraphicObj.GetGraphic(), m_aPreviewRect ) )
1359 : {
1360 0 : const Point aPos( m_aPreviewRect.TopLeft() );
1361 0 : const Size aSize( m_aPreviewRect.GetSize() );
1362 :
1363 0 : if( m_aGraphicObj.IsAnimated() )
1364 0 : m_aGraphicObj.StartAnimation( this, aPos, aSize );
1365 : else
1366 0 : m_aGraphicObj.Draw( this, aPos, aSize );
1367 : }
1368 0 : }
1369 : // -----------------------------------------------------------------------------
1370 0 : void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1371 : {
1372 0 : Window::DataChanged( rDCEvt );
1373 :
1374 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1375 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1376 : {
1377 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1378 0 : Invalidate();
1379 : }
1380 0 : }
1381 : // -----------------------------------------------------------------------------
1382 0 : void OPreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
1383 : {
1384 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1385 0 : if( bFont )
1386 : {
1387 0 : Font aFont;
1388 0 : aFont = rStyleSettings.GetFieldFont();
1389 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1390 0 : SetPointFont( aFont );
1391 : }
1392 :
1393 0 : if( bForeground || bFont )
1394 : {
1395 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
1396 0 : SetTextFillColor();
1397 : }
1398 :
1399 0 : if( bBackground )
1400 0 : SetBackground( rStyleSettings.GetFieldColor() );
1401 0 : }
1402 : // -----------------------------------------------------------------------------
1403 : // -----------------------------------------------------------------------------
1404 :
1405 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|