LibreOffice Module sd (master) 1
tmplctrl.cxx
Go to the documentation of this file.
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/weldutils.hxx>
23#include <svl/stritem.hxx>
24#include <sfx2/dispatch.hxx>
25#include <sfx2/viewfrm.hxx>
26
27#include <tmplctrl.hxx>
28#include <ViewShellBase.hxx>
29#include <drawdoc.hxx>
30#include <sdpage.hxx>
31#include <sdattr.hrc>
32#include <app.hrc>
33#include <sdresid.hxx>
34#include <strings.hrc>
35
37
38// class SdTemplateControl ------------------------------------------
40 sal_uInt16 _nId,
41 StatusBar& rStb ) :
42 SfxStatusBarControl( _nSlotId, _nId, rStb )
43{
44 GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_STATUSBAR_MASTERPAGE));
45}
46
48{
49}
50
52 sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
53{
54 if( eState != SfxItemState::DEFAULT || pState->IsVoidItem() )
55 GetStatusBar().SetItemText( GetId(), OUString() );
56 else if ( auto pStringItem = dynamic_cast< const SfxStringItem *>( pState ) )
57 {
58 msTemplate = pStringItem->GetValue();
60 }
61}
62
64{
65}
66
68{
69 if ( rCEvt.GetCommand() != CommandEventId::ContextMenu || GetStatusBar().GetItemText( GetId() ).isEmpty() )
70 return;
71
72 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
73
74 sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase( pViewFrame );
75 if( !pViewShellBase )
76 return;
77
78 SdDrawDocument* pDoc = pViewShellBase->GetDocument();
79 if( !pDoc )
80 return;
81
82 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/simpress/ui/masterpagemenu.ui"));
83 std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
84
85 const sal_uInt16 nMasterCount = pDoc->GetMasterSdPageCount(PageKind::Standard);
86
87 for (sal_uInt16 nPage = 0; nPage < nMasterCount; ++nPage)
88 {
89 SdPage* pMaster = pDoc->GetMasterSdPage(nPage, PageKind::Standard);
90 if (!pMaster)
91 continue;
92 xPopup->append(OUString::number(nPage), pMaster->GetName());
93 }
94
95 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
97 OUString sResult = xPopup->popup_at_rect(pParent, aRect);
98 if (!sResult.isEmpty())
99 {
100 sal_uInt16 nCurrId = sResult.toUInt32();
101 SdPage* pMaster = pDoc->GetMasterSdPage(nCurrId, PageKind::Standard);
102 SfxStringItem aStyle( ATTR_PRESLAYOUT_NAME, pMaster->GetName() );
103 pViewFrame->GetDispatcher()->ExecuteList(
104 SID_PRESENTATION_LAYOUT, SfxCallMode::SLOT, { &aStyle });
105 pViewFrame->GetBindings().Invalidate(SID_PRESENTATION_LAYOUT);
106 pViewFrame->GetBindings().Invalidate(SID_STATUS_LAYOUT);
107 }
108}
109
110/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const
Definition: drawdoc2.cxx:222
SdPage * GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind)
Definition: drawdoc2.cxx:217
const OUString & GetName() const
Definition: sdpage.cxx:2505
SdTemplateControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: tmplctrl.cxx:39
virtual void Command(const CommandEvent &rCEvt) override
Definition: tmplctrl.cxx:67
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: tmplctrl.cxx:63
OUString msTemplate
Definition: tmplctrl.hxx:37
virtual ~SdTemplateControl() override
Definition: tmplctrl.cxx:47
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tmplctrl.cxx:51
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
virtual bool IsVoidItem() const
StatusBar & GetStatusBar() const
sal_uInt16 GetId() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxBindings & GetBindings()
SfxDispatcher * GetDispatcher()
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
static ViewShellBase * GetViewShellBase(SfxViewFrame const *pFrame)
When given a view frame this static method returns the corresponding sd::ViewShellBase object.
SdDrawDocument * GetDocument() const
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
SfxItemState
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83
SFX_IMPL_STATUSBAR_CONTROL(SdTemplateControl, SfxStringItem)