1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
30cdf0e10cSrcweir #include <vcl/timer.hxx>
31cdf0e10cSrcweir #include <sfx2/app.hxx>
32cdf0e10cSrcweir #include <svx/htmlmode.hxx>
33cdf0e10cSrcweir #include <svl/intitem.hxx>
34cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
35cdf0e10cSrcweir #ifndef _TOOLBOX_HXX //autogen
36cdf0e10cSrcweir #include <vcl/toolbox.hxx>
37cdf0e10cSrcweir #endif
38cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include "cmdid.h"
42cdf0e10cSrcweir #include "docsh.hxx"
43cdf0e10cSrcweir #include "swtypes.hxx"
44cdf0e10cSrcweir #include "swmodule.hxx"
45cdf0e10cSrcweir #include "wrtsh.hxx"
46cdf0e10cSrcweir #include "view.hxx"
47cdf0e10cSrcweir #include "viewopt.hxx"
48cdf0e10cSrcweir #include "errhdl.hxx"
49cdf0e10cSrcweir #include "ribbar.hrc"
50cdf0e10cSrcweir #include "tbxanchr.hxx"
51cdf0e10cSrcweir
52cdf0e10cSrcweir
53cdf0e10cSrcweir
54cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor, SfxUInt16Item);
55cdf0e10cSrcweir
56cdf0e10cSrcweir /******************************************************************************
57cdf0e10cSrcweir * Beschreibung:
58cdf0e10cSrcweir ******************************************************************************/
59cdf0e10cSrcweir
SwTbxAnchor(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)60cdf0e10cSrcweir SwTbxAnchor::SwTbxAnchor( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
61cdf0e10cSrcweir SfxToolBoxControl( nSlotId, nId, rTbx ),
62cdf0e10cSrcweir nActAnchorId(0)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
65cdf0e10cSrcweir }
66cdf0e10cSrcweir
67cdf0e10cSrcweir /******************************************************************************
68cdf0e10cSrcweir * Beschreibung:
69cdf0e10cSrcweir ******************************************************************************/
70cdf0e10cSrcweir
~SwTbxAnchor()71cdf0e10cSrcweir SwTbxAnchor::~SwTbxAnchor()
72cdf0e10cSrcweir {
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir /******************************************************************************
76cdf0e10cSrcweir * Beschreibung:
77cdf0e10cSrcweir ******************************************************************************/
78cdf0e10cSrcweir
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)79cdf0e10cSrcweir void SwTbxAnchor::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
82cdf0e10cSrcweir
83cdf0e10cSrcweir if( eState == SFX_ITEM_AVAILABLE )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
86cdf0e10cSrcweir if(pItem)
87cdf0e10cSrcweir nActAnchorId = pItem->GetValue();
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir /******************************************************************************
93cdf0e10cSrcweir * Beschreibung:
94cdf0e10cSrcweir ******************************************************************************/
95cdf0e10cSrcweir
CreatePopupWindow()96cdf0e10cSrcweir SfxPopupWindow* SwTbxAnchor::CreatePopupWindow()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir SwTbxAnchor::Click();
99cdf0e10cSrcweir return 0;
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir /******************************************************************************
103cdf0e10cSrcweir * Beschreibung:
104cdf0e10cSrcweir ******************************************************************************/
105cdf0e10cSrcweir
Click()106cdf0e10cSrcweir void SwTbxAnchor::Click()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir PopupMenu aPopMenu(SW_RES(MN_ANCHOR_POPUP));
109cdf0e10cSrcweir
110cdf0e10cSrcweir SfxViewFrame* pViewFrame( 0 );
111cdf0e10cSrcweir SfxDispatcher* pDispatch( 0 );
112cdf0e10cSrcweir SfxViewShell* pCurSh( SfxViewShell::Current() );
113cdf0e10cSrcweir
114cdf0e10cSrcweir if ( pCurSh )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir pViewFrame = pCurSh->GetViewFrame();
117cdf0e10cSrcweir if ( pViewFrame )
118cdf0e10cSrcweir pDispatch = pViewFrame->GetDispatcher();
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir // SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
122cdf0e10cSrcweir // SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
123cdf0e10cSrcweir SwView* pActiveView = 0;
124cdf0e10cSrcweir if(pViewFrame)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir const TypeId aTypeId = TYPE(SwView);
127cdf0e10cSrcweir SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
128cdf0e10cSrcweir while( pView )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir if(pView->GetViewFrame() == pViewFrame)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir pActiveView = pView;
133cdf0e10cSrcweir break;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir if(!pActiveView)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir DBG_ERROR("No active view could be found");
141cdf0e10cSrcweir return;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir SwWrtShell* pWrtShell = pActiveView->GetWrtShellPtr();
144cdf0e10cSrcweir aPopMenu.EnableItem( FN_TOOL_ANKER_FRAME, 0 != pWrtShell->IsFlyInFly() );
145cdf0e10cSrcweir
146cdf0e10cSrcweir Rectangle aRect(GetToolBox().GetItemRect(GetId()));
147cdf0e10cSrcweir sal_uInt16 nHtmlMode = ::GetHtmlMode((SwDocShell*)SfxObjectShell::Current());
148cdf0e10cSrcweir sal_Bool bHtmlModeNoAnchor = ( nHtmlMode & HTMLMODE_ON) && 0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS);
149cdf0e10cSrcweir
150cdf0e10cSrcweir if (bHtmlModeNoAnchor || pWrtShell->IsInHeaderFooter())
151cdf0e10cSrcweir aPopMenu.RemoveItem(aPopMenu.GetItemPos(FN_TOOL_ANKER_PAGE));
152cdf0e10cSrcweir
153cdf0e10cSrcweir if (nActAnchorId)
154cdf0e10cSrcweir aPopMenu.CheckItem(nActAnchorId);
155cdf0e10cSrcweir
156cdf0e10cSrcweir
157cdf0e10cSrcweir sal_uInt16 nSlotId = aPopMenu.Execute(&GetToolBox(), aRect);
158cdf0e10cSrcweir GetToolBox().EndSelection();
159cdf0e10cSrcweir
160cdf0e10cSrcweir if (nSlotId)
161cdf0e10cSrcweir pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
162cdf0e10cSrcweir }
163