~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/include/ipepage.h

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-12-11 21:22:35 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091211212235-5iio4nzpra64snab
Tags: 7.0.10-1
* New upstream.  Closes: #551192.
  - New build-depends: libcairo2-dev, liblua5.1-0-dev, gsfonts
  - patches/config.diff: Remove.  Upstream build system replaced.
  - Runtime lib package changed to libipe7.0.10 from libipe1c2a
  - Devel package renamed to libipe-dev (from libipe1-dev)
  - Package ipe depends on lua5.1 due to ipe-update-master.

* rules: Re-write to use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
/*
6
6
 
7
7
    This file is part of the extensible drawing editor Ipe.
8
 
    Copyright (C) 1993-2007  Otfried Cheong
 
8
    Copyright (C) 1993-2009  Otfried Cheong
9
9
 
10
10
    Ipe is free software; you can redistribute it and/or modify it
11
11
    under the terms of the GNU General Public License as published by
12
 
    the Free Software Foundation; either version 2 of the License, or
 
12
    the Free Software Foundation; either version 3 of the License, or
13
13
    (at your option) any later version.
14
14
 
15
15
    As a special exception, you have permission to link Ipe with the
32
32
#ifndef IPEPAGE_H
33
33
#define IPEPAGE_H
34
34
 
35
 
#include "ipeobj.h"
36
 
#include "ipepath.h"
37
35
#include "ipetext.h"
38
36
 
39
37
// --------------------------------------------------------------------
40
38
 
41
 
class IpeStyleSheet;
42
 
class IpeDataSource;
43
 
class IpeRepository;
44
 
 
45
 
struct SSubPath;
46
 
 
47
 
class IPE_EXPORT IpeLayer {
48
 
public:
49
 
  explicit IpeLayer(IpeString name);
50
 
  explicit IpeLayer(const IpeXmlAttributes &attr);
51
 
  void SaveAsXml(IpeStream &stream) const;
52
 
  //! Return name.
53
 
  inline IpeString Name() const { return iName; }
54
 
  //! Set name.
55
 
  inline void SetName(const IpeString &name) { iName = name; }
56
 
 
57
 
  //! Is dimmed?
58
 
  inline bool IsDimmed() const { return !!(iFlags & EDim); }
59
 
  //! Is locked?
60
 
  inline bool IsLocked() const { return !!(iFlags & ELocked); }
61
 
  //! Is snapping enabled?
62
 
  inline bool IsSnapping() const { return !(iFlags & ENoSnapping); }
63
 
 
64
 
  void SetDimmed(bool flag);
65
 
  void SetLocked(bool flag);
66
 
  void SetSnapping(bool flag);
67
 
 
68
 
public:
69
 
  enum {EDim = 0x01, ELocked = 0x02, ENoSnapping = 0x04 };
70
 
  IpeString iName;
71
 
  int iFlags;
72
 
};
73
 
 
74
 
//! Layers of a page.
75
 
typedef std::vector<IpeLayer> IpeLayerSeq;
76
 
 
77
 
// --------------------------------------------------------------------
78
 
 
79
 
class IPE_EXPORT IpeView {
80
 
public:
81
 
  //! The various fancy effects that Acrobat Reader will show.
82
 
  enum TEffect {
83
 
    ENormal, ESplitHI, ESplitHO, ESplitVI, ESplitVO,
84
 
    EBlindsH, EBlindsV, EBoxI, EBoxO,
85
 
    EWipeLR, EWipeBT, EWipeRL, EWipeTB,
86
 
    EDissolve, EGlitterLR, EGlitterTB, EGlitterD };
87
 
 
88
 
  IpeView();
89
 
  IpeView(const IpeXmlAttributes &attr);
90
 
  void SaveAsXml(IpeStream &stream) const;
91
 
  void PageDictionary(IpeStream &stream) const;
92
 
 
93
 
  //! How many layers are visible in this view?
94
 
  inline int CountLayers() const { return iLayers.size(); }
95
 
  //! Return name of one visible layer.
96
 
  inline IpeString Layer(int i) const { return iLayers[i]; }
97
 
  bool HasLayer(IpeString name) const;
98
 
  void DeleteLayer(IpeString name);
99
 
  void AddLayer(IpeString name);
100
 
  inline void ClearLayers() { iLayers.clear(); }
101
 
 
102
 
  //! The layer active in this view.
103
 
  inline IpeString Active() const { return iActive; }
104
 
  //! Set active layer.
105
 
  inline void SetActive(const IpeString &l) { iActive = l; }
106
 
  //! The transition effect when switching to this view.
107
 
  inline TEffect Effect() const { return iEffect; }
108
 
  //! Set transition effect for switching to this view.
109
 
  inline void SetEffect(TEffect e) { iEffect = e; }
110
 
  //! How long will this view be shown (in secs)?
111
 
  inline int Duration() const { return iDuration; }
112
 
  //! Set duration of this view (in secs).
113
 
  inline void SetDuration(int secs) { iDuration = secs; }
114
 
  //! The transition time for the effect (in secs).
115
 
  inline int TransitionTime() const { return iTransitionTime; }
116
 
  //! Set transition time for the effect (in secs).
117
 
  inline void SetTransitionTime(int secs) { iTransitionTime = secs; }
118
 
private:
119
 
  std::vector<IpeString> iLayers;
120
 
  IpeString iActive;
121
 
  TEffect iEffect;
122
 
  int iTransitionTime;
123
 
  int iDuration;
124
 
};
125
 
 
126
 
//! View sequence of a page.
127
 
typedef std::vector<IpeView> IpeViewSeq;
128
 
 
129
 
// --------------------------------------------------------------------
130
 
 
131
 
class IPE_EXPORT IpePage : public IpePgObjectSeq {
132
 
public:
133
 
  explicit IpePage();
134
 
 
135
 
  void SaveAsXml(IpePainter &painter, IpeStream &stream) const;
136
 
 
137
 
  //! Return number of layers.
138
 
  inline int CountLayers() const { return iLayers.size(); }
139
 
  //! Return a layer.
140
 
  inline const IpeLayer &Layer(int index) const { return iLayers[index]; }
141
 
  //! Return a layer.
142
 
  inline IpeLayer &Layer(int index) { return iLayers[index]; }
143
 
  int FindLayer(IpeString name) const;
144
 
  int AddLayer(const IpeLayer &layer, int index = -1);
145
 
  int NewLayer(int index);
146
 
  void DeleteLayer(int index);
147
 
  bool IsLayerActiveInView(int index) const;
148
 
 
149
 
  //! Return presentation sequence of this page.
150
 
  inline const IpeViewSeq &Views() const {return iViews;}
151
 
  //! Return number of views.
152
 
  inline int CountViews() const { return iViews.size(); }
153
 
  //! Return a view.
154
 
  inline const IpeView &View(int index) const { return iViews[index]; }
155
 
  //! Return a view.
156
 
  inline IpeView &View(int index) { return iViews[index]; }
157
 
  void SetView(int index, const IpeView &view);
158
 
  void AddView(const IpeView &view, int index = -1);
159
 
  void DeleteView(int index);
160
 
  void renameLayer(IpeString oldName, IpeString newName);
161
 
 
162
 
  IpeRect TextBox(const IpeStyleSheet *sheet) const;
163
 
 
164
 
  void SetEdited(bool edited);
165
 
  //! Return true if page has been modified since last save.
166
 
  inline bool IsEdited() const { return iEdited; }
167
 
 
168
 
  //! Return title of this page.
169
 
  IpeString title() const;
170
 
  void setTitle(IpeString title);
171
 
  IpeString section(int level) const;
172
 
  void setSection(int level, bool useTitle, IpeString name);
173
 
  //! Does this section title reflect the page title?
174
 
  bool sectionUsesTitle(int level) const { return iUseTitle[level]; }
175
 
  const IpeText *titleText() const;
176
 
  void applyTitleStyle(const IpeStyleSheet *sheet);
177
 
 
178
 
  void DeselectAll();
179
 
  void DeselectLayer(int layer);
180
 
  void DeselectNotInView(int view);
181
 
  bool HasSelection() const;
182
 
  iterator PrimarySelection();
183
 
  void EnsurePrimarySelection();
184
 
  void ExtractSelection(IpePgObjectSeq &seq);
185
 
  bool UpdateCloseSelection(const IpeVector &pos, double d,
186
 
                            bool primaryOnly, int view);
187
 
 
188
 
  void Copy(IpeStream &stream, const IpeStyleSheet *sheet) const;
189
 
  bool Paste(int layer, IpeDataSource &source, IpeRepository *rep);
190
 
  void CopyPage(IpeStream &stream, const IpeStyleSheet *sheet) const;
191
 
 
192
 
  void MakeLayerTable(std::vector<bool> &layers, int view,
193
 
                      bool excludeLocked) const;
194
 
 
195
 
  void MoveToLayer(int layer);
196
 
  void Delete();
197
 
  void SelectAll(int view);
198
 
  void SelectAllInLayer(int layer);
199
 
  void Group(int layer);
200
 
  bool Ungroup(int layer);
201
 
  void Front();
202
 
  void Back();
203
 
  void forward();
204
 
  void backward();
205
 
  void movePrimaryBeforeSecondary();
206
 
  void movePrimaryBehindSecondary();
207
 
  void Duplicate(int layer);
208
 
  void SetStroke(IpeAttribute color);
209
 
  void SetFill(IpeAttribute color);
210
 
  void SetLineWidth(IpeAttribute attr);
211
 
  void SetDashStyle(IpeAttribute attr);
212
 
  void SetArrows(bool forward, bool backward, IpeAttribute size);
213
 
  void SetArrowSize(IpeAttribute size);
214
 
  void SetMarkShape(int shape);
215
 
  void SetMarkSize(IpeAttribute size);
216
 
  void SetTextSize(IpeAttribute size);
217
 
  void setTransformable(bool transf);
218
 
  void setTextStyle(IpeAttribute style);
219
 
  void setLabelHorizontalAlignment(IpeText::THorizontalAlignment align);
220
 
  void setLabelVerticalAlignment(IpeText::TVerticalAlignment align);
221
 
  void setPinned(IpeObject::TPinned pin);
222
 
  void setLineJoin(IpeAttribute join);
223
 
  void setLineCap(IpeAttribute cap);
224
 
  void setWindRule(IpeAttribute rule);
225
 
 
226
 
  bool ComposePaths(int layer);
227
 
  bool DecomposePath(int layer);
228
 
  bool JoinPaths(int layer);
229
 
 
230
 
  //! Return grid size for this page (0 if not set).
231
 
  inline int GridSize() const { return iGridSize; }
232
 
  //! Set grid size.
233
 
  inline void SetGridSize(int gs) { iGridSize = gs; }
234
 
 
235
 
private:
236
 
  IpePath *DoJoinPaths(IpePath *prim, SSubPath *subs, int size);
237
 
private:
238
 
  bool iEdited;
239
 
  IpeViewSeq iViews;
240
 
  IpeLayerSeq iLayers;
241
 
  int iGridSize;
242
 
  IpeString iTitle;
243
 
  IpeText iTitleObject;
244
 
  bool iUseTitle[2];
245
 
  IpeString iSection[2];
246
 
};
247
 
 
248
 
//! Constructor takes ownership of object.
249
 
inline IpePgObject::IpePgObject(TSelect sel, int layer, IpeObject *obj)
250
 
  : iSelect(sel), iLayer(layer), iObject(obj)
251
 
{
252
 
  // nothing
253
 
}
 
39
namespace ipe {
 
40
 
 
41
  class StyleSheet;
 
42
  // class DataSource;
 
43
 
 
44
  // --------------------------------------------------------------------
 
45
 
 
46
  class Page {
 
47
  public:
 
48
    explicit Page();
 
49
 
 
50
    static Page *basic();
 
51
 
 
52
    void saveAsXml(Stream &stream) const;
 
53
    void saveAsIpePage(Stream &stream) const;
 
54
    void saveSelection(Stream &stream) const;
 
55
 
 
56
    //! Return number of layers.
 
57
    inline int countLayers() const { return iLayers.size(); }
 
58
    //! Return name of layer \a index.
 
59
    inline String layer(int index) const { return iLayers[index].iName; }
 
60
 
 
61
    //! Is layer \a i locked?
 
62
    inline bool isLocked(int i) const {
 
63
      return !!(iLayers[i].iFlags & ELocked); }
 
64
    //! Does layer \a i have active snapping?
 
65
    inline bool hasSnapping(int i) const {
 
66
      return !(iLayers[i].iFlags & ENoSnapping); }
 
67
 
 
68
    void setLocked(int i, bool flag);
 
69
    void setSnapping(int i, bool flag);
 
70
 
 
71
    int findLayer(String name) const;
 
72
    void addLayer(String name);
 
73
    void addLayer();
 
74
    void removeLayer(String name);
 
75
    void renameLayer(String oldName, String newName);
 
76
 
 
77
    //! Return number of views.
 
78
    inline int countViews() const { return iViews.size(); }
 
79
    //! Return effect of view.
 
80
    inline Attribute effect(int index) const { return iViews[index].iEffect; }
 
81
    void setEffect(int index, Attribute sym);
 
82
    //! Return active layer of view.
 
83
    inline String active(int index) const { return iViews[index].iActive; }
 
84
    //! Set active layer of view.
 
85
    void setActive(int index, String name);
 
86
 
 
87
    void insertView(int i, String active);
 
88
    void removeView(int i);
 
89
    void clearViews();
 
90
 
 
91
    //! Is \a layer visible in \a view?
 
92
    inline bool visible(int view, int layer) const {
 
93
      return iLayers[layer].iVisible[view]; }
 
94
    //! Is object at index \a objno visible in \a view?
 
95
    inline bool objectVisible(int view, int objno) const {
 
96
      return iLayers[layerOf(objno)].iVisible[view]; }
 
97
 
 
98
    void setVisible(int view, String layer, bool vis);
 
99
 
 
100
    Rect textBox(const Cascade *sheet) const;
 
101
 
 
102
    //! Return title of this page.
 
103
    String title() const;
 
104
    void setTitle(String title);
 
105
    String section(int level) const;
 
106
    void setSection(int level, bool useTitle, String name);
 
107
    //! Does this section title reflect the page title?
 
108
    bool sectionUsesTitle(int level) const { return iUseTitle[level]; }
 
109
    const Text *titleText() const;
 
110
    void applyTitleStyle(const Cascade *sheet);
 
111
 
 
112
    //! Return number of objects on the page.
 
113
    inline int count() const { return int(iObjects.size()); }
 
114
 
 
115
    //! Return object at index \a i.
 
116
    inline Object *object(int i) { return iObjects[i].iObject; }
 
117
    //! Return object at index \a i (const version).
 
118
    inline const Object *object(int i) const { return iObjects[i].iObject; }
 
119
 
 
120
    //! Return selection status of object at index \a i.
 
121
    inline TSelect select(int i) const { return iObjects[i].iSelect; }
 
122
    //! Return layer of object at index \a i.
 
123
    inline int layerOf(int i) const { return iObjects[i].iLayer; }
 
124
 
 
125
    //! Set selection status of object at index \a i.
 
126
    inline void setSelect(int i, TSelect sel) { iObjects[i].iSelect = sel; }
 
127
    //! Set layer of object at index \a i.
 
128
    inline void setLayerOf(int i, int layer) { iObjects[i].iLayer = layer; }
 
129
 
 
130
    Rect pageBBox(const Cascade *sheet) const;
 
131
    Rect viewBBox(const Cascade *sheet, int view) const;
 
132
    Rect bbox(int i) const;
 
133
 
 
134
    void transform(int i, const Matrix &m);
 
135
    double distance(int i, const Vector &v, double bound) const;
 
136
    void snapVtx(int i, const Vector &mouse, Vector &pos, double &bound) const;
 
137
    void snapBnd(int i, const Vector &mouse, Vector &pos, double &bound) const;
 
138
    void invalidateBBox(int i) const;
 
139
 
 
140
    void insert(int i, TSelect sel, int layer, Object *obj);
 
141
    void append(TSelect sel, int layer, Object *obj);
 
142
    void remove(int i);
 
143
    void replace(int i, Object *obj);
 
144
    bool setAttribute(int i, Property prop, Attribute value,
 
145
                      Attribute stroke, Attribute fill);
 
146
 
 
147
    int primarySelection() const;
 
148
    bool hasSelection() const;
 
149
    void deselectAll();
 
150
    void ensurePrimarySelection();
 
151
 
 
152
  private:
 
153
    enum { ELocked = 0x01, ENoSnapping = 0x02 };
 
154
 
 
155
    struct SLayer {
 
156
    public:
 
157
      SLayer(String name);
 
158
    public:
 
159
      String iName;
 
160
      int iFlags;
 
161
      // Invariant: iVisible.size() == iViews.size()
 
162
      std::vector<bool> iVisible;
 
163
    };
 
164
    typedef std::vector<SLayer> LayerSeq;
 
165
 
 
166
    struct SView {
 
167
    public:
 
168
      SView() { iEffect = Attribute::NORMAL(); }
 
169
    public:
 
170
      Attribute iEffect;
 
171
      String iActive;
 
172
    };
 
173
    typedef std::vector<SView> ViewSeq;
 
174
 
 
175
    struct SObject {
 
176
      SObject();
 
177
      SObject(const SObject &rhs);
 
178
      ~SObject();
 
179
      SObject &operator=(const SObject &rhs);
 
180
 
 
181
      TSelect iSelect;
 
182
      int iLayer;
 
183
      mutable Rect iBBox;
 
184
      Object *iObject;
 
185
    };
 
186
    typedef std::vector<SObject> ObjSeq;
 
187
 
 
188
    LayerSeq iLayers;
 
189
    ViewSeq iViews;
 
190
 
 
191
    String iTitle;
 
192
    Text iTitleObject;
 
193
    bool iUseTitle[2];
 
194
    String iSection[2];
 
195
    ObjSeq iObjects;
 
196
  };
 
197
 
 
198
} // namespace
254
199
 
255
200
// --------------------------------------------------------------------
256
201
#endif