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