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