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