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