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