xref: /aoo42x/main/sc/source/ui/cctrl/tbinsert.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 // System - Includes -----------------------------------------------------
32 
33 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
34 
35 
36 
37 // INCLUDE ---------------------------------------------------------------
38 
39 #include <tools/shl.hxx>
40 #include <svl/intitem.hxx>
41 #include <sfx2/dispatch.hxx>
42 #include <sfx2/dispatch.hxx>
43 #include <sfx2/viewsh.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <sfx2/imagemgr.hxx>
46 #include <vcl/toolbox.hxx>
47 
48 #include "tbinsert.hxx"
49 #include "tbinsert.hrc"
50 #include "global.hxx"
51 #include "scmod.hxx"
52 #include "scresid.hxx"
53 #include "sc.hrc"
54 
55 // -----------------------------------------------------------------------
56 
57 SFX_IMPL_TOOLBOX_CONTROL( ScTbxInsertCtrl, SfxUInt16Item);
58 
59 //------------------------------------------------------------------
60 //
61 //	ToolBox - Controller
62 //
63 //------------------------------------------------------------------
64 
65 ScTbxInsertCtrl::ScTbxInsertCtrl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx  ) :
66 		SfxToolBoxControl( nSlotId, nId, rTbx ),
67 		nLastSlotId(0)
68 {
69 	rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) );
70 }
71 
72 __EXPORT ScTbxInsertCtrl::~ScTbxInsertCtrl()
73 {
74 }
75 
76 void __EXPORT ScTbxInsertCtrl::StateChanged( sal_uInt16 /* nSID */, SfxItemState eState,
77 											  const SfxPoolItem* pState )
78 {
79 	GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
80 
81 	if( eState == SFX_ITEM_AVAILABLE )
82 	{
83 
84         const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
85 		if(pItem)
86 		{
87 			nLastSlotId = pItem->GetValue();
88 			sal_uInt16 nImageId = nLastSlotId ? nLastSlotId : GetSlotId();
89             rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
90             aSlotURL += rtl::OUString::valueOf( sal_Int32( nImageId ));
91             Image aImage = GetImage( m_xFrame,
92                                      aSlotURL,
93                                      hasBigImages(),
94                                      GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode() );
95             GetToolBox().SetItemImage(GetId(), aImage);
96 		}
97 	}
98 }
99 
100 SfxPopupWindow* __EXPORT ScTbxInsertCtrl::CreatePopupWindow()
101 {
102 //    sal_uInt16 nWinResId, nTbxResId;
103 	sal_uInt16 nSlotId = GetSlotId();
104 	if (nSlotId == SID_TBXCTL_INSERT)
105 	{
106         rtl::OUString aInsertBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertbar" ));
107         createAndPositionSubToolBar( aInsertBarResStr );
108 //      nWinResId = RID_TBXCTL_INSERT;
109 //		nTbxResId = RID_TOOLBOX_INSERT;
110 	}
111 	else if (nSlotId == SID_TBXCTL_INSCELLS)
112 	{
113         rtl::OUString aInsertCellsBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertcellsbar" ));
114         createAndPositionSubToolBar( aInsertCellsBarResStr );
115 //		nWinResId = RID_TBXCTL_INSCELLS;
116 //		nTbxResId = RID_TOOLBOX_INSCELLS;
117 	}
118 	else /* SID_TBXCTL_INSOBJ */
119 	{
120         rtl::OUString aInsertObjectBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/insertobjectbar" ));
121         createAndPositionSubToolBar( aInsertObjectBarResStr );
122 //		nWinResId = RID_TBXCTL_INSOBJ;
123 //		nTbxResId = RID_TOOLBOX_INSOBJ;
124 	}
125 /*
126 	WindowAlign eNewAlign = ( GetToolBox().IsHorizontal() ) ? WINDOWALIGN_LEFT : WINDOWALIGN_TOP;
127 	ScTbxInsertPopup *pWin = new ScTbxInsertPopup( nSlotId, eNewAlign,
128 									ScResId(nWinResId), ScResId(nTbxResId), GetBindings() );
129 	pWin->StartPopupMode(&GetToolBox(), sal_True);
130 	pWin->StartSelection();
131 	pWin->Show();
132 	return pWin;
133 */
134     return NULL;
135 }
136 
137 SfxPopupWindowType __EXPORT ScTbxInsertCtrl::GetPopupWindowType() const
138 {
139 	return nLastSlotId ? SFX_POPUPWINDOW_ONTIMEOUT : SFX_POPUPWINDOW_ONCLICK;
140 }
141 
142 void __EXPORT ScTbxInsertCtrl::Select( sal_Bool /* bMod1 */ )
143 {
144     SfxViewShell*   pCurSh( SfxViewShell::Current() );
145     SfxDispatcher*  pDispatch( 0 );
146 
147     if ( pCurSh )
148     {
149         SfxViewFrame*   pViewFrame = pCurSh->GetViewFrame();
150         if ( pViewFrame )
151             pDispatch = pViewFrame->GetDispatcher();
152     }
153 
154     if ( pDispatch )
155         pDispatch->Execute(nLastSlotId);
156 }
157 /*
158 //------------------------------------------------------------------
159 //
160 //	Popup - Window
161 //
162 //------------------------------------------------------------------
163 
164 ScTbxInsertPopup::ScTbxInsertPopup( sal_uInt16 nId, WindowAlign eNewAlign,
165 						const ResId& rRIdWin, const ResId& rRIdTbx,
166 						SfxBindings& rBindings ) :
167 				SfxPopupWindow	( nId, rRIdWin, rBindings),
168 				aTbx			( this, GetBindings(), rRIdTbx ),
169 				aRIdWinTemp(rRIdWin),
170 				aRIdTbxTemp(rRIdTbx)
171 {
172 	aTbx.UseDefault();
173 	FreeResource();
174 
175 	aTbx.GetToolBox().SetAlign( eNewAlign );
176 	if (eNewAlign == WINDOWALIGN_LEFT || eNewAlign == WINDOWALIGN_RIGHT)
177 		SetText( EMPTY_STRING );
178 
179 	Size aSize = aTbx.CalcWindowSizePixel();
180 	aTbx.SetPosSizePixel( Point(), aSize );
181 	SetOutputSizePixel( aSize );
182 	aTbx.GetToolBox().SetSelectHdl(	LINK(this, ScTbxInsertPopup, TbxSelectHdl));
183 	aTbxClickHdl = aTbx.GetToolBox().GetClickHdl();
184 	aTbx.GetToolBox().SetClickHdl(	LINK(this, ScTbxInsertPopup, TbxClickHdl));
185 }
186 
187 ScTbxInsertPopup::~ScTbxInsertPopup()
188 {
189 }
190 
191 SfxPopupWindow* __EXPORT ScTbxInsertPopup::Clone() const
192 {
193 	return new ScTbxInsertPopup( GetId(), aTbx.GetToolBox().GetAlign(),
194 									aRIdWinTemp, aRIdTbxTemp,
195 									(SfxBindings&) GetBindings() );
196 }
197 
198 void ScTbxInsertPopup::StartSelection()
199 {
200 	aTbx.GetToolBox().StartSelection();
201 }
202 
203 IMPL_LINK(ScTbxInsertPopup, TbxSelectHdl, ToolBox*, pBox)
204 {
205 	EndPopupMode();
206 
207 	sal_uInt16 nLastSlotId = pBox->GetCurItemId();
208 	SfxUInt16Item aItem( GetId(), nLastSlotId );
209 	SfxDispatcher* pDisp = GetBindings().GetDispatcher();
210 	pDisp->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L );
211 	pDisp->Execute( nLastSlotId, SFX_CALLMODE_ASYNCHRON );
212 	return 0;
213 }
214 
215 IMPL_LINK(ScTbxInsertPopup, TbxClickHdl, ToolBox*, pBox)
216 {
217 	sal_uInt16 nLastSlotId = pBox->GetCurItemId();
218 	SfxUInt16Item aItem( GetId(), nLastSlotId );
219 	GetBindings().GetDispatcher()->Execute( GetId(), SFX_CALLMODE_SYNCHRON, &aItem, 0L );
220 	if(aTbxClickHdl.IsSet())
221 		aTbxClickHdl.Call(pBox);
222 	return 0;
223 }
224 
225 void __EXPORT ScTbxInsertPopup::PopupModeEnd()
226 {
227 	aTbx.GetToolBox().EndSelection();
228 	SfxPopupWindow::PopupModeEnd();
229 }
230 */
231 
232 
233