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