Linux x86 build fix
[LibreOffice.git] / extensions / source / propctrlr / propertyeditor.cxx
blob60f72f4c980aca168f155d89c386e11714af02d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "propertyeditor.hxx"
21 #include "browserpage.hxx"
22 #include "linedescriptor.hxx"
24 #include <tools/debug.hxx>
27 namespace pcr
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, WinBits nWinStyle)
45 :Control(pParent, nWinStyle)
46 ,m_aTabControl( VclPtr<TabControl>::Create(this) )
47 ,m_pListener(NULL)
48 ,m_pObserver(NULL)
49 ,m_nNextId(1)
50 ,m_bHasHelpSection( false )
51 ,m_nMinHelpLines( 0 )
52 ,m_nMaxHelpLines( 0 )
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()
65 disposeOnce();
68 void OPropertyEditor::dispose()
70 Hide();
71 ClearAll();
72 m_aTabControl.disposeAndClear();
73 Control::dispose();
77 void OPropertyEditor::ClearAll()
79 m_nNextId=1;
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));
85 if (pPage)
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 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 ) );
122 if ( pPage )
123 nMinHeight += pPage->getMinimumHeight();
125 else
126 nMinHeight += 250; // arbitrary ...
128 return nMinHeight;
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));
140 if (pPage)
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()
169 if ( m_aTabControl )
170 m_aTabControl->GrabFocus();
174 OBrowserPage* OPropertyEditor::getPage( const OUString& _rPropertyName )
176 OBrowserPage* pPage = NULL;
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 ) );
180 return pPage;
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 Rectangle aPlayground(
205 Point( LAYOUT_BORDER_LEFT, LAYOUT_BORDER_TOP ),
206 Size(
207 GetOutputSizePixel().Width() - LAYOUT_BORDER_LEFT - LAYOUT_BORDER_RIGHT,
208 GetOutputSizePixel().Height() - LAYOUT_BORDER_TOP - LAYOUT_BORDER_BOTTOM
212 Rectangle aTabArea( aPlayground );
213 m_aTabControl->SetPosSizePixel( aTabArea.TopLeft(), aTabArea.GetSize() );
217 sal_uInt16 OPropertyEditor::AppendPage( const OUString & _rText, const OString& _rHelpId )
219 // obtain a new id
220 sal_uInt16 nId = m_nNextId++;
221 // insert the id
222 m_aTabControl->InsertPage(nId, _rText);
224 // create a new page
225 VclPtrInstance<OBrowserPage> pPage(m_aTabControl.get());
226 pPage->SetText( _rText );
227 // some knittings
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);
239 return 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));
254 if (pPage)
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();
271 else
272 return 0;
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));
284 if (pPage)
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, const void* _pArgument )
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 ) );
307 if ( !pPage )
308 continue;
309 (this->*_pOperation)( *pPage, _pArgument );
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 );
349 void OPropertyEditor::SetHelpText( const OUString& _rHelpText )
351 sal_uInt16 nCount = m_aTabControl->GetPageCount();
352 for ( sal_uInt16 i=0; i<nCount; ++i )
354 sal_uInt16 nID = m_aTabControl->GetPageId(i);
355 OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl->GetTabPage( nID ) );
356 if ( !pPage )
357 continue;
358 setHelpSectionText( *pPage, &_rHelpText );
363 void OPropertyEditor::SetHelpLineLimites( sal_Int32 _nMinLines, sal_Int32 _nMaxLines )
365 m_nMinHelpLines = _nMinLines;
366 m_nMaxHelpLines = _nMaxLines;
367 forEachPage( &OPropertyEditor::setHelpLineLimits );
371 void OPropertyEditor::enableHelpSection( OBrowserPage& _rPage, const void* )
373 _rPage.getListBox().EnableHelpSection( m_bHasHelpSection );
377 void OPropertyEditor::setHelpSectionText( OBrowserPage& _rPage, const void* _pPointerToOUString )
379 OSL_ENSURE( _pPointerToOUString, "OPropertyEditor::setHelpSectionText: invalid argument!" );
380 if ( !_pPointerToOUString )
381 return;
383 const OUString& rText( *static_cast<const OUString*>(_pPointerToOUString) );
384 _rPage.getListBox().SetHelpText( rText );
388 void OPropertyEditor::setHelpLineLimits( OBrowserPage& _rPage, const void* )
390 _rPage.getListBox().SetHelpLineLimites( m_nMinHelpLines, m_nMaxHelpLines );
394 sal_uInt16 OPropertyEditor::InsertEntry( const OLineDescriptor& rData, sal_uInt16 _nPageId, sal_uInt16 nPos )
396 // let the current page handle this
397 OBrowserPage* pPage = getPage( _nPageId );
398 DBG_ASSERT( pPage, "OPropertyEditor::InsertEntry: don't have such a page!" );
399 if ( !pPage )
400 return EDITOR_LIST_ENTRY_NOTFOUND;
402 sal_uInt16 nEntry = pPage->getListBox().InsertEntry( rData, nPos );
404 OSL_ENSURE( m_aPropertyPageIds.find( rData.sName ) == m_aPropertyPageIds.end(),
405 "OPropertyEditor::InsertEntry: property already present in the map!" );
406 m_aPropertyPageIds.insert( MapStringToPageId::value_type( rData.sName, _nPageId ) );
408 return nEntry;
412 void OPropertyEditor::RemoveEntry( const OUString& _rName )
414 OBrowserPage* pPage = getPage( _rName );
415 if ( pPage )
417 OSL_VERIFY( pPage->getListBox().RemoveEntry( _rName ) );
419 OSL_ENSURE( m_aPropertyPageIds.find( _rName ) != m_aPropertyPageIds.end(),
420 "OPropertyEditor::RemoveEntry: property not present in the map!" );
421 m_aPropertyPageIds.erase( _rName );
426 void OPropertyEditor::ChangeEntry( const OLineDescriptor& rData )
428 OBrowserPage* pPage = getPage( rData.sName );
429 if ( pPage )
430 pPage->getListBox().ChangeEntry( rData, EDITOR_LIST_REPLACE_EXISTING );
434 void OPropertyEditor::SetPropertyValue( const OUString& rEntryName, const Any& _rValue, bool _bUnknownValue )
436 OBrowserPage* pPage = getPage( rEntryName );
437 if ( pPage )
438 pPage->getListBox().SetPropertyValue( rEntryName, _rValue, _bUnknownValue );
442 sal_uInt16 OPropertyEditor::GetPropertyPos( const OUString& rEntryName ) const
444 sal_uInt16 nVal=EDITOR_LIST_ENTRY_NOTFOUND;
445 const OBrowserPage* pPage = getPage( rEntryName );
446 if ( pPage )
447 nVal = pPage->getListBox().GetPropertyPos( rEntryName );
448 return nVal;
452 void OPropertyEditor::ShowPropertyPage( sal_uInt16 _nPageId, bool _bShow )
454 if ( !_bShow )
456 sal_uInt16 nPagePos = m_aTabControl->GetPagePos( _nPageId );
457 if ( TAB_PAGE_NOTFOUND == nPagePos )
458 return;
459 DBG_ASSERT( m_aHiddenPages.find( _nPageId ) == m_aHiddenPages.end(), "OPropertyEditor::ShowPropertyPage: page already hidden!" );
461 m_aHiddenPages[ _nPageId ] = HiddenPage( nPagePos, m_aTabControl->GetTabPage( _nPageId ) );
462 m_aTabControl->RemovePage( _nPageId );
464 else
466 ::std::map< sal_uInt16, HiddenPage >::iterator aPagePos = m_aHiddenPages.find( _nPageId );
467 if ( aPagePos == m_aHiddenPages.end() )
468 return;
470 aPagePos->second.pPage->SetSizePixel( m_aTabControl->GetTabPageSizePixel() );
471 m_aTabControl->InsertPage( aPagePos->first, aPagePos->second.pPage->GetText(), aPagePos->second.nPos );
472 m_aTabControl->SetTabPage( aPagePos->first, aPagePos->second.pPage );
474 m_aHiddenPages.erase( aPagePos );
479 void OPropertyEditor::EnablePropertyControls( const OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable )
481 for ( sal_uInt16 i = 0; i < m_aTabControl->GetPageCount(); ++i )
483 OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl->GetTabPage( m_aTabControl->GetPageId( i ) ) );
484 if ( pPage )
485 pPage->getListBox().EnablePropertyControls( _rEntryName, _nControls, _bEnable );
490 void OPropertyEditor::EnablePropertyLine( const OUString& _rEntryName, bool _bEnable )
492 for ( sal_uInt16 i = 0; i < m_aTabControl->GetPageCount(); ++i )
494 OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl->GetTabPage( m_aTabControl->GetPageId( i ) ) );
495 if ( pPage )
496 pPage->getListBox().EnablePropertyLine( _rEntryName, _bEnable );
501 Reference< XPropertyControl > OPropertyEditor::GetPropertyControl(const OUString& rEntryName)
503 Reference< XPropertyControl > xControl;
504 // let the current page handle this
505 OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl->GetTabPage(m_aTabControl->GetCurPageId()));
506 if (pPage)
507 xControl = pPage->getListBox().GetPropertyControl(rEntryName);
508 return xControl;
512 IMPL_LINK_NOARG(OPropertyEditor, OnPageActivate)
514 if (m_aPageActivationHandler.IsSet())
515 m_aPageActivationHandler.Call(NULL);
516 return 0L;
520 IMPL_LINK_NOARG_TYPED(OPropertyEditor, OnPageDeactivate, TabControl *, bool)
522 // commit the data on the current (to-be-decativated) tab page
523 // (79404)
524 sal_Int32 nCurrentId = m_aTabControl->GetCurPageId();
525 OBrowserPage* pCurrentPage = static_cast<OBrowserPage*>(m_aTabControl->GetTabPage((sal_uInt16)nCurrentId));
526 if ( !pCurrentPage )
527 return true;
529 if ( pCurrentPage->getListBox().IsModified() )
530 pCurrentPage->getListBox().CommitModified();
532 return true;
536 } // namespace pcr
540 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */