xref: /AOO41X/main/svtools/workben/toolpanel/toolpaneltest.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir *
4*cdf0e10cSrcweir * Copyright 2009 by Sun Microsystems, Inc.
5*cdf0e10cSrcweir *
6*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir *
8*cdf0e10cSrcweir * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir *
10*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir *
14*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir *
20*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir ************************************************************************/
25*cdf0e10cSrcweir 
26*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
27*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "ctrlbox.hxx"
30*cdf0e10cSrcweir #include "svtools/toolpanel/toolpaneldeck.hxx"
31*cdf0e10cSrcweir #include "svtools/toolpanel/tablayouter.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
37*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
38*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
39*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
40*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
41*cdf0e10cSrcweir #include <vcl/button.hxx>
42*cdf0e10cSrcweir #include <vcl/edit.hxx>
43*cdf0e10cSrcweir #include <vcl/fixed.hxx>
44*cdf0e10cSrcweir #include <vcl/help.hxx>
45*cdf0e10cSrcweir #include <vcl/lstbox.hxx>
46*cdf0e10cSrcweir #include <vcl/svapp.hxx>
47*cdf0e10cSrcweir #include <vcl/tabctrl.hxx>
48*cdf0e10cSrcweir #include <vcl/taskpanelist.hxx>
49*cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir namespace svt { namespace toolpanel
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
55*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
56*cdf0e10cSrcweir using ::com::sun::star::uno::Any;
57*cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
58*cdf0e10cSrcweir using ::com::sun::star::uno::XComponentContext;
59*cdf0e10cSrcweir using ::com::sun::star::accessibility::XAccessible;
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //=============================================================================
62*cdf0e10cSrcweir //= PanelDemo
63*cdf0e10cSrcweir //=============================================================================
64*cdf0e10cSrcweir class PanelDemo : public Application
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir public:
67*cdf0e10cSrcweir 	virtual void Main();
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir private:
70*cdf0e10cSrcweir     static Reference< XMultiServiceFactory > createApplicationServiceManager();
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir //=============================================================================
74*cdf0e10cSrcweir //= ColoredPanelWindow
75*cdf0e10cSrcweir //=============================================================================
76*cdf0e10cSrcweir class ColoredPanelWindow : public Window
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir public:
79*cdf0e10cSrcweir     ColoredPanelWindow( Window& i_rParent, const Color& i_rColor, const String& i_rTitle )
80*cdf0e10cSrcweir         :Window( &i_rParent )
81*cdf0e10cSrcweir         ,m_aEdit( this, WB_BORDER )
82*cdf0e10cSrcweir         ,m_aTabControl( this )
83*cdf0e10cSrcweir         ,m_sTitle( i_rTitle )
84*cdf0e10cSrcweir     {
85*cdf0e10cSrcweir         SetLineColor();
86*cdf0e10cSrcweir         SetFillColor( i_rColor );
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir         m_aEdit.Show();
89*cdf0e10cSrcweir         m_aTabControl.Show();
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         const sal_Char* pTabTitles[] =
92*cdf0e10cSrcweir         {
93*cdf0e10cSrcweir             "This", "is a", "Tab", "Control", "intended", "for", "comparison"
94*cdf0e10cSrcweir         };
95*cdf0e10cSrcweir         for ( size_t i=0; i < sizeof( pTabTitles ) / sizeof( pTabTitles[0] ); ++i )
96*cdf0e10cSrcweir         {
97*cdf0e10cSrcweir             String sText( String::CreateFromAscii( pTabTitles[i] ) );
98*cdf0e10cSrcweir             m_aTabControl.InsertPage( i + 1, sText );
99*cdf0e10cSrcweir         }
100*cdf0e10cSrcweir     }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     virtual void Paint( const Rectangle& /*i_rRect*/ )
103*cdf0e10cSrcweir     {
104*cdf0e10cSrcweir         const Size aOutputSize( GetOutputSizePixel() );
105*cdf0e10cSrcweir         const Rectangle aTitleRect( Point( 10, 10 ), Size( aOutputSize.Width() - 20, 20 ) );
106*cdf0e10cSrcweir         DrawRect( aTitleRect );
107*cdf0e10cSrcweir         SetTextColor( GetFillColor().IsDark() ? COL_WHITE : COL_BLACK );
108*cdf0e10cSrcweir         DrawText( aTitleRect, m_sTitle, TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER );
109*cdf0e10cSrcweir     }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     virtual void GetFocus()
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir         m_aEdit.GrabFocus();
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir     virtual void Resize()
117*cdf0e10cSrcweir     {
118*cdf0e10cSrcweir         const Size aOutputSize( GetOutputSizePixel() );
119*cdf0e10cSrcweir         m_aEdit.SetPosSizePixel(
120*cdf0e10cSrcweir             Point( 20, 40 ),
121*cdf0e10cSrcweir             Size( aOutputSize.Width() - 40, 20 )
122*cdf0e10cSrcweir         );
123*cdf0e10cSrcweir         m_aTabControl.SetPosSizePixel(
124*cdf0e10cSrcweir             Point( 20, 70 ),
125*cdf0e10cSrcweir             Size( aOutputSize.Width() - 40, 150 )
126*cdf0e10cSrcweir         );
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir private:
130*cdf0e10cSrcweir     Edit        m_aEdit;
131*cdf0e10cSrcweir     TabControl  m_aTabControl;
132*cdf0e10cSrcweir     String      m_sTitle;
133*cdf0e10cSrcweir };
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //=============================================================================
136*cdf0e10cSrcweir //= ColoredPanel
137*cdf0e10cSrcweir //=============================================================================
138*cdf0e10cSrcweir class ColoredPanel : public IToolPanel
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir public:
141*cdf0e10cSrcweir     ColoredPanel( Window& i_rParent, const Color& i_rColor, const sal_Char* i_pAsciiPanelName );
142*cdf0e10cSrcweir     ColoredPanel( Window& i_rParent, const Color& i_rColor, const String& i_rPanelName );
143*cdf0e10cSrcweir     ~ColoredPanel();
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     // IToolPanel
146*cdf0e10cSrcweir     virtual ::rtl::OUString GetDisplayName() const;
147*cdf0e10cSrcweir     virtual Image GetImage() const;
148*cdf0e10cSrcweir     virtual rtl::OString GetHelpID() const;
149*cdf0e10cSrcweir     virtual void Activate( Window& i_rParentWindow );
150*cdf0e10cSrcweir     virtual void Deactivate();
151*cdf0e10cSrcweir     virtual void SetSizePixel( const Size& i_rPanelWindowSize );
152*cdf0e10cSrcweir     virtual void GrabFocus();
153*cdf0e10cSrcweir     virtual void Dispose();
154*cdf0e10cSrcweir     virtual Reference< XAccessible > CreatePanelAccessible( const Reference< XAccessible >& i_rParentAccessible );
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir     // IReference
157*cdf0e10cSrcweir     virtual oslInterlockedCount SAL_CALL acquire();
158*cdf0e10cSrcweir     virtual oslInterlockedCount SAL_CALL release();
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir private:
161*cdf0e10cSrcweir     oslInterlockedCount m_refCount;
162*cdf0e10cSrcweir     ::std::auto_ptr< ColoredPanelWindow >
163*cdf0e10cSrcweir                         m_pWindow;
164*cdf0e10cSrcweir     ::rtl::OUString     m_aPanelName;
165*cdf0e10cSrcweir     BitmapEx            m_aPanelIcon;
166*cdf0e10cSrcweir };
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir //=============================================================================
169*cdf0e10cSrcweir //= ColoredPanel
170*cdf0e10cSrcweir //=============================================================================
171*cdf0e10cSrcweir //-----------------------------------------------------------------------------
172*cdf0e10cSrcweir ColoredPanel::ColoredPanel( Window& i_rParent, const Color& i_rColor, const sal_Char* i_pAsciiPanelName )
173*cdf0e10cSrcweir     :m_refCount(0)
174*cdf0e10cSrcweir     ,m_pWindow( new ColoredPanelWindow( i_rParent, i_rColor, ::rtl::OUString::createFromAscii( i_pAsciiPanelName ) ) )
175*cdf0e10cSrcweir     ,m_aPanelName( ::rtl::OUString::createFromAscii( i_pAsciiPanelName ) )
176*cdf0e10cSrcweir     ,m_aPanelIcon()
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     Bitmap aBitmap( Size( 16, 16 ), 8 );
179*cdf0e10cSrcweir     m_aPanelIcon = BitmapEx( aBitmap );
180*cdf0e10cSrcweir     m_aPanelIcon.Erase( i_rColor );
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir //-----------------------------------------------------------------------------
184*cdf0e10cSrcweir ColoredPanel::ColoredPanel( Window& i_rParent, const Color& i_rColor, const String& i_rPanelName )
185*cdf0e10cSrcweir     :m_refCount(0)
186*cdf0e10cSrcweir     ,m_pWindow( new ColoredPanelWindow( i_rParent, i_rColor, i_rPanelName ) )
187*cdf0e10cSrcweir     ,m_aPanelName( i_rPanelName )
188*cdf0e10cSrcweir     ,m_aPanelIcon()
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     Bitmap aBitmap( Size( 16, 16 ), 8 );
191*cdf0e10cSrcweir     m_aPanelIcon = BitmapEx( aBitmap );
192*cdf0e10cSrcweir     m_aPanelIcon.Erase( i_rColor );
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir //-----------------------------------------------------------------------------
196*cdf0e10cSrcweir ColoredPanel::~ColoredPanel()
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir //-----------------------------------------------------------------------------
201*cdf0e10cSrcweir oslInterlockedCount SAL_CALL ColoredPanel::acquire()
202*cdf0e10cSrcweir {
203*cdf0e10cSrcweir     return osl_incrementInterlockedCount( &m_refCount );
204*cdf0e10cSrcweir }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir //-----------------------------------------------------------------------------
207*cdf0e10cSrcweir oslInterlockedCount SAL_CALL ColoredPanel::release()
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     oslInterlockedCount newCount = osl_decrementInterlockedCount( &m_refCount );
210*cdf0e10cSrcweir     if ( 0 == newCount )
211*cdf0e10cSrcweir         delete this;
212*cdf0e10cSrcweir     return newCount;
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir //-----------------------------------------------------------------------------
216*cdf0e10cSrcweir void ColoredPanel::Activate( Window& i_rParentWindow )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" );
219*cdf0e10cSrcweir     OSL_ENSURE( &i_rParentWindow == m_pWindow->GetParent(), "ColoredPanel::Activate: unexpected new parent window!" );
220*cdf0e10cSrcweir         // the documentation of IToolPanel::Activate says it is guaranteed that the parent window is
221*cdf0e10cSrcweir         // always the same ...
222*cdf0e10cSrcweir     m_pWindow->SetPosSizePixel( Point(), i_rParentWindow.GetSizePixel() );
223*cdf0e10cSrcweir     m_pWindow->Show();
224*cdf0e10cSrcweir }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir //-----------------------------------------------------------------------------
227*cdf0e10cSrcweir void ColoredPanel::Deactivate()
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" );
230*cdf0e10cSrcweir     m_pWindow->Hide();
231*cdf0e10cSrcweir }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir //-----------------------------------------------------------------------------
234*cdf0e10cSrcweir void ColoredPanel::SetSizePixel( const Size& i_rPanelWindowSize )
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" );
237*cdf0e10cSrcweir     m_pWindow->SetSizePixel( i_rPanelWindowSize );
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir //-----------------------------------------------------------------------------
241*cdf0e10cSrcweir void ColoredPanel::GrabFocus()
242*cdf0e10cSrcweir {
243*cdf0e10cSrcweir     ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" );
244*cdf0e10cSrcweir     m_pWindow->GrabFocus();
245*cdf0e10cSrcweir }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir //-----------------------------------------------------------------------------
248*cdf0e10cSrcweir void ColoredPanel::Dispose()
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir     ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" );
251*cdf0e10cSrcweir     m_pWindow.reset();
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir //-----------------------------------------------------------------------------
255*cdf0e10cSrcweir Reference< XAccessible > ColoredPanel::CreatePanelAccessible( const Reference< XAccessible >& i_rParentAccessible )
256*cdf0e10cSrcweir {
257*cdf0e10cSrcweir     ENSURE_OR_RETURN( m_pWindow.get(), "disposed!", NULL );
258*cdf0e10cSrcweir     (void)i_rParentAccessible;
259*cdf0e10cSrcweir     return m_pWindow->GetAccessible();
260*cdf0e10cSrcweir }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir //-----------------------------------------------------------------------------
263*cdf0e10cSrcweir ::rtl::OUString ColoredPanel::GetDisplayName() const
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     return m_aPanelName;
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir //-----------------------------------------------------------------------------
269*cdf0e10cSrcweir Image ColoredPanel::GetImage() const
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir     return Image( m_aPanelIcon );
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir //-----------------------------------------------------------------------------
275*cdf0e10cSrcweir rtl::OString ColoredPanel::GetHelpID() const
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir     return rtl::OString();
278*cdf0e10cSrcweir }
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir //=============================================================================
281*cdf0e10cSrcweir //= OptionsWindow
282*cdf0e10cSrcweir //=============================================================================
283*cdf0e10cSrcweir class PanelDemoMainWindow;
284*cdf0e10cSrcweir class OptionsWindow :public Window
285*cdf0e10cSrcweir                     ,public ::svt::IToolPanelDeckListener
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir public:
288*cdf0e10cSrcweir     OptionsWindow( PanelDemoMainWindow& i_rParent );
289*cdf0e10cSrcweir     ~OptionsWindow();
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir     // Window overridables
292*cdf0e10cSrcweir     virtual void    Resize();
293*cdf0e10cSrcweir     virtual void    GetFocus();
294*cdf0e10cSrcweir     virtual void    StateChanged( StateChangedType i_nStateChange );
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     // IToolPanelDeckListener
297*cdf0e10cSrcweir     virtual void PanelInserted( const PToolPanel& i_pPanel, const size_t i_nPosition );
298*cdf0e10cSrcweir     virtual void PanelRemoved( const size_t i_nPosition );
299*cdf0e10cSrcweir     virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive );
300*cdf0e10cSrcweir     virtual void LayouterChanged( const PDeckLayouter& i_rNewLayouter );
301*cdf0e10cSrcweir     virtual void Dying();
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir private:
304*cdf0e10cSrcweir     DECL_LINK( OnRadioToggled, RadioButton* );
305*cdf0e10cSrcweir     DECL_LINK( OnListEntrySelected, ListBox* );
306*cdf0e10cSrcweir     DECL_LINK( OnListEntryDoubleClicked, ListBox* );
307*cdf0e10cSrcweir     DECL_LINK( OnButtonClicked, PushButton* );
308*cdf0e10cSrcweir     DECL_LINK( OnEditModified, Edit* );
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     void    impl_initPanelList();
311*cdf0e10cSrcweir     void    impl_updateRemoveButton();
312*cdf0e10cSrcweir     void    impl_updateInsertButton();
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir private:
315*cdf0e10cSrcweir     FixedLine       m_aAlignmentHeader;
316*cdf0e10cSrcweir     RadioButton     m_aAlignLeft;
317*cdf0e10cSrcweir     RadioButton     m_aAlignRight;
318*cdf0e10cSrcweir     RadioButton     m_aAlignTop;
319*cdf0e10cSrcweir     RadioButton     m_aAlignBottom;
320*cdf0e10cSrcweir     FixedLine       m_aTabItemContent;
321*cdf0e10cSrcweir     RadioButton     m_aImagesAndText;
322*cdf0e10cSrcweir     RadioButton     m_aImagesOnly;
323*cdf0e10cSrcweir     RadioButton     m_aTextOnly;
324*cdf0e10cSrcweir     RadioButton     m_aAutomaticContent;
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir     FixedLine       m_aPanelsHeader;
327*cdf0e10cSrcweir     ListBox         m_aPanelList;
328*cdf0e10cSrcweir     PushButton      m_aRemovePanel;
329*cdf0e10cSrcweir     ColorListBox    m_aColors;
330*cdf0e10cSrcweir     Edit            m_aNewPanelName;
331*cdf0e10cSrcweir     PushButton      m_aInsertPanel;
332*cdf0e10cSrcweir };
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir //=============================================================================
335*cdf0e10cSrcweir //= PanelDemoMainWindow
336*cdf0e10cSrcweir //=============================================================================
337*cdf0e10cSrcweir class PanelDemoMainWindow : public WorkWindow
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir public:
340*cdf0e10cSrcweir 					PanelDemoMainWindow();
341*cdf0e10cSrcweir 					~PanelDemoMainWindow();
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir     // window overridables
344*cdf0e10cSrcweir 	virtual void	Resize();
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir public:
347*cdf0e10cSrcweir     // operations
348*cdf0e10cSrcweir     void AlignTabs( const ::svt::TabAlignment i_eAlignment );
349*cdf0e10cSrcweir     void SetTabItemContent( const TabItemContent i_eItemContent );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     // member access
352*cdf0e10cSrcweir     IToolPanelDeck& GetToolPanelDeck();
353*cdf0e10cSrcweir     PToolPanel      CreateToolPanel( const Color& i_rColor, const String& i_rPanelName );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir protected:
356*cdf0e10cSrcweir     virtual void    GetFocus();
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir private:
359*cdf0e10cSrcweir     ToolPanelDeck   m_aToolPanelDeck;
360*cdf0e10cSrcweir     OptionsWindow   m_aDemoOptions;
361*cdf0e10cSrcweir };
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir //=============================================================================
364*cdf0e10cSrcweir //= PanelDemoMainWindow - implementation
365*cdf0e10cSrcweir //=============================================================================
366*cdf0e10cSrcweir //-----------------------------------------------------------------------------
367*cdf0e10cSrcweir OptionsWindow::OptionsWindow( PanelDemoMainWindow& i_rParent )
368*cdf0e10cSrcweir     :Window( &i_rParent, WB_BORDER | WB_DIALOGCONTROL )
369*cdf0e10cSrcweir     ,m_aAlignmentHeader( this )
370*cdf0e10cSrcweir     ,m_aAlignLeft( this, WB_GROUP )
371*cdf0e10cSrcweir     ,m_aAlignRight( this, 0 )
372*cdf0e10cSrcweir     ,m_aAlignTop( this, 0 )
373*cdf0e10cSrcweir     ,m_aAlignBottom( this, 0 )
374*cdf0e10cSrcweir     ,m_aTabItemContent( this )
375*cdf0e10cSrcweir     ,m_aImagesAndText( this )
376*cdf0e10cSrcweir     ,m_aImagesOnly( this )
377*cdf0e10cSrcweir     ,m_aTextOnly( this )
378*cdf0e10cSrcweir     ,m_aAutomaticContent( this )
379*cdf0e10cSrcweir     ,m_aPanelsHeader( this )
380*cdf0e10cSrcweir     ,m_aPanelList( this )
381*cdf0e10cSrcweir     ,m_aRemovePanel( this )
382*cdf0e10cSrcweir     ,m_aColors( this, WB_DROPDOWN )
383*cdf0e10cSrcweir     ,m_aNewPanelName( this, WB_BORDER )
384*cdf0e10cSrcweir     ,m_aInsertPanel( this )
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_BLACK ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Black" ) ) );
389*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_BLUE ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Blue" ) ) );
390*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_GREEN ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Green" ) ) );
391*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_CYAN ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Cyan" ) ) );
392*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_RED ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Red" ) ) );
393*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_MAGENTA ),	   String( RTL_CONSTASCII_USTRINGPARAM( "Magenta" ) ) );
394*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_BROWN ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Brown" ) ) );
395*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_GRAY ),		   String( RTL_CONSTASCII_USTRINGPARAM( "Gray" ) ) );
396*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_LIGHTGRAY ),	   String( RTL_CONSTASCII_USTRINGPARAM( "Light Gray" ) ) );
397*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_LIGHTBLUE ),	   String( RTL_CONSTASCII_USTRINGPARAM( "Light Blue" ) ) );
398*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_LIGHTGREEN ),    String( RTL_CONSTASCII_USTRINGPARAM( "Light Green" ) ) );
399*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_LIGHTCYAN ),	   String( RTL_CONSTASCII_USTRINGPARAM( "Light Cyan" ) ) );
400*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_LIGHTRED ),	   String( RTL_CONSTASCII_USTRINGPARAM( "Light Red" ) ) );
401*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_LIGHTMAGENTA ),  String( RTL_CONSTASCII_USTRINGPARAM( "Light Magenta" ) ) );
402*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_YELLOW ), 	   String( RTL_CONSTASCII_USTRINGPARAM( "Yellow" ) ) );
403*cdf0e10cSrcweir 	m_aColors.InsertEntry( Color( COL_WHITE ),		   String( RTL_CONSTASCII_USTRINGPARAM( "White" ) ) );
404*cdf0e10cSrcweir     m_aColors.SetDropDownLineCount( 16 );
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir     Window* pControls[] =
407*cdf0e10cSrcweir     {
408*cdf0e10cSrcweir         &m_aAlignmentHeader, &m_aAlignLeft, &m_aAlignRight, &m_aAlignTop, &m_aAlignBottom, &m_aTabItemContent,
409*cdf0e10cSrcweir         &m_aImagesAndText, &m_aImagesOnly, &m_aTextOnly, &m_aAutomaticContent, &m_aPanelsHeader, &m_aPanelList,
410*cdf0e10cSrcweir         &m_aRemovePanel, &m_aColors, &m_aNewPanelName, &m_aInsertPanel
411*cdf0e10cSrcweir     };
412*cdf0e10cSrcweir     const sal_Char* pTexts[] =
413*cdf0e10cSrcweir     {
414*cdf0e10cSrcweir         "Tab Bar Alignment", "Left", "Right", "Top", "Bottom", "Tab Items", "Images and Text", "Images only",
415*cdf0e10cSrcweir         "Text only", "Automatic", "Panels", "", "Remove Panel", "", "", "Insert Panel"
416*cdf0e10cSrcweir     };
417*cdf0e10cSrcweir     for ( size_t i=0; i < sizeof( pControls ) / sizeof( pControls[0] ); ++i )
418*cdf0e10cSrcweir     {
419*cdf0e10cSrcweir         const WindowType eWindowType = pControls[i]->GetType();
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir         pControls[i]->SetText( String::CreateFromAscii( pTexts[i] ) );
422*cdf0e10cSrcweir         pControls[i]->Show();
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir         if ( eWindowType == WINDOW_RADIOBUTTON )
425*cdf0e10cSrcweir             static_cast< RadioButton* >( pControls[i] )->SetToggleHdl( LINK( this, OptionsWindow, OnRadioToggled ) );
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         if  ( eWindowType == WINDOW_LISTBOX )
428*cdf0e10cSrcweir         {
429*cdf0e10cSrcweir             static_cast< ListBox* >( pControls[i] )->SetSelectHdl( LINK( this, OptionsWindow, OnListEntrySelected ) );
430*cdf0e10cSrcweir             static_cast< ListBox* >( pControls[i] )->SetDoubleClickHdl( LINK( this, OptionsWindow, OnListEntryDoubleClicked ) );
431*cdf0e10cSrcweir         }
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir         if ( eWindowType == WINDOW_PUSHBUTTON )
434*cdf0e10cSrcweir         {
435*cdf0e10cSrcweir             static_cast< PushButton* >( pControls[i] )->SetClickHdl( LINK( this, OptionsWindow, OnButtonClicked ) );
436*cdf0e10cSrcweir         }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir         if ( eWindowType == WINDOW_EDIT )
439*cdf0e10cSrcweir         {
440*cdf0e10cSrcweir             static_cast< Edit* >( pControls[i] )->SetModifyHdl( LINK( this, OptionsWindow, OnEditModified ) );
441*cdf0e10cSrcweir         }
442*cdf0e10cSrcweir     }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     m_aAlignRight.Check();
445*cdf0e10cSrcweir     m_aImagesAndText.Check();
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir     Show();
448*cdf0e10cSrcweir }
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir //-----------------------------------------------------------------------------
451*cdf0e10cSrcweir OptionsWindow::~OptionsWindow()
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir //-----------------------------------------------------------------------------
456*cdf0e10cSrcweir void OptionsWindow::impl_updateInsertButton()
457*cdf0e10cSrcweir {
458*cdf0e10cSrcweir     m_aInsertPanel.Enable( ( m_aColors.GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND ) && ( m_aNewPanelName.GetText().Len() > 0 ) );
459*cdf0e10cSrcweir }
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir //-----------------------------------------------------------------------------
462*cdf0e10cSrcweir void OptionsWindow::impl_updateRemoveButton()
463*cdf0e10cSrcweir {
464*cdf0e10cSrcweir     m_aRemovePanel.Enable( m_aPanelList.GetSelectEntryCount() > 0 );
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir //-----------------------------------------------------------------------------
468*cdf0e10cSrcweir void OptionsWindow::impl_initPanelList()
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir     m_aPanelList.Clear();
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir     PanelDemoMainWindow& rController( dynamic_cast< PanelDemoMainWindow& >( *GetParent() ) );
473*cdf0e10cSrcweir     IToolPanelDeck& rPanelDeck( rController.GetToolPanelDeck() );
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir     for ( size_t i=0; i<rPanelDeck.GetPanelCount(); ++i )
476*cdf0e10cSrcweir     {
477*cdf0e10cSrcweir         PToolPanel pPanel = rPanelDeck.GetPanel( i );
478*cdf0e10cSrcweir         m_aPanelList.InsertEntry( pPanel->GetDisplayName(), pPanel->GetImage() );
479*cdf0e10cSrcweir     }
480*cdf0e10cSrcweir     ActivePanelChanged( ::boost::optional< size_t >(), rPanelDeck.GetActivePanel() );
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir     impl_updateRemoveButton();
483*cdf0e10cSrcweir     impl_updateInsertButton();
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir     rPanelDeck.AddListener( *this );
486*cdf0e10cSrcweir }
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir //-----------------------------------------------------------------------------
489*cdf0e10cSrcweir void OptionsWindow::StateChanged( StateChangedType i_nStateChange )
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir     Window::StateChanged( i_nStateChange );
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     if ( i_nStateChange == STATE_CHANGE_INITSHOW )
494*cdf0e10cSrcweir     {
495*cdf0e10cSrcweir         impl_initPanelList();
496*cdf0e10cSrcweir     }
497*cdf0e10cSrcweir }
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir //-----------------------------------------------------------------------------
500*cdf0e10cSrcweir void OptionsWindow::GetFocus()
501*cdf0e10cSrcweir {
502*cdf0e10cSrcweir     Window::GetFocus();
503*cdf0e10cSrcweir     RadioButton* pRadios[] =
504*cdf0e10cSrcweir     {
505*cdf0e10cSrcweir         &m_aAlignLeft, &m_aAlignRight, &m_aAlignTop, &m_aAlignBottom
506*cdf0e10cSrcweir     };
507*cdf0e10cSrcweir     for ( size_t i=0; i < sizeof( pRadios ) / sizeof( pRadios[0] ); ++i )
508*cdf0e10cSrcweir     {
509*cdf0e10cSrcweir         if ( pRadios[i]->IsChecked() )
510*cdf0e10cSrcweir         {
511*cdf0e10cSrcweir             pRadios[i]->GrabFocus();
512*cdf0e10cSrcweir             break;
513*cdf0e10cSrcweir         }
514*cdf0e10cSrcweir     }
515*cdf0e10cSrcweir }
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir //-----------------------------------------------------------------------------
518*cdf0e10cSrcweir void OptionsWindow::Resize()
519*cdf0e10cSrcweir {
520*cdf0e10cSrcweir     Window::Resize();
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir     const Size aOutputSize( GetOutputSizePixel() );
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     const Size aSpacing( LogicToPixel( Size( 3, 3 ), MAP_APPFONT ) );
525*cdf0e10cSrcweir     const long nIndent( LogicToPixel( Size( 6, 9 ), MAP_APPFONT ).Width() );
526*cdf0e10cSrcweir     const long nFixedLineHeight( LogicToPixel( Size( 0, 8 ), MAP_APPFONT ).Height() );
527*cdf0e10cSrcweir     const long nEditLineHeight( LogicToPixel( Size( 0, 12 ), MAP_APPFONT ).Height() );
528*cdf0e10cSrcweir     const long nButtonLineHeight( LogicToPixel( Size( 0, 14 ), MAP_APPFONT ).Height() );
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir     const long nSuperordinateWidth = aOutputSize.Width() - 2 * aSpacing.Width();
531*cdf0e10cSrcweir     const long nSuperordinateX = aSpacing.Width();
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     const long nSubordinateWidth = aOutputSize.Width() - 2 * aSpacing.Width() - nIndent;
534*cdf0e10cSrcweir     const long nSubordinateX = aSpacing.Width() + nIndent;
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir     Point aItemPos( nSuperordinateX, aSpacing.Height() );
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir     struct ControlRow
539*cdf0e10cSrcweir     {
540*cdf0e10cSrcweir         Window* pWindow;
541*cdf0e10cSrcweir         bool    bSubordinate;
542*cdf0e10cSrcweir         size_t  nRows;
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir         ControlRow( Window& i_rWindow, const bool i_bSubordinate, const size_t i_nRows = 1 )
545*cdf0e10cSrcweir             :pWindow( &i_rWindow )
546*cdf0e10cSrcweir             ,bSubordinate( i_bSubordinate )
547*cdf0e10cSrcweir             ,nRows( i_nRows )
548*cdf0e10cSrcweir         {
549*cdf0e10cSrcweir         }
550*cdf0e10cSrcweir     };
551*cdf0e10cSrcweir     ControlRow aControlRows[] =
552*cdf0e10cSrcweir     {
553*cdf0e10cSrcweir         ControlRow( m_aAlignmentHeader,     false ),
554*cdf0e10cSrcweir         ControlRow( m_aAlignLeft,           true ),
555*cdf0e10cSrcweir         ControlRow( m_aAlignRight,          true ),
556*cdf0e10cSrcweir         ControlRow( m_aAlignTop,            true ),
557*cdf0e10cSrcweir         ControlRow( m_aAlignBottom,         true ),
558*cdf0e10cSrcweir         ControlRow( m_aTabItemContent,      false ),
559*cdf0e10cSrcweir         ControlRow( m_aImagesAndText,       true ),
560*cdf0e10cSrcweir         ControlRow( m_aImagesOnly,          true ),
561*cdf0e10cSrcweir         ControlRow( m_aTextOnly,            true ),
562*cdf0e10cSrcweir         ControlRow( m_aAutomaticContent,    true ),
563*cdf0e10cSrcweir         ControlRow( m_aPanelsHeader,        false ),
564*cdf0e10cSrcweir         ControlRow( m_aPanelList,           true, 6 ),
565*cdf0e10cSrcweir         ControlRow( m_aRemovePanel,         true ),
566*cdf0e10cSrcweir         ControlRow( m_aColors,              true ),
567*cdf0e10cSrcweir         ControlRow( m_aNewPanelName,        true ),
568*cdf0e10cSrcweir         ControlRow( m_aInsertPanel,         true )
569*cdf0e10cSrcweir     };
570*cdf0e10cSrcweir     bool bPreviousWasSubordinate = false;
571*cdf0e10cSrcweir     for ( size_t i=0; i < sizeof( aControlRows ) / sizeof( aControlRows[0] ); ++i )
572*cdf0e10cSrcweir     {
573*cdf0e10cSrcweir         aItemPos.X() = ( aControlRows[i].bSubordinate ) ? nSubordinateX : nSuperordinateX;
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir         if ( bPreviousWasSubordinate && !aControlRows[i].bSubordinate )
576*cdf0e10cSrcweir             aItemPos.Y() += aSpacing.Height();
577*cdf0e10cSrcweir         bPreviousWasSubordinate = aControlRows[i].bSubordinate;
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir         // height depends on the window type
580*cdf0e10cSrcweir         const WindowType eWindowType = aControlRows[i].pWindow->GetType();
581*cdf0e10cSrcweir         long nControlHeight( nFixedLineHeight );
582*cdf0e10cSrcweir         if  (   ( eWindowType == WINDOW_EDIT )
583*cdf0e10cSrcweir             ||  ( eWindowType == WINDOW_LISTBOX )
584*cdf0e10cSrcweir             )
585*cdf0e10cSrcweir         {
586*cdf0e10cSrcweir             nControlHeight = nEditLineHeight;
587*cdf0e10cSrcweir         }
588*cdf0e10cSrcweir         else
589*cdf0e10cSrcweir         if  (   ( eWindowType == WINDOW_PUSHBUTTON )
590*cdf0e10cSrcweir             )
591*cdf0e10cSrcweir         {
592*cdf0e10cSrcweir             nControlHeight = nButtonLineHeight;
593*cdf0e10cSrcweir         }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir         Size aControlSize(
596*cdf0e10cSrcweir             aControlRows[i].bSubordinate ? nSubordinateWidth : nSuperordinateWidth,
597*cdf0e10cSrcweir             nControlHeight * aControlRows[i].nRows
598*cdf0e10cSrcweir         );
599*cdf0e10cSrcweir         aControlRows[i].pWindow->SetPosSizePixel( aItemPos, aControlSize );
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir         aItemPos.Move( 0, aControlSize.Height() + aSpacing.Height() );
602*cdf0e10cSrcweir     }
603*cdf0e10cSrcweir }
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir //-----------------------------------------------------------------------------
606*cdf0e10cSrcweir void OptionsWindow::PanelInserted( const PToolPanel& i_pPanel, const size_t i_nPosition )
607*cdf0e10cSrcweir {
608*cdf0e10cSrcweir     m_aPanelList.InsertEntry( i_pPanel->GetDisplayName(), i_pPanel->GetImage(), sal_uInt16( i_nPosition ) );
609*cdf0e10cSrcweir }
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir //-----------------------------------------------------------------------------
612*cdf0e10cSrcweir void OptionsWindow::PanelRemoved( const size_t i_nPosition )
613*cdf0e10cSrcweir {
614*cdf0e10cSrcweir     m_aPanelList.RemoveEntry( sal_uInt16( i_nPosition ) );
615*cdf0e10cSrcweir     impl_updateRemoveButton();
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir //-----------------------------------------------------------------------------
619*cdf0e10cSrcweir void OptionsWindow::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
620*cdf0e10cSrcweir {
621*cdf0e10cSrcweir     (void)i_rOldActive;
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir     if ( !i_rNewActive )
624*cdf0e10cSrcweir         m_aPanelList.SetNoSelection();
625*cdf0e10cSrcweir     else
626*cdf0e10cSrcweir         m_aPanelList.SelectEntryPos( sal_uInt16( *i_rNewActive ) );
627*cdf0e10cSrcweir }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir //-----------------------------------------------------------------------------
630*cdf0e10cSrcweir void OptionsWindow::LayouterChanged( const PDeckLayouter& i_rNewLayouter )
631*cdf0e10cSrcweir {
632*cdf0e10cSrcweir     (void)i_rNewLayouter;
633*cdf0e10cSrcweir     // not interested in
634*cdf0e10cSrcweir }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir //-----------------------------------------------------------------------------
637*cdf0e10cSrcweir void OptionsWindow::Dying()
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir     // not interested in
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir //-----------------------------------------------------------------------------
643*cdf0e10cSrcweir IMPL_LINK( OptionsWindow, OnListEntrySelected, ListBox*, i_pListBox )
644*cdf0e10cSrcweir {
645*cdf0e10cSrcweir     if ( i_pListBox == &m_aColors )
646*cdf0e10cSrcweir     {
647*cdf0e10cSrcweir         m_aNewPanelName.SetText( m_aColors.GetEntry( m_aColors.GetSelectEntryPos()  ) );
648*cdf0e10cSrcweir         impl_updateInsertButton();
649*cdf0e10cSrcweir     }
650*cdf0e10cSrcweir     else if ( i_pListBox == &m_aPanelList )
651*cdf0e10cSrcweir     {
652*cdf0e10cSrcweir         impl_updateRemoveButton();
653*cdf0e10cSrcweir     }
654*cdf0e10cSrcweir     return 0L;
655*cdf0e10cSrcweir }
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir //-----------------------------------------------------------------------------
658*cdf0e10cSrcweir IMPL_LINK( OptionsWindow, OnListEntryDoubleClicked, ListBox*, i_pListBox )
659*cdf0e10cSrcweir {
660*cdf0e10cSrcweir     PanelDemoMainWindow& rController( dynamic_cast< PanelDemoMainWindow& >( *GetParent() ) );
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir     if ( i_pListBox == &m_aPanelList )
663*cdf0e10cSrcweir     {
664*cdf0e10cSrcweir         size_t nActivatePanel = size_t( m_aPanelList.GetSelectEntryPos() );
665*cdf0e10cSrcweir         rController.GetToolPanelDeck().ActivatePanel( nActivatePanel );
666*cdf0e10cSrcweir     }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir     return 0L;
669*cdf0e10cSrcweir }
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir //-----------------------------------------------------------------------------
672*cdf0e10cSrcweir IMPL_LINK( OptionsWindow, OnEditModified, Edit*, i_pEdit )
673*cdf0e10cSrcweir {
674*cdf0e10cSrcweir     if ( i_pEdit && &m_aNewPanelName )
675*cdf0e10cSrcweir     {
676*cdf0e10cSrcweir         impl_updateInsertButton();
677*cdf0e10cSrcweir     }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     return 0L;
680*cdf0e10cSrcweir }
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir //-----------------------------------------------------------------------------
683*cdf0e10cSrcweir IMPL_LINK( OptionsWindow, OnButtonClicked, PushButton*, i_pPushButton )
684*cdf0e10cSrcweir {
685*cdf0e10cSrcweir     PanelDemoMainWindow& rController( dynamic_cast< PanelDemoMainWindow& >( *GetParent() ) );
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir     if ( i_pPushButton == &m_aRemovePanel )
688*cdf0e10cSrcweir     {
689*cdf0e10cSrcweir         rController.GetToolPanelDeck().RemovePanel( size_t( m_aPanelList.GetSelectEntryPos() ) );
690*cdf0e10cSrcweir     }
691*cdf0e10cSrcweir     else if ( i_pPushButton == &m_aInsertPanel )
692*cdf0e10cSrcweir     {
693*cdf0e10cSrcweir         PToolPanel pNewPanel( rController.CreateToolPanel( m_aColors.GetEntryColor( m_aColors.GetSelectEntryPos() ), m_aNewPanelName.GetText() ) );
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir         ::boost::optional< size_t > aActivePanel( rController.GetToolPanelDeck().GetActivePanel() );
696*cdf0e10cSrcweir         size_t nNewPanelPos = !aActivePanel ? rController.GetToolPanelDeck().GetPanelCount() : *aActivePanel + 1;
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir         rController.GetToolPanelDeck().InsertPanel( pNewPanel, nNewPanelPos );
699*cdf0e10cSrcweir     }
700*cdf0e10cSrcweir     return 0L;
701*cdf0e10cSrcweir }
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir //-----------------------------------------------------------------------------
704*cdf0e10cSrcweir IMPL_LINK( OptionsWindow, OnRadioToggled, RadioButton*, i_pRadioButton )
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir     PanelDemoMainWindow& rController( dynamic_cast< PanelDemoMainWindow& >( *GetParent() ) );
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir     if ( i_pRadioButton->IsChecked() )
709*cdf0e10cSrcweir     {
710*cdf0e10cSrcweir         if ( i_pRadioButton == &m_aAlignLeft )
711*cdf0e10cSrcweir         {
712*cdf0e10cSrcweir             rController.AlignTabs( TABS_LEFT );
713*cdf0e10cSrcweir         }
714*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aAlignRight )
715*cdf0e10cSrcweir         {
716*cdf0e10cSrcweir             rController.AlignTabs( TABS_RIGHT );
717*cdf0e10cSrcweir         }
718*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aAlignTop )
719*cdf0e10cSrcweir         {
720*cdf0e10cSrcweir             rController.AlignTabs( TABS_TOP );
721*cdf0e10cSrcweir         }
722*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aAlignBottom )
723*cdf0e10cSrcweir         {
724*cdf0e10cSrcweir             rController.AlignTabs( TABS_BOTTOM );
725*cdf0e10cSrcweir         }
726*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aImagesAndText )
727*cdf0e10cSrcweir         {
728*cdf0e10cSrcweir             rController.SetTabItemContent( TABITEM_IMAGE_AND_TEXT );
729*cdf0e10cSrcweir         }
730*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aImagesOnly )
731*cdf0e10cSrcweir         {
732*cdf0e10cSrcweir             rController.SetTabItemContent( TABITEM_IMAGE_ONLY );
733*cdf0e10cSrcweir         }
734*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aTextOnly )
735*cdf0e10cSrcweir         {
736*cdf0e10cSrcweir             rController.SetTabItemContent( TABITEM_TEXT_ONLY );
737*cdf0e10cSrcweir         }
738*cdf0e10cSrcweir         else if ( i_pRadioButton == &m_aAutomaticContent )
739*cdf0e10cSrcweir         {
740*cdf0e10cSrcweir             rController.SetTabItemContent( TABITEM_AUTO );
741*cdf0e10cSrcweir         }
742*cdf0e10cSrcweir     }
743*cdf0e10cSrcweir     return 0L;
744*cdf0e10cSrcweir }
745*cdf0e10cSrcweir //=============================================================================
746*cdf0e10cSrcweir //= PanelDemoMainWindow - implementation
747*cdf0e10cSrcweir //=============================================================================
748*cdf0e10cSrcweir //-----------------------------------------------------------------------------
749*cdf0e10cSrcweir PanelDemoMainWindow::PanelDemoMainWindow()
750*cdf0e10cSrcweir     :WorkWindow( NULL, WB_APP | WB_STDWORK | WB_CLIPCHILDREN )
751*cdf0e10cSrcweir     ,m_aToolPanelDeck( *this, WB_BORDER )
752*cdf0e10cSrcweir     ,m_aDemoOptions( *this )
753*cdf0e10cSrcweir {
754*cdf0e10cSrcweir     m_aToolPanelDeck.SetPosSizePixel( Point( 20, 20 ), Size( 500, 300 ) );
755*cdf0e10cSrcweir     m_aToolPanelDeck.SetBorderStyle( WINDOW_BORDER_MONO );
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir     m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), Color( COL_RED ), "Red" ) ), m_aToolPanelDeck.GetPanelCount() );
758*cdf0e10cSrcweir     m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), Color( COL_GREEN ), "Some flavor of Green" ) ), m_aToolPanelDeck.GetPanelCount() );
759*cdf0e10cSrcweir     m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), RGB_COLORDATA( 255, 255, 0 ), "Yellow is ugly" ) ), m_aToolPanelDeck.GetPanelCount() );
760*cdf0e10cSrcweir     m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), RGB_COLORDATA( 0, 0, 128 ), "Blue is the Color" ) ), m_aToolPanelDeck.GetPanelCount() );
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir     m_aToolPanelDeck.ActivatePanel( size_t( 0 ) );
763*cdf0e10cSrcweir     m_aToolPanelDeck.Show();
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir     SetText( String::CreateFromAscii( "ToolPanelDeck Demo Application" ) );
766*cdf0e10cSrcweir 	Show();
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir     Help::EnableQuickHelp();
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir     GetSystemWindow()->GetTaskPaneList()->AddWindow( &m_aToolPanelDeck );
771*cdf0e10cSrcweir     GetSystemWindow()->GetTaskPaneList()->AddWindow( &m_aDemoOptions );
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir //-----------------------------------------------------------------------------
775*cdf0e10cSrcweir PanelDemoMainWindow::~PanelDemoMainWindow()
776*cdf0e10cSrcweir {
777*cdf0e10cSrcweir     GetSystemWindow()->GetTaskPaneList()->RemoveWindow( &m_aDemoOptions );
778*cdf0e10cSrcweir     GetSystemWindow()->GetTaskPaneList()->RemoveWindow( &m_aToolPanelDeck );
779*cdf0e10cSrcweir }
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir //-----------------------------------------------------------------------------
782*cdf0e10cSrcweir void PanelDemoMainWindow::GetFocus()
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir     WorkWindow::GetFocus();
785*cdf0e10cSrcweir     m_aToolPanelDeck.GrabFocus();
786*cdf0e10cSrcweir }
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir //-----------------------------------------------------------------------------
789*cdf0e10cSrcweir void PanelDemoMainWindow::Resize()
790*cdf0e10cSrcweir {
791*cdf0e10cSrcweir     WorkWindow::Resize();
792*cdf0e10cSrcweir     Size aSize( GetOutputSizePixel() );
793*cdf0e10cSrcweir     aSize.Width() -= 240;
794*cdf0e10cSrcweir     aSize.Height() -= 40;
795*cdf0e10cSrcweir     m_aToolPanelDeck.SetPosSizePixel( Point( 20, 20 ), aSize );
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir     m_aDemoOptions.SetPosSizePixel(
798*cdf0e10cSrcweir         Point( 20 + aSize.Width(), 20 ),
799*cdf0e10cSrcweir         Size( 200, aSize.Height() )
800*cdf0e10cSrcweir     );
801*cdf0e10cSrcweir }
802*cdf0e10cSrcweir 
803*cdf0e10cSrcweir //-----------------------------------------------------------------------------
804*cdf0e10cSrcweir void PanelDemoMainWindow::AlignTabs( const ::svt::TabAlignment i_eAlignment )
805*cdf0e10cSrcweir {
806*cdf0e10cSrcweir     TabItemContent eCurrentItemContent( TABITEM_IMAGE_AND_TEXT );
807*cdf0e10cSrcweir     TabDeckLayouter* pLayouter = dynamic_cast< TabDeckLayouter* >( m_aToolPanelDeck.GetLayouter().get() );
808*cdf0e10cSrcweir     OSL_ENSURE( pLayouter, "PanelDemoMainWindow::AlignTabs: wrong layouter!" );
809*cdf0e10cSrcweir     if ( pLayouter )
810*cdf0e10cSrcweir         eCurrentItemContent = pLayouter->GetTabItemContent();
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir     m_aToolPanelDeck.SetLayouter( PDeckLayouter( new TabDeckLayouter( m_aToolPanelDeck, m_aToolPanelDeck, i_eAlignment, eCurrentItemContent ) ) );
813*cdf0e10cSrcweir }
814*cdf0e10cSrcweir 
815*cdf0e10cSrcweir //-----------------------------------------------------------------------------
816*cdf0e10cSrcweir void PanelDemoMainWindow::SetTabItemContent( const TabItemContent i_eItemContent )
817*cdf0e10cSrcweir {
818*cdf0e10cSrcweir     TabDeckLayouter* pLayouter = dynamic_cast< TabDeckLayouter* >( m_aToolPanelDeck.GetLayouter().get() );
819*cdf0e10cSrcweir     OSL_ENSURE( pLayouter, "PanelDemoMainWindow::SetTabItemContent: wrong layouter!" );
820*cdf0e10cSrcweir         // we currently use tab layouters only ...
821*cdf0e10cSrcweir     if ( !pLayouter )
822*cdf0e10cSrcweir         return;
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir     pLayouter->SetTabItemContent( i_eItemContent );
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir //-----------------------------------------------------------------------------
828*cdf0e10cSrcweir IToolPanelDeck& PanelDemoMainWindow::GetToolPanelDeck()
829*cdf0e10cSrcweir {
830*cdf0e10cSrcweir     return m_aToolPanelDeck;
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir //-----------------------------------------------------------------------------
834*cdf0e10cSrcweir PToolPanel PanelDemoMainWindow::CreateToolPanel( const Color& i_rColor, const String& i_rPanelName )
835*cdf0e10cSrcweir {
836*cdf0e10cSrcweir     return PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), i_rColor, i_rPanelName ) );
837*cdf0e10cSrcweir }
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir //=============================================================================
840*cdf0e10cSrcweir //= PanelDemo
841*cdf0e10cSrcweir //=============================================================================
842*cdf0e10cSrcweir //-----------------------------------------------------------------------------
843*cdf0e10cSrcweir Reference< XMultiServiceFactory > PanelDemo::createApplicationServiceManager()
844*cdf0e10cSrcweir {
845*cdf0e10cSrcweir     Reference< XMultiServiceFactory > xMS;
846*cdf0e10cSrcweir 	try
847*cdf0e10cSrcweir 	{
848*cdf0e10cSrcweir 		Reference< XComponentContext >  xComponentContext = ::cppu::defaultBootstrap_InitialComponentContext();
849*cdf0e10cSrcweir         if ( xComponentContext.is() )
850*cdf0e10cSrcweir 		    xMS = xMS.query( xComponentContext->getServiceManager() );
851*cdf0e10cSrcweir 	}
852*cdf0e10cSrcweir     catch( const ::com::sun::star::uno::Exception& )
853*cdf0e10cSrcweir 	{
854*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
855*cdf0e10cSrcweir 	}
856*cdf0e10cSrcweir 
857*cdf0e10cSrcweir 	return xMS;
858*cdf0e10cSrcweir }
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir //-----------------------------------------------------------------------------
861*cdf0e10cSrcweir void __EXPORT PanelDemo::Main()
862*cdf0e10cSrcweir {
863*cdf0e10cSrcweir     // create service factory
864*cdf0e10cSrcweir     Reference< XMultiServiceFactory >  xSMgr = createApplicationServiceManager();
865*cdf0e10cSrcweir 	::comphelper::setProcessServiceFactory( xSMgr );
866*cdf0e10cSrcweir 
867*cdf0e10cSrcweir     // initialize the UCB
868*cdf0e10cSrcweir 	Sequence< Any > aArgs(2);
869*cdf0e10cSrcweir 	aArgs[0] <<= rtl::OUString::createFromAscii( "Local" );
870*cdf0e10cSrcweir 	aArgs[1] <<= rtl::OUString::createFromAscii( "Office" );
871*cdf0e10cSrcweir     ::ucbhelper::ContentBroker::initialize( xSMgr, aArgs );
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir     // run the application
874*cdf0e10cSrcweir 	PanelDemoMainWindow aWindow;
875*cdf0e10cSrcweir 	Execute();
876*cdf0e10cSrcweir }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir PanelDemo aTheApplication;
879*cdf0e10cSrcweir 
880*cdf0e10cSrcweir } } // namespace ::svt::toolpanel
881