update credits
[LibreOffice.git] / sw / source / ui / ribbar / tbxanchr.cxx
blob055318378f1d165d4c50175641f9bf3cb7b15c43
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <string>
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>
30 #include "cmdid.h"
31 #include "docsh.hxx"
32 #include "swtypes.hxx"
33 #include "swmodule.hxx"
34 #include "wrtsh.hxx"
35 #include "view.hxx"
36 #include "viewopt.hxx"
37 #include "ribbar.hrc"
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 ),
46 nActAnchorId(0)
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 );
62 if(pItem)
63 nActAnchorId = pItem->GetValue();
68 SfxPopupWindow* SwTbxAnchor::CreatePopupWindow()
70 SwTbxAnchor::Click();
71 return 0;
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() );
82 if ( pCurSh )
84 pViewFrame = pCurSh->GetViewFrame();
85 if ( pViewFrame )
86 pDispatch = pViewFrame->GetDispatcher();
89 SwView* pActiveView = 0;
90 if(pViewFrame)
92 const TypeId aTypeId = TYPE(SwView);
93 SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
94 while( pView )
96 if(pView->GetViewFrame() == pViewFrame)
98 pActiveView = pView;
99 break;
101 pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
104 if(!pActiveView)
106 OSL_FAIL("No active view found");
107 return;
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));
117 if (nActAnchorId)
118 aPopMenu.CheckItem(nActAnchorId);
121 sal_uInt16 nSlotId = aPopMenu.Execute(&GetToolBox(), aRect);
122 GetToolBox().EndSelection();
124 if (nSlotId)
125 pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */