Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / app / AppDetailPageHelper.cxx
blob56c0071b0ee397401e8f59ce893fa871c0c315c3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/awt/XTabController.hpp>
29 #include <com/sun/star/awt/XWindow.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/container/XChild.hpp>
32 #include <com/sun/star/container/XContainer.hpp>
33 #include <com/sun/star/form/XLoadable.hpp>
34 #include <com/sun/star/frame/XLayoutManager.hpp>
35 #include <com/sun/star/frame/Frame.hpp>
36 #include <com/sun/star/frame/FrameSearchFlag.hpp>
37 #include <com/sun/star/frame/XComponentLoader.hpp>
38 #include <com/sun/star/frame/XFrames.hpp>
39 #include <com/sun/star/frame/XFramesSupplier.hpp>
40 #include <com/sun/star/sdb/CommandType.hpp>
41 #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
42 #include <com/sun/star/sdb/application/DatabaseObject.hpp>
43 #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
44 #include <com/sun/star/sdbc/XConnection.hpp>
45 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
46 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
47 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
48 #include <com/sun/star/ucb/XCommandProcessor.hpp>
49 #include <com/sun/star/ucb/Command.hpp>
50 #include <com/sun/star/util/XCloseable.hpp>
51 #include <toolkit/helper/vclunohelper.hxx>
52 #include "AppView.hxx"
53 #include "dbaccess_helpid.hrc"
54 #include "dbu_app.hrc"
55 #include "callbacks.hxx"
56 #include <dbaccess/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 <vcl/settings.hxx>
63 #include <tools/stream.hxx>
64 #include <rtl/ustrbuf.hxx>
65 #include "IApplicationController.hxx"
66 #include "svtools/treelistentry.hxx"
68 #include <com/sun/star/document/XDocumentProperties.hpp>
70 #include <boost/scoped_ptr.hpp>
72 using namespace ::dbaui;
73 using namespace ::com::sun::star::container;
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::ucb;
76 using namespace ::com::sun::star::frame;
77 using namespace ::com::sun::star::form;
78 using namespace ::com::sun::star::sdb;
79 using namespace ::com::sun::star::sdb::application;
80 using namespace ::com::sun::star::sdbc;
81 using namespace ::com::sun::star::sdbcx;
82 using namespace ::com::sun::star::beans;
83 using namespace ::com::sun::star;
84 using ::com::sun::star::awt::XTabController;
86 namespace dbaui
88 namespace DatabaseObject = css::sdb::application::DatabaseObject;
89 namespace DatabaseObjectContainer = css::sdb::application::DatabaseObjectContainer;
92 namespace
94 SvTreeListEntry* lcl_findEntry_impl(DBTreeListBox& rTree,const OUString& _rName,SvTreeListEntry* _pFirst)
96 SvTreeListEntry* pReturn = NULL;
97 sal_Int32 nIndex = 0;
98 OUString sName( _rName.getToken(0,'/',nIndex) );
100 SvTreeListEntry* pEntry = _pFirst;
101 while( pEntry )
103 if ( rTree.GetEntryText(pEntry) == sName )
105 if ( nIndex != -1 )
107 sName = _rName.getToken(0,'/',nIndex);
108 pEntry = rTree.FirstChild(pEntry);
110 else
112 pReturn = pEntry;
113 break;
116 else
117 pEntry = SvTreeListBox::NextSibling(pEntry);
119 return pReturn;
121 SvTreeListEntry* lcl_findEntry(DBTreeListBox& rTree,const OUString& _rName,SvTreeListEntry* _pFirst)
123 sal_Int32 nIndex = 0;
124 OUString sErase = _rName.getToken(0,'/',nIndex); // we don't want to have the "private:forms" part
125 return (nIndex != -1 ? lcl_findEntry_impl(rTree,_rName.copy(sErase.getLength() + 1),_pFirst) : NULL);
127 // class OPreviewWindow
128 class OTablePreviewWindow : public vcl::Window
130 DECL_LINK(OnDisableInput, void*);
131 void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
132 protected:
133 virtual void DataChanged(const DataChangedEvent& rDCEvt) SAL_OVERRIDE;
134 public:
135 OTablePreviewWindow( vcl::Window* pParent, WinBits nStyle = 0 );
136 virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
138 OTablePreviewWindow::OTablePreviewWindow(vcl::Window* pParent, WinBits nStyle) : Window( pParent, nStyle)
140 ImplInitSettings( true, true, true );
142 bool OTablePreviewWindow::Notify( NotifyEvent& rNEvt )
144 bool nRet = Window::Notify( rNEvt );
145 if ( rNEvt.GetType() == MouseNotifyEvent::INPUTENABLE && IsInputEnabled() )
146 PostUserEvent( LINK( this, OTablePreviewWindow, OnDisableInput), NULL, true );
147 return nRet;
149 IMPL_LINK_NOARG(OTablePreviewWindow, OnDisableInput)
151 EnableInput(false);
152 return 0L;
154 void OTablePreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
156 Window::DataChanged( rDCEvt );
158 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
159 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
161 ImplInitSettings( true, true, true );
162 Invalidate();
165 void OTablePreviewWindow::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
167 //FIXME RenderContext
168 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
169 if( bFont )
171 vcl::Font aFont;
172 aFont = rStyleSettings.GetFieldFont();
173 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
174 SetPointFont(*this, aFont);
177 if( bForeground || bFont )
179 SetTextColor( rStyleSettings.GetFieldTextColor() );
180 SetTextFillColor();
183 if( bBackground )
184 SetBackground( rStyleSettings.GetFieldColor() );
189 // class OAppDetailPageHelper
190 OAppDetailPageHelper::OAppDetailPageHelper(vcl::Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode) : Window(_pParent,WB_DIALOGCONTROL)
191 ,m_rBorderWin(_rBorderWin)
192 ,m_aFL(VclPtr<FixedLine>::Create(this,WB_VERT))
193 ,m_aTBPreview(VclPtr<ToolBox>::Create(this,WB_TABSTOP) )
194 ,m_aBorder(VclPtr<Window>::Create(this,WB_BORDER | WB_READONLY))
195 ,m_aPreview(VclPtr<OPreviewWindow>::Create(m_aBorder.get()))
196 ,m_aDocumentInfo(VclPtr< ::svtools::ODocumentInfoPreview >::Create(m_aBorder.get(), WB_LEFT | WB_VSCROLL | WB_READONLY) )
197 ,m_ePreviewMode(_ePreviewMode)
200 m_aBorder->SetBorderStyle(WindowBorderStyle::MONO);
202 m_aMenu.reset(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
204 m_aTBPreview->SetOutStyle(TOOLBOX_STYLE_FLAT);
205 m_aTBPreview->InsertItem(SID_DB_APP_DISABLE_PREVIEW,m_aMenu->GetItemText(SID_DB_APP_DISABLE_PREVIEW),ToolBoxItemBits::LEFT|ToolBoxItemBits::DROPDOWN|ToolBoxItemBits::AUTOSIZE|ToolBoxItemBits::RADIOCHECK);
206 m_aTBPreview->SetHelpId(HID_APP_VIEW_PREVIEW_CB);
207 m_aTBPreview->SetDropdownClickHdl( LINK( this, OAppDetailPageHelper, OnDropdownClickHdl ) );
208 m_aTBPreview->EnableMenuStrings();
209 m_aTBPreview->Enable(true);
211 m_aBorder->SetUniqueId(UID_APP_VIEW_PREVIEW_1);
213 m_aPreview->SetHelpId(HID_APP_VIEW_PREVIEW_1);
215 m_pTablePreview.set( VclPtr<OTablePreviewWindow>::Create(m_aBorder.get(), WB_READONLY | WB_DIALOGCONTROL ) );
216 m_pTablePreview->SetHelpId(HID_APP_VIEW_PREVIEW_2);
218 m_aDocumentInfo->SetHelpId(HID_APP_VIEW_PREVIEW_3);
220 m_xWindow = VCLUnoHelper::GetInterface( m_pTablePreview );
222 SetUniqueId(UID_APP_DETAILPAGE_HELPER);
223 for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
224 m_pLists[i] = NULL;
225 ImplInitSettings();
228 OAppDetailPageHelper::~OAppDetailPageHelper()
230 disposeOnce();
233 void OAppDetailPageHelper::dispose()
237 Reference< ::util::XCloseable> xCloseable(m_xFrame,UNO_QUERY);
238 if ( xCloseable.is() )
239 xCloseable->close(sal_True);
241 catch(const Exception&)
243 OSL_FAIL("Exception thrown while disposing preview frame!");
246 for (int i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
248 if ( m_pLists[i] )
250 m_pLists[i]->clearCurrentSelection();
251 m_pLists[i]->Hide();
252 m_pLists[i]->clearCurrentSelection(); // why a second time?
253 m_pLists[i].disposeAndClear();
256 m_aMenu.reset();
257 m_pTablePreview.disposeAndClear();
258 m_aDocumentInfo.disposeAndClear();
259 m_aPreview.disposeAndClear();
260 m_aBorder.disposeAndClear();
261 m_aTBPreview.disposeAndClear();
262 m_aFL.disposeAndClear();
264 vcl::Window::dispose();
267 int OAppDetailPageHelper::getVisibleControlIndex() const
269 int i = 0;
270 for (; i < E_ELEMENT_TYPE_COUNT ; ++i)
272 if ( m_pLists[i] && m_pLists[i]->IsVisible() )
273 break;
275 return i;
278 void OAppDetailPageHelper::selectAll()
280 int nPos = getVisibleControlIndex();
281 if ( nPos < E_ELEMENT_TYPE_COUNT )
283 m_pLists[nPos]->SelectAll(true);
287 void OAppDetailPageHelper::sort(int _nPos,SvSortMode _eSortMode )
289 OSL_ENSURE(m_pLists[_nPos],"List can not be NULL! ->GPF");
290 SvTreeList* pModel = m_pLists[_nPos]->GetModel();
291 SvSortMode eOldSortMode = pModel->GetSortMode();
292 pModel->SetSortMode(_eSortMode);
293 if ( eOldSortMode != _eSortMode )
294 pModel->Resort();
297 bool OAppDetailPageHelper::isSortUp() const
299 SvSortMode eSortMode = SortNone;
300 int nPos = getVisibleControlIndex();
301 if ( nPos < E_ELEMENT_TYPE_COUNT )
303 SvTreeList* pModel = m_pLists[nPos]->GetModel();
304 eSortMode = pModel->GetSortMode();
306 return eSortMode == SortAscending;
309 void OAppDetailPageHelper::sortDown()
311 int nPos = getVisibleControlIndex();
312 if ( nPos < E_ELEMENT_TYPE_COUNT )
313 sort(nPos,SortDescending);
316 void OAppDetailPageHelper::sortUp()
318 int nPos = getVisibleControlIndex();
319 if ( nPos < E_ELEMENT_TYPE_COUNT )
320 sort(nPos,SortAscending);
323 void OAppDetailPageHelper::getSelectionElementNames( ::std::vector< OUString>& _rNames ) const
325 int nPos = getVisibleControlIndex();
326 if ( nPos < E_ELEMENT_TYPE_COUNT )
328 DBTreeListBox& rTree = *m_pLists[nPos];
329 sal_Int32 nCount = rTree.GetEntryCount();
330 _rNames.reserve(nCount);
331 SvTreeListEntry* pEntry = rTree.FirstSelected();
332 ElementType eType = getElementType();
333 while( pEntry )
335 if ( eType == E_TABLE )
337 if( rTree.GetChildCount(pEntry) == 0 )
338 _rNames.push_back( getQualifiedName( pEntry ) );
340 else
342 OUString sName = rTree.GetEntryText(pEntry);
343 SvTreeListEntry* pParent = rTree.GetParent(pEntry);
344 while(pParent)
346 sName = rTree.GetEntryText(pParent) + "/" + sName;
347 pParent = rTree.GetParent(pParent);
349 _rNames.push_back(sName);
351 pEntry = rTree.NextSelected(pEntry);
356 void OAppDetailPageHelper::describeCurrentSelectionForControl( const Control& _rControl, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
358 for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
360 if ( m_pLists[i] == &_rControl )
362 describeCurrentSelectionForType(static_cast<ElementType>(i), _out_rSelectedObjects);
363 return;
366 OSL_FAIL( "OAppDetailPageHelper::describeCurrentSelectionForControl: invalid control!" );
369 void OAppDetailPageHelper::describeCurrentSelectionForType( const ElementType _eType, Sequence< NamedDatabaseObject >& _out_rSelectedObjects )
371 OSL_ENSURE( _eType < E_ELEMENT_TYPE_COUNT, "OAppDetailPageHelper::describeCurrentSelectionForType: invalid type!" );
372 DBTreeListBox* pList = ( _eType < E_ELEMENT_TYPE_COUNT ) ? m_pLists[ _eType ].get() : NULL;
373 OSL_ENSURE( pList, "OAppDetailPageHelper::describeCurrentSelectionForType: "
374 "You really should ensure this type has already been viewed before!" );
375 if ( !pList )
376 return;
378 ::std::vector< NamedDatabaseObject > aSelected;
380 SvTreeListEntry* pEntry = pList->FirstSelected();
381 while( pEntry )
383 NamedDatabaseObject aObject;
384 switch ( _eType )
386 case E_TABLE:
388 OTableTreeListBox& rTableTree = dynamic_cast< OTableTreeListBox& >( *pList );
389 aObject = rTableTree.describeObject( pEntry );
391 break;
392 case E_QUERY:
393 aObject.Type = DatabaseObject::QUERY;
394 aObject.Name = pList->GetEntryText( pEntry );
395 break;
397 case E_FORM:
398 case E_REPORT:
400 OUString sName = pList->GetEntryText(pEntry);
401 SvTreeListEntry* pParent = pList->GetParent(pEntry);
402 while ( pParent )
404 OUStringBuffer buffer;
405 buffer.append( pList->GetEntryText( pParent ) );
406 buffer.append( '/' );
407 buffer.append( sName );
408 sName = buffer.makeStringAndClear();
410 pParent = pList->GetParent( pParent );
413 if ( isLeaf( pEntry ) )
414 aObject.Type = ( _eType == E_FORM ) ? DatabaseObject::FORM : DatabaseObject::REPORT;
415 else
416 aObject.Type = ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER : DatabaseObjectContainer::REPORTS_FOLDER;
417 aObject.Name = sName;
419 break;
420 default:
421 OSL_FAIL( "OAppDetailPageHelper::describeCurrentSelectionForType: unexpected type!" );
422 break;
425 if ( !aObject.Name.isEmpty() )
427 aSelected.push_back( aObject );
430 pEntry = pList->NextSelected(pEntry);
433 _out_rSelectedObjects.realloc( aSelected.size() );
434 ::std::copy( aSelected.begin(), aSelected.end(), _out_rSelectedObjects.getArray() );
437 void OAppDetailPageHelper::selectElements(const Sequence< OUString>& _aNames)
439 int nPos = getVisibleControlIndex();
440 if ( nPos < E_ELEMENT_TYPE_COUNT )
442 DBTreeListBox& rTree = *m_pLists[nPos];
443 rTree.SelectAll(false);
444 const OUString* pIter = _aNames.getConstArray();
445 const OUString* pEnd = pIter + _aNames.getLength();
446 for(;pIter != pEnd;++pIter)
448 SvTreeListEntry* pEntry = rTree.GetEntryPosByName(*pIter);
449 if ( pEntry )
450 rTree.Select(pEntry);
455 OUString OAppDetailPageHelper::getQualifiedName( SvTreeListEntry* _pEntry ) const
457 int nPos = getVisibleControlIndex();
458 OUString sComposedName;
460 if ( nPos >= E_ELEMENT_TYPE_COUNT )
461 return sComposedName;
463 OSL_ENSURE(m_pLists[nPos],"Tables tree view is NULL! -> GPF");
464 DBTreeListBox& rTree = *m_pLists[nPos];
466 SvTreeListEntry* pEntry = _pEntry;
467 if ( !pEntry )
468 pEntry = rTree.FirstSelected();
470 if ( !pEntry )
471 return sComposedName;
473 if ( getElementType() == E_TABLE )
475 const OTableTreeListBox& rTreeView = dynamic_cast< const OTableTreeListBox& >( *m_pLists[nPos] );
476 sComposedName = rTreeView.getQualifiedTableName( pEntry );
478 else
480 sComposedName = rTree.GetEntryText(pEntry);
481 SvTreeListEntry* pParent = rTree.GetParent(pEntry);
482 while(pParent)
484 sComposedName = rTree.GetEntryText(pParent) + "/" + sComposedName;
485 pParent = rTree.GetParent(pParent);
489 return sComposedName;
492 ElementType OAppDetailPageHelper::getElementType() const
494 int nPos = getVisibleControlIndex();
495 return static_cast<ElementType>(nPos);
498 sal_Int32 OAppDetailPageHelper::getSelectionCount()
500 sal_Int32 nCount = 0;
501 int nPos = getVisibleControlIndex();
502 if ( nPos < E_ELEMENT_TYPE_COUNT )
504 DBTreeListBox& rTree = *m_pLists[nPos];
505 SvTreeListEntry* pEntry = rTree.FirstSelected();
506 while( pEntry )
508 ++nCount;
509 pEntry = rTree.NextSelected(pEntry);
512 return nCount;
515 sal_Int32 OAppDetailPageHelper::getElementCount()
517 sal_Int32 nCount = 0;
518 int nPos = getVisibleControlIndex();
519 if ( nPos < E_ELEMENT_TYPE_COUNT )
521 nCount = m_pLists[nPos]->GetEntryCount();
523 return nCount;
526 bool OAppDetailPageHelper::isLeaf(SvTreeListEntry* _pEntry)
528 if ( !_pEntry )
529 return false;
530 sal_Int32 nEntryType = reinterpret_cast< sal_IntPtr >( _pEntry->GetUserData() );
531 if ( ( nEntryType == DatabaseObjectContainer::TABLES )
532 || ( nEntryType == DatabaseObjectContainer::CATALOG )
533 || ( nEntryType == DatabaseObjectContainer::SCHEMA )
534 || ( nEntryType == DatabaseObjectContainer::FORMS_FOLDER )
535 || ( nEntryType == DatabaseObjectContainer::REPORTS_FOLDER )
537 return false;
539 return true;
542 bool OAppDetailPageHelper::isALeafSelected() const
544 int nPos = getVisibleControlIndex();
545 bool bLeafSelected = false;
546 if ( nPos < E_ELEMENT_TYPE_COUNT )
548 DBTreeListBox& rTree = *m_pLists[nPos];
549 SvTreeListEntry* pEntry = rTree.FirstSelected( );
550 while( !bLeafSelected && pEntry )
552 bLeafSelected = isLeaf( pEntry );
553 pEntry = rTree.NextSelected(pEntry);
556 return bLeafSelected;
559 SvTreeListEntry* OAppDetailPageHelper::getEntry( const Point& _aPosPixel) const
561 SvTreeListEntry* pReturn = NULL;
562 int nPos = getVisibleControlIndex();
563 if ( nPos < E_ELEMENT_TYPE_COUNT )
564 pReturn = m_pLists[nPos]->GetEntry( _aPosPixel, true );
565 return pReturn;
568 void OAppDetailPageHelper::createTablesPage(const Reference< XConnection>& _xConnection)
570 OSL_ENSURE(_xConnection.is(),"Connection is NULL! -> GPF");
572 if ( !m_pLists[E_TABLE] )
574 VclPtrInstance<OTableTreeListBox> pTreeView(this,
575 WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
576 pTreeView->SetHelpId(HID_APP_TABLE_TREE);
577 m_pLists[E_TABLE] = pTreeView;
579 ImageProvider aImageProvider( _xConnection );
580 createTree( pTreeView,
581 ImageProvider::getDefaultImage( DatabaseObject::TABLE )
584 pTreeView->notifyHiContrastChanged();
585 m_aBorder->SetZOrder(pTreeView, WINDOW_ZORDER_BEHIND);
587 if ( !m_pLists[E_TABLE]->GetEntryCount() )
589 static_cast<OTableTreeListBox*>(m_pLists[E_TABLE].get())->UpdateTableList(_xConnection);
591 SvTreeListEntry* pEntry = m_pLists[E_TABLE]->First();
592 if ( pEntry )
593 m_pLists[E_TABLE]->Expand(pEntry);
594 m_pLists[E_TABLE]->SelectAll(false);
597 setDetailPage(m_pLists[E_TABLE]);
600 void OAppDetailPageHelper::getElementIcons( ElementType _eType, sal_uInt16& _rImageId)
602 ImageProvider aImageProvider;
603 _rImageId = 0;
605 sal_Int32 nDatabaseObjectType( 0 );
606 switch(_eType )
608 case E_FORM: nDatabaseObjectType = DatabaseObject::FORM; break;
609 case E_REPORT: nDatabaseObjectType = DatabaseObject::REPORT; break;
610 case E_QUERY: nDatabaseObjectType = DatabaseObject::QUERY; break;
611 default:
612 OSL_FAIL( "OAppDetailPageHelper::GetElementIcons: invalid element type!" );
613 return;
615 _rImageId = ImageProvider::getDefaultImageResourceID( nDatabaseObjectType );
618 void OAppDetailPageHelper::createPage(ElementType _eType,const Reference< XNameAccess >& _xContainer)
620 OSL_ENSURE(E_TABLE != _eType,"E_TABLE isn't allowed.");
622 sal_uInt16 nImageId = 0;
623 OString sHelpId;
624 ImageProvider aImageProvider;
625 Image aFolderImage;
626 switch( _eType )
628 case E_FORM:
629 sHelpId = HID_APP_FORM_TREE;
630 aFolderImage = ImageProvider::getFolderImage( DatabaseObject::FORM );
631 break;
632 case E_REPORT:
633 sHelpId = HID_APP_REPORT_TREE;
634 aFolderImage = ImageProvider::getFolderImage( DatabaseObject::REPORT );
635 break;
636 case E_QUERY:
637 sHelpId = HID_APP_QUERY_TREE;
638 aFolderImage = ImageProvider::getFolderImage( DatabaseObject::QUERY );
639 break;
640 default:
641 OSL_FAIL("Illegal call!");
643 getElementIcons( _eType, nImageId );
645 if ( !m_pLists[_eType] )
647 m_pLists[_eType] = createSimpleTree( sHelpId, aFolderImage );
650 if ( m_pLists[_eType] )
652 if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() )
654 fillNames( _xContainer, _eType, nImageId, NULL );
656 m_pLists[_eType]->SelectAll(false);
658 setDetailPage(m_pLists[_eType]);
662 void OAppDetailPageHelper::setDetailPage(vcl::Window* _pWindow)
664 OSL_ENSURE(_pWindow,"OAppDetailPageHelper::setDetailPage: Window is NULL!");
665 vcl::Window* pCurrent = getCurrentView();
666 if ( pCurrent )
667 pCurrent->Hide();
669 showPreview(NULL);
670 bool bHasFocus = false;
671 m_aFL->Show();
673 bHasFocus = pCurrent != 0 && pCurrent->HasChildPathFocus();
674 _pWindow->Show();
676 m_aTBPreview->Show();
677 m_aBorder->Show();
678 switchPreview(m_ePreviewMode,true);
680 if ( bHasFocus )
681 _pWindow->GrabFocus();
682 Resize();
685 namespace
687 namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
688 namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
690 static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType )
692 const sal_Int32 nFolderIndicator =
693 ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER
694 : ( _eType == E_REPORT ) ? DatabaseObjectContainer::REPORTS_FOLDER : -1;
695 return nFolderIndicator;
699 void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType,
700 const sal_uInt16 _nImageId, SvTreeListEntry* _pParent )
702 OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF");
703 OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" );
705 DBTreeListBox* pList = m_pLists[ _eType ];
706 OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" );
707 if ( !pList )
708 return;
710 if ( _xContainer.is() && _xContainer->hasElements() )
712 const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
714 Sequence< OUString> aSeq = _xContainer->getElementNames();
715 const OUString* pIter = aSeq.getConstArray();
716 const OUString* pEnd = pIter + aSeq.getLength();
717 for(;pIter != pEnd;++pIter)
719 SvTreeListEntry* pEntry = NULL;
720 Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY);
721 if ( xSubElements.is() )
723 pEntry = pList->InsertEntry( *pIter, _pParent, false, TREELIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
724 getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) );
725 fillNames( xSubElements, _eType, _nImageId, pEntry );
727 else
729 pEntry = pList->InsertEntry( *pIter, _pParent );
731 Image aImage = Image( ModuleRes( _nImageId ) );
732 pList->SetExpandedEntryBmp( pEntry, aImage );
733 pList->SetCollapsedEntryBmp( pEntry, aImage );
739 DBTreeListBox* OAppDetailPageHelper::createSimpleTree( const OString& _sHelpId, const Image& _rImage)
741 VclPtrInstance<DBTreeListBox> pTreeView(this,
742 WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
743 pTreeView->SetHelpId( _sHelpId );
744 return createTree( pTreeView, _rImage );
747 DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage )
749 WaitObject aWaitCursor(this);
751 _pTreeView->SetStyle(_pTreeView->GetStyle() | WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
752 _pTreeView->GetModel()->SetSortMode(SortAscending);
753 _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
754 _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
756 _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
757 _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
759 _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
760 _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
761 _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
763 _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
764 _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
765 _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
766 _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
768 _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
769 _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
771 return _pTreeView;
774 void OAppDetailPageHelper::clearPages()
776 showPreview(NULL);
777 for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
779 if ( m_pLists[i] )
780 m_pLists[i]->Clear();
784 bool OAppDetailPageHelper::isFilled() const
786 size_t i = 0;
787 for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
789 return i != E_ELEMENT_TYPE_COUNT;
792 void OAppDetailPageHelper::elementReplaced(ElementType _eType
793 ,const OUString& _rOldName
794 ,const OUString& _rNewName )
796 DBTreeListBox* pTreeView = getCurrentView();
797 if ( pTreeView )
799 OUString sNewName = _rNewName;
800 SvTreeListEntry* pEntry = NULL;
801 switch( _eType )
803 case E_TABLE:
804 static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
805 static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
806 return;
808 case E_QUERY:
809 pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
810 break;
811 case E_FORM:
812 case E_REPORT:
813 pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
814 break;
815 default:
816 OSL_FAIL("Invalid element type");
818 OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
819 if ( pEntry )
821 pTreeView->SetEntryText(pEntry,sNewName);
826 SvTreeListEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const OUString& _rName, const Any& _rObject )
828 SvTreeListEntry* pRet = NULL;
829 DBTreeListBox* pTreeView = m_pLists[_eType];
830 if( _eType == E_TABLE && pTreeView )
832 pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
834 else if ( pTreeView )
837 SvTreeListEntry* pEntry = NULL;
838 Reference<XChild> xChild(_rObject,UNO_QUERY);
839 if ( xChild.is() && E_QUERY != _eType )
841 Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
842 if ( xContent.is() )
844 OUString sName = xContent->getIdentifier()->getContentIdentifier();
845 pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
849 sal_uInt16 nImageId = 0;
850 getElementIcons( _eType, nImageId );
851 Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
852 if ( xContainer.is() )
854 const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
855 pRet = pTreeView->InsertEntry( _rName, pEntry, false, TREELIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
856 fillNames( xContainer, _eType, nImageId, pRet );
858 else
860 pRet = pTreeView->InsertEntry( _rName, pEntry );
862 Image aImage = Image( ModuleRes( nImageId ) );
863 pTreeView->SetExpandedEntryBmp( pRet, aImage );
864 pTreeView->SetCollapsedEntryBmp( pRet, aImage );
867 return pRet;
870 void OAppDetailPageHelper::elementRemoved( ElementType _eType,const OUString& _rName )
872 DBTreeListBox* pTreeView = getCurrentView();
873 if ( pTreeView )
875 switch( _eType )
877 case E_TABLE:
878 // we don't need to clear the table here, it is already done by the dispose listener
879 static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
880 break;
881 case E_QUERY:
882 if ( pTreeView )
884 SvTreeListEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
885 if ( pEntry )
886 pTreeView->GetModel()->Remove(pEntry);
888 break;
889 case E_FORM:
890 case E_REPORT:
892 if ( pTreeView )
894 SvTreeListEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
895 if ( pEntry )
896 pTreeView->GetModel()->Remove(pEntry);
899 break;
900 default:
901 OSL_FAIL("Invalid element type");
903 if ( !pTreeView->GetEntryCount() )
904 showPreview(NULL);
908 IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
910 OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
911 bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
912 return bHandled ? 1L : 0L;
915 IMPL_LINK_NOARG(OAppDetailPageHelper, OnEntrySelChange)
917 getBorderWin().getView()->getAppController().onSelectionChanged();
918 return 1L;
921 IMPL_LINK_NOARG( OAppDetailPageHelper, OnCutEntry )
923 getBorderWin().getView()->getAppController().onCutEntry();
924 return 1L;
927 IMPL_LINK_NOARG( OAppDetailPageHelper, OnCopyEntry )
929 getBorderWin().getView()->getAppController().onCopyEntry();
930 return 1L;
933 IMPL_LINK_NOARG( OAppDetailPageHelper, OnPasteEntry )
935 getBorderWin().getView()->getAppController().onPasteEntry();
936 return 1L;
939 IMPL_LINK_NOARG( OAppDetailPageHelper, OnDeleteEntry )
941 getBorderWin().getView()->getAppController().onDeleteEntry();
942 return 1L;
945 void OAppDetailPageHelper::Resize()
947 // parent window dimension
948 Size aOutputSize( GetOutputSize() );
949 long nOutputWidth = aOutputSize.Width();
950 long nOutputHeight = aOutputSize.Height();
952 vcl::Window* pWindow = getCurrentView();
953 if ( pWindow )
955 Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
956 sal_Int32 n6PPT = aFLSize.Height();
957 long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
959 pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
961 m_aFL->SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
963 Size aTBSize = m_aTBPreview->CalcWindowSizePixel();
964 m_aTBPreview->SetPosSizePixel(Point(nOutputWidth - aTBSize.getWidth(), 0 ),
965 aTBSize );
967 m_aBorder->SetPosSizePixel(Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
968 Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
969 m_aPreview->SetPosSizePixel(Point(0,0),m_aBorder->GetSizePixel() );
970 m_aDocumentInfo->SetPosSizePixel(Point(0,0),m_aBorder->GetSizePixel() );
971 m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder->GetSizePixel() );
976 bool OAppDetailPageHelper::isPreviewEnabled()
978 return m_ePreviewMode != E_PREVIEWNONE;
981 void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,bool _bForce)
983 if ( m_ePreviewMode != _eMode || _bForce )
985 m_ePreviewMode = _eMode;
987 getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
989 sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
990 switch ( m_ePreviewMode )
992 case E_PREVIEWNONE:
993 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
994 break;
995 case E_DOCUMENT:
996 nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
997 break;
998 case E_DOCUMENTINFO:
999 if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1000 nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1001 else
1002 m_ePreviewMode = E_PREVIEWNONE;
1003 break;
1006 m_aMenu->CheckItem(nSelectedAction);
1007 m_aTBPreview->SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1008 Resize();
1010 // simulate a selectionChanged event at the controller, to force the preview to be updated
1011 if ( isPreviewEnabled() )
1013 if ( getCurrentView() && getCurrentView()->FirstSelected() )
1015 getBorderWin().getView()->getAppController().onSelectionChanged();
1018 else
1020 m_pTablePreview->Hide();
1021 m_aPreview->Hide();
1022 m_aDocumentInfo->Hide();
1027 void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1029 if ( isPreviewEnabled() )
1031 m_pTablePreview->Hide();
1033 WaitObject aWaitCursor( this );
1036 Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1037 if ( xContent.is() )
1039 com::sun::star::ucb::Command aCommand;
1040 if ( m_ePreviewMode == E_DOCUMENT )
1041 aCommand.Name = "preview";
1042 else
1043 aCommand.Name = "getDocumentInfo";
1045 Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1046 if ( m_ePreviewMode == E_DOCUMENT )
1048 m_aDocumentInfo->Hide();
1049 m_aPreview->Show();
1051 Graphic aGraphic;
1052 Sequence < sal_Int8 > aBmpSequence;
1053 if ( aPreview >>= aBmpSequence )
1055 SvMemoryStream aData( aBmpSequence.getArray(),
1056 aBmpSequence.getLength(),
1057 StreamMode::READ );
1059 GraphicConverter::Import(aData,aGraphic);
1061 m_aPreview->setGraphic( aGraphic );
1062 m_aPreview->Invalidate();
1064 else
1066 m_aPreview->Hide();
1067 m_aDocumentInfo->clear();
1068 m_aDocumentInfo->Show();
1069 Reference<document::XDocumentProperties> xProp(
1070 aPreview, UNO_QUERY);
1071 if ( xProp.is() )
1072 m_aDocumentInfo->fill(xProp,OUString());
1075 else
1077 m_aPreview->Hide();
1078 m_aDocumentInfo->Hide();
1081 catch( const Exception& )
1083 DBG_UNHANDLED_EXCEPTION();
1088 void OAppDetailPageHelper::showPreview( const OUString& _sDataSourceName,
1089 const OUString& _sName,
1090 bool _bTable)
1092 if ( isPreviewEnabled() )
1094 WaitObject aWaitCursor( this );
1095 m_aPreview->Hide();
1096 m_aDocumentInfo->Hide();
1097 m_pTablePreview->Show();
1098 if ( !m_xFrame.is() )
1102 m_xFrame = Frame::create( getBorderWin().getView()->getORB() );
1103 m_xFrame->initialize( m_xWindow );
1105 // no layout manager (and thus no toolbars) in the preview
1106 // Must be called after initialize ... but before any other call to this frame.
1107 // Otherwise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1108 m_xFrame->setLayoutManager( Reference< XLayoutManager >() );
1110 Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1111 if ( xSup.is() )
1113 Reference<XFrames> xFrames = xSup->getFrames();
1114 xFrames->append( Reference<XFrame>(m_xFrame,UNO_QUERY_THROW));
1117 catch(const Exception&)
1122 Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1123 boost::scoped_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1124 getBorderWin().getView()->getORB(),
1125 xApplication, NULL, _bTable
1126 ) );
1127 pDispatcher->setTargetFrame( Reference<XFrame>(m_xFrame,UNO_QUERY_THROW) );
1129 ::comphelper::NamedValueCollection aArgs;
1130 aArgs.put( "Preview", sal_True );
1131 aArgs.put( "ReadOnly", sal_True );
1132 aArgs.put( "AsTemplate", sal_False );
1133 aArgs.put( OUString(PROPERTY_SHOWMENU), sal_False );
1135 Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1136 bool bClearPreview = !xPreview.is();
1138 // clear the preview when the query or table could not be loaded
1139 if ( !bClearPreview )
1141 Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1142 bClearPreview = !xTabController.is();
1143 if ( !bClearPreview )
1145 Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1146 bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1149 if ( bClearPreview )
1150 showPreview(NULL);
1154 IMPL_LINK_NOARG_TYPED(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, void)
1156 m_aTBPreview->EndSelection();
1158 // tell the toolbox that the item is pressed down
1159 m_aTBPreview->SetItemDown( SID_DB_APP_DISABLE_PREVIEW, true );
1161 // simulate a mouse move (so the "down" state is really painted)
1162 Point aPoint = m_aTBPreview->GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1163 MouseEvent aMove( aPoint, 0, MouseEventModifiers::SIMPLEMOVE | MouseEventModifiers::SYNTHETIC );
1164 m_aTBPreview->MouseMove( aMove );
1166 m_aTBPreview->Update();
1168 // execute the menu
1169 boost::scoped_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1171 sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1172 , SID_DB_APP_VIEW_DOC_PREVIEW
1173 , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1176 for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1178 aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1180 aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1182 // no disabled entries
1183 aMenu->RemoveDisabledEntries();
1185 sal_uInt16 nSelectedAction = aMenu->Execute(m_aTBPreview.get(), m_aTBPreview->GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1186 // "cleanup" the toolbox state
1187 MouseEvent aLeave( aPoint, 0, MouseEventModifiers::LEAVEWINDOW | MouseEventModifiers::SYNTHETIC );
1188 m_aTBPreview->MouseMove( aLeave );
1189 m_aTBPreview->SetItemDown( SID_DB_APP_DISABLE_PREVIEW, false);
1190 if ( nSelectedAction )
1192 m_aTBPreview->SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1193 Resize();
1194 getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1198 void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1200 SvTreeListBox* pCurrentView = getCurrentView();
1201 OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1203 KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1204 sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1206 if ( ( KEY_RETURN == nCode ) && pCurrentView )
1208 getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1210 else
1211 Window::KeyInput(rKEvt);
1214 void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1216 Window::DataChanged( rDCEvt );
1218 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
1219 (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
1220 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
1221 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1222 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
1225 ImplInitSettings();
1226 if ( m_pLists[ E_TABLE ] )
1228 OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ].get() );
1229 OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1230 if ( pTableTree )
1231 pTableTree->notifyHiContrastChanged();
1236 void OAppDetailPageHelper::ImplInitSettings()
1238 // FIXME RenderContext
1239 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1240 vcl::Font aFont;
1241 aFont = rStyleSettings.GetFieldFont();
1242 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1243 SetPointFont(*this, aFont);
1244 m_aTBPreview->SetPointFont(*m_aTBPreview, aFont);
1246 SetTextColor( rStyleSettings.GetFieldTextColor() );
1247 SetTextFillColor();
1248 m_aBorder->SetTextColor( rStyleSettings.GetFieldTextColor() );
1249 m_aBorder->SetTextFillColor();
1250 m_aTBPreview->SetTextColor( rStyleSettings.GetFieldTextColor() );
1251 m_aTBPreview->SetTextFillColor();
1252 SetBackground( rStyleSettings.GetFieldColor() );
1253 m_aBorder->SetBackground( rStyleSettings.GetFieldColor() );
1254 m_aFL->SetBackground( rStyleSettings.GetFieldColor() );
1255 m_aDocumentInfo->SetBackground( rStyleSettings.GetFieldColor() );
1256 m_aTBPreview->SetBackground( rStyleSettings.GetFieldColor() );
1257 m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1260 OPreviewWindow::OPreviewWindow(vcl::Window* _pParent)
1261 : Window(_pParent)
1263 ImplInitSettings( true, true, true );
1266 bool OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1268 const Size aWinSize( GetOutputSizePixel() );
1269 Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1270 bool bRet = false;
1272 if( aNewSize.Width() && aNewSize.Height() )
1274 // scale to fit window
1275 const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1276 const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1278 if ( fGrfWH < fWinWH )
1280 aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1281 aNewSize.Height()= aWinSize.Height();
1283 else
1285 aNewSize.Width() = aWinSize.Width();
1286 aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1289 const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
1290 ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1292 rResultRect = Rectangle( aNewPos, aNewSize );
1293 bRet = true;
1296 return bRet;
1299 void OPreviewWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
1301 Window::Paint(rRenderContext, rRect);
1303 if (ImplGetGraphicCenterRect(m_aGraphicObj.GetGraphic(), m_aPreviewRect))
1305 const Point aPos(m_aPreviewRect.TopLeft());
1306 const Size aSize(m_aPreviewRect.GetSize());
1308 if (m_aGraphicObj.IsAnimated())
1309 m_aGraphicObj.StartAnimation(&rRenderContext, aPos, aSize);
1310 else
1311 m_aGraphicObj.Draw(&rRenderContext, aPos, aSize);
1315 void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1317 Window::DataChanged( rDCEvt );
1319 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1320 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
1322 ImplInitSettings( true, true, true );
1323 Invalidate();
1327 void OPreviewWindow::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
1329 // FIXME RenderContext
1330 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1331 if( bFont )
1333 vcl::Font aFont;
1334 aFont = rStyleSettings.GetFieldFont();
1335 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1336 SetPointFont(*this, aFont);
1339 if( bForeground || bFont )
1341 SetTextColor( rStyleSettings.GetFieldTextColor() );
1342 SetTextFillColor();
1345 if( bBackground )
1346 SetBackground( rStyleSettings.GetFieldColor() );
1349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */