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 <vcl/menu.hxx>
22 #include <svl/stritem.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/viewfrm.hxx>
25 #include <vcl/commandevent.hxx>
26 #include <vcl/status.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 {
42 public:
44 
45  sal_uInt16 GetCurId() const { return nCurId; }
46 
47 private:
48  sal_uInt16 nCurId;
49 
50  virtual void Select() override;
51 };
52 
54  PopupMenu(),
55  nCurId(USHRT_MAX)
56 {
57 }
58 
60 {
61  nCurId = GetCurItemId();
62 }
63 
65  sal_uInt16 _nId,
66  StatusBar& rStb ) :
67  SfxStatusBarControl( _nSlotId, _nId, rStb )
68 {
69  GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_TMPLCTRL_HINT));
70 }
71 
73 {
74 }
75 
77  sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
78 {
79  const SfxStringItem* pItem = nullptr;
80  if (SfxItemState::DEFAULT == eState && (pItem = dynamic_cast<const SfxStringItem*>(pState)))
81  {
82  sTemplate = pItem->GetValue();
84  }
85  else
86  GetStatusBar().SetItemText(GetId(), OUString());
87 }
88 
90 {
92 }
93 
95 {
96  if ( rCEvt.GetCommand() == CommandEventId::ContextMenu &&
97  !GetStatusBar().GetItemText( GetId() ).isEmpty() )
98  {
100  {
101  SwView* pView = ::GetActiveView();
102  SwWrtShell *const pWrtShell(pView ? pView->GetWrtShellPtr() : nullptr);
103  if (nullptr != pWrtShell &&
104  !pWrtShell->SwCursorShell::HasSelection()&&
105  !pWrtShell->IsSelFrameMode() &&
106  !pWrtShell->IsObjSelected())
107  {
108  SfxStyleSheetBasePool* pPool = pView->GetDocShell()->
109  GetStyleSheetPool();
110  pPool->SetSearchMask(SfxStyleFamily::Page);
111  if( pPool->Count() > 1 )
112  {
113  sal_uInt16 nCount = 0;
114  SfxStyleSheetBase* pStyle = pPool->First();
115  while( pStyle )
116  {
117  aPop->InsertItem( ++nCount, pStyle->GetName() );
118  pStyle = pPool->Next();
119  }
120 
121  aPop->Execute( &GetStatusBar(), rCEvt.GetMousePosPixel());
122  const sal_uInt16 nCurrId = aPop->GetCurId();
123  if( nCurrId != USHRT_MAX)
124  {
125  // looks a bit awkward, but another way is not possible
126  pStyle = pPool->operator[]( nCurrId - 1 );
127  SfxStringItem aStyle( FN_SET_PAGE_STYLE, pStyle->GetName() );
128  pWrtShell->GetView().GetViewFrame()->GetDispatcher()->ExecuteList(
130  SfxCallMode::SLOT|SfxCallMode::RECORD,
131  { &aStyle });
132  }
133  }
134  }
135  }
136  }
137 }
138 
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwTemplateControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: tmplctrl.cxx:64
SfxStyleSheetBase * First()
#define FN_SET_PAGE_STYLE
Definition: cmdid.h:323
SwView * GetActiveView()
Definition: swmodul1.cxx:123
sal_uInt16 nCurId
Definition: tmplctrl.cxx:48
sal_uInt16 GetCurId() const
Definition: tmplctrl.cxx:45
const OUString & GetItemText(sal_uInt16 nItemId) const
virtual ~SwTemplateControl() override
Definition: tmplctrl.cxx:72
SFX_IMPL_STATUSBAR_CONTROL(SwTemplateControl, SfxStringItem)
sal_uInt16 Execute(vcl::Window *pWindow, const Point &rPopupPos)
Used by the UI to modify the document model.
Definition: wrtsh.hxx:88
virtual void Select() override
Definition: tmplctrl.cxx:59
const OUString & GetName() const
sal_uInt16 GetId() const
sal_uInt16 GetCurItemId() const
const OUString & GetValue() const
CommandEventId GetCommand() const
virtual void Paint(const UserDrawEvent &rEvt) override
Definition: tmplctrl.cxx:89
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
SwDocShell * GetDocShell()
Definition: view.cxx:1115
const Point & GetMousePosPixel() const
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:401
SfxItemState
SfxStyleSheetBase * Next()
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
StatusBar & GetStatusBar() const
void SetSearchMask(SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tmplctrl.cxx:76
void SetItemText(sal_uInt16 nItemId, const OUString &rText)
OUString sTemplate
Definition: tmplctrl.hxx:39
virtual void Command(const CommandEvent &rCEvt) override
Definition: tmplctrl.cxx:94
Definition: view.hxx:146