xref: /aoo41x/main/sc/source/ui/cctrl/tbinsert.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // System - Includes -----------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <tools/shl.hxx>
36cdf0e10cSrcweir #include <svl/intitem.hxx>
37cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
38cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
39cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
40cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
41cdf0e10cSrcweir #include <sfx2/imagemgr.hxx>
42cdf0e10cSrcweir #include <vcl/toolbox.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "tbinsert.hxx"
45cdf0e10cSrcweir #include "tbinsert.hrc"
46cdf0e10cSrcweir #include "global.hxx"
47cdf0e10cSrcweir #include "scmod.hxx"
48cdf0e10cSrcweir #include "scresid.hxx"
49cdf0e10cSrcweir #include "sc.hrc"
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // -----------------------------------------------------------------------
52cdf0e10cSrcweir 
53cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl, SfxUInt16Item);
54cdf0e10cSrcweir 
55cdf0e10cSrcweir //------------------------------------------------------------------
56cdf0e10cSrcweir //
57cdf0e10cSrcweir //	ToolBox - Controller
58cdf0e10cSrcweir //
59cdf0e10cSrcweir //------------------------------------------------------------------
60cdf0e10cSrcweir 
ScTbxInsertCtrl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)61cdf0e10cSrcweir ScTbxInsertCtrl::ScTbxInsertCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx  ) :
62cdf0e10cSrcweir 		SfxToolBoxControl( nSlotId, nId, rTbx ),
63cdf0e10cSrcweir 		nLastSlotId(0)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
~ScTbxInsertCtrl()68cdf0e10cSrcweir __EXPORT ScTbxInsertCtrl::~ScTbxInsertCtrl()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)72cdf0e10cSrcweir void __EXPORT ScTbxInsertCtrl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState,
73cdf0e10cSrcweir 											  const SfxPoolItem* pState )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	if( eState == SFX_ITEM_AVAILABLE )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
81cdf0e10cSrcweir 		if(pItem)
82cdf0e10cSrcweir 		{
83cdf0e10cSrcweir 			nLastSlotId = pItem->GetValue();
84cdf0e10cSrcweir 			sal_uInt16 nImageId = nLastSlotId ? nLastSlotId : GetSlotId();
85cdf0e10cSrcweir             rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
86cdf0e10cSrcweir             aSlotURL += rtl::OUString::valueOf( sal_Int32( nImageId ));
87cdf0e10cSrcweir             Image aImage = GetImage( m_xFrame,
88cdf0e10cSrcweir                                      aSlotURL,
89cdf0e10cSrcweir                                      hasBigImages(),
90cdf0e10cSrcweir                                      GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode() );
91cdf0e10cSrcweir             GetToolBox().SetItemImage(GetId(), aImage);
92cdf0e10cSrcweir 		}
93cdf0e10cSrcweir 	}
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
CreatePopupWindow()96cdf0e10cSrcweir SfxPopupWindow* __EXPORT ScTbxInsertCtrl::CreatePopupWindow()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir //    sal_uInt16 nWinResId, nTbxResId;
99cdf0e10cSrcweir 	sal_uInt16 nSlotId = GetSlotId();
100cdf0e10cSrcweir 	if (nSlotId == SID_TBXCTL_INSERT)
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir         rtl::OUString aInsertBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" ));
103cdf0e10cSrcweir         createAndPositionSubToolBar( aInsertBarResStr );
104cdf0e10cSrcweir //      nWinResId = RID_TBXCTL_INSERT;
105cdf0e10cSrcweir //		nTbxResId = RID_TOOLBOX_INSERT;
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 	else if (nSlotId == SID_TBXCTL_INSCELLS)
108cdf0e10cSrcweir 	{
109cdf0e10cSrcweir         rtl::OUString aInsertCellsBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcellsbar" ));
110cdf0e10cSrcweir         createAndPositionSubToolBar( aInsertCellsBarResStr );
111cdf0e10cSrcweir //		nWinResId = RID_TBXCTL_INSCELLS;
112cdf0e10cSrcweir //		nTbxResId = RID_TOOLBOX_INSCELLS;
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 	else /* SID_TBXCTL_INSOBJ */
115cdf0e10cSrcweir 	{
116cdf0e10cSrcweir         rtl::OUString aInsertObjectBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" ));
117cdf0e10cSrcweir         createAndPositionSubToolBar( aInsertObjectBarResStr );
118cdf0e10cSrcweir //		nWinResId = RID_TBXCTL_INSOBJ;
119cdf0e10cSrcweir //		nTbxResId = RID_TOOLBOX_INSOBJ;
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir /*
122cdf0e10cSrcweir 	WindowAlign eNewAlign = ( GetToolBox().IsHorizontal() ) ? WINDOWALIGN_LEFT : WINDOWALIGN_TOP;
123cdf0e10cSrcweir 	ScTbxInsertPopup *pWin = new ScTbxInsertPopup( nSlotId, eNewAlign,
124cdf0e10cSrcweir 									ScResId(nWinResId), ScResId(nTbxResId), GetBindings() );
125cdf0e10cSrcweir 	pWin->StartPopupMode(&GetToolBox(), sal_True);
126cdf0e10cSrcweir 	pWin->StartSelection();
127cdf0e10cSrcweir 	pWin->Show();
128cdf0e10cSrcweir 	return pWin;
129cdf0e10cSrcweir */
130cdf0e10cSrcweir     return NULL;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
GetPopupWindowType() const133cdf0e10cSrcweir SfxPopupWindowType __EXPORT ScTbxInsertCtrl::GetPopupWindowType() const
134cdf0e10cSrcweir {
135cdf0e10cSrcweir 	return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
Select(sal_Bool)138cdf0e10cSrcweir void __EXPORT ScTbxInsertCtrl::Select( sal_Bool /* bMod1 */ )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     SfxViewShell*   pCurSh( SfxViewShell::Current() );
141cdf0e10cSrcweir     SfxDispatcher*  pDispatch( 0 );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     if ( pCurSh )
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         SfxViewFrame*   pViewFrame = pCurSh->GetViewFrame();
146cdf0e10cSrcweir         if ( pViewFrame )
147cdf0e10cSrcweir             pDispatch = pViewFrame->GetDispatcher();
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     if ( pDispatch )
151cdf0e10cSrcweir         pDispatch->Execute(nLastSlotId);
152cdf0e10cSrcweir }
153cdf0e10cSrcweir /*
154cdf0e10cSrcweir //------------------------------------------------------------------
155cdf0e10cSrcweir //
156cdf0e10cSrcweir //	Popup - Window
157cdf0e10cSrcweir //
158cdf0e10cSrcweir //------------------------------------------------------------------
159cdf0e10cSrcweir 
160cdf0e10cSrcweir ScTbxInsertPopup::ScTbxInsertPopup( sal_uInt16 nId, WindowAlign eNewAlign,
161cdf0e10cSrcweir 						const ResId& rRIdWin, const ResId& rRIdTbx,
162cdf0e10cSrcweir 						SfxBindings& rBindings ) :
163cdf0e10cSrcweir 				SfxPopupWindow	( nId, rRIdWin, rBindings),
164cdf0e10cSrcweir 				aTbx			( this, GetBindings(), rRIdTbx ),
165cdf0e10cSrcweir 				aRIdWinTemp(rRIdWin),
166cdf0e10cSrcweir 				aRIdTbxTemp(rRIdTbx)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	aTbx.UseDefault();
169cdf0e10cSrcweir 	FreeResource();
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	aTbx.GetToolBox().SetAlign( eNewAlign );
172cdf0e10cSrcweir 	if (eNewAlign == WINDOWALIGN_LEFT || eNewAlign == WINDOWALIGN_RIGHT)
173cdf0e10cSrcweir 		SetText( EMPTY_STRING );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	Size aSize = aTbx.CalcWindowSizePixel();
176cdf0e10cSrcweir 	aTbx.SetPosSizePixel( Point(), aSize );
177cdf0e10cSrcweir 	SetOutputSizePixel( aSize );
178cdf0e10cSrcweir 	aTbx.GetToolBox().SetSelectHdl(	LINK(this, ScTbxInsertPopup, TbxSelectHdl));
179cdf0e10cSrcweir 	aTbxClickHdl = aTbx.GetToolBox().GetClickHdl();
180cdf0e10cSrcweir 	aTbx.GetToolBox().SetClickHdl(	LINK(this, ScTbxInsertPopup, TbxClickHdl));
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir ScTbxInsertPopup::~ScTbxInsertPopup()
184cdf0e10cSrcweir {
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir SfxPopupWindow* __EXPORT ScTbxInsertPopup::Clone() const
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	return new ScTbxInsertPopup( GetId(), aTbx.GetToolBox().GetAlign(),
190cdf0e10cSrcweir 									aRIdWinTemp, aRIdTbxTemp,
191cdf0e10cSrcweir 									(SfxBindings&) GetBindings() );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir void ScTbxInsertPopup::StartSelection()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	aTbx.GetToolBox().StartSelection();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir IMPL_LINK(ScTbxInsertPopup, TbxSelectHdl, ToolBox*, pBox)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	EndPopupMode();
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	sal_uInt16 nLastSlotId = pBox->GetCurItemId();
204cdf0e10cSrcweir 	SfxUInt16Item aItem( GetId(), nLastSlotId );
205cdf0e10cSrcweir 	SfxDispatcher* pDisp = GetBindings().GetDispatcher();
206cdf0e10cSrcweir 	pDisp->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L );
207cdf0e10cSrcweir 	pDisp->Execute( nLastSlotId, SFX_CALLMODE_ASYNCHRON );
208cdf0e10cSrcweir 	return 0;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir IMPL_LINK(ScTbxInsertPopup, TbxClickHdl, ToolBox*, pBox)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	sal_uInt16 nLastSlotId = pBox->GetCurItemId();
214cdf0e10cSrcweir 	SfxUInt16Item aItem( GetId(), nLastSlotId );
215cdf0e10cSrcweir 	GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L );
216cdf0e10cSrcweir 	if(aTbxClickHdl.IsSet())
217cdf0e10cSrcweir 		aTbxClickHdl.Call(pBox);
218cdf0e10cSrcweir 	return 0;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir void __EXPORT ScTbxInsertPopup::PopupModeEnd()
222cdf0e10cSrcweir {
223cdf0e10cSrcweir 	aTbx.GetToolBox().EndSelection();
224cdf0e10cSrcweir 	SfxPopupWindow::PopupModeEnd();
225cdf0e10cSrcweir }
226cdf0e10cSrcweir */
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 
229