Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / cctrl / tbinsert.cxx
blob94bb5a67111a445e744bb6960f943a5bbf5e5f44
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <string>
22 #include <tools/shl.hxx>
23 #include <svl/intitem.hxx>
24 #include <sfx2/dispatch.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <sfx2/imagemgr.hxx>
28 #include <vcl/toolbox.hxx>
30 #include "tbinsert.hxx"
31 #include "tbinsert.hrc"
32 #include "global.hxx"
33 #include "scmod.hxx"
34 #include "scresid.hxx"
35 #include "sc.hrc"
37 // -----------------------------------------------------------------------
39 SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl, SfxUInt16Item);
41 //------------------------------------------------------------------
43 // ToolBox - Controller
45 //------------------------------------------------------------------
47 ScTbxInsertCtrl::ScTbxInsertCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
48 SfxToolBoxControl( nSlotId, nId, rTbx ),
49 nLastSlotId(0)
51 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
54 ScTbxInsertCtrl::~ScTbxInsertCtrl()
58 void ScTbxInsertCtrl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState,
59 const SfxPoolItem* pState )
61 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
63 if( eState == SFX_ITEM_AVAILABLE )
66 const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
67 if(pItem)
69 nLastSlotId = pItem->GetValue();
70 sal_uInt16 nImageId = nLastSlotId ? nLastSlotId : GetSlotId();
71 OUString aSlotURL( "slot:" );
72 aSlotURL += OUString::number( nImageId);
73 Image aImage = GetImage( m_xFrame,
74 aSlotURL,
75 hasBigImages()
77 GetToolBox().SetItemImage(GetId(), aImage);
82 SfxPopupWindow* ScTbxInsertCtrl::CreatePopupWindow()
84 sal_uInt16 nSlotId = GetSlotId();
85 if (nSlotId == SID_TBXCTL_INSERT)
87 OUString aInsertBarResStr( "private:resource/toolbar/insertbar" );
88 createAndPositionSubToolBar( aInsertBarResStr );
90 else if (nSlotId == SID_TBXCTL_INSCELLS)
92 OUString aInsertCellsBarResStr( "private:resource/toolbar/insertcellsbar" );
93 createAndPositionSubToolBar( aInsertCellsBarResStr );
95 else
97 OUString aInsertObjectBarResStr( "private:resource/toolbar/insertobjectbar" );
98 createAndPositionSubToolBar( aInsertObjectBarResStr );
100 return NULL;
103 SfxPopupWindowType ScTbxInsertCtrl::GetPopupWindowType() const
105 return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
108 void ScTbxInsertCtrl::Select( sal_Bool /* bMod1 */ )
110 SfxViewShell* pCurSh( SfxViewShell::Current() );
111 SfxDispatcher* pDispatch( 0 );
113 if ( pCurSh )
115 SfxViewFrame* pViewFrame = pCurSh->GetViewFrame();
116 if ( pViewFrame )
117 pDispatch = pViewFrame->GetDispatcher();
120 if ( pDispatch )
121 pDispatch->Execute(nLastSlotId);
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */