1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "propertyeditor.hxx"
21 #include "browserpage.hxx"
22 #include "linedescriptor.hxx"
24 #include <tools/debug.hxx>
31 #define LAYOUT_BORDER_LEFT 3
32 #define LAYOUT_BORDER_TOP 3
33 #define LAYOUT_BORDER_RIGHT 3
34 #define LAYOUT_BORDER_BOTTOM 3
36 using ::com::sun::star::uno::Any
;
37 using ::com::sun::star::inspection::XPropertyControl
;
38 using ::com::sun::star::uno::Reference
;
41 // class OPropertyEditor
44 OPropertyEditor::OPropertyEditor( vcl::Window
* pParent
)
45 :Control(pParent
, WB_DIALOGCONTROL
)
46 ,m_aTabControl( VclPtr
<TabControl
>::Create(this) )
50 ,m_bHasHelpSection( false )
55 m_aTabControl
->Show();
56 m_aTabControl
->SetDeactivatePageHdl(LINK(this, OPropertyEditor
, OnPageDeactivate
));
57 m_aTabControl
->SetActivatePageHdl(LINK(this, OPropertyEditor
, OnPageActivate
));
58 m_aTabControl
->SetBackground(GetBackground());
59 m_aTabControl
->SetPaintTransparent(true);
63 OPropertyEditor::~OPropertyEditor()
68 void OPropertyEditor::dispose()
72 m_aTabControl
.disposeAndClear();
77 void OPropertyEditor::ClearAll()
80 sal_uInt16 nCount
= m_aTabControl
->GetPageCount();
81 for(long i
= nCount
-1; i
>= 0; --i
)
83 sal_uInt16 nID
= m_aTabControl
->GetPageId((sal_uInt16
)i
);
84 VclPtr
<OBrowserPage
> pPage
= static_cast<OBrowserPage
*>(m_aTabControl
->GetTabPage(nID
));
87 pPage
->EnableInput(false);
88 m_aTabControl
->RemovePage(nID
);
89 pPage
.disposeAndClear();
92 m_aTabControl
->Clear();
95 MapStringToPageId aEmpty
;
96 m_aPropertyPageIds
.swap( aEmpty
);
99 while ( !m_aHiddenPages
.empty() )
101 m_aHiddenPages
.begin()->second
.pPage
.disposeAndClear();
102 m_aHiddenPages
.erase( m_aHiddenPages
.begin() );
104 m_aHiddenPages
.clear();
108 sal_Int32
OPropertyEditor::getMinimumHeight()
110 sal_Int32
nMinHeight( LAYOUT_BORDER_TOP
+ LAYOUT_BORDER_BOTTOM
);
112 if ( m_aTabControl
->GetPageCount() > 0 )
114 sal_uInt16 nFirstID
= m_aTabControl
->GetPageId( 0 );
116 // reserve space for the tabs themself
117 tools::Rectangle
aTabArea( m_aTabControl
->GetTabBounds( nFirstID
) );
118 nMinHeight
+= aTabArea
.GetHeight();
120 // ask the page how much it requires
121 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( nFirstID
) );
123 nMinHeight
+= pPage
->getMinimumHeight();
126 nMinHeight
+= 250; // arbitrary ...
132 sal_Int32
OPropertyEditor::getMinimumWidth()
134 sal_uInt16 nCount
= m_aTabControl
->GetPageCount();
135 sal_Int32 nPageMinWidth
= 0;
136 for(long i
= nCount
-1; i
>= 0; --i
)
138 sal_uInt16 nID
= m_aTabControl
->GetPageId((sal_uInt16
)i
);
139 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
->GetTabPage(nID
));
142 sal_Int32 nCurPageMinWidth
= pPage
->getMinimumWidth();
143 if( nCurPageMinWidth
> nPageMinWidth
)
144 nPageMinWidth
= nCurPageMinWidth
;
147 return nPageMinWidth
+6;
151 void OPropertyEditor::CommitModified()
153 // commit all of my pages, if necessary
155 sal_uInt16 nCount
= m_aTabControl
->GetPageCount();
156 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
158 sal_uInt16 nID
= m_aTabControl
->GetPageId( i
);
159 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( nID
) );
161 if ( pPage
&& pPage
->getListBox().IsModified() )
162 pPage
->getListBox().CommitModified();
167 void OPropertyEditor::GetFocus()
170 m_aTabControl
->GrabFocus();
174 OBrowserPage
* OPropertyEditor::getPage( const OUString
& _rPropertyName
)
176 OBrowserPage
* pPage
= nullptr;
177 MapStringToPageId::const_iterator aPropertyPageIdPos
= m_aPropertyPageIds
.find( _rPropertyName
);
178 if ( aPropertyPageIdPos
!= m_aPropertyPageIds
.end() )
179 pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( aPropertyPageIdPos
->second
) );
184 const OBrowserPage
* OPropertyEditor::getPage( const OUString
& _rPropertyName
) const
186 return const_cast< OPropertyEditor
* >( this )->getPage( _rPropertyName
);
190 OBrowserPage
* OPropertyEditor::getPage( sal_uInt16
& _rPageId
)
192 return static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( _rPageId
) );
196 const OBrowserPage
* OPropertyEditor::getPage( sal_uInt16
& _rPageId
) const
198 return const_cast< OPropertyEditor
* >( this )->getPage( _rPageId
);
202 void OPropertyEditor::Resize()
204 tools::Rectangle
aPlayground(
205 Point( LAYOUT_BORDER_LEFT
, LAYOUT_BORDER_TOP
),
207 GetOutputSizePixel().Width() - LAYOUT_BORDER_LEFT
- LAYOUT_BORDER_RIGHT
,
208 GetOutputSizePixel().Height() - LAYOUT_BORDER_TOP
- LAYOUT_BORDER_BOTTOM
212 tools::Rectangle
aTabArea( aPlayground
);
213 m_aTabControl
->SetPosSizePixel( aTabArea
.TopLeft(), aTabArea
.GetSize() );
217 sal_uInt16
OPropertyEditor::AppendPage( const OUString
& _rText
, const OString
& _rHelpId
)
220 sal_uInt16 nId
= m_nNextId
++;
222 m_aTabControl
->InsertPage(nId
, _rText
);
225 VclPtrInstance
<OBrowserPage
> pPage(m_aTabControl
.get());
226 pPage
->SetText( _rText
);
228 pPage
->SetSizePixel(m_aTabControl
->GetTabPageSizePixel());
229 pPage
->getListBox().SetListener(m_pListener
);
230 pPage
->getListBox().SetObserver(m_pObserver
);
231 pPage
->getListBox().EnableHelpSection( m_bHasHelpSection
);
232 pPage
->getListBox().SetHelpLineLimites( m_nMinHelpLines
, m_nMaxHelpLines
);
233 pPage
->SetHelpId( _rHelpId
);
235 // immediately activate the page
236 m_aTabControl
->SetTabPage(nId
, pPage
);
237 m_aTabControl
->SetCurPageId(nId
);
243 void OPropertyEditor::SetHelpId( const OString
& rHelpId
)
245 Control::SetHelpId("");
246 m_aTabControl
->SetHelpId(rHelpId
);
250 void OPropertyEditor::RemovePage(sal_uInt16 nID
)
252 VclPtr
<OBrowserPage
> pPage
= static_cast<OBrowserPage
*>(m_aTabControl
->GetTabPage(nID
));
255 pPage
->EnableInput(false);
256 m_aTabControl
->RemovePage(nID
);
257 pPage
.disposeAndClear();
261 void OPropertyEditor::SetPage(sal_uInt16 nId
)
263 m_aTabControl
->SetCurPageId(nId
);
267 sal_uInt16
OPropertyEditor::GetCurPage()
269 if(m_aTabControl
->GetPageCount()>0)
270 return m_aTabControl
->GetCurPageId();
276 void OPropertyEditor::Update(const std::mem_fun_t
<void,OBrowserListBox
>& _aUpdateFunction
)
278 // forward this to all our pages
279 sal_uInt16 nCount
= m_aTabControl
->GetPageCount();
280 for (sal_uInt16 i
=0;i
<nCount
;++i
)
282 sal_uInt16 nID
= m_aTabControl
->GetPageId(i
);
283 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
->GetTabPage(nID
));
285 _aUpdateFunction(&pPage
->getListBox());
289 void OPropertyEditor::EnableUpdate()
291 Update(std::mem_fun(&OBrowserListBox::EnableUpdate
));
294 void OPropertyEditor::DisableUpdate()
296 Update(std::mem_fun(&OBrowserListBox::DisableUpdate
));
300 void OPropertyEditor::forEachPage( PageOperation _pOperation
)
302 sal_uInt16 nCount
= m_aTabControl
->GetPageCount();
303 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
305 sal_uInt16 nID
= m_aTabControl
->GetPageId(i
);
306 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( nID
) );
309 (this->*_pOperation
)( *pPage
, nullptr );
314 void OPropertyEditor::setPageLineListener( OBrowserPage
& _rPage
, const void* )
316 _rPage
.getListBox().SetListener( m_pListener
);
320 void OPropertyEditor::SetLineListener(IPropertyLineListener
* _pListener
)
322 m_pListener
= _pListener
;
323 forEachPage( &OPropertyEditor::setPageLineListener
);
327 void OPropertyEditor::setPageControlObserver( OBrowserPage
& _rPage
, const void* )
329 _rPage
.getListBox().SetObserver( m_pObserver
);
333 void OPropertyEditor::SetControlObserver( IPropertyControlObserver
* _pObserver
)
335 m_pObserver
= _pObserver
;
336 forEachPage( &OPropertyEditor::setPageControlObserver
);
340 void OPropertyEditor::EnableHelpSection( bool _bEnable
)
342 m_bHasHelpSection
= _bEnable
;
343 forEachPage( &OPropertyEditor::enableHelpSection
);
347 void OPropertyEditor::SetHelpText( const OUString
& _rHelpText
)
349 sal_uInt16 nCount
= m_aTabControl
->GetPageCount();
350 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
352 sal_uInt16 nID
= m_aTabControl
->GetPageId(i
);
353 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( nID
) );
356 setHelpSectionText( *pPage
, &_rHelpText
);
361 void OPropertyEditor::SetHelpLineLimites( sal_Int32 _nMinLines
, sal_Int32 _nMaxLines
)
363 m_nMinHelpLines
= _nMinLines
;
364 m_nMaxHelpLines
= _nMaxLines
;
365 forEachPage( &OPropertyEditor::setHelpLineLimits
);
369 void OPropertyEditor::enableHelpSection( OBrowserPage
& _rPage
, const void* )
371 _rPage
.getListBox().EnableHelpSection( m_bHasHelpSection
);
375 void OPropertyEditor::setHelpSectionText( OBrowserPage
& _rPage
, const void* _pPointerToOUString
)
377 OSL_ENSURE( _pPointerToOUString
, "OPropertyEditor::setHelpSectionText: invalid argument!" );
378 if ( !_pPointerToOUString
)
381 const OUString
& rText( *static_cast<const OUString
*>(_pPointerToOUString
) );
382 _rPage
.getListBox().SetHelpText( rText
);
386 void OPropertyEditor::setHelpLineLimits( OBrowserPage
& _rPage
, const void* )
388 _rPage
.getListBox().SetHelpLineLimites( m_nMinHelpLines
, m_nMaxHelpLines
);
392 void OPropertyEditor::InsertEntry( const OLineDescriptor
& rData
, sal_uInt16 _nPageId
, sal_uInt16 nPos
)
394 // let the current page handle this
395 OBrowserPage
* pPage
= getPage( _nPageId
);
396 DBG_ASSERT( pPage
, "OPropertyEditor::InsertEntry: don't have such a page!" );
400 pPage
->getListBox().InsertEntry( rData
, nPos
);
402 OSL_ENSURE( m_aPropertyPageIds
.find( rData
.sName
) == m_aPropertyPageIds
.end(),
403 "OPropertyEditor::InsertEntry: property already present in the map!" );
404 m_aPropertyPageIds
.insert( MapStringToPageId::value_type( rData
.sName
, _nPageId
) );
408 void OPropertyEditor::RemoveEntry( const OUString
& _rName
)
410 OBrowserPage
* pPage
= getPage( _rName
);
413 OSL_VERIFY( pPage
->getListBox().RemoveEntry( _rName
) );
415 OSL_ENSURE( m_aPropertyPageIds
.find( _rName
) != m_aPropertyPageIds
.end(),
416 "OPropertyEditor::RemoveEntry: property not present in the map!" );
417 m_aPropertyPageIds
.erase( _rName
);
422 void OPropertyEditor::ChangeEntry( const OLineDescriptor
& rData
)
424 OBrowserPage
* pPage
= getPage( rData
.sName
);
426 pPage
->getListBox().ChangeEntry( rData
, EDITOR_LIST_REPLACE_EXISTING
);
430 void OPropertyEditor::SetPropertyValue( const OUString
& rEntryName
, const Any
& _rValue
, bool _bUnknownValue
)
432 OBrowserPage
* pPage
= getPage( rEntryName
);
434 pPage
->getListBox().SetPropertyValue( rEntryName
, _rValue
, _bUnknownValue
);
438 sal_uInt16
OPropertyEditor::GetPropertyPos( const OUString
& rEntryName
) const
440 sal_uInt16 nVal
=EDITOR_LIST_ENTRY_NOTFOUND
;
441 const OBrowserPage
* pPage
= getPage( rEntryName
);
443 nVal
= pPage
->getListBox().GetPropertyPos( rEntryName
);
448 void OPropertyEditor::ShowPropertyPage( sal_uInt16 _nPageId
, bool _bShow
)
452 sal_uInt16 nPagePos
= m_aTabControl
->GetPagePos( _nPageId
);
453 if ( TAB_PAGE_NOTFOUND
== nPagePos
)
455 DBG_ASSERT( m_aHiddenPages
.find( _nPageId
) == m_aHiddenPages
.end(), "OPropertyEditor::ShowPropertyPage: page already hidden!" );
457 m_aHiddenPages
[ _nPageId
] = HiddenPage( nPagePos
, m_aTabControl
->GetTabPage( _nPageId
) );
458 m_aTabControl
->RemovePage( _nPageId
);
462 std::map
< sal_uInt16
, HiddenPage
>::iterator aPagePos
= m_aHiddenPages
.find( _nPageId
);
463 if ( aPagePos
== m_aHiddenPages
.end() )
466 aPagePos
->second
.pPage
->SetSizePixel( m_aTabControl
->GetTabPageSizePixel() );
467 m_aTabControl
->InsertPage( aPagePos
->first
, aPagePos
->second
.pPage
->GetText(), aPagePos
->second
.nPos
);
468 m_aTabControl
->SetTabPage( aPagePos
->first
, aPagePos
->second
.pPage
);
470 m_aHiddenPages
.erase( aPagePos
);
475 void OPropertyEditor::EnablePropertyControls( const OUString
& _rEntryName
, sal_Int16 _nControls
, bool _bEnable
)
477 for ( sal_uInt16 i
= 0; i
< m_aTabControl
->GetPageCount(); ++i
)
479 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( m_aTabControl
->GetPageId( i
) ) );
481 pPage
->getListBox().EnablePropertyControls( _rEntryName
, _nControls
, _bEnable
);
486 void OPropertyEditor::EnablePropertyLine( const OUString
& _rEntryName
, bool _bEnable
)
488 for ( sal_uInt16 i
= 0; i
< m_aTabControl
->GetPageCount(); ++i
)
490 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
->GetTabPage( m_aTabControl
->GetPageId( i
) ) );
492 pPage
->getListBox().EnablePropertyLine( _rEntryName
, _bEnable
);
497 Reference
< XPropertyControl
> OPropertyEditor::GetPropertyControl(const OUString
& rEntryName
)
499 Reference
< XPropertyControl
> xControl
;
500 // let the current page handle this
501 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
->GetTabPage(m_aTabControl
->GetCurPageId()));
503 xControl
= pPage
->getListBox().GetPropertyControl(rEntryName
);
508 IMPL_LINK_NOARG(OPropertyEditor
, OnPageActivate
, TabControl
*, void)
510 m_aPageActivationHandler
.Call(nullptr);
514 IMPL_LINK_NOARG(OPropertyEditor
, OnPageDeactivate
, TabControl
*, bool)
516 // commit the data on the current (to-be-deactivated) tab page
518 sal_Int32 nCurrentId
= m_aTabControl
->GetCurPageId();
519 OBrowserPage
* pCurrentPage
= static_cast<OBrowserPage
*>(m_aTabControl
->GetTabPage((sal_uInt16
)nCurrentId
));
523 if ( pCurrentPage
->getListBox().IsModified() )
524 pCurrentPage
->getListBox().CommitModified();
533 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */