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