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