xref: /AOO42X/main/sw/source/ui/ribbar/tbxanchr.cxx (revision e6140a76b94f0417b75df5f46a8be5a24c510454)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_sw.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
26cdf0e10cSrcweir #include <vcl/timer.hxx>
27cdf0e10cSrcweir #include <sfx2/app.hxx>
28cdf0e10cSrcweir #include <svx/htmlmode.hxx>
29cdf0e10cSrcweir #include <svl/intitem.hxx>
30cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
31cdf0e10cSrcweir #ifndef _TOOLBOX_HXX //autogen
32cdf0e10cSrcweir #include <vcl/toolbox.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #include <sfx2/mnumgr.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "cmdid.h"
37cdf0e10cSrcweir #include "docsh.hxx"
38cdf0e10cSrcweir #include "swtypes.hxx"
39cdf0e10cSrcweir #include "swmodule.hxx"
40cdf0e10cSrcweir #include "wrtsh.hxx"
41cdf0e10cSrcweir #include "view.hxx"
42cdf0e10cSrcweir #include "viewopt.hxx"
43cdf0e10cSrcweir #include "errhdl.hxx"
44cdf0e10cSrcweir #include "ribbar.hrc"
45cdf0e10cSrcweir #include "tbxanchr.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor, SfxUInt16Item);
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /******************************************************************************
50cdf0e10cSrcweir  *  Beschreibung:
51cdf0e10cSrcweir  ******************************************************************************/
52cdf0e10cSrcweir 
SwTbxAnchor(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)53cdf0e10cSrcweir SwTbxAnchor::SwTbxAnchor( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
54cdf0e10cSrcweir     SfxToolBoxControl( nSlotId, nId, rTbx ),
55cdf0e10cSrcweir     nActAnchorId(0)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir /******************************************************************************
61cdf0e10cSrcweir  *  Beschreibung:
62cdf0e10cSrcweir  ******************************************************************************/
63cdf0e10cSrcweir 
~SwTbxAnchor()64cdf0e10cSrcweir  SwTbxAnchor::~SwTbxAnchor()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir /******************************************************************************
69cdf0e10cSrcweir  *  Beschreibung:
70cdf0e10cSrcweir  ******************************************************************************/
71cdf0e10cSrcweir 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)72cdf0e10cSrcweir void  SwTbxAnchor::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     if( eState == SFX_ITEM_AVAILABLE )
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir         const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
79cdf0e10cSrcweir         if(pItem)
80cdf0e10cSrcweir             nActAnchorId = pItem->GetValue();
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir /******************************************************************************
86cdf0e10cSrcweir  *  Beschreibung:
87cdf0e10cSrcweir  ******************************************************************************/
88cdf0e10cSrcweir 
CreatePopupWindow()89cdf0e10cSrcweir SfxPopupWindow* SwTbxAnchor::CreatePopupWindow()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     SwTbxAnchor::Click();
92cdf0e10cSrcweir     return 0;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir /******************************************************************************
96cdf0e10cSrcweir  *  Beschreibung:
97cdf0e10cSrcweir  ******************************************************************************/
98cdf0e10cSrcweir 
Click()99cdf0e10cSrcweir void  SwTbxAnchor::Click()
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     PopupMenu aPopMenu(SW_RES(MN_ANCHOR_POPUP));
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     SfxViewFrame*   pViewFrame( 0 );
104cdf0e10cSrcweir     SfxDispatcher*  pDispatch( 0 );
105cdf0e10cSrcweir     SfxViewShell*   pCurSh( SfxViewShell::Current() );
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     if ( pCurSh )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         pViewFrame = pCurSh->GetViewFrame();
110cdf0e10cSrcweir         if ( pViewFrame )
111cdf0e10cSrcweir             pDispatch = pViewFrame->GetDispatcher();
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir //  SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
115cdf0e10cSrcweir //  SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
116cdf0e10cSrcweir     SwView* pActiveView = 0;
117cdf0e10cSrcweir     if(pViewFrame)
118cdf0e10cSrcweir     {
119cdf0e10cSrcweir         const TypeId aTypeId = TYPE(SwView);
120cdf0e10cSrcweir         SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
121cdf0e10cSrcweir         while( pView )
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             if(pView->GetViewFrame() == pViewFrame)
124cdf0e10cSrcweir             {
125cdf0e10cSrcweir                 pActiveView = pView;
126cdf0e10cSrcweir                 break;
127cdf0e10cSrcweir             }
128cdf0e10cSrcweir             pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir     if(!pActiveView)
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         DBG_ERROR("No active view could be found");
134cdf0e10cSrcweir         return;
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir     SwWrtShell* pWrtShell = pActiveView->GetWrtShellPtr();
137*e6140a76Smseidel     aPopMenu.EnableItem( FN_TOOL_ANCHOR_FRAME, 0 != pWrtShell->IsFlyInFly() );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     Rectangle aRect(GetToolBox().GetItemRect(GetId()));
140cdf0e10cSrcweir     sal_uInt16 nHtmlMode = ::GetHtmlMode((SwDocShell*)SfxObjectShell::Current());
141cdf0e10cSrcweir     sal_Bool bHtmlModeNoAnchor = ( nHtmlMode & HTMLMODE_ON) && 0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     if (bHtmlModeNoAnchor || pWrtShell->IsInHeaderFooter())
144*e6140a76Smseidel         aPopMenu.RemoveItem(aPopMenu.GetItemPos(FN_TOOL_ANCHOR_PAGE));
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     if (nActAnchorId)
147cdf0e10cSrcweir         aPopMenu.CheckItem(nActAnchorId);
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     sal_uInt16 nSlotId = aPopMenu.Execute(&GetToolBox(), aRect);
151cdf0e10cSrcweir     GetToolBox().EndSelection();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     if (nSlotId)
154cdf0e10cSrcweir         pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
155cdf0e10cSrcweir }
156*e6140a76Smseidel 
157*e6140a76Smseidel /* vim: set noet sw=4 ts=4: */
158