1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbxanchr.cxx,v $
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>
45 #include <sfx2/mnumgr.hxx>
50 #include "swtypes.hxx"
51 #include "swmodule.hxx"
54 #include "viewopt.hxx"
57 #include "tbxanchr.hxx"
61 SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor
, SfxUInt16Item
);
63 /******************************************************************************
65 ******************************************************************************/
67 SwTbxAnchor::SwTbxAnchor( USHORT nSlotId
, USHORT nId
, ToolBox
& rTbx
) :
68 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
71 rTbx
.SetItemBits( nId
, TIB_DROPDOWNONLY
| rTbx
.GetItemBits( nId
) );
74 /******************************************************************************
76 ******************************************************************************/
78 SwTbxAnchor::~SwTbxAnchor()
82 /******************************************************************************
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
);
94 nActAnchorId
= pItem
->GetValue();
99 /******************************************************************************
101 ******************************************************************************/
103 SfxPopupWindow
* SwTbxAnchor::CreatePopupWindow()
105 SwTbxAnchor::Click();
109 /******************************************************************************
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() );
123 pViewFrame
= pCurSh
->GetViewFrame();
125 pDispatch
= pViewFrame
->GetDispatcher();
128 // SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
129 // SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
130 SwView
* pActiveView
= 0;
133 const TypeId aTypeId
= TYPE(SwView
);
134 SwView
* pView
= (SwView
*)SfxViewShell::GetFirst(&aTypeId
);
137 if(pView
->GetViewFrame() == pViewFrame
)
142 pView
= (SwView
*)SfxViewShell::GetNext(*pView
, &aTypeId
);
147 DBG_ERROR("No active view could be found");
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
));
161 aPopMenu
.CheckItem(nActAnchorId
);
164 USHORT nSlotId
= aPopMenu
.Execute(&GetToolBox(), aRect
);
165 GetToolBox().EndSelection();
168 pDispatch
->Execute(nSlotId
, SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
);