]> git.donarmstrong.com Git - xournal.git/blob - src/xournal.h
15906cdf6a257fe4298e94b6bebc60e706ea5492
[xournal.git] / src / xournal.h
1 #include <gtk/gtk.h>
2 #include <libgnomecanvas/libgnomecanvas.h>
3 #include <poppler/glib/poppler.h>
4
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). */
9
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. */
14
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. */
19
20 // PREF FILES INFO
21
22 #define CONFIG_DIR ".xournal"
23 #define MRU_FILE "recent-files"
24 #define MRU_SIZE 8 
25 #define CONFIG_FILE "config"
26
27 // version string for about box
28
29 #ifdef WIN32
30 #define VERSION_STRING VERSION "-win32"
31 #else
32 #define VERSION_STRING VERSION
33 #endif
34
35 // DATA STRUCTURES AND CONSTANTS
36
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
45
46 #define VBOX_MAIN_NITEMS 5 // number of interface items in vboxMain
47
48 /* a string (+ aux data) that maintains a refcount */
49
50 typedef struct Refstring {
51   int nref;
52   char *s;
53   gpointer aux;
54 } Refstring;
55
56
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.
59 */
60
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;
75
76 #define BG_SOLID 0
77 #define BG_PIXMAP 1
78 #define BG_PDF 2      // not implemented yet
79
80 #define RULING_NONE 0
81 #define RULING_LINED 1
82 #define RULING_RULED 2
83 #define RULING_GRAPH 3
84
85 #define DOMAIN_ABSOLUTE 0
86 #define DOMAIN_ATTACH 1
87 #define DOMAIN_CLONE 2  // only while loading file
88
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;
98
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
112
113 extern guint predef_colors_rgba[COLOR_MAX];
114 extern guint predef_bgcolors_rgba[COLOR_MAX];
115
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
122
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
134
135 #define TOOLOPT_ERASER_STANDARD     0
136 #define TOOLOPT_ERASER_WHITEOUT     1
137 #define TOOLOPT_ERASER_STROKES      2
138
139 extern double predef_thickness[NUM_STROKE_TOOLS][THICKNESS_MAX];
140
141 typedef struct BBox {
142   double left, right, top, bottom;
143 } BBox;
144
145 struct UndoErasureData;
146
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;
162
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
189
190 typedef struct Layer {
191   GList *items; // the items on the layer, from bottom to top
192   int nitems;
193   GnomeCanvasGroup *group;
194 } Layer;
195
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;
204
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;
210
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;
224
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   GdkDevice *stroke_device; // who's painting this stroke
256   int screen_width, screen_height; // initial screen size, for XInput events
257   double hand_refpt[2];
258   int hand_scrollto_cx, hand_scrollto_cy;
259   gboolean hand_scrollto_pending;
260   char *filename;
261   gchar *default_path; // default path for new notes
262   gboolean view_continuous, fullscreen, maximize_at_start;
263   gboolean in_update_page_stuff; // semaphore to avoid scrollbar retroaction
264   struct Selection *selection;
265   GdkCursor *cursor;
266   gboolean progressive_bg; // update PDF bg's one at a time
267   char *mrufile, *configfile; // file names for MRU & config
268   char *mru[MRU_SIZE]; // MRU data
269   GtkWidget *mrumenu[MRU_SIZE];
270   gboolean bg_apply_all_pages;
271   int window_default_width, window_default_height, scrollbar_step_increment;
272   gboolean print_ruling; // print the paper ruling ?
273   int default_unit; // the default unit for paper sizes
274   int startuptool; // the default tool at startup
275   int zoom_step_increment; // the increment in the zoom dialog box
276   double zoom_step_factor; // the multiplicative factor in zoom in/out
277   double startup_zoom;
278   gboolean autoload_pdf_xoj;
279 #if GLIB_CHECK_VERSION(2,6,0)
280   GKeyFile *config_data;
281 #endif
282   int vertical_order[2][VBOX_MAIN_NITEMS]; // the order of interface components
283   gchar *default_font_name, *font_name;
284   gdouble default_font_size, font_size;
285   gulong resize_signal_handler;
286   gdouble hiliter_opacity;
287   guint hiliter_alpha_mask;
288   gboolean left_handed; // left-handed mode?
289   gboolean auto_save_prefs; // auto-save preferences ?
290   gboolean shorten_menus; // shorten menus ?
291   gchar *shorten_menu_items; // which items to hide
292   gboolean is_sel_cursor; // displaying a selection-related cursor
293   gint pre_fullscreen_width, pre_fullscreen_height; // for win32 fullscreen
294 #if GTK_CHECK_VERSION(2,10,0)
295   GtkPrintSettings *print_settings;
296 #endif
297 } UIData;
298
299 #define BRUSH_LINKED 0
300 #define BRUSH_COPIED 1
301 #define BRUSH_STATIC 2
302
303 typedef struct UndoErasureData {
304   struct Item *item; // the item that got erased
305   int npos; // its position in its layer
306   int nrepl; // the number of replacement items
307   GList *replacement_items;
308 } UndoErasureData;
309
310 typedef struct UndoItem {
311   int type;
312   struct Item *item; // for ITEM_STROKE, ITEM_TEXT, ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
313   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
314   struct Layer *layer2; // for ITEM_DELETE_LAYER with val=-1, ITEM_MOVESEL
315   struct Page *page;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
316   GList *erasurelist; // for ITEM_ERASURE, ITEM_RECOGNIZER
317   GList *itemlist;  // for ITEM_MOVESEL, ITEM_PASTE, ITEM_REPAINTSEL, ITEM_RESIZESEL
318   GList *auxlist;   // for ITEM_REPAINTSEL (brushes), ITEM_MOVESEL (depths)
319   struct Background *bg;  // for ITEM_NEW_BG_ONE/RESIZE, ITEM_NEW_DEFAULT_BG
320   int val; // for ITEM_NEW_PAGE, ITEM_NEW_LAYER, ITEM_DELETE_LAYER, ITEM_DELETE_PAGE
321   double val_x, val_y; // for ITEM_MOVESEL, ITEM_NEW_BG_RESIZE, ITEM_PAPER_RESIZE, ITEM_NEW_DEFAULT_BG, ITEM_TEXT_ATTRIB, ITEM_RESIZESEL
322   double scaling_x, scaling_y; // for ITEM_RESIZESEL
323   gchar *str; // for ITEM_TEXT_EDIT, ITEM_TEXT_ATTRIB
324   struct Brush *brush; // for ITEM_TEXT_ATTRIB
325   struct UndoItem *next;
326   int multiop;
327 } UndoItem;
328
329 #define MULTIOP_CONT_REDO 1 // not the last in a multiop, so keep redoing
330 #define MULTIOP_CONT_UNDO 2 // not the first in a multiop, so keep undoing
331
332
333 typedef struct BgPdfRequest {
334   int pageno;
335   double dpi;
336 } BgPdfRequest;
337
338 typedef struct BgPdfPage {
339   double dpi;
340   GdkPixbuf *pixbuf;
341   int pixel_height, pixel_width; // pixel size of pixbuf
342 } BgPdfPage;
343
344 typedef struct BgPdf {
345   int status; // the rest only makes sense if this is not STATUS_NOT_INIT
346   guint pid; // the identifier of the idle callback
347   Refstring *filename;
348   int file_domain;
349   gchar *file_contents; // buffer containing a copy of file data
350   gsize file_length;  // size of above buffer
351   int npages;
352   GList *pages; // a list of BgPdfPage structures
353   GList *requests; // a list of BgPdfRequest structures
354   gboolean has_failed; // has failed in the past...
355   PopplerDocument *document; // the poppler document
356 } BgPdf;
357
358 #define STATUS_NOT_INIT 0
359 #define STATUS_READY    1  // things are initialized and can work
360 // there used to be more possible values, things got streamlined...
361
362 // UTILITY MACROS
363
364 // getting a component of the interface by name
365 #define GET_COMPONENT(a)  GTK_WIDGET (g_object_get_data(G_OBJECT (winMain), a))
366
367 // the margin between consecutive pages in continuous view
368 #define VIEW_CONTINUOUS_SKIP 20.0
369
370
371 // GLOBAL VARIABLES
372
373 // the main window and the canvas
374
375 extern GtkWidget *winMain;
376 extern GnomeCanvas *canvas;
377
378 // the data
379
380 extern struct Journal journal;
381 extern struct UIData ui;
382 extern struct BgPdf bgpdf;
383 extern struct UndoItem *undo, *redo;
384
385 extern double DEFAULT_ZOOM;
386
387 #define UNIT_CM 0
388 #define UNIT_IN 1
389 #define UNIT_PX 2
390 #define UNIT_PT 3