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