Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
28 :
29 : #include "cmdid.h"
30 : #include "docsh.hxx"
31 : #include "swtypes.hxx"
32 : #include "swmodule.hxx"
33 : #include "wrtsh.hxx"
34 : #include "view.hxx"
35 : #include "viewopt.hxx"
36 : #include "ribbar.hrc"
37 : #include "tbxanchr.hxx"
38 :
39 0 : SFX_IMPL_TOOLBOX_CONTROL(SwTbxAnchor, SfxUInt16Item);
40 :
41 0 : SwTbxAnchor::SwTbxAnchor( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
42 : SfxToolBoxControl( nSlotId, nId, rTbx ),
43 0 : nActAnchorId(0)
44 : {
45 0 : rTbx.SetItemBits( nId, TIB_DROPDOWNONLY | rTbx.GetItemBits( nId ) );
46 0 : }
47 :
48 0 : SwTbxAnchor::~SwTbxAnchor()
49 : {
50 0 : }
51 :
52 0 : void SwTbxAnchor::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
53 : {
54 0 : GetToolBox().EnableItem( GetId(), (GetItemState(pState) != SFX_ITEM_DISABLED) );
55 :
56 0 : if( eState == SFX_ITEM_AVAILABLE )
57 : {
58 0 : const SfxUInt16Item* pItem = PTR_CAST( SfxUInt16Item, pState );
59 0 : if(pItem)
60 0 : nActAnchorId = pItem->GetValue();
61 : }
62 :
63 0 : }
64 :
65 0 : SfxPopupWindow* SwTbxAnchor::CreatePopupWindow()
66 : {
67 0 : SwTbxAnchor::Click();
68 0 : return 0;
69 : }
70 :
71 0 : void SwTbxAnchor::Click()
72 : {
73 0 : PopupMenu aPopMenu(SW_RES(MN_ANCHOR_POPUP));
74 :
75 0 : SfxViewFrame* pViewFrame( 0 );
76 0 : SfxDispatcher* pDispatch( 0 );
77 0 : SfxViewShell* pCurSh( SfxViewShell::Current() );
78 :
79 0 : if ( pCurSh )
80 : {
81 0 : pViewFrame = pCurSh->GetViewFrame();
82 0 : if ( pViewFrame )
83 0 : pDispatch = pViewFrame->GetDispatcher();
84 : }
85 :
86 0 : SwView* pActiveView = 0;
87 0 : if(pViewFrame)
88 : {
89 0 : const TypeId aTypeId = TYPE(SwView);
90 0 : SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
91 0 : while( pView )
92 : {
93 0 : if(pView->GetViewFrame() == pViewFrame)
94 : {
95 0 : pActiveView = pView;
96 0 : break;
97 : }
98 0 : pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
99 : }
100 : }
101 0 : if(!pActiveView)
102 : {
103 : OSL_FAIL("No active view found");
104 0 : return;
105 : }
106 0 : SwWrtShell* pWrtShell = pActiveView->GetWrtShellPtr();
107 0 : aPopMenu.EnableItem( FN_TOOL_ANCHOR_FRAME, 0 != pWrtShell->IsFlyInFly() );
108 :
109 0 : Rectangle aRect(GetToolBox().GetItemRect(GetId()));
110 :
111 0 : if (pWrtShell->IsInHeaderFooter())
112 0 : aPopMenu.RemoveItem(aPopMenu.GetItemPos(FN_TOOL_ANCHOR_PAGE));
113 :
114 0 : if (nActAnchorId)
115 0 : aPopMenu.CheckItem(nActAnchorId);
116 :
117 0 : sal_uInt16 nSlotId = aPopMenu.Execute(&GetToolBox(), aRect);
118 0 : GetToolBox().EndSelection();
119 :
120 0 : if (nSlotId)
121 0 : pDispatch->Execute(nSlotId, SFX_CALLMODE_ASYNCHRON|SFX_CALLMODE_RECORD);
122 : }
123 :
124 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|