1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <svl/intitem.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/viewsh.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <sfx2/imagemgr.hxx>
27 #include <vcl/toolbox.hxx>
29 #include "tbinsert.hxx"
30 #include "tbinsert.hrc"
33 #include "scresid.hxx"
36 SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl
, SfxUInt16Item
);
38 // ToolBox - Controller
40 ScTbxInsertCtrl::ScTbxInsertCtrl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
41 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
44 rTbx
.SetItemBits( nId
, ToolBoxItemBits::DROPDOWN
| rTbx
.GetItemBits( nId
) );
47 ScTbxInsertCtrl::~ScTbxInsertCtrl()
51 void ScTbxInsertCtrl::StateChanged( sal_uInt16
/* nSID */, SfxItemState eState
,
52 const SfxPoolItem
* pState
)
54 GetToolBox().EnableItem( GetId(), (GetItemState(pState
) != SfxItemState::DISABLED
) );
56 if( eState
== SfxItemState::DEFAULT
)
59 const SfxUInt16Item
* pItem
= PTR_CAST( SfxUInt16Item
, pState
);
62 nLastSlotId
= pItem
->GetValue();
63 sal_uInt16 nImageId
= nLastSlotId
? nLastSlotId
: GetSlotId();
64 OUString
aSlotURL( "slot:" );
65 aSlotURL
+= OUString::number( nImageId
);
66 Image aImage
= GetImage( m_xFrame
,
70 GetToolBox().SetItemImage(GetId(), aImage
);
75 VclPtr
<SfxPopupWindow
> ScTbxInsertCtrl::CreatePopupWindow()
77 sal_uInt16 nSlotId
= GetSlotId();
78 if (nSlotId
== SID_TBXCTL_INSERT
)
80 OUString
aInsertBarResStr( "private:resource/toolbar/insertbar" );
81 createAndPositionSubToolBar( aInsertBarResStr
);
83 else if (nSlotId
== SID_TBXCTL_INSCELLS
)
85 OUString
aInsertCellsBarResStr( "private:resource/toolbar/insertcellsbar" );
86 createAndPositionSubToolBar( aInsertCellsBarResStr
);
90 OUString
aInsertObjectBarResStr( "private:resource/toolbar/insertobjectbar" );
91 createAndPositionSubToolBar( aInsertObjectBarResStr
);
96 SfxPopupWindowType
ScTbxInsertCtrl::GetPopupWindowType() const
98 return nLastSlotId
? SfxPopupWindowType::ONTIMEOUT
: SfxPopupWindowType::ONCLICK
;
101 void ScTbxInsertCtrl::Select( sal_uInt16
/*nSelectModifier*/ )
103 SfxViewShell
* pCurSh( SfxViewShell::Current() );
104 SfxDispatcher
* pDispatch( 0 );
108 SfxViewFrame
* pViewFrame
= pCurSh
->GetViewFrame();
110 pDispatch
= pViewFrame
->GetDispatcher();
114 pDispatch
->Execute(nLastSlotId
);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */