/src/libreoffice/include/sfx2/event.hxx
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 | | #ifndef INCLUDED_SFX2_EVENT_HXX |
20 | | #define INCLUDED_SFX2_EVENT_HXX |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <ostream> |
25 | | |
26 | | #include <unotools/weakref.hxx> |
27 | | #include <sfx2/dllapi.h> |
28 | | #include <svl/hint.hxx> |
29 | | #include <unotools/eventcfg.hxx> |
30 | | #include <rtl/ustring.hxx> |
31 | | #include <sfx2/objsh.hxx> |
32 | | |
33 | | #include <com/sun/star/uno/Sequence.hxx> |
34 | | #include <com/sun/star/frame/XController2.hpp> |
35 | | #include <utility> |
36 | | |
37 | | namespace com::sun::star::beans { struct PropertyValue; } |
38 | | namespace com::sun::star::view { enum class PrintableState; } |
39 | | |
40 | | /** |
41 | | these values get stored in streams in a 16-bit value |
42 | | */ |
43 | | enum class SvMacroItemId : sal_uInt16 { |
44 | | NONE = 0, |
45 | | |
46 | | // used by SwHTMLForm_Impl |
47 | | HtmlOnSubmitForm, |
48 | | HtmlOnResetForm, |
49 | | HtmlOnGetFocus, |
50 | | HtmlOnLoseFocus, |
51 | | HtmlOnClick, |
52 | | HtmlOnClickItem, |
53 | | HtmlOnChange, |
54 | | HtmlOnSelect, |
55 | | |
56 | | // used by SwHTMLParser |
57 | | OpenDoc, |
58 | | PrepareCloseDoc, |
59 | | ActivateDoc, |
60 | | DeactivateDoc, |
61 | | |
62 | | // Events for Controls etc. |
63 | | OnMouseOver = 5100, |
64 | | OnClick = 5101, |
65 | | OnMouseOut = 5102, |
66 | | |
67 | | OnImageLoadDone = 10000, |
68 | | OnImageLoadCancel = 10001, |
69 | | OnImageLoadError = 10002, |
70 | | |
71 | | SwObjectSelect = 20000, |
72 | | SwStartInsGlossary = 20001, |
73 | | SwEndInsGlossary = 20002, |
74 | | SwFrmKeyInputAlpha = 20004, |
75 | | SwFrmKeyInputNoAlpha = 20005, |
76 | | SwFrmResize = 20006, |
77 | | SwFrmMove = 20007, |
78 | | }; |
79 | | |
80 | | template< typename charT, typename traits > |
81 | | inline std::basic_ostream<charT, traits> & operator <<( |
82 | | std::basic_ostream<charT, traits> & stream, const SvMacroItemId& id ) |
83 | | { |
84 | | switch(id) |
85 | | { |
86 | | case SvMacroItemId::NONE: return stream << "NONE"; |
87 | | case SvMacroItemId::HtmlOnSubmitForm: return stream << "HtmlOnSubmitForm"; |
88 | | case SvMacroItemId::HtmlOnResetForm: return stream << "HtmlOnResetForm"; |
89 | | case SvMacroItemId::HtmlOnGetFocus: return stream << "HtmlOnGetFocus"; |
90 | | case SvMacroItemId::HtmlOnLoseFocus: return stream << "HtmlOnLoseFocus"; |
91 | | case SvMacroItemId::HtmlOnClick: return stream << "HtmlOnClick"; |
92 | | case SvMacroItemId::HtmlOnClickItem: return stream << "HtmlOnClickItem"; |
93 | | case SvMacroItemId::HtmlOnChange: return stream << "HtmlOnChange"; |
94 | | case SvMacroItemId::HtmlOnSelect: return stream << "HtmlOnSelect"; |
95 | | case SvMacroItemId::OpenDoc: return stream << "OpenDoc"; |
96 | | case SvMacroItemId::PrepareCloseDoc: return stream << "PrepareCloseDoc"; |
97 | | case SvMacroItemId::ActivateDoc: return stream << "ActivateDoc"; |
98 | | case SvMacroItemId::DeactivateDoc: return stream << "DeactivateDoc"; |
99 | | case SvMacroItemId::OnMouseOver: return stream << "OnMouseOver"; |
100 | | case SvMacroItemId::OnClick: return stream << "OnClick"; |
101 | | case SvMacroItemId::OnMouseOut: return stream << "OnMouseOut"; |
102 | | case SvMacroItemId::OnImageLoadDone: return stream << "OnImageLoadDone"; |
103 | | case SvMacroItemId::OnImageLoadCancel: return stream << "OnImageLoadCancel"; |
104 | | case SvMacroItemId::OnImageLoadError: return stream << "OnImageLoadError"; |
105 | | case SvMacroItemId::SwObjectSelect: return stream << "SwObjectSelect"; |
106 | | case SvMacroItemId::SwStartInsGlossary: return stream << "SwStartInsGlossary"; |
107 | | case SvMacroItemId::SwEndInsGlossary: return stream << "SwEndInsGlossary"; |
108 | | case SvMacroItemId::SwFrmKeyInputAlpha: return stream << "SwFrmKeyInputAlpha"; |
109 | | case SvMacroItemId::SwFrmKeyInputNoAlpha: return stream << "SwFrmKeyInputNoAlpha"; |
110 | | case SvMacroItemId::SwFrmResize: return stream << "SwFrmResize"; |
111 | | case SvMacroItemId::SwFrmMove: return stream << "SwFrmMove"; |
112 | | default: return stream << "unk(" << std::to_string(int(id)) << ")"; |
113 | | } |
114 | | } |
115 | | |
116 | | enum class SfxEventHintId { |
117 | | NONE = 0, |
118 | | ActivateDoc, |
119 | | CloseDoc, |
120 | | CloseView, |
121 | | CreateDoc, |
122 | | DeactivateDoc, |
123 | | DocCreated, |
124 | | LoadFinished, |
125 | | ModifyChanged, |
126 | | OpenDoc, |
127 | | PrepareCloseDoc, |
128 | | PrepareCloseView, |
129 | | PrintDoc, |
130 | | SaveAsDoc, |
131 | | SaveAsDocDone, |
132 | | SaveAsDocFailed, |
133 | | SaveDoc, |
134 | | SaveDocDone, |
135 | | SaveDocFailed, |
136 | | SaveToDoc, |
137 | | SaveToDocDone, |
138 | | SaveToDocFailed, |
139 | | StorageChanged, |
140 | | ViewCreated, |
141 | | VisAreaChanged, |
142 | | // SW events |
143 | | SwMailMerge, |
144 | | SwMailMergeEnd, |
145 | | SwEventPageCount, |
146 | | SwEventFieldMerge, |
147 | | SwEventFieldMergeFinished, |
148 | | SwEventLayoutFinished, |
149 | | }; |
150 | | |
151 | | template< typename charT, typename traits > |
152 | | inline std::basic_ostream<charT, traits> & operator <<( |
153 | | std::basic_ostream<charT, traits> & stream, const SfxEventHintId& id ) |
154 | | { |
155 | | switch(id) |
156 | | { |
157 | | case SfxEventHintId::NONE: return stream << "NONE"; |
158 | | case SfxEventHintId::ActivateDoc: return stream << "ActivateDoc"; |
159 | | case SfxEventHintId::CloseDoc: return stream << "CloseDoc"; |
160 | | case SfxEventHintId::CloseView: return stream << "CloseView"; |
161 | | case SfxEventHintId::CreateDoc: return stream << "CreateDoc"; |
162 | | case SfxEventHintId::DeactivateDoc: return stream << "DeactivateDoc"; |
163 | | case SfxEventHintId::DocCreated: return stream << "DocCreated"; |
164 | | case SfxEventHintId::LoadFinished: return stream << "LoadFinished"; |
165 | | case SfxEventHintId::ModifyChanged: return stream << "ModifyChanged"; |
166 | | case SfxEventHintId::OpenDoc: return stream << "OpenDoc"; |
167 | | case SfxEventHintId::PrepareCloseDoc: return stream << "PrepareCloseDoc"; |
168 | | case SfxEventHintId::PrepareCloseView: return stream << "PrepareCloseView"; |
169 | | case SfxEventHintId::PrintDoc: return stream << "PrintDoc"; |
170 | | case SfxEventHintId::SaveAsDoc: return stream << "SaveAsDoc"; |
171 | | case SfxEventHintId::SaveAsDocDone: return stream << "SaveAsDocDone"; |
172 | | case SfxEventHintId::SaveAsDocFailed: return stream << "SaveAsDocFailed"; |
173 | | case SfxEventHintId::SaveDoc: return stream << "SaveDoc"; |
174 | | case SfxEventHintId::SaveDocDone: return stream << "SaveDocDone"; |
175 | | case SfxEventHintId::SaveDocFailed: return stream << "SaveDocFailed"; |
176 | | case SfxEventHintId::SaveToDoc: return stream << "SaveToDoc"; |
177 | | case SfxEventHintId::SaveToDocDone: return stream << "SaveToDocDone"; |
178 | | case SfxEventHintId::SaveToDocFailed: return stream << "SaveToDocFailed"; |
179 | | case SfxEventHintId::StorageChanged: return stream << "StorageChanged"; |
180 | | case SfxEventHintId::ViewCreated: return stream << "ViewCreated"; |
181 | | case SfxEventHintId::VisAreaChanged: return stream << "VisAreaChanged"; |
182 | | case SfxEventHintId::SwMailMerge: return stream << "SwMailMerge"; |
183 | | case SfxEventHintId::SwMailMergeEnd: return stream << "SwMailMergeEnd"; |
184 | | case SfxEventHintId::SwEventPageCount: return stream << "SwEventPageCount"; |
185 | | case SfxEventHintId::SwEventFieldMerge: return stream << "SwEventFieldMerge"; |
186 | | case SfxEventHintId::SwEventFieldMergeFinished: return stream << "SwEventFieldMergeFinished"; |
187 | | case SfxEventHintId::SwEventLayoutFinished: return stream << "SwEventLayoutFinished"; |
188 | | default: return stream << "unk(" << std::to_string(int(id)) << ")"; |
189 | | } |
190 | | } |
191 | | |
192 | | class SFX2_DLLPUBLIC SfxEventHint : public SfxHint |
193 | | { |
194 | | unotools::WeakReference<SfxObjectShell> pObjShell; |
195 | | OUString aEventName; |
196 | | SfxEventHintId nEventId; |
197 | | |
198 | | public: |
199 | | SfxEventHint(SfxEventHintId nId, OUString aName, SfxObjectShell *pObj) |
200 | 347k | : SfxHint(SfxHintId::ThisIsAnSfxEventHint) |
201 | 347k | , pObjShell(pObj) |
202 | 347k | , aEventName(std::move(aName)) |
203 | 347k | , nEventId(nId) |
204 | 347k | { |
205 | 347k | } |
206 | | |
207 | | SfxEventHintId GetEventId() const |
208 | 481k | { return nEventId; } |
209 | | |
210 | | const OUString& GetEventName() const |
211 | 114k | { return aEventName; } |
212 | | |
213 | 367k | rtl::Reference<SfxObjectShell> GetObjShell() const { return pObjShell.get(); } |
214 | | }; |
215 | | |
216 | | |
217 | | class SFX2_DLLPUBLIC SfxViewEventHint : public SfxEventHint |
218 | | { |
219 | | css::uno::Reference< css::frame::XController2 > xViewController; |
220 | | |
221 | | public: |
222 | | SfxViewEventHint( SfxEventHintId nId, const OUString& aName, SfxObjectShell *pObj, const css::uno::Reference< css::frame::XController >& xController ) |
223 | 7.87k | : SfxEventHint( nId, aName, pObj ) |
224 | 7.87k | , xViewController( xController, css::uno::UNO_QUERY ) |
225 | 7.87k | {} |
226 | | |
227 | | SfxViewEventHint( SfxEventHintId nId, const OUString& aName, SfxObjectShell *pObj, css::uno::Reference< css::frame::XController2 > xController ) |
228 | 7.87k | : SfxEventHint( nId, aName, pObj ) |
229 | 7.87k | , xViewController(std::move( xController )) |
230 | 7.87k | {} |
231 | | |
232 | | const css::uno::Reference< css::frame::XController2 >& GetController() const |
233 | 15.7k | { return xViewController; } |
234 | | }; |
235 | | |
236 | | class SfxPrintingHint final : public SfxViewEventHint |
237 | | { |
238 | | css::view::PrintableState mnPrintableState; |
239 | | css::uno::Sequence < css::beans::PropertyValue > aOpts; |
240 | | public: |
241 | | SfxPrintingHint( |
242 | | css::view::PrintableState nState, |
243 | | const css::uno::Sequence < css::beans::PropertyValue >& rOpts, |
244 | | SfxObjectShell *pObj, |
245 | | const css::uno::Reference< css::frame::XController2 >& xController ) |
246 | 0 | : SfxViewEventHint( |
247 | 0 | SfxEventHintId::PrintDoc, |
248 | 0 | GlobalEventConfig::GetEventName( GlobalEventId::PRINTDOC ), |
249 | 0 | pObj, |
250 | 0 | xController ) |
251 | 0 | , mnPrintableState( nState ) |
252 | 0 | , aOpts( rOpts ) |
253 | 0 | {} |
254 | | |
255 | | SfxPrintingHint( css::view::PrintableState nState ) |
256 | 0 | : SfxViewEventHint( |
257 | 0 | SfxEventHintId::PrintDoc, |
258 | 0 | GlobalEventConfig::GetEventName( GlobalEventId::PRINTDOC ), |
259 | 0 | nullptr, |
260 | 0 | css::uno::Reference< css::frame::XController >() ) |
261 | 0 | , mnPrintableState( nState ) |
262 | 0 | {} |
263 | | |
264 | 0 | css::view::PrintableState GetWhich() const { return mnPrintableState; } |
265 | 0 | const css::uno::Sequence < css::beans::PropertyValue >& GetOptions() const { return aOpts; } |
266 | | }; |
267 | | |
268 | | #endif |
269 | | |
270 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |