merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / ribbar / tbxanchr.cxx
blob2deec945639cbde8e12fc3792bd00412da174906
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: tbxanchr.cxx,v $
10 * $Revision: 1.12 $
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_sw.hxx"
36 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
37 #include <vcl/timer.hxx>
38 #include <sfx2/app.hxx>
39 #include <svx/htmlmode.hxx>
40 #include <svtools/intitem.hxx>
41 #include <sfx2/dispatch.hxx>
42 #ifndef _TOOLBOX_HXX //autogen
43 #include <vcl/toolbox.hxx>
44 #endif
45 #include <sfx2/mnumgr.hxx>
48 #include "cmdid.h"
49 #include "docsh.hxx"
50 #include "swtypes.hxx"
51 #include "swmodule.hxx"
52 #include "wrtsh.hxx"
53 #include "view.hxx"
54 #include "viewopt.hxx"
55 #include "errhdl.hxx"
56 #include "ribbar.hrc"
57 #include "tbxanchr.hxx"
61 SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor, SfxUInt16Item);
63 /******************************************************************************
64 * Beschreibung:
65 ******************************************************************************/
67 SwTbxAnchor::SwTbxAnchor( USHORT nSlotId, USHORT nId, ToolBox& rTbx ) :
68 SfxToolBoxControl( nSlotId, nId, rTbx ),
69 nActAnchorId(0)
71 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
74 /******************************************************************************
75 * Beschreibung:
76 ******************************************************************************/
78 SwTbxAnchor::~SwTbxAnchor()
82 /******************************************************************************
83 * Beschreibung:
84 ******************************************************************************/
86 void SwTbxAnchor::StateChanged( USHORT /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
88 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
90 if( eState == SFX_ITEM_AVAILABLE )
92 const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
93 if(pItem)
94 nActAnchorId = pItem->GetValue();
99 /******************************************************************************
100 * Beschreibung:
101 ******************************************************************************/
103 SfxPopupWindow* SwTbxAnchor::CreatePopupWindow()
105 SwTbxAnchor::Click();
106 return 0;
109 /******************************************************************************
110 * Beschreibung:
111 ******************************************************************************/
113 void SwTbxAnchor::Click()
115 PopupMenu aPopMenu(SW_RES(MN_ANCHOR_POPUP));
117 SfxViewFrame* pViewFrame( 0 );
118 SfxDispatcher* pDispatch( 0 );
119 SfxViewShell* pCurSh( SfxViewShell::Current() );
121 if ( pCurSh )
123 pViewFrame = pCurSh->GetViewFrame();
124 if ( pViewFrame )
125 pDispatch = pViewFrame->GetDispatcher();
128 // SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
129 // SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
130 SwView* pActiveView = 0;
131 if(pViewFrame)
133 const TypeId aTypeId = TYPE(SwView);
134 SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
135 while( pView )
137 if(pView->GetViewFrame() == pViewFrame)
139 pActiveView = pView;
140 break;
142 pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
145 if(!pActiveView)
147 DBG_ERROR("No active view could be found");
148 return;
150 SwWrtShell* pWrtShell = pActiveView->GetWrtShellPtr();
151 aPopMenu.EnableItem( FN_TOOL_ANKER_FRAME, 0 != pWrtShell->IsFlyInFly() );
153 Rectangle aRect(GetToolBox().GetItemRect(GetId()));
154 USHORT nHtmlMode = ::GetHtmlMode((SwDocShell*)SfxObjectShell::Current());
155 BOOL bHtmlModeNoAnchor = ( nHtmlMode & HTMLMODE_ON) && 0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS);
157 if (bHtmlModeNoAnchor || pWrtShell->IsInHeaderFooter())
158 aPopMenu.RemoveItem(aPopMenu.GetItemPos(FN_TOOL_ANKER_PAGE));
160 if (nActAnchorId)
161 aPopMenu.CheckItem(nActAnchorId);
164 USHORT nSlotId = aPopMenu.Execute(&GetToolBox(), aRect);
165 GetToolBox().EndSelection();
167 if (nSlotId)
168 pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);