LibreOffice Module sw (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 <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>
27
28#include <swtypes.hxx>
29#include <strings.hrc>
30
31#include <wrtsh.hxx>
32#include <view.hxx>
33#include <swmodule.hxx>
34#include <cmdid.h>
35#include <docsh.hxx>
36#include <tmplctrl.hxx>
37
39
41 sal_uInt16 _nId,
42 StatusBar& rStb ) :
43 SfxStatusBarControl( _nSlotId, _nId, rStb )
44{
45}
46
48{
49}
50
52 sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
53{
54 const SfxStringItem* pItem = nullptr;
55 if (SfxItemState::DEFAULT == eState && (pItem = dynamic_cast<const SfxStringItem*>(pState)))
56 {
57 m_sTemplate = pItem->GetValue();
59 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_TMPLCTRL_HINT));
60 }
61 else
62 {
63 GetStatusBar().SetItemText(GetId(), OUString());
65 }
66}
67
69{
70}
71
73{
74 if ( rCEvt.GetCommand() != CommandEventId::ContextMenu ||
75 GetStatusBar().GetItemText( GetId() ).isEmpty())
76 return;
77
78 {
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())
85 {
86 SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
87 GetStyleSheetPool();
88 auto xIter = pPool->CreateIterator(SfxStyleFamily::Page);
89 if (xIter->Count() > 1)
90 {
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"));
93
94 sal_uInt32 nCount = 0;
95 SfxStyleSheetBase* pStyle = xIter->First();
96 while( pStyle )
97 {
98 xPopup->append(OUString::number(++nCount), pStyle->GetName());
99 pStyle = xIter->Next();
100 }
101
102 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
104 OUString sResult = xPopup->popup_at_rect(pParent, aRect);
105 if (!sResult.isEmpty())
106 {
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() );
113 SfxCallMode::SLOT|SfxCallMode::RECORD,
114 { &aStyle });
115 }
116 }
117 }
118 }
119}
120
121/* 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)
const OUString & GetValue() const
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
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 * >())
StatusBar & GetStatusBar() const
sal_uInt16 GetId() const
virtual std::unique_ptr< SfxStyleSheetIterator > CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
const OUString & GetName() const
SfxDispatcher * GetDispatcher()
SfxViewFrame & GetViewFrame() const
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
size_t IsObjSelected() const
Definition: feshview.cxx:1125
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: tmplctrl.cxx:68
virtual ~SwTemplateControl() override
Definition: tmplctrl.cxx:47
SwTemplateControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: tmplctrl.cxx:40
virtual void Command(const CommandEvent &rCEvt) override
Definition: tmplctrl.cxx:72
OUString m_sTemplate
Definition: tmplctrl.hxx:39
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tmplctrl.cxx:51
Definition: view.hxx:146
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:424
SwDocShell * GetDocShell()
Definition: view.cxx:1193
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
bool IsSelFrameMode() const
Definition: wrtsh.hxx:177
const SwView & GetView() const
Definition: wrtsh.hxx:443
#define FN_SET_PAGE_STYLE
Definition: cmdid.h:374
int nCount
float u
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
SfxItemState
SwView * GetActiveView()
Definition: swmodul1.cxx:115
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
SFX_IMPL_STATUSBAR_CONTROL(SwTemplateControl, SfxStringItem)