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>
26 //............................................................................
29 //............................................................................
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
;
40 //==================================================================
41 // class OPropertyEditor
42 //==================================================================
43 DBG_NAME(OPropertyEditor
)
44 //------------------------------------------------------------------
45 OPropertyEditor::OPropertyEditor( Window
* pParent
, WinBits nWinStyle
)
46 :Control(pParent
, nWinStyle
)
47 ,m_aTabControl( this )
49 ,m_bHasHelpSection( false )
53 DBG_CTOR(OPropertyEditor
,NULL
);
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(sal_True
);
62 //------------------------------------------------------------------
63 OPropertyEditor::~OPropertyEditor()
67 DBG_DTOR(OPropertyEditor
,NULL
);
70 //------------------------------------------------------------------
71 void OPropertyEditor::ClearAll()
74 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
75 for(long i
= nCount
-1; i
>= 0; --i
)
77 sal_uInt16 nID
= m_aTabControl
.GetPageId((sal_uInt16
)i
);
78 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
81 pPage
->EnableInput(sal_False
);
82 m_aTabControl
.RemovePage(nID
);
86 m_aTabControl
.Clear();
89 MapStringToPageId aEmpty
;
90 m_aPropertyPageIds
.swap( aEmpty
);
93 while ( !m_aHiddenPages
.empty() )
95 delete m_aHiddenPages
.begin()->second
.pPage
;
96 m_aHiddenPages
.erase( m_aHiddenPages
.begin() );
100 //------------------------------------------------------------------
101 sal_Int32
OPropertyEditor::getMinimumHeight()
103 sal_Int32
nMinHeight( LAYOUT_BORDER_TOP
+ LAYOUT_BORDER_BOTTOM
);
105 if ( m_aTabControl
.GetPageCount() > 0 )
107 sal_uInt16 nFirstID
= m_aTabControl
.GetPageId( 0 );
109 // reserve space for the tabs themself
110 Rectangle
aTabArea( m_aTabControl
.GetTabBounds( nFirstID
) );
111 nMinHeight
+= aTabArea
.GetHeight();
113 // ask the page how much it requires
114 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( nFirstID
) );
116 nMinHeight
+= pPage
->getMinimumHeight();
119 nMinHeight
+= 250; // arbitrary ...
124 //------------------------------------------------------------------
125 sal_Int32
OPropertyEditor::getMinimumWidth()
127 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
128 sal_Int32 nPageMinWidth
= 0;
129 for(long i
= nCount
-1; i
>= 0; --i
)
131 sal_uInt16 nID
= m_aTabControl
.GetPageId((sal_uInt16
)i
);
132 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
135 sal_Int32 nCurPageMinWidth
= pPage
->getMinimumWidth();
136 if( nCurPageMinWidth
> nPageMinWidth
)
137 nPageMinWidth
= nCurPageMinWidth
;
140 return nPageMinWidth
+6;
143 //------------------------------------------------------------------
144 void OPropertyEditor::CommitModified()
146 // commit all of my pages, if necessary
148 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
149 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
151 sal_uInt16 nID
= m_aTabControl
.GetPageId( i
);
152 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( nID
) );
154 if ( pPage
&& pPage
->getListBox().IsModified() )
155 pPage
->getListBox().CommitModified();
159 //------------------------------------------------------------------
160 void OPropertyEditor::GetFocus()
162 m_aTabControl
.GrabFocus();
165 //------------------------------------------------------------------
166 OBrowserPage
* OPropertyEditor::getPage( const OUString
& _rPropertyName
)
168 OBrowserPage
* pPage
= NULL
;
169 MapStringToPageId::const_iterator aPropertyPageIdPos
= m_aPropertyPageIds
.find( _rPropertyName
);
170 if ( aPropertyPageIdPos
!= m_aPropertyPageIds
.end() )
171 pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( aPropertyPageIdPos
->second
) );
175 //------------------------------------------------------------------
176 const OBrowserPage
* OPropertyEditor::getPage( const OUString
& _rPropertyName
) const
178 return const_cast< OPropertyEditor
* >( this )->getPage( _rPropertyName
);
181 //------------------------------------------------------------------
182 OBrowserPage
* OPropertyEditor::getPage( sal_uInt16
& _rPageId
)
184 return static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( _rPageId
) );
187 //------------------------------------------------------------------
188 const OBrowserPage
* OPropertyEditor::getPage( sal_uInt16
& _rPageId
) const
190 return const_cast< OPropertyEditor
* >( this )->getPage( _rPageId
);
193 //------------------------------------------------------------------
194 void OPropertyEditor::Resize()
196 Rectangle
aPlayground(
197 Point( LAYOUT_BORDER_LEFT
, LAYOUT_BORDER_TOP
),
199 GetOutputSizePixel().Width() - LAYOUT_BORDER_LEFT
- LAYOUT_BORDER_RIGHT
,
200 GetOutputSizePixel().Height() - LAYOUT_BORDER_TOP
- LAYOUT_BORDER_BOTTOM
204 Rectangle
aTabArea( aPlayground
);
205 m_aTabControl
.SetPosSizePixel( aTabArea
.TopLeft(), aTabArea
.GetSize() );
208 //------------------------------------------------------------------
209 sal_uInt16
OPropertyEditor::AppendPage( const String
& _rText
, const OString
& _rHelpId
)
212 sal_uInt16 nId
= m_nNextId
++;
214 m_aTabControl
.InsertPage(nId
, _rText
);
217 OBrowserPage
* pPage
= new OBrowserPage(&m_aTabControl
);
218 pPage
->SetText( _rText
);
220 pPage
->SetSizePixel(m_aTabControl
.GetTabPageSizePixel());
221 pPage
->getListBox().SetListener(m_pListener
);
222 pPage
->getListBox().SetObserver(m_pObserver
);
223 pPage
->getListBox().EnableHelpSection( m_bHasHelpSection
);
224 pPage
->getListBox().SetHelpLineLimites( m_nMinHelpLines
, m_nMaxHelpLines
);
225 pPage
->SetHelpId( _rHelpId
);
227 // immediately activate the page
228 m_aTabControl
.SetTabPage(nId
, pPage
);
229 m_aTabControl
.SetCurPageId(nId
);
234 //------------------------------------------------------------------
235 void OPropertyEditor::SetHelpId( const OString
& rHelpId
)
237 Control::SetHelpId("");
238 m_aTabControl
.SetHelpId(rHelpId
);
241 //------------------------------------------------------------------
242 void OPropertyEditor::RemovePage(sal_uInt16 nID
)
244 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
247 pPage
->EnableInput(sal_False
);
248 m_aTabControl
.RemovePage(nID
);
253 //------------------------------------------------------------------
254 void OPropertyEditor::SetPage(sal_uInt16 nId
)
256 m_aTabControl
.SetCurPageId(nId
);
259 //------------------------------------------------------------------
260 sal_uInt16
OPropertyEditor::GetCurPage()
262 if(m_aTabControl
.GetPageCount()>0)
263 return m_aTabControl
.GetCurPageId();
268 //------------------------------------------------------------------
269 void OPropertyEditor::Update(const ::std::mem_fun_t
<void,OBrowserListBox
>& _aUpdateFunction
)
271 // forward this to all our pages
272 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
273 for (sal_uInt16 i
=0;i
<nCount
;++i
)
275 sal_uInt16 nID
= m_aTabControl
.GetPageId(i
);
276 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(nID
));
278 _aUpdateFunction(&pPage
->getListBox());
281 //------------------------------------------------------------------
282 void OPropertyEditor::EnableUpdate()
284 Update(::std::mem_fun(&OBrowserListBox::EnableUpdate
));
286 //------------------------------------------------------------------
287 void OPropertyEditor::DisableUpdate()
289 Update(::std::mem_fun(&OBrowserListBox::DisableUpdate
));
292 //------------------------------------------------------------------
293 void OPropertyEditor::forEachPage( PageOperation _pOperation
, const void* _pArgument
)
295 sal_uInt16 nCount
= m_aTabControl
.GetPageCount();
296 for ( sal_uInt16 i
=0; i
<nCount
; ++i
)
298 sal_uInt16 nID
= m_aTabControl
.GetPageId(i
);
299 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( nID
) );
302 (this->*_pOperation
)( *pPage
, _pArgument
);
306 //------------------------------------------------------------------
307 void OPropertyEditor::setPageLineListener( OBrowserPage
& _rPage
, const void* )
309 _rPage
.getListBox().SetListener( m_pListener
);
312 //------------------------------------------------------------------
313 void OPropertyEditor::SetLineListener(IPropertyLineListener
* _pListener
)
315 m_pListener
= _pListener
;
316 forEachPage( &OPropertyEditor::setPageLineListener
);
319 //------------------------------------------------------------------
320 void OPropertyEditor::setPageControlObserver( OBrowserPage
& _rPage
, const void* )
322 _rPage
.getListBox().SetObserver( m_pObserver
);
325 //------------------------------------------------------------------
326 void OPropertyEditor::SetControlObserver( IPropertyControlObserver
* _pObserver
)
328 m_pObserver
= _pObserver
;
329 forEachPage( &OPropertyEditor::setPageControlObserver
);
332 //------------------------------------------------------------------
333 void OPropertyEditor::EnableHelpSection( bool _bEnable
)
335 m_bHasHelpSection
= _bEnable
;
336 forEachPage( &OPropertyEditor::enableHelpSection
);
339 //------------------------------------------------------------------
340 bool OPropertyEditor::HasHelpSection() const
342 return m_bHasHelpSection
;
345 //------------------------------------------------------------------
346 void OPropertyEditor::SetHelpText( const OUString
& _rHelpText
)
348 forEachPage( &OPropertyEditor::setHelpSectionText
, &_rHelpText
);
351 //------------------------------------------------------------------
352 void OPropertyEditor::SetHelpLineLimites( sal_Int32 _nMinLines
, sal_Int32 _nMaxLines
)
354 m_nMinHelpLines
= _nMinLines
;
355 m_nMaxHelpLines
= _nMaxLines
;
356 forEachPage( &OPropertyEditor::setHelpLineLimits
);
359 //------------------------------------------------------------------
360 void OPropertyEditor::enableHelpSection( OBrowserPage
& _rPage
, const void* )
362 _rPage
.getListBox().EnableHelpSection( m_bHasHelpSection
);
365 //------------------------------------------------------------------
366 void OPropertyEditor::setHelpSectionText( OBrowserPage
& _rPage
, const void* _pPointerToOUString
)
368 OSL_ENSURE( _pPointerToOUString
, "OPropertyEditor::setHelpSectionText: invalid argument!" );
369 if ( !_pPointerToOUString
)
372 const OUString
& rText( *(const OUString
*)_pPointerToOUString
);
373 _rPage
.getListBox().SetHelpText( rText
);
376 //------------------------------------------------------------------
377 void OPropertyEditor::setHelpLineLimits( OBrowserPage
& _rPage
, const void* )
379 _rPage
.getListBox().SetHelpLineLimites( m_nMinHelpLines
, m_nMaxHelpLines
);
382 //------------------------------------------------------------------
383 sal_uInt16
OPropertyEditor::InsertEntry( const OLineDescriptor
& rData
, sal_uInt16 _nPageId
, sal_uInt16 nPos
)
385 // let the current page handle this
386 OBrowserPage
* pPage
= getPage( _nPageId
);
387 DBG_ASSERT( pPage
, "OPropertyEditor::InsertEntry: don't have such a page!" );
389 return LISTBOX_ENTRY_NOTFOUND
;
391 sal_uInt16 nEntry
= pPage
->getListBox().InsertEntry( rData
, nPos
);
393 OSL_ENSURE( m_aPropertyPageIds
.find( rData
.sName
) == m_aPropertyPageIds
.end(),
394 "OPropertyEditor::InsertEntry: property already present in the map!" );
395 m_aPropertyPageIds
.insert( MapStringToPageId::value_type( rData
.sName
, _nPageId
) );
400 //------------------------------------------------------------------
401 void OPropertyEditor::RemoveEntry( const OUString
& _rName
)
403 OBrowserPage
* pPage
= getPage( _rName
);
406 OSL_VERIFY( pPage
->getListBox().RemoveEntry( _rName
) );
408 OSL_ENSURE( m_aPropertyPageIds
.find( _rName
) != m_aPropertyPageIds
.end(),
409 "OPropertyEditor::RemoveEntry: property not present in the map!" );
410 m_aPropertyPageIds
.erase( _rName
);
414 //------------------------------------------------------------------
415 void OPropertyEditor::ChangeEntry( const OLineDescriptor
& rData
)
417 OBrowserPage
* pPage
= getPage( rData
.sName
);
419 pPage
->getListBox().ChangeEntry( rData
, EDITOR_LIST_REPLACE_EXISTING
);
422 //------------------------------------------------------------------
423 void OPropertyEditor::SetPropertyValue( const OUString
& rEntryName
, const Any
& _rValue
, bool _bUnknownValue
)
425 OBrowserPage
* pPage
= getPage( rEntryName
);
427 pPage
->getListBox().SetPropertyValue( rEntryName
, _rValue
, _bUnknownValue
);
430 //------------------------------------------------------------------
431 sal_uInt16
OPropertyEditor::GetPropertyPos( const OUString
& rEntryName
) const
433 sal_uInt16 nVal
=LISTBOX_ENTRY_NOTFOUND
;
434 const OBrowserPage
* pPage
= getPage( rEntryName
);
436 nVal
= pPage
->getListBox().GetPropertyPos( rEntryName
);
440 //------------------------------------------------------------------
441 void OPropertyEditor::ShowPropertyPage( sal_uInt16 _nPageId
, bool _bShow
)
445 sal_uInt16 nPagePos
= m_aTabControl
.GetPagePos( _nPageId
);
446 if ( TAB_PAGE_NOTFOUND
== nPagePos
)
448 DBG_ASSERT( m_aHiddenPages
.find( _nPageId
) == m_aHiddenPages
.end(), "OPropertyEditor::ShowPropertyPage: page already hidden!" );
450 m_aHiddenPages
[ _nPageId
] = HiddenPage( nPagePos
, m_aTabControl
.GetTabPage( _nPageId
) );
451 m_aTabControl
.RemovePage( _nPageId
);
455 ::std::map
< sal_uInt16
, HiddenPage
>::iterator aPagePos
= m_aHiddenPages
.find( _nPageId
);
456 if ( aPagePos
== m_aHiddenPages
.end() )
459 aPagePos
->second
.pPage
->SetSizePixel( m_aTabControl
.GetTabPageSizePixel() );
460 m_aTabControl
.InsertPage( aPagePos
->first
, aPagePos
->second
.pPage
->GetText(), aPagePos
->second
.nPos
);
461 m_aTabControl
.SetTabPage( aPagePos
->first
, aPagePos
->second
.pPage
);
463 m_aHiddenPages
.erase( aPagePos
);
467 //------------------------------------------------------------------
468 void OPropertyEditor::EnablePropertyControls( const OUString
& _rEntryName
, sal_Int16 _nControls
, bool _bEnable
)
470 for ( sal_uInt16 i
= 0; i
< m_aTabControl
.GetPageCount(); ++i
)
472 OBrowserPage
* pPage
= static_cast< OBrowserPage
* >( m_aTabControl
.GetTabPage( m_aTabControl
.GetPageId( i
) ) );
474 pPage
->getListBox().EnablePropertyControls( _rEntryName
, _nControls
, _bEnable
);
478 //------------------------------------------------------------------
479 void OPropertyEditor::EnablePropertyLine( const OUString
& _rEntryName
, 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
) ) );
485 pPage
->getListBox().EnablePropertyLine( _rEntryName
, _bEnable
);
489 //------------------------------------------------------------------
490 Reference
< XPropertyControl
> OPropertyEditor::GetPropertyControl(const OUString
& rEntryName
)
492 Reference
< XPropertyControl
> xControl
;
493 // let the current page handle this
494 OBrowserPage
* pPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage(m_aTabControl
.GetCurPageId()));
496 xControl
= pPage
->getListBox().GetPropertyControl(rEntryName
);
500 //------------------------------------------------------------------
501 IMPL_LINK_NOARG(OPropertyEditor
, OnPageActivate
)
503 if (m_aPageActivationHandler
.IsSet())
504 m_aPageActivationHandler
.Call(NULL
);
508 //------------------------------------------------------------------
509 IMPL_LINK_NOARG(OPropertyEditor
, OnPageDeactivate
)
511 // commit the data on the current (to-be-decativated) tab page
513 sal_Int32 nCurrentId
= m_aTabControl
.GetCurPageId();
514 OBrowserPage
* pCurrentPage
= static_cast<OBrowserPage
*>(m_aTabControl
.GetTabPage((sal_uInt16
)nCurrentId
));
518 if ( pCurrentPage
->getListBox().IsModified() )
519 pCurrentPage
->getListBox().CommitModified();
524 //............................................................................
526 //............................................................................
529 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */