fix crash upon unplugging input devices
[xournal.git] / src / xournal.h
blob7c7d4c3fa40b1979f1f9c68377b993704dda668b
1 #include <gtk/gtk.h>
2 #include <libgnomecanvas/libgnomecanvas.h>
3 #include <poppler/glib/poppler.h>
5 // #define INPUT_DEBUG
6 /* uncomment this line if you experience event-processing problems
7 and want to list the input events received by xournal. Caution, lots
8 of output (redirect to a file). */
10 #define ENABLE_XINPUT_BUGFIX
11 /* comment out this line if you are experiencing calibration problems with
12 XInput and want to try things differently. This will probably break
13 on-the-fly display rotation after application startup, though. */
15 #define FILE_DIALOG_SIZE_BUGFIX
16 /* ugly, but should help users with versions of GTK+ that suffer from the
17 "tiny file dialog" syndrome, without hurting those with well-behaved
18 versions of GTK+. Comment out if you'd prefer not to include this fix. */
20 // PREF FILES INFO
22 #define CONFIG_DIR ".xournal"
23 #define MRU_FILE "recent-files"
24 #define MRU_SIZE 8
25 #define CONFIG_FILE "config"
27 // version string for about box
29 #ifdef WIN32
30 #define VERSION_STRING VERSION "-win32"
31 #else
32 #define VERSION_STRING VERSION
33 #endif
35 // DATA STRUCTURES AND CONSTANTS
37 #define PIXEL_MOTION_THRESHOLD 0.3
38 #define MAX_AXES 12
39 #define EPSILON 1E-7
40 #define MAX_ZOOM 20.0
41 #define DISPLAY_DPI_DEFAULT 96.0
42 #define MIN_ZOOM 0.2
43 #define RESIZE_MARGIN 6.0
44 #define MAX_SAFE_RENDER_DPI 720 // max dpi at which PDF bg's get rendered
46 #define VBOX_MAIN_NITEMS 5 // number of interface items in vboxMain
48 /* a string (+ aux data) that maintains a refcount */
50 typedef struct Refstring {
51 int nref;
52 char *s;
53 gpointer aux;
54 } Refstring;
57 /* The journal is mostly a list of pages. Each page is a list of layers,
58 and a background. Each layer is a list of items, from bottom to top.
61 typedef struct Background {
62 int type;
63 GnomeCanvasItem *canvas_item;
64 int color_no;
65 guint color_rgba;
66 int ruling;
67 GdkPixbuf *pixbuf;
68 Refstring *filename;
69 int file_domain;
70 int file_page_seq;
71 double pixbuf_scale; // for PIXMAP, this is the *current* zoom value
72 // for PDF, this is the *requested* zoom value
73 int pixel_height, pixel_width; // PDF only: pixel size of current pixbuf
74 } Background;
76 #define BG_SOLID 0
77 #define BG_PIXMAP 1
78 #define BG_PDF 2 // not implemented yet
80 #define RULING_NONE 0
81 #define RULING_LINED 1
82 #define RULING_RULED 2
83 #define RULING_GRAPH 3
85 #define DOMAIN_ABSOLUTE 0
86 #define DOMAIN_ATTACH 1
87 #define DOMAIN_CLONE 2 // only while loading file
89 typedef struct Brush {
90 int tool_type;
91 int color_no;
92 guint color_rgba;
93 int thickness_no;
94 double thickness;
95 int tool_options;
96 gboolean ruler, recognizer, variable_width;
97 } Brush;
99 #define COLOR_BLACK 0
100 #define COLOR_BLUE 1
101 #define COLOR_RED 2
102 #define COLOR_GREEN 3
103 #define COLOR_GRAY 4
104 #define COLOR_LIGHTBLUE 5
105 #define COLOR_LIGHTGREEN 6
106 #define COLOR_MAGENTA 7
107 #define COLOR_ORANGE 8
108 #define COLOR_YELLOW 9
109 #define COLOR_WHITE 10
110 #define COLOR_OTHER -1
111 #define COLOR_MAX 11
113 extern guint predef_colors_rgba[COLOR_MAX];
114 extern guint predef_bgcolors_rgba[COLOR_MAX];
116 #define THICKNESS_VERYFINE 0
117 #define THICKNESS_FINE 1
118 #define THICKNESS_MEDIUM 2
119 #define THICKNESS_THICK 3
120 #define THICKNESS_VERYTHICK 4
121 #define THICKNESS_MAX 5
123 #define TOOL_PEN 0
124 #define TOOL_ERASER 1
125 #define TOOL_HIGHLIGHTER 2
126 #define TOOL_TEXT 3
127 #define TOOL_SELECTREGION 4
128 #define TOOL_SELECTRECT 5
129 #define TOOL_VERTSPACE 6
130 #define TOOL_HAND 7
131 #define NUM_STROKE_TOOLS 3
132 #define NUM_TOOLS 8
133 #define NUM_BUTTONS 3
135 #define TOOLOPT_ERASER_STANDARD 0
136 #define TOOLOPT_ERASER_WHITEOUT 1
137 #define TOOLOPT_ERASER_STROKES 2
139 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
141 typedef struct BBox {
142 double left, right, top, bottom;
143 } BBox;
145 struct UndoErasureData;
147 typedef struct Item {
148 int type;
149 struct Brush brush; // the brush to use, if ITEM_STROKE
150 // 'brush' also contains color info for text items
151 GnomeCanvasPoints *path;
152 gdouble *widths;
153 GnomeCanvasItem *canvas_item; // the corresponding canvas item, or NULL
154 struct BBox bbox;
155 struct UndoErasureData *erasure; // for temporary use during erasures
156 // the following fields for ITEM_TEXT:
157 gchar *text;
158 gchar *font_name;
159 gdouble font_size;
160 GtkWidget *widget; // the widget while text is being edited (ITEM_TEMP_TEXT)
161 } Item;
163 // item type values for Item.type, UndoItem.type, ui.cur_item_type ...
164 // (not all are valid in all places)
165 #define ITEM_NONE -1
166 #define ITEM_STROKE 0
167 #define ITEM_TEMP_STROKE 1
168 #define ITEM_ERASURE 2
169 #define ITEM_SELECTRECT 3
170 #define ITEM_MOVESEL 4
171 #define ITEM_PASTE 5
172 #define ITEM_NEW_LAYER 6
173 #define ITEM_DELETE_LAYER 7
174 #define ITEM_NEW_BG_ONE 8
175 #define ITEM_NEW_BG_RESIZE 9
176 #define ITEM_PAPER_RESIZE 10
177 #define ITEM_NEW_DEFAULT_BG 11
178 #define ITEM_NEW_PAGE 13
179 #define ITEM_DELETE_PAGE 14
180 #define ITEM_REPAINTSEL 15
181 #define ITEM_MOVESEL_VERT 16
182 #define ITEM_HAND 17
183 #define ITEM_TEXT 18
184 #define ITEM_TEMP_TEXT 19
185 #define ITEM_TEXT_EDIT 20
186 #define ITEM_TEXT_ATTRIB 21
187 #define ITEM_RESIZESEL 22
188 #define ITEM_RECOGNIZER 23
190 typedef struct Layer {
191 GList *items; // the items on the layer, from bottom to top
192 int nitems;
193 GnomeCanvasGroup *group;
194 } Layer;
196 typedef struct Page {
197 GList *layers; // the layers on the page
198 int nlayers;
199 double height, width;
200 double hoffset, voffset; // offsets of canvas group rel. to canvas root
201 struct Background *bg;
202 GnomeCanvasGroup *group;
203 } Page;
205 typedef struct Journal {
206 GList *pages; // the pages in the journal
207 int npages;
208 int last_attach_no; // for naming of attached backgrounds
209 } Journal;
211 typedef struct Selection {
212 int type; // ITEM_SELECTRECT, ITEM_MOVESEL_VERT
213 BBox bbox; // the rectangle bbox of the selection
214 struct Layer *layer; // the layer on which the selection lives
215 double anchor_x, anchor_y, last_x, last_y; // for selection motion
216 gboolean resizing_top, resizing_bottom, resizing_left, resizing_right; // for selection resizing
217 double new_x1, new_x2, new_y1, new_y2; // for selection resizing
218 GnomeCanvasItem *canvas_item; // if the selection box is on screen
219 GList *items; // the selected items (a list of struct Item)
220 int move_pageno, orig_pageno; // if selection moves to a different page
221 struct Layer *move_layer;
222 float move_pagedelta;
223 } Selection;
225 typedef struct UIData {
226 int pageno, layerno; // the current page and layer
227 struct Page *cur_page;
228 struct Layer *cur_layer;
229 gboolean saved; // is file saved ?
230 struct Brush *cur_brush; // the brush in use (one of brushes[...])
231 int toolno[NUM_BUTTONS+1]; // the number of the currently selected tool
232 struct Brush brushes[NUM_BUTTONS+1][NUM_STROKE_TOOLS]; // the current pen, eraser, hiliter
233 struct Brush default_brushes[NUM_STROKE_TOOLS]; // the default ones
234 int linked_brush[NUM_BUTTONS+1]; // whether brushes are linked across buttons
235 int cur_mapping; // the current button number for mappings
236 gboolean button_switch_mapping; // button clicks switch button 1 mappings
237 gboolean use_erasertip;
238 int which_mouse_button; // the mouse button drawing the current path
239 int which_unswitch_button; // if button_switch_mapping, the mouse button that switched the mapping
240 struct Page default_page; // the model for the default page
241 int layerbox_length; // the number of entries registered in the layers combo-box
242 struct Item *cur_item; // the item being drawn, or NULL
243 int cur_item_type;
244 GnomeCanvasPoints cur_path; // the path being drawn
245 gdouble *cur_widths; // width array for the path being drawn
246 int cur_path_storage_alloc;
247 int cur_widths_storage_alloc;
248 double zoom; // zoom factor, in pixels per pt
249 gboolean use_xinput; // use input devices instead of core pointer
250 gboolean allow_xinput; // allow use of xinput ?
251 gboolean discard_corepointer; // discard core pointer events in XInput mode
252 gboolean pressure_sensitivity; // use pen pressure to control stroke width?
253 double width_minimum_multiplier, width_maximum_multiplier; // calibration for pressure sensitivity
254 gboolean is_corestroke; // this stroke is painted with core pointer
255 gboolean saved_is_corestroke;
256 GdkDevice *stroke_device; // who's painting this stroke
257 int screen_width, screen_height; // initial screen size, for XInput events
258 double hand_refpt[2];
259 int hand_scrollto_cx, hand_scrollto_cy;
260 gboolean hand_scrollto_pending;
261 char *filename;
262 gchar *default_path; // default path for new notes
263 gboolean view_continuous, fullscreen, maximize_at_start;
264 gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
265 struct Selection *selection;
266 GdkCursor *cursor;
267 gboolean progressive_bg; // update PDF bg's one at a time
268 char *mrufile, *configfile; // file names for MRU & config
269 char *mru[MRU_SIZE]; // MRU data
270 GtkWidget *mrumenu[MRU_SIZE];
271 gboolean bg_apply_all_pages;
272 int window_default_width, window_default_height, scrollbar_step_increment;
273 gboolean print_ruling; // print the paper ruling ?
274 int default_unit; // the default unit for paper sizes
275 int startuptool; // the default tool at startup
276 int zoom_step_increment; // the increment in the zoom dialog box
277 double zoom_step_factor; // the multiplicative factor in zoom in/out
278 double startup_zoom;
279 gboolean autoload_pdf_xoj;
280 #if GLIB_CHECK_VERSION(2,6,0)
281 GKeyFile *config_data;
282 #endif
283 int vertical_order[2][VBOX_MAIN_NITEMS]; // the order of interface components
284 gchar *default_font_name, *font_name;
285 gdouble default_font_size, font_size;
286 gulong resize_signal_handler;
287 gdouble hiliter_opacity;
288 guint hiliter_alpha_mask;
289 gboolean left_handed; // left-handed mode?
290 gboolean auto_save_prefs; // auto-save preferences ?
291 gboolean shorten_menus; // shorten menus ?
292 gchar *shorten_menu_items; // which items to hide
293 gboolean is_sel_cursor; // displaying a selection-related cursor
294 gint pre_fullscreen_width, pre_fullscreen_height; // for win32 fullscreen
295 #if GTK_CHECK_VERSION(2,10,0)
296 GtkPrintSettings *print_settings;
297 #endif
298 } UIData;
300 #define BRUSH_LINKED 0
301 #define BRUSH_COPIED 1
302 #define BRUSH_STATIC 2
304 typedef struct UndoErasureData {
305 struct Item *item; // the item that got erased
306 int npos; // its position in its layer
307 int nrepl; // the number of replacement items
308 GList *replacement_items;
309 } UndoErasureData;
311 typedef struct UndoItem {
312 int type;
313 struct Item *item; // for ITEM_STROKE, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
314 struct Layer *layer; // for ITEM_STROKE, ITEM_ERASURE, ITEM_PASTE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_MOVESEL, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_RECOGNIZER
315 struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
316 struct Page *page; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
317 GList *erasurelist; // for ITEM_ERASURE, ITEM_RECOGNIZER
318 GList *itemlist; // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL, ITEM_RESIZESEL
319 GList *auxlist; // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
320 struct Background *bg; // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
321 int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
322 double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG, ITEM_TEXT_ATTRIB, ITEM_RESIZESEL
323 double scaling_x, scaling_y; // for ITEM_RESIZESEL
324 gchar *str; // for ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
325 struct Brush *brush; // for ITEM_TEXT_ATTRIB
326 struct UndoItem *next;
327 int multiop;
328 } UndoItem;
330 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
331 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
334 typedef struct BgPdfRequest {
335 int pageno;
336 double dpi;
337 } BgPdfRequest;
339 typedef struct BgPdfPage {
340 double dpi;
341 GdkPixbuf *pixbuf;
342 int pixel_height, pixel_width; // pixel size of pixbuf
343 } BgPdfPage;
345 typedef struct BgPdf {
346 int status; // the rest only makes sense if this is not STATUS_NOT_INIT
347 guint pid; // the identifier of the idle callback
348 Refstring *filename;
349 int file_domain;
350 gchar *file_contents; // buffer containing a copy of file data
351 gsize file_length; // size of above buffer
352 int npages;
353 GList *pages; // a list of BgPdfPage structures
354 GList *requests; // a list of BgPdfRequest structures
355 gboolean has_failed; // has failed in the past...
356 PopplerDocument *document; // the poppler document
357 } BgPdf;
359 #define STATUS_NOT_INIT 0
360 #define STATUS_READY 1 // things are initialized and can work
361 // there used to be more possible values, things got streamlined...
363 // UTILITY MACROS
365 // getting a component of the interface by name
366 #define GET_COMPONENT(a) GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
368 // the margin between consecutive pages in continuous view
369 #define VIEW_CONTINUOUS_SKIP 20.0
372 // GLOBAL VARIABLES
374 // the main window and the canvas
376 extern GtkWidget *winMain;
377 extern GnomeCanvas *canvas;
379 // the data
381 extern struct Journal journal;
382 extern struct UIData ui;
383 extern struct BgPdf bgpdf;
384 extern struct UndoItem *undo, *redo;
386 extern double DEFAULT_ZOOM;
388 #define UNIT_CM 0
389 #define UNIT_IN 1
390 #define UNIT_PX 2
391 #define UNIT_PT 3