Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / inc / swevent.hxx
blobb25246cb2e12565efa126d592a06de009fbf5bf8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SW_INC_SWEVENT_HXX
21 #define INCLUDED_SW_INC_SWEVENT_HXX
23 #include "calbck.hxx"
24 #include "frmfmt.hxx"
25 #include "hints.hxx"
27 #define STR_SW_EVENT_PAGE_COUNT 0
28 #define STR_SW_EVENT_MAIL_MERGE 1
29 #define STR_SW_EVENT_MAIL_MERGE_END 2
30 #define STR_SW_EVENT_FIELD_MERGE 3
31 #define STR_SW_EVENT_FIELD_MERGE_FINISHED 4
32 #define STR_SW_EVENT_LAYOUT_FINISHED 5
33 #define STR_SW_EVENT_OBJECT_SELECT 6
34 #define STR_SW_EVENT_START_INS_GLOSSARY 7
35 #define STR_SW_EVENT_END_INS_GLOSSARY 8
36 #define STR_SW_EVENT_FRM_KEYINPUT_ALPHA 9
37 #define STR_SW_EVENT_FRM_KEYINPUT_NOALPHA 10
38 #define STR_SW_EVENT_FRM_RESIZE 11
39 #define STR_SW_EVENT_FRM_MOVE 12
41 class SwFormatINetFormat;
42 class IMapObject;
44 // Enum for objects that call events into Basic or JavaScript.
45 enum SwCallEventObjectType
47 EVENT_OBJECT_NONE = 0, // Null is nothing at all.
48 EVENT_OBJECT_IMAGE,
49 EVENT_OBJECT_INETATTR,
50 EVENT_OBJECT_URLITEM,
51 EVENT_OBJECT_IMAGEMAP
54 // Structure for the exchange between UI/CORE.
56 struct SwCallMouseEvent final
57 : public SwClient
59 SwCallEventObjectType eType;
60 union
62 // EVENT_OBJECT_IMAGE/EVENT_OBJECT_URLITEM
63 const SwFrameFormat* pFormat;
65 // EVENT_OBJECT_INETATTR
66 const SwFormatINetFormat* pINetAttr;
68 // EVENT_OBJECT_IMAGEMAP
69 struct
71 const SwFrameFormat* pFormat;
72 const IMapObject* pIMapObj;
73 } IMAP;
74 } PTR;
76 SwCallMouseEvent()
77 : eType( EVENT_OBJECT_NONE )
78 { PTR.pFormat = nullptr; PTR.IMAP.pIMapObj = nullptr; }
80 SwCallMouseEvent(SwCallMouseEvent const& rOther)
81 : SwClient(rOther.GetRegisteredInNonConst())
82 , eType(rOther.eType)
84 memcpy(&PTR, &rOther.PTR, sizeof(PTR));
87 void Set( SwCallEventObjectType eTyp, const SwFrameFormat* pFormat )
88 { Clear(); eType = eTyp; PTR.pFormat = pFormat; PTR.IMAP.pIMapObj = nullptr; assert(pFormat); const_cast<SwFrameFormat*>(pFormat)->Add(this); }
90 void Set( const SwFrameFormat* pFormat, const IMapObject* pIMapObj )
91 { Clear(); eType = EVENT_OBJECT_IMAGEMAP; PTR.pFormat = pFormat; PTR.IMAP.pIMapObj = pIMapObj; assert(pFormat); const_cast<SwFrameFormat*>(pFormat)->Add(this); }
93 void Set( const SwFormatINetFormat* pINetAttr )
94 { Clear(); eType = EVENT_OBJECT_INETATTR; PTR.pINetAttr = pINetAttr; PTR.IMAP.pIMapObj = nullptr; }
96 bool operator==( const SwCallMouseEvent& rEvent ) const
98 return eType == rEvent.eType &&
99 PTR.pFormat == rEvent.PTR.pFormat &&
100 PTR.IMAP.pIMapObj == rEvent.PTR.IMAP.pIMapObj;
102 bool operator!=( const SwCallMouseEvent& rEvent ) const
103 { return !( *this == rEvent ); }
105 void Clear()
107 if (EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType)
109 // note: pFormat is not necessarily the same as
110 // GetRegisteredIn() here; see ~SwFormat()
111 assert(PTR.pFormat);
112 EndListeningAll();
114 eType = EVENT_OBJECT_NONE; PTR.pFormat = nullptr; PTR.IMAP.pIMapObj = nullptr;
117 bool HasEvent() const { return EVENT_OBJECT_NONE != eType; }
119 virtual void SwClientNotify(const SwModify& rMod, const SfxHint& rHint) override
121 if (rHint.GetId() != SfxHintId::SwLegacyModify)
122 return;
123 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
124 assert(EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType);
125 SwClient::SwClientNotify(rMod, rHint);
126 bool bClear = !GetRegisteredIn();
127 switch(pLegacy->GetWhich())
129 case RES_FMT_CHG:
130 bClear |= pLegacy->m_pOld->StaticWhichCast(RES_FMT_CHG).pChangedFormat == PTR.pFormat;
131 break;
132 case RES_REMOVE_UNO_OBJECT:
133 bClear |= pLegacy->m_pOld->StaticWhichCast(RES_REMOVE_UNO_OBJECT).pObject == PTR.pFormat;
135 if(bClear)
136 Clear();
140 #endif
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */