HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_PostIt.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP_PostIt.h (OP Library, C++)
7  *
8  * COMMENTS: Defines post it notes.
9  *
10  */
11 
12 #ifndef __OP_PostIt__
13 #define __OP_PostIt__
14 
15 #include "OP_API.h"
16 #include "OP_Error.h"
17 #include "OP_ItemId.h"
18 #include "OP_NetworkBoxItem.h"
19 #include "OP_PostItNoteFlags.h"
20 #include "OP_Stat.h"
21 
22 #include <UT/UT_Color.h>
23 #include <UT/UT_ErrorManager.h>
24 #include <UT/UT_String.h>
25 #include <SYS/SYS_Types.h>
26 
27 #include <iosfwd>
28 
29 
30 class OP_Network;
31 class OP_SaveFlags;
32 class UT_IStream;
33 class UT_WorkBuffer;
34 
35 
36 #define OP_POSTIT_DEFAULT_W 2.5F
37 #define OP_POSTIT_DEFAULT_H 2.5F
38 #define OP_POSTIT_MINIMUM_W 0.3F
39 #define OP_POSTIT_MINIMUM_H 0.3F
40 #define OP_POSTIT_MINIMIZED_W 2.5F
41 
43 {
44 public:
45  /// Create a network box with the specified name. If a duplicate name is
46  /// passed in, it will be altered to make it unique in the network.
47  OP_PostIt(const UT_String &name, OP_Network *net);
48  ~OP_PostIt() override;
49 
50  void setXY(fpreal x, fpreal y) override;
51  fpreal getX() const override;
52  fpreal getY() const override;
53  fpreal getW() const override;
54  fpreal getH() const override;
55  fpreal getMaximizedW() const;
56  fpreal getMaximizedH() const;
57 
58  bool setWWithBoundsChecks(fpreal h);
59  bool setHWithBoundsChecks(fpreal h);
60 
61  const OP_PostItNoteFlags &flags() const { return myFlags; }
62  OP_PostItNoteFlags &flags() { return myFlags; }
63 
64 
65  /// Returns true if this box is currently picked
66  bool getPicked() const override;
67 
68  /// Set whether this box is picked; returns true if the picked
69  /// status has changed.
70  bool setPicked(
71  bool on_off,
72  bool propagate_parent_event = true
73  ) override;
74 
75  /// Each netbox has a unique id. This is used primarily for undos, as we
76  /// also keep a list of notes in order of id, so lookup by id becomes
77  /// quite quick.
78  static OP_PostIt *lookupPostItNote(int unique_id);
79  int getUniqueId() const
80  { return myUniqueId; }
81  int64 getItemUniqueId() const override
82  { return myUniqueId; }
83 
84  /// The name which is used for identification and in displays of this
85  /// box. setName() returns true if the name change was successful, and
86  /// alters the name slightly if necessary to make it unique within this
87  /// network.
88  bool setName(const UT_String &name);
89  const UT_String &getItemName() const override
90  { return myName; };
91  bool setItemName(const UT_String &name) override
92  { return setName(name); }
93 
94  bool setText(const UT_String &text);
95  virtual const UT_String &getText() const
96  { return myText; };
97 
98  bool setTextSize(fpreal size);
100  { return myTextSize; }
101 
102  bool setTextColor(const UT_Color &clr);
103  const UT_Color &getTextColor() const
104  { return myTextColor; }
105 
106  bool setDrawBackground(bool draw_background);
107  bool getDrawBackground() const
108  { return flags().getDrawBackground(); }
109 
110  OP_ItemType getItemType() const override;
111  OP_Network *getParentNetwork() const override;
112 
113  /// Get and set the width and height of this box. Units are absolute
114  /// as opposed to the relative units found in OPUI.
115  /// If the width or height specified is smaller than that which will
116  /// contain all of the items, the width or height respectively will only
117  /// be adjusted to the minimum size required to contain the items. To avoid
118  /// this automatic size check, set 'force' to true.
119  void setW(fpreal w, bool force = false);
120  void setH(fpreal h, bool force = false);
121 
122  /// Calculate the smallest bounds we're willing to accept as our size
123  /// given our contents. By default, 'incl_buff_border' is set to add a small
124  /// buffer border to make the layout look pretty. NOTE: If we contain no
125  /// items, we return an inverted bounding box, see implementation for
126  /// further details.
127  void getItemBounds(fpreal &x1, fpreal &y1, fpreal &x2,
128  fpreal &y2, bool incl_buff_border = true)
129  const;
130 
131  /// ALWAYS call this with 'resizing' == true before you do any resizing
132  /// operations (e.g. setW()), and call it after you're done resizing with
133  /// 'resizing' == false. You should only do this once for each group of
134  /// resizing operations on the same netbox.
135  ///
136  /// This method:
137  /// 1) ensures we get a proper undo block around all the resize ops, and
138  /// 2) allows you to use setXY() to stretch the box to the left (otherwise,
139  /// setXY() just moves the box)
140  void setResizing(bool resizing);
141  bool getResizing();
142 
143  /// Same as setXY(), but here we can force the box to take on these X/Y
144  /// coordinates, even if our contents don't fit us any more. The
145  /// propagate_parent_event tells this method whether or not it should send
146  /// and event after moving the network box -- this should normally be set
147  /// to true.
148  void setXY(fpreal x, fpreal y,
149  bool force,
150  bool propagate_parent_event);
151 
152  virtual OP_ERROR save(std::ostream &os,
153  const OP_SaveFlags &sflags,
154  const char *path_prefix);
155  virtual OP_ERROR saveIntrinsic(std::ostream &os,
156  const OP_SaveFlags &sflags);
157 
158  /// Load the contents of the stream into the attributes of this post-it
159  /// note; if binary is nonzero, load in binary mode.
160  /// Loading doesn't send the OP_POSTIT_NOTE_CREATED message to the network;
161  /// the caller is responsible for doing that.
162  virtual bool load(UT_IStream &is,
163  const char *ext="",
164  const char *path=0);
165 
166  void getFullPath(UT_String &str) const;
167  void getFullPath(UT_WorkBuffer &str) const;
168 
169  /// Get whether this box is currently minimized
170  bool getMinimized() const;
171 
172  /// Set whether this box is currently minimized
173  /// If update_position is true, then the box is moved to accomodate the
174  /// minimized status. If propagate_parent_event is true, an event is sent
175  /// to the network about our minimized state.
176  bool setMinimized(bool isminimized,
177  bool update_position,
178  bool propagate_parent_event);
179 
180  /// Used by opscript, this outputs the sequence of hscript commands
181  /// necessary to recreate this sticky note.
182  int saveCommand(std::ostream &os) const;
183 
184  /// Returns the amount of memory owned by this OP_PostIt
185  int64 getMemoryUsage(bool inclusive) const;
186 
187  /// Control the default color used on new post it notes.
188  static const UT_Color &defaultColor();
189  static void setDefaultColor(const UT_Color *color);
190  static const UT_Color &defaultTextColor();
191  static void setDefaultTextColor(const UT_Color *color);
192 
193 private:
194  /// This should only be called by our loading mechanism while we load, right
195  /// after we get created!
196  void setUniqueId(int id);
197 
198  OP_ERROR saveIntrinsicError();
199  OP_ERROR saveError();
200  OP_ERROR error() const
201  { return UTgetErrorSeverity(); }
202 
203  bool loadPostItFlags(UT_IStream &is, const char *path);
204  bool loadNetworkBox(UT_IStream &is, const char *path);
205  bool loadIntrinsic(UT_IStream &is, const char *path);
206  virtual bool loadPacket(UT_IStream &is, short class_id,
207  short signature, const char *path = 0);
208  virtual bool loadPacket(UT_IStream &is, const char *token,
209  const char *path=0);
210 
211  OP_ERROR saveNetworkBox(std::ostream &os,
212  const OP_SaveFlags &sflags,
213  const char *path_prefix);
214 
215  friend class OP_Network;
216 
217 private:
218  // Note that although netboxes share their namespace with nodes, they do not
219  // share their "ID space".
220  int myUniqueId;
221  OP_Network *myNetwork;
222 
223  UT_String myName;
224  UT_String myText;
225  fpreal myTextSize;
226  UT_Color myTextColor;
227 
228  /// Keeps info like timestamps for last modification time, creation time,
229  /// etc
231 
232  /// ALWAYS set these through accessors to ensure proper undo creation
233  fpreal myX, myY;
234  fpreal myW, myH;
235 
236  OP_PostItNoteFlags myFlags;
237 };
238 
239 #endif
GLbitfield flags
Definition: glcorearb.h:1596
int getUniqueId() const
Definition: OP_PostIt.h:79
virtual OP_ItemType getItemType() const =0
Our children should implement this and return what type of item they are.
int64 getMemoryUsage(bool inclusive) const
bool setItemName(const UT_String &name) override
Definition: OP_PostIt.h:91
const OP_PostItNoteFlags & flags() const
Definition: OP_PostIt.h:61
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
virtual void setXY(fpreal x, fpreal y)=0
virtual fpreal getY() const =0
UT_ErrorSeverity
Definition: UT_Error.h:25
virtual fpreal getX() const =0
GLint y
Definition: glcorearb.h:103
virtual OP_Network * getParentNetwork() const =0
Returns the network that is our parent.
GLdouble GLdouble x2
Definition: glad.h:2349
virtual bool setPicked(bool on_off, bool propagate_parent_event=true)=0
< returns > If no error
Definition: snippets.dox:2
UT_API UT_ErrorSeverity UTgetErrorSeverity()
OP_ItemType
Definition: OP_ItemId.h:28
virtual fpreal getW() const =0
int64 getItemUniqueId() const override
Functions to get hip-file-unique ids for any item type.
Definition: OP_PostIt.h:81
const UT_Color & getTextColor() const
Definition: OP_PostIt.h:103
GLdouble y1
Definition: glad.h:2349
long long int64
Definition: SYS_Types.h:116
GLuint const GLchar * name
Definition: glcorearb.h:786
GLint GLenum GLint x
Definition: glcorearb.h:409
GLsizeiptr size
Definition: glcorearb.h:664
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
fpreal getTextSize() const
Definition: OP_PostIt.h:99
OP_PostItNoteFlags & flags()
Definition: OP_PostIt.h:62
SIM_API const UT_StringHolder force
GLuint color
Definition: glcorearb.h:1261
bool getDrawBackground() const
Definition: OP_PostIt.h:107
fpreal64 fpreal
Definition: SYS_Types.h:277
#define OP_API
Definition: OP_API.h:10
virtual bool getPicked() const =0
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
virtual fpreal getH() const =0
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
virtual const UT_String & getText() const
Definition: OP_PostIt.h:95
Definition: OP_PostIt.h:42
const UT_String & getItemName() const override
Definition: OP_PostIt.h:89