1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "propertyeditor.hxx"
30 #include "browserpage.hxx"
31 #include "linedescriptor.hxx"
33 /** === begin UNO includes === **/
34 /** === end UNO includes === **/
35 #include <tools/debug.hxx>
37 //............................................................................
40 //............................................................................
42 #define LAYOUT_BORDER_LEFT 3
43 #define LAYOUT_BORDER_TOP 3
44 #define LAYOUT_BORDER_RIGHT 3
45 #define LAYOUT_BORDER_BOTTOM 3
47 /** === begin UNO using === **/
48 using ::com::sun::star::uno::Any
;
49 using ::com::sun::star::inspection::XPropertyControl
;
50 using ::com::sun::star::uno::Reference
;
51 /** === end UNO using === **/
53 //==================================================================
54 // class OPropertyEditor
55 //==================================================================
56 DBG_NAME(OPropertyEditor
)
57 //------------------------------------------------------------------
58 OPropertyEditor::OPropertyEditor( Window
* pParent
, WinBits nWinStyle
)
59 :Control(pParent
, nWinStyle
)
60 ,m_aTabControl( this )
62 ,m_bHasHelpSection( false )
66 DBG_CTOR(OPropertyEditor
,NULL
);
69 m_aTabControl
.SetDeactivatePageHdl(LINK(this, OPropertyEditor
, OnPageDeactivate
));
70 m_aTabControl
.SetActivatePageHdl(LINK(this, OPropertyEditor
, OnPageActivate
));
71 m_aTabControl
.SetBackground(GetBackground());
72 m_aTabControl
.SetPaintTransparent(sal_True
);
75 //------------------------------------------------------------------
76 OPropertyEditor::~OPropertyEditor()
80 DBG_DTOR(OPropertyEditor
,NULL
);
83 //------------------------------------------------------------------
84 void OPropertyEditor::ClearAll()
87 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
88 for(long i
= nCount
-1; i
>= 0; --i
)
90 sal_uInt16 nID
= m_aTabControl
.GetPageId((sal_uInt16
)i
);
91 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
94 pPage
->EnableInput(sal_False
);
95 m_aTabControl
.RemovePage(nID
);
99 m_aTabControl
.Clear();
102 MapStringToPageId aEmpty
;
103 m_aPropertyPageIds
.swap( aEmpty
);
106 while ( !m_aHiddenPages
.empty() )
108 delete m_aHiddenPages
.begin()->second
.pPage
;
109 m_aHiddenPages
.erase( m_aHiddenPages
.begin() );
113 //------------------------------------------------------------------
114 sal_Int32
OPropertyEditor::getMinimumHeight()
116 sal_Int32
nMinHeight( LAYOUT_BORDER_TOP
+ LAYOUT_BORDER_BOTTOM
);
118 if ( m_aTabControl
.GetPageCount() > 0 )
120 sal_uInt16 nFirstID
= m_aTabControl
.GetPageId( 0 );
122 // reserve space for the tabs themself
123 Rectangle
aTabArea( m_aTabControl
.GetTabBounds( nFirstID
) );
124 nMinHeight
+= aTabArea
.GetHeight();
126 // ask the page how much it requires
127 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( nFirstID
) );
129 nMinHeight
+= pPage
->getMinimumHeight();
132 nMinHeight
+= 250; // arbitrary ...
137 //------------------------------------------------------------------
138 sal_Int32
OPropertyEditor::getMinimumWidth()
140 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
141 sal_Int32 nPageMinWidth
= 0;
142 for(long i
= nCount
-1; i
>= 0; --i
)
144 sal_uInt16 nID
= m_aTabControl
.GetPageId((sal_uInt16
)i
);
145 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
148 sal_Int32 nCurPageMinWidth
= pPage
->getMinimumWidth();
149 if( nCurPageMinWidth
> nPageMinWidth
)
150 nPageMinWidth
= nCurPageMinWidth
;
153 return nPageMinWidth
+6;
156 //------------------------------------------------------------------
157 void OPropertyEditor::CommitModified()
159 // commit all of my pages, if necessary
161 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
162 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
164 sal_uInt16 nID
= m_aTabControl
.GetPageId( i
);
165 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( nID
) );
167 if ( pPage
&& pPage
->getListBox().IsModified() )
168 pPage
->getListBox().CommitModified();
172 //------------------------------------------------------------------
173 void OPropertyEditor::GetFocus()
175 m_aTabControl
.GrabFocus();
178 //------------------------------------------------------------------
179 OBrowserPage
* OPropertyEditor::getPage( const ::rtl::OUString
& _rPropertyName
)
181 OBrowserPage
* pPage
= NULL
;
182 MapStringToPageId::const_iterator aPropertyPageIdPos
= m_aPropertyPageIds
.find( _rPropertyName
);
183 if ( aPropertyPageIdPos
!= m_aPropertyPageIds
.end() )
184 pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( aPropertyPageIdPos
->second
) );
188 //------------------------------------------------------------------
189 const OBrowserPage
* OPropertyEditor::getPage( const ::rtl::OUString
& _rPropertyName
) const
191 return const_cast< OPropertyEditor
* >( this )->getPage( _rPropertyName
);
194 //------------------------------------------------------------------
195 OBrowserPage
* OPropertyEditor::getPage( sal_uInt16
& _rPageId
)
197 return static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( _rPageId
) );
200 //------------------------------------------------------------------
201 const OBrowserPage
* OPropertyEditor::getPage( sal_uInt16
& _rPageId
) const
203 return const_cast< OPropertyEditor
* >( this )->getPage( _rPageId
);
206 //------------------------------------------------------------------
207 void OPropertyEditor::Resize()
209 Rectangle
aPlayground(
210 Point( LAYOUT_BORDER_LEFT
, LAYOUT_BORDER_TOP
),
212 GetOutputSizePixel().Width() - LAYOUT_BORDER_LEFT
- LAYOUT_BORDER_RIGHT
,
213 GetOutputSizePixel().Height() - LAYOUT_BORDER_TOP
- LAYOUT_BORDER_BOTTOM
217 Rectangle
aTabArea( aPlayground
);
218 m_aTabControl
.SetPosSizePixel( aTabArea
.TopLeft(), aTabArea
.GetSize() );
221 //------------------------------------------------------------------
222 sal_uInt16
OPropertyEditor::AppendPage( const String
& _rText
, const rtl::OString
& _rHelpId
)
225 sal_uInt16 nId
= m_nNextId
++;
227 m_aTabControl
.InsertPage(nId
, _rText
);
230 OBrowserPage
* pPage
= new OBrowserPage(&m_aTabControl
);
231 pPage
->SetText( _rText
);
233 pPage
->SetSizePixel(m_aTabControl
.GetTabPageSizePixel());
234 pPage
->getListBox().SetListener(m_pListener
);
235 pPage
->getListBox().SetObserver(m_pObserver
);
236 pPage
->getListBox().EnableHelpSection( m_bHasHelpSection
);
237 pPage
->getListBox().SetHelpLineLimites( m_nMinHelpLines
, m_nMaxHelpLines
);
238 pPage
->SetHelpId( _rHelpId
);
240 // immediately activate the page
241 m_aTabControl
.SetTabPage(nId
, pPage
);
242 m_aTabControl
.SetCurPageId(nId
);
247 //------------------------------------------------------------------
248 void OPropertyEditor::SetHelpId( const rtl::OString
& rHelpId
)
250 Control::SetHelpId("");
251 m_aTabControl
.SetHelpId(rHelpId
);
254 //------------------------------------------------------------------
255 void OPropertyEditor::RemovePage(sal_uInt16 nID
)
257 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
260 pPage
->EnableInput(sal_False
);
261 m_aTabControl
.RemovePage(nID
);
266 //------------------------------------------------------------------
267 void OPropertyEditor::SetPage(sal_uInt16 nId
)
269 m_aTabControl
.SetCurPageId(nId
);
272 //------------------------------------------------------------------
273 sal_uInt16
OPropertyEditor::GetCurPage()
275 if(m_aTabControl
.GetPageCount()>0)
276 return m_aTabControl
.GetCurPageId();
281 //------------------------------------------------------------------
282 void OPropertyEditor::Update(const ::std::mem_fun_t
<void,OBrowserListBox
>& _aUpdateFunction
)
284 // forward this to all our pages
285 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
286 for (sal_uInt16 i
=0;i
<nCount
;++i
)
288 sal_uInt16 nID
= m_aTabControl
.GetPageId(i
);
289 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
291 _aUpdateFunction(&pPage
->getListBox());
294 //------------------------------------------------------------------
295 void OPropertyEditor::EnableUpdate()
297 Update(::std::mem_fun(&OBrowserListBox::EnableUpdate
));
299 //------------------------------------------------------------------
300 void OPropertyEditor::DisableUpdate()
302 Update(::std::mem_fun(&OBrowserListBox::DisableUpdate
));
305 //------------------------------------------------------------------
306 void OPropertyEditor::forEachPage( PageOperation _pOperation
, const void* _pArgument
)
308 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
309 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
311 sal_uInt16 nID
= m_aTabControl
.GetPageId(i
);
312 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( nID
) );
315 (this->*_pOperation
)( *pPage
, _pArgument
);
319 //------------------------------------------------------------------
320 void OPropertyEditor::setPageLineListener( OBrowserPage
& _rPage
, const void* )
322 _rPage
.getListBox().SetListener( m_pListener
);
325 //------------------------------------------------------------------
326 void OPropertyEditor::SetLineListener(IPropertyLineListener
* _pListener
)
328 m_pListener
= _pListener
;
329 forEachPage( &OPropertyEditor::setPageLineListener
);
332 //------------------------------------------------------------------
333 void OPropertyEditor::setPageControlObserver( OBrowserPage
& _rPage
, const void* )
335 _rPage
.getListBox().SetObserver( m_pObserver
);
338 //------------------------------------------------------------------
339 void OPropertyEditor::SetControlObserver( IPropertyControlObserver
* _pObserver
)
341 m_pObserver
= _pObserver
;
342 forEachPage( &OPropertyEditor::setPageControlObserver
);
345 //------------------------------------------------------------------
346 void OPropertyEditor::EnableHelpSection( bool _bEnable
)
348 m_bHasHelpSection
= _bEnable
;
349 forEachPage( &OPropertyEditor::enableHelpSection
);
352 //------------------------------------------------------------------
353 bool OPropertyEditor::HasHelpSection() const
355 return m_bHasHelpSection
;
358 //------------------------------------------------------------------
359 void OPropertyEditor::SetHelpText( const ::rtl::OUString
& _rHelpText
)
361 forEachPage( &OPropertyEditor::setHelpSectionText
, &_rHelpText
);
364 //------------------------------------------------------------------
365 void OPropertyEditor::SetHelpLineLimites( sal_Int32 _nMinLines
, sal_Int32 _nMaxLines
)
367 m_nMinHelpLines
= _nMinLines
;
368 m_nMaxHelpLines
= _nMaxLines
;
369 forEachPage( &OPropertyEditor::setHelpLineLimits
);
372 //------------------------------------------------------------------
373 void OPropertyEditor::enableHelpSection( OBrowserPage
& _rPage
, const void* )
375 _rPage
.getListBox().EnableHelpSection( m_bHasHelpSection
);
378 //------------------------------------------------------------------
379 void OPropertyEditor::setHelpSectionText( OBrowserPage
& _rPage
, const void* _pPointerToOUString
)
381 OSL_ENSURE( _pPointerToOUString
, "OPropertyEditor::setHelpSectionText: invalid argument!" );
382 if ( !_pPointerToOUString
)
385 const ::rtl::OUString
& rText( *(const ::rtl::OUString
*)_pPointerToOUString
);
386 _rPage
.getListBox().SetHelpText( rText
);
389 //------------------------------------------------------------------
390 void OPropertyEditor::setHelpLineLimits( OBrowserPage
& _rPage
, const void* )
392 _rPage
.getListBox().SetHelpLineLimites( m_nMinHelpLines
, m_nMaxHelpLines
);
395 //------------------------------------------------------------------
396 sal_uInt16
OPropertyEditor::InsertEntry( const OLineDescriptor
& rData
, sal_uInt16 _nPageId
, sal_uInt16 nPos
)
398 // let the current page handle this
399 OBrowserPage
* pPage
= getPage( _nPageId
);
400 DBG_ASSERT( pPage
, "OPropertyEditor::InsertEntry: don't have such a page!" );
402 return LISTBOX_ENTRY_NOTFOUND
;
404 sal_uInt16 nEntry
= pPage
->getListBox().InsertEntry( rData
, nPos
);
406 OSL_ENSURE( m_aPropertyPageIds
.find( rData
.sName
) == m_aPropertyPageIds
.end(),
407 "OPropertyEditor::InsertEntry: property already present in the map!" );
408 m_aPropertyPageIds
.insert( MapStringToPageId::value_type( rData
.sName
, _nPageId
) );
413 //------------------------------------------------------------------
414 void OPropertyEditor::RemoveEntry( const ::rtl::OUString
& _rName
)
416 OBrowserPage
* pPage
= getPage( _rName
);
419 OSL_VERIFY( pPage
->getListBox().RemoveEntry( _rName
) );
421 OSL_ENSURE( m_aPropertyPageIds
.find( _rName
) != m_aPropertyPageIds
.end(),
422 "OPropertyEditor::RemoveEntry: property not present in the map!" );
423 m_aPropertyPageIds
.erase( _rName
);
427 //------------------------------------------------------------------
428 void OPropertyEditor::ChangeEntry( const OLineDescriptor
& rData
)
430 OBrowserPage
* pPage
= getPage( rData
.sName
);
432 pPage
->getListBox().ChangeEntry( rData
, EDITOR_LIST_REPLACE_EXISTING
);
435 //------------------------------------------------------------------
436 void OPropertyEditor::SetPropertyValue( const ::rtl::OUString
& rEntryName
, const Any
& _rValue
, bool _bUnknownValue
)
438 OBrowserPage
* pPage
= getPage( rEntryName
);
440 pPage
->getListBox().SetPropertyValue( rEntryName
, _rValue
, _bUnknownValue
);
443 //------------------------------------------------------------------
444 sal_uInt16
OPropertyEditor::GetPropertyPos( const ::rtl::OUString
& rEntryName
) const
446 sal_uInt16 nVal
=LISTBOX_ENTRY_NOTFOUND
;
447 const OBrowserPage
* pPage
= getPage( rEntryName
);
449 nVal
= pPage
->getListBox().GetPropertyPos( rEntryName
);
453 //------------------------------------------------------------------
454 void OPropertyEditor::ShowPropertyPage( sal_uInt16 _nPageId
, bool _bShow
)
458 sal_uInt16 nPagePos
= m_aTabControl
.GetPagePos( _nPageId
);
459 if ( TAB_PAGE_NOTFOUND
== nPagePos
)
461 DBG_ASSERT( m_aHiddenPages
.find( _nPageId
) == m_aHiddenPages
.end(), "OPropertyEditor::ShowPropertyPage: page already hidden!" );
463 m_aHiddenPages
[ _nPageId
] = HiddenPage( nPagePos
, m_aTabControl
.GetTabPage( _nPageId
) );
464 m_aTabControl
.RemovePage( _nPageId
);
468 ::std::map
< sal_uInt16
, HiddenPage
>::iterator aPagePos
= m_aHiddenPages
.find( _nPageId
);
469 if ( aPagePos
== m_aHiddenPages
.end() )
472 aPagePos
->second
.pPage
->SetSizePixel( m_aTabControl
.GetTabPageSizePixel() );
473 m_aTabControl
.InsertPage( aPagePos
->first
, aPagePos
->second
.pPage
->GetText(), aPagePos
->second
.nPos
);
474 m_aTabControl
.SetTabPage( aPagePos
->first
, aPagePos
->second
.pPage
);
476 m_aHiddenPages
.erase( aPagePos
);
480 //------------------------------------------------------------------
481 void OPropertyEditor::EnablePropertyControls( const ::rtl::OUString
& _rEntryName
, sal_Int16 _nControls
, bool _bEnable
)
483 for ( sal_uInt16 i
= 0; i
< m_aTabControl
.GetPageCount(); ++i
)
485 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( m_aTabControl
.GetPageId( i
) ) );
487 pPage
->getListBox().EnablePropertyControls( _rEntryName
, _nControls
, _bEnable
);
491 //------------------------------------------------------------------
492 void OPropertyEditor::EnablePropertyLine( const ::rtl::OUString
& _rEntryName
, bool _bEnable
)
494 for ( sal_uInt16 i
= 0; i
< m_aTabControl
.GetPageCount(); ++i
)
496 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( m_aTabControl
.GetPageId( i
) ) );
498 pPage
->getListBox().EnablePropertyLine( _rEntryName
, _bEnable
);
502 //------------------------------------------------------------------
503 Reference
< XPropertyControl
> OPropertyEditor::GetPropertyControl(const ::rtl::OUString
& rEntryName
)
505 Reference
< XPropertyControl
> xControl
;
506 // let the current page handle this
507 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(m_aTabControl
.GetCurPageId()));
509 xControl
= pPage
->getListBox().GetPropertyControl(rEntryName
);
513 //------------------------------------------------------------------
514 IMPL_LINK_NOARG(OPropertyEditor
, OnPageActivate
)
516 if (m_aPageActivationHandler
.IsSet())
517 m_aPageActivationHandler
.Call(NULL
);
521 //------------------------------------------------------------------
522 IMPL_LINK_NOARG(OPropertyEditor
, OnPageDeactivate
)
524 // commit the data on the current (to-be-decativated) tab page
526 sal_Int32 nCurrentId
= m_aTabControl
.GetCurPageId();
527 OBrowserPage
* pCurrentPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage((sal_uInt16
)nCurrentId
));
531 if ( pCurrentPage
->getListBox().IsModified() )
532 pCurrentPage
->getListBox().CommitModified();
537 //............................................................................
539 //............................................................................
542 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */