]> git.donarmstrong.com Git - xournal.git/blob - src/xournal.h
236ff33578c30a9c015ff350e8e89ee9aaadf4d6
[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 #define NUM_BUTTONS       3
102
103 #define TOOLOPT_ERASER_STANDARD     0
104 #define TOOLOPT_ERASER_WHITEOUT     1
105 #define TOOLOPT_ERASER_STROKES      2
106
107 #define HILITER_ALPHA_MASK 0xffffff80
108
109 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
110
111 typedef struct BBox {
112   double left, right, top, bottom;
113 } BBox;
114
115 struct UndoErasureData;
116
117 typedef struct Item {
118   int type;
119   struct Brush brush; // the brush to use, if ITEM_STROKE
120   GnomeCanvasPoints *path;
121   GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
122   struct BBox bbox;
123   struct UndoErasureData *erasure; // for temporary use during erasures
124 } Item;
125
126 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
127 // (not all are valid in all places)
128 #define ITEM_NONE -1
129 #define ITEM_STROKE 0
130 #define ITEM_TEMP_STROKE 1
131 #define ITEM_ERASURE 2
132 #define ITEM_SELECTRECT 3
133 #define ITEM_MOVESEL 4
134 #define ITEM_PASTE 5
135 #define ITEM_NEW_LAYER 6
136 #define ITEM_DELETE_LAYER 7
137 #define ITEM_NEW_BG_ONE 8
138 #define ITEM_NEW_BG_RESIZE 9
139 #define ITEM_PAPER_RESIZE 10
140 #define ITEM_NEW_DEFAULT_BG 11
141 #define ITEM_NEW_PAGE 13
142 #define ITEM_DELETE_PAGE 14
143 #define ITEM_REPAINTSEL 15
144 #define ITEM_MOVESEL_VERT 16
145
146 typedef struct Layer {
147   GList *items; // the items on the layer, from bottom to top
148   int nitems;
149   GnomeCanvasGroup *group;
150 } Layer;
151
152 typedef struct Page {
153   GList *layers; // the layers on the page
154   int nlayers;
155   double height, width;
156   double hoffset, voffset; // offsets of canvas group rel. to canvas root
157   struct Background *bg;
158   GnomeCanvasGroup *group;
159 } Page;
160
161 typedef struct Journal {
162   GList *pages;  // the pages in the journal
163   int npages;
164   int last_attach_no; // for naming of attached backgrounds
165 } Journal;
166
167 typedef struct Selection {
168   int type;  // ITEM_SELECTRECT, ITEM_MOVESEL_VERT
169   BBox bbox; // the rectangle bbox of the selection
170   struct Layer *layer; // the layer on which the selection lives
171   double anchor_x, anchor_y, last_x, last_y; // for selection motion
172   GnomeCanvasItem *canvas_item; // if the selection box is on screen 
173   GList *items; // the selected items (a list of struct Item)
174   int move_pageno, orig_pageno; // if selection moves to a different page
175   struct Layer *move_layer;
176   float move_pagedelta;
177 } Selection;
178
179 typedef struct UIData {
180   int pageno, layerno; // the current page and layer
181   struct Page *cur_page;
182   struct Layer *cur_layer;
183   gboolean saved; // is file saved ?
184   struct Brush *cur_brush;  // the brush in use (one of brushes[...])
185   int toolno[NUM_BUTTONS+1];  // the number of the currently selected tool
186   struct Brush brushes[NUM_BUTTONS+1][NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
187   struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
188   gboolean ruler[NUM_BUTTONS+1]; // whether each button is in ruler mode
189   int linked_brush[NUM_BUTTONS+1]; // whether brushes are linked across buttons
190   int cur_mapping; // the current button number for mappings
191   gboolean use_erasertip;
192   int which_mouse_button; // the mouse button drawing the current path
193   struct Page default_page;  // the model for the default page
194   int layerbox_length;  // the number of entries registered in the layers combo-box
195   struct Item *cur_item; // the item being drawn, or NULL
196   int cur_item_type;
197   GnomeCanvasPoints cur_path; // the path being drawn
198   int cur_path_storage_alloc;
199   double zoom; // zoom factor, in pixels per pt
200   gboolean use_xinput; // use input devices instead of core pointer
201   gboolean allow_xinput; // allow use of xinput ?
202   int screen_width, screen_height; // initial screen size, for XInput events
203   char *filename;
204   gboolean view_continuous, fullscreen;
205   gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
206   struct Selection *selection;
207   GdkCursor *cursor;
208   gboolean antialias_bg; // bilinear interpolation on bg pixmaps
209   gboolean progressive_bg; // rescale bg's one at a time
210   char *mrufile; // file for the MRU
211   char *mru[MRU_SIZE]; // MRU data
212   GtkWidget *mrumenu[MRU_SIZE];
213   gboolean bg_apply_all_pages;
214 } UIData;
215
216 #define BRUSH_LINKED 0
217 #define BRUSH_COPIED 1
218 #define BRUSH_STATIC 2
219
220 typedef struct UndoErasureData {
221   struct Item *item; // the item that got erased
222   int npos; // its position in its layer
223   int nrepl; // the number of replacement items
224   GList *replacement_items;
225 } UndoErasureData;
226
227 typedef struct UndoItem {
228   int type;
229   struct Item *item; // for ITEM_STROKE
230   struct Layer *layer; // for ITEM_STROKE, ITEM_ERASURE, ITEM_PASTE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_MOVESEL
231   struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
232   struct Page *page;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
233   GList *erasurelist; // for ITEM_ERASURE
234   GList *itemlist;  // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL
235   GList *auxlist;   // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
236   struct Background *bg;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
237   int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
238   double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG
239   struct UndoItem *next;
240   int multiop;
241 } UndoItem;
242
243 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
244 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
245
246
247 typedef struct BgPdfRequest {
248   int pageno;
249   int dpi;
250   gboolean initial_request; // if so, loop over page numbers
251   gboolean is_printing;     // this is for printing, not for display
252 } BgPdfRequest;
253
254 typedef struct BgPdfPage {
255   int dpi;
256   GdkPixbuf *pixbuf;
257 } BgPdfPage;
258
259 typedef struct BgPdf {
260   int status; // the rest only makes sense if this is not STATUS_NOT_INIT
261   int pid; // PID of the converter process
262   Refstring *filename;
263   int file_domain;
264   gchar *tmpfile_copy; // the temporary work copy of the file (in tmpdir)
265   int npages;
266   GList *pages; // a list of BgPdfPage structures
267   GList *requests; // a list of BgPdfRequest structures
268   gchar *tmpdir; // where to look for pages coming from pdf converter
269   gboolean create_pages; // create journal pages as we find stuff in PDF
270   gboolean has_failed; // has failed in the past...
271 } BgPdf;
272
273 #define STATUS_NOT_INIT 0
274 #define STATUS_IDLE     1
275 #define STATUS_RUNNING  2  // currently running child process on head(requests)
276 #define STATUS_ABORTED  3  // child process running, but head(requests) aborted
277 #define STATUS_SHUTDOWN 4  // waiting for child process to shut down
278
279 // UTILITY MACROS
280
281 // getting a component of the interface by name
282 #define GET_COMPONENT(a)  GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
283
284 // the margin between consecutive pages in continuous view
285 #define VIEW_CONTINUOUS_SKIP 20.0
286
287
288 // GLOBAL VARIABLES
289
290 // the main window and the canvas
291
292 extern GtkWidget *winMain;
293 extern GnomeCanvas *canvas;
294
295 // the data
296
297 extern struct Journal journal;
298 extern struct UIData ui;
299 extern struct BgPdf bgpdf;
300 extern struct UndoItem *undo, *redo;