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  virtual ~OP_PostIt();
49 
50  virtual void setXY(fpreal x, fpreal y);
51  virtual fpreal getX() const;
52  virtual fpreal getY() const;
53  virtual fpreal getW() const;
54  virtual fpreal getH() const;
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  virtual int getPicked() const;
67 
68  /// Set whether this box is picked; returns true if the picked
69  /// status has changed.
70  virtual int setPicked(int on_off,
71  bool propagate_parent_event = true);
72 
73  /// Each netbox has a unique id. This is used primarily for undos, as we
74  /// also keep a list of notes in order of id, so lookup by id becomes
75  /// quite quick.
76  static OP_PostIt *lookupPostItNote(int unique_id);
77  int getUniqueId() const
78  { return myUniqueId; }
79  virtual int64 getItemUniqueId() const
80  { return myUniqueId; }
81 
82  /// The name which is used for identification and in displays of this
83  /// box. setName() returns true if the name change was successful, and
84  /// alters the name slightly if necessary to make it unique within this
85  /// network.
86  bool setName(const UT_String &name);
87  virtual const UT_String &getItemName() const
88  { return myName; };
89  virtual bool setItemName(const UT_String &name)
90  { return setName(name); }
91 
92  bool setText(const UT_String &text);
93  virtual const UT_String &getText() const
94  { return myText; };
95 
96  bool setTextSize(fpreal size);
98  { return myTextSize; }
99 
100  bool setTextColor(const UT_Color &clr);
101  const UT_Color &getTextColor() const
102  { return myTextColor; }
103 
104  bool setDrawBackground(bool draw_background);
105  bool getDrawBackground() const
106  { return flags().getDrawBackground(); }
107 
108  virtual OP_ItemType getItemType() const;
109  virtual OP_Network *getParentNetwork() const;
110 
111  /// Get and set the width and height of this box. Units are absolute
112  /// as opposed to the relative units found in OPUI.
113  /// If the width or height specified is smaller than that which will
114  /// contain all of the items, the width or height respectively will only
115  /// be adjusted to the minimum size required to contain the items. To avoid
116  /// this automatic size check, set 'force' to true.
117  void setW(fpreal w, bool force = false);
118  void setH(fpreal h, bool force = false);
119 
120  /// Calculate the smallest bounds we're willing to accept as our size
121  /// given our contents. By default, 'incl_buff_border' is set to add a small
122  /// buffer border to make the layout look pretty. NOTE: If we contain no
123  /// items, we return an inverted bounding box, see implementation for
124  /// further details.
125  void getItemBounds(fpreal &x1, fpreal &y1, fpreal &x2,
126  fpreal &y2, bool incl_buff_border = true)
127  const;
128 
129  /// ALWAYS call this with 'resizing' == true before you do any resizing
130  /// operations (e.g. setW()), and call it after you're done resizing with
131  /// 'resizing' == false. You should only do this once for each group of
132  /// resizing operations on the same netbox.
133  ///
134  /// This method:
135  /// 1) ensures we get a proper undo block around all the resize ops, and
136  /// 2) allows you to use setXY() to stretch the box to the left (otherwise,
137  /// setXY() just moves the box)
138  void setResizing(bool resizing);
139  bool getResizing();
140 
141  /// Same as setXY(), but here we can force the box to take on these X/Y
142  /// coordinates, even if our contents don't fit us any more. The
143  /// propagate_parent_event tells this method whether or not it should send
144  /// and event after moving the network box -- this should normally be set
145  /// to true.
146  void setXY(fpreal x, fpreal y,
147  bool force,
148  bool propagate_parent_event);
149 
150  virtual OP_ERROR save(std::ostream &os,
151  const OP_SaveFlags &sflags,
152  const char *path_prefix);
153  virtual OP_ERROR saveIntrinsic(std::ostream &os,
154  const OP_SaveFlags &sflags);
155 
156  /// Load the contents of the stream into the attributes of this post-it
157  /// note; if binary is nonzero, load in binary mode.
158  /// Loading doesn't send the OP_POSTIT_NOTE_CREATED message to the network;
159  /// the caller is responsible for doing that.
160  virtual bool load(UT_IStream &is,
161  const char *ext="",
162  const char *path=0);
163 
164  void getFullPath(UT_String &str) const;
165  void getFullPath(UT_WorkBuffer &str) const;
166 
167  /// Get whether this box is currently minimized
168  bool getMinimized() const;
169 
170  /// Set whether this box is currently minimized
171  /// If update_position is true, then the box is moved to accomodate the
172  /// minimized status. If propagate_parent_event is true, an event is sent
173  /// to the network about our minimized state.
174  bool setMinimized(bool isminimized,
175  bool update_position,
176  bool propagate_parent_event);
177 
178  /// Used by opscript, this outputs the sequence of hscript commands
179  /// necessary to recreate this sticky note.
180  int saveCommand(std::ostream &os) const;
181 
182  /// Returns the amount of memory owned by this OP_PostIt
183  int64 getMemoryUsage(bool inclusive) const;
184 
185  /// Control the default color used on new post it notes.
186  static const UT_Color &defaultColor();
187  static void setDefaultColor(const UT_Color *color);
188  static const UT_Color &defaultTextColor();
189  static void setDefaultTextColor(const UT_Color *color);
190 
191 private:
192  /// This should only be called by our loading mechanism while we load, right
193  /// after we get created!
194  void setUniqueId(int id);
195 
196  OP_ERROR saveIntrinsicError();
197  OP_ERROR saveError();
198  OP_ERROR error() const
199  { return UTgetErrorSeverity(); }
200 
201  bool loadPostItFlags(UT_IStream &is, const char *path);
202  bool loadNetworkBox(UT_IStream &is, const char *path);
203  bool loadIntrinsic(UT_IStream &is, const char *path);
204  virtual bool loadPacket(UT_IStream &is, short class_id,
205  short signature, const char *path = 0);
206  virtual bool loadPacket(UT_IStream &is, const char *token,
207  const char *path=0);
208 
209  OP_ERROR saveNetworkBox(std::ostream &os,
210  const OP_SaveFlags &sflags,
211  const char *path_prefix);
212 
213  friend class OP_Network;
214 
215 private:
216  // Note that although netboxes share their namespace with nodes, they do not
217  // share their "ID space".
218  int myUniqueId;
219  OP_Network *myNetwork;
220 
221  UT_String myName;
222  UT_String myText;
223  fpreal myTextSize;
224  UT_Color myTextColor;
225 
226  /// Keeps info like timestamps for last modification time, creation time,
227  /// etc
229 
230  /// ALWAYS set these through accessors to ensure proper undo creation
231  fpreal myX, myY;
232  fpreal myW, myH;
233 
234  OP_PostItNoteFlags myFlags;
235 };
236 
237 #endif
int getUniqueId() const
Definition: OP_PostIt.h:77
virtual bool setItemName(const UT_String &name)
Definition: OP_PostIt.h:89
virtual OP_ItemType getItemType() const =0
Our children should implement this and return what type of item they are.
int64 getMemoryUsage(bool inclusive) const
virtual int setPicked(int on_off, bool propagate_parent_event=true)=0
GLuint color
Definition: glcorearb.h:1260
const OP_PostItNoteFlags & flags() const
Definition: OP_PostIt.h:61
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
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
GLbitfield flags
Definition: glcorearb.h:1595
virtual int64 getItemUniqueId() const
Functions to get hip-file-unique ids for any item type.
Definition: OP_PostIt.h:79
GLint y
Definition: glcorearb.h:102
virtual OP_Network * getParentNetwork() const =0
Returns the network that is our parent.
GLsizeiptr size
Definition: glcorearb.h:663
virtual const UT_String & getItemName() const
Definition: OP_PostIt.h:87
UT_API UT_ErrorSeverity UTgetErrorSeverity()
OP_ItemType
Definition: OP_ItemId.h:28
long long int64
Definition: SYS_Types.h:107
virtual fpreal getW() const =0
const UT_Color & getTextColor() const
Definition: OP_PostIt.h:101
GLuint const GLchar * name
Definition: glcorearb.h:785
virtual int getPicked() const =0
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
double fpreal
Definition: SYS_Types.h:270
fpreal getTextSize() const
Definition: OP_PostIt.h:97
OP_PostItNoteFlags & flags()
Definition: OP_PostIt.h:62
bool getDrawBackground() const
Definition: OP_PostIt.h:105
#define OP_API
Definition: OP_API.h:10
GLint GLenum GLint x
Definition: glcorearb.h:408
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual fpreal getH() const =0
virtual const UT_String & getText() const
Definition: OP_PostIt.h:93
Definition: OP_PostIt.h:42