sync master with lastest vba changes
[ooovba.git] / sc / source / ui / cctrl / tbinsert.cxx
blob501e72561aca1b1b0813467dd5458e3cddacb286
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbinsert.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes -----------------------------------------------------
36 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
40 // INCLUDE ---------------------------------------------------------------
42 #include <tools/shl.hxx>
43 #include <svtools/intitem.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/viewsh.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/imagemgr.hxx>
49 #include <vcl/toolbox.hxx>
51 #include "tbinsert.hxx"
52 #include "tbinsert.hrc"
53 #include "global.hxx"
54 #include "scmod.hxx"
55 #include "scresid.hxx"
56 #include "sc.hrc"
58 // -----------------------------------------------------------------------
60 SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl, SfxUInt16Item);
62 //------------------------------------------------------------------
64 // ToolBox - Controller
66 //------------------------------------------------------------------
68 ScTbxInsertCtrl::ScTbxInsertCtrl( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :
69 SfxToolBoxControl( nSlotId, nId, rTbx ),
70 nLastSlotId(0)
72 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
75 __EXPORT ScTbxInsertCtrl::~ScTbxInsertCtrl()
79 void __EXPORT ScTbxInsertCtrl::StateChanged( USHORT /* nSID */, SfxItemState eState,
80 const SfxPoolItem* pState )
82 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
84 if( eState == SFX_ITEM_AVAILABLE )
87 const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
88 if(pItem)
90 nLastSlotId = pItem->GetValue();
91 USHORT nImageId = nLastSlotId ? nLastSlotId : GetSlotId();
92 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
93 aSlotURL += rtl::OUString::valueOf( sal_Int32( nImageId ));
94 Image aImage = GetImage( m_xFrame,
95 aSlotURL,
96 hasBigImages(),
97 GetToolBox().GetDisplayBackground().GetColor().IsDark() );
98 GetToolBox().SetItemImage(GetId(), aImage);
103 SfxPopupWindow* __EXPORT ScTbxInsertCtrl::CreatePopupWindow()
105 // USHORT nWinResId, nTbxResId;
106 USHORT nSlotId = GetSlotId();
107 if (nSlotId == SID_TBXCTL_INSERT)
109 rtl::OUString aInsertBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" ));
110 createAndPositionSubToolBar( aInsertBarResStr );
111 // nWinResId = RID_TBXCTL_INSERT;
112 // nTbxResId = RID_TOOLBOX_INSERT;
114 else if (nSlotId == SID_TBXCTL_INSCELLS)
116 rtl::OUString aInsertCellsBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcellsbar" ));
117 createAndPositionSubToolBar( aInsertCellsBarResStr );
118 // nWinResId = RID_TBXCTL_INSCELLS;
119 // nTbxResId = RID_TOOLBOX_INSCELLS;
121 else /* SID_TBXCTL_INSOBJ */
123 rtl::OUString aInsertObjectBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" ));
124 createAndPositionSubToolBar( aInsertObjectBarResStr );
125 // nWinResId = RID_TBXCTL_INSOBJ;
126 // nTbxResId = RID_TOOLBOX_INSOBJ;
129 WindowAlign eNewAlign = ( GetToolBox().IsHorizontal() ) ? WINDOWALIGN_LEFT : WINDOWALIGN_TOP;
130 ScTbxInsertPopup *pWin = new ScTbxInsertPopup( nSlotId, eNewAlign,
131 ScResId(nWinResId), ScResId(nTbxResId), GetBindings() );
132 pWin->StartPopupMode(&GetToolBox(), TRUE);
133 pWin->StartSelection();
134 pWin->Show();
135 return pWin;
137 return NULL;
140 SfxPopupWindowType __EXPORT ScTbxInsertCtrl::GetPopupWindowType() const
142 return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
145 void __EXPORT ScTbxInsertCtrl::Select( BOOL /* bMod1 */ )
147 SfxViewShell* pCurSh( SfxViewShell::Current() );
148 SfxDispatcher* pDispatch( 0 );
150 if ( pCurSh )
152 SfxViewFrame* pViewFrame = pCurSh->GetViewFrame();
153 if ( pViewFrame )
154 pDispatch = pViewFrame->GetDispatcher();
157 if ( pDispatch )
158 pDispatch->Execute(nLastSlotId);
161 //------------------------------------------------------------------
163 // Popup - Window
165 //------------------------------------------------------------------
167 ScTbxInsertPopup::ScTbxInsertPopup( USHORT nId, WindowAlign eNewAlign,
168 const ResId& rRIdWin, const ResId& rRIdTbx,
169 SfxBindings& rBindings ) :
170 SfxPopupWindow ( nId, rRIdWin, rBindings),
171 aTbx ( this, GetBindings(), rRIdTbx ),
172 aRIdWinTemp(rRIdWin),
173 aRIdTbxTemp(rRIdTbx)
175 aTbx.UseDefault();
176 FreeResource();
178 aTbx.GetToolBox().SetAlign( eNewAlign );
179 if (eNewAlign == WINDOWALIGN_LEFT || eNewAlign == WINDOWALIGN_RIGHT)
180 SetText( EMPTY_STRING );
182 Size aSize = aTbx.CalcWindowSizePixel();
183 aTbx.SetPosSizePixel( Point(), aSize );
184 SetOutputSizePixel( aSize );
185 aTbx.GetToolBox().SetSelectHdl( LINK(this, ScTbxInsertPopup, TbxSelectHdl));
186 aTbxClickHdl = aTbx.GetToolBox().GetClickHdl();
187 aTbx.GetToolBox().SetClickHdl( LINK(this, ScTbxInsertPopup, TbxClickHdl));
190 ScTbxInsertPopup::~ScTbxInsertPopup()
194 SfxPopupWindow* __EXPORT ScTbxInsertPopup::Clone() const
196 return new ScTbxInsertPopup( GetId(), aTbx.GetToolBox().GetAlign(),
197 aRIdWinTemp, aRIdTbxTemp,
198 (SfxBindings&) GetBindings() );
201 void ScTbxInsertPopup::StartSelection()
203 aTbx.GetToolBox().StartSelection();
206 IMPL_LINK(ScTbxInsertPopup, TbxSelectHdl, ToolBox*, pBox)
208 EndPopupMode();
210 USHORT nLastSlotId = pBox->GetCurItemId();
211 SfxUInt16Item aItem( GetId(), nLastSlotId );
212 SfxDispatcher* pDisp = GetBindings().GetDispatcher();
213 pDisp->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L );
214 pDisp->Execute( nLastSlotId, SFX_CALLMODE_ASYNCHRON );
215 return 0;
218 IMPL_LINK(ScTbxInsertPopup, TbxClickHdl, ToolBox*, pBox)
220 USHORT nLastSlotId = pBox->GetCurItemId();
221 SfxUInt16Item aItem( GetId(), nLastSlotId );
222 GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L );
223 if(aTbxClickHdl.IsSet())
224 aTbxClickHdl.Call(pBox);
225 return 0;
228 void __EXPORT ScTbxInsertPopup::PopupModeEnd()
230 aTbx.GetToolBox().EndSelection();
231 SfxPopupWindow::PopupModeEnd();