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));
103  weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect);
104  OString 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() );
111  pWrtShell->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
113  SfxCallMode::SLOT|SfxCallMode::RECORD,
114  { &aStyle });
115  }
116  }
117  }
118  }
119 }
120 
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTemplateControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: tmplctrl.cxx:40
virtual std::unique_ptr< SfxStyleSheetIterator > CreateIterator(SfxStyleFamily, SfxStyleSearchBits nMask=SfxStyleSearchBits::All)
OUString m_sTemplate
Definition: tmplctrl.hxx:39
#define FN_SET_PAGE_STYLE
Definition: cmdid.h:341
SwView * GetActiveView()
Definition: swmodul1.cxx:116
const OUString & GetItemText(sal_uInt16 nItemId) const
virtual ~SwTemplateControl() override
Definition: tmplctrl.cxx:47
SFX_IMPL_STATUSBAR_CONTROL(SwTemplateControl, SfxStringItem)
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
const OUString & GetName() const
int nCount
sal_uInt16 GetId() const
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
const OUString & GetValue() const
CommandEventId GetCommand() const
float u
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: tmplctrl.cxx:68
SwDocShell * GetDocShell()
Definition: view.cxx:1132
const Point & GetMousePosPixel() const
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:414
SfxItemState
StatusBar & GetStatusBar() const
virtual void Command(const CommandEvent &rCEvt) override
Definition: tmplctrl.cxx:72
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tmplctrl.cxx:51
Definition: view.hxx:144
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)