Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "propertyeditor.hxx"
21 : #include "browserpage.hxx"
22 : #include "linedescriptor.hxx"
23 :
24 : #include <tools/debug.hxx>
25 :
26 : //............................................................................
27 : namespace pcr
28 : {
29 : //............................................................................
30 :
31 : #define LAYOUT_BORDER_LEFT 3
32 : #define LAYOUT_BORDER_TOP 3
33 : #define LAYOUT_BORDER_RIGHT 3
34 : #define LAYOUT_BORDER_BOTTOM 3
35 :
36 : using ::com::sun::star::uno::Any;
37 : using ::com::sun::star::inspection::XPropertyControl;
38 : using ::com::sun::star::uno::Reference;
39 :
40 : //==================================================================
41 : // class OPropertyEditor
42 : //==================================================================
43 : DBG_NAME(OPropertyEditor)
44 : //------------------------------------------------------------------
45 2 : OPropertyEditor::OPropertyEditor( Window* pParent, WinBits nWinStyle)
46 : :Control(pParent, nWinStyle)
47 : ,m_aTabControl( this )
48 : ,m_nNextId(1)
49 : ,m_bHasHelpSection( false )
50 : ,m_nMinHelpLines( 0 )
51 2 : ,m_nMaxHelpLines( 0 )
52 : {
53 : DBG_CTOR(OPropertyEditor,NULL);
54 :
55 2 : m_aTabControl.Show();
56 2 : m_aTabControl.SetDeactivatePageHdl(LINK(this, OPropertyEditor, OnPageDeactivate));
57 2 : m_aTabControl.SetActivatePageHdl(LINK(this, OPropertyEditor, OnPageActivate));
58 2 : m_aTabControl.SetBackground(GetBackground());
59 2 : m_aTabControl.SetPaintTransparent(sal_True);
60 2 : }
61 :
62 : //------------------------------------------------------------------
63 6 : OPropertyEditor::~OPropertyEditor()
64 : {
65 2 : Hide();
66 2 : ClearAll();
67 : DBG_DTOR(OPropertyEditor,NULL);
68 4 : }
69 :
70 : //------------------------------------------------------------------
71 4 : void OPropertyEditor::ClearAll()
72 : {
73 4 : m_nNextId=1;
74 4 : sal_uInt16 nCount = m_aTabControl.GetPageCount();
75 4 : for(long i = nCount-1; i >= 0; --i)
76 : {
77 0 : sal_uInt16 nID = m_aTabControl.GetPageId((sal_uInt16)i);
78 0 : OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl.GetTabPage(nID));
79 0 : if (pPage)
80 : {
81 0 : pPage->EnableInput(sal_False);
82 0 : m_aTabControl.RemovePage(nID);
83 0 : delete pPage;
84 : }
85 : }
86 4 : m_aTabControl.Clear();
87 :
88 : {
89 4 : MapStringToPageId aEmpty;
90 4 : m_aPropertyPageIds.swap( aEmpty );
91 : }
92 :
93 8 : while ( !m_aHiddenPages.empty() )
94 : {
95 0 : delete m_aHiddenPages.begin()->second.pPage;
96 0 : m_aHiddenPages.erase( m_aHiddenPages.begin() );
97 : }
98 4 : }
99 :
100 : //------------------------------------------------------------------
101 0 : sal_Int32 OPropertyEditor::getMinimumHeight()
102 : {
103 0 : sal_Int32 nMinHeight( LAYOUT_BORDER_TOP + LAYOUT_BORDER_BOTTOM );
104 :
105 0 : if ( m_aTabControl.GetPageCount() > 0 )
106 : {
107 0 : sal_uInt16 nFirstID = m_aTabControl.GetPageId( 0 );
108 :
109 : // reserve space for the tabs themself
110 0 : Rectangle aTabArea( m_aTabControl.GetTabBounds( nFirstID ) );
111 0 : nMinHeight += aTabArea.GetHeight();
112 :
113 : // ask the page how much it requires
114 0 : OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( nFirstID ) );
115 0 : if ( pPage )
116 0 : nMinHeight += pPage->getMinimumHeight();
117 : }
118 : else
119 0 : nMinHeight += 250; // arbitrary ...
120 :
121 0 : return nMinHeight;
122 : }
123 :
124 : //------------------------------------------------------------------
125 0 : sal_Int32 OPropertyEditor::getMinimumWidth()
126 : {
127 0 : sal_uInt16 nCount = m_aTabControl.GetPageCount();
128 0 : sal_Int32 nPageMinWidth = 0;
129 0 : for(long i = nCount-1; i >= 0; --i)
130 : {
131 0 : sal_uInt16 nID = m_aTabControl.GetPageId((sal_uInt16)i);
132 0 : OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl.GetTabPage(nID));
133 0 : if (pPage)
134 : {
135 0 : sal_Int32 nCurPageMinWidth = pPage->getMinimumWidth();
136 0 : if( nCurPageMinWidth > nPageMinWidth )
137 0 : nPageMinWidth = nCurPageMinWidth;
138 : }
139 : }
140 0 : return nPageMinWidth+6;
141 : }
142 :
143 : //------------------------------------------------------------------
144 2 : void OPropertyEditor::CommitModified()
145 : {
146 : // commit all of my pages, if necessary
147 :
148 2 : sal_uInt16 nCount = m_aTabControl.GetPageCount();
149 2 : for ( sal_uInt16 i=0; i<nCount; ++i )
150 : {
151 0 : sal_uInt16 nID = m_aTabControl.GetPageId( i );
152 0 : OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( nID ) );
153 :
154 0 : if ( pPage && pPage->getListBox().IsModified() )
155 0 : pPage->getListBox().CommitModified();
156 : }
157 2 : }
158 :
159 : //------------------------------------------------------------------
160 0 : void OPropertyEditor::GetFocus()
161 : {
162 0 : m_aTabControl.GrabFocus();
163 0 : }
164 :
165 : //------------------------------------------------------------------
166 0 : OBrowserPage* OPropertyEditor::getPage( const OUString& _rPropertyName )
167 : {
168 0 : OBrowserPage* pPage = NULL;
169 0 : MapStringToPageId::const_iterator aPropertyPageIdPos = m_aPropertyPageIds.find( _rPropertyName );
170 0 : if ( aPropertyPageIdPos != m_aPropertyPageIds.end() )
171 0 : pPage = static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( aPropertyPageIdPos->second ) );
172 0 : return pPage;
173 : }
174 :
175 : //------------------------------------------------------------------
176 0 : const OBrowserPage* OPropertyEditor::getPage( const OUString& _rPropertyName ) const
177 : {
178 0 : return const_cast< OPropertyEditor* >( this )->getPage( _rPropertyName );
179 : }
180 :
181 : //------------------------------------------------------------------
182 0 : OBrowserPage* OPropertyEditor::getPage( sal_uInt16& _rPageId )
183 : {
184 0 : return static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( _rPageId ) );
185 : }
186 :
187 : //------------------------------------------------------------------
188 0 : const OBrowserPage* OPropertyEditor::getPage( sal_uInt16& _rPageId ) const
189 : {
190 0 : return const_cast< OPropertyEditor* >( this )->getPage( _rPageId );
191 : }
192 :
193 : //------------------------------------------------------------------
194 2 : void OPropertyEditor::Resize()
195 : {
196 : Rectangle aPlayground(
197 : Point( LAYOUT_BORDER_LEFT, LAYOUT_BORDER_TOP ),
198 : Size(
199 4 : GetOutputSizePixel().Width() - LAYOUT_BORDER_LEFT - LAYOUT_BORDER_RIGHT,
200 4 : GetOutputSizePixel().Height() - LAYOUT_BORDER_TOP - LAYOUT_BORDER_BOTTOM
201 : )
202 4 : );
203 :
204 2 : Rectangle aTabArea( aPlayground );
205 2 : m_aTabControl.SetPosSizePixel( aTabArea.TopLeft(), aTabArea.GetSize() );
206 2 : }
207 :
208 : //------------------------------------------------------------------
209 0 : sal_uInt16 OPropertyEditor::AppendPage( const String & _rText, const OString& _rHelpId )
210 : {
211 : // obtain a new id
212 0 : sal_uInt16 nId = m_nNextId++;
213 : // insert the id
214 0 : m_aTabControl.InsertPage(nId, _rText);
215 :
216 : // create a new page
217 0 : OBrowserPage* pPage = new OBrowserPage(&m_aTabControl);
218 0 : pPage->SetText( _rText );
219 : // some knittings
220 0 : pPage->SetSizePixel(m_aTabControl.GetTabPageSizePixel());
221 0 : pPage->getListBox().SetListener(m_pListener);
222 0 : pPage->getListBox().SetObserver(m_pObserver);
223 0 : pPage->getListBox().EnableHelpSection( m_bHasHelpSection );
224 0 : pPage->getListBox().SetHelpLineLimites( m_nMinHelpLines, m_nMaxHelpLines );
225 0 : pPage->SetHelpId( _rHelpId );
226 :
227 : // immediately activate the page
228 0 : m_aTabControl.SetTabPage(nId, pPage);
229 0 : m_aTabControl.SetCurPageId(nId);
230 :
231 0 : return nId;
232 : }
233 :
234 : //------------------------------------------------------------------
235 2 : void OPropertyEditor::SetHelpId( const OString& rHelpId )
236 : {
237 2 : Control::SetHelpId("");
238 2 : m_aTabControl.SetHelpId(rHelpId);
239 2 : }
240 :
241 : //------------------------------------------------------------------
242 0 : void OPropertyEditor::RemovePage(sal_uInt16 nID)
243 : {
244 0 : OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl.GetTabPage(nID));
245 :
246 0 : if (pPage)
247 0 : pPage->EnableInput(sal_False);
248 0 : m_aTabControl.RemovePage(nID);
249 0 : if (pPage)
250 0 : delete pPage;
251 0 : }
252 :
253 : //------------------------------------------------------------------
254 0 : void OPropertyEditor::SetPage(sal_uInt16 nId)
255 : {
256 0 : m_aTabControl.SetCurPageId(nId);
257 0 : }
258 :
259 : //------------------------------------------------------------------
260 2 : sal_uInt16 OPropertyEditor::GetCurPage()
261 : {
262 2 : if(m_aTabControl.GetPageCount()>0)
263 0 : return m_aTabControl.GetCurPageId();
264 : else
265 2 : return 0;
266 : }
267 :
268 : //------------------------------------------------------------------
269 4 : void OPropertyEditor::Update(const ::std::mem_fun_t<void,OBrowserListBox>& _aUpdateFunction)
270 : {
271 : // forward this to all our pages
272 4 : sal_uInt16 nCount = m_aTabControl.GetPageCount();
273 4 : for (sal_uInt16 i=0;i<nCount;++i)
274 : {
275 0 : sal_uInt16 nID = m_aTabControl.GetPageId(i);
276 0 : OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl.GetTabPage(nID));
277 0 : if (pPage)
278 0 : _aUpdateFunction(&pPage->getListBox());
279 : }
280 4 : }
281 : //------------------------------------------------------------------
282 2 : void OPropertyEditor::EnableUpdate()
283 : {
284 2 : Update(::std::mem_fun(&OBrowserListBox::EnableUpdate));
285 2 : }
286 : //------------------------------------------------------------------
287 2 : void OPropertyEditor::DisableUpdate()
288 : {
289 2 : Update(::std::mem_fun(&OBrowserListBox::DisableUpdate));
290 2 : }
291 :
292 : //------------------------------------------------------------------
293 8 : void OPropertyEditor::forEachPage( PageOperation _pOperation, const void* _pArgument )
294 : {
295 8 : sal_uInt16 nCount = m_aTabControl.GetPageCount();
296 8 : for ( sal_uInt16 i=0; i<nCount; ++i )
297 : {
298 0 : sal_uInt16 nID = m_aTabControl.GetPageId(i);
299 0 : OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( nID ) );
300 0 : if ( !pPage )
301 0 : continue;
302 0 : (this->*_pOperation)( *pPage, _pArgument );
303 : }
304 8 : }
305 :
306 : //------------------------------------------------------------------
307 0 : void OPropertyEditor::setPageLineListener( OBrowserPage& _rPage, const void* )
308 : {
309 0 : _rPage.getListBox().SetListener( m_pListener );
310 0 : }
311 :
312 : //------------------------------------------------------------------
313 2 : void OPropertyEditor::SetLineListener(IPropertyLineListener* _pListener)
314 : {
315 2 : m_pListener = _pListener;
316 2 : forEachPage( &OPropertyEditor::setPageLineListener );
317 2 : }
318 :
319 : //------------------------------------------------------------------
320 0 : void OPropertyEditor::setPageControlObserver( OBrowserPage& _rPage, const void* )
321 : {
322 0 : _rPage.getListBox().SetObserver( m_pObserver );
323 0 : }
324 :
325 : //------------------------------------------------------------------
326 2 : void OPropertyEditor::SetControlObserver( IPropertyControlObserver* _pObserver )
327 : {
328 2 : m_pObserver = _pObserver;
329 2 : forEachPage( &OPropertyEditor::setPageControlObserver );
330 2 : }
331 :
332 : //------------------------------------------------------------------
333 2 : void OPropertyEditor::EnableHelpSection( bool _bEnable )
334 : {
335 2 : m_bHasHelpSection = _bEnable;
336 2 : forEachPage( &OPropertyEditor::enableHelpSection );
337 2 : }
338 :
339 : //------------------------------------------------------------------
340 0 : bool OPropertyEditor::HasHelpSection() const
341 : {
342 0 : return m_bHasHelpSection;
343 : }
344 :
345 : //------------------------------------------------------------------
346 0 : void OPropertyEditor::SetHelpText( const OUString& _rHelpText )
347 : {
348 0 : forEachPage( &OPropertyEditor::setHelpSectionText, &_rHelpText );
349 0 : }
350 :
351 : //------------------------------------------------------------------
352 2 : void OPropertyEditor::SetHelpLineLimites( sal_Int32 _nMinLines, sal_Int32 _nMaxLines )
353 : {
354 2 : m_nMinHelpLines = _nMinLines;
355 2 : m_nMaxHelpLines = _nMaxLines;
356 2 : forEachPage( &OPropertyEditor::setHelpLineLimits );
357 2 : }
358 :
359 : //------------------------------------------------------------------
360 0 : void OPropertyEditor::enableHelpSection( OBrowserPage& _rPage, const void* )
361 : {
362 0 : _rPage.getListBox().EnableHelpSection( m_bHasHelpSection );
363 0 : }
364 :
365 : //------------------------------------------------------------------
366 0 : void OPropertyEditor::setHelpSectionText( OBrowserPage& _rPage, const void* _pPointerToOUString )
367 : {
368 : OSL_ENSURE( _pPointerToOUString, "OPropertyEditor::setHelpSectionText: invalid argument!" );
369 0 : if ( !_pPointerToOUString )
370 0 : return;
371 :
372 0 : const OUString& rText( *(const OUString*)_pPointerToOUString );
373 0 : _rPage.getListBox().SetHelpText( rText );
374 : }
375 :
376 : //------------------------------------------------------------------
377 0 : void OPropertyEditor::setHelpLineLimits( OBrowserPage& _rPage, const void* )
378 : {
379 0 : _rPage.getListBox().SetHelpLineLimites( m_nMinHelpLines, m_nMaxHelpLines );
380 0 : }
381 :
382 : //------------------------------------------------------------------
383 0 : sal_uInt16 OPropertyEditor::InsertEntry( const OLineDescriptor& rData, sal_uInt16 _nPageId, sal_uInt16 nPos )
384 : {
385 : // let the current page handle this
386 0 : OBrowserPage* pPage = getPage( _nPageId );
387 : DBG_ASSERT( pPage, "OPropertyEditor::InsertEntry: don't have such a page!" );
388 0 : if ( !pPage )
389 0 : return LISTBOX_ENTRY_NOTFOUND;
390 :
391 0 : sal_uInt16 nEntry = pPage->getListBox().InsertEntry( rData, nPos );
392 :
393 : OSL_ENSURE( m_aPropertyPageIds.find( rData.sName ) == m_aPropertyPageIds.end(),
394 : "OPropertyEditor::InsertEntry: property already present in the map!" );
395 0 : m_aPropertyPageIds.insert( MapStringToPageId::value_type( rData.sName, _nPageId ) );
396 :
397 0 : return nEntry;
398 : }
399 :
400 : //------------------------------------------------------------------
401 0 : void OPropertyEditor::RemoveEntry( const OUString& _rName )
402 : {
403 0 : OBrowserPage* pPage = getPage( _rName );
404 0 : if ( pPage )
405 : {
406 0 : OSL_VERIFY( pPage->getListBox().RemoveEntry( _rName ) );
407 :
408 : OSL_ENSURE( m_aPropertyPageIds.find( _rName ) != m_aPropertyPageIds.end(),
409 : "OPropertyEditor::RemoveEntry: property not present in the map!" );
410 0 : m_aPropertyPageIds.erase( _rName );
411 : }
412 0 : }
413 :
414 : //------------------------------------------------------------------
415 0 : void OPropertyEditor::ChangeEntry( const OLineDescriptor& rData )
416 : {
417 0 : OBrowserPage* pPage = getPage( rData.sName );
418 0 : if ( pPage )
419 0 : pPage->getListBox().ChangeEntry( rData, EDITOR_LIST_REPLACE_EXISTING );
420 0 : }
421 :
422 : //------------------------------------------------------------------
423 0 : void OPropertyEditor::SetPropertyValue( const OUString& rEntryName, const Any& _rValue, bool _bUnknownValue )
424 : {
425 0 : OBrowserPage* pPage = getPage( rEntryName );
426 0 : if ( pPage )
427 0 : pPage->getListBox().SetPropertyValue( rEntryName, _rValue, _bUnknownValue );
428 0 : }
429 :
430 : //------------------------------------------------------------------
431 0 : sal_uInt16 OPropertyEditor::GetPropertyPos( const OUString& rEntryName ) const
432 : {
433 0 : sal_uInt16 nVal=LISTBOX_ENTRY_NOTFOUND;
434 0 : const OBrowserPage* pPage = getPage( rEntryName );
435 0 : if ( pPage )
436 0 : nVal = pPage->getListBox().GetPropertyPos( rEntryName );
437 0 : return nVal;
438 : }
439 :
440 : //------------------------------------------------------------------
441 0 : void OPropertyEditor::ShowPropertyPage( sal_uInt16 _nPageId, bool _bShow )
442 : {
443 0 : if ( !_bShow )
444 : {
445 0 : sal_uInt16 nPagePos = m_aTabControl.GetPagePos( _nPageId );
446 0 : if ( TAB_PAGE_NOTFOUND == nPagePos )
447 0 : return;
448 : DBG_ASSERT( m_aHiddenPages.find( _nPageId ) == m_aHiddenPages.end(), "OPropertyEditor::ShowPropertyPage: page already hidden!" );
449 :
450 0 : m_aHiddenPages[ _nPageId ] = HiddenPage( nPagePos, m_aTabControl.GetTabPage( _nPageId ) );
451 0 : m_aTabControl.RemovePage( _nPageId );
452 : }
453 : else
454 : {
455 0 : ::std::map< sal_uInt16, HiddenPage >::iterator aPagePos = m_aHiddenPages.find( _nPageId );
456 0 : if ( aPagePos == m_aHiddenPages.end() )
457 0 : return;
458 :
459 0 : aPagePos->second.pPage->SetSizePixel( m_aTabControl.GetTabPageSizePixel() );
460 0 : m_aTabControl.InsertPage( aPagePos->first, aPagePos->second.pPage->GetText(), aPagePos->second.nPos );
461 0 : m_aTabControl.SetTabPage( aPagePos->first, aPagePos->second.pPage );
462 :
463 0 : m_aHiddenPages.erase( aPagePos );
464 : }
465 : }
466 :
467 : //------------------------------------------------------------------
468 0 : void OPropertyEditor::EnablePropertyControls( const OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable )
469 : {
470 0 : for ( sal_uInt16 i = 0; i < m_aTabControl.GetPageCount(); ++i )
471 : {
472 0 : OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( m_aTabControl.GetPageId( i ) ) );
473 0 : if ( pPage )
474 0 : pPage->getListBox().EnablePropertyControls( _rEntryName, _nControls, _bEnable );
475 : }
476 0 : }
477 :
478 : //------------------------------------------------------------------
479 0 : void OPropertyEditor::EnablePropertyLine( const OUString& _rEntryName, bool _bEnable )
480 : {
481 0 : for ( sal_uInt16 i = 0; i < m_aTabControl.GetPageCount(); ++i )
482 : {
483 0 : OBrowserPage* pPage = static_cast< OBrowserPage* >( m_aTabControl.GetTabPage( m_aTabControl.GetPageId( i ) ) );
484 0 : if ( pPage )
485 0 : pPage->getListBox().EnablePropertyLine( _rEntryName, _bEnable );
486 : }
487 0 : }
488 :
489 : //------------------------------------------------------------------
490 0 : Reference< XPropertyControl > OPropertyEditor::GetPropertyControl(const OUString& rEntryName)
491 : {
492 0 : Reference< XPropertyControl > xControl;
493 : // let the current page handle this
494 0 : OBrowserPage* pPage = static_cast<OBrowserPage*>(m_aTabControl.GetTabPage(m_aTabControl.GetCurPageId()));
495 0 : if (pPage)
496 0 : xControl = pPage->getListBox().GetPropertyControl(rEntryName);
497 0 : return xControl;
498 : }
499 :
500 : //------------------------------------------------------------------
501 0 : IMPL_LINK_NOARG(OPropertyEditor, OnPageActivate)
502 : {
503 0 : if (m_aPageActivationHandler.IsSet())
504 0 : m_aPageActivationHandler.Call(NULL);
505 0 : return 0L;
506 : }
507 :
508 : //------------------------------------------------------------------
509 0 : IMPL_LINK_NOARG(OPropertyEditor, OnPageDeactivate)
510 : {
511 : // commit the data on the current (to-be-decativated) tab page
512 : // (79404)
513 0 : sal_Int32 nCurrentId = m_aTabControl.GetCurPageId();
514 0 : OBrowserPage* pCurrentPage = static_cast<OBrowserPage*>(m_aTabControl.GetTabPage((sal_uInt16)nCurrentId));
515 0 : if ( !pCurrentPage )
516 0 : return 1L;
517 :
518 0 : if ( pCurrentPage->getListBox().IsModified() )
519 0 : pCurrentPage->getListBox().CommitModified();
520 :
521 0 : return 1L;
522 : }
523 :
524 : //............................................................................
525 3 : } // namespace pcr
526 : //............................................................................
527 :
528 :
529 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|