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/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 <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 OUString& _rName,SvTreeListEntry* _pFirst)
93 : {
94 0 : SvTreeListEntry* pReturn = NULL;
95 0 : sal_Int32 nIndex = 0;
96 0 : OUString 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 OUString& _rName,SvTreeListEntry* _pFirst)
120 : {
121 0 : sal_Int32 nIndex = 0;
122 0 : 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< 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 : OUString sName = rTree.GetEntryText(pEntry);
343 0 : SvTreeListEntry* pParent = rTree.GetParent(pEntry);
344 0 : while(pParent)
345 : {
346 0 : sName = rTree.GetEntryText(pParent) + OUString("/") + 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 : OUString sName = pList->GetEntryText(pEntry);
404 0 : SvTreeListEntry* pParent = pList->GetParent(pEntry);
405 0 : while ( pParent )
406 : {
407 0 : 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< 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 OUString* pIter = _aNames.getConstArray();
449 0 : const 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 : OUString OAppDetailPageHelper::getQualifiedName( SvTreeListEntry* _pEntry ) const
460 : {
461 0 : int nPos = getVisibleControlIndex();
462 0 : 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) + OUString("/") + 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 0 : || ( nEntryType == DatabaseObjectContainer::CATALOG )
564 0 : || ( nEntryType == DatabaseObjectContainer::SCHEMA )
565 0 : || ( nEntryType == DatabaseObjectContainer::FORMS_FOLDER )
566 0 : || ( 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 : ,WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP
608 0 : ,sal_False);
609 0 : pTreeView->SetHelpId(HID_APP_TABLE_TREE);
610 0 : m_pLists[E_TABLE] = pTreeView;
611 :
612 0 : ImageProvider aImageProvider( _xConnection );
613 : createTree( pTreeView,
614 : aImageProvider.getDefaultImage( DatabaseObject::TABLE )
615 0 : );
616 :
617 0 : pTreeView->notifyHiContrastChanged();
618 0 : m_aBorder.SetZOrder(pTreeView, WINDOW_ZORDER_BEHIND);
619 : }
620 0 : if ( !m_pLists[E_TABLE]->GetEntryCount() )
621 : {
622 0 : static_cast<OTableTreeListBox*>(m_pLists[E_TABLE])->UpdateTableList(_xConnection);
623 :
624 0 : SvTreeListEntry* pEntry = m_pLists[E_TABLE]->First();
625 0 : if ( pEntry )
626 0 : m_pLists[E_TABLE]->Expand(pEntry);
627 0 : m_pLists[E_TABLE]->SelectAll(sal_False);
628 : }
629 :
630 0 : setDetailPage(m_pLists[E_TABLE]);
631 0 : }
632 :
633 : // -----------------------------------------------------------------------------
634 0 : void OAppDetailPageHelper::getElementIcons( ElementType _eType, sal_uInt16& _rImageId)
635 : {
636 0 : ImageProvider aImageProvider;
637 0 : _rImageId = 0;
638 :
639 0 : sal_Int32 nDatabaseObjectType( 0 );
640 0 : switch(_eType )
641 : {
642 0 : case E_FORM: nDatabaseObjectType = DatabaseObject::FORM; break;
643 0 : case E_REPORT: nDatabaseObjectType = DatabaseObject::REPORT; break;
644 0 : case E_QUERY: nDatabaseObjectType = DatabaseObject::QUERY; break;
645 : default:
646 : OSL_FAIL( "OAppDetailPageHelper::GetElementIcons: invalid element type!" );
647 0 : return;
648 : }
649 0 : _rImageId = aImageProvider.getDefaultImageResourceID( nDatabaseObjectType );
650 : }
651 :
652 : // -----------------------------------------------------------------------------
653 0 : void OAppDetailPageHelper::createPage(ElementType _eType,const Reference< XNameAccess >& _xContainer)
654 : {
655 : OSL_ENSURE(E_TABLE != _eType,"E_TABLE isn't allowed.");
656 :
657 0 : sal_uInt16 nImageId = 0;
658 0 : OString sHelpId;
659 0 : ImageProvider aImageProvider;
660 0 : Image aFolderImage;
661 0 : switch( _eType )
662 : {
663 : case E_FORM:
664 0 : sHelpId = HID_APP_FORM_TREE;
665 0 : aFolderImage = aImageProvider.getFolderImage( DatabaseObject::FORM );
666 0 : break;
667 : case E_REPORT:
668 0 : sHelpId = HID_APP_REPORT_TREE;
669 0 : aFolderImage = aImageProvider.getFolderImage( DatabaseObject::REPORT );
670 0 : break;
671 : case E_QUERY:
672 0 : sHelpId = HID_APP_QUERY_TREE;
673 0 : aFolderImage = aImageProvider.getFolderImage( DatabaseObject::QUERY );
674 0 : break;
675 : default:
676 : OSL_FAIL("Illegal call!");
677 : }
678 0 : getElementIcons( _eType, nImageId );
679 :
680 0 : if ( !m_pLists[_eType] )
681 : {
682 0 : m_pLists[_eType] = createSimpleTree( sHelpId, aFolderImage );
683 : }
684 :
685 0 : if ( m_pLists[_eType] )
686 : {
687 0 : if ( !m_pLists[_eType]->GetEntryCount() && _xContainer.is() )
688 : {
689 0 : fillNames( _xContainer, _eType, nImageId, NULL );
690 :
691 0 : m_pLists[_eType]->SelectAll(sal_False);
692 : }
693 0 : setDetailPage(m_pLists[_eType]);
694 0 : }
695 0 : }
696 : // -----------------------------------------------------------------------------
697 0 : void OAppDetailPageHelper::setDetailPage(Window* _pWindow)
698 : {
699 : OSL_ENSURE(_pWindow,"OAppDetailPageHelper::setDetailPage: Window is NULL!");
700 0 : Window* pCurrent = getCurrentView();
701 0 : if ( pCurrent )
702 0 : pCurrent->Hide();
703 :
704 0 : showPreview(NULL);
705 0 : sal_Bool bHasFocus = sal_False;
706 0 : m_aFL.Show();
707 : {
708 0 : bHasFocus = pCurrent->HasChildPathFocus();
709 0 : _pWindow->Show();
710 : }
711 0 : m_aTBPreview.Show();
712 0 : m_aBorder.Show();
713 0 : switchPreview(m_ePreviewMode,sal_True);
714 :
715 0 : if ( bHasFocus )
716 0 : _pWindow->GrabFocus();
717 0 : Resize();
718 0 : }
719 :
720 : // -----------------------------------------------------------------------------
721 : namespace
722 : {
723 : namespace DatabaseObject = ::com::sun::star::sdb::application::DatabaseObject;
724 : namespace DatabaseObjectContainer = ::com::sun::star::sdb::application::DatabaseObjectContainer;
725 :
726 0 : static sal_Int32 lcl_getFolderIndicatorForType( const ElementType _eType )
727 : {
728 : const sal_Int32 nFolderIndicator =
729 : ( _eType == E_FORM ) ? DatabaseObjectContainer::FORMS_FOLDER
730 0 : : ( _eType == E_REPORT ) ? DatabaseObjectContainer::REPORTS_FOLDER : -1;
731 0 : return nFolderIndicator;
732 : }
733 : }
734 :
735 : // -----------------------------------------------------------------------------
736 0 : void OAppDetailPageHelper::fillNames( const Reference< XNameAccess >& _xContainer, const ElementType _eType,
737 : const sal_uInt16 _nImageId, SvTreeListEntry* _pParent )
738 : {
739 : OSL_ENSURE(_xContainer.is(),"Data source is NULL! -> GPF");
740 : OSL_ENSURE( ( _eType >= E_TABLE ) && ( _eType < E_ELEMENT_TYPE_COUNT ), "OAppDetailPageHelper::fillNames: invalid type!" );
741 :
742 0 : DBTreeListBox* pList = m_pLists[ _eType ];
743 : OSL_ENSURE( pList, "OAppDetailPageHelper::fillNames: you really should create the list before calling this!" );
744 0 : if ( !pList )
745 0 : return;
746 :
747 0 : if ( _xContainer.is() && _xContainer->hasElements() )
748 : {
749 0 : const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
750 :
751 0 : Sequence< OUString> aSeq = _xContainer->getElementNames();
752 0 : const OUString* pIter = aSeq.getConstArray();
753 0 : const OUString* pEnd = pIter + aSeq.getLength();
754 0 : for(;pIter != pEnd;++pIter)
755 : {
756 0 : SvTreeListEntry* pEntry = NULL;
757 0 : Reference<XNameAccess> xSubElements(_xContainer->getByName(*pIter),UNO_QUERY);
758 0 : if ( xSubElements.is() )
759 : {
760 0 : pEntry = pList->InsertEntry( *pIter, _pParent, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
761 0 : getBorderWin().getView()->getAppController().containerFound( Reference< XContainer >( xSubElements, UNO_QUERY ) );
762 0 : fillNames( xSubElements, _eType, _nImageId, pEntry );
763 : }
764 : else
765 : {
766 0 : pEntry = pList->InsertEntry( *pIter, _pParent );
767 :
768 0 : Image aImage = Image( ModuleRes( _nImageId ) );
769 0 : pList->SetExpandedEntryBmp( pEntry, aImage );
770 0 : pList->SetCollapsedEntryBmp( pEntry, aImage );
771 : }
772 0 : }
773 : }
774 : }
775 : // -----------------------------------------------------------------------------
776 0 : DBTreeListBox* OAppDetailPageHelper::createSimpleTree( const OString& _sHelpId, const Image& _rImage)
777 : {
778 : DBTreeListBox* pTreeView = new DBTreeListBox(this,
779 0 : WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
780 0 : pTreeView->SetHelpId( _sHelpId );
781 0 : return createTree( pTreeView, _rImage );
782 : }
783 :
784 : // -----------------------------------------------------------------------------
785 0 : DBTreeListBox* OAppDetailPageHelper::createTree( DBTreeListBox* _pTreeView, const Image& _rImage )
786 : {
787 0 : WaitObject aWaitCursor(this);
788 :
789 0 : _pTreeView->SetStyle(_pTreeView->GetStyle() | WB_HASLINES | WB_SORT | WB_HASBUTTONS | WB_HSCROLL |WB_HASBUTTONSATROOT | WB_TABSTOP);
790 0 : _pTreeView->GetModel()->SetSortMode(SortAscending);
791 0 : _pTreeView->EnableCheckButton( NULL ); // do not show any buttons
792 0 : _pTreeView->SetSelectionMode(MULTIPLE_SELECTION);
793 :
794 0 : _pTreeView->SetDefaultCollapsedEntryBmp( _rImage );
795 0 : _pTreeView->SetDefaultExpandedEntryBmp( _rImage );
796 :
797 0 : _pTreeView->SetDoubleClickHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
798 0 : _pTreeView->SetEnterKeyHdl(LINK(this, OAppDetailPageHelper, OnEntryDoubleClick));
799 0 : _pTreeView->SetSelChangeHdl(LINK(this, OAppDetailPageHelper, OnEntrySelChange));
800 :
801 0 : _pTreeView->setCutHandler(LINK(this, OAppDetailPageHelper, OnCutEntry));
802 0 : _pTreeView->setCopyHandler(LINK(this, OAppDetailPageHelper, OnCopyEntry));
803 0 : _pTreeView->setPasteHandler(LINK(this, OAppDetailPageHelper, OnPasteEntry));
804 0 : _pTreeView->setDeleteHandler(LINK(this, OAppDetailPageHelper, OnDeleteEntry));
805 :
806 0 : _pTreeView->setControlActionListener( &getBorderWin().getView()->getAppController() );
807 0 : _pTreeView->setContextMenuProvider( &getBorderWin().getView()->getAppController() );
808 :
809 0 : return _pTreeView;
810 : }
811 : // -----------------------------------------------------------------------------
812 0 : void OAppDetailPageHelper::clearPages()
813 : {
814 0 : showPreview(NULL);
815 0 : for (size_t i=0; i < E_ELEMENT_TYPE_COUNT; ++i)
816 : {
817 0 : if ( m_pLists[i] )
818 0 : m_pLists[i]->Clear();
819 : }
820 0 : }
821 : // -----------------------------------------------------------------------------
822 0 : sal_Bool OAppDetailPageHelper::isFilled() const
823 : {
824 0 : size_t i = 0;
825 0 : for (; i < E_ELEMENT_TYPE_COUNT && !m_pLists[i]; ++i)
826 : ;
827 0 : return i != E_ELEMENT_TYPE_COUNT;
828 : }
829 : // -----------------------------------------------------------------------------
830 0 : void OAppDetailPageHelper::elementReplaced(ElementType _eType
831 : ,const OUString& _rOldName
832 : ,const OUString& _rNewName )
833 : {
834 0 : DBTreeListBox* pTreeView = getCurrentView();
835 0 : if ( pTreeView )
836 : {
837 0 : OUString sNewName = _rNewName;
838 0 : SvTreeListEntry* pEntry = NULL;
839 0 : switch( _eType )
840 : {
841 : case E_TABLE:
842 0 : static_cast<OTableTreeListBox*>(pTreeView)->removedTable( _rOldName );
843 0 : static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rNewName );
844 0 : return;
845 :
846 : case E_QUERY:
847 0 : pEntry = lcl_findEntry_impl(*pTreeView,_rOldName,pTreeView->First());
848 0 : break;
849 : case E_FORM:
850 : case E_REPORT:
851 0 : pEntry = lcl_findEntry(*pTreeView,_rOldName,pTreeView->First());
852 0 : break;
853 : default:
854 : OSL_FAIL("Invalid element type");
855 : }
856 : OSL_ENSURE(pEntry,"Do you know that the name isn't existence!");
857 0 : if ( pEntry )
858 : {
859 0 : pTreeView->SetEntryText(pEntry,sNewName);
860 0 : }
861 : }
862 : }
863 : // -----------------------------------------------------------------------------
864 0 : SvTreeListEntry* OAppDetailPageHelper::elementAdded(ElementType _eType,const OUString& _rName, const Any& _rObject )
865 : {
866 0 : SvTreeListEntry* pRet = NULL;
867 0 : DBTreeListBox* pTreeView = m_pLists[_eType];
868 0 : if( _eType == E_TABLE && pTreeView )
869 : {
870 0 : pRet = static_cast<OTableTreeListBox*>(pTreeView)->addedTable( _rName );
871 : }
872 0 : else if ( pTreeView )
873 : {
874 :
875 0 : SvTreeListEntry* pEntry = NULL;
876 0 : Reference<XChild> xChild(_rObject,UNO_QUERY);
877 0 : if ( xChild.is() && E_QUERY != _eType )
878 : {
879 0 : Reference<XContent> xContent(xChild->getParent(),UNO_QUERY);
880 0 : if ( xContent.is() )
881 : {
882 0 : OUString sName = xContent->getIdentifier()->getContentIdentifier();
883 0 : pEntry = lcl_findEntry(*pTreeView,sName,pTreeView->First());
884 0 : }
885 : }
886 :
887 0 : sal_uInt16 nImageId = 0;
888 0 : getElementIcons( _eType, nImageId );
889 0 : Reference<XNameAccess> xContainer(_rObject,UNO_QUERY);
890 0 : if ( xContainer.is() )
891 : {
892 0 : const sal_Int32 nFolderIndicator = lcl_getFolderIndicatorForType( _eType );
893 0 : pRet = pTreeView->InsertEntry( _rName, pEntry, sal_False, LIST_APPEND, reinterpret_cast< void* >( nFolderIndicator ) );
894 0 : fillNames( xContainer, _eType, nImageId, pRet );
895 : }
896 : else
897 : {
898 0 : pRet = pTreeView->InsertEntry( _rName, pEntry );
899 :
900 0 : Image aImage = Image( ModuleRes( nImageId ) );
901 0 : pTreeView->SetExpandedEntryBmp( pRet, aImage );
902 0 : pTreeView->SetCollapsedEntryBmp( pRet, aImage );
903 0 : }
904 : }
905 0 : return pRet;
906 : }
907 : // -----------------------------------------------------------------------------
908 0 : void OAppDetailPageHelper::elementRemoved( ElementType _eType,const OUString& _rName )
909 : {
910 0 : DBTreeListBox* pTreeView = getCurrentView();
911 0 : if ( pTreeView )
912 : {
913 0 : switch( _eType )
914 : {
915 : case E_TABLE:
916 : // we don't need to clear the table here, it is already done by the dispose listener
917 0 : static_cast< OTableTreeListBox* >( pTreeView )->removedTable( _rName );
918 0 : break;
919 : case E_QUERY:
920 0 : if ( pTreeView )
921 : {
922 0 : SvTreeListEntry* pEntry = lcl_findEntry_impl(*pTreeView,_rName,pTreeView->First());
923 0 : if ( pEntry )
924 0 : pTreeView->GetModel()->Remove(pEntry);
925 : }
926 0 : break;
927 : case E_FORM:
928 : case E_REPORT:
929 : {
930 0 : if ( pTreeView )
931 : {
932 0 : SvTreeListEntry* pEntry = lcl_findEntry(*pTreeView,_rName,pTreeView->First());
933 0 : if ( pEntry )
934 0 : pTreeView->GetModel()->Remove(pEntry);
935 : }
936 : }
937 0 : break;
938 : default:
939 : OSL_FAIL("Invalid element type");
940 : }
941 0 : if ( !pTreeView->GetEntryCount() )
942 0 : showPreview(NULL);
943 : }
944 0 : }
945 : // -----------------------------------------------------------------------------
946 0 : IMPL_LINK(OAppDetailPageHelper, OnEntryDoubleClick, SvTreeListBox*, _pTree)
947 : {
948 : OSL_ENSURE( _pTree, "OAppDetailPageHelper, OnEntryDoubleClick: invalid callback!" );
949 0 : bool bHandled = ( _pTree != NULL ) && getBorderWin().getView()->getAppController().onEntryDoubleClick( *_pTree );
950 0 : return bHandled ? 1L : 0L;
951 : }
952 : // -----------------------------------------------------------------------------
953 0 : IMPL_LINK(OAppDetailPageHelper, OnEntrySelChange, void*, /*NOINTERESTEDIN*/)
954 : {
955 0 : getBorderWin().getView()->getAppController().onSelectionChanged();
956 0 : return 1L;
957 : }
958 : // -----------------------------------------------------------------------------
959 0 : IMPL_LINK( OAppDetailPageHelper, OnCutEntry, void*, /*NOINTERESTEDIN*/ )
960 : {
961 0 : getBorderWin().getView()->getAppController().onCutEntry();
962 0 : return 1L;
963 : }
964 : // -----------------------------------------------------------------------------
965 0 : IMPL_LINK( OAppDetailPageHelper, OnCopyEntry, void*, /*NOINTERESTEDIN*/ )
966 : {
967 0 : getBorderWin().getView()->getAppController().onCopyEntry();
968 0 : return 1L;
969 : }
970 : // -----------------------------------------------------------------------------
971 0 : IMPL_LINK( OAppDetailPageHelper, OnPasteEntry, void*, /*NOINTERESTEDIN*/ )
972 : {
973 0 : getBorderWin().getView()->getAppController().onPasteEntry();
974 0 : return 1L;
975 : }
976 : // -----------------------------------------------------------------------------
977 0 : IMPL_LINK( OAppDetailPageHelper, OnDeleteEntry, void*, /*NOINTERESTEDIN*/ )
978 : {
979 0 : getBorderWin().getView()->getAppController().onDeleteEntry();
980 0 : return 1L;
981 : }
982 : // -----------------------------------------------------------------------------
983 0 : void OAppDetailPageHelper::Resize()
984 : {
985 : // parent window dimension
986 0 : Size aOutputSize( GetOutputSize() );
987 0 : long nOutputWidth = aOutputSize.Width();
988 0 : long nOutputHeight = aOutputSize.Height();
989 :
990 0 : Window* pWindow = getCurrentView();
991 0 : if ( pWindow )
992 : {
993 0 : Size aFLSize = LogicToPixel( Size( 2, 6 ), MAP_APPFONT );
994 0 : sal_Int32 n6PPT = aFLSize.Height();
995 0 : long nHalfOutputWidth = static_cast<long>(nOutputWidth * 0.5);
996 :
997 0 : pWindow->SetPosSizePixel( Point(0, 0), Size(nHalfOutputWidth - n6PPT, nOutputHeight) );
998 :
999 0 : m_aFL.SetPosSizePixel( Point(nHalfOutputWidth , 0 ), Size(aFLSize.Width(), nOutputHeight ) );
1000 :
1001 0 : Size aTBSize = m_aTBPreview.CalcWindowSizePixel();
1002 0 : m_aTBPreview.SetPosSizePixel(Point(nOutputWidth - aTBSize.getWidth(), 0 ),
1003 0 : aTBSize );
1004 :
1005 0 : m_aBorder.SetPosSizePixel(Point(nHalfOutputWidth + aFLSize.Width() + n6PPT, aTBSize.getHeight() + n6PPT ),
1006 0 : Size(nHalfOutputWidth - aFLSize.Width() - n6PPT, nOutputHeight - 2*n6PPT - aTBSize.getHeight()) );
1007 0 : m_aPreview.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1008 0 : m_aDocumentInfo.SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1009 0 : m_pTablePreview->SetPosSizePixel(Point(0,0),m_aBorder.GetSizePixel() );
1010 : }
1011 0 : }
1012 : // -----------------------------------------------------------------------------
1013 0 : PreviewMode OAppDetailPageHelper::getPreviewMode()
1014 : {
1015 0 : return m_ePreviewMode;
1016 : }
1017 : // -----------------------------------------------------------------------------
1018 0 : sal_Bool OAppDetailPageHelper::isPreviewEnabled()
1019 : {
1020 0 : return m_ePreviewMode != E_PREVIEWNONE;
1021 : }
1022 : // -----------------------------------------------------------------------------
1023 0 : void OAppDetailPageHelper::switchPreview(PreviewMode _eMode,sal_Bool _bForce)
1024 : {
1025 0 : if ( m_ePreviewMode != _eMode || _bForce )
1026 : {
1027 0 : m_ePreviewMode = _eMode;
1028 :
1029 0 : getBorderWin().getView()->getAppController().previewChanged(static_cast<sal_Int32>(m_ePreviewMode));
1030 :
1031 0 : sal_uInt16 nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1032 0 : switch ( m_ePreviewMode )
1033 : {
1034 : case E_PREVIEWNONE:
1035 0 : nSelectedAction = SID_DB_APP_DISABLE_PREVIEW;
1036 0 : break;
1037 : case E_DOCUMENT:
1038 0 : nSelectedAction = SID_DB_APP_VIEW_DOC_PREVIEW;
1039 0 : break;
1040 : case E_DOCUMENTINFO:
1041 0 : if ( getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) )
1042 0 : nSelectedAction = SID_DB_APP_VIEW_DOCINFO_PREVIEW;
1043 : else
1044 0 : m_ePreviewMode = E_PREVIEWNONE;
1045 0 : break;
1046 : }
1047 :
1048 0 : m_aMenu->CheckItem(nSelectedAction);
1049 0 : m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, m_aMenu->GetItemText(nSelectedAction));
1050 0 : Resize();
1051 :
1052 : // simulate a selectionChanged event at the controller, to force the preview to be updated
1053 0 : if ( isPreviewEnabled() )
1054 : {
1055 0 : if ( getCurrentView() && getCurrentView()->FirstSelected() )
1056 : {
1057 0 : getBorderWin().getView()->getAppController().onSelectionChanged();
1058 : }
1059 : }
1060 : else
1061 : {
1062 0 : m_pTablePreview->Hide();
1063 0 : m_aPreview.Hide();
1064 0 : m_aDocumentInfo.Hide();
1065 : }
1066 : }
1067 0 : }
1068 : // -----------------------------------------------------------------------------
1069 0 : void OAppDetailPageHelper::showPreview(const Reference< XContent >& _xContent)
1070 : {
1071 0 : if ( isPreviewEnabled() )
1072 : {
1073 0 : m_pTablePreview->Hide();
1074 :
1075 0 : WaitObject aWaitCursor( this );
1076 : try
1077 : {
1078 0 : Reference<XCommandProcessor> xContent(_xContent,UNO_QUERY);
1079 0 : if ( xContent.is() )
1080 : {
1081 0 : com::sun::star::ucb::Command aCommand;
1082 0 : if ( m_ePreviewMode == E_DOCUMENT )
1083 0 : aCommand.Name = OUString("preview");
1084 : else
1085 0 : aCommand.Name = OUString("getDocumentInfo");
1086 :
1087 0 : Any aPreview = xContent->execute(aCommand,xContent->createCommandIdentifier(),Reference< XCommandEnvironment >());
1088 0 : if ( m_ePreviewMode == E_DOCUMENT )
1089 : {
1090 0 : m_aDocumentInfo.Hide();
1091 0 : m_aPreview.Show();
1092 :
1093 0 : Graphic aGraphic;
1094 0 : Sequence < sal_Int8 > aBmpSequence;
1095 0 : if ( aPreview >>= aBmpSequence )
1096 : {
1097 0 : SvMemoryStream aData( aBmpSequence.getArray(),
1098 0 : aBmpSequence.getLength(),
1099 0 : STREAM_READ );
1100 :
1101 0 : GraphicConverter::Import(aData,aGraphic);
1102 : }
1103 0 : m_aPreview.setGraphic( aGraphic );
1104 0 : m_aPreview.Invalidate();
1105 : }
1106 : else
1107 : {
1108 0 : m_aPreview.Hide();
1109 0 : m_aDocumentInfo.clear();
1110 0 : m_aDocumentInfo.Show();
1111 : Reference<document::XDocumentProperties> xProp(
1112 0 : aPreview, UNO_QUERY);
1113 0 : if ( xProp.is() )
1114 0 : m_aDocumentInfo.fill(xProp,OUString());
1115 0 : }
1116 : }
1117 : else
1118 : {
1119 0 : m_aPreview.Hide();
1120 0 : m_aDocumentInfo.Hide();
1121 0 : }
1122 : }
1123 0 : catch( const Exception& )
1124 : {
1125 : DBG_UNHANDLED_EXCEPTION();
1126 0 : }
1127 : }
1128 0 : }
1129 : // -----------------------------------------------------------------------------
1130 0 : void OAppDetailPageHelper::showPreview( const OUString& _sDataSourceName,
1131 : const OUString& _sName,
1132 : sal_Bool _bTable)
1133 : {
1134 0 : if ( isPreviewEnabled() )
1135 : {
1136 0 : WaitObject aWaitCursor( this );
1137 0 : m_aPreview.Hide();
1138 0 : m_aDocumentInfo.Hide();
1139 0 : m_pTablePreview->Show();
1140 0 : if ( !m_xFrame.is() )
1141 : {
1142 : try
1143 : {
1144 0 : m_xFrame = Frame::create( getBorderWin().getView()->getORB() );
1145 0 : m_xFrame->initialize( m_xWindow );
1146 :
1147 : // no layout manager (and thus no toolbars) in the preview
1148 : // Must be called after initialize ... but before any other call to this frame.
1149 : // Otherwise frame throws "life time exceptions" as e.g. NON_INITIALIZED
1150 0 : m_xFrame->setLayoutManager( Reference< XLayoutManager >() );
1151 :
1152 0 : Reference<XFramesSupplier> xSup(getBorderWin().getView()->getAppController().getXController()->getFrame(),UNO_QUERY);
1153 0 : if ( xSup.is() )
1154 : {
1155 0 : Reference<XFrames> xFrames = xSup->getFrames();
1156 0 : xFrames->append( Reference<XFrame>(m_xFrame,UNO_QUERY_THROW));
1157 0 : }
1158 : }
1159 0 : catch(const Exception&)
1160 : {
1161 : }
1162 : }
1163 :
1164 0 : Reference< XDatabaseDocumentUI > xApplication( getBorderWin().getView()->getAppController().getXController(), UNO_QUERY );
1165 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1166 : ::std::auto_ptr< DatabaseObjectView > pDispatcher( new ResultSetBrowser(
1167 0 : getBorderWin().getView()->getORB(),
1168 : xApplication, NULL, _bTable
1169 0 : ) );
1170 : SAL_WNODEPRECATED_DECLARATIONS_POP
1171 0 : pDispatcher->setTargetFrame( Reference<XFrame>(m_xFrame,UNO_QUERY_THROW) );
1172 :
1173 0 : ::comphelper::NamedValueCollection aArgs;
1174 0 : aArgs.put( "Preview", sal_True );
1175 0 : aArgs.put( "ReadOnly", sal_True );
1176 0 : aArgs.put( "AsTemplate", sal_False );
1177 0 : aArgs.put( (OUString)PROPERTY_SHOWMENU, sal_False );
1178 :
1179 0 : Reference< XController > xPreview( pDispatcher->openExisting( makeAny( _sDataSourceName ), _sName, aArgs ), UNO_QUERY );
1180 0 : sal_Bool bClearPreview = !xPreview.is();
1181 :
1182 : // clear the preview when the query or table could not be loaded
1183 0 : if ( !bClearPreview )
1184 : {
1185 0 : Reference< XTabController > xTabController( xPreview, UNO_QUERY );
1186 0 : bClearPreview = !xTabController.is();
1187 0 : if ( !bClearPreview )
1188 : {
1189 0 : Reference< XLoadable > xLoadable( xTabController->getModel(), UNO_QUERY );
1190 0 : bClearPreview = !( xLoadable.is() && xLoadable->isLoaded() );
1191 0 : }
1192 : }
1193 0 : if ( bClearPreview )
1194 0 : showPreview(NULL);
1195 : }
1196 0 : }
1197 : // -----------------------------------------------------------------------------
1198 0 : IMPL_LINK(OAppDetailPageHelper, OnDropdownClickHdl, ToolBox*, /*pToolBox*/)
1199 : {
1200 0 : m_aTBPreview.EndSelection();
1201 :
1202 : // tell the toolbox that the item is pressed down
1203 0 : m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_True );
1204 :
1205 : // simulate a mouse move (so the "down" state is really painted)
1206 0 : Point aPoint = m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ).TopLeft();
1207 0 : MouseEvent aMove( aPoint, 0, MOUSE_SIMPLEMOVE | MOUSE_SYNTHETIC );
1208 0 : m_aTBPreview.MouseMove( aMove );
1209 :
1210 0 : m_aTBPreview.Update();
1211 :
1212 : // execute the menu
1213 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1214 0 : ::std::auto_ptr<PopupMenu> aMenu(new PopupMenu( ModuleRes( RID_MENU_APP_PREVIEW ) ));
1215 : SAL_WNODEPRECATED_DECLARATIONS_POP
1216 :
1217 : sal_uInt16 pActions[] = { SID_DB_APP_DISABLE_PREVIEW
1218 : , SID_DB_APP_VIEW_DOC_PREVIEW
1219 : , SID_DB_APP_VIEW_DOCINFO_PREVIEW
1220 0 : };
1221 :
1222 0 : for(size_t i=0; i < sizeof(pActions)/sizeof(pActions[0]);++i)
1223 : {
1224 0 : aMenu->CheckItem(pActions[i],m_aMenu->IsItemChecked(pActions[i]));
1225 : }
1226 0 : aMenu->EnableItem( SID_DB_APP_VIEW_DOCINFO_PREVIEW, getBorderWin().getView()->getAppController().isCommandEnabled(SID_DB_APP_VIEW_DOCINFO_PREVIEW) );
1227 :
1228 : // no disabled entries
1229 0 : aMenu->RemoveDisabledEntries();
1230 :
1231 0 : sal_uInt16 nSelectedAction = aMenu->Execute(&m_aTBPreview, m_aTBPreview.GetItemRect( SID_DB_APP_DISABLE_PREVIEW ));
1232 : // "cleanup" the toolbox state
1233 0 : MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
1234 0 : m_aTBPreview.MouseMove( aLeave );
1235 0 : m_aTBPreview.SetItemDown( SID_DB_APP_DISABLE_PREVIEW, sal_False);
1236 0 : if ( nSelectedAction )
1237 : {
1238 0 : m_aTBPreview.SetItemText(SID_DB_APP_DISABLE_PREVIEW, aMenu->GetItemText(nSelectedAction));
1239 0 : Resize();
1240 0 : getBorderWin().getView()->getAppController().executeChecked(nSelectedAction,Sequence<PropertyValue>());
1241 : }
1242 0 : return 0L;
1243 : }
1244 :
1245 : // -----------------------------------------------------------------------------
1246 0 : void OAppDetailPageHelper::KeyInput( const KeyEvent& rKEvt )
1247 : {
1248 0 : SvTreeListBox* pCurrentView = getCurrentView();
1249 : OSL_PRECOND( pCurrentView, "OAppDetailPageHelper::KeyInput: how this?" );
1250 :
1251 0 : KeyFuncType eFunc = rKEvt.GetKeyCode().GetFunction(); (void)eFunc;
1252 0 : sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
1253 :
1254 0 : if ( ( KEY_RETURN == nCode ) && pCurrentView )
1255 : {
1256 0 : getBorderWin().getView()->getAppController().onEntryDoubleClick( *pCurrentView );
1257 : }
1258 : else
1259 0 : Window::KeyInput(rKEvt);
1260 0 : }
1261 :
1262 : // -----------------------------------------------------------------------------
1263 0 : void OAppDetailPageHelper::DataChanged( const DataChangedEvent& rDCEvt )
1264 : {
1265 0 : Window::DataChanged( rDCEvt );
1266 :
1267 0 : if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
1268 0 : (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
1269 0 : (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
1270 0 : ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1271 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
1272 :
1273 : {
1274 0 : ImplInitSettings();
1275 0 : if ( m_pLists[ E_TABLE ] )
1276 : {
1277 0 : OTableTreeListBox* pTableTree = dynamic_cast< OTableTreeListBox* >( m_pLists[ E_TABLE ] );
1278 : OSL_ENSURE( pTableTree != NULL, "OAppDetailPageHelper::DataChanged: a tree list for tables which is no TableTreeList?" );
1279 0 : if ( pTableTree )
1280 0 : pTableTree->notifyHiContrastChanged();
1281 : }
1282 : }
1283 0 : }
1284 : // -----------------------------------------------------------------------------
1285 0 : void OAppDetailPageHelper::ImplInitSettings()
1286 : {
1287 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1288 0 : Font aFont;
1289 0 : aFont = rStyleSettings.GetFieldFont();
1290 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1291 0 : SetPointFont( aFont );
1292 0 : m_aTBPreview.SetPointFont( aFont );
1293 :
1294 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
1295 0 : SetTextFillColor();
1296 0 : m_aBorder.SetTextColor( rStyleSettings.GetFieldTextColor() );
1297 0 : m_aBorder.SetTextFillColor();
1298 0 : m_aTBPreview.SetTextColor( rStyleSettings.GetFieldTextColor() );
1299 0 : m_aTBPreview.SetTextFillColor();
1300 :
1301 0 : SetBackground( rStyleSettings.GetFieldColor() );
1302 0 : m_aBorder.SetBackground( rStyleSettings.GetFieldColor() );
1303 0 : m_aFL.SetBackground( rStyleSettings.GetFieldColor() );
1304 0 : m_aDocumentInfo.SetBackground( rStyleSettings.GetFieldColor() );
1305 0 : m_aTBPreview.SetBackground( rStyleSettings.GetFieldColor() );
1306 0 : m_pTablePreview->SetBackground( rStyleSettings.GetFieldColor() );
1307 0 : }
1308 : // -----------------------------------------------------------------------------
1309 0 : OPreviewWindow::OPreviewWindow(Window* _pParent)
1310 0 : : Window(_pParent)
1311 : {
1312 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1313 0 : }
1314 : // -----------------------------------------------------------------------------
1315 0 : sal_Bool OPreviewWindow::ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const
1316 : {
1317 0 : const Size aWinSize( GetOutputSizePixel() );
1318 0 : Size aNewSize( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) );
1319 0 : sal_Bool bRet = sal_False;
1320 :
1321 0 : if( aNewSize.Width() && aNewSize.Height() )
1322 : {
1323 : // scale to fit window
1324 0 : const double fGrfWH = (double) aNewSize.Width() / aNewSize.Height();
1325 0 : const double fWinWH = (double) aWinSize.Width() / aWinSize.Height();
1326 :
1327 0 : if ( fGrfWH < fWinWH )
1328 : {
1329 0 : aNewSize.Width() = (long) ( aWinSize.Height() * fGrfWH );
1330 0 : aNewSize.Height()= aWinSize.Height();
1331 : }
1332 : else
1333 : {
1334 0 : aNewSize.Width() = aWinSize.Width();
1335 0 : aNewSize.Height()= (long) ( aWinSize.Width() / fGrfWH);
1336 : }
1337 :
1338 0 : const Point aNewPos( ( aWinSize.Width() - aNewSize.Width() ) >> 1,
1339 0 : ( aWinSize.Height() - aNewSize.Height() ) >> 1 );
1340 :
1341 0 : rResultRect = Rectangle( aNewPos, aNewSize );
1342 0 : bRet = sal_True;
1343 : }
1344 :
1345 0 : return bRet;
1346 : }
1347 :
1348 : // ------------------------------------------------------------------------
1349 :
1350 0 : void OPreviewWindow::Paint( const Rectangle& rRect )
1351 : {
1352 0 : Window::Paint( rRect );
1353 :
1354 0 : if( ImplGetGraphicCenterRect( m_aGraphicObj.GetGraphic(), m_aPreviewRect ) )
1355 : {
1356 0 : const Point aPos( m_aPreviewRect.TopLeft() );
1357 0 : const Size aSize( m_aPreviewRect.GetSize() );
1358 :
1359 0 : if( m_aGraphicObj.IsAnimated() )
1360 0 : m_aGraphicObj.StartAnimation( this, aPos, aSize );
1361 : else
1362 0 : m_aGraphicObj.Draw( this, aPos, aSize );
1363 : }
1364 0 : }
1365 : // -----------------------------------------------------------------------------
1366 0 : void OPreviewWindow::DataChanged( const DataChangedEvent& rDCEvt )
1367 : {
1368 0 : Window::DataChanged( rDCEvt );
1369 :
1370 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1371 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1372 : {
1373 0 : ImplInitSettings( sal_True, sal_True, sal_True );
1374 0 : Invalidate();
1375 : }
1376 0 : }
1377 : // -----------------------------------------------------------------------------
1378 0 : void OPreviewWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
1379 : {
1380 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
1381 0 : if( bFont )
1382 : {
1383 0 : Font aFont;
1384 0 : aFont = rStyleSettings.GetFieldFont();
1385 0 : aFont.SetColor( rStyleSettings.GetWindowTextColor() );
1386 0 : SetPointFont( aFont );
1387 : }
1388 :
1389 0 : if( bForeground || bFont )
1390 : {
1391 0 : SetTextColor( rStyleSettings.GetFieldTextColor() );
1392 0 : SetTextFillColor();
1393 : }
1394 :
1395 0 : if( bBackground )
1396 0 : SetBackground( rStyleSettings.GetFieldColor() );
1397 12 : }
1398 : // -----------------------------------------------------------------------------
1399 : // -----------------------------------------------------------------------------
1400 :
1401 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|