LibreOffice Module sfx2 (master) 1
tplcitem.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/intitem.hxx>
21#include <vcl/svapp.hxx>
22#include <osl/diagnose.h>
23
24#include <sfx2/bindings.hxx>
25#include <sfx2/tplpitem.hxx>
26#include <sfx2/sfxsids.hrc>
27#include <tplcitem.hxx>
28#include <templdgi.hxx>
29
30// Constructor
31
33 sal_uInt16 nSlotId, // ID
34 SfxCommonTemplateDialog_Impl &rDlg, // Controller-Instance,
35 // which is assigned to this item.
36 SfxBindings &rBindings):
37 SfxControllerItem(nSlotId, rBindings),
38 rTemplateDlg(rDlg),
39 nWaterCanState(0xff),
40 nUserEventId(nullptr)
41{
42}
43
45{
46 if(nUserEventId)
48}
49
50
51// Notice about change of status, is propagated through the Controller
52// passed on by the constructor
53
55 const SfxPoolItem* pItem )
56{
57 switch(nSID)
58 {
59 case SID_STYLE_FAMILY1:
60 case SID_STYLE_FAMILY2:
61 case SID_STYLE_FAMILY3:
62 case SID_STYLE_FAMILY4:
63 case SID_STYLE_FAMILY5:
64 case SID_STYLE_FAMILY6:
65 {
66 bool bAvailable = SfxItemState::DEFAULT == eState;
67 if ( !bAvailable )
69 else {
70 const SfxTemplateItem *pStateItem = dynamic_cast< const SfxTemplateItem* >(pItem);
71 DBG_ASSERT(pStateItem != nullptr, "SfxTemplateItem expected");
72 rTemplateDlg.SetFamilyState( GetId(), pStateItem );
73 }
74 bool bDisable = eState == SfxItemState::DISABLED;
75 // Disable Family
76 sal_uInt16 nFamily = 0;
77 switch( GetId())
78 {
79 case SID_STYLE_FAMILY1:
80 nFamily = 1; break;
81 case SID_STYLE_FAMILY2:
82 nFamily = 2; break;
83 case SID_STYLE_FAMILY3:
84 nFamily = 3; break;
85 case SID_STYLE_FAMILY4:
86 nFamily = 4; break;
87 case SID_STYLE_FAMILY5:
88 nFamily = 5; break;
89 case SID_STYLE_FAMILY6:
90 nFamily = 6; break;
91
92 default: OSL_FAIL("unknown StyleFamily"); break;
93 }
94 rTemplateDlg.EnableFamilyItem( nFamily, !bDisable );
95 break;
96 }
97 case SID_STYLE_WATERCAN:
98 {
99 if ( eState == SfxItemState::DISABLED )
100 nWaterCanState = 0xff;
101 else if( eState == SfxItemState::DEFAULT )
102 {
103 const SfxBoolItem& rStateItem = dynamic_cast<const SfxBoolItem&>(*pItem);
104 nWaterCanState = rStateItem.GetValue() ? 1 : 0;
105 }
106 //not necessary if the last event is still on the way
107 if(!nUserEventId)
109 this, SfxTemplateControllerItem, SetWaterCanStateHdl_Impl ) );
110 break;
111 }
112 case SID_STYLE_EDIT:
113 rTemplateDlg.EnableEdit( SfxItemState::DISABLED != eState, nullptr );
114 break;
115 case SID_STYLE_DELETE:
116 rTemplateDlg.EnableDel( SfxItemState::DISABLED != eState, nullptr );
117 break;
118 case SID_STYLE_HIDE:
119 rTemplateDlg.EnableHide( SfxItemState::DISABLED != eState, nullptr );
120 break;
121 case SID_STYLE_SHOW:
122 rTemplateDlg.EnableShow( SfxItemState::DISABLED != eState, nullptr );
123 break;
124 case SID_STYLE_NEW_BY_EXAMPLE:
125
126 rTemplateDlg.EnableExample_Impl(nSID, SfxItemState::DISABLED != eState);
127 break;
128 case SID_STYLE_UPDATE_BY_EXAMPLE:
129 {
130 rTemplateDlg.EnableExample_Impl(nSID, eState != SfxItemState::DISABLED);
131 break;
132 }
133 case SID_STYLE_NEW:
134 {
135 rTemplateDlg.EnableNew( SfxItemState::DISABLED != eState, nullptr );
136 break;
137 }
138 case SID_STYLE_DRAGHIERARCHIE:
139 {
140 rTemplateDlg.EnableTreeDrag( SfxItemState::DISABLED != eState );
141 break;
142 }
143 case SID_STYLE_FAMILY :
144 {
145 const SfxUInt16Item *pStateItem = dynamic_cast< const SfxUInt16Item* >(pItem);
146 if (pStateItem)
147 {
148 rTemplateDlg.SetFamily(static_cast<SfxStyleFamily>(pStateItem->GetValue()));
149 }
150 break;
151 }
152 }
153}
154
155IMPL_LINK_NOARG(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl, void*, void)
156{
157 nUserEventId = nullptr;
158 std::unique_ptr<SfxBoolItem> pState;
159 switch(nWaterCanState)
160 {
161 case 0 :
162 case 1 :
163 pState.reset(new SfxBoolItem(SID_STYLE_WATERCAN, nWaterCanState != 0));
164 break;
165 }
166 rTemplateDlg.SetWaterCanState(pState.get());
167}
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
sal_uInt16 GetValue() const
bool GetValue() const
void SetFamilyState(sal_uInt16 nSlotId, const SfxTemplateItem *)
Definition: templdlg.cxx:417
void SetFamily(SfxStyleFamily nFamily)
Definition: templdlg.cxx:878
void EnableDel(bool b, const StyleList *rStyleList)
Definition: templdlg.cxx:937
virtual void EnableFamilyItem(sal_uInt16 nId, bool bEnabled)=0
void EnableShow(bool b, const StyleList *rStyleList)
Definition: templdlg.cxx:952
void EnableExample_Impl(sal_uInt16 nId, bool bEnable)
Definition: templdlg.cxx:696
virtual void EnableEdit(bool b, StyleList *rStyleList)
Definition: templdlg.cxx:932
void EnableHide(bool b, const StyleList *rStyleList)
Definition: templdlg.cxx:947
void EnableNew(bool b, const StyleList *rStyleList)
Definition: templdlg.cxx:942
sal_uInt16 GetId() const
Definition: ctrlitem.hxx:63
SfxTemplateControllerItem(sal_uInt16 nId, SfxCommonTemplateDialog_Impl &rDialog, SfxBindings &rBindings)
Definition: tplcitem.cxx:32
SfxCommonTemplateDialog_Impl & rTemplateDlg
Definition: tplcitem.hxx:30
virtual ~SfxTemplateControllerItem() override
Definition: tplcitem.cxx:44
virtual void StateChangedAtToolBoxControl(sal_uInt16, SfxItemState, const SfxPoolItem *pState) override
Definition: tplcitem.cxx:54
ImplSVEvent * nUserEventId
Definition: tplcitem.hxx:32
#define DBG_ASSERT(sCon, aError)
SfxItemState
SfxStyleFamily
IMPL_LINK_NOARG(SfxTemplateControllerItem, SetWaterCanStateHdl_Impl, void *, void)
Definition: tplcitem.cxx:155