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