Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <string>
21 :
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>
29 :
30 : #include "tbinsert.hxx"
31 : #include "tbinsert.hrc"
32 : #include "global.hxx"
33 : #include "scmod.hxx"
34 : #include "scresid.hxx"
35 : #include "sc.hrc"
36 :
37 : // -----------------------------------------------------------------------
38 :
39 15 : SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl, SfxUInt16Item);
40 :
41 : //------------------------------------------------------------------
42 : //
43 : // ToolBox - Controller
44 : //
45 : //------------------------------------------------------------------
46 :
47 0 : ScTbxInsertCtrl::ScTbxInsertCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
48 : SfxToolBoxControl( nSlotId, nId, rTbx ),
49 0 : nLastSlotId(0)
50 : {
51 0 : rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
52 0 : }
53 :
54 0 : ScTbxInsertCtrl::~ScTbxInsertCtrl()
55 : {
56 0 : }
57 :
58 0 : void ScTbxInsertCtrl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState,
59 : const SfxPoolItem* pState )
60 : {
61 0 : GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
62 :
63 0 : if( eState == SFX_ITEM_AVAILABLE )
64 : {
65 :
66 0 : const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
67 0 : if(pItem)
68 : {
69 0 : nLastSlotId = pItem->GetValue();
70 0 : sal_uInt16 nImageId = nLastSlotId ? nLastSlotId : GetSlotId();
71 0 : rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
72 0 : aSlotURL += rtl::OUString::valueOf( sal_Int32( nImageId ));
73 : Image aImage = GetImage( m_xFrame,
74 : aSlotURL,
75 0 : hasBigImages()
76 0 : );
77 0 : GetToolBox().SetItemImage(GetId(), aImage);
78 : }
79 : }
80 0 : }
81 :
82 0 : SfxPopupWindow* ScTbxInsertCtrl::CreatePopupWindow()
83 : {
84 0 : sal_uInt16 nSlotId = GetSlotId();
85 0 : if (nSlotId == SID_TBXCTL_INSERT)
86 : {
87 0 : rtl::OUString aInsertBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" ));
88 0 : createAndPositionSubToolBar( aInsertBarResStr );
89 : }
90 0 : else if (nSlotId == SID_TBXCTL_INSCELLS)
91 : {
92 0 : rtl::OUString aInsertCellsBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcellsbar" ));
93 0 : createAndPositionSubToolBar( aInsertCellsBarResStr );
94 : }
95 : else
96 : {
97 0 : rtl::OUString aInsertObjectBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" ));
98 0 : createAndPositionSubToolBar( aInsertObjectBarResStr );
99 : }
100 0 : return NULL;
101 : }
102 :
103 0 : SfxPopupWindowType ScTbxInsertCtrl::GetPopupWindowType() const
104 : {
105 0 : return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
106 : }
107 :
108 0 : void ScTbxInsertCtrl::Select( sal_Bool /* bMod1 */ )
109 : {
110 0 : SfxViewShell* pCurSh( SfxViewShell::Current() );
111 0 : SfxDispatcher* pDispatch( 0 );
112 :
113 0 : if ( pCurSh )
114 : {
115 0 : SfxViewFrame* pViewFrame = pCurSh->GetViewFrame();
116 0 : if ( pViewFrame )
117 0 : pDispatch = pViewFrame->GetDispatcher();
118 : }
119 :
120 0 : if ( pDispatch )
121 0 : pDispatch->Execute(nLastSlotId);
122 0 : }
123 :
124 :
125 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|