]> git.donarmstrong.com Git - xournal.git/blob - src/xournal.h
Public release 0.2.1.
[xournal.git] / src / xournal.h
1 #include <gtk/gtk.h>
2 #include <libgnomecanvas/libgnomecanvas.h>
3
4 // PREF FILES INFO
5
6 #define CONFIG_DIR ".xournal"
7 #define MRU_FILE "recent-files"
8 #define MRU_SIZE 8 
9
10 // DATA STRUCTURES AND CONSTANTS
11
12 #define PIXEL_MOTION_THRESHOLD 0.3
13 #define MAX_AXES 12
14 #define EPSILON 1E-7
15 #define MAX_ZOOM 20
16 #define DEFAULT_ZOOM 1.3333333333
17 #define MIN_ZOOM 0.2
18
19 /* a string (+ aux data) that maintains a refcount */
20
21 typedef struct Refstring {
22   int nref;
23   char *s;
24   gpointer aux;
25 } Refstring;
26
27
28 /* The journal is mostly a list of pages. Each page is a list of layers,
29    and a background. Each layer is a list of items, from bottom to top.
30 */
31
32 typedef struct Background {
33   int type;
34   GnomeCanvasItem *canvas_item;
35   int color_no;
36   guint color_rgba;
37   int ruling;
38   GdkPixbuf *pixbuf;
39   Refstring *filename;
40   int file_domain;
41   int file_page_seq;
42   int pixbuf_dpi;      // for PDF only - the *current* dpi value
43   double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
44                        // for PDF, this is the *requested* zoom value
45 } Background;
46
47 #define BG_SOLID 0
48 #define BG_PIXMAP 1
49 #define BG_PDF 2      // not implemented yet
50
51 #define RULING_NONE 0
52 #define RULING_LINED 1
53 #define RULING_RULED 2
54 #define RULING_GRAPH 3
55
56 #define DOMAIN_ABSOLUTE 0
57 #define DOMAIN_ATTACH 1
58 #define DOMAIN_CLONE 2  // only while loading file
59
60 typedef struct Brush {
61   int tool_type;
62   int color_no;
63   guint color_rgba;
64   int thickness_no;
65   double thickness;
66   int tool_options;
67 } Brush;
68
69 #define COLOR_BLACK      0
70 #define COLOR_BLUE       1
71 #define COLOR_RED        2
72 #define COLOR_GREEN      3
73 #define COLOR_GRAY       4
74 #define COLOR_LIGHTBLUE  5
75 #define COLOR_LIGHTGREEN 6
76 #define COLOR_MAGENTA    7
77 #define COLOR_ORANGE     8
78 #define COLOR_YELLOW     9
79 #define COLOR_WHITE     10
80 #define COLOR_OTHER     -1
81 #define COLOR_MAX       11
82
83 extern guint predef_colors_rgba[COLOR_MAX];
84 extern guint predef_bgcolors_rgba[COLOR_MAX];
85
86 #define THICKNESS_VERYFINE  0
87 #define THICKNESS_FINE      1
88 #define THICKNESS_MEDIUM    2
89 #define THICKNESS_THICK     3
90 #define THICKNESS_VERYTHICK 4
91 #define THICKNESS_MAX       5
92
93 #define TOOL_PEN          0
94 #define TOOL_ERASER       1
95 #define TOOL_HIGHLIGHTER  2
96 #define TOOL_TEXT         3
97 #define TOOL_SELECTREGION 4
98 #define TOOL_SELECTRECT   5
99 #define TOOL_VERTSPACE    6
100 #define NUM_STROKE_TOOLS  3
101
102 #define TOOLOPT_ERASER_STANDARD     0
103 #define TOOLOPT_ERASER_WHITEOUT     1
104 #define TOOLOPT_ERASER_STROKES      2
105
106 #define HILITER_ALPHA_MASK 0xffffff80
107
108 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
109
110 typedef struct BBox {
111   double left, right, top, bottom;
112 } BBox;
113
114 struct UndoErasureData;
115
116 typedef struct Item {
117   int type;
118   struct Brush brush; // the brush to use, if ITEM_STROKE
119   GnomeCanvasPoints *path;
120   GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
121   struct BBox bbox;
122   struct UndoErasureData *erasure; // for temporary use during erasures
123 } Item;
124
125 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
126 // (not all are valid in all places)
127 #define ITEM_NONE -1
128 #define ITEM_STROKE 0
129 #define ITEM_TEMP_STROKE 1
130 #define ITEM_ERASURE 2
131 #define ITEM_SELECTRECT 3
132 #define ITEM_MOVESEL 4
133 #define ITEM_PASTE 5
134 #define ITEM_NEW_LAYER 6
135 #define ITEM_DELETE_LAYER 7
136 #define ITEM_NEW_BG_ONE 8
137 #define ITEM_NEW_BG_RESIZE 9
138 #define ITEM_PAPER_RESIZE 10
139 #define ITEM_NEW_DEFAULT_BG 11
140 #define ITEM_NEW_PAGE 13
141 #define ITEM_DELETE_PAGE 14
142 #define ITEM_REPAINTSEL 15
143
144 typedef struct Layer {
145   GList *items; // the items on the layer, from bottom to top
146   int nitems;
147   GnomeCanvasGroup *group;
148 } Layer;
149
150 typedef struct Page {
151   GList *layers; // the layers on the page
152   int nlayers;
153   double height, width;
154   double hoffset, voffset; // offsets of canvas group rel. to canvas root
155   struct Background *bg;
156   GnomeCanvasGroup *group;
157 } Page;
158
159 typedef struct Journal {
160   GList *pages;  // the pages in the journal
161   int npages;
162   int last_attach_no; // for naming of attached backgrounds
163 } Journal;
164
165 typedef struct Selection {
166   int type;
167   BBox bbox; // the rectangle bbox of the selection
168   struct Layer *layer; // the layer on which the selection lives
169   double anchor_x, anchor_y, last_x, last_y; // for selection motion
170   GnomeCanvasItem *canvas_item; // if the selection box is on screen 
171   GList *items; // the selected items (a list of struct Item)
172 } Selection;
173
174 typedef struct UIData {
175   int pageno, layerno; // the current page and layer
176   struct Page *cur_page;
177   struct Layer *cur_layer;
178   int toolno;  // the number of the currently selected tool
179   gboolean saved; // is file saved ?
180   struct Brush *cur_brush;  // the brush in use (one of brushes[...])
181   struct Brush brushes[NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
182   struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
183   gboolean ruler; // whether we're in ruler mode
184   struct Page default_page;  // the model for the default page
185   int layerbox_length;  // the number of entries registered in the layers combo-box
186   struct Item *cur_item; // the item being drawn, or NULL
187   int cur_item_type;
188   GnomeCanvasPoints cur_path; // the path being drawn
189   int cur_path_storage_alloc;
190   int which_mouse_button; // the mouse button drawing the current path
191   int saved_toolno;  // while using an eraser device
192   gboolean saved_ruler;
193   double zoom; // zoom factor, in pixels per pt
194   gboolean use_xinput; // use input devices instead of core pointer
195   gboolean allow_xinput; // allow use of xinput ?
196   int screen_width, screen_height; // initial screen size, for XInput events
197   char *filename;
198   gboolean view_continuous, fullscreen;
199   gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
200   struct Selection *selection;
201   GdkCursor *cursor;
202   gboolean emulate_eraser;
203   gboolean antialias_bg; // bilinear interpolation on bg pixmaps
204   gboolean progressive_bg; // rescale bg's one at a time
205   char *mrufile; // file for the MRU
206   char *mru[MRU_SIZE]; // MRU data
207   GtkWidget *mrumenu[MRU_SIZE];
208 } UIData;
209
210 typedef struct UndoErasureData {
211   struct Item *item; // the item that got erased
212   int npos; // its position in its layer
213   int nrepl; // the number of replacement items
214   GList *replacement_items;
215 } UndoErasureData;
216
217 typedef struct UndoItem {
218   int type;
219   struct Item *item; // for ITEM_STROKE
220   struct Layer *layer; // for ITEM_STROKE, ITEM_ERASURE, ITEM_PASTE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER
221   struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1
222   struct Page *page;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
223   GList *erasurelist; // for ITEM_ERASURE
224   GList *itemlist;  // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL
225   GList *auxlist;   // for ITEM_REPAINTSEL
226   struct Background *bg;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
227   int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
228   double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG
229   struct UndoItem *next;
230   int multiop;
231 } UndoItem;
232
233 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
234 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
235
236
237 typedef struct BgPdfRequest {
238   int pageno;
239   int dpi;
240   gboolean initial_request; // if so, loop over page numbers
241   gboolean is_printing;     // this is for printing, not for display
242 } BgPdfRequest;
243
244 typedef struct BgPdfPage {
245   int dpi;
246   GdkPixbuf *pixbuf;
247 } BgPdfPage;
248
249 typedef struct BgPdf {
250   int status; // the rest only makes sense if this is not STATUS_NOT_INIT
251   int pid; // PID of the converter process
252   Refstring *filename;
253   int file_domain;
254   gchar *tmpfile_copy; // the temporary work copy of the file (in tmpdir)
255   int npages;
256   GList *pages; // a list of BgPdfPage structures
257   GList *requests; // a list of BgPdfRequest structures
258   gchar *tmpdir; // where to look for pages coming from pdf converter
259   gboolean create_pages; // create journal pages as we find stuff in PDF
260   gboolean has_failed; // has failed in the past...
261 } BgPdf;
262
263 #define STATUS_NOT_INIT 0
264 #define STATUS_IDLE     1
265 #define STATUS_RUNNING  2  // currently running child process on head(requests)
266 #define STATUS_ABORTED  3  // child process running, but head(requests) aborted
267 #define STATUS_SHUTDOWN 4  // waiting for child process to shut down
268
269 // UTILITY MACROS
270
271 // getting a component of the interface by name
272 #define GET_COMPONENT(a)  GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
273
274 // the margin between consecutive pages in continuous view
275 #define VIEW_CONTINUOUS_SKIP 20.0
276
277
278 // GLOBAL VARIABLES
279
280 // the main window and the canvas
281
282 extern GtkWidget *winMain;
283 extern GnomeCanvas *canvas;
284
285 // the data
286
287 extern struct Journal journal;
288 extern struct UIData ui;
289 extern struct BgPdf bgpdf;
290 extern struct UndoItem *undo, *redo;