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
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28
29 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
30 #include <vcl/timer.hxx>
31 #include <sfx2/app.hxx>
32 #include <svx/htmlmode.hxx>
33 #include <svl/intitem.hxx>
34 #include <sfx2/dispatch.hxx>
35 #ifndef _TOOLBOX_HXX //autogen
36 #include <vcl/toolbox.hxx>
37 #endif
38 #include <sfx2/mnumgr.hxx>
39
40
41 #include "cmdid.h"
42 #include "docsh.hxx"
43 #include "swtypes.hxx"
44 #include "swmodule.hxx"
45 #include "wrtsh.hxx"
46 #include "view.hxx"
47 #include "viewopt.hxx"
48 #include "errhdl.hxx"
49 #include "ribbar.hrc"
50 #include "tbxanchr.hxx"
51
52
53
54 SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor, SfxUInt16Item);
55
56 /******************************************************************************
57 * Beschreibung:
58 ******************************************************************************/
59
SwTbxAnchor(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)60 SwTbxAnchor::SwTbxAnchor( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
61 SfxToolBoxControl( nSlotId, nId, rTbx ),
62 nActAnchorId(0)
63 {
64 rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
65 }
66
67 /******************************************************************************
68 * Beschreibung:
69 ******************************************************************************/
70
~SwTbxAnchor()71 SwTbxAnchor::~SwTbxAnchor()
72 {
73 }
74
75 /******************************************************************************
76 * Beschreibung:
77 ******************************************************************************/
78
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem * pState)79 void SwTbxAnchor::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
80 {
81 GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
82
83 if( eState == SFX_ITEM_AVAILABLE )
84 {
85 const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
86 if(pItem)
87 nActAnchorId = pItem->GetValue();
88 }
89
90 }
91
92 /******************************************************************************
93 * Beschreibung:
94 ******************************************************************************/
95
CreatePopupWindow()96 SfxPopupWindow* SwTbxAnchor::CreatePopupWindow()
97 {
98 SwTbxAnchor::Click();
99 return 0;
100 }
101
102 /******************************************************************************
103 * Beschreibung:
104 ******************************************************************************/
105
Click()106 void SwTbxAnchor::Click()
107 {
108 PopupMenu aPopMenu(SW_RES(MN_ANCHOR_POPUP));
109
110 SfxViewFrame* pViewFrame( 0 );
111 SfxDispatcher* pDispatch( 0 );
112 SfxViewShell* pCurSh( SfxViewShell::Current() );
113
114 if ( pCurSh )
115 {
116 pViewFrame = pCurSh->GetViewFrame();
117 if ( pViewFrame )
118 pDispatch = pViewFrame->GetDispatcher();
119 }
120
121 // SfxDispatcher* pDispatch = GetBindings().GetDispatcher();
122 // SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
123 SwView* pActiveView = 0;
124 if(pViewFrame)
125 {
126 const TypeId aTypeId = TYPE(SwView);
127 SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
128 while( pView )
129 {
130 if(pView->GetViewFrame() == pViewFrame)
131 {
132 pActiveView = pView;
133 break;
134 }
135 pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
136 }
137 }
138 if(!pActiveView)
139 {
140 DBG_ERROR("No active view could be found");
141 return;
142 }
143 SwWrtShell* pWrtShell = pActiveView->GetWrtShellPtr();
144 aPopMenu.EnableItem( FN_TOOL_ANKER_FRAME, 0 != pWrtShell->IsFlyInFly() );
145
146 Rectangle aRect(GetToolBox().GetItemRect(GetId()));
147 sal_uInt16 nHtmlMode = ::GetHtmlMode((SwDocShell*)SfxObjectShell::Current());
148 sal_Bool bHtmlModeNoAnchor = ( nHtmlMode & HTMLMODE_ON) && 0 == (nHtmlMode & HTMLMODE_SOME_ABS_POS);
149
150 if (bHtmlModeNoAnchor || pWrtShell->IsInHeaderFooter())
151 aPopMenu.RemoveItem(aPopMenu.GetItemPos(FN_TOOL_ANKER_PAGE));
152
153 if (nActAnchorId)
154 aPopMenu.CheckItem(nActAnchorId);
155
156
157 sal_uInt16 nSlotId = aPopMenu.Execute(&GetToolBox(), aRect);
158 GetToolBox().EndSelection();
159
160 if (nSlotId)
161 pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
162 }
163