1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 32 33 #include <tools/ref.hxx> 34 #include <tools/shl.hxx> 35 #include <svl/aeitem.hxx> 36 #include <sfx2/dispatch.hxx> 37 #include <sfx2/viewsh.hxx> 38 #include <sfx2/imagemgr.hxx> 39 #include <sfx2/viewfrm.hxx> 40 #include <vcl/toolbox.hxx> 41 42 #include <svx/dialmgr.hxx> 43 #include <svx/dialogs.hrc> 44 45 #include "svx/tbxctl.hxx" 46 #include "svx/tbxdraw.hxx" 47 #include "svx/tbxcolor.hxx" 48 #include "tbxdraw.hrc" 49 #include <com/sun/star/frame/XLayoutManager.hpp> 50 51 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlDraw, SfxAllEnumItem); 52 53 using namespace ::com::sun::star::uno; 54 using namespace ::com::sun::star::frame; 55 56 // ----------------------------------------------------------------------- 57 58 SvxTbxCtlDraw::SvxTbxCtlDraw( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 59 60 SfxToolBoxControl( nSlotId, nId, rTbx ), 61 62 m_sToolboxName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/drawbar" ) ) 63 64 { 65 rTbx.SetItemBits( nId, TIB_CHECKABLE | rTbx.GetItemBits( nId ) ); 66 rTbx.Invalidate(); 67 } 68 69 // ----------------------------------------------------------------------- 70 71 void SvxTbxCtlDraw::StateChanged( sal_uInt16 nSID, SfxItemState eState, 72 const SfxPoolItem* pState ) 73 { 74 GetToolBox().EnableItem( GetId(), ( eState != SFX_ITEM_DISABLED ) ); 75 SfxToolBoxControl::StateChanged( nSID, eState, pState ); 76 77 Reference< XLayoutManager > xLayoutMgr = getLayoutManager(); 78 if ( xLayoutMgr.is() ) 79 GetToolBox().CheckItem( 80 GetId(), xLayoutMgr->isElementVisible( m_sToolboxName ) != sal_False ); 81 } 82 83 // ----------------------------------------------------------------------- 84 85 SfxPopupWindowType SvxTbxCtlDraw::GetPopupWindowType() const 86 { 87 return SFX_POPUPWINDOW_ONCLICK; 88 } 89 90 // ----------------------------------------------------------------------- 91 92 void SvxTbxCtlDraw::toggleToolbox() 93 { 94 Reference< XLayoutManager > xLayoutMgr = getLayoutManager(); 95 if ( xLayoutMgr.is() ) 96 { 97 sal_Bool bCheck = sal_False; 98 if ( xLayoutMgr->isElementVisible( m_sToolboxName ) ) 99 { 100 xLayoutMgr->hideElement( m_sToolboxName ); 101 xLayoutMgr->destroyElement( m_sToolboxName ); 102 } 103 else 104 { 105 bCheck = sal_True; 106 xLayoutMgr->createElement( m_sToolboxName ); 107 xLayoutMgr->showElement( m_sToolboxName ); 108 } 109 110 GetToolBox().CheckItem( GetId(), bCheck ); 111 } 112 } 113 114 // ----------------------------------------------------------------------- 115 116 void SvxTbxCtlDraw::Select( sal_Bool ) 117 { 118 toggleToolbox(); 119 } 120 121