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