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