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