Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / utlui / tmplctrl.cxx
blob647bdcd92b948886d7cf9f8139b58a60c5be7171
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svl/style.hxx>
21 #include <svl/stritem.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <vcl/commandevent.hxx>
25 #include <vcl/status.hxx>
26 #include <vcl/weldutils.hxx>
28 #include <swtypes.hxx>
29 #include <strings.hrc>
31 #include <wrtsh.hxx>
32 #include <view.hxx>
33 #include <swmodule.hxx>
34 #include <cmdid.h>
35 #include <docsh.hxx>
36 #include <tmplctrl.hxx>
38 SFX_IMPL_STATUSBAR_CONTROL( SwTemplateControl, SfxStringItem );
40 SwTemplateControl::SwTemplateControl( sal_uInt16 _nSlotId,
41 sal_uInt16 _nId,
42 StatusBar& rStb ) :
43 SfxStatusBarControl( _nSlotId, _nId, rStb )
47 SwTemplateControl::~SwTemplateControl()
51 void SwTemplateControl::StateChangedAtStatusBarControl(
52 sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
54 const SfxStringItem* pItem = nullptr;
55 if (SfxItemState::DEFAULT == eState && (pItem = dynamic_cast<const SfxStringItem*>(pState)))
57 m_sTemplate = pItem->GetValue();
58 GetStatusBar().SetItemText(GetId(), m_sTemplate);
59 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_TMPLCTRL_HINT));
61 else
63 GetStatusBar().SetItemText(GetId(), OUString());
64 GetStatusBar().SetQuickHelpText(GetId(), u"");
68 void SwTemplateControl::Paint( const UserDrawEvent& )
72 void SwTemplateControl::Command( const CommandEvent& rCEvt )
74 if ( rCEvt.GetCommand() != CommandEventId::ContextMenu ||
75 GetStatusBar().GetItemText( GetId() ).isEmpty())
76 return;
79 SwView* pView = ::GetActiveView();
80 SwWrtShell *const pWrtShell(pView ? pView->GetWrtShellPtr() : nullptr);
81 if (nullptr != pWrtShell &&
82 !pWrtShell->SwCursorShell::HasSelection()&&
83 !pWrtShell->IsSelFrameMode() &&
84 !pWrtShell->IsObjSelected())
86 SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
87 GetStyleSheetPool();
88 auto xIter = pPool->CreateIterator(SfxStyleFamily::Page);
89 if (xIter->Count() > 1)
91 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(nullptr, "modules/swriter/ui/pagestylemenu.ui"));
92 std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
94 sal_uInt32 nCount = 0;
95 SfxStyleSheetBase* pStyle = xIter->First();
96 while( pStyle )
98 xPopup->append(OUString::number(++nCount), pStyle->GetName());
99 pStyle = xIter->Next();
102 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
103 weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect);
104 OUString sResult = xPopup->popup_at_rect(pParent, aRect);
105 if (!sResult.isEmpty())
107 sal_uInt32 nCurrId = sResult.toUInt32();
108 // looks a bit awkward, but another way is not possible
109 pStyle = xIter->operator[]( nCurrId - 1 );
110 SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
111 pWrtShell->GetView().GetViewFrame().GetDispatcher()->ExecuteList(
112 FN_SET_PAGE_STYLE,
113 SfxCallMode::SLOT|SfxCallMode::RECORD,
114 { &aStyle });
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */