1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2009 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 ************************************************************************/
28 #include "ctrlbox.hxx"
29 #include "svtools/toolpanel/toolpaneldeck.hxx"
30 #include "svtools/toolpanel/tablayouter.hxx"
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
35 #include <comphelper/processfactory.hxx>
36 #include <cppuhelper/bootstrap.hxx>
37 #include <cppuhelper/servicefactory.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <ucbhelper/contentbroker.hxx>
40 #include <vcl/button.hxx>
41 #include <vcl/edit.hxx>
42 #include <vcl/fixed.hxx>
43 #include <vcl/help.hxx>
44 #include <vcl/lstbox.hxx>
45 #include <vcl/svapp.hxx>
46 #include <vcl/tabctrl.hxx>
47 #include <vcl/taskpanelist.hxx>
48 #include <vcl/wrkwin.hxx>
49 #include <sal/macros.h>
51 namespace svt
{ namespace toolpanel
54 using ::com::sun::star::uno::Reference
;
55 using ::com::sun::star::uno::Sequence
;
56 using ::com::sun::star::uno::Any
;
57 using ::com::sun::star::lang::XMultiServiceFactory
;
58 using ::com::sun::star::uno::XComponentContext
;
59 using ::com::sun::star::accessibility::XAccessible
;
61 //=============================================================================
63 //=============================================================================
64 class PanelDemo
: public Application
70 static Reference
< XMultiServiceFactory
> createApplicationServiceManager();
73 //=============================================================================
74 //= ColoredPanelWindow
75 //=============================================================================
76 class ColoredPanelWindow
: public Window
79 ColoredPanelWindow( Window
& i_rParent
, const Color
& i_rColor
, const String
& i_rTitle
)
81 ,m_aEdit( this, WB_BORDER
)
82 ,m_aTabControl( this )
86 SetFillColor( i_rColor
);
91 const sal_Char
* pTabTitles
[] =
93 "This", "is a", "Tab", "Control", "intended", "for", "comparison"
95 for ( size_t i
=0; i
< SAL_N_ELEMENTS( pTabTitles
); ++i
)
97 String
sText( String::CreateFromAscii( pTabTitles
[i
] ) );
98 m_aTabControl
.InsertPage( i
+ 1, sText
);
102 virtual void Paint( const Rectangle
& /*i_rRect*/ )
104 const Size
aOutputSize( GetOutputSizePixel() );
105 const Rectangle
aTitleRect( Point( 10, 10 ), Size( aOutputSize
.Width() - 20, 20 ) );
106 DrawRect( aTitleRect
);
107 SetTextColor( GetFillColor().IsDark() ? COL_WHITE
: COL_BLACK
);
108 DrawText( aTitleRect
, m_sTitle
, TEXT_DRAW_CENTER
| TEXT_DRAW_VCENTER
);
111 virtual void GetFocus()
116 virtual void Resize()
118 const Size
aOutputSize( GetOutputSizePixel() );
119 m_aEdit
.SetPosSizePixel(
121 Size( aOutputSize
.Width() - 40, 20 )
123 m_aTabControl
.SetPosSizePixel(
125 Size( aOutputSize
.Width() - 40, 150 )
131 TabControl m_aTabControl
;
135 //=============================================================================
137 //=============================================================================
138 class ColoredPanel
: public IToolPanel
141 ColoredPanel( Window
& i_rParent
, const Color
& i_rColor
, const sal_Char
* i_pAsciiPanelName
);
142 ColoredPanel( Window
& i_rParent
, const Color
& i_rColor
, const String
& i_rPanelName
);
146 virtual ::rtl::OUString
GetDisplayName() const;
147 virtual Image
GetImage() const;
148 virtual rtl::OString
GetHelpID() const;
149 virtual void Activate( Window
& i_rParentWindow
);
150 virtual void Deactivate();
151 virtual void SetSizePixel( const Size
& i_rPanelWindowSize
);
152 virtual void GrabFocus();
153 virtual void Dispose();
154 virtual Reference
< XAccessible
> CreatePanelAccessible( const Reference
< XAccessible
>& i_rParentAccessible
);
157 virtual oslInterlockedCount SAL_CALL
acquire();
158 virtual oslInterlockedCount SAL_CALL
release();
161 oslInterlockedCount m_refCount
;
162 ::std::auto_ptr
< ColoredPanelWindow
>
164 ::rtl::OUString m_aPanelName
;
165 BitmapEx m_aPanelIcon
;
168 //=============================================================================
170 //=============================================================================
171 //-----------------------------------------------------------------------------
172 ColoredPanel::ColoredPanel( Window
& i_rParent
, const Color
& i_rColor
, const sal_Char
* i_pAsciiPanelName
)
174 ,m_pWindow( new ColoredPanelWindow( i_rParent
, i_rColor
, ::rtl::OUString::createFromAscii( i_pAsciiPanelName
) ) )
175 ,m_aPanelName( ::rtl::OUString::createFromAscii( i_pAsciiPanelName
) )
178 Bitmap
aBitmap( Size( 16, 16 ), 8 );
179 m_aPanelIcon
= BitmapEx( aBitmap
);
180 m_aPanelIcon
.Erase( i_rColor
);
183 //-----------------------------------------------------------------------------
184 ColoredPanel::ColoredPanel( Window
& i_rParent
, const Color
& i_rColor
, const String
& i_rPanelName
)
186 ,m_pWindow( new ColoredPanelWindow( i_rParent
, i_rColor
, i_rPanelName
) )
187 ,m_aPanelName( i_rPanelName
)
190 Bitmap
aBitmap( Size( 16, 16 ), 8 );
191 m_aPanelIcon
= BitmapEx( aBitmap
);
192 m_aPanelIcon
.Erase( i_rColor
);
195 //-----------------------------------------------------------------------------
196 ColoredPanel::~ColoredPanel()
200 //-----------------------------------------------------------------------------
201 oslInterlockedCount SAL_CALL
ColoredPanel::acquire()
203 return osl_incrementInterlockedCount( &m_refCount
);
206 //-----------------------------------------------------------------------------
207 oslInterlockedCount SAL_CALL
ColoredPanel::release()
209 oslInterlockedCount newCount
= osl_decrementInterlockedCount( &m_refCount
);
215 //-----------------------------------------------------------------------------
216 void ColoredPanel::Activate( Window
& i_rParentWindow
)
218 ENSURE_OR_RETURN_VOID( m_pWindow
.get(), "disposed!" );
219 OSL_ENSURE( &i_rParentWindow
== m_pWindow
->GetParent(), "ColoredPanel::Activate: unexpected new parent window!" );
220 // the documentation of IToolPanel::Activate says it is guaranteed that the parent window is
221 // always the same ...
222 m_pWindow
->SetPosSizePixel( Point(), i_rParentWindow
.GetSizePixel() );
226 //-----------------------------------------------------------------------------
227 void ColoredPanel::Deactivate()
229 ENSURE_OR_RETURN_VOID( m_pWindow
.get(), "disposed!" );
233 //-----------------------------------------------------------------------------
234 void ColoredPanel::SetSizePixel( const Size
& i_rPanelWindowSize
)
236 ENSURE_OR_RETURN_VOID( m_pWindow
.get(), "disposed!" );
237 m_pWindow
->SetSizePixel( i_rPanelWindowSize
);
240 //-----------------------------------------------------------------------------
241 void ColoredPanel::GrabFocus()
243 ENSURE_OR_RETURN_VOID( m_pWindow
.get(), "disposed!" );
244 m_pWindow
->GrabFocus();
247 //-----------------------------------------------------------------------------
248 void ColoredPanel::Dispose()
250 ENSURE_OR_RETURN_VOID( m_pWindow
.get(), "disposed!" );
254 //-----------------------------------------------------------------------------
255 Reference
< XAccessible
> ColoredPanel::CreatePanelAccessible( const Reference
< XAccessible
>& i_rParentAccessible
)
257 ENSURE_OR_RETURN( m_pWindow
.get(), "disposed!", NULL
);
258 (void)i_rParentAccessible
;
259 return m_pWindow
->GetAccessible();
262 //-----------------------------------------------------------------------------
263 ::rtl::OUString
ColoredPanel::GetDisplayName() const
268 //-----------------------------------------------------------------------------
269 Image
ColoredPanel::GetImage() const
271 return Image( m_aPanelIcon
);
274 //-----------------------------------------------------------------------------
275 rtl::OString
ColoredPanel::GetHelpID() const
277 return rtl::OString();
280 //=============================================================================
282 //=============================================================================
283 class PanelDemoMainWindow
;
284 class OptionsWindow
:public Window
285 ,public ::svt::IToolPanelDeckListener
288 OptionsWindow( PanelDemoMainWindow
& i_rParent
);
291 // Window overridables
292 virtual void Resize();
293 virtual void GetFocus();
294 virtual void StateChanged( StateChangedType i_nStateChange
);
296 // IToolPanelDeckListener
297 virtual void PanelInserted( const PToolPanel
& i_pPanel
, const size_t i_nPosition
);
298 virtual void PanelRemoved( const size_t i_nPosition
);
299 virtual void ActivePanelChanged( const ::boost::optional
< size_t >& i_rOldActive
, const ::boost::optional
< size_t >& i_rNewActive
);
300 virtual void LayouterChanged( const PDeckLayouter
& i_rNewLayouter
);
301 virtual void Dying();
304 DECL_LINK( OnRadioToggled
, RadioButton
* );
305 DECL_LINK( OnListEntrySelected
, ListBox
* );
306 DECL_LINK( OnListEntryDoubleClicked
, ListBox
* );
307 DECL_LINK( OnButtonClicked
, PushButton
* );
308 DECL_LINK( OnEditModified
, Edit
* );
310 void impl_initPanelList();
311 void impl_updateRemoveButton();
312 void impl_updateInsertButton();
315 FixedLine m_aAlignmentHeader
;
316 RadioButton m_aAlignLeft
;
317 RadioButton m_aAlignRight
;
318 RadioButton m_aAlignTop
;
319 RadioButton m_aAlignBottom
;
320 FixedLine m_aTabItemContent
;
321 RadioButton m_aImagesAndText
;
322 RadioButton m_aImagesOnly
;
323 RadioButton m_aTextOnly
;
324 RadioButton m_aAutomaticContent
;
326 FixedLine m_aPanelsHeader
;
327 ListBox m_aPanelList
;
328 PushButton m_aRemovePanel
;
329 ColorListBox m_aColors
;
330 Edit m_aNewPanelName
;
331 PushButton m_aInsertPanel
;
334 //=============================================================================
335 //= PanelDemoMainWindow
336 //=============================================================================
337 class PanelDemoMainWindow
: public WorkWindow
340 PanelDemoMainWindow();
341 ~PanelDemoMainWindow();
343 // window overridables
344 virtual void Resize();
348 void AlignTabs( const ::svt::TabAlignment i_eAlignment
);
349 void SetTabItemContent( const TabItemContent i_eItemContent
);
352 IToolPanelDeck
& GetToolPanelDeck();
353 PToolPanel
CreateToolPanel( const Color
& i_rColor
, const String
& i_rPanelName
);
356 virtual void GetFocus();
359 ToolPanelDeck m_aToolPanelDeck
;
360 OptionsWindow m_aDemoOptions
;
363 //=============================================================================
364 //= PanelDemoMainWindow - implementation
365 //=============================================================================
366 //-----------------------------------------------------------------------------
367 OptionsWindow::OptionsWindow( PanelDemoMainWindow
& i_rParent
)
368 :Window( &i_rParent
, WB_BORDER
| WB_DIALOGCONTROL
)
369 ,m_aAlignmentHeader( this )
370 ,m_aAlignLeft( this, WB_GROUP
)
371 ,m_aAlignRight( this, 0 )
372 ,m_aAlignTop( this, 0 )
373 ,m_aAlignBottom( this, 0 )
374 ,m_aTabItemContent( this )
375 ,m_aImagesAndText( this )
376 ,m_aImagesOnly( this )
378 ,m_aAutomaticContent( this )
379 ,m_aPanelsHeader( this )
380 ,m_aPanelList( this )
381 ,m_aRemovePanel( this )
382 ,m_aColors( this, WB_DROPDOWN
)
383 ,m_aNewPanelName( this, WB_BORDER
)
384 ,m_aInsertPanel( this )
386 SetBorderStyle( WINDOW_BORDER_MONO
);
388 m_aColors
.InsertEntry( Color( COL_BLACK
), String( RTL_CONSTASCII_USTRINGPARAM( "Black" ) ) );
389 m_aColors
.InsertEntry( Color( COL_BLUE
), String( RTL_CONSTASCII_USTRINGPARAM( "Blue" ) ) );
390 m_aColors
.InsertEntry( Color( COL_GREEN
), String( RTL_CONSTASCII_USTRINGPARAM( "Green" ) ) );
391 m_aColors
.InsertEntry( Color( COL_CYAN
), String( RTL_CONSTASCII_USTRINGPARAM( "Cyan" ) ) );
392 m_aColors
.InsertEntry( Color( COL_RED
), String( RTL_CONSTASCII_USTRINGPARAM( "Red" ) ) );
393 m_aColors
.InsertEntry( Color( COL_MAGENTA
), String( RTL_CONSTASCII_USTRINGPARAM( "Magenta" ) ) );
394 m_aColors
.InsertEntry( Color( COL_BROWN
), String( RTL_CONSTASCII_USTRINGPARAM( "Brown" ) ) );
395 m_aColors
.InsertEntry( Color( COL_GRAY
), String( RTL_CONSTASCII_USTRINGPARAM( "Gray" ) ) );
396 m_aColors
.InsertEntry( Color( COL_LIGHTGRAY
), String( RTL_CONSTASCII_USTRINGPARAM( "Light Gray" ) ) );
397 m_aColors
.InsertEntry( Color( COL_LIGHTBLUE
), String( RTL_CONSTASCII_USTRINGPARAM( "Light Blue" ) ) );
398 m_aColors
.InsertEntry( Color( COL_LIGHTGREEN
), String( RTL_CONSTASCII_USTRINGPARAM( "Light Green" ) ) );
399 m_aColors
.InsertEntry( Color( COL_LIGHTCYAN
), String( RTL_CONSTASCII_USTRINGPARAM( "Light Cyan" ) ) );
400 m_aColors
.InsertEntry( Color( COL_LIGHTRED
), String( RTL_CONSTASCII_USTRINGPARAM( "Light Red" ) ) );
401 m_aColors
.InsertEntry( Color( COL_LIGHTMAGENTA
), String( RTL_CONSTASCII_USTRINGPARAM( "Light Magenta" ) ) );
402 m_aColors
.InsertEntry( Color( COL_YELLOW
), String( RTL_CONSTASCII_USTRINGPARAM( "Yellow" ) ) );
403 m_aColors
.InsertEntry( Color( COL_WHITE
), String( RTL_CONSTASCII_USTRINGPARAM( "White" ) ) );
404 m_aColors
.SetDropDownLineCount( 16 );
406 Window
* pControls
[] =
408 &m_aAlignmentHeader
, &m_aAlignLeft
, &m_aAlignRight
, &m_aAlignTop
, &m_aAlignBottom
, &m_aTabItemContent
,
409 &m_aImagesAndText
, &m_aImagesOnly
, &m_aTextOnly
, &m_aAutomaticContent
, &m_aPanelsHeader
, &m_aPanelList
,
410 &m_aRemovePanel
, &m_aColors
, &m_aNewPanelName
, &m_aInsertPanel
412 const sal_Char
* pTexts
[] =
414 "Tab Bar Alignment", "Left", "Right", "Top", "Bottom", "Tab Items", "Images and Text", "Images only",
415 "Text only", "Automatic", "Panels", "", "Remove Panel", "", "", "Insert Panel"
417 for ( size_t i
=0; i
< SAL_N_ELEMENTS( pControls
); ++i
)
419 const WindowType eWindowType
= pControls
[i
]->GetType();
421 pControls
[i
]->SetText( String::CreateFromAscii( pTexts
[i
] ) );
422 pControls
[i
]->Show();
424 if ( eWindowType
== WINDOW_RADIOBUTTON
)
425 static_cast< RadioButton
* >( pControls
[i
] )->SetToggleHdl( LINK( this, OptionsWindow
, OnRadioToggled
) );
427 if ( eWindowType
== WINDOW_LISTBOX
)
429 static_cast< ListBox
* >( pControls
[i
] )->SetSelectHdl( LINK( this, OptionsWindow
, OnListEntrySelected
) );
430 static_cast< ListBox
* >( pControls
[i
] )->SetDoubleClickHdl( LINK( this, OptionsWindow
, OnListEntryDoubleClicked
) );
433 if ( eWindowType
== WINDOW_PUSHBUTTON
)
435 static_cast< PushButton
* >( pControls
[i
] )->SetClickHdl( LINK( this, OptionsWindow
, OnButtonClicked
) );
438 if ( eWindowType
== WINDOW_EDIT
)
440 static_cast< Edit
* >( pControls
[i
] )->SetModifyHdl( LINK( this, OptionsWindow
, OnEditModified
) );
444 m_aAlignRight
.Check();
445 m_aImagesAndText
.Check();
450 //-----------------------------------------------------------------------------
451 OptionsWindow::~OptionsWindow()
455 //-----------------------------------------------------------------------------
456 void OptionsWindow::impl_updateInsertButton()
458 m_aInsertPanel
.Enable( ( m_aColors
.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND
) && ( m_aNewPanelName
.GetText().Len() > 0 ) );
461 //-----------------------------------------------------------------------------
462 void OptionsWindow::impl_updateRemoveButton()
464 m_aRemovePanel
.Enable( m_aPanelList
.GetSelectEntryCount() > 0 );
467 //-----------------------------------------------------------------------------
468 void OptionsWindow::impl_initPanelList()
470 m_aPanelList
.Clear();
472 PanelDemoMainWindow
& rController( dynamic_cast< PanelDemoMainWindow
& >( *GetParent() ) );
473 IToolPanelDeck
& rPanelDeck( rController
.GetToolPanelDeck() );
475 for ( size_t i
=0; i
<rPanelDeck
.GetPanelCount(); ++i
)
477 PToolPanel pPanel
= rPanelDeck
.GetPanel( i
);
478 m_aPanelList
.InsertEntry( pPanel
->GetDisplayName(), pPanel
->GetImage() );
480 ActivePanelChanged( ::boost::optional
< size_t >(), rPanelDeck
.GetActivePanel() );
482 impl_updateRemoveButton();
483 impl_updateInsertButton();
485 rPanelDeck
.AddListener( *this );
488 //-----------------------------------------------------------------------------
489 void OptionsWindow::StateChanged( StateChangedType i_nStateChange
)
491 Window::StateChanged( i_nStateChange
);
493 if ( i_nStateChange
== STATE_CHANGE_INITSHOW
)
495 impl_initPanelList();
499 //-----------------------------------------------------------------------------
500 void OptionsWindow::GetFocus()
503 RadioButton
* pRadios
[] =
505 &m_aAlignLeft
, &m_aAlignRight
, &m_aAlignTop
, &m_aAlignBottom
507 for ( size_t i
=0; i
< SAL_N_ELEMENTS( pRadios
); ++i
)
509 if ( pRadios
[i
]->IsChecked() )
511 pRadios
[i
]->GrabFocus();
517 //-----------------------------------------------------------------------------
518 void OptionsWindow::Resize()
522 const Size
aOutputSize( GetOutputSizePixel() );
524 const Size
aSpacing( LogicToPixel( Size( 3, 3 ), MAP_APPFONT
) );
525 const long nIndent( LogicToPixel( Size( 6, 9 ), MAP_APPFONT
).Width() );
526 const long nFixedLineHeight( LogicToPixel( Size( 0, 8 ), MAP_APPFONT
).Height() );
527 const long nEditLineHeight( LogicToPixel( Size( 0, 12 ), MAP_APPFONT
).Height() );
528 const long nButtonLineHeight( LogicToPixel( Size( 0, 14 ), MAP_APPFONT
).Height() );
530 const long nSuperordinateWidth
= aOutputSize
.Width() - 2 * aSpacing
.Width();
531 const long nSuperordinateX
= aSpacing
.Width();
533 const long nSubordinateWidth
= aOutputSize
.Width() - 2 * aSpacing
.Width() - nIndent
;
534 const long nSubordinateX
= aSpacing
.Width() + nIndent
;
536 Point
aItemPos( nSuperordinateX
, aSpacing
.Height() );
544 ControlRow( Window
& i_rWindow
, const bool i_bSubordinate
, const size_t i_nRows
= 1 )
545 :pWindow( &i_rWindow
)
546 ,bSubordinate( i_bSubordinate
)
551 ControlRow aControlRows
[] =
553 ControlRow( m_aAlignmentHeader
, false ),
554 ControlRow( m_aAlignLeft
, true ),
555 ControlRow( m_aAlignRight
, true ),
556 ControlRow( m_aAlignTop
, true ),
557 ControlRow( m_aAlignBottom
, true ),
558 ControlRow( m_aTabItemContent
, false ),
559 ControlRow( m_aImagesAndText
, true ),
560 ControlRow( m_aImagesOnly
, true ),
561 ControlRow( m_aTextOnly
, true ),
562 ControlRow( m_aAutomaticContent
, true ),
563 ControlRow( m_aPanelsHeader
, false ),
564 ControlRow( m_aPanelList
, true, 6 ),
565 ControlRow( m_aRemovePanel
, true ),
566 ControlRow( m_aColors
, true ),
567 ControlRow( m_aNewPanelName
, true ),
568 ControlRow( m_aInsertPanel
, true )
570 bool bPreviousWasSubordinate
= false;
571 for ( size_t i
=0; i
< SAL_N_ELEMENTS( aControlRows
); ++i
)
573 aItemPos
.X() = ( aControlRows
[i
].bSubordinate
) ? nSubordinateX
: nSuperordinateX
;
575 if ( bPreviousWasSubordinate
&& !aControlRows
[i
].bSubordinate
)
576 aItemPos
.Y() += aSpacing
.Height();
577 bPreviousWasSubordinate
= aControlRows
[i
].bSubordinate
;
579 // height depends on the window type
580 const WindowType eWindowType
= aControlRows
[i
].pWindow
->GetType();
581 long nControlHeight( nFixedLineHeight
);
582 if ( ( eWindowType
== WINDOW_EDIT
)
583 || ( eWindowType
== WINDOW_LISTBOX
)
586 nControlHeight
= nEditLineHeight
;
589 if ( ( eWindowType
== WINDOW_PUSHBUTTON
)
592 nControlHeight
= nButtonLineHeight
;
596 aControlRows
[i
].bSubordinate
? nSubordinateWidth
: nSuperordinateWidth
,
597 nControlHeight
* aControlRows
[i
].nRows
599 aControlRows
[i
].pWindow
->SetPosSizePixel( aItemPos
, aControlSize
);
601 aItemPos
.Move( 0, aControlSize
.Height() + aSpacing
.Height() );
605 //-----------------------------------------------------------------------------
606 void OptionsWindow::PanelInserted( const PToolPanel
& i_pPanel
, const size_t i_nPosition
)
608 m_aPanelList
.InsertEntry( i_pPanel
->GetDisplayName(), i_pPanel
->GetImage(), sal_uInt16( i_nPosition
) );
611 //-----------------------------------------------------------------------------
612 void OptionsWindow::PanelRemoved( const size_t i_nPosition
)
614 m_aPanelList
.RemoveEntry( sal_uInt16( i_nPosition
) );
615 impl_updateRemoveButton();
618 //-----------------------------------------------------------------------------
619 void OptionsWindow::ActivePanelChanged( const ::boost::optional
< size_t >& i_rOldActive
, const ::boost::optional
< size_t >& i_rNewActive
)
624 m_aPanelList
.SetNoSelection();
626 m_aPanelList
.SelectEntryPos( sal_uInt16( *i_rNewActive
) );
629 //-----------------------------------------------------------------------------
630 void OptionsWindow::LayouterChanged( const PDeckLayouter
& i_rNewLayouter
)
632 (void)i_rNewLayouter
;
636 //-----------------------------------------------------------------------------
637 void OptionsWindow::Dying()
642 //-----------------------------------------------------------------------------
643 IMPL_LINK( OptionsWindow
, OnListEntrySelected
, ListBox
*, i_pListBox
)
645 if ( i_pListBox
== &m_aColors
)
647 m_aNewPanelName
.SetText( m_aColors
.GetEntry( m_aColors
.GetSelectEntryPos() ) );
648 impl_updateInsertButton();
650 else if ( i_pListBox
== &m_aPanelList
)
652 impl_updateRemoveButton();
657 //-----------------------------------------------------------------------------
658 IMPL_LINK( OptionsWindow
, OnListEntryDoubleClicked
, ListBox
*, i_pListBox
)
660 PanelDemoMainWindow
& rController( dynamic_cast< PanelDemoMainWindow
& >( *GetParent() ) );
662 if ( i_pListBox
== &m_aPanelList
)
664 size_t nActivatePanel
= size_t( m_aPanelList
.GetSelectEntryPos() );
665 rController
.GetToolPanelDeck().ActivatePanel( nActivatePanel
);
671 //-----------------------------------------------------------------------------
672 IMPL_LINK( OptionsWindow
, OnEditModified
, Edit
*, i_pEdit
)
674 if ( i_pEdit
&& &m_aNewPanelName
)
676 impl_updateInsertButton();
682 //-----------------------------------------------------------------------------
683 IMPL_LINK( OptionsWindow
, OnButtonClicked
, PushButton
*, i_pPushButton
)
685 PanelDemoMainWindow
& rController( dynamic_cast< PanelDemoMainWindow
& >( *GetParent() ) );
687 if ( i_pPushButton
== &m_aRemovePanel
)
689 rController
.GetToolPanelDeck().RemovePanel( size_t( m_aPanelList
.GetSelectEntryPos() ) );
691 else if ( i_pPushButton
== &m_aInsertPanel
)
693 PToolPanel
pNewPanel( rController
.CreateToolPanel( m_aColors
.GetEntryColor( m_aColors
.GetSelectEntryPos() ), m_aNewPanelName
.GetText() ) );
695 ::boost::optional
< size_t > aActivePanel( rController
.GetToolPanelDeck().GetActivePanel() );
696 size_t nNewPanelPos
= !aActivePanel
? rController
.GetToolPanelDeck().GetPanelCount() : *aActivePanel
+ 1;
698 rController
.GetToolPanelDeck().InsertPanel( pNewPanel
, nNewPanelPos
);
703 //-----------------------------------------------------------------------------
704 IMPL_LINK( OptionsWindow
, OnRadioToggled
, RadioButton
*, i_pRadioButton
)
706 PanelDemoMainWindow
& rController( dynamic_cast< PanelDemoMainWindow
& >( *GetParent() ) );
708 if ( i_pRadioButton
->IsChecked() )
710 if ( i_pRadioButton
== &m_aAlignLeft
)
712 rController
.AlignTabs( TABS_LEFT
);
714 else if ( i_pRadioButton
== &m_aAlignRight
)
716 rController
.AlignTabs( TABS_RIGHT
);
718 else if ( i_pRadioButton
== &m_aAlignTop
)
720 rController
.AlignTabs( TABS_TOP
);
722 else if ( i_pRadioButton
== &m_aAlignBottom
)
724 rController
.AlignTabs( TABS_BOTTOM
);
726 else if ( i_pRadioButton
== &m_aImagesAndText
)
728 rController
.SetTabItemContent( TABITEM_IMAGE_AND_TEXT
);
730 else if ( i_pRadioButton
== &m_aImagesOnly
)
732 rController
.SetTabItemContent( TABITEM_IMAGE_ONLY
);
734 else if ( i_pRadioButton
== &m_aTextOnly
)
736 rController
.SetTabItemContent( TABITEM_TEXT_ONLY
);
738 else if ( i_pRadioButton
== &m_aAutomaticContent
)
740 rController
.SetTabItemContent( TABITEM_AUTO
);
745 //=============================================================================
746 //= PanelDemoMainWindow - implementation
747 //=============================================================================
748 //-----------------------------------------------------------------------------
749 PanelDemoMainWindow::PanelDemoMainWindow()
750 :WorkWindow( NULL
, WB_APP
| WB_STDWORK
| WB_CLIPCHILDREN
)
751 ,m_aToolPanelDeck( *this, WB_BORDER
)
752 ,m_aDemoOptions( *this )
754 m_aToolPanelDeck
.SetPosSizePixel( Point( 20, 20 ), Size( 500, 300 ) );
755 m_aToolPanelDeck
.SetBorderStyle( WINDOW_BORDER_MONO
);
757 m_aToolPanelDeck
.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck
.GetPanelWindowAnchor(), Color( COL_RED
), "Red" ) ), m_aToolPanelDeck
.GetPanelCount() );
758 m_aToolPanelDeck
.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck
.GetPanelWindowAnchor(), Color( COL_GREEN
), "Some flavor of Green" ) ), m_aToolPanelDeck
.GetPanelCount() );
759 m_aToolPanelDeck
.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck
.GetPanelWindowAnchor(), RGB_COLORDATA( 255, 255, 0 ), "Yellow is ugly" ) ), m_aToolPanelDeck
.GetPanelCount() );
760 m_aToolPanelDeck
.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck
.GetPanelWindowAnchor(), RGB_COLORDATA( 0, 0, 128 ), "Blue is the Color" ) ), m_aToolPanelDeck
.GetPanelCount() );
762 m_aToolPanelDeck
.ActivatePanel( size_t( 0 ) );
763 m_aToolPanelDeck
.Show();
765 SetText( String::CreateFromAscii( "ToolPanelDeck Demo Application" ) );
768 Help::EnableQuickHelp();
770 GetSystemWindow()->GetTaskPaneList()->AddWindow( &m_aToolPanelDeck
);
771 GetSystemWindow()->GetTaskPaneList()->AddWindow( &m_aDemoOptions
);
774 //-----------------------------------------------------------------------------
775 PanelDemoMainWindow::~PanelDemoMainWindow()
777 GetSystemWindow()->GetTaskPaneList()->RemoveWindow( &m_aDemoOptions
);
778 GetSystemWindow()->GetTaskPaneList()->RemoveWindow( &m_aToolPanelDeck
);
781 //-----------------------------------------------------------------------------
782 void PanelDemoMainWindow::GetFocus()
784 WorkWindow::GetFocus();
785 m_aToolPanelDeck
.GrabFocus();
788 //-----------------------------------------------------------------------------
789 void PanelDemoMainWindow::Resize()
791 WorkWindow::Resize();
792 Size
aSize( GetOutputSizePixel() );
793 aSize
.Width() -= 240;
794 aSize
.Height() -= 40;
795 m_aToolPanelDeck
.SetPosSizePixel( Point( 20, 20 ), aSize
);
797 m_aDemoOptions
.SetPosSizePixel(
798 Point( 20 + aSize
.Width(), 20 ),
799 Size( 200, aSize
.Height() )
803 //-----------------------------------------------------------------------------
804 void PanelDemoMainWindow::AlignTabs( const ::svt::TabAlignment i_eAlignment
)
806 TabItemContent
eCurrentItemContent( TABITEM_IMAGE_AND_TEXT
);
807 TabDeckLayouter
* pLayouter
= dynamic_cast< TabDeckLayouter
* >( m_aToolPanelDeck
.GetLayouter().get() );
808 OSL_ENSURE( pLayouter
, "PanelDemoMainWindow::AlignTabs: wrong layouter!" );
810 eCurrentItemContent
= pLayouter
->GetTabItemContent();
812 m_aToolPanelDeck
.SetLayouter( PDeckLayouter( new TabDeckLayouter( m_aToolPanelDeck
, m_aToolPanelDeck
, i_eAlignment
, eCurrentItemContent
) ) );
815 //-----------------------------------------------------------------------------
816 void PanelDemoMainWindow::SetTabItemContent( const TabItemContent i_eItemContent
)
818 TabDeckLayouter
* pLayouter
= dynamic_cast< TabDeckLayouter
* >( m_aToolPanelDeck
.GetLayouter().get() );
819 OSL_ENSURE( pLayouter
, "PanelDemoMainWindow::SetTabItemContent: wrong layouter!" );
820 // we currently use tab layouters only ...
824 pLayouter
->SetTabItemContent( i_eItemContent
);
827 //-----------------------------------------------------------------------------
828 IToolPanelDeck
& PanelDemoMainWindow::GetToolPanelDeck()
830 return m_aToolPanelDeck
;
833 //-----------------------------------------------------------------------------
834 PToolPanel
PanelDemoMainWindow::CreateToolPanel( const Color
& i_rColor
, const String
& i_rPanelName
)
836 return PToolPanel( new ColoredPanel( m_aToolPanelDeck
.GetPanelWindowAnchor(), i_rColor
, i_rPanelName
) );
839 //=============================================================================
841 //=============================================================================
842 //-----------------------------------------------------------------------------
843 Reference
< XMultiServiceFactory
> PanelDemo::createApplicationServiceManager()
845 Reference
< XMultiServiceFactory
> xMS
;
848 Reference
< XComponentContext
> xComponentContext
= ::cppu::defaultBootstrap_InitialComponentContext();
849 if ( xComponentContext
.is() )
850 xMS
= xMS
.query( xComponentContext
->getServiceManager() );
852 catch( const ::com::sun::star::uno::Exception
& )
854 DBG_UNHANDLED_EXCEPTION();
860 //-----------------------------------------------------------------------------
861 int PanelDemo::Main()
863 // create service factory
864 Reference
< XMultiServiceFactory
> xSMgr
= createApplicationServiceManager();
865 ::comphelper::setProcessServiceFactory( xSMgr
);
867 // initialize the UCB
868 Sequence
< Any
> aArgs(2);
869 aArgs
[0] <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Local" ));
870 aArgs
[1] <<= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Office" ));
871 ::ucbhelper::ContentBroker::initialize( xSMgr
, aArgs
);
873 // run the application
874 PanelDemoMainWindow aWindow
;
879 PanelDemo aTheApplication
;
881 } } // namespace ::svt::toolpanel
883 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */