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_svx.hxx" 26 27 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 28 29 #include <tools/ref.hxx> 30 #include <tools/shl.hxx> 31 #include <svl/aeitem.hxx> 32 #include <sfx2/dispatch.hxx> 33 #include <sfx2/viewsh.hxx> 34 #include <sfx2/imagemgr.hxx> 35 #include <sfx2/viewfrm.hxx> 36 #include <vcl/toolbox.hxx> 37 38 #include <svx/dialmgr.hxx> 39 #include <svx/dialogs.hrc> 40 41 #include "svx/tbxctl.hxx" 42 #include "svx/tbxdraw.hxx" 43 #include "svx/tbxcolor.hxx" 44 #include "tbxdraw.hrc" 45 #include <com/sun/star/frame/XLayoutManager.hpp> 46 47 SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlDraw, SfxAllEnumItem); 48 49 using namespace ::com::sun::star::uno; 50 using namespace ::com::sun::star::frame; 51 52 // ----------------------------------------------------------------------- 53 54 SvxTbxCtlDraw::SvxTbxCtlDraw( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 55 56 SfxToolBoxControl( nSlotId, nId, rTbx ), 57 58 m_sToolboxName( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/drawbar" ) ) 59 60 { 61 rTbx.SetItemBits( nId, TIB_CHECKABLE | rTbx.GetItemBits( nId ) ); 62 rTbx.Invalidate(); 63 } 64 65 // ----------------------------------------------------------------------- 66 67 void SvxTbxCtlDraw::StateChanged( sal_uInt16 nSID, SfxItemState eState, 68 const SfxPoolItem* pState ) 69 { 70 GetToolBox().EnableItem( GetId(), ( eState != SFX_ITEM_DISABLED ) ); 71 SfxToolBoxControl::StateChanged( nSID, eState, pState ); 72 73 Reference< XLayoutManager > xLayoutMgr = getLayoutManager(); 74 if ( xLayoutMgr.is() ) 75 GetToolBox().CheckItem( 76 GetId(), xLayoutMgr->isElementVisible( m_sToolboxName ) != sal_False ); 77 } 78 79 // ----------------------------------------------------------------------- 80 81 SfxPopupWindowType SvxTbxCtlDraw::GetPopupWindowType() const 82 { 83 return SFX_POPUPWINDOW_ONCLICK; 84 } 85 86 // ----------------------------------------------------------------------- 87 88 void SvxTbxCtlDraw::toggleToolbox() 89 { 90 Reference< XLayoutManager > xLayoutMgr = getLayoutManager(); 91 if ( xLayoutMgr.is() ) 92 { 93 sal_Bool bCheck = sal_False; 94 if ( xLayoutMgr->isElementVisible( m_sToolboxName ) ) 95 { 96 xLayoutMgr->hideElement( m_sToolboxName ); 97 xLayoutMgr->destroyElement( m_sToolboxName ); 98 } 99 else 100 { 101 bCheck = sal_True; 102 xLayoutMgr->createElement( m_sToolboxName ); 103 xLayoutMgr->showElement( m_sToolboxName ); 104 } 105 106 GetToolBox().CheckItem( GetId(), bCheck ); 107 } 108 } 109 110 // ----------------------------------------------------------------------- 111 112 void SvxTbxCtlDraw::Select( sal_Bool ) 113 { 114 toggleToolbox(); 115 } 116 117