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