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