LibreOffice Module sw (master)  1
swevent.hxx
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 #ifndef INCLUDED_SW_INC_SWEVENT_HXX
21 #define INCLUDED_SW_INC_SWEVENT_HXX
22 
23 #include "calbck.hxx"
24 #include "frmfmt.hxx"
25 #include "hints.hxx"
26 
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
40 
41 class SwFormatINetFormat;
42 class IMapObject;
43 
44 // Enum for objects that call events into Basic or JavaScript.
46 {
47  EVENT_OBJECT_NONE = 0, // Null is nothing at all.
52 };
53 
54 // Structure for the exchange between UI/CORE.
55 
56 struct SwCallMouseEvent final
57  : public SwClient
58 {
60  union
61  {
62  // EVENT_OBJECT_IMAGE/EVENT_OBJECT_URLITEM
64 
65  // EVENT_OBJECT_INETATTR
67 
68  // EVENT_OBJECT_IMAGEMAP
69  struct
70  {
71  const SwFrameFormat* pFormat;
73  } IMAP;
74  } PTR;
75 
77  : eType( EVENT_OBJECT_NONE )
78  { PTR.pFormat = nullptr; PTR.IMAP.pIMapObj = nullptr; }
79 
82  , eType(rOther.eType)
83  {
84  memcpy(&PTR, &rOther.PTR, sizeof(PTR));
85  }
86 
88  { Clear(); eType = eTyp; PTR.pFormat = pFormat; PTR.IMAP.pIMapObj = nullptr; assert(pFormat); const_cast<SwFrameFormat*>(pFormat)->Add(this); }
89 
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); }
92 
94  { Clear(); eType = EVENT_OBJECT_INETATTR; PTR.pINetAttr = pINetAttr; PTR.IMAP.pIMapObj = nullptr; }
95 
96  bool operator==( const SwCallMouseEvent& rEvent ) const
97  {
98  return eType == rEvent.eType &&
99  PTR.pFormat == rEvent.PTR.pFormat &&
100  PTR.IMAP.pIMapObj == rEvent.PTR.IMAP.pIMapObj;
101  }
102  bool operator!=( const SwCallMouseEvent& rEvent ) const
103  { return !( *this == rEvent ); }
104 
105  void Clear()
106  {
107  if (EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType)
108  {
109  // note: pFormat is not necessarily the same as
110  // GetRegisteredIn() here; see ~SwFormat()
111  assert(PTR.pFormat);
112  EndListeningAll();
113  }
114  eType = EVENT_OBJECT_NONE; PTR.pFormat = nullptr; PTR.IMAP.pIMapObj = nullptr;
115  }
116 
117  bool HasEvent() const { return EVENT_OBJECT_NONE != eType; }
118 
119  virtual void Modify(SfxPoolItem const*const pOldValue, SfxPoolItem const*const pNewValue) override
120  {
121  assert(EVENT_OBJECT_IMAGE == eType || EVENT_OBJECT_URLITEM == eType || EVENT_OBJECT_IMAGEMAP == eType);
122  SwClient::Modify(pOldValue, pNewValue);
123  if (!GetRegisteredIn()
124  || (RES_FMT_CHG == pOldValue->Which()
125  && static_cast<SwFormatChg const*>(pOldValue)->pChangedFormat == PTR.pFormat)
126  || (RES_REMOVE_UNO_OBJECT == pOldValue->Which()
127  && static_cast<SwPtrMsgPoolItem const*>(pOldValue)->pObject == PTR.pFormat))
128  {
129  Clear();
130  }
131  }
132 };
133 
134 #endif
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Modify(SfxPoolItem const *const pOldValue, SfxPoolItem const *const pNewValue) override
Definition: swevent.hxx:119
const IMapObject * pIMapObj
Definition: swevent.hxx:72
#define RES_REMOVE_UNO_OBJECT
Definition: hintids.hxx:305
bool operator!=(const SwCallMouseEvent &rEvent) const
Definition: swevent.hxx:102
void EndListeningAll()
Definition: calbck.cxx:124
const SwFrameFormat * pFormat
Definition: swevent.hxx:63
SwCallEventObjectType eType
Definition: swevent.hxx:59
Style of a layout element.
Definition: frmfmt.hxx:57
union SwCallMouseEvent::@28 PTR
bool HasEvent() const
Definition: swevent.hxx:117
SwCallMouseEvent(SwCallMouseEvent const &rOther)
Definition: swevent.hxx:80
#define RES_FMT_CHG
Definition: hintids.hxx:286
void Set(SwCallEventObjectType eTyp, const SwFrameFormat *pFormat)
Definition: swevent.hxx:87
struct SwCallMouseEvent::@28::@29 IMAP
SwCallEventObjectType
Definition: swevent.hxx:45
void Set(const SwFormatINetFormat *pINetAttr)
Definition: swevent.hxx:93
bool operator==(const SwCallMouseEvent &rEvent) const
Definition: swevent.hxx:96
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:157
void Set(const SwFrameFormat *pFormat, const IMapObject *pIMapObj)
Definition: swevent.hxx:90
SwModify * GetRegisteredInNonConst() const
Definition: calbck.hxx:134
const SwFormatINetFormat * pINetAttr
Definition: swevent.hxx:66
sal_uInt16 Which() const
virtual void Modify(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:130