1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/timer.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/htmlmode.hxx>
24 #include <svl/intitem.hxx>
25 #include <sfx2/dispatch.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <sfx2/mnumgr.hxx>
32 #include "swtypes.hxx"
33 #include "swmodule.hxx"
36 #include "viewopt.hxx"
38 #include "tbxanchr.hxx"
42 SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor
, SfxUInt16Item
);
44 SwTbxAnchor::SwTbxAnchor( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rTbx
) :
45 SfxToolBoxControl( nSlotId
, nId
, rTbx
),
48 rTbx
.SetItemBits( nId
, TIB_DROPDOWNONLY
| rTbx
.GetItemBits( nId
) );
51 SwTbxAnchor::~SwTbxAnchor()
55 void SwTbxAnchor::StateChanged( sal_uInt16
/*nSID*/, SfxItemState eState
, const SfxPoolItem
* pState
)
57 GetToolBox().EnableItem( GetId(), (GetItemState(pState
) != SFX_ITEM_DISABLED
) );
59 if( eState
== SFX_ITEM_AVAILABLE
)
61 const SfxUInt16Item
* pItem
= PTR_CAST( SfxUInt16Item
, pState
);
63 nActAnchorId
= pItem
->GetValue();
68 SfxPopupWindow
* SwTbxAnchor::CreatePopupWindow()
74 void SwTbxAnchor::Click()
76 PopupMenu
aPopMenu(SW_RES(MN_ANCHOR_POPUP
));
78 SfxViewFrame
* pViewFrame( 0 );
79 SfxDispatcher
* pDispatch( 0 );
80 SfxViewShell
* pCurSh( SfxViewShell::Current() );
84 pViewFrame
= pCurSh
->GetViewFrame();
86 pDispatch
= pViewFrame
->GetDispatcher();
89 SwView
* pActiveView
= 0;
92 const TypeId aTypeId
= TYPE(SwView
);
93 SwView
* pView
= (SwView
*)SfxViewShell::GetFirst(&aTypeId
);
96 if(pView
->GetViewFrame() == pViewFrame
)
101 pView
= (SwView
*)SfxViewShell::GetNext(*pView
, &aTypeId
);
106 OSL_FAIL("No active view found");
109 SwWrtShell
* pWrtShell
= pActiveView
->GetWrtShellPtr();
110 aPopMenu
.EnableItem( FN_TOOL_ANCHOR_FRAME
, 0 != pWrtShell
->IsFlyInFly() );
112 Rectangle
aRect(GetToolBox().GetItemRect(GetId()));
114 if (pWrtShell
->IsInHeaderFooter())
115 aPopMenu
.RemoveItem(aPopMenu
.GetItemPos(FN_TOOL_ANCHOR_PAGE
));
118 aPopMenu
.CheckItem(nActAnchorId
);
121 sal_uInt16 nSlotId
= aPopMenu
.Execute(&GetToolBox(), aRect
);
122 GetToolBox().EndSelection();
125 pDispatch
->Execute(nSlotId
, SFX_CALLMODE_ASYNCHRON
|SFX_CALLMODE_RECORD
);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */