/src/libreoffice/sd/source/ui/app/tmplctrl.cxx
Line | Count | Source |
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 <vcl/commandevent.hxx> |
21 | | #include <vcl/status.hxx> |
22 | | #include <vcl/svapp.hxx> |
23 | | #include <vcl/weld/Builder.hxx> |
24 | | #include <vcl/weld/Menu.hxx> |
25 | | #include <vcl/weld/weldutils.hxx> |
26 | | #include <svl/stritem.hxx> |
27 | | #include <sfx2/dispatch.hxx> |
28 | | #include <sfx2/viewfrm.hxx> |
29 | | |
30 | | #include <tmplctrl.hxx> |
31 | | #include <ViewShellBase.hxx> |
32 | | #include <drawdoc.hxx> |
33 | | #include <sdpage.hxx> |
34 | | #include <sdattr.hrc> |
35 | | #include <app.hrc> |
36 | | #include <sdresid.hxx> |
37 | | #include <strings.hrc> |
38 | | |
39 | | SFX_IMPL_STATUSBAR_CONTROL( SdTemplateControl, SfxStringItem ); |
40 | | |
41 | | // class SdTemplateControl ------------------------------------------ |
42 | | SdTemplateControl::SdTemplateControl( sal_uInt16 _nSlotId, |
43 | | sal_uInt16 _nId, |
44 | | StatusBar& rStb ) : |
45 | 0 | SfxStatusBarControl( _nSlotId, _nId, rStb ) |
46 | 0 | { |
47 | 0 | GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_STATUSBAR_MASTERPAGE)); |
48 | 0 | } |
49 | | |
50 | | SdTemplateControl::~SdTemplateControl() |
51 | 0 | { |
52 | 0 | } |
53 | | |
54 | | void SdTemplateControl::StateChangedAtStatusBarControl( |
55 | | sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) |
56 | 0 | { |
57 | 0 | if (eState != SfxItemState::DEFAULT || SfxItemState::DISABLED == eState) |
58 | 0 | GetStatusBar().SetItemText( GetId(), OUString() ); |
59 | | |
60 | 0 | else if ( auto pStringItem = dynamic_cast< const SfxStringItem *>( pState ) ) |
61 | 0 | { |
62 | 0 | msTemplate = pStringItem->GetValue(); |
63 | 0 | GetStatusBar().SetItemText( GetId(), msTemplate ); |
64 | 0 | } |
65 | 0 | } |
66 | | |
67 | | void SdTemplateControl::Paint( const UserDrawEvent& ) |
68 | 0 | { |
69 | 0 | } |
70 | | |
71 | | void SdTemplateControl::Command( const CommandEvent& rCEvt ) |
72 | 0 | { |
73 | 0 | if ( rCEvt.GetCommand() != CommandEventId::ContextMenu || GetStatusBar().GetItemText( GetId() ).isEmpty() ) |
74 | 0 | return; |
75 | | |
76 | 0 | SfxViewFrame* pViewFrame = SfxViewFrame::Current(); |
77 | |
|
78 | 0 | sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame ); |
79 | 0 | if( !pViewShellBase ) |
80 | 0 | return; |
81 | | |
82 | 0 | SdDrawDocument* pDoc = pViewShellBase->GetDocument(); |
83 | 0 | if( !pDoc ) |
84 | 0 | return; |
85 | | |
86 | 0 | std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, u"modules/simpress/ui/masterpagemenu.ui"_ustr)); |
87 | 0 | std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(u"menu"_ustr)); |
88 | |
|
89 | 0 | const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PageKind::Standard); |
90 | |
|
91 | 0 | for (sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage) |
92 | 0 | { |
93 | 0 | SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PageKind::Standard); |
94 | 0 | if (!pMaster) |
95 | 0 | continue; |
96 | 0 | xPopup->append(OUString::number(nPage), pMaster->GetName()); |
97 | 0 | } |
98 | |
|
99 | 0 | ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1)); |
100 | 0 | weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect); |
101 | 0 | OUString sResult = xPopup->popup_at_rect(pParent, aRect); |
102 | 0 | if (!sResult.isEmpty()) |
103 | 0 | { |
104 | 0 | sal_uInt16 nCurrId = sResult.toUInt32(); |
105 | 0 | SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PageKind::Standard); |
106 | 0 | SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() ); |
107 | 0 | pViewFrame->GetDispatcher()->ExecuteList( |
108 | 0 | SID_PRESENTATION_LAYOUT, SfxCallMode::SLOT, { &aStyle }); |
109 | 0 | pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT); |
110 | 0 | pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT); |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |