InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ISelectionMessages.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Michael Martz
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // Note: This is not intended as an interface header. These are abstract C++ classes
24 // which are used to communicate information from subjects to observers within the
25 // selection architecture.
26 //
27 //========================================================================================
28 
29 #ifndef _ISelectionMessages_
30 #define _ISelectionMessages_
31 
32 //________________________________________________________________________________________________
33 // INCLUDES
34 //________________________________________________________________________________________________
35  //.......Interface headers....................................................................
36  #include "IPMUnknown.h" // for the definition of
37 
38  //.......Other headers........................................................................
39  #include "K2SmartPtr.h"
40  #include "K2Vector.h"
41  #include "KeyValuePair.h"
42  #include "TableTypes.h"
43 //________________________________________________________________________________________________
44 // CLASS FORWARDS
45 //________________________________________________________________________________________________
46  class ISubject;
47  class SelectionSuiteData;
48  class UIDList;
49  class ITableModel;
50  class XMLReference;
52  namespace InDesign { class TextRange;}
53  class RangeData;
54  class ITextSelectionSuite;
55 //________________________________________________________________________________________________
56 // TYPEDEFS
57 //________________________________________________________________________________________________
59 
60  namespace Selection
61  {
62  enum Action { kReplace, kAddTo, kRemoveFrom, kSetKeyObject };
63  enum ScrollChoice { kDontScrollSelection, kScrollIntoView};
64  enum LayoutScrollChoice { kDontScrollLayoutSelection, kScrollIntoViewIfNecessary, kAlwaysCenterInView };
65  }
66 
67 
68 //________________________________________________________________________________________________
69 // COMPILER DIRECTIVES
70 //________________________________________________________________________________________________
71  #ifdef PUBLIC_BUILD
72 #endif // PUBLIC_BUILD
73 //================================================================================================
74 //________________________________________________________________________________________________
75 // CLASS DECLARATIONS
76 //________________________________________________________________________________________________
81  {
82  //____________________________________________________________________________________________
83  // Data Types
84  //____________________________________________________________________________________________
85  public:
86  enum SelectionMessageType { kClientMessage, kASB_SuiteMessage, kSelectionChanged, kCSB_NeedsNotify };
87 
88  public:
89  virtual ~IInternalSelectionMessage (void) {}
93  virtual SelectionMessageType GetMessageType (void) const = 0;
94 
100  virtual PMIID GetASB_SuiteIID (void) const = 0;
101 
107  virtual void* GetMessage (void) const = 0;
108 
112  virtual ClassID GetCSB_ClassID (void) const = 0;
113 
114  };
115 
121  {
122  public:
123  typedef object_type data_type;
124  virtual ~SelectionSuiteData (void);
125  };
132  {
133  //____________________________________________________________________________________________
134  // Data Types
135  //____________________________________________________________________________________________
136  public:
137  virtual ~ISelectionMessage (void) {}
138  /*
139  ISelectionMessage had no explicit destructor, so the compiler created an empty **non-virtual** destructor for it.
140  The derived class SelectionMessage had a virtual destructor that deleted it's member suiteBroadcastData. This set up a nasty bug.
141  If a SelectionMessage was deleted through a ISelectionMessage pointer the empty non-virtual destructor was called and the suiteBroadcastData
142  was not freed. Sadly downstream code relied on it *not* being deleted.
143 
144  Apple's clang compiler warns about deleting an object with a non virtual destructor, so I tried to fix the compiler warning by giving ISelectionMessage
145  a virtual destructor, but then we started crashing in downstream code since the suiteBroadcastData was now being deleted.
146 
147  As far as I could tell, the SelectionMessage destructor was *never* called. In our codebase SelectionMessage instances are always allocated via operator new, are held
148  via an ISelectionMessage pointer and are deleted through that pointer.
149  Allocation ony happens in SelectionManager.cpp, CConcreteSelection.cpp, and Default_CSB.cpp.
150 
151  As a result. I could work around this problem by declaring that SelectionMessage only holds a reference to the member suiteBroadcastData, rather than owning it.
152  Then I could add the missing virtual destructor to ISelectionMessage, make an empty destructor for SelectionMessage, and keep the compiler and downstream code happy.
153 
154  We really shouldnt be passing a naked ptr type for suiteBroadcastData through so many layers of code, with no clear indication (or an incorrect one) of who is responsible for deleting it.
155  Allocations like this should be wrapped in a boost::shared_ptr<ISelectionMessage> and then passed as a shared_ptr rather than passing the raw pointer.
156  Practically though even fixing this one case is hard to retrofit into something as big as InDesign, and well beyond the scope of my clang compiler warnings task.
157 
158  In fact none of the abstract message classes in this file had declared virtual destructors, so I added one to each of them.
159  Thankfully this was the only one where a derived instance was being deleted through a pointer to the abstract baseclass.
160 
161  --djb 6/17/2012
162  */
163 
164  enum SelectionMessageType { kSelectionChanged, kSelectionAttributeChanged, kSelectionChanged_Frequent};
165 
166  public:
170  virtual SelectionMessageType GetMessageType (void) const = 0;
171 
179  virtual bool16 WasSuiteAffected (const PMIID&) const = 0;
180 
188  virtual SelectionSuiteData* GetSuiteBroadcastData (const PMIID&) const = 0;
189 
198  virtual SuiteBroadcastData* GetSuiteBroadcastDataList (void) = 0;
199  };
200 
205  {
206  public:
207  virtual ~ISelectionHighlightMessage (void) {}
211  virtual ClassID GetCSB (void) const = 0;
212 
216  virtual void* GetMessage (void) const = 0;
217  };
218 
223  {
224  public:
225  virtual ~ILayoutSelectionHighlightMessage (void) {}
229  virtual UIDList GetItemsToRemove (void) const = 0;
230 
234  virtual UIDList GetItemsToAdd (void) const = 0;
235 
239  virtual bool16 IsPathSelection (void) const = 0;
240 
244  virtual Selection::LayoutScrollChoice GetAutoScroll (void) const = 0;
245  };
246 
247 
252  {//SpreadSelectionSuite
253  public:
254  enum SpreadSelectionMessageType { kSelectionChanged, kKeyObjectChanged };
255 
256  public:
257  virtual ~ISpreadSelectionHighlightMessage (void) {}
261  virtual UIDList GetItemsToRemove (void) const = 0;
262 
266  virtual UIDList GetItemsToAdd (void) const = 0;
267 
271  virtual Selection::LayoutScrollChoice GetAutoScroll (void) const = 0;
272 
273 
277  virtual SpreadSelectionMessageType GetMessageType(void) const = 0;
278  };
279 
280 
285  {
286  public:
287  SelectionExtension() : fLeftExtension(kInvalidUID), fRightExtension(kInvalidUID) { }
288  SelectionExtension (UID leftExtension, UID rightExtension) { SetExtension (leftExtension, rightExtension); }
289 
290 
294  inline void SetExtension (UID leftExtension, UID rightExtension) { fLeftExtension = leftExtension; fRightExtension = rightExtension; }
295 
299  inline UID GetLeftExtension () const { return fLeftExtension; }
303  inline UID GetRightExtension () const { return fRightExtension; }
304 
305  private:
306  UID fLeftExtension;
307  UID fRightExtension;
308  };
309 
314  {
315  public:
316  virtual ~ITextSelectionHighlightMessage (void) {}
320  virtual InDesign::TextRange GetOldRange (void) const = 0;
321 
325  virtual InDesign::TextRange GetNewRange (void) const = 0;
326 
327 
328  enum ScrollChoice { kDontScrollSelection, kScrollIntoView};
332  virtual ScrollChoice GetAutoScroll( RangeData* ) const = 0;
333 
337  virtual ITextSelectionSuite* GetSelection(void) const = 0;
338 
342  virtual SelectionExtension GetOldSelectionExtension() const = 0;
346  virtual SelectionExtension GeNewSelectionExtension() const = 0;
347  };
348 
355  {
356  public:
357  virtual ~ITableSelectionHighlightMessage (void) {}
362  virtual const ITableModel* GetPrevTableModel (void) const = 0;
367  virtual const GridArea GetPrevSelectedCells (void) const = 0;
368 
373  virtual const ITableModel* GetNewTableModel (void) const = 0;
378  virtual const GridArea GetNewSelectedCells (void) const = 0;
379  };
380 
385  {
386  public:
387  virtual ~IXMLSelectionHighlightMessage (void) {}
391  virtual const K2Vector<XMLReference>* GetElementsToAdd (void) const = 0;
395  virtual const K2Vector<XMLReference>* GetElementsToRemove (void) const = 0;
396 
400  virtual const K2Vector<XMLAttributeReference>* GetAttributesToAdd (void) const = 0;
404  virtual const K2Vector<XMLAttributeReference>* GetAttributesToRemove (void) const = 0;
405 
406  };
407 
412  {
413  //____________________________________________________________________________________________
414  // Data Types
415  //____________________________________________________________________________________________
416  public:
417  enum MessageType { kActiveCSBsChangedMessage };
418 
419  public:
420  virtual ~ISelectionChangedISuiteMessage (void) {}
424  virtual MessageType GetMessageType (void) const = 0;
425 
431  virtual const K2Vector<KeyValuePair<ClassID, bool16> >* GetEnabledCSBs (void) const = 0;
432 
437  virtual const K2Vector<PMIID>* GetEnabledSuiteInterfaces (void) const = 0;
438  };
439 
440 
441 #endif // _ISelectionMessages_