1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 33 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 34 #include <vcl/timer.hxx> 35 #include <sfx2/app.hxx> 36 #include <svx/htmlmode.hxx> 37 #include <svl/intitem.hxx> 38 #include <sfx2/dispatch.hxx> 39 #ifndef _TOOLBOX_HXX //autogen 40 #include <vcl/toolbox.hxx> 41 #endif 42 #include <sfx2/mnumgr.hxx> 43 44 45 #include "cmdid.h" 46 #include "docsh.hxx" 47 #include "swtypes.hxx" 48 #include "swmodule.hxx" 49 #include "wrtsh.hxx" 50 #include "view.hxx" 51 #include "viewopt.hxx" 52 #include "errhdl.hxx" 53 #include "ribbar.hrc" 54 #include "tbxanchr.hxx" 55 56 57 58 SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor, SfxUInt16Item); 59 60 /****************************************************************************** 61 * Beschreibung: 62 ******************************************************************************/ 63 64 SwTbxAnchor::SwTbxAnchor( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 65 SfxToolBoxControl( nSlotId, nId, rTbx ), 66 nActAnchorId(0) 67 { 68 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) ); 69 } 70 71 /****************************************************************************** 72 * Beschreibung: 73 ******************************************************************************/ 74 75 SwTbxAnchor::~SwTbxAnchor() 76 { 77 } 78 79 /****************************************************************************** 80 * Beschreibung: 81 ******************************************************************************/ 82 83 void SwTbxAnchor::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) 84 { 85 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) ); 86 87 if( eState == SFX_ITEM_AVAILABLE ) 88 { 89 const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState ); 90 if(pItem) 91 nActAnchorId = pItem->GetValue(); 92 } 93 94 } 95 96 /****************************************************************************** 97 * Beschreibung: 98 ******************************************************************************/ 99 100 SfxPopupWindow* SwTbxAnchor::CreatePopupWindow() 101 { 102 SwTbxAnchor::Click(); 103 return 0; 104 } 105 106 /****************************************************************************** 107 * Beschreibung: 108 ******************************************************************************/ 109 110 void SwTbxAnchor::Click() 111 { 112 PopupMenu aPopMenu(SW_RES(MN_ANCHOR_POPUP)); 113 114 SfxViewFrame* pViewFrame( 0 ); 115 SfxDispatcher* pDispatch( 0 ); 116 SfxViewShell* pCurSh( SfxViewShell::Current() ); 117 118 if ( pCurSh ) 119 { 120 pViewFrame = pCurSh->GetViewFrame(); 121 if ( pViewFrame ) 122 pDispatch = pViewFrame->GetDispatcher(); 123 } 124 125 // SfxDispatcher* pDispatch = GetBindings().GetDispatcher(); 126 // SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0; 127 SwView* pActiveView = 0; 128 if(pViewFrame) 129 { 130 const TypeId aTypeId = TYPE(SwView); 131 SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId); 132 while( pView ) 133 { 134 if(pView->GetViewFrame() == pViewFrame) 135 { 136 pActiveView = pView; 137 break; 138 } 139 pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId); 140 } 141 } 142 if(!pActiveView) 143 { 144 DBG_ERROR("No active view could be found"); 145 return; 146 } 147 SwWrtShell* pWrtShell = pActiveView->GetWrtShellPtr(); 148 aPopMenu.EnableItem( FN_TOOL_ANKER_FRAME, 0 != pWrtShell->IsFlyInFly() ); 149 150 Rectangle aRect(GetToolBox().GetItemRect(GetId())); 151 sal_uInt16 nHtmlMode = ::GetHtmlMode((SwDocShell*)SfxObjectShell::Current()); 152 sal_Bool bHtmlModeNoAnchor = ( nHtmlMode & HTMLMODE_ON) && 0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS); 153 154 if (bHtmlModeNoAnchor || pWrtShell->IsInHeaderFooter()) 155 aPopMenu.RemoveItem(aPopMenu.GetItemPos(FN_TOOL_ANKER_PAGE)); 156 157 if (nActAnchorId) 158 aPopMenu.CheckItem(nActAnchorId); 159 160 161 sal_uInt16 nSlotId = aPopMenu.Execute(&GetToolBox(), aRect); 162 GetToolBox().EndSelection(); 163 164 if (nSlotId) 165 pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD); 166 } 167